]> Dogcows Code - chaz/openbox/blob - src/client.hh
give the grips cursors
[chaz/openbox] / src / client.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __client_hh
3 #define __client_hh
4
5 /*! @file client.hh
6 @brief The OBClient class maintains the state of a client window by handling
7 property changes on the window and some client messages
8 */
9
10 extern "C" {
11 #include <X11/Xlib.h>
12
13 #ifdef SHAPE
14 #include <X11/extensions/shape.h>
15 #endif // SHAPE
16 }
17
18 #include <string>
19
20 #include "otk/point.hh"
21 #include "otk/strut.hh"
22 #include "otk/rect.hh"
23 #include "otk/eventhandler.hh"
24
25 namespace ob {
26
27 class OBFrame;
28
29 //! Maintains the state of a client window.
30 /*!
31 OBClient maintains the state of a client window. The state consists of the
32 hints that the application sets on the window, such as the title, or window
33 gravity.
34 <p>
35 OBClient also manages client messages for the client window. When the
36 application (or any application) requests something to be changed for the
37 client, it will call the ActionHandler (for client messages) or update the
38 class' member variables and call whatever is nessary to complete the
39 change (such as causing a redraw of the titlebar after the title is changed).
40 */
41 class OBClient : public otk::OtkEventHandler {
42 public:
43
44 //! The frame window which decorates around the client window
45 /*!
46 NOTE: This should NEVER be used inside the client class's constructor!
47 */
48 OBFrame *frame;
49
50 //! Corners of the client window, used for anchor positions
51 enum Corner { TopLeft,
52 TopRight,
53 BottomLeft,
54 BottomRight };
55
56 //! Possible window types
57 enum WindowType { Type_Desktop, //!< A desktop (bottom-most window)
58 Type_Dock, //!< A dock bar/panel window
59 Type_Toolbar, //!< A toolbar window, pulled off an app
60 Type_Menu, //!< A sticky menu from an app
61 Type_Utility, //!< A small utility window such as a palette
62 Type_Splash, //!< A splash screen window
63 Type_Dialog, //!< A dialog window
64 Type_Normal //!< A normal application window
65 };
66
67 //! Possible flags for MWM Hints (defined by Motif 2.0)
68 enum MwmFlags { MwmFlag_Functions = 1 << 0, //!< The MMW Hints define funcs
69 MwmFlag_Decorations = 1 << 1 //!< The MWM Hints define decor
70 };
71
72 //! Possible functions for MWM Hints (defined by Motif 2.0)
73 enum MwmFunctions { MwmFunc_All = 1 << 0, //!< All functions
74 MwmFunc_Resize = 1 << 1, //!< Allow resizing
75 MwmFunc_Move = 1 << 2, //!< Allow moving
76 MwmFunc_Iconify = 1 << 3, //!< Allow to be iconfied
77 MwmFunc_Maximize = 1 << 4 //!< Allow to be maximized
78 //MwmFunc_Close = 1 << 5 //!< Allow to be closed
79 };
80
81 //! Possible decorations for MWM Hints (defined by Motif 2.0)
82 enum MemDecorations { MwmDecor_All = 1 << 0, //!< All decorations
83 MwmDecor_Border = 1 << 1, //!< Show a border
84 MwmDecor_Handle = 1 << 2, //!< Show a handle (bottom)
85 MwmDecor_Title = 1 << 3, //!< Show a titlebar
86 //MwmDecor_Menu = 1 << 4, //!< Show a menu
87 MwmDecor_Iconify = 1 << 5, //!< Show an iconify button
88 MwmDecor_Maximize = 1 << 6 //!< Show a maximize button
89 };
90
91 //! The things the user can do to the client window
92 enum Function { Func_Resize = 1 << 0, //!< Allow resizing
93 Func_Move = 1 << 1, //!< Allow moving
94 Func_Iconify = 1 << 2, //!< Allow to be iconified
95 Func_Maximize = 1 << 3, //!< Allow to be maximized
96 Func_Close = 1 << 4 //!< Allow to be closed
97 };
98 //! Holds a bitmask of OBClient::Function values
99 typedef unsigned char FunctionFlags;
100
101 //! The decorations the client window wants to be displayed on it
102 enum Decoration { Decor_Titlebar = 1 << 0, //!< Display a titlebar
103 Decor_Handle = 1 << 1, //!< Display a handle (bottom)
104 Decor_Border = 1 << 2, //!< Display a border
105 Decor_Iconify = 1 << 3, //!< Display an iconify button
106 Decor_Maximize = 1 << 4, //!< Display a maximize button
107 Decor_Sticky = 1 << 5, //!< Display a sticky button
108 Decor_Close = 1 << 6 //!< Display a close button
109 };
110 //! Holds a bitmask of OBClient::Decoration values
111 typedef unsigned char DecorationFlags;
112
113 //! The MWM Hints as retrieved from the window property
114 /*!
115 This structure only contains 3 elements, even though the Motif 2.0
116 structure contains 5. We only use the first 3, so that is all gets defined.
117 */
118 typedef struct MwmHints {
119 //! The number of elements in the OBClient::MwmHints struct
120 static const unsigned int elements = 3;
121 unsigned long flags; //!< A bitmask of OBClient::MwmFlags values
122 unsigned long functions; //!< A bitmask of OBClient::MwmFunctions values
123 unsigned long decorations;//!< A bitmask of OBClient::MwmDecorations values
124 };
125
126 //! Possible actions that can be made with the _NET_WM_STATE client message
127 enum StateAction { State_Remove = 0, //!< _NET_WM_STATE_REMOVE
128 State_Add, //!< _NET_WM_STATE_ADD
129 State_Toggle //!< _NET_WM_STATE_TOGGLE
130 };
131
132 //! The event mask to grab on client windows
133 static const long event_mask = PropertyChangeMask | FocusChangeMask |
134 StructureNotifyMask;
135
136 //! The number of unmap events to ignore on the window
137 int ignore_unmaps;
138
139 private:
140 //! The screen number on which the client resides
141 int _screen;
142
143 //! The actual window that this class is wrapping up
144 Window _window;
145
146 //! The id of the group the window belongs to
147 Window _group;
148
149 // XXX: transient_for, transients
150
151 //! The desktop on which the window resides (0xffffffff for all desktops)
152 unsigned long _desktop;
153
154 //! Normal window title
155 std::string _title; // XXX: Have to keep track if this string is Utf8 or not
156 //! Window title when iconifiged
157 std::string _icon_title;
158
159 //! The application that created the window
160 std::string _app_name;
161 //! The class of the window, can used for grouping
162 std::string _app_class;
163
164 //! The type of window (what its function is)
165 WindowType _type;
166
167 //! Position and size of the window
168 /*!
169 This will not always be the actual position of the window on screen, it is
170 rather, the position requested by the client, to which the window's gravity
171 is applied.
172 */
173 otk::Rect _area;
174
175 //! The logical size of the window
176 /*!
177 The "logical" size of the window is refers to the user's perception of the
178 size of the window, and is the value that should be displayed to the user.
179 For example, with xterms, this value it the number of characters being
180 displayed in the terminal, instead of the number of pixels.
181 */
182 otk::Point _logical_size;
183
184 //! Width of the border on the window.
185 /*!
186 The window manager will set this to 0 while the window is being managed,
187 but needs to restore it afterwards, so it is saved here.
188 */
189 int _border_width;
190
191 //! The minimum size of the client window
192 /*!
193 If the min is > the max, then the window is not resizable
194 */
195 otk::Point _min_size;
196 //! The maximum size of the client window
197 /*!
198 If the min is > the max, then the window is not resizable
199 */
200 otk::Point _max_size;
201 //! The size of increments to resize the client window by
202 otk::Point _size_inc;
203 //! The base size of the client window
204 /*!
205 This value should be subtracted from the window's actual size when
206 displaying its size to the user, or working with its min/max size
207 */
208 otk::Point _base_size;
209
210 //! Where to place the decorated window in relation to the undecorated window
211 int _gravity;
212
213 //! The state of the window, one of WithdrawnState, IconicState, or
214 //! NormalState
215 long _wmstate;
216
217 //! Was the window's position requested by the application? if not, we should
218 //! place the window ourselves when it first appears
219 bool _positioned;
220
221 //! Can the window receive input focus?
222 bool _can_focus;
223 //! Urgency flag
224 bool _urgent;
225 //! Notify the window when it receives focus?
226 bool _focus_notify;
227
228 //! The window uses shape extension to be non-rectangular?
229 bool _shaped;
230
231 //! The window is modal, so it must be processed before any windows it is
232 //! related to can be focused
233 bool _modal;
234 //! Only the window's titlebar is displayed
235 bool _shaded;
236 //! The window is iconified
237 bool _iconic;
238 //! The window is maximized to fill the screen vertically
239 bool _max_vert;
240 //! The window is maximized to fill the screen horizontally
241 bool _max_horz;
242 //! The window is a 'fullscreen' window, and should be on top of all others
243 bool _fullscreen;
244 //! The window should be on top of other windows of the same type
245 bool _floating;
246
247 //! A bitmask of values in the OBClient::Decoration enum
248 /*!
249 The values in the variable are the decorations that the client wants to be
250 displayed around it.
251 */
252 DecorationFlags _decorations;
253
254 //! A bitmask of values in the OBClient::Function enum
255 /*!
256 The values in the variable specify the ways in which the user is allowed to
257 modify this window.
258 */
259 FunctionFlags _functions;
260
261 //! Retrieves the desktop hint's value and sets OBClient::_desktop
262 void getDesktop();
263 //! Retrieves the window's type and sets OBClient::_type
264 void getType();
265 //! Gets the MWM Hints and adjusts OBClient::_functions and
266 //! OBClient::_decorations
267 void getMwmHints();
268 //! Gets the position and size of the window and sets OBClient::_area
269 void getArea();
270 //! Gets the net_state hint and sets the boolean flags for any states set in
271 //! the hint
272 void getState();
273 //! Determines if the window uses the Shape extension and sets
274 //! OBClient::_shaped
275 void getShaped();
276
277 //! Sets the wm_state to the specified value
278 void setWMState(long state);
279 //! Sends the window to the specified desktop
280 void setDesktop(long desktop);
281 //! Adjusts the window's net_state
282 void setState(StateAction action, long data1, long data2);
283
284 //! Update the protocols that the window supports and adjusts things if they
285 //! change
286 void updateProtocols();
287 //! Updates the WMNormalHints and adjusts things if they change
288 void updateNormalHints();
289 //! Updates the WMHints and adjusts things if they change
290 void updateWMHints();
291 //! Updates the window's title
292 void updateTitle();
293 //! Updates the window's icon title
294 void updateIconTitle();
295 //! Updates the window's application name and class
296 void updateClass();
297 // XXX: updateTransientFor();
298
299 //! Move the client window
300 /*!
301 This shouldnt be used to move the window internally! It will apply
302 window gravity after moving the window.
303 */
304 void move(int x, int y);
305
306 //! Resizes the client window, anchoring it in a given corner
307 /*!
308 This also maintains things like the client's minsize, and size increments.
309 @param anchor The corner to keep in the same position when resizing
310 @param size The new size for the client
311 */
312 void resize(Corner anchor, int x, int y);
313
314 public:
315 //! Constructs a new OBClient object around a specified window id
316 /*!
317 @param window The window id that the OBClient class should handle
318 @param screen The screen on which the window resides
319 */
320 OBClient(int screen, Window window);
321 //! Destroys the OBClient object
322 virtual ~OBClient();
323
324 //! Returns the screen on which the clien resides
325 inline int screen() const { return _screen; }
326
327 //! Returns the window id that the OBClient object is handling
328 inline Window window() const { return _window; }
329
330 //! Returns the type of the window, one of the OBClient::WindowType values
331 inline WindowType type() const { return _type; }
332 //! Returns the desktop on which the window resides
333 /*!
334 This value is a 0-based index.<br>
335 A value of 0xffffffff indicates that the window exists on all desktops.
336 */
337 inline unsigned long desktop() const { return _desktop; }
338 //! Returns the window's title
339 inline const std::string &title() const { return _title; }
340 //! Returns the window's title when it is iconified
341 inline const std::string &iconTitle() const { return _title; }
342 //! Returns the application's name to whom the window belongs
343 inline const std::string &appName() const { return _app_name; }
344 //! Returns the class of the window
345 inline const std::string &appClass() const { return _app_class; }
346 //! Returns if the window can be focused
347 /*!
348 @return true if the window can receive focusl otherwise, false
349 */
350 inline bool canFocus() const { return _can_focus; }
351 //! Returns if the window has indicated that it needs urgent attention
352 inline bool urgent() const { return _urgent; }
353 //! Returns if the window wants to be notified when it receives focus
354 inline bool focusNotify() const { return _focus_notify; }
355 //! Returns if the window uses the Shape extension
356 inline bool shaped() const { return _shaped; }
357 //! Returns the window's gravity
358 /*!
359 This value determines where to place the decorated window in relation to
360 its position without decorations.<br>
361 One of: NorthWestGravity, SouthWestGravity, EastGravity, ...,
362 SouthGravity, StaticGravity, ForgetGravity
363 */
364 inline int gravity() const { return _gravity; }
365 //! Returns if the application requested the initial position for the window
366 /*!
367 If the application did not request a position (this function returns false)
368 then the window should be placed intelligently by the window manager
369 initially
370 */
371 inline bool positionRequested() const { return _positioned; }
372 //! Returns the decorations that the client window wishes to be displayed on
373 //! it
374 inline DecorationFlags decorations() const { return _decorations; }
375 //! Returns the functions that the user can perform on the window
376 inline FunctionFlags funtions() const { return _functions; }
377
378 //! Returns if the window is modal
379 /*!
380 If the window is modal, then no other windows that it is related to can get
381 focus while it exists/remains modal.
382 */
383 inline bool modal() const { return _modal; }
384 //! Returns if the window is shaded
385 /*!
386 When the window is shaded, only its titlebar is visible, the client itself
387 is not mapped
388 */
389 inline bool shaded() const { return _shaded; }
390 //! Returns if the window is iconified
391 /*!
392 When the window is iconified, it is not visible at all (except in iconbars/
393 panels/etc that want to show lists of iconified windows
394 */
395 inline bool iconic() const { return _iconic; }
396 //! Returns if the window is maximized vertically
397 inline bool maxVert() const { return _max_vert; }
398 //! Returns if the window is maximized horizontally
399 inline bool maxHorz() const { return _max_horz; }
400 //! Returns if the window is fullscreen
401 /*!
402 When the window is fullscreen, it is kept above all others
403 */
404 inline bool fullscreen() const { return _fullscreen; }
405 //! Returns if the window is floating
406 /*!
407 When the window is floating, it is kept above all others in the same
408 stacking layer as it
409 */
410 inline bool floating() const { return _floating; }
411
412 //! Returns the client's requested border width (not used by the wm)
413 inline int borderWidth() const { return _border_width; }
414
415 //! Returns the position and size of the client relative to the root window
416 inline const otk::Rect &area() const { return _area; }
417
418 virtual void propertyHandler(const XPropertyEvent &e);
419 virtual void clientMessageHandler(const XClientMessageEvent &e);
420 virtual void shapeHandler(const XShapeEvent &e);
421 virtual void configureRequestHandler(const XConfigureRequestEvent &e);
422 virtual void unmapHandler(const XUnmapEvent &e);
423 virtual void destroyHandler(const XDestroyWindowEvent &e);
424 };
425
426 }
427
428 #endif // __client_hh
This page took 0.050813 seconds and 4 git commands to generate.