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