1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 @brief The Client class maintains the state of a client window by handling
7 property changes on the window and some client messages
11 #include "otk/strut.hh"
12 #include "otk/rect.hh"
13 #include "otk/eventhandler.hh"
14 #include "otk/ustring.hh"
20 #include <X11/extensions/shape.h>
32 //! The MWM Hints as retrieved from the window property
34 This structure only contains 3 elements, even though the Motif 2.0
35 structure contains 5. We only use the first 3, so that is all gets defined.
38 unsigned long flags
; //!< A bitmask of Client::MwmFlags values
39 unsigned long functions
; //!< A bitmask of Client::MwmFunctions values
40 unsigned long decorations
;//!< A bitmask of Client::MwmDecorations values
41 //! The number of elements in the Client::MwmHints struct
42 static const unsigned int elements
= 3;
45 //! Maintains the state of a client window.
47 Client 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 Client 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 Client
: public otk::EventHandler
{
60 //! The frame window which decorates around the client window
62 NOTE: This should NEVER be used inside the client class's constructor!
66 //! Holds a list of Clients
67 typedef std::list
<Client
*> List
;
69 //! The possible stacking layers a client window can be a part of
71 Layer_Icon
, //!< 0 - iconified windows, in any order at all
72 Layer_Desktop
, //!< 1 - desktop windows
73 Layer_Below
, //!< 2 - normal windows w/ below
74 Layer_Normal
, //!< 3 - normal windows
75 Layer_Above
, //!< 4 - normal windows w/ above
76 Layer_Top
, //!< 5 - always-on-top-windows (docks?)
77 Layer_Fullscreen
, //!< 6 - fullscreeen windows
78 Layer_Internal
, //!< 7 - openbox windows/menus
82 //! Corners of the client window, used for anchor positions
83 enum Corner
{ TopLeft
,
88 //! Possible window types
89 enum WindowType
{ Type_Desktop
, //!< A desktop (bottom-most window)
90 Type_Dock
, //!< A dock bar/panel window
91 Type_Toolbar
, //!< A toolbar window, pulled off an app
92 Type_Menu
, //!< An unpinned menu from an app
93 Type_Utility
, //!< A small utility window such as a palette
94 Type_Splash
, //!< A splash screen window
95 Type_Dialog
, //!< A dialog window
96 Type_Normal
//!< A normal application window
99 //! Possible flags for MWM Hints (defined by Motif 2.0)
100 enum MwmFlags
{ MwmFlag_Functions
= 1 << 0, //!< The MMW Hints define funcs
101 MwmFlag_Decorations
= 1 << 1 //!< The MWM Hints define decor
104 //! Possible functions for MWM Hints (defined by Motif 2.0)
105 enum MwmFunctions
{ MwmFunc_All
= 1 << 0, //!< All functions
106 MwmFunc_Resize
= 1 << 1, //!< Allow resizing
107 MwmFunc_Move
= 1 << 2, //!< Allow moving
108 MwmFunc_Iconify
= 1 << 3, //!< Allow to be iconfied
109 MwmFunc_Maximize
= 1 << 4 //!< Allow to be maximized
110 //MwmFunc_Close = 1 << 5 //!< Allow to be closed
113 //! Possible decorations for MWM Hints (defined by Motif 2.0)
114 enum MemDecorations
{ MwmDecor_All
= 1 << 0, //!< All decorations
115 MwmDecor_Border
= 1 << 1, //!< Show a border
116 MwmDecor_Handle
= 1 << 2, //!< Show a handle (bottom)
117 MwmDecor_Title
= 1 << 3, //!< Show a titlebar
118 //MwmDecor_Menu = 1 << 4, //!< Show a menu
119 MwmDecor_Iconify
= 1 << 5, //!< Show an iconify button
120 MwmDecor_Maximize
= 1 << 6 //!< Show a maximize button
123 //! The things the user can do to the client window
124 enum Function
{ Func_Resize
= 1 << 0, //!< Allow resizing
125 Func_Move
= 1 << 1, //!< Allow moving
126 Func_Iconify
= 1 << 2, //!< Allow to be iconified
127 Func_Maximize
= 1 << 3, //!< Allow to be maximized
128 Func_Shade
= 1 << 4, //!< Allow to be shaded
129 Func_Fullscreen
= 1 << 5, //!< Allow to be made fullscreen
130 Func_Close
= 1 << 6 //!< Allow to be closed
132 //! Holds a bitmask of Client::Function values
133 typedef unsigned char FunctionFlags
;
135 //! The decorations the client window wants to be displayed on it
136 enum Decoration
{ Decor_Titlebar
= 1 << 0, //!< Display a titlebar
137 Decor_Handle
= 1 << 1, //!< Display a handle (bottom)
138 Decor_Border
= 1 << 2, //!< Display a border
139 Decor_Iconify
= 1 << 3, //!< Display an iconify button
140 Decor_Maximize
= 1 << 4, //!< Display a maximize button
141 //! Display a button to toggle the window's placement on
143 Decor_AllDesktops
= 1 << 5,
144 Decor_Close
= 1 << 6 //!< Display a close button
146 //! Holds a bitmask of Client::Decoration values
147 typedef unsigned char DecorationFlags
;
149 //! Possible actions that can be made with the _NET_WM_STATE client message
150 enum StateAction
{ State_Remove
= 0, //!< _NET_WM_STATE_REMOVE
151 State_Add
, //!< _NET_WM_STATE_ADD
152 State_Toggle
//!< _NET_WM_STATE_TOGGLE
155 //! The event mask to grab on client windows
156 static const long event_mask
= PropertyChangeMask
| FocusChangeMask
|
159 //! The mask of events to not let propogate past the client
161 This makes things like xprop work on the client window, but means we have
162 to explicitly grab clicks that we want.
164 static const long no_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
|
167 //! The number of unmap events to ignore on the window
171 //! The screen number on which the client resides
174 //! The actual window that this class is wrapping up
177 //! The id of the group the window belongs to
180 //! The client which this client is a transient (child) for
181 Client
*_transient_for
;
183 //! The clients which are transients (children) of this client
184 Client::List _transients
;
186 //! The desktop on which the window resides (0xffffffff for all desktops)
187 unsigned int _desktop
;
189 //! Normal window title
191 //! Window title when iconifiged
192 otk::ustring _icon_title
;
194 //! The application that created the window
195 std::string _app_name
;
196 //! The class of the window, can used for grouping
197 std::string _app_class
;
198 //! The specified role of the window, used for identification
201 //! The type of window (what its function is)
204 //! Position and size of the window
206 This will not always be the actual position of the window on screen, it is
207 rather, the position requested by the client, to which the window's gravity
212 //! The window's strut
214 The strut defines areas of the screen that are marked off-bounds for window
215 placement. In theory, where this window exists.
219 //! The logical size of the window
221 The "logical" size of the window is refers to the user's perception of the
222 size of the window, and is the value that should be displayed to the user.
223 For example, with xterms, this value it the number of characters being
224 displayed in the terminal, instead of the number of pixels.
226 otk::Size _logical_size
;
228 //! Width of the border on the window.
230 The window manager will set this to 0 while the window is being managed,
231 but needs to restore it afterwards, so it is saved here.
235 //! The minimum aspect ratio the client window can be sized to.
237 A value of 0 means this is ignored.
240 //! The maximum aspect ratio the client window can be sized to.
242 A value of 0 means this is ignored.
246 //! The minimum size of the client window
248 If the min is > the max, then the window is not resizable
251 //! The maximum size of the client window
253 If the min is > the max, then the window is not resizable
256 //! The size of increments to resize the client window by
258 //! The base size of the client window
260 This value should be subtracted from the window's actual size when
261 displaying its size to the user, or working with its min/max size
263 otk::Size _base_size
;
265 //! Window decoration and functionality hints
268 //! Where to place the decorated window in relation to the undecorated window
271 //! The state of the window, one of WithdrawnState, IconicState, or
275 //! True if the client supports the delete_window protocol
278 //! Was the window's position requested by the application? if not, we should
279 //! place the window ourselves when it first appears
282 //! Can the window receive input focus?
286 //! Notify the window when it receives focus?
288 //! Does the client window have the input focus?
291 //! The window uses shape extension to be non-rectangular?
294 //! The window is modal, so it must be processed before any windows it is
295 //! related to can be focused
297 //! Only the window's titlebar is displayed
299 //! The window is iconified
301 //! The window is maximized to fill the screen vertically
303 //! The window is maximized to fill the screen horizontally
305 //! The window should not be displayed by pagers
307 //! The window should not be displayed by taskbars
309 //! The window is a 'fullscreen' window, and should be on top of all others
311 //! The window should be on top of other windows of the same type
313 //! The window should be underneath other windows of the same type
318 //! A bitmask of values in the Client::Decoration enum
320 The values in the variable are the decorations that the client wants to be
323 DecorationFlags _decorations
;
325 //! A bitmask of values in the Client::Decoration enum.
327 Specifies the decorations that should NOT be displayed on the client.
329 DecorationFlags _disabled_decorations
;
331 //! A bitmask of values in the Client::Function enum
333 The values in the variable specify the ways in which the user is allowed to
336 FunctionFlags _functions
;
338 //! Retrieves the window's initial gravity
340 //! Retrieves the desktop hint's value and sets Client::_desktop
342 //! Retrieves the window's type and sets Client::_type
344 //! Gets the MWM Hints and adjusts Client::_functions and
345 //! Client::_decorations
347 //! Gets the position and size of the window and sets Client::_area
349 //! Gets the net_state hint and sets the boolean flags for any states set in
352 //! Determines if the window uses the Shape extension and sets
356 //! Set up what decor should be shown on the window and what functions should
357 //! be allowed (Client::_decorations and Client::_functions).
359 This also updates the NET_WM_ALLOWED_ACTIONS hint.
361 void setupDecorAndFunctions();
363 //! Sets the wm_state to the specified value
364 void setWMState(long state
);
365 //! Adjusts the window's net_state
367 This should not be called as part of the window mapping process! It is for
368 use when updating the state post-mapping.<br>
369 Client::applyStartupState is used to do the same things during the mapping
372 void setState(StateAction action
, long data1
, long data2
);
374 //! Sends the window to the specified desktop
375 void setDesktop(unsigned int desktop
);
377 //! Calculates the stacking layer for the client window
380 //! Update the protocols that the window supports and adjusts things if they
382 void updateProtocols();
383 //! Updates the WMNormalHints and adjusts things if they change
384 void updateNormalHints();
385 //! Updates the WMHints and adjusts things if they change
387 @param initstate Whether to read the initial_state property from the
388 WMHints. This should only be used during the mapping
391 void updateWMHints(bool initstate
= false);
392 //! Updates the window's title
394 //! Updates the window's icon title
395 void updateIconTitle();
396 //! Updates the window's application name and class
398 //! Updates the strut for the client
400 //! Updates the window's transient status, and any parents of it
401 void updateTransientFor();
403 //! Change the client's state hints to match the class' data
405 //! Change the allowed actions set on the client
406 void changeAllowedActions();
408 //! Request the client to close its window.
411 //! Shades or unshades the client window
413 @param shade true if the window should be shaded; false if it should be
416 void shade(bool shade
);
418 //! Recursively searches the client 'tree' for a modal client, always skips
419 //! the topmost node (the window you're starting with).
420 Client
*Client::searchModalTree(Client
*node
, Client
*skip
);
422 //! Fires the urgent callbacks which lets the user do what they want with
426 //! Fullscreen's or unfullscreen's the client window
428 @param fs true if the window should be made fullscreen; false if it should
429 be returned to normal state.
430 @param savearea true to have the client's current size and position saved;
431 otherwise, they are not. You should not save when mapping a
432 new window that is set to fullscreen. This has no effect
433 when restoring a window from fullscreen.
435 void fullscreen(bool fs
, bool savearea
= true);
437 //! Iconifies or uniconifies the client window
439 @param iconic true if the window should be iconified; false if it should be
441 @param curdesk If iconic is false, then this determines if the window will
442 be uniconified to the current viewable desktop (true) or to
443 its previous desktop (false)
445 void iconify(bool iconic
, bool curdesk
= true);
447 //! Maximize or unmaximize the client window
449 @param max true if the window should be maximized; false if it should be
450 returned to normal size.
451 @param dir 0 to set both horz and vert, 1 to set horz, 2 to set vert.
452 @param savearea true to have the client's current size and position saved;
453 otherwise, they are not. You should not save when mapping a
454 new window that is set to fullscreen. This has no effect
455 when unmaximizing a window.
457 void maximize(bool max
, int dir
, bool savearea
= true);
459 //! Internal version of the Client::move function
461 @param x The X coordinate to move to.
462 @param y The Y coordinate to move to.
464 void internal_move(int x
, int y
);
465 //! Internal version of the Client::resize function
467 This also maintains things like the client's minsize, and size increments.
468 @param anchor The corner to keep in the same position when resizing.
469 @param w The width component of the new size for the client.
470 @param h The height component of the new size for the client.
471 @param user Specifies whether this is a user-requested change or a
472 program requested change.
473 @param x An optional X coordinate to which the window will be moved
475 @param y An optional Y coordinate to which the window will be moved
477 The x and y coordinates must both be sepcified together, or they will have
478 no effect. When they are specified, the anchor is ignored.
480 void internal_resize(Corner anchor
, int w
, int h
,
481 bool user
= true, int x
= INT_MIN
, int y
= INT_MIN
);
483 //! Removes or reapplies the client's border to its window
485 Used when managing and unmanaging a window.
486 @param addborder true if adding the border to the client; false if removing
489 void toggleClientBorder(bool addborder
);
491 //! Applies the states requested when the window mapped
493 This should be called only once, during the window mapping process. It
494 applies things like maximized, and fullscreen.
496 void applyStartupState();
500 //! Constructs a new Client object around a specified window id
502 BB @param window The window id that the Client class should handle
503 @param screen The screen on which the window resides
505 Client(int screen
, Window window
);
506 //! Destroys the Client object
510 //! Returns the screen on which the clien resides
511 inline int screen() const { return _screen
; }
513 //! Returns the window id that the Client object is handling
514 inline Window
window() const { return _window
; }
516 //! Returns the type of the window, one of the Client::WindowType values
517 inline WindowType
type() const { return _type
; }
518 //! Returns if the window should be treated as a normal window.
520 Some windows (desktops, docks, splash screens) have special rules applied
521 to them in a number of places regarding focus or user interaction.
523 inline bool normal() const {
524 return ! (_type
== Type_Desktop
|| _type
== Type_Dock
||
525 _type
== Type_Splash
);
528 //! Returns the desktop on which the window resides
530 This value is a 0-based index.<br>
531 A value of 0xffffffff indicates that the window exists on all desktops.
533 inline unsigned int desktop() const { return _desktop
; }
534 //! Returns the window's title
535 inline const otk::ustring
&title() const { return _title
; }
536 //! Returns the window's title when it is iconified
537 inline const otk::ustring
&iconTitle() const { return _title
; }
538 //! Returns the application's name to whom the window belongs
539 inline const std::string
&appName() const { return _app_name
; }
540 //! Returns the class of the window
541 inline const std::string
&appClass() const { return _app_class
; }
542 //! Returns the program-specified role of the window
543 inline const std::string
&role() const { return _role
; }
544 //! Returns if the window can be focused
546 @return true if the window can receive focus; otherwise, false
548 inline bool canFocus() const { return _can_focus
; }
549 //! Returns if the window has indicated that it needs urgent attention
550 inline bool urgent() const { return _urgent
; }
551 //! Returns if the window wants to be notified when it receives focus
552 inline bool focusNotify() const { return _focus_notify
; }
553 //! Returns if the window is the focused window
554 inline bool focused() const { return _focused
; }
555 //! Returns if the window uses the Shape extension
556 inline bool shaped() const { return _shaped
; }
557 //! Returns the window's gravity
559 This value determines where to place the decorated window in relation to
560 its position without decorations.<br>
561 One of: NorthWestGravity, SouthWestGravity, EastGravity, ...,
562 SouthGravity, StaticGravity, ForgetGravity
564 inline int gravity() const { return _gravity
; }
565 //! Returns if the application requested the initial position for the window
567 If the application did not request a position (this function returns false)
568 then the window should be placed intelligently by the window manager
571 inline bool positionRequested() const { return _positioned
; }
572 //! Returns the decorations that the client window wishes to be displayed on
574 inline DecorationFlags
decorations() const { return _decorations
; }
575 //! Returns the decorations that the user has requested to be disabled on the
577 inline DecorationFlags
disabledDecorations() const
578 { return _disabled_decorations
; }
579 //! Returns the functions that the user can perform on the window
580 inline FunctionFlags
funtions() const { return _functions
; }
582 //! Return the client this window is transient for
583 inline Client
*transientFor() const { return _transient_for
; }
585 //! Returns if the window is modal
587 If the window is modal, then no other windows that it is related to can get
588 focus while it exists/remains modal.
590 inline bool modal() const { return _modal
; }
591 //! The window should not be displayed by pagers
592 inline bool skipPager() const { return _skip_pager
; }
593 //! The window should not be displayed by taskbars
594 inline bool skipTaskbar() const { return _skip_taskbar
; }
595 //! Returns if the window is shaded
597 When the window is shaded, only its titlebar is visible.
599 inline bool shaded() const { return _shaded
; }
600 //! Returns if the window is in fullscreen mode
601 inline bool fullscreen() const { return _fullscreen
; }
602 //! Returns if the window is iconified
604 When the window is iconified, it is not visible at all (except in iconbars/
605 panels/etc that want to show lists of iconified windows
607 inline bool iconic() const { return _iconic
; }
608 //! Returns if the window is maximized vertically
609 inline bool maxVert() const { return _max_vert
; }
610 //! Returns if the window is maximized horizontally
611 inline bool maxHorz() const { return _max_horz
; }
612 //! Returns the window's stacking layer
613 inline StackLayer
layer() const { return _layer
; }
615 //! Returns the logical size of the window
617 The "logical" size of the window is refers to the user's perception of the
618 size of the window, and is the value that should be displayed to the user.
619 For example, with xterms, this value it the number of characters being
620 displayed in the terminal, instead of the number of pixels.
622 const otk::Size
&logicalSize() const { return _logical_size
; }
624 //! Returns the position and size of the client relative to the root window
625 inline const otk::Rect
&area() const { return _area
; }
627 //! Returns the client's strut definition
628 inline const otk::Strut
&strut() const { return _strut
; }
630 //! Move the window (actually, its frame) to a position.
632 This moves the window so that the top-left corner of its frame will be at
633 the position specified.
634 @param x The X coordinate to move to.
635 @param y The Y coordinate to move to.
637 void move(int x
, int y
);
639 //! Resizes the client window, anchoring it in a given corner
641 This also maintains things like the client's minsize, and size increments.
642 @param anchor The corner to keep in the same position when resizing.
643 @param w The width component of the new size for the client.
644 @param h The height component of the new size for the client.
646 void resize(Corner anchor
, int w
, int h
);
648 //! Reapplies the maximized state to the window
650 Use this to make the window readjust its maximized size to new
651 surroundings (struts, etc).
655 //! Shows the window if it should be shown, or hides it
657 Used when changing desktops, the window's state, etc.
661 //! Choose a mask of decorations to not display on the client
663 Pass a value of 0 to the function to turn all decorations back on. Note
664 that you cannot add decorations to a window with this, you can only remove
665 decorations that would otherwise have been displayed.
666 @param flags The mask of values from Client::Decoration to specify which
667 decorations should not be displayed.
669 void disableDecorations(DecorationFlags flags
);
671 //! Return a modal child of the client window
673 @return A modal child of the client window, or 0 if none was found.
675 Client
*findModalChild();
677 //! Attempt to focus the client window
680 //! Remove focus from the client window
681 void unfocus() const;
683 //! Validate client, by making sure no Destroy or Unmap events exist in
684 //! the event queue for the window.
686 @return true if the client is valid; false if the client has already
687 been unmapped/destroyed, and so is invalid.
689 bool validate() const;
691 void installColormap(bool install
) const;
693 virtual void focusHandler(const XFocusChangeEvent
&e
);
694 virtual void unfocusHandler(const XFocusChangeEvent
&e
);
695 virtual void propertyHandler(const XPropertyEvent
&e
);
696 virtual void clientMessageHandler(const XClientMessageEvent
&e
);
697 virtual void configureRequestHandler(const XConfigureRequestEvent
&e
);
698 virtual void unmapHandler(const XUnmapEvent
&e
);
699 virtual void destroyHandler(const XDestroyWindowEvent
&e
);
700 virtual void reparentHandler(const XReparentEvent
&e
);
701 virtual void mapRequestHandler(const XMapRequestEvent
&e
);
703 virtual void shapeHandler(const XShapeEvent
&e
);
706 friend void Screen::manageWindow(Window
);
707 friend void Screen::unmanageWindow(Client
*);
712 #endif // __client_hh