]> Dogcows Code - chaz/openbox/blob - src/client.hh
manages windows that exist before running.
[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 OBClient class maintains the state of a client window by handling
7 property changes on the window and some client messages
8 */
9
10 extern "C" {
11 #include <X11/Xlib.h>
12
13 #ifdef SHAPE
14 #include <X11/extensions/shape.h>
15 #endif // SHAPE
16 }
17
18 #include <string>
19
20 #include "otk/strut.hh"
21 #include "otk/rect.hh"
22
23 namespace ob {
24
25 class OBFrame;
26
27 //! Maintains the state of a client window.
28 /*!
29 OBClient maintains the state of a client window. The state consists of the
30 hints that the application sets on the window, such as the title, or window
31 gravity.
32 <p>
33 OBClient also manages client messages for the client window. When the
34 application (or any application) requests something to be changed for the
35 client, it will call the ActionHandler (for client messages) or update the
36 class' member variables and call whatever is nessary to complete the
37 change (such as causing a redraw of the titlebar after the title is changed).
38 */
39 class OBClient {
40 public:
41
42 //! The frame window which decorates around the client window
43 OBFrame *frame;
44
45 //! Possible window types
46 enum WindowType { Type_Desktop, //!< A desktop (bottom-most window)
47 Type_Dock, //!< A dock bar/panel window
48 Type_Toolbar, //!< A toolbar window, pulled off an app
49 Type_Menu, //!< A sticky menu from an app
50 Type_Utility, //!< A small utility window such as a palette
51 Type_Splash, //!< A splash screen window
52 Type_Dialog, //!< A dialog window
53 Type_Normal //!< A normal application window
54 };
55
56 //! Possible flags for MWM Hints (defined by Motif 2.0)
57 enum MwmFlags { MwmFlag_Functions = 1 << 0, //!< The MMW Hints define funcs
58 MwmFlag_Decorations = 1 << 1 //!< The MWM Hints define decor
59 };
60
61 //! Possible functions for MWM Hints (defined by Motif 2.0)
62 enum MwmFunctions { MwmFunc_All = 1 << 0, //!< All functions
63 MwmFunc_Resize = 1 << 1, //!< Allow resizing
64 MwmFunc_Move = 1 << 2, //!< Allow moving
65 MwmFunc_Iconify = 1 << 3, //!< Allow to be iconfied
66 MwmFunc_Maximize = 1 << 4 //!< Allow to be maximized
67 //MwmFunc_Close = 1 << 5 //!< Allow to be closed
68 };
69
70 //! Possible decorations for MWM Hints (defined by Motif 2.0)
71 enum MemDecorations { MwmDecor_All = 1 << 0, //!< All decorations
72 MwmDecor_Border = 1 << 1, //!< Show a border
73 MwmDecor_Handle = 1 << 2, //!< Show a handle (bottom)
74 MwmDecor_Title = 1 << 3, //!< Show a titlebar
75 //MwmDecor_Menu = 1 << 4, //!< Show a menu
76 MwmDecor_Iconify = 1 << 5, //!< Show an iconify button
77 MwmDecor_Maximize = 1 << 6 //!< Show a maximize button
78 };
79
80 //! The things the user can do to the client window
81 enum Function { Func_Resize = 1 << 0, //!< Allow resizing
82 Func_Move = 1 << 1, //!< Allow moving
83 Func_Iconify = 1 << 2, //!< Allow to be iconified
84 Func_Maximize = 1 << 3, //!< Allow to be maximized
85 Func_Close = 1 << 4 //!< Allow to be closed
86 };
87 //! Holds a bitmask of OBClient::Function values
88 typedef unsigned char FunctionFlags;
89
90 //! The decorations the client window wants to be displayed on it
91 enum Decoration { Decor_Titlebar = 1 << 0, //!< Display a titlebar
92 Decor_Handle = 1 << 1, //!< Display a handle (bottom)
93 Decor_Border = 1 << 2, //!< Display a border
94 Decor_Iconify = 1 << 3, //!< Display an iconify button
95 Decor_Maximize = 1 << 4, //!< Display a maximize button
96 Decor_Sticky = 1 << 5, //!< Display a sticky button
97 Decor_Close = 1 << 6 //!< Display a close button
98 };
99 //! Holds a bitmask of OBClient::Decoration values
100 typedef unsigned char DecorationFlags;
101
102 //! The MWM Hints as retrieved from the window property
103 /*!
104 This structure only contains 3 elements, even though the Motif 2.0
105 structure contains 5. We only use the first 3, so that is all gets defined.
106 */
107 typedef struct MwmHints {
108 //! The number of elements in the OBClient::MwmHints struct
109 static const unsigned int elements = 3;
110 unsigned long flags; //!< A bitmask of OBClient::MwmFlags values
111 unsigned long functions; //!< A bitmask of OBClient::MwmFunctions values
112 unsigned long decorations;//!< A bitmask of OBClient::MwmDecorations values
113 };
114
115 //! Possible actions that can be made with the _NET_WM_STATE client message
116 enum StateAction { State_Remove = 0, //!< _NET_WM_STATE_REMOVE
117 State_Add, //!< _NET_WM_STATE_ADD
118 State_Toggle //!< _NET_WM_STATE_TOGGLE
119 };
120
121 //! The event mask to grab on client windows
122 static const long event_mask = PropertyChangeMask | FocusChangeMask;
123
124 //! The number of unmap events to ignore on the window
125 int ignore_unmaps;
126
127 private:
128 //! The screen number on which the client resides
129 int _screen;
130
131 //! The actual window that this class is wrapping up
132 Window _window;
133
134 //! The id of the group the window belongs to
135 Window _group;
136
137 // XXX: transient_for, transients
138
139 //! The desktop on which the window resides (0xffffffff for all desktops)
140 unsigned long _desktop;
141
142 //! Normal window title
143 std::string _title; // XXX: Have to keep track if this string is Utf8 or not
144 //! Window title when iconifiged
145 std::string _icon_title;
146
147 //! The application that created the window
148 std::string _app_name;
149 //! The class of the window, can used for grouping
150 std::string _app_class;
151
152 //! The type of window (what its function is)
153 WindowType _type;
154
155 //! Position and size of the window (relative to the root window)
156 otk::Rect _area;
157
158 //! Width of the border on the window.
159 /*!
160 The window manager will set this to 0 while the window is being managed,
161 but needs to restore it afterwards, so it is saved here.
162 */
163 int _border_width;
164
165 //! The minimum width of the client window
166 /*!
167 If the min is > the max, then the window is not resizable
168 */
169 int _min_x;
170 //! The minimum height of the client window
171 /*!
172 If the min is > the max, then the window is not resizable
173 */
174 int _min_y;
175 //! The maximum width of the client window
176 /*!
177 If the min is > the max, then the window is not resizable
178 */
179 int _max_x;
180 //! The maximum height of the client window
181 /*!
182 If the min is > the max, then the window is not resizable
183 */
184 int _max_y;
185 //! The size of increments to resize the client window by (for the width)
186 int _inc_x;
187 //! The size of increments to resize the client window by (for the height)
188 int _inc_y;
189 //! The base width of the client window
190 /*!
191 This value should be subtracted from the window's actual width when
192 displaying its size to the user, or working with its min/max width
193 */
194 int _base_x;
195 //! The base height of the client window
196 /*!
197 This value should be subtracted from the window's actual height when
198 displaying its size to the user, or working with its min/max height
199 */
200 int _base_y;
201
202 //! Where to place the decorated window in relation to the undecorated window
203 int _gravity;
204
205 //! The state of the window, one of WithdrawnState, IconicState, or
206 //! NormalState
207 long _wmstate;
208
209 //! Was the window's position requested by the application? if not, we should
210 //! place the window ourselves when it first appears
211 bool _positioned;
212
213 //! Can the window receive input focus?
214 bool _can_focus;
215 //! Urgency flag
216 bool _urgent;
217 //! Notify the window when it receives focus?
218 bool _focus_notify;
219
220 //! The window uses shape extension to be non-rectangular?
221 bool _shaped;
222
223 //! The window is modal, so it must be processed before any windows it is
224 //! related to can be focused
225 bool _modal;
226 //! Only the window's titlebar is displayed
227 bool _shaded;
228 //! The window is iconified
229 bool _iconic;
230 //! The window is maximized to fill the screen vertically
231 bool _max_vert;
232 //! The window is maximized to fill the screen horizontally
233 bool _max_horz;
234 //! The window is a 'fullscreen' window, and should be on top of all others
235 bool _fullscreen;
236 //! The window should be on top of other windows of the same type
237 bool _floating;
238
239 //! A bitmask of values in the OBClient::Decoration enum
240 /*!
241 The values in the variable are the decorations that the client wants to be
242 displayed around it.
243 */
244 DecorationFlags _decorations;
245
246 //! A bitmask of values in the OBClient::Function enum
247 /*!
248 The values in the variable specify the ways in which the user is allowed to
249 modify this window.
250 */
251 FunctionFlags _functions;
252
253 //! Retrieves the desktop hint's value and sets OBClient::_desktop
254 void getDesktop();
255 //! Retrieves the window's type and sets OBClient::_type
256 void getType();
257 //! Gets the MWM Hints and adjusts OBClient::_functions and
258 //! OBClient::_decorations
259 void getMwmHints();
260 //! Gets the position and size of the window and sets OBClient::_area
261 void getArea();
262 //! Gets the net_state hint and sets the boolean flags for any states set in
263 //! the hint
264 void getState();
265 //! Determines if the window uses the Shape extension and sets
266 //! OBClient::_shaped
267 void getShaped();
268
269 //! Sets the wm_state to the specified value
270 void setWMState(long state);
271 //! Sends the window to the specified desktop
272 void setDesktop(long desktop);
273 //! Adjusts the window's net_state
274 void setState(StateAction action, long data1, long data2);
275
276 //! Update the protocols that the window supports and adjusts things if they
277 //! change
278 void updateProtocols();
279 //! Updates the WMNormalHints and adjusts things if they change
280 void updateNormalHints();
281 //! Updates the WMHints and adjusts things if they change
282 void updateWMHints();
283 //! Updates the window's title
284 void updateTitle();
285 //! Updates the window's icon title
286 void updateIconTitle();
287 //! Updates the window's application name and class
288 void updateClass();
289 // XXX: updateTransientFor();
290
291 public:
292 //! Constructs a new OBClient object around a specified window id
293 /*!
294 @param window The window id that the OBClient class should handle
295 @param screen The screen on which the window resides
296 */
297 OBClient(int screen, Window window);
298 //! Destroys the OBClient object
299 virtual ~OBClient();
300
301 //! Returns the screen on which the clien resides
302 inline int screen() const { return _screen; }
303
304 //! Returns the window id that the OBClient object is handling
305 inline Window window() const { return _window; }
306
307 //! Returns the type of the window, one of the OBClient::WindowType values
308 inline WindowType type() const { return _type; }
309 //! Returns the desktop on which the window resides
310 /*!
311 This value is a 0-based index.<br>
312 A value of 0xffffffff indicates that the window exists on all desktops.
313 */
314 inline unsigned long desktop() const { return _desktop; }
315 //! Returns the window's title
316 inline const std::string &title() const { return _title; }
317 //! Returns the window's title when it is iconified
318 inline const std::string &iconTitle() const { return _title; }
319 //! Returns the application's name to whom the window belongs
320 inline const std::string &appName() const { return _app_name; }
321 //! Returns the class of the window
322 inline const std::string &appClass() const { return _app_class; }
323 //! Returns if the window can be focused
324 /*!
325 @return true if the window can receive focusl otherwise, false
326 */
327 inline bool canFocus() const { return _can_focus; }
328 //! Returns if the window has indicated that it needs urgent attention
329 inline bool urgent() const { return _urgent; }
330 //! Returns if the window wants to be notified when it receives focus
331 inline bool focusNotify() const { return _focus_notify; }
332 //! Returns if the window uses the Shape extension
333 inline bool shaped() const { return _shaped; }
334 //! Returns the window's gravity
335 /*!
336 This value determines where to place the decorated window in relation to
337 its position without decorations.<br>
338 One of: NorthWestGravity, SouthWestGravity, EastGravity, ...,
339 SouthGravity, StaticGravity, ForgetGravity
340 */
341 inline int gravity() const { return _gravity; }
342 //! Returns if the application requested the initial position for the window
343 /*!
344 If the application did not request a position (this function returns false)
345 then the window should be placed intelligently by the window manager
346 initially
347 */
348 inline bool positionRequested() const { return _positioned; }
349 //! Returns the decorations that the client window wishes to be displayed on
350 //! it
351 inline DecorationFlags decorations() const { return _decorations; }
352 //! Returns the functions that the user can perform on the window
353 inline FunctionFlags funtions() const { return _functions; }
354
355 //! Returns if the window is modal
356 /*!
357 If the window is modal, then no other windows that it is related to can get
358 focus while it exists/remains modal.
359 */
360 inline bool modal() const { return _modal; }
361 //! Returns if the window is shaded
362 /*!
363 When the window is shaded, only its titlebar is visible, the client itself
364 is not mapped
365 */
366 inline bool shaded() const { return _shaded; }
367 //! Returns if the window is iconified
368 /*!
369 When the window is iconified, it is not visible at all (except in iconbars/
370 panels/etc that want to show lists of iconified windows
371 */
372 inline bool iconic() const { return _iconic; }
373 //! Returns if the window is maximized vertically
374 inline bool maxVert() const { return _max_vert; }
375 //! Returns if the window is maximized horizontally
376 inline bool maxHorz() const { return _max_horz; }
377 //! Returns if the window is fullscreen
378 /*!
379 When the window is fullscreen, it is kept above all others
380 */
381 inline bool fullscreen() const { return _fullscreen; }
382 //! Returns if the window is floating
383 /*!
384 When the window is floating, it is kept above all others in the same
385 stacking layer as it
386 */
387 inline bool floating() const { return _floating; }
388
389 //! Returns the window's border width
390 /*!
391 The border width is set to 0 when the client becomes managed, but the
392 border width is stored here so that it can be restored to the client window
393 when it is unmanaged later.
394 */
395 inline int borderWidth() const { return _border_width; }
396 //! Returns the minimum width of the client window
397 /*!
398 If the min is > the max, then the window is not resizable
399 */
400 inline int minX() const { return _min_x; }
401 //! Returns the minimum height of the client window
402 /*!
403 If the min is > the max, then the window is not resizable
404 */
405 inline int minY() const { return _min_y; }
406 //! Returns the maximum width of the client window
407 /*!
408 If the min is > the max, then the window is not resizable
409 */
410 inline int maxX() const { return _max_x; }
411 //! Returns the maximum height of the client window
412 /*!
413 If the min is > the max, then the window is not resizable
414 */
415 inline int maxY() const { return _max_y; }
416 //! Returns the increment size for resizing the window (for the width)
417 inline int incrementX() const { return _inc_x; }
418 //! Returns the increment size for resizing the window (for the height)
419 inline int incrementY() const { return _inc_y; }
420 //! Returns the base width of the window
421 /*!
422 This value should be subtracted from the window's actual width when
423 displaying its size to the user, or working with its min/max width
424 */
425 inline int baseX() const { return _base_x; }
426 //! Returns the base height of the window
427 /*!
428 This value should be subtracted from the window's actual height when
429 displaying its size to the user, or working with its min/max height
430 */
431 inline int baseY() const { return _base_y; }
432
433 //! Returns the position and size of the client relative to the root window
434 inline const otk::Rect &area() const { return _area; }
435
436 //! Updates the OBClient class from a property change XEvent
437 void update(const XPropertyEvent &e);
438 //! Processes a client message XEvent for the window and causes an action
439 //! or whatever was specified to occur
440 void update(const XClientMessageEvent &e);
441 #if defined(SHAPE) || defined(DOXYGEN_IGNORE)
442 //! Updates the client's shape status
443 void update(const XShapeEvent &e);
444 #endif
445
446 //! Changes the stored positions and size of the OBClient window
447 /*!
448 This does not actually change the physical geometry, that needs to be done
449 before/after setting this value to keep it in sync
450 */
451 void setArea(const otk::Rect &area);
452 };
453
454 }
455
456 #endif // __client_hh
This page took 0.05528 seconds and 5 git commands to generate.