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]);
187 if (config_focus_new)
188 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
191 void client_manage(Window window)
195 XWindowAttributes attrib;
196 XSetWindowAttributes attrib_set;
198 gboolean activate = FALSE;
202 /* check if it has already been unmapped by the time we started mapping
203 the grab does a sync so we don't have to here */
204 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
205 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
206 XPutBackEvent(ob_display, &e);
209 return; /* don't manage it */
212 /* make sure it isn't an override-redirect window */
213 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
214 attrib.override_redirect) {
216 return; /* don't manage it */
219 /* is the window a docking app */
220 if ((wmhint = XGetWMHints(ob_display, window))) {
221 if ((wmhint->flags & StateHint) &&
222 wmhint->initial_state == WithdrawnState) {
223 dock_add(window, wmhint);
231 ob_debug("Managing window: %lx\n", window);
233 /* choose the events we want to receive on the CLIENT window */
234 attrib_set.event_mask = CLIENT_EVENTMASK;
235 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
236 XChangeWindowAttributes(ob_display, window,
237 CWEventMask|CWDontPropagate, &attrib_set);
240 /* create the ObClient struct, and populate it from the hints on the
242 self = g_new0(ObClient, 1);
243 self->obwin.type = Window_Client;
244 self->window = window;
246 /* non-zero defaults */
247 self->title_count = 1;
248 self->wmstate = NormalState;
250 self->decorate = TRUE;
251 self->desktop = screen_num_desktops; /* always an invalid value */
253 client_get_all(self);
254 client_restore_session_state(self);
256 sn_app_started(self->class);
258 client_change_state(self);
260 /* remove the client's border (and adjust re gravity) */
261 client_toggle_border(self, FALSE);
263 /* specify that if we exit, the window should not be destroyed and should
264 be reparented back to root automatically */
265 XChangeSaveSet(ob_display, window, SetModeInsert);
267 /* create the decoration frame for the client window */
268 self->frame = frame_new();
270 frame_grab_client(self->frame, self);
274 client_apply_startup_state(self);
276 /* update the focus lists */
277 focus_order_add_new(self);
279 stacking_add(CLIENT_AS_WINDOW(self));
280 client_restore_session_stacking(self);
282 /* focus the new window? */
283 if (ob_state() != OB_STATE_STARTING && config_focus_new &&
284 /* note the check against Type_Normal/Dialog, not client_normal(self),
285 which would also include other types. in this case we want more
286 strict rules for focus */
287 (self->type == OB_CLIENT_TYPE_NORMAL ||
288 self->type == OB_CLIENT_TYPE_DIALOG))
292 if (self->desktop != screen_desktop) {
293 /* activate the window */
296 gboolean group_foc = FALSE;
301 for (it = self->group->members; it; it = it->next)
303 if (client_focused(it->data))
311 (!self->transient_for && (!self->group ||
312 !self->group->members->next))) ||
313 client_search_focus_tree_full(self) ||
315 !client_normal(focus_client))
317 /* activate the window */
324 if (ob_state() == OB_STATE_RUNNING) {
325 int x = self->area.x, ox = x;
326 int y = self->area.y, oy = y;
328 place_client(self, &x, &y);
330 /* make sure the window is visible */
331 client_find_onscreen(self, &x, &y,
332 self->frame->area.width,
333 self->frame->area.height,
334 client_normal(self));
336 if (x != ox || y != oy)
337 client_move(self, x, y);
340 client_showhide(self);
342 /* use client_focus instead of client_activate cuz client_activate does
343 stuff like switch desktops etc and I'm not interested in all that when
344 a window maps since its not based on an action from the user like
345 clicking a window to activate is. so keep the new window out of the way
347 if (activate) client_focus(self);
349 /* client_activate does this but we aret using it so we have to do it
351 if (screen_showing_desktop)
352 screen_show_desktop(FALSE);
354 /* add to client list/map */
355 client_list = g_list_append(client_list, self);
356 g_hash_table_insert(window_map, &self->window, self);
358 /* this has to happen after we're in the client_list */
359 screen_update_areas();
361 /* update the list hints */
364 keyboard_grab_for_client(self, TRUE);
365 mouse_grab_for_client(self, TRUE);
367 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
370 void client_unmanage_all()
372 while (client_list != NULL)
373 client_unmanage(client_list->data);
376 void client_unmanage(ObClient *self)
381 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
383 g_assert(self != NULL);
385 keyboard_grab_for_client(self, FALSE);
386 mouse_grab_for_client(self, FALSE);
388 /* remove the window from our save set */
389 XChangeSaveSet(ob_display, self->window, SetModeDelete);
391 /* we dont want events no more */
392 XSelectInput(ob_display, self->window, NoEventMask);
394 frame_hide(self->frame);
396 client_list = g_list_remove(client_list, self);
397 stacking_remove(self);
398 g_hash_table_remove(window_map, &self->window);
400 /* update the focus lists */
401 focus_order_remove(self);
403 /* once the client is out of the list, update the struts to remove it's
405 screen_update_areas();
407 /* tell our parent(s) that we're gone */
408 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
411 for (it = self->group->members; it; it = it->next)
412 if (it->data != self)
413 ((ObClient*)it->data)->transients =
414 g_slist_remove(((ObClient*)it->data)->transients, self);
415 } else if (self->transient_for) { /* transient of window */
416 self->transient_for->transients =
417 g_slist_remove(self->transient_for->transients, self);
420 /* tell our transients that we're gone */
421 for (it = self->transients; it != NULL; it = it->next) {
422 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
423 ((ObClient*)it->data)->transient_for = NULL;
424 client_calc_layer(it->data);
428 for (it = client_destructors; it; it = g_slist_next(it)) {
429 GDestroyNotify func = (GDestroyNotify) it->data;
433 if (focus_client == self) {
436 /* focus the last focused window on the desktop, and ignore enter
437 events from the unmap so it doesnt mess with the focus */
438 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
439 client_unfocus(self);
442 /* remove from its group */
444 group_remove(self->group, self);
448 /* give the client its border back */
449 client_toggle_border(self, TRUE);
451 /* reparent the window out of the frame, and free the frame */
452 frame_release_client(self->frame, self);
455 if (ob_state() != OB_STATE_EXITING) {
456 /* these values should not be persisted across a window
458 PROP_ERASE(self->window, net_wm_desktop);
459 PROP_ERASE(self->window, net_wm_state);
460 PROP_ERASE(self->window, wm_state);
462 /* if we're left in an iconic state, the client wont be mapped. this is
463 bad, since we will no longer be managing the window on restart */
465 XMapWindow(ob_display, self->window);
469 ob_debug("Unmanaged window 0x%lx\n", self->window);
471 /* free all data allocated in the client struct */
472 g_slist_free(self->transients);
473 for (j = 0; j < self->nicons; ++j)
474 g_free(self->icons[j].data);
475 if (self->nicons > 0)
478 g_free(self->icon_title);
482 g_free(self->sm_client_id);
485 /* update the list hints */
489 static void client_urgent_notify(ObClient *self)
492 frame_flash_start(self->frame);
494 frame_flash_stop(self->frame);
497 static void client_restore_session_state(ObClient *self)
501 if (!(it = session_state_find(self)))
504 self->session = it->data;
506 RECT_SET(self->area, self->session->x, self->session->y,
507 self->session->w, self->session->h);
508 self->positioned = TRUE;
509 XResizeWindow(ob_display, self->window,
510 self->session->w, self->session->h);
512 self->desktop = (self->session->desktop == DESKTOP_ALL ?
513 self->session->desktop :
514 MIN(screen_num_desktops - 1, self->session->desktop));
515 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
517 self->shaded = self->session->shaded;
518 self->iconic = self->session->iconic;
519 self->skip_pager = self->session->skip_pager;
520 self->skip_taskbar = self->session->skip_taskbar;
521 self->fullscreen = self->session->fullscreen;
522 self->above = self->session->above;
523 self->below = self->session->below;
524 self->max_horz = self->session->max_horz;
525 self->max_vert = self->session->max_vert;
528 static void client_restore_session_stacking(ObClient *self)
532 if (!self->session) return;
534 it = g_list_find(session_saved_state, self->session);
535 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
538 for (cit = client_list; cit; cit = g_list_next(cit))
539 if (session_state_cmp(it->data, cit->data))
542 client_calc_layer(self);
543 stacking_below(CLIENT_AS_WINDOW(self),
544 CLIENT_AS_WINDOW(cit->data));
550 void client_move_onscreen(ObClient *self, gboolean rude)
552 int x = self->area.x;
553 int y = self->area.y;
554 if (client_find_onscreen(self, &x, &y,
555 self->frame->area.width,
556 self->frame->area.height, rude)) {
557 client_move(self, x, y);
561 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
565 int ox = *x, oy = *y;
567 frame_client_gravity(self->frame, x, y); /* get where the frame
570 /* XXX watch for xinerama dead areas */
572 a = screen_area(self->desktop);
573 if (client_normal(self)) {
574 if (!self->strut.right && *x >= a->x + a->width - 1)
575 *x = a->x + a->width - self->frame->area.width;
576 if (!self->strut.bottom && *y >= a->y + a->height - 1)
577 *y = a->y + a->height - self->frame->area.height;
578 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
580 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
585 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
586 Java can suck it too. */
588 /* dont let windows map/move into the strut unless they
589 are bigger than the available area */
591 if (!self->strut.left && *x < a->x) *x = a->x;
592 if (!self->strut.right && *x + w > a->x + a->width)
593 *x = a->x + a->width - w;
595 if (h <= a->height) {
596 if (!self->strut.top && *y < a->y) *y = a->y;
597 if (!self->strut.bottom && *y + h > a->y + a->height)
598 *y = a->y + a->height - h;
602 frame_frame_gravity(self->frame, x, y); /* get where the client
605 return ox != *x || oy != *y;
608 static void client_toggle_border(ObClient *self, gboolean show)
610 /* adjust our idea of where the client is, based on its border. When the
611 border is removed, the client should now be considered to be in a
613 when re-adding the border to the client, the same operation needs to be
615 int oldx = self->area.x, oldy = self->area.y;
616 int x = oldx, y = oldy;
617 switch(self->gravity) {
619 case NorthWestGravity:
621 case SouthWestGravity:
623 case NorthEastGravity:
625 case SouthEastGravity:
626 if (show) x -= self->border_width * 2;
627 else x += self->border_width * 2;
634 if (show) x -= self->border_width;
635 else x += self->border_width;
638 switch(self->gravity) {
640 case NorthWestGravity:
642 case NorthEastGravity:
644 case SouthWestGravity:
646 case SouthEastGravity:
647 if (show) y -= self->border_width * 2;
648 else y += self->border_width * 2;
655 if (show) y -= self->border_width;
656 else y += self->border_width;
663 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
665 /* move the client so it is back it the right spot _with_ its
667 if (x != oldx || y != oldy)
668 XMoveWindow(ob_display, self->window, x, y);
670 XSetWindowBorderWidth(ob_display, self->window, 0);
674 static void client_get_all(ObClient *self)
676 client_get_area(self);
677 client_update_transient_for(self);
678 client_update_wmhints(self);
679 client_get_startup_id(self);
680 client_get_desktop(self);
681 client_get_state(self);
682 client_get_shaped(self);
684 client_get_mwm_hints(self);
685 client_get_type(self);/* this can change the mwmhints for special cases */
687 client_update_protocols(self);
689 client_get_gravity(self); /* get the attribute gravity */
690 client_update_normal_hints(self); /* this may override the attribute
693 /* got the type, the mwmhints, the protocols, and the normal hints
694 (min/max sizes), so we're ready to set up the decorations/functions */
695 client_setup_decor_and_functions(self);
697 client_update_title(self);
698 client_update_class(self);
699 client_update_sm_client_id(self);
700 client_update_strut(self);
701 client_update_icons(self);
704 static void client_get_startup_id(ObClient *self)
706 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
708 PROP_GETS(self->group->leader,
709 net_startup_id, utf8, &self->startup_id);
712 static void client_get_area(ObClient *self)
714 XWindowAttributes wattrib;
717 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
718 g_assert(ret != BadWindow);
720 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
721 self->border_width = wattrib.border_width;
724 static void client_get_desktop(ObClient *self)
726 guint32 d = screen_num_desktops; /* an always-invalid value */
728 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
729 if (d >= screen_num_desktops && d != DESKTOP_ALL)
730 self->desktop = screen_num_desktops - 1;
734 gboolean trdesk = FALSE;
736 if (self->transient_for) {
737 if (self->transient_for != OB_TRAN_GROUP) {
738 self->desktop = self->transient_for->desktop;
743 for (it = self->group->members; it; it = it->next)
744 if (it->data != self &&
745 !((ObClient*)it->data)->transient_for) {
746 self->desktop = ((ObClient*)it->data)->desktop;
753 /* try get from the startup-notification protocol */
754 if (sn_get_desktop(self->startup_id, &self->desktop)) {
755 if (self->desktop >= screen_num_desktops &&
756 self->desktop != DESKTOP_ALL)
757 self->desktop = screen_num_desktops - 1;
759 /* defaults to the current desktop */
760 self->desktop = screen_desktop;
763 if (self->desktop != d) {
764 /* set the desktop hint, to make sure that it always exists */
765 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
769 static void client_get_state(ObClient *self)
774 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
776 for (i = 0; i < num; ++i) {
777 if (state[i] == prop_atoms.net_wm_state_modal)
779 else if (state[i] == prop_atoms.net_wm_state_shaded)
781 else if (state[i] == prop_atoms.net_wm_state_hidden)
783 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
784 self->skip_taskbar = TRUE;
785 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
786 self->skip_pager = TRUE;
787 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
788 self->fullscreen = TRUE;
789 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
790 self->max_vert = TRUE;
791 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
792 self->max_horz = TRUE;
793 else if (state[i] == prop_atoms.net_wm_state_above)
795 else if (state[i] == prop_atoms.net_wm_state_below)
803 static void client_get_shaped(ObClient *self)
805 self->shaped = FALSE;
807 if (extensions_shape) {
812 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
814 XShapeQueryExtents(ob_display, self->window, &s, &foo,
815 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
817 self->shaped = (s != 0);
822 void client_update_transient_for(ObClient *self)
825 ObClient *target = NULL;
827 if (XGetTransientForHint(ob_display, self->window, &t)) {
828 self->transient = TRUE;
829 if (t != self->window) { /* cant be transient to itself! */
830 target = g_hash_table_lookup(window_map, &t);
831 /* if this happens then we need to check for it*/
832 g_assert(target != self);
833 if (target && !WINDOW_IS_CLIENT(target)) {
834 /* this can happen when a dialog is a child of
835 a dockapp, for example */
839 if (!target && self->group) {
840 /* not transient to a client, see if it is transient for a
842 if (t == self->group->leader ||
844 t == RootWindow(ob_display, ob_screen)) {
845 /* window is a transient for its group! */
846 target = OB_TRAN_GROUP;
851 self->transient = FALSE;
853 /* if anything has changed... */
854 if (target != self->transient_for) {
855 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
858 /* remove from old parents */
859 for (it = self->group->members; it; it = g_slist_next(it)) {
860 ObClient *c = it->data;
861 if (c != self && !c->transient_for)
862 c->transients = g_slist_remove(c->transients, self);
864 } else if (self->transient_for != NULL) { /* transient of window */
865 /* remove from old parent */
866 self->transient_for->transients =
867 g_slist_remove(self->transient_for->transients, self);
869 self->transient_for = target;
870 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
873 /* add to new parents */
874 for (it = self->group->members; it; it = g_slist_next(it)) {
875 ObClient *c = it->data;
876 if (c != self && !c->transient_for)
877 c->transients = g_slist_append(c->transients, self);
880 /* remove all transients which are in the group, that causes
881 circlular pointer hell of doom */
882 for (it = self->group->members; it; it = g_slist_next(it)) {
884 for (sit = self->transients; sit; sit = next) {
885 next = g_slist_next(sit);
886 if (sit->data == it->data)
888 g_slist_delete_link(self->transients, sit);
891 } else if (self->transient_for != NULL) { /* transient of window */
892 /* add to new parent */
893 self->transient_for->transients =
894 g_slist_append(self->transient_for->transients, self);
899 static void client_get_mwm_hints(ObClient *self)
904 self->mwmhints.flags = 0; /* default to none */
906 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
908 if (num >= OB_MWM_ELEMENTS) {
909 self->mwmhints.flags = hints[0];
910 self->mwmhints.functions = hints[1];
911 self->mwmhints.decorations = hints[2];
917 void client_get_type(ObClient *self)
924 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
925 /* use the first value that we know about in the array */
926 for (i = 0; i < num; ++i) {
927 if (val[i] == prop_atoms.net_wm_window_type_desktop)
928 self->type = OB_CLIENT_TYPE_DESKTOP;
929 else if (val[i] == prop_atoms.net_wm_window_type_dock)
930 self->type = OB_CLIENT_TYPE_DOCK;
931 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
932 self->type = OB_CLIENT_TYPE_TOOLBAR;
933 else if (val[i] == prop_atoms.net_wm_window_type_menu)
934 self->type = OB_CLIENT_TYPE_MENU;
935 else if (val[i] == prop_atoms.net_wm_window_type_utility)
936 self->type = OB_CLIENT_TYPE_UTILITY;
937 else if (val[i] == prop_atoms.net_wm_window_type_splash)
938 self->type = OB_CLIENT_TYPE_SPLASH;
939 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
940 self->type = OB_CLIENT_TYPE_DIALOG;
941 else if (val[i] == prop_atoms.net_wm_window_type_normal)
942 self->type = OB_CLIENT_TYPE_NORMAL;
943 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
944 /* prevent this window from getting any decor or
946 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
947 OB_MWM_FLAG_DECORATIONS);
948 self->mwmhints.decorations = 0;
949 self->mwmhints.functions = 0;
951 if (self->type != (ObClientType) -1)
952 break; /* grab the first legit type */
957 if (self->type == (ObClientType) -1) {
958 /*the window type hint was not set, which means we either classify
959 ourself as a normal window or a dialog, depending on if we are a
962 self->type = OB_CLIENT_TYPE_DIALOG;
964 self->type = OB_CLIENT_TYPE_NORMAL;
968 void client_update_protocols(ObClient *self)
973 self->focus_notify = FALSE;
974 self->delete_window = FALSE;
976 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
977 for (i = 0; i < num_return; ++i) {
978 if (proto[i] == prop_atoms.wm_delete_window) {
979 /* this means we can request the window to close */
980 self->delete_window = TRUE;
981 } else if (proto[i] == prop_atoms.wm_take_focus)
982 /* if this protocol is requested, then the window will be
983 notified whenever we want it to receive focus */
984 self->focus_notify = TRUE;
990 static void client_get_gravity(ObClient *self)
992 XWindowAttributes wattrib;
995 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
996 g_assert(ret != BadWindow);
997 self->gravity = wattrib.win_gravity;
1000 void client_update_normal_hints(ObClient *self)
1004 int oldgravity = self->gravity;
1007 self->min_ratio = 0.0f;
1008 self->max_ratio = 0.0f;
1009 SIZE_SET(self->size_inc, 1, 1);
1010 SIZE_SET(self->base_size, 0, 0);
1011 SIZE_SET(self->min_size, 0, 0);
1012 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1014 /* get the hints from the window */
1015 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1016 self->positioned = !!(size.flags & (PPosition|USPosition));
1018 if (size.flags & PWinGravity) {
1019 self->gravity = size.win_gravity;
1021 /* if the client has a frame, i.e. has already been mapped and
1022 is changing its gravity */
1023 if (self->frame && self->gravity != oldgravity) {
1024 /* move our idea of the client's position based on its new
1026 self->area.x = self->frame->area.x;
1027 self->area.y = self->frame->area.y;
1028 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1032 if (size.flags & PAspect) {
1033 if (size.min_aspect.y)
1034 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
1035 if (size.max_aspect.y)
1036 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
1039 if (size.flags & PMinSize)
1040 SIZE_SET(self->min_size, size.min_width, size.min_height);
1042 if (size.flags & PMaxSize)
1043 SIZE_SET(self->max_size, size.max_width, size.max_height);
1045 if (size.flags & PBaseSize)
1046 SIZE_SET(self->base_size, size.base_width, size.base_height);
1048 if (size.flags & PResizeInc)
1049 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1053 void client_setup_decor_and_functions(ObClient *self)
1055 /* start with everything (cept fullscreen) */
1057 (OB_FRAME_DECOR_TITLEBAR |
1058 (ob_rr_theme->show_handle ? OB_FRAME_DECOR_HANDLE : 0) |
1059 OB_FRAME_DECOR_GRIPS |
1060 OB_FRAME_DECOR_BORDER |
1061 OB_FRAME_DECOR_ICON |
1062 OB_FRAME_DECOR_ALLDESKTOPS |
1063 OB_FRAME_DECOR_ICONIFY |
1064 OB_FRAME_DECOR_MAXIMIZE |
1065 OB_FRAME_DECOR_SHADE);
1067 (OB_CLIENT_FUNC_RESIZE |
1068 OB_CLIENT_FUNC_MOVE |
1069 OB_CLIENT_FUNC_ICONIFY |
1070 OB_CLIENT_FUNC_MAXIMIZE |
1071 OB_CLIENT_FUNC_SHADE);
1072 if (self->delete_window) {
1073 self->functions |= OB_CLIENT_FUNC_CLOSE;
1074 self->decorations |= OB_FRAME_DECOR_CLOSE;
1077 if (!(self->min_size.width < self->max_size.width ||
1078 self->min_size.height < self->max_size.height))
1079 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1081 switch (self->type) {
1082 case OB_CLIENT_TYPE_NORMAL:
1083 /* normal windows retain all of the possible decorations and
1084 functionality, and are the only windows that you can fullscreen */
1085 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1088 case OB_CLIENT_TYPE_DIALOG:
1089 case OB_CLIENT_TYPE_UTILITY:
1090 /* these windows cannot be maximized */
1091 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1094 case OB_CLIENT_TYPE_MENU:
1095 case OB_CLIENT_TYPE_TOOLBAR:
1096 /* these windows get less functionality */
1097 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1100 case OB_CLIENT_TYPE_DESKTOP:
1101 case OB_CLIENT_TYPE_DOCK:
1102 case OB_CLIENT_TYPE_SPLASH:
1103 /* none of these windows are manipulated by the window manager */
1104 self->decorations = 0;
1105 self->functions = 0;
1109 /* Mwm Hints are applied subtractively to what has already been chosen for
1110 decor and functionality */
1111 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1112 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1113 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1114 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1115 /* if the mwm hints request no handle or title, then all
1116 decorations are disabled */
1117 self->decorations = 0;
1121 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1122 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1123 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1124 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1125 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1126 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1127 /* dont let mwm hints kill any buttons
1128 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1129 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1130 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1131 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1133 /* dont let mwm hints kill the close button
1134 if (! (self->mwmhints.functions & MwmFunc_Close))
1135 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1139 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1140 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1141 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1142 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1143 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1144 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1146 /* can't maximize without moving/resizing */
1147 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1148 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1149 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1150 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1151 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1154 /* kill the handle on fully maxed windows */
1155 if (self->max_vert && self->max_horz)
1156 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1158 /* finally, the user can have requested no decorations, which overrides
1160 if (!self->decorate)
1161 self->decorations = OB_FRAME_DECOR_BORDER;
1163 /* if we don't have a titlebar, then we cannot shade! */
1164 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1165 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1167 /* now we need to check against rules for the client's current state */
1168 if (self->fullscreen) {
1169 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1170 OB_CLIENT_FUNC_FULLSCREEN |
1171 OB_CLIENT_FUNC_ICONIFY);
1172 self->decorations = 0;
1175 client_change_allowed_actions(self);
1178 /* adjust the client's decorations, etc. */
1179 client_reconfigure(self);
1181 /* this makes sure that these windows appear on all desktops */
1182 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1183 self->desktop != DESKTOP_ALL)
1185 self->desktop = DESKTOP_ALL;
1190 static void client_change_allowed_actions(ObClient *self)
1195 /* desktop windows are kept on all desktops */
1196 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1197 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1199 if (self->functions & OB_CLIENT_FUNC_SHADE)
1200 actions[num++] = prop_atoms.net_wm_action_shade;
1201 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1202 actions[num++] = prop_atoms.net_wm_action_close;
1203 if (self->functions & OB_CLIENT_FUNC_MOVE)
1204 actions[num++] = prop_atoms.net_wm_action_move;
1205 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1206 actions[num++] = prop_atoms.net_wm_action_minimize;
1207 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1208 actions[num++] = prop_atoms.net_wm_action_resize;
1209 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1210 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1211 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1212 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1213 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1216 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1218 /* make sure the window isn't breaking any rules now */
1220 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1221 if (self->frame) client_shade(self, FALSE);
1222 else self->shaded = FALSE;
1224 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1225 if (self->frame) client_iconify(self, FALSE, TRUE);
1226 else self->iconic = FALSE;
1228 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1229 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1230 else self->fullscreen = FALSE;
1232 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1234 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1235 else self->max_vert = self->max_horz = FALSE;
1239 void client_reconfigure(ObClient *self)
1241 /* by making this pass FALSE for user, we avoid the emacs event storm where
1242 every configurenotify causes an update in its normal hints, i think this
1243 is generally what we want anyways... */
1244 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1245 self->area.width, self->area.height, FALSE, TRUE);
1248 void client_update_wmhints(ObClient *self)
1251 gboolean ur = FALSE;
1254 /* assume a window takes input if it doesnt specify */
1255 self->can_focus = TRUE;
1257 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1258 if (hints->flags & InputHint)
1259 self->can_focus = hints->input;
1261 /* only do this when first managing the window *AND* when we aren't
1263 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1264 if (hints->flags & StateHint)
1265 self->iconic = hints->initial_state == IconicState;
1267 if (hints->flags & XUrgencyHint)
1270 if (!(hints->flags & WindowGroupHint))
1271 hints->window_group = None;
1273 /* did the group state change? */
1274 if (hints->window_group !=
1275 (self->group ? self->group->leader : None)) {
1276 /* remove from the old group if there was one */
1277 if (self->group != NULL) {
1278 /* remove transients of the group */
1279 for (it = self->group->members; it; it = it->next)
1280 self->transients = g_slist_remove(self->transients,
1282 group_remove(self->group, self);
1285 if (hints->window_group != None) {
1286 self->group = group_add(hints->window_group, self);
1288 /* i can only have transients from the group if i am not
1290 if (!self->transient_for) {
1291 /* add other transients of the group that are already
1293 for (it = self->group->members; it; it = it->next) {
1294 ObClient *c = it->data;
1295 if (c != self && c->transient_for == OB_TRAN_GROUP)
1297 g_slist_append(self->transients, c);
1302 /* because the self->transient flag wont change from this call,
1303 we don't need to update the window's type and such, only its
1304 transient_for, and the transients lists of other windows in
1305 the group may be affected */
1306 client_update_transient_for(self);
1309 /* the WM_HINTS can contain an icon */
1310 client_update_icons(self);
1315 if (ur != self->urgent) {
1317 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1319 /* fire the urgent callback if we're mapped, otherwise, wait until
1320 after we're mapped */
1322 client_urgent_notify(self);
1326 void client_update_title(ObClient *self)
1332 gboolean read_title;
1335 old_title = self->title;
1338 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1339 /* try old x stuff */
1340 if (!PROP_GETS(self->window, wm_name, locale, &data))
1341 data = g_strdup("Unnamed Window");
1343 /* did the title change? then reset the title_count */
1344 if (old_title && 0 != strncmp(old_title, data, strlen(data)))
1345 self->title_count = 1;
1347 /* look for duplicates and append a number */
1349 for (it = client_list; it; it = it->next)
1350 if (it->data != self) {
1351 ObClient *c = it->data;
1352 if (0 == strncmp(c->title, data, strlen(data)))
1353 nums |= 1 << c->title_count;
1355 /* find first free number */
1356 for (i = 1; i <= 32; ++i)
1357 if (!(nums & (1 << i))) {
1358 if (self->title_count == 1 || i == 1)
1359 self->title_count = i;
1362 /* dont display the number for the first window */
1363 if (self->title_count > 1) {
1365 ndata = g_strdup_printf("%s - [%u]", data, self->title_count);
1370 PROP_SETS(self->window, net_wm_visible_name, data);
1375 frame_adjust_title(self->frame);
1379 /* update the icon title */
1381 g_free(self->icon_title);
1385 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1386 /* try old x stuff */
1387 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1388 data = g_strdup(self->title);
1392 /* append the title count, dont display the number for the first window */
1393 if (read_title && self->title_count > 1) {
1394 char *vdata, *ndata;
1395 ndata = g_strdup_printf(" - [%u]", self->title_count);
1396 vdata = g_strconcat(data, ndata, NULL);
1402 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1404 self->icon_title = data;
1407 void client_update_class(ObClient *self)
1412 if (self->name) g_free(self->name);
1413 if (self->class) g_free(self->class);
1414 if (self->role) g_free(self->role);
1416 self->name = self->class = self->role = NULL;
1418 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1420 self->name = g_strdup(data[0]);
1422 self->class = g_strdup(data[1]);
1427 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1430 if (self->name == NULL) self->name = g_strdup("");
1431 if (self->class == NULL) self->class = g_strdup("");
1432 if (self->role == NULL) self->role = g_strdup("");
1435 void client_update_strut(ObClient *self)
1439 gboolean got = FALSE;
1442 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1446 STRUT_PARTIAL_SET(strut,
1447 data[0], data[2], data[1], data[3],
1448 data[4], data[5], data[8], data[9],
1449 data[6], data[7], data[10], data[11]);
1455 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1458 STRUT_PARTIAL_SET(strut,
1459 data[0], data[2], data[1], data[3],
1460 0, 0, 0, 0, 0, 0, 0, 0);
1466 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1467 0, 0, 0, 0, 0, 0, 0, 0);
1469 if (!STRUT_EQUAL(strut, self->strut)) {
1470 self->strut = strut;
1472 /* updating here is pointless while we're being mapped cuz we're not in
1473 the client list yet */
1475 screen_update_areas();
1479 void client_update_icons(ObClient *self)
1485 for (i = 0; i < self->nicons; ++i)
1486 g_free(self->icons[i].data);
1487 if (self->nicons > 0)
1488 g_free(self->icons);
1491 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1492 /* figure out how many valid icons are in here */
1494 while (num - i > 2) {
1498 if (i > num || w*h == 0) break;
1502 self->icons = g_new(ObClientIcon, self->nicons);
1504 /* store the icons */
1506 for (j = 0; j < self->nicons; ++j) {
1509 w = self->icons[j].width = data[i++];
1510 h = self->icons[j].height = data[i++];
1512 if (w*h == 0) continue;
1514 self->icons[j].data = g_new(RrPixel32, w * h);
1515 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1520 self->icons[j].data[t] =
1521 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1522 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1523 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1524 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1530 } else if (PROP_GETA32(self->window, kwm_win_icon,
1531 kwm_win_icon, &data, &num)) {
1534 self->icons = g_new(ObClientIcon, self->nicons);
1535 xerror_set_ignore(TRUE);
1536 if (!RrPixmapToRGBA(ob_rr_inst,
1538 &self->icons[self->nicons-1].width,
1539 &self->icons[self->nicons-1].height,
1540 &self->icons[self->nicons-1].data)) {
1541 g_free(&self->icons[self->nicons-1]);
1544 xerror_set_ignore(FALSE);
1550 if ((hints = XGetWMHints(ob_display, self->window))) {
1551 if (hints->flags & IconPixmapHint) {
1553 self->icons = g_new(ObClientIcon, self->nicons);
1554 xerror_set_ignore(TRUE);
1555 if (!RrPixmapToRGBA(ob_rr_inst,
1557 (hints->flags & IconMaskHint ?
1558 hints->icon_mask : None),
1559 &self->icons[self->nicons-1].width,
1560 &self->icons[self->nicons-1].height,
1561 &self->icons[self->nicons-1].data)){
1562 g_free(&self->icons[self->nicons-1]);
1565 xerror_set_ignore(FALSE);
1571 if (!self->nicons) {
1573 self->icons = g_new(ObClientIcon, self->nicons);
1574 self->icons[self->nicons-1].width = 48;
1575 self->icons[self->nicons-1].height = 48;
1576 self->icons[self->nicons-1].data = g_memdup(ob_rr_theme->def_win_icon,
1582 frame_adjust_icon(self->frame);
1585 static void client_change_state(ObClient *self)
1588 guint32 netstate[10];
1591 state[0] = self->wmstate;
1593 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1597 netstate[num++] = prop_atoms.net_wm_state_modal;
1599 netstate[num++] = prop_atoms.net_wm_state_shaded;
1601 netstate[num++] = prop_atoms.net_wm_state_hidden;
1602 if (self->skip_taskbar)
1603 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1604 if (self->skip_pager)
1605 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1606 if (self->fullscreen)
1607 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1609 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1611 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1613 netstate[num++] = prop_atoms.net_wm_state_above;
1615 netstate[num++] = prop_atoms.net_wm_state_below;
1616 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1618 client_calc_layer(self);
1621 frame_adjust_state(self->frame);
1624 ObClient *client_search_focus_tree(ObClient *self)
1629 for (it = self->transients; it != NULL; it = it->next) {
1630 if (client_focused(it->data)) return it->data;
1631 if ((ret = client_search_focus_tree(it->data))) return ret;
1636 ObClient *client_search_focus_tree_full(ObClient *self)
1638 if (self->transient_for) {
1639 if (self->transient_for != OB_TRAN_GROUP) {
1640 return client_search_focus_tree_full(self->transient_for);
1643 gboolean recursed = FALSE;
1645 for (it = self->group->members; it; it = it->next)
1646 if (!((ObClient*)it->data)->transient_for) {
1648 if ((c = client_search_focus_tree_full(it->data)))
1657 /* this function checks the whole tree, the client_search_focus_tree~
1658 does not, so we need to check this window */
1659 if (client_focused(self))
1661 return client_search_focus_tree(self);
1664 static ObStackingLayer calc_layer(ObClient *self)
1668 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1669 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1670 l = OB_STACKING_LAYER_DESKTOP;
1671 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1672 if (!self->below) l = OB_STACKING_LAYER_TOP;
1673 else l = OB_STACKING_LAYER_NORMAL;
1675 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1676 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1677 else l = OB_STACKING_LAYER_NORMAL;
1682 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1683 ObStackingLayer l, gboolean raised)
1685 ObStackingLayer old, own;
1689 own = calc_layer(self);
1690 self->layer = l > own ? l : own;
1692 for (it = self->transients; it; it = it->next)
1693 client_calc_layer_recursive(it->data, orig,
1694 l, raised ? raised : l != old);
1696 if (!raised && l != old)
1697 if (orig->frame) { /* only restack if the original window is managed */
1698 /* XXX add_non_intrusive ever? */
1699 stacking_remove(CLIENT_AS_WINDOW(self));
1700 stacking_add(CLIENT_AS_WINDOW(self));
1704 void client_calc_layer(ObClient *self)
1711 /* transients take on the layer of their parents */
1712 self = client_search_top_transient(self);
1714 l = calc_layer(self);
1716 client_calc_layer_recursive(self, orig, l, FALSE);
1719 gboolean client_should_show(ObClient *self)
1721 if (self->iconic) return FALSE;
1722 else if (!(self->desktop == screen_desktop ||
1723 self->desktop == DESKTOP_ALL)) return FALSE;
1724 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1729 static void client_showhide(ObClient *self)
1732 if (client_should_show(self))
1733 frame_show(self->frame);
1735 frame_hide(self->frame);
1738 gboolean client_normal(ObClient *self) {
1739 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1740 self->type == OB_CLIENT_TYPE_DOCK ||
1741 self->type == OB_CLIENT_TYPE_SPLASH);
1744 static void client_apply_startup_state(ObClient *self)
1746 /* these are in a carefully crafted order.. */
1749 self->iconic = FALSE;
1750 client_iconify(self, TRUE, FALSE);
1752 if (self->fullscreen) {
1753 self->fullscreen = FALSE;
1754 client_fullscreen(self, TRUE, FALSE);
1757 self->shaded = FALSE;
1758 client_shade(self, TRUE);
1761 client_urgent_notify(self);
1763 if (self->max_vert && self->max_horz) {
1764 self->max_vert = self->max_horz = FALSE;
1765 client_maximize(self, TRUE, 0, FALSE);
1766 } else if (self->max_vert) {
1767 self->max_vert = FALSE;
1768 client_maximize(self, TRUE, 2, FALSE);
1769 } else if (self->max_horz) {
1770 self->max_horz = FALSE;
1771 client_maximize(self, TRUE, 1, FALSE);
1774 /* nothing to do for the other states:
1783 void client_configure_full(ObClient *self, ObCorner anchor,
1784 int x, int y, int w, int h,
1785 gboolean user, gboolean final,
1786 gboolean force_reply)
1789 gboolean send_resize_client;
1790 gboolean moved = FALSE, resized = FALSE;
1791 guint fdecor = self->frame->decorations;
1792 gboolean fhorz = self->frame->max_horz;
1794 /* make the frame recalculate its dimentions n shit without changing
1795 anything visible for real, this way the constraints below can work with
1796 the updated frame dimensions. */
1797 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1799 /* gets the frame's position */
1800 frame_client_gravity(self->frame, &x, &y);
1802 /* these positions are frame positions, not client positions */
1804 /* set the size and position if fullscreen */
1805 if (self->fullscreen) {
1808 XF86VidModeModeLine mode;
1813 i = client_monitor(self);
1814 a = screen_physical_area_monitor(i);
1817 if (i == 0 && /* primary head */
1818 extensions_vidmode &&
1819 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1820 /* get the mode last so the mode.privsize isnt freed incorrectly */
1821 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1826 if (mode.privsize) XFree(mode.private);
1836 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1840 a = screen_area_monitor(self->desktop, client_monitor(self));
1842 /* set the size and position if maximized */
1843 if (self->max_horz) {
1845 w = a->width - self->frame->size.left - self->frame->size.right;
1847 if (self->max_vert) {
1849 h = a->height - self->frame->size.top - self->frame->size.bottom;
1853 /* gets the client's position */
1854 frame_frame_gravity(self->frame, &x, &y);
1856 /* these override the above states! if you cant move you can't move! */
1858 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1862 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1863 w = self->area.width;
1864 h = self->area.height;
1868 if (!(w == self->area.width && h == self->area.height)) {
1869 int basew, baseh, minw, minh;
1871 /* base size is substituted with min size if not specified */
1872 if (self->base_size.width || self->base_size.height) {
1873 basew = self->base_size.width;
1874 baseh = self->base_size.height;
1876 basew = self->min_size.width;
1877 baseh = self->min_size.height;
1879 /* min size is substituted with base size if not specified */
1880 if (self->min_size.width || self->min_size.height) {
1881 minw = self->min_size.width;
1882 minh = self->min_size.height;
1884 minw = self->base_size.width;
1885 minh = self->base_size.height;
1888 /* if this is a user-requested resize, then check against min/max
1891 /* smaller than min size or bigger than max size? */
1892 if (w > self->max_size.width) w = self->max_size.width;
1893 if (w < minw) w = minw;
1894 if (h > self->max_size.height) h = self->max_size.height;
1895 if (h < minh) h = minh;
1900 /* keep to the increments */
1901 w /= self->size_inc.width;
1902 h /= self->size_inc.height;
1904 /* you cannot resize to nothing */
1905 if (basew + w < 1) w = 1 - basew;
1906 if (baseh + h < 1) h = 1 - baseh;
1908 /* store the logical size */
1909 SIZE_SET(self->logical_size,
1910 self->size_inc.width > 1 ? w : w + basew,
1911 self->size_inc.height > 1 ? h : h + baseh);
1913 w *= self->size_inc.width;
1914 h *= self->size_inc.height;
1919 /* adjust the height to match the width for the aspect ratios.
1920 for this, min size is not substituted for base size ever. */
1921 w -= self->base_size.width;
1922 h -= self->base_size.height;
1924 if (self->min_ratio)
1925 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1926 if (self->max_ratio)
1927 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1929 w += self->base_size.width;
1930 h += self->base_size.height;
1934 case OB_CORNER_TOPLEFT:
1936 case OB_CORNER_TOPRIGHT:
1937 x -= w - self->area.width;
1939 case OB_CORNER_BOTTOMLEFT:
1940 y -= h - self->area.height;
1942 case OB_CORNER_BOTTOMRIGHT:
1943 x -= w - self->area.width;
1944 y -= h - self->area.height;
1948 moved = x != self->area.x || y != self->area.y;
1949 resized = w != self->area.width || h != self->area.height;
1951 oldw = self->area.width;
1952 oldh = self->area.height;
1953 RECT_SET(self->area, x, y, w, h);
1955 /* for app-requested resizes, always resize if 'resized' is true.
1956 for user-requested ones, only resize if final is true, or when
1957 resizing in redraw mode */
1958 send_resize_client = ((!user && resized) ||
1960 (resized && config_redraw_resize))));
1962 /* if the client is enlarging, the resize the client before the frame */
1963 if (send_resize_client && user && (w > oldw || h > oldh))
1964 XResizeWindow(ob_display, self->window, MAX(w, oldw), MAX(h, oldh));
1966 /* move/resize the frame to match the request */
1968 if (self->decorations != fdecor || self->max_horz != fhorz)
1969 moved = resized = TRUE;
1971 if (moved || resized)
1972 frame_adjust_area(self->frame, moved, resized, FALSE);
1974 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1977 event.type = ConfigureNotify;
1978 event.xconfigure.display = ob_display;
1979 event.xconfigure.event = self->window;
1980 event.xconfigure.window = self->window;
1982 /* root window real coords */
1983 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1985 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1987 event.xconfigure.width = w;
1988 event.xconfigure.height = h;
1989 event.xconfigure.border_width = 0;
1990 event.xconfigure.above = self->frame->plate;
1991 event.xconfigure.override_redirect = FALSE;
1992 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1993 FALSE, StructureNotifyMask, &event);
1997 /* if the client is shrinking, then resize the frame before the client */
1998 if (send_resize_client && (!user || (w <= oldw || h <= oldh)))
1999 XResizeWindow(ob_display, self->window, w, h);
2004 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
2008 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
2009 self->fullscreen == fs) return; /* already done */
2011 self->fullscreen = fs;
2012 client_change_state(self); /* change the state hints on the client,
2013 and adjust out layer/stacking */
2017 guint32 dimensions[4];
2018 dimensions[0] = self->area.x;
2019 dimensions[1] = self->area.y;
2020 dimensions[2] = self->area.width;
2021 dimensions[3] = self->area.height;
2023 PROP_SETA32(self->window, openbox_premax, cardinal,
2027 /* these are not actually used cuz client_configure will set them
2028 as appropriate when the window is fullscreened */
2035 /* pick some fallbacks... */
2036 a = screen_area_monitor(self->desktop, 0);
2037 x = a->x + a->width / 4;
2038 y = a->y + a->height / 4;
2042 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2043 (guint32**)&dimensions, &num)) {
2054 client_setup_decor_and_functions(self);
2056 client_move_resize(self, x, y, w, h);
2058 /* try focus us when we go into fullscreen mode */
2062 static void client_iconify_recursive(ObClient *self,
2063 gboolean iconic, gboolean curdesk)
2066 gboolean changed = FALSE;
2069 if (self->iconic != iconic) {
2070 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2073 self->iconic = iconic;
2076 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2077 self->wmstate = IconicState;
2078 self->ignore_unmaps++;
2079 /* we unmap the client itself so that we can get MapRequest
2080 events, and because the ICCCM tells us to! */
2081 XUnmapWindow(ob_display, self->window);
2083 /* update the focus lists.. iconic windows go to the bottom of
2084 the list, put the new iconic window at the 'top of the
2086 focus_order_to_top(self);
2092 client_set_desktop(self, screen_desktop, FALSE);
2093 self->wmstate = self->shaded ? IconicState : NormalState;
2094 XMapWindow(ob_display, self->window);
2096 /* this puts it after the current focused window */
2097 focus_order_remove(self);
2098 focus_order_add_new(self);
2100 /* this is here cuz with the VIDMODE extension, the viewport can
2101 change while a fullscreen window is iconic, and when it
2102 uniconifies, it would be nice if it did so to the new position
2104 client_reconfigure(self);
2111 client_change_state(self);
2112 client_showhide(self);
2113 screen_update_areas();
2116 /* iconify all transients */
2117 for (it = self->transients; it != NULL; it = it->next)
2118 if (it->data != self) client_iconify_recursive(it->data,
2122 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2124 /* move up the transient chain as far as possible first */
2125 self = client_search_top_transient(self);
2127 client_iconify_recursive(client_search_top_transient(self),
2131 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2135 g_assert(dir == 0 || dir == 1 || dir == 2);
2136 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2138 /* check if already done */
2140 if (dir == 0 && self->max_horz && self->max_vert) return;
2141 if (dir == 1 && self->max_horz) return;
2142 if (dir == 2 && self->max_vert) return;
2144 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2145 if (dir == 1 && !self->max_horz) return;
2146 if (dir == 2 && !self->max_vert) return;
2149 /* work with the frame's coords */
2150 x = self->frame->area.x;
2151 y = self->frame->area.y;
2152 w = self->area.width;
2153 h = self->area.height;
2157 gint32 dimensions[4];
2166 /* get the property off the window and use it for the dimensions
2167 we are already maxed on */
2168 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2169 (guint32**)&readdim, &num)) {
2171 if (self->max_horz) {
2172 dimensions[0] = readdim[0];
2173 dimensions[2] = readdim[2];
2175 if (self->max_vert) {
2176 dimensions[1] = readdim[1];
2177 dimensions[3] = readdim[3];
2183 PROP_SETA32(self->window, openbox_premax, cardinal,
2184 (guint32*)dimensions, 4);
2191 /* pick some fallbacks... */
2192 a = screen_area_monitor(self->desktop, 0);
2193 if (dir == 0 || dir == 1) { /* horz */
2194 x = a->x + a->width / 4;
2197 if (dir == 0 || dir == 2) { /* vert */
2198 y = a->y + a->height / 4;
2202 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2203 (guint32**)&dimensions, &num)) {
2205 if (dir == 0 || dir == 1) { /* horz */
2209 if (dir == 0 || dir == 2) { /* vert */
2218 if (dir == 0 || dir == 1) /* horz */
2219 self->max_horz = max;
2220 if (dir == 0 || dir == 2) /* vert */
2221 self->max_vert = max;
2223 if (!self->max_horz && !self->max_vert)
2224 PROP_ERASE(self->window, openbox_premax);
2226 client_change_state(self); /* change the state hints on the client */
2228 client_setup_decor_and_functions(self);
2230 /* figure out where the client should be going */
2231 frame_frame_gravity(self->frame, &x, &y);
2232 client_move_resize(self, x, y, w, h);
2235 void client_shade(ObClient *self, gboolean shade)
2237 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2238 shade) || /* can't shade */
2239 self->shaded == shade) return; /* already done */
2241 /* when we're iconic, don't change the wmstate */
2243 self->wmstate = shade ? IconicState : NormalState;
2244 self->shaded = shade;
2245 client_change_state(self);
2246 /* resize the frame to just the titlebar */
2247 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2250 void client_close(ObClient *self)
2254 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2257 XXX: itd be cool to do timeouts and shit here for killing the client's
2259 like... if the window is around after 5 seconds, then the close button
2260 turns a nice red, and if this function is called again, the client is
2264 ce.xclient.type = ClientMessage;
2265 ce.xclient.message_type = prop_atoms.wm_protocols;
2266 ce.xclient.display = ob_display;
2267 ce.xclient.window = self->window;
2268 ce.xclient.format = 32;
2269 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2270 ce.xclient.data.l[1] = event_lasttime;
2271 ce.xclient.data.l[2] = 0l;
2272 ce.xclient.data.l[3] = 0l;
2273 ce.xclient.data.l[4] = 0l;
2274 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2277 void client_kill(ObClient *self)
2279 XKillClient(ob_display, self->window);
2282 void client_set_desktop_recursive(ObClient *self,
2283 guint target, gboolean donthide)
2288 if (target != self->desktop) {
2290 ob_debug("Setting desktop %u\n", target+1);
2292 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2294 /* remove from the old desktop(s) */
2295 focus_order_remove(self);
2297 old = self->desktop;
2298 self->desktop = target;
2299 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2300 /* the frame can display the current desktop state */
2301 frame_adjust_state(self->frame);
2302 /* 'move' the window to the new desktop */
2304 client_showhide(self);
2305 /* raise if it was not already on the desktop */
2306 if (old != DESKTOP_ALL)
2307 stacking_raise(CLIENT_AS_WINDOW(self));
2308 screen_update_areas();
2310 /* add to the new desktop(s) */
2311 if (config_focus_new)
2312 focus_order_to_top(self);
2314 focus_order_to_bottom(self);
2317 /* move all transients */
2318 for (it = self->transients; it != NULL; it = it->next)
2319 if (it->data != self) client_set_desktop_recursive(it->data,
2323 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2325 client_set_desktop_recursive(client_search_top_transient(self),
2329 ObClient *client_search_modal_child(ObClient *self)
2334 for (it = self->transients; it != NULL; it = it->next) {
2335 ObClient *c = it->data;
2336 if ((ret = client_search_modal_child(c))) return ret;
2337 if (c->modal) return c;
2342 gboolean client_validate(ObClient *self)
2346 XSync(ob_display, FALSE); /* get all events on the server */
2348 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2349 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2350 XPutBackEvent(ob_display, &e);
2357 void client_set_wm_state(ObClient *self, long state)
2359 if (state == self->wmstate) return; /* no change */
2363 client_iconify(self, TRUE, TRUE);
2366 client_iconify(self, FALSE, TRUE);
2371 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2373 gboolean shaded = self->shaded;
2374 gboolean fullscreen = self->fullscreen;
2375 gboolean max_horz = self->max_horz;
2376 gboolean max_vert = self->max_vert;
2379 if (!(action == prop_atoms.net_wm_state_add ||
2380 action == prop_atoms.net_wm_state_remove ||
2381 action == prop_atoms.net_wm_state_toggle))
2382 /* an invalid action was passed to the client message, ignore it */
2385 for (i = 0; i < 2; ++i) {
2386 Atom state = i == 0 ? data1 : data2;
2388 if (!state) continue;
2390 /* if toggling, then pick whether we're adding or removing */
2391 if (action == prop_atoms.net_wm_state_toggle) {
2392 if (state == prop_atoms.net_wm_state_modal)
2393 action = self->modal ? prop_atoms.net_wm_state_remove :
2394 prop_atoms.net_wm_state_add;
2395 else if (state == prop_atoms.net_wm_state_maximized_vert)
2396 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2397 prop_atoms.net_wm_state_add;
2398 else if (state == prop_atoms.net_wm_state_maximized_horz)
2399 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2400 prop_atoms.net_wm_state_add;
2401 else if (state == prop_atoms.net_wm_state_shaded)
2402 action = self->shaded ? prop_atoms.net_wm_state_remove :
2403 prop_atoms.net_wm_state_add;
2404 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2405 action = self->skip_taskbar ?
2406 prop_atoms.net_wm_state_remove :
2407 prop_atoms.net_wm_state_add;
2408 else if (state == prop_atoms.net_wm_state_skip_pager)
2409 action = self->skip_pager ?
2410 prop_atoms.net_wm_state_remove :
2411 prop_atoms.net_wm_state_add;
2412 else if (state == prop_atoms.net_wm_state_fullscreen)
2413 action = self->fullscreen ?
2414 prop_atoms.net_wm_state_remove :
2415 prop_atoms.net_wm_state_add;
2416 else if (state == prop_atoms.net_wm_state_above)
2417 action = self->above ? prop_atoms.net_wm_state_remove :
2418 prop_atoms.net_wm_state_add;
2419 else if (state == prop_atoms.net_wm_state_below)
2420 action = self->below ? prop_atoms.net_wm_state_remove :
2421 prop_atoms.net_wm_state_add;
2424 if (action == prop_atoms.net_wm_state_add) {
2425 if (state == prop_atoms.net_wm_state_modal) {
2426 /* XXX raise here or something? */
2428 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2430 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2432 } else if (state == prop_atoms.net_wm_state_shaded) {
2434 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2435 self->skip_taskbar = TRUE;
2436 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2437 self->skip_pager = TRUE;
2438 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2440 } else if (state == prop_atoms.net_wm_state_above) {
2442 } else if (state == prop_atoms.net_wm_state_below) {
2446 } else { /* action == prop_atoms.net_wm_state_remove */
2447 if (state == prop_atoms.net_wm_state_modal) {
2448 self->modal = FALSE;
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 = FALSE;
2457 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2458 self->skip_pager = FALSE;
2459 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2461 } else if (state == prop_atoms.net_wm_state_above) {
2462 self->above = FALSE;
2463 } else if (state == prop_atoms.net_wm_state_below) {
2464 self->below = FALSE;
2468 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2469 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2471 if (max_horz == max_vert) { /* both going the same way */
2472 client_maximize(self, max_horz, 0, TRUE);
2474 client_maximize(self, max_horz, 1, TRUE);
2475 client_maximize(self, max_vert, 2, TRUE);
2479 if (max_horz != self->max_horz)
2480 client_maximize(self, max_horz, 1, TRUE);
2482 client_maximize(self, max_vert, 2, TRUE);
2485 /* change fullscreen state before shading, as it will affect if the window
2487 if (fullscreen != self->fullscreen)
2488 client_fullscreen(self, fullscreen, TRUE);
2489 if (shaded != self->shaded)
2490 client_shade(self, shaded);
2491 client_calc_layer(self);
2492 client_change_state(self); /* change the hint to reflect these changes */
2495 ObClient *client_focus_target(ObClient *self)
2499 /* if we have a modal child, then focus it, not us */
2500 child = client_search_modal_child(self);
2501 if (child) return child;
2505 gboolean client_can_focus(ObClient *self)
2509 /* choose the correct target */
2510 self = client_focus_target(self);
2512 if (!self->frame->visible)
2515 if (!((self->can_focus || self->focus_notify) &&
2516 (self->desktop == screen_desktop ||
2517 self->desktop == DESKTOP_ALL) &&
2521 /* do a check to see if the window has already been unmapped or destroyed
2522 do this intelligently while watching out for unmaps we've generated
2523 (ignore_unmaps > 0) */
2524 if (XCheckTypedWindowEvent(ob_display, self->window,
2525 DestroyNotify, &ev)) {
2526 XPutBackEvent(ob_display, &ev);
2529 while (XCheckTypedWindowEvent(ob_display, self->window,
2530 UnmapNotify, &ev)) {
2531 if (self->ignore_unmaps) {
2532 self->ignore_unmaps--;
2534 XPutBackEvent(ob_display, &ev);
2542 gboolean client_focus(ObClient *self)
2544 /* choose the correct target */
2545 self = client_focus_target(self);
2547 if (!client_can_focus(self)) {
2548 if (!self->frame->visible) {
2549 /* update the focus lists */
2550 focus_order_to_top(self);
2555 if (self->can_focus) {
2556 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2557 I choose to use it always, hopefully to find errors quicker, if any
2558 are left. (I hate X. I hate focus events.)
2560 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2561 #799. So now it is RevertToNone again.
2563 XSetInputFocus(ob_display, self->window, RevertToNone,
2567 if (self->focus_notify) {
2569 ce.xclient.type = ClientMessage;
2570 ce.xclient.message_type = prop_atoms.wm_protocols;
2571 ce.xclient.display = ob_display;
2572 ce.xclient.window = self->window;
2573 ce.xclient.format = 32;
2574 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2575 ce.xclient.data.l[1] = event_lasttime;
2576 ce.xclient.data.l[2] = 0l;
2577 ce.xclient.data.l[3] = 0l;
2578 ce.xclient.data.l[4] = 0l;
2579 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2583 ob_debug("%sively focusing %lx at %d\n",
2584 (self->can_focus ? "act" : "pass"),
2585 self->window, (int) event_lasttime);
2588 /* Cause the FocusIn to come back to us. Important for desktop switches,
2589 since otherwise we'll have no FocusIn on the queue and send it off to
2590 the focus_backup. */
2591 XSync(ob_display, FALSE);
2595 void client_unfocus(ObClient *self)
2597 if (focus_client == self) {
2599 ob_debug("client_unfocus for %lx\n", self->window);
2601 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2605 void client_activate(ObClient *self, gboolean here)
2607 if (client_normal(self) && screen_showing_desktop)
2608 screen_show_desktop(FALSE);
2610 client_iconify(self, FALSE, FALSE);
2611 if (self->desktop != DESKTOP_ALL &&
2612 self->desktop != screen_desktop) {
2614 client_set_desktop(self, screen_desktop, FALSE);
2616 screen_set_desktop(self->desktop);
2617 } else if (!self->frame->visible)
2618 /* if its not visible for other reasons, then don't mess
2622 client_shade(self, FALSE);
2624 stacking_raise(CLIENT_AS_WINDOW(self));
2627 gboolean client_focused(ObClient *self)
2629 return self == focus_client;
2632 ObClientIcon *client_icon(ObClient *self, int w, int h)
2635 /* si is the smallest image >= req */
2636 /* li is the largest image < req */
2637 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2639 for (i = 0; i < self->nicons; ++i) {
2640 size = self->icons[i].width * self->icons[i].height;
2641 if (size < smallest && size >= (unsigned)(w * h)) {
2645 if (size > largest && size <= (unsigned)(w * h)) {
2650 if (largest == 0) /* didnt find one smaller than the requested size */
2651 return &self->icons[si];
2652 return &self->icons[li];
2655 /* this be mostly ripped from fvwm */
2656 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2658 int my_cx, my_cy, his_cx, his_cy;
2661 int score, best_score;
2662 ObClient *best_client, *cur;
2668 /* first, find the centre coords of the currently focused window */
2669 my_cx = c->frame->area.x + c->frame->area.width / 2;
2670 my_cy = c->frame->area.y + c->frame->area.height / 2;
2675 for(it = g_list_first(client_list); it; it = it->next) {
2678 /* the currently selected window isn't interesting */
2681 if (!client_normal(cur))
2683 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2687 if(client_focus_target(cur) == cur &&
2688 !(cur->can_focus || cur->focus_notify))
2691 /* find the centre coords of this window, from the
2692 * currently focused window's point of view */
2693 his_cx = (cur->frame->area.x - my_cx)
2694 + cur->frame->area.width / 2;
2695 his_cy = (cur->frame->area.y - my_cy)
2696 + cur->frame->area.height / 2;
2698 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2699 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2701 /* Rotate the diagonals 45 degrees counterclockwise.
2702 * To do this, multiply the matrix /+h +h\ with the
2703 * vector (x y). \-h +h/
2704 * h = sqrt(0.5). We can set h := 1 since absolute
2705 * distance doesn't matter here. */
2706 tx = his_cx + his_cy;
2707 his_cy = -his_cx + his_cy;
2712 case OB_DIRECTION_NORTH:
2713 case OB_DIRECTION_SOUTH:
2714 case OB_DIRECTION_NORTHEAST:
2715 case OB_DIRECTION_SOUTHWEST:
2716 offset = (his_cx < 0) ? -his_cx : his_cx;
2717 distance = ((dir == OB_DIRECTION_NORTH ||
2718 dir == OB_DIRECTION_NORTHEAST) ?
2721 case OB_DIRECTION_EAST:
2722 case OB_DIRECTION_WEST:
2723 case OB_DIRECTION_SOUTHEAST:
2724 case OB_DIRECTION_NORTHWEST:
2725 offset = (his_cy < 0) ? -his_cy : his_cy;
2726 distance = ((dir == OB_DIRECTION_WEST ||
2727 dir == OB_DIRECTION_NORTHWEST) ?
2732 /* the target must be in the requested direction */
2736 /* Calculate score for this window. The smaller the better. */
2737 score = distance + offset;
2739 /* windows more than 45 degrees off the direction are
2740 * heavily penalized and will only be chosen if nothing
2741 * else within a million pixels */
2742 if(offset > distance)
2745 if(best_score == -1 || score < best_score)
2753 void client_set_layer(ObClient *self, int layer)
2757 self->above = FALSE;
2758 } else if (layer == 0) {
2759 self->below = self->above = FALSE;
2761 self->below = FALSE;
2764 client_calc_layer(self);
2765 client_change_state(self); /* reflect this in the state hints */
2768 guint client_monitor(ObClient *self)
2772 for (i = 0; i < screen_num_monitors; ++i) {
2773 Rect *area = screen_physical_area_monitor(i);
2774 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2777 if (i == screen_num_monitors) i = 0;
2778 g_assert(i < screen_num_monitors);
2782 ObClient *client_search_top_transient(ObClient *self)
2784 /* move up the transient chain as far as possible */
2785 if (self->transient_for) {
2786 if (self->transient_for != OB_TRAN_GROUP) {
2787 return client_search_top_transient(self->transient_for);
2791 for (it = self->group->members; it; it = it->next) {
2792 ObClient *c = it->data;
2794 /* checking transient_for prevents infinate loops! */
2795 if (c != self && !c->transient_for)
2806 ObClient *client_search_transient(ObClient *self, ObClient *search)
2810 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2811 if (sit->data == search)
2813 if (client_search_transient(sit->data, search))
2819 void client_update_sm_client_id(ObClient *self)
2821 g_free(self->sm_client_id);
2822 self->sm_client_id = NULL;
2824 if (!PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id) &&
2826 PROP_GETS(self->group->leader, sm_client_id, locale,
2827 &self->sm_client_id);
2830 /* finds the nearest edge in the given direction from the current client
2831 * note to self: the edge is the -frame- edge (the actual one), not the
2834 int client_directional_edge_search(ObClient *c, ObDirection dir)
2837 int my_edge_start, my_edge_end, my_offset;
2844 a = screen_area(c->desktop);
2847 case OB_DIRECTION_NORTH:
2848 my_edge_start = c->frame->area.x;
2849 my_edge_end = c->frame->area.x + c->frame->area.width;
2850 my_offset = c->frame->area.y;
2852 dest = a->y; /* default: top of screen */
2854 for(it = g_list_first(client_list); it; it = it->next) {
2855 int his_edge_start, his_edge_end, his_offset;
2856 ObClient *cur = it->data;
2860 if(!client_normal(cur))
2862 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2867 his_edge_start = cur->frame->area.x;
2868 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2869 his_offset = cur->frame->area.y + cur->frame->area.height;
2871 if(his_offset + 1 > my_offset)
2874 if(his_offset < dest)
2877 if(his_edge_start >= my_edge_start &&
2878 his_edge_start <= my_edge_end)
2881 if(my_edge_start >= his_edge_start &&
2882 my_edge_start <= his_edge_end)
2887 case OB_DIRECTION_SOUTH:
2888 my_edge_start = c->frame->area.x;
2889 my_edge_end = c->frame->area.x + c->frame->area.width;
2890 my_offset = c->frame->area.y + c->frame->area.height;
2892 dest = a->y + a->height; /* default: bottom of screen */
2894 for(it = g_list_first(client_list); it; it = it->next) {
2895 int his_edge_start, his_edge_end, his_offset;
2896 ObClient *cur = it->data;
2900 if(!client_normal(cur))
2902 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2907 his_edge_start = cur->frame->area.x;
2908 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2909 his_offset = cur->frame->area.y;
2912 if(his_offset - 1 < my_offset)
2915 if(his_offset > dest)
2918 if(his_edge_start >= my_edge_start &&
2919 his_edge_start <= my_edge_end)
2922 if(my_edge_start >= his_edge_start &&
2923 my_edge_start <= his_edge_end)
2928 case OB_DIRECTION_WEST:
2929 my_edge_start = c->frame->area.y;
2930 my_edge_end = c->frame->area.y + c->frame->area.height;
2931 my_offset = c->frame->area.x;
2933 dest = a->x; /* default: leftmost egde of screen */
2935 for(it = g_list_first(client_list); it; it = it->next) {
2936 int his_edge_start, his_edge_end, his_offset;
2937 ObClient *cur = it->data;
2941 if(!client_normal(cur))
2943 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2948 his_edge_start = cur->frame->area.y;
2949 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2950 his_offset = cur->frame->area.x + cur->frame->area.width;
2952 if(his_offset + 1 > my_offset)
2955 if(his_offset < dest)
2958 if(his_edge_start >= my_edge_start &&
2959 his_edge_start <= my_edge_end)
2962 if(my_edge_start >= his_edge_start &&
2963 my_edge_start <= his_edge_end)
2969 case OB_DIRECTION_EAST:
2970 my_edge_start = c->frame->area.y;
2971 my_edge_end = c->frame->area.y + c->frame->area.height;
2972 my_offset = c->frame->area.x + c->frame->area.width;
2974 dest = a->x + a->width; /* default: rightmost edge of screen */
2976 for(it = g_list_first(client_list); it; it = it->next) {
2977 int his_edge_start, his_edge_end, his_offset;
2978 ObClient *cur = it->data;
2982 if(!client_normal(cur))
2984 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2989 his_edge_start = cur->frame->area.y;
2990 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2991 his_offset = cur->frame->area.x;
2993 if(his_offset - 1 < my_offset)
2996 if(his_offset > dest)
2999 if(his_edge_start >= my_edge_start &&
3000 his_edge_start <= my_edge_end)
3003 if(my_edge_start >= his_edge_start &&
3004 my_edge_start <= his_edge_end)
3009 case OB_DIRECTION_NORTHEAST:
3010 case OB_DIRECTION_SOUTHEAST:
3011 case OB_DIRECTION_NORTHWEST:
3012 case OB_DIRECTION_SOUTHWEST:
3013 /* not implemented */
3016 g_assert_not_reached();