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