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>
22 #include "otk/point.hh"
23 #include "otk/strut.hh"
24 #include "otk/rect.hh"
25 #include "otk/eventhandler.hh"
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
45 //! Maintains the state of a client window.
47 OBClient maintains the state of a client window. The state consists of the
48 hints that the application sets on the window, such as the title, or window
51 OBClient also manages client messages for the client window. When the
52 application (or any application) requests something to be changed for the
53 client, it will call the ActionHandler (for client messages) or update the
54 class' member variables and call whatever is nessary to complete the
55 change (such as causing a redraw of the titlebar after the title is changed).
57 class OBClient
: public otk::OtkEventHandler
, public OBWidget
{
60 //! The frame window which decorates around the client window
62 NOTE: This should NEVER be used inside the client class's constructor!
66 //! Corners of the client window, used for anchor positions
67 enum Corner
{ TopLeft
,
72 //! Possible window types
73 enum WindowType
{ Type_Desktop
, //!< A desktop (bottom-most window)
74 Type_Dock
, //!< A dock bar/panel window
75 Type_Toolbar
, //!< A toolbar window, pulled off an app
76 Type_Menu
, //!< A sticky menu from an app
77 Type_Utility
, //!< A small utility window such as a palette
78 Type_Splash
, //!< A splash screen window
79 Type_Dialog
, //!< A dialog window
80 Type_Normal
//!< A normal application window
83 //! Possible flags for MWM Hints (defined by Motif 2.0)
84 enum MwmFlags
{ MwmFlag_Functions
= 1 << 0, //!< The MMW Hints define funcs
85 MwmFlag_Decorations
= 1 << 1 //!< The MWM Hints define decor
88 //! Possible functions for MWM Hints (defined by Motif 2.0)
89 enum MwmFunctions
{ MwmFunc_All
= 1 << 0, //!< All functions
90 MwmFunc_Resize
= 1 << 1, //!< Allow resizing
91 MwmFunc_Move
= 1 << 2, //!< Allow moving
92 MwmFunc_Iconify
= 1 << 3, //!< Allow to be iconfied
93 MwmFunc_Maximize
= 1 << 4 //!< Allow to be maximized
94 //MwmFunc_Close = 1 << 5 //!< Allow to be closed
97 //! Possible decorations for MWM Hints (defined by Motif 2.0)
98 enum MemDecorations
{ MwmDecor_All
= 1 << 0, //!< All decorations
99 MwmDecor_Border
= 1 << 1, //!< Show a border
100 MwmDecor_Handle
= 1 << 2, //!< Show a handle (bottom)
101 MwmDecor_Title
= 1 << 3, //!< Show a titlebar
102 //MwmDecor_Menu = 1 << 4, //!< Show a menu
103 MwmDecor_Iconify
= 1 << 5, //!< Show an iconify button
104 MwmDecor_Maximize
= 1 << 6 //!< Show a maximize button
107 //! The things the user can do to the client window
108 enum Function
{ Func_Resize
= 1 << 0, //!< Allow resizing
109 Func_Move
= 1 << 1, //!< Allow moving
110 Func_Iconify
= 1 << 2, //!< Allow to be iconified
111 Func_Maximize
= 1 << 3, //!< Allow to be maximized
112 Func_Close
= 1 << 4 //!< Allow to be closed
114 //! Holds a bitmask of OBClient::Function values
115 typedef unsigned char FunctionFlags
;
117 //! The decorations the client window wants to be displayed on it
118 enum Decoration
{ Decor_Titlebar
= 1 << 0, //!< Display a titlebar
119 Decor_Handle
= 1 << 1, //!< Display a handle (bottom)
120 Decor_Border
= 1 << 2, //!< Display a border
121 Decor_Iconify
= 1 << 3, //!< Display an iconify button
122 Decor_Maximize
= 1 << 4, //!< Display a maximize button
123 Decor_Sticky
= 1 << 5, //!< Display a sticky button
124 Decor_Close
= 1 << 6 //!< Display a close button
126 //! Holds a bitmask of OBClient::Decoration values
127 typedef unsigned char DecorationFlags
;
129 //! Possible actions that can be made with the _NET_WM_STATE client message
130 enum StateAction
{ State_Remove
= 0, //!< _NET_WM_STATE_REMOVE
131 State_Add
, //!< _NET_WM_STATE_ADD
132 State_Toggle
//!< _NET_WM_STATE_TOGGLE
135 //! The event mask to grab on client windows
136 static const long event_mask
= PropertyChangeMask
| FocusChangeMask
|
139 //! The mask of events to not let propogate past the client
141 This makes things like xprop work on the client window, but means we have
142 to explicitly grab clicks that we want.
144 static const long no_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
|
147 //! The number of unmap events to ignore on the window
151 //! The screen number on which the client resides
154 //! The actual window that this class is wrapping up
157 //! The id of the group the window belongs to
160 // XXX: transient_for, transients
162 //! The desktop on which the window resides (0xffffffff for all desktops)
163 unsigned long _desktop
;
165 //! Normal window title
166 std::string _title
; // XXX: Have to keep track if this string is Utf8 or not
167 //! Window title when iconifiged
168 std::string _icon_title
;
170 //! The application that created the window
171 std::string _app_name
;
172 //! The class of the window, can used for grouping
173 std::string _app_class
;
175 //! The type of window (what its function is)
178 //! Position and size of the window
180 This will not always be the actual position of the window on screen, it is
181 rather, the position requested by the client, to which the window's gravity
186 //! The logical size of the window
188 The "logical" size of the window is refers to the user's perception of the
189 size of the window, and is the value that should be displayed to the user.
190 For example, with xterms, this value it the number of characters being
191 displayed in the terminal, instead of the number of pixels.
193 otk::Point _logical_size
;
195 //! Width of the border on the window.
197 The window manager will set this to 0 while the window is being managed,
198 but needs to restore it afterwards, so it is saved here.
202 //! The minimum size of the client window
204 If the min is > the max, then the window is not resizable
206 otk::Point _min_size
;
207 //! The maximum size of the client window
209 If the min is > the max, then the window is not resizable
211 otk::Point _max_size
;
212 //! The size of increments to resize the client window by
213 otk::Point _size_inc
;
214 //! The base size of the client window
216 This value should be subtracted from the window's actual size when
217 displaying its size to the user, or working with its min/max size
219 otk::Point _base_size
;
221 //! Where to place the decorated window in relation to the undecorated window
224 //! The state of the window, one of WithdrawnState, IconicState, or
228 //! Was the window's position requested by the application? if not, we should
229 //! place the window ourselves when it first appears
232 //! Can the window receive input focus?
236 //! Notify the window when it receives focus?
238 //! Does the client window have the input focus?
241 //! The window uses shape extension to be non-rectangular?
244 //! The window is modal, so it must be processed before any windows it is
245 //! related to can be focused
247 //! Only the window's titlebar is displayed
249 //! The window is iconified
251 //! The window is maximized to fill the screen vertically
253 //! The window is maximized to fill the screen horizontally
255 //! The window should not be displayed by pagers
257 //! The window should not be displayed by taskbars
259 //! The window is a 'fullscreen' window, and should be on top of all others
261 //! The window should be on top of other windows of the same type
263 //! The window should be underneath other windows of the same type
266 OBScreen::StackLayer _layer
;
268 //! A bitmask of values in the OBClient::Decoration enum
270 The values in the variable are the decorations that the client wants to be
273 DecorationFlags _decorations
;
275 //! A bitmask of values in the OBClient::Function enum
277 The values in the variable specify the ways in which the user is allowed to
280 FunctionFlags _functions
;
282 //! Retrieves the desktop hint's value and sets OBClient::_desktop
284 //! Retrieves the window's type and sets OBClient::_type
286 //! Gets the MWM Hints and adjusts OBClient::_functions and
287 //! OBClient::_decorations
289 //! Gets the position and size of the window and sets OBClient::_area
291 //! Gets the net_state hint and sets the boolean flags for any states set in
294 //! Determines if the window uses the Shape extension and sets
295 //! OBClient::_shaped
298 //! Sets the wm_state to the specified value
299 void setWMState(long state
);
300 //! Sends the window to the specified desktop
301 void setDesktop(long desktop
);
302 //! Adjusts the window's net_state
303 void setState(StateAction action
, long data1
, long data2
);
305 //! Calculates the stacking layer for the client window
308 //! Update the protocols that the window supports and adjusts things if they
310 void updateProtocols();
311 //! Updates the WMNormalHints and adjusts things if they change
312 void updateNormalHints();
313 //! Updates the WMHints and adjusts things if they change
314 void updateWMHints();
315 //! Updates the window's title
317 //! Updates the window's icon title
318 void updateIconTitle();
319 //! Updates the window's application name and class
321 // XXX: updateTransientFor();
323 //! Change the client's state hints to match the class' data
328 //! Constructs a new OBClient object around a specified window id
330 @param window The window id that the OBClient class should handle
331 @param screen The screen on which the window resides
333 OBClient(int screen
, Window window
);
334 //! Destroys the OBClient object
338 //! Returns the screen on which the clien resides
339 inline int screen() const { return _screen
; }
341 //! Returns the window id that the OBClient object is handling
342 inline Window
window() const { return _window
; }
344 //! Returns the type of the window, one of the OBClient::WindowType values
345 inline WindowType
type() const { return _type
; }
346 //! Returns the desktop on which the window resides
348 This value is a 0-based index.<br>
349 A value of 0xffffffff indicates that the window exists on all desktops.
351 inline unsigned long desktop() const { return _desktop
; }
352 //! Returns the window's title
353 inline const std::string
&title() const { return _title
; }
354 //! Returns the window's title when it is iconified
355 inline const std::string
&iconTitle() const { return _title
; }
356 //! Returns the application's name to whom the window belongs
357 inline const std::string
&appName() const { return _app_name
; }
358 //! Returns the class of the window
359 inline const std::string
&appClass() const { return _app_class
; }
360 //! Returns if the window can be focused
362 @return true if the window can receive focusl otherwise, false
364 inline bool canFocus() const { return _can_focus
; }
365 //! Returns if the window has indicated that it needs urgent attention
366 inline bool urgent() const { return _urgent
; }
367 //! Returns if the window wants to be notified when it receives focus
368 inline bool focusNotify() const { return _focus_notify
; }
369 //! Returns if the window uses the Shape extension
370 inline bool shaped() const { return _shaped
; }
371 //! Returns the window's gravity
373 This value determines where to place the decorated window in relation to
374 its position without decorations.<br>
375 One of: NorthWestGravity, SouthWestGravity, EastGravity, ...,
376 SouthGravity, StaticGravity, ForgetGravity
378 inline int gravity() const { return _gravity
; }
379 //! Returns if the application requested the initial position for the window
381 If the application did not request a position (this function returns false)
382 then the window should be placed intelligently by the window manager
385 inline bool positionRequested() const { return _positioned
; }
386 //! Returns the decorations that the client window wishes to be displayed on
388 inline DecorationFlags
decorations() const { return _decorations
; }
389 //! Returns the functions that the user can perform on the window
390 inline FunctionFlags
funtions() const { return _functions
; }
392 //! Returns if the window is modal
394 If the window is modal, then no other windows that it is related to can get
395 focus while it exists/remains modal.
397 inline bool modal() const { return _modal
; }
398 //! Returns if the window is shaded
400 When the window is shaded, only its titlebar is visible, the client itself
403 inline bool shaded() const { return _shaded
; }
404 //! Returns if the window is iconified
406 When the window is iconified, it is not visible at all (except in iconbars/
407 panels/etc that want to show lists of iconified windows
409 inline bool iconic() const { return _iconic
; }
410 //! Returns if the window is maximized vertically
411 inline bool maxVert() const { return _max_vert
; }
412 //! Returns if the window is maximized horizontally
413 inline bool maxHorz() const { return _max_horz
; }
414 //! Returns the window's stacking layer
415 inline OBScreen::StackLayer
layer() const { return _layer
; }
417 //! Removes or reapplies the client's border to its window
419 Used when managing and unmanaging a window.
420 @param addborder true if adding the border to the client; false if removing
423 void toggleClientBorder(bool addborder
);
425 //! Returns the position and size of the client relative to the root window
426 inline const otk::Rect
&area() const { return _area
; }
428 //! Move the client window
429 void move(int x
, int y
);
431 //! Resizes the client window, anchoring it in a given corner
433 This also maintains things like the client's minsize, and size increments.
434 @param anchor The corner to keep in the same position when resizing
435 @param x The X component of the new size for the client
436 @param y The Y component of the new size for the client
438 void resize(Corner anchor
, int x
, int y
);
440 //! Request the client to close its window.
443 //! Shades or unshades the client window
445 @param shade true if the window should be shaded; false if it should be
448 void shade(bool shade
);
450 //! Attempt to focus the client window
453 //! Remove focus from the client window
456 virtual void focusHandler(const XFocusChangeEvent
&e
);
457 virtual void unfocusHandler(const XFocusChangeEvent
&e
);
458 virtual void propertyHandler(const XPropertyEvent
&e
);
459 virtual void clientMessageHandler(const XClientMessageEvent
&e
);
460 virtual void shapeHandler(const XShapeEvent
&e
);
461 virtual void configureRequestHandler(const XConfigureRequestEvent
&e
);
462 virtual void unmapHandler(const XUnmapEvent
&e
);
463 virtual void destroyHandler(const XDestroyWindowEvent
&e
);
464 virtual void reparentHandler(const XReparentEvent
&e
);
469 #endif // __client_hh