1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
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.
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.
16 See the COPYING file for a copy of the GNU General Public License.
21 #include "startupnotify.h"
25 #include "moveresize.h"
28 #include "extensions.h"
38 #include "menuframe.h"
41 #include "render/render.h"
44 #include <X11/Xutil.h>
46 /*! The event mask to grab on client windows */
47 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
50 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
53 GList *client_list = NULL;
54 GSList *client_destructors = NULL;
56 static void client_get_all(ObClient *self);
57 static void client_toggle_border(ObClient *self, gboolean show);
58 static void client_get_startup_id(ObClient *self);
59 static void client_get_area(ObClient *self);
60 static void client_get_desktop(ObClient *self);
61 static void client_get_state(ObClient *self);
62 static void client_get_shaped(ObClient *self);
63 static void client_get_mwm_hints(ObClient *self);
64 static void client_get_gravity(ObClient *self);
65 static void client_showhide(ObClient *self);
66 static void client_change_allowed_actions(ObClient *self);
67 static void client_change_state(ObClient *self);
68 static void client_apply_startup_state(ObClient *self);
69 static void client_restore_session_state(ObClient *self);
70 static void client_restore_session_stacking(ObClient *self);
71 static void client_urgent_notify(ObClient *self);
73 void client_startup(gboolean reconfig)
80 void client_shutdown(gboolean reconfig)
84 void client_add_destructor(GDestroyNotify func)
86 client_destructors = g_slist_prepend(client_destructors, (gpointer)func);
89 void client_remove_destructor(GDestroyNotify func)
91 client_destructors = g_slist_remove(client_destructors, (gpointer)func);
94 void client_set_list()
96 Window *windows, *win_it;
98 guint size = g_list_length(client_list);
100 /* create an array of the window ids */
102 windows = g_new(Window, size);
104 for (it = client_list; it != NULL; it = it->next, ++win_it)
105 *win_it = ((ObClient*)it->data)->window;
109 PROP_SETA32(RootWindow(ob_display, ob_screen),
110 net_client_list, window, (guint32*)windows, size);
119 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
123 for (it = self->transients; it; it = it->next) {
124 if (!func(it->data, data)) return;
125 client_foreach_transient(it->data, func, data);
129 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
131 if (self->transient_for) {
132 if (self->transient_for != OB_TRAN_GROUP) {
133 if (!func(self->transient_for, data)) return;
134 client_foreach_ancestor(self->transient_for, func, data);
138 for (it = self->group->members; it; it = it->next)
139 if (it->data != self &&
140 !((ObClient*)it->data)->transient_for) {
141 if (!func(it->data, data)) return;
142 client_foreach_ancestor(it->data, func, data);
149 void client_manage_all()
151 unsigned int i, j, nchild;
154 XWindowAttributes attrib;
156 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
157 &w, &w, &children, &nchild);
159 /* remove all icon windows from the list */
160 for (i = 0; i < nchild; i++) {
161 if (children[i] == None) continue;
162 wmhints = XGetWMHints(ob_display, children[i]);
164 if ((wmhints->flags & IconWindowHint) &&
165 (wmhints->icon_window != children[i]))
166 for (j = 0; j < nchild; j++)
167 if (children[j] == wmhints->icon_window) {
175 for (i = 0; i < nchild; ++i) {
176 if (children[i] == None)
178 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
179 if (attrib.override_redirect) continue;
181 if (attrib.map_state != IsUnmapped)
182 client_manage(children[i]);
188 void client_manage(Window window)
192 XWindowAttributes attrib;
193 XSetWindowAttributes attrib_set;
195 gboolean activate = FALSE;
199 /* check if it has already been unmapped by the time we started mapping
200 the grab does a sync so we don't have to here */
201 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
202 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
203 XPutBackEvent(ob_display, &e);
206 return; /* don't manage it */
209 /* make sure it isn't an override-redirect window */
210 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
211 attrib.override_redirect) {
213 return; /* don't manage it */
216 /* is the window a docking app */
217 if ((wmhint = XGetWMHints(ob_display, window))) {
218 if ((wmhint->flags & StateHint) &&
219 wmhint->initial_state == WithdrawnState) {
220 dock_add(window, wmhint);
228 ob_debug("Managing window: %lx\n", window);
230 /* choose the events we want to receive on the CLIENT window */
231 attrib_set.event_mask = CLIENT_EVENTMASK;
232 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
233 XChangeWindowAttributes(ob_display, window,
234 CWEventMask|CWDontPropagate, &attrib_set);
237 /* create the ObClient struct, and populate it from the hints on the
239 self = g_new0(ObClient, 1);
240 self->obwin.type = Window_Client;
241 self->window = window;
243 /* non-zero defaults */
244 self->title_count = 1;
245 self->wmstate = NormalState;
247 self->decorate = TRUE;
248 self->desktop = screen_num_desktops; /* always an invalid value */
250 client_get_all(self);
251 client_restore_session_state(self);
253 sn_app_started(self->class);
255 client_change_state(self);
257 /* remove the client's border (and adjust re gravity) */
258 client_toggle_border(self, FALSE);
260 /* specify that if we exit, the window should not be destroyed and should
261 be reparented back to root automatically */
262 XChangeSaveSet(ob_display, window, SetModeInsert);
264 /* create the decoration frame for the client window */
265 self->frame = frame_new();
267 frame_grab_client(self->frame, self);
271 client_apply_startup_state(self);
273 /* update the focus lists */
274 focus_order_add_new(self);
276 stacking_add(CLIENT_AS_WINDOW(self));
277 client_restore_session_stacking(self);
279 /* focus the new window? */
280 if (ob_state() != OB_STATE_STARTING &&
281 (config_focus_new || client_search_focus_tree_full(self)) &&
282 /* note the check against Type_Normal/Dialog, not client_normal(self),
283 which would also include other types. in this case we want more
284 strict rules for focus */
285 (self->type == OB_CLIENT_TYPE_NORMAL ||
286 self->type == OB_CLIENT_TYPE_DIALOG))
290 if (self->desktop != screen_desktop) {
291 /* activate the window */
294 gboolean group_foc = FALSE;
299 for (it = self->group->members; it; it = it->next)
301 if (client_focused(it->data))
309 (!self->transient_for && (!self->group ||
310 !self->group->members->next))) ||
311 client_search_focus_tree_full(self) ||
313 !client_normal(focus_client))
315 /* activate the window */
322 if (ob_state() == OB_STATE_RUNNING) {
323 int x = self->area.x, ox = x;
324 int y = self->area.y, oy = y;
326 place_client(self, &x, &y);
328 /* make sure the window is visible */
329 client_find_onscreen(self, &x, &y,
330 self->frame->area.width,
331 self->frame->area.height,
332 client_normal(self));
334 if (x != ox || y != oy)
335 client_move(self, x, y);
338 client_showhide(self);
340 /* use client_focus instead of client_activate cuz client_activate does
341 stuff like switch desktops etc and I'm not interested in all that when
342 a window maps since its not based on an action from the user like
343 clicking a window to activate is. so keep the new window out of the way
345 if (activate) client_focus(self);
347 /* client_activate does this but we aret using it so we have to do it
349 if (screen_showing_desktop)
350 screen_show_desktop(FALSE);
352 /* add to client list/map */
353 client_list = g_list_append(client_list, self);
354 g_hash_table_insert(window_map, &self->window, self);
356 /* this has to happen after we're in the client_list */
357 screen_update_areas();
359 /* update the list hints */
362 keyboard_grab_for_client(self, TRUE);
363 mouse_grab_for_client(self, TRUE);
365 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
368 void client_unmanage_all()
370 while (client_list != NULL)
371 client_unmanage(client_list->data);
374 void client_unmanage(ObClient *self)
379 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
381 g_assert(self != NULL);
383 keyboard_grab_for_client(self, FALSE);
384 mouse_grab_for_client(self, FALSE);
386 /* remove the window from our save set */
387 XChangeSaveSet(ob_display, self->window, SetModeDelete);
389 /* we dont want events no more */
390 XSelectInput(ob_display, self->window, NoEventMask);
392 frame_hide(self->frame);
394 client_list = g_list_remove(client_list, self);
395 stacking_remove(self);
396 g_hash_table_remove(window_map, &self->window);
398 /* update the focus lists */
399 focus_order_remove(self);
401 /* once the client is out of the list, update the struts to remove it's
403 screen_update_areas();
405 /* tell our parent(s) that we're gone */
406 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
409 for (it = self->group->members; it; it = it->next)
410 if (it->data != self)
411 ((ObClient*)it->data)->transients =
412 g_slist_remove(((ObClient*)it->data)->transients, self);
413 } else if (self->transient_for) { /* transient of window */
414 self->transient_for->transients =
415 g_slist_remove(self->transient_for->transients, self);
418 /* tell our transients that we're gone */
419 for (it = self->transients; it != NULL; it = it->next) {
420 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
421 ((ObClient*)it->data)->transient_for = NULL;
422 client_calc_layer(it->data);
426 for (it = client_destructors; it; it = g_slist_next(it)) {
427 GDestroyNotify func = (GDestroyNotify) it->data;
431 if (focus_client == self) {
434 /* focus the last focused window on the desktop, and ignore enter
435 events from the unmap so it doesnt mess with the focus */
436 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
437 client_unfocus(self);
440 /* remove from its group */
442 group_remove(self->group, self);
446 /* give the client its border back */
447 client_toggle_border(self, TRUE);
449 /* reparent the window out of the frame, and free the frame */
450 frame_release_client(self->frame, self);
453 if (ob_state() != OB_STATE_EXITING) {
454 /* these values should not be persisted across a window
456 PROP_ERASE(self->window, net_wm_desktop);
457 PROP_ERASE(self->window, net_wm_state);
458 PROP_ERASE(self->window, wm_state);
460 /* if we're left in an iconic state, the client wont be mapped. this is
461 bad, since we will no longer be managing the window on restart */
463 XMapWindow(ob_display, self->window);
467 ob_debug("Unmanaged window 0x%lx\n", self->window);
469 /* free all data allocated in the client struct */
470 g_slist_free(self->transients);
471 for (j = 0; j < self->nicons; ++j)
472 g_free(self->icons[j].data);
473 if (self->nicons > 0)
476 g_free(self->icon_title);
480 g_free(self->sm_client_id);
483 /* update the list hints */
487 static void client_urgent_notify(ObClient *self)
490 frame_flash_start(self->frame);
492 frame_flash_stop(self->frame);
495 static void client_restore_session_state(ObClient *self)
499 if (!(it = session_state_find(self)))
502 self->session = it->data;
504 RECT_SET(self->area, self->session->x, self->session->y,
505 self->session->w, self->session->h);
506 self->positioned = TRUE;
507 XResizeWindow(ob_display, self->window,
508 self->session->w, self->session->h);
510 self->desktop = (self->session->desktop == DESKTOP_ALL ?
511 self->session->desktop :
512 MIN(screen_num_desktops - 1, self->session->desktop));
513 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
515 self->shaded = self->session->shaded;
516 self->iconic = self->session->iconic;
517 self->skip_pager = self->session->skip_pager;
518 self->skip_taskbar = self->session->skip_taskbar;
519 self->fullscreen = self->session->fullscreen;
520 self->above = self->session->above;
521 self->below = self->session->below;
522 self->max_horz = self->session->max_horz;
523 self->max_vert = self->session->max_vert;
526 static void client_restore_session_stacking(ObClient *self)
530 if (!self->session) return;
532 it = g_list_find(session_saved_state, self->session);
533 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
536 for (cit = client_list; cit; cit = g_list_next(cit))
537 if (session_state_cmp(it->data, cit->data))
540 client_calc_layer(self);
541 stacking_below(CLIENT_AS_WINDOW(self),
542 CLIENT_AS_WINDOW(cit->data));
548 void client_move_onscreen(ObClient *self, gboolean rude)
550 int x = self->area.x;
551 int y = self->area.y;
552 if (client_find_onscreen(self, &x, &y,
553 self->frame->area.width,
554 self->frame->area.height, rude)) {
555 client_move(self, x, y);
559 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
563 int ox = *x, oy = *y;
565 frame_client_gravity(self->frame, x, y); /* get where the frame
568 /* XXX watch for xinerama dead areas */
570 a = screen_area(self->desktop);
571 if (client_normal(self)) {
572 if (!self->strut.right && *x >= a->x + a->width - 1)
573 *x = a->x + a->width - self->frame->area.width;
574 if (!self->strut.bottom && *y >= a->y + a->height - 1)
575 *y = a->y + a->height - self->frame->area.height;
576 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
578 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
583 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
584 Java can suck it too. */
586 /* dont let windows map/move into the strut unless they
587 are bigger than the available area */
589 if (!self->strut.left && *x < a->x) *x = a->x;
590 if (!self->strut.right && *x + w > a->x + a->width)
591 *x = a->x + a->width - w;
593 if (h <= a->height) {
594 if (!self->strut.top && *y < a->y) *y = a->y;
595 if (!self->strut.bottom && *y + h > a->y + a->height)
596 *y = a->y + a->height - h;
600 frame_frame_gravity(self->frame, x, y); /* get where the client
603 return ox != *x || oy != *y;
606 static void client_toggle_border(ObClient *self, gboolean show)
608 /* adjust our idea of where the client is, based on its border. When the
609 border is removed, the client should now be considered to be in a
611 when re-adding the border to the client, the same operation needs to be
613 int oldx = self->area.x, oldy = self->area.y;
614 int x = oldx, y = oldy;
615 switch(self->gravity) {
617 case NorthWestGravity:
619 case SouthWestGravity:
621 case NorthEastGravity:
623 case SouthEastGravity:
624 if (show) x -= self->border_width * 2;
625 else x += self->border_width * 2;
632 if (show) x -= self->border_width;
633 else x += self->border_width;
636 switch(self->gravity) {
638 case NorthWestGravity:
640 case NorthEastGravity:
642 case SouthWestGravity:
644 case SouthEastGravity:
645 if (show) y -= self->border_width * 2;
646 else y += self->border_width * 2;
653 if (show) y -= self->border_width;
654 else y += self->border_width;
661 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
663 /* move the client so it is back it the right spot _with_ its
665 if (x != oldx || y != oldy)
666 XMoveWindow(ob_display, self->window, x, y);
668 XSetWindowBorderWidth(ob_display, self->window, 0);
672 static void client_get_all(ObClient *self)
674 client_get_area(self);
675 client_update_transient_for(self);
676 client_update_wmhints(self);
677 client_get_startup_id(self);
678 client_get_desktop(self);
679 client_get_state(self);
680 client_get_shaped(self);
682 client_get_mwm_hints(self);
683 client_get_type(self);/* this can change the mwmhints for special cases */
685 client_update_protocols(self);
687 client_get_gravity(self); /* get the attribute gravity */
688 client_update_normal_hints(self); /* this may override the attribute
691 /* got the type, the mwmhints, the protocols, and the normal hints
692 (min/max sizes), so we're ready to set up the decorations/functions */
693 client_setup_decor_and_functions(self);
695 client_update_title(self);
696 client_update_class(self);
697 client_update_sm_client_id(self);
698 client_update_strut(self);
699 client_update_icons(self);
702 static void client_get_startup_id(ObClient *self)
704 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
706 PROP_GETS(self->group->leader,
707 net_startup_id, utf8, &self->startup_id);
710 static void client_get_area(ObClient *self)
712 XWindowAttributes wattrib;
715 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
716 g_assert(ret != BadWindow);
718 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
719 self->border_width = wattrib.border_width;
722 static void client_get_desktop(ObClient *self)
724 guint32 d = screen_num_desktops; /* an always-invalid value */
726 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
727 if (d >= screen_num_desktops && d != DESKTOP_ALL)
728 self->desktop = screen_num_desktops - 1;
732 gboolean trdesk = FALSE;
734 if (self->transient_for) {
735 if (self->transient_for != OB_TRAN_GROUP) {
736 self->desktop = self->transient_for->desktop;
741 for (it = self->group->members; it; it = it->next)
742 if (it->data != self &&
743 !((ObClient*)it->data)->transient_for) {
744 self->desktop = ((ObClient*)it->data)->desktop;
751 /* try get from the startup-notification protocol */
752 if (sn_get_desktop(self->startup_id, &self->desktop)) {
753 if (self->desktop >= screen_num_desktops &&
754 self->desktop != DESKTOP_ALL)
755 self->desktop = screen_num_desktops - 1;
757 /* defaults to the current desktop */
758 self->desktop = screen_desktop;
761 if (self->desktop != d) {
762 /* set the desktop hint, to make sure that it always exists */
763 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
767 static void client_get_state(ObClient *self)
772 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
774 for (i = 0; i < num; ++i) {
775 if (state[i] == prop_atoms.net_wm_state_modal)
777 else if (state[i] == prop_atoms.net_wm_state_shaded)
779 else if (state[i] == prop_atoms.net_wm_state_hidden)
781 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
782 self->skip_taskbar = TRUE;
783 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
784 self->skip_pager = TRUE;
785 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
786 self->fullscreen = TRUE;
787 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
788 self->max_vert = TRUE;
789 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
790 self->max_horz = TRUE;
791 else if (state[i] == prop_atoms.net_wm_state_above)
793 else if (state[i] == prop_atoms.net_wm_state_below)
801 static void client_get_shaped(ObClient *self)
803 self->shaped = FALSE;
805 if (extensions_shape) {
810 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
812 XShapeQueryExtents(ob_display, self->window, &s, &foo,
813 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
815 self->shaped = (s != 0);
820 void client_update_transient_for(ObClient *self)
823 ObClient *target = NULL;
825 if (XGetTransientForHint(ob_display, self->window, &t)) {
826 self->transient = TRUE;
827 if (t != self->window) { /* cant be transient to itself! */
828 target = g_hash_table_lookup(window_map, &t);
829 /* if this happens then we need to check for it*/
830 g_assert(target != self);
831 if (target && !WINDOW_IS_CLIENT(target)) {
832 /* this can happen when a dialog is a child of
833 a dockapp, for example */
837 if (!target && self->group) {
838 /* not transient to a client, see if it is transient for a
840 if (t == self->group->leader ||
842 t == RootWindow(ob_display, ob_screen)) {
843 /* window is a transient for its group! */
844 target = OB_TRAN_GROUP;
849 self->transient = FALSE;
851 /* if anything has changed... */
852 if (target != self->transient_for) {
853 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
856 /* remove from old parents */
857 for (it = self->group->members; it; it = g_slist_next(it)) {
858 ObClient *c = it->data;
859 if (c != self && !c->transient_for)
860 c->transients = g_slist_remove(c->transients, self);
862 } else if (self->transient_for != NULL) { /* transient of window */
863 /* remove from old parent */
864 self->transient_for->transients =
865 g_slist_remove(self->transient_for->transients, self);
867 self->transient_for = target;
868 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
871 /* add to new parents */
872 for (it = self->group->members; it; it = g_slist_next(it)) {
873 ObClient *c = it->data;
874 if (c != self && !c->transient_for)
875 c->transients = g_slist_append(c->transients, self);
878 /* remove all transients which are in the group, that causes
879 circlular pointer hell of doom */
880 for (it = self->group->members; it; it = g_slist_next(it)) {
882 for (sit = self->transients; sit; sit = next) {
883 next = g_slist_next(sit);
884 if (sit->data == it->data)
886 g_slist_delete_link(self->transients, sit);
889 } else if (self->transient_for != NULL) { /* transient of window */
890 /* add to new parent */
891 self->transient_for->transients =
892 g_slist_append(self->transient_for->transients, self);
897 static void client_get_mwm_hints(ObClient *self)
902 self->mwmhints.flags = 0; /* default to none */
904 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
906 if (num >= OB_MWM_ELEMENTS) {
907 self->mwmhints.flags = hints[0];
908 self->mwmhints.functions = hints[1];
909 self->mwmhints.decorations = hints[2];
915 void client_get_type(ObClient *self)
922 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
923 /* use the first value that we know about in the array */
924 for (i = 0; i < num; ++i) {
925 if (val[i] == prop_atoms.net_wm_window_type_desktop)
926 self->type = OB_CLIENT_TYPE_DESKTOP;
927 else if (val[i] == prop_atoms.net_wm_window_type_dock)
928 self->type = OB_CLIENT_TYPE_DOCK;
929 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
930 self->type = OB_CLIENT_TYPE_TOOLBAR;
931 else if (val[i] == prop_atoms.net_wm_window_type_menu)
932 self->type = OB_CLIENT_TYPE_MENU;
933 else if (val[i] == prop_atoms.net_wm_window_type_utility)
934 self->type = OB_CLIENT_TYPE_UTILITY;
935 else if (val[i] == prop_atoms.net_wm_window_type_splash)
936 self->type = OB_CLIENT_TYPE_SPLASH;
937 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
938 self->type = OB_CLIENT_TYPE_DIALOG;
939 else if (val[i] == prop_atoms.net_wm_window_type_normal)
940 self->type = OB_CLIENT_TYPE_NORMAL;
941 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
942 /* prevent this window from getting any decor or
944 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
945 OB_MWM_FLAG_DECORATIONS);
946 self->mwmhints.decorations = 0;
947 self->mwmhints.functions = 0;
949 if (self->type != (ObClientType) -1)
950 break; /* grab the first legit type */
955 if (self->type == (ObClientType) -1) {
956 /*the window type hint was not set, which means we either classify
957 ourself as a normal window or a dialog, depending on if we are a
960 self->type = OB_CLIENT_TYPE_DIALOG;
962 self->type = OB_CLIENT_TYPE_NORMAL;
966 void client_update_protocols(ObClient *self)
971 self->focus_notify = FALSE;
972 self->delete_window = FALSE;
974 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
975 for (i = 0; i < num_return; ++i) {
976 if (proto[i] == prop_atoms.wm_delete_window) {
977 /* this means we can request the window to close */
978 self->delete_window = TRUE;
979 } else if (proto[i] == prop_atoms.wm_take_focus)
980 /* if this protocol is requested, then the window will be
981 notified whenever we want it to receive focus */
982 self->focus_notify = TRUE;
988 static void client_get_gravity(ObClient *self)
990 XWindowAttributes wattrib;
993 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
994 g_assert(ret != BadWindow);
995 self->gravity = wattrib.win_gravity;
998 void client_update_normal_hints(ObClient *self)
1002 int oldgravity = self->gravity;
1005 self->min_ratio = 0.0f;
1006 self->max_ratio = 0.0f;
1007 SIZE_SET(self->size_inc, 1, 1);
1008 SIZE_SET(self->base_size, 0, 0);
1009 SIZE_SET(self->min_size, 0, 0);
1010 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1012 /* get the hints from the window */
1013 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1014 self->positioned = !!(size.flags & (PPosition|USPosition));
1016 if (size.flags & PWinGravity) {
1017 self->gravity = size.win_gravity;
1019 /* if the client has a frame, i.e. has already been mapped and
1020 is changing its gravity */
1021 if (self->frame && self->gravity != oldgravity) {
1022 /* move our idea of the client's position based on its new
1024 self->area.x = self->frame->area.x;
1025 self->area.y = self->frame->area.y;
1026 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1030 if (size.flags & PAspect) {
1031 if (size.min_aspect.y)
1032 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
1033 if (size.max_aspect.y)
1034 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
1037 if (size.flags & PMinSize)
1038 SIZE_SET(self->min_size, size.min_width, size.min_height);
1040 if (size.flags & PMaxSize)
1041 SIZE_SET(self->max_size, size.max_width, size.max_height);
1043 if (size.flags & PBaseSize)
1044 SIZE_SET(self->base_size, size.base_width, size.base_height);
1046 if (size.flags & PResizeInc)
1047 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1051 void client_setup_decor_and_functions(ObClient *self)
1053 /* start with everything (cept fullscreen) */
1055 (OB_FRAME_DECOR_TITLEBAR |
1056 (ob_rr_theme->show_handle ? OB_FRAME_DECOR_HANDLE : 0) |
1057 OB_FRAME_DECOR_GRIPS |
1058 OB_FRAME_DECOR_BORDER |
1059 OB_FRAME_DECOR_ICON |
1060 OB_FRAME_DECOR_ALLDESKTOPS |
1061 OB_FRAME_DECOR_ICONIFY |
1062 OB_FRAME_DECOR_MAXIMIZE |
1063 OB_FRAME_DECOR_SHADE);
1065 (OB_CLIENT_FUNC_RESIZE |
1066 OB_CLIENT_FUNC_MOVE |
1067 OB_CLIENT_FUNC_ICONIFY |
1068 OB_CLIENT_FUNC_MAXIMIZE |
1069 OB_CLIENT_FUNC_SHADE);
1070 if (self->delete_window) {
1071 self->functions |= OB_CLIENT_FUNC_CLOSE;
1072 self->decorations |= OB_FRAME_DECOR_CLOSE;
1075 if (!(self->min_size.width < self->max_size.width ||
1076 self->min_size.height < self->max_size.height))
1077 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1079 switch (self->type) {
1080 case OB_CLIENT_TYPE_NORMAL:
1081 /* normal windows retain all of the possible decorations and
1082 functionality, and are the only windows that you can fullscreen */
1083 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1086 case OB_CLIENT_TYPE_DIALOG:
1087 case OB_CLIENT_TYPE_UTILITY:
1088 /* these windows cannot be maximized */
1089 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1092 case OB_CLIENT_TYPE_MENU:
1093 case OB_CLIENT_TYPE_TOOLBAR:
1094 /* these windows get less functionality */
1095 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1098 case OB_CLIENT_TYPE_DESKTOP:
1099 case OB_CLIENT_TYPE_DOCK:
1100 case OB_CLIENT_TYPE_SPLASH:
1101 /* none of these windows are manipulated by the window manager */
1102 self->decorations = 0;
1103 self->functions = 0;
1107 /* Mwm Hints are applied subtractively to what has already been chosen for
1108 decor and functionality */
1109 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1110 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1111 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1112 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1113 /* if the mwm hints request no handle or title, then all
1114 decorations are disabled */
1115 self->decorations = 0;
1119 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1120 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1121 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1122 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1123 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1124 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1125 /* dont let mwm hints kill any buttons
1126 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1127 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1128 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1129 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1131 /* dont let mwm hints kill the close button
1132 if (! (self->mwmhints.functions & MwmFunc_Close))
1133 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1137 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1138 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1139 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1140 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1141 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1142 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1144 /* can't maximize without moving/resizing */
1145 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1146 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1147 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1148 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1149 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1152 /* kill the handle on fully maxed windows */
1153 if (self->max_vert && self->max_horz)
1154 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1156 /* finally, the user can have requested no decorations, which overrides
1158 if (!self->decorate)
1159 self->decorations = OB_FRAME_DECOR_BORDER;
1161 /* if we don't have a titlebar, then we cannot shade! */
1162 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1163 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1165 /* now we need to check against rules for the client's current state */
1166 if (self->fullscreen) {
1167 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1168 OB_CLIENT_FUNC_FULLSCREEN |
1169 OB_CLIENT_FUNC_ICONIFY);
1170 self->decorations = 0;
1173 client_change_allowed_actions(self);
1176 /* adjust the client's decorations, etc. */
1177 client_reconfigure(self);
1179 /* this makes sure that these windows appear on all desktops */
1180 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1181 self->desktop != DESKTOP_ALL)
1183 self->desktop = DESKTOP_ALL;
1188 static void client_change_allowed_actions(ObClient *self)
1193 /* desktop windows are kept on all desktops */
1194 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1195 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1197 if (self->functions & OB_CLIENT_FUNC_SHADE)
1198 actions[num++] = prop_atoms.net_wm_action_shade;
1199 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1200 actions[num++] = prop_atoms.net_wm_action_close;
1201 if (self->functions & OB_CLIENT_FUNC_MOVE)
1202 actions[num++] = prop_atoms.net_wm_action_move;
1203 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1204 actions[num++] = prop_atoms.net_wm_action_minimize;
1205 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1206 actions[num++] = prop_atoms.net_wm_action_resize;
1207 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1208 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1209 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1210 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1211 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1214 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1216 /* make sure the window isn't breaking any rules now */
1218 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1219 if (self->frame) client_shade(self, FALSE);
1220 else self->shaded = FALSE;
1222 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1223 if (self->frame) client_iconify(self, FALSE, TRUE);
1224 else self->iconic = FALSE;
1226 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1227 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1228 else self->fullscreen = FALSE;
1230 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1232 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1233 else self->max_vert = self->max_horz = FALSE;
1237 void client_reconfigure(ObClient *self)
1239 /* by making this pass FALSE for user, we avoid the emacs event storm where
1240 every configurenotify causes an update in its normal hints, i think this
1241 is generally what we want anyways... */
1242 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1243 self->area.width, self->area.height, FALSE, TRUE);
1246 void client_update_wmhints(ObClient *self)
1249 gboolean ur = FALSE;
1252 /* assume a window takes input if it doesnt specify */
1253 self->can_focus = TRUE;
1255 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1256 if (hints->flags & InputHint)
1257 self->can_focus = hints->input;
1259 /* only do this when first managing the window *AND* when we aren't
1261 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1262 if (hints->flags & StateHint)
1263 self->iconic = hints->initial_state == IconicState;
1265 if (hints->flags & XUrgencyHint)
1268 if (!(hints->flags & WindowGroupHint))
1269 hints->window_group = None;
1271 /* did the group state change? */
1272 if (hints->window_group !=
1273 (self->group ? self->group->leader : None)) {
1274 /* remove from the old group if there was one */
1275 if (self->group != NULL) {
1276 /* remove transients of the group */
1277 for (it = self->group->members; it; it = it->next)
1278 self->transients = g_slist_remove(self->transients,
1280 group_remove(self->group, self);
1283 if (hints->window_group != None) {
1284 self->group = group_add(hints->window_group, self);
1286 /* i can only have transients from the group if i am not
1288 if (!self->transient_for) {
1289 /* add other transients of the group that are already
1291 for (it = self->group->members; it; it = it->next) {
1292 ObClient *c = it->data;
1293 if (c != self && c->transient_for == OB_TRAN_GROUP)
1295 g_slist_append(self->transients, c);
1300 /* because the self->transient flag wont change from this call,
1301 we don't need to update the window's type and such, only its
1302 transient_for, and the transients lists of other windows in
1303 the group may be affected */
1304 client_update_transient_for(self);
1307 /* the WM_HINTS can contain an icon */
1308 client_update_icons(self);
1313 if (ur != self->urgent) {
1315 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1317 /* fire the urgent callback if we're mapped, otherwise, wait until
1318 after we're mapped */
1320 client_urgent_notify(self);
1324 void client_update_title(ObClient *self)
1330 gboolean read_title;
1333 old_title = self->title;
1336 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1337 /* try old x stuff */
1338 if (!PROP_GETS(self->window, wm_name, locale, &data))
1339 data = g_strdup("Unnamed Window");
1341 /* did the title change? then reset the title_count */
1342 if (old_title && 0 != strncmp(old_title, data, strlen(data)))
1343 self->title_count = 1;
1345 /* look for duplicates and append a number */
1347 for (it = client_list; it; it = it->next)
1348 if (it->data != self) {
1349 ObClient *c = it->data;
1350 if (0 == strncmp(c->title, data, strlen(data)))
1351 nums |= 1 << c->title_count;
1353 /* find first free number */
1354 for (i = 1; i <= 32; ++i)
1355 if (!(nums & (1 << i))) {
1356 if (self->title_count == 1 || i == 1)
1357 self->title_count = i;
1360 /* dont display the number for the first window */
1361 if (self->title_count > 1) {
1363 ndata = g_strdup_printf("%s - [%u]", data, self->title_count);
1368 PROP_SETS(self->window, net_wm_visible_name, data);
1373 frame_adjust_title(self->frame);
1377 /* update the icon title */
1379 g_free(self->icon_title);
1383 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1384 /* try old x stuff */
1385 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1386 data = g_strdup(self->title);
1390 /* append the title count, dont display the number for the first window */
1391 if (read_title && self->title_count > 1) {
1392 char *vdata, *ndata;
1393 ndata = g_strdup_printf(" - [%u]", self->title_count);
1394 vdata = g_strconcat(data, ndata, NULL);
1400 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1402 self->icon_title = data;
1405 void client_update_class(ObClient *self)
1410 if (self->name) g_free(self->name);
1411 if (self->class) g_free(self->class);
1412 if (self->role) g_free(self->role);
1414 self->name = self->class = self->role = NULL;
1416 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1418 self->name = g_strdup(data[0]);
1420 self->class = g_strdup(data[1]);
1425 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1428 if (self->name == NULL) self->name = g_strdup("");
1429 if (self->class == NULL) self->class = g_strdup("");
1430 if (self->role == NULL) self->role = g_strdup("");
1433 void client_update_strut(ObClient *self)
1437 gboolean got = FALSE;
1440 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1444 STRUT_PARTIAL_SET(strut,
1445 data[0], data[2], data[1], data[3],
1446 data[4], data[5], data[8], data[9],
1447 data[6], data[7], data[10], data[11]);
1453 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1456 STRUT_PARTIAL_SET(strut,
1457 data[0], data[2], data[1], data[3],
1458 0, 0, 0, 0, 0, 0, 0, 0);
1464 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1465 0, 0, 0, 0, 0, 0, 0, 0);
1467 if (!STRUT_EQUAL(strut, self->strut)) {
1468 self->strut = strut;
1470 /* updating here is pointless while we're being mapped cuz we're not in
1471 the client list yet */
1473 screen_update_areas();
1477 void client_update_icons(ObClient *self)
1483 for (i = 0; i < self->nicons; ++i)
1484 g_free(self->icons[i].data);
1485 if (self->nicons > 0)
1486 g_free(self->icons);
1489 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1490 /* figure out how many valid icons are in here */
1492 while (num - i > 2) {
1496 if (i > num || w*h == 0) break;
1500 self->icons = g_new(ObClientIcon, self->nicons);
1502 /* store the icons */
1504 for (j = 0; j < self->nicons; ++j) {
1507 w = self->icons[j].width = data[i++];
1508 h = self->icons[j].height = data[i++];
1510 if (w*h == 0) continue;
1512 self->icons[j].data = g_new(RrPixel32, w * h);
1513 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1518 self->icons[j].data[t] =
1519 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1520 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1521 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1522 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1528 } else if (PROP_GETA32(self->window, kwm_win_icon,
1529 kwm_win_icon, &data, &num)) {
1532 self->icons = g_new(ObClientIcon, self->nicons);
1533 xerror_set_ignore(TRUE);
1534 if (!RrPixmapToRGBA(ob_rr_inst,
1536 &self->icons[self->nicons-1].width,
1537 &self->icons[self->nicons-1].height,
1538 &self->icons[self->nicons-1].data)) {
1539 g_free(&self->icons[self->nicons-1]);
1542 xerror_set_ignore(FALSE);
1548 if ((hints = XGetWMHints(ob_display, self->window))) {
1549 if (hints->flags & IconPixmapHint) {
1551 self->icons = g_new(ObClientIcon, self->nicons);
1552 xerror_set_ignore(TRUE);
1553 if (!RrPixmapToRGBA(ob_rr_inst,
1555 (hints->flags & IconMaskHint ?
1556 hints->icon_mask : None),
1557 &self->icons[self->nicons-1].width,
1558 &self->icons[self->nicons-1].height,
1559 &self->icons[self->nicons-1].data)){
1560 g_free(&self->icons[self->nicons-1]);
1563 xerror_set_ignore(FALSE);
1569 if (!self->nicons) {
1571 self->icons = g_new(ObClientIcon, self->nicons);
1572 self->icons[self->nicons-1].width = 48;
1573 self->icons[self->nicons-1].height = 48;
1574 self->icons[self->nicons-1].data = g_memdup(ob_rr_theme->def_win_icon,
1580 frame_adjust_icon(self->frame);
1583 static void client_change_state(ObClient *self)
1586 guint32 netstate[10];
1589 state[0] = self->wmstate;
1591 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1595 netstate[num++] = prop_atoms.net_wm_state_modal;
1597 netstate[num++] = prop_atoms.net_wm_state_shaded;
1599 netstate[num++] = prop_atoms.net_wm_state_hidden;
1600 if (self->skip_taskbar)
1601 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1602 if (self->skip_pager)
1603 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1604 if (self->fullscreen)
1605 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1607 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1609 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1611 netstate[num++] = prop_atoms.net_wm_state_above;
1613 netstate[num++] = prop_atoms.net_wm_state_below;
1614 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1616 client_calc_layer(self);
1619 frame_adjust_state(self->frame);
1622 ObClient *client_search_focus_tree(ObClient *self)
1627 for (it = self->transients; it != NULL; it = it->next) {
1628 if (client_focused(it->data)) return it->data;
1629 if ((ret = client_search_focus_tree(it->data))) return ret;
1634 ObClient *client_search_focus_tree_full(ObClient *self)
1636 if (self->transient_for) {
1637 if (self->transient_for != OB_TRAN_GROUP) {
1638 return client_search_focus_tree_full(self->transient_for);
1641 gboolean recursed = FALSE;
1643 for (it = self->group->members; it; it = it->next)
1644 if (!((ObClient*)it->data)->transient_for) {
1646 if ((c = client_search_focus_tree_full(it->data)))
1655 /* this function checks the whole tree, the client_search_focus_tree~
1656 does not, so we need to check this window */
1657 if (client_focused(self))
1659 return client_search_focus_tree(self);
1662 static ObStackingLayer calc_layer(ObClient *self)
1666 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1667 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1668 l = OB_STACKING_LAYER_DESKTOP;
1669 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1670 if (!self->below) l = OB_STACKING_LAYER_TOP;
1671 else l = OB_STACKING_LAYER_NORMAL;
1673 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1674 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1675 else l = OB_STACKING_LAYER_NORMAL;
1680 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1681 ObStackingLayer l, gboolean raised)
1683 ObStackingLayer old, own;
1687 own = calc_layer(self);
1688 self->layer = l > own ? l : own;
1690 for (it = self->transients; it; it = it->next)
1691 client_calc_layer_recursive(it->data, orig,
1692 l, raised ? raised : l != old);
1694 if (!raised && l != old)
1695 if (orig->frame) { /* only restack if the original window is managed */
1696 /* XXX add_non_intrusive ever? */
1697 stacking_remove(CLIENT_AS_WINDOW(self));
1698 stacking_add(CLIENT_AS_WINDOW(self));
1702 void client_calc_layer(ObClient *self)
1709 /* transients take on the layer of their parents */
1710 self = client_search_top_transient(self);
1712 l = calc_layer(self);
1714 client_calc_layer_recursive(self, orig, l, FALSE);
1717 gboolean client_should_show(ObClient *self)
1719 if (self->iconic) return FALSE;
1720 else if (!(self->desktop == screen_desktop ||
1721 self->desktop == DESKTOP_ALL)) return FALSE;
1722 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1727 static void client_showhide(ObClient *self)
1730 if (client_should_show(self))
1731 frame_show(self->frame);
1733 frame_hide(self->frame);
1736 gboolean client_normal(ObClient *self) {
1737 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1738 self->type == OB_CLIENT_TYPE_DOCK ||
1739 self->type == OB_CLIENT_TYPE_SPLASH);
1742 static void client_apply_startup_state(ObClient *self)
1744 /* these are in a carefully crafted order.. */
1747 self->iconic = FALSE;
1748 client_iconify(self, TRUE, FALSE);
1750 if (self->fullscreen) {
1751 self->fullscreen = FALSE;
1752 client_fullscreen(self, TRUE, FALSE);
1755 self->shaded = FALSE;
1756 client_shade(self, TRUE);
1759 client_urgent_notify(self);
1761 if (self->max_vert && self->max_horz) {
1762 self->max_vert = self->max_horz = FALSE;
1763 client_maximize(self, TRUE, 0, FALSE);
1764 } else if (self->max_vert) {
1765 self->max_vert = FALSE;
1766 client_maximize(self, TRUE, 2, FALSE);
1767 } else if (self->max_horz) {
1768 self->max_horz = FALSE;
1769 client_maximize(self, TRUE, 1, FALSE);
1772 /* nothing to do for the other states:
1781 void client_configure_full(ObClient *self, ObCorner anchor,
1782 int x, int y, int w, int h,
1783 gboolean user, gboolean final,
1784 gboolean force_reply)
1787 gboolean send_resize_client;
1788 gboolean moved = FALSE, resized = FALSE;
1789 guint fdecor = self->frame->decorations;
1790 gboolean fhorz = self->frame->max_horz;
1792 /* make the frame recalculate its dimentions n shit without changing
1793 anything visible for real, this way the constraints below can work with
1794 the updated frame dimensions. */
1795 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1797 /* gets the frame's position */
1798 frame_client_gravity(self->frame, &x, &y);
1800 /* these positions are frame positions, not client positions */
1802 /* set the size and position if fullscreen */
1803 if (self->fullscreen) {
1806 XF86VidModeModeLine mode;
1811 i = client_monitor(self);
1812 a = screen_physical_area_monitor(i);
1815 if (i == 0 && /* primary head */
1816 extensions_vidmode &&
1817 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1818 /* get the mode last so the mode.privsize isnt freed incorrectly */
1819 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1824 if (mode.privsize) XFree(mode.private);
1834 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1838 a = screen_area_monitor(self->desktop, client_monitor(self));
1840 /* set the size and position if maximized */
1841 if (self->max_horz) {
1843 w = a->width - self->frame->size.left - self->frame->size.right;
1845 if (self->max_vert) {
1847 h = a->height - self->frame->size.top - self->frame->size.bottom;
1851 /* gets the client's position */
1852 frame_frame_gravity(self->frame, &x, &y);
1854 /* these override the above states! if you cant move you can't move! */
1856 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1860 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1861 w = self->area.width;
1862 h = self->area.height;
1866 if (!(w == self->area.width && h == self->area.height)) {
1867 int basew, baseh, minw, minh;
1869 /* base size is substituted with min size if not specified */
1870 if (self->base_size.width || self->base_size.height) {
1871 basew = self->base_size.width;
1872 baseh = self->base_size.height;
1874 basew = self->min_size.width;
1875 baseh = self->min_size.height;
1877 /* min size is substituted with base size if not specified */
1878 if (self->min_size.width || self->min_size.height) {
1879 minw = self->min_size.width;
1880 minh = self->min_size.height;
1882 minw = self->base_size.width;
1883 minh = self->base_size.height;
1886 /* if this is a user-requested resize, then check against min/max
1889 /* smaller than min size or bigger than max size? */
1890 if (w > self->max_size.width) w = self->max_size.width;
1891 if (w < minw) w = minw;
1892 if (h > self->max_size.height) h = self->max_size.height;
1893 if (h < minh) h = minh;
1898 /* keep to the increments */
1899 w /= self->size_inc.width;
1900 h /= self->size_inc.height;
1902 /* you cannot resize to nothing */
1903 if (basew + w < 1) w = 1 - basew;
1904 if (baseh + h < 1) h = 1 - baseh;
1906 /* store the logical size */
1907 SIZE_SET(self->logical_size,
1908 self->size_inc.width > 1 ? w : w + basew,
1909 self->size_inc.height > 1 ? h : h + baseh);
1911 w *= self->size_inc.width;
1912 h *= self->size_inc.height;
1917 /* adjust the height to match the width for the aspect ratios.
1918 for this, min size is not substituted for base size ever. */
1919 w -= self->base_size.width;
1920 h -= self->base_size.height;
1922 if (self->min_ratio)
1923 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1924 if (self->max_ratio)
1925 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1927 w += self->base_size.width;
1928 h += self->base_size.height;
1932 case OB_CORNER_TOPLEFT:
1934 case OB_CORNER_TOPRIGHT:
1935 x -= w - self->area.width;
1937 case OB_CORNER_BOTTOMLEFT:
1938 y -= h - self->area.height;
1940 case OB_CORNER_BOTTOMRIGHT:
1941 x -= w - self->area.width;
1942 y -= h - self->area.height;
1946 moved = x != self->area.x || y != self->area.y;
1947 resized = w != self->area.width || h != self->area.height;
1949 oldw = self->area.width;
1950 oldh = self->area.height;
1951 RECT_SET(self->area, x, y, w, h);
1953 /* for app-requested resizes, always resize if 'resized' is true.
1954 for user-requested ones, only resize if final is true, or when
1955 resizing in redraw mode */
1956 send_resize_client = ((!user && resized) ||
1958 (resized && config_redraw_resize))));
1960 /* if the client is enlarging, the resize the client before the frame */
1961 if (send_resize_client && user && (w > oldw || h > oldh))
1962 XResizeWindow(ob_display, self->window, MAX(w, oldw), MAX(h, oldh));
1964 /* move/resize the frame to match the request */
1966 if (self->decorations != fdecor || self->max_horz != fhorz)
1967 moved = resized = TRUE;
1969 if (moved || resized)
1970 frame_adjust_area(self->frame, moved, resized, FALSE);
1972 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1975 event.type = ConfigureNotify;
1976 event.xconfigure.display = ob_display;
1977 event.xconfigure.event = self->window;
1978 event.xconfigure.window = self->window;
1980 /* root window real coords */
1981 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1983 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1985 event.xconfigure.width = w;
1986 event.xconfigure.height = h;
1987 event.xconfigure.border_width = 0;
1988 event.xconfigure.above = self->frame->plate;
1989 event.xconfigure.override_redirect = FALSE;
1990 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1991 FALSE, StructureNotifyMask, &event);
1995 /* if the client is shrinking, then resize the frame before the client */
1996 if (send_resize_client && (!user || (w <= oldw || h <= oldh)))
1997 XResizeWindow(ob_display, self->window, w, h);
2002 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
2006 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
2007 self->fullscreen == fs) return; /* already done */
2009 self->fullscreen = fs;
2010 client_change_state(self); /* change the state hints on the client,
2011 and adjust out layer/stacking */
2015 guint32 dimensions[4];
2016 dimensions[0] = self->area.x;
2017 dimensions[1] = self->area.y;
2018 dimensions[2] = self->area.width;
2019 dimensions[3] = self->area.height;
2021 PROP_SETA32(self->window, openbox_premax, cardinal,
2025 /* these are not actually used cuz client_configure will set them
2026 as appropriate when the window is fullscreened */
2033 /* pick some fallbacks... */
2034 a = screen_area_monitor(self->desktop, 0);
2035 x = a->x + a->width / 4;
2036 y = a->y + a->height / 4;
2040 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2041 (guint32**)&dimensions, &num)) {
2052 client_setup_decor_and_functions(self);
2054 client_move_resize(self, x, y, w, h);
2056 /* try focus us when we go into fullscreen mode */
2060 static void client_iconify_recursive(ObClient *self,
2061 gboolean iconic, gboolean curdesk)
2064 gboolean changed = FALSE;
2067 if (self->iconic != iconic) {
2068 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2071 self->iconic = iconic;
2074 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2077 old = self->wmstate;
2078 self->wmstate = IconicState;
2079 if (old != self->wmstate)
2080 PROP_MSG(self->window, kde_wm_change_state,
2081 self->wmstate, 1, 0, 0);
2083 self->ignore_unmaps++;
2084 /* we unmap the client itself so that we can get MapRequest
2085 events, and because the ICCCM tells us to! */
2086 XUnmapWindow(ob_display, self->window);
2088 /* update the focus lists.. iconic windows go to the bottom of
2089 the list, put the new iconic window at the 'top of the
2091 focus_order_to_top(self);
2099 client_set_desktop(self, screen_desktop, FALSE);
2101 old = self->wmstate;
2102 self->wmstate = self->shaded ? IconicState : NormalState;
2103 if (old != self->wmstate)
2104 PROP_MSG(self->window, kde_wm_change_state,
2105 self->wmstate, 1, 0, 0);
2107 XMapWindow(ob_display, self->window);
2109 /* this puts it after the current focused window */
2110 focus_order_remove(self);
2111 focus_order_add_new(self);
2113 /* this is here cuz with the VIDMODE extension, the viewport can
2114 change while a fullscreen window is iconic, and when it
2115 uniconifies, it would be nice if it did so to the new position
2117 client_reconfigure(self);
2124 client_change_state(self);
2125 client_showhide(self);
2126 screen_update_areas();
2129 /* iconify all transients */
2130 for (it = self->transients; it != NULL; it = it->next)
2131 if (it->data != self) client_iconify_recursive(it->data,
2135 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2137 /* move up the transient chain as far as possible first */
2138 self = client_search_top_transient(self);
2140 client_iconify_recursive(client_search_top_transient(self),
2144 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2148 g_assert(dir == 0 || dir == 1 || dir == 2);
2149 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2151 /* check if already done */
2153 if (dir == 0 && self->max_horz && self->max_vert) return;
2154 if (dir == 1 && self->max_horz) return;
2155 if (dir == 2 && self->max_vert) return;
2157 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2158 if (dir == 1 && !self->max_horz) return;
2159 if (dir == 2 && !self->max_vert) return;
2162 /* work with the frame's coords */
2163 x = self->frame->area.x;
2164 y = self->frame->area.y;
2165 w = self->area.width;
2166 h = self->area.height;
2170 gint32 dimensions[4];
2179 /* get the property off the window and use it for the dimensions
2180 we are already maxed on */
2181 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2182 (guint32**)&readdim, &num)) {
2184 if (self->max_horz) {
2185 dimensions[0] = readdim[0];
2186 dimensions[2] = readdim[2];
2188 if (self->max_vert) {
2189 dimensions[1] = readdim[1];
2190 dimensions[3] = readdim[3];
2196 PROP_SETA32(self->window, openbox_premax, cardinal,
2197 (guint32*)dimensions, 4);
2204 /* pick some fallbacks... */
2205 a = screen_area_monitor(self->desktop, 0);
2206 if (dir == 0 || dir == 1) { /* horz */
2207 x = a->x + a->width / 4;
2210 if (dir == 0 || dir == 2) { /* vert */
2211 y = a->y + a->height / 4;
2215 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2216 (guint32**)&dimensions, &num)) {
2218 if (dir == 0 || dir == 1) { /* horz */
2222 if (dir == 0 || dir == 2) { /* vert */
2231 if (dir == 0 || dir == 1) /* horz */
2232 self->max_horz = max;
2233 if (dir == 0 || dir == 2) /* vert */
2234 self->max_vert = max;
2236 if (!self->max_horz && !self->max_vert)
2237 PROP_ERASE(self->window, openbox_premax);
2239 client_change_state(self); /* change the state hints on the client */
2241 client_setup_decor_and_functions(self);
2243 /* figure out where the client should be going */
2244 frame_frame_gravity(self->frame, &x, &y);
2245 client_move_resize(self, x, y, w, h);
2248 void client_shade(ObClient *self, gboolean shade)
2250 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2251 shade) || /* can't shade */
2252 self->shaded == shade) return; /* already done */
2254 /* when we're iconic, don't change the wmstate */
2255 if (!self->iconic) {
2258 old = self->wmstate;
2259 self->wmstate = shade ? IconicState : NormalState;
2260 if (old != self->wmstate)
2261 PROP_MSG(self->window, kde_wm_change_state,
2262 self->wmstate, 1, 0, 0);
2265 self->shaded = shade;
2266 client_change_state(self);
2267 /* resize the frame to just the titlebar */
2268 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2271 void client_close(ObClient *self)
2275 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2278 XXX: itd be cool to do timeouts and shit here for killing the client's
2280 like... if the window is around after 5 seconds, then the close button
2281 turns a nice red, and if this function is called again, the client is
2285 ce.xclient.type = ClientMessage;
2286 ce.xclient.message_type = prop_atoms.wm_protocols;
2287 ce.xclient.display = ob_display;
2288 ce.xclient.window = self->window;
2289 ce.xclient.format = 32;
2290 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2291 ce.xclient.data.l[1] = event_lasttime;
2292 ce.xclient.data.l[2] = 0l;
2293 ce.xclient.data.l[3] = 0l;
2294 ce.xclient.data.l[4] = 0l;
2295 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2298 void client_kill(ObClient *self)
2300 XKillClient(ob_display, self->window);
2303 void client_set_desktop_recursive(ObClient *self,
2304 guint target, gboolean donthide)
2309 if (target != self->desktop) {
2311 ob_debug("Setting desktop %u\n", target+1);
2313 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2315 /* remove from the old desktop(s) */
2316 focus_order_remove(self);
2318 old = self->desktop;
2319 self->desktop = target;
2320 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2321 /* the frame can display the current desktop state */
2322 frame_adjust_state(self->frame);
2323 /* 'move' the window to the new desktop */
2325 client_showhide(self);
2326 /* raise if it was not already on the desktop */
2327 if (old != DESKTOP_ALL)
2328 stacking_raise(CLIENT_AS_WINDOW(self));
2329 screen_update_areas();
2331 /* add to the new desktop(s) */
2332 if (config_focus_new)
2333 focus_order_to_top(self);
2335 focus_order_to_bottom(self);
2338 /* move all transients */
2339 for (it = self->transients; it != NULL; it = it->next)
2340 if (it->data != self) client_set_desktop_recursive(it->data,
2344 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2346 client_set_desktop_recursive(client_search_top_transient(self),
2350 ObClient *client_search_modal_child(ObClient *self)
2355 for (it = self->transients; it != NULL; it = it->next) {
2356 ObClient *c = it->data;
2357 if ((ret = client_search_modal_child(c))) return ret;
2358 if (c->modal) return c;
2363 gboolean client_validate(ObClient *self)
2367 XSync(ob_display, FALSE); /* get all events on the server */
2369 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2370 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2371 XPutBackEvent(ob_display, &e);
2378 void client_set_wm_state(ObClient *self, long state)
2380 if (state == self->wmstate) return; /* no change */
2384 client_iconify(self, TRUE, TRUE);
2387 client_iconify(self, FALSE, TRUE);
2392 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2394 gboolean shaded = self->shaded;
2395 gboolean fullscreen = self->fullscreen;
2396 gboolean max_horz = self->max_horz;
2397 gboolean max_vert = self->max_vert;
2400 if (!(action == prop_atoms.net_wm_state_add ||
2401 action == prop_atoms.net_wm_state_remove ||
2402 action == prop_atoms.net_wm_state_toggle))
2403 /* an invalid action was passed to the client message, ignore it */
2406 for (i = 0; i < 2; ++i) {
2407 Atom state = i == 0 ? data1 : data2;
2409 if (!state) continue;
2411 /* if toggling, then pick whether we're adding or removing */
2412 if (action == prop_atoms.net_wm_state_toggle) {
2413 if (state == prop_atoms.net_wm_state_modal)
2414 action = self->modal ? prop_atoms.net_wm_state_remove :
2415 prop_atoms.net_wm_state_add;
2416 else if (state == prop_atoms.net_wm_state_maximized_vert)
2417 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2418 prop_atoms.net_wm_state_add;
2419 else if (state == prop_atoms.net_wm_state_maximized_horz)
2420 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2421 prop_atoms.net_wm_state_add;
2422 else if (state == prop_atoms.net_wm_state_shaded)
2423 action = self->shaded ? prop_atoms.net_wm_state_remove :
2424 prop_atoms.net_wm_state_add;
2425 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2426 action = self->skip_taskbar ?
2427 prop_atoms.net_wm_state_remove :
2428 prop_atoms.net_wm_state_add;
2429 else if (state == prop_atoms.net_wm_state_skip_pager)
2430 action = self->skip_pager ?
2431 prop_atoms.net_wm_state_remove :
2432 prop_atoms.net_wm_state_add;
2433 else if (state == prop_atoms.net_wm_state_fullscreen)
2434 action = self->fullscreen ?
2435 prop_atoms.net_wm_state_remove :
2436 prop_atoms.net_wm_state_add;
2437 else if (state == prop_atoms.net_wm_state_above)
2438 action = self->above ? prop_atoms.net_wm_state_remove :
2439 prop_atoms.net_wm_state_add;
2440 else if (state == prop_atoms.net_wm_state_below)
2441 action = self->below ? prop_atoms.net_wm_state_remove :
2442 prop_atoms.net_wm_state_add;
2445 if (action == prop_atoms.net_wm_state_add) {
2446 if (state == prop_atoms.net_wm_state_modal) {
2447 /* XXX raise here or something? */
2449 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2451 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2453 } else if (state == prop_atoms.net_wm_state_shaded) {
2455 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2456 self->skip_taskbar = TRUE;
2457 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2458 self->skip_pager = TRUE;
2459 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2461 } else if (state == prop_atoms.net_wm_state_above) {
2463 } else if (state == prop_atoms.net_wm_state_below) {
2467 } else { /* action == prop_atoms.net_wm_state_remove */
2468 if (state == prop_atoms.net_wm_state_modal) {
2469 self->modal = FALSE;
2470 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2472 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2474 } else if (state == prop_atoms.net_wm_state_shaded) {
2476 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2477 self->skip_taskbar = FALSE;
2478 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2479 self->skip_pager = FALSE;
2480 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2482 } else if (state == prop_atoms.net_wm_state_above) {
2483 self->above = FALSE;
2484 } else if (state == prop_atoms.net_wm_state_below) {
2485 self->below = FALSE;
2489 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2490 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2492 if (max_horz == max_vert) { /* both going the same way */
2493 client_maximize(self, max_horz, 0, TRUE);
2495 client_maximize(self, max_horz, 1, TRUE);
2496 client_maximize(self, max_vert, 2, TRUE);
2500 if (max_horz != self->max_horz)
2501 client_maximize(self, max_horz, 1, TRUE);
2503 client_maximize(self, max_vert, 2, TRUE);
2506 /* change fullscreen state before shading, as it will affect if the window
2508 if (fullscreen != self->fullscreen)
2509 client_fullscreen(self, fullscreen, TRUE);
2510 if (shaded != self->shaded)
2511 client_shade(self, shaded);
2512 client_calc_layer(self);
2513 client_change_state(self); /* change the hint to reflect these changes */
2516 ObClient *client_focus_target(ObClient *self)
2520 /* if we have a modal child, then focus it, not us */
2521 child = client_search_modal_child(self);
2522 if (child) return child;
2526 gboolean client_can_focus(ObClient *self)
2530 /* choose the correct target */
2531 self = client_focus_target(self);
2533 if (!self->frame->visible)
2536 if (!((self->can_focus || self->focus_notify) &&
2537 (self->desktop == screen_desktop ||
2538 self->desktop == DESKTOP_ALL) &&
2542 /* do a check to see if the window has already been unmapped or destroyed
2543 do this intelligently while watching out for unmaps we've generated
2544 (ignore_unmaps > 0) */
2545 if (XCheckTypedWindowEvent(ob_display, self->window,
2546 DestroyNotify, &ev)) {
2547 XPutBackEvent(ob_display, &ev);
2550 while (XCheckTypedWindowEvent(ob_display, self->window,
2551 UnmapNotify, &ev)) {
2552 if (self->ignore_unmaps) {
2553 self->ignore_unmaps--;
2555 XPutBackEvent(ob_display, &ev);
2563 gboolean client_focus(ObClient *self)
2565 /* choose the correct target */
2566 self = client_focus_target(self);
2568 if (!client_can_focus(self)) {
2569 if (!self->frame->visible) {
2570 /* update the focus lists */
2571 focus_order_to_top(self);
2576 if (self->can_focus) {
2577 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2578 I choose to use it always, hopefully to find errors quicker, if any
2579 are left. (I hate X. I hate focus events.)
2581 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2582 #799. So now it is RevertToNone again.
2584 XSetInputFocus(ob_display, self->window, RevertToNone,
2588 if (self->focus_notify) {
2590 ce.xclient.type = ClientMessage;
2591 ce.xclient.message_type = prop_atoms.wm_protocols;
2592 ce.xclient.display = ob_display;
2593 ce.xclient.window = self->window;
2594 ce.xclient.format = 32;
2595 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2596 ce.xclient.data.l[1] = event_lasttime;
2597 ce.xclient.data.l[2] = 0l;
2598 ce.xclient.data.l[3] = 0l;
2599 ce.xclient.data.l[4] = 0l;
2600 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2604 ob_debug("%sively focusing %lx at %d\n",
2605 (self->can_focus ? "act" : "pass"),
2606 self->window, (int) event_lasttime);
2609 /* Cause the FocusIn to come back to us. Important for desktop switches,
2610 since otherwise we'll have no FocusIn on the queue and send it off to
2611 the focus_backup. */
2612 XSync(ob_display, FALSE);
2616 void client_unfocus(ObClient *self)
2618 if (focus_client == self) {
2620 ob_debug("client_unfocus for %lx\n", self->window);
2622 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2626 void client_activate(ObClient *self, gboolean here)
2628 if (client_normal(self) && screen_showing_desktop)
2629 screen_show_desktop(FALSE);
2631 client_iconify(self, FALSE, FALSE);
2632 if (self->desktop != DESKTOP_ALL &&
2633 self->desktop != screen_desktop) {
2635 client_set_desktop(self, screen_desktop, FALSE);
2637 screen_set_desktop(self->desktop);
2638 } else if (!self->frame->visible)
2639 /* if its not visible for other reasons, then don't mess
2643 client_shade(self, FALSE);
2645 stacking_raise(CLIENT_AS_WINDOW(self));
2648 gboolean client_focused(ObClient *self)
2650 return self == focus_client;
2653 ObClientIcon *client_icon(ObClient *self, int w, int h)
2656 /* si is the smallest image >= req */
2657 /* li is the largest image < req */
2658 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2660 for (i = 0; i < self->nicons; ++i) {
2661 size = self->icons[i].width * self->icons[i].height;
2662 if (size < smallest && size >= (unsigned)(w * h)) {
2666 if (size > largest && size <= (unsigned)(w * h)) {
2671 if (largest == 0) /* didnt find one smaller than the requested size */
2672 return &self->icons[si];
2673 return &self->icons[li];
2676 /* this be mostly ripped from fvwm */
2677 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2679 int my_cx, my_cy, his_cx, his_cy;
2682 int score, best_score;
2683 ObClient *best_client, *cur;
2689 /* first, find the centre coords of the currently focused window */
2690 my_cx = c->frame->area.x + c->frame->area.width / 2;
2691 my_cy = c->frame->area.y + c->frame->area.height / 2;
2696 for(it = g_list_first(client_list); it; it = it->next) {
2699 /* the currently selected window isn't interesting */
2702 if (!client_normal(cur))
2704 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2708 if(client_focus_target(cur) == cur &&
2709 !(cur->can_focus || cur->focus_notify))
2712 /* find the centre coords of this window, from the
2713 * currently focused window's point of view */
2714 his_cx = (cur->frame->area.x - my_cx)
2715 + cur->frame->area.width / 2;
2716 his_cy = (cur->frame->area.y - my_cy)
2717 + cur->frame->area.height / 2;
2719 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2720 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2722 /* Rotate the diagonals 45 degrees counterclockwise.
2723 * To do this, multiply the matrix /+h +h\ with the
2724 * vector (x y). \-h +h/
2725 * h = sqrt(0.5). We can set h := 1 since absolute
2726 * distance doesn't matter here. */
2727 tx = his_cx + his_cy;
2728 his_cy = -his_cx + his_cy;
2733 case OB_DIRECTION_NORTH:
2734 case OB_DIRECTION_SOUTH:
2735 case OB_DIRECTION_NORTHEAST:
2736 case OB_DIRECTION_SOUTHWEST:
2737 offset = (his_cx < 0) ? -his_cx : his_cx;
2738 distance = ((dir == OB_DIRECTION_NORTH ||
2739 dir == OB_DIRECTION_NORTHEAST) ?
2742 case OB_DIRECTION_EAST:
2743 case OB_DIRECTION_WEST:
2744 case OB_DIRECTION_SOUTHEAST:
2745 case OB_DIRECTION_NORTHWEST:
2746 offset = (his_cy < 0) ? -his_cy : his_cy;
2747 distance = ((dir == OB_DIRECTION_WEST ||
2748 dir == OB_DIRECTION_NORTHWEST) ?
2753 /* the target must be in the requested direction */
2757 /* Calculate score for this window. The smaller the better. */
2758 score = distance + offset;
2760 /* windows more than 45 degrees off the direction are
2761 * heavily penalized and will only be chosen if nothing
2762 * else within a million pixels */
2763 if(offset > distance)
2766 if(best_score == -1 || score < best_score)
2774 void client_set_layer(ObClient *self, int layer)
2778 self->above = FALSE;
2779 } else if (layer == 0) {
2780 self->below = self->above = FALSE;
2782 self->below = FALSE;
2785 client_calc_layer(self);
2786 client_change_state(self); /* reflect this in the state hints */
2789 guint client_monitor(ObClient *self)
2793 for (i = 0; i < screen_num_monitors; ++i) {
2794 Rect *area = screen_physical_area_monitor(i);
2795 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2798 if (i == screen_num_monitors) i = 0;
2799 g_assert(i < screen_num_monitors);
2803 ObClient *client_search_top_transient(ObClient *self)
2805 /* move up the transient chain as far as possible */
2806 if (self->transient_for) {
2807 if (self->transient_for != OB_TRAN_GROUP) {
2808 return client_search_top_transient(self->transient_for);
2812 for (it = self->group->members; it; it = it->next) {
2813 ObClient *c = it->data;
2815 /* checking transient_for prevents infinate loops! */
2816 if (c != self && !c->transient_for)
2827 ObClient *client_search_transient(ObClient *self, ObClient *search)
2831 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2832 if (sit->data == search)
2834 if (client_search_transient(sit->data, search))
2840 void client_update_sm_client_id(ObClient *self)
2842 g_free(self->sm_client_id);
2843 self->sm_client_id = NULL;
2845 if (!PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id) &&
2847 PROP_GETS(self->group->leader, sm_client_id, locale,
2848 &self->sm_client_id);
2851 /* finds the nearest edge in the given direction from the current client
2852 * note to self: the edge is the -frame- edge (the actual one), not the
2855 int client_directional_edge_search(ObClient *c, ObDirection dir)
2858 int my_edge_start, my_edge_end, my_offset;
2865 a = screen_area(c->desktop);
2868 case OB_DIRECTION_NORTH:
2869 my_edge_start = c->frame->area.x;
2870 my_edge_end = c->frame->area.x + c->frame->area.width;
2871 my_offset = c->frame->area.y;
2873 dest = a->y; /* default: top of screen */
2875 for(it = g_list_first(client_list); it; it = it->next) {
2876 int his_edge_start, his_edge_end, his_offset;
2877 ObClient *cur = it->data;
2881 if(!client_normal(cur))
2883 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2888 his_edge_start = cur->frame->area.x;
2889 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2890 his_offset = cur->frame->area.y + cur->frame->area.height;
2892 if(his_offset + 1 > my_offset)
2895 if(his_offset < dest)
2898 if(his_edge_start >= my_edge_start &&
2899 his_edge_start <= my_edge_end)
2902 if(my_edge_start >= his_edge_start &&
2903 my_edge_start <= his_edge_end)
2908 case OB_DIRECTION_SOUTH:
2909 my_edge_start = c->frame->area.x;
2910 my_edge_end = c->frame->area.x + c->frame->area.width;
2911 my_offset = c->frame->area.y + c->frame->area.height;
2913 dest = a->y + a->height; /* default: bottom of screen */
2915 for(it = g_list_first(client_list); it; it = it->next) {
2916 int his_edge_start, his_edge_end, his_offset;
2917 ObClient *cur = it->data;
2921 if(!client_normal(cur))
2923 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2928 his_edge_start = cur->frame->area.x;
2929 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2930 his_offset = cur->frame->area.y;
2933 if(his_offset - 1 < my_offset)
2936 if(his_offset > dest)
2939 if(his_edge_start >= my_edge_start &&
2940 his_edge_start <= my_edge_end)
2943 if(my_edge_start >= his_edge_start &&
2944 my_edge_start <= his_edge_end)
2949 case OB_DIRECTION_WEST:
2950 my_edge_start = c->frame->area.y;
2951 my_edge_end = c->frame->area.y + c->frame->area.height;
2952 my_offset = c->frame->area.x;
2954 dest = a->x; /* default: leftmost egde of screen */
2956 for(it = g_list_first(client_list); it; it = it->next) {
2957 int his_edge_start, his_edge_end, his_offset;
2958 ObClient *cur = it->data;
2962 if(!client_normal(cur))
2964 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2969 his_edge_start = cur->frame->area.y;
2970 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2971 his_offset = cur->frame->area.x + cur->frame->area.width;
2973 if(his_offset + 1 > my_offset)
2976 if(his_offset < dest)
2979 if(his_edge_start >= my_edge_start &&
2980 his_edge_start <= my_edge_end)
2983 if(my_edge_start >= his_edge_start &&
2984 my_edge_start <= his_edge_end)
2990 case OB_DIRECTION_EAST:
2991 my_edge_start = c->frame->area.y;
2992 my_edge_end = c->frame->area.y + c->frame->area.height;
2993 my_offset = c->frame->area.x + c->frame->area.width;
2995 dest = a->x + a->width; /* default: rightmost edge of screen */
2997 for(it = g_list_first(client_list); it; it = it->next) {
2998 int his_edge_start, his_edge_end, his_offset;
2999 ObClient *cur = it->data;
3003 if(!client_normal(cur))
3005 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
3010 his_edge_start = cur->frame->area.y;
3011 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3012 his_offset = cur->frame->area.x;
3014 if(his_offset - 1 < my_offset)
3017 if(his_offset > dest)
3020 if(his_edge_start >= my_edge_start &&
3021 his_edge_start <= my_edge_end)
3024 if(my_edge_start >= his_edge_start &&
3025 my_edge_start <= his_edge_end)
3030 case OB_DIRECTION_NORTHEAST:
3031 case OB_DIRECTION_SOUTHEAST:
3032 case OB_DIRECTION_NORTHWEST:
3033 case OB_DIRECTION_SOUTHWEST:
3034 /* not implemented */
3036 g_assert_not_reached();
3041 ObClient* client_under_pointer()
3045 ObClient *ret = NULL;
3047 if (screen_pointer_pos(&x, &y)) {
3048 for (it = stacking_list; it != NULL; it = it->next) {
3049 if (WINDOW_IS_CLIENT(it->data)) {
3050 ObClient *c = WINDOW_AS_CLIENT(it->data);
3051 if (c->desktop == screen_desktop &&
3052 RECT_CONTAINS(c->frame->area, x, y)) {