]> Dogcows Code - chaz/openbox/blob - src/client.hh
add support for wm_window_role
[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 "screen.hh"
21 #include "widget.hh"
22 #include "otk/point.hh"
23 #include "otk/strut.hh"
24 #include "otk/rect.hh"
25 #include "otk/eventhandler.hh"
26
27 namespace ob {
28
29 class OBFrame;
30
31 //! The MWM Hints as retrieved from the window property
32 /*!
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.
35 */
36 struct MwmHints {
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
42 };
43
44
45 //! Maintains the state of a client window.
46 /*!
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
49 gravity.
50 <p>
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).
56 */
57 class OBClient : public otk::OtkEventHandler, public OBWidget {
58 public:
59
60 //! The frame window which decorates around the client window
61 /*!
62 NOTE: This should NEVER be used inside the client class's constructor!
63 */
64 OBFrame *frame;
65
66 //! Corners of the client window, used for anchor positions
67 enum Corner { TopLeft,
68 TopRight,
69 BottomLeft,
70 BottomRight };
71
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
81 };
82
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
86 };
87
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
95 };
96
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
105 };
106
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
113 };
114 //! Holds a bitmask of OBClient::Function values
115 typedef unsigned char FunctionFlags;
116
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
125 };
126 //! Holds a bitmask of OBClient::Decoration values
127 typedef unsigned char DecorationFlags;
128
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
133 };
134
135 //! The event mask to grab on client windows
136 static const long event_mask = PropertyChangeMask | FocusChangeMask |
137 StructureNotifyMask;
138
139 //! The mask of events to not let propogate past the client
140 /*!
141 This makes things like xprop work on the client window, but means we have
142 to explicitly grab clicks that we want.
143 */
144 static const long no_propagate_mask = ButtonPressMask | ButtonReleaseMask |
145 ButtonMotionMask;
146
147 //! The number of unmap events to ignore on the window
148 int ignore_unmaps;
149
150 private:
151 //! The screen number on which the client resides
152 int _screen;
153
154 //! The actual window that this class is wrapping up
155 Window _window;
156
157 //! The id of the group the window belongs to
158 Window _group;
159
160 // XXX: transient_for, transients
161
162 //! The desktop on which the window resides (0xffffffff for all desktops)
163 unsigned long _desktop;
164
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;
169
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;
174 //! The specified role of the window, used for identification
175 std::string _role;
176
177 //! The type of window (what its function is)
178 WindowType _type;
179
180 //! Position and size of the window
181 /*!
182 This will not always be the actual position of the window on screen, it is
183 rather, the position requested by the client, to which the window's gravity
184 is applied.
185 */
186 otk::Rect _area;
187
188 //! The window's strut
189 /*!
190 The strut defines areas of the screen that are marked off-bounds for window
191 placement. In theory, where this window exists.
192 */
193 otk::Strut _strut;
194
195 //! The logical size of the window
196 /*!
197 The "logical" size of the window is refers to the user's perception of the
198 size of the window, and is the value that should be displayed to the user.
199 For example, with xterms, this value it the number of characters being
200 displayed in the terminal, instead of the number of pixels.
201 */
202 otk::Point _logical_size;
203
204 //! Width of the border on the window.
205 /*!
206 The window manager will set this to 0 while the window is being managed,
207 but needs to restore it afterwards, so it is saved here.
208 */
209 int _border_width;
210
211 //! The minimum size of the client window
212 /*!
213 If the min is > the max, then the window is not resizable
214 */
215 otk::Point _min_size;
216 //! The maximum size of the client window
217 /*!
218 If the min is > the max, then the window is not resizable
219 */
220 otk::Point _max_size;
221 //! The size of increments to resize the client window by
222 otk::Point _size_inc;
223 //! The base size of the client window
224 /*!
225 This value should be subtracted from the window's actual size when
226 displaying its size to the user, or working with its min/max size
227 */
228 otk::Point _base_size;
229
230 //! Where to place the decorated window in relation to the undecorated window
231 int _gravity;
232
233 //! The state of the window, one of WithdrawnState, IconicState, or
234 //! NormalState
235 long _wmstate;
236
237 //! Was the window's position requested by the application? if not, we should
238 //! place the window ourselves when it first appears
239 bool _positioned;
240
241 //! Can the window receive input focus?
242 bool _can_focus;
243 //! Urgency flag
244 bool _urgent;
245 //! Notify the window when it receives focus?
246 bool _focus_notify;
247 //! Does the client window have the input focus?
248 bool _focused;
249
250 //! The window uses shape extension to be non-rectangular?
251 bool _shaped;
252
253 //! The window is modal, so it must be processed before any windows it is
254 //! related to can be focused
255 bool _modal;
256 //! Only the window's titlebar is displayed
257 bool _shaded;
258 //! The window is iconified
259 bool _iconic;
260 //! The window is maximized to fill the screen vertically
261 bool _max_vert;
262 //! The window is maximized to fill the screen horizontally
263 bool _max_horz;
264 //! The window should not be displayed by pagers
265 bool _skip_pager;
266 //! The window should not be displayed by taskbars
267 bool _skip_taskbar;
268 //! The window is a 'fullscreen' window, and should be on top of all others
269 bool _fullscreen;
270 //! The window should be on top of other windows of the same type
271 bool _above;
272 //! The window should be underneath other windows of the same type
273 bool _below;
274
275 OBScreen::StackLayer _layer;
276
277 //! A bitmask of values in the OBClient::Decoration enum
278 /*!
279 The values in the variable are the decorations that the client wants to be
280 displayed around it.
281 */
282 DecorationFlags _decorations;
283
284 //! A bitmask of values in the OBClient::Function enum
285 /*!
286 The values in the variable specify the ways in which the user is allowed to
287 modify this window.
288 */
289 FunctionFlags _functions;
290
291 //! Retrieves the desktop hint's value and sets OBClient::_desktop
292 void getDesktop();
293 //! Retrieves the window's type and sets OBClient::_type
294 void getType();
295 //! Gets the MWM Hints and adjusts OBClient::_functions and
296 //! OBClient::_decorations
297 void getMwmHints();
298 //! Gets the position and size of the window and sets OBClient::_area
299 void getArea();
300 //! Gets the net_state hint and sets the boolean flags for any states set in
301 //! the hint
302 void getState();
303 //! Determines if the window uses the Shape extension and sets
304 //! OBClient::_shaped
305 void getShaped();
306
307 //! Sets the wm_state to the specified value
308 void setWMState(long state);
309 //! Sends the window to the specified desktop
310 void setDesktop(long desktop);
311 //! Adjusts the window's net_state
312 void setState(StateAction action, long data1, long data2);
313
314 //! Calculates the stacking layer for the client window
315 void calcLayer();
316
317 //! Update the protocols that the window supports and adjusts things if they
318 //! change
319 void updateProtocols();
320 //! Updates the WMNormalHints and adjusts things if they change
321 void updateNormalHints();
322 //! Updates the WMHints and adjusts things if they change
323 void updateWMHints();
324 //! Updates the window's title
325 void updateTitle();
326 //! Updates the window's icon title
327 void updateIconTitle();
328 //! Updates the window's application name and class
329 void updateClass();
330 // XXX: updateTransientFor();
331 //! Updates the strut for the client
332 void updateStrut();
333
334 //! Change the client's state hints to match the class' data
335 void changeState();
336
337 public:
338 #ifndef SWIG
339 //! Constructs a new OBClient object around a specified window id
340 /*!
341 @param window The window id that the OBClient class should handle
342 @param screen The screen on which the window resides
343 */
344 OBClient(int screen, Window window);
345 //! Destroys the OBClient object
346 virtual ~OBClient();
347 #endif
348
349 //! Returns the screen on which the clien resides
350 inline int screen() const { return _screen; }
351
352 //! Returns the window id that the OBClient object is handling
353 inline Window window() const { return _window; }
354
355 //! Returns the type of the window, one of the OBClient::WindowType values
356 inline WindowType type() const { return _type; }
357 //! Returns if the window should be treated as a normal window.
358 /*!
359 Some windows (desktops, docks, splash screens) have special rules applied
360 to them in a number of places regarding focus or user interaction.
361 */
362 inline bool normal() const {
363 return ! (_type == Type_Desktop || _type == Type_Dock ||
364 _type == Type_Splash);
365 }
366
367 //! Returns the desktop on which the window resides
368 /*!
369 This value is a 0-based index.<br>
370 A value of 0xffffffff indicates that the window exists on all desktops.
371 */
372 inline unsigned long desktop() const { return _desktop; }
373 //! Returns the window's title
374 inline const std::string &title() const { return _title; }
375 //! Returns the window's title when it is iconified
376 inline const std::string &iconTitle() const { return _title; }
377 //! Returns the application's name to whom the window belongs
378 inline const std::string &appName() const { return _app_name; }
379 //! Returns the class of the window
380 inline const std::string &appClass() const { return _app_class; }
381 //! Returns the program-specified role of the window
382 inline const std::string &role() const { return _role; }
383 //! Returns if the window can be focused
384 /*!
385 @return true if the window can receive focus; otherwise, false
386 */
387 inline bool canFocus() const { return _can_focus; }
388 //! Returns if the window has indicated that it needs urgent attention
389 inline bool urgent() const { return _urgent; }
390 //! Returns if the window wants to be notified when it receives focus
391 inline bool focusNotify() const { return _focus_notify; }
392 //! Returns if the window uses the Shape extension
393 inline bool shaped() const { return _shaped; }
394 //! Returns the window's gravity
395 /*!
396 This value determines where to place the decorated window in relation to
397 its position without decorations.<br>
398 One of: NorthWestGravity, SouthWestGravity, EastGravity, ...,
399 SouthGravity, StaticGravity, ForgetGravity
400 */
401 inline int gravity() const { return _gravity; }
402 //! Returns if the application requested the initial position for the window
403 /*!
404 If the application did not request a position (this function returns false)
405 then the window should be placed intelligently by the window manager
406 initially
407 */
408 inline bool positionRequested() const { return _positioned; }
409 //! Returns the decorations that the client window wishes to be displayed on
410 //! it
411 inline DecorationFlags decorations() const { return _decorations; }
412 //! Returns the functions that the user can perform on the window
413 inline FunctionFlags funtions() const { return _functions; }
414
415 //! Returns if the window is modal
416 /*!
417 If the window is modal, then no other windows that it is related to can get
418 focus while it exists/remains modal.
419 */
420 inline bool modal() const { return _modal; }
421 //! Returns if the window is shaded
422 /*!
423 When the window is shaded, only its titlebar is visible, the client itself
424 is not mapped
425 */
426 inline bool shaded() const { return _shaded; }
427 //! Returns if the window is iconified
428 /*!
429 When the window is iconified, it is not visible at all (except in iconbars/
430 panels/etc that want to show lists of iconified windows
431 */
432 inline bool iconic() const { return _iconic; }
433 //! Returns if the window is maximized vertically
434 inline bool maxVert() const { return _max_vert; }
435 //! Returns if the window is maximized horizontally
436 inline bool maxHorz() const { return _max_horz; }
437 //! Returns the window's stacking layer
438 inline OBScreen::StackLayer layer() const { return _layer; }
439
440 //! Removes or reapplies the client's border to its window
441 /*!
442 Used when managing and unmanaging a window.
443 @param addborder true if adding the border to the client; false if removing
444 from the client
445 */
446 void toggleClientBorder(bool addborder);
447
448 //! Returns the position and size of the client relative to the root window
449 inline const otk::Rect &area() const { return _area; }
450
451 //! Returns the client's strut definition
452 inline const otk::Strut &strut() const { return _strut; }
453
454 //! Move the client window
455 void move(int x, int y);
456
457 //! Resizes the client window, anchoring it in a given corner
458 /*!
459 This also maintains things like the client's minsize, and size increments.
460 @param anchor The corner to keep in the same position when resizing.
461 @param w The width component of the new size for the client.
462 @param h The height component of the new size for the client.
463 @param x An optional X coordinate to which the window will be moved
464 after resizing.
465 @param y An optional Y coordinate to which the window will be moved
466 after resizing.
467 The x and y coordinates must both be sepcified together, or they will have
468 no effect. When they are specified, the anchor is ignored.
469 */
470 void resize(Corner anchor, int w, int h, int x = INT_MIN, int y = INT_MIN);
471
472 //! Request the client to close its window.
473 void close();
474
475 //! Sets the window's stacking layer
476 /*!
477 @param l An integer specifying the layer.<br>
478 '0' - the normal layer<br>
479 '> 0' - the 'above' layer<br>
480 '< 0' - the 'below' layer
481 */
482 void setStackLayer(int l);
483
484 //! Shades or unshades the client window
485 /*!
486 @param shade true if the window should be shaded; false if it should be
487 unshaded.
488 */
489 void shade(bool shade);
490
491 //! Attempt to focus the client window
492 bool focus();
493
494 //! Remove focus from the client window
495 void unfocus();
496
497 virtual void focusHandler(const XFocusChangeEvent &e);
498 virtual void unfocusHandler(const XFocusChangeEvent &e);
499 virtual void propertyHandler(const XPropertyEvent &e);
500 virtual void clientMessageHandler(const XClientMessageEvent &e);
501 virtual void configureRequestHandler(const XConfigureRequestEvent &e);
502 virtual void unmapHandler(const XUnmapEvent &e);
503 virtual void destroyHandler(const XDestroyWindowEvent &e);
504 virtual void reparentHandler(const XReparentEvent &e);
505 virtual void mapRequestHandler(const XMapRequestEvent &e);
506 #if defined(SHAPE)
507 virtual void shapeHandler(const XShapeEvent &e);
508 #endif // SHAPE
509 };
510
511 }
512
513 #endif // __client_hh
This page took 0.063403 seconds and 5 git commands to generate.