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"
40 #include "menuframe.h"
43 #include "render/render.h"
50 #include <X11/Xutil.h>
52 /*! The event mask to grab on client windows */
53 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
56 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
61 ObClientCallback func;
65 GList *client_list = NULL;
67 static GSList *client_destroy_notifies = NULL;
69 static void client_get_all(ObClient *self, gboolean real);
70 static void client_get_startup_id(ObClient *self);
71 static void client_get_session_ids(ObClient *self);
72 static void client_get_area(ObClient *self);
73 static void client_get_desktop(ObClient *self);
74 static void client_get_state(ObClient *self);
75 static void client_get_shaped(ObClient *self);
76 static void client_get_mwm_hints(ObClient *self);
77 static void client_get_colormap(ObClient *self);
78 static void client_change_allowed_actions(ObClient *self);
79 static void client_change_state(ObClient *self);
80 static void client_change_wm_state(ObClient *self);
81 static void client_apply_startup_state(ObClient *self,
82 gint x, gint y, gint w, gint h);
83 static void client_restore_session_state(ObClient *self);
84 static gboolean client_restore_session_stacking(ObClient *self);
85 static ObAppSettings *client_get_settings_state(ObClient *self);
86 static void client_update_transient_tree(ObClient *self,
87 ObGroup *oldgroup, ObGroup *newgroup,
90 static void client_present(ObClient *self, gboolean here, gboolean raise);
91 static GSList *client_search_all_top_parents_internal(ObClient *self,
93 ObStackingLayer layer);
94 static void client_call_notifies(ObClient *self, GSList *list);
96 void client_startup(gboolean reconfig)
103 void client_shutdown(gboolean reconfig)
105 if (reconfig) return;
108 static void client_call_notifies(ObClient *self, GSList *list)
112 for (it = list; it; it = g_slist_next(it)) {
113 ClientCallback *d = it->data;
114 d->func(self, d->data);
118 void client_add_destroy_notify(ObClientCallback func, gpointer data)
120 ClientCallback *d = g_new(ClientCallback, 1);
123 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
126 void client_remove_destroy_notify(ObClientCallback func)
130 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
131 ClientCallback *d = it->data;
132 if (d->func == func) {
134 client_destroy_notifies =
135 g_slist_delete_link(client_destroy_notifies, it);
141 void client_set_list()
143 Window *windows, *win_it;
145 guint size = g_list_length(client_list);
147 /* create an array of the window ids */
149 windows = g_new(Window, size);
151 for (it = client_list; it; it = g_list_next(it), ++win_it)
152 *win_it = ((ObClient*)it->data)->window;
156 PROP_SETA32(RootWindow(ob_display, ob_screen),
157 net_client_list, window, (gulong*)windows, size);
166 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
170 for (it = self->transients; it; it = g_slist_next(it)) {
171 if (!func(it->data, data)) return;
172 client_foreach_transient(it->data, func, data);
176 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
178 if (self->transient_for) {
179 if (self->transient_for != OB_TRAN_GROUP) {
180 if (!func(self->transient_for, data)) return;
181 client_foreach_ancestor(self->transient_for, func, data);
185 for (it = self->group->members; it; it = g_slist_next(it))
186 if (it->data != self &&
187 !((ObClient*)it->data)->transient_for) {
188 if (!func(it->data, data)) return;
189 client_foreach_ancestor(it->data, func, data);
196 void client_manage_all()
201 XWindowAttributes attrib;
203 XQueryTree(ob_display, RootWindow(ob_display, ob_screen),
204 &w, &w, &children, &nchild);
206 /* remove all icon windows from the list */
207 for (i = 0; i < nchild; i++) {
208 if (children[i] == None) continue;
209 wmhints = XGetWMHints(ob_display, children[i]);
211 if ((wmhints->flags & IconWindowHint) &&
212 (wmhints->icon_window != children[i]))
213 for (j = 0; j < nchild; j++)
214 if (children[j] == wmhints->icon_window) {
222 for (i = 0; i < nchild; ++i) {
223 if (children[i] == None)
225 if (XGetWindowAttributes(ob_display, children[i], &attrib)) {
226 if (attrib.override_redirect) continue;
228 if (attrib.map_state != IsUnmapped)
229 client_manage(children[i]);
235 void client_manage(Window window)
239 XWindowAttributes attrib;
240 XSetWindowAttributes attrib_set;
242 gboolean activate = FALSE;
243 ObAppSettings *settings;
244 gint placex, placey, placew, placeh;
245 gboolean transient = FALSE;
249 /* check if it has already been unmapped by the time we started
250 mapping. the grab does a sync so we don't have to here */
251 if (XCheckTypedWindowEvent(ob_display, window, DestroyNotify, &e) ||
252 XCheckTypedWindowEvent(ob_display, window, UnmapNotify, &e))
254 XPutBackEvent(ob_display, &e);
256 ob_debug("Trying to manage unmapped window. Aborting that.\n");
258 return; /* don't manage it */
261 /* make sure it isn't an override-redirect window */
262 if (!XGetWindowAttributes(ob_display, window, &attrib) ||
263 attrib.override_redirect)
266 return; /* don't manage it */
269 /* is the window a docking app */
270 if ((wmhint = XGetWMHints(ob_display, window))) {
271 if ((wmhint->flags & StateHint) &&
272 wmhint->initial_state == WithdrawnState)
274 dock_add(window, wmhint);
282 ob_debug("Managing window: 0x%lx\n", window);
284 /* choose the events we want to receive on the CLIENT window */
285 attrib_set.event_mask = CLIENT_EVENTMASK;
286 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
287 XChangeWindowAttributes(ob_display, window,
288 CWEventMask|CWDontPropagate, &attrib_set);
290 /* create the ObClient struct, and populate it from the hints on the
292 self = g_new0(ObClient, 1);
293 self->obwin.type = Window_Client;
294 self->window = window;
296 /* non-zero defaults */
297 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
298 self->gravity = NorthWestGravity;
299 self->desktop = screen_num_desktops; /* always an invalid value */
300 self->user_time = focus_client ? focus_client->user_time : CurrentTime;
302 /* get all the stuff off the window */
303 client_get_all(self, TRUE);
305 /* specify that if we exit, the window should not be destroyed and
306 should be reparented back to root automatically */
307 XChangeSaveSet(ob_display, window, SetModeInsert);
309 /* create the decoration frame for the client window */
310 self->frame = frame_new(self);
312 frame_grab_client(self->frame);
314 /* we've grabbed everything and set everything that we need to at mapping
318 /* per-app settings override stuff from client_get_all, and return the
319 settings for other uses too. the returned settings is a shallow copy,
320 that needs to be freed with g_free(). */
321 settings = client_get_settings_state(self);
322 /* the session should get the last say thought */
323 client_restore_session_state(self);
325 /* now we have all of the window's information so we can set this up */
326 client_setup_decor_and_functions(self, FALSE);
329 Time t = sn_app_started(self->startup_id, self->class);
330 if (t) self->user_time = t;
333 /* do this after we have a frame.. it uses the frame to help determine the
334 WM_STATE to apply. */
335 client_change_state(self);
337 /* add ourselves to the focus order */
338 focus_order_add_new(self);
340 /* do this to add ourselves to the stacking list in a non-intrusive way */
341 client_calc_layer(self);
343 /* focus the new window? */
344 if (ob_state() != OB_STATE_STARTING &&
345 (!self->session || self->session->focused) &&
347 /* this means focus=true for window is same as config_focus_new=true */
348 ((config_focus_new || (settings && settings->focus == 1)) ||
349 client_search_focus_tree_full(self)) &&
350 /* this checks for focus=false for the window */
351 (!settings || settings->focus != 0) &&
352 /* note the check against Type_Normal/Dialog, not client_normal(self),
353 which would also include other types. in this case we want more
354 strict rules for focus */
355 (self->type == OB_CLIENT_TYPE_NORMAL ||
356 self->type == OB_CLIENT_TYPE_DIALOG))
361 /* remove the client's border */
362 XSetWindowBorderWidth(ob_display, self->window, 0);
364 /* adjust the frame to the client's size before showing or placing
366 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
367 frame_adjust_client_area(self->frame);
369 /* where the frame was placed is where the window was originally */
370 placex = self->area.x;
371 placey = self->area.y;
372 placew = self->area.width;
373 placeh = self->area.height;
375 /* figure out placement for the window if the window is new */
376 if (ob_state() == OB_STATE_RUNNING) {
377 ob_debug("Positioned: %s @ %d %d\n",
378 (!self->positioned ? "no" :
379 (self->positioned == PPosition ? "program specified" :
380 (self->positioned == USPosition ? "user specified" :
381 (self->positioned == (PPosition | USPosition) ?
382 "program + user specified" :
383 "BADNESS !?")))), placex, placey);
385 ob_debug("Sized: %s @ %d %d\n",
386 (!self->sized ? "no" :
387 (self->sized == PSize ? "program specified" :
388 (self->sized == USSize ? "user specified" :
389 (self->sized == (PSize | USSize) ?
390 "program + user specified" :
391 "BADNESS !?")))), placew, placeh);
393 /* splash screens are also returned as TRUE for transient,
394 and so will be forced on screen below */
395 transient = place_client(self, &placex, &placey, settings);
397 /* make sure the window is visible. */
398 client_find_onscreen(self, &placex, &placey, placew, placeh,
399 /* non-normal clients has less rules, and
400 windows that are being restored from a
401 session do also. we can assume you want
402 it back where you saved it. Clients saying
403 they placed themselves are subjected to
404 harder rules, ones that are placed by
405 place.c or by the user are allowed partially
406 off-screen and on xinerama divides (ie,
407 it is up to the placement routines to avoid
408 the xinerama divides)
410 splash screens get "transient" set to TRUE by
411 the place_client call
414 (!(self->positioned & USPosition) &&
415 client_normal(self) &&
419 /* if the window isn't user-sized, then make it fit inside
420 the visible screen area on its monitor. Use basically the same rules
421 for forcing the window on screen in the client_find_onscreen call.
423 do this after place_client, it chooses the monitor!
425 splash screens get "transient" set to TRUE by
426 the place_client call
429 (!(self->sized & USSize) &&
430 client_normal(self) &&
433 /* make a copy to modify */
434 Rect a = *screen_area_monitor(self->desktop, client_monitor(self));
436 /* shrink by the frame's area */
437 a.width -= self->frame->size.left + self->frame->size.right;
438 a.height -= self->frame->size.top + self->frame->size.bottom;
440 /* fit the window inside the area */
441 if (placew > a.width || self->area.height > a.height) {
442 placew = MIN(self->area.width, a.width);
443 placeh = MIN(self->area.height, a.height);
445 ob_debug("setting window size to %dx%d\n",
446 self->area.width, self->area.height);
451 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
452 "some restrictions may apply\n",
453 self->window, placex, placey, placew, placeh);
455 ob_debug(" but session requested %d, %d %d x %d instead, "
457 self->session->x, self->session->y,
458 self->session->w, self->session->h);
460 /* do this after the window is placed, so the premax/prefullscreen numbers
463 this also places the window
465 client_apply_startup_state(self, placex, placey, placew, placeh);
468 guint32 last_time = focus_client ?
469 focus_client->user_time : CurrentTime;
471 /* This is focus stealing prevention */
472 ob_debug_type(OB_DEBUG_FOCUS,
473 "Want to focus new window 0x%x with time %u "
475 self->window, self->user_time, last_time);
477 /* if it's on another desktop */
478 if (!(self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
479 && /* the timestamp is from before you changed desktops */
480 self->user_time && screen_desktop_user_time &&
481 !event_time_after(self->user_time, screen_desktop_user_time))
484 ob_debug_type(OB_DEBUG_FOCUS,
485 "Not focusing the window because its on another "
488 /* If something is focused, and it's not our relative... */
489 else if (focus_client && client_search_focus_tree_full(self) == NULL)
491 /* If time stamp is old, don't steal focus */
492 if (self->user_time && last_time &&
493 !event_time_after(self->user_time, last_time))
496 ob_debug_type(OB_DEBUG_FOCUS,
497 "Not focusing the window because the time is "
500 /* If its a transient (and parents aren't focused) and the time
501 is ambiguous (either the current focus target doesn't have
502 a timestamp, or they are the same (we probably inherited it
504 else if (client_has_parent(self) &&
505 (!last_time || self->user_time == last_time))
508 ob_debug_type(OB_DEBUG_FOCUS,
509 "Not focusing the window because it is a "
510 "transient, and the time is very ambiguous\n");
512 /* Don't steal focus from globally active clients.
513 I stole this idea from KWin. It seems nice.
515 else if (!(focus_client->can_focus ||
516 focus_client->focus_notify))
519 ob_debug_type(OB_DEBUG_FOCUS,
520 "Not focusing the window because a globally "
521 "active client has focus\n");
523 /* Don't move focus if it's not going to go to this window
525 else if (client_focus_target(self) != self) {
527 ob_debug_type(OB_DEBUG_FOCUS,
528 "Not focusing the window because another window "
529 "would get the focus anyway\n");
534 ob_debug_type(OB_DEBUG_FOCUS,
535 "Focus stealing prevention activated for %s with "
536 "time %u (last time %u)\n",
537 self->title, self->user_time, last_time);
538 /* if the client isn't focused, then hilite it so the user
540 client_hilite(self, TRUE);
544 /* This may look rather odd. Well it's because new windows are added
545 to the stacking order non-intrusively. If we're not going to focus
546 the new window or hilite it, then we raise it to the top. This will
547 take affect for things that don't get focused like splash screens.
548 Also if you don't have focus_new enabled, then it's going to get
549 raised to the top. Legacy begets legacy I guess?
551 if (!client_restore_session_stacking(self))
552 stacking_raise(CLIENT_AS_WINDOW(self));
555 mouse_grab_for_client(self, TRUE);
557 /* this has to happen before we try focus the window, but we want it to
558 happen after the client's stacking has been determined or it looks bad
563 gboolean stacked = client_restore_session_stacking(self);
564 client_present(self, FALSE, !stacked);
567 /* add to client list/map */
568 client_list = g_list_append(client_list, self);
569 g_hash_table_insert(window_map, &self->window, self);
571 /* this has to happen after we're in the client_list */
572 if (STRUT_EXISTS(self->strut))
573 screen_update_areas();
575 /* update the list hints */
578 /* free the ObAppSettings shallow copy */
581 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
582 window, self->frame->window, self->class);
588 ObClient *client_fake_manage(Window window)
591 ObAppSettings *settings;
593 ob_debug("Pretend-managing window: %lx\n", window);
595 /* do this minimal stuff to figure out the client's decorations */
597 self = g_new0(ObClient, 1);
598 self->window = window;
600 client_get_all(self, FALSE);
601 /* per-app settings override stuff, and return the settings for other
602 uses too. this returns a shallow copy that needs to be freed */
603 settings = client_get_settings_state(self);
605 client_setup_decor_and_functions(self, FALSE);
607 /* create the decoration frame for the client window and adjust its size */
608 self->frame = frame_new(self);
609 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
611 ob_debug("gave extents left %d right %d top %d bottom %d\n",
612 self->frame->size.left, self->frame->size.right,
613 self->frame->size.top, self->frame->size.bottom);
615 /* free the ObAppSettings shallow copy */
621 void client_unmanage_all()
623 while (client_list != NULL)
624 client_unmanage(client_list->data);
627 void client_unmanage(ObClient *self)
632 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
633 self->window, self->frame->window,
634 self->class, self->title ? self->title : "");
636 g_assert(self != NULL);
638 /* we dont want events no more. do this before hiding the frame so we
639 don't generate more events */
640 XSelectInput(ob_display, self->window, NoEventMask);
642 frame_hide(self->frame);
643 /* flush to send the hide to the server quickly */
646 /* ignore enter events from the unmap so it doesnt mess with the
648 event_ignore_all_queued_enters();
650 mouse_grab_for_client(self, FALSE);
652 /* remove the window from our save set */
653 XChangeSaveSet(ob_display, self->window, SetModeDelete);
655 /* kill the property windows */
656 propwin_remove(self->user_time_window, OB_PROPWIN_USER_TIME, self);
658 /* update the focus lists */
659 focus_order_remove(self);
660 if (client_focused(self)) {
661 /* don't leave an invalid focus_client */
665 client_list = g_list_remove(client_list, self);
666 stacking_remove(self);
667 g_hash_table_remove(window_map, &self->window);
669 /* once the client is out of the list, update the struts to remove its
671 if (STRUT_EXISTS(self->strut))
672 screen_update_areas();
674 client_call_notifies(self, client_destroy_notifies);
676 /* tell our parent(s) that we're gone */
677 if (self->transient_for == OB_TRAN_GROUP) { /* transient of group */
678 for (it = self->group->members; it; it = g_slist_next(it))
679 if (it->data != self)
680 ((ObClient*)it->data)->transients =
681 g_slist_remove(((ObClient*)it->data)->transients,self);
682 } else if (self->transient_for) { /* transient of window */
683 self->transient_for->transients =
684 g_slist_remove(self->transient_for->transients, self);
687 /* tell our transients that we're gone */
688 for (it = self->transients; it; it = g_slist_next(it)) {
689 if (((ObClient*)it->data)->transient_for != OB_TRAN_GROUP) {
690 ((ObClient*)it->data)->transient_for = NULL;
691 client_calc_layer(it->data);
695 /* remove from its group */
697 group_remove(self->group, self);
701 /* restore the window's original geometry so it is not lost */
707 if (self->fullscreen)
708 a = self->pre_fullscreen_area;
709 else if (self->max_horz || self->max_vert) {
710 if (self->max_horz) {
711 a.x = self->pre_max_area.x;
712 a.width = self->pre_max_area.width;
714 if (self->max_vert) {
715 a.y = self->pre_max_area.y;
716 a.height = self->pre_max_area.height;
720 self->fullscreen = self->max_horz = self->max_vert = FALSE;
721 /* let it be moved and resized no matter what */
722 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
723 self->decorations = 0; /* unmanaged windows have no decor */
725 /* give the client its border back */
726 XSetWindowBorderWidth(ob_display, self->window, self->border_width);
728 client_move_resize(self, a.x, a.y, a.width, a.height);
731 /* reparent the window out of the frame, and free the frame */
732 frame_release_client(self->frame);
733 frame_free(self->frame);
736 if (ob_state() != OB_STATE_EXITING) {
737 /* these values should not be persisted across a window
739 PROP_ERASE(self->window, net_wm_desktop);
740 PROP_ERASE(self->window, net_wm_state);
741 PROP_ERASE(self->window, wm_state);
743 /* if we're left in an unmapped state, the client wont be mapped.
744 this is bad, since we will no longer be managing the window on
746 XMapWindow(ob_display, self->window);
749 /* update the list hints */
752 ob_debug("Unmanaged window 0x%lx\n", self->window);
754 /* free all data allocated in the client struct */
755 g_slist_free(self->transients);
756 for (j = 0; j < self->nicons; ++j)
757 g_free(self->icons[j].data);
758 if (self->nicons > 0)
760 g_free(self->wm_command);
762 g_free(self->icon_title);
766 g_free(self->client_machine);
767 g_free(self->sm_client_id);
771 void client_fake_unmanage(ObClient *self)
773 /* this is all that got allocated to get the decorations */
775 frame_free(self->frame);
779 /*! Returns a new structure containing the per-app settings for this client.
780 The returned structure needs to be freed with g_free. */
781 static ObAppSettings *client_get_settings_state(ObClient *self)
783 ObAppSettings *settings;
786 settings = config_create_app_settings();
788 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
789 ObAppSettings *app = it->data;
790 gboolean match = TRUE;
792 g_assert(app->name != NULL || app->class != NULL);
794 /* we know that either name or class is not NULL so it will have to
795 match to use the rule */
797 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
799 else if (app->class &&
800 !g_pattern_match(app->class,
801 strlen(self->class), self->class, NULL))
803 else if (app->role &&
804 !g_pattern_match(app->role,
805 strlen(self->role), self->role, NULL))
809 ob_debug("Window matching: %s\n", app->name);
811 /* copy the settings to our struct, overriding the existing
812 settings if they are not defaults */
813 config_app_settings_copy_non_defaults(app, settings);
817 if (settings->shade != -1)
818 self->shaded = !!settings->shade;
819 if (settings->decor != -1)
820 self->undecorated = !settings->decor;
821 if (settings->iconic != -1)
822 self->iconic = !!settings->iconic;
823 if (settings->skip_pager != -1)
824 self->skip_pager = !!settings->skip_pager;
825 if (settings->skip_taskbar != -1)
826 self->skip_taskbar = !!settings->skip_taskbar;
828 if (settings->max_vert != -1)
829 self->max_vert = !!settings->max_vert;
830 if (settings->max_horz != -1)
831 self->max_horz = !!settings->max_horz;
833 if (settings->fullscreen != -1)
834 self->fullscreen = !!settings->fullscreen;
836 if (settings->desktop) {
837 if (settings->desktop == DESKTOP_ALL)
838 self->desktop = settings->desktop;
839 else if (settings->desktop > 0 &&
840 settings->desktop <= screen_num_desktops)
841 self->desktop = settings->desktop - 1;
844 if (settings->layer == -1) {
848 else if (settings->layer == 0) {
852 else if (settings->layer == 1) {
859 static void client_restore_session_state(ObClient *self)
863 ob_debug_type(OB_DEBUG_SM,
864 "Restore session for client %s\n", self->title);
866 if (!(it = session_state_find(self))) {
867 ob_debug_type(OB_DEBUG_SM,
868 "Session data not found for client %s\n", self->title);
872 self->session = it->data;
874 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s\n",
877 RECT_SET_POINT(self->area, self->session->x, self->session->y);
878 self->positioned = USPosition;
879 self->sized = USSize;
880 if (self->session->w > 0)
881 self->area.width = self->session->w;
882 if (self->session->h > 0)
883 self->area.height = self->session->h;
884 XResizeWindow(ob_display, self->window,
885 self->area.width, self->area.height);
887 self->desktop = (self->session->desktop == DESKTOP_ALL ?
888 self->session->desktop :
889 MIN(screen_num_desktops - 1, self->session->desktop));
890 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
892 self->shaded = self->session->shaded;
893 self->iconic = self->session->iconic;
894 self->skip_pager = self->session->skip_pager;
895 self->skip_taskbar = self->session->skip_taskbar;
896 self->fullscreen = self->session->fullscreen;
897 self->above = self->session->above;
898 self->below = self->session->below;
899 self->max_horz = self->session->max_horz;
900 self->max_vert = self->session->max_vert;
901 self->undecorated = self->session->undecorated;
904 static gboolean client_restore_session_stacking(ObClient *self)
908 if (!self->session) return FALSE;
910 mypos = g_list_find(session_saved_state, self->session);
911 if (!mypos) return FALSE;
913 /* start above me and look for the first client */
914 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
917 for (cit = client_list; cit; cit = g_list_next(cit)) {
918 ObClient *c = cit->data;
919 /* found a client that was in the session, so go below it */
920 if (c->session == it->data) {
921 stacking_below(CLIENT_AS_WINDOW(self),
922 CLIENT_AS_WINDOW(cit->data));
930 void client_move_onscreen(ObClient *self, gboolean rude)
932 gint x = self->area.x;
933 gint y = self->area.y;
934 if (client_find_onscreen(self, &x, &y,
936 self->area.height, rude)) {
937 client_move(self, x, y);
941 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
945 gint ox = *x, oy = *y;
946 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
950 RECT_SET(desired, *x, *y, w, h);
951 all_a = screen_area(self->desktop);
952 mon_a = screen_area_monitor(self->desktop, screen_find_monitor(&desired));
954 /* get where the frame would be */
955 frame_client_gravity(self->frame, x, y, w, h);
957 /* get the requested size of the window with decorations */
958 fw = self->frame->size.left + w + self->frame->size.right;
959 fh = self->frame->size.top + h + self->frame->size.bottom;
961 /* This makes sure windows aren't entirely outside of the screen so you
962 can't see them at all.
963 It makes sure 10% of the window is on the screen at least. At don't let
964 it move itself off the top of the screen, which would hide the titlebar
965 on you. (The user can still do this if they want too, it's only limiting
968 XXX watch for xinerama dead areas...
970 if (client_normal(self)) {
971 if (!self->strut.right && *x + fw/10 >= all_a->x + all_a->width - 1)
972 *x = all_a->x + all_a->width - fw/10;
973 if (!self->strut.bottom && *y + fh/10 >= all_a->y + all_a->height - 1)
974 *y = all_a->y + all_a->height - fh/10;
975 if (!self->strut.left && *x + fw*9/10 - 1 < all_a->x)
976 *x = all_a->x - fw*9/10;
977 if (!self->strut.top && *y + fh*9/10 - 1 < all_a->y)
978 *y = all_a->y - fw*9/10;
981 /* If rudeness wasn't requested, then figure out of the client is currently
982 entirely on the screen. If it is, and the position isn't changing by
983 request, and it is enlarging, then be rude even though it wasn't
986 Point oldtl, oldtr, oldbl, oldbr;
987 Point newtl, newtr, newbl, newbr;
988 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
990 POINT_SET(oldtl, self->frame->area.x, self->frame->area.y);
991 POINT_SET(oldbr, self->frame->area.x + self->frame->area.width - 1,
992 self->frame->area.y + self->frame->area.height - 1);
993 POINT_SET(oldtr, oldbr.x, oldtl.y);
994 POINT_SET(oldbl, oldtl.x, oldbr.y);
996 POINT_SET(newtl, *x, *y);
997 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
998 POINT_SET(newtr, newbr.x, newtl.y);
999 POINT_SET(newbl, newtl.x, newbr.y);
1001 /* is it moving or just resizing from some corner? */
1002 stationary_l = oldtl.x == newtl.x;
1003 stationary_r = oldtr.x == newtr.x;
1004 stationary_t = oldtl.y == newtl.y;
1005 stationary_b = oldbl.y == newbl.y;
1007 /* if left edge is growing and didnt move right edge */
1008 if (stationary_r && newtl.x < oldtl.x)
1010 /* if right edge is growing and didnt move left edge */
1011 if (stationary_l && newtr.x > oldtr.x)
1013 /* if top edge is growing and didnt move bottom edge */
1014 if (stationary_b && newtl.y < oldtl.y)
1016 /* if bottom edge is growing and didnt move top edge */
1017 if (stationary_t && newbl.y > oldbl.y)
1021 /* This here doesn't let windows even a pixel outside the struts/screen.
1022 * When called from client_manage, programs placing themselves are
1023 * forced completely onscreen, while things like
1024 * xterm -geometry resolution-width/2 will work fine. Trying to
1025 * place it completely offscreen will be handled in the above code.
1026 * Sorry for this confused comment, i am tired. */
1027 if (rudel && !self->strut.left && *x < mon_a->x) *x = mon_a->x;
1028 if (ruder && !self->strut.right && *x + fw > mon_a->x + mon_a->width)
1029 *x = mon_a->x + MAX(0, mon_a->width - fw);
1031 if (rudet && !self->strut.top && *y < mon_a->y) *y = mon_a->y;
1032 if (rudeb && !self->strut.bottom && *y + fh > mon_a->y + mon_a->height)
1033 *y = mon_a->y + MAX(0, mon_a->height - fh);
1035 /* get where the client should be */
1036 frame_frame_gravity(self->frame, x, y, w, h);
1038 return ox != *x || oy != *y;
1041 static void client_get_all(ObClient *self, gboolean real)
1043 /* this is needed for the frame to set itself up */
1044 client_get_area(self);
1046 /* these things can change the decor and functions of the window */
1048 client_get_mwm_hints(self);
1049 /* this can change the mwmhints for special cases */
1050 client_get_type_and_transientness(self);
1051 client_get_state(self);
1052 client_update_normal_hints(self);
1054 /* get the session related properties, these can change decorations
1055 from per-app settings */
1056 client_get_session_ids(self);
1058 /* now we got everything that can affect the decorations */
1062 /* get this early so we have it for debugging */
1063 client_update_title(self);
1065 client_update_protocols(self);
1067 client_update_wmhints(self);
1068 /* this may have already been called from client_update_wmhints */
1069 if (self->transient_for == NULL)
1070 client_update_transient_for(self);
1072 client_get_startup_id(self);
1073 client_get_desktop(self);/* uses transient data/group/startup id if a
1074 desktop is not specified */
1075 client_get_shaped(self);
1078 /* a couple type-based defaults for new windows */
1080 /* this makes sure that these windows appear on all desktops */
1081 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1082 self->desktop = DESKTOP_ALL;
1086 client_update_sync_request_counter(self);
1089 client_get_colormap(self);
1090 client_update_strut(self);
1091 client_update_icons(self);
1092 client_update_user_time_window(self);
1093 if (!self->user_time_window) /* check if this would have been called */
1094 client_update_user_time(self);
1095 client_update_icon_geometry(self);
1098 static void client_get_startup_id(ObClient *self)
1100 if (!(PROP_GETS(self->window, net_startup_id, utf8, &self->startup_id)))
1102 PROP_GETS(self->group->leader,
1103 net_startup_id, utf8, &self->startup_id);
1106 static void client_get_area(ObClient *self)
1108 XWindowAttributes wattrib;
1111 ret = XGetWindowAttributes(ob_display, self->window, &wattrib);
1112 g_assert(ret != BadWindow);
1114 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1115 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1116 self->border_width = wattrib.border_width;
1118 ob_debug("client area: %d %d %d %d bw %d\n", wattrib.x, wattrib.y,
1119 wattrib.width, wattrib.height, wattrib.border_width);
1122 static void client_get_desktop(ObClient *self)
1124 guint32 d = screen_num_desktops; /* an always-invalid value */
1126 if (PROP_GET32(self->window, net_wm_desktop, cardinal, &d)) {
1127 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1128 self->desktop = screen_num_desktops - 1;
1131 ob_debug("client requested desktop 0x%x\n", self->desktop);
1133 gboolean trdesk = FALSE;
1135 if (self->transient_for) {
1136 if (self->transient_for != OB_TRAN_GROUP) {
1137 if (self->transient_for->desktop != DESKTOP_ALL) {
1138 self->desktop = self->transient_for->desktop;
1142 /* if all the group is on one desktop, then open it on the
1145 gboolean first = TRUE;
1146 guint all = screen_num_desktops; /* not a valid value */
1148 for (it = self->group->members; it; it = g_slist_next(it)) {
1149 ObClient *c = it->data;
1155 else if (all != c->desktop)
1156 all = screen_num_desktops; /* make it invalid */
1159 if (all != screen_num_desktops) {
1160 self->desktop = all;
1166 /* try get from the startup-notification protocol */
1167 if (sn_get_desktop(self->startup_id, &self->desktop)) {
1168 if (self->desktop >= screen_num_desktops &&
1169 self->desktop != DESKTOP_ALL)
1170 self->desktop = screen_num_desktops - 1;
1172 /* defaults to the current desktop */
1173 self->desktop = screen_desktop;
1178 static void client_get_state(ObClient *self)
1183 if (PROP_GETA32(self->window, net_wm_state, atom, &state, &num)) {
1185 for (i = 0; i < num; ++i) {
1186 if (state[i] == prop_atoms.net_wm_state_modal)
1188 else if (state[i] == prop_atoms.net_wm_state_shaded)
1189 self->shaded = TRUE;
1190 else if (state[i] == prop_atoms.net_wm_state_hidden)
1191 self->iconic = TRUE;
1192 else if (state[i] == prop_atoms.net_wm_state_skip_taskbar)
1193 self->skip_taskbar = TRUE;
1194 else if (state[i] == prop_atoms.net_wm_state_skip_pager)
1195 self->skip_pager = TRUE;
1196 else if (state[i] == prop_atoms.net_wm_state_fullscreen)
1197 self->fullscreen = TRUE;
1198 else if (state[i] == prop_atoms.net_wm_state_maximized_vert)
1199 self->max_vert = TRUE;
1200 else if (state[i] == prop_atoms.net_wm_state_maximized_horz)
1201 self->max_horz = TRUE;
1202 else if (state[i] == prop_atoms.net_wm_state_above)
1204 else if (state[i] == prop_atoms.net_wm_state_below)
1206 else if (state[i] == prop_atoms.net_wm_state_demands_attention)
1207 self->demands_attention = TRUE;
1208 else if (state[i] == prop_atoms.ob_wm_state_undecorated)
1209 self->undecorated = TRUE;
1216 static void client_get_shaped(ObClient *self)
1218 self->shaped = FALSE;
1220 if (extensions_shape) {
1225 XShapeSelectInput(ob_display, self->window, ShapeNotifyMask);
1227 XShapeQueryExtents(ob_display, self->window, &s, &foo,
1228 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1230 self->shaped = (s != 0);
1235 void client_update_transient_for(ObClient *self)
1238 ObClient *target = NULL;
1240 if (XGetTransientForHint(ob_display, self->window, &t)) {
1241 if (t != self->window) { /* cant be transient to itself! */
1242 target = g_hash_table_lookup(window_map, &t);
1243 /* if this happens then we need to check for it*/
1244 g_assert(target != self);
1245 if (target && !WINDOW_IS_CLIENT(target)) {
1246 /* this can happen when a dialog is a child of
1247 a dockapp, for example */
1251 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1253 Setting the transient_for to Root is actually illegal, however
1254 applications from time have done this to specify transient for
1257 Now you can do that by being a TYPE_DIALOG and not setting
1258 the transient_for hint at all on your window. But people still
1259 use Root, and Kwin is very strange in this regard.
1261 KWin 3.0 will not consider windows with transient_for set to
1262 Root as transient for their group *UNLESS* they are also modal.
1263 In that case, it will make them transient for the group. This
1264 leads to all sorts of weird behavior from KDE apps which are
1265 only tested in KWin. I'd like to follow their behavior just to
1266 make this work right with KDE stuff, but that seems wrong.
1268 if (!target && self->group) {
1269 /* not transient to a client, see if it is transient for a
1271 if (t == RootWindow(ob_display, ob_screen)) {
1272 /* window is a transient for its group! */
1273 target = OB_TRAN_GROUP;
1277 } else if (self->transient && self->group)
1278 target = OB_TRAN_GROUP;
1280 client_update_transient_tree(self, self->group, self->group,
1281 self->transient_for, target);
1282 self->transient_for = target;
1286 static void client_update_transient_tree(ObClient *self,
1287 ObGroup *oldgroup, ObGroup *newgroup,
1288 ObClient* oldparent,
1289 ObClient *newparent)
1295 Group transient windows are not allowed to have other group
1296 transient windows as their children.
1300 /* No change has occured */
1301 if (oldgroup == newgroup && oldparent == newparent) return;
1303 /** Remove the client from the transient tree wherever it has changed **/
1305 /* If the window is becoming a direct transient for a window in its group
1306 then any group transients which were our children and are now becoming
1307 our parents need to stop being our children.
1309 Group transients can't be children of group transients already, but
1310 we could have any number of direct parents above up, any of which could
1311 be transient for the group, and we need to remove it from our children.
1313 if (oldparent != newparent &&
1314 newparent != NULL && newparent != OB_TRAN_GROUP &&
1315 newgroup != NULL && newgroup == oldgroup)
1317 ObClient *look = newparent;
1319 self->transients = g_slist_remove(self->transients, look);
1320 look = look->transient_for;
1321 } while (look != NULL && look != OB_TRAN_GROUP);
1325 /* If the group changed, or if we are just becoming transient for the
1326 group, then we need to remove any old group transient windows
1327 from our children. But if we were already transient for the group, then
1328 other group transients are not our children. */
1329 if ((oldgroup != newgroup ||
1330 (newparent == OB_TRAN_GROUP && oldparent != newparent)) &&
1331 oldgroup != NULL && oldparent != OB_TRAN_GROUP)
1333 for (it = self->transients; it; it = next) {
1334 next = g_slist_next(it);
1336 if (c->group == oldgroup)
1337 self->transients = g_slist_delete_link(self->transients, it);
1341 /* If we used to be transient for a group and now we are not, or we're
1342 transient for a new group, then we need to remove ourselves from all
1344 if (oldparent == OB_TRAN_GROUP && (oldgroup != newgroup ||
1345 oldparent != newparent))
1347 for (it = oldgroup->members; it; it = g_slist_next(it)) {
1349 if (c != self && (!c->transient_for ||
1350 c->transient_for != OB_TRAN_GROUP))
1351 c->transients = g_slist_remove(c->transients, self);
1354 /* If we used to be transient for a single window and we are no longer
1355 transient for it, then we need to remove ourself from its children */
1356 else if (oldparent != NULL && oldparent != OB_TRAN_GROUP &&
1357 oldparent != newparent)
1358 oldparent->transients = g_slist_remove(oldparent->transients, self);
1361 /** Re-add the client to the transient tree wherever it has changed **/
1363 /* If we're now transient for a group and we weren't transient for it
1364 before then we need to add ourselves to all our new parents */
1365 if (newparent == OB_TRAN_GROUP && (oldgroup != newgroup ||
1366 oldparent != newparent))
1368 for (it = oldgroup->members; it; it = g_slist_next(it)) {
1370 if (c != self && (!c->transient_for ||
1371 c->transient_for != OB_TRAN_GROUP))
1372 c->transients = g_slist_prepend(c->transients, self);
1375 /* If we are now transient for a single window which we weren't before,
1376 we need to add ourselves to its children
1378 WARNING: Cyclical transient ness is possible if two windows are
1379 transient for eachother.
1381 else if (newparent != NULL && newparent != OB_TRAN_GROUP &&
1382 newparent != oldparent &&
1383 /* don't make ourself its child if it is already our child */
1384 !client_is_direct_child(self, newparent))
1385 newparent->transients = g_slist_prepend(newparent->transients, self);
1387 /* If the group changed then we need to add any new group transient
1388 windows to our children. But if we're transient for the group, then
1389 other group transients are not our children.
1391 WARNING: Cyclical transient-ness is possible. For e.g. if:
1392 A is transient for the group
1393 B is transient for A
1394 C is transient for B
1395 A can't be transient for C or we have a cycle
1397 if (oldgroup != newgroup && newgroup != NULL &&
1398 newparent != OB_TRAN_GROUP)
1400 for (it = newgroup->members; it; it = g_slist_next(it)) {
1402 if (c != self && c->transient_for == OB_TRAN_GROUP &&
1403 /* Don't make it our child if it is already our parent */
1404 !client_is_direct_child(c, self))
1406 self->transients = g_slist_prepend(self->transients, c);
1412 static void client_get_mwm_hints(ObClient *self)
1417 self->mwmhints.flags = 0; /* default to none */
1419 if (PROP_GETA32(self->window, motif_wm_hints, motif_wm_hints,
1421 if (num >= OB_MWM_ELEMENTS) {
1422 self->mwmhints.flags = hints[0];
1423 self->mwmhints.functions = hints[1];
1424 self->mwmhints.decorations = hints[2];
1430 void client_get_type_and_transientness(ObClient *self)
1437 self->transient = FALSE;
1439 if (PROP_GETA32(self->window, net_wm_window_type, atom, &val, &num)) {
1440 /* use the first value that we know about in the array */
1441 for (i = 0; i < num; ++i) {
1442 if (val[i] == prop_atoms.net_wm_window_type_desktop)
1443 self->type = OB_CLIENT_TYPE_DESKTOP;
1444 else if (val[i] == prop_atoms.net_wm_window_type_dock)
1445 self->type = OB_CLIENT_TYPE_DOCK;
1446 else if (val[i] == prop_atoms.net_wm_window_type_toolbar)
1447 self->type = OB_CLIENT_TYPE_TOOLBAR;
1448 else if (val[i] == prop_atoms.net_wm_window_type_menu)
1449 self->type = OB_CLIENT_TYPE_MENU;
1450 else if (val[i] == prop_atoms.net_wm_window_type_utility)
1451 self->type = OB_CLIENT_TYPE_UTILITY;
1452 else if (val[i] == prop_atoms.net_wm_window_type_splash)
1453 self->type = OB_CLIENT_TYPE_SPLASH;
1454 else if (val[i] == prop_atoms.net_wm_window_type_dialog)
1455 self->type = OB_CLIENT_TYPE_DIALOG;
1456 else if (val[i] == prop_atoms.net_wm_window_type_normal)
1457 self->type = OB_CLIENT_TYPE_NORMAL;
1458 else if (val[i] == prop_atoms.kde_net_wm_window_type_override) {
1459 /* prevent this window from getting any decor or
1461 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1462 OB_MWM_FLAG_DECORATIONS);
1463 self->mwmhints.decorations = 0;
1464 self->mwmhints.functions = 0;
1466 if (self->type != (ObClientType) -1)
1467 break; /* grab the first legit type */
1472 if (XGetTransientForHint(ob_display, self->window, &t))
1473 self->transient = TRUE;
1475 if (self->type == (ObClientType) -1) {
1476 /*the window type hint was not set, which means we either classify
1477 ourself as a normal window or a dialog, depending on if we are a
1479 if (self->transient)
1480 self->type = OB_CLIENT_TYPE_DIALOG;
1482 self->type = OB_CLIENT_TYPE_NORMAL;
1485 /* then, based on our type, we can update our transientness.. */
1486 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1487 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1488 self->type == OB_CLIENT_TYPE_MENU ||
1489 self->type == OB_CLIENT_TYPE_UTILITY)
1491 self->transient = TRUE;
1495 void client_update_protocols(ObClient *self)
1498 guint num_return, i;
1500 self->focus_notify = FALSE;
1501 self->delete_window = FALSE;
1503 if (PROP_GETA32(self->window, wm_protocols, atom, &proto, &num_return)) {
1504 for (i = 0; i < num_return; ++i) {
1505 if (proto[i] == prop_atoms.wm_delete_window)
1506 /* this means we can request the window to close */
1507 self->delete_window = TRUE;
1508 else if (proto[i] == prop_atoms.wm_take_focus)
1509 /* if this protocol is requested, then the window will be
1510 notified whenever we want it to receive focus */
1511 self->focus_notify = TRUE;
1513 else if (proto[i] == prop_atoms.net_wm_sync_request)
1514 /* if this protocol is requested, then resizing the
1515 window will be synchronized between the frame and the
1517 self->sync_request = TRUE;
1525 void client_update_sync_request_counter(ObClient *self)
1529 if (PROP_GET32(self->window, net_wm_sync_request_counter, cardinal, &i)) {
1530 self->sync_counter = i;
1532 self->sync_counter = None;
1536 void client_get_colormap(ObClient *self)
1538 XWindowAttributes wa;
1540 if (XGetWindowAttributes(ob_display, self->window, &wa))
1541 client_update_colormap(self, wa.colormap);
1544 void client_update_colormap(ObClient *self, Colormap colormap)
1546 if (colormap == self->colormap) return;
1548 ob_debug("Setting client %s colormap: 0x%x\n", self->title, colormap);
1550 if (client_focused(self)) {
1551 screen_install_colormap(self, FALSE); /* uninstall old one */
1552 self->colormap = colormap;
1553 screen_install_colormap(self, FALSE); /* install new one */
1555 self->colormap = colormap;
1558 void client_update_normal_hints(ObClient *self)
1564 self->min_ratio = 0.0f;
1565 self->max_ratio = 0.0f;
1566 SIZE_SET(self->size_inc, 1, 1);
1567 SIZE_SET(self->base_size, 0, 0);
1568 SIZE_SET(self->min_size, 0, 0);
1569 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1571 /* get the hints from the window */
1572 if (XGetWMNormalHints(ob_display, self->window, &size, &ret)) {
1573 /* normal windows can't request placement! har har
1574 if (!client_normal(self))
1576 self->positioned = (size.flags & (PPosition|USPosition));
1577 self->sized = (size.flags & (PSize|USSize));
1579 if (size.flags & PWinGravity)
1580 self->gravity = size.win_gravity;
1582 if (size.flags & PAspect) {
1583 if (size.min_aspect.y)
1585 (gfloat) size.min_aspect.x / size.min_aspect.y;
1586 if (size.max_aspect.y)
1588 (gfloat) size.max_aspect.x / size.max_aspect.y;
1591 if (size.flags & PMinSize)
1592 SIZE_SET(self->min_size, size.min_width, size.min_height);
1594 if (size.flags & PMaxSize)
1595 SIZE_SET(self->max_size, size.max_width, size.max_height);
1597 if (size.flags & PBaseSize)
1598 SIZE_SET(self->base_size, size.base_width, size.base_height);
1600 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1601 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1605 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1607 /* start with everything (cept fullscreen) */
1609 (OB_FRAME_DECOR_TITLEBAR |
1610 OB_FRAME_DECOR_HANDLE |
1611 OB_FRAME_DECOR_GRIPS |
1612 OB_FRAME_DECOR_BORDER |
1613 OB_FRAME_DECOR_ICON |
1614 OB_FRAME_DECOR_ALLDESKTOPS |
1615 OB_FRAME_DECOR_ICONIFY |
1616 OB_FRAME_DECOR_MAXIMIZE |
1617 OB_FRAME_DECOR_SHADE |
1618 OB_FRAME_DECOR_CLOSE);
1620 (OB_CLIENT_FUNC_RESIZE |
1621 OB_CLIENT_FUNC_MOVE |
1622 OB_CLIENT_FUNC_ICONIFY |
1623 OB_CLIENT_FUNC_MAXIMIZE |
1624 OB_CLIENT_FUNC_SHADE |
1625 OB_CLIENT_FUNC_CLOSE |
1626 OB_CLIENT_FUNC_BELOW |
1627 OB_CLIENT_FUNC_ABOVE |
1628 OB_CLIENT_FUNC_UNDECORATE);
1630 if (!(self->min_size.width < self->max_size.width ||
1631 self->min_size.height < self->max_size.height))
1632 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1634 switch (self->type) {
1635 case OB_CLIENT_TYPE_NORMAL:
1636 /* normal windows retain all of the possible decorations and
1637 functionality, and are the only windows that you can fullscreen */
1638 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1641 case OB_CLIENT_TYPE_DIALOG:
1642 case OB_CLIENT_TYPE_UTILITY:
1643 /* these windows don't have anything added or removed by default */
1646 case OB_CLIENT_TYPE_MENU:
1647 case OB_CLIENT_TYPE_TOOLBAR:
1648 /* these windows can't iconify or maximize */
1649 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1650 OB_FRAME_DECOR_MAXIMIZE);
1651 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1652 OB_CLIENT_FUNC_MAXIMIZE);
1655 case OB_CLIENT_TYPE_SPLASH:
1656 /* these don't get get any decorations, and the only thing you can
1657 do with them is move them */
1658 self->decorations = 0;
1659 self->functions = OB_CLIENT_FUNC_MOVE;
1662 case OB_CLIENT_TYPE_DESKTOP:
1663 /* these windows are not manipulated by the window manager */
1664 self->decorations = 0;
1665 self->functions = 0;
1668 case OB_CLIENT_TYPE_DOCK:
1669 /* these windows are not manipulated by the window manager, but they
1670 can set below layer which has a special meaning */
1671 self->decorations = 0;
1672 self->functions = OB_CLIENT_FUNC_BELOW;
1676 /* Mwm Hints are applied subtractively to what has already been chosen for
1677 decor and functionality */
1678 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1679 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1680 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1681 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1683 /* if the mwm hints request no handle or title, then all
1684 decorations are disabled, but keep the border if that's
1686 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1687 self->decorations = OB_FRAME_DECOR_BORDER;
1689 self->decorations = 0;
1694 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1695 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1696 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1697 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1698 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1699 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1700 /* dont let mwm hints kill any buttons
1701 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1702 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1703 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1704 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1706 /* dont let mwm hints kill the close button
1707 if (! (self->mwmhints.functions & MwmFunc_Close))
1708 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1712 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1713 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1714 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1715 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1716 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1717 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1719 /* can't maximize without moving/resizing */
1720 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1721 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1722 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1723 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1724 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1727 if (self->max_horz && self->max_vert) {
1728 /* you can't resize fully maximized windows */
1729 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1730 /* kill the handle on fully maxed windows */
1731 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1734 /* If there are no decorations to remove, don't allow the user to try
1736 if (self->decorations == 0)
1737 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1739 /* finally, the user can have requested no decorations, which overrides
1740 everything (but doesnt give it a border if it doesnt have one) */
1741 if (self->undecorated) {
1742 if (config_theme_keepborder)
1743 self->decorations &= OB_FRAME_DECOR_BORDER;
1745 self->decorations = 0;
1748 /* if we don't have a titlebar, then we cannot shade! */
1749 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1750 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1752 /* now we need to check against rules for the client's current state */
1753 if (self->fullscreen) {
1754 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1755 OB_CLIENT_FUNC_FULLSCREEN |
1756 OB_CLIENT_FUNC_ICONIFY);
1757 self->decorations = 0;
1760 client_change_allowed_actions(self);
1763 client_reconfigure(self);
1766 static void client_change_allowed_actions(ObClient *self)
1771 /* desktop windows are kept on all desktops */
1772 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1773 actions[num++] = prop_atoms.net_wm_action_change_desktop;
1775 if (self->functions & OB_CLIENT_FUNC_SHADE)
1776 actions[num++] = prop_atoms.net_wm_action_shade;
1777 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1778 actions[num++] = prop_atoms.net_wm_action_close;
1779 if (self->functions & OB_CLIENT_FUNC_MOVE)
1780 actions[num++] = prop_atoms.net_wm_action_move;
1781 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1782 actions[num++] = prop_atoms.net_wm_action_minimize;
1783 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1784 actions[num++] = prop_atoms.net_wm_action_resize;
1785 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1786 actions[num++] = prop_atoms.net_wm_action_fullscreen;
1787 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1788 actions[num++] = prop_atoms.net_wm_action_maximize_horz;
1789 actions[num++] = prop_atoms.net_wm_action_maximize_vert;
1791 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1792 actions[num++] = prop_atoms.net_wm_action_above;
1793 if (self->functions & OB_CLIENT_FUNC_BELOW)
1794 actions[num++] = prop_atoms.net_wm_action_below;
1795 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1796 actions[num++] = prop_atoms.ob_wm_action_undecorate;
1798 PROP_SETA32(self->window, net_wm_allowed_actions, atom, actions, num);
1800 /* make sure the window isn't breaking any rules now */
1802 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1803 if (self->frame) client_shade(self, FALSE);
1804 else self->shaded = FALSE;
1806 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY) && self->iconic) {
1807 if (self->frame) client_iconify(self, FALSE, TRUE, FALSE);
1808 else self->iconic = FALSE;
1810 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1811 if (self->frame) client_fullscreen(self, FALSE);
1812 else self->fullscreen = FALSE;
1814 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1816 if (self->frame) client_maximize(self, FALSE, 0);
1817 else self->max_vert = self->max_horz = FALSE;
1821 void client_reconfigure(ObClient *self)
1823 client_configure(self, self->area.x, self->area.y,
1824 self->area.width, self->area.height,
1828 void client_update_wmhints(ObClient *self)
1832 /* assume a window takes input if it doesnt specify */
1833 self->can_focus = TRUE;
1835 if ((hints = XGetWMHints(ob_display, self->window)) != NULL) {
1838 if (hints->flags & InputHint)
1839 self->can_focus = hints->input;
1841 /* only do this when first managing the window *AND* when we aren't
1843 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1844 if (hints->flags & StateHint)
1845 self->iconic = hints->initial_state == IconicState;
1848 self->urgent = (hints->flags & XUrgencyHint);
1849 if (self->urgent && !ur)
1850 client_hilite(self, TRUE);
1851 else if (!self->urgent && ur && self->demands_attention)
1852 client_hilite(self, FALSE);
1854 if (!(hints->flags & WindowGroupHint))
1855 hints->window_group = None;
1857 /* did the group state change? */
1858 if (hints->window_group !=
1859 (self->group ? self->group->leader : None))
1861 ObGroup *oldgroup = self->group;
1863 /* remove from the old group if there was one */
1864 if (self->group != NULL) {
1865 group_remove(self->group, self);
1869 /* add ourself to the group if we have one */
1870 if (hints->window_group != None) {
1871 self->group = group_add(hints->window_group, self);
1874 /* Put ourselves into the new group's transient tree, and remove
1875 ourselves from the old group's */
1876 client_update_transient_tree(self, oldgroup, self->group,
1877 self->transient_for,
1878 self->transient_for);
1880 /* Lastly, being in a group, or not, can change if the window is
1881 transient for anything.
1883 The logic for this is:
1884 self->transient = TRUE always if the window wants to be
1885 transient for something, even if transient_for was NULL because
1886 it wasn't in a group before.
1888 If transient_for was NULL and oldgroup was NULL we can assume
1889 that when we add the new group, it will become transient for
1892 If transient_for was OB_TRAN_GROUP, then it must have already
1893 had a group. If it is getting a new group, the above call to
1894 client_update_transient_tree has already taken care of
1895 everything ! If it is losing all group status then it will
1896 no longer be transient for anything and that needs to be
1899 if (self->transient &&
1900 ((self->transient_for == NULL && oldgroup == NULL) ||
1901 (self->transient_for == OB_TRAN_GROUP && !self->group)))
1902 client_update_transient_for(self);
1905 /* the WM_HINTS can contain an icon */
1906 if (hints->flags & IconPixmapHint)
1907 client_update_icons(self);
1913 void client_update_title(ObClient *self)
1916 gchar *visible = NULL;
1918 g_free(self->title);
1921 if (!PROP_GETS(self->window, net_wm_name, utf8, &data)) {
1922 /* try old x stuff */
1923 if (!(PROP_GETS(self->window, wm_name, locale, &data)
1924 || PROP_GETS(self->window, wm_name, utf8, &data))) {
1925 if (self->transient) {
1927 GNOME alert windows are not given titles:
1928 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1930 data = g_strdup("");
1932 data = g_strdup("Unnamed Window");
1936 if (self->client_machine) {
1937 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1942 PROP_SETS(self->window, net_wm_visible_name, visible);
1943 self->title = visible;
1946 frame_adjust_title(self->frame);
1948 /* update the icon title */
1950 g_free(self->icon_title);
1953 if (!PROP_GETS(self->window, net_wm_icon_name, utf8, &data))
1954 /* try old x stuff */
1955 if (!(PROP_GETS(self->window, wm_icon_name, locale, &data) ||
1956 PROP_GETS(self->window, wm_icon_name, utf8, &data)))
1957 data = g_strdup(self->title);
1959 if (self->client_machine) {
1960 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1965 PROP_SETS(self->window, net_wm_visible_icon_name, visible);
1966 self->icon_title = visible;
1969 void client_update_strut(ObClient *self)
1973 gboolean got = FALSE;
1976 if (PROP_GETA32(self->window, net_wm_strut_partial, cardinal,
1980 STRUT_PARTIAL_SET(strut,
1981 data[0], data[2], data[1], data[3],
1982 data[4], data[5], data[8], data[9],
1983 data[6], data[7], data[10], data[11]);
1989 PROP_GETA32(self->window, net_wm_strut, cardinal, &data, &num)) {
1995 /* use the screen's width/height */
1996 a = screen_physical_area();
1998 STRUT_PARTIAL_SET(strut,
1999 data[0], data[2], data[1], data[3],
2000 a->y, a->y + a->height - 1,
2001 a->x, a->x + a->width - 1,
2002 a->y, a->y + a->height - 1,
2003 a->x, a->x + a->width - 1);
2009 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2010 0, 0, 0, 0, 0, 0, 0, 0);
2012 if (!STRUT_EQUAL(strut, self->strut)) {
2013 self->strut = strut;
2015 /* updating here is pointless while we're being mapped cuz we're not in
2016 the client list yet */
2018 screen_update_areas();
2022 void client_update_icons(ObClient *self)
2028 for (i = 0; i < self->nicons; ++i)
2029 g_free(self->icons[i].data);
2030 if (self->nicons > 0)
2031 g_free(self->icons);
2034 if (PROP_GETA32(self->window, net_wm_icon, cardinal, &data, &num)) {
2035 /* figure out how many valid icons are in here */
2037 while (num - i > 2) {
2041 if (i > num || w*h == 0) break;
2045 self->icons = g_new(ObClientIcon, self->nicons);
2047 /* store the icons */
2049 for (j = 0; j < self->nicons; ++j) {
2052 w = self->icons[j].width = data[i++];
2053 h = self->icons[j].height = data[i++];
2055 if (w*h == 0) continue;
2057 self->icons[j].data = g_new(RrPixel32, w * h);
2058 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
2063 self->icons[j].data[t] =
2064 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2065 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
2066 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
2067 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
2076 if ((hints = XGetWMHints(ob_display, self->window))) {
2077 if (hints->flags & IconPixmapHint) {
2079 self->icons = g_new(ObClientIcon, self->nicons);
2080 xerror_set_ignore(TRUE);
2081 if (!RrPixmapToRGBA(ob_rr_inst,
2083 (hints->flags & IconMaskHint ?
2084 hints->icon_mask : None),
2085 &self->icons[self->nicons-1].width,
2086 &self->icons[self->nicons-1].height,
2087 &self->icons[self->nicons-1].data)){
2088 g_free(&self->icons[self->nicons-1]);
2091 xerror_set_ignore(FALSE);
2097 /* set the default icon onto the window
2098 in theory, this could be a race, but if a window doesn't set an icon
2099 or removes it entirely, it's not very likely it is going to set one
2100 right away afterwards */
2101 if (self->nicons == 0) {
2102 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2105 data = g_new(gulong, 48*48+2);
2106 data[0] = data[1] = 48;
2107 for (i = 0; i < 48*48; ++i)
2108 data[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2109 (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) +
2110 (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) +
2111 (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0);
2112 PROP_SETA32(self->window, net_wm_icon, cardinal, data, 48*48+2);
2114 } else if (self->frame)
2115 /* don't draw the icon empty if we're just setting one now anyways,
2116 we'll get the property change any second */
2117 frame_adjust_icon(self->frame);
2120 void client_update_user_time(ObClient *self)
2123 gboolean got = FALSE;
2125 if (self->user_time_window)
2126 got = PROP_GET32(self->user_time_window,
2127 net_wm_user_time, cardinal, &time);
2129 got = PROP_GET32(self->window, net_wm_user_time, cardinal, &time);
2132 /* we set this every time, not just when it grows, because in practice
2133 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
2134 backward we don't want all windows to stop focusing. we'll just
2135 assume noone is setting times older than the last one, cuz that
2136 would be pretty stupid anyways
2138 self->user_time = time;
2140 /*ob_debug("window %s user time %u\n", self->title, time);*/
2144 void client_update_user_time_window(ObClient *self)
2148 if (!PROP_GET32(self->window, net_wm_user_time_window, window, &w))
2151 if (w != self->user_time_window) {
2152 /* remove the old window */
2153 propwin_remove(self->user_time_window, OB_PROPWIN_USER_TIME, self);
2154 self->user_time_window = None;
2156 if (self->group && self->group->leader == w) {
2157 ob_debug_type(OB_DEBUG_APP_BUGS, "Window is setting its "
2158 "_NET_WM_USER_TYPE_WINDOW to its group leader\n");
2159 /* do it anyways..? */
2161 else if (w == self->window) {
2162 ob_debug_type(OB_DEBUG_APP_BUGS, "Window is setting its "
2163 "_NET_WM_USER_TIME_WINDOW to itself\n");
2164 w = None; /* don't do it */
2167 /* add the new window */
2168 propwin_add(w, OB_PROPWIN_USER_TIME, self);
2169 self->user_time_window = w;
2171 /* and update from it */
2172 client_update_user_time(self);
2176 void client_update_icon_geometry(ObClient *self)
2181 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2183 if (PROP_GETA32(self->window, net_wm_icon_geometry, cardinal, &data, &num)
2186 /* don't let them set it with an area < 0 */
2187 RECT_SET(self->icon_geometry, data[0], data[1],
2188 MAX(data[2],0), MAX(data[3],0));
2192 static void client_get_session_ids(ObClient *self)
2199 if (!PROP_GET32(self->window, wm_client_leader, window, &leader))
2202 /* get the SM_CLIENT_ID */
2205 got = PROP_GETS(leader, sm_client_id, locale, &self->sm_client_id);
2207 PROP_GETS(self->window, sm_client_id, locale, &self->sm_client_id);
2209 /* get the WM_CLASS (name and class). make them "" if they are not
2213 got = PROP_GETSS(leader, wm_class, locale, &ss);
2215 got = PROP_GETSS(self->window, wm_class, locale, &ss);
2219 self->name = g_strdup(ss[0]);
2221 self->class = g_strdup(ss[1]);
2226 if (self->name == NULL) self->name = g_strdup("");
2227 if (self->class == NULL) self->class = g_strdup("");
2229 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2232 got = PROP_GETS(leader, wm_window_role, locale, &s);
2234 got = PROP_GETS(self->window, wm_window_role, locale, &s);
2239 self->role = g_strdup("");
2241 /* get the WM_COMMAND */
2245 got = PROP_GETSS(leader, wm_command, locale, &ss);
2247 got = PROP_GETSS(self->window, wm_command, locale, &ss);
2250 /* merge/mash them all together */
2251 gchar *merge = NULL;
2254 for (i = 0; ss[i]; ++i) {
2257 merge = g_strconcat(merge, ss[i], NULL);
2259 merge = g_strconcat(ss[i], NULL);
2264 self->wm_command = merge;
2267 /* get the WM_CLIENT_MACHINE */
2270 got = PROP_GETS(leader, wm_client_machine, locale, &s);
2272 got = PROP_GETS(self->window, wm_client_machine, locale, &s);
2275 gchar localhost[128];
2277 gethostname(localhost, 127);
2278 localhost[127] = '\0';
2279 if (strcmp(localhost, s) != 0)
2280 self->client_machine = s;
2286 static void client_change_wm_state(ObClient *self)
2291 old = self->wmstate;
2293 if (self->shaded || self->iconic ||
2294 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2296 self->wmstate = IconicState;
2298 self->wmstate = NormalState;
2300 if (old != self->wmstate) {
2301 PROP_MSG(self->window, kde_wm_change_state,
2302 self->wmstate, 1, 0, 0);
2304 state[0] = self->wmstate;
2306 PROP_SETA32(self->window, wm_state, wm_state, state, 2);
2310 static void client_change_state(ObClient *self)
2312 gulong netstate[11];
2317 netstate[num++] = prop_atoms.net_wm_state_modal;
2319 netstate[num++] = prop_atoms.net_wm_state_shaded;
2321 netstate[num++] = prop_atoms.net_wm_state_hidden;
2322 if (self->skip_taskbar)
2323 netstate[num++] = prop_atoms.net_wm_state_skip_taskbar;
2324 if (self->skip_pager)
2325 netstate[num++] = prop_atoms.net_wm_state_skip_pager;
2326 if (self->fullscreen)
2327 netstate[num++] = prop_atoms.net_wm_state_fullscreen;
2329 netstate[num++] = prop_atoms.net_wm_state_maximized_vert;
2331 netstate[num++] = prop_atoms.net_wm_state_maximized_horz;
2333 netstate[num++] = prop_atoms.net_wm_state_above;
2335 netstate[num++] = prop_atoms.net_wm_state_below;
2336 if (self->demands_attention)
2337 netstate[num++] = prop_atoms.net_wm_state_demands_attention;
2338 if (self->undecorated)
2339 netstate[num++] = prop_atoms.ob_wm_state_undecorated;
2340 PROP_SETA32(self->window, net_wm_state, atom, netstate, num);
2343 frame_adjust_state(self->frame);
2346 ObClient *client_search_focus_tree(ObClient *self)
2351 for (it = self->transients; it; it = g_slist_next(it)) {
2352 if (client_focused(it->data)) return it->data;
2353 if ((ret = client_search_focus_tree(it->data))) return ret;
2358 ObClient *client_search_focus_tree_full(ObClient *self)
2360 if (self->transient_for) {
2361 if (self->transient_for != OB_TRAN_GROUP) {
2362 return client_search_focus_tree_full(self->transient_for);
2366 for (it = self->group->members; it; it = g_slist_next(it)) {
2367 if (it->data != self) {
2368 ObClient *c = it->data;
2370 if (client_focused(c)) return c;
2371 if ((c = client_search_focus_tree(it->data))) return c;
2377 /* this function checks the whole tree, the client_search_focus_tree
2378 does not, so we need to check this window */
2379 if (client_focused(self))
2381 return client_search_focus_tree(self);
2384 gboolean client_has_parent(ObClient *self)
2386 if (self->transient_for) {
2387 if (self->transient_for != OB_TRAN_GROUP) {
2388 if (client_normal(self->transient_for))
2391 else if (self->group) {
2394 for (it = self->group->members; it; it = g_slist_next(it)) {
2395 if (it->data != self && client_normal(it->data))
2403 static ObStackingLayer calc_layer(ObClient *self)
2407 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2408 l = OB_STACKING_LAYER_DESKTOP;
2409 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2410 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2411 else l = OB_STACKING_LAYER_ABOVE;
2413 else if ((self->fullscreen ||
2414 /* No decorations and fills the monitor = oldskool fullscreen.
2415 But not for maximized windows.
2417 (self->decorations == 0 &&
2418 !(self->max_horz && self->max_vert) &&
2419 RECT_EQUAL(self->area,
2420 *screen_physical_area_monitor
2421 (client_monitor(self))))) &&
2422 (client_focused(self) || client_search_focus_tree(self)))
2423 l = OB_STACKING_LAYER_FULLSCREEN;
2424 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2425 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2426 else l = OB_STACKING_LAYER_NORMAL;
2431 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2432 ObStackingLayer min)
2434 ObStackingLayer old, own;
2438 own = calc_layer(self);
2439 self->layer = MAX(own, min);
2441 if (self->layer != old) {
2442 stacking_remove(CLIENT_AS_WINDOW(self));
2443 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2446 for (it = self->transients; it; it = g_slist_next(it))
2447 client_calc_layer_recursive(it->data, orig,
2451 void client_calc_layer(ObClient *self)
2458 /* transients take on the layer of their parents */
2459 it = client_search_all_top_parents(self);
2461 for (; it; it = g_slist_next(it))
2462 client_calc_layer_recursive(it->data, orig, 0);
2465 gboolean client_should_show(ObClient *self)
2469 if (client_normal(self) && screen_showing_desktop)
2471 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2477 gboolean client_show(ObClient *self)
2479 gboolean show = FALSE;
2481 if (client_should_show(self)) {
2482 frame_show(self->frame);
2485 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2486 it needs to be in IconicState. This includes when it is on another
2489 client_change_wm_state(self);
2494 gboolean client_hide(ObClient *self)
2496 gboolean hide = FALSE;
2498 if (!client_should_show(self)) {
2499 if (self == focus_client) {
2500 /* if there is a grab going on, then we need to cancel it. if we
2501 move focus during the grab, applications will get
2502 NotifyWhileGrabbed events and ignore them !
2504 actions should not rely on being able to move focus during an
2507 event_cancel_all_key_grabs();
2510 frame_hide(self->frame);
2513 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2514 it needs to be in IconicState. This includes when it is on another
2517 client_change_wm_state(self);
2522 void client_showhide(ObClient *self)
2524 if (!client_show(self))
2528 gboolean client_normal(ObClient *self) {
2529 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2530 self->type == OB_CLIENT_TYPE_DOCK ||
2531 self->type == OB_CLIENT_TYPE_SPLASH);
2534 gboolean client_helper(ObClient *self)
2536 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2537 self->type == OB_CLIENT_TYPE_MENU ||
2538 self->type == OB_CLIENT_TYPE_TOOLBAR);
2541 gboolean client_mouse_focusable(ObClient *self)
2543 return !(self->type == OB_CLIENT_TYPE_MENU ||
2544 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2545 self->type == OB_CLIENT_TYPE_SPLASH ||
2546 self->type == OB_CLIENT_TYPE_DOCK);
2549 gboolean client_enter_focusable(ObClient *self)
2551 /* you can focus desktops but it shouldn't on enter */
2552 return (client_mouse_focusable(self) &&
2553 self->type != OB_CLIENT_TYPE_DESKTOP);
2557 static void client_apply_startup_state(ObClient *self,
2558 gint x, gint y, gint w, gint h)
2560 /* save the states that we are going to apply */
2561 gboolean iconic = self->iconic;
2562 gboolean fullscreen = self->fullscreen;
2563 gboolean undecorated = self->undecorated;
2564 gboolean shaded = self->shaded;
2565 gboolean demands_attention = self->demands_attention;
2566 gboolean max_horz = self->max_horz;
2567 gboolean max_vert = self->max_vert;
2569 /* turn them all off in the client, so they won't affect the window
2571 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2572 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2574 /* move the client to its placed position, or it it's already there,
2575 generate a ConfigureNotify telling the client where it is.
2577 do this after adjusting the frame. otherwise it gets all weird and
2578 clients don't work right
2580 do this before applying the states so they have the correct
2581 pre-max/pre-fullscreen values
2583 client_configure(self, x, y, w, h, FALSE, TRUE);
2584 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2585 self->window, self->area.x, self->area.y,
2586 self->area.width, self->area.height);
2588 /* apply the states. these are in a carefully crafted order.. */
2591 client_iconify(self, TRUE, FALSE, TRUE);
2593 client_fullscreen(self, TRUE);
2595 client_set_undecorated(self, TRUE);
2597 client_shade(self, TRUE);
2598 if (demands_attention)
2599 client_hilite(self, TRUE);
2601 if (max_vert && max_horz)
2602 client_maximize(self, TRUE, 0);
2604 client_maximize(self, TRUE, 2);
2606 client_maximize(self, TRUE, 1);
2608 /* set the desktop hint, to make sure that it always exists */
2609 PROP_SET32(self->window, net_wm_desktop, cardinal, self->desktop);
2611 /* nothing to do for the other states:
2620 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2622 /* these should be the current values. this is for when you're not moving,
2624 g_assert(*x == self->area.x);
2625 g_assert(oldw == self->area.width);
2628 switch (self->gravity) {
2630 case NorthWestGravity:
2632 case SouthWestGravity:
2639 *x -= (neww - oldw) / 2;
2641 case NorthEastGravity:
2643 case SouthEastGravity:
2649 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2651 /* these should be the current values. this is for when you're not moving,
2653 g_assert(*y == self->area.y);
2654 g_assert(oldh == self->area.height);
2657 switch (self->gravity) {
2659 case NorthWestGravity:
2661 case NorthEastGravity:
2668 *y -= (newh - oldh) / 2;
2670 case SouthWestGravity:
2672 case SouthEastGravity:
2678 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2679 gint *logicalw, gint *logicalh,
2682 Rect desired_area = {*x, *y, *w, *h};
2684 /* make the frame recalculate its dimentions n shit without changing
2685 anything visible for real, this way the constraints below can work with
2686 the updated frame dimensions. */
2687 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
2689 /* work within the prefered sizes given by the window */
2690 if (!(*w == self->area.width && *h == self->area.height)) {
2691 gint basew, baseh, minw, minh;
2693 /* base size is substituted with min size if not specified */
2694 if (self->base_size.width || self->base_size.height) {
2695 basew = self->base_size.width;
2696 baseh = self->base_size.height;
2698 basew = self->min_size.width;
2699 baseh = self->min_size.height;
2701 /* min size is substituted with base size if not specified */
2702 if (self->min_size.width || self->min_size.height) {
2703 minw = self->min_size.width;
2704 minh = self->min_size.height;
2706 minw = self->base_size.width;
2707 minh = self->base_size.height;
2710 /* if this is a user-requested resize, then check against min/max
2713 /* smaller than min size or bigger than max size? */
2714 if (*w > self->max_size.width) *w = self->max_size.width;
2715 if (*w < minw) *w = minw;
2716 if (*h > self->max_size.height) *h = self->max_size.height;
2717 if (*h < minh) *h = minh;
2722 /* keep to the increments */
2723 *w /= self->size_inc.width;
2724 *h /= self->size_inc.height;
2726 /* you cannot resize to nothing */
2727 if (basew + *w < 1) *w = 1 - basew;
2728 if (baseh + *h < 1) *h = 1 - baseh;
2730 /* save the logical size */
2731 *logicalw = self->size_inc.width > 1 ? *w : *w + basew;
2732 *logicalh = self->size_inc.height > 1 ? *h : *h + baseh;
2734 *w *= self->size_inc.width;
2735 *h *= self->size_inc.height;
2740 /* adjust the height to match the width for the aspect ratios.
2741 for this, min size is not substituted for base size ever. */
2742 *w -= self->base_size.width;
2743 *h -= self->base_size.height;
2745 if (!self->fullscreen) {
2746 if (self->min_ratio)
2747 if (*h * self->min_ratio > *w) {
2748 *h = (gint)(*w / self->min_ratio);
2750 /* you cannot resize to nothing */
2753 *w = (gint)(*h * self->min_ratio);
2756 if (self->max_ratio)
2757 if (*h * self->max_ratio < *w) {
2758 *h = (gint)(*w / self->max_ratio);
2760 /* you cannot resize to nothing */
2763 *w = (gint)(*h * self->min_ratio);
2768 *w += self->base_size.width;
2769 *h += self->base_size.height;
2772 /* gets the frame's position */
2773 frame_client_gravity(self->frame, x, y, *w, *h);
2775 /* these positions are frame positions, not client positions */
2777 /* set the size and position if fullscreen */
2778 if (self->fullscreen) {
2782 i = screen_find_monitor(&desired_area);
2783 a = screen_physical_area_monitor(i);
2790 user = FALSE; /* ignore if the client can't be moved/resized when it
2792 } else if (self->max_horz || self->max_vert) {
2796 i = screen_find_monitor(&desired_area);
2797 a = screen_area_monitor(self->desktop, i);
2799 /* set the size and position if maximized */
2800 if (self->max_horz) {
2802 *w = a->width - self->frame->size.left - self->frame->size.right;
2804 if (self->max_vert) {
2806 *h = a->height - self->frame->size.top - self->frame->size.bottom;
2809 user = FALSE; /* ignore if the client can't be moved/resized when it
2813 /* gets the client's position */
2814 frame_frame_gravity(self->frame, x, y, *w, *h);
2816 /* these override the above states! if you cant move you can't move! */
2818 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
2822 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2823 *w = self->area.width;
2824 *h = self->area.height;
2833 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
2834 gboolean user, gboolean final)
2837 gboolean send_resize_client;
2838 gboolean moved = FALSE, resized = FALSE;
2839 gboolean fmoved, fresized;
2840 guint fdecor = self->frame->decorations;
2841 gboolean fhorz = self->frame->max_horz;
2842 gboolean fvert = self->frame->max_vert;
2843 gint logicalw, logicalh;
2845 /* find the new x, y, width, and height (and logical size) */
2846 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
2848 /* set the logical size if things changed */
2849 if (!(w == self->area.width && h == self->area.height))
2850 SIZE_SET(self->logical_size, logicalw, logicalh);
2852 /* figure out if we moved or resized or what */
2853 moved = x != self->area.x || y != self->area.y;
2854 resized = w != self->area.width || h != self->area.height;
2856 oldw = self->area.width;
2857 oldh = self->area.height;
2858 RECT_SET(self->area, x, y, w, h);
2860 /* for app-requested resizes, always resize if 'resized' is true.
2861 for user-requested ones, only resize if final is true, or when
2862 resizing in redraw mode */
2863 send_resize_client = ((!user && resized) ||
2865 (resized && config_resize_redraw))));
2867 /* if the client is enlarging, then resize the client before the frame */
2868 if (send_resize_client && (w > oldw || h > oldh)) {
2869 XResizeWindow(ob_display, self->window, MAX(w, oldw), MAX(h, oldh));
2870 frame_adjust_client_area(self->frame);
2873 /* find the frame's dimensions and move/resize it */
2877 /* if decorations changed, then readjust everything for the frame */
2878 if (self->decorations != fdecor ||
2879 self->max_horz != fhorz || self->max_vert != fvert)
2881 fmoved = fresized = TRUE;
2884 /* adjust the frame */
2885 if (fmoved || fresized)
2886 frame_adjust_area(self->frame, fmoved, fresized, FALSE);
2888 if ((!user || (user && final)) && !resized)
2892 /* we have reset the client to 0 border width, so don't include
2893 it in these coords */
2894 POINT_SET(self->root_pos,
2895 self->frame->area.x + self->frame->size.left -
2897 self->frame->area.y + self->frame->size.top -
2898 self->border_width);
2900 event.type = ConfigureNotify;
2901 event.xconfigure.display = ob_display;
2902 event.xconfigure.event = self->window;
2903 event.xconfigure.window = self->window;
2905 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
2906 self->title, self->root_pos.x, self->root_pos.y, w, h);
2908 /* root window real coords */
2909 event.xconfigure.x = self->root_pos.x;
2910 event.xconfigure.y = self->root_pos.y;
2911 event.xconfigure.width = w;
2912 event.xconfigure.height = h;
2913 event.xconfigure.border_width = self->border_width;
2914 event.xconfigure.above = None;
2915 event.xconfigure.override_redirect = FALSE;
2916 XSendEvent(event.xconfigure.display, event.xconfigure.window,
2917 FALSE, StructureNotifyMask, &event);
2920 /* if the client is shrinking, then resize the frame before the client */
2921 if (send_resize_client && (w <= oldw && h <= oldh)) {
2922 frame_adjust_client_area(self->frame);
2923 XResizeWindow(ob_display, self->window, w, h);
2929 void client_fullscreen(ObClient *self, gboolean fs)
2933 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
2934 self->fullscreen == fs) return; /* already done */
2936 self->fullscreen = fs;
2937 client_change_state(self); /* change the state hints on the client */
2940 self->pre_fullscreen_area = self->area;
2941 /* if the window is maximized, its area isn't all that meaningful.
2942 save it's premax area instead. */
2943 if (self->max_horz) {
2944 self->pre_fullscreen_area.x = self->pre_max_area.x;
2945 self->pre_fullscreen_area.width = self->pre_max_area.width;
2947 if (self->max_vert) {
2948 self->pre_fullscreen_area.y = self->pre_max_area.y;
2949 self->pre_fullscreen_area.height = self->pre_max_area.height;
2952 /* these will help configure_full figure out where to fullscreen
2956 w = self->area.width;
2957 h = self->area.height;
2959 g_assert(self->pre_fullscreen_area.width > 0 &&
2960 self->pre_fullscreen_area.height > 0);
2962 x = self->pre_fullscreen_area.x;
2963 y = self->pre_fullscreen_area.y;
2964 w = self->pre_fullscreen_area.width;
2965 h = self->pre_fullscreen_area.height;
2966 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
2969 client_setup_decor_and_functions(self, FALSE);
2970 client_move_resize(self, x, y, w, h);
2972 /* and adjust our layer/stacking. do this after resizing the window,
2973 and applying decorations, because windows which fill the screen are
2974 considered "fullscreen" and it affects their layer */
2975 client_calc_layer(self);
2978 /* try focus us when we go into fullscreen mode */
2983 static void client_iconify_recursive(ObClient *self,
2984 gboolean iconic, gboolean curdesk,
2985 gboolean hide_animation)
2988 gboolean changed = FALSE;
2991 if (self->iconic != iconic) {
2992 ob_debug("%sconifying window: 0x%lx\n", (iconic ? "I" : "Uni"),
2996 /* don't let non-normal windows iconify along with their parents
2998 if (client_normal(self)) {
2999 self->iconic = iconic;
3001 /* update the focus lists.. iconic windows go to the bottom of
3003 focus_order_to_bottom(self);
3008 self->iconic = iconic;
3010 if (curdesk && self->desktop != screen_desktop &&
3011 self->desktop != DESKTOP_ALL)
3012 client_set_desktop(self, screen_desktop, FALSE);
3014 /* this puts it after the current focused window */
3015 focus_order_remove(self);
3016 focus_order_add_new(self);
3023 client_change_state(self);
3024 if (config_animate_iconify && !hide_animation)
3025 frame_begin_iconify_animation(self->frame, iconic);
3026 /* do this after starting the animation so it doesn't flash */
3027 client_showhide(self);
3030 /* iconify all direct transients, and deiconify all transients
3032 for (it = self->transients; it; it = g_slist_next(it))
3033 if (it->data != self)
3034 if (client_is_direct_child(self, it->data) || !iconic)
3035 client_iconify_recursive(it->data, iconic, curdesk,
3039 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3040 gboolean hide_animation)
3042 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3043 /* move up the transient chain as far as possible first */
3044 self = client_search_top_normal_parent(self);
3045 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3049 void client_maximize(ObClient *self, gboolean max, gint dir)
3053 g_assert(dir == 0 || dir == 1 || dir == 2);
3054 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
3056 /* check if already done */
3058 if (dir == 0 && self->max_horz && self->max_vert) return;
3059 if (dir == 1 && self->max_horz) return;
3060 if (dir == 2 && self->max_vert) return;
3062 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3063 if (dir == 1 && !self->max_horz) return;
3064 if (dir == 2 && !self->max_vert) return;
3067 /* these will help configure_full figure out which screen to fill with
3071 w = self->area.width;
3072 h = self->area.height;
3075 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3076 RECT_SET(self->pre_max_area,
3077 self->area.x, self->pre_max_area.y,
3078 self->area.width, self->pre_max_area.height);
3080 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3081 RECT_SET(self->pre_max_area,
3082 self->pre_max_area.x, self->area.y,
3083 self->pre_max_area.width, self->area.height);
3086 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3087 g_assert(self->pre_max_area.width > 0);
3089 x = self->pre_max_area.x;
3090 w = self->pre_max_area.width;
3092 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3093 0, self->pre_max_area.height);
3095 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3096 g_assert(self->pre_max_area.height > 0);
3098 y = self->pre_max_area.y;
3099 h = self->pre_max_area.height;
3101 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3102 self->pre_max_area.width, 0);
3106 if (dir == 0 || dir == 1) /* horz */
3107 self->max_horz = max;
3108 if (dir == 0 || dir == 2) /* vert */
3109 self->max_vert = max;
3111 client_change_state(self); /* change the state hints on the client */
3113 client_setup_decor_and_functions(self, FALSE);
3114 client_move_resize(self, x, y, w, h);
3117 void client_shade(ObClient *self, gboolean shade)
3119 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3120 shade) || /* can't shade */
3121 self->shaded == shade) return; /* already done */
3123 self->shaded = shade;
3124 client_change_state(self);
3125 client_change_wm_state(self); /* the window is being hidden/shown */
3126 /* resize the frame to just the titlebar */
3127 frame_adjust_area(self->frame, FALSE, FALSE, FALSE);
3130 void client_close(ObClient *self)
3134 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3136 /* in the case that the client provides no means to requesting that it
3137 close, we just kill it */
3138 if (!self->delete_window)
3142 XXX: itd be cool to do timeouts and shit here for killing the client's
3144 like... if the window is around after 5 seconds, then the close button
3145 turns a nice red, and if this function is called again, the client is
3149 ce.xclient.type = ClientMessage;
3150 ce.xclient.message_type = prop_atoms.wm_protocols;
3151 ce.xclient.display = ob_display;
3152 ce.xclient.window = self->window;
3153 ce.xclient.format = 32;
3154 ce.xclient.data.l[0] = prop_atoms.wm_delete_window;
3155 ce.xclient.data.l[1] = event_curtime;
3156 ce.xclient.data.l[2] = 0l;
3157 ce.xclient.data.l[3] = 0l;
3158 ce.xclient.data.l[4] = 0l;
3159 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
3162 void client_kill(ObClient *self)
3164 XKillClient(ob_display, self->window);
3167 void client_hilite(ObClient *self, gboolean hilite)
3169 if (self->demands_attention == hilite)
3170 return; /* no change */
3172 /* don't allow focused windows to hilite */
3173 self->demands_attention = hilite && !client_focused(self);
3174 if (self->frame != NULL) { /* if we're mapping, just set the state */
3175 if (self->demands_attention)
3176 frame_flash_start(self->frame);
3178 frame_flash_stop(self->frame);
3179 client_change_state(self);
3183 void client_set_desktop_recursive(ObClient *self,
3190 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3192 ob_debug("Setting desktop %u\n", target+1);
3194 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3196 old = self->desktop;
3197 self->desktop = target;
3198 PROP_SET32(self->window, net_wm_desktop, cardinal, target);
3199 /* the frame can display the current desktop state */
3200 frame_adjust_state(self->frame);
3201 /* 'move' the window to the new desktop */
3203 client_showhide(self);
3204 /* raise if it was not already on the desktop */
3205 if (old != DESKTOP_ALL)
3206 stacking_raise(CLIENT_AS_WINDOW(self));
3207 if (STRUT_EXISTS(self->strut))
3208 screen_update_areas();
3211 /* move all transients */
3212 for (it = self->transients; it; it = g_slist_next(it))
3213 if (it->data != self)
3214 if (client_is_direct_child(self, it->data))
3215 client_set_desktop_recursive(it->data, target, donthide);
3218 void client_set_desktop(ObClient *self, guint target,
3221 self = client_search_top_normal_parent(self);
3222 client_set_desktop_recursive(self, target, donthide);
3225 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3227 while (child != parent &&
3228 child->transient_for && child->transient_for != OB_TRAN_GROUP)
3229 child = child->transient_for;
3230 return child == parent;
3233 ObClient *client_search_modal_child(ObClient *self)
3238 for (it = self->transients; it; it = g_slist_next(it)) {
3239 ObClient *c = it->data;
3240 if ((ret = client_search_modal_child(c))) return ret;
3241 if (c->modal) return c;
3246 gboolean client_validate(ObClient *self)
3250 XSync(ob_display, FALSE); /* get all events on the server */
3252 if (XCheckTypedWindowEvent(ob_display, self->window, DestroyNotify, &e) ||
3253 XCheckTypedWindowEvent(ob_display, self->window, UnmapNotify, &e)) {
3254 XPutBackEvent(ob_display, &e);
3261 void client_set_wm_state(ObClient *self, glong state)
3263 if (state == self->wmstate) return; /* no change */
3267 client_iconify(self, TRUE, TRUE, FALSE);
3270 client_iconify(self, FALSE, TRUE, FALSE);
3275 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3277 gboolean shaded = self->shaded;
3278 gboolean fullscreen = self->fullscreen;
3279 gboolean undecorated = self->undecorated;
3280 gboolean max_horz = self->max_horz;
3281 gboolean max_vert = self->max_vert;
3282 gboolean modal = self->modal;
3283 gboolean iconic = self->iconic;
3284 gboolean demands_attention = self->demands_attention;
3285 gboolean above = self->above;
3286 gboolean below = self->below;
3289 if (!(action == prop_atoms.net_wm_state_add ||
3290 action == prop_atoms.net_wm_state_remove ||
3291 action == prop_atoms.net_wm_state_toggle))
3292 /* an invalid action was passed to the client message, ignore it */
3295 for (i = 0; i < 2; ++i) {
3296 Atom state = i == 0 ? data1 : data2;
3298 if (!state) continue;
3300 /* if toggling, then pick whether we're adding or removing */
3301 if (action == prop_atoms.net_wm_state_toggle) {
3302 if (state == prop_atoms.net_wm_state_modal)
3303 action = modal ? prop_atoms.net_wm_state_remove :
3304 prop_atoms.net_wm_state_add;
3305 else if (state == prop_atoms.net_wm_state_maximized_vert)
3306 action = self->max_vert ? prop_atoms.net_wm_state_remove :
3307 prop_atoms.net_wm_state_add;
3308 else if (state == prop_atoms.net_wm_state_maximized_horz)
3309 action = self->max_horz ? prop_atoms.net_wm_state_remove :
3310 prop_atoms.net_wm_state_add;
3311 else if (state == prop_atoms.net_wm_state_shaded)
3312 action = shaded ? prop_atoms.net_wm_state_remove :
3313 prop_atoms.net_wm_state_add;
3314 else if (state == prop_atoms.net_wm_state_skip_taskbar)
3315 action = self->skip_taskbar ?
3316 prop_atoms.net_wm_state_remove :
3317 prop_atoms.net_wm_state_add;
3318 else if (state == prop_atoms.net_wm_state_skip_pager)
3319 action = self->skip_pager ?
3320 prop_atoms.net_wm_state_remove :
3321 prop_atoms.net_wm_state_add;
3322 else if (state == prop_atoms.net_wm_state_hidden)
3323 action = self->iconic ?
3324 prop_atoms.net_wm_state_remove :
3325 prop_atoms.net_wm_state_add;
3326 else if (state == prop_atoms.net_wm_state_fullscreen)
3327 action = fullscreen ?
3328 prop_atoms.net_wm_state_remove :
3329 prop_atoms.net_wm_state_add;
3330 else if (state == prop_atoms.net_wm_state_above)
3331 action = self->above ? prop_atoms.net_wm_state_remove :
3332 prop_atoms.net_wm_state_add;
3333 else if (state == prop_atoms.net_wm_state_below)
3334 action = self->below ? prop_atoms.net_wm_state_remove :
3335 prop_atoms.net_wm_state_add;
3336 else if (state == prop_atoms.net_wm_state_demands_attention)
3337 action = self->demands_attention ?
3338 prop_atoms.net_wm_state_remove :
3339 prop_atoms.net_wm_state_add;
3340 else if (state == prop_atoms.ob_wm_state_undecorated)
3341 action = undecorated ? prop_atoms.net_wm_state_remove :
3342 prop_atoms.net_wm_state_add;
3345 if (action == prop_atoms.net_wm_state_add) {
3346 if (state == prop_atoms.net_wm_state_modal) {
3348 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
3350 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
3352 } else if (state == prop_atoms.net_wm_state_shaded) {
3354 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
3355 self->skip_taskbar = TRUE;
3356 } else if (state == prop_atoms.net_wm_state_skip_pager) {
3357 self->skip_pager = TRUE;
3358 } else if (state == prop_atoms.net_wm_state_hidden) {
3360 } else if (state == prop_atoms.net_wm_state_fullscreen) {
3362 } else if (state == prop_atoms.net_wm_state_above) {
3365 } else if (state == prop_atoms.net_wm_state_below) {
3368 } else if (state == prop_atoms.net_wm_state_demands_attention) {
3369 demands_attention = TRUE;
3370 } else if (state == prop_atoms.ob_wm_state_undecorated) {
3374 } else { /* action == prop_atoms.net_wm_state_remove */
3375 if (state == prop_atoms.net_wm_state_modal) {
3377 } else if (state == prop_atoms.net_wm_state_maximized_vert) {
3379 } else if (state == prop_atoms.net_wm_state_maximized_horz) {
3381 } else if (state == prop_atoms.net_wm_state_shaded) {
3383 } else if (state == prop_atoms.net_wm_state_skip_taskbar) {
3384 self->skip_taskbar = FALSE;
3385 } else if (state == prop_atoms.net_wm_state_skip_pager) {
3386 self->skip_pager = FALSE;
3387 } else if (state == prop_atoms.net_wm_state_hidden) {
3389 } else if (state == prop_atoms.net_wm_state_fullscreen) {
3391 } else if (state == prop_atoms.net_wm_state_above) {
3393 } else if (state == prop_atoms.net_wm_state_below) {
3395 } else if (state == prop_atoms.net_wm_state_demands_attention) {
3396 demands_attention = FALSE;
3397 } else if (state == prop_atoms.ob_wm_state_undecorated) {
3398 undecorated = FALSE;
3403 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3404 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3406 if (max_horz == max_vert) { /* both going the same way */
3407 client_maximize(self, max_horz, 0);
3409 client_maximize(self, max_horz, 1);
3410 client_maximize(self, max_vert, 2);
3414 if (max_horz != self->max_horz)
3415 client_maximize(self, max_horz, 1);
3417 client_maximize(self, max_vert, 2);
3420 /* change fullscreen state before shading, as it will affect if the window
3422 if (fullscreen != self->fullscreen)
3423 client_fullscreen(self, fullscreen);
3424 if (shaded != self->shaded)
3425 client_shade(self, shaded);
3426 if (undecorated != self->undecorated)
3427 client_set_undecorated(self, undecorated);
3428 if (above != self->above || below != self->below) {
3429 self->above = above;
3430 self->below = below;
3431 client_calc_layer(self);
3434 if (modal != self->modal) {
3435 self->modal = modal;
3436 /* when a window changes modality, then its stacking order with its
3437 transients needs to change */
3438 stacking_raise(CLIENT_AS_WINDOW(self));
3440 /* it also may get focused. if something is focused that shouldn't
3441 be focused anymore, then move the focus */
3442 if (focus_client && client_focus_target(focus_client) != focus_client)
3443 client_focus(focus_client);
3446 if (iconic != self->iconic)
3447 client_iconify(self, iconic, FALSE, FALSE);
3449 if (demands_attention != self->demands_attention)
3450 client_hilite(self, demands_attention);
3452 client_change_state(self); /* change the hint to reflect these changes */
3455 ObClient *client_focus_target(ObClient *self)
3457 ObClient *child = NULL;
3459 child = client_search_modal_child(self);
3460 if (child) return child;
3464 gboolean client_can_focus(ObClient *self)
3466 /* choose the correct target */
3467 self = client_focus_target(self);
3469 if (!self->frame->visible)
3472 if (!(self->can_focus || self->focus_notify))
3478 gboolean client_focus(ObClient *self)
3480 /* we might not focus this window, so if we have modal children which would
3481 be focused instead, bring them to this desktop */
3482 client_bring_modal_windows(self);
3484 /* choose the correct target */
3485 self = client_focus_target(self);
3487 if (!client_can_focus(self)) {
3488 if (!self->frame->visible) {
3489 /* update the focus lists */
3490 focus_order_to_top(self);
3492 ob_debug_type(OB_DEBUG_FOCUS,
3493 "Client %s can't be focused\n", self->title);
3497 ob_debug_type(OB_DEBUG_FOCUS,
3498 "Focusing client \"%s\" (0x%x) at time %u\n",
3499 self->title, self->window, event_curtime);
3501 /* if there is a grab going on, then we need to cancel it. if we move
3502 focus during the grab, applications will get NotifyWhileGrabbed events
3505 actions should not rely on being able to move focus during an
3508 event_cancel_all_key_grabs();
3510 xerror_set_ignore(TRUE);
3511 xerror_occured = FALSE;
3513 if (self->can_focus) {
3514 /* This can cause a BadMatch error with CurrentTime, or if an app
3515 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3516 XSetInputFocus(ob_display, self->window, RevertToPointerRoot,
3520 if (self->focus_notify) {
3522 ce.xclient.type = ClientMessage;
3523 ce.xclient.message_type = prop_atoms.wm_protocols;
3524 ce.xclient.display = ob_display;
3525 ce.xclient.window = self->window;
3526 ce.xclient.format = 32;
3527 ce.xclient.data.l[0] = prop_atoms.wm_take_focus;
3528 ce.xclient.data.l[1] = event_curtime;
3529 ce.xclient.data.l[2] = 0l;
3530 ce.xclient.data.l[3] = 0l;
3531 ce.xclient.data.l[4] = 0l;
3532 XSendEvent(ob_display, self->window, FALSE, NoEventMask, &ce);
3535 xerror_set_ignore(FALSE);
3537 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d\n", xerror_occured);
3538 return !xerror_occured;
3541 /*! Present the client to the user.
3542 @param raise If the client should be raised or not. You should only set
3543 raise to false if you don't care if the window is completely
3546 static void client_present(ObClient *self, gboolean here, gboolean raise)
3548 /* if using focus_delay, stop the timer now so that focus doesn't
3550 event_halt_focus_delay();
3552 if (client_normal(self) && screen_showing_desktop)
3553 screen_show_desktop(FALSE, self);
3555 client_iconify(self, FALSE, here, FALSE);
3556 if (self->desktop != DESKTOP_ALL &&
3557 self->desktop != screen_desktop)
3560 client_set_desktop(self, screen_desktop, FALSE);
3562 screen_set_desktop(self->desktop, FALSE);
3563 } else if (!self->frame->visible)
3564 /* if its not visible for other reasons, then don't mess
3568 client_shade(self, FALSE);
3570 stacking_raise(CLIENT_AS_WINDOW(self));
3575 void client_activate(ObClient *self, gboolean here, gboolean user)
3577 guint32 last_time = focus_client ? focus_client->user_time : CurrentTime;
3578 gboolean allow = FALSE;
3580 /* if the request came from the user, or if nothing is focused, then grant
3582 if the currently focused app doesn't set a user_time, then it can't
3583 benefit from any focus stealing prevention.
3585 if (user || !focus_client || !last_time)
3587 /* otherwise, if they didn't give a time stamp or if it is too old, they
3590 allow = event_curtime && event_time_after(event_curtime, last_time);
3592 ob_debug_type(OB_DEBUG_FOCUS,
3593 "Want to activate window 0x%x with time %u (last time %u), "
3594 "source=%s allowing? %d\n",
3595 self->window, event_curtime, last_time,
3596 (user ? "user" : "application"), allow);
3599 client_present(self, here, TRUE);
3601 /* don't focus it but tell the user it wants attention */
3602 client_hilite(self, TRUE);
3605 static void client_bring_windows_recursive(ObClient *self,
3612 for (it = self->transients; it; it = g_slist_next(it))
3613 client_bring_windows_recursive(it->data, desktop, helpers, modals);
3615 if (((helpers && client_helper(self)) ||
3616 (modals && self->modal))&&
3617 self->desktop != desktop && self->desktop != DESKTOP_ALL)
3619 client_set_desktop(self, desktop, FALSE);
3623 void client_bring_helper_windows(ObClient *self)
3625 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE);
3628 void client_bring_modal_windows(ObClient *self)
3630 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE);
3633 gboolean client_focused(ObClient *self)
3635 return self == focus_client;
3638 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
3641 gulong min_diff, min_i;
3643 if (!self->nicons) {
3644 ObClientIcon *parent = NULL;
3646 if (self->transient_for) {
3647 if (self->transient_for != OB_TRAN_GROUP)
3648 parent = client_icon_recursive(self->transient_for, w, h);
3651 for (it = self->group->members; it; it = g_slist_next(it)) {
3652 ObClient *c = it->data;
3653 if (c != self && !c->transient_for) {
3654 if ((parent = client_icon_recursive(c, w, h)))
3664 /* some kind of crappy approximation to find the icon closest in size to
3665 what we requested, but icons are generally all the same ratio as
3666 eachother so it's good enough. */
3668 min_diff = ABS(self->icons[0].width - w) + ABS(self->icons[0].height - h);
3671 for (i = 1; i < self->nicons; ++i) {
3674 diff = ABS(self->icons[i].width - w) + ABS(self->icons[i].height - h);
3675 if (diff < min_diff) {
3680 return &self->icons[min_i];
3683 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
3686 static ObClientIcon deficon;
3688 if (!(ret = client_icon_recursive(self, w, h))) {
3689 deficon.width = deficon.height = 48;
3690 deficon.data = ob_rr_theme->def_win_icon;
3696 void client_set_layer(ObClient *self, gint layer)
3700 self->above = FALSE;
3701 } else if (layer == 0) {
3702 self->below = self->above = FALSE;
3704 self->below = FALSE;
3707 client_calc_layer(self);
3708 client_change_state(self); /* reflect this in the state hints */
3711 void client_set_undecorated(ObClient *self, gboolean undecorated)
3713 if (self->undecorated != undecorated &&
3714 /* don't let it undecorate if the function is missing, but let
3716 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
3718 self->undecorated = undecorated;
3719 client_setup_decor_and_functions(self, TRUE);
3720 client_change_state(self); /* reflect this in the state hints */
3724 guint client_monitor(ObClient *self)
3726 return screen_find_monitor(&self->frame->area);
3729 ObClient *client_search_top_normal_parent(ObClient *self)
3731 while (self->transient_for && self->transient_for != OB_TRAN_GROUP &&
3732 client_normal(self->transient_for))
3733 self = self->transient_for;
3737 static GSList *client_search_all_top_parents_internal(ObClient *self,
3739 ObStackingLayer layer)
3743 /* move up the direct transient chain as far as possible */
3744 while (self->transient_for && self->transient_for != OB_TRAN_GROUP &&
3745 (!bylayer || self->transient_for->layer == layer) &&
3746 client_normal(self->transient_for))
3747 self = self->transient_for;
3749 if (!self->transient_for)
3750 ret = g_slist_prepend(ret, self);
3754 g_assert(self->group);
3756 for (it = self->group->members; it; it = g_slist_next(it)) {
3757 ObClient *c = it->data;
3759 if (!c->transient_for && client_normal(c) &&
3760 (!bylayer || c->layer == layer))
3762 ret = g_slist_prepend(ret, c);
3766 if (ret == NULL) /* no group parents */
3767 ret = g_slist_prepend(ret, self);
3773 GSList *client_search_all_top_parents(ObClient *self)
3775 return client_search_all_top_parents_internal(self, FALSE, 0);
3778 GSList *client_search_all_top_parents_layer(ObClient *self)
3780 return client_search_all_top_parents_internal(self, TRUE, self->layer);
3783 ObClient *client_search_focus_parent(ObClient *self)
3785 if (self->transient_for) {
3786 if (self->transient_for != OB_TRAN_GROUP) {
3787 if (client_focused(self->transient_for))
3788 return self->transient_for;
3792 for (it = self->group->members; it; it = g_slist_next(it)) {
3793 ObClient *c = it->data;
3795 /* checking transient_for prevents infinate loops! */
3796 if (c != self && !c->transient_for)
3797 if (client_focused(c))
3806 ObClient *client_search_parent(ObClient *self, ObClient *search)
3808 if (self->transient_for) {
3809 if (self->transient_for != OB_TRAN_GROUP) {
3810 if (self->transient_for == search)
3815 for (it = self->group->members; it; it = g_slist_next(it)) {
3816 ObClient *c = it->data;
3818 /* checking transient_for prevents infinate loops! */
3819 if (c != self && !c->transient_for)
3829 ObClient *client_search_transient(ObClient *self, ObClient *search)
3833 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
3834 if (sit->data == search)
3836 if (client_search_transient(sit->data, search))
3842 #define WANT_EDGE(cur, c) \
3845 if(!client_normal(cur)) \
3847 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3852 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3853 if ((his_edge_start >= my_edge_start && \
3854 his_edge_start <= my_edge_end) || \
3855 (my_edge_start >= his_edge_start && \
3856 my_edge_start <= his_edge_end)) \
3859 /* finds the nearest edge in the given direction from the current client
3860 * note to self: the edge is the -frame- edge (the actual one), not the
3863 gint client_directional_edge_search(ObClient *c, ObDirection dir, gboolean hang)
3865 gint dest, monitor_dest;
3866 gint my_edge_start, my_edge_end, my_offset;
3873 a = screen_area(c->desktop);
3874 monitor = screen_area_monitor(c->desktop, client_monitor(c));
3877 case OB_DIRECTION_NORTH:
3878 my_edge_start = c->frame->area.x;
3879 my_edge_end = c->frame->area.x + c->frame->area.width;
3880 my_offset = c->frame->area.y + (hang ? c->frame->area.height : 0);
3882 /* default: top of screen */
3883 dest = a->y + (hang ? c->frame->area.height : 0);
3884 monitor_dest = monitor->y + (hang ? c->frame->area.height : 0);
3885 /* if the monitor edge comes before the screen edge, */
3886 /* use that as the destination instead. (For xinerama) */
3887 if (monitor_dest != dest && my_offset > monitor_dest)
3888 dest = monitor_dest;
3890 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3891 gint his_edge_start, his_edge_end, his_offset;
3892 ObClient *cur = it->data;
3896 his_edge_start = cur->frame->area.x;
3897 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3898 his_offset = cur->frame->area.y +
3899 (hang ? 0 : cur->frame->area.height);
3901 if(his_offset + 1 > my_offset)
3904 if(his_offset < dest)
3907 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3910 case OB_DIRECTION_SOUTH:
3911 my_edge_start = c->frame->area.x;
3912 my_edge_end = c->frame->area.x + c->frame->area.width;
3913 my_offset = c->frame->area.y + (hang ? 0 : c->frame->area.height);
3915 /* default: bottom of screen */
3916 dest = a->y + a->height - (hang ? c->frame->area.height : 0);
3917 monitor_dest = monitor->y + monitor->height -
3918 (hang ? c->frame->area.height : 0);
3919 /* if the monitor edge comes before the screen edge, */
3920 /* use that as the destination instead. (For xinerama) */
3921 if (monitor_dest != dest && my_offset < monitor_dest)
3922 dest = monitor_dest;
3924 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3925 gint his_edge_start, his_edge_end, his_offset;
3926 ObClient *cur = it->data;
3930 his_edge_start = cur->frame->area.x;
3931 his_edge_end = cur->frame->area.x + cur->frame->area.width;
3932 his_offset = cur->frame->area.y +
3933 (hang ? cur->frame->area.height : 0);
3936 if(his_offset - 1 < my_offset)
3939 if(his_offset > dest)
3942 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3945 case OB_DIRECTION_WEST:
3946 my_edge_start = c->frame->area.y;
3947 my_edge_end = c->frame->area.y + c->frame->area.height;
3948 my_offset = c->frame->area.x + (hang ? c->frame->area.width : 0);
3950 /* default: leftmost egde of screen */
3951 dest = a->x + (hang ? c->frame->area.width : 0);
3952 monitor_dest = monitor->x + (hang ? c->frame->area.width : 0);
3953 /* if the monitor edge comes before the screen edge, */
3954 /* use that as the destination instead. (For xinerama) */
3955 if (monitor_dest != dest && my_offset > monitor_dest)
3956 dest = monitor_dest;
3958 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3959 gint his_edge_start, his_edge_end, his_offset;
3960 ObClient *cur = it->data;
3964 his_edge_start = cur->frame->area.y;
3965 his_edge_end = cur->frame->area.y + cur->frame->area.height;
3966 his_offset = cur->frame->area.x +
3967 (hang ? 0 : cur->frame->area.width);
3969 if(his_offset + 1 > my_offset)
3972 if(his_offset < dest)
3975 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
3978 case OB_DIRECTION_EAST:
3979 my_edge_start = c->frame->area.y;
3980 my_edge_end = c->frame->area.y + c->frame->area.height;
3981 my_offset = c->frame->area.x + (hang ? 0 : c->frame->area.width);
3983 /* default: rightmost edge of screen */
3984 dest = a->x + a->width - (hang ? c->frame->area.width : 0);
3985 monitor_dest = monitor->x + monitor->width -
3986 (hang ? c->frame->area.width : 0);
3987 /* if the monitor edge comes before the screen edge, */
3988 /* use that as the destination instead. (For xinerama) */
3989 if (monitor_dest != dest && my_offset < monitor_dest)
3990 dest = monitor_dest;
3992 for(it = client_list; it && my_offset != dest; it = g_list_next(it)) {
3993 gint his_edge_start, his_edge_end, his_offset;
3994 ObClient *cur = it->data;
3998 his_edge_start = cur->frame->area.y;
3999 his_edge_end = cur->frame->area.y + cur->frame->area.height;
4000 his_offset = cur->frame->area.x +
4001 (hang ? cur->frame->area.width : 0);
4003 if(his_offset - 1 < my_offset)
4006 if(his_offset > dest)
4009 HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end)
4012 case OB_DIRECTION_NORTHEAST:
4013 case OB_DIRECTION_SOUTHEAST:
4014 case OB_DIRECTION_NORTHWEST:
4015 case OB_DIRECTION_SOUTHWEST:
4016 /* not implemented */
4018 g_assert_not_reached();
4019 dest = 0; /* suppress warning */
4024 ObClient* client_under_pointer()
4028 ObClient *ret = NULL;
4030 if (screen_pointer_pos(&x, &y)) {
4031 for (it = stacking_list; it; it = g_list_next(it)) {
4032 if (WINDOW_IS_CLIENT(it->data)) {
4033 ObClient *c = WINDOW_AS_CLIENT(it->data);
4034 if (c->frame->visible &&
4035 /* ignore all animating windows */
4036 !frame_iconify_animating(c->frame) &&
4037 RECT_CONTAINS(c->frame->area, x, y))
4048 gboolean client_has_group_siblings(ObClient *self)
4050 return self->group && self->group->members->next;