]> Dogcows Code - chaz/openbox/blob - src/client.hh
add more doxygen
[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 Client class maintains the state of a client window by handling
7 property changes on the window and some client messages
8 */
9
10 #include "widgetbase.hh"
11 #include "otk/point.hh"
12 #include "otk/strut.hh"
13 #include "otk/rect.hh"
14 #include "otk/eventhandler.hh"
15
16 extern "C" {
17 #include <X11/Xlib.h>
18
19 #ifdef SHAPE
20 #include <X11/extensions/shape.h>
21 #endif // SHAPE
22 }
23
24 #include <string>
25 #include <list>
26
27 namespace ob {
28
29 class Frame;
30
31 //! The MWM Hints as retrieved from the window property
32 /*!
33 This structure only contains 3 elements, even though the Motif 2.0
34 structure contains 5. We only use the first 3, so that is all gets defined.
35 */
36 struct MwmHints {
37 unsigned long flags; //!< A bitmask of Client::MwmFlags values
38 unsigned long functions; //!< A bitmask of Client::MwmFunctions values
39 unsigned long decorations;//!< A bitmask of Client::MwmDecorations values
40 //! The number of elements in the Client::MwmHints struct
41 static const unsigned int elements = 3;
42 };
43
44 //! Maintains the state of a client window.
45 /*!
46 Client maintains the state of a client window. The state consists of the
47 hints that the application sets on the window, such as the title, or window
48 gravity.
49 <p>
50 Client also manages client messages for the client window. When the
51 application (or any application) requests something to be changed for the
52 client, it will call the ActionHandler (for client messages) or update the
53 class' member variables and call whatever is nessary to complete the
54 change (such as causing a redraw of the titlebar after the title is changed).
55 */
56 class Client : public otk::EventHandler, public WidgetBase {
57 public:
58
59 //! The frame window which decorates around the client window
60 /*!
61 NOTE: This should NEVER be used inside the client class's constructor!
62 */
63 Frame *frame;
64
65 //! Holds a list of Clients
66 typedef std::list<Client*> List;
67
68 //! The possible stacking layers a client window can be a part of
69 enum StackLayer {
70 Layer_Icon, //!< 0 - iconified windows, in any order at all
71 Layer_Desktop, //!< 1 - desktop windows
72 Layer_Below, //!< 2 - normal windows w/ below
73 Layer_Normal, //!< 3 - normal windows
74 Layer_Above, //!< 4 - normal windows w/ above
75 Layer_Top, //!< 5 - always-on-top-windows (docks?)
76 Layer_Fullscreen, //!< 6 - fullscreeen windows
77 Layer_Internal, //!< 7 - openbox windows/menus
78 NUM_LAYERS
79 };
80
81 //! Corners of the client window, used for anchor positions
82 enum Corner { TopLeft,
83 TopRight,
84 BottomLeft,
85 BottomRight };
86
87 //! Possible window types
88 enum WindowType { Type_Desktop, //!< A desktop (bottom-most window)
89 Type_Dock, //!< A dock bar/panel window
90 Type_Toolbar, //!< A toolbar window, pulled off an app
91 Type_Menu, //!< A sticky menu from an app
92 Type_Utility, //!< A small utility window such as a palette
93 Type_Splash, //!< A splash screen window
94 Type_Dialog, //!< A dialog window
95 Type_Normal //!< A normal application window
96 };
97
98 //! Possible flags for MWM Hints (defined by Motif 2.0)
99 enum MwmFlags { MwmFlag_Functions = 1 << 0, //!< The MMW Hints define funcs
100 MwmFlag_Decorations = 1 << 1 //!< The MWM Hints define decor
101 };
102
103 //! Possible functions for MWM Hints (defined by Motif 2.0)
104 enum MwmFunctions { MwmFunc_All = 1 << 0, //!< All functions
105 MwmFunc_Resize = 1 << 1, //!< Allow resizing
106 MwmFunc_Move = 1 << 2, //!< Allow moving
107 MwmFunc_Iconify = 1 << 3, //!< Allow to be iconfied
108 MwmFunc_Maximize = 1 << 4 //!< Allow to be maximized
109 //MwmFunc_Close = 1 << 5 //!< Allow to be closed
110 };
111
112 //! Possible decorations for MWM Hints (defined by Motif 2.0)
113 enum MemDecorations { MwmDecor_All = 1 << 0, //!< All decorations
114 MwmDecor_Border = 1 << 1, //!< Show a border
115 MwmDecor_Handle = 1 << 2, //!< Show a handle (bottom)
116 MwmDecor_Title = 1 << 3, //!< Show a titlebar
117 //MwmDecor_Menu = 1 << 4, //!< Show a menu
118 MwmDecor_Iconify = 1 << 5, //!< Show an iconify button
119 MwmDecor_Maximize = 1 << 6 //!< Show a maximize button
120 };
121
122 //! The things the user can do to the client window
123 enum Function { Func_Resize = 1 << 0, //!< Allow resizing
124 Func_Move = 1 << 1, //!< Allow moving
125 Func_Iconify = 1 << 2, //!< Allow to be iconified
126 Func_Maximize = 1 << 3, //!< Allow to be maximized
127 Func_Close = 1 << 4 //!< Allow to be closed
128 };
129 //! Holds a bitmask of Client::Function values
130 typedef unsigned char FunctionFlags;
131
132 //! The decorations the client window wants to be displayed on it
133 enum Decoration { Decor_Titlebar = 1 << 0, //!< Display a titlebar
134 Decor_Handle = 1 << 1, //!< Display a handle (bottom)
135 Decor_Border = 1 << 2, //!< Display a border
136 Decor_Iconify = 1 << 3, //!< Display an iconify button
137 Decor_Maximize = 1 << 4, //!< Display a maximize button
138 Decor_Sticky = 1 << 5, //!< Display a sticky button
139 Decor_Close = 1 << 6 //!< Display a close button
140 };
141 //! Holds a bitmask of Client::Decoration values
142 typedef unsigned char DecorationFlags;
143
144 //! Possible actions that can be made with the _NET_WM_STATE client message
145 enum StateAction { State_Remove = 0, //!< _NET_WM_STATE_REMOVE
146 State_Add, //!< _NET_WM_STATE_ADD
147 State_Toggle //!< _NET_WM_STATE_TOGGLE
148 };
149
150 //! The event mask to grab on client windows
151 static const long event_mask = PropertyChangeMask | FocusChangeMask |
152 StructureNotifyMask;
153
154 //! The mask of events to not let propogate past the client
155 /*!
156 This makes things like xprop work on the client window, but means we have
157 to explicitly grab clicks that we want.
158 */
159 static const long no_propagate_mask = ButtonPressMask | ButtonReleaseMask |
160 ButtonMotionMask;
161
162 //! The number of unmap events to ignore on the window
163 int ignore_unmaps;
164
165 private:
166 //! The screen number on which the client resides
167 int _screen;
168
169 //! The actual window that this class is wrapping up
170 Window _window;
171
172 //! The id of the group the window belongs to
173 Window _group;
174
175 //! The client which this client is a transient (child) for
176 Client *_transient_for;
177
178 //! The clients which are transients (children) of this client
179 Client::List _transients;
180
181 //! The desktop on which the window resides (0xffffffff for all desktops)
182 long _desktop;
183
184 //! Normal window title
185 std::string _title; // XXX: Have to keep track if this string is Utf8 or not
186 //! Window title when iconifiged
187 std::string _icon_title;
188
189 //! The application that created the window
190 std::string _app_name;
191 //! The class of the window, can used for grouping
192 std::string _app_class;
193 //! The specified role of the window, used for identification
194 std::string _role;
195
196 //! The type of window (what its function is)
197 WindowType _type;
198
199 //! Position and size of the window
200 /*!
201 This will not always be the actual position of the window on screen, it is
202 rather, the position requested by the client, to which the window's gravity
203 is applied.
204 */
205 otk::Rect _area;
206
207 //! The window's strut
208 /*!
209 The strut defines areas of the screen that are marked off-bounds for window
210 placement. In theory, where this window exists.
211 */
212 otk::Strut _strut;
213
214 //! The logical size of the window
215 /*!
216 The "logical" size of the window is refers to the user's perception of the
217 size of the window, and is the value that should be displayed to the user.
218 For example, with xterms, this value it the number of characters being
219 displayed in the terminal, instead of the number of pixels.
220 */
221 otk::Point _logical_size;
222
223 //! Width of the border on the window.
224 /*!
225 The window manager will set this to 0 while the window is being managed,
226 but needs to restore it afterwards, so it is saved here.
227 */
228 int _border_width;
229
230 //! The minimum size of the client window
231 /*!
232 If the min is > the max, then the window is not resizable
233 */
234 otk::Point _min_size;
235 //! The maximum size of the client window
236 /*!
237 If the min is > the max, then the window is not resizable
238 */
239 otk::Point _max_size;
240 //! The size of increments to resize the client window by
241 otk::Point _size_inc;
242 //! The base size of the client window
243 /*!
244 This value should be subtracted from the window's actual size when
245 displaying its size to the user, or working with its min/max size
246 */
247 otk::Point _base_size;
248
249 //! Window decoration and functionality hints
250 MwmHints _mwmhints;
251
252 //! Where to place the decorated window in relation to the undecorated window
253 int _gravity;
254
255 //! The state of the window, one of WithdrawnState, IconicState, or
256 //! NormalState
257 long _wmstate;
258
259 //! Was the window's position requested by the application? if not, we should
260 //! place the window ourselves when it first appears
261 bool _positioned;
262
263 //! Can the window receive input focus?
264 bool _can_focus;
265 //! Urgency flag
266 bool _urgent;
267 //! Notify the window when it receives focus?
268 bool _focus_notify;
269 //! Does the client window have the input focus?
270 bool _focused;
271
272 //! The window uses shape extension to be non-rectangular?
273 bool _shaped;
274
275 //! The window is modal, so it must be processed before any windows it is
276 //! related to can be focused
277 bool _modal;
278 //! Only the window's titlebar is displayed
279 bool _shaded;
280 //! The window is iconified
281 bool _iconic;
282 //! The window is maximized to fill the screen vertically
283 bool _max_vert;
284 //! The window is maximized to fill the screen horizontally
285 bool _max_horz;
286 //! The window should not be displayed by pagers
287 bool _skip_pager;
288 //! The window should not be displayed by taskbars
289 bool _skip_taskbar;
290 //! The window is a 'fullscreen' window, and should be on top of all others
291 bool _fullscreen;
292 //! The window should be on top of other windows of the same type
293 bool _above;
294 //! The window should be underneath other windows of the same type
295 bool _below;
296
297 StackLayer _layer;
298
299 //! A bitmask of values in the Client::Decoration enum
300 /*!
301 The values in the variable are the decorations that the client wants to be
302 displayed around it.
303 */
304 DecorationFlags _decorations;
305
306 //! A bitmask of values in the Client::Function enum
307 /*!
308 The values in the variable specify the ways in which the user is allowed to
309 modify this window.
310 */
311 FunctionFlags _functions;
312
313 //! Retrieves the desktop hint's value and sets Client::_desktop
314 void getDesktop();
315 //! Retrieves the window's type and sets Client::_type
316 void getType();
317 //! Gets the MWM Hints and adjusts Client::_functions and
318 //! Client::_decorations
319 void getMwmHints();
320 //! Gets the position and size of the window and sets Client::_area
321 void getArea();
322 //! Gets the net_state hint and sets the boolean flags for any states set in
323 //! the hint
324 void getState();
325 //! Determines if the window uses the Shape extension and sets
326 //! Client::_shaped
327 void getShaped();
328
329 //! Set up what decor should be shown on the window and what functions should
330 //! be allowed (Client::_decorations and Client::_functions).
331 /*!
332 This also updates the NET_WM_ALLOWED_ACTIONS hint.
333 */
334 void setupDecorAndFunctions();
335
336 //! Sets the wm_state to the specified value
337 void setWMState(long state);
338 //! Adjusts the window's net_state
339 void setState(StateAction action, long data1, long data2);
340
341 //! Sends the window to the specified desktop
342 void setDesktop(long desktop);
343
344 //! Calculates the stacking layer for the client window
345 void calcLayer();
346
347 //! Update the protocols that the window supports and adjusts things if they
348 //! change
349 void updateProtocols();
350 //! Updates the WMNormalHints and adjusts things if they change
351 void updateNormalHints();
352 //! Updates the WMHints and adjusts things if they change
353 void updateWMHints();
354 //! Updates the window's title
355 void updateTitle();
356 //! Updates the window's icon title
357 void updateIconTitle();
358 //! Updates the window's application name and class
359 void updateClass();
360 //! Updates the strut for the client
361 void updateStrut();
362 //! Updates the window's transient status, and any parents of it
363 void updateTransientFor();
364
365 //! Change the client's state hints to match the class' data
366 void changeState();
367
368 //! Request the client to close its window.
369 void close();
370
371 //! Shades or unshades the client window
372 /*!
373 @param shade true if the window should be shaded; false if it should be
374 unshaded.
375 */
376 void shade(bool shade);
377
378 public:
379 #ifndef SWIG
380 //! Constructs a new Client object around a specified window id
381 /*!
382 BB @param window The window id that the Client class should handle
383 @param screen The screen on which the window resides
384 */
385 Client(int screen, Window window);
386 //! Destroys the Client object
387 virtual ~Client();
388 #endif
389
390 //! Returns the screen on which the clien resides
391 inline int screen() const { return _screen; }
392
393 //! Returns the window id that the Client object is handling
394 inline Window window() const { return _window; }
395
396 //! Returns the type of the window, one of the Client::WindowType values
397 inline WindowType type() const { return _type; }
398 //! Returns if the window should be treated as a normal window.
399 /*!
400 Some windows (desktops, docks, splash screens) have special rules applied
401 to them in a number of places regarding focus or user interaction.
402 */
403 inline bool normal() const {
404 return ! (_type == Type_Desktop || _type == Type_Dock ||
405 _type == Type_Splash);
406 }
407
408 //! Returns the desktop on which the window resides
409 /*!
410 This value is a 0-based index.<br>
411 A value of 0xffffffff indicates that the window exists on all desktops.
412 */
413 inline long desktop() const { return _desktop; }
414 //! Returns the window's title
415 inline const std::string &title() const { return _title; }
416 //! Returns the window's title when it is iconified
417 inline const std::string &iconTitle() const { return _title; }
418 //! Returns the application's name to whom the window belongs
419 inline const std::string &appName() const { return _app_name; }
420 //! Returns the class of the window
421 inline const std::string &appClass() const { return _app_class; }
422 //! Returns the program-specified role of the window
423 inline const std::string &role() const { return _role; }
424 //! Returns if the window can be focused
425 /*!
426 @return true if the window can receive focus; otherwise, false
427 */
428 inline bool canFocus() const { return _can_focus; }
429 //! Returns if the window has indicated that it needs urgent attention
430 inline bool urgent() const { return _urgent; }
431 //! Returns if the window wants to be notified when it receives focus
432 inline bool focusNotify() const { return _focus_notify; }
433 //! Returns if the window uses the Shape extension
434 inline bool shaped() const { return _shaped; }
435 //! Returns the window's gravity
436 /*!
437 This value determines where to place the decorated window in relation to
438 its position without decorations.<br>
439 One of: NorthWestGravity, SouthWestGravity, EastGravity, ...,
440 SouthGravity, StaticGravity, ForgetGravity
441 */
442 inline int gravity() const { return _gravity; }
443 //! Returns if the application requested the initial position for the window
444 /*!
445 If the application did not request a position (this function returns false)
446 then the window should be placed intelligently by the window manager
447 initially
448 */
449 inline bool positionRequested() const { return _positioned; }
450 //! Returns the decorations that the client window wishes to be displayed on
451 //! it
452 inline DecorationFlags decorations() const { return _decorations; }
453 //! Returns the functions that the user can perform on the window
454 inline FunctionFlags funtions() const { return _functions; }
455
456 //! Return the client this window is transient for
457 inline Client *transientFor() const { return _transient_for; }
458
459 //! Returns if the window is modal
460 /*!
461 If the window is modal, then no other windows that it is related to can get
462 focus while it exists/remains modal.
463 */
464 inline bool modal() const { return _modal; }
465 //! Returns if the window is shaded
466 /*!
467 When the window is shaded, only its titlebar is visible.
468 */
469 inline bool shaded() const { return _shaded; }
470 //! Returns if the window is iconified
471 /*!
472 When the window is iconified, it is not visible at all (except in iconbars/
473 panels/etc that want to show lists of iconified windows
474 */
475 inline bool iconic() const { return _iconic; }
476 //! Returns if the window is maximized vertically
477 inline bool maxVert() const { return _max_vert; }
478 //! Returns if the window is maximized horizontally
479 inline bool maxHorz() const { return _max_horz; }
480 //! Returns the window's stacking layer
481 inline StackLayer layer() const { return _layer; }
482
483 //! Removes or reapplies the client's border to its window
484 /*!
485 Used when managing and unmanaging a window.
486 @param addborder true if adding the border to the client; false if removing
487 from the client
488 */
489 void toggleClientBorder(bool addborder);
490
491 //! Returns the position and size of the client relative to the root window
492 inline const otk::Rect &area() const { return _area; }
493
494 //! Returns the client's strut definition
495 inline const otk::Strut &strut() const { return _strut; }
496
497 //! Move the client window
498 /*!
499 @param x The X coordinate to move to.
500 @param y The Y coordinate to move to.
501 */
502 void move(int x, int y);
503
504 //! Resizes the client window, anchoring it in a given corner
505 /*!
506 This also maintains things like the client's minsize, and size increments.
507 @param anchor The corner to keep in the same position when resizing.
508 @param w The width component of the new size for the client.
509 @param h The height component of the new size for the client.
510 @param x An optional X coordinate to which the window will be moved
511 after resizing.
512 @param y An optional Y coordinate to which the window will be moved
513 after resizing.
514 The x and y coordinates must both be sepcified together, or they will have
515 no effect. When they are specified, the anchor is ignored.
516 */
517 void resize(Corner anchor, int w, int h, int x = INT_MIN, int y = INT_MIN);
518
519 //! Attempt to focus the client window
520 bool focus() const;
521
522 //! Remove focus from the client window
523 void unfocus() const;
524
525 virtual void focusHandler(const XFocusChangeEvent &e);
526 virtual void unfocusHandler(const XFocusChangeEvent &e);
527 virtual void propertyHandler(const XPropertyEvent &e);
528 virtual void clientMessageHandler(const XClientMessageEvent &e);
529 virtual void configureRequestHandler(const XConfigureRequestEvent &e);
530 virtual void unmapHandler(const XUnmapEvent &e);
531 virtual void destroyHandler(const XDestroyWindowEvent &e);
532 virtual void reparentHandler(const XReparentEvent &e);
533 #if defined(SHAPE)
534 virtual void shapeHandler(const XShapeEvent &e);
535 #endif // SHAPE
536 };
537
538 }
539
540 #endif // __client_hh
This page took 0.055854 seconds and 5 git commands to generate.