7 #include "moveresize.h"
9 #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;
37 static void client_get_all(ObClient *self);
38 static void client_toggle_border(ObClient *self, gboolean show);
39 static void client_get_area(ObClient *self);
40 static void client_get_desktop(ObClient *self);
41 static void client_get_state(ObClient *self);
42 static void client_get_shaped(ObClient *self);
43 static void client_get_mwm_hints(ObClient *self);
44 static void client_get_gravity(ObClient *self);
45 static void client_showhide(ObClient *self);
46 static void client_change_allowed_actions(ObClient *self);
47 static void client_change_state(ObClient *self);
48 static void client_apply_startup_state(ObClient *self);
49 static void client_restore_session_state(ObClient *self);
50 static void client_restore_session_stacking(ObClient *self);
57 void client_shutdown()
61 void client_set_list()
63 Window *windows, *win_it;
65 guint size = g_list_length(client_list);
67 /* create an array of the window ids */
69 windows = g_new(Window, size);
71 for (it = client_list; it != NULL; it = it->next, ++win_it)
72 *win_it = ((ObClient*)it->data)->window;
76 PROP_SETA32(RootWindow(ob_display, ob_screen),
77 net_client_list, window, (guint32*)windows, size);
86 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
90 for (it = self->transients; it; it = it->next) {
91 if (!func(it->data, data)) return;
92 client_foreach_transient(it->data, func, data);
96 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
98 if (self->transient_for) {
99 if (self->transient_for != OB_TRAN_GROUP) {
100 if (!func(self->transient_for, data)) return;
101 client_foreach_ancestor(self->transient_for, func, data);
105 for (it = self->group->members; it; it = it->next)
106 if (it->data != self &&
107 !((ObClient*)it->data)->transient_for) {
108 if (!func(it->data, data)) return;
109 client_foreach_ancestor(it->data, func, data);
116 void client_manage_all()
118 unsigned int i, j, nchild;
121 XWindowAttributes attrib;
123 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
124 &w, &w, &children, &nchild);
126 /* remove all icon windows from the list */
127 for (i = 0; i < nchild; i++) {
128 if (children[i] == None) continue;
129 wmhints = XGetWMHints(ob_display, children[i]);
131 if ((wmhints->flags & IconWindowHint) &&
132 (wmhints->icon_window != children[i]))
133 for (j = 0; j < nchild; j++)
134 if (children[j] == wmhints->icon_window) {
142 for (i = 0; i < nchild; ++i) {
143 if (children[i] == None)
145 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
146 if (attrib.override_redirect) continue;
148 if (attrib.map_state != IsUnmapped)
149 client_manage(children[i]);
154 /* stack them as they were on startup!
155 why with stacking_lower? Why, because then windows who aren't in the
156 stacking list are on the top where you can see them instead of buried
158 for (i = startup_stack_size; i > 0; --i) {
161 w = startup_stack_order[i-1];
162 obw = g_hash_table_lookup(window_map, &w);
164 g_assert(WINDOW_IS_CLIENT(obw));
165 stacking_lower(CLIENT_AS_WINDOW(obw));
168 g_free(startup_stack_order);
169 startup_stack_order = NULL;
170 startup_stack_size = 0;
172 if (config_focus_new) {
175 active = g_hash_table_lookup(window_map, &startup_active);
177 g_assert(WINDOW_IS_CLIENT(active));
178 if (!client_focus(WINDOW_AS_CLIENT(active)))
179 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
181 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
185 void client_manage(Window window)
189 XWindowAttributes attrib;
190 XSetWindowAttributes attrib_set;
192 gboolean activate = FALSE;
196 /* check if it has already been unmapped by the time we started mapping
197 the grab does a sync so we don't have to here */
198 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
199 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e)) {
200 XPutBackEvent(ob_display, &e);
203 return; /* don't manage it */
206 /* make sure it isn't an override-redirect window */
207 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
208 attrib.override_redirect) {
210 return; /* don't manage it */
213 /* is the window a docking app */
214 if ((wmhint = XGetWMHints(ob_display, window))) {
215 if ((wmhint->flags & StateHint) &&
216 wmhint->initial_state == WithdrawnState) {
217 dock_add(window, wmhint);
225 ob_debug("Managing window: %lx\n", window);
227 /* choose the events we want to receive on the CLIENT window */
228 attrib_set.event_mask = CLIENT_EVENTMASK;
229 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
230 XChangeWindowAttributes(ob_display, window,
231 CWEventMask|CWDontPropagate, &attrib_set);
234 /* create the ObClient struct, and populate it from the hints on the
236 self = g_new0(ObClient, 1);
237 self->obwin.type = Window_Client;
238 self->window = window;
240 client_get_all(self);
241 client_restore_session_state(self);
243 client_change_state(self);
245 /* remove the client's border (and adjust re gravity) */
246 client_toggle_border(self, FALSE);
248 /* specify that if we exit, the window should not be destroyed and should
249 be reparented back to root automatically */
250 XChangeSaveSet(ob_display, window, SetModeInsert);
252 /* create the decoration frame for the client window */
253 self->frame = frame_new();
255 frame_grab_client(self->frame, self);
257 client_apply_startup_state(self);
261 /* update the focus lists */
262 focus_order_add_new(self);
264 stacking_add(CLIENT_AS_WINDOW(self));
265 client_restore_session_stacking(self);
267 /* focus the new window? */
268 if (ob_state() != OB_STATE_STARTING && config_focus_new &&
269 /* note the check against Type_Normal/Dialog, not client_normal(self),
270 which would also include other types. in this case we want more
271 strict rules for focus */
272 (self->type == OB_CLIENT_TYPE_NORMAL ||
273 self->type == OB_CLIENT_TYPE_DIALOG))
277 if (self->desktop != screen_desktop) {
278 /* activate the window */
281 gboolean group_foc = FALSE;
286 for (it = self->group->members; it; it = it->next)
288 if (client_focused(it->data))
296 (!self->transient_for && (!self->group ||
297 !self->group->members->next))) ||
298 client_search_focus_tree_full(self) ||
300 !client_normal(focus_client))
302 /* activate the window */
309 dispatch_client(Event_Client_New, self, 0, 0);
311 /* make sure the window is visible */
312 if (ob_state() == OB_STATE_RUNNING)
313 client_move_onscreen(self, client_normal(self));
315 client_showhide(self);
317 /* use client_focus instead of client_activate cuz client_activate does
318 stuff like switch desktops etc and I'm not interested in all that when
319 a window maps since its not based on an action from the user like
320 clicking a window to activate is. so keep the new window out of the way
322 if (activate) client_focus(self);
324 /* client_activate does this but we aret using it so we have to do it
326 if (screen_showing_desktop)
327 screen_show_desktop(FALSE);
329 /* add to client list/map */
330 client_list = g_list_append(client_list, self);
331 g_hash_table_insert(window_map, &self->window, self);
333 /* this has to happen after we're in the client_list */
334 screen_update_areas();
336 /* update the list hints */
339 keyboard_grab_for_client(self, TRUE);
340 mouse_grab_for_client(self, TRUE);
342 dispatch_client(Event_Client_Mapped, self, 0, 0);
344 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
347 void client_unmanage_all()
349 while (client_list != NULL)
350 client_unmanage(client_list->data);
353 void client_unmanage(ObClient *self)
358 ob_debug("Unmanaging window: %lx (%s)\n", self->window, self->class);
360 dispatch_client(Event_Client_Destroy, self, 0, 0);
361 g_assert(self != NULL);
363 keyboard_grab_for_client(self, FALSE);
364 mouse_grab_for_client(self, FALSE);
366 /* remove the window from our save set */
367 XChangeSaveSet(ob_display, self->window, SetModeDelete);
369 /* we dont want events no more */
370 XSelectInput(ob_display, self->window, NoEventMask);
372 frame_hide(self->frame);
374 client_list = g_list_remove(client_list, self);
375 stacking_remove(self);
376 g_hash_table_remove(window_map, &self->window);
378 /* update the focus lists */
379 focus_order_remove(self);
381 /* once the client is out of the list, update the struts to remove it's
383 screen_update_areas();
385 /* tell our parent(s) that we're gone */
386 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
389 for (it = self->group->members; it; it = it->next)
390 if (it->data != self)
391 ((ObClient*)it->data)->transients =
392 g_slist_remove(((ObClient*)it->data)->transients, self);
393 } else if (self->transient_for) { /* transient of window */
394 self->transient_for->transients =
395 g_slist_remove(self->transient_for->transients, self);
398 /* tell our transients that we're gone */
399 for (it = self->transients; it != NULL; it = it->next) {
400 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
401 ((ObClient*)it->data)->transient_for = NULL;
402 client_calc_layer(it->data);
406 if (moveresize_client == self)
407 moveresize_end(TRUE);
409 /* menus can be associated with a client, so close any that are since
410 we are disappearing now */
411 menu_frame_hide_all_client(self);
413 if (focus_client == self) {
416 /* focus the last focused window on the desktop, and ignore enter
417 events from the unmap so it doesnt mess with the focus */
418 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
419 client_unfocus(self);
422 /* remove from its group */
424 group_remove(self->group, self);
428 /* dispatch the unmapped event */
429 dispatch_client(Event_Client_Unmapped, self, 0, 0);
430 g_assert(self != NULL);
432 /* give the client its border back */
433 client_toggle_border(self, TRUE);
435 /* reparent the window out of the frame, and free the frame */
436 frame_release_client(self->frame, self);
439 if (ob_state() != OB_STATE_EXITING) {
440 /* these values should not be persisted across a window
442 PROP_ERASE(self->window, net_wm_desktop);
443 PROP_ERASE(self->window, net_wm_state);
444 PROP_ERASE(self->window, wm_state);
446 /* if we're left in an iconic state, the client wont be mapped. this is
447 bad, since we will no longer be managing the window on restart */
449 XMapWindow(ob_display, self->window);
453 ob_debug("Unmanaged window 0x%lx\n", self->window);
455 /* free all data allocated in the client struct */
456 g_slist_free(self->transients);
457 for (j = 0; j < self->nicons; ++j)
458 g_free(self->icons[j].data);
459 if (self->nicons > 0)
462 g_free(self->icon_title);
468 /* update the list hints */
472 static void client_restore_session_state(ObClient *self)
476 if (!(it = session_state_find(self)))
479 self->session = it->data;
481 RECT_SET(self->area, self->session->x, self->session->y,
482 self->session->w, self->session->h);
483 self->positioned = TRUE;
484 XResizeWindow(ob_display, self->window,
485 self->session->w, self->session->h);
487 self->desktop = (self->session->desktop == DESKTOP_ALL ?
488 self->session->desktop :
489 MIN(screen_num_desktops - 1, self->session->desktop));
490 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
492 self->shaded = self->session->shaded;
493 self->iconic = self->session->iconic;
494 self->skip_pager = self->session->skip_pager;
495 self->skip_taskbar = self->session->skip_taskbar;
496 self->fullscreen = self->session->fullscreen;
497 self->above = self->session->above;
498 self->below = self->session->below;
499 self->max_horz = self->session->max_horz;
500 self->max_vert = self->session->max_vert;
503 static void client_restore_session_stacking(ObClient *self)
507 if (!self->session) return;
509 it = g_list_find(session_saved_state, self->session);
510 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
513 for (cit = client_list; cit; cit = g_list_next(cit))
514 if (session_state_cmp(it->data, cit->data))
517 client_calc_layer(self);
518 stacking_below(CLIENT_AS_WINDOW(self),
519 CLIENT_AS_WINDOW(cit->data));
525 void client_move_onscreen(ObClient *self, gboolean rude)
527 int x = self->area.x;
528 int y = self->area.y;
529 if (client_find_onscreen(self, &x, &y,
530 self->frame->area.width,
531 self->frame->area.height, rude)) {
532 client_configure(self, OB_CORNER_TOPLEFT, x, y,
533 self->area.width, self->area.height,
538 gboolean client_find_onscreen(ObClient *self, int *x, int *y, int w, int h,
542 int ox = *x, oy = *y;
544 frame_client_gravity(self->frame, x, y); /* get where the frame
547 /* XXX watch for xinerama dead areas */
549 a = screen_area(self->desktop);
550 if (!self->strut.right && *x >= a->x + a->width - 1)
551 *x = a->x + a->width - self->frame->area.width;
552 if (!self->strut.bottom && *y >= a->y + a->height - 1)
553 *y = a->y + a->height - self->frame->area.height;
554 if (!self->strut.left && *x + self->frame->area.width - 1 < a->x)
556 if (!self->strut.top && *y + self->frame->area.height - 1 < a->y)
560 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
561 Java can suck it too. */
563 /* dont let windows map/move into the strut unless they
564 are bigger than the available area */
566 if (!self->strut.left && *x < a->x) *x = a->x;
567 if (!self->strut.right && *x + w > a->x + a->width)
568 *x = a->x + a->width - w;
570 if (h <= a->height) {
571 if (!self->strut.top && *y < a->y) *y = a->y;
572 if (!self->strut.bottom && *y + h > a->y + a->height)
573 *y = a->y + a->height - h;
577 frame_frame_gravity(self->frame, x, y); /* get where the client
580 return ox != *x || oy != *y;
583 static void client_toggle_border(ObClient *self, gboolean show)
585 /* adjust our idea of where the client is, based on its border. When the
586 border is removed, the client should now be considered to be in a
588 when re-adding the border to the client, the same operation needs to be
590 int oldx = self->area.x, oldy = self->area.y;
591 int x = oldx, y = oldy;
592 switch(self->gravity) {
594 case NorthWestGravity:
596 case SouthWestGravity:
598 case NorthEastGravity:
600 case SouthEastGravity:
601 if (show) x -= self->border_width * 2;
602 else x += self->border_width * 2;
609 if (show) x -= self->border_width;
610 else x += self->border_width;
613 switch(self->gravity) {
615 case NorthWestGravity:
617 case NorthEastGravity:
619 case SouthWestGravity:
621 case SouthEastGravity:
622 if (show) y -= self->border_width * 2;
623 else y += self->border_width * 2;
630 if (show) y -= self->border_width;
631 else y += self->border_width;
638 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
640 /* move the client so it is back it the right spot _with_ its
642 if (x != oldx || y != oldy)
643 XMoveWindow(ob_display, self->window, x, y);
645 XSetWindowBorderWidth(ob_display, self->window, 0);
649 static void client_get_all(ObClient *self)
651 /* non-zero defaults */
652 self->title_count = 1;
653 self->wmstate = NormalState;
655 self->decorate = TRUE;
657 client_get_area(self);
658 client_update_transient_for(self);
659 client_update_wmhints(self);
660 client_get_desktop(self);
661 client_get_state(self);
662 client_get_shaped(self);
664 client_get_mwm_hints(self);
665 client_get_type(self);/* this can change the mwmhints for special cases */
667 client_update_protocols(self);
669 client_get_gravity(self); /* get the attribute gravity */
670 client_update_normal_hints(self); /* this may override the attribute
673 /* got the type, the mwmhints, the protocols, and the normal hints
674 (min/max sizes), so we're ready to set up the decorations/functions */
675 client_setup_decor_and_functions(self);
677 client_update_title(self);
678 client_update_class(self);
679 client_update_strut(self);
680 client_update_icons(self);
683 static void client_get_area(ObClient *self)
685 XWindowAttributes wattrib;
688 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
689 g_assert(ret != BadWindow);
691 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
692 self->border_width = wattrib.border_width;
695 static void client_get_desktop(ObClient *self)
697 guint32 d = screen_num_desktops; /* an always-invalid value */
699 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
700 if (d >= screen_num_desktops && d != DESKTOP_ALL)
701 self->desktop = screen_num_desktops - 1;
705 gboolean trdesk = FALSE;
707 if (self->transient_for) {
708 if (self->transient_for != OB_TRAN_GROUP) {
709 self->desktop = self->transient_for->desktop;
714 for (it = self->group->members; it; it = it->next)
715 if (it->data != self &&
716 !((ObClient*)it->data)->transient_for) {
717 self->desktop = ((ObClient*)it->data)->desktop;
724 /* defaults to the current desktop */
725 self->desktop = screen_desktop;
727 if (self->desktop != d) {
728 /* set the desktop hint, to make sure that it always exists */
729 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
733 static void client_get_state(ObClient *self)
738 self->modal = self->shaded = self->max_horz = self->max_vert =
739 self->fullscreen = self->above = self->below = self->iconic =
740 self->skip_taskbar = self->skip_pager = FALSE;
742 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
744 for (i = 0; i < num; ++i) {
745 if (state[i] == prop_atoms.net_wm_state_modal)
747 else if (state[i] == prop_atoms.net_wm_state_shaded)
749 else if (state[i] == prop_atoms.net_wm_state_hidden)
751 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
752 self->skip_taskbar = TRUE;
753 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
754 self->skip_pager = TRUE;
755 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
756 self->fullscreen = TRUE;
757 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
758 self->max_vert = TRUE;
759 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
760 self->max_horz = TRUE;
761 else if (state[i] == prop_atoms.net_wm_state_above)
763 else if (state[i] == prop_atoms.net_wm_state_below)
771 static void client_get_shaped(ObClient *self)
773 self->shaped = FALSE;
775 if (extensions_shape) {
780 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
782 XShapeQueryExtents(ob_display, self->window, &s, &foo,
783 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
785 self->shaped = (s != 0);
790 void client_update_transient_for(ObClient *self)
793 ObClient *target = NULL;
795 if (XGetTransientForHint(ob_display, self->window, &t)) {
796 self->transient = TRUE;
797 if (t != self->window) { /* cant be transient to itself! */
798 target = g_hash_table_lookup(window_map, &t);
799 /* if this happens then we need to check for it*/
800 g_assert(target != self);
801 g_assert(!target || WINDOW_IS_CLIENT(target));
803 if (!target && self->group) {
804 /* not transient to a client, see if it is transient for a
806 if (t == self->group->leader ||
808 t == RootWindow(ob_display, ob_screen)) {
809 /* window is a transient for its group! */
810 target = OB_TRAN_GROUP;
815 self->transient = FALSE;
817 /* if anything has changed... */
818 if (target != self->transient_for) {
819 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
822 /* remove from old parents */
823 for (it = self->group->members; it; it = g_slist_next(it)) {
824 ObClient *c = it->data;
825 if (c != self && !c->transient_for)
826 c->transients = g_slist_remove(c->transients, self);
828 } else if (self->transient_for != NULL) { /* transient of window */
829 /* remove from old parent */
830 self->transient_for->transients =
831 g_slist_remove(self->transient_for->transients, self);
833 self->transient_for = target;
834 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
837 /* add to new parents */
838 for (it = self->group->members; it; it = g_slist_next(it)) {
839 ObClient *c = it->data;
840 if (c != self && !c->transient_for)
841 c->transients = g_slist_append(c->transients, self);
844 /* remove all transients which are in the group, that causes
845 circlular pointer hell of doom */
846 for (it = self->group->members; it; it = g_slist_next(it)) {
848 for (sit = self->transients; sit; sit = next) {
849 next = g_slist_next(sit);
850 if (sit->data == it->data)
852 g_slist_delete_link(self->transients, sit);
855 } else if (self->transient_for != NULL) { /* transient of window */
856 /* add to new parent */
857 self->transient_for->transients =
858 g_slist_append(self->transient_for->transients, self);
863 static void client_get_mwm_hints(ObClient *self)
868 self->mwmhints.flags = 0; /* default to none */
870 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
872 if (num >= OB_MWM_ELEMENTS) {
873 self->mwmhints.flags = hints[0];
874 self->mwmhints.functions = hints[1];
875 self->mwmhints.decorations = hints[2];
881 void client_get_type(ObClient *self)
888 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
889 /* use the first value that we know about in the array */
890 for (i = 0; i < num; ++i) {
891 if (val[i] == prop_atoms.net_wm_window_type_desktop)
892 self->type = OB_CLIENT_TYPE_DESKTOP;
893 else if (val[i] == prop_atoms.net_wm_window_type_dock)
894 self->type = OB_CLIENT_TYPE_DOCK;
895 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
896 self->type = OB_CLIENT_TYPE_TOOLBAR;
897 else if (val[i] == prop_atoms.net_wm_window_type_menu)
898 self->type = OB_CLIENT_TYPE_MENU;
899 else if (val[i] == prop_atoms.net_wm_window_type_utility)
900 self->type = OB_CLIENT_TYPE_UTILITY;
901 else if (val[i] == prop_atoms.net_wm_window_type_splash)
902 self->type = OB_CLIENT_TYPE_SPLASH;
903 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
904 self->type = OB_CLIENT_TYPE_DIALOG;
905 else if (val[i] == prop_atoms.net_wm_window_type_normal)
906 self->type = OB_CLIENT_TYPE_NORMAL;
907 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
908 /* prevent this window from getting any decor or
910 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
911 OB_MWM_FLAG_DECORATIONS);
912 self->mwmhints.decorations = 0;
913 self->mwmhints.functions = 0;
915 if (self->type != (ObClientType) -1)
916 break; /* grab the first legit type */
921 if (self->type == (ObClientType) -1) {
922 /*the window type hint was not set, which means we either classify
923 ourself as a normal window or a dialog, depending on if we are a
926 self->type = OB_CLIENT_TYPE_DIALOG;
928 self->type = OB_CLIENT_TYPE_NORMAL;
932 void client_update_protocols(ObClient *self)
937 self->focus_notify = FALSE;
938 self->delete_window = FALSE;
940 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
941 for (i = 0; i < num_return; ++i) {
942 if (proto[i] == prop_atoms.wm_delete_window) {
943 /* this means we can request the window to close */
944 self->delete_window = TRUE;
945 } else if (proto[i] == prop_atoms.wm_take_focus)
946 /* if this protocol is requested, then the window will be
947 notified whenever we want it to receive focus */
948 self->focus_notify = TRUE;
954 static void client_get_gravity(ObClient *self)
956 XWindowAttributes wattrib;
959 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
960 g_assert(ret != BadWindow);
961 self->gravity = wattrib.win_gravity;
964 void client_update_normal_hints(ObClient *self)
968 int oldgravity = self->gravity;
971 self->min_ratio = 0.0f;
972 self->max_ratio = 0.0f;
973 SIZE_SET(self->size_inc, 1, 1);
974 SIZE_SET(self->base_size, 0, 0);
975 SIZE_SET(self->min_size, 0, 0);
976 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
978 /* get the hints from the window */
979 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
980 self->positioned = !!(size.flags & (PPosition|USPosition));
982 if (size.flags & PWinGravity) {
983 self->gravity = size.win_gravity;
985 /* if the client has a frame, i.e. has already been mapped and
986 is changing its gravity */
987 if (self->frame && self->gravity != oldgravity) {
988 /* move our idea of the client's position based on its new
990 self->area.x = self->frame->area.x;
991 self->area.y = self->frame->area.y;
992 frame_frame_gravity(self->frame, &self->area.x, &self->area.y);
996 if (size.flags & PAspect) {
997 if (size.min_aspect.y)
998 self->min_ratio = (float)size.min_aspect.x / size.min_aspect.y;
999 if (size.max_aspect.y)
1000 self->max_ratio = (float)size.max_aspect.x / size.max_aspect.y;
1003 if (size.flags & PMinSize)
1004 SIZE_SET(self->min_size, size.min_width, size.min_height);
1006 if (size.flags & PMaxSize)
1007 SIZE_SET(self->max_size, size.max_width, size.max_height);
1009 if (size.flags & PBaseSize)
1010 SIZE_SET(self->base_size, size.base_width, size.base_height);
1012 if (size.flags & PResizeInc)
1013 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1017 void client_setup_decor_and_functions(ObClient *self)
1019 /* start with everything (cept fullscreen) */
1020 self->decorations = (OB_FRAME_DECOR_TITLEBAR |
1021 OB_FRAME_DECOR_HANDLE |
1022 OB_FRAME_DECOR_GRIPS |
1023 OB_FRAME_DECOR_BORDER |
1024 OB_FRAME_DECOR_ICON |
1025 OB_FRAME_DECOR_ALLDESKTOPS |
1026 OB_FRAME_DECOR_ICONIFY |
1027 OB_FRAME_DECOR_MAXIMIZE |
1028 OB_FRAME_DECOR_SHADE);
1029 self->functions = (OB_CLIENT_FUNC_RESIZE |
1030 OB_CLIENT_FUNC_MOVE |
1031 OB_CLIENT_FUNC_ICONIFY |
1032 OB_CLIENT_FUNC_MAXIMIZE |
1033 OB_CLIENT_FUNC_SHADE);
1034 if (self->delete_window) {
1035 self->functions |= OB_CLIENT_FUNC_CLOSE;
1036 self->decorations |= OB_FRAME_DECOR_CLOSE;
1039 if (!(self->min_size.width < self->max_size.width ||
1040 self->min_size.height < self->max_size.height))
1041 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1043 switch (self->type) {
1044 case OB_CLIENT_TYPE_NORMAL:
1045 /* normal windows retain all of the possible decorations and
1046 functionality, and are the only windows that you can fullscreen */
1047 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1050 case OB_CLIENT_TYPE_DIALOG:
1051 case OB_CLIENT_TYPE_UTILITY:
1052 /* these windows cannot be maximized */
1053 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1056 case OB_CLIENT_TYPE_MENU:
1057 case OB_CLIENT_TYPE_TOOLBAR:
1058 /* these windows get less functionality */
1059 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1062 case OB_CLIENT_TYPE_DESKTOP:
1063 case OB_CLIENT_TYPE_DOCK:
1064 case OB_CLIENT_TYPE_SPLASH:
1065 /* none of these windows are manipulated by the window manager */
1066 self->decorations = 0;
1067 self->functions = 0;
1071 /* Mwm Hints are applied subtractively to what has already been chosen for
1072 decor and functionality */
1073 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1074 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1075 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1076 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1077 /* if the mwm hints request no handle or title, then all
1078 decorations are disabled */
1079 self->decorations = 0;
1083 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1084 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1085 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1086 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1087 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1088 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1089 /* dont let mwm hints kill any buttons
1090 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1091 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1092 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1093 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1095 /* dont let mwm hints kill the close button
1096 if (! (self->mwmhints.functions & MwmFunc_Close))
1097 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1101 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1102 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1103 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1104 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1105 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1106 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1108 /* can't maximize without moving/resizing */
1109 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1110 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1111 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1112 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1113 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1116 /* kill the handle on fully maxed windows */
1117 if (self->max_vert && self->max_horz)
1118 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1120 /* finally, the user can have requested no decorations, which overrides
1122 if (!self->decorate)
1123 self->decorations = OB_FRAME_DECOR_BORDER;
1125 /* if we don't have a titlebar, then we cannot shade! */
1126 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1127 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1129 /* now we need to check against rules for the client's current state */
1130 if (self->fullscreen) {
1131 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1132 OB_CLIENT_FUNC_FULLSCREEN |
1133 OB_CLIENT_FUNC_ICONIFY);
1134 self->decorations = 0;
1137 client_change_allowed_actions(self);
1140 /* adjust the client's decorations, etc. */
1141 client_reconfigure(self);
1143 /* this makes sure that these windows appear on all desktops */
1144 if (self->type == OB_CLIENT_TYPE_DESKTOP &&
1145 self->desktop != DESKTOP_ALL)
1147 self->desktop = DESKTOP_ALL;
1152 static void client_change_allowed_actions(ObClient *self)
1157 /* desktop windows are kept on all desktops */
1158 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1159 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1161 if (self->functions & OB_CLIENT_FUNC_SHADE)
1162 actions[num++] = prop_atoms.net_wm_action_shade;
1163 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1164 actions[num++] = prop_atoms.net_wm_action_close;
1165 if (self->functions & OB_CLIENT_FUNC_MOVE)
1166 actions[num++] = prop_atoms.net_wm_action_move;
1167 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1168 actions[num++] = prop_atoms.net_wm_action_minimize;
1169 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1170 actions[num++] = prop_atoms.net_wm_action_resize;
1171 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1172 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1173 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1174 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1175 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1178 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1180 /* make sure the window isn't breaking any rules now */
1182 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1183 if (self->frame) client_shade(self, FALSE);
1184 else self->shaded = FALSE;
1186 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1187 if (self->frame) client_iconify(self, FALSE, TRUE);
1188 else self->iconic = FALSE;
1190 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1191 if (self->frame) client_fullscreen(self, FALSE, TRUE);
1192 else self->fullscreen = FALSE;
1194 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1196 if (self->frame) client_maximize(self, FALSE, 0, TRUE);
1197 else self->max_vert = self->max_horz = FALSE;
1201 void client_reconfigure(ObClient *self)
1203 /* by making this pass FALSE for user, we avoid the emacs event storm where
1204 every configurenotify causes an update in its normal hints, i think this
1205 is generally what we want anyways... */
1206 client_configure(self, OB_CORNER_TOPLEFT, self->area.x, self->area.y,
1207 self->area.width, self->area.height, FALSE, TRUE);
1210 void client_update_wmhints(ObClient *self)
1213 gboolean ur = FALSE;
1216 /* assume a window takes input if it doesnt specify */
1217 self->can_focus = TRUE;
1219 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1220 if (hints->flags & InputHint)
1221 self->can_focus = hints->input;
1223 /* only do this when first managing the window *AND* when we aren't
1225 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1226 if (hints->flags & StateHint)
1227 self->iconic = hints->initial_state == IconicState;
1229 if (hints->flags & XUrgencyHint)
1232 if (!(hints->flags & WindowGroupHint))
1233 hints->window_group = None;
1235 /* did the group state change? */
1236 if (hints->window_group !=
1237 (self->group ? self->group->leader : None)) {
1238 /* remove from the old group if there was one */
1239 if (self->group != NULL) {
1240 /* remove transients of the group */
1241 for (it = self->group->members; it; it = it->next)
1242 self->transients = g_slist_remove(self->transients,
1244 group_remove(self->group, self);
1247 if (hints->window_group != None) {
1248 self->group = group_add(hints->window_group, self);
1250 /* i can only have transients from the group if i am not
1252 if (!self->transient_for) {
1253 /* add other transients of the group that are already
1255 for (it = self->group->members; it; it = it->next) {
1256 ObClient *c = it->data;
1257 if (c != self && c->transient_for == OB_TRAN_GROUP)
1259 g_slist_append(self->transients, c);
1264 /* because the self->transient flag wont change from this call,
1265 we don't need to update the window's type and such, only its
1266 transient_for, and the transients lists of other windows in
1267 the group may be affected */
1268 client_update_transient_for(self);
1271 /* the WM_HINTS can contain an icon */
1272 client_update_icons(self);
1277 if (ur != self->urgent) {
1279 ob_debug("Urgent Hint for 0x%lx: %s\n", self->window,
1281 /* fire the urgent callback if we're mapped, otherwise, wait until
1282 after we're mapped */
1284 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1288 void client_update_title(ObClient *self)
1294 gboolean read_title;
1296 g_free(self->title);
1299 if (!PROP_GETS(self->window, net_wm_name, utf8, &data))
1300 /* try old x stuff */
1301 if (!PROP_GETS(self->window, wm_name, locale, &data))
1302 data = g_strdup("Unnamed Window");
1304 /* look for duplicates and append a number */
1306 for (it = client_list; it; it = it->next)
1307 if (it->data != self) {
1308 ObClient *c = it->data;
1309 if (0 == strncmp(c->title, data, strlen(data)))
1310 nums |= 1 << c->title_count;
1312 /* find first free number */
1313 for (i = 1; i <= 32; ++i)
1314 if (!(nums & (1 << i))) {
1315 if (self->title_count == 1 || i == 1)
1316 self->title_count = i;
1319 /* dont display the number for the first window */
1320 if (self->title_count > 1) {
1321 char *vdata, *ndata;
1322 ndata = g_strdup_printf(" - [%u]", self->title_count);
1323 vdata = g_strconcat(data, ndata, NULL);
1329 PROP_SETS(self->window, net_wm_visible_name, data);
1334 frame_adjust_title(self->frame);
1336 /* update the icon title */
1338 g_free(self->icon_title);
1342 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1343 /* try old x stuff */
1344 if (!PROP_GETS(self->window, wm_icon_name, locale, &data)) {
1345 data = g_strdup(self->title);
1349 /* append the title count, dont display the number for the first window */
1350 if (read_title && self->title_count > 1) {
1351 char *vdata, *ndata;
1352 ndata = g_strdup_printf(" - [%u]", self->title_count);
1353 vdata = g_strconcat(data, ndata, NULL);
1359 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1361 self->icon_title = data;
1364 void client_update_class(ObClient *self)
1369 if (self->name) g_free(self->name);
1370 if (self->class) g_free(self->class);
1371 if (self->role) g_free(self->role);
1373 self->name = self->class = self->role = NULL;
1375 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1377 self->name = g_strdup(data[0]);
1379 self->class = g_strdup(data[1]);
1384 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1385 self->role = g_strdup(s);
1387 if (self->name == NULL) self->name = g_strdup("");
1388 if (self->class == NULL) self->class = g_strdup("");
1389 if (self->role == NULL) self->role = g_strdup("");
1392 void client_update_strut(ObClient *self)
1396 gboolean got = FALSE;
1399 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1403 STRUT_PARTIAL_SET(strut,
1404 data[0], data[2], data[1], data[3],
1405 data[4], data[5], data[8], data[9],
1406 data[6], data[7], data[10], data[11]);
1412 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1415 STRUT_PARTIAL_SET(strut,
1416 data[0], data[2], data[1], data[3],
1417 0, 0, 0, 0, 0, 0, 0, 0);
1423 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1424 0, 0, 0, 0, 0, 0, 0, 0);
1426 if (!STRUT_EQUAL(strut, self->strut)) {
1427 self->strut = strut;
1429 /* updating here is pointless while we're being mapped cuz we're not in
1430 the client list yet */
1432 screen_update_areas();
1436 void client_update_icons(ObClient *self)
1442 for (i = 0; i < self->nicons; ++i)
1443 g_free(self->icons[i].data);
1444 if (self->nicons > 0)
1445 g_free(self->icons);
1448 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1449 /* figure out how many valid icons are in here */
1451 while (num - i > 2) {
1455 if (i > num || w*h == 0) break;
1459 self->icons = g_new(ObClientIcon, self->nicons);
1461 /* store the icons */
1463 for (j = 0; j < self->nicons; ++j) {
1466 w = self->icons[j].width = data[i++];
1467 h = self->icons[j].height = data[i++];
1469 if (w*h == 0) continue;
1471 self->icons[j].data = g_new(RrPixel32, w * h);
1472 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1477 self->icons[j].data[t] =
1478 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1479 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1480 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1481 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1487 } else if (PROP_GETA32(self->window, kwm_win_icon,
1488 kwm_win_icon, &data, &num)) {
1491 self->icons = g_new(ObClientIcon, self->nicons);
1492 xerror_set_ignore(TRUE);
1493 if (!RrPixmapToRGBA(ob_rr_inst,
1495 &self->icons[self->nicons-1].width,
1496 &self->icons[self->nicons-1].height,
1497 &self->icons[self->nicons-1].data)) {
1498 g_free(&self->icons[self->nicons-1]);
1501 xerror_set_ignore(FALSE);
1507 if ((hints = XGetWMHints(ob_display, self->window))) {
1508 if (hints->flags & IconPixmapHint) {
1510 self->icons = g_new(ObClientIcon, self->nicons);
1511 xerror_set_ignore(TRUE);
1512 if (!RrPixmapToRGBA(ob_rr_inst,
1514 (hints->flags & IconMaskHint ?
1515 hints->icon_mask : None),
1516 &self->icons[self->nicons-1].width,
1517 &self->icons[self->nicons-1].height,
1518 &self->icons[self->nicons-1].data)){
1519 g_free(&self->icons[self->nicons-1]);
1522 xerror_set_ignore(FALSE);
1529 frame_adjust_icon(self->frame);
1532 static void client_change_state(ObClient *self)
1535 guint32 netstate[10];
1538 state[0] = self->wmstate;
1540 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1544 netstate[num++] = prop_atoms.net_wm_state_modal;
1546 netstate[num++] = prop_atoms.net_wm_state_shaded;
1548 netstate[num++] = prop_atoms.net_wm_state_hidden;
1549 if (self->skip_taskbar)
1550 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1551 if (self->skip_pager)
1552 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1553 if (self->fullscreen)
1554 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
1556 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
1558 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
1560 netstate[num++] = prop_atoms.net_wm_state_above;
1562 netstate[num++] = prop_atoms.net_wm_state_below;
1563 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
1565 client_calc_layer(self);
1568 frame_adjust_state(self->frame);
1571 ObClient *client_search_focus_tree(ObClient *self)
1576 for (it = self->transients; it != NULL; it = it->next) {
1577 if (client_focused(it->data)) return it->data;
1578 if ((ret = client_search_focus_tree(it->data))) return ret;
1583 ObClient *client_search_focus_tree_full(ObClient *self)
1585 if (self->transient_for) {
1586 if (self->transient_for != OB_TRAN_GROUP) {
1587 return client_search_focus_tree_full(self->transient_for);
1590 gboolean recursed = FALSE;
1592 for (it = self->group->members; it; it = it->next)
1593 if (!((ObClient*)it->data)->transient_for) {
1595 if ((c = client_search_focus_tree_full(it->data)))
1604 /* this function checks the whole tree, the client_search_focus_tree~
1605 does not, so we need to check this window */
1606 if (client_focused(self))
1608 return client_search_focus_tree(self);
1611 static ObStackingLayer calc_layer(ObClient *self)
1615 if (self->fullscreen) l = OB_STACKING_LAYER_FULLSCREEN;
1616 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
1617 l = OB_STACKING_LAYER_DESKTOP;
1618 else if (self->type == OB_CLIENT_TYPE_DOCK) {
1619 if (!self->below) l = OB_STACKING_LAYER_TOP;
1620 else l = OB_STACKING_LAYER_NORMAL;
1622 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
1623 else if (self->below) l = OB_STACKING_LAYER_BELOW;
1624 else l = OB_STACKING_LAYER_NORMAL;
1629 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
1630 ObStackingLayer l, gboolean raised)
1632 ObStackingLayer old, own;
1636 own = calc_layer(self);
1637 self->layer = l > own ? l : own;
1639 for (it = self->transients; it; it = it->next)
1640 client_calc_layer_recursive(it->data, orig,
1641 l, raised ? raised : l != old);
1643 if (!raised && l != old)
1644 if (orig->frame) { /* only restack if the original window is managed */
1645 /* XXX add_non_intrusive ever? */
1646 stacking_remove(CLIENT_AS_WINDOW(self));
1647 stacking_add(CLIENT_AS_WINDOW(self));
1651 void client_calc_layer(ObClient *self)
1658 /* transients take on the layer of their parents */
1659 self = client_search_top_transient(self);
1661 l = calc_layer(self);
1663 client_calc_layer_recursive(self, orig, l, FALSE);
1666 gboolean client_should_show(ObClient *self)
1668 if (self->iconic) return FALSE;
1669 else if (!(self->desktop == screen_desktop ||
1670 self->desktop == DESKTOP_ALL)) return FALSE;
1671 else if (client_normal(self) && screen_showing_desktop) return FALSE;
1676 static void client_showhide(ObClient *self)
1679 if (client_should_show(self))
1680 frame_show(self->frame);
1682 frame_hide(self->frame);
1685 gboolean client_normal(ObClient *self) {
1686 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
1687 self->type == OB_CLIENT_TYPE_DOCK ||
1688 self->type == OB_CLIENT_TYPE_SPLASH);
1691 static void client_apply_startup_state(ObClient *self)
1693 /* these are in a carefully crafted order.. */
1696 self->iconic = FALSE;
1697 client_iconify(self, TRUE, FALSE);
1699 if (self->fullscreen) {
1700 self->fullscreen = FALSE;
1701 client_fullscreen(self, TRUE, FALSE);
1704 self->shaded = FALSE;
1705 client_shade(self, TRUE);
1708 dispatch_client(Event_Client_Urgent, self, self->urgent, 0);
1710 if (self->max_vert && self->max_horz) {
1711 self->max_vert = self->max_horz = FALSE;
1712 client_maximize(self, TRUE, 0, FALSE);
1713 } else if (self->max_vert) {
1714 self->max_vert = FALSE;
1715 client_maximize(self, TRUE, 2, FALSE);
1716 } else if (self->max_horz) {
1717 self->max_horz = FALSE;
1718 client_maximize(self, TRUE, 1, FALSE);
1721 /* nothing to do for the other states:
1730 void client_configure_full(ObClient *self, ObCorner anchor,
1731 int x, int y, int w, int h,
1732 gboolean user, gboolean final,
1733 gboolean force_reply)
1735 gboolean moved = FALSE, resized = FALSE;
1736 guint fdecor = self->frame->decorations;
1737 gboolean fhorz = self->frame->max_horz;
1739 /* make the frame recalculate its dimentions n shit without changing
1740 anything visible for real, this way the constraints below can work with
1741 the updated frame dimensions. */
1742 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
1744 /* gets the frame's position */
1745 frame_client_gravity(self->frame, &x, &y);
1747 /* these positions are frame positions, not client positions */
1749 /* set the size and position if fullscreen */
1750 if (self->fullscreen) {
1753 XF86VidModeModeLine mode;
1758 i = client_monitor(self);
1759 a = screen_physical_area_monitor(i);
1762 if (i == 0 && /* primary head */
1763 extensions_vidmode &&
1764 XF86VidModeGetViewPort(ob_display, ob_screen, &x, &y) &&
1765 /* get the mode last so the mode.privsize isnt freed incorrectly */
1766 XF86VidModeGetModeLine(ob_display, ob_screen, &dot, &mode)) {
1771 if (mode.privsize) XFree(mode.private);
1781 user = FALSE; /* ignore that increment etc shit when in fullscreen */
1785 a = screen_area_monitor(self->desktop, client_monitor(self));
1787 /* set the size and position if maximized */
1788 if (self->max_horz) {
1790 w = a->width - self->frame->size.left - self->frame->size.right;
1792 if (self->max_vert) {
1794 h = a->height - self->frame->size.top - self->frame->size.bottom;
1798 /* gets the client's position */
1799 frame_frame_gravity(self->frame, &x, &y);
1801 /* these override the above states! if you cant move you can't move! */
1803 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
1807 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
1808 w = self->area.width;
1809 h = self->area.height;
1813 if (!(w == self->area.width && h == self->area.height)) {
1814 int basew, baseh, minw, minh;
1817 /* base size is substituted with min size if not specified */
1818 if (self->base_size.width || self->base_size.height) {
1819 basew = self->base_size.width;
1820 baseh = self->base_size.height;
1822 basew = self->min_size.width;
1823 baseh = self->min_size.height;
1825 /* min size is substituted with base size if not specified */
1826 if (self->min_size.width || self->min_size.height) {
1827 minw = self->min_size.width;
1828 minh = self->min_size.height;
1830 minw = self->base_size.width;
1831 minh = self->base_size.height;
1834 /* for interactive resizing. have to move half an increment in each
1837 /* how far we are towards the next size inc */
1838 mw = (w - basew) % self->size_inc.width;
1839 mh = (h - baseh) % self->size_inc.height;
1841 aw = self->size_inc.width / 2;
1842 ah = self->size_inc.height / 2;
1843 /* don't let us move into a new size increment */
1844 if (mw + aw >= self->size_inc.width)
1845 aw = self->size_inc.width - mw - 1;
1846 if (mh + ah >= self->size_inc.height)
1847 ah = self->size_inc.height - mh - 1;
1851 /* if this is a user-requested resize, then check against min/max
1854 /* smaller than min size or bigger than max size? */
1855 if (w > self->max_size.width) w = self->max_size.width;
1856 if (w < minw) w = minw;
1857 if (h > self->max_size.height) h = self->max_size.height;
1858 if (h < minh) h = minh;
1863 /* keep to the increments */
1864 w /= self->size_inc.width;
1865 h /= self->size_inc.height;
1867 /* you cannot resize to nothing */
1868 if (basew + w < 1) w = 1 - basew;
1869 if (baseh + h < 1) h = 1 - baseh;
1871 /* store the logical size */
1872 SIZE_SET(self->logical_size,
1873 self->size_inc.width > 1 ? w : w + basew,
1874 self->size_inc.height > 1 ? h : h + baseh);
1876 w *= self->size_inc.width;
1877 h *= self->size_inc.height;
1882 /* adjust the height to match the width for the aspect ratios.
1883 for this, min size is not substituted for base size ever. */
1884 w -= self->base_size.width;
1885 h -= self->base_size.height;
1887 if (self->min_ratio)
1888 if (h * self->min_ratio > w) h = (int)(w / self->min_ratio);
1889 if (self->max_ratio)
1890 if (h * self->max_ratio < w) h = (int)(w / self->max_ratio);
1892 w += self->base_size.width;
1893 h += self->base_size.height;
1897 case OB_CORNER_TOPLEFT:
1899 case OB_CORNER_TOPRIGHT:
1900 x -= w - self->area.width;
1902 case OB_CORNER_BOTTOMLEFT:
1903 y -= h - self->area.height;
1905 case OB_CORNER_BOTTOMRIGHT:
1906 x -= w - self->area.width;
1907 y -= h - self->area.height;
1911 moved = x != self->area.x || y != self->area.y;
1912 resized = w != self->area.width || h != self->area.height;
1914 RECT_SET(self->area, x, y, w, h);
1916 /* for app-requested resizes, always resize if 'resized' is true.
1917 for user-requested ones, only resize if final is true, or when
1918 resizing in redraw mode */
1919 if ((!user && resized) ||
1920 (user && (final || (resized && config_redraw_resize))))
1921 XResizeWindow(ob_display, self->window, w, h);
1923 /* move/resize the frame to match the request */
1925 if (self->decorations != fdecor || self->max_horz != fhorz)
1926 moved = resized = TRUE;
1928 if (moved || resized)
1929 frame_adjust_area(self->frame, moved, resized, FALSE);
1931 if (!resized && (force_reply || ((!user && moved) || (user && final))))
1934 event.type = ConfigureNotify;
1935 event.xconfigure.display = ob_display;
1936 event.xconfigure.event = self->window;
1937 event.xconfigure.window = self->window;
1939 /* root window real coords */
1940 event.xconfigure.x = self->frame->area.x + self->frame->size.left -
1942 event.xconfigure.y = self->frame->area.y + self->frame->size.top -
1944 event.xconfigure.width = w;
1945 event.xconfigure.height = h;
1946 event.xconfigure.border_width = 0;
1947 event.xconfigure.above = self->frame->plate;
1948 event.xconfigure.override_redirect = FALSE;
1949 XSendEvent(event.xconfigure.display, event.xconfigure.window,
1950 FALSE, StructureNotifyMask, &event);
1955 void client_fullscreen(ObClient *self, gboolean fs, gboolean savearea)
1959 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
1960 self->fullscreen == fs) return; /* already done */
1962 self->fullscreen = fs;
1963 client_change_state(self); /* change the state hints on the client,
1964 and adjust out layer/stacking */
1968 guint32 dimensions[4];
1969 dimensions[0] = self->area.x;
1970 dimensions[1] = self->area.y;
1971 dimensions[2] = self->area.width;
1972 dimensions[3] = self->area.height;
1974 PROP_SETA32(self->window, openbox_premax, cardinal,
1978 /* these are not actually used cuz client_configure will set them
1979 as appropriate when the window is fullscreened */
1986 /* pick some fallbacks... */
1987 a = screen_area_monitor(self->desktop, 0);
1988 x = a->x + a->width / 4;
1989 y = a->y + a->height / 4;
1993 if (PROP_GETA32(self->window, openbox_premax, cardinal,
1994 (guint32**)&dimensions, &num)) {
2005 client_setup_decor_and_functions(self);
2007 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2009 /* try focus us when we go into fullscreen mode */
2013 static void client_iconify_recursive(ObClient *self,
2014 gboolean iconic, gboolean curdesk)
2017 gboolean changed = FALSE;
2020 if (self->iconic != iconic) {
2021 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2024 self->iconic = iconic;
2027 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2028 self->wmstate = IconicState;
2029 self->ignore_unmaps++;
2030 /* we unmap the client itself so that we can get MapRequest
2031 events, and because the ICCCM tells us to! */
2032 XUnmapWindow(ob_display, self->window);
2034 /* update the focus lists.. iconic windows go to the bottom of
2035 the list, put the new iconic window at the 'top of the
2037 focus_order_to_top(self);
2043 client_set_desktop(self, screen_desktop, FALSE);
2044 self->wmstate = self->shaded ? IconicState : NormalState;
2045 XMapWindow(ob_display, self->window);
2047 /* this puts it after the current focused window */
2048 focus_order_remove(self);
2049 focus_order_add_new(self);
2051 /* this is here cuz with the VIDMODE extension, the viewport can
2052 change while a fullscreen window is iconic, and when it
2053 uniconifies, it would be nice if it did so to the new position
2055 client_reconfigure(self);
2062 client_change_state(self);
2063 client_showhide(self);
2064 screen_update_areas();
2066 dispatch_client(iconic ? Event_Client_Unmapped : Event_Client_Mapped,
2070 /* iconify all transients */
2071 for (it = self->transients; it != NULL; it = it->next)
2072 if (it->data != self) client_iconify_recursive(it->data,
2076 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2078 /* move up the transient chain as far as possible first */
2079 self = client_search_top_transient(self);
2081 client_iconify_recursive(client_search_top_transient(self),
2085 void client_maximize(ObClient *self, gboolean max, int dir, gboolean savearea)
2089 g_assert(dir == 0 || dir == 1 || dir == 2);
2090 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2092 /* check if already done */
2094 if (dir == 0 && self->max_horz && self->max_vert) return;
2095 if (dir == 1 && self->max_horz) return;
2096 if (dir == 2 && self->max_vert) return;
2098 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2099 if (dir == 1 && !self->max_horz) return;
2100 if (dir == 2 && !self->max_vert) return;
2103 /* work with the frame's coords */
2104 x = self->frame->area.x;
2105 y = self->frame->area.y;
2106 w = self->area.width;
2107 h = self->area.height;
2111 gint32 dimensions[4];
2120 /* get the property off the window and use it for the dimensions
2121 we are already maxed on */
2122 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2123 (guint32**)&readdim, &num)) {
2125 if (self->max_horz) {
2126 dimensions[0] = readdim[0];
2127 dimensions[2] = readdim[2];
2129 if (self->max_vert) {
2130 dimensions[1] = readdim[1];
2131 dimensions[3] = readdim[3];
2137 PROP_SETA32(self->window, openbox_premax, cardinal,
2138 (guint32*)dimensions, 4);
2145 /* pick some fallbacks... */
2146 a = screen_area_monitor(self->desktop, 0);
2147 if (dir == 0 || dir == 1) { /* horz */
2148 x = a->x + a->width / 4;
2151 if (dir == 0 || dir == 2) { /* vert */
2152 y = a->y + a->height / 4;
2156 if (PROP_GETA32(self->window, openbox_premax, cardinal,
2157 (guint32**)&dimensions, &num)) {
2159 if (dir == 0 || dir == 1) { /* horz */
2163 if (dir == 0 || dir == 2) { /* vert */
2172 if (dir == 0 || dir == 1) /* horz */
2173 self->max_horz = max;
2174 if (dir == 0 || dir == 2) /* vert */
2175 self->max_vert = max;
2177 if (!self->max_horz && !self->max_vert)
2178 PROP_ERASE(self->window, openbox_premax);
2180 client_change_state(self); /* change the state hints on the client */
2182 client_setup_decor_and_functions(self);
2184 /* figure out where the client should be going */
2185 frame_frame_gravity(self->frame, &x, &y);
2186 client_configure(self, OB_CORNER_TOPLEFT, x, y, w, h, TRUE, TRUE);
2189 void client_shade(ObClient *self, gboolean shade)
2191 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2192 shade) || /* can't shade */
2193 self->shaded == shade) return; /* already done */
2195 /* when we're iconic, don't change the wmstate */
2197 self->wmstate = shade ? IconicState : NormalState;
2198 self->shaded = shade;
2199 client_change_state(self);
2200 /* resize the frame to just the titlebar */
2201 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2204 void client_close(ObClient *self)
2208 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2211 XXX: itd be cool to do timeouts and shit here for killing the client's
2213 like... if the window is around after 5 seconds, then the close button
2214 turns a nice red, and if this function is called again, the client is
2218 ce.xclient.type = ClientMessage;
2219 ce.xclient.message_type = prop_atoms.wm_protocols;
2220 ce.xclient.display = ob_display;
2221 ce.xclient.window = self->window;
2222 ce.xclient.format = 32;
2223 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2224 ce.xclient.data.l[1] = event_lasttime;
2225 ce.xclient.data.l[2] = 0l;
2226 ce.xclient.data.l[3] = 0l;
2227 ce.xclient.data.l[4] = 0l;
2228 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2231 void client_kill(ObClient *self)
2233 XKillClient(ob_display, self->window);
2236 void client_set_desktop_recursive(ObClient *self,
2237 guint target, gboolean donthide)
2242 if (target != self->desktop) {
2244 ob_debug("Setting desktop %u\n", target+1);
2246 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2248 /* remove from the old desktop(s) */
2249 focus_order_remove(self);
2251 old = self->desktop;
2252 self->desktop = target;
2253 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2254 /* the frame can display the current desktop state */
2255 frame_adjust_state(self->frame);
2256 /* 'move' the window to the new desktop */
2258 client_showhide(self);
2259 /* raise if it was not already on the desktop */
2260 if (old != DESKTOP_ALL)
2261 stacking_raise(CLIENT_AS_WINDOW(self));
2262 screen_update_areas();
2264 /* add to the new desktop(s) */
2265 if (config_focus_new)
2266 focus_order_to_top(self);
2268 focus_order_to_bottom(self);
2270 dispatch_client(Event_Client_Desktop, self, target, old);
2273 /* move all transients */
2274 for (it = self->transients; it != NULL; it = it->next)
2275 if (it->data != self) client_set_desktop_recursive(it->data,
2279 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2281 client_set_desktop_recursive(client_search_top_transient(self),
2285 ObClient *client_search_modal_child(ObClient *self)
2290 for (it = self->transients; it != NULL; it = it->next) {
2291 ObClient *c = it->data;
2292 if ((ret = client_search_modal_child(c))) return ret;
2293 if (c->modal) return c;
2298 gboolean client_validate(ObClient *self)
2302 XSync(ob_display, FALSE); /* get all events on the server */
2304 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2305 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2306 XPutBackEvent(ob_display, &e);
2313 void client_set_wm_state(ObClient *self, long state)
2315 if (state == self->wmstate) return; /* no change */
2319 client_iconify(self, TRUE, TRUE);
2322 client_iconify(self, FALSE, TRUE);
2327 void client_set_state(ObClient *self, Atom action, long data1, long data2)
2329 gboolean shaded = self->shaded;
2330 gboolean fullscreen = self->fullscreen;
2331 gboolean max_horz = self->max_horz;
2332 gboolean max_vert = self->max_vert;
2335 if (!(action == prop_atoms.net_wm_state_add ||
2336 action == prop_atoms.net_wm_state_remove ||
2337 action == prop_atoms.net_wm_state_toggle))
2338 /* an invalid action was passed to the client message, ignore it */
2341 for (i = 0; i < 2; ++i) {
2342 Atom state = i == 0 ? data1 : data2;
2344 if (!state) continue;
2346 /* if toggling, then pick whether we're adding or removing */
2347 if (action == prop_atoms.net_wm_state_toggle) {
2348 if (state == prop_atoms.net_wm_state_modal)
2349 action = self->modal ? prop_atoms.net_wm_state_remove :
2350 prop_atoms.net_wm_state_add;
2351 else if (state == prop_atoms.net_wm_state_maximized_vert)
2352 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2353 prop_atoms.net_wm_state_add;
2354 else if (state == prop_atoms.net_wm_state_maximized_horz)
2355 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2356 prop_atoms.net_wm_state_add;
2357 else if (state == prop_atoms.net_wm_state_shaded)
2358 action = self->shaded ? prop_atoms.net_wm_state_remove :
2359 prop_atoms.net_wm_state_add;
2360 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2361 action = self->skip_taskbar ?
2362 prop_atoms.net_wm_state_remove :
2363 prop_atoms.net_wm_state_add;
2364 else if (state == prop_atoms.net_wm_state_skip_pager)
2365 action = self->skip_pager ?
2366 prop_atoms.net_wm_state_remove :
2367 prop_atoms.net_wm_state_add;
2368 else if (state == prop_atoms.net_wm_state_fullscreen)
2369 action = self->fullscreen ?
2370 prop_atoms.net_wm_state_remove :
2371 prop_atoms.net_wm_state_add;
2372 else if (state == prop_atoms.net_wm_state_above)
2373 action = self->above ? prop_atoms.net_wm_state_remove :
2374 prop_atoms.net_wm_state_add;
2375 else if (state == prop_atoms.net_wm_state_below)
2376 action = self->below ? prop_atoms.net_wm_state_remove :
2377 prop_atoms.net_wm_state_add;
2380 if (action == prop_atoms.net_wm_state_add) {
2381 if (state == prop_atoms.net_wm_state_modal) {
2382 /* XXX raise here or something? */
2384 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2386 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2388 } else if (state == prop_atoms.net_wm_state_shaded) {
2390 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2391 self->skip_taskbar = TRUE;
2392 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2393 self->skip_pager = TRUE;
2394 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2396 } else if (state == prop_atoms.net_wm_state_above) {
2398 } else if (state == prop_atoms.net_wm_state_below) {
2402 } else { /* action == prop_atoms.net_wm_state_remove */
2403 if (state == prop_atoms.net_wm_state_modal) {
2404 self->modal = FALSE;
2405 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2407 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2409 } else if (state == prop_atoms.net_wm_state_shaded) {
2411 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2412 self->skip_taskbar = FALSE;
2413 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2414 self->skip_pager = FALSE;
2415 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2417 } else if (state == prop_atoms.net_wm_state_above) {
2418 self->above = FALSE;
2419 } else if (state == prop_atoms.net_wm_state_below) {
2420 self->below = FALSE;
2424 if (max_horz != self->max_horz || max_vert != self->max_vert) {
2425 if (max_horz != self->max_horz && max_vert != self->max_vert) {
2427 if (max_horz == max_vert) { /* both going the same way */
2428 client_maximize(self, max_horz, 0, TRUE);
2430 client_maximize(self, max_horz, 1, TRUE);
2431 client_maximize(self, max_vert, 2, TRUE);
2435 if (max_horz != self->max_horz)
2436 client_maximize(self, max_horz, 1, TRUE);
2438 client_maximize(self, max_vert, 2, TRUE);
2441 /* change fullscreen state before shading, as it will affect if the window
2443 if (fullscreen != self->fullscreen)
2444 client_fullscreen(self, fullscreen, TRUE);
2445 if (shaded != self->shaded)
2446 client_shade(self, shaded);
2447 client_calc_layer(self);
2448 client_change_state(self); /* change the hint to reflect these changes */
2451 ObClient *client_focus_target(ObClient *self)
2455 /* if we have a modal child, then focus it, not us */
2456 child = client_search_modal_child(self);
2457 if (child) return child;
2461 gboolean client_can_focus(ObClient *self)
2465 /* choose the correct target */
2466 self = client_focus_target(self);
2468 if (!self->frame->visible)
2471 if (!((self->can_focus || self->focus_notify) &&
2472 (self->desktop == screen_desktop ||
2473 self->desktop == DESKTOP_ALL) &&
2477 /* do a check to see if the window has already been unmapped or destroyed
2478 do this intelligently while watching out for unmaps we've generated
2479 (ignore_unmaps > 0) */
2480 if (XCheckTypedWindowEvent(ob_display, self->window,
2481 DestroyNotify, &ev)) {
2482 XPutBackEvent(ob_display, &ev);
2485 while (XCheckTypedWindowEvent(ob_display, self->window,
2486 UnmapNotify, &ev)) {
2487 if (self->ignore_unmaps) {
2488 self->ignore_unmaps--;
2490 XPutBackEvent(ob_display, &ev);
2498 gboolean client_focus(ObClient *self)
2500 /* choose the correct target */
2501 self = client_focus_target(self);
2503 if (!client_can_focus(self)) {
2504 if (!self->frame->visible) {
2505 /* update the focus lists */
2506 focus_order_to_top(self);
2511 if (self->can_focus)
2512 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2513 I choose to use it always, hopefully to find errors quicker, if any
2514 are left. (I hate X. I hate focus events.) */
2515 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
2518 if (self->focus_notify) {
2520 ce.xclient.type = ClientMessage;
2521 ce.xclient.message_type = prop_atoms.wm_protocols;
2522 ce.xclient.display = ob_display;
2523 ce.xclient.window = self->window;
2524 ce.xclient.format = 32;
2525 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
2526 ce.xclient.data.l[1] = event_lasttime;
2527 ce.xclient.data.l[2] = 0l;
2528 ce.xclient.data.l[3] = 0l;
2529 ce.xclient.data.l[4] = 0l;
2530 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2534 ob_debug("%sively focusing %lx at %d\n",
2535 (self->can_focus ? "act" : "pass"),
2536 self->window, (int) event_lasttime);
2539 /* Cause the FocusIn to come back to us. Important for desktop switches,
2540 since otherwise we'll have no FocusIn on the queue and send it off to
2541 the focus_backup. */
2542 XSync(ob_display, FALSE);
2546 void client_unfocus(ObClient *self)
2548 g_assert(focus_client == self);
2550 ob_debug("client_unfocus for %lx\n", self->window);
2552 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING);
2555 void client_activate(ObClient *self, gboolean here)
2557 if (client_normal(self) && screen_showing_desktop)
2558 screen_show_desktop(FALSE);
2560 client_iconify(self, FALSE, FALSE);
2561 if (self->desktop != DESKTOP_ALL &&
2562 self->desktop != screen_desktop) {
2564 client_set_desktop(self, screen_desktop, FALSE);
2566 screen_set_desktop(self->desktop);
2567 } else if (!self->frame->visible)
2568 /* if its not visible for other reasons, then don't mess
2572 client_shade(self, FALSE);
2574 stacking_raise(CLIENT_AS_WINDOW(self));
2577 gboolean client_focused(ObClient *self)
2579 return self == focus_client;
2582 ObClientIcon *client_icon(ObClient *self, int w, int h)
2585 /* si is the smallest image >= req */
2586 /* li is the largest image < req */
2587 unsigned long size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
2589 if (!self->nicons) return NULL;
2591 for (i = 0; i < self->nicons; ++i) {
2592 size = self->icons[i].width * self->icons[i].height;
2593 if (size < smallest && size >= (unsigned)(w * h)) {
2597 if (size > largest && size <= (unsigned)(w * h)) {
2602 if (largest == 0) /* didnt find one smaller than the requested size */
2603 return &self->icons[si];
2604 return &self->icons[li];
2607 /* this be mostly ripped from fvwm */
2608 ObClient *client_find_directional(ObClient *c, ObDirection dir)
2610 int my_cx, my_cy, his_cx, his_cy;
2613 int score, best_score;
2614 ObClient *best_client, *cur;
2620 /* first, find the centre coords of the currently focused window */
2621 my_cx = c->frame->area.x + c->frame->area.width / 2;
2622 my_cy = c->frame->area.y + c->frame->area.height / 2;
2627 for(it = g_list_first(client_list); it; it = it->next) {
2630 /* the currently selected window isn't interesting */
2633 if (!client_normal(cur))
2635 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2639 if(client_focus_target(cur) == cur &&
2640 !(cur->can_focus || cur->focus_notify))
2643 /* find the centre coords of this window, from the
2644 * currently focused window's point of view */
2645 his_cx = (cur->frame->area.x - my_cx)
2646 + cur->frame->area.width / 2;
2647 his_cy = (cur->frame->area.y - my_cy)
2648 + cur->frame->area.height / 2;
2650 if(dir == OB_DIRECTION_NORTHEAST || dir == OB_DIRECTION_SOUTHEAST ||
2651 dir == OB_DIRECTION_SOUTHWEST || dir == OB_DIRECTION_NORTHWEST) {
2653 /* Rotate the diagonals 45 degrees counterclockwise.
2654 * To do this, multiply the matrix /+h +h\ with the
2655 * vector (x y). \-h +h/
2656 * h = sqrt(0.5). We can set h := 1 since absolute
2657 * distance doesn't matter here. */
2658 tx = his_cx + his_cy;
2659 his_cy = -his_cx + his_cy;
2664 case OB_DIRECTION_NORTH:
2665 case OB_DIRECTION_SOUTH:
2666 case OB_DIRECTION_NORTHEAST:
2667 case OB_DIRECTION_SOUTHWEST:
2668 offset = (his_cx < 0) ? -his_cx : his_cx;
2669 distance = ((dir == OB_DIRECTION_NORTH ||
2670 dir == OB_DIRECTION_NORTHEAST) ?
2673 case OB_DIRECTION_EAST:
2674 case OB_DIRECTION_WEST:
2675 case OB_DIRECTION_SOUTHEAST:
2676 case OB_DIRECTION_NORTHWEST:
2677 offset = (his_cy < 0) ? -his_cy : his_cy;
2678 distance = ((dir == OB_DIRECTION_WEST ||
2679 dir == OB_DIRECTION_NORTHWEST) ?
2684 /* the target must be in the requested direction */
2688 /* Calculate score for this window. The smaller the better. */
2689 score = distance + offset;
2691 /* windows more than 45 degrees off the direction are
2692 * heavily penalized and will only be chosen if nothing
2693 * else within a million pixels */
2694 if(offset > distance)
2697 if(best_score == -1 || score < best_score)
2705 void client_set_layer(ObClient *self, int layer)
2709 self->above = FALSE;
2710 } else if (layer == 0) {
2711 self->below = self->above = FALSE;
2713 self->below = FALSE;
2716 client_calc_layer(self);
2717 client_change_state(self); /* reflect this in the state hints */
2720 guint client_monitor(ObClient *self)
2724 for (i = 0; i < screen_num_monitors; ++i) {
2725 Rect *area = screen_physical_area_monitor(i);
2726 if (RECT_INTERSECTS_RECT(*area, self->frame->area))
2729 if (i == screen_num_monitors) i = 0;
2730 g_assert(i < screen_num_monitors);
2734 ObClient *client_search_top_transient(ObClient *self)
2736 /* move up the transient chain as far as possible */
2737 if (self->transient_for) {
2738 if (self->transient_for != OB_TRAN_GROUP) {
2739 return client_search_top_transient(self->transient_for);
2743 for (it = self->group->members; it; it = it->next) {
2744 ObClient *c = it->data;
2746 /* checking transient_for prevents infinate loops! */
2747 if (c != self && !c->transient_for)
2758 ObClient *client_search_transient(ObClient *self, ObClient *search)
2762 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
2763 if (sit->data == search)
2765 if (client_search_transient(sit->data, search))
2771 gchar* client_get_sm_client_id(ObClient *self)
2775 if (!PROP_GETS(self->window, sm_client_id, locale, &id) && self->group)
2776 PROP_GETS(self->group->leader, sm_client_id, locale, &id);
2780 /* finds the nearest edge in the given direction from the current client
2781 * note to self: the edge is the -frame- edge (the actual one), not the
2784 int client_directional_edge_search(ObClient *c, ObDirection dir)
2787 int my_edge_start, my_edge_end, my_offset;
2794 a = screen_area(c->desktop);
2797 case OB_DIRECTION_NORTH:
2798 my_edge_start = c->frame->area.x;
2799 my_edge_end = c->frame->area.x + c->frame->area.width;
2800 my_offset = c->frame->area.y;
2802 dest = a->y; /* default: top of screen */
2804 for(it = g_list_first(client_list); it; it = it->next) {
2805 int his_edge_start, his_edge_end, his_offset;
2806 ObClient *cur = it->data;
2810 if(!client_normal(cur))
2812 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2817 his_edge_start = cur->frame->area.x;
2818 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2819 his_offset = cur->frame->area.y + cur->frame->area.height;
2821 if(his_offset + 1 > my_offset)
2824 if(his_offset < dest)
2827 if(his_edge_start >= my_edge_start &&
2828 his_edge_start <= my_edge_end)
2831 if(my_edge_start >= his_edge_start &&
2832 my_edge_start <= his_edge_end)
2837 case OB_DIRECTION_SOUTH:
2838 my_edge_start = c->frame->area.x;
2839 my_edge_end = c->frame->area.x + c->frame->area.width;
2840 my_offset = c->frame->area.y + c->frame->area.height;
2842 dest = a->y + a->height; /* default: bottom of screen */
2844 for(it = g_list_first(client_list); it; it = it->next) {
2845 int his_edge_start, his_edge_end, his_offset;
2846 ObClient *cur = it->data;
2850 if(!client_normal(cur))
2852 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2857 his_edge_start = cur->frame->area.x;
2858 his_edge_end = cur->frame->area.x + cur->frame->area.width;
2859 his_offset = cur->frame->area.y;
2862 if(his_offset - 1 < my_offset)
2865 if(his_offset > dest)
2868 if(his_edge_start >= my_edge_start &&
2869 his_edge_start <= my_edge_end)
2872 if(my_edge_start >= his_edge_start &&
2873 my_edge_start <= his_edge_end)
2878 case OB_DIRECTION_WEST:
2879 my_edge_start = c->frame->area.y;
2880 my_edge_end = c->frame->area.y + c->frame->area.height;
2881 my_offset = c->frame->area.x;
2883 dest = a->x; /* default: leftmost egde of screen */
2885 for(it = g_list_first(client_list); it; it = it->next) {
2886 int his_edge_start, his_edge_end, his_offset;
2887 ObClient *cur = it->data;
2891 if(!client_normal(cur))
2893 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2898 his_edge_start = cur->frame->area.y;
2899 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2900 his_offset = cur->frame->area.x + cur->frame->area.width;
2902 if(his_offset + 1 > my_offset)
2905 if(his_offset < dest)
2908 if(his_edge_start >= my_edge_start &&
2909 his_edge_start <= my_edge_end)
2912 if(my_edge_start >= his_edge_start &&
2913 my_edge_start <= his_edge_end)
2919 case OB_DIRECTION_EAST:
2920 my_edge_start = c->frame->area.y;
2921 my_edge_end = c->frame->area.y + c->frame->area.height;
2922 my_offset = c->frame->area.x + c->frame->area.width;
2924 dest = a->x + a->width; /* default: rightmost edge of screen */
2926 for(it = g_list_first(client_list); it; it = it->next) {
2927 int his_edge_start, his_edge_end, his_offset;
2928 ObClient *cur = it->data;
2932 if(!client_normal(cur))
2934 if(c->desktop != cur->desktop && cur->desktop != DESKTOP_ALL)
2939 his_edge_start = cur->frame->area.y;
2940 his_edge_end = cur->frame->area.y + cur->frame->area.height;
2941 his_offset = cur->frame->area.x;
2943 if(his_offset - 1 < my_offset)
2946 if(his_offset > dest)
2949 if(his_edge_start >= my_edge_start &&
2950 his_edge_start <= my_edge_end)
2953 if(my_edge_start >= his_edge_start &&
2954 my_edge_start <= his_edge_end)
2959 case OB_DIRECTION_NORTHEAST:
2960 case OB_DIRECTION_SOUTHEAST:
2961 case OB_DIRECTION_NORTHWEST:
2962 case OB_DIRECTION_SOUTHWEST:
2963 /* not implemented */
2966 g_assert_not_reached();