1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
39 #include "menuframe.h"
42 #include "render/render.h"
49 #include <X11/Xutil.h>
51 /*! The event mask to grab on client windows */
52 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
55 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
60 ObClientDestructor func;
64 GList *client_list = NULL;
66 static GSList *client_destructors = NULL;
68 static void client_get_all(ObClient *self);
69 static void client_toggle_border(ObClient *self, gboolean show);
70 static void client_get_startup_id(ObClient *self);
71 static void client_get_area(ObClient *self);
72 static void client_get_desktop(ObClient *self);
73 static void client_get_state(ObClient *self);
74 static void client_get_layer(ObClient *self);
75 static void client_get_shaped(ObClient *self);
76 static void client_get_mwm_hints(ObClient *self);
77 static void client_get_gravity(ObClient *self);
78 static void client_get_client_machine(ObClient *self);
79 static void client_get_colormap(ObClient *self);
80 static void client_change_allowed_actions(ObClient *self);
81 static void client_change_state(ObClient *self);
82 static void client_change_wm_state(ObClient *self);
83 static void client_apply_startup_state(ObClient *self, gint x, gint y);
84 static void client_restore_session_state(ObClient *self);
85 static void client_restore_session_stacking(ObClient *self);
86 static ObAppSettings *client_get_settings_state(ObClient *self);
88 void client_startup(gboolean reconfig)
95 void client_shutdown(gboolean reconfig)
99 void client_add_destructor(ObClientDestructor func, gpointer data)
101 Destructor *d = g_new(Destructor, 1);
104 client_destructors = g_slist_prepend(client_destructors, d);
107 void client_remove_destructor(ObClientDestructor func)
111 for (it = client_destructors; it; it = g_slist_next(it)) {
112 Destructor *d = it->data;
113 if (d->func == func) {
115 client_destructors = g_slist_delete_link(client_destructors, it);
121 void client_set_list()
123 Window *windows, *win_it;
125 guint size = g_list_length(client_list);
127 /* create an array of the window ids */
129 windows = g_new(Window, size);
131 for (it = client_list; it; it = g_list_next(it), ++win_it)
132 *win_it = ((ObClient*)it->data)->window;
136 PROP_SETA32(RootWindow(ob_display, ob_screen),
137 net_client_list, window, (gulong*)windows, size);
146 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
150 for (it = self->transients; it; it = g_slist_next(it)) {
151 if (!func(it->data, data)) return;
152 client_foreach_transient(it->data, func, data);
156 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
158 if (self->transient_for) {
159 if (self->transient_for != OB_TRAN_GROUP) {
160 if (!func(self->transient_for, data)) return;
161 client_foreach_ancestor(self->transient_for, func, data);
165 for (it = self->group->members; it; it = g_slist_next(it))
166 if (it->data != self &&
167 !((ObClient*)it->data)->transient_for) {
168 if (!func(it->data, data)) return;
169 client_foreach_ancestor(it->data, func, data);
176 void client_manage_all()
181 XWindowAttributes attrib;
183 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
184 &w, &w, &children, &nchild);
186 /* remove all icon windows from the list */
187 for (i = 0; i < nchild; i++) {
188 if (children[i] == None) continue;
189 wmhints = XGetWMHints(ob_display, children[i]);
191 if ((wmhints->flags & IconWindowHint) &&
192 (wmhints->icon_window != children[i]))
193 for (j = 0; j < nchild; j++)
194 if (children[j] == wmhints->icon_window) {
202 for (i = 0; i < nchild; ++i) {
203 if (children[i] == None)
205 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
206 if (attrib.override_redirect) continue;
208 if (attrib.map_state != IsUnmapped)
209 client_manage(children[i]);
215 void client_manage(Window window)
219 XWindowAttributes attrib;
220 XSetWindowAttributes attrib_set;
222 gboolean activate = FALSE;
223 ObAppSettings *settings;
228 /* check if it has already been unmapped by the time we started mapping.
229 the grab does a sync so we don't have to here */
230 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
231 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e))
233 XPutBackEvent(ob_display, &e);
235 ob_debug("Trying to manage unmapped window. Aborting that.\n");
237 return; /* don't manage it */
240 /* make sure it isn't an override-redirect window */
241 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
242 attrib.override_redirect)
245 return; /* don't manage it */
248 /* is the window a docking app */
249 if ((wmhint = XGetWMHints(ob_display, window))) {
250 if ((wmhint->flags & StateHint) &&
251 wmhint->initial_state == WithdrawnState)
253 dock_add(window, wmhint);
261 ob_debug("Managing window: %lx\n", window);
263 /* choose the events we want to receive on the CLIENT window */
264 attrib_set.event_mask = CLIENT_EVENTMASK;
265 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
266 XChangeWindowAttributes(ob_display, window,
267 CWEventMask|CWDontPropagate, &attrib_set);
270 /* create the ObClient struct, and populate it from the hints on the
272 self = g_new0(ObClient, 1);
273 self->obwin.type = Window_Client;
274 self->window = window;
276 /* non-zero defaults */
277 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
279 self->desktop = screen_num_desktops; /* always an invalid value */
280 self->user_time = CurrentTime;
282 client_get_all(self);
283 /* per-app settings override stuff, and return the settings for other
285 settings = client_get_settings_state(self);
286 /* the session should get the last say */
287 client_restore_session_state(self);
289 client_calc_layer(self);
292 Time t = sn_app_started(self->startup_id, self->class);
293 if (t) self->user_time = t;
296 /* update the focus lists, do this before the call to change_state or
297 it can end up in the list twice! */
298 focus_order_add_new(self);
300 /* remove the client's border (and adjust re gravity) */
301 client_toggle_border(self, FALSE);
303 /* specify that if we exit, the window should not be destroyed and should
304 be reparented back to root automatically */
305 XChangeSaveSet(ob_display, window, SetModeInsert);
307 /* create the decoration frame for the client window */
308 self->frame = frame_new(self);
310 frame_grab_client(self->frame, self);
312 /* do this after we have a frame.. it uses the frame to help determine the
313 WM_STATE to apply. */
314 client_change_state(self);
318 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
319 client_restore_session_stacking(self);
321 /* focus the new window? */
322 if (ob_state() != OB_STATE_STARTING &&
324 /* this means focus=true for window is same as config_focus_new=true */
325 ((config_focus_new || (settings && settings->focus == 1)) ||
326 client_search_focus_parent(self)) &&
327 /* this checks for focus=false for the window */
328 (!settings || settings->focus != 0) &&
329 /* note the check against Type_Normal/Dialog, not client_normal(self),
330 which would also include other types. in this case we want more
331 strict rules for focus */
332 (self->type == OB_CLIENT_TYPE_NORMAL ||
333 self->type == OB_CLIENT_TYPE_DIALOG))
338 /* get the current position */
342 /* figure out placement for the window */
343 if (ob_state() == OB_STATE_RUNNING) {
346 transient = place_client(self, &newx, &newy, settings);
348 /* make sure the window is visible. */
349 client_find_onscreen(self, &newx, &newy,
350 self->frame->area.width,
351 self->frame->area.height,
352 /* non-normal clients has less rules, and
353 windows that are being restored from a
354 session do also. we can assume you want
355 it back where you saved it. Clients saying
356 they placed themselves are subjected to
357 harder rules, ones that are placed by
358 place.c or by the user are allowed partially
359 off-screen and on xinerama divides (ie,
360 it is up to the placement routines to avoid
361 the xinerama divides) */
363 (((self->positioned & PPosition) &&
364 !(self->positioned & USPosition)) &&
365 client_normal(self) &&
369 /* do this after the window is placed, so the premax/prefullscreen numbers
371 also, this moves the window to the position where it has been placed
373 ob_debug("placing window 0x%x at %d, %d with size %d x %d\n",
374 self->window, newx, newy, self->area.width, self->area.height);
375 client_apply_startup_state(self, newx, newy);
377 mouse_grab_for_client(self, TRUE);
380 guint32 last_time = focus_client ?
381 focus_client->user_time : CurrentTime;
383 /* This is focus stealing prevention */
384 ob_debug("Want to focus new window 0x%x with time %u (last time %u)\n",
385 self->window, self->user_time, last_time);
387 /* if it's on another desktop */
388 if (!(self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
389 && /* the timestamp is from before you changed desktops */
390 self->user_time && screen_desktop_user_time &&
391 !event_time_after(self->user_time, screen_desktop_user_time))
395 /* If nothing is focused, or a parent was focused, then focus this
398 else if (!focus_client || client_search_focus_parent(self) != NULL)
402 /* If time stamp is old, don't steal focus */
403 if (self->user_time && last_time &&
404 !event_time_after(self->user_time, last_time))
408 /* Don't steal focus from globally active clients.
409 I stole this idea from KWin. It seems nice.
411 if (!(focus_client->can_focus || focus_client->focus_notify))
416 ob_debug("Focus stealing prevention activated for %s with time %u "
418 self->title, self->user_time, last_time);
419 /* if the client isn't focused, then hilite it so the user
421 client_hilite(self, TRUE);
425 /* This may look rather odd. Well it's because new windows are added
426 to the stacking order non-intrusively. If we're not going to focus
427 the new window or hilite it, then we raise it to the top. This will
428 take affect for things that don't get focused like splash screens.
429 Also if you don't have focus_new enabled, then it's going to get
430 raised to the top. Legacy begets legacy I guess?
435 /* this has to happen before we try focus the window, but we want it to
436 happen after the client's stacking has been determined or it looks bad
440 /* use client_focus instead of client_activate cuz client_activate does
441 stuff like switch desktops etc and I'm not interested in all that when
442 a window maps since its not based on an action from the user like
443 clicking a window to activate it. so keep the new window out of the way
446 client_activate(self, FALSE, TRUE);
448 /* add to client list/map */
449 client_list = g_list_append(client_list, self);
450 g_hash_table_insert(window_map, &self->window, self);
452 /* this has to happen after we're in the client_list */
453 if (STRUT_EXISTS(self->strut))
454 screen_update_areas();
456 /* update the list hints */
459 ob_debug("Managed window 0x%lx (%s)\n", window, self->class);
462 void client_unmanage_all()
464 while (client_list != NULL)
465 client_unmanage(client_list->data);
468 void client_unmanage(ObClient *self)
473 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self->window, self->class,
474 self->title ? self->title : "");
476 g_assert(self != NULL);
478 /* we dont want events no more. do this before hiding the frame so we
479 don't generate more events */
480 XSelectInput(ob_display, self->window, NoEventMask);
482 frame_hide(self->frame);
483 /* flush to send the hide to the server quickly */
486 /* ignore enter events from the unmap so it doesnt mess with the focus */
487 event_ignore_queued_enters();
489 mouse_grab_for_client(self, FALSE);
491 /* remove the window from our save set */
492 XChangeSaveSet(ob_display, self->window, SetModeDelete);
494 /* update the focus lists */
495 focus_order_remove(self);
496 if (client_focused(self)) {
497 /* we have to fall back here because we might not get a focus out.
498 1. we need to xselectinput off the window before we unmap it because
499 otherwise we end up getting unmapnotifies we don't want and they
500 can mess up mapping it again quickly
501 2. this means that if we unmanage from a synthetic unmapnotify, we
502 are the ones unmapped it, and causing the focusout. so we won't
503 get the focusout event.
504 3. we can't handle focusin events on the root window because they
505 come from all screens, so the focus change gets lost
507 if this ever gets removed in the future MAKE SURE to replace it
509 /- don't leave an invalid focus_client -/
512 focus_fallback(FALSE);
515 client_list = g_list_remove(client_list, self);
516 stacking_remove(self);
517 g_hash_table_remove(window_map, &self->window);
519 /* once the client is out of the list, update the struts to remove its
521 if (STRUT_EXISTS(self->strut))
522 screen_update_areas();
524 for (it = client_destructors; it; it = g_slist_next(it)) {
525 Destructor *d = it->data;
526 d->func(self, d->data);
529 /* tell our parent(s) that we're gone */
530 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
531 for (it = self->group->members; it; it = g_slist_next(it))
532 if (it->data != self)
533 ((ObClient*)it->data)->transients =
534 g_slist_remove(((ObClient*)it->data)->transients, self);
535 } else if (self->transient_for) { /* transient of window */
536 self->transient_for->transients =
537 g_slist_remove(self->transient_for->transients, self);
540 /* tell our transients that we're gone */
541 for (it = self->transients; it; it = g_slist_next(it)) {
542 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
543 ((ObClient*)it->data)->transient_for = NULL;
544 client_calc_layer(it->data);
548 /* remove from its group */
550 group_remove(self->group, self);
554 /* restore the window's original geometry so it is not lost */
558 if (self->fullscreen)
559 a = self->pre_fullscreen_area;
560 else if (self->max_horz || self->max_vert) {
561 if (self->max_horz) {
562 a.x = self->pre_max_area.x;
563 a.width = self->pre_max_area.width;
565 if (self->max_vert) {
566 a.y = self->pre_max_area.y;
567 a.height = self->pre_max_area.height;
571 /* give the client its border back */
572 client_toggle_border(self, TRUE);
574 self->fullscreen = self->max_horz = self->max_vert = FALSE;
575 self->decorations = 0; /* unmanaged windows have no decor */
577 client_move_resize(self, a.x, a.y, a.width, a.height);
580 /* reparent the window out of the frame, and free the frame */
581 frame_release_client(self->frame, self);
584 if (ob_state() != OB_STATE_EXITING) {
585 /* these values should not be persisted across a window
587 PROP_ERASE(self->window, net_wm_desktop);
588 PROP_ERASE(self->window, net_wm_state);
589 PROP_ERASE(self->window, wm_state);
591 /* if we're left in an unmapped state, the client wont be mapped. this
592 is bad, since we will no longer be managing the window on restart */
593 XMapWindow(ob_display, self->window);
596 ob_debug("Unmanaged window 0x%lx\n", self->window);
598 /* free all data allocated in the client struct */
599 g_slist_free(self->transients);
600 for (j = 0; j < self->nicons; ++j)
601 g_free(self->icons[j].data);
602 if (self->nicons > 0)
605 g_free(self->icon_title);
609 g_free(self->client_machine);
610 g_free(self->sm_client_id);
613 /* update the list hints */
617 static ObAppSettings *client_get_settings_state(ObClient *self)
619 ObAppSettings *settings = NULL;
622 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
623 ObAppSettings *app = it->data;
625 if ((app->name && !app->class && !strcmp(app->name, self->name))
626 || (app->class && !app->name && !strcmp(app->class, self->class))
627 || (app->class && app->name && !strcmp(app->class, self->class)
628 && !strcmp(app->name, self->name)))
630 ob_debug("Window matching: %s\n", app->name);
631 /* Match if no role was specified in the per app setting, or if the
632 * string matches the beginning of the role, since apps like to set
633 * the role to things like browser-window-23c4b2f */
635 || !strncmp(app->role, self->role, strlen(app->role)))
645 if (settings->shade != -1)
646 self->shaded = !!settings->shade;
647 if (settings->decor != -1)
648 self->undecorated = !settings->decor;
649 if (settings->iconic != -1)
650 self->iconic = !!settings->iconic;
651 if (settings->skip_pager != -1)
652 self->skip_pager = !!settings->skip_pager;
653 if (settings->skip_taskbar != -1)
654 self->skip_taskbar = !!settings->skip_taskbar;
656 if (settings->max_vert != -1)
657 self->max_vert = !!settings->max_vert;
658 if (settings->max_horz != -1)
659 self->max_horz = !!settings->max_horz;
661 if (settings->fullscreen != -1)
662 self->fullscreen = !!settings->fullscreen;
664 if (settings->desktop < screen_num_desktops
665 || settings->desktop == DESKTOP_ALL)
666 self->desktop = settings->desktop;
668 if (settings->layer == -1) {
672 else if (settings->layer == 0) {
676 else if (settings->layer == 1) {
684 static void client_restore_session_state(ObClient *self)
688 if (!(it = session_state_find(self)))
691 self->session = it->data;
693 RECT_SET_POINT(self->area, self->session->x, self->session->y);
694 self->positioned = PPosition;
695 if (self->session->w > 0)
696 self->area.width = self->session->w;
697 if (self->session->h > 0)
698 self->area.height = self->session->h;
699 XResizeWindow(ob_display, self->window,
700 self->area.width, self->area.height);
702 self->desktop = (self->session->desktop == DESKTOP_ALL ?
703 self->session->desktop :
704 MIN(screen_num_desktops - 1, self->session->desktop));
705 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
707 self->shaded = self->session->shaded;
708 self->iconic = self->session->iconic;
709 self->skip_pager = self->session->skip_pager;
710 self->skip_taskbar = self->session->skip_taskbar;
711 self->fullscreen = self->session->fullscreen;
712 self->above = self->session->above;
713 self->below = self->session->below;
714 self->max_horz = self->session->max_horz;
715 self->max_vert = self->session->max_vert;
718 static void client_restore_session_stacking(ObClient *self)
722 if (!self->session) return;
724 it = g_list_find(session_saved_state, self->session);
725 for (it = g_list_previous(it); it; it = g_list_previous(it)) {
728 for (cit = client_list; cit; cit = g_list_next(cit))
729 if (session_state_cmp(it->data, cit->data))
732 client_calc_layer(self);
733 stacking_below(CLIENT_AS_WINDOW(self),
734 CLIENT_AS_WINDOW(cit->data));
740 void client_move_onscreen(ObClient *self, gboolean rude)
742 gint x = self->area.x;
743 gint y = self->area.y;
744 if (client_find_onscreen(self, &x, &y,
745 self->frame->area.width,
746 self->frame->area.height, rude)) {
747 client_move(self, x, y);
751 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
755 gint ox = *x, oy = *y;
756 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
759 all_a = screen_area(self->desktop);
760 mon_a = screen_area_monitor(self->desktop, client_monitor(self));
762 /* get where the frame would be */
763 frame_client_gravity(self->frame, x, y, w, h);
765 /* get the requested size of the window with decorations */
766 fw = self->frame->size.left + w + self->frame->size.right;
767 fh = self->frame->size.top + h + self->frame->size.bottom;
769 /* This makes sure windows aren't entirely outside of the screen so you
770 can't see them at all.
771 It makes sure 10% of the window is on the screen at least. At don't let
772 it move itself off the top of the screen, which would hide the titlebar
773 on you. (The user can still do this if they want too, it's only limiting
776 XXX watch for xinerama dead areas...
778 if (client_normal(self)) {
779 if (!self->strut.right && *x + fw/10 >= all_a->x + all_a->width - 1)
780 *x = all_a->x + all_a->width - fw/10;
781 if (!self->strut.bottom && *y + fh/10 >= all_a->y + all_a->height - 1)
782 *y = all_a->y + all_a->height - fh/10;
783 if (!self->strut.left && *x + fw*9/10 - 1 < all_a->x)
784 *x = all_a->x - fw*9/10;
785 if (!self->strut.top && *y + fh*9/10 - 1 < all_a->y)
786 *y = all_a->y - fw*9/10;
789 /* If rudeness wasn't requested, then figure out of the client is currently
790 entirely on the screen. If it is, and the position isn't changing by
791 request, and it is enlarging, then be rude even though it wasn't
794 Point oldtl, oldtr, oldbl, oldbr;
795 Point newtl, newtr, newbl, newbr;
798 POINT_SET(oldtl, self->frame->area.x, self->frame->area.y);
799 POINT_SET(oldbr, self->frame->area.x + self->frame->area.width - 1,
800 self->frame->area.y + self->frame->area.height - 1);
801 POINT_SET(oldtr, oldbr.x, oldtl.y);
802 POINT_SET(oldbl, oldtl.x, oldbr.y);
804 POINT_SET(newtl, *x, *y);
805 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
806 POINT_SET(newtr, newbr.x, newtl.y);
807 POINT_SET(newbl, newtl.x, newbr.y);
809 /* is it moving or just resizing from some corner? */
810 stationary = (POINT_EQUAL(oldtl, newtl) || POINT_EQUAL(oldtr, newtr) ||
811 POINT_EQUAL(oldbl, newbl) || POINT_EQUAL(oldbr, newbr));
813 /* if left edge is growing */
814 if (stationary && newtl.x < oldtl.x)
816 /* if right edge is growing */
817 if (stationary && newtr.x > oldtr.x)
819 /* if top edge is growing */
820 if (stationary && newtl.y < oldtl.y)
822 /* if bottom edge is growing */
823 if (stationary && newbl.y > oldbl.y)
827 /* This here doesn't let windows even a pixel outside the struts/screen.
828 * When called from client_manage, programs placing themselves are
829 * forced completely onscreen, while things like
830 * xterm -geometry resolution-width/2 will work fine. Trying to
831 * place it completely offscreen will be handled in the above code.
832 * Sorry for this confused comment, i am tired. */
833 if (fw <= mon_a->width) {
834 if (rudel && !self->strut.left && *x < mon_a->x) *x = mon_a->x;
835 if (ruder && !self->strut.right && *x + fw > mon_a->x + mon_a->width)
836 *x = mon_a->x + mon_a->width - fw;
838 if (fh <= mon_a->height) {
839 if (rudet && !self->strut.top && *y < mon_a->y) *y = mon_a->y;
840 if (rudeb && !self->strut.bottom && *y + fh > mon_a->y + mon_a->height)
841 *y = mon_a->y + mon_a->height - fh;
844 /* get where the client should be */
845 frame_frame_gravity(self->frame, x, y, w, h);
847 return ox != *x || oy != *y;
850 static void client_toggle_border(ObClient *self, gboolean show)
852 /* adjust our idea of where the client is, based on its border. When the
853 border is removed, the client should now be considered to be in a
855 when re-adding the border to the client, the same operation needs to be
857 gint oldx = self->area.x, oldy = self->area.y;
858 gint x = oldx, y = oldy;
859 switch(self->gravity) {
861 case NorthWestGravity:
863 case SouthWestGravity:
865 case NorthEastGravity:
867 case SouthEastGravity:
868 if (show) x -= self->border_width * 2;
869 else x += self->border_width * 2;
876 if (show) x -= self->border_width;
877 else x += self->border_width;
880 switch(self->gravity) {
882 case NorthWestGravity:
884 case NorthEastGravity:
886 case SouthWestGravity:
888 case SouthEastGravity:
889 if (show) y -= self->border_width * 2;
890 else y += self->border_width * 2;
897 if (show) y -= self->border_width;
898 else y += self->border_width;
905 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
907 /* set border_width to 0 because there is no border to add into
908 calculations anymore */
909 self->border_width = 0;
911 XSetWindowBorderWidth(ob_display, self->window, 0);
915 static void client_get_all(ObClient *self)
917 client_get_area(self);
918 client_get_mwm_hints(self);
920 /* The transient hint is used to pick a type, but the type can also affect
921 transiency (dialogs are always made transients of their group if they
922 have one). This is Havoc's idea, but it is needed to make some apps
923 work right (eg tsclient). */
924 client_update_transient_for(self);
925 client_get_type(self);/* this can change the mwmhints for special cases */
926 client_get_state(self);
927 client_update_transient_for(self);
929 client_update_wmhints(self);
930 client_get_startup_id(self);
931 client_get_desktop(self);/* uses transient data/group/startup id if a
932 desktop is not specified */
933 client_get_shaped(self);
935 client_get_layer(self); /* if layer hasn't been specified, get it from
936 other sources if possible */
939 /* a couple type-based defaults for new windows */
941 /* this makes sure that these windows appear on all desktops */
942 if (self->type == OB_CLIENT_TYPE_DESKTOP)
943 self->desktop = DESKTOP_ALL;
946 client_update_protocols(self);
948 client_get_gravity(self); /* get the attribute gravity */
949 client_update_normal_hints(self); /* this may override the attribute
952 /* got the type, the mwmhints, the protocols, and the normal hints
953 (min/max sizes), so we're ready to set up the decorations/functions */
954 client_setup_decor_and_functions(self);
957 client_update_sync_request_counter(self);
959 client_get_client_machine(self);
960 client_get_colormap(self);
961 client_update_title(self);
962 client_update_class(self);
963 client_update_sm_client_id(self);
964 client_update_strut(self);
965 client_update_icons(self);
966 client_update_user_time(self);
969 static void client_get_startup_id(ObClient *self)
971 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
973 PROP_GETS(self->group->leader,
974 net_startup_id, utf8, &self->startup_id);
977 static void client_get_area(ObClient *self)
979 XWindowAttributes wattrib;
982 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
983 g_assert(ret != BadWindow);
985 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
986 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
987 self->border_width = wattrib.border_width;
989 ob_debug("client area: %d %d %d %d\n", wattrib.x, wattrib.y,
990 wattrib.width, wattrib.height);
993 static void client_get_desktop(ObClient *self)
995 guint32 d = screen_num_desktops; /* an always-invalid value */
997 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
998 if (d >= screen_num_desktops && d != DESKTOP_ALL)
999 self->desktop = screen_num_desktops - 1;
1003 gboolean trdesk = FALSE;
1005 if (self->transient_for) {
1006 if (self->transient_for != OB_TRAN_GROUP) {
1007 self->desktop = self->transient_for->desktop;
1012 for (it = self->group->members; it; it = g_slist_next(it))
1013 if (it->data != self &&
1014 !((ObClient*)it->data)->transient_for) {
1015 self->desktop = ((ObClient*)it->data)->desktop;
1022 /* try get from the startup-notification protocol */
1023 if (sn_get_desktop(self->startup_id, &self->desktop)) {
1024 if (self->desktop >= screen_num_desktops &&
1025 self->desktop != DESKTOP_ALL)
1026 self->desktop = screen_num_desktops - 1;
1028 /* defaults to the current desktop */
1029 self->desktop = screen_desktop;
1034 static void client_get_layer(ObClient *self)
1036 if (!(self->above || self->below)) {
1038 /* apply stuff from the group */
1042 for (it = self->group->members; it; it = g_slist_next(it)) {
1043 ObClient *c = it->data;
1044 if (c != self && !client_search_transient(self, c) &&
1045 client_normal(self) && client_normal(c))
1048 (c->above ? 1 : (c->below ? -1 : 0)));
1062 g_assert_not_reached();
1069 static void client_get_state(ObClient *self)
1074 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
1076 for (i = 0; i < num; ++i) {
1077 if (state[i] == prop_atoms.net_wm_state_modal)
1079 else if (state[i] == prop_atoms.net_wm_state_shaded)
1080 self->shaded = TRUE;
1081 else if (state[i] == prop_atoms.net_wm_state_hidden)
1082 self->iconic = TRUE;
1083 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
1084 self->skip_taskbar = TRUE;
1085 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
1086 self->skip_pager = TRUE;
1087 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
1088 self->fullscreen = TRUE;
1089 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
1090 self->max_vert = TRUE;
1091 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
1092 self->max_horz = TRUE;
1093 else if (state[i] == prop_atoms.net_wm_state_above)
1095 else if (state[i] == prop_atoms.net_wm_state_below)
1097 else if (state[i] == prop_atoms.net_wm_state_demands_attention)
1098 self->demands_attention = TRUE;
1099 else if (state[i] == prop_atoms.ob_wm_state_undecorated)
1100 self->undecorated = TRUE;
1107 static void client_get_shaped(ObClient *self)
1109 self->shaped = FALSE;
1111 if (extensions_shape) {
1116 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
1118 XShapeQueryExtents(ob_display, self->window, &s, &foo,
1119 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1121 self->shaped = (s != 0);
1126 void client_update_transient_for(ObClient *self)
1129 ObClient *target = NULL;
1131 if (XGetTransientForHint(ob_display, self->window, &t)) {
1132 self->transient = TRUE;
1133 if (t != self->window) { /* cant be transient to itself! */
1134 target = g_hash_table_lookup(window_map, &t);
1135 /* if this happens then we need to check for it*/
1136 g_assert(target != self);
1137 if (target && !WINDOW_IS_CLIENT(target)) {
1138 /* this can happen when a dialog is a child of
1139 a dockapp, for example */
1143 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1145 Setting the transient_for to Root is actually illegal, however
1146 applications from time have done this to specify transient for
1149 Now you can do that by being a TYPE_DIALOG and not setting
1150 the transient_for hint at all on your window. But people still
1151 use Root, and Kwin is very strange in this regard.
1153 KWin 3.0 will not consider windows with transient_for set to
1154 Root as transient for their group *UNLESS* they are also modal.
1155 In that case, it will make them transient for the group. This
1156 leads to all sorts of weird behavior from KDE apps which are
1157 only tested in KWin. I'd like to follow their behavior just to
1158 make this work right with KDE stuff, but that seems wrong.
1160 if (!target && self->group) {
1161 /* not transient to a client, see if it is transient for a
1163 if (t == RootWindow(ob_display, ob_screen)) {
1164 /* window is a transient for its group! */
1165 target = OB_TRAN_GROUP;
1169 } else if (self->group) {
1170 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1171 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1172 self->type == OB_CLIENT_TYPE_MENU ||
1173 self->type == OB_CLIENT_TYPE_UTILITY)
1175 self->transient = TRUE;
1176 target = OB_TRAN_GROUP;
1179 self->transient = FALSE;
1181 /* if anything has changed... */
1182 if (target != self->transient_for) {
1183 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
1186 /* remove from old parents */
1187 for (it = self->group->members; it; it = g_slist_next(it)) {
1188 ObClient *c = it->data;
1189 if (c != self && (!c->transient_for ||
1190 c->transient_for != OB_TRAN_GROUP))
1191 c->transients = g_slist_remove(c->transients, self);
1193 } else if (self->transient_for != NULL) { /* transient of window */
1194 /* remove from old parent */
1195 self->transient_for->transients =
1196 g_slist_remove(self->transient_for->transients, self);
1198 self->transient_for = target;
1199 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
1202 /* add to new parents */
1203 for (it = self->group->members; it; it = g_slist_next(it)) {
1204 ObClient *c = it->data;
1205 if (c != self && (!c->transient_for ||
1206 c->transient_for != OB_TRAN_GROUP))
1207 c->transients = g_slist_append(c->transients, self);
1210 /* remove all transients which are in the group, that causes
1211 circlular pointer hell of doom */
1212 for (it = self->group->members; it; it = g_slist_next(it)) {
1214 for (sit = self->transients; sit; sit = next) {
1215 next = g_slist_next(sit);
1216 if (sit->data == it->data)
1218 g_slist_delete_link(self->transients, sit);
1221 } else if (self->transient_for != NULL) { /* transient of window */
1222 /* add to new parent */
1223 self->transient_for->transients =
1224 g_slist_append(self->transient_for->transients, self);
1229 static void client_get_mwm_hints(ObClient *self)
1234 self->mwmhints.flags = 0; /* default to none */
1236 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
1238 if (num >= OB_MWM_ELEMENTS) {
1239 self->mwmhints.flags = hints[0];
1240 self->mwmhints.functions = hints[1];
1241 self->mwmhints.decorations = hints[2];
1247 void client_get_type(ObClient *self)
1254 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
1255 /* use the first value that we know about in the array */
1256 for (i = 0; i < num; ++i) {
1257 if (val[i] == prop_atoms.net_wm_window_type_desktop)
1258 self->type = OB_CLIENT_TYPE_DESKTOP;
1259 else if (val[i] == prop_atoms.net_wm_window_type_dock)
1260 self->type = OB_CLIENT_TYPE_DOCK;
1261 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
1262 self->type = OB_CLIENT_TYPE_TOOLBAR;
1263 else if (val[i] == prop_atoms.net_wm_window_type_menu)
1264 self->type = OB_CLIENT_TYPE_MENU;
1265 else if (val[i] == prop_atoms.net_wm_window_type_utility)
1266 self->type = OB_CLIENT_TYPE_UTILITY;
1267 else if (val[i] == prop_atoms.net_wm_window_type_splash)
1268 self->type = OB_CLIENT_TYPE_SPLASH;
1269 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
1270 self->type = OB_CLIENT_TYPE_DIALOG;
1271 else if (val[i] == prop_atoms.net_wm_window_type_normal)
1272 self->type = OB_CLIENT_TYPE_NORMAL;
1273 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
1274 /* prevent this window from getting any decor or
1276 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1277 OB_MWM_FLAG_DECORATIONS);
1278 self->mwmhints.decorations = 0;
1279 self->mwmhints.functions = 0;
1281 if (self->type != (ObClientType) -1)
1282 break; /* grab the first legit type */
1287 if (self->type == (ObClientType) -1) {
1288 /*the window type hint was not set, which means we either classify
1289 ourself as a normal window or a dialog, depending on if we are a
1291 if (self->transient)
1292 self->type = OB_CLIENT_TYPE_DIALOG;
1294 self->type = OB_CLIENT_TYPE_NORMAL;
1298 void client_update_protocols(ObClient *self)
1301 guint num_return, i;
1303 self->focus_notify = FALSE;
1304 self->delete_window = FALSE;
1306 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
1307 for (i = 0; i < num_return; ++i) {
1308 if (proto[i] == prop_atoms.wm_delete_window)
1309 /* this means we can request the window to close */
1310 self->delete_window = TRUE;
1311 else if (proto[i] == prop_atoms.wm_take_focus)
1312 /* if this protocol is requested, then the window will be
1313 notified whenever we want it to receive focus */
1314 self->focus_notify = TRUE;
1316 else if (proto[i] == prop_atoms.net_wm_sync_request)
1317 /* if this protocol is requested, then resizing the
1318 window will be synchronized between the frame and the
1320 self->sync_request = TRUE;
1328 void client_update_sync_request_counter(ObClient *self)
1332 if (PROP_GET32(self->window, net_wm_sync_request_counter, cardinal, &i)) {
1333 self->sync_counter = i;
1335 self->sync_counter = None;
1339 static void client_get_gravity(ObClient *self)
1341 XWindowAttributes wattrib;
1344 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
1345 g_assert(ret != BadWindow);
1346 self->gravity = wattrib.win_gravity;
1349 void client_get_colormap(ObClient *self)
1351 XWindowAttributes wa;
1353 if (XGetWindowAttributes(ob_display, self->window, &wa))
1354 client_update_colormap(self, wa.colormap);
1357 void client_update_colormap(ObClient *self, Colormap colormap)
1359 self->colormap = colormap;
1362 void client_update_normal_hints(ObClient *self)
1366 gint oldgravity = self->gravity;
1369 self->min_ratio = 0.0f;
1370 self->max_ratio = 0.0f;
1371 SIZE_SET(self->size_inc, 1, 1);
1372 SIZE_SET(self->base_size, 0, 0);
1373 SIZE_SET(self->min_size, 0, 0);
1374 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1376 /* get the hints from the window */
1377 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1378 /* normal windows can't request placement! har har
1379 if (!client_normal(self))
1381 self->positioned = (size.flags & (PPosition|USPosition));
1383 if (size.flags & PWinGravity) {
1384 self->gravity = size.win_gravity;
1386 /* if the client has a frame, i.e. has already been mapped and
1387 is changing its gravity */
1388 if (self->frame && self->gravity != oldgravity) {
1389 /* move our idea of the client's position based on its new
1391 client_convert_gravity(self, oldgravity,
1392 &self->area.x, &self->area.y,
1393 self->area.width, self->area.height);
1397 if (size.flags & PAspect) {
1398 if (size.min_aspect.y)
1400 (gfloat) size.min_aspect.x / size.min_aspect.y;
1401 if (size.max_aspect.y)
1403 (gfloat) size.max_aspect.x / size.max_aspect.y;
1406 if (size.flags & PMinSize)
1407 SIZE_SET(self->min_size, size.min_width, size.min_height);
1409 if (size.flags & PMaxSize)
1410 SIZE_SET(self->max_size, size.max_width, size.max_height);
1412 if (size.flags & PBaseSize)
1413 SIZE_SET(self->base_size, size.base_width, size.base_height);
1415 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1416 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1420 void client_setup_decor_and_functions(ObClient *self)
1422 /* start with everything (cept fullscreen) */
1424 (OB_FRAME_DECOR_TITLEBAR |
1425 OB_FRAME_DECOR_HANDLE |
1426 OB_FRAME_DECOR_GRIPS |
1427 OB_FRAME_DECOR_BORDER |
1428 OB_FRAME_DECOR_ICON |
1429 OB_FRAME_DECOR_ALLDESKTOPS |
1430 OB_FRAME_DECOR_ICONIFY |
1431 OB_FRAME_DECOR_MAXIMIZE |
1432 OB_FRAME_DECOR_SHADE |
1433 OB_FRAME_DECOR_CLOSE);
1435 (OB_CLIENT_FUNC_RESIZE |
1436 OB_CLIENT_FUNC_MOVE |
1437 OB_CLIENT_FUNC_ICONIFY |
1438 OB_CLIENT_FUNC_MAXIMIZE |
1439 OB_CLIENT_FUNC_SHADE |
1440 OB_CLIENT_FUNC_CLOSE);
1442 if (!(self->min_size.width < self->max_size.width ||
1443 self->min_size.height < self->max_size.height))
1444 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1446 switch (self->type) {
1447 case OB_CLIENT_TYPE_NORMAL:
1448 /* normal windows retain all of the possible decorations and
1449 functionality, and are the only windows that you can fullscreen */
1450 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1453 case OB_CLIENT_TYPE_DIALOG:
1454 case OB_CLIENT_TYPE_UTILITY:
1455 /* these windows cannot be maximized */
1456 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1459 case OB_CLIENT_TYPE_MENU:
1460 case OB_CLIENT_TYPE_TOOLBAR:
1461 /* these windows get less functionality */
1462 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY | OB_CLIENT_FUNC_RESIZE);
1465 case OB_CLIENT_TYPE_DESKTOP:
1466 case OB_CLIENT_TYPE_DOCK:
1467 case OB_CLIENT_TYPE_SPLASH:
1468 /* none of these windows are manipulated by the window manager */
1469 self->decorations = 0;
1470 self->functions = 0;
1474 /* Mwm Hints are applied subtractively to what has already been chosen for
1475 decor and functionality */
1476 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1477 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1478 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1479 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1481 /* if the mwm hints request no handle or title, then all
1482 decorations are disabled, but keep the border if that's
1484 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1485 self->decorations = OB_FRAME_DECOR_BORDER;
1487 self->decorations = 0;
1492 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1493 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1494 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1495 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1496 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1497 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1498 /* dont let mwm hints kill any buttons
1499 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1500 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1501 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1502 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1504 /* dont let mwm hints kill the close button
1505 if (! (self->mwmhints.functions & MwmFunc_Close))
1506 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1510 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1511 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1512 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1513 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1514 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1515 self->decorations &= ~OB_FRAME_DECOR_GRIPS;
1517 /* can't maximize without moving/resizing */
1518 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1519 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1520 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1521 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1522 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1525 /* kill the handle on fully maxed windows */
1526 if (self->max_vert && self->max_horz)
1527 self->decorations &= ~OB_FRAME_DECOR_HANDLE;
1529 /* finally, the user can have requested no decorations, which overrides
1530 everything (but doesnt give it a border if it doesnt have one) */
1531 if (self->undecorated) {
1532 if (config_theme_keepborder)
1533 self->decorations &= OB_FRAME_DECOR_BORDER;
1535 self->decorations = 0;
1538 /* if we don't have a titlebar, then we cannot shade! */
1539 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1540 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1542 /* now we need to check against rules for the client's current state */
1543 if (self->fullscreen) {
1544 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1545 OB_CLIENT_FUNC_FULLSCREEN |
1546 OB_CLIENT_FUNC_ICONIFY);
1547 self->decorations = 0;
1550 client_change_allowed_actions(self);
1553 /* adjust the client's decorations, etc. */
1554 client_reconfigure(self);
1558 static void client_change_allowed_actions(ObClient *self)
1563 /* desktop windows are kept on all desktops */
1564 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1565 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1567 if (self->functions & OB_CLIENT_FUNC_SHADE)
1568 actions[num++] = prop_atoms.net_wm_action_shade;
1569 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1570 actions[num++] = prop_atoms.net_wm_action_close;
1571 if (self->functions & OB_CLIENT_FUNC_MOVE)
1572 actions[num++] = prop_atoms.net_wm_action_move;
1573 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1574 actions[num++] = prop_atoms.net_wm_action_minimize;
1575 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1576 actions[num++] = prop_atoms.net_wm_action_resize;
1577 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1578 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1579 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1580 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1581 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1584 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1586 /* make sure the window isn't breaking any rules now */
1588 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1589 if (self->frame) client_shade(self, FALSE);
1590 else self->shaded = FALSE;
1592 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1593 if (self->frame) client_iconify(self, FALSE, TRUE);
1594 else self->iconic = FALSE;
1596 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1597 if (self->frame) client_fullscreen(self, FALSE);
1598 else self->fullscreen = FALSE;
1600 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1602 if (self->frame) client_maximize(self, FALSE, 0);
1603 else self->max_vert = self->max_horz = FALSE;
1607 void client_reconfigure(ObClient *self)
1609 /* by making this pass FALSE for user, we avoid the emacs event storm where
1610 every configurenotify causes an update in its normal hints, i think this
1611 is generally what we want anyways... */
1612 client_configure(self, self->area.x, self->area.y,
1613 self->area.width, self->area.height, FALSE, TRUE);
1616 void client_update_wmhints(ObClient *self)
1621 /* assume a window takes input if it doesnt specify */
1622 self->can_focus = TRUE;
1624 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1625 if (hints->flags & InputHint)
1626 self->can_focus = hints->input;
1628 /* only do this when first managing the window *AND* when we aren't
1630 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1631 if (hints->flags & StateHint)
1632 self->iconic = hints->initial_state == IconicState;
1634 if (!(hints->flags & WindowGroupHint))
1635 hints->window_group = None;
1637 /* did the group state change? */
1638 if (hints->window_group !=
1639 (self->group ? self->group->leader : None)) {
1640 /* remove from the old group if there was one */
1641 if (self->group != NULL) {
1642 /* remove transients of the group */
1643 for (it = self->group->members; it; it = g_slist_next(it))
1644 self->transients = g_slist_remove(self->transients,
1647 /* remove myself from parents in the group */
1648 if (self->transient_for == OB_TRAN_GROUP) {
1649 for (it = self->group->members; it;
1650 it = g_slist_next(it))
1652 ObClient *c = it->data;
1654 if (c != self && !c->transient_for)
1655 c->transients = g_slist_remove(c->transients,
1660 group_remove(self->group, self);
1663 if (hints->window_group != None) {
1664 self->group = group_add(hints->window_group, self);
1666 /* i can only have transients from the group if i am not
1668 if (!self->transient_for) {
1669 /* add other transients of the group that are already
1671 for (it = self->group->members; it;
1672 it = g_slist_next(it))
1674 ObClient *c = it->data;
1675 if (c != self && c->transient_for == OB_TRAN_GROUP)
1677 g_slist_append(self->transients, c);
1682 /* because the self->transient flag wont change from this call,
1683 we don't need to update the window's type and such, only its
1684 transient_for, and the transients lists of other windows in
1685 the group may be affected */
1686 client_update_transient_for(self);
1689 /* the WM_HINTS can contain an icon */
1690 client_update_icons(self);
1696 void client_update_title(ObClient *self)
1699 gchar *visible = NULL;
1701 g_free(self->title);
1704 if (!PROP_GETS(self->window, net_wm_name, utf8, &data)) {
1705 /* try old x stuff */
1706 if (!(PROP_GETS(self->window, wm_name, locale, &data)
1707 || PROP_GETS(self->window, wm_name, utf8, &data))) {
1708 if (self->transient) {
1710 GNOME alert windows are not given titles:
1711 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1713 data = g_strdup("");
1715 data = g_strdup("Unnamed Window");
1719 if (self->client_machine) {
1720 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1725 PROP_SETS(self->window, net_wm_visible_name, visible);
1726 self->title = visible;
1729 frame_adjust_title(self->frame);
1731 /* update the icon title */
1733 g_free(self->icon_title);
1736 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1737 /* try old x stuff */
1738 if (!(PROP_GETS(self->window, wm_icon_name, locale, &data) ||
1739 PROP_GETS(self->window, wm_icon_name, utf8, &data)))
1740 data = g_strdup(self->title);
1742 PROP_SETS(self->window, net_wm_visible_icon_name, data);
1743 self->icon_title = data;
1746 void client_update_class(ObClient *self)
1751 if (self->name) g_free(self->name);
1752 if (self->class) g_free(self->class);
1753 if (self->role) g_free(self->role);
1755 self->name = self->class = self->role = NULL;
1757 if (PROP_GETSS(self->window, wm_class, locale, &data)) {
1759 self->name = g_strdup(data[0]);
1761 self->class = g_strdup(data[1]);
1766 if (PROP_GETS(self->window, wm_window_role, locale, &s))
1769 if (self->name == NULL) self->name = g_strdup("");
1770 if (self->class == NULL) self->class = g_strdup("");
1771 if (self->role == NULL) self->role = g_strdup("");
1774 void client_update_strut(ObClient *self)
1778 gboolean got = FALSE;
1781 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1785 STRUT_PARTIAL_SET(strut,
1786 data[0], data[2], data[1], data[3],
1787 data[4], data[5], data[8], data[9],
1788 data[6], data[7], data[10], data[11]);
1794 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1800 /* use the screen's width/height */
1801 a = screen_physical_area();
1803 STRUT_PARTIAL_SET(strut,
1804 data[0], data[2], data[1], data[3],
1805 a->y, a->y + a->height - 1,
1806 a->x, a->x + a->width - 1,
1807 a->y, a->y + a->height - 1,
1808 a->x, a->x + a->width - 1);
1814 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
1815 0, 0, 0, 0, 0, 0, 0, 0);
1817 if (!STRUT_EQUAL(strut, self->strut)) {
1818 self->strut = strut;
1820 /* updating here is pointless while we're being mapped cuz we're not in
1821 the client list yet */
1823 screen_update_areas();
1827 void client_update_icons(ObClient *self)
1833 for (i = 0; i < self->nicons; ++i)
1834 g_free(self->icons[i].data);
1835 if (self->nicons > 0)
1836 g_free(self->icons);
1839 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
1840 /* figure out how many valid icons are in here */
1842 while (num - i > 2) {
1846 if (i > num || w*h == 0) break;
1850 self->icons = g_new(ObClientIcon, self->nicons);
1852 /* store the icons */
1854 for (j = 0; j < self->nicons; ++j) {
1857 w = self->icons[j].width = data[i++];
1858 h = self->icons[j].height = data[i++];
1860 if (w*h == 0) continue;
1862 self->icons[j].data = g_new(RrPixel32, w * h);
1863 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
1868 self->icons[j].data[t] =
1869 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
1870 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
1871 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
1872 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
1881 if ((hints = XGetWMHints(ob_display, self->window))) {
1882 if (hints->flags & IconPixmapHint) {
1884 self->icons = g_new(ObClientIcon, self->nicons);
1885 xerror_set_ignore(TRUE);
1886 if (!RrPixmapToRGBA(ob_rr_inst,
1888 (hints->flags & IconMaskHint ?
1889 hints->icon_mask : None),
1890 &self->icons[self->nicons-1].width,
1891 &self->icons[self->nicons-1].height,
1892 &self->icons[self->nicons-1].data)){
1893 g_free(&self->icons[self->nicons-1]);
1896 xerror_set_ignore(FALSE);
1902 /* set the default icon onto the window
1903 in theory, this could be a race, but if a window doesn't set an icon
1904 or removes it entirely, it's not very likely it is going to set one
1905 right away afterwards */
1906 if (self->nicons == 0) {
1907 RrPixel32 *icon = ob_rr_theme->def_win_icon;
1910 data = g_new(gulong, 48*48+2);
1911 data[0] = data[1] = 48;
1912 for (i = 0; i < 48*48; ++i)
1913 data[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
1914 (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) +
1915 (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) +
1916 (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0);
1917 PROP_SETA32(self->window, net_wm_icon, cardinal, data, 48*48+2);
1919 } else if (self->frame)
1920 /* don't draw the icon empty if we're just setting one now anyways,
1921 we'll get the property change any second */
1922 frame_adjust_icon(self->frame);
1925 void client_update_user_time(ObClient *self)
1929 if (PROP_GET32(self->window, net_wm_user_time, cardinal, &time)) {
1930 /* we set this every time, not just when it grows, because in practice
1931 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1932 backward we don't want all windows to stop focusing. we'll just
1933 assume noone is setting times older than the last one, cuz that
1934 would be pretty stupid anyways
1936 self->user_time = time;
1939 ob_debug("window %s user time %u\n", self->title, time);
1944 static void client_get_client_machine(ObClient *self)
1947 gchar localhost[128];
1949 g_free(self->client_machine);
1951 if (PROP_GETS(self->window, wm_client_machine, locale, &data)) {
1952 gethostname(localhost, 127);
1953 localhost[127] = '\0';
1954 if (strcmp(localhost, data))
1955 self->client_machine = data;
1959 static void client_change_wm_state(ObClient *self)
1964 old = self->wmstate;
1966 if (self->shaded || self->iconic || !self->frame->visible)
1967 self->wmstate = IconicState;
1969 self->wmstate = NormalState;
1971 if (old != self->wmstate) {
1972 PROP_MSG(self->window, kde_wm_change_state,
1973 self->wmstate, 1, 0, 0);
1975 state[0] = self->wmstate;
1977 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
1981 static void client_change_state(ObClient *self)
1983 gulong netstate[11];
1988 netstate[num++] = prop_atoms.net_wm_state_modal;
1990 netstate[num++] = prop_atoms.net_wm_state_shaded;
1992 netstate[num++] = prop_atoms.net_wm_state_hidden;
1993 if (self->skip_taskbar)
1994 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
1995 if (self->skip_pager)
1996 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
1997 if (self->fullscreen)
1998 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
2000 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
2002 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
2004 netstate[num++] = prop_atoms.net_wm_state_above;
2006 netstate[num++] = prop_atoms.net_wm_state_below;
2007 if (self->demands_attention)
2008 netstate[num++] = prop_atoms.net_wm_state_demands_attention;
2009 if (self->undecorated)
2010 netstate[num++] = prop_atoms.ob_wm_state_undecorated;
2011 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
2014 frame_adjust_state(self->frame);
2017 ObClient *client_search_focus_tree(ObClient *self)
2022 for (it = self->transients; it; it = g_slist_next(it)) {
2023 if (client_focused(it->data)) return it->data;
2024 if ((ret = client_search_focus_tree(it->data))) return ret;
2029 ObClient *client_search_focus_tree_full(ObClient *self)
2031 if (self->transient_for) {
2032 if (self->transient_for != OB_TRAN_GROUP) {
2033 return client_search_focus_tree_full(self->transient_for);
2036 gboolean recursed = FALSE;
2038 for (it = self->group->members; it; it = g_slist_next(it))
2039 if (!((ObClient*)it->data)->transient_for) {
2041 if ((c = client_search_focus_tree_full(it->data)))
2050 /* this function checks the whole tree, the client_search_focus_tree~
2051 does not, so we need to check this window */
2052 if (client_focused(self))
2054 return client_search_focus_tree(self);
2057 static ObStackingLayer calc_layer(ObClient *self)
2061 if (self->fullscreen &&
2062 (client_focused(self) || client_search_focus_tree(self)))
2063 l = OB_STACKING_LAYER_FULLSCREEN;
2064 else if (self->type == OB_CLIENT_TYPE_DESKTOP)
2065 l = OB_STACKING_LAYER_DESKTOP;
2066 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2067 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2068 else l = OB_STACKING_LAYER_ABOVE;
2070 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2071 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2072 else l = OB_STACKING_LAYER_NORMAL;
2077 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2078 ObStackingLayer min, gboolean raised)
2080 ObStackingLayer old, own;
2084 own = calc_layer(self);
2085 self->layer = MAX(own, min);
2087 for (it = self->transients; it; it = g_slist_next(it))
2088 client_calc_layer_recursive(it->data, orig,
2090 raised ? raised : self->layer != old);
2092 if (!raised && self->layer != old)
2093 if (orig->frame) { /* only restack if the original window is managed */
2094 stacking_remove(CLIENT_AS_WINDOW(self));
2095 stacking_add(CLIENT_AS_WINDOW(self));
2099 void client_calc_layer(ObClient *self)
2106 /* transients take on the layer of their parents */
2107 it = client_search_all_top_parents(self);
2109 for (; it; it = g_slist_next(it))
2110 client_calc_layer_recursive(it->data, orig, 0, FALSE);
2113 gboolean client_should_show(ObClient *self)
2117 if (client_normal(self) && screen_showing_desktop)
2120 if (self->transient_for) {
2121 if (self->transient_for != OB_TRAN_GROUP)
2122 return client_should_show(self->transient_for);
2126 for (it = self->group->members; it; it = g_slist_next(it)) {
2127 ObClient *c = it->data;
2128 if (c != self && !c->transient_for) {
2129 if (client_should_show(c))
2136 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2142 void client_show(ObClient *self)
2145 if (client_should_show(self)) {
2146 frame_show(self->frame);
2149 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2150 needs to be in IconicState. This includes when it is on another
2153 client_change_wm_state(self);
2156 void client_hide(ObClient *self)
2158 if (!client_should_show(self)) {
2159 frame_hide(self->frame);
2162 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2163 needs to be in IconicState. This includes when it is on another
2166 client_change_wm_state(self);
2169 void client_showhide(ObClient *self)
2172 if (client_should_show(self)) {
2173 frame_show(self->frame);
2176 frame_hide(self->frame);
2179 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2180 needs to be in IconicState. This includes when it is on another
2183 client_change_wm_state(self);
2186 gboolean client_normal(ObClient *self) {
2187 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2188 self->type == OB_CLIENT_TYPE_DOCK ||
2189 self->type == OB_CLIENT_TYPE_SPLASH);
2192 static void client_apply_startup_state(ObClient *self, gint x, gint y)
2194 gboolean pos = FALSE; /* has the window's position been configured? */
2197 /* save the position, and set self->area for these to use */
2203 /* set the desktop hint, to make sure that it always exists */
2204 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
2206 /* these are in a carefully crafted order.. */
2209 self->iconic = FALSE;
2210 client_iconify(self, TRUE, FALSE);
2212 if (self->fullscreen) {
2213 self->fullscreen = FALSE;
2214 client_fullscreen(self, TRUE);
2217 if (self->undecorated) {
2218 self->undecorated = FALSE;
2219 client_set_undecorated(self, TRUE);
2222 self->shaded = FALSE;
2223 client_shade(self, TRUE);
2225 if (self->demands_attention) {
2226 self->demands_attention = FALSE;
2227 client_hilite(self, TRUE);
2230 if (self->max_vert && self->max_horz) {
2231 self->max_vert = self->max_horz = FALSE;
2232 client_maximize(self, TRUE, 0);
2234 } else if (self->max_vert) {
2235 self->max_vert = FALSE;
2236 client_maximize(self, TRUE, 2);
2238 } else if (self->max_horz) {
2239 self->max_horz = FALSE;
2240 client_maximize(self, TRUE, 1);
2244 /* if the client didn't get positioned yet, then do so now
2245 call client_move even if the window is not being moved anywhere, because
2246 when we reparent it and decorate it, it is getting moved and we need to
2247 be telling it so with a ConfigureNotify event.
2250 /* use the saved position */
2253 client_move(self, x, y);
2256 /* nothing to do for the other states:
2265 void client_convert_gravity(ObClient *self, gint gravity, gint *x, gint *y,
2268 gint oldg = self->gravity;
2270 /* get the frame's position from the requested stuff */
2271 self->gravity = gravity;
2272 frame_client_gravity(self->frame, x, y, w, h);
2273 self->gravity = oldg;
2275 /* get the client's position in its true gravity from that */
2276 frame_frame_gravity(self->frame, x, y, w, h);
2279 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2280 gint *logicalw, gint *logicalh,
2283 Rect desired_area = {*x, *y, *w, *h};
2285 /* make the frame recalculate its dimentions n shit without changing
2286 anything visible for real, this way the constraints below can work with
2287 the updated frame dimensions. */
2288 frame_adjust_area(self->frame, TRUE, TRUE, TRUE);
2290 /* work within the prefered sizes given by the window */
2291 if (!(*w == self->area.width && *h == self->area.height)) {
2292 gint basew, baseh, minw, minh;
2294 /* base size is substituted with min size if not specified */
2295 if (self->base_size.width || self->base_size.height) {
2296 basew = self->base_size.width;
2297 baseh = self->base_size.height;
2299 basew = self->min_size.width;
2300 baseh = self->min_size.height;
2302 /* min size is substituted with base size if not specified */
2303 if (self->min_size.width || self->min_size.height) {
2304 minw = self->min_size.width;
2305 minh = self->min_size.height;
2307 minw = self->base_size.width;
2308 minh = self->base_size.height;
2311 /* if this is a user-requested resize, then check against min/max
2314 /* smaller than min size or bigger than max size? */
2315 if (*w > self->max_size.width) *w = self->max_size.width;
2316 if (*w < minw) *w = minw;
2317 if (*h > self->max_size.height) *h = self->max_size.height;
2318 if (*h < minh) *h = minh;
2323 /* keep to the increments */
2324 *w /= self->size_inc.width;
2325 *h /= self->size_inc.height;
2327 /* you cannot resize to nothing */
2328 if (basew + *w < 1) *w = 1 - basew;
2329 if (baseh + *h < 1) *h = 1 - baseh;
2331 /* save the logical size */
2332 *logicalw = self->size_inc.width > 1 ? *w : *w + basew;
2333 *logicalh = self->size_inc.height > 1 ? *h : *h + baseh;
2335 *w *= self->size_inc.width;
2336 *h *= self->size_inc.height;
2341 /* adjust the height to match the width for the aspect ratios.
2342 for this, min size is not substituted for base size ever. */
2343 *w -= self->base_size.width;
2344 *h -= self->base_size.height;
2346 if (!self->fullscreen) {
2347 if (self->min_ratio)
2348 if (*h * self->min_ratio > *w) {
2349 *h = (gint)(*w / self->min_ratio);
2351 /* you cannot resize to nothing */
2354 *w = (gint)(*h * self->min_ratio);
2357 if (self->max_ratio)
2358 if (*h * self->max_ratio < *w) {
2359 *h = (gint)(*w / self->max_ratio);
2361 /* you cannot resize to nothing */
2364 *w = (gint)(*h * self->min_ratio);
2369 *w += self->base_size.width;
2370 *h += self->base_size.height;
2373 /* gets the frame's position */
2374 frame_client_gravity(self->frame, x, y, *w, *h);
2376 /* these positions are frame positions, not client positions */
2378 /* set the size and position if fullscreen */
2379 if (self->fullscreen) {
2383 i = screen_find_monitor(&desired_area);
2384 a = screen_physical_area_monitor(i);
2391 user = FALSE; /* ignore if the client can't be moved/resized when it
2392 is entering fullscreen */
2393 } else if (self->max_horz || self->max_vert) {
2397 i = screen_find_monitor(&desired_area);
2398 a = screen_area_monitor(self->desktop, i);
2400 /* set the size and position if maximized */
2401 if (self->max_horz) {
2403 *w = a->width - self->frame->size.left - self->frame->size.right;
2405 if (self->max_vert) {
2407 *h = a->height - self->frame->size.top - self->frame->size.bottom;
2410 /* maximizing is not allowed if the user can't move+resize the window
2414 /* gets the client's position */
2415 frame_frame_gravity(self->frame, x, y, *w, *h);
2417 /* these override the above states! if you cant move you can't move! */
2419 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
2423 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2424 *w = self->area.width;
2425 *h = self->area.height;
2434 void client_configure_full(ObClient *self, gint x, gint y, gint w, gint h,
2435 gboolean user, gboolean final,
2436 gboolean force_reply)
2438 gint oldw, oldh, oldrx, oldry;
2439 gboolean send_resize_client;
2440 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
2441 guint fdecor = self->frame->decorations;
2442 gboolean fhorz = self->frame->max_horz;
2443 gint logicalw, logicalh;
2445 /* find the new x, y, width, and height (and logical size) */
2446 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
2448 /* set the logical size if things changed */
2449 if (!(w == self->area.width && h == self->area.height))
2450 SIZE_SET(self->logical_size, logicalw, logicalh);
2452 /* figure out if we moved or resized or what */
2453 moved = x != self->area.x || y != self->area.y;
2454 resized = w != self->area.width || h != self->area.height;
2456 oldw = self->area.width;
2457 oldh = self->area.height;
2458 RECT_SET(self->area, x, y, w, h);
2460 /* for app-requested resizes, always resize if 'resized' is true.
2461 for user-requested ones, only resize if final is true, or when
2462 resizing in redraw mode */
2463 send_resize_client = ((!user && resized) ||
2465 (resized && config_resize_redraw))));
2467 /* if the client is enlarging, then resize the client before the frame */
2468 if (send_resize_client && user && (w > oldw || h > oldh)) {
2469 XResizeWindow(ob_display, self->window, MAX(w, oldw), MAX(h, oldh));
2470 /* resize the plate to show the client padding color underneath */
2471 frame_adjust_client_area(self->frame);
2474 /* find the frame's dimensions and move/resize it */
2475 if (self->decorations != fdecor || self->max_horz != fhorz)
2476 moved = resized = TRUE;
2477 if (moved || resized)
2478 frame_adjust_area(self->frame, moved, resized, FALSE);
2480 /* find the client's position relative to the root window */
2481 oldrx = self->root_pos.x;
2482 oldry = self->root_pos.y;
2483 rootmoved = (oldrx != (signed)(self->frame->area.x +
2484 self->frame->size.left -
2485 self->border_width) ||
2486 oldry != (signed)(self->frame->area.y +
2487 self->frame->size.top -
2488 self->border_width));
2490 if (force_reply || ((!user || (user && final)) && rootmoved))
2494 POINT_SET(self->root_pos,
2495 self->frame->area.x + self->frame->size.left -
2497 self->frame->area.y + self->frame->size.top -
2498 self->border_width);
2500 event.type = ConfigureNotify;
2501 event.xconfigure.display = ob_display;
2502 event.xconfigure.event = self->window;
2503 event.xconfigure.window = self->window;
2505 /* root window real coords */
2506 event.xconfigure.x = self->root_pos.x;
2507 event.xconfigure.y = self->root_pos.y;
2508 event.xconfigure.width = w;
2509 event.xconfigure.height = h;
2510 event.xconfigure.border_width = 0;
2511 event.xconfigure.above = self->frame->plate;
2512 event.xconfigure.override_redirect = FALSE;
2513 XSendEvent(event.xconfigure.display, event.xconfigure.window,
2514 FALSE, StructureNotifyMask, &event);
2517 /* if the client is shrinking, then resize the frame before the client */
2518 if (send_resize_client && (!user || (w <= oldw || h <= oldh))) {
2519 /* resize the plate to show the client padding color underneath */
2520 frame_adjust_client_area(self->frame);
2522 XResizeWindow(ob_display, self->window, w, h);
2528 void client_fullscreen(ObClient *self, gboolean fs)
2532 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
2533 self->fullscreen == fs) return; /* already done */
2535 self->fullscreen = fs;
2536 client_change_state(self); /* change the state hints on the client */
2537 client_calc_layer(self); /* and adjust out layer/stacking */
2540 self->pre_fullscreen_area = self->area;
2541 /* if the window is maximized, its area isn't all that meaningful.
2542 save it's premax area instead. */
2543 if (self->max_horz) {
2544 self->pre_fullscreen_area.x = self->pre_max_area.x;
2545 self->pre_fullscreen_area.width = self->pre_max_area.width;
2547 if (self->max_vert) {
2548 self->pre_fullscreen_area.y = self->pre_max_area.y;
2549 self->pre_fullscreen_area.height = self->pre_max_area.height;
2552 /* these are not actually used cuz client_configure will set them
2553 as appropriate when the window is fullscreened */
2558 if (self->pre_fullscreen_area.width > 0 &&
2559 self->pre_fullscreen_area.height > 0)
2561 x = self->pre_fullscreen_area.x;
2562 y = self->pre_fullscreen_area.y;
2563 w = self->pre_fullscreen_area.width;
2564 h = self->pre_fullscreen_area.height;
2565 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
2567 /* pick some fallbacks... */
2568 a = screen_area_monitor(self->desktop, 0);
2569 x = a->x + a->width / 4;
2570 y = a->y + a->height / 4;
2576 client_setup_decor_and_functions(self);
2578 client_move_resize(self, x, y, w, h);
2580 /* try focus us when we go into fullscreen mode */
2584 static void client_iconify_recursive(ObClient *self,
2585 gboolean iconic, gboolean curdesk)
2588 gboolean changed = FALSE;
2591 if (self->iconic != iconic) {
2592 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2596 if (self->functions & OB_CLIENT_FUNC_ICONIFY) {
2597 self->iconic = iconic;
2599 /* update the focus lists.. iconic windows go to the bottom of
2600 the list, put the new iconic window at the 'top of the
2602 focus_order_to_top(self);
2607 self->iconic = iconic;
2610 client_set_desktop(self, screen_desktop, FALSE);
2612 /* this puts it after the current focused window */
2613 focus_order_remove(self);
2614 focus_order_add_new(self);
2621 client_change_state(self);
2622 client_showhide(self);
2623 if (STRUT_EXISTS(self->strut))
2624 screen_update_areas();
2627 /* iconify all direct transients */
2628 for (it = self->transients; it; it = g_slist_next(it))
2629 if (it->data != self)
2630 if (client_is_direct_child(self, it->data))
2631 client_iconify_recursive(it->data, iconic, curdesk);
2634 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk)
2636 /* move up the transient chain as far as possible first */
2637 self = client_search_top_parent(self);
2638 client_iconify_recursive(self, iconic, curdesk);
2641 void client_maximize(ObClient *self, gboolean max, gint dir)
2645 g_assert(dir == 0 || dir == 1 || dir == 2);
2646 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
2648 /* check if already done */
2650 if (dir == 0 && self->max_horz && self->max_vert) return;
2651 if (dir == 1 && self->max_horz) return;
2652 if (dir == 2 && self->max_vert) return;
2654 if (dir == 0 && !self->max_horz && !self->max_vert) return;
2655 if (dir == 1 && !self->max_horz) return;
2656 if (dir == 2 && !self->max_vert) return;
2659 /* we just tell it to configure in the same place and client_configure
2660 worries about filling the screen with the window */
2663 w = self->area.width;
2664 h = self->area.height;
2667 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
2668 RECT_SET(self->pre_max_area,
2669 self->area.x, self->pre_max_area.y,
2670 self->area.width, self->pre_max_area.height);
2672 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
2673 RECT_SET(self->pre_max_area,
2674 self->pre_max_area.x, self->area.y,
2675 self->pre_max_area.width, self->area.height);
2680 a = screen_area_monitor(self->desktop, 0);
2681 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
2682 if (self->pre_max_area.width > 0) {
2683 x = self->pre_max_area.x;
2684 w = self->pre_max_area.width;
2686 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
2687 0, self->pre_max_area.height);
2689 /* pick some fallbacks... */
2690 x = a->x + a->width / 4;
2694 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
2695 if (self->pre_max_area.height > 0) {
2696 y = self->pre_max_area.y;
2697 h = self->pre_max_area.height;
2699 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
2700 self->pre_max_area.width, 0);
2702 /* pick some fallbacks... */
2703 y = a->y + a->height / 4;
2709 if (dir == 0 || dir == 1) /* horz */
2710 self->max_horz = max;
2711 if (dir == 0 || dir == 2) /* vert */
2712 self->max_vert = max;
2714 client_change_state(self); /* change the state hints on the client */
2716 client_setup_decor_and_functions(self);
2718 client_move_resize(self, x, y, w, h);
2721 void client_shade(ObClient *self, gboolean shade)
2723 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
2724 shade) || /* can't shade */
2725 self->shaded == shade) return; /* already done */
2727 self->shaded = shade;
2728 client_change_state(self);
2729 client_change_wm_state(self); /* the window is being hidden/shown */
2730 /* resize the frame to just the titlebar */
2731 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
2734 void client_close(ObClient *self)
2738 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
2740 /* in the case that the client provides no means to requesting that it
2741 close, we just kill it */
2742 if (!self->delete_window)
2746 XXX: itd be cool to do timeouts and shit here for killing the client's
2748 like... if the window is around after 5 seconds, then the close button
2749 turns a nice red, and if this function is called again, the client is
2753 ce.xclient.type = ClientMessage;
2754 ce.xclient.message_type = prop_atoms.wm_protocols;
2755 ce.xclient.display = ob_display;
2756 ce.xclient.window = self->window;
2757 ce.xclient.format = 32;
2758 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
2759 ce.xclient.data.l[1] = event_curtime;
2760 ce.xclient.data.l[2] = 0l;
2761 ce.xclient.data.l[3] = 0l;
2762 ce.xclient.data.l[4] = 0l;
2763 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
2766 void client_kill(ObClient *self)
2768 XKillClient(ob_display, self->window);
2771 void client_hilite(ObClient *self, gboolean hilite)
2773 if (self->demands_attention == hilite)
2774 return; /* no change */
2776 /* don't allow focused windows to hilite */
2777 self->demands_attention = hilite && !client_focused(self);
2778 if (self->demands_attention)
2779 frame_flash_start(self->frame);
2781 frame_flash_stop(self->frame);
2782 client_change_state(self);
2785 void client_set_desktop_recursive(ObClient *self,
2786 guint target, gboolean donthide)
2791 if (target != self->desktop) {
2793 ob_debug("Setting desktop %u\n", target+1);
2795 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
2797 /* remove from the old desktop(s) */
2798 focus_order_remove(self);
2800 old = self->desktop;
2801 self->desktop = target;
2802 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
2803 /* the frame can display the current desktop state */
2804 frame_adjust_state(self->frame);
2805 /* 'move' the window to the new desktop */
2807 client_showhide(self);
2808 /* raise if it was not already on the desktop */
2809 if (old != DESKTOP_ALL)
2811 if (STRUT_EXISTS(self->strut))
2812 screen_update_areas();
2814 /* add to the new desktop(s) */
2815 if (config_focus_new)
2816 focus_order_to_top(self);
2818 focus_order_to_bottom(self);
2821 /* move all transients */
2822 for (it = self->transients; it; it = g_slist_next(it))
2823 if (it->data != self)
2824 if (client_is_direct_child(self, it->data))
2825 client_set_desktop_recursive(it->data, target, donthide);
2828 void client_set_desktop(ObClient *self, guint target, gboolean donthide)
2830 self = client_search_top_parent(self);
2831 client_set_desktop_recursive(self, target, donthide);
2834 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
2836 while (child != parent &&
2837 child->transient_for && child->transient_for != OB_TRAN_GROUP)
2838 child = child->transient_for;
2839 return child == parent;
2842 ObClient *client_search_modal_child(ObClient *self)
2847 for (it = self->transients; it; it = g_slist_next(it)) {
2848 ObClient *c = it->data;
2849 if ((ret = client_search_modal_child(c))) return ret;
2850 if (c->modal) return c;
2855 gboolean client_validate(ObClient *self)
2859 XSync(ob_display, FALSE); /* get all events on the server */
2861 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
2862 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
2863 XPutBackEvent(ob_display, &e);
2870 void client_set_wm_state(ObClient *self, glong state)
2872 if (state == self->wmstate) return; /* no change */
2876 client_iconify(self, TRUE, TRUE);
2879 client_iconify(self, FALSE, TRUE);
2884 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
2886 gboolean shaded = self->shaded;
2887 gboolean fullscreen = self->fullscreen;
2888 gboolean undecorated = self->undecorated;
2889 gboolean max_horz = self->max_horz;
2890 gboolean max_vert = self->max_vert;
2891 gboolean modal = self->modal;
2892 gboolean iconic = self->iconic;
2893 gboolean demands_attention = self->demands_attention;
2896 if (!(action == prop_atoms.net_wm_state_add ||
2897 action == prop_atoms.net_wm_state_remove ||
2898 action == prop_atoms.net_wm_state_toggle))
2899 /* an invalid action was passed to the client message, ignore it */
2902 for (i = 0; i < 2; ++i) {
2903 Atom state = i == 0 ? data1 : data2;
2905 if (!state) continue;
2907 /* if toggling, then pick whether we're adding or removing */
2908 if (action == prop_atoms.net_wm_state_toggle) {
2909 if (state == prop_atoms.net_wm_state_modal)
2910 action = modal ? prop_atoms.net_wm_state_remove :
2911 prop_atoms.net_wm_state_add;
2912 else if (state == prop_atoms.net_wm_state_maximized_vert)
2913 action = self->max_vert ? prop_atoms.net_wm_state_remove :
2914 prop_atoms.net_wm_state_add;
2915 else if (state == prop_atoms.net_wm_state_maximized_horz)
2916 action = self->max_horz ? prop_atoms.net_wm_state_remove :
2917 prop_atoms.net_wm_state_add;
2918 else if (state == prop_atoms.net_wm_state_shaded)
2919 action = shaded ? prop_atoms.net_wm_state_remove :
2920 prop_atoms.net_wm_state_add;
2921 else if (state == prop_atoms.net_wm_state_skip_taskbar)
2922 action = self->skip_taskbar ?
2923 prop_atoms.net_wm_state_remove :
2924 prop_atoms.net_wm_state_add;
2925 else if (state == prop_atoms.net_wm_state_skip_pager)
2926 action = self->skip_pager ?
2927 prop_atoms.net_wm_state_remove :
2928 prop_atoms.net_wm_state_add;
2929 else if (state == prop_atoms.net_wm_state_hidden)
2930 action = self->iconic ?
2931 prop_atoms.net_wm_state_remove :
2932 prop_atoms.net_wm_state_add;
2933 else if (state == prop_atoms.net_wm_state_fullscreen)
2934 action = fullscreen ?
2935 prop_atoms.net_wm_state_remove :
2936 prop_atoms.net_wm_state_add;
2937 else if (state == prop_atoms.net_wm_state_above)
2938 action = self->above ? prop_atoms.net_wm_state_remove :
2939 prop_atoms.net_wm_state_add;
2940 else if (state == prop_atoms.net_wm_state_below)
2941 action = self->below ? prop_atoms.net_wm_state_remove :
2942 prop_atoms.net_wm_state_add;
2943 else if (state == prop_atoms.net_wm_state_demands_attention)
2944 action = self->demands_attention ?
2945 prop_atoms.net_wm_state_remove :
2946 prop_atoms.net_wm_state_add;
2947 else if (state == prop_atoms.ob_wm_state_undecorated)
2948 action = undecorated ? prop_atoms.net_wm_state_remove :
2949 prop_atoms.net_wm_state_add;
2952 if (action == prop_atoms.net_wm_state_add) {
2953 if (state == prop_atoms.net_wm_state_modal) {
2955 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2957 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2959 } else if (state == prop_atoms.net_wm_state_shaded) {
2961 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2962 self->skip_taskbar = TRUE;
2963 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2964 self->skip_pager = TRUE;
2965 } else if (state == prop_atoms.net_wm_state_hidden) {
2967 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2969 } else if (state == prop_atoms.net_wm_state_above) {
2971 self->below = FALSE;
2972 } else if (state == prop_atoms.net_wm_state_below) {
2973 self->above = FALSE;
2975 } else if (state == prop_atoms.net_wm_state_demands_attention) {
2976 demands_attention = TRUE;
2977 } else if (state == prop_atoms.ob_wm_state_undecorated) {
2981 } else { /* action == prop_atoms.net_wm_state_remove */
2982 if (state == prop_atoms.net_wm_state_modal) {
2984 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
2986 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
2988 } else if (state == prop_atoms.net_wm_state_shaded) {
2990 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
2991 self->skip_taskbar = FALSE;
2992 } else if (state == prop_atoms.net_wm_state_skip_pager) {
2993 self->skip_pager = FALSE;
2994 } else if (state == prop_atoms.net_wm_state_hidden) {
2996 } else if (state == prop_atoms.net_wm_state_fullscreen) {
2998 } else if (state == prop_atoms.net_wm_state_above) {
2999 self->above = FALSE;
3000 } else if (state == prop_atoms.net_wm_state_below) {
3001 self->below = FALSE;
3002 } else if (state == prop_atoms.net_wm_state_demands_attention) {
3003 demands_attention = FALSE;
3004 } else if (state == prop_atoms.ob_wm_state_undecorated) {
3005 undecorated = FALSE;
3009 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3010 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3012 if (max_horz == max_vert) { /* both going the same way */
3013 client_maximize(self, max_horz, 0);
3015 client_maximize(self, max_horz, 1);
3016 client_maximize(self, max_vert, 2);
3020 if (max_horz != self->max_horz)
3021 client_maximize(self, max_horz, 1);
3023 client_maximize(self, max_vert, 2);
3026 /* change fullscreen state before shading, as it will affect if the window
3028 if (fullscreen != self->fullscreen)
3029 client_fullscreen(self, fullscreen);
3030 if (shaded != self->shaded)
3031 client_shade(self, shaded);
3032 if (undecorated != self->undecorated)
3033 client_set_undecorated(self, undecorated);
3034 if (modal != self->modal) {
3035 self->modal = modal;
3036 /* when a window changes modality, then its stacking order with its
3037 transients needs to change */
3040 if (iconic != self->iconic)
3041 client_iconify(self, iconic, FALSE);
3043 if (demands_attention != self->demands_attention)
3044 client_hilite(self, demands_attention);
3046 client_change_state(self); /* change the hint to reflect these changes */
3049 ObClient *client_focus_target(ObClient *self)
3051 ObClient *child = NULL;
3053 child = client_search_modal_child(self);
3054 if (child) return child;
3058 gboolean client_can_focus(ObClient *self)
3062 /* choose the correct target */
3063 self = client_focus_target(self);
3065 if (!self->frame->visible)
3068 if (!(self->can_focus || self->focus_notify))
3071 /* do a check to see if the window has already been unmapped or destroyed
3072 do this intelligently while watching out for unmaps we've generated
3073 (ignore_unmaps > 0) */
3074 if (XCheckTypedWindowEvent(ob_display, self->window,
3075 DestroyNotify, &ev)) {
3076 XPutBackEvent(ob_display, &ev);
3079 while (XCheckTypedWindowEvent(ob_display, self->window,
3080 UnmapNotify, &ev)) {
3081 if (self->ignore_unmaps) {
3082 self->ignore_unmaps--;
3084 XPutBackEvent(ob_display, &ev);
3092 gboolean client_focus(ObClient *self)
3094 /* choose the correct target */
3095 self = client_focus_target(self);
3097 if (!client_can_focus(self)) {
3098 if (!self->frame->visible) {
3099 /* update the focus lists */
3100 focus_order_to_top(self);
3105 ob_debug_type(OB_DEBUG_FOCUS,
3106 "Focusing client \"%s\" at time %u\n",
3107 self->title, event_curtime);
3109 if (self->can_focus) {
3110 /* This can cause a BadMatch error with CurrentTime, or if an app
3111 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3112 xerror_set_ignore(TRUE);
3113 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
3115 xerror_set_ignore(FALSE);
3118 if (self->focus_notify) {
3120 ce.xclient.type = ClientMessage;
3121 ce.xclient.message_type = prop_atoms.wm_protocols;
3122 ce.xclient.display = ob_display;
3123 ce.xclient.window = self->window;
3124 ce.xclient.format = 32;
3125 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
3126 ce.xclient.data.l[1] = event_curtime;
3127 ce.xclient.data.l[2] = 0l;
3128 ce.xclient.data.l[3] = 0l;
3129 ce.xclient.data.l[4] = 0l;
3130 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
3134 ob_debug("%sively focusing %lx at %d\n",
3135 (self->can_focus ? "act" : "pass"),
3136 self->window, (gint) event_curtime);
3139 /* Cause the FocusIn to come back to us. Important for desktop switches,
3140 since otherwise we'll have no FocusIn on the queue and send it off to
3141 the focus_backup. */
3142 XSync(ob_display, FALSE);
3146 void client_activate(ObClient *self, gboolean here, gboolean user)
3148 guint32 last_time = focus_client ? focus_client->user_time : CurrentTime;
3150 /* XXX do some stuff here if user is false to determine if we really want
3151 to activate it or not (a parent or group member is currently
3154 ob_debug_type(OB_DEBUG_FOCUS,
3155 "Want to activate window 0x%x with time %u (last time %u), "
3157 self->window, event_curtime, last_time,
3158 (user ? "user" : "application"));
3160 if (!user && event_curtime && last_time &&
3161 !event_time_after(event_curtime, last_time))
3163 client_hilite(self, TRUE);
3165 if (event_curtime != CurrentTime)
3166 self->user_time = event_curtime;
3168 /* if using focus_delay, stop the timer now so that focus doesn't
3170 event_halt_focus_delay();
3172 if (client_normal(self) && screen_showing_desktop)
3173 screen_show_desktop(FALSE);
3175 client_iconify(self, FALSE, here);
3176 if (self->desktop != DESKTOP_ALL &&
3177 self->desktop != screen_desktop) {
3179 client_set_desktop(self, screen_desktop, FALSE);
3181 screen_set_desktop(self->desktop);
3182 } else if (!self->frame->visible)
3183 /* if its not visible for other reasons, then don't mess
3187 client_shade(self, FALSE);
3191 /* we do this as an action here. this is rather important. this is
3192 because we want the results from the focus change to take place
3193 BEFORE we go about raising the window. when a fullscreen window
3194 loses focus, we need this or else the raise wont be able to raise
3195 above the to-lose-focus fullscreen window. */
3200 void client_raise(ObClient *self)
3202 action_run_string("Raise", self, CurrentTime);
3205 void client_lower(ObClient *self)
3207 action_run_string("Lower", self, CurrentTime);
3210 gboolean client_focused(ObClient *self)
3212 return self == focus_client;
3215 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
3218 /* si is the smallest image >= req */
3219 /* li is the largest image < req */
3220 gulong size, smallest = 0xffffffff, largest = 0, si = 0, li = 0;
3222 if (!self->nicons) {
3223 ObClientIcon *parent = NULL;
3225 if (self->transient_for) {
3226 if (self->transient_for != OB_TRAN_GROUP)
3227 parent = client_icon_recursive(self->transient_for, w, h);
3230 for (it = self->group->members; it; it = g_slist_next(it)) {
3231 ObClient *c = it->data;
3232 if (c != self && !c->transient_for) {
3233 if ((parent = client_icon_recursive(c, w, h)))
3243 for (i = 0; i < self->nicons; ++i) {
3244 size = self->icons[i].width * self->icons[i].height;
3245 if (size < smallest && size >= (unsigned)(w * h)) {
3249 if (size > largest && size <= (unsigned)(w * h)) {
3254 if (largest == 0) /* didnt find one smaller than the requested size */
3255 return &self->icons[si];
3256 return &self->icons[li];
3259 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
3262 static ObClientIcon deficon;
3264 if (!(ret = client_icon_recursive(self, w, h))) {
3265 deficon.width = deficon.height = 48;
3266 deficon.data = ob_rr_theme->def_win_icon;
3272 void client_set_layer(ObClient *self, gint layer)
3276 self->above = FALSE;
3277 } else if (layer == 0) {
3278 self->below = self->above = FALSE;
3280 self->below = FALSE;
3283 client_calc_layer(self);
3284 client_change_state(self); /* reflect this in the state hints */
3287 void client_set_undecorated(ObClient *self, gboolean undecorated)
3289 if (self->undecorated != undecorated) {
3290 self->undecorated = undecorated;
3291 client_setup_decor_and_functions(self);
3292 /* Make sure the client knows it might have moved. Maybe there is a
3293 * better way of doing this so only one client_configure is sent, but
3294 * since 125 of these are sent per second when moving the window (with
3295 * user = FALSE) i doubt it matters much.
3297 client_configure(self, self->area.x, self->area.y,
3298 self->area.width, self->area.height, TRUE, TRUE);
3299 client_change_state(self); /* reflect this in the state hints */
3303 guint client_monitor(ObClient *self)
3305 return screen_find_monitor(&self->frame->area);
3308 ObClient *client_search_top_parent(ObClient *self)
3310 while (self->transient_for && self->transient_for != OB_TRAN_GROUP &&
3311 client_normal(self))
3312 self = self->transient_for;
3316 GSList *client_search_all_top_parents(ObClient *self)
3320 /* move up the direct transient chain as far as possible */
3321 while (self->transient_for && self->transient_for != OB_TRAN_GROUP)
3322 self = self->transient_for;
3324 if (!self->transient_for)
3325 ret = g_slist_prepend(ret, self);
3329 g_assert(self->group);
3331 for (it = self->group->members; it; it = g_slist_next(it)) {
3332 ObClient *c = it->data;
3334 if (!c->transient_for && client_normal(c))
3335 ret = g_slist_prepend(ret, c);
3338 if (ret == NULL) /* no group parents */
3339 ret = g_slist_prepend(ret, self);
3345 ObClient *client_search_focus_parent(ObClient *self)
3347 if (self->transient_for) {
3348 if (self->transient_for != OB_TRAN_GROUP) {
3349 if (client_focused(self->transient_for))
3350 return self->transient_for;
3354 for (it = self->group->members; it; it = g_slist_next(it)) {
3355 ObClient *c = it->data;
3357 /* checking transient_for prevents infinate loops! */
3358 if (c != self && !c->transient_for)
3359 if (client_focused(c))
3368 ObClient *client_search_parent(ObClient *self, ObClient *search)
3370 if (self->transient_for) {
3371 if (self->transient_for != OB_TRAN_GROUP) {
3372 if (self->transient_for == search)
3377 for (it = self->group->members; it; it = g_slist_next(it)) {
3378 ObClient *c = it->data;
3380 /* checking transient_for prevents infinate loops! */
3381 if (c != self && !c->transient_for)
3391 ObClient *client_search_transient(ObClient *self, ObClient *search)
3395 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
3396 if (sit->data == search)
3398 if (client_search_transient(sit->data, search))
3404 void client_update_sm_client_id(ObClient *self)
3406 g_free(self->sm_client_id);
3407 self->sm_client_id = NULL;
3409 if (!PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id) &&
3411 PROP_GETS(self->group->leader, sm_client_id, locale,
3412 &self->sm_client_id);
3415 #define WANT_EDGE(cur, c) \
3418 if(!client_normal(cur)) \
3420 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3424 if(cur->layer < c->layer && !config_resist_layers_below) \
3427 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3428 if ((his_edge_start >= my_edge_start && \
3429 his_edge_start <= my_edge_end) || \
3430 (my_edge_start >= his_edge_start && \
3431 my_edge_start <= his_edge_end)) \
3434 /* finds the nearest edge in the given direction from the current client
3435 * note to self: the edge is the -frame- edge (the actual one), not the
3438 gint client_directional_edge_search(ObClient *c, ObDirection dir, gboolean hang)
3440 gint dest, monitor_dest;
3441 gint my_edge_start, my_edge_end, my_offset;
3448 a = screen_area(c->desktop);
3449 monitor = screen_area_monitor(c->desktop, client_monitor(c));
3452 case OB_DIRECTION_NORTH:
3453 my_edge_start = c->frame->area.x;
3454 my_edge_end = c->frame->area.x + c->frame->area.width;
3455 my_offset = c->frame->area.y + (hang ? c->frame->area.height : 0);
3457 /* default: top of screen */
3458 dest = a->y + (hang ? c->frame->area.height : 0);
3459 monitor_dest = monitor->y + (hang ? c->frame->area.height : 0);
3460 /* if the monitor edge comes before the screen edge, */
3461 /* use that as the destination instead. (For xinerama) */
3462 if (monitor_dest != dest && my_offset > monitor_dest)
3463 dest = monitor_dest;
3465 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3466 gint his_edge_start, his_edge_end, his_offset;
3467 ObClient *cur = it->data;
3471 his_edge_start = cur->frame->area.x;
3472 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3473 his_offset = cur->frame->area.y +
3474 (hang ? 0 : cur->frame->area.height);
3476 if(his_offset + 1 > my_offset)
3479 if(his_offset < dest)
3482 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3485 case OB_DIRECTION_SOUTH:
3486 my_edge_start = c->frame->area.x;
3487 my_edge_end = c->frame->area.x + c->frame->area.width;
3488 my_offset = c->frame->area.y + (hang ? 0 : c->frame->area.height);
3490 /* default: bottom of screen */
3491 dest = a->y + a->height - (hang ? c->frame->area.height : 0);
3492 monitor_dest = monitor->y + monitor->height -
3493 (hang ? c->frame->area.height : 0);
3494 /* if the monitor edge comes before the screen edge, */
3495 /* use that as the destination instead. (For xinerama) */
3496 if (monitor_dest != dest && my_offset < monitor_dest)
3497 dest = monitor_dest;
3499 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3500 gint his_edge_start, his_edge_end, his_offset;
3501 ObClient *cur = it->data;
3505 his_edge_start = cur->frame->area.x;
3506 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3507 his_offset = cur->frame->area.y +
3508 (hang ? cur->frame->area.height : 0);
3511 if(his_offset - 1 < my_offset)
3514 if(his_offset > dest)
3517 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3520 case OB_DIRECTION_WEST:
3521 my_edge_start = c->frame->area.y;
3522 my_edge_end = c->frame->area.y + c->frame->area.height;
3523 my_offset = c->frame->area.x + (hang ? c->frame->area.width : 0);
3525 /* default: leftmost egde of screen */
3526 dest = a->x + (hang ? c->frame->area.width : 0);
3527 monitor_dest = monitor->x + (hang ? c->frame->area.width : 0);
3528 /* if the monitor edge comes before the screen edge, */
3529 /* use that as the destination instead. (For xinerama) */
3530 if (monitor_dest != dest && my_offset > monitor_dest)
3531 dest = monitor_dest;
3533 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3534 gint his_edge_start, his_edge_end, his_offset;
3535 ObClient *cur = it->data;
3539 his_edge_start = cur->frame->area.y;
3540 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3541 his_offset = cur->frame->area.x +
3542 (hang ? 0 : cur->frame->area.width);
3544 if(his_offset + 1 > my_offset)
3547 if(his_offset < dest)
3550 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3553 case OB_DIRECTION_EAST:
3554 my_edge_start = c->frame->area.y;
3555 my_edge_end = c->frame->area.y + c->frame->area.height;
3556 my_offset = c->frame->area.x + (hang ? 0 : c->frame->area.width);
3558 /* default: rightmost edge of screen */
3559 dest = a->x + a->width - (hang ? c->frame->area.width : 0);
3560 monitor_dest = monitor->x + monitor->width -
3561 (hang ? c->frame->area.width : 0);
3562 /* if the monitor edge comes before the screen edge, */
3563 /* use that as the destination instead. (For xinerama) */
3564 if (monitor_dest != dest && my_offset < monitor_dest)
3565 dest = monitor_dest;
3567 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3568 gint his_edge_start, his_edge_end, his_offset;
3569 ObClient *cur = it->data;
3573 his_edge_start = cur->frame->area.y;
3574 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3575 his_offset = cur->frame->area.x +
3576 (hang ? cur->frame->area.width : 0);
3578 if(his_offset - 1 < my_offset)
3581 if(his_offset > dest)
3584 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3587 case OB_DIRECTION_NORTHEAST:
3588 case OB_DIRECTION_SOUTHEAST:
3589 case OB_DIRECTION_NORTHWEST:
3590 case OB_DIRECTION_SOUTHWEST:
3591 /* not implemented */
3593 g_assert_not_reached();
3594 dest = 0; /* suppress warning */
3599 ObClient* client_under_pointer()
3603 ObClient *ret = NULL;
3605 if (screen_pointer_pos(&x, &y)) {
3606 for (it = stacking_list; it; it = g_list_next(it)) {
3607 if (WINDOW_IS_CLIENT(it->data)) {
3608 ObClient *c = WINDOW_AS_CLIENT(it->data);
3609 if (c->frame->visible &&
3610 RECT_CONTAINS(c->frame->area, x, y)) {
3620 gboolean client_has_group_siblings(ObClient *self)
3622 return self->group && self->group->members->next;