]> icculus.org git repositories - dana/openbox.git/blob - openbox/client.h
draw menu separators
[dana/openbox.git] / openbox / client.h
1 #ifndef __client_h
2 #define __client_h
3
4 #include "misc.h"
5 #include "mwm.h"
6 #include "geom.h"
7 #include "stacking.h"
8 #include "render/color.h"
9
10 #include <glib.h>
11 #include <X11/Xlib.h>
12
13 struct _ObFrame;
14 struct _ObGroup;
15 struct _ObSessionState;
16
17 typedef struct _ObClient     ObClient;
18 typedef struct _ObClientIcon ObClientIcon;
19
20 /* The value in client.transient_for indicating it is a transient for its
21    group instead of for a single window */
22 #define OB_TRAN_GROUP ((void*)~0l)
23
24 /*! Holds an icon in ARGB format */
25 struct _ObClientIcon
26 {
27     gint width;
28     gint height;
29     RrPixel32 *data;
30 };
31      
32 /*! Possible window types */
33 typedef enum
34 {
35     OB_CLIENT_TYPE_DESKTOP, /*!< A desktop (bottom-most window) */
36     OB_CLIENT_TYPE_DOCK,    /*!< A dock bar/panel window */
37     OB_CLIENT_TYPE_TOOLBAR, /*!< A toolbar window, pulled off an app */
38     OB_CLIENT_TYPE_MENU,    /*!< An unpinned menu from an app */
39     OB_CLIENT_TYPE_UTILITY, /*!< A small utility window such as a palette */
40     OB_CLIENT_TYPE_SPLASH,  /*!< A splash screen window */
41     OB_CLIENT_TYPE_DIALOG,  /*!< A dialog window */
42     OB_CLIENT_TYPE_NORMAL   /*!< A normal application window */
43 } ObClientType;
44
45 /*! The things the user can do to the client window */
46 typedef enum
47 {
48     OB_CLIENT_FUNC_RESIZE     = 1 << 0, /*!< Allow user resizing */
49     OB_CLIENT_FUNC_MOVE       = 1 << 1, /*!< Allow user moving */
50     OB_CLIENT_FUNC_ICONIFY    = 1 << 2, /*!< Allow to be iconified */
51     OB_CLIENT_FUNC_MAXIMIZE   = 1 << 3, /*!< Allow to be maximized */
52     OB_CLIENT_FUNC_SHADE      = 1 << 4, /*!< Allow to be shaded */
53     OB_CLIENT_FUNC_FULLSCREEN = 1 << 5, /*!< Allow to be made fullscreen */
54     OB_CLIENT_FUNC_CLOSE      = 1 << 6  /*!< Allow to be closed */
55 } ObFunctions;
56
57 struct _ObClient
58 {
59     ObWindow obwin;
60
61     Window  window;
62
63     /*! The window's decorations. NULL while the window is being managed! */
64     struct _ObFrame *frame;
65
66     /*! The number of unmap events to ignore on the window */
67     int ignore_unmaps;
68
69     /*! The id of the group the window belongs to */
70     struct _ObGroup *group;
71
72     /*! Saved session data to apply to this client */
73     struct _ObSessionState *session;
74
75     /*! Whether or not the client is a transient window. This is guaranteed to 
76       be TRUE if transient_for != NULL, but not guaranteed to be FALSE if
77       transient_for == NULL. */
78     gboolean transient;
79     /*! The client which this client is a transient (child) for.
80       A value of TRAN_GROUP signifies that the window is a transient for all
81       members of its ObGroup, and is not a valid pointer to be followed in this
82       case.
83      */
84     ObClient *transient_for;
85     /*! The clients which are transients (children) of this client */
86     GSList *transients;
87     /*! The desktop on which the window resides (0xffffffff for all
88       desktops) */
89     guint desktop;
90
91     /*! Normal window title */
92     gchar *title;
93     /*! The count for the title. When another window with the same title
94       exists, a count will be appended to it. */
95     guint title_count;
96     /*! Window title when iconified */
97     gchar *icon_title;
98
99     /*! The application that created the window */
100     gchar *name;
101     /*! The class of the window, can used for grouping */
102     gchar *class;
103     /*! The specified role of the window, used for identification */
104     gchar *role;
105
106     /*! The type of window (what its function is) */
107     ObClientType type;
108
109     /*! Position and size of the window
110       This will not always be the actual position of the window on screen, it
111       is, rather, the position requested by the client, to which the window's
112       gravity is applied.
113     */
114     Rect area;
115
116     /*! The window's strut
117       The strut defines areas of the screen that are marked off-bounds for
118       window placement. In theory, where this window exists.
119     */
120     StrutPartial strut;
121      
122     /*! The logical size of the window
123       The "logical" size of the window is refers to the user's perception of
124       the size of the window, and is the value that should be displayed to the
125       user. For example, with xterms, this value it the number of characters
126       being displayed in the terminal, instead of the number of pixels.
127     */
128     Size logical_size;
129
130     /*! Width of the border on the window.
131       The window manager will set this to 0 while the window is being managed,
132       but needs to restore it afterwards, so it is saved here.
133     */
134     guint border_width;
135
136     /*! The minimum aspect ratio the client window can be sized to.
137       A value of 0 means this is ignored.
138     */
139     float min_ratio;
140     /*! The maximum aspect ratio the client window can be sized to.
141       A value of 0 means this is ignored.
142     */
143     float max_ratio;
144   
145     /*! The minimum size of the client window
146       If the min is > the max, then the window is not resizable
147     */
148     Size min_size;
149     /*! The maximum size of the client window
150       If the min is > the max, then the window is not resizable
151     */
152     Size max_size;
153     /*! The size of increments to resize the client window by */
154     Size size_inc;
155     /*! The base size of the client window
156       This value should be subtracted from the window's actual size when
157       displaying its size to the user, or working with its min/max size
158     */
159     Size base_size;
160
161     /*! Window decoration and functionality hints */
162     ObMwmHints mwmhints;
163   
164     /*! Where to place the decorated window in relation to the undecorated
165       window */
166     int gravity;
167
168     /*! The state of the window, one of WithdrawnState, IconicState, or
169       NormalState */
170     long wmstate;
171
172     /*! True if the client supports the delete_window protocol */
173     gboolean delete_window;
174   
175     /*! Was the window's position requested by the application? if not, we
176       should place the window ourselves when it first appears */
177     gboolean positioned;
178   
179     /*! Can the window receive input focus? */
180     gboolean can_focus;
181     /*! Urgency flag */
182     gboolean urgent;
183     /*! Notify the window when it receives focus? */
184     gboolean focus_notify;
185
186     /*! The window uses shape extension to be non-rectangular? */
187     gboolean shaped;
188
189     /*! The window is modal, so it must be processed before any windows it is
190       related to can be focused */
191     gboolean modal;
192     /*! Only the window's titlebar is displayed */
193     gboolean shaded;
194     /*! The window is iconified */
195     gboolean iconic;
196     /*! The window is maximized to fill the screen vertically */
197     gboolean max_vert;
198     /*! The window is maximized to fill the screen horizontally */
199     gboolean max_horz;
200     /*! The window should not be displayed by pagers */
201     gboolean skip_pager;
202     /*! The window should not be displayed by taskbars */
203     gboolean skip_taskbar;
204     /*! The window is a 'fullscreen' window, and should be on top of all
205       others */
206     gboolean fullscreen;
207     /*! The window should be on top of other windows of the same type.
208       above takes priority over below. */
209     gboolean above;
210     /*! The window should be underneath other windows of the same type.
211       above takes priority over below. */
212     gboolean below;
213
214     /*! The layer in which the window will be stacked, windows in lower layers
215       are always below windows in higher layers. */
216     ObStackingLayer layer;
217
218     /*! A bitmask of values in the ObFrameDecorations enum
219       The values in the variable are the decorations that the client wants to
220       be displayed around it.
221     */
222     guint decorations;
223
224     /*! A user option. When this is set to FALSE the client will not ever
225       be decorated.
226     */
227     gboolean decorate;
228
229     /*! A bitmask of values in the ObFunctions enum
230       The values in the variable specify the ways in which the user is allowed
231       to modify this window.
232     */
233     guint functions;
234
235     /*! Icons for the client as specified on the client window */
236     ObClientIcon *icons;
237     /*! The number of icons in icons */
238     guint nicons;
239 };
240
241 extern GList *client_list;
242
243 void client_startup();
244 void client_shutdown();
245
246 typedef void (*ObClientDestructorFunc)(ObClient *c);
247
248 void client_add_destructor(ObClientDestructorFunc func);
249 void client_remove_destructor(ObClientDestructorFunc func);
250
251 /*! Manages all existing windows */
252 void client_manage_all();
253 /*! Manages a given window */
254 void client_manage(Window win);
255 /*! Unmanages all managed windows */
256 void client_unmanage_all();
257 /*! Unmanages a given client */
258 void client_unmanage(ObClient *client);
259
260 /*! Sets the client list on the root window from the client_list */
261 void client_set_list();
262
263 /*! Determines if the client should be shown or hidden currently.
264   @return TRUE if it should be visible; otherwise, FALSE.
265 */
266 gboolean client_should_show(ObClient *self);
267
268 /*! Returns if the window should be treated as a normal window.
269   Some windows (desktops, docks, splash screens) have special rules applied
270   to them in a number of places regarding focus or user interaction. */
271 gboolean client_normal(ObClient *self);
272
273 /* Returns if the window is focused */
274 gboolean client_focused(ObClient *self);
275
276 #define client_configure(self, anchor, x, y, w, h, user, final) \
277   client_configure_full(self, anchor, x, y, w, h, user, final, FALSE)
278
279 /*! Move and/or resize the window.
280   This also maintains things like the client's minsize, and size increments.
281   @param anchor The corner to keep in the same position when resizing.
282   @param x The x coordiante of the new position for the client.
283   @param y The y coordiante of the new position for the client.
284   @param w The width component of the new size for the client.
285   @param h The height component of the new size for the client.
286   @param user Specifies whether this is a user-requested change or a
287               program requested change. For program requested changes, the
288               constraints are not checked.
289   @param final If user is true, then this should specify if this is a final
290                configuration. e.g. Final should be FALSE if doing an
291                interactive move/resize, and then be TRUE for the last call
292                only.
293   @param force_reply Send a ConfigureNotify to the client regardless of if
294                      the position changed.
295 */
296 void client_configure_full(ObClient *self, ObCorner anchor,
297                            int x, int y, int w, int h,
298                            gboolean user, gboolean final,
299                            gboolean force_reply);
300
301 void client_reconfigure(ObClient *self);
302
303 /*! Finds coordinates to keep a client on the screen.
304   @param self The client
305   @param x The x coord of the client, may be changed.
306   @param y The y coord of the client, may be changed.
307   @param w The width of the client.
308   @param w The height of the client.
309   @param rude Be rude about it. If false, it is only moved if it is entirely
310               not visible. If true, then make sure the window is inside the
311               struts if possible.
312   @return true if the client was moved to be on-screen; false if not.
313 */
314 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
315                               gboolean rude);
316
317 /*! Moves a client so that it is on screen if it is entirely out of the
318   viewable screen.
319   @param self The client to move
320   @param rude Be rude about it. If false, it is only moved if it is entirely
321               not visible. If true, then make sure the window is inside the
322               struts if possible.
323 */
324 void client_move_onscreen(ObClient *self, gboolean rude);
325
326 /*! Fullscreen's or unfullscreen's the client window
327   @param fs true if the window should be made fullscreen; false if it should
328             be returned to normal state.
329   @param savearea true to have the client's current size and position saved;
330                   otherwise, they are not. You should not save when mapping a
331                   new window that is set to fullscreen. This has no effect
332                   when restoring a window from fullscreen.
333 */
334 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea);
335
336 /*! Iconifies or uniconifies the client window
337   @param iconic true if the window should be iconified; false if it should be
338                 restored.
339   @param curdesk If iconic is FALSE, then this determines if the window will
340                  be uniconified to the current viewable desktop (true) or to
341                  its previous desktop (false)
342 */
343 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk);
344
345 /*! Maximize or unmaximize the client window
346   @param max true if the window should be maximized; false if it should be
347              returned to normal size.
348   @param dir 0 to set both horz and vert, 1 to set horz, 2 to set vert.
349   @param savearea true to have the client's current size and position saved;
350                   otherwise, they are not. You should not save when mapping a
351                   new window that is set to fullscreen. This has no effect
352                   when unmaximizing a window.
353 */
354 void client_maximize(ObClient *self, gboolean max, int dir,
355                      gboolean savearea);
356
357 /*! Shades or unshades the client window
358   @param shade true if the window should be shaded; false if it should be
359                unshaded.
360 */
361 void client_shade(ObClient *self, gboolean shade);
362
363 /*! Request the client to close its window */
364 void client_close(ObClient *self);
365
366 /*! Kill the client off violently */
367 void client_kill(ObClient *self);
368
369 /*! Sends the window to the specified desktop
370   @param donthide If TRUE, the window will not be shown/hidden after its
371          desktop has been changed. Generally this should be FALSE. */
372 void client_set_desktop(ObClient *self, guint target, gboolean donthide);
373
374 /*! Validate client, by making sure no Destroy or Unmap events exist in
375   the event queue for the window.
376   @return true if the client is valid; false if the client has already
377           been unmapped/destroyed, and so is invalid.
378 */
379 gboolean client_validate(ObClient *self);
380
381 /*! Sets the wm_state to the specified value */
382 void client_set_wm_state(ObClient *self, long state);
383
384 /*! Adjusts the window's net_state
385   This should not be called as part of the window mapping process! It is for
386   use when updating the state post-mapping.<br>
387   client_apply_startup_state is used to do the same things during the mapping
388   process.
389 */
390 void client_set_state(ObClient *self, Atom action, long data1, long data2);
391
392 /* Given a ObClient, find the client that focus would actually be sent to if
393    you wanted to give focus to the specified ObClient. Will return the same
394    ObClient passed to it or another ObClient if appropriate. */
395 ObClient *client_focus_target(ObClient *self);
396
397 /*! Returns what client_focus would return if passed the same client, but
398   without focusing it or modifying the focus order lists. */
399 gboolean client_can_focus(ObClient *self);
400
401 /*! Attempt to focus the client window */
402 gboolean client_focus(ObClient *self);
403
404 /*! Remove focus from the client window */
405 void client_unfocus(ObClient *self);
406
407 /*! Activates the client for use, focusing, uniconifying it, etc. To be used
408   when the user deliberately selects a window for use.
409   @param here If true, then the client is brought to the current desktop;
410               otherwise, the desktop is changed to where the client lives.
411 */
412 void client_activate(ObClient *self, gboolean here);
413
414 /*! Calculates the stacking layer for the client window */
415 void client_calc_layer(ObClient *self);
416
417 /*! Updates the window's transient status, and any parents of it */
418 void client_update_transient_for(ObClient *self);
419 /*! Update the protocols that the window supports and adjusts things if they
420   change */
421 void client_update_protocols(ObClient *self);
422 /*! Updates the WMNormalHints and adjusts things if they change */
423 void client_update_normal_hints(ObClient *self);
424
425 /*! Updates the WMHints and adjusts things if they change
426   @param initstate Whether to read the initial_state property from the
427                    WMHints. This should only be used during the mapping
428                    process.
429 */
430 void client_update_wmhints(ObClient *self);
431 /*! Updates the window's title and icon title */
432 void client_update_title(ObClient *self);
433 /*! Updates the window's application name and class */
434 void client_update_class(ObClient *self);
435 /*! Updates the strut for the client */
436 void client_update_strut(ObClient *self);
437 /*! Updates the window's icons */
438 void client_update_icons(ObClient *self);
439
440 /*! Set up what decor should be shown on the window and what functions should
441   be allowed (ObClient::decorations and ObClient::functions).
442   This also updates the NET_WM_ALLOWED_ACTIONS hint.
443 */
444 void client_setup_decor_and_functions(ObClient *self);
445
446 /*! Retrieves the window's type and sets ObClient->type */
447 void client_get_type(ObClient *self);
448
449 ObClientIcon *client_icon(ObClient *self, int w, int h);
450
451 /*! Searches a client's transients for a focused window. The function does not
452   check for the passed client, only for its transients.
453   If no focused transient is found, NULL is returned.
454 */
455 ObClient *client_search_focus_tree(ObClient *self);
456
457 /*! Searches a client's transient tree for a focused window. The function
458   searches up the tree and down other branches as well as the passed client's.
459   If no focused client is found, NULL is returned.
460 */
461 ObClient *client_search_focus_tree_full(ObClient *self);
462
463 /*! Return a modal child of the client window that can be focused.
464     @return A modal child of the client window that can be focused, or 0 if
465             none was found.
466 */
467 ObClient *client_search_modal_child(ObClient *self);
468
469 ObClient *client_search_top_transient(ObClient *self);
470
471 ObClient *client_search_transient(ObClient *self, ObClient *search);
472
473 /*! Return the "closest" client in the given direction */
474 ObClient *client_find_directional(ObClient *c, ObDirection dir);
475
476 /*! Return the closest edge in the given direction */
477 int client_directional_edge_search(ObClient *c, ObDirection dir);
478
479 /*! Set a client window to be above/below other clients.
480   @layer < 0 indicates the client should be placed below other clients.<br>
481          = 0 indicates the client should be placed with other clients.<br>
482          > 0 indicates the client should be placed above other clients.
483 */
484 void client_set_layer(ObClient *self, int layer);
485
486 guint client_monitor(ObClient *self);
487
488 gchar* client_get_sm_client_id(ObClient *self);
489
490 #endif