1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 @brief The OBClient class maintains the state of a client window by handling
7 property changes on the window and some client messages
11 #include "otk/point.hh"
12 #include "otk/strut.hh"
13 #include "otk/rect.hh"
14 #include "otk/eventhandler.hh"
20 #include <X11/extensions/shape.h>
31 //! The MWM Hints as retrieved from the window property
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.
37 //! The number of elements in the OBClient::MwmHints struct
38 static const unsigned int elements
= 3;
39 unsigned long flags
; //!< A bitmask of OBClient::MwmFlags values
40 unsigned long functions
; //!< A bitmask of OBClient::MwmFunctions values
41 unsigned long decorations
;//!< A bitmask of OBClient::MwmDecorations values
44 //! Maintains the state of a client window.
46 OBClient 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
50 OBClient 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).
56 class OBClient
: public otk::OtkEventHandler
, public OBWidget
{
59 //! The frame window which decorates around the client window
61 NOTE: This should NEVER be used inside the client class's constructor!
65 //! Holds a list of OBClients
66 typedef std::list
<OBClient
*> List
;
68 //! The possible stacking layers a client window can be a part of
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
81 //! Corners of the client window, used for anchor positions
82 enum Corner
{ TopLeft
,
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
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
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
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
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
129 //! Holds a bitmask of OBClient::Function values
130 typedef unsigned char FunctionFlags
;
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
141 //! Holds a bitmask of OBClient::Decoration values
142 typedef unsigned char DecorationFlags
;
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
150 //! The event mask to grab on client windows
151 static const long event_mask
= PropertyChangeMask
| FocusChangeMask
|
154 //! The mask of events to not let propogate past the client
156 This makes things like xprop work on the client window, but means we have
157 to explicitly grab clicks that we want.
159 static const long no_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
|
162 //! The number of unmap events to ignore on the window
166 //! The screen number on which the client resides
169 //! The actual window that this class is wrapping up
172 //! The id of the group the window belongs to
175 //! The client which this client is a transient (child) for
176 OBClient
*_transient_for
;
178 //! The clients which are transients (children) of this client
179 OBClient::List _transients
;
181 //! The desktop on which the window resides (0xffffffff for all desktops)
182 unsigned long _desktop
;
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
;
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
196 //! The type of window (what its function is)
199 //! Position and size of the window
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
207 //! The window's strut
209 The strut defines areas of the screen that are marked off-bounds for window
210 placement. In theory, where this window exists.
214 //! The logical size of the window
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.
221 otk::Point _logical_size
;
223 //! Width of the border on the window.
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.
230 //! The minimum size of the client window
232 If the min is > the max, then the window is not resizable
234 otk::Point _min_size
;
235 //! The maximum size of the client window
237 If the min is > the max, then the window is not resizable
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
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
247 otk::Point _base_size
;
249 //! Where to place the decorated window in relation to the undecorated window
252 //! The state of the window, one of WithdrawnState, IconicState, or
256 //! Was the window's position requested by the application? if not, we should
257 //! place the window ourselves when it first appears
260 //! Can the window receive input focus?
264 //! Notify the window when it receives focus?
266 //! Does the client window have the input focus?
269 //! The window uses shape extension to be non-rectangular?
272 //! The window is modal, so it must be processed before any windows it is
273 //! related to can be focused
275 //! Only the window's titlebar is displayed
277 //! The window is iconified
279 //! The window is maximized to fill the screen vertically
281 //! The window is maximized to fill the screen horizontally
283 //! The window should not be displayed by pagers
285 //! The window should not be displayed by taskbars
287 //! The window is a 'fullscreen' window, and should be on top of all others
289 //! The window should be on top of other windows of the same type
291 //! The window should be underneath other windows of the same type
296 //! A bitmask of values in the OBClient::Decoration enum
298 The values in the variable are the decorations that the client wants to be
301 DecorationFlags _decorations
;
303 //! A bitmask of values in the OBClient::Function enum
305 The values in the variable specify the ways in which the user is allowed to
308 FunctionFlags _functions
;
310 //! Retrieves the desktop hint's value and sets OBClient::_desktop
312 //! Retrieves the window's type and sets OBClient::_type
314 //! Gets the MWM Hints and adjusts OBClient::_functions and
315 //! OBClient::_decorations
317 //! Gets the position and size of the window and sets OBClient::_area
319 //! Gets the net_state hint and sets the boolean flags for any states set in
322 //! Determines if the window uses the Shape extension and sets
323 //! OBClient::_shaped
326 //! Sets the wm_state to the specified value
327 void setWMState(long state
);
328 //! Sends the window to the specified desktop
329 void setDesktop(long desktop
);
330 //! Adjusts the window's net_state
331 void setState(StateAction action
, long data1
, long data2
);
333 //! Calculates the stacking layer for the client window
336 //! Update the protocols that the window supports and adjusts things if they
338 void updateProtocols();
339 //! Updates the WMNormalHints and adjusts things if they change
340 void updateNormalHints();
341 //! Updates the WMHints and adjusts things if they change
342 void updateWMHints();
343 //! Updates the window's title
345 //! Updates the window's icon title
346 void updateIconTitle();
347 //! Updates the window's application name and class
349 //! Updates the strut for the client
351 //! Updates the window's transient status, and any parents of it
352 void updateTransientFor();
354 //! Change the client's state hints to match the class' data
359 //! Constructs a new OBClient object around a specified window id
361 @param window The window id that the OBClient class should handle
362 @param screen The screen on which the window resides
364 OBClient(int screen
, Window window
);
365 //! Destroys the OBClient object
369 //! Returns the screen on which the clien resides
370 inline int screen() const { return _screen
; }
372 //! Returns the window id that the OBClient object is handling
373 inline Window
window() const { return _window
; }
375 //! Returns the type of the window, one of the OBClient::WindowType values
376 inline WindowType
type() const { return _type
; }
377 //! Returns if the window should be treated as a normal window.
379 Some windows (desktops, docks, splash screens) have special rules applied
380 to them in a number of places regarding focus or user interaction.
382 inline bool normal() const {
383 return ! (_type
== Type_Desktop
|| _type
== Type_Dock
||
384 _type
== Type_Splash
);
387 //! Returns the desktop on which the window resides
389 This value is a 0-based index.<br>
390 A value of 0xffffffff indicates that the window exists on all desktops.
392 inline unsigned long desktop() const { return _desktop
; }
393 //! Returns the window's title
394 inline const std::string
&title() const { return _title
; }
395 //! Returns the window's title when it is iconified
396 inline const std::string
&iconTitle() const { return _title
; }
397 //! Returns the application's name to whom the window belongs
398 inline const std::string
&appName() const { return _app_name
; }
399 //! Returns the class of the window
400 inline const std::string
&appClass() const { return _app_class
; }
401 //! Returns the program-specified role of the window
402 inline const std::string
&role() const { return _role
; }
403 //! Returns if the window can be focused
405 @return true if the window can receive focus; otherwise, false
407 inline bool canFocus() const { return _can_focus
; }
408 //! Returns if the window has indicated that it needs urgent attention
409 inline bool urgent() const { return _urgent
; }
410 //! Returns if the window wants to be notified when it receives focus
411 inline bool focusNotify() const { return _focus_notify
; }
412 //! Returns if the window uses the Shape extension
413 inline bool shaped() const { return _shaped
; }
414 //! Returns the window's gravity
416 This value determines where to place the decorated window in relation to
417 its position without decorations.<br>
418 One of: NorthWestGravity, SouthWestGravity, EastGravity, ...,
419 SouthGravity, StaticGravity, ForgetGravity
421 inline int gravity() const { return _gravity
; }
422 //! Returns if the application requested the initial position for the window
424 If the application did not request a position (this function returns false)
425 then the window should be placed intelligently by the window manager
428 inline bool positionRequested() const { return _positioned
; }
429 //! Returns the decorations that the client window wishes to be displayed on
431 inline DecorationFlags
decorations() const { return _decorations
; }
432 //! Returns the functions that the user can perform on the window
433 inline FunctionFlags
funtions() const { return _functions
; }
435 //! Returns if the window is modal
437 If the window is modal, then no other windows that it is related to can get
438 focus while it exists/remains modal.
440 inline bool modal() const { return _modal
; }
441 //! Returns if the window is shaded
443 When the window is shaded, only its titlebar is visible, the client itself
446 inline bool shaded() const { return _shaded
; }
447 //! Returns if the window is iconified
449 When the window is iconified, it is not visible at all (except in iconbars/
450 panels/etc that want to show lists of iconified windows
452 inline bool iconic() const { return _iconic
; }
453 //! Returns if the window is maximized vertically
454 inline bool maxVert() const { return _max_vert
; }
455 //! Returns if the window is maximized horizontally
456 inline bool maxHorz() const { return _max_horz
; }
457 //! Returns the window's stacking layer
458 inline StackLayer
layer() const { return _layer
; }
460 //! Removes or reapplies the client's border to its window
462 Used when managing and unmanaging a window.
463 @param addborder true if adding the border to the client; false if removing
466 void toggleClientBorder(bool addborder
);
468 //! Returns the position and size of the client relative to the root window
469 inline const otk::Rect
&area() const { return _area
; }
471 //! Returns the client's strut definition
472 inline const otk::Strut
&strut() const { return _strut
; }
474 //! Move the client window
475 void move(int x
, int y
);
477 //! Resizes the client window, anchoring it in a given corner
479 This also maintains things like the client's minsize, and size increments.
480 @param anchor The corner to keep in the same position when resizing.
481 @param w The width component of the new size for the client.
482 @param h The height component of the new size for the client.
483 @param x An optional X coordinate to which the window will be moved
485 @param y An optional Y coordinate to which the window will be moved
487 The x and y coordinates must both be sepcified together, or they will have
488 no effect. When they are specified, the anchor is ignored.
490 void resize(Corner anchor
, int w
, int h
, int x
= INT_MIN
, int y
= INT_MIN
);
492 //! Request the client to close its window.
495 //! Sets the window's stacking layer
497 @param l An integer specifying the layer.<br>
498 '0' - the normal layer<br>
499 '> 0' - the 'above' layer<br>
500 '< 0' - the 'below' layer
502 void setStackLayer(int l
);
504 //! Shades or unshades the client window
506 @param shade true if the window should be shaded; false if it should be
509 void shade(bool shade
);
511 //! Attempt to focus the client window
514 //! Remove focus from the client window
517 virtual void focusHandler(const XFocusChangeEvent
&e
);
518 virtual void unfocusHandler(const XFocusChangeEvent
&e
);
519 virtual void propertyHandler(const XPropertyEvent
&e
);
520 virtual void clientMessageHandler(const XClientMessageEvent
&e
);
521 virtual void configureRequestHandler(const XConfigureRequestEvent
&e
);
522 virtual void unmapHandler(const XUnmapEvent
&e
);
523 virtual void destroyHandler(const XDestroyWindowEvent
&e
);
524 virtual void reparentHandler(const XReparentEvent
&e
);
525 virtual void mapRequestHandler(const XMapRequestEvent
&e
);
527 virtual void shapeHandler(const XShapeEvent
&e
);
533 #endif // __client_hh