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
14 #include <X11/extensions/shape.h>
20 #include "otk/strut.hh"
21 #include "otk/rect.hh"
22 #include "otk/eventhandler.hh"
28 //! Maintains the state of a client window.
30 OBClient maintains the state of a client window. The state consists of the
31 hints that the application sets on the window, such as the title, or window
34 OBClient also manages client messages for the client window. When the
35 application (or any application) requests something to be changed for the
36 client, it will call the ActionHandler (for client messages) or update the
37 class' member variables and call whatever is nessary to complete the
38 change (such as causing a redraw of the titlebar after the title is changed).
40 class OBClient
: public otk::OtkEventHandler
{
43 //! The frame window which decorates around the client window
46 //! Possible window types
47 enum WindowType
{ Type_Desktop
, //!< A desktop (bottom-most window)
48 Type_Dock
, //!< A dock bar/panel window
49 Type_Toolbar
, //!< A toolbar window, pulled off an app
50 Type_Menu
, //!< A sticky menu from an app
51 Type_Utility
, //!< A small utility window such as a palette
52 Type_Splash
, //!< A splash screen window
53 Type_Dialog
, //!< A dialog window
54 Type_Normal
//!< A normal application window
57 //! Possible flags for MWM Hints (defined by Motif 2.0)
58 enum MwmFlags
{ MwmFlag_Functions
= 1 << 0, //!< The MMW Hints define funcs
59 MwmFlag_Decorations
= 1 << 1 //!< The MWM Hints define decor
62 //! Possible functions for MWM Hints (defined by Motif 2.0)
63 enum MwmFunctions
{ MwmFunc_All
= 1 << 0, //!< All functions
64 MwmFunc_Resize
= 1 << 1, //!< Allow resizing
65 MwmFunc_Move
= 1 << 2, //!< Allow moving
66 MwmFunc_Iconify
= 1 << 3, //!< Allow to be iconfied
67 MwmFunc_Maximize
= 1 << 4 //!< Allow to be maximized
68 //MwmFunc_Close = 1 << 5 //!< Allow to be closed
71 //! Possible decorations for MWM Hints (defined by Motif 2.0)
72 enum MemDecorations
{ MwmDecor_All
= 1 << 0, //!< All decorations
73 MwmDecor_Border
= 1 << 1, //!< Show a border
74 MwmDecor_Handle
= 1 << 2, //!< Show a handle (bottom)
75 MwmDecor_Title
= 1 << 3, //!< Show a titlebar
76 //MwmDecor_Menu = 1 << 4, //!< Show a menu
77 MwmDecor_Iconify
= 1 << 5, //!< Show an iconify button
78 MwmDecor_Maximize
= 1 << 6 //!< Show a maximize button
81 //! The things the user can do to the client window
82 enum Function
{ Func_Resize
= 1 << 0, //!< Allow resizing
83 Func_Move
= 1 << 1, //!< Allow moving
84 Func_Iconify
= 1 << 2, //!< Allow to be iconified
85 Func_Maximize
= 1 << 3, //!< Allow to be maximized
86 Func_Close
= 1 << 4 //!< Allow to be closed
88 //! Holds a bitmask of OBClient::Function values
89 typedef unsigned char FunctionFlags
;
91 //! The decorations the client window wants to be displayed on it
92 enum Decoration
{ Decor_Titlebar
= 1 << 0, //!< Display a titlebar
93 Decor_Handle
= 1 << 1, //!< Display a handle (bottom)
94 Decor_Border
= 1 << 2, //!< Display a border
95 Decor_Iconify
= 1 << 3, //!< Display an iconify button
96 Decor_Maximize
= 1 << 4, //!< Display a maximize button
97 Decor_Sticky
= 1 << 5, //!< Display a sticky button
98 Decor_Close
= 1 << 6 //!< Display a close button
100 //! Holds a bitmask of OBClient::Decoration values
101 typedef unsigned char DecorationFlags
;
103 //! The MWM Hints as retrieved from the window property
105 This structure only contains 3 elements, even though the Motif 2.0
106 structure contains 5. We only use the first 3, so that is all gets defined.
108 typedef struct MwmHints
{
109 //! The number of elements in the OBClient::MwmHints struct
110 static const unsigned int elements
= 3;
111 unsigned long flags
; //!< A bitmask of OBClient::MwmFlags values
112 unsigned long functions
; //!< A bitmask of OBClient::MwmFunctions values
113 unsigned long decorations
;//!< A bitmask of OBClient::MwmDecorations values
116 //! Possible actions that can be made with the _NET_WM_STATE client message
117 enum StateAction
{ State_Remove
= 0, //!< _NET_WM_STATE_REMOVE
118 State_Add
, //!< _NET_WM_STATE_ADD
119 State_Toggle
//!< _NET_WM_STATE_TOGGLE
122 //! The event mask to grab on client windows
123 static const long event_mask
= PropertyChangeMask
| FocusChangeMask
;
125 //! The number of unmap events to ignore on the window
129 //! The screen number on which the client resides
132 //! The actual window that this class is wrapping up
135 //! The id of the group the window belongs to
138 // XXX: transient_for, transients
140 //! The desktop on which the window resides (0xffffffff for all desktops)
141 unsigned long _desktop
;
143 //! Normal window title
144 std::string _title
; // XXX: Have to keep track if this string is Utf8 or not
145 //! Window title when iconifiged
146 std::string _icon_title
;
148 //! The application that created the window
149 std::string _app_name
;
150 //! The class of the window, can used for grouping
151 std::string _app_class
;
153 //! The type of window (what its function is)
156 //! Position and size of the window (relative to the root window)
159 //! Width of the border on the window.
161 The window manager will set this to 0 while the window is being managed,
162 but needs to restore it afterwards, so it is saved here.
166 //! The minimum width of the client window
168 If the min is > the max, then the window is not resizable
171 //! The minimum height of the client window
173 If the min is > the max, then the window is not resizable
176 //! The maximum width of the client window
178 If the min is > the max, then the window is not resizable
181 //! The maximum height of the client window
183 If the min is > the max, then the window is not resizable
186 //! The size of increments to resize the client window by (for the width)
188 //! The size of increments to resize the client window by (for the height)
190 //! The base width of the client window
192 This value should be subtracted from the window's actual width when
193 displaying its size to the user, or working with its min/max width
196 //! The base height of the client window
198 This value should be subtracted from the window's actual height when
199 displaying its size to the user, or working with its min/max height
203 //! Where to place the decorated window in relation to the undecorated window
206 //! The state of the window, one of WithdrawnState, IconicState, or
210 //! Was the window's position requested by the application? if not, we should
211 //! place the window ourselves when it first appears
214 //! Can the window receive input focus?
218 //! Notify the window when it receives focus?
221 //! The window uses shape extension to be non-rectangular?
224 //! The window is modal, so it must be processed before any windows it is
225 //! related to can be focused
227 //! Only the window's titlebar is displayed
229 //! The window is iconified
231 //! The window is maximized to fill the screen vertically
233 //! The window is maximized to fill the screen horizontally
235 //! The window is a 'fullscreen' window, and should be on top of all others
237 //! The window should be on top of other windows of the same type
240 //! A bitmask of values in the OBClient::Decoration enum
242 The values in the variable are the decorations that the client wants to be
245 DecorationFlags _decorations
;
247 //! A bitmask of values in the OBClient::Function enum
249 The values in the variable specify the ways in which the user is allowed to
252 FunctionFlags _functions
;
254 //! Retrieves the desktop hint's value and sets OBClient::_desktop
256 //! Retrieves the window's type and sets OBClient::_type
258 //! Gets the MWM Hints and adjusts OBClient::_functions and
259 //! OBClient::_decorations
261 //! Gets the position and size of the window and sets OBClient::_area
263 //! Gets the net_state hint and sets the boolean flags for any states set in
266 //! Determines if the window uses the Shape extension and sets
267 //! OBClient::_shaped
270 //! Sets the wm_state to the specified value
271 void setWMState(long state
);
272 //! Sends the window to the specified desktop
273 void setDesktop(long desktop
);
274 //! Adjusts the window's net_state
275 void setState(StateAction action
, long data1
, long data2
);
277 //! Update the protocols that the window supports and adjusts things if they
279 void updateProtocols();
280 //! Updates the WMNormalHints and adjusts things if they change
281 void updateNormalHints();
282 //! Updates the WMHints and adjusts things if they change
283 void updateWMHints();
284 //! Updates the window's title
286 //! Updates the window's icon title
287 void updateIconTitle();
288 //! Updates the window's application name and class
290 // XXX: updateTransientFor();
293 //! Constructs a new OBClient object around a specified window id
295 @param window The window id that the OBClient class should handle
296 @param screen The screen on which the window resides
298 OBClient(int screen
, Window window
);
299 //! Destroys the OBClient object
302 //! Returns the screen on which the clien resides
303 inline int screen() const { return _screen
; }
305 //! Returns the window id that the OBClient object is handling
306 inline Window
window() const { return _window
; }
308 //! Returns the type of the window, one of the OBClient::WindowType values
309 inline WindowType
type() const { return _type
; }
310 //! Returns the desktop on which the window resides
312 This value is a 0-based index.<br>
313 A value of 0xffffffff indicates that the window exists on all desktops.
315 inline unsigned long desktop() const { return _desktop
; }
316 //! Returns the window's title
317 inline const std::string
&title() const { return _title
; }
318 //! Returns the window's title when it is iconified
319 inline const std::string
&iconTitle() const { return _title
; }
320 //! Returns the application's name to whom the window belongs
321 inline const std::string
&appName() const { return _app_name
; }
322 //! Returns the class of the window
323 inline const std::string
&appClass() const { return _app_class
; }
324 //! Returns if the window can be focused
326 @return true if the window can receive focusl otherwise, false
328 inline bool canFocus() const { return _can_focus
; }
329 //! Returns if the window has indicated that it needs urgent attention
330 inline bool urgent() const { return _urgent
; }
331 //! Returns if the window wants to be notified when it receives focus
332 inline bool focusNotify() const { return _focus_notify
; }
333 //! Returns if the window uses the Shape extension
334 inline bool shaped() const { return _shaped
; }
335 //! Returns the window's gravity
337 This value determines where to place the decorated window in relation to
338 its position without decorations.<br>
339 One of: NorthWestGravity, SouthWestGravity, EastGravity, ...,
340 SouthGravity, StaticGravity, ForgetGravity
342 inline int gravity() const { return _gravity
; }
343 //! Returns if the application requested the initial position for the window
345 If the application did not request a position (this function returns false)
346 then the window should be placed intelligently by the window manager
349 inline bool positionRequested() const { return _positioned
; }
350 //! Returns the decorations that the client window wishes to be displayed on
352 inline DecorationFlags
decorations() const { return _decorations
; }
353 //! Returns the functions that the user can perform on the window
354 inline FunctionFlags
funtions() const { return _functions
; }
356 //! Returns if the window is modal
358 If the window is modal, then no other windows that it is related to can get
359 focus while it exists/remains modal.
361 inline bool modal() const { return _modal
; }
362 //! Returns if the window is shaded
364 When the window is shaded, only its titlebar is visible, the client itself
367 inline bool shaded() const { return _shaded
; }
368 //! Returns if the window is iconified
370 When the window is iconified, it is not visible at all (except in iconbars/
371 panels/etc that want to show lists of iconified windows
373 inline bool iconic() const { return _iconic
; }
374 //! Returns if the window is maximized vertically
375 inline bool maxVert() const { return _max_vert
; }
376 //! Returns if the window is maximized horizontally
377 inline bool maxHorz() const { return _max_horz
; }
378 //! Returns if the window is fullscreen
380 When the window is fullscreen, it is kept above all others
382 inline bool fullscreen() const { return _fullscreen
; }
383 //! Returns if the window is floating
385 When the window is floating, it is kept above all others in the same
388 inline bool floating() const { return _floating
; }
390 //! Returns the window's border width
392 The border width is set to 0 when the client becomes managed, but the
393 border width is stored here so that it can be restored to the client window
394 when it is unmanaged later.
396 inline int borderWidth() const { return _border_width
; }
397 //! Returns the minimum width of the client window
399 If the min is > the max, then the window is not resizable
401 inline int minX() const { return _min_x
; }
402 //! Returns the minimum height of the client window
404 If the min is > the max, then the window is not resizable
406 inline int minY() const { return _min_y
; }
407 //! Returns the maximum width of the client window
409 If the min is > the max, then the window is not resizable
411 inline int maxX() const { return _max_x
; }
412 //! Returns the maximum height of the client window
414 If the min is > the max, then the window is not resizable
416 inline int maxY() const { return _max_y
; }
417 //! Returns the increment size for resizing the window (for the width)
418 inline int incrementX() const { return _inc_x
; }
419 //! Returns the increment size for resizing the window (for the height)
420 inline int incrementY() const { return _inc_y
; }
421 //! Returns the base width of the window
423 This value should be subtracted from the window's actual width when
424 displaying its size to the user, or working with its min/max width
426 inline int baseX() const { return _base_x
; }
427 //! Returns the base height of the window
429 This value should be subtracted from the window's actual height when
430 displaying its size to the user, or working with its min/max height
432 inline int baseY() const { return _base_y
; }
434 //! Returns the position and size of the client relative to the root window
435 inline const otk::Rect
&area() const { return _area
; }
437 virtual void propertyHandler(const XPropertyEvent
&e
);
439 virtual void clientMessageHandler(const XClientMessageEvent
&e
);
441 virtual void shapeHandler(const XShapeEvent
&e
);
443 //! Changes the stored positions and size of the OBClient window
445 This does not actually change the physical geometry, that needs to be done
446 before/after setting this value to keep it in sync
448 void setArea(const otk::Rect
&area
);
453 #endif // __client_hh