1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
11 #include "otk/strut.hh"
12 #include "otk/rect.hh"
16 //! Maintains the state of a client window.
18 OBClient maintains the state of a client window. The state consists of the
19 hints that the application sets on the window, such as the title, or window
22 OBClient also manages client messages for the client window. When the
23 application (or any application) requests something to be changed for the
24 client, it will call the ActionHandler (for client messages) or update the
25 class' member variables and call whatever is nessary to complete the
26 change (such as causing a redraw of the titlebar after the title is changed).
30 //! Possible window types
31 enum WindowType
{ Type_Desktop
, //!< A desktop (bottom-most window)
32 Type_Dock
, //!< A dock bar/panel window
33 Type_Toolbar
, //!< A toolbar window, pulled off an app
34 Type_Menu
, //!< A sticky menu from an app
35 Type_Utility
, //!< A small utility window such as a palette
36 Type_Splash
, //!< A splash screen window
37 Type_Dialog
, //!< A dialog window
38 Type_Normal
//!< A normal application window
41 //! Possible flags for MWM Hints (defined by Motif 2.0)
42 enum MwmFlags
{ MwmFlag_Functions
= 1 << 0, //!< The MMW Hints define funcs
43 MwmFlag_Decorations
= 1 << 1 //!< The MWM Hints define decor
46 //! Possible functions for MWM Hints (defined by Motif 2.0)
47 enum MwmFunctions
{ MwmFunc_All
= 1 << 0, //!< All functions
48 MwmFunc_Resize
= 1 << 1, //!< Allow resizing
49 MwmFunc_Move
= 1 << 2, //!< Allow moving
50 MwmFunc_Iconify
= 1 << 3, //!< Allow to be iconfied
51 MwmFunc_Maximize
= 1 << 4 //!< Allow to be maximized
52 //MwmFunc_Close = 1 << 5 //!< Allow to be closed
55 //! Possible decorations for MWM Hints (defined by Motif 2.0)
56 enum MemDecorations
{ MwmDecor_All
= 1 << 0, //!< All decorations
57 MwmDecor_Border
= 1 << 1, //!< Show a border
58 MwmDecor_Handle
= 1 << 2, //!< Show a handle (bottom)
59 MwmDecor_Title
= 1 << 3, //!< Show a titlebar
60 //MwmDecor_Menu = 1 << 4, //!< Show a menu
61 MwmDecor_Iconify
= 1 << 5, //!< Show an iconify button
62 MwmDecor_Maximize
= 1 << 6 //!< Show a maximize button
65 //! The things the user can do to the client window
66 enum Function
{ Func_Resize
= 1 << 0, //!< Allow resizing
67 Func_Move
= 1 << 1, //!< Allow moving
68 Func_Iconify
= 1 << 2, //!< Allow to be iconified
69 Func_Maximize
= 1 << 3, //!< Allow to be maximized
70 Func_Close
= 1 << 4 //!< Allow to be closed
72 //! Holds a bitmask of OBClient::Function values
73 typedef unsigned char FunctionFlags
;
75 //! The decorations the client window wants to be displayed on it
76 enum Decoration
{ Decor_Titlebar
= 1 << 0, //!< Display a titlebar
77 Decor_Handle
= 1 << 1, //!< Display a handle (bottom)
78 Decor_Border
= 1 << 2, //!< Display a border
79 Decor_Iconify
= 1 << 3, //!< Display an iconify button
80 Decor_Maximize
= 1 << 4, //!< Display a maximize button
81 Decor_Close
= 1 << 5 //!< Display a close button
83 //! Holds a bitmask of OBClient::Decoration values
84 typedef unsigned char DecorationFlags
;
86 //! The MWM Hints as retrieved from the window property
88 This structure only contains 3 elements, even though the Motif 2.0
89 structure contains 5. We only use the first 3, so that is all gets defined.
91 typedef struct MwmHints
{
92 //! The number of elements in the OBClient::MwmHints struct
93 static const unsigned int elements
= 3;
94 unsigned long flags
; //!< A bitmask of OBClient::MwmFlags values
95 unsigned long functions
; //!< A bitmask of OBClient::MwmFunctions values
96 unsigned long decorations
;//!< A bitmask of OBClient::MwmDecorations values
99 //! Possible actions that can be made with the _NET_WM_STATE client message
100 enum StateAction
{ State_Remove
= 0, //!< _NET_WM_STATE_REMOVE
101 State_Add
, //!< _NET_WM_STATE_ADD
102 State_Toggle
//!< _NET_WM_STATE_TOGGLE
106 //! The actual window that this class is wrapping up
109 //! The id of the group the window belongs to
112 // XXX: transient_for, transients
114 //! The desktop on which the window resides (0xffffffff for all desktops)
115 unsigned long _desktop
;
117 //! Normal window title
118 std::string _title
; // XXX: Have to keep track if this string is Utf8 or not
119 //! Window title when iconifiged
120 std::string _icon_title
;
122 //! The application that created the window
123 std::string _app_name
;
124 //! The class of the window, can used for grouping
125 std::string _app_class
;
127 //! The type of window (what its function is)
130 //! Position and size of the window (relative to the root window)
133 //! Width of the border on the window.
135 The window manager will set this to 0 while the window is being managed,
136 but needs to restore it afterwards, so it is saved here.
140 //! The minimum width of the client window
142 If the min is > the max, then the window is not resizable
145 //! The minimum height of the client window
147 If the min is > the max, then the window is not resizable
150 //! The maximum width of the client window
152 If the min is > the max, then the window is not resizable
155 //! The maximum height of the client window
157 If the min is > the max, then the window is not resizable
160 //! The size of increments to resize the client window by (for the width)
162 //! The size of increments to resize the client window by (for the height)
164 //! The base width of the client window
166 This value should be subtracted from the window's actual width when
167 displaying its size to the user, or working with its min/max width
170 //! The base height of the client window
172 This value should be subtracted from the window's actual height when
173 displaying its size to the user, or working with its min/max height
177 //! Where to place the decorated window in relation to the undecorated window
180 //! The state of the window, one of WithdrawnState, IconicState, or
184 //! Was the window's position requested by the application? if not, we should
185 //! place the window ourselves when it first appears
188 //! Can the window receive input focus?
192 //! Notify the window when it receives focus?
195 //! The window uses shape extension to be non-rectangular?
198 //! The window is modal, so it must be processed before any windows it is
199 //! related to can be focused
201 //! Only the window's titlebar is displayed
203 //! The window is iconified
205 //! The window is maximized to fill the screen vertically
207 //! The window is maximized to fill the screen horizontally
209 //! The window is a 'fullscreen' window, and should be on top of all others
211 //! The window should be on top of other windows of the same type
214 //! A bitmask of values in the OBClient::Decoration enum
216 The values in the variable are the decorations that the client wants to be
219 DecorationFlags _decorations
;
221 //! A bitmask of values in the OBClient::Function enum
223 The values in the variable specify the ways in which the user is allowed to
226 FunctionFlags _functions
;
228 //! Retrieves the desktop hint's value and sets OBClient::_desktop
230 //! Retrieves the window's type and sets OBClient::_type
232 //! Gets the MWM Hints and adjusts OBClient::_functions and
233 //! OBClient::_decorations
235 //! Gets the position and size of the window and sets OBClient::_area
237 //! Gets the net_state hint and sets the boolean flags for any states set in
240 //! Determines if the window uses the Shape extension and sets
241 //! OBClient::_shaped
244 //! Sets the wm_state to the specified value
245 void setWMState(long state
);
246 //! Sends the window to the specified desktop
247 void setDesktop(long desktop
);
248 //! Adjusts the window's net_state
249 void setState(StateAction action
, long data1
, long data2
);
251 //! Update the protocols that the window supports and adjusts things if they
253 void updateProtocols();
254 //! Updates the WMNormalHints and adjusts things if they change
255 void updateNormalHints();
256 //! Updates the WMHints and adjusts things if they change
257 void updateWMHints();
258 //! Updates the window's title
260 //! Updates the window's icon title
261 void updateIconTitle();
262 //! Updates the window's application name and class
264 // XXX: updateTransientFor();
267 OBClient(Window window
);
270 inline Window
window() const { return _window
; }
272 inline WindowType
type() const { return _type
; }
273 inline unsigned long desktop() const { return _desktop
; }
274 inline const std::string
&title() const { return _title
; }
275 inline const std::string
&iconTitle() const { return _title
; }
276 inline const std::string
&appName() const { return _app_name
; }
277 inline const std::string
&appClass() const { return _app_class
; }
278 inline bool canFocus() const { return _can_focus
; }
279 inline bool urgent() const { return _urgent
; }
280 inline bool focusNotify() const { return _focus_notify
; }
281 inline bool shaped() const { return _shaped
; }
282 inline int gravity() const { return _gravity
; }
283 inline bool positionRequested() const { return _positioned
; }
284 inline DecorationFlags
decorations() const { return _decorations
; }
285 inline FunctionFlags
funtions() const { return _functions
; }
288 inline bool modal() const { return _modal
; }
289 inline bool shaded() const { return _shaded
; }
290 inline bool iconic() const { return _iconic
; }
291 inline bool maxVert() const { return _max_vert
; }
292 inline bool maxHorz() const { return _max_horz
; }
293 inline bool fullscreen() const { return _fullscreen
; }
294 inline bool floating() const { return _floating
; }
296 inline int borderWidth() const { return _border_width
; }
297 inline int minX() const { return _min_x
; }
298 inline int minY() const { return _min_y
; }
299 inline int maxX() const { return _max_x
; }
300 inline int maxY() const { return _max_y
; }
301 inline int incrementX() const { return _inc_x
; }
302 inline int incrementY() const { return _inc_y
; }
303 inline int baseX() const { return _base_x
; }
304 inline int baseY() const { return _base_y
; }
306 inline const otk::Rect
&area() const { return _area
; }
308 void update(const XPropertyEvent
&e
);
309 void update(const XClientMessageEvent
&e
);
311 void setArea(const otk::Rect
&area
);
316 #endif // __client_hh