3 #include "startupnotify.h"
7 #include "moveresize.h"
10 #include "extensions.h"
20 #include "menuframe.h"
23 #include "render/render.h"
26 #include <X11/Xutil.h>
28 /*! The event mask to grab on client windows */
29 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
32 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
35 GList *client_list = NULL;
36 GSList *client_destructors = NULL;
38 static void client_get_all(ObClient *self);
39 static void client_toggle_border(ObClient *self, gboolean show);
40 static void client_get_startup_id(ObClient *self);
41 static void client_get_area(ObClient *self);
42 static void client_get_desktop(ObClient *self);
43 static void client_get_state(ObClient *self);
44 static void client_get_shaped(ObClient *self);
45 static void client_get_mwm_hints(ObClient *self);
46 static void client_get_gravity(ObClient *self);
47 static void client_showhide(ObClient *self);
48 static void client_change_allowed_actions(ObClient *self);
49 static void client_change_state(ObClient *self);
50 static void client_apply_startup_state(ObClient *self);
51 static void client_restore_session_state(ObClient *self);
52 static void client_restore_session_stacking(ObClient *self);
53 static void client_urgent_notify(ObClient *self);
55 void client_startup(gboolean reconfig)
62 void client_shutdown(gboolean reconfig)
66 void client_add_destructor(GDestroyNotify func)
68 client_destructors = g_slist_prepend(client_destructors, (gpointer)func);
71 void client_remove_destructor(GDestroyNotify func)
73 client_destructors = g_slist_remove(client_destructors, (gpointer)func);
76 void client_set_list()
78 Window *windows, *win_it;
80 guint size = g_list_length(client_list);
82 /* create an array of the window ids */
84 windows = g_new(Window, size);
86 for (it = client_list; it != NULL; it = it->next, ++win_it)
87 *win_it = ((ObClient*)it->data)->window;
91 PROP_SETA32(RootWindow(ob_display, ob_screen),
92 net_client_list, window, (guint32*)windows, size);
101 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
105 for (it = self->transients; it; it = it->next) {
106 if (!func(it->data, data)) return;
107 client_foreach_transient(it->data, func, data);
111 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
113 if (self->transient_for) {
114 if (self->transient_for != OB_TRAN_GROUP) {
115 if (!func(self->transient_for, data)) return;
116 client_foreach_ancestor(self->transient_for, func, data);
120 for (it = self->group->members; it; it = it->next)
121 if (it->data != self &&
122 !((ObClient*)it->data)->transient_for) {
123 if (!func(it->data, data)) return;
124 client_foreach_ancestor(it->data, func, data);
131 void client_manage_all()
133 unsigned int i, j, nchild;
136 XWindowAttributes attrib;
138 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
139 &w, &w, &children, &nchild);
141 /* remove all icon windows from the list */
142 for (i = 0; i < nchild; i++) {
143 if (children[i] == None) continue;
144 wmhints = XGetWMHints(ob_display, children[i]);
146 if ((wmhints->flags & IconWindowHint) &&
147 (wmhints->icon_window != children[i]))
148 for (j = 0; j < nchild; j++)
149 if (children[j] == wmhints->icon_window) {
157 for (i = 0; i < nchild; ++i) {
158 if (children[i] == None)
160 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
161 if (attrib.override_redirect) continue;
163 if (attrib.map_state != IsUnmapped)
164 client_manage(children[i]);
169 if (config_focus_new)
170 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
173 void client_manage(Window window)
177 XWindowAttributes attrib;
178 XSetWindowAttributes attrib_set;
180 gboolean activate = FALSE;
184 /* check if it has already been unmapped by the time we started mapping
185 the grab does a sync so we don't have to here */
186 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
187 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
188 XPutBackEvent(ob_display, &e);
191 return; /* don't manage it */
194 /* make sure it isn't an override-redirect window */
195 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
196 attrib.override_redirect) {
198 return; /* don't manage it */
201 /* is the window a docking app */
202 if ((wmhint = XGetWMHints(ob_display, window))) {
203 if ((wmhint->flags & StateHint) &&
204 wmhint->initial_state == WithdrawnState) {
205 dock_add(window, wmhint);
213 ob_debug("Managing window: %lx\n", window);
215 /* choose the events we want to receive on the CLIENT window */
216 attrib_set.event_mask = CLIENT_EVENTMASK;
217 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
218 XChangeWindowAttributes(ob_display, window,
219 CWEventMask|CWDontPropagate, &attrib_set);
222 /* create the ObClient struct, and populate it from the hints on the
224 self = g_new0(ObClient, 1);
225 self->obwin.type = Window_Client;
226 self->window = window;
228 /* non-zero defaults */
229 self->title_count = 1;
230 self->wmstate = NormalState;
232 self->decorate = TRUE;
233 self->desktop = screen_num_desktops; /* always an invalid value */
235 client_get_all(self);
236 client_restore_session_state(self);
238 sn_app_started(self->class);
240 client_change_state(self);
242 /* remove the client's border (and adjust re gravity) */
243 client_toggle_border(self, FALSE);
245 /* specify that if we exit, the window should not be destroyed and should
246 be reparented back to root automatically */
247 XChangeSaveSet(ob_display, window, SetModeInsert);
249 /* create the decoration frame for the client window */
250 self->frame = frame_new();
252 frame_grab_client(self->frame, self);
256 client_apply_startup_state(self);
258 /* update the focus lists */
259 focus_order_add_new(self);
261 stacking_add(CLIENT_AS_WINDOW(self));
262 client_restore_session_stacking(self);
264 /* focus the new window? */
265 if (ob_state() != OB_STATE_STARTING && config_focus_new &&
266 /* note the check against Type_Normal/Dialog, not client_normal(self),
267 which would also include other types. in this case we want more
268 strict rules for focus */
269 (self->type == OB_CLIENT_TYPE_NORMAL ||
270 self->type == OB_CLIENT_TYPE_DIALOG))
274 if (self->desktop != screen_desktop) {
275 /* activate the window */
278 gboolean group_foc = FALSE;
283 for (it = self->group->members; it; it = it->next)
285 if (client_focused(it->data))
293 (!self->transient_for && (!self->group ||
294 !self->group->members->next))) ||
295 client_search_focus_tree_full(self) ||
297 !client_normal(focus_client))
299 /* activate the window */
306 if (ob_state() == OB_STATE_RUNNING) {
307 int x = self->area.x, ox = x;
308 int y = self->area.y, oy = y;
310 place_client(self, &x, &y);
312 /* make sure the window is visible */
313 client_find_onscreen(self, &x, &y,
314 self->frame->area.width,
315 self->frame->area.height,
316 client_normal(self));
318 if (x != ox || y != oy)
319 client_move(self, x, y);
322 client_showhide(self);
324 /* use client_focus instead of client_activate cuz client_activate does
325 stuff like switch desktops etc and I'm not interested in all that when
326 a window maps since its not based on an action from the user like
327 clicking a window to activate is. so keep the new window out of the way
329 if (activate) client_focus(self);
331 /* client_activate does this but we aret using it so we have to do it
333 if (screen_showing_desktop)
334 screen_show_desktop(FALSE);
336 /* add to client list/map */
337 client_list = g_list_append(client_list, self);
338 g_hash_table_insert(window_map, &self->window, self);
340 /* this has to happen after we're in the client_list */
341 screen_update_areas();
343 /* update the list hints */
346 keyboard_grab_for_client(self, TRUE);
347 mouse_grab_for_client(self, TRUE);
349 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
352 void client_unmanage_all()
354 while (client_list != NULL)
355 client_unmanage(client_list->data);
358 void client_unmanage(ObClient *self)
363 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
365 g_assert(self != NULL);
367 keyboard_grab_for_client(self, FALSE);
368 mouse_grab_for_client(self, FALSE);
370 /* remove the window from our save set */
371 XChangeSaveSet(ob_display, self->window, SetModeDelete);
373 /* we dont want events no more */
374 XSelectInput(ob_display, self->window, NoEventMask);
376 frame_hide(self->frame);
378 client_list = g_list_remove(client_list, self);
379 stacking_remove(self);
380 g_hash_table_remove(window_map, &self->window);
382 /* update the focus lists */
383 focus_order_remove(self);
385 /* once the client is out of the list, update the struts to remove it's
387 screen_update_areas();
389 /* tell our parent(s) that we're gone */
390 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
393 for (it = self->group->members; it; it = it->next)
394 if (it->data != self)
395 ((ObClient*)it->data)->transients =
396 g_slist_remove(((ObClient*)it->data)->transients, self);
397 } else if (self->transient_for) { /* transient of window */
398 self->transient_for->transients =
399 g_slist_remove(self->transient_for->transients, self);
402 /* tell our transients that we're gone */
403 for (it = self->transients; it != NULL; it = it->next) {
404 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
405 ((ObClient*)it->data)->transient_for = NULL;
406 client_calc_layer(it->data);
410 for (it = client_destructors; it; it = g_slist_next(it)) {
411 GDestroyNotify func = (GDestroyNotify) it->data;
415 if (focus_client == self) {
418 /* focus the last focused window on the desktop, and ignore enter
419 events from the unmap so it doesnt mess with the focus */
420 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
421 client_unfocus(self);
424 /* remove from its group */
426 group_remove(self->group, self);
430 /* give the client its border back */
431 client_toggle_border(self, TRUE);
433 /* reparent the window out of the frame, and free the frame */
434 frame_release_client(self->frame, self);
437 if (ob_state() != OB_STATE_EXITING) {
438 /* these values should not be persisted across a window
440 PROP_ERASE(self->window, net_wm_desktop);
441 PROP_ERASE(self->window, net_wm_state);
442 PROP_ERASE(self->window, wm_state);
444 /* if we're left in an iconic state, the client wont be mapped. this is
445 bad, since we will no longer be managing the window on restart */
447 XMapWindow(ob_display, self->window);
451 ob_debug("Unmanaged window 0x%lx\n", self->window);
453 /* free all data allocated in the client struct */
454 g_slist_free(self->transients);
455 for (j = 0; j < self->nicons; ++j)
456 g_free(self->icons[j].data);
457 if (self->nicons > 0)
460 g_free(self->icon_title);
464 g_free(self->sm_client_id);
467 /* update the list hints */
471 static void client_urgent_notify(ObClient *self)
474 frame_flash_start(self->frame);
476 frame_flash_stop(self->frame);
479 static void client_restore_session_state(ObClient *self)
483 if (!(it = session_state_find(self)))
486 self->session = it->data;
488 RECT_SET(self->area, self->session->x, self->session->y,
489 self->session->w, self->session->h);
490 self->positioned = TRUE;
491 XResizeWindow(ob_display, self->window,
492 self->session->w, self->session->h);
494 self->desktop = (self->session->desktop == DESKTOP_ALL ?
495 self->session->desktop :
496 MIN(screen_num_desktops - 1, self->session->desktop));
497 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
499 self->shaded = self->session->shaded;
500 self->iconic = self->session->iconic;
501 self->skip_pager = self->session->skip_pager;
502 self->skip_taskbar = self->session->skip_taskbar;
503 self->fullscreen = self->session->fullscreen;
504 self->above = self->session->above;
505 self->below = self->session->below;
506 self->max_horz = self->session->max_horz;
507 self->max_vert = self->session->max_vert;
510 static void client_restore_session_stacking(ObClient *self)
514 if (!self->session) return;
516 it = g_list_find(session_saved_state, self->session);
517 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
520 for (cit = client_list; cit; cit = g_list_next(cit))
521 if (session_state_cmp(it->data, cit->data))
524 client_calc_layer(self);
525 stacking_below(CLIENT_AS_WINDOW(self),
526 CLIENT_AS_WINDOW(cit->data));
532 void client_move_onscreen(ObClient *self, gboolean rude)
534 int x = self->area.x;
535 int y = self->area.y;
536 if (client_find_onscreen(self, &x, &y,
537 self->frame->area.width,
538 self->frame->area.height, rude)) {
539 client_move(self, x, y);
543 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
547 int ox = *x, oy = *y;
549 frame_client_gravity(self->frame, x, y); /* get where the frame
552 /* XXX watch for xinerama dead areas */
554 a = screen_area(self->desktop);
555 if (client_normal(self)) {
556 if (!self->strut.right && *x >= a->x + a->width - 1)
557 *x = a->x + a->width - self->frame->area.width;
558 if (!self->strut.bottom && *y >= a->y + a->height - 1)
559 *y = a->y + a->height - self->frame->area.height;
560 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
562 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
567 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
568 Java can suck it too. */
570 /* dont let windows map/move into the strut unless they
571 are bigger than the available area */
573 if (!self->strut.left && *x < a->x) *x = a->x;
574 if (!self->strut.right && *x + w > a->x + a->width)
575 *x = a->x + a->width - w;
577 if (h <= a->height) {
578 if (!self->strut.top && *y < a->y) *y = a->y;
579 if (!self->strut.bottom && *y + h > a->y + a->height)
580 *y = a->y + a->height - h;
584 frame_frame_gravity(self->frame, x, y); /* get where the client
587 return ox != *x || oy != *y;
590 static void client_toggle_border(ObClient *self, gboolean show)
592 /* adjust our idea of where the client is, based on its border. When the
593 border is removed, the client should now be considered to be in a
595 when re-adding the border to the client, the same operation needs to be
597 int oldx = self->area.x, oldy = self->area.y;
598 int x = oldx, y = oldy;
599 switch(self->gravity) {
601 case NorthWestGravity:
603 case SouthWestGravity:
605 case NorthEastGravity:
607 case SouthEastGravity:
608 if (show) x -= self->border_width * 2;
609 else x += self->border_width * 2;
616 if (show) x -= self->border_width;
617 else x += self->border_width;
620 switch(self->gravity) {
622 case NorthWestGravity:
624 case NorthEastGravity:
626 case SouthWestGravity:
628 case SouthEastGravity:
629 if (show) y -= self->border_width * 2;
630 else y += self->border_width * 2;
637 if (show) y -= self->border_width;
638 else y += self->border_width;
645 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
647 /* move the client so it is back it the right spot _with_ its
649 if (x != oldx || y != oldy)
650 XMoveWindow(ob_display, self->window, x, y);
652 XSetWindowBorderWidth(ob_display, self->window, 0);
656 static void client_get_all(ObClient *self)
658 client_get_area(self);
659 client_update_transient_for(self);
660 client_update_wmhints(self);
661 client_get_startup_id(self);
662 client_get_desktop(self);
663 client_get_state(self);
664 client_get_shaped(self);
666 client_get_mwm_hints(self);
667 client_get_type(self);/* this can change the mwmhints for special cases */
669 client_update_protocols(self);
671 client_get_gravity(self); /* get the attribute gravity */
672 client_update_normal_hints(self); /* this may override the attribute
675 /* got the type, the mwmhints, the protocols, and the normal hints
676 (min/max sizes), so we're ready to set up the decorations/functions */
677 client_setup_decor_and_functions(self);
679 client_update_title(self);
680 client_update_class(self);
681 client_update_sm_client_id(self);
682 client_update_strut(self);
683 client_update_icons(self);
686 static void client_get_startup_id(ObClient *self)
688 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
690 PROP_GETS(self->group->leader,
691 net_startup_id, utf8, &self->startup_id);
694 static void client_get_area(ObClient *self)
696 XWindowAttributes wattrib;
699 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
700 g_assert(ret != BadWindow);
702 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
703 self->border_width = wattrib.border_width;
706 static void client_get_desktop(ObClient *self)
708 guint32 d = screen_num_desktops; /* an always-invalid value */
710 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
711 if (d >= screen_num_desktops && d != DESKTOP_ALL)
712 self->desktop = screen_num_desktops - 1;
716 gboolean trdesk = FALSE;
718 if (self->transient_for) {
719 if (self->transient_for != OB_TRAN_GROUP) {
720 self->desktop = self->transient_for->desktop;
725 for (it = self->group->members; it; it = it->next)
726 if (it->data != self &&
727 !((ObClient*)it->data)->transient_for) {
728 self->desktop = ((ObClient*)it->data)->desktop;
735 /* try get from the startup-notification protocol */
736 if (sn_get_desktop(self->startup_id, &self->desktop)) {
737 if (self->desktop >= screen_num_desktops &&
738 self->desktop != DESKTOP_ALL)
739 self->desktop = screen_num_desktops - 1;
741 /* defaults to the current desktop */
742 self->desktop = screen_desktop;
745 if (self->desktop != d) {
746 /* set the desktop hint, to make sure that it always exists */
747 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
751 static void client_get_state(ObClient *self)
756 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
758 for (i = 0; i < num; ++i) {
759 if (state[i] == prop_atoms.net_wm_state_modal)
761 else if (state[i] == prop_atoms.net_wm_state_shaded)
763 else if (state[i] == prop_atoms.net_wm_state_hidden)
765 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
766 self->skip_taskbar = TRUE;
767 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
768 self->skip_pager = TRUE;
769 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
770 self->fullscreen = TRUE;
771 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
772 self->max_vert = TRUE;
773 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
774 self->max_horz = TRUE;
775 else if (state[i] == prop_atoms.net_wm_state_above)
777 else if (state[i] == prop_atoms.net_wm_state_below)
785 static void client_get_shaped(ObClient *self)
787 self->shaped = FALSE;
789 if (extensions_shape) {
794 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
796 XShapeQueryExtents(ob_display, self->window, &s, &foo,
797 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
799 self->shaped = (s != 0);
804 void client_update_transient_for(ObClient *self)
807 ObClient *target = NULL;
809 if (XGetTransientForHint(ob_display, self->window, &t)) {
810 self->transient = TRUE;
811 if (t != self->window) { /* cant be transient to itself! */
812 target = g_hash_table_lookup(window_map, &t);
813 /* if this happens then we need to check for it*/
814 g_assert(target != self);
815 if (target && !WINDOW_IS_CLIENT(target)) {
816 /* this can happen when a dialog is a child of
817 a dockapp, for example */
821 if (!target && self->group) {
822 /* not transient to a client, see if it is transient for a
824 if (t == self->group->leader ||
826 t == RootWindow(ob_display, ob_screen)) {
827 /* window is a transient for its group! */
828 target = OB_TRAN_GROUP;
833 self->transient = FALSE;
835 /* if anything has changed... */
836 if (target != self->transient_for) {
837 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
840 /* remove from old parents */
841 for (it = self->group->members; it; it = g_slist_next(it)) {
842 ObClient *c = it->data;
843 if (c != self && !c->transient_for)
844 c->transients = g_slist_remove(c->transients, self);
846 } else if (self->transient_for != NULL) { /* transient of window */
847 /* remove from old parent */
848 self->transient_for->transients =
849 g_slist_remove(self->transient_for->transients, self);
851 self->transient_for = target;
852 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
855 /* add to new 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_append(c->transients, self);
862 /* remove all transients which are in the group, that causes
863 circlular pointer hell of doom */
864 for (it = self->group->members; it; it = g_slist_next(it)) {
866 for (sit = self->transients; sit; sit = next) {
867 next = g_slist_next(sit);
868 if (sit->data == it->data)
870 g_slist_delete_link(self->transients, sit);
873 } else if (self->transient_for != NULL) { /* transient of window */
874 /* add to new parent */
875 self->transient_for->transients =
876 g_slist_append(self->transient_for->transients, self);
881 static void client_get_mwm_hints(ObClient *self)
886 self->mwmhints.flags = 0; /* default to none */
888 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
890 if (num >= OB_MWM_ELEMENTS) {
891 self->mwmhints.flags = hints[0];
892 self->mwmhints.functions = hints[1];
893 self->mwmhints.decorations = hints[2];
899 void client_get_type(ObClient *self)
906 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
907 /* use the first value that we know about in the array */
908 for (i = 0; i < num; ++i) {
909 if (val[i] == prop_atoms.net_wm_window_type_desktop)
910 self->type = OB_CLIENT_TYPE_DESKTOP;
911 else if (val[i] == prop_atoms.net_wm_window_type_dock)
912 self->type = OB_CLIENT_TYPE_DOCK;
913 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
914 self->type = OB_CLIENT_TYPE_TOOLBAR;
915 else if (val[i] == prop_atoms.net_wm_window_type_menu)
916 self->type = OB_CLIENT_TYPE_MENU;
917 else if (val[i] == prop_atoms.net_wm_window_type_utility)
918 self->type = OB_CLIENT_TYPE_UTILITY;
919 else if (val[i] == prop_atoms.net_wm_window_type_splash)
920 self->type = OB_CLIENT_TYPE_SPLASH;
921 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
922 self->type = OB_CLIENT_TYPE_DIALOG;
923 else if (val[i] == prop_atoms.net_wm_window_type_normal)
924 self->type = OB_CLIENT_TYPE_NORMAL;
925 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
926 /* prevent this window from getting any decor or
928 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
929 OB_MWM_FLAG_DECORATIONS);
930 self->mwmhints.decorations = 0;
931 self->mwmhints.functions = 0;
933 if (self->type != (ObClientType) -1)
934 break; /* grab the first legit type */
939 if (self->type == (ObClientType) -1) {
940 /*the window type hint was not set, which means we either classify
941 ourself as a normal window or a dialog, depending on if we are a
944 self->type = OB_CLIENT_TYPE_DIALOG;
946 self->type = OB_CLIENT_TYPE_NORMAL;
950 void client_update_protocols(ObClient *self)
955 self->focus_notify = FALSE;
956 self->delete_window = FALSE;
958 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
959 for (i = 0; i < num_return; ++i) {
960 if (proto[i] == prop_atoms.wm_delete_window) {
961 /* this means we can request the window to close */
962 self->delete_window = TRUE;
963 } else if (proto[i] == prop_atoms.wm_take_focus)
964 /* if this protocol is requested, then the window will be
965 notified whenever we want it to receive focus */
966 self->focus_notify = TRUE;
972 static void client_get_gravity(ObClient *self)
974 XWindowAttributes wattrib;
977 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
978 g_assert(ret != BadWindow);
979 self->gravity = wattrib.win_gravity;
982 void client_update_normal_hints(ObClient *self)
986 int oldgravity = self->gravity;
989 self->min_ratio = 0.0f;
990 self->max_ratio = 0.0f;
991 SIZE_SET(self->size_inc, 1, 1);
992 SIZE_SET(self->base_size, 0, 0);
993 SIZE_SET(self->min_size, 0, 0);
994 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
996 /* get the hints from the window */
997 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
998 self->positioned = !!(size.flags & (PPosition|USPosition));
1000 if (size.flags & PWinGravity) {
1001 self->gravity = size.win_gravity;
1003 /* if the client has a frame, i.e. has already been mapped and
1004 is changing its gravity */
1005 if (self->frame && self->gravity != oldgravity) {
1006 /* move our idea of the client's position based on its new
1008 self->area.x = self->frame->area.x;
1009 self->area.y = self->frame->area.y;
1010 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
1014 if (size.flags & PAspect) {
1015 if (size.min_aspect.y)
1016 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
1017 if (size.max_aspect.y)
1018 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
1021 if (size.flags & PMinSize)
1022 SIZE_SET(self->min_size, size.min_width, size.min_height);
1024 if (size.flags & PMaxSize)
1025 SIZE_SET(self->max_size, size.max_width, size.max_height);
1027 if (size.flags & PBaseSize)
1028 SIZE_SET(self->base_size, size.base_width, size.base_height);
1030 if (size.flags & PResizeInc)
1031 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1035 void client_setup_decor_and_functions(ObClient *self)
1037 /* start with everything (cept fullscreen) */
1039 (OB_FRAME_DECOR_TITLEBAR |
1040 (ob_rr_theme->show_handle ? OB_FRAME_DECOR_HANDLE : 0) |
1041 OB_FRAME_DECOR_GRIPS |
1042 OB_FRAME_DECOR_BORDER |
1043 OB_FRAME_DECOR_ICON |
1044 OB_FRAME_DECOR_ALLDESKTOPS |
1045 OB_FRAME_DECOR_ICONIFY |
1046 OB_FRAME_DECOR_MAXIMIZE |
1047 OB_FRAME_DECOR_SHADE);
1049 (OB_CLIENT_FUNC_RESIZE |
1050 OB_CLIENT_FUNC_MOVE |
1051 OB_CLIENT_FUNC_ICONIFY |
1052 OB_CLIENT_FUNC_MAXIMIZE |
1053 OB_CLIENT_FUNC_SHADE);
1054 if (self->delete_window) {
1055 self->functions |= OB_CLIENT_FUNC_CLOSE;
1056 self->decorations |= OB_FRAME_DECOR_CLOSE;
1059 if (!(self->min_size.width < self->max_size.width ||
1060 self->min_size.height < self->max_size.height))
1061 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1063 switch (self->type) {
1064 case OB_CLIENT_TYPE_NORMAL:
1065 /* normal windows retain all of the possible decorations and
1066 functionality, and are the only windows that you can fullscreen */
1067 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1070 case OB_CLIENT_TYPE_DIALOG:
1071 case OB_CLIENT_TYPE_UTILITY:
1072 /* these windows cannot be maximized */
1073 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1076 case OB_CLIENT_TYPE_MENU:
1077 case OB_CLIENT_TYPE_TOOLBAR:
1078 /* these windows get less functionality */
1079 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1082 case OB_CLIENT_TYPE_DESKTOP:
1083 case OB_CLIENT_TYPE_DOCK:
1084 case OB_CLIENT_TYPE_SPLASH:
1085 /* none of these windows are manipulated by the window manager */
1086 self->decorations = 0;
1087 self->functions = 0;
1091 /* Mwm Hints are applied subtractively to what has already been chosen for
1092 decor and functionality */
1093 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1094 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1095 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1096 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1097 /* if the mwm hints request no handle or title, then all
1098 decorations are disabled */
1099 self->decorations = 0;
1103 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1104 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1105 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1106 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1107 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1108 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1109 /* dont let mwm hints kill any buttons
1110 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1111 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1112 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1113 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1115 /* dont let mwm hints kill the close button
1116 if (! (self->mwmhints.functions & MwmFunc_Close))
1117 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1121 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1122 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1123 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1124 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1125 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1126 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1128 /* can't maximize without moving/resizing */
1129 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1130 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1131 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1132 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1133 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1136 /* kill the handle on fully maxed windows */
1137 if (self->max_vert && self->max_horz)
1138 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1140 /* finally, the user can have requested no decorations, which overrides
1142 if (!self->decorate)
1143 self->decorations = OB_FRAME_DECOR_BORDER;
1145 /* if we don't have a titlebar, then we cannot shade! */
1146 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1147 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1149 /* now we need to check against rules for the client's current state */
1150 if (self->fullscreen) {
1151 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1152 OB_CLIENT_FUNC_FULLSCREEN |
1153 OB_CLIENT_FUNC_ICONIFY);
1154 self->decorations = 0;
1157 client_change_allowed_actions(self);
1160 /* adjust the client's decorations, etc. */
1161 client_reconfigure(self);
1163 /* this makes sure that these windows appear on all desktops */
1164 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1165 self->desktop != DESKTOP_ALL)
1167 self->desktop = DESKTOP_ALL;
1172 static void client_change_allowed_actions(ObClient *self)
1177 /* desktop windows are kept on all desktops */
1178 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1179 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1181 if (self->functions & OB_CLIENT_FUNC_SHADE)
1182 actions[num++] = prop_atoms.net_wm_action_shade;
1183 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1184 actions[num++] = prop_atoms.net_wm_action_close;
1185 if (self->functions & OB_CLIENT_FUNC_MOVE)
1186 actions[num++] = prop_atoms.net_wm_action_move;
1187 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1188 actions[num++] = prop_atoms.net_wm_action_minimize;
1189 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1190 actions[num++] = prop_atoms.net_wm_action_resize;
1191 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1192 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1193 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1194 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1195 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1198 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1200 /* make sure the window isn't breaking any rules now */
1202 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1203 if (self->frame) client_shade(self, FALSE);
1204 else self->shaded = FALSE;
1206 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1207 if (self->frame) client_iconify(self, FALSE, TRUE);
1208 else self->iconic = FALSE;
1210 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1211 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1212 else self->fullscreen = FALSE;
1214 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1216 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1217 else self->max_vert = self->max_horz = FALSE;
1221 void client_reconfigure(ObClient *self)
1223 /* by making this pass FALSE for user, we avoid the emacs event storm where
1224 every configurenotify causes an update in its normal hints, i think this
1225 is generally what we want anyways... */
1226 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1227 self->area.width, self->area.height, FALSE, TRUE);
1230 void client_update_wmhints(ObClient *self)
1233 gboolean ur = FALSE;
1236 /* assume a window takes input if it doesnt specify */
1237 self->can_focus = TRUE;
1239 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1240 if (hints->flags & InputHint)
1241 self->can_focus = hints->input;
1243 /* only do this when first managing the window *AND* when we aren't
1245 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1246 if (hints->flags & StateHint)
1247 self->iconic = hints->initial_state == IconicState;
1249 if (hints->flags & XUrgencyHint)
1252 if (!(hints->flags & WindowGroupHint))
1253 hints->window_group = None;
1255 /* did the group state change? */
1256 if (hints->window_group !=
1257 (self->group ? self->group->leader : None)) {
1258 /* remove from the old group if there was one */
1259 if (self->group != NULL) {
1260 /* remove transients of the group */
1261 for (it = self->group->members; it; it = it->next)
1262 self->transients = g_slist_remove(self->transients,
1264 group_remove(self->group, self);
1267 if (hints->window_group != None) {
1268 self->group = group_add(hints->window_group, self);
1270 /* i can only have transients from the group if i am not
1272 if (!self->transient_for) {
1273 /* add other transients of the group that are already
1275 for (it = self->group->members; it; it = it->next) {
1276 ObClient *c = it->data;
1277 if (c != self && c->transient_for == OB_TRAN_GROUP)
1279 g_slist_append(self->transients, c);
1284 /* because the self->transient flag wont change from this call,
1285 we don't need to update the window's type and such, only its
1286 transient_for, and the transients lists of other windows in
1287 the group may be affected */
1288 client_update_transient_for(self);
1291 /* the WM_HINTS can contain an icon */
1292 client_update_icons(self);
1297 if (ur != self->urgent) {
1299 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1301 /* fire the urgent callback if we're mapped, otherwise, wait until
1302 after we're mapped */
1304 client_urgent_notify(self);
1308 void client_update_title(ObClient *self)
1314 gboolean read_title;
1317 old_title = self->title;
1320 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1321 /* try old x stuff */
1322 if (!PROP_GETS(self->window, wm_name, locale, &data))
1323 data = g_strdup("Unnamed Window");
1325 /* did the title change? then reset the title_count */
1326 if (old_title && 0 != strncmp(old_title, data, strlen(data)))
1327 self->title_count = 1;
1329 /* look for duplicates and append a number */
1331 for (it = client_list; it; it = it->next)
1332 if (it->data != self) {
1333 ObClient *c = it->data;
1334 if (0 == strncmp(c->title, data, strlen(data)))
1335 nums |= 1 << c->title_count;
1337 /* find first free number */
1338 for (i = 1; i <= 32; ++i)
1339 if (!(nums & (1 << i))) {
1340 if (self->title_count == 1 || i == 1)
1341 self->title_count = i;
1344 /* dont display the number for the first window */
1345 if (self->title_count > 1) {
1347 ndata = g_strdup_printf("%s - [%u]", data, self->title_count);
1352 PROP_SETS(self->window, net_wm_visible_name, data);
1357 frame_adjust_title(self->frame);
1361 /* update the icon title */
1363 g_free(self->icon_title);
1367 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1368 /* try old x stuff */
1369 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1370 data = g_strdup(self->title);
1374 /* append the title count, dont display the number for the first window */
1375 if (read_title && self->title_count > 1) {
1376 char *vdata, *ndata;
1377 ndata = g_strdup_printf(" - [%u]", self->title_count);
1378 vdata = g_strconcat(data, ndata, NULL);
1384 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1386 self->icon_title = data;
1389 void client_update_class(ObClient *self)
1394 if (self->name) g_free(self->name);
1395 if (self->class) g_free(self->class);
1396 if (self->role) g_free(self->role);
1398 self->name = self->class = self->role = NULL;
1400 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1402 self->name = g_strdup(data[0]);
1404 self->class = g_strdup(data[1]);
1409 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1412 if (self->name == NULL) self->name = g_strdup("");
1413 if (self->class == NULL) self->class = g_strdup("");
1414 if (self->role == NULL) self->role = g_strdup("");
1417 void client_update_strut(ObClient *self)
1421 gboolean got = FALSE;
1424 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1428 STRUT_PARTIAL_SET(strut,
1429 data[0], data[2], data[1], data[3],
1430 data[4], data[5], data[8], data[9],
1431 data[6], data[7], data[10], data[11]);
1437 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1440 STRUT_PARTIAL_SET(strut,
1441 data[0], data[2], data[1], data[3],
1442 0, 0, 0, 0, 0, 0, 0, 0);
1448 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1449 0, 0, 0, 0, 0, 0, 0, 0);
1451 if (!STRUT_EQUAL(strut, self->strut)) {
1452 self->strut = strut;
1454 /* updating here is pointless while we're being mapped cuz we're not in
1455 the client list yet */
1457 screen_update_areas();
1461 void client_update_icons(ObClient *self)
1467 for (i = 0; i < self->nicons; ++i)
1468 g_free(self->icons[i].data);
1469 if (self->nicons > 0)
1470 g_free(self->icons);
1473 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1474 /* figure out how many valid icons are in here */
1476 while (num - i > 2) {
1480 if (i > num || w*h == 0) break;
1484 self->icons = g_new(ObClientIcon, self->nicons);
1486 /* store the icons */
1488 for (j = 0; j < self->nicons; ++j) {
1491 w = self->icons[j].width = data[i++];
1492 h = self->icons[j].height = data[i++];
1494 if (w*h == 0) continue;
1496 self->icons[j].data = g_new(RrPixel32, w * h);
1497 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1502 self->icons[j].data[t] =
1503 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1504 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1505 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1506 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1512 } else if (PROP_GETA32(self->window, kwm_win_icon,
1513 kwm_win_icon, &data, &num)) {
1516 self->icons = g_new(ObClientIcon, self->nicons);
1517 xerror_set_ignore(TRUE);
1518 if (!RrPixmapToRGBA(ob_rr_inst,
1520 &self->icons[self->nicons-1].width,
1521 &self->icons[self->nicons-1].height,
1522 &self->icons[self->nicons-1].data)) {
1523 g_free(&self->icons[self->nicons-1]);
1526 xerror_set_ignore(FALSE);
1532 if ((hints = XGetWMHints(ob_display, self->window))) {
1533 if (hints->flags & IconPixmapHint) {
1535 self->icons = g_new(ObClientIcon, self->nicons);
1536 xerror_set_ignore(TRUE);
1537 if (!RrPixmapToRGBA(ob_rr_inst,
1539 (hints->flags & IconMaskHint ?
1540 hints->icon_mask : None),
1541 &self->icons[self->nicons-1].width,
1542 &self->icons[self->nicons-1].height,
1543 &self->icons[self->nicons-1].data)){
1544 g_free(&self->icons[self->nicons-1]);
1547 xerror_set_ignore(FALSE);
1553 if (!self->nicons) {
1555 self->icons = g_new(ObClientIcon, self->nicons);
1556 self->icons[self->nicons-1].width = 48;
1557 self->icons[self->nicons-1].height = 48;
1558 self->icons[self->nicons-1].data = g_memdup(ob_rr_theme->def_win_icon,
1564 frame_adjust_icon(self->frame);
1567 static void client_change_state(ObClient *self)
1570 guint32 netstate[10];
1573 state[0] = self->wmstate;
1575 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1579 netstate[num++] = prop_atoms.net_wm_state_modal;
1581 netstate[num++] = prop_atoms.net_wm_state_shaded;
1583 netstate[num++] = prop_atoms.net_wm_state_hidden;
1584 if (self->skip_taskbar)
1585 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1586 if (self->skip_pager)
1587 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1588 if (self->fullscreen)
1589 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1591 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1593 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1595 netstate[num++] = prop_atoms.net_wm_state_above;
1597 netstate[num++] = prop_atoms.net_wm_state_below;
1598 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1600 client_calc_layer(self);
1603 frame_adjust_state(self->frame);
1606 ObClient *client_search_focus_tree(ObClient *self)
1611 for (it = self->transients; it != NULL; it = it->next) {
1612 if (client_focused(it->data)) return it->data;
1613 if ((ret = client_search_focus_tree(it->data))) return ret;
1618 ObClient *client_search_focus_tree_full(ObClient *self)
1620 if (self->transient_for) {
1621 if (self->transient_for != OB_TRAN_GROUP) {
1622 return client_search_focus_tree_full(self->transient_for);
1625 gboolean recursed = FALSE;
1627 for (it = self->group->members; it; it = it->next)
1628 if (!((ObClient*)it->data)->transient_for) {
1630 if ((c = client_search_focus_tree_full(it->data)))
1639 /* this function checks the whole tree, the client_search_focus_tree~
1640 does not, so we need to check this window */
1641 if (client_focused(self))
1643 return client_search_focus_tree(self);
1646 static ObStackingLayer calc_layer(ObClient *self)
1650 if (self->fullscreen &&
1651 (client_focused(self) || client_search_focus_tree(self)))
1652 l = OB_STACKING_LAYER_FULLSCREEN;
1653 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1654 l = OB_STACKING_LAYER_DESKTOP;
1655 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1656 if (!self->below) l = OB_STACKING_LAYER_TOP;
1657 else l = OB_STACKING_LAYER_NORMAL;
1659 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1660 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1661 else l = OB_STACKING_LAYER_NORMAL;
1666 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1667 ObStackingLayer l, gboolean raised)
1669 ObStackingLayer old, own;
1673 own = calc_layer(self);
1674 self->layer = MAX(l, own);
1676 g_message("calc for 0x%x %d %d", self->window, old, self->layer);
1678 for (it = self->transients; it; it = it->next)
1679 client_calc_layer_recursive(it->data, orig,
1680 l, raised ? raised : l != old);
1682 if (!raised && l != old)
1683 if (orig->frame) { /* only restack if the original window is managed */
1684 stacking_remove(CLIENT_AS_WINDOW(self));
1685 stacking_add(CLIENT_AS_WINDOW(self));
1689 void client_calc_layer(ObClient *self)
1696 /* transients take on the layer of their parents */
1697 self = client_search_top_transient(self);
1699 l = calc_layer(self);
1701 client_calc_layer_recursive(self, orig, l, FALSE);
1704 gboolean client_should_show(ObClient *self)
1706 if (self->iconic) return FALSE;
1707 else if (!(self->desktop == screen_desktop ||
1708 self->desktop == DESKTOP_ALL)) return FALSE;
1709 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1714 static void client_showhide(ObClient *self)
1717 if (client_should_show(self))
1718 frame_show(self->frame);
1720 frame_hide(self->frame);
1723 gboolean client_normal(ObClient *self) {
1724 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1725 self->type == OB_CLIENT_TYPE_DOCK ||
1726 self->type == OB_CLIENT_TYPE_SPLASH);
1729 static void client_apply_startup_state(ObClient *self)
1731 /* these are in a carefully crafted order.. */
1734 self->iconic = FALSE;
1735 client_iconify(self, TRUE, FALSE);
1737 if (self->fullscreen) {
1738 self->fullscreen = FALSE;
1739 client_fullscreen(self, TRUE, FALSE);
1742 self->shaded = FALSE;
1743 client_shade(self, TRUE);
1746 client_urgent_notify(self);
1748 if (self->max_vert && self->max_horz) {
1749 self->max_vert = self->max_horz = FALSE;
1750 client_maximize(self, TRUE, 0, FALSE);
1751 } else if (self->max_vert) {
1752 self->max_vert = FALSE;
1753 client_maximize(self, TRUE, 2, FALSE);
1754 } else if (self->max_horz) {
1755 self->max_horz = FALSE;
1756 client_maximize(self, TRUE, 1, FALSE);
1759 /* nothing to do for the other states:
1768 void client_configure_full(ObClient *self, ObCorner anchor,
1769 int x, int y, int w, int h,
1770 gboolean user, gboolean final,
1771 gboolean force_reply)
1774 gboolean send_resize_client;
1775 gboolean moved = FALSE, resized = FALSE;
1776 guint fdecor = self->frame->decorations;
1777 gboolean fhorz = self->frame->max_horz;
1779 /* make the frame recalculate its dimentions n shit without changing
1780 anything visible for real, this way the constraints below can work with
1781 the updated frame dimensions. */
1782 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1784 /* gets the frame's position */
1785 frame_client_gravity(self->frame, &x, &y);
1787 /* these positions are frame positions, not client positions */
1789 /* set the size and position if fullscreen */
1790 if (self->fullscreen) {
1793 XF86VidModeModeLine mode;
1798 i = client_monitor(self);
1799 a = screen_physical_area_monitor(i);
1802 if (i == 0 && /* primary head */
1803 extensions_vidmode &&
1804 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1805 /* get the mode last so the mode.privsize isnt freed incorrectly */
1806 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1811 if (mode.privsize) XFree(mode.private);
1821 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1825 a = screen_area_monitor(self->desktop, client_monitor(self));
1827 /* set the size and position if maximized */
1828 if (self->max_horz) {
1830 w = a->width - self->frame->size.left - self->frame->size.right;
1832 if (self->max_vert) {
1834 h = a->height - self->frame->size.top - self->frame->size.bottom;
1838 /* gets the client's position */
1839 frame_frame_gravity(self->frame, &x, &y);
1841 /* these override the above states! if you cant move you can't move! */
1843 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1847 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1848 w = self->area.width;
1849 h = self->area.height;
1853 if (!(w == self->area.width && h == self->area.height)) {
1854 int basew, baseh, minw, minh;
1856 /* base size is substituted with min size if not specified */
1857 if (self->base_size.width || self->base_size.height) {
1858 basew = self->base_size.width;
1859 baseh = self->base_size.height;
1861 basew = self->min_size.width;
1862 baseh = self->min_size.height;
1864 /* min size is substituted with base size if not specified */
1865 if (self->min_size.width || self->min_size.height) {
1866 minw = self->min_size.width;
1867 minh = self->min_size.height;
1869 minw = self->base_size.width;
1870 minh = self->base_size.height;
1873 /* if this is a user-requested resize, then check against min/max
1876 /* smaller than min size or bigger than max size? */
1877 if (w > self->max_size.width) w = self->max_size.width;
1878 if (w < minw) w = minw;
1879 if (h > self->max_size.height) h = self->max_size.height;
1880 if (h < minh) h = minh;
1885 /* keep to the increments */
1886 w /= self->size_inc.width;
1887 h /= self->size_inc.height;
1889 /* you cannot resize to nothing */
1890 if (basew + w < 1) w = 1 - basew;
1891 if (baseh + h < 1) h = 1 - baseh;
1893 /* store the logical size */
1894 SIZE_SET(self->logical_size,
1895 self->size_inc.width > 1 ? w : w + basew,
1896 self->size_inc.height > 1 ? h : h + baseh);
1898 w *= self->size_inc.width;
1899 h *= self->size_inc.height;
1904 /* adjust the height to match the width for the aspect ratios.
1905 for this, min size is not substituted for base size ever. */
1906 w -= self->base_size.width;
1907 h -= self->base_size.height;
1909 if (self->min_ratio)
1910 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1911 if (self->max_ratio)
1912 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1914 w += self->base_size.width;
1915 h += self->base_size.height;
1919 case OB_CORNER_TOPLEFT:
1921 case OB_CORNER_TOPRIGHT:
1922 x -= w - self->area.width;
1924 case OB_CORNER_BOTTOMLEFT:
1925 y -= h - self->area.height;
1927 case OB_CORNER_BOTTOMRIGHT:
1928 x -= w - self->area.width;
1929 y -= h - self->area.height;
1933 moved = x != self->area.x || y != self->area.y;
1934 resized = w != self->area.width || h != self->area.height;
1936 oldw = self->area.width;
1937 oldh = self->area.height;
1938 RECT_SET(self->area, x, y, w, h);
1940 /* for app-requested resizes, always resize if 'resized' is true.
1941 for user-requested ones, only resize if final is true, or when
1942 resizing in redraw mode */
1943 send_resize_client = ((!user && resized) ||
1945 (resized && config_redraw_resize))));
1947 /* if the client is enlarging, the resize the client before the frame */
1948 if (send_resize_client && (w > oldw || h > oldh))
1949 XResizeWindow(ob_display, self->window, MAX(w, oldw), MAX(h, oldh));
1951 /* move/resize the frame to match the request */
1953 if (self->decorations != fdecor || self->max_horz != fhorz)
1954 moved = resized = TRUE;
1956 if (moved || resized)
1957 frame_adjust_area(self->frame, moved, resized, FALSE);
1959 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1962 event.type = ConfigureNotify;
1963 event.xconfigure.display = ob_display;
1964 event.xconfigure.event = self->window;
1965 event.xconfigure.window = self->window;
1967 /* root window real coords */
1968 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1970 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1972 event.xconfigure.width = w;
1973 event.xconfigure.height = h;
1974 event.xconfigure.border_width = 0;
1975 event.xconfigure.above = self->frame->plate;
1976 event.xconfigure.override_redirect = FALSE;
1977 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1978 FALSE, StructureNotifyMask, &event);
1982 /* if the client is shrinking, then resize the frame before the client */
1983 if (send_resize_client && (w <= oldw || h <= oldh))
1984 XResizeWindow(ob_display, self->window, w, h);
1989 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1993 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1994 self->fullscreen == fs) return; /* already done */
1996 self->fullscreen = fs;
1997 client_change_state(self); /* change the state hints on the client,
1998 and adjust out layer/stacking */
2002 guint32 dimensions[4];
2003 dimensions[0] = self->area.x;
2004 dimensions[1] = self->area.y;
2005 dimensions[2] = self->area.width;
2006 dimensions[3] = self->area.height;
2008 PROP_SETA32(self->window, openbox_premax, cardinal,
2012 /* these are not actually used cuz client_configure will set them
2013 as appropriate when the window is fullscreened */
2020 /* pick some fallbacks... */
2021 a = screen_area_monitor(self->desktop, 0);
2022 x = a->x + a->width / 4;
2023 y = a->y + a->height / 4;
2027 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2028 (guint32**)&dimensions, &num)) {
2039 client_setup_decor_and_functions(self);
2041 client_move_resize(self, x, y, w, h);
2043 /* try focus us when we go into fullscreen mode */
2047 static void client_iconify_recursive(ObClient *self,
2048 gboolean iconic, gboolean curdesk)
2051 gboolean changed = FALSE;
2054 if (self->iconic != iconic) {
2055 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2058 self->iconic = iconic;
2061 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2062 self->wmstate = IconicState;
2063 self->ignore_unmaps++;
2064 /* we unmap the client itself so that we can get MapRequest
2065 events, and because the ICCCM tells us to! */
2066 XUnmapWindow(ob_display, self->window);
2068 /* update the focus lists.. iconic windows go to the bottom of
2069 the list, put the new iconic window at the 'top of the
2071 focus_order_to_top(self);
2077 client_set_desktop(self, screen_desktop, FALSE);
2078 self->wmstate = self->shaded ? IconicState : NormalState;
2079 XMapWindow(ob_display, self->window);
2081 /* this puts it after the current focused window */
2082 focus_order_remove(self);
2083 focus_order_add_new(self);
2085 /* this is here cuz with the VIDMODE extension, the viewport can
2086 change while a fullscreen window is iconic, and when it
2087 uniconifies, it would be nice if it did so to the new position
2089 client_reconfigure(self);
2096 client_change_state(self);
2097 client_showhide(self);
2098 screen_update_areas();
2101 /* iconify all transients */
2102 for (it = self->transients; it != NULL; it = it->next)
2103 if (it->data != self) client_iconify_recursive(it->data,
2107 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2109 /* move up the transient chain as far as possible first */
2110 self = client_search_top_transient(self);
2112 client_iconify_recursive(client_search_top_transient(self),
2116 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2120 g_assert(dir == 0 || dir == 1 || dir == 2);
2121 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2123 /* check if already done */
2125 if (dir == 0 && self->max_horz && self->max_vert) return;
2126 if (dir == 1 && self->max_horz) return;
2127 if (dir == 2 && self->max_vert) return;
2129 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2130 if (dir == 1 && !self->max_horz) return;
2131 if (dir == 2 && !self->max_vert) return;
2134 /* work with the frame's coords */
2135 x = self->frame->area.x;
2136 y = self->frame->area.y;
2137 w = self->area.width;
2138 h = self->area.height;
2142 gint32 dimensions[4];
2151 /* get the property off the window and use it for the dimensions
2152 we are already maxed on */
2153 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2154 (guint32**)&readdim, &num)) {
2156 if (self->max_horz) {
2157 dimensions[0] = readdim[0];
2158 dimensions[2] = readdim[2];
2160 if (self->max_vert) {
2161 dimensions[1] = readdim[1];
2162 dimensions[3] = readdim[3];
2168 PROP_SETA32(self->window, openbox_premax, cardinal,
2169 (guint32*)dimensions, 4);
2176 /* pick some fallbacks... */
2177 a = screen_area_monitor(self->desktop, 0);
2178 if (dir == 0 || dir == 1) { /* horz */
2179 x = a->x + a->width / 4;
2182 if (dir == 0 || dir == 2) { /* vert */
2183 y = a->y + a->height / 4;
2187 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2188 (guint32**)&dimensions, &num)) {
2190 if (dir == 0 || dir == 1) { /* horz */
2194 if (dir == 0 || dir == 2) { /* vert */
2203 if (dir == 0 || dir == 1) /* horz */
2204 self->max_horz = max;
2205 if (dir == 0 || dir == 2) /* vert */
2206 self->max_vert = max;
2208 if (!self->max_horz && !self->max_vert)
2209 PROP_ERASE(self->window, openbox_premax);
2211 client_change_state(self); /* change the state hints on the client */
2213 client_setup_decor_and_functions(self);
2215 /* figure out where the client should be going */
2216 frame_frame_gravity(self->frame, &x, &y);
2217 client_move_resize(self, x, y, w, h);
2220 void client_shade(ObClient *self, gboolean shade)
2222 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2223 shade) || /* can't shade */
2224 self->shaded == shade) return; /* already done */
2226 /* when we're iconic, don't change the wmstate */
2228 self->wmstate = shade ? IconicState : NormalState;
2229 self->shaded = shade;
2230 client_change_state(self);
2231 /* resize the frame to just the titlebar */
2232 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2235 void client_close(ObClient *self)
2239 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2242 XXX: itd be cool to do timeouts and shit here for killing the client's
2244 like... if the window is around after 5 seconds, then the close button
2245 turns a nice red, and if this function is called again, the client is
2249 ce.xclient.type = ClientMessage;
2250 ce.xclient.message_type = prop_atoms.wm_protocols;
2251 ce.xclient.display = ob_display;
2252 ce.xclient.window = self->window;
2253 ce.xclient.format = 32;
2254 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2255 ce.xclient.data.l[1] = event_lasttime;
2256 ce.xclient.data.l[2] = 0l;
2257 ce.xclient.data.l[3] = 0l;
2258 ce.xclient.data.l[4] = 0l;
2259 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2262 void client_kill(ObClient *self)
2264 XKillClient(ob_display, self->window);
2267 void client_set_desktop_recursive(ObClient *self,
2268 guint target, gboolean donthide)
2273 if (target != self->desktop) {
2275 ob_debug("Setting desktop %u\n", target+1);
2277 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2279 /* remove from the old desktop(s) */
2280 focus_order_remove(self);
2282 old = self->desktop;
2283 self->desktop = target;
2284 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2285 /* the frame can display the current desktop state */
2286 frame_adjust_state(self->frame);
2287 /* 'move' the window to the new desktop */
2289 client_showhide(self);
2290 /* raise if it was not already on the desktop */
2291 if (old != DESKTOP_ALL)
2292 stacking_raise(CLIENT_AS_WINDOW(self));
2293 screen_update_areas();
2295 /* add to the new desktop(s) */
2296 if (config_focus_new)
2297 focus_order_to_top(self);
2299 focus_order_to_bottom(self);
2302 /* move all transients */
2303 for (it = self->transients; it != NULL; it = it->next)
2304 if (it->data != self) client_set_desktop_recursive(it->data,
2308 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2310 client_set_desktop_recursive(client_search_top_transient(self),
2314 ObClient *client_search_modal_child(ObClient *self)
2319 for (it = self->transients; it != NULL; it = it->next) {
2320 ObClient *c = it->data;
2321 if ((ret = client_search_modal_child(c))) return ret;
2322 if (c->modal) return c;
2327 gboolean client_validate(ObClient *self)
2331 XSync(ob_display, FALSE); /* get all events on the server */
2333 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2334 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2335 XPutBackEvent(ob_display, &e);
2342 void client_set_wm_state(ObClient *self, long state)
2344 if (state == self->wmstate) return; /* no change */
2348 client_iconify(self, TRUE, TRUE);
2351 client_iconify(self, FALSE, TRUE);
2356 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2358 gboolean shaded = self->shaded;
2359 gboolean fullscreen = self->fullscreen;
2360 gboolean max_horz = self->max_horz;
2361 gboolean max_vert = self->max_vert;
2364 if (!(action == prop_atoms.net_wm_state_add ||
2365 action == prop_atoms.net_wm_state_remove ||
2366 action == prop_atoms.net_wm_state_toggle))
2367 /* an invalid action was passed to the client message, ignore it */
2370 for (i = 0; i < 2; ++i) {
2371 Atom state = i == 0 ? data1 : data2;
2373 if (!state) continue;
2375 /* if toggling, then pick whether we're adding or removing */
2376 if (action == prop_atoms.net_wm_state_toggle) {
2377 if (state == prop_atoms.net_wm_state_modal)
2378 action = self->modal ? prop_atoms.net_wm_state_remove :
2379 prop_atoms.net_wm_state_add;
2380 else if (state == prop_atoms.net_wm_state_maximized_vert)
2381 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2382 prop_atoms.net_wm_state_add;
2383 else if (state == prop_atoms.net_wm_state_maximized_horz)
2384 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2385 prop_atoms.net_wm_state_add;
2386 else if (state == prop_atoms.net_wm_state_shaded)
2387 action = self->shaded ? prop_atoms.net_wm_state_remove :
2388 prop_atoms.net_wm_state_add;
2389 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2390 action = self->skip_taskbar ?
2391 prop_atoms.net_wm_state_remove :
2392 prop_atoms.net_wm_state_add;
2393 else if (state == prop_atoms.net_wm_state_skip_pager)
2394 action = self->skip_pager ?
2395 prop_atoms.net_wm_state_remove :
2396 prop_atoms.net_wm_state_add;
2397 else if (state == prop_atoms.net_wm_state_fullscreen)
2398 action = self->fullscreen ?
2399 prop_atoms.net_wm_state_remove :
2400 prop_atoms.net_wm_state_add;
2401 else if (state == prop_atoms.net_wm_state_above)
2402 action = self->above ? prop_atoms.net_wm_state_remove :
2403 prop_atoms.net_wm_state_add;
2404 else if (state == prop_atoms.net_wm_state_below)
2405 action = self->below ? prop_atoms.net_wm_state_remove :
2406 prop_atoms.net_wm_state_add;
2409 if (action == prop_atoms.net_wm_state_add) {
2410 if (state == prop_atoms.net_wm_state_modal) {
2411 /* XXX raise here or something? */
2413 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2415 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2417 } else if (state == prop_atoms.net_wm_state_shaded) {
2419 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2420 self->skip_taskbar = TRUE;
2421 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2422 self->skip_pager = TRUE;
2423 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2425 } else if (state == prop_atoms.net_wm_state_above) {
2427 } else if (state == prop_atoms.net_wm_state_below) {
2431 } else { /* action == prop_atoms.net_wm_state_remove */
2432 if (state == prop_atoms.net_wm_state_modal) {
2433 self->modal = FALSE;
2434 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2436 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2438 } else if (state == prop_atoms.net_wm_state_shaded) {
2440 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2441 self->skip_taskbar = FALSE;
2442 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2443 self->skip_pager = FALSE;
2444 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2446 } else if (state == prop_atoms.net_wm_state_above) {
2447 self->above = FALSE;
2448 } else if (state == prop_atoms.net_wm_state_below) {
2449 self->below = FALSE;
2453 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2454 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2456 if (max_horz == max_vert) { /* both going the same way */
2457 client_maximize(self, max_horz, 0, TRUE);
2459 client_maximize(self, max_horz, 1, TRUE);
2460 client_maximize(self, max_vert, 2, TRUE);
2464 if (max_horz != self->max_horz)
2465 client_maximize(self, max_horz, 1, TRUE);
2467 client_maximize(self, max_vert, 2, TRUE);
2470 /* change fullscreen state before shading, as it will affect if the window
2472 if (fullscreen != self->fullscreen)
2473 client_fullscreen(self, fullscreen, TRUE);
2474 if (shaded != self->shaded)
2475 client_shade(self, shaded);
2476 client_calc_layer(self);
2477 client_change_state(self); /* change the hint to reflect these changes */
2480 ObClient *client_focus_target(ObClient *self)
2484 /* if we have a modal child, then focus it, not us */
2485 child = client_search_modal_child(self);
2486 if (child) return child;
2490 gboolean client_can_focus(ObClient *self)
2494 /* choose the correct target */
2495 self = client_focus_target(self);
2497 if (!self->frame->visible)
2500 if (!((self->can_focus || self->focus_notify) &&
2501 (self->desktop == screen_desktop ||
2502 self->desktop == DESKTOP_ALL) &&
2506 /* do a check to see if the window has already been unmapped or destroyed
2507 do this intelligently while watching out for unmaps we've generated
2508 (ignore_unmaps > 0) */
2509 if (XCheckTypedWindowEvent(ob_display, self->window,
2510 DestroyNotify, &ev)) {
2511 XPutBackEvent(ob_display, &ev);
2514 while (XCheckTypedWindowEvent(ob_display, self->window,
2515 UnmapNotify, &ev)) {
2516 if (self->ignore_unmaps) {
2517 self->ignore_unmaps--;
2519 XPutBackEvent(ob_display, &ev);
2527 gboolean client_focus(ObClient *self)
2529 /* choose the correct target */
2530 self = client_focus_target(self);
2532 if (!self->frame->visible) {
2533 /* update the focus lists */
2534 focus_order_to_top(self);
2538 if (!client_can_focus(self))
2541 if (self->can_focus) {
2542 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2543 I choose to use it always, hopefully to find errors quicker, if any
2544 are left. (I hate X. I hate focus events.)
2546 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2547 #799. So now it is RevertToNone again.
2549 XSetInputFocus(ob_display, self->window, RevertToNone,
2553 if (self->focus_notify) {
2555 ce.xclient.type = ClientMessage;
2556 ce.xclient.message_type = prop_atoms.wm_protocols;
2557 ce.xclient.display = ob_display;
2558 ce.xclient.window = self->window;
2559 ce.xclient.format = 32;
2560 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2561 ce.xclient.data.l[1] = event_lasttime;
2562 ce.xclient.data.l[2] = 0l;
2563 ce.xclient.data.l[3] = 0l;
2564 ce.xclient.data.l[4] = 0l;
2565 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2568 focus_set_client(self);
2571 ob_debug("%sively focusing %lx at %d\n",
2572 (self->can_focus ? "act" : "pass"),
2573 self->window, (int) event_lasttime);
2576 /* Cause the FocusIn to come back to us. Important for desktop switches,
2577 since otherwise we'll have no FocusIn on the queue and send it off to
2578 the focus_backup. */
2579 XSync(ob_display, FALSE);
2583 void client_unfocus(ObClient *self)
2585 g_assert(focus_client == self);
2587 ob_debug("client_unfocus for %lx\n", self->window);
2589 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2592 void client_activate(ObClient *self, gboolean here)
2594 if (client_normal(self) && screen_showing_desktop)
2595 screen_show_desktop(FALSE);
2597 client_iconify(self, FALSE, FALSE);
2598 if (self->desktop != DESKTOP_ALL &&
2599 self->desktop != screen_desktop) {
2601 client_set_desktop(self, screen_desktop, FALSE);
2603 screen_set_desktop(self->desktop);
2604 } else if (!self->frame->visible)
2605 /* if its not visible for other reasons, then don't mess
2609 client_shade(self, FALSE);
2611 stacking_raise(CLIENT_AS_WINDOW(self));
2614 gboolean client_focused(ObClient *self)
2616 return self == focus_client;
2619 ObClientIcon *client_icon(ObClient *self, int w, int h)
2622 /* si is the smallest image >= req */
2623 /* li is the largest image < req */
2624 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2626 for (i = 0; i < self->nicons; ++i) {
2627 size = self->icons[i].width * self->icons[i].height;
2628 if (size < smallest && size >= (unsigned)(w * h)) {
2632 if (size > largest && size <= (unsigned)(w * h)) {
2637 if (largest == 0) /* didnt find one smaller than the requested size */
2638 return &self->icons[si];
2639 return &self->icons[li];
2642 /* this be mostly ripped from fvwm */
2643 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2645 int my_cx, my_cy, his_cx, his_cy;
2648 int score, best_score;
2649 ObClient *best_client, *cur;
2655 /* first, find the centre coords of the currently focused window */
2656 my_cx = c->frame->area.x + c->frame->area.width / 2;
2657 my_cy = c->frame->area.y + c->frame->area.height / 2;
2662 for(it = g_list_first(client_list); it; it = it->next) {
2665 /* the currently selected window isn't interesting */
2668 if (!client_normal(cur))
2670 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2674 if(client_focus_target(cur) == cur &&
2675 !(cur->can_focus || cur->focus_notify))
2678 /* find the centre coords of this window, from the
2679 * currently focused window's point of view */
2680 his_cx = (cur->frame->area.x - my_cx)
2681 + cur->frame->area.width / 2;
2682 his_cy = (cur->frame->area.y - my_cy)
2683 + cur->frame->area.height / 2;
2685 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2686 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2688 /* Rotate the diagonals 45 degrees counterclockwise.
2689 * To do this, multiply the matrix /+h +h\ with the
2690 * vector (x y). \-h +h/
2691 * h = sqrt(0.5). We can set h := 1 since absolute
2692 * distance doesn't matter here. */
2693 tx = his_cx + his_cy;
2694 his_cy = -his_cx + his_cy;
2699 case OB_DIRECTION_NORTH:
2700 case OB_DIRECTION_SOUTH:
2701 case OB_DIRECTION_NORTHEAST:
2702 case OB_DIRECTION_SOUTHWEST:
2703 offset = (his_cx < 0) ? -his_cx : his_cx;
2704 distance = ((dir == OB_DIRECTION_NORTH ||
2705 dir == OB_DIRECTION_NORTHEAST) ?
2708 case OB_DIRECTION_EAST:
2709 case OB_DIRECTION_WEST:
2710 case OB_DIRECTION_SOUTHEAST:
2711 case OB_DIRECTION_NORTHWEST:
2712 offset = (his_cy < 0) ? -his_cy : his_cy;
2713 distance = ((dir == OB_DIRECTION_WEST ||
2714 dir == OB_DIRECTION_NORTHWEST) ?
2719 /* the target must be in the requested direction */
2723 /* Calculate score for this window. The smaller the better. */
2724 score = distance + offset;
2726 /* windows more than 45 degrees off the direction are
2727 * heavily penalized and will only be chosen if nothing
2728 * else within a million pixels */
2729 if(offset > distance)
2732 if(best_score == -1 || score < best_score)
2740 void client_set_layer(ObClient *self, int layer)
2744 self->above = FALSE;
2745 } else if (layer == 0) {
2746 self->below = self->above = FALSE;
2748 self->below = FALSE;
2751 client_calc_layer(self);
2752 client_change_state(self); /* reflect this in the state hints */
2755 guint client_monitor(ObClient *self)
2759 for (i = 0; i < screen_num_monitors; ++i) {
2760 Rect *area = screen_physical_area_monitor(i);
2761 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2764 if (i == screen_num_monitors) i = 0;
2765 g_assert(i < screen_num_monitors);
2769 ObClient *client_search_top_transient(ObClient *self)
2771 /* move up the transient chain as far as possible */
2772 if (self->transient_for) {
2773 if (self->transient_for != OB_TRAN_GROUP) {
2774 return client_search_top_transient(self->transient_for);
2778 for (it = self->group->members; it; it = it->next) {
2779 ObClient *c = it->data;
2781 /* checking transient_for prevents infinate loops! */
2782 if (c != self && !c->transient_for)
2793 ObClient *client_search_transient(ObClient *self, ObClient *search)
2797 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2798 if (sit->data == search)
2800 if (client_search_transient(sit->data, search))
2806 void client_update_sm_client_id(ObClient *self)
2808 g_free(self->sm_client_id);
2809 self->sm_client_id = NULL;
2811 if (!PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id) &&
2813 PROP_GETS(self->group->leader, sm_client_id, locale,
2814 &self->sm_client_id);
2817 /* finds the nearest edge in the given direction from the current client
2818 * note to self: the edge is the -frame- edge (the actual one), not the
2821 int client_directional_edge_search(ObClient *c, ObDirection dir)
2824 int my_edge_start, my_edge_end, my_offset;
2831 a = screen_area(c->desktop);
2834 case OB_DIRECTION_NORTH:
2835 my_edge_start = c->frame->area.x;
2836 my_edge_end = c->frame->area.x + c->frame->area.width;
2837 my_offset = c->frame->area.y;
2839 dest = a->y; /* default: top of screen */
2841 for(it = g_list_first(client_list); it; it = it->next) {
2842 int his_edge_start, his_edge_end, his_offset;
2843 ObClient *cur = it->data;
2847 if(!client_normal(cur))
2849 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2854 his_edge_start = cur->frame->area.x;
2855 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2856 his_offset = cur->frame->area.y + cur->frame->area.height;
2858 if(his_offset + 1 > my_offset)
2861 if(his_offset < dest)
2864 if(his_edge_start >= my_edge_start &&
2865 his_edge_start <= my_edge_end)
2868 if(my_edge_start >= his_edge_start &&
2869 my_edge_start <= his_edge_end)
2874 case OB_DIRECTION_SOUTH:
2875 my_edge_start = c->frame->area.x;
2876 my_edge_end = c->frame->area.x + c->frame->area.width;
2877 my_offset = c->frame->area.y + c->frame->area.height;
2879 dest = a->y + a->height; /* default: bottom of screen */
2881 for(it = g_list_first(client_list); it; it = it->next) {
2882 int his_edge_start, his_edge_end, his_offset;
2883 ObClient *cur = it->data;
2887 if(!client_normal(cur))
2889 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2894 his_edge_start = cur->frame->area.x;
2895 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2896 his_offset = cur->frame->area.y;
2899 if(his_offset - 1 < my_offset)
2902 if(his_offset > dest)
2905 if(his_edge_start >= my_edge_start &&
2906 his_edge_start <= my_edge_end)
2909 if(my_edge_start >= his_edge_start &&
2910 my_edge_start <= his_edge_end)
2915 case OB_DIRECTION_WEST:
2916 my_edge_start = c->frame->area.y;
2917 my_edge_end = c->frame->area.y + c->frame->area.height;
2918 my_offset = c->frame->area.x;
2920 dest = a->x; /* default: leftmost egde of screen */
2922 for(it = g_list_first(client_list); it; it = it->next) {
2923 int his_edge_start, his_edge_end, his_offset;
2924 ObClient *cur = it->data;
2928 if(!client_normal(cur))
2930 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2935 his_edge_start = cur->frame->area.y;
2936 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2937 his_offset = cur->frame->area.x + cur->frame->area.width;
2939 if(his_offset + 1 > my_offset)
2942 if(his_offset < dest)
2945 if(his_edge_start >= my_edge_start &&
2946 his_edge_start <= my_edge_end)
2949 if(my_edge_start >= his_edge_start &&
2950 my_edge_start <= his_edge_end)
2956 case OB_DIRECTION_EAST:
2957 my_edge_start = c->frame->area.y;
2958 my_edge_end = c->frame->area.y + c->frame->area.height;
2959 my_offset = c->frame->area.x + c->frame->area.width;
2961 dest = a->x + a->width; /* default: rightmost edge of screen */
2963 for(it = g_list_first(client_list); it; it = it->next) {
2964 int his_edge_start, his_edge_end, his_offset;
2965 ObClient *cur = it->data;
2969 if(!client_normal(cur))
2971 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2976 his_edge_start = cur->frame->area.y;
2977 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2978 his_offset = cur->frame->area.x;
2980 if(his_offset - 1 < my_offset)
2983 if(his_offset > dest)
2986 if(his_edge_start >= my_edge_start &&
2987 his_edge_start <= my_edge_end)
2990 if(my_edge_start >= his_edge_start &&
2991 my_edge_start <= his_edge_end)
2996 case OB_DIRECTION_NORTHEAST:
2997 case OB_DIRECTION_SOUTHEAST:
2998 case OB_DIRECTION_NORTHWEST:
2999 case OB_DIRECTION_SOUTHWEST:
3000 /* not implemented */
3003 g_assert_not_reached();