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>
37 //! The MWM Hints as retrieved from the window property
39 This structure only contains 3 elements, even though the Motif 2.0
40 structure contains 5. We only use the first 3, so that is all gets defined.
43 unsigned long flags
; //!< A bitmask of Client::MwmFlags values
44 unsigned long functions
; //!< A bitmask of Client::MwmFunctions values
45 unsigned long decorations
;//!< A bitmask of Client::MwmDecorations values
46 //! The number of elements in the Client::MwmHints struct
47 static const unsigned int elements
= 3;
50 //! Maintains the state of a client window.
52 Client maintains the state of a client window. The state consists of the
53 hints that the application sets on the window, such as the title, or window
56 Client also manages client messages for the client window. When the
57 application (or any application) requests something to be changed for the
58 client, it will call the ActionHandler (for client messages) or update the
59 class' member variables and call whatever is nessary to complete the
60 change (such as causing a redraw of the titlebar after the title is changed).
62 class Client
: public otk::EventHandler
{
65 //! The frame window which decorates around the client window
67 NOTE: This should NEVER be used inside the client class's constructor!
71 //! Holds a list of Clients
72 typedef std::list
<Client
*> List
;
74 //! The possible stacking layers a client window can be a part of
76 Layer_Icon
, //!< 0 - iconified windows, in any order at all
77 Layer_Desktop
, //!< 1 - desktop windows
78 Layer_Below
, //!< 2 - normal windows w/ below
79 Layer_Normal
, //!< 3 - normal windows
80 Layer_Above
, //!< 4 - normal windows w/ above
81 Layer_Top
, //!< 5 - always-on-top-windows (docks?)
82 Layer_Fullscreen
, //!< 6 - fullscreeen windows
83 Layer_Internal
, //!< 7 - openbox windows/menus
87 //! Corners of the client window, used for anchor positions
88 enum Corner
{ TopLeft
,
93 //! Possible window types
94 enum WindowType
{ Type_Desktop
, //!< A desktop (bottom-most window)
95 Type_Dock
, //!< A dock bar/panel window
96 Type_Toolbar
, //!< A toolbar window, pulled off an app
97 Type_Menu
, //!< An unpinned menu from an app
98 Type_Utility
, //!< A small utility window such as a palette
99 Type_Splash
, //!< A splash screen window
100 Type_Dialog
, //!< A dialog window
101 Type_Normal
//!< A normal application window
104 //! Possible flags for MWM Hints (defined by Motif 2.0)
105 enum MwmFlags
{ MwmFlag_Functions
= 1 << 0, //!< The MMW Hints define funcs
106 MwmFlag_Decorations
= 1 << 1 //!< The MWM Hints define decor
109 //! Possible functions for MWM Hints (defined by Motif 2.0)
110 enum MwmFunctions
{ MwmFunc_All
= 1 << 0, //!< All functions
111 MwmFunc_Resize
= 1 << 1, //!< Allow resizing
112 MwmFunc_Move
= 1 << 2, //!< Allow moving
113 MwmFunc_Iconify
= 1 << 3, //!< Allow to be iconfied
114 MwmFunc_Maximize
= 1 << 4 //!< Allow to be maximized
115 //MwmFunc_Close = 1 << 5 //!< Allow to be closed
118 //! Possible decorations for MWM Hints (defined by Motif 2.0)
119 enum MemDecorations
{ MwmDecor_All
= 1 << 0, //!< All decorations
120 MwmDecor_Border
= 1 << 1, //!< Show a border
121 MwmDecor_Handle
= 1 << 2, //!< Show a handle (bottom)
122 MwmDecor_Title
= 1 << 3, //!< Show a titlebar
123 //MwmDecor_Menu = 1 << 4, //!< Show a menu
124 MwmDecor_Iconify
= 1 << 5, //!< Show an iconify button
125 MwmDecor_Maximize
= 1 << 6 //!< Show a maximize button
128 //! The things the user can do to the client window
129 enum Function
{ Func_Resize
= 1 << 0, //!< Allow resizing
130 Func_Move
= 1 << 1, //!< Allow moving
131 Func_Iconify
= 1 << 2, //!< Allow to be iconified
132 Func_Maximize
= 1 << 3, //!< Allow to be maximized
133 Func_Shade
= 1 << 4, //!< Allow to be shaded
134 Func_Fullscreen
= 1 << 5, //!< Allow to be made fullscreen
135 Func_Close
= 1 << 6 //!< Allow to be closed
137 //! Holds a bitmask of Client::Function values
138 typedef unsigned char FunctionFlags
;
140 //! The decorations the client window wants to be displayed on it
141 enum Decoration
{ Decor_Titlebar
= 1 << 0, //!< Display a titlebar
142 Decor_Handle
= 1 << 1, //!< Display a handle (bottom)
143 Decor_Border
= 1 << 2, //!< Display a border
144 Decor_Icon
= 1 << 3, //!< Display the window's icon
145 Decor_Iconify
= 1 << 4, //!< Display an iconify button
146 Decor_Maximize
= 1 << 5, //!< Display a maximize button
147 //! Display a button to toggle the window's placement on
149 Decor_AllDesktops
= 1 << 6,
150 Decor_Close
= 1 << 7 //!< Display a close button
152 //! Holds a bitmask of Client::Decoration values
153 typedef unsigned char DecorationFlags
;
155 //! Possible actions that can be made with the _NET_WM_STATE client message
156 enum StateAction
{ State_Remove
= 0, //!< _NET_WM_STATE_REMOVE
157 State_Add
, //!< _NET_WM_STATE_ADD
158 State_Toggle
//!< _NET_WM_STATE_TOGGLE
161 //! The event mask to grab on client windows
162 static const long event_mask
= PropertyChangeMask
| FocusChangeMask
|
165 //! The mask of events to not let propogate past the client
167 This makes things like xprop work on the client window, but means we have
168 to explicitly grab clicks that we want.
170 static const long no_propagate_mask
= ButtonPressMask
| ButtonReleaseMask
|
173 //! The number of unmap events to ignore on the window
177 //! The screen number on which the client resides
180 //! The actual window that this class is wrapping up
183 //! The id of the group the window belongs to
186 //! The client which this client is a transient (child) for
187 Client
*_transient_for
;
189 //! The clients which are transients (children) of this client
190 Client::List _transients
;
192 //! The desktop on which the window resides (0xffffffff for all desktops)
193 unsigned int _desktop
;
195 //! Normal window title
197 //! Window title when iconifiged
198 otk::ustring _icon_title
;
200 //! The application that created the window
201 std::string _app_name
;
202 //! The class of the window, can used for grouping
203 std::string _app_class
;
204 //! The specified role of the window, used for identification
207 //! The type of window (what its function is)
210 //! Position and size of the window
212 This will not always be the actual position of the window on screen, it is
213 rather, the position requested by the client, to which the window's gravity
218 //! The window's strut
220 The strut defines areas of the screen that are marked off-bounds for window
221 placement. In theory, where this window exists.
225 //! The logical size of the window
227 The "logical" size of the window is refers to the user's perception of the
228 size of the window, and is the value that should be displayed to the user.
229 For example, with xterms, this value it the number of characters being
230 displayed in the terminal, instead of the number of pixels.
232 otk::Size _logical_size
;
234 //! Width of the border on the window.
236 The window manager will set this to 0 while the window is being managed,
237 but needs to restore it afterwards, so it is saved here.
241 //! The minimum aspect ratio the client window can be sized to.
243 A value of 0 means this is ignored.
246 //! The maximum aspect ratio the client window can be sized to.
248 A value of 0 means this is ignored.
252 //! The minimum size of the client window
254 If the min is > the max, then the window is not resizable
257 //! The maximum size of the client window
259 If the min is > the max, then the window is not resizable
262 //! The size of increments to resize the client window by
264 //! The base size of the client window
266 This value should be subtracted from the window's actual size when
267 displaying its size to the user, or working with its min/max size
269 otk::Size _base_size
;
271 //! Window decoration and functionality hints
274 //! Where to place the decorated window in relation to the undecorated window
277 //! The state of the window, one of WithdrawnState, IconicState, or
281 //! True if the client supports the delete_window protocol
284 //! Was the window's position requested by the application? if not, we should
285 //! place the window ourselves when it first appears
288 //! Can the window receive input focus?
292 //! Notify the window when it receives focus?
294 //! Does the client window have the input focus?
297 //! The window uses shape extension to be non-rectangular?
300 //! The window is modal, so it must be processed before any windows it is
301 //! related to can be focused
303 //! Only the window's titlebar is displayed
305 //! The window is iconified
307 //! The window is maximized to fill the screen vertically
309 //! The window is maximized to fill the screen horizontally
311 //! The window should not be displayed by pagers
313 //! The window should not be displayed by taskbars
315 //! The window is a 'fullscreen' window, and should be on top of all others
317 //! The window should be on top of other windows of the same type
319 //! The window should be underneath other windows of the same type
322 //! The layer in which the window will be stacked, windows in lower layers
323 //! are always below windows in higher layers.
326 //! A bitmask of values in the Client::Decoration enum
328 The values in the variable are the decorations that the client wants to be
331 DecorationFlags _decorations
;
333 //! A bitmask of values in the Client::Decoration enum.
335 Specifies the decorations that should NOT be displayed on the client.
337 DecorationFlags _disabled_decorations
;
339 //! A bitmask of values in the Client::Function enum
341 The values in the variable specify the ways in which the user is allowed to
344 FunctionFlags _functions
;
346 //! Icons for the client as specified on the client window
348 //! The number of icons in _icons
352 Pixmap _pixmap_icon_mask
;
354 //! Retrieves the window's initial gravity
356 //! Retrieves the desktop hint's value and sets Client::_desktop
358 //! Retrieves the window's type and sets Client::_type
360 //! Gets the MWM Hints and adjusts Client::_functions and
361 //! Client::_decorations
363 //! Gets the position and size of the window and sets Client::_area
365 //! Gets the net_state hint and sets the boolean flags for any states set in
368 //! Determines if the window uses the Shape extension and sets
372 //! Set up what decor should be shown on the window and what functions should
373 //! be allowed (Client::_decorations and Client::_functions).
375 This also updates the NET_WM_ALLOWED_ACTIONS hint.
377 void setupDecorAndFunctions();
379 //! Sets the wm_state to the specified value
380 void setWMState(long state
);
381 //! Adjusts the window's net_state
383 This should not be called as part of the window mapping process! It is for
384 use when updating the state post-mapping.<br>
385 Client::applyStartupState is used to do the same things during the mapping
388 void setState(StateAction action
, long data1
, long data2
);
390 //! Sends the window to the specified desktop
391 void setDesktop(unsigned int desktop
);
393 //! Calculates the stacking layer for the client window
396 //! Update the protocols that the window supports and adjusts things if they
398 void updateProtocols();
399 //! Updates the WMNormalHints and adjusts things if they change
400 void updateNormalHints();
401 //! Updates the WMHints and adjusts things if they change
403 @param initstate Whether to read the initial_state property from the
404 WMHints. This should only be used during the mapping
407 void updateWMHints(bool initstate
= false);
408 //! Updates the window's title
410 //! Updates the window's icon title
411 void updateIconTitle();
412 //! Updates the window's application name and class
414 //! Updates the strut for the client
416 //! Updates the window's transient status, and any parents of it
417 void updateTransientFor();
418 //! Updates the window's icons
420 //! Updates the window's kwm icon
421 void updateKwmIcon();
423 //! Change the client's state hints to match the class' data
425 //! Change the allowed actions set on the client
426 void changeAllowedActions();
428 //! Request the client to close its window.
431 //! Shades or unshades the client window
433 @param shade true if the window should be shaded; false if it should be
436 void shade(bool shade
);
438 //! Recursively searches the client 'tree' for a modal client, always skips
439 //! the topmost node (the window you're starting with).
440 Client
*Client::searchModalTree(Client
*node
, Client
*skip
);
442 //! Recursively searches the client 'tree' for a focused client, always skips
443 //! the topmost node (the window you're starting with).
444 Client
*Client::searchFocusTree(Client
*node
, Client
*skip
);
446 //! Fires the urgent callbacks which lets the user do what they want with
450 //! Fullscreen's or unfullscreen's the client window
452 @param fs true if the window should be made fullscreen; false if it should
453 be returned to normal state.
454 @param savearea true to have the client's current size and position saved;
455 otherwise, they are not. You should not save when mapping a
456 new window that is set to fullscreen. This has no effect
457 when restoring a window from fullscreen.
459 void fullscreen(bool fs
, bool savearea
= true);
461 //! Iconifies or uniconifies the client window
463 @param iconic true if the window should be iconified; false if it should be
465 @param curdesk If iconic is false, then this determines if the window will
466 be uniconified to the current viewable desktop (true) or to
467 its previous desktop (false)
469 void iconify(bool iconic
, bool curdesk
= true);
471 //! Maximize or unmaximize the client window
473 @param max true if the window should be maximized; false if it should be
474 returned to normal size.
475 @param dir 0 to set both horz and vert, 1 to set horz, 2 to set vert.
476 @param savearea true to have the client's current size and position saved;
477 otherwise, they are not. You should not save when mapping a
478 new window that is set to fullscreen. This has no effect
479 when unmaximizing a window.
481 void maximize(bool max
, int dir
, bool savearea
= true);
483 //! Internal version of the Client::move function
485 @param x The X coordinate to move to.
486 @param y The Y coordinate to move to.
488 void internal_move(int x
, int y
);
489 //! Internal version of the Client::resize function
491 This also maintains things like the client's minsize, and size increments.
492 @param anchor The corner to keep in the same position when resizing.
493 @param w The width component of the new size for the client.
494 @param h The height component of the new size for the client.
495 @param user Specifies whether this is a user-requested change or a
496 program requested change.
497 @param x An optional X coordinate to which the window will be moved
499 @param y An optional Y coordinate to which the window will be moved
501 The x and y coordinates must both be sepcified together, or they will have
502 no effect. When they are specified, the anchor is ignored.
504 void internal_resize(Corner anchor
, int w
, int h
,
505 bool user
= true, int x
= INT_MIN
, int y
= INT_MIN
);
507 //! Removes or reapplies the client's border to its window
509 Used when managing and unmanaging a window.
510 @param addborder true if adding the border to the client; false if removing
513 void toggleClientBorder(bool addborder
);
515 //! Applies the states requested when the window mapped
517 This should be called only once, during the window mapping process. It
518 applies things like maximized, and fullscreen.
520 void applyStartupState();
524 //! Constructs a new Client object around a specified window id
526 BB @param window The window id that the Client class should handle
527 @param screen The screen on which the window resides
529 Client(int screen
, Window window
);
530 //! Destroys the Client object
534 //! Returns the screen on which the clien resides
535 inline int screen() const { return _screen
; }
537 //! Returns the window id that the Client object is handling
538 inline Window
window() const { return _window
; }
540 //! Returns the type of the window, one of the Client::WindowType values
541 inline WindowType
type() const { return _type
; }
542 //! Returns if the window should be treated as a normal window.
544 Some windows (desktops, docks, splash screens) have special rules applied
545 to them in a number of places regarding focus or user interaction.
547 inline bool normal() const {
548 return ! (_type
== Type_Desktop
|| _type
== Type_Dock
||
549 _type
== Type_Splash
);
552 //! Returns the desktop on which the window resides
554 This value is a 0-based index.<br>
555 A value of 0xffffffff indicates that the window exists on all desktops.
557 inline unsigned int desktop() const { return _desktop
; }
558 //! Returns the window's title
559 inline const otk::ustring
&title() const { return _title
; }
560 //! Returns the window's title when it is iconified
561 inline const otk::ustring
&iconTitle() const { return _title
; }
562 //! Returns the application's name to whom the window belongs
563 inline const std::string
&appName() const { return _app_name
; }
564 //! Returns the class of the window
565 inline const std::string
&appClass() const { return _app_class
; }
566 //! Returns the program-specified role of the window
567 inline const std::string
&role() const { return _role
; }
568 //! Returns if the window can be focused
570 @return true if the window can receive focus; otherwise, false
572 inline bool canFocus() const { return _can_focus
; }
573 //! Returns if the window has indicated that it needs urgent attention
574 inline bool urgent() const { return _urgent
; }
575 //! Returns if the window wants to be notified when it receives focus
576 inline bool focusNotify() const { return _focus_notify
; }
577 //! Returns if the window is the focused window
578 inline bool focused() const { return _focused
; }
579 //! Returns if the window uses the Shape extension
580 inline bool shaped() const { return _shaped
; }
581 //! Returns the window's gravity
583 This value determines where to place the decorated window in relation to
584 its position without decorations.<br>
585 One of: NorthWestGravity, SouthWestGravity, EastGravity, ...,
586 SouthGravity, StaticGravity, ForgetGravity
588 inline int gravity() const { return _gravity
; }
589 //! Returns if the application requested the initial position for the window
591 If the application did not request a position (this function returns false)
592 then the window should be placed intelligently by the window manager
595 inline bool positionRequested() const { return _positioned
; }
596 //! Returns the decorations that the client window wishes to be displayed on
598 inline DecorationFlags
decorations() const { return _decorations
; }
599 //! Returns the decorations that the user has requested to be disabled on the
601 inline DecorationFlags
disabledDecorations() const
602 { return _disabled_decorations
; }
603 //! Returns the functions that the user can perform on the window
604 inline FunctionFlags
funtions() const { return _functions
; }
606 //! Return the client this window is transient for
607 inline Client
*transientFor() const { return _transient_for
; }
609 //! Returns if the window is modal
611 If the window is modal, then no other windows that it is related to can get
612 focus while it exists/remains modal.
614 inline bool modal() const { return _modal
; }
615 //! The window should not be displayed by pagers
616 inline bool skipPager() const { return _skip_pager
; }
617 //! The window should not be displayed by taskbars
618 inline bool skipTaskbar() const { return _skip_taskbar
; }
619 //! Returns if the window is shaded
621 When the window is shaded, only its titlebar is visible.
623 inline bool shaded() const { return _shaded
; }
624 //! Returns if the window is in fullscreen mode
625 inline bool fullscreen() const { return _fullscreen
; }
626 //! Returns if the window is iconified
628 When the window is iconified, it is not visible at all (except in iconbars/
629 panels/etc that want to show lists of iconified windows
631 inline bool iconic() const { return _iconic
; }
632 //! Returns if the window is maximized vertically
633 inline bool maxVert() const { return _max_vert
; }
634 //! Returns if the window is maximized horizontally
635 inline bool maxHorz() const { return _max_horz
; }
636 //! Returns the window's stacking layer
637 inline StackLayer
layer() const { return _layer
; }
639 //! Returns the logical size of the window
641 The "logical" size of the window is refers to the user's perception of the
642 size of the window, and is the value that should be displayed to the user.
643 For example, with xterms, this value it the number of characters being
644 displayed in the terminal, instead of the number of pixels.
646 const otk::Size
&logicalSize() const { return _logical_size
; }
648 //! Returns the position and size of the client relative to the root window
650 Note that this value is *not* the size and position of the window's
651 frame, though the position will often line up.<br>
652 If you want the frame's area, use Frame::area() instead.
654 inline const otk::Rect
&area() const { return _area
; }
656 //! Returns the client's strut definition
657 inline const otk::Strut
&strut() const { return _strut
; }
659 //! Returns an icon for the window
661 The icon chosen will be the smallest icon available that is still bigger or
662 equal to the specified Size.<br>
663 If none that meet the requirements is found, the largest icon that is
664 smaller than the specified size will be returned.
666 const Icon
*icon(const otk::Size
&s
) const;
668 //! Returns the pixmap for the pixmap icon specified on the window (or None)
670 The icon given by Client::icon should take precedence over this icon/mask.
672 Pixmap
pixmapIcon() const { return _pixmap_icon
; }
673 //! Returns the mask for the pixmap icon specified on the window (or None)
675 The icon given by Client::icon should take precedence over this icon/mask.
677 Pixmap
pixmapIconMask() const { return _pixmap_icon_mask
; }
679 //! Move the window (actually, its frame) to a position.
681 This moves the window so that the top-left corner of its frame will be at
682 the position specified.
683 @param x The X coordinate to move to.
684 @param y The Y coordinate to move to.
686 void move(int x
, int y
);
688 //! Resizes the client window, anchoring it in a given corner
690 This also maintains things like the client's minsize, and size increments.
691 @param anchor The corner to keep in the same position when resizing.
692 @param w The width component of the new size for the client.
693 @param h The height component of the new size for the client.
695 void resize(Corner anchor
, int w
, int h
);
697 //! Reapplies the maximized state to the window
699 Use this to make the window readjust its maximized size to new
700 surroundings (struts, etc).
704 //! Shows the window if it should be shown, or hides it
706 Used when changing desktops, the window's state, etc.
710 //! Choose a mask of decorations to not display on the client
712 Pass a value of 0 to the function to turn all decorations back on. Note
713 that you cannot add decorations to a window with this, you can only remove
714 decorations that would otherwise have been displayed.
715 @param flags The mask of values from Client::Decoration to specify which
716 decorations should not be displayed.
718 void disableDecorations(DecorationFlags flags
);
720 //! Return a modal child of the client window
722 @return A modal child of the client window, or 0 if none was found.
724 Client
*findModalChild();
726 //! Attempt to focus the client window
729 //! Remove focus from the client window
730 void unfocus() const;
732 //! Validate client, by making sure no Destroy or Unmap events exist in
733 //! the event queue for the window.
735 @return true if the client is valid; false if the client has already
736 been unmapped/destroyed, and so is invalid.
738 bool validate() const;
740 void installColormap(bool install
) const;
742 virtual void focusHandler(const XFocusChangeEvent
&e
);
743 virtual void unfocusHandler(const XFocusChangeEvent
&e
);
744 virtual void propertyHandler(const XPropertyEvent
&e
);
745 virtual void clientMessageHandler(const XClientMessageEvent
&e
);
746 virtual void configureRequestHandler(const XConfigureRequestEvent
&e
);
747 virtual void unmapHandler(const XUnmapEvent
&e
);
748 virtual void destroyHandler(const XDestroyWindowEvent
&e
);
749 virtual void reparentHandler(const XReparentEvent
&e
);
750 virtual void mapRequestHandler(const XMapRequestEvent
&e
);
752 virtual void shapeHandler(const XShapeEvent
&e
);
755 friend void Screen::manageWindow(Window
);
756 friend void Screen::unmanageWindow(Client
*);
761 #endif // __client_hh