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