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 && config_focus_new &&
281 /* note the check against Type_Normal/Dialog, not client_normal(self),
282 which would also include other types. in this case we want more
283 strict rules for focus */
284 (self->type == OB_CLIENT_TYPE_NORMAL ||
285 self->type == OB_CLIENT_TYPE_DIALOG))
289 if (self->desktop != screen_desktop) {
290 /* activate the window */
293 gboolean group_foc = FALSE;
298 for (it = self->group->members; it; it = it->next)
300 if (client_focused(it->data))
308 (!self->transient_for && (!self->group ||
309 !self->group->members->next))) ||
310 client_search_focus_tree_full(self) ||
312 !client_normal(focus_client))
314 /* activate the window */
321 if (ob_state() == OB_STATE_RUNNING) {
322 int x = self->area.x, ox = x;
323 int y = self->area.y, oy = y;
325 place_client(self, &x, &y);
327 /* make sure the window is visible */
328 client_find_onscreen(self, &x, &y,
329 self->frame->area.width,
330 self->frame->area.height,
331 client_normal(self));
333 if (x != ox || y != oy)
334 client_move(self, x, y);
337 client_showhide(self);
339 /* use client_focus instead of client_activate cuz client_activate does
340 stuff like switch desktops etc and I'm not interested in all that when
341 a window maps since its not based on an action from the user like
342 clicking a window to activate is. so keep the new window out of the way
344 if (activate) client_focus(self);
346 /* client_activate does this but we aret using it so we have to do it
348 if (screen_showing_desktop)
349 screen_show_desktop(FALSE);
351 /* add to client list/map */
352 client_list = g_list_append(client_list, self);
353 g_hash_table_insert(window_map, &self->window, self);
355 /* this has to happen after we're in the client_list */
356 screen_update_areas();
358 /* update the list hints */
361 keyboard_grab_for_client(self, TRUE);
362 mouse_grab_for_client(self, TRUE);
364 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
367 void client_unmanage_all()
369 while (client_list != NULL)
370 client_unmanage(client_list->data);
373 void client_unmanage(ObClient *self)
378 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
380 g_assert(self != NULL);
382 keyboard_grab_for_client(self, FALSE);
383 mouse_grab_for_client(self, FALSE);
385 /* remove the window from our save set */
386 XChangeSaveSet(ob_display, self->window, SetModeDelete);
388 /* we dont want events no more */
389 XSelectInput(ob_display, self->window, NoEventMask);
391 frame_hide(self->frame);
393 client_list = g_list_remove(client_list, self);
394 stacking_remove(self);
395 g_hash_table_remove(window_map, &self->window);
397 /* update the focus lists */
398 focus_order_remove(self);
400 /* once the client is out of the list, update the struts to remove it's
402 screen_update_areas();
404 /* tell our parent(s) that we're gone */
405 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
408 for (it = self->group->members; it; it = it->next)
409 if (it->data != self)
410 ((ObClient*)it->data)->transients =
411 g_slist_remove(((ObClient*)it->data)->transients, self);
412 } else if (self->transient_for) { /* transient of window */
413 self->transient_for->transients =
414 g_slist_remove(self->transient_for->transients, self);
417 /* tell our transients that we're gone */
418 for (it = self->transients; it != NULL; it = it->next) {
419 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
420 ((ObClient*)it->data)->transient_for = NULL;
421 client_calc_layer(it->data);
425 for (it = client_destructors; it; it = g_slist_next(it)) {
426 GDestroyNotify func = (GDestroyNotify) it->data;
430 if (focus_client == self) {
433 /* focus the last focused window on the desktop, and ignore enter
434 events from the unmap so it doesnt mess with the focus */
435 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
436 client_unfocus(self);
439 /* remove from its group */
441 group_remove(self->group, self);
445 /* give the client its border back */
446 client_toggle_border(self, TRUE);
448 /* reparent the window out of the frame, and free the frame */
449 frame_release_client(self->frame, self);
452 if (ob_state() != OB_STATE_EXITING) {
453 /* these values should not be persisted across a window
455 PROP_ERASE(self->window, net_wm_desktop);
456 PROP_ERASE(self->window, net_wm_state);
457 PROP_ERASE(self->window, wm_state);
459 /* if we're left in an iconic state, the client wont be mapped. this is
460 bad, since we will no longer be managing the window on restart */
462 XMapWindow(ob_display, self->window);
466 ob_debug("Unmanaged window 0x%lx\n", self->window);
468 /* free all data allocated in the client struct */
469 g_slist_free(self->transients);
470 for (j = 0; j < self->nicons; ++j)
471 g_free(self->icons[j].data);
472 if (self->nicons > 0)
475 g_free(self->icon_title);
479 g_free(self->sm_client_id);
482 /* update the list hints */
486 static void client_urgent_notify(ObClient *self)
489 frame_flash_start(self->frame);
491 frame_flash_stop(self->frame);
494 static void client_restore_session_state(ObClient *self)
498 if (!(it = session_state_find(self)))
501 self->session = it->data;
503 RECT_SET(self->area, self->session->x, self->session->y,
504 self->session->w, self->session->h);
505 self->positioned = TRUE;
506 XResizeWindow(ob_display, self->window,
507 self->session->w, self->session->h);
509 self->desktop = (self->session->desktop == DESKTOP_ALL ?
510 self->session->desktop :
511 MIN(screen_num_desktops - 1, self->session->desktop));
512 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
514 self->shaded = self->session->shaded;
515 self->iconic = self->session->iconic;
516 self->skip_pager = self->session->skip_pager;
517 self->skip_taskbar = self->session->skip_taskbar;
518 self->fullscreen = self->session->fullscreen;
519 self->above = self->session->above;
520 self->below = self->session->below;
521 self->max_horz = self->session->max_horz;
522 self->max_vert = self->session->max_vert;
525 static void client_restore_session_stacking(ObClient *self)
529 if (!self->session) return;
531 it = g_list_find(session_saved_state, self->session);
532 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
535 for (cit = client_list; cit; cit = g_list_next(cit))
536 if (session_state_cmp(it->data, cit->data))
539 client_calc_layer(self);
540 stacking_below(CLIENT_AS_WINDOW(self),
541 CLIENT_AS_WINDOW(cit->data));
547 void client_move_onscreen(ObClient *self, gboolean rude)
549 int x = self->area.x;
550 int y = self->area.y;
551 if (client_find_onscreen(self, &x, &y,
552 self->frame->area.width,
553 self->frame->area.height, rude)) {
554 client_move(self, x, y);
558 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
562 int ox = *x, oy = *y;
564 frame_client_gravity(self->frame, x, y); /* get where the frame
567 /* XXX watch for xinerama dead areas */
569 a = screen_area(self->desktop);
570 if (client_normal(self)) {
571 if (!self->strut.right && *x >= a->x + a->width - 1)
572 *x = a->x + a->width - self->frame->area.width;
573 if (!self->strut.bottom && *y >= a->y + a->height - 1)
574 *y = a->y + a->height - self->frame->area.height;
575 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
577 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
582 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
583 Java can suck it too. */
585 /* dont let windows map/move into the strut unless they
586 are bigger than the available area */
588 if (!self->strut.left && *x < a->x) *x = a->x;
589 if (!self->strut.right && *x + w > a->x + a->width)
590 *x = a->x + a->width - w;
592 if (h <= a->height) {
593 if (!self->strut.top && *y < a->y) *y = a->y;
594 if (!self->strut.bottom && *y + h > a->y + a->height)
595 *y = a->y + a->height - h;
599 frame_frame_gravity(self->frame, x, y); /* get where the client
602 return ox != *x || oy != *y;
605 static void client_toggle_border(ObClient *self, gboolean show)
607 /* adjust our idea of where the client is, based on its border. When the
608 border is removed, the client should now be considered to be in a
610 when re-adding the border to the client, the same operation needs to be
612 int oldx = self->area.x, oldy = self->area.y;
613 int x = oldx, y = oldy;
614 switch(self->gravity) {
616 case NorthWestGravity:
618 case SouthWestGravity:
620 case NorthEastGravity:
622 case SouthEastGravity:
623 if (show) x -= self->border_width * 2;
624 else x += self->border_width * 2;
631 if (show) x -= self->border_width;
632 else x += self->border_width;
635 switch(self->gravity) {
637 case NorthWestGravity:
639 case NorthEastGravity:
641 case SouthWestGravity:
643 case SouthEastGravity:
644 if (show) y -= self->border_width * 2;
645 else y += self->border_width * 2;
652 if (show) y -= self->border_width;
653 else y += self->border_width;
660 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
662 /* move the client so it is back it the right spot _with_ its
664 if (x != oldx || y != oldy)
665 XMoveWindow(ob_display, self->window, x, y);
667 XSetWindowBorderWidth(ob_display, self->window, 0);
671 static void client_get_all(ObClient *self)
673 client_get_area(self);
674 client_update_transient_for(self);
675 client_update_wmhints(self);
676 client_get_startup_id(self);
677 client_get_desktop(self);
678 client_get_state(self);
679 client_get_shaped(self);
681 client_get_mwm_hints(self);
682 client_get_type(self);/* this can change the mwmhints for special cases */
684 client_update_protocols(self);
686 client_get_gravity(self); /* get the attribute gravity */
687 client_update_normal_hints(self); /* this may override the attribute
690 /* got the type, the mwmhints, the protocols, and the normal hints
691 (min/max sizes), so we're ready to set up the decorations/functions */
692 client_setup_decor_and_functions(self);
694 client_update_title(self);
695 client_update_class(self);
696 client_update_sm_client_id(self);
697 client_update_strut(self);
698 client_update_icons(self);
701 static void client_get_startup_id(ObClient *self)
703 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
705 PROP_GETS(self->group->leader,
706 net_startup_id, utf8, &self->startup_id);
709 static void client_get_area(ObClient *self)
711 XWindowAttributes wattrib;
714 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
715 g_assert(ret != BadWindow);
717 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
718 self->border_width = wattrib.border_width;
721 static void client_get_desktop(ObClient *self)
723 guint32 d = screen_num_desktops; /* an always-invalid value */
725 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
726 if (d >= screen_num_desktops && d != DESKTOP_ALL)
727 self->desktop = screen_num_desktops - 1;
731 gboolean trdesk = FALSE;
733 if (self->transient_for) {
734 if (self->transient_for != OB_TRAN_GROUP) {
735 self->desktop = self->transient_for->desktop;
740 for (it = self->group->members; it; it = it->next)
741 if (it->data != self &&
742 !((ObClient*)it->data)->transient_for) {
743 self->desktop = ((ObClient*)it->data)->desktop;
750 /* try get from the startup-notification protocol */
751 if (sn_get_desktop(self->startup_id, &self->desktop)) {
752 if (self->desktop >= screen_num_desktops &&
753 self->desktop != DESKTOP_ALL)
754 self->desktop = screen_num_desktops - 1;
756 /* defaults to the current desktop */
757 self->desktop = screen_desktop;
760 if (self->desktop != d) {
761 /* set the desktop hint, to make sure that it always exists */
762 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
766 static void client_get_state(ObClient *self)
771 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
773 for (i = 0; i < num; ++i) {
774 if (state[i] == prop_atoms.net_wm_state_modal)
776 else if (state[i] == prop_atoms.net_wm_state_shaded)
778 else if (state[i] == prop_atoms.net_wm_state_hidden)
780 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
781 self->skip_taskbar = TRUE;
782 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
783 self->skip_pager = TRUE;
784 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
785 self->fullscreen = TRUE;
786 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
787 self->max_vert = TRUE;
788 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
789 self->max_horz = TRUE;
790 else if (state[i] == prop_atoms.net_wm_state_above)
792 else if (state[i] == prop_atoms.net_wm_state_below)
800 static void client_get_shaped(ObClient *self)
802 self->shaped = FALSE;
804 if (extensions_shape) {
809 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
811 XShapeQueryExtents(ob_display, self->window, &s, &foo,
812 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
814 self->shaped = (s != 0);
819 void client_update_transient_for(ObClient *self)
822 ObClient *target = NULL;
824 if (XGetTransientForHint(ob_display, self->window, &t)) {
825 self->transient = TRUE;
826 if (t != self->window) { /* cant be transient to itself! */
827 target = g_hash_table_lookup(window_map, &t);
828 /* if this happens then we need to check for it*/
829 g_assert(target != self);
830 if (target && !WINDOW_IS_CLIENT(target)) {
831 /* this can happen when a dialog is a child of
832 a dockapp, for example */
836 if (!target && self->group) {
837 /* not transient to a client, see if it is transient for a
839 if (t == self->group->leader ||
841 t == RootWindow(ob_display, ob_screen)) {
842 /* window is a transient for its group! */
843 target = OB_TRAN_GROUP;
848 self->transient = FALSE;
850 /* if anything has changed... */
851 if (target != self->transient_for) {
852 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
855 /* remove from old parents */
856 for (it = self->group->members; it; it = g_slist_next(it)) {
857 ObClient *c = it->data;
858 if (c != self && !c->transient_for)
859 c->transients = g_slist_remove(c->transients, self);
861 } else if (self->transient_for != NULL) { /* transient of window */
862 /* remove from old parent */
863 self->transient_for->transients =
864 g_slist_remove(self->transient_for->transients, self);
866 self->transient_for = target;
867 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
870 /* add to new parents */
871 for (it = self->group->members; it; it = g_slist_next(it)) {
872 ObClient *c = it->data;
873 if (c != self && !c->transient_for)
874 c->transients = g_slist_append(c->transients, self);
877 /* remove all transients which are in the group, that causes
878 circlular pointer hell of doom */
879 for (it = self->group->members; it; it = g_slist_next(it)) {
881 for (sit = self->transients; sit; sit = next) {
882 next = g_slist_next(sit);
883 if (sit->data == it->data)
885 g_slist_delete_link(self->transients, sit);
888 } else if (self->transient_for != NULL) { /* transient of window */
889 /* add to new parent */
890 self->transient_for->transients =
891 g_slist_append(self->transient_for->transients, self);
896 static void client_get_mwm_hints(ObClient *self)
901 self->mwmhints.flags = 0; /* default to none */
903 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
905 if (num >= OB_MWM_ELEMENTS) {
906 self->mwmhints.flags = hints[0];
907 self->mwmhints.functions = hints[1];
908 self->mwmhints.decorations = hints[2];
914 void client_get_type(ObClient *self)
921 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
922 /* use the first value that we know about in the array */
923 for (i = 0; i < num; ++i) {
924 if (val[i] == prop_atoms.net_wm_window_type_desktop)
925 self->type = OB_CLIENT_TYPE_DESKTOP;
926 else if (val[i] == prop_atoms.net_wm_window_type_dock)
927 self->type = OB_CLIENT_TYPE_DOCK;
928 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
929 self->type = OB_CLIENT_TYPE_TOOLBAR;
930 else if (val[i] == prop_atoms.net_wm_window_type_menu)
931 self->type = OB_CLIENT_TYPE_MENU;
932 else if (val[i] == prop_atoms.net_wm_window_type_utility)
933 self->type = OB_CLIENT_TYPE_UTILITY;
934 else if (val[i] == prop_atoms.net_wm_window_type_splash)
935 self->type = OB_CLIENT_TYPE_SPLASH;
936 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
937 self->type = OB_CLIENT_TYPE_DIALOG;
938 else if (val[i] == prop_atoms.net_wm_window_type_normal)
939 self->type = OB_CLIENT_TYPE_NORMAL;
940 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
941 /* prevent this window from getting any decor or
943 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
944 OB_MWM_FLAG_DECORATIONS);
945 self->mwmhints.decorations = 0;
946 self->mwmhints.functions = 0;
948 if (self->type != (ObClientType) -1)
949 break; /* grab the first legit type */
954 if (self->type == (ObClientType) -1) {
955 /*the window type hint was not set, which means we either classify
956 ourself as a normal window or a dialog, depending on if we are a
959 self->type = OB_CLIENT_TYPE_DIALOG;
961 self->type = OB_CLIENT_TYPE_NORMAL;
965 void client_update_protocols(ObClient *self)
970 self->focus_notify = FALSE;
971 self->delete_window = FALSE;
973 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
974 for (i = 0; i < num_return; ++i) {
975 if (proto[i] == prop_atoms.wm_delete_window) {
976 /* this means we can request the window to close */
977 self->delete_window = TRUE;
978 } else if (proto[i] == prop_atoms.wm_take_focus)
979 /* if this protocol is requested, then the window will be
980 notified whenever we want it to receive focus */
981 self->focus_notify = TRUE;
987 static void client_get_gravity(ObClient *self)
989 XWindowAttributes wattrib;
992 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
993 g_assert(ret != BadWindow);
994 self->gravity = wattrib.win_gravity;
997 void client_update_normal_hints(ObClient *self)
1001 int oldgravity = self->gravity;
1004 self->min_ratio = 0.0f;
1005 self->max_ratio = 0.0f;
1006 SIZE_SET(self->size_inc, 1, 1);
1007 SIZE_SET(self->base_size, 0, 0);
1008 SIZE_SET(self->min_size, 0, 0);
1009 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1011 /* get the hints from the window */
1012 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1013 self->positioned = !!(size.flags & (PPosition|USPosition));
1015 if (size.flags & PWinGravity) {
1016 self->gravity = size.win_gravity;
1018 /* if the client has a frame, i.e. has already been mapped and
1019 is changing its gravity */
1020 if (self->frame && self->gravity != oldgravity) {
1021 /* move our idea of the client's position based on its new
1023 self->area.x = self->frame->area.x;
1024 self->area.y = self->frame->area.y;
1025 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1029 if (size.flags & PAspect) {
1030 if (size.min_aspect.y)
1031 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
1032 if (size.max_aspect.y)
1033 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
1036 if (size.flags & PMinSize)
1037 SIZE_SET(self->min_size, size.min_width, size.min_height);
1039 if (size.flags & PMaxSize)
1040 SIZE_SET(self->max_size, size.max_width, size.max_height);
1042 if (size.flags & PBaseSize)
1043 SIZE_SET(self->base_size, size.base_width, size.base_height);
1045 if (size.flags & PResizeInc)
1046 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1050 void client_setup_decor_and_functions(ObClient *self)
1052 /* start with everything (cept fullscreen) */
1054 (OB_FRAME_DECOR_TITLEBAR |
1055 (ob_rr_theme->show_handle ? OB_FRAME_DECOR_HANDLE : 0) |
1056 OB_FRAME_DECOR_GRIPS |
1057 OB_FRAME_DECOR_BORDER |
1058 OB_FRAME_DECOR_ICON |
1059 OB_FRAME_DECOR_ALLDESKTOPS |
1060 OB_FRAME_DECOR_ICONIFY |
1061 OB_FRAME_DECOR_MAXIMIZE |
1062 OB_FRAME_DECOR_SHADE);
1064 (OB_CLIENT_FUNC_RESIZE |
1065 OB_CLIENT_FUNC_MOVE |
1066 OB_CLIENT_FUNC_ICONIFY |
1067 OB_CLIENT_FUNC_MAXIMIZE |
1068 OB_CLIENT_FUNC_SHADE);
1069 if (self->delete_window) {
1070 self->functions |= OB_CLIENT_FUNC_CLOSE;
1071 self->decorations |= OB_FRAME_DECOR_CLOSE;
1074 if (!(self->min_size.width < self->max_size.width ||
1075 self->min_size.height < self->max_size.height))
1076 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1078 switch (self->type) {
1079 case OB_CLIENT_TYPE_NORMAL:
1080 /* normal windows retain all of the possible decorations and
1081 functionality, and are the only windows that you can fullscreen */
1082 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1085 case OB_CLIENT_TYPE_DIALOG:
1086 case OB_CLIENT_TYPE_UTILITY:
1087 /* these windows cannot be maximized */
1088 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1091 case OB_CLIENT_TYPE_MENU:
1092 case OB_CLIENT_TYPE_TOOLBAR:
1093 /* these windows get less functionality */
1094 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1097 case OB_CLIENT_TYPE_DESKTOP:
1098 case OB_CLIENT_TYPE_DOCK:
1099 case OB_CLIENT_TYPE_SPLASH:
1100 /* none of these windows are manipulated by the window manager */
1101 self->decorations = 0;
1102 self->functions = 0;
1106 /* Mwm Hints are applied subtractively to what has already been chosen for
1107 decor and functionality */
1108 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1109 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1110 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1111 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1112 /* if the mwm hints request no handle or title, then all
1113 decorations are disabled */
1114 self->decorations = 0;
1118 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1119 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1120 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1121 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1122 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1123 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1124 /* dont let mwm hints kill any buttons
1125 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1126 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1127 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1128 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1130 /* dont let mwm hints kill the close button
1131 if (! (self->mwmhints.functions & MwmFunc_Close))
1132 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1136 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1137 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1138 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1139 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1140 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1141 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1143 /* can't maximize without moving/resizing */
1144 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1145 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1146 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1147 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1148 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1151 /* kill the handle on fully maxed windows */
1152 if (self->max_vert && self->max_horz)
1153 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1155 /* finally, the user can have requested no decorations, which overrides
1157 if (!self->decorate)
1158 self->decorations = OB_FRAME_DECOR_BORDER;
1160 /* if we don't have a titlebar, then we cannot shade! */
1161 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1162 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1164 /* now we need to check against rules for the client's current state */
1165 if (self->fullscreen) {
1166 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1167 OB_CLIENT_FUNC_FULLSCREEN |
1168 OB_CLIENT_FUNC_ICONIFY);
1169 self->decorations = 0;
1172 client_change_allowed_actions(self);
1175 /* adjust the client's decorations, etc. */
1176 client_reconfigure(self);
1178 /* this makes sure that these windows appear on all desktops */
1179 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1180 self->desktop != DESKTOP_ALL)
1182 self->desktop = DESKTOP_ALL;
1187 static void client_change_allowed_actions(ObClient *self)
1192 /* desktop windows are kept on all desktops */
1193 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1194 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1196 if (self->functions & OB_CLIENT_FUNC_SHADE)
1197 actions[num++] = prop_atoms.net_wm_action_shade;
1198 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1199 actions[num++] = prop_atoms.net_wm_action_close;
1200 if (self->functions & OB_CLIENT_FUNC_MOVE)
1201 actions[num++] = prop_atoms.net_wm_action_move;
1202 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1203 actions[num++] = prop_atoms.net_wm_action_minimize;
1204 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1205 actions[num++] = prop_atoms.net_wm_action_resize;
1206 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1207 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1208 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1209 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1210 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1213 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1215 /* make sure the window isn't breaking any rules now */
1217 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1218 if (self->frame) client_shade(self, FALSE);
1219 else self->shaded = FALSE;
1221 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1222 if (self->frame) client_iconify(self, FALSE, TRUE);
1223 else self->iconic = FALSE;
1225 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1226 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1227 else self->fullscreen = FALSE;
1229 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1231 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1232 else self->max_vert = self->max_horz = FALSE;
1236 void client_reconfigure(ObClient *self)
1238 /* by making this pass FALSE for user, we avoid the emacs event storm where
1239 every configurenotify causes an update in its normal hints, i think this
1240 is generally what we want anyways... */
1241 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1242 self->area.width, self->area.height, FALSE, TRUE);
1245 void client_update_wmhints(ObClient *self)
1248 gboolean ur = FALSE;
1251 /* assume a window takes input if it doesnt specify */
1252 self->can_focus = TRUE;
1254 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1255 if (hints->flags & InputHint)
1256 self->can_focus = hints->input;
1258 /* only do this when first managing the window *AND* when we aren't
1260 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1261 if (hints->flags & StateHint)
1262 self->iconic = hints->initial_state == IconicState;
1264 if (hints->flags & XUrgencyHint)
1267 if (!(hints->flags & WindowGroupHint))
1268 hints->window_group = None;
1270 /* did the group state change? */
1271 if (hints->window_group !=
1272 (self->group ? self->group->leader : None)) {
1273 /* remove from the old group if there was one */
1274 if (self->group != NULL) {
1275 /* remove transients of the group */
1276 for (it = self->group->members; it; it = it->next)
1277 self->transients = g_slist_remove(self->transients,
1279 group_remove(self->group, self);
1282 if (hints->window_group != None) {
1283 self->group = group_add(hints->window_group, self);
1285 /* i can only have transients from the group if i am not
1287 if (!self->transient_for) {
1288 /* add other transients of the group that are already
1290 for (it = self->group->members; it; it = it->next) {
1291 ObClient *c = it->data;
1292 if (c != self && c->transient_for == OB_TRAN_GROUP)
1294 g_slist_append(self->transients, c);
1299 /* because the self->transient flag wont change from this call,
1300 we don't need to update the window's type and such, only its
1301 transient_for, and the transients lists of other windows in
1302 the group may be affected */
1303 client_update_transient_for(self);
1306 /* the WM_HINTS can contain an icon */
1307 client_update_icons(self);
1312 if (ur != self->urgent) {
1314 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1316 /* fire the urgent callback if we're mapped, otherwise, wait until
1317 after we're mapped */
1319 client_urgent_notify(self);
1323 void client_update_title(ObClient *self)
1329 gboolean read_title;
1332 old_title = self->title;
1335 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1336 /* try old x stuff */
1337 if (!PROP_GETS(self->window, wm_name, locale, &data))
1338 data = g_strdup("Unnamed Window");
1340 /* did the title change? then reset the title_count */
1341 if (old_title && 0 != strncmp(old_title, data, strlen(data)))
1342 self->title_count = 1;
1344 /* look for duplicates and append a number */
1346 for (it = client_list; it; it = it->next)
1347 if (it->data != self) {
1348 ObClient *c = it->data;
1349 if (0 == strncmp(c->title, data, strlen(data)))
1350 nums |= 1 << c->title_count;
1352 /* find first free number */
1353 for (i = 1; i <= 32; ++i)
1354 if (!(nums & (1 << i))) {
1355 if (self->title_count == 1 || i == 1)
1356 self->title_count = i;
1359 /* dont display the number for the first window */
1360 if (self->title_count > 1) {
1362 ndata = g_strdup_printf("%s - [%u]", data, self->title_count);
1367 PROP_SETS(self->window, net_wm_visible_name, data);
1372 frame_adjust_title(self->frame);
1376 /* update the icon title */
1378 g_free(self->icon_title);
1382 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1383 /* try old x stuff */
1384 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1385 data = g_strdup(self->title);
1389 /* append the title count, dont display the number for the first window */
1390 if (read_title && self->title_count > 1) {
1391 char *vdata, *ndata;
1392 ndata = g_strdup_printf(" - [%u]", self->title_count);
1393 vdata = g_strconcat(data, ndata, NULL);
1399 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1401 self->icon_title = data;
1404 void client_update_class(ObClient *self)
1409 if (self->name) g_free(self->name);
1410 if (self->class) g_free(self->class);
1411 if (self->role) g_free(self->role);
1413 self->name = self->class = self->role = NULL;
1415 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1417 self->name = g_strdup(data[0]);
1419 self->class = g_strdup(data[1]);
1424 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1427 if (self->name == NULL) self->name = g_strdup("");
1428 if (self->class == NULL) self->class = g_strdup("");
1429 if (self->role == NULL) self->role = g_strdup("");
1432 void client_update_strut(ObClient *self)
1436 gboolean got = FALSE;
1439 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1443 STRUT_PARTIAL_SET(strut,
1444 data[0], data[2], data[1], data[3],
1445 data[4], data[5], data[8], data[9],
1446 data[6], data[7], data[10], data[11]);
1452 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1455 STRUT_PARTIAL_SET(strut,
1456 data[0], data[2], data[1], data[3],
1457 0, 0, 0, 0, 0, 0, 0, 0);
1463 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1464 0, 0, 0, 0, 0, 0, 0, 0);
1466 if (!STRUT_EQUAL(strut, self->strut)) {
1467 self->strut = strut;
1469 /* updating here is pointless while we're being mapped cuz we're not in
1470 the client list yet */
1472 screen_update_areas();
1476 void client_update_icons(ObClient *self)
1482 for (i = 0; i < self->nicons; ++i)
1483 g_free(self->icons[i].data);
1484 if (self->nicons > 0)
1485 g_free(self->icons);
1488 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1489 /* figure out how many valid icons are in here */
1491 while (num - i > 2) {
1495 if (i > num || w*h == 0) break;
1499 self->icons = g_new(ObClientIcon, self->nicons);
1501 /* store the icons */
1503 for (j = 0; j < self->nicons; ++j) {
1506 w = self->icons[j].width = data[i++];
1507 h = self->icons[j].height = data[i++];
1509 if (w*h == 0) continue;
1511 self->icons[j].data = g_new(RrPixel32, w * h);
1512 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1517 self->icons[j].data[t] =
1518 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1519 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1520 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1521 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1527 } else if (PROP_GETA32(self->window, kwm_win_icon,
1528 kwm_win_icon, &data, &num)) {
1531 self->icons = g_new(ObClientIcon, self->nicons);
1532 xerror_set_ignore(TRUE);
1533 if (!RrPixmapToRGBA(ob_rr_inst,
1535 &self->icons[self->nicons-1].width,
1536 &self->icons[self->nicons-1].height,
1537 &self->icons[self->nicons-1].data)) {
1538 g_free(&self->icons[self->nicons-1]);
1541 xerror_set_ignore(FALSE);
1547 if ((hints = XGetWMHints(ob_display, self->window))) {
1548 if (hints->flags & IconPixmapHint) {
1550 self->icons = g_new(ObClientIcon, self->nicons);
1551 xerror_set_ignore(TRUE);
1552 if (!RrPixmapToRGBA(ob_rr_inst,
1554 (hints->flags & IconMaskHint ?
1555 hints->icon_mask : None),
1556 &self->icons[self->nicons-1].width,
1557 &self->icons[self->nicons-1].height,
1558 &self->icons[self->nicons-1].data)){
1559 g_free(&self->icons[self->nicons-1]);
1562 xerror_set_ignore(FALSE);
1568 if (!self->nicons) {
1570 self->icons = g_new(ObClientIcon, self->nicons);
1571 self->icons[self->nicons-1].width = 48;
1572 self->icons[self->nicons-1].height = 48;
1573 self->icons[self->nicons-1].data = g_memdup(ob_rr_theme->def_win_icon,
1579 frame_adjust_icon(self->frame);
1582 static void client_change_state(ObClient *self)
1585 guint32 netstate[10];
1588 state[0] = self->wmstate;
1590 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1594 netstate[num++] = prop_atoms.net_wm_state_modal;
1596 netstate[num++] = prop_atoms.net_wm_state_shaded;
1598 netstate[num++] = prop_atoms.net_wm_state_hidden;
1599 if (self->skip_taskbar)
1600 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1601 if (self->skip_pager)
1602 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1603 if (self->fullscreen)
1604 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1606 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1608 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1610 netstate[num++] = prop_atoms.net_wm_state_above;
1612 netstate[num++] = prop_atoms.net_wm_state_below;
1613 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1615 client_calc_layer(self);
1618 frame_adjust_state(self->frame);
1621 ObClient *client_search_focus_tree(ObClient *self)
1626 for (it = self->transients; it != NULL; it = it->next) {
1627 if (client_focused(it->data)) return it->data;
1628 if ((ret = client_search_focus_tree(it->data))) return ret;
1633 ObClient *client_search_focus_tree_full(ObClient *self)
1635 if (self->transient_for) {
1636 if (self->transient_for != OB_TRAN_GROUP) {
1637 return client_search_focus_tree_full(self->transient_for);
1640 gboolean recursed = FALSE;
1642 for (it = self->group->members; it; it = it->next)
1643 if (!((ObClient*)it->data)->transient_for) {
1645 if ((c = client_search_focus_tree_full(it->data)))
1654 /* this function checks the whole tree, the client_search_focus_tree~
1655 does not, so we need to check this window */
1656 if (client_focused(self))
1658 return client_search_focus_tree(self);
1661 static ObStackingLayer calc_layer(ObClient *self)
1665 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1666 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1667 l = OB_STACKING_LAYER_DESKTOP;
1668 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1669 if (!self->below) l = OB_STACKING_LAYER_TOP;
1670 else l = OB_STACKING_LAYER_NORMAL;
1672 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1673 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1674 else l = OB_STACKING_LAYER_NORMAL;
1679 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1680 ObStackingLayer l, gboolean raised)
1682 ObStackingLayer old, own;
1686 own = calc_layer(self);
1687 self->layer = l > own ? l : own;
1689 for (it = self->transients; it; it = it->next)
1690 client_calc_layer_recursive(it->data, orig,
1691 l, raised ? raised : l != old);
1693 if (!raised && l != old)
1694 if (orig->frame) { /* only restack if the original window is managed */
1695 /* XXX add_non_intrusive ever? */
1696 stacking_remove(CLIENT_AS_WINDOW(self));
1697 stacking_add(CLIENT_AS_WINDOW(self));
1701 void client_calc_layer(ObClient *self)
1708 /* transients take on the layer of their parents */
1709 self = client_search_top_transient(self);
1711 l = calc_layer(self);
1713 client_calc_layer_recursive(self, orig, l, FALSE);
1716 gboolean client_should_show(ObClient *self)
1718 if (self->iconic) return FALSE;
1719 else if (!(self->desktop == screen_desktop ||
1720 self->desktop == DESKTOP_ALL)) return FALSE;
1721 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1726 static void client_showhide(ObClient *self)
1729 if (client_should_show(self))
1730 frame_show(self->frame);
1732 frame_hide(self->frame);
1735 gboolean client_normal(ObClient *self) {
1736 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1737 self->type == OB_CLIENT_TYPE_DOCK ||
1738 self->type == OB_CLIENT_TYPE_SPLASH);
1741 static void client_apply_startup_state(ObClient *self)
1743 /* these are in a carefully crafted order.. */
1746 self->iconic = FALSE;
1747 client_iconify(self, TRUE, FALSE);
1749 if (self->fullscreen) {
1750 self->fullscreen = FALSE;
1751 client_fullscreen(self, TRUE, FALSE);
1754 self->shaded = FALSE;
1755 client_shade(self, TRUE);
1758 client_urgent_notify(self);
1760 if (self->max_vert && self->max_horz) {
1761 self->max_vert = self->max_horz = FALSE;
1762 client_maximize(self, TRUE, 0, FALSE);
1763 } else if (self->max_vert) {
1764 self->max_vert = FALSE;
1765 client_maximize(self, TRUE, 2, FALSE);
1766 } else if (self->max_horz) {
1767 self->max_horz = FALSE;
1768 client_maximize(self, TRUE, 1, FALSE);
1771 /* nothing to do for the other states:
1780 void client_configure_full(ObClient *self, ObCorner anchor,
1781 int x, int y, int w, int h,
1782 gboolean user, gboolean final,
1783 gboolean force_reply)
1786 gboolean send_resize_client;
1787 gboolean moved = FALSE, resized = FALSE;
1788 guint fdecor = self->frame->decorations;
1789 gboolean fhorz = self->frame->max_horz;
1791 /* make the frame recalculate its dimentions n shit without changing
1792 anything visible for real, this way the constraints below can work with
1793 the updated frame dimensions. */
1794 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1796 /* gets the frame's position */
1797 frame_client_gravity(self->frame, &x, &y);
1799 /* these positions are frame positions, not client positions */
1801 /* set the size and position if fullscreen */
1802 if (self->fullscreen) {
1805 XF86VidModeModeLine mode;
1810 i = client_monitor(self);
1811 a = screen_physical_area_monitor(i);
1814 if (i == 0 && /* primary head */
1815 extensions_vidmode &&
1816 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1817 /* get the mode last so the mode.privsize isnt freed incorrectly */
1818 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1823 if (mode.privsize) XFree(mode.private);
1833 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1837 a = screen_area_monitor(self->desktop, client_monitor(self));
1839 /* set the size and position if maximized */
1840 if (self->max_horz) {
1842 w = a->width - self->frame->size.left - self->frame->size.right;
1844 if (self->max_vert) {
1846 h = a->height - self->frame->size.top - self->frame->size.bottom;
1850 /* gets the client's position */
1851 frame_frame_gravity(self->frame, &x, &y);
1853 /* these override the above states! if you cant move you can't move! */
1855 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1859 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1860 w = self->area.width;
1861 h = self->area.height;
1865 if (!(w == self->area.width && h == self->area.height)) {
1866 int basew, baseh, minw, minh;
1868 /* base size is substituted with min size if not specified */
1869 if (self->base_size.width || self->base_size.height) {
1870 basew = self->base_size.width;
1871 baseh = self->base_size.height;
1873 basew = self->min_size.width;
1874 baseh = self->min_size.height;
1876 /* min size is substituted with base size if not specified */
1877 if (self->min_size.width || self->min_size.height) {
1878 minw = self->min_size.width;
1879 minh = self->min_size.height;
1881 minw = self->base_size.width;
1882 minh = self->base_size.height;
1885 /* if this is a user-requested resize, then check against min/max
1888 /* smaller than min size or bigger than max size? */
1889 if (w > self->max_size.width) w = self->max_size.width;
1890 if (w < minw) w = minw;
1891 if (h > self->max_size.height) h = self->max_size.height;
1892 if (h < minh) h = minh;
1897 /* keep to the increments */
1898 w /= self->size_inc.width;
1899 h /= self->size_inc.height;
1901 /* you cannot resize to nothing */
1902 if (basew + w < 1) w = 1 - basew;
1903 if (baseh + h < 1) h = 1 - baseh;
1905 /* store the logical size */
1906 SIZE_SET(self->logical_size,
1907 self->size_inc.width > 1 ? w : w + basew,
1908 self->size_inc.height > 1 ? h : h + baseh);
1910 w *= self->size_inc.width;
1911 h *= self->size_inc.height;
1916 /* adjust the height to match the width for the aspect ratios.
1917 for this, min size is not substituted for base size ever. */
1918 w -= self->base_size.width;
1919 h -= self->base_size.height;
1921 if (self->min_ratio)
1922 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1923 if (self->max_ratio)
1924 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1926 w += self->base_size.width;
1927 h += self->base_size.height;
1931 case OB_CORNER_TOPLEFT:
1933 case OB_CORNER_TOPRIGHT:
1934 x -= w - self->area.width;
1936 case OB_CORNER_BOTTOMLEFT:
1937 y -= h - self->area.height;
1939 case OB_CORNER_BOTTOMRIGHT:
1940 x -= w - self->area.width;
1941 y -= h - self->area.height;
1945 moved = x != self->area.x || y != self->area.y;
1946 resized = w != self->area.width || h != self->area.height;
1948 oldw = self->area.width;
1949 oldh = self->area.height;
1950 RECT_SET(self->area, x, y, w, h);
1952 /* for app-requested resizes, always resize if 'resized' is true.
1953 for user-requested ones, only resize if final is true, or when
1954 resizing in redraw mode */
1955 send_resize_client = ((!user && resized) ||
1957 (resized && config_redraw_resize))));
1959 /* if the client is enlarging, the resize the client before the frame */
1960 if (send_resize_client && user && (w > oldw || h > oldh))
1961 XResizeWindow(ob_display, self->window, MAX(w, oldw), MAX(h, oldh));
1963 /* move/resize the frame to match the request */
1965 if (self->decorations != fdecor || self->max_horz != fhorz)
1966 moved = resized = TRUE;
1968 if (moved || resized)
1969 frame_adjust_area(self->frame, moved, resized, FALSE);
1971 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1974 event.type = ConfigureNotify;
1975 event.xconfigure.display = ob_display;
1976 event.xconfigure.event = self->window;
1977 event.xconfigure.window = self->window;
1979 /* root window real coords */
1980 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1982 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1984 event.xconfigure.width = w;
1985 event.xconfigure.height = h;
1986 event.xconfigure.border_width = 0;
1987 event.xconfigure.above = self->frame->plate;
1988 event.xconfigure.override_redirect = FALSE;
1989 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1990 FALSE, StructureNotifyMask, &event);
1994 /* if the client is shrinking, then resize the frame before the client */
1995 if (send_resize_client && (!user || (w <= oldw || h <= oldh)))
1996 XResizeWindow(ob_display, self->window, w, h);
2001 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
2005 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
2006 self->fullscreen == fs) return; /* already done */
2008 self->fullscreen = fs;
2009 client_change_state(self); /* change the state hints on the client,
2010 and adjust out layer/stacking */
2014 guint32 dimensions[4];
2015 dimensions[0] = self->area.x;
2016 dimensions[1] = self->area.y;
2017 dimensions[2] = self->area.width;
2018 dimensions[3] = self->area.height;
2020 PROP_SETA32(self->window, openbox_premax, cardinal,
2024 /* these are not actually used cuz client_configure will set them
2025 as appropriate when the window is fullscreened */
2032 /* pick some fallbacks... */
2033 a = screen_area_monitor(self->desktop, 0);
2034 x = a->x + a->width / 4;
2035 y = a->y + a->height / 4;
2039 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2040 (guint32**)&dimensions, &num)) {
2051 client_setup_decor_and_functions(self);
2053 client_move_resize(self, x, y, w, h);
2055 /* try focus us when we go into fullscreen mode */
2059 static void client_iconify_recursive(ObClient *self,
2060 gboolean iconic, gboolean curdesk)
2063 gboolean changed = FALSE;
2066 if (self->iconic != iconic) {
2067 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2070 self->iconic = iconic;
2073 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2074 self->wmstate = IconicState;
2075 self->ignore_unmaps++;
2076 /* we unmap the client itself so that we can get MapRequest
2077 events, and because the ICCCM tells us to! */
2078 XUnmapWindow(ob_display, self->window);
2080 /* update the focus lists.. iconic windows go to the bottom of
2081 the list, put the new iconic window at the 'top of the
2083 focus_order_to_top(self);
2089 client_set_desktop(self, screen_desktop, FALSE);
2090 self->wmstate = self->shaded ? IconicState : NormalState;
2091 XMapWindow(ob_display, self->window);
2093 /* this puts it after the current focused window */
2094 focus_order_remove(self);
2095 focus_order_add_new(self);
2097 /* this is here cuz with the VIDMODE extension, the viewport can
2098 change while a fullscreen window is iconic, and when it
2099 uniconifies, it would be nice if it did so to the new position
2101 client_reconfigure(self);
2108 client_change_state(self);
2109 client_showhide(self);
2110 screen_update_areas();
2113 /* iconify all transients */
2114 for (it = self->transients; it != NULL; it = it->next)
2115 if (it->data != self) client_iconify_recursive(it->data,
2119 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2121 /* move up the transient chain as far as possible first */
2122 self = client_search_top_transient(self);
2124 client_iconify_recursive(client_search_top_transient(self),
2128 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2132 g_assert(dir == 0 || dir == 1 || dir == 2);
2133 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2135 /* check if already done */
2137 if (dir == 0 && self->max_horz && self->max_vert) return;
2138 if (dir == 1 && self->max_horz) return;
2139 if (dir == 2 && self->max_vert) return;
2141 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2142 if (dir == 1 && !self->max_horz) return;
2143 if (dir == 2 && !self->max_vert) return;
2146 /* work with the frame's coords */
2147 x = self->frame->area.x;
2148 y = self->frame->area.y;
2149 w = self->area.width;
2150 h = self->area.height;
2154 gint32 dimensions[4];
2163 /* get the property off the window and use it for the dimensions
2164 we are already maxed on */
2165 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2166 (guint32**)&readdim, &num)) {
2168 if (self->max_horz) {
2169 dimensions[0] = readdim[0];
2170 dimensions[2] = readdim[2];
2172 if (self->max_vert) {
2173 dimensions[1] = readdim[1];
2174 dimensions[3] = readdim[3];
2180 PROP_SETA32(self->window, openbox_premax, cardinal,
2181 (guint32*)dimensions, 4);
2188 /* pick some fallbacks... */
2189 a = screen_area_monitor(self->desktop, 0);
2190 if (dir == 0 || dir == 1) { /* horz */
2191 x = a->x + a->width / 4;
2194 if (dir == 0 || dir == 2) { /* vert */
2195 y = a->y + a->height / 4;
2199 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2200 (guint32**)&dimensions, &num)) {
2202 if (dir == 0 || dir == 1) { /* horz */
2206 if (dir == 0 || dir == 2) { /* vert */
2215 if (dir == 0 || dir == 1) /* horz */
2216 self->max_horz = max;
2217 if (dir == 0 || dir == 2) /* vert */
2218 self->max_vert = max;
2220 if (!self->max_horz && !self->max_vert)
2221 PROP_ERASE(self->window, openbox_premax);
2223 client_change_state(self); /* change the state hints on the client */
2225 client_setup_decor_and_functions(self);
2227 /* figure out where the client should be going */
2228 frame_frame_gravity(self->frame, &x, &y);
2229 client_move_resize(self, x, y, w, h);
2232 void client_shade(ObClient *self, gboolean shade)
2234 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2235 shade) || /* can't shade */
2236 self->shaded == shade) return; /* already done */
2238 /* when we're iconic, don't change the wmstate */
2240 self->wmstate = shade ? IconicState : NormalState;
2241 self->shaded = shade;
2242 client_change_state(self);
2243 /* resize the frame to just the titlebar */
2244 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2247 void client_close(ObClient *self)
2251 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2254 XXX: itd be cool to do timeouts and shit here for killing the client's
2256 like... if the window is around after 5 seconds, then the close button
2257 turns a nice red, and if this function is called again, the client is
2261 ce.xclient.type = ClientMessage;
2262 ce.xclient.message_type = prop_atoms.wm_protocols;
2263 ce.xclient.display = ob_display;
2264 ce.xclient.window = self->window;
2265 ce.xclient.format = 32;
2266 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2267 ce.xclient.data.l[1] = event_lasttime;
2268 ce.xclient.data.l[2] = 0l;
2269 ce.xclient.data.l[3] = 0l;
2270 ce.xclient.data.l[4] = 0l;
2271 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2274 void client_kill(ObClient *self)
2276 XKillClient(ob_display, self->window);
2279 void client_set_desktop_recursive(ObClient *self,
2280 guint target, gboolean donthide)
2285 if (target != self->desktop) {
2287 ob_debug("Setting desktop %u\n", target+1);
2289 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2291 /* remove from the old desktop(s) */
2292 focus_order_remove(self);
2294 old = self->desktop;
2295 self->desktop = target;
2296 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2297 /* the frame can display the current desktop state */
2298 frame_adjust_state(self->frame);
2299 /* 'move' the window to the new desktop */
2301 client_showhide(self);
2302 /* raise if it was not already on the desktop */
2303 if (old != DESKTOP_ALL)
2304 stacking_raise(CLIENT_AS_WINDOW(self));
2305 screen_update_areas();
2307 /* add to the new desktop(s) */
2308 if (config_focus_new)
2309 focus_order_to_top(self);
2311 focus_order_to_bottom(self);
2314 /* move all transients */
2315 for (it = self->transients; it != NULL; it = it->next)
2316 if (it->data != self) client_set_desktop_recursive(it->data,
2320 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2322 client_set_desktop_recursive(client_search_top_transient(self),
2326 ObClient *client_search_modal_child(ObClient *self)
2331 for (it = self->transients; it != NULL; it = it->next) {
2332 ObClient *c = it->data;
2333 if ((ret = client_search_modal_child(c))) return ret;
2334 if (c->modal) return c;
2339 gboolean client_validate(ObClient *self)
2343 XSync(ob_display, FALSE); /* get all events on the server */
2345 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2346 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2347 XPutBackEvent(ob_display, &e);
2354 void client_set_wm_state(ObClient *self, long state)
2356 if (state == self->wmstate) return; /* no change */
2360 client_iconify(self, TRUE, TRUE);
2363 client_iconify(self, FALSE, TRUE);
2368 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2370 gboolean shaded = self->shaded;
2371 gboolean fullscreen = self->fullscreen;
2372 gboolean max_horz = self->max_horz;
2373 gboolean max_vert = self->max_vert;
2376 if (!(action == prop_atoms.net_wm_state_add ||
2377 action == prop_atoms.net_wm_state_remove ||
2378 action == prop_atoms.net_wm_state_toggle))
2379 /* an invalid action was passed to the client message, ignore it */
2382 for (i = 0; i < 2; ++i) {
2383 Atom state = i == 0 ? data1 : data2;
2385 if (!state) continue;
2387 /* if toggling, then pick whether we're adding or removing */
2388 if (action == prop_atoms.net_wm_state_toggle) {
2389 if (state == prop_atoms.net_wm_state_modal)
2390 action = self->modal ? prop_atoms.net_wm_state_remove :
2391 prop_atoms.net_wm_state_add;
2392 else if (state == prop_atoms.net_wm_state_maximized_vert)
2393 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2394 prop_atoms.net_wm_state_add;
2395 else if (state == prop_atoms.net_wm_state_maximized_horz)
2396 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2397 prop_atoms.net_wm_state_add;
2398 else if (state == prop_atoms.net_wm_state_shaded)
2399 action = self->shaded ? prop_atoms.net_wm_state_remove :
2400 prop_atoms.net_wm_state_add;
2401 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2402 action = self->skip_taskbar ?
2403 prop_atoms.net_wm_state_remove :
2404 prop_atoms.net_wm_state_add;
2405 else if (state == prop_atoms.net_wm_state_skip_pager)
2406 action = self->skip_pager ?
2407 prop_atoms.net_wm_state_remove :
2408 prop_atoms.net_wm_state_add;
2409 else if (state == prop_atoms.net_wm_state_fullscreen)
2410 action = self->fullscreen ?
2411 prop_atoms.net_wm_state_remove :
2412 prop_atoms.net_wm_state_add;
2413 else if (state == prop_atoms.net_wm_state_above)
2414 action = self->above ? prop_atoms.net_wm_state_remove :
2415 prop_atoms.net_wm_state_add;
2416 else if (state == prop_atoms.net_wm_state_below)
2417 action = self->below ? prop_atoms.net_wm_state_remove :
2418 prop_atoms.net_wm_state_add;
2421 if (action == prop_atoms.net_wm_state_add) {
2422 if (state == prop_atoms.net_wm_state_modal) {
2423 /* XXX raise here or something? */
2425 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2427 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2429 } else if (state == prop_atoms.net_wm_state_shaded) {
2431 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2432 self->skip_taskbar = TRUE;
2433 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2434 self->skip_pager = TRUE;
2435 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2437 } else if (state == prop_atoms.net_wm_state_above) {
2439 } else if (state == prop_atoms.net_wm_state_below) {
2443 } else { /* action == prop_atoms.net_wm_state_remove */
2444 if (state == prop_atoms.net_wm_state_modal) {
2445 self->modal = FALSE;
2446 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2448 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2450 } else if (state == prop_atoms.net_wm_state_shaded) {
2452 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2453 self->skip_taskbar = FALSE;
2454 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2455 self->skip_pager = FALSE;
2456 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2458 } else if (state == prop_atoms.net_wm_state_above) {
2459 self->above = FALSE;
2460 } else if (state == prop_atoms.net_wm_state_below) {
2461 self->below = FALSE;
2465 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2466 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2468 if (max_horz == max_vert) { /* both going the same way */
2469 client_maximize(self, max_horz, 0, TRUE);
2471 client_maximize(self, max_horz, 1, TRUE);
2472 client_maximize(self, max_vert, 2, TRUE);
2476 if (max_horz != self->max_horz)
2477 client_maximize(self, max_horz, 1, TRUE);
2479 client_maximize(self, max_vert, 2, TRUE);
2482 /* change fullscreen state before shading, as it will affect if the window
2484 if (fullscreen != self->fullscreen)
2485 client_fullscreen(self, fullscreen, TRUE);
2486 if (shaded != self->shaded)
2487 client_shade(self, shaded);
2488 client_calc_layer(self);
2489 client_change_state(self); /* change the hint to reflect these changes */
2492 ObClient *client_focus_target(ObClient *self)
2496 /* if we have a modal child, then focus it, not us */
2497 child = client_search_modal_child(self);
2498 if (child) return child;
2502 gboolean client_can_focus(ObClient *self)
2506 /* choose the correct target */
2507 self = client_focus_target(self);
2509 if (!self->frame->visible)
2512 if (!((self->can_focus || self->focus_notify) &&
2513 (self->desktop == screen_desktop ||
2514 self->desktop == DESKTOP_ALL) &&
2518 /* do a check to see if the window has already been unmapped or destroyed
2519 do this intelligently while watching out for unmaps we've generated
2520 (ignore_unmaps > 0) */
2521 if (XCheckTypedWindowEvent(ob_display, self->window,
2522 DestroyNotify, &ev)) {
2523 XPutBackEvent(ob_display, &ev);
2526 while (XCheckTypedWindowEvent(ob_display, self->window,
2527 UnmapNotify, &ev)) {
2528 if (self->ignore_unmaps) {
2529 self->ignore_unmaps--;
2531 XPutBackEvent(ob_display, &ev);
2539 gboolean client_focus(ObClient *self)
2541 /* choose the correct target */
2542 self = client_focus_target(self);
2544 if (!client_can_focus(self)) {
2545 if (!self->frame->visible) {
2546 /* update the focus lists */
2547 focus_order_to_top(self);
2552 if (self->can_focus) {
2553 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2554 I choose to use it always, hopefully to find errors quicker, if any
2555 are left. (I hate X. I hate focus events.)
2557 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2558 #799. So now it is RevertToNone again.
2560 XSetInputFocus(ob_display, self->window, RevertToNone,
2564 if (self->focus_notify) {
2566 ce.xclient.type = ClientMessage;
2567 ce.xclient.message_type = prop_atoms.wm_protocols;
2568 ce.xclient.display = ob_display;
2569 ce.xclient.window = self->window;
2570 ce.xclient.format = 32;
2571 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2572 ce.xclient.data.l[1] = event_lasttime;
2573 ce.xclient.data.l[2] = 0l;
2574 ce.xclient.data.l[3] = 0l;
2575 ce.xclient.data.l[4] = 0l;
2576 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2580 ob_debug("%sively focusing %lx at %d\n",
2581 (self->can_focus ? "act" : "pass"),
2582 self->window, (int) event_lasttime);
2585 /* Cause the FocusIn to come back to us. Important for desktop switches,
2586 since otherwise we'll have no FocusIn on the queue and send it off to
2587 the focus_backup. */
2588 XSync(ob_display, FALSE);
2592 void client_unfocus(ObClient *self)
2594 if (focus_client == self) {
2596 ob_debug("client_unfocus for %lx\n", self->window);
2598 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2602 void client_activate(ObClient *self, gboolean here)
2604 if (client_normal(self) && screen_showing_desktop)
2605 screen_show_desktop(FALSE);
2607 client_iconify(self, FALSE, FALSE);
2608 if (self->desktop != DESKTOP_ALL &&
2609 self->desktop != screen_desktop) {
2611 client_set_desktop(self, screen_desktop, FALSE);
2613 screen_set_desktop(self->desktop);
2614 } else if (!self->frame->visible)
2615 /* if its not visible for other reasons, then don't mess
2619 client_shade(self, FALSE);
2621 stacking_raise(CLIENT_AS_WINDOW(self));
2624 gboolean client_focused(ObClient *self)
2626 return self == focus_client;
2629 ObClientIcon *client_icon(ObClient *self, int w, int h)
2632 /* si is the smallest image >= req */
2633 /* li is the largest image < req */
2634 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2636 for (i = 0; i < self->nicons; ++i) {
2637 size = self->icons[i].width * self->icons[i].height;
2638 if (size < smallest && size >= (unsigned)(w * h)) {
2642 if (size > largest && size <= (unsigned)(w * h)) {
2647 if (largest == 0) /* didnt find one smaller than the requested size */
2648 return &self->icons[si];
2649 return &self->icons[li];
2652 /* this be mostly ripped from fvwm */
2653 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2655 int my_cx, my_cy, his_cx, his_cy;
2658 int score, best_score;
2659 ObClient *best_client, *cur;
2665 /* first, find the centre coords of the currently focused window */
2666 my_cx = c->frame->area.x + c->frame->area.width / 2;
2667 my_cy = c->frame->area.y + c->frame->area.height / 2;
2672 for(it = g_list_first(client_list); it; it = it->next) {
2675 /* the currently selected window isn't interesting */
2678 if (!client_normal(cur))
2680 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2684 if(client_focus_target(cur) == cur &&
2685 !(cur->can_focus || cur->focus_notify))
2688 /* find the centre coords of this window, from the
2689 * currently focused window's point of view */
2690 his_cx = (cur->frame->area.x - my_cx)
2691 + cur->frame->area.width / 2;
2692 his_cy = (cur->frame->area.y - my_cy)
2693 + cur->frame->area.height / 2;
2695 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2696 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2698 /* Rotate the diagonals 45 degrees counterclockwise.
2699 * To do this, multiply the matrix /+h +h\ with the
2700 * vector (x y). \-h +h/
2701 * h = sqrt(0.5). We can set h := 1 since absolute
2702 * distance doesn't matter here. */
2703 tx = his_cx + his_cy;
2704 his_cy = -his_cx + his_cy;
2709 case OB_DIRECTION_NORTH:
2710 case OB_DIRECTION_SOUTH:
2711 case OB_DIRECTION_NORTHEAST:
2712 case OB_DIRECTION_SOUTHWEST:
2713 offset = (his_cx < 0) ? -his_cx : his_cx;
2714 distance = ((dir == OB_DIRECTION_NORTH ||
2715 dir == OB_DIRECTION_NORTHEAST) ?
2718 case OB_DIRECTION_EAST:
2719 case OB_DIRECTION_WEST:
2720 case OB_DIRECTION_SOUTHEAST:
2721 case OB_DIRECTION_NORTHWEST:
2722 offset = (his_cy < 0) ? -his_cy : his_cy;
2723 distance = ((dir == OB_DIRECTION_WEST ||
2724 dir == OB_DIRECTION_NORTHWEST) ?
2729 /* the target must be in the requested direction */
2733 /* Calculate score for this window. The smaller the better. */
2734 score = distance + offset;
2736 /* windows more than 45 degrees off the direction are
2737 * heavily penalized and will only be chosen if nothing
2738 * else within a million pixels */
2739 if(offset > distance)
2742 if(best_score == -1 || score < best_score)
2750 void client_set_layer(ObClient *self, int layer)
2754 self->above = FALSE;
2755 } else if (layer == 0) {
2756 self->below = self->above = FALSE;
2758 self->below = FALSE;
2761 client_calc_layer(self);
2762 client_change_state(self); /* reflect this in the state hints */
2765 guint client_monitor(ObClient *self)
2769 for (i = 0; i < screen_num_monitors; ++i) {
2770 Rect *area = screen_physical_area_monitor(i);
2771 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2774 if (i == screen_num_monitors) i = 0;
2775 g_assert(i < screen_num_monitors);
2779 ObClient *client_search_top_transient(ObClient *self)
2781 /* move up the transient chain as far as possible */
2782 if (self->transient_for) {
2783 if (self->transient_for != OB_TRAN_GROUP) {
2784 return client_search_top_transient(self->transient_for);
2788 for (it = self->group->members; it; it = it->next) {
2789 ObClient *c = it->data;
2791 /* checking transient_for prevents infinate loops! */
2792 if (c != self && !c->transient_for)
2803 ObClient *client_search_transient(ObClient *self, ObClient *search)
2807 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2808 if (sit->data == search)
2810 if (client_search_transient(sit->data, search))
2816 void client_update_sm_client_id(ObClient *self)
2818 g_free(self->sm_client_id);
2819 self->sm_client_id = NULL;
2821 if (!PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id) &&
2823 PROP_GETS(self->group->leader, sm_client_id, locale,
2824 &self->sm_client_id);
2827 /* finds the nearest edge in the given direction from the current client
2828 * note to self: the edge is the -frame- edge (the actual one), not the
2831 int client_directional_edge_search(ObClient *c, ObDirection dir)
2834 int my_edge_start, my_edge_end, my_offset;
2841 a = screen_area(c->desktop);
2844 case OB_DIRECTION_NORTH:
2845 my_edge_start = c->frame->area.x;
2846 my_edge_end = c->frame->area.x + c->frame->area.width;
2847 my_offset = c->frame->area.y;
2849 dest = a->y; /* default: top of screen */
2851 for(it = g_list_first(client_list); it; it = it->next) {
2852 int his_edge_start, his_edge_end, his_offset;
2853 ObClient *cur = it->data;
2857 if(!client_normal(cur))
2859 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2864 his_edge_start = cur->frame->area.x;
2865 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2866 his_offset = cur->frame->area.y + cur->frame->area.height;
2868 if(his_offset + 1 > my_offset)
2871 if(his_offset < dest)
2874 if(his_edge_start >= my_edge_start &&
2875 his_edge_start <= my_edge_end)
2878 if(my_edge_start >= his_edge_start &&
2879 my_edge_start <= his_edge_end)
2884 case OB_DIRECTION_SOUTH:
2885 my_edge_start = c->frame->area.x;
2886 my_edge_end = c->frame->area.x + c->frame->area.width;
2887 my_offset = c->frame->area.y + c->frame->area.height;
2889 dest = a->y + a->height; /* default: bottom of screen */
2891 for(it = g_list_first(client_list); it; it = it->next) {
2892 int his_edge_start, his_edge_end, his_offset;
2893 ObClient *cur = it->data;
2897 if(!client_normal(cur))
2899 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2904 his_edge_start = cur->frame->area.x;
2905 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2906 his_offset = cur->frame->area.y;
2909 if(his_offset - 1 < my_offset)
2912 if(his_offset > dest)
2915 if(his_edge_start >= my_edge_start &&
2916 his_edge_start <= my_edge_end)
2919 if(my_edge_start >= his_edge_start &&
2920 my_edge_start <= his_edge_end)
2925 case OB_DIRECTION_WEST:
2926 my_edge_start = c->frame->area.y;
2927 my_edge_end = c->frame->area.y + c->frame->area.height;
2928 my_offset = c->frame->area.x;
2930 dest = a->x; /* default: leftmost egde of screen */
2932 for(it = g_list_first(client_list); it; it = it->next) {
2933 int his_edge_start, his_edge_end, his_offset;
2934 ObClient *cur = it->data;
2938 if(!client_normal(cur))
2940 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2945 his_edge_start = cur->frame->area.y;
2946 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2947 his_offset = cur->frame->area.x + cur->frame->area.width;
2949 if(his_offset + 1 > my_offset)
2952 if(his_offset < dest)
2955 if(his_edge_start >= my_edge_start &&
2956 his_edge_start <= my_edge_end)
2959 if(my_edge_start >= his_edge_start &&
2960 my_edge_start <= his_edge_end)
2966 case OB_DIRECTION_EAST:
2967 my_edge_start = c->frame->area.y;
2968 my_edge_end = c->frame->area.y + c->frame->area.height;
2969 my_offset = c->frame->area.x + c->frame->area.width;
2971 dest = a->x + a->width; /* default: rightmost edge of screen */
2973 for(it = g_list_first(client_list); it; it = it->next) {
2974 int his_edge_start, his_edge_end, his_offset;
2975 ObClient *cur = it->data;
2979 if(!client_normal(cur))
2981 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2986 his_edge_start = cur->frame->area.y;
2987 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2988 his_offset = cur->frame->area.x;
2990 if(his_offset - 1 < my_offset)
2993 if(his_offset > dest)
2996 if(his_edge_start >= my_edge_start &&
2997 his_edge_start <= my_edge_end)
3000 if(my_edge_start >= his_edge_start &&
3001 my_edge_start <= his_edge_end)
3006 case OB_DIRECTION_NORTHEAST:
3007 case OB_DIRECTION_SOUTHEAST:
3008 case OB_DIRECTION_NORTHWEST:
3009 case OB_DIRECTION_SOUTHWEST:
3010 /* not implemented */
3013 g_assert_not_reached();
3018 ObClient* client_under_pointer()
3022 ObClient *ret = NULL;
3024 if (screen_pointer_pos(&x, &y)) {
3025 for (it = stacking_list; it != NULL; it = it->next) {
3026 if (WINDOW_IS_CLIENT(it->data)) {
3027 ObClient *c = WINDOW_AS_CLIENT(it->data);
3028 if (c->desktop == screen_desktop &&
3029 RECT_CONTAINS(c->frame->area, x, y)) {