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"
25 #include "moveresize.h"
38 #include "menuframe.h"
41 #include "render/render.h"
43 #include "obt/display.h"
51 # include <signal.h> /* for kill() */
55 #include <X11/Xutil.h>
57 /*! The event mask to grab on client windows */
58 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
61 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
66 ObClientCallback func;
70 GList *client_list = NULL;
72 static GSList *client_destroy_notifies = NULL;
74 static void client_get_all(ObClient *self, gboolean real);
75 static void client_get_startup_id(ObClient *self);
76 static void client_get_session_ids(ObClient *self);
77 static void client_get_area(ObClient *self);
78 static void client_get_desktop(ObClient *self);
79 static void client_get_state(ObClient *self);
80 static void client_get_shaped(ObClient *self);
81 static void client_get_mwm_hints(ObClient *self);
82 static void client_get_colormap(ObClient *self);
83 static void client_set_desktop_recursive(ObClient *self,
87 static void client_change_allowed_actions(ObClient *self);
88 static void client_change_state(ObClient *self);
89 static void client_change_wm_state(ObClient *self);
90 static void client_apply_startup_state(ObClient *self,
91 gint x, gint y, gint w, gint h);
92 static void client_restore_session_state(ObClient *self);
93 static gboolean client_restore_session_stacking(ObClient *self);
94 static ObAppSettings *client_get_settings_state(ObClient *self);
95 static void client_update_transient_tree(ObClient *self,
96 ObGroup *oldgroup, ObGroup *newgroup,
97 gboolean oldgtran, gboolean newgtran,
100 static void client_present(ObClient *self, gboolean here, gboolean raise,
102 static GSList *client_search_all_top_parents_internal(ObClient *self,
104 ObStackingLayer layer);
105 static void client_call_notifies(ObClient *self, GSList *list);
106 static void client_ping_event(ObClient *self, gboolean dead);
107 static void client_prompt_kill(ObClient *self);
110 void client_startup(gboolean reconfig)
112 if (reconfig) return;
117 void client_shutdown(gboolean reconfig)
119 if (reconfig) return;
122 static void client_call_notifies(ObClient *self, GSList *list)
126 for (it = list; it; it = g_slist_next(it)) {
127 ClientCallback *d = it->data;
128 d->func(self, d->data);
132 void client_add_destroy_notify(ObClientCallback func, gpointer data)
134 ClientCallback *d = g_new(ClientCallback, 1);
137 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
140 void client_remove_destroy_notify(ObClientCallback func)
144 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
145 ClientCallback *d = it->data;
146 if (d->func == func) {
148 client_destroy_notifies =
149 g_slist_delete_link(client_destroy_notifies, it);
155 void client_set_list(void)
157 Window *windows, *win_it;
159 guint size = g_list_length(client_list);
161 /* create an array of the window ids */
163 windows = g_new(Window, size);
165 for (it = client_list; it; it = g_list_next(it), ++win_it)
166 *win_it = ((ObClient*)it->data)->window;
170 OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW,
171 (gulong*)windows, size);
179 void client_manage(Window window, ObPrompt *prompt)
182 XSetWindowAttributes attrib_set;
183 gboolean activate = FALSE;
184 ObAppSettings *settings;
185 gboolean transient = FALSE;
186 Rect place, *monitor;
187 Time launch_time, map_time;
189 ob_debug("Managing window: 0x%lx", window);
191 map_time = event_get_server_time();
193 /* choose the events we want to receive on the CLIENT window
194 (ObPrompt windows can request events too) */
195 attrib_set.event_mask = CLIENT_EVENTMASK |
196 (prompt ? prompt->event_mask : 0);
197 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
198 XChangeWindowAttributes(obt_display, window,
199 CWEventMask|CWDontPropagate, &attrib_set);
201 /* create the ObClient struct, and populate it from the hints on the
203 self = g_new0(ObClient, 1);
204 self->obwin.type = OB_WINDOW_CLASS_CLIENT;
205 self->window = window;
206 self->prompt = prompt;
208 /* non-zero defaults */
209 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
210 self->gravity = NorthWestGravity;
211 self->desktop = screen_num_desktops; /* always an invalid value */
213 /* get all the stuff off the window */
214 client_get_all(self, TRUE);
216 ob_debug("Window type: %d", self->type);
217 ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
219 /* now we have all of the window's information so we can set this up.
220 do this before creating the frame, so it can tell that we are still
221 mapping and doesn't go applying things right away */
222 client_setup_decor_and_functions(self, FALSE);
224 /* specify that if we exit, the window should not be destroyed and
225 should be reparented back to root automatically, unless we are managing
226 an internal ObPrompt window */
228 XChangeSaveSet(obt_display, window, SetModeInsert);
230 /* create the decoration frame for the client window */
231 self->frame = frame_new(self);
233 frame_grab_client(self->frame);
235 /* we've grabbed everything and set everything that we need to at mapping
239 /* per-app settings override stuff from client_get_all, and return the
240 settings for other uses too. the returned settings is a shallow copy,
241 that needs to be freed with g_free(). */
242 settings = client_get_settings_state(self);
243 /* the session should get the last say though */
244 client_restore_session_state(self);
246 /* tell startup notification that this app started */
247 launch_time = sn_app_started(self->startup_id, self->class, self->name);
249 /* do this after we have a frame.. it uses the frame to help determine the
250 WM_STATE to apply. */
251 client_change_state(self);
253 /* add ourselves to the focus order */
254 focus_order_add_new(self);
256 /* do this to add ourselves to the stacking list in a non-intrusive way */
257 client_calc_layer(self);
259 /* focus the new window? */
260 if (ob_state() != OB_STATE_STARTING &&
261 (!self->session || self->session->focused) &&
262 /* this means focus=true for window is same as config_focus_new=true */
263 ((config_focus_new || (settings && settings->focus == 1)) ||
264 client_search_focus_tree_full(self)) &&
265 /* this checks for focus=false for the window */
266 (!settings || settings->focus != 0) &&
267 focus_valid_target(self, FALSE, FALSE, TRUE, FALSE, FALSE))
272 /* remove the client's border */
273 XSetWindowBorderWidth(obt_display, self->window, 0);
275 /* adjust the frame to the client's size before showing or placing
277 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
278 frame_adjust_client_area(self->frame);
280 /* where the frame was placed is where the window was originally */
282 monitor = screen_physical_area_monitor(screen_find_monitor(&place));
284 /* figure out placement for the window if the window is new */
285 if (ob_state() == OB_STATE_RUNNING) {
286 ob_debug("Positioned: %s @ %d %d",
287 (!self->positioned ? "no" :
288 (self->positioned == PPosition ? "program specified" :
289 (self->positioned == USPosition ? "user specified" :
290 (self->positioned == (PPosition | USPosition) ?
291 "program + user specified" :
292 "BADNESS !?")))), place.x, place.y);
294 ob_debug("Sized: %s @ %d %d",
295 (!self->sized ? "no" :
296 (self->sized == PSize ? "program specified" :
297 (self->sized == USSize ? "user specified" :
298 (self->sized == (PSize | USSize) ?
299 "program + user specified" :
300 "BADNESS !?")))), place.width, place.height);
302 /* splash screens are also returned as TRUE for transient,
303 and so will be forced on screen below */
304 transient = place_client(self, &place.x, &place.y, settings);
306 /* make sure the window is visible. */
307 client_find_onscreen(self, &place.x, &place.y,
308 place.width, place.height,
309 /* non-normal clients has less rules, and
310 windows that are being restored from a
311 session do also. we can assume you want
312 it back where you saved it. Clients saying
313 they placed themselves are subjected to
314 harder rules, ones that are placed by
315 place.c or by the user are allowed partially
316 off-screen and on xinerama divides (ie,
317 it is up to the placement routines to avoid
318 the xinerama divides)
320 splash screens get "transient" set to TRUE by
321 the place_client call
323 ob_state() == OB_STATE_RUNNING &&
325 (!((self->positioned & USPosition) ||
326 (settings && settings->pos_given)) &&
327 client_normal(self) &&
329 /* don't move oldschool fullscreen windows to
330 fit inside the struts (fixes Acroread, which
331 makes its fullscreen window fit the screen
332 but it is not USSize'd or USPosition'd) */
333 !(self->decorations == 0 &&
334 RECT_EQUAL(place, *monitor)))));
337 /* if the window isn't user-sized, then make it fit inside
338 the visible screen area on its monitor. Use basically the same rules
339 for forcing the window on screen in the client_find_onscreen call.
341 do this after place_client, it chooses the monitor!
343 splash screens get "transient" set to TRUE by
344 the place_client call
346 if (ob_state() == OB_STATE_RUNNING &&
348 (!(self->sized & USSize || self->positioned & USPosition) &&
349 client_normal(self) &&
351 /* don't shrink oldschool fullscreen windows to fit inside the
352 struts (fixes Acroread, which makes its fullscreen window
353 fit the screen but it is not USSize'd or USPosition'd) */
354 !(self->decorations == 0 && RECT_EQUAL(place, *monitor)))))
356 Rect *a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &place);
358 /* get the size of the frame */
359 place.width += self->frame->size.left + self->frame->size.right;
360 place.height += self->frame->size.top + self->frame->size.bottom;
362 /* fit the window inside the area */
363 place.width = MIN(place.width, a->width);
364 place.height = MIN(place.height, a->height);
366 ob_debug("setting window size to %dx%d", place.width, place.height);
368 /* get the size of the client back */
369 place.width -= self->frame->size.left + self->frame->size.right;
370 place.height -= self->frame->size.top + self->frame->size.bottom;
375 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
376 "some restrictions may apply",
377 self->window, place.x, place.y, place.width, place.height);
379 ob_debug(" but session requested %d, %d %d x %d instead, "
381 self->session->x, self->session->y,
382 self->session->w, self->session->h);
384 /* do this after the window is placed, so the premax/prefullscreen numbers
387 this also places the window
389 client_apply_startup_state(self, place.x, place.y,
390 place.width, place.height);
395 ob_debug_type(OB_DEBUG_FOCUS, "Going to try activate new window? %s",
396 activate ? "yes" : "no");
398 gboolean raise = FALSE;
400 /* This is focus stealing prevention */
401 ob_debug_type(OB_DEBUG_FOCUS,
402 "Want to focus new window 0x%x at time %u "
403 "launched at %u (last user interaction time %u)",
404 self->window, map_time, launch_time,
405 event_last_user_time);
407 if (menu_frame_visible || moveresize_in_progress) {
410 ob_debug_type(OB_DEBUG_FOCUS,
411 "Not focusing the window because the user is inside "
412 "an Openbox menu or is move/resizing a window and "
413 "we don't want to interrupt them");
416 /* if it's on another desktop */
417 else if (!(self->desktop == screen_desktop ||
418 self->desktop == DESKTOP_ALL) &&
419 /* the timestamp is from before you changed desktops */
420 launch_time && screen_desktop_user_time &&
421 !event_time_after(launch_time, screen_desktop_user_time))
425 ob_debug_type(OB_DEBUG_FOCUS,
426 "Not focusing the window because its on another "
429 /* If something is focused, and it's not our relative... */
430 else if (focus_client && client_search_focus_tree_full(self) == NULL &&
431 client_search_focus_group_full(self) == NULL)
433 /* If the user is working in another window right now, then don't
435 if (event_last_user_time && launch_time &&
436 event_time_after(event_last_user_time, launch_time) &&
437 event_last_user_time != launch_time &&
438 event_time_after(event_last_user_time,
439 map_time - OB_EVENT_USER_TIME_DELAY))
442 ob_debug_type(OB_DEBUG_FOCUS,
443 "Not focusing the window because the user is "
444 "working in another window");
446 /* If its a transient (and its parents aren't focused) */
447 else if (client_has_parent(self)) {
449 ob_debug_type(OB_DEBUG_FOCUS,
450 "Not focusing the window because it is a "
451 "transient, and its relatives aren't focused");
453 /* Don't steal focus from globally active clients.
454 I stole this idea from KWin. It seems nice.
456 else if (!(focus_client->can_focus ||
457 focus_client->focus_notify))
460 ob_debug_type(OB_DEBUG_FOCUS,
461 "Not focusing the window because a globally "
462 "active client has focus");
464 /* Don't move focus if it's not going to go to this window
466 else if (client_focus_target(self) != self) {
469 ob_debug_type(OB_DEBUG_FOCUS,
470 "Not focusing the window because another window "
471 "would get the focus anyway");
473 else if (!(self->desktop == screen_desktop ||
474 self->desktop == DESKTOP_ALL))
478 ob_debug_type(OB_DEBUG_FOCUS,
479 "Not focusing the window because it is on "
480 "another desktop and no relatives are focused ");
485 ob_debug_type(OB_DEBUG_FOCUS,
486 "Focus stealing prevention activated for %s at "
487 "time %u (last user interactioon time %u)",
488 self->title, map_time, event_last_user_time);
489 /* if the client isn't focused, then hilite it so the user
491 client_hilite(self, TRUE);
492 /* we may want to raise it even tho we're not activating it */
493 if (raise && !client_restore_session_stacking(self))
494 stacking_raise(CLIENT_AS_WINDOW(self));
498 /* This may look rather odd. Well it's because new windows are added
499 to the stacking order non-intrusively. If we're not going to focus
500 the new window or hilite it, then we raise it to the top. This will
501 take affect for things that don't get focused like splash screens.
502 Also if you don't have focus_new enabled, then it's going to get
503 raised to the top. Legacy begets legacy I guess?
505 if (!client_restore_session_stacking(self))
506 stacking_raise(CLIENT_AS_WINDOW(self));
509 mouse_grab_for_client(self, TRUE);
511 /* this has to happen before we try focus the window, but we want it to
512 happen after the client's stacking has been determined or it looks bad
516 if (!config_focus_under_mouse)
517 ignore_start = event_start_ignore_all_enters();
521 if (!config_focus_under_mouse)
522 event_end_ignore_all_enters(ignore_start);
526 gboolean stacked = client_restore_session_stacking(self);
527 client_present(self, FALSE, !stacked, TRUE);
530 /* add to client list/map */
531 client_list = g_list_append(client_list, self);
532 window_add(&self->window, CLIENT_AS_WINDOW(self));
534 /* this has to happen after we're in the client_list */
535 if (STRUT_EXISTS(self->strut))
536 screen_update_areas();
538 /* update the list hints */
541 /* free the ObAppSettings shallow copy */
544 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
545 window, self->frame->window, self->class);
549 ObClient *client_fake_manage(Window window)
552 ObAppSettings *settings;
554 ob_debug("Pretend-managing window: %lx", window);
556 /* do this minimal stuff to figure out the client's decorations */
558 self = g_new0(ObClient, 1);
559 self->window = window;
561 client_get_all(self, FALSE);
562 /* per-app settings override stuff, and return the settings for other
563 uses too. this returns a shallow copy that needs to be freed */
564 settings = client_get_settings_state(self);
566 client_setup_decor_and_functions(self, FALSE);
568 /* create the decoration frame for the client window and adjust its size */
569 self->frame = frame_new(self);
570 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
572 ob_debug("gave extents left %d right %d top %d bottom %d",
573 self->frame->size.left, self->frame->size.right,
574 self->frame->size.top, self->frame->size.bottom);
576 /* free the ObAppSettings shallow copy */
582 void client_unmanage_all(void)
584 while (client_list != NULL)
585 client_unmanage(client_list->data);
588 void client_unmanage(ObClient *self)
594 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
595 self->window, self->frame->window,
596 self->class, self->title ? self->title : "");
598 g_assert(self != NULL);
600 /* we dont want events no more. do this before hiding the frame so we
601 don't generate more events */
602 XSelectInput(obt_display, self->window, NoEventMask);
604 /* ignore enter events from the unmap so it doesnt mess with the focus */
605 if (!config_focus_under_mouse)
606 ignore_start = event_start_ignore_all_enters();
608 frame_hide(self->frame);
609 /* flush to send the hide to the server quickly */
612 if (!config_focus_under_mouse)
613 event_end_ignore_all_enters(ignore_start);
615 mouse_grab_for_client(self, FALSE);
617 /* remove the window from our save set, unless we are managing an internal
620 XChangeSaveSet(obt_display, self->window, SetModeDelete);
622 /* update the focus lists */
623 focus_order_remove(self);
624 if (client_focused(self)) {
625 /* don't leave an invalid focus_client */
629 /* if we're prompting to kill the client, close that */
630 prompt_unref(self->kill_prompt);
631 self->kill_prompt = NULL;
633 client_list = g_list_remove(client_list, self);
634 stacking_remove(self);
635 window_remove(self->window);
637 /* once the client is out of the list, update the struts to remove its
639 if (STRUT_EXISTS(self->strut))
640 screen_update_areas();
642 client_call_notifies(self, client_destroy_notifies);
644 /* tell our parent(s) that we're gone */
645 for (it = self->parents; it; it = g_slist_next(it))
646 ((ObClient*)it->data)->transients =
647 g_slist_remove(((ObClient*)it->data)->transients,self);
649 /* tell our transients that we're gone */
650 for (it = self->transients; it; it = g_slist_next(it)) {
651 ((ObClient*)it->data)->parents =
652 g_slist_remove(((ObClient*)it->data)->parents, self);
653 /* we could be keeping our children in a higher layer */
654 client_calc_layer(it->data);
657 /* remove from its group */
659 group_remove(self->group, self);
663 /* restore the window's original geometry so it is not lost */
669 if (self->fullscreen)
670 a = self->pre_fullscreen_area;
671 else if (self->max_horz || self->max_vert) {
672 if (self->max_horz) {
673 a.x = self->pre_max_area.x;
674 a.width = self->pre_max_area.width;
676 if (self->max_vert) {
677 a.y = self->pre_max_area.y;
678 a.height = self->pre_max_area.height;
682 self->fullscreen = self->max_horz = self->max_vert = FALSE;
683 /* let it be moved and resized no matter what */
684 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
685 self->decorations = 0; /* unmanaged windows have no decor */
687 /* give the client its border back */
688 XSetWindowBorderWidth(obt_display, self->window, self->border_width);
690 client_move_resize(self, a.x, a.y, a.width, a.height);
693 /* reparent the window out of the frame, and free the frame */
694 frame_release_client(self->frame);
695 frame_free(self->frame);
698 if (ob_state() != OB_STATE_EXITING) {
699 /* these values should not be persisted across a window
701 OBT_PROP_ERASE(self->window, NET_WM_DESKTOP);
702 OBT_PROP_ERASE(self->window, NET_WM_STATE);
703 OBT_PROP_ERASE(self->window, WM_STATE);
705 /* if we're left in an unmapped state, the client wont be mapped.
706 this is bad, since we will no longer be managing the window on
708 XMapWindow(obt_display, self->window);
711 /* these should not be left on the window ever. other window managers
712 don't necessarily use them and it will mess them up (like compiz) */
713 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_NAME);
714 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_ICON_NAME);
716 /* update the list hints */
719 ob_debug("Unmanaged window 0x%lx", self->window);
721 /* free all data allocated in the client struct */
722 g_slist_free(self->transients);
723 for (j = 0; j < self->nicons; ++j)
724 g_free(self->icons[j].data);
725 if (self->nicons > 0)
727 g_free(self->startup_id);
728 g_free(self->wm_command);
730 g_free(self->icon_title);
731 g_free(self->original_title);
735 g_free(self->client_machine);
736 g_free(self->sm_client_id);
740 void client_fake_unmanage(ObClient *self)
742 /* this is all that got allocated to get the decorations */
744 frame_free(self->frame);
748 /*! Returns a new structure containing the per-app settings for this client.
749 The returned structure needs to be freed with g_free. */
750 static ObAppSettings *client_get_settings_state(ObClient *self)
752 ObAppSettings *settings;
755 settings = config_create_app_settings();
757 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
758 ObAppSettings *app = it->data;
759 gboolean match = TRUE;
761 g_assert(app->name != NULL || app->class != NULL);
763 /* we know that either name or class is not NULL so it will have to
764 match to use the rule */
766 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
768 else if (app->class &&
769 !g_pattern_match(app->class,
770 strlen(self->class), self->class, NULL))
772 else if (app->role &&
773 !g_pattern_match(app->role,
774 strlen(self->role), self->role, NULL))
778 ob_debug("Window matching: %s", app->name);
780 /* copy the settings to our struct, overriding the existing
781 settings if they are not defaults */
782 config_app_settings_copy_non_defaults(app, settings);
786 if (settings->shade != -1)
787 self->shaded = !!settings->shade;
788 if (settings->decor != -1)
789 self->undecorated = !settings->decor;
790 if (settings->iconic != -1)
791 self->iconic = !!settings->iconic;
792 if (settings->skip_pager != -1)
793 self->skip_pager = !!settings->skip_pager;
794 if (settings->skip_taskbar != -1)
795 self->skip_taskbar = !!settings->skip_taskbar;
797 if (settings->max_vert != -1)
798 self->max_vert = !!settings->max_vert;
799 if (settings->max_horz != -1)
800 self->max_horz = !!settings->max_horz;
802 if (settings->fullscreen != -1)
803 self->fullscreen = !!settings->fullscreen;
805 if (settings->desktop) {
806 if (settings->desktop == DESKTOP_ALL)
807 self->desktop = settings->desktop;
808 else if (settings->desktop > 0 &&
809 settings->desktop <= screen_num_desktops)
810 self->desktop = settings->desktop - 1;
813 if (settings->layer == -1) {
817 else if (settings->layer == 0) {
821 else if (settings->layer == 1) {
828 static void client_restore_session_state(ObClient *self)
832 ob_debug_type(OB_DEBUG_SM,
833 "Restore session for client %s", self->title);
835 if (!(it = session_state_find(self))) {
836 ob_debug_type(OB_DEBUG_SM,
837 "Session data not found for client %s", self->title);
841 self->session = it->data;
843 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s",
846 RECT_SET_POINT(self->area, self->session->x, self->session->y);
847 self->positioned = USPosition;
848 self->sized = USSize;
849 if (self->session->w > 0)
850 self->area.width = self->session->w;
851 if (self->session->h > 0)
852 self->area.height = self->session->h;
853 XResizeWindow(obt_display, self->window,
854 self->area.width, self->area.height);
856 self->desktop = (self->session->desktop == DESKTOP_ALL ?
857 self->session->desktop :
858 MIN(screen_num_desktops - 1, self->session->desktop));
859 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
861 self->shaded = self->session->shaded;
862 self->iconic = self->session->iconic;
863 self->skip_pager = self->session->skip_pager;
864 self->skip_taskbar = self->session->skip_taskbar;
865 self->fullscreen = self->session->fullscreen;
866 self->above = self->session->above;
867 self->below = self->session->below;
868 self->max_horz = self->session->max_horz;
869 self->max_vert = self->session->max_vert;
870 self->undecorated = self->session->undecorated;
873 static gboolean client_restore_session_stacking(ObClient *self)
877 if (!self->session) return FALSE;
879 mypos = g_list_find(session_saved_state, self->session);
880 if (!mypos) return FALSE;
882 /* start above me and look for the first client */
883 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
886 for (cit = client_list; cit; cit = g_list_next(cit)) {
887 ObClient *c = cit->data;
888 /* found a client that was in the session, so go below it */
889 if (c->session == it->data) {
890 stacking_below(CLIENT_AS_WINDOW(self),
891 CLIENT_AS_WINDOW(cit->data));
899 void client_move_onscreen(ObClient *self, gboolean rude)
901 gint x = self->area.x;
902 gint y = self->area.y;
903 if (client_find_onscreen(self, &x, &y,
905 self->area.height, rude)) {
906 client_move(self, x, y);
910 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
913 gint ox = *x, oy = *y;
914 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
920 RECT_SET(desired, *x, *y, w, h);
921 frame_rect_to_frame(self->frame, &desired);
923 /* get where the frame would be */
924 frame_client_gravity(self->frame, x, y);
926 /* get the requested size of the window with decorations */
927 fw = self->frame->size.left + w + self->frame->size.right;
928 fh = self->frame->size.top + h + self->frame->size.bottom;
930 /* If rudeness wasn't requested, then still be rude in a given direction
931 if the client is not moving, only resizing in that direction */
933 Point oldtl, oldtr, oldbl, oldbr;
934 Point newtl, newtr, newbl, newbr;
935 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
937 POINT_SET(oldtl, self->frame->area.x, self->frame->area.y);
938 POINT_SET(oldbr, self->frame->area.x + self->frame->area.width - 1,
939 self->frame->area.y + self->frame->area.height - 1);
940 POINT_SET(oldtr, oldbr.x, oldtl.y);
941 POINT_SET(oldbl, oldtl.x, oldbr.y);
943 POINT_SET(newtl, *x, *y);
944 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
945 POINT_SET(newtr, newbr.x, newtl.y);
946 POINT_SET(newbl, newtl.x, newbr.y);
948 /* is it moving or just resizing from some corner? */
949 stationary_l = oldtl.x == newtl.x;
950 stationary_r = oldtr.x == newtr.x;
951 stationary_t = oldtl.y == newtl.y;
952 stationary_b = oldbl.y == newbl.y;
954 /* if left edge is growing and didnt move right edge */
955 if (stationary_r && newtl.x < oldtl.x)
957 /* if right edge is growing and didnt move left edge */
958 if (stationary_l && newtr.x > oldtr.x)
960 /* if top edge is growing and didnt move bottom edge */
961 if (stationary_b && newtl.y < oldtl.y)
963 /* if bottom edge is growing and didnt move top edge */
964 if (stationary_t && newbl.y > oldbl.y)
968 /* we iterate through every monitor that the window is at least partially
969 on, to make sure it is obeying the rules on them all
971 if the window does not appear on any monitors, then use the first one
974 for (i = 0; i < screen_num_monitors; ++i) {
977 if (!screen_physical_area_monitor_contains(i, &desired)) {
978 if (i < screen_num_monitors - 1 || found_mon)
981 /* the window is not inside any monitor! so just use the first
983 a = screen_area(self->desktop, 0, NULL);
986 a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &desired);
989 /* This makes sure windows aren't entirely outside of the screen so you
990 can't see them at all.
991 It makes sure 10% of the window is on the screen at least. At don't
992 let it move itself off the top of the screen, which would hide the
993 titlebar on you. (The user can still do this if they want too, it's
994 only limiting the application.
996 if (client_normal(self)) {
997 if (!self->strut.right && *x + fw/10 >= a->x + a->width - 1)
998 *x = a->x + a->width - fw/10;
999 if (!self->strut.bottom && *y + fh/10 >= a->y + a->height - 1)
1000 *y = a->y + a->height - fh/10;
1001 if (!self->strut.left && *x + fw*9/10 - 1 < a->x)
1002 *x = a->x - fw*9/10;
1003 if (!self->strut.top && *y + fh*9/10 - 1 < a->y)
1004 *y = a->y - fh*9/10;
1007 /* This here doesn't let windows even a pixel outside the
1008 struts/screen. When called from client_manage, programs placing
1009 themselves are forced completely onscreen, while things like
1010 xterm -geometry resolution-width/2 will work fine. Trying to
1011 place it completely offscreen will be handled in the above code.
1012 Sorry for this confused comment, i am tired. */
1013 if (rudel && !self->strut.left && *x < a->x) *x = a->x;
1014 if (ruder && !self->strut.right && *x + fw > a->x + a->width)
1015 *x = a->x + MAX(0, a->width - fw);
1017 if (rudet && !self->strut.top && *y < a->y) *y = a->y;
1018 if (rudeb && !self->strut.bottom && *y + fh > a->y + a->height)
1019 *y = a->y + MAX(0, a->height - fh);
1024 /* get where the client should be */
1025 frame_frame_gravity(self->frame, x, y);
1027 return ox != *x || oy != *y;
1030 static void client_get_all(ObClient *self, gboolean real)
1032 /* this is needed for the frame to set itself up */
1033 client_get_area(self);
1035 /* these things can change the decor and functions of the window */
1037 client_get_mwm_hints(self);
1038 /* this can change the mwmhints for special cases */
1039 client_get_type_and_transientness(self);
1040 client_get_state(self);
1041 client_update_normal_hints(self);
1043 /* get the session related properties, these can change decorations
1044 from per-app settings */
1045 client_get_session_ids(self);
1047 /* now we got everything that can affect the decorations */
1051 /* get this early so we have it for debugging */
1052 client_update_title(self);
1054 client_update_protocols(self);
1056 client_update_wmhints(self);
1057 /* this may have already been called from client_update_wmhints */
1058 if (!self->parents && !self->transient_for_group)
1059 client_update_transient_for(self);
1061 client_get_startup_id(self);
1062 client_get_desktop(self);/* uses transient data/group/startup id if a
1063 desktop is not specified */
1064 client_get_shaped(self);
1067 /* a couple type-based defaults for new windows */
1069 /* this makes sure that these windows appear on all desktops */
1070 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1071 self->desktop = DESKTOP_ALL;
1075 client_update_sync_request_counter(self);
1078 client_get_colormap(self);
1079 client_update_strut(self);
1080 client_update_icons(self);
1081 client_update_icon_geometry(self);
1084 static void client_get_startup_id(ObClient *self)
1086 if (!(OBT_PROP_GETS(self->window, NET_STARTUP_ID, utf8,
1087 &self->startup_id)))
1089 OBT_PROP_GETS(self->group->leader,
1090 NET_STARTUP_ID, utf8, &self->startup_id);
1093 static void client_get_area(ObClient *self)
1095 XWindowAttributes wattrib;
1098 ret = XGetWindowAttributes(obt_display, self->window, &wattrib);
1099 g_assert(ret != BadWindow);
1101 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1102 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1103 self->border_width = wattrib.border_width;
1105 ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y,
1106 wattrib.width, wattrib.height, wattrib.border_width);
1109 static void client_get_desktop(ObClient *self)
1111 guint32 d = screen_num_desktops; /* an always-invalid value */
1113 if (OBT_PROP_GET32(self->window, NET_WM_DESKTOP, CARDINAL, &d)) {
1114 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1115 self->desktop = screen_num_desktops - 1;
1118 ob_debug("client requested desktop 0x%x", self->desktop);
1121 gboolean first = TRUE;
1122 guint all = screen_num_desktops; /* not a valid value */
1124 /* if they are all on one desktop, then open it on the
1126 for (it = self->parents; it; it = g_slist_next(it)) {
1127 ObClient *c = it->data;
1129 if (c->desktop == DESKTOP_ALL) continue;
1135 else if (all != c->desktop)
1136 all = screen_num_desktops; /* make it invalid */
1138 if (all != screen_num_desktops) {
1139 self->desktop = all;
1141 ob_debug("client desktop set from parents: 0x%x",
1144 /* try get from the startup-notification protocol */
1145 else if (sn_get_desktop(self->startup_id, &self->desktop)) {
1146 if (self->desktop >= screen_num_desktops &&
1147 self->desktop != DESKTOP_ALL)
1148 self->desktop = screen_num_desktops - 1;
1149 ob_debug("client desktop set from startup-notification: 0x%x",
1152 /* defaults to the current desktop */
1154 self->desktop = screen_desktop;
1155 ob_debug("client desktop set to the current desktop: %d",
1161 static void client_get_state(ObClient *self)
1166 if (OBT_PROP_GETA32(self->window, NET_WM_STATE, ATOM, &state, &num)) {
1168 for (i = 0; i < num; ++i) {
1169 if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
1171 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
1172 self->shaded = TRUE;
1173 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
1174 self->iconic = TRUE;
1175 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
1176 self->skip_taskbar = TRUE;
1177 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
1178 self->skip_pager = TRUE;
1179 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
1180 self->fullscreen = TRUE;
1181 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
1182 self->max_vert = TRUE;
1183 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
1184 self->max_horz = TRUE;
1185 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
1187 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
1189 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
1190 self->demands_attention = TRUE;
1191 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
1192 self->undecorated = TRUE;
1199 static void client_get_shaped(ObClient *self)
1201 self->shaped = FALSE;
1203 if (obt_display_extension_shape) {
1208 XShapeSelectInput(obt_display, self->window, ShapeNotifyMask);
1210 XShapeQueryExtents(obt_display, self->window, &s, &foo,
1211 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1213 self->shaped = (s != 0);
1218 void client_update_transient_for(ObClient *self)
1221 ObClient *target = NULL;
1222 gboolean trangroup = FALSE;
1224 if (XGetTransientForHint(obt_display, self->window, &t)) {
1225 if (t != self->window) { /* cant be transient to itself! */
1226 ObWindow *tw = window_find(t);
1227 /* if this happens then we need to check for it*/
1228 g_assert(tw != CLIENT_AS_WINDOW(self));
1229 if (tw && WINDOW_IS_CLIENT(tw)) {
1230 /* watch out for windows with a parent that is something
1231 different, like a dockapp for example */
1232 target = WINDOW_AS_CLIENT(tw);
1236 /* Setting the transient_for to Root is actually illegal, however
1237 applications from time have done this to specify transient for
1239 if (!target && self->group && t == obt_root(ob_screen))
1241 } else if (self->group && self->transient)
1244 client_update_transient_tree(self, self->group, self->group,
1245 self->transient_for_group, trangroup,
1246 client_direct_parent(self), target);
1247 self->transient_for_group = trangroup;
1251 static void client_update_transient_tree(ObClient *self,
1252 ObGroup *oldgroup, ObGroup *newgroup,
1253 gboolean oldgtran, gboolean newgtran,
1254 ObClient* oldparent,
1255 ObClient *newparent)
1260 g_assert(!oldgtran || oldgroup);
1261 g_assert(!newgtran || newgroup);
1262 g_assert((!oldgtran && !oldparent) ||
1263 (oldgtran && !oldparent) ||
1264 (!oldgtran && oldparent));
1265 g_assert((!newgtran && !newparent) ||
1266 (newgtran && !newparent) ||
1267 (!newgtran && newparent));
1270 Group transient windows are not allowed to have other group
1271 transient windows as their children.
1275 /* No change has occured */
1276 if (oldgroup == newgroup &&
1277 oldgtran == newgtran &&
1278 oldparent == newparent) return;
1280 /** Remove the client from the transient tree **/
1282 for (it = self->transients; it; it = next) {
1283 next = g_slist_next(it);
1285 self->transients = g_slist_delete_link(self->transients, it);
1286 c->parents = g_slist_remove(c->parents, self);
1288 for (it = self->parents; it; it = next) {
1289 next = g_slist_next(it);
1291 self->parents = g_slist_delete_link(self->parents, it);
1292 c->transients = g_slist_remove(c->transients, self);
1295 /** Re-add the client to the transient tree **/
1297 /* If we're transient for a group then we need to add ourselves to all our
1300 for (it = newgroup->members; it; it = g_slist_next(it)) {
1303 !client_search_top_direct_parent(c)->transient_for_group &&
1306 c->transients = g_slist_prepend(c->transients, self);
1307 self->parents = g_slist_prepend(self->parents, c);
1312 /* If we are now transient for a single window we need to add ourselves to
1315 WARNING: Cyclical transient ness is possible if two windows are
1316 transient for eachother.
1318 else if (newparent &&
1319 /* don't make ourself its child if it is already our child */
1320 !client_is_direct_child(self, newparent) &&
1321 client_normal(newparent))
1323 newparent->transients = g_slist_prepend(newparent->transients, self);
1324 self->parents = g_slist_prepend(self->parents, newparent);
1327 /* Add any group transient windows to our children. But if we're transient
1328 for the group, then other group transients are not our children.
1330 WARNING: Cyclical transient-ness is possible. For e.g. if:
1331 A is transient for the group
1332 B is transient for A
1333 C is transient for B
1334 A can't be transient for C or we have a cycle
1336 if (!newgtran && newgroup &&
1338 !client_search_top_direct_parent(newparent)->transient_for_group) &&
1339 client_normal(self))
1341 for (it = newgroup->members; it; it = g_slist_next(it)) {
1343 if (c != self && c->transient_for_group &&
1344 /* Don't make it our child if it is already our parent */
1345 !client_is_direct_child(c, self))
1347 self->transients = g_slist_prepend(self->transients, c);
1348 c->parents = g_slist_prepend(c->parents, self);
1353 /** If we change our group transient-ness, our children change their
1354 effect group transient-ness, which affects how they relate to other
1357 for (it = self->transients; it; it = g_slist_next(it)) {
1359 if (!c->transient_for_group)
1360 client_update_transient_tree(c, c->group, c->group,
1361 c->transient_for_group,
1362 c->transient_for_group,
1363 client_direct_parent(c),
1364 client_direct_parent(c));
1368 static void client_get_mwm_hints(ObClient *self)
1373 self->mwmhints.flags = 0; /* default to none */
1375 if (OBT_PROP_GETA32(self->window, MOTIF_WM_HINTS, MOTIF_WM_HINTS,
1377 if (num >= OB_MWM_ELEMENTS) {
1378 self->mwmhints.flags = hints[0];
1379 self->mwmhints.functions = hints[1];
1380 self->mwmhints.decorations = hints[2];
1386 void client_get_type_and_transientness(ObClient *self)
1393 self->transient = FALSE;
1395 if (OBT_PROP_GETA32(self->window, NET_WM_WINDOW_TYPE, ATOM, &val, &num)) {
1396 /* use the first value that we know about in the array */
1397 for (i = 0; i < num; ++i) {
1398 if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
1399 self->type = OB_CLIENT_TYPE_DESKTOP;
1400 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK))
1401 self->type = OB_CLIENT_TYPE_DOCK;
1402 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR))
1403 self->type = OB_CLIENT_TYPE_TOOLBAR;
1404 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
1405 self->type = OB_CLIENT_TYPE_MENU;
1406 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY))
1407 self->type = OB_CLIENT_TYPE_UTILITY;
1408 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH))
1409 self->type = OB_CLIENT_TYPE_SPLASH;
1410 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG))
1411 self->type = OB_CLIENT_TYPE_DIALOG;
1412 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL))
1413 self->type = OB_CLIENT_TYPE_NORMAL;
1414 else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE))
1416 /* prevent this window from getting any decor or
1418 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1419 OB_MWM_FLAG_DECORATIONS);
1420 self->mwmhints.decorations = 0;
1421 self->mwmhints.functions = 0;
1423 if (self->type != (ObClientType) -1)
1424 break; /* grab the first legit type */
1429 if (XGetTransientForHint(obt_display, self->window, &t))
1430 self->transient = TRUE;
1432 if (self->type == (ObClientType) -1) {
1433 /*the window type hint was not set, which means we either classify
1434 ourself as a normal window or a dialog, depending on if we are a
1436 if (self->transient)
1437 self->type = OB_CLIENT_TYPE_DIALOG;
1439 self->type = OB_CLIENT_TYPE_NORMAL;
1442 /* then, based on our type, we can update our transientness.. */
1443 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1444 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1445 self->type == OB_CLIENT_TYPE_MENU ||
1446 self->type == OB_CLIENT_TYPE_UTILITY)
1448 self->transient = TRUE;
1452 void client_update_protocols(ObClient *self)
1457 self->focus_notify = FALSE;
1458 self->delete_window = FALSE;
1460 if (OBT_PROP_GETA32(self->window, WM_PROTOCOLS, ATOM, &proto, &num_ret)) {
1461 for (i = 0; i < num_ret; ++i) {
1462 if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW))
1463 /* this means we can request the window to close */
1464 self->delete_window = TRUE;
1465 else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS))
1466 /* if this protocol is requested, then the window will be
1467 notified whenever we want it to receive focus */
1468 self->focus_notify = TRUE;
1469 else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING))
1470 /* if this protocol is requested, then the window will allow
1471 pings to determine if it is still alive */
1474 else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST))
1475 /* if this protocol is requested, then resizing the
1476 window will be synchronized between the frame and the
1478 self->sync_request = TRUE;
1486 void client_update_sync_request_counter(ObClient *self)
1490 if (OBT_PROP_GET32(self->window, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i))
1492 self->sync_counter = i;
1494 self->sync_counter = None;
1498 static void client_get_colormap(ObClient *self)
1500 XWindowAttributes wa;
1502 if (XGetWindowAttributes(obt_display, self->window, &wa))
1503 client_update_colormap(self, wa.colormap);
1506 void client_update_colormap(ObClient *self, Colormap colormap)
1508 if (colormap == self->colormap) return;
1510 ob_debug("Setting client %s colormap: 0x%x", self->title, colormap);
1512 if (client_focused(self)) {
1513 screen_install_colormap(self, FALSE); /* uninstall old one */
1514 self->colormap = colormap;
1515 screen_install_colormap(self, FALSE); /* install new one */
1517 self->colormap = colormap;
1520 void client_update_normal_hints(ObClient *self)
1526 self->min_ratio = 0.0f;
1527 self->max_ratio = 0.0f;
1528 SIZE_SET(self->size_inc, 1, 1);
1529 SIZE_SET(self->base_size, 0, 0);
1530 SIZE_SET(self->min_size, 0, 0);
1531 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1533 /* get the hints from the window */
1534 if (XGetWMNormalHints(obt_display, self->window, &size, &ret)) {
1535 /* normal windows can't request placement! har har
1536 if (!client_normal(self))
1538 self->positioned = (size.flags & (PPosition|USPosition));
1539 self->sized = (size.flags & (PSize|USSize));
1541 if (size.flags & PWinGravity)
1542 self->gravity = size.win_gravity;
1544 if (size.flags & PAspect) {
1545 if (size.min_aspect.y)
1547 (gfloat) size.min_aspect.x / size.min_aspect.y;
1548 if (size.max_aspect.y)
1550 (gfloat) size.max_aspect.x / size.max_aspect.y;
1553 if (size.flags & PMinSize)
1554 SIZE_SET(self->min_size, size.min_width, size.min_height);
1556 if (size.flags & PMaxSize)
1557 SIZE_SET(self->max_size, size.max_width, size.max_height);
1559 if (size.flags & PBaseSize)
1560 SIZE_SET(self->base_size, size.base_width, size.base_height);
1562 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1563 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1565 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1566 self->min_size.width, self->min_size.height,
1567 self->max_size.width, self->max_size.height);
1568 ob_debug("size inc (%d %d) base size (%d %d)",
1569 self->size_inc.width, self->size_inc.height,
1570 self->base_size.width, self->base_size.height);
1573 ob_debug("Normal hints: not set");
1576 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1578 /* start with everything (cept fullscreen) */
1580 (OB_FRAME_DECOR_TITLEBAR |
1581 OB_FRAME_DECOR_HANDLE |
1582 OB_FRAME_DECOR_GRIPS |
1583 OB_FRAME_DECOR_BORDER |
1584 OB_FRAME_DECOR_ICON |
1585 OB_FRAME_DECOR_ALLDESKTOPS |
1586 OB_FRAME_DECOR_ICONIFY |
1587 OB_FRAME_DECOR_MAXIMIZE |
1588 OB_FRAME_DECOR_SHADE |
1589 OB_FRAME_DECOR_CLOSE);
1591 (OB_CLIENT_FUNC_RESIZE |
1592 OB_CLIENT_FUNC_MOVE |
1593 OB_CLIENT_FUNC_ICONIFY |
1594 OB_CLIENT_FUNC_MAXIMIZE |
1595 OB_CLIENT_FUNC_SHADE |
1596 OB_CLIENT_FUNC_CLOSE |
1597 OB_CLIENT_FUNC_BELOW |
1598 OB_CLIENT_FUNC_ABOVE |
1599 OB_CLIENT_FUNC_UNDECORATE);
1601 if (!(self->min_size.width < self->max_size.width ||
1602 self->min_size.height < self->max_size.height))
1603 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1605 switch (self->type) {
1606 case OB_CLIENT_TYPE_NORMAL:
1607 /* normal windows retain all of the possible decorations and
1608 functionality, and can be fullscreen */
1609 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1612 case OB_CLIENT_TYPE_DIALOG:
1613 /* sometimes apps make dialog windows fullscreen for some reason (for
1614 e.g. kpdf does this..) */
1615 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1618 case OB_CLIENT_TYPE_UTILITY:
1619 /* these windows don't have anything added or removed by default */
1622 case OB_CLIENT_TYPE_MENU:
1623 case OB_CLIENT_TYPE_TOOLBAR:
1624 /* these windows can't iconify or maximize */
1625 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1626 OB_FRAME_DECOR_MAXIMIZE);
1627 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1628 OB_CLIENT_FUNC_MAXIMIZE);
1631 case OB_CLIENT_TYPE_SPLASH:
1632 /* these don't get get any decorations, and the only thing you can
1633 do with them is move them */
1634 self->decorations = 0;
1635 self->functions = OB_CLIENT_FUNC_MOVE;
1638 case OB_CLIENT_TYPE_DESKTOP:
1639 /* these windows are not manipulated by the window manager */
1640 self->decorations = 0;
1641 self->functions = 0;
1644 case OB_CLIENT_TYPE_DOCK:
1645 /* these windows are not manipulated by the window manager, but they
1646 can set below layer which has a special meaning */
1647 self->decorations = 0;
1648 self->functions = OB_CLIENT_FUNC_BELOW;
1652 /* Mwm Hints are applied subtractively to what has already been chosen for
1653 decor and functionality */
1654 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1655 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1656 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1657 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1659 /* if the mwm hints request no handle or title, then all
1660 decorations are disabled, but keep the border if that's
1662 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1663 self->decorations = OB_FRAME_DECOR_BORDER;
1665 self->decorations = 0;
1670 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1671 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1672 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1673 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1674 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1675 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1676 /* dont let mwm hints kill any buttons
1677 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1678 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1679 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1680 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1682 /* dont let mwm hints kill the close button
1683 if (! (self->mwmhints.functions & MwmFunc_Close))
1684 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1688 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1689 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1690 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1691 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1692 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1693 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1695 /* can't maximize without moving/resizing */
1696 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1697 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1698 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1699 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1700 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1703 if (self->max_horz && self->max_vert) {
1704 /* you can't resize fully maximized windows */
1705 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1706 /* kill the handle on fully maxed windows */
1707 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1710 /* If there are no decorations to remove, don't allow the user to try
1712 if (self->decorations == 0)
1713 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1715 /* finally, the user can have requested no decorations, which overrides
1716 everything (but doesnt give it a border if it doesnt have one) */
1717 if (self->undecorated)
1718 self->decorations = 0;
1720 /* if we don't have a titlebar, then we cannot shade! */
1721 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1722 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1724 /* now we need to check against rules for the client's current state */
1725 if (self->fullscreen) {
1726 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1727 OB_CLIENT_FUNC_FULLSCREEN |
1728 OB_CLIENT_FUNC_ICONIFY);
1729 self->decorations = 0;
1732 client_change_allowed_actions(self);
1735 /* force reconfigure to make sure decorations are updated */
1736 client_reconfigure(self, TRUE);
1739 static void client_change_allowed_actions(ObClient *self)
1744 /* desktop windows are kept on all desktops */
1745 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1746 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP);
1748 if (self->functions & OB_CLIENT_FUNC_SHADE)
1749 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE);
1750 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1751 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE);
1752 if (self->functions & OB_CLIENT_FUNC_MOVE)
1753 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE);
1754 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1755 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE);
1756 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1757 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE);
1758 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1759 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN);
1760 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1761 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ);
1762 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT);
1764 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1765 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE);
1766 if (self->functions & OB_CLIENT_FUNC_BELOW)
1767 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW);
1768 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1769 actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE);
1771 OBT_PROP_SETA32(self->window, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num);
1773 /* make sure the window isn't breaking any rules now
1775 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1776 it can't be iconified with its parent
1779 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1780 if (self->frame) client_shade(self, FALSE);
1781 else self->shaded = FALSE;
1783 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1784 if (self->frame) client_fullscreen(self, FALSE);
1785 else self->fullscreen = FALSE;
1787 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1789 if (self->frame) client_maximize(self, FALSE, 0);
1790 else self->max_vert = self->max_horz = FALSE;
1794 void client_update_wmhints(ObClient *self)
1798 /* assume a window takes input if it doesnt specify */
1799 self->can_focus = TRUE;
1801 if ((hints = XGetWMHints(obt_display, self->window)) != NULL) {
1804 if (hints->flags & InputHint)
1805 self->can_focus = hints->input;
1807 /* only do this when first managing the window *AND* when we aren't
1809 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1810 if (hints->flags & StateHint)
1811 self->iconic = hints->initial_state == IconicState;
1814 self->urgent = (hints->flags & XUrgencyHint);
1815 if (self->urgent && !ur)
1816 client_hilite(self, TRUE);
1817 else if (!self->urgent && ur && self->demands_attention)
1818 client_hilite(self, FALSE);
1820 if (!(hints->flags & WindowGroupHint))
1821 hints->window_group = None;
1823 /* did the group state change? */
1824 if (hints->window_group !=
1825 (self->group ? self->group->leader : None))
1827 ObGroup *oldgroup = self->group;
1829 /* remove from the old group if there was one */
1830 if (self->group != NULL) {
1831 group_remove(self->group, self);
1835 /* add ourself to the group if we have one */
1836 if (hints->window_group != None) {
1837 self->group = group_add(hints->window_group, self);
1840 /* Put ourselves into the new group's transient tree, and remove
1841 ourselves from the old group's */
1842 client_update_transient_tree(self, oldgroup, self->group,
1843 self->transient_for_group,
1844 self->transient_for_group,
1845 client_direct_parent(self),
1846 client_direct_parent(self));
1848 /* Lastly, being in a group, or not, can change if the window is
1849 transient for anything.
1851 The logic for this is:
1852 self->transient = TRUE always if the window wants to be
1853 transient for something, even if transient_for was NULL because
1854 it wasn't in a group before.
1856 If parents was NULL and oldgroup was NULL we can assume
1857 that when we add the new group, it will become transient for
1860 If transient_for_group is TRUE, then it must have already
1861 had a group. If it is getting a new group, the above call to
1862 client_update_transient_tree has already taken care of
1863 everything ! If it is losing all group status then it will
1864 no longer be transient for anything and that needs to be
1867 if (self->transient &&
1868 ((self->parents == NULL && oldgroup == NULL) ||
1869 (self->transient_for_group && !self->group)))
1870 client_update_transient_for(self);
1873 /* the WM_HINTS can contain an icon */
1874 if (hints->flags & IconPixmapHint)
1875 client_update_icons(self);
1881 void client_update_title(ObClient *self)
1884 gchar *visible = NULL;
1886 g_free(self->title);
1887 g_free(self->original_title);
1890 if (!OBT_PROP_GETS(self->window, NET_WM_NAME, utf8, &data)) {
1891 /* try old x stuff */
1892 if (!(OBT_PROP_GETS(self->window, WM_NAME, locale, &data)
1893 || OBT_PROP_GETS(self->window, WM_NAME, utf8, &data))) {
1894 if (self->transient) {
1896 GNOME alert windows are not given titles:
1897 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1899 data = g_strdup("");
1901 data = g_strdup("Unnamed Window");
1904 self->original_title = g_strdup(data);
1906 if (self->client_machine) {
1907 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1912 if (self->not_responding) {
1914 if (self->kill_level > 0)
1915 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1917 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1921 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_NAME, utf8, visible);
1922 self->title = visible;
1925 frame_adjust_title(self->frame);
1927 /* update the icon title */
1929 g_free(self->icon_title);
1932 if (!OBT_PROP_GETS(self->window, NET_WM_ICON_NAME, utf8, &data))
1933 /* try old x stuff */
1934 if (!(OBT_PROP_GETS(self->window, WM_ICON_NAME, locale, &data) ||
1935 OBT_PROP_GETS(self->window, WM_ICON_NAME, utf8, &data)))
1936 data = g_strdup(self->title);
1938 if (self->client_machine) {
1939 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1944 if (self->not_responding) {
1946 if (self->kill_level > 0)
1947 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1949 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1953 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_ICON_NAME, utf8, visible);
1954 self->icon_title = visible;
1957 void client_update_strut(ObClient *self)
1961 gboolean got = FALSE;
1964 if (OBT_PROP_GETA32(self->window, NET_WM_STRUT_PARTIAL, CARDINAL,
1969 STRUT_PARTIAL_SET(strut,
1970 data[0], data[2], data[1], data[3],
1971 data[4], data[5], data[8], data[9],
1972 data[6], data[7], data[10], data[11]);
1978 OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) {
1984 /* use the screen's width/height */
1985 a = screen_physical_area_all_monitors();
1987 STRUT_PARTIAL_SET(strut,
1988 data[0], data[2], data[1], data[3],
1989 a->y, a->y + a->height - 1,
1990 a->x, a->x + a->width - 1,
1991 a->y, a->y + a->height - 1,
1992 a->x, a->x + a->width - 1);
1999 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2000 0, 0, 0, 0, 0, 0, 0, 0);
2002 if (!STRUT_EQUAL(strut, self->strut)) {
2003 self->strut = strut;
2005 /* updating here is pointless while we're being mapped cuz we're not in
2006 the client list yet */
2008 screen_update_areas();
2012 /* Avoid storing icons above this size if possible */
2013 #define AVOID_ABOVE 64
2015 void client_update_icons(ObClient *self)
2020 guint num_seen; /* number of icons present */
2021 guint num_small_seen; /* number of icons small enough present */
2022 guint smallest, smallest_area;
2024 for (i = 0; i < self->nicons; ++i)
2025 g_free(self->icons[i].data);
2026 if (self->nicons > 0)
2027 g_free(self->icons);
2030 if (OBT_PROP_GETA32(self->window, NET_WM_ICON, CARDINAL, &data, &num)) {
2031 /* figure out how many valid icons are in here */
2033 num_seen = num_small_seen = 0;
2034 smallest = smallest_area = 0;
2040 /* watch for it being too small for the specified size, or for
2041 zero sized icons. */
2042 if (i > num || w == 0 || h == 0) break;
2044 if (!smallest_area || w*h < smallest_area) {
2045 smallest = num_seen;
2046 smallest_area = w*h;
2049 if (w <= AVOID_ABOVE && h <= AVOID_ABOVE)
2052 if (num_small_seen > 0)
2053 self->nicons = num_small_seen;
2057 self->icons = g_new(ObClientIcon, self->nicons);
2059 /* store the icons */
2061 for (j = 0; j < self->nicons;) {
2064 w = self->icons[j].width = data[i++];
2065 h = self->icons[j].height = data[i++];
2067 /* if there are some icons smaller than the threshold, we're
2068 skipping all the ones above */
2069 if (num_small_seen > 0) {
2070 if (w > AVOID_ABOVE || h > AVOID_ABOVE) {
2075 /* if there were no icons smaller than the threshold, then we are
2076 only taking the smallest available one we saw */
2077 else if (j != smallest) {
2082 self->icons[j].data = g_new(RrPixel32, w * h);
2083 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
2088 self->icons[j].data[t] =
2089 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2090 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
2091 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
2092 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
2103 if ((hints = XGetWMHints(obt_display, self->window))) {
2104 if (hints->flags & IconPixmapHint) {
2106 self->icons = g_new(ObClientIcon, self->nicons);
2107 obt_display_ignore_errors(TRUE);
2108 if (!RrPixmapToRGBA(ob_rr_inst,
2110 (hints->flags & IconMaskHint ?
2111 hints->icon_mask : None),
2112 &self->icons[0].width,
2113 &self->icons[0].height,
2114 &self->icons[0].data))
2116 g_free(self->icons);
2119 obt_display_ignore_errors(FALSE);
2125 /* set the default icon onto the window
2126 in theory, this could be a race, but if a window doesn't set an icon
2127 or removes it entirely, it's not very likely it is going to set one
2128 right away afterwards
2130 if it has parents, then one of them will have an icon already
2132 if (self->nicons == 0 && !self->parents) {
2133 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2136 data = g_new(gulong, 48*48+2);
2137 data[0] = data[1] = 48;
2138 for (i = 0; i < 48*48; ++i)
2139 data[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2140 (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) +
2141 (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) +
2142 (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0);
2143 OBT_PROP_SETA32(self->window, NET_WM_ICON, CARDINAL, data, 48*48+2);
2145 } else if (self->frame)
2146 /* don't draw the icon empty if we're just setting one now anyways,
2147 we'll get the property change any second */
2148 frame_adjust_icon(self->frame);
2151 void client_update_icon_geometry(ObClient *self)
2156 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2158 if (OBT_PROP_GETA32(self->window, NET_WM_ICON_GEOMETRY, CARDINAL,
2162 /* don't let them set it with an area < 0 */
2163 RECT_SET(self->icon_geometry, data[0], data[1],
2164 MAX(data[2],0), MAX(data[3],0));
2169 static void client_get_session_ids(ObClient *self)
2176 if (!OBT_PROP_GET32(self->window, WM_CLIENT_LEADER, WINDOW, &leader))
2179 /* get the SM_CLIENT_ID */
2182 got = OBT_PROP_GETS(leader, SM_CLIENT_ID, locale, &self->sm_client_id);
2184 OBT_PROP_GETS(self->window, SM_CLIENT_ID, locale, &self->sm_client_id);
2186 /* get the WM_CLASS (name and class). make them "" if they are not
2190 got = OBT_PROP_GETSS(leader, WM_CLASS, locale, &ss);
2192 got = OBT_PROP_GETSS(self->window, WM_CLASS, locale, &ss);
2196 self->name = g_strdup(ss[0]);
2198 self->class = g_strdup(ss[1]);
2203 if (self->name == NULL) self->name = g_strdup("");
2204 if (self->class == NULL) self->class = g_strdup("");
2206 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2209 got = OBT_PROP_GETS(leader, WM_WINDOW_ROLE, locale, &s);
2211 got = OBT_PROP_GETS(self->window, WM_WINDOW_ROLE, locale, &s);
2216 self->role = g_strdup("");
2218 /* get the WM_COMMAND */
2222 got = OBT_PROP_GETSS(leader, WM_COMMAND, locale, &ss);
2224 got = OBT_PROP_GETSS(self->window, WM_COMMAND, locale, &ss);
2227 /* merge/mash them all together */
2228 gchar *merge = NULL;
2231 for (i = 0; ss[i]; ++i) {
2234 merge = g_strconcat(merge, ss[i], NULL);
2236 merge = g_strconcat(ss[i], NULL);
2241 self->wm_command = merge;
2244 /* get the WM_CLIENT_MACHINE */
2247 got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, locale, &s);
2249 got = OBT_PROP_GETS(self->window, WM_CLIENT_MACHINE, locale, &s);
2252 gchar localhost[128];
2255 gethostname(localhost, 127);
2256 localhost[127] = '\0';
2257 if (strcmp(localhost, s) != 0)
2258 self->client_machine = s;
2262 /* see if it has the PID set too (the PID requires that the
2263 WM_CLIENT_MACHINE be set) */
2264 if (OBT_PROP_GET32(self->window, NET_WM_PID, CARDINAL, &pid))
2269 static void client_change_wm_state(ObClient *self)
2274 old = self->wmstate;
2276 if (self->shaded || self->iconic ||
2277 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2279 self->wmstate = IconicState;
2281 self->wmstate = NormalState;
2283 if (old != self->wmstate) {
2284 OBT_PROP_MSG(ob_screen, self->window, KDE_WM_CHANGE_STATE,
2285 self->wmstate, 1, 0, 0, 0);
2287 state[0] = self->wmstate;
2289 OBT_PROP_SETA32(self->window, WM_STATE, WM_STATE, state, 2);
2293 static void client_change_state(ObClient *self)
2295 gulong netstate[12];
2300 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
2302 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED);
2304 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN);
2305 if (self->skip_taskbar)
2306 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR);
2307 if (self->skip_pager)
2308 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER);
2309 if (self->fullscreen)
2310 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN);
2312 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT);
2314 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ);
2316 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE);
2318 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW);
2319 if (self->demands_attention)
2320 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION);
2321 if (self->undecorated)
2322 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED);
2323 OBT_PROP_SETA32(self->window, NET_WM_STATE, ATOM, netstate, num);
2326 frame_adjust_state(self->frame);
2329 ObClient *client_search_focus_tree(ObClient *self)
2334 for (it = self->transients; it; it = g_slist_next(it)) {
2335 if (client_focused(it->data)) return it->data;
2336 if ((ret = client_search_focus_tree(it->data))) return ret;
2341 ObClient *client_search_focus_tree_full(ObClient *self)
2343 if (self->parents) {
2346 for (it = self->parents; it; it = g_slist_next(it)) {
2347 ObClient *c = it->data;
2348 if ((c = client_search_focus_tree_full(it->data))) return c;
2354 /* this function checks the whole tree, the client_search_focus_tree
2355 does not, so we need to check this window */
2356 if (client_focused(self))
2358 return client_search_focus_tree(self);
2362 ObClient *client_search_focus_group_full(ObClient *self)
2367 for (it = self->group->members; it; it = g_slist_next(it)) {
2368 ObClient *c = it->data;
2370 if (client_focused(c)) return c;
2371 if ((c = client_search_focus_tree(it->data))) return c;
2374 if (client_focused(self)) return self;
2378 gboolean client_has_parent(ObClient *self)
2380 return self->parents != NULL;
2383 static ObStackingLayer calc_layer(ObClient *self)
2388 monitor = screen_physical_area_monitor(client_monitor(self));
2390 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2391 l = OB_STACKING_LAYER_DESKTOP;
2392 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2393 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2394 else l = OB_STACKING_LAYER_ABOVE;
2396 else if ((self->fullscreen ||
2397 /* No decorations and fills the monitor = oldskool fullscreen.
2398 But not for maximized windows.
2400 (self->decorations == 0 &&
2401 !(self->max_horz && self->max_vert) &&
2402 RECT_EQUAL(self->area, *monitor))) &&
2403 /* you are fullscreen while you or your children are focused.. */
2404 (client_focused(self) || client_search_focus_tree(self) ||
2405 /* you can be fullscreen if you're on another desktop */
2406 (self->desktop != screen_desktop &&
2407 self->desktop != DESKTOP_ALL) ||
2408 /* and you can also be fullscreen if the focused client is on
2409 another monitor, or nothing else is focused */
2411 client_monitor(focus_client) != client_monitor(self))))
2412 l = OB_STACKING_LAYER_FULLSCREEN;
2413 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2414 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2415 else l = OB_STACKING_LAYER_NORMAL;
2422 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2423 ObStackingLayer min)
2425 ObStackingLayer old, own;
2429 own = calc_layer(self);
2430 self->layer = MAX(own, min);
2432 if (self->layer != old) {
2433 stacking_remove(CLIENT_AS_WINDOW(self));
2434 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2437 /* we've been restacked */
2438 self->visited = TRUE;
2440 for (it = self->transients; it; it = g_slist_next(it))
2441 client_calc_layer_recursive(it->data, orig,
2445 static void client_calc_layer_internal(ObClient *self)
2449 /* transients take on the layer of their parents */
2450 sit = client_search_all_top_parents(self);
2452 for (; sit; sit = g_slist_next(sit))
2453 client_calc_layer_recursive(sit->data, self, 0);
2456 void client_calc_layer(ObClient *self)
2460 /* skip over stuff above fullscreen layer */
2461 for (it = stacking_list; it; it = g_list_next(it))
2462 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2464 /* find the windows in the fullscreen layer, and mark them not-visited */
2465 for (; it; it = g_list_next(it)) {
2466 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2467 else if (WINDOW_IS_CLIENT(it->data))
2468 WINDOW_AS_CLIENT(it->data)->visited = FALSE;
2471 client_calc_layer_internal(self);
2473 /* skip over stuff above fullscreen layer */
2474 for (it = stacking_list; it; it = g_list_next(it))
2475 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2477 /* now recalc any windows in the fullscreen layer which have not
2478 had their layer recalced already */
2479 for (; it; it = g_list_next(it)) {
2480 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2481 else if (WINDOW_IS_CLIENT(it->data) &&
2482 !WINDOW_AS_CLIENT(it->data)->visited)
2483 client_calc_layer_internal(it->data);
2487 gboolean client_should_show(ObClient *self)
2491 if (client_normal(self) && screen_showing_desktop)
2493 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2499 gboolean client_show(ObClient *self)
2501 gboolean show = FALSE;
2503 if (client_should_show(self)) {
2504 /* replay pending pointer event before showing the window, in case it
2505 should be going to something under the window */
2506 mouse_replay_pointer();
2508 frame_show(self->frame);
2511 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2512 it needs to be in IconicState. This includes when it is on another
2515 client_change_wm_state(self);
2520 gboolean client_hide(ObClient *self)
2522 gboolean hide = FALSE;
2524 if (!client_should_show(self)) {
2525 if (self == focus_client) {
2526 /* if there is a grab going on, then we need to cancel it. if we
2527 move focus during the grab, applications will get
2528 NotifyWhileGrabbed events and ignore them !
2530 actions should not rely on being able to move focus during an
2533 event_cancel_all_key_grabs();
2536 /* We don't need to ignore enter events here.
2537 The window can hide/iconify in 3 different ways:
2538 1 - through an x message. in this case we ignore all enter events
2539 caused by responding to the x message (unless underMouse)
2540 2 - by a keyboard action. in this case we ignore all enter events
2541 caused by the action
2542 3 - by a mouse action. in this case they are doing stuff with the
2543 mouse and focus _should_ move.
2545 Also in action_end, we simulate an enter event that can't be ignored
2546 so trying to ignore them is futile in case 3 anyways
2549 /* replay pending pointer event before hiding the window, in case it
2550 should be going to the window */
2551 mouse_replay_pointer();
2553 frame_hide(self->frame);
2556 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2557 it needs to be in IconicState. This includes when it is on another
2560 client_change_wm_state(self);
2565 void client_showhide(ObClient *self)
2567 if (!client_show(self))
2571 gboolean client_normal(ObClient *self) {
2572 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2573 self->type == OB_CLIENT_TYPE_DOCK ||
2574 self->type == OB_CLIENT_TYPE_SPLASH);
2577 gboolean client_helper(ObClient *self)
2579 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2580 self->type == OB_CLIENT_TYPE_MENU ||
2581 self->type == OB_CLIENT_TYPE_TOOLBAR);
2584 gboolean client_mouse_focusable(ObClient *self)
2586 return !(self->type == OB_CLIENT_TYPE_MENU ||
2587 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2588 self->type == OB_CLIENT_TYPE_SPLASH ||
2589 self->type == OB_CLIENT_TYPE_DOCK);
2592 gboolean client_enter_focusable(ObClient *self)
2594 /* you can focus desktops but it shouldn't on enter */
2595 return (client_mouse_focusable(self) &&
2596 self->type != OB_CLIENT_TYPE_DESKTOP);
2600 static void client_apply_startup_state(ObClient *self,
2601 gint x, gint y, gint w, gint h)
2603 /* save the states that we are going to apply */
2604 gboolean iconic = self->iconic;
2605 gboolean fullscreen = self->fullscreen;
2606 gboolean undecorated = self->undecorated;
2607 gboolean shaded = self->shaded;
2608 gboolean demands_attention = self->demands_attention;
2609 gboolean max_horz = self->max_horz;
2610 gboolean max_vert = self->max_vert;
2614 /* turn them all off in the client, so they won't affect the window
2616 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2617 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2619 /* move the client to its placed position, or it it's already there,
2620 generate a ConfigureNotify telling the client where it is.
2622 do this after adjusting the frame. otherwise it gets all weird and
2623 clients don't work right
2625 do this before applying the states so they have the correct
2626 pre-max/pre-fullscreen values
2628 client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
2629 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2630 self->window, x, y, w, h);
2631 /* save the area, and make it where it should be for the premax stuff */
2632 oldarea = self->area;
2633 RECT_SET(self->area, x, y, w, h);
2635 /* apply the states. these are in a carefully crafted order.. */
2638 client_iconify(self, TRUE, FALSE, TRUE);
2640 client_fullscreen(self, TRUE);
2642 client_set_undecorated(self, TRUE);
2644 client_shade(self, TRUE);
2645 if (demands_attention)
2646 client_hilite(self, TRUE);
2648 if (max_vert && max_horz)
2649 client_maximize(self, TRUE, 0);
2651 client_maximize(self, TRUE, 2);
2653 client_maximize(self, TRUE, 1);
2655 /* if the window hasn't been configured yet, then do so now, in fact the
2656 x,y,w,h may _not_ be the same as the area rect, which can end up
2657 meaning that the client isn't properly moved/resized by the fullscreen
2659 pho can cause this because it maps at size of the screen but not 0,0
2660 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2661 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2662 cuz thats where the pre-fullscreen will be. however the actual area is
2663 not, so this needs to be called even if we have fullscreened/maxed
2665 self->area = oldarea;
2666 client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
2668 /* set the desktop hint, to make sure that it always exists */
2669 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
2671 /* nothing to do for the other states:
2680 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2682 /* these should be the current values. this is for when you're not moving,
2684 g_assert(*x == self->area.x);
2685 g_assert(oldw == self->area.width);
2688 switch (self->gravity) {
2690 case NorthWestGravity:
2692 case SouthWestGravity:
2699 *x -= (neww - oldw) / 2;
2701 case NorthEastGravity:
2703 case SouthEastGravity:
2709 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2711 /* these should be the current values. this is for when you're not moving,
2713 g_assert(*y == self->area.y);
2714 g_assert(oldh == self->area.height);
2717 switch (self->gravity) {
2719 case NorthWestGravity:
2721 case NorthEastGravity:
2728 *y -= (newh - oldh) / 2;
2730 case SouthWestGravity:
2732 case SouthEastGravity:
2738 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2739 gint *logicalw, gint *logicalh,
2742 Rect desired = {*x, *y, *w, *h};
2743 frame_rect_to_frame(self->frame, &desired);
2745 /* make the frame recalculate its dimentions n shit without changing
2746 anything visible for real, this way the constraints below can work with
2747 the updated frame dimensions. */
2748 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
2750 /* gets the frame's position */
2751 frame_client_gravity(self->frame, x, y);
2753 /* these positions are frame positions, not client positions */
2755 /* set the size and position if fullscreen */
2756 if (self->fullscreen) {
2760 i = screen_find_monitor(&desired);
2761 a = screen_physical_area_monitor(i);
2768 user = FALSE; /* ignore if the client can't be moved/resized when it
2772 } else if (self->max_horz || self->max_vert) {
2776 /* use all possible struts when maximizing to the full screen */
2777 i = screen_find_monitor(&desired);
2778 a = screen_area(self->desktop, i,
2779 (self->max_horz && self->max_vert ? NULL : &desired));
2781 /* set the size and position if maximized */
2782 if (self->max_horz) {
2784 *w = a->width - self->frame->size.left - self->frame->size.right;
2786 if (self->max_vert) {
2788 *h = a->height - self->frame->size.top - self->frame->size.bottom;
2791 user = FALSE; /* ignore if the client can't be moved/resized when it
2797 /* gets the client's position */
2798 frame_frame_gravity(self->frame, x, y);
2800 /* work within the prefered sizes given by the window */
2801 if (!(*w == self->area.width && *h == self->area.height)) {
2802 gint basew, baseh, minw, minh;
2804 gfloat minratio, maxratio;
2806 incw = self->fullscreen || self->max_horz ? 1 : self->size_inc.width;
2807 inch = self->fullscreen || self->max_vert ? 1 : self->size_inc.height;
2808 minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2809 0 : self->min_ratio;
2810 maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2811 0 : self->max_ratio;
2813 /* base size is substituted with min size if not specified */
2814 if (self->base_size.width || self->base_size.height) {
2815 basew = self->base_size.width;
2816 baseh = self->base_size.height;
2818 basew = self->min_size.width;
2819 baseh = self->min_size.height;
2821 /* min size is substituted with base size if not specified */
2822 if (self->min_size.width || self->min_size.height) {
2823 minw = self->min_size.width;
2824 minh = self->min_size.height;
2826 minw = self->base_size.width;
2827 minh = self->base_size.height;
2830 /* if this is a user-requested resize, then check against min/max
2833 /* smaller than min size or bigger than max size? */
2834 if (*w > self->max_size.width) *w = self->max_size.width;
2835 if (*w < minw) *w = minw;
2836 if (*h > self->max_size.height) *h = self->max_size.height;
2837 if (*h < minh) *h = minh;
2842 /* keep to the increments */
2846 /* you cannot resize to nothing */
2847 if (basew + *w < 1) *w = 1 - basew;
2848 if (baseh + *h < 1) *h = 1 - baseh;
2850 /* save the logical size */
2851 *logicalw = incw > 1 ? *w : *w + basew;
2852 *logicalh = inch > 1 ? *h : *h + baseh;
2860 /* adjust the height to match the width for the aspect ratios.
2861 for this, min size is not substituted for base size ever. */
2862 *w -= self->base_size.width;
2863 *h -= self->base_size.height;
2866 if (*h * minratio > *w) {
2867 *h = (gint)(*w / minratio);
2869 /* you cannot resize to nothing */
2872 *w = (gint)(*h * minratio);
2876 if (*h * maxratio < *w) {
2877 *h = (gint)(*w / maxratio);
2879 /* you cannot resize to nothing */
2882 *w = (gint)(*h * minratio);
2886 *w += self->base_size.width;
2887 *h += self->base_size.height;
2890 /* these override the above states! if you cant move you can't move! */
2892 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
2896 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2897 *w = self->area.width;
2898 *h = self->area.height;
2907 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
2908 gboolean user, gboolean final, gboolean force_reply)
2912 gboolean send_resize_client;
2913 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
2914 gboolean fmoved, fresized;
2915 guint fdecor = self->frame->decorations;
2916 gboolean fhorz = self->frame->max_horz;
2917 gboolean fvert = self->frame->max_vert;
2918 gint logicalw, logicalh;
2920 /* find the new x, y, width, and height (and logical size) */
2921 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
2923 /* set the logical size if things changed */
2924 if (!(w == self->area.width && h == self->area.height))
2925 SIZE_SET(self->logical_size, logicalw, logicalh);
2927 /* figure out if we moved or resized or what */
2928 moved = (x != self->area.x || y != self->area.y);
2929 resized = (w != self->area.width || h != self->area.height);
2931 oldw = self->area.width;
2932 oldh = self->area.height;
2933 oldframe = self->frame->area;
2934 RECT_SET(self->area, x, y, w, h);
2936 /* for app-requested resizes, always resize if 'resized' is true.
2937 for user-requested ones, only resize if final is true, or when
2938 resizing in redraw mode */
2939 send_resize_client = ((!user && resized) ||
2941 (resized && config_resize_redraw))));
2943 /* if the client is enlarging, then resize the client before the frame */
2944 if (send_resize_client && (w > oldw || h > oldh)) {
2945 XMoveResizeWindow(obt_display, self->window,
2946 self->frame->size.left, self->frame->size.top,
2947 MAX(w, oldw), MAX(h, oldh));
2948 frame_adjust_client_area(self->frame);
2951 /* find the frame's dimensions and move/resize it */
2955 /* if decorations changed, then readjust everything for the frame */
2956 if (self->decorations != fdecor ||
2957 self->max_horz != fhorz || self->max_vert != fvert)
2959 fmoved = fresized = TRUE;
2962 /* adjust the frame */
2963 if (fmoved || fresized) {
2964 gulong ignore_start;
2966 ignore_start = event_start_ignore_all_enters();
2968 /* replay pending pointer event before move the window, in case it
2969 would change what window gets the event */
2970 mouse_replay_pointer();
2972 frame_adjust_area(self->frame, fmoved, fresized, FALSE);
2975 event_end_ignore_all_enters(ignore_start);
2978 if (!user || final) {
2979 gint oldrx = self->root_pos.x;
2980 gint oldry = self->root_pos.y;
2981 /* we have reset the client to 0 border width, so don't include
2982 it in these coords */
2983 POINT_SET(self->root_pos,
2984 self->frame->area.x + self->frame->size.left -
2986 self->frame->area.y + self->frame->size.top -
2987 self->border_width);
2988 if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
2992 /* This is kinda tricky and should not be changed.. let me explain!
2994 When user = FALSE, then the request is coming from the application
2995 itself, and we are more strict about when to send a synthetic
2996 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
2997 in this case (if force_reply is true)
2999 When user = TRUE, then the request is coming from "us", like when we
3000 maximize a window or something. In this case we are more lenient. We
3001 used to follow the same rules as above, but _Java_ Swing can't handle
3002 this. So just to appease Swing, when user = TRUE, we always send
3003 a synthetic ConfigureNotify to give the window its root coordinates.
3005 if ((!user && !resized && (rootmoved || force_reply)) ||
3006 (user && final && rootmoved))
3010 event.type = ConfigureNotify;
3011 event.xconfigure.display = obt_display;
3012 event.xconfigure.event = self->window;
3013 event.xconfigure.window = self->window;
3015 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3016 self->title, self->root_pos.x, self->root_pos.y, w, h);
3018 /* root window real coords */
3019 event.xconfigure.x = self->root_pos.x;
3020 event.xconfigure.y = self->root_pos.y;
3021 event.xconfigure.width = w;
3022 event.xconfigure.height = h;
3023 event.xconfigure.border_width = self->border_width;
3024 event.xconfigure.above = None;
3025 event.xconfigure.override_redirect = FALSE;
3026 XSendEvent(event.xconfigure.display, event.xconfigure.window,
3027 FALSE, StructureNotifyMask, &event);
3030 /* if the client is shrinking, then resize the frame before the client.
3032 both of these resize sections may run, because the top one only resizes
3033 in the direction that is growing
3035 if (send_resize_client && (w <= oldw || h <= oldh)) {
3036 frame_adjust_client_area(self->frame);
3037 XMoveResizeWindow(obt_display, self->window,
3038 self->frame->size.left, self->frame->size.top, w, h);
3041 XFlush(obt_display);
3043 /* if it moved between monitors, then this can affect the stacking
3044 layer of this window or others - for fullscreen windows */
3045 if (screen_find_monitor(&self->frame->area) !=
3046 screen_find_monitor(&oldframe))
3048 client_calc_layer(self);
3052 void client_fullscreen(ObClient *self, gboolean fs)
3056 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
3057 self->fullscreen == fs) return; /* already done */
3059 self->fullscreen = fs;
3060 client_change_state(self); /* change the state hints on the client */
3063 self->pre_fullscreen_area = self->area;
3064 /* if the window is maximized, its area isn't all that meaningful.
3065 save it's premax area instead. */
3066 if (self->max_horz) {
3067 self->pre_fullscreen_area.x = self->pre_max_area.x;
3068 self->pre_fullscreen_area.width = self->pre_max_area.width;
3070 if (self->max_vert) {
3071 self->pre_fullscreen_area.y = self->pre_max_area.y;
3072 self->pre_fullscreen_area.height = self->pre_max_area.height;
3075 /* these will help configure_full figure out where to fullscreen
3079 w = self->area.width;
3080 h = self->area.height;
3082 g_assert(self->pre_fullscreen_area.width > 0 &&
3083 self->pre_fullscreen_area.height > 0);
3085 x = self->pre_fullscreen_area.x;
3086 y = self->pre_fullscreen_area.y;
3087 w = self->pre_fullscreen_area.width;
3088 h = self->pre_fullscreen_area.height;
3089 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
3092 ob_debug("Window %s going fullscreen (%d)",
3093 self->title, self->fullscreen);
3095 client_setup_decor_and_functions(self, FALSE);
3096 client_move_resize(self, x, y, w, h);
3098 /* and adjust our layer/stacking. do this after resizing the window,
3099 and applying decorations, because windows which fill the screen are
3100 considered "fullscreen" and it affects their layer */
3101 client_calc_layer(self);
3104 /* try focus us when we go into fullscreen mode */
3109 static void client_iconify_recursive(ObClient *self,
3110 gboolean iconic, gboolean curdesk,
3111 gboolean hide_animation)
3114 gboolean changed = FALSE;
3117 if (self->iconic != iconic) {
3118 ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
3122 /* don't let non-normal windows iconify along with their parents
3124 if (client_normal(self)) {
3125 self->iconic = iconic;
3127 /* update the focus lists.. iconic windows go to the bottom of
3129 focus_order_to_bottom(self);
3134 self->iconic = iconic;
3136 if (curdesk && self->desktop != screen_desktop &&
3137 self->desktop != DESKTOP_ALL)
3138 client_set_desktop(self, screen_desktop, FALSE, FALSE);
3140 /* this puts it after the current focused window */
3141 focus_order_remove(self);
3142 focus_order_add_new(self);
3149 client_change_state(self);
3150 if (config_animate_iconify && !hide_animation)
3151 frame_begin_iconify_animation(self->frame, iconic);
3152 /* do this after starting the animation so it doesn't flash */
3153 client_showhide(self);
3156 /* iconify all direct transients, and deiconify all transients
3158 for (it = self->transients; it; it = g_slist_next(it))
3159 if (it->data != self)
3160 if (client_is_direct_child(self, it->data) || !iconic)
3161 client_iconify_recursive(it->data, iconic, curdesk,
3165 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3166 gboolean hide_animation)
3168 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3169 /* move up the transient chain as far as possible first */
3170 self = client_search_top_direct_parent(self);
3171 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3175 void client_maximize(ObClient *self, gboolean max, gint dir)
3179 g_assert(dir == 0 || dir == 1 || dir == 2);
3180 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
3182 /* check if already done */
3184 if (dir == 0 && self->max_horz && self->max_vert) return;
3185 if (dir == 1 && self->max_horz) return;
3186 if (dir == 2 && self->max_vert) return;
3188 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3189 if (dir == 1 && !self->max_horz) return;
3190 if (dir == 2 && !self->max_vert) return;
3193 /* these will help configure_full figure out which screen to fill with
3197 w = self->area.width;
3198 h = self->area.height;
3201 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3202 RECT_SET(self->pre_max_area,
3203 self->area.x, self->pre_max_area.y,
3204 self->area.width, self->pre_max_area.height);
3206 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3207 RECT_SET(self->pre_max_area,
3208 self->pre_max_area.x, self->area.y,
3209 self->pre_max_area.width, self->area.height);
3212 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3213 g_assert(self->pre_max_area.width > 0);
3215 x = self->pre_max_area.x;
3216 w = self->pre_max_area.width;
3218 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3219 0, self->pre_max_area.height);
3221 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3222 g_assert(self->pre_max_area.height > 0);
3224 y = self->pre_max_area.y;
3225 h = self->pre_max_area.height;
3227 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3228 self->pre_max_area.width, 0);
3232 if (dir == 0 || dir == 1) /* horz */
3233 self->max_horz = max;
3234 if (dir == 0 || dir == 2) /* vert */
3235 self->max_vert = max;
3237 client_change_state(self); /* change the state hints on the client */
3239 client_setup_decor_and_functions(self, FALSE);
3240 client_move_resize(self, x, y, w, h);
3243 void client_shade(ObClient *self, gboolean shade)
3245 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3246 shade) || /* can't shade */
3247 self->shaded == shade) return; /* already done */
3249 self->shaded = shade;
3250 client_change_state(self);
3251 client_change_wm_state(self); /* the window is being hidden/shown */
3252 /* resize the frame to just the titlebar */
3253 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
3256 static void client_ping_event(ObClient *self, gboolean dead)
3258 if (self->not_responding != dead) {
3259 self->not_responding = dead;
3260 client_update_title(self);
3263 /* the client isn't responding, so ask to kill it */
3264 client_prompt_kill(self);
3266 /* it came back to life ! */
3268 if (self->kill_prompt) {
3269 prompt_unref(self->kill_prompt);
3270 self->kill_prompt = NULL;
3273 self->kill_level = 0;
3278 void client_close(ObClient *self)
3280 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3282 /* if closing an internal obprompt, that is just cancelling it */
3284 prompt_cancel(self->prompt);
3288 /* in the case that the client provides no means to requesting that it
3289 close, we just kill it */
3290 if (!self->delete_window)
3291 /* don't use client_kill(), we should only kill based on PID in
3292 response to a lack of PING replies */
3293 XKillClient(obt_display, self->window);
3295 /* request the client to close with WM_DELETE_WINDOW */
3296 OBT_PROP_MSG_TO(self->window, self->window, WM_PROTOCOLS,
3297 OBT_PROP_ATOM(WM_DELETE_WINDOW), event_curtime,
3298 0, 0, 0, NoEventMask);
3300 /* we're trying to close the window, so see if it is responding. if it
3301 is not, then we will let them kill the window */
3303 ping_start(self, client_ping_event);
3305 /* if we already know the window isn't responding (maybe they clicked
3306 no in the kill dialog but it hasn't come back to life), then show
3308 if (self->not_responding)
3309 client_prompt_kill(self);
3313 #define OB_KILL_RESULT_NO 0
3314 #define OB_KILL_RESULT_YES 1
3316 static void client_kill_requested(ObPrompt *p, gint result, gpointer data)
3318 ObClient *self = data;
3320 if (result == OB_KILL_RESULT_YES)
3323 prompt_unref(self->kill_prompt);
3324 self->kill_prompt = NULL;
3327 static void client_prompt_kill(ObClient *self)
3329 /* check if we're already prompting */
3330 if (!self->kill_prompt) {
3331 ObPromptAnswer answers[] = {
3332 { _("No"), OB_KILL_RESULT_NO },
3333 { _("Yes"), OB_KILL_RESULT_YES }
3337 if (client_on_localhost(self)) {
3340 if (self->kill_level == 0)
3346 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"), self->original_title, sig);
3350 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"), self->original_title);
3353 self->kill_prompt = prompt_new(m, answers,
3354 sizeof(answers)/sizeof(answers[0]),
3355 OB_KILL_RESULT_NO, /* default = no */
3356 OB_KILL_RESULT_NO, /* cancel = no */
3357 client_kill_requested, self);
3361 prompt_show(self->kill_prompt, self);
3364 void client_kill(ObClient *self)
3366 /* don't kill our own windows */
3367 if (self->prompt) return;
3369 if (client_on_localhost(self) && self->pid) {
3370 /* running on the local host */
3371 if (self->kill_level == 0) {
3372 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3373 self->window, self->pid);
3374 kill(self->pid, SIGTERM);
3377 /* show that we're trying to kill it */
3378 client_update_title(self);
3381 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3382 self->window, self->pid);
3383 kill(self->pid, SIGKILL); /* kill -9 */
3387 /* running on a remote host */
3388 XKillClient(obt_display, self->window);
3392 void client_hilite(ObClient *self, gboolean hilite)
3394 if (self->demands_attention == hilite)
3395 return; /* no change */
3397 /* don't allow focused windows to hilite */
3398 self->demands_attention = hilite && !client_focused(self);
3399 if (self->frame != NULL) { /* if we're mapping, just set the state */
3400 if (self->demands_attention)
3401 frame_flash_start(self->frame);
3403 frame_flash_stop(self->frame);
3404 client_change_state(self);
3408 static void client_set_desktop_recursive(ObClient *self,
3416 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3418 ob_debug("Setting desktop %u", target+1);
3420 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3422 old = self->desktop;
3423 self->desktop = target;
3424 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, target);
3425 /* the frame can display the current desktop state */
3426 frame_adjust_state(self->frame);
3427 /* 'move' the window to the new desktop */
3431 /* raise if it was not already on the desktop */
3432 if (old != DESKTOP_ALL && !dontraise)
3433 stacking_raise(CLIENT_AS_WINDOW(self));
3434 if (STRUT_EXISTS(self->strut))
3435 screen_update_areas();
3437 /* the new desktop's geometry may be different, so we may need to
3438 resize, for example if we are maximized */
3439 client_reconfigure(self, FALSE);
3442 /* move all transients */
3443 for (it = self->transients; it; it = g_slist_next(it))
3444 if (it->data != self)
3445 if (client_is_direct_child(self, it->data))
3446 client_set_desktop_recursive(it->data, target,
3447 donthide, dontraise);
3450 void client_set_desktop(ObClient *self, guint target,
3451 gboolean donthide, gboolean dontraise)
3453 self = client_search_top_direct_parent(self);
3454 client_set_desktop_recursive(self, target, donthide, dontraise);
3457 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3459 while (child != parent && (child = client_direct_parent(child)));
3460 return child == parent;
3463 ObClient *client_search_modal_child(ObClient *self)
3468 for (it = self->transients; it; it = g_slist_next(it)) {
3469 ObClient *c = it->data;
3470 if ((ret = client_search_modal_child(c))) return ret;
3471 if (c->modal) return c;
3476 gboolean client_validate(ObClient *self)
3480 XSync(obt_display, FALSE); /* get all events on the server */
3482 if (XCheckTypedWindowEvent(obt_display, self->window, DestroyNotify, &e) ||
3483 XCheckTypedWindowEvent(obt_display, self->window, UnmapNotify, &e))
3485 XPutBackEvent(obt_display, &e);
3492 void client_set_wm_state(ObClient *self, glong state)
3494 if (state == self->wmstate) return; /* no change */
3498 client_iconify(self, TRUE, TRUE, FALSE);
3501 client_iconify(self, FALSE, TRUE, FALSE);
3506 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3508 gboolean shaded = self->shaded;
3509 gboolean fullscreen = self->fullscreen;
3510 gboolean undecorated = self->undecorated;
3511 gboolean max_horz = self->max_horz;
3512 gboolean max_vert = self->max_vert;
3513 gboolean modal = self->modal;
3514 gboolean iconic = self->iconic;
3515 gboolean demands_attention = self->demands_attention;
3516 gboolean above = self->above;
3517 gboolean below = self->below;
3520 if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) ||
3521 action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) ||
3522 action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)))
3523 /* an invalid action was passed to the client message, ignore it */
3526 for (i = 0; i < 2; ++i) {
3527 Atom state = i == 0 ? data1 : data2;
3529 if (!state) continue;
3531 /* if toggling, then pick whether we're adding or removing */
3532 if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) {
3533 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
3534 action = modal ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3535 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3536 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
3537 action = self->max_vert ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3538 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3539 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
3540 action = self->max_horz ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3541 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3542 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
3543 action = shaded ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3544 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3545 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
3546 action = self->skip_taskbar ?
3547 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3548 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3549 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
3550 action = self->skip_pager ?
3551 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3552 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3553 else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
3554 action = self->iconic ?
3555 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3556 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3557 else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
3558 action = fullscreen ?
3559 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3560 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3561 else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
3562 action = self->above ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3563 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3564 else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
3565 action = self->below ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3566 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3567 else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
3568 action = self->demands_attention ?
3569 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3570 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3571 else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
3572 action = undecorated ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3573 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3576 if (action == OBT_PROP_ATOM(NET_WM_STATE_ADD)) {
3577 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3579 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3581 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3583 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3585 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3586 self->skip_taskbar = TRUE;
3587 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3588 self->skip_pager = TRUE;
3589 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3591 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3593 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3596 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3599 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3600 demands_attention = TRUE;
3601 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3605 } else { /* action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) */
3606 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3608 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3610 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3612 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3614 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3615 self->skip_taskbar = FALSE;
3616 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3617 self->skip_pager = FALSE;
3618 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3620 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3622 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3624 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3626 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3627 demands_attention = FALSE;
3628 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3629 undecorated = FALSE;
3634 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3635 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3637 if (max_horz == max_vert) { /* both going the same way */
3638 client_maximize(self, max_horz, 0);
3640 client_maximize(self, max_horz, 1);
3641 client_maximize(self, max_vert, 2);
3645 if (max_horz != self->max_horz)
3646 client_maximize(self, max_horz, 1);
3648 client_maximize(self, max_vert, 2);
3651 /* change fullscreen state before shading, as it will affect if the window
3653 if (fullscreen != self->fullscreen)
3654 client_fullscreen(self, fullscreen);
3655 if (shaded != self->shaded)
3656 client_shade(self, shaded);
3657 if (undecorated != self->undecorated)
3658 client_set_undecorated(self, undecorated);
3659 if (above != self->above || below != self->below) {
3660 self->above = above;
3661 self->below = below;
3662 client_calc_layer(self);
3665 if (modal != self->modal) {
3666 self->modal = modal;
3667 /* when a window changes modality, then its stacking order with its
3668 transients needs to change */
3669 stacking_raise(CLIENT_AS_WINDOW(self));
3671 /* it also may get focused. if something is focused that shouldn't
3672 be focused anymore, then move the focus */
3673 if (focus_client && client_focus_target(focus_client) != focus_client)
3674 client_focus(focus_client);
3677 if (iconic != self->iconic)
3678 client_iconify(self, iconic, FALSE, FALSE);
3680 if (demands_attention != self->demands_attention)
3681 client_hilite(self, demands_attention);
3683 client_change_state(self); /* change the hint to reflect these changes */
3686 ObClient *client_focus_target(ObClient *self)
3688 ObClient *child = NULL;
3690 child = client_search_modal_child(self);
3691 if (child) return child;
3695 gboolean client_can_focus(ObClient *self)
3697 /* choose the correct target */
3698 self = client_focus_target(self);
3700 if (!self->frame->visible)
3703 if (!(self->can_focus || self->focus_notify))
3709 gboolean client_focus(ObClient *self)
3711 /* we might not focus this window, so if we have modal children which would
3712 be focused instead, bring them to this desktop */
3713 client_bring_modal_windows(self);
3715 /* choose the correct target */
3716 self = client_focus_target(self);
3718 if (!client_can_focus(self)) {
3719 ob_debug_type(OB_DEBUG_FOCUS,
3720 "Client %s can't be focused", self->title);
3724 ob_debug_type(OB_DEBUG_FOCUS,
3725 "Focusing client \"%s\" (0x%x) at time %u",
3726 self->title, self->window, event_curtime);
3728 /* if using focus_delay, stop the timer now so that focus doesn't
3730 event_halt_focus_delay();
3732 /* if there is a grab going on, then we need to cancel it. if we move
3733 focus during the grab, applications will get NotifyWhileGrabbed events
3736 actions should not rely on being able to move focus during an
3739 event_cancel_all_key_grabs();
3741 obt_display_ignore_errors(TRUE);
3743 if (self->can_focus) {
3744 /* This can cause a BadMatch error with CurrentTime, or if an app
3745 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3746 XSetInputFocus(obt_display, self->window, RevertToPointerRoot,
3750 if (self->focus_notify) {
3752 ce.xclient.type = ClientMessage;
3753 ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
3754 ce.xclient.display = obt_display;
3755 ce.xclient.window = self->window;
3756 ce.xclient.format = 32;
3757 ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS);
3758 ce.xclient.data.l[1] = event_curtime;
3759 ce.xclient.data.l[2] = 0l;
3760 ce.xclient.data.l[3] = 0l;
3761 ce.xclient.data.l[4] = 0l;
3762 XSendEvent(obt_display, self->window, FALSE, NoEventMask, &ce);
3765 obt_display_ignore_errors(FALSE);
3767 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d",
3768 obt_display_error_occured);
3769 return !obt_display_error_occured;
3772 static void client_present(ObClient *self, gboolean here, gboolean raise,
3775 if (client_normal(self) && screen_showing_desktop)
3776 screen_show_desktop(FALSE, self);
3778 client_iconify(self, FALSE, here, FALSE);
3779 if (self->desktop != DESKTOP_ALL &&
3780 self->desktop != screen_desktop)
3783 client_set_desktop(self, screen_desktop, FALSE, TRUE);
3785 screen_set_desktop(self->desktop, FALSE);
3786 } else if (!self->frame->visible)
3787 /* if its not visible for other reasons, then don't mess
3790 if (self->shaded && unshade)
3791 client_shade(self, FALSE);
3793 stacking_raise(CLIENT_AS_WINDOW(self));
3798 void client_activate(ObClient *self, gboolean here, gboolean raise,
3799 gboolean unshade, gboolean user)
3801 client_present(self, here, raise, unshade);
3804 static void client_bring_windows_recursive(ObClient *self,
3812 for (it = self->transients; it; it = g_slist_next(it))
3813 client_bring_windows_recursive(it->data, desktop,
3814 helpers, modals, iconic);
3816 if (((helpers && client_helper(self)) ||
3817 (modals && self->modal)) &&
3818 ((self->desktop != desktop && self->desktop != DESKTOP_ALL) ||
3819 (iconic && self->iconic)))
3821 if (iconic && self->iconic)
3822 client_iconify(self, FALSE, TRUE, FALSE);
3824 client_set_desktop(self, desktop, FALSE, FALSE);
3828 void client_bring_helper_windows(ObClient *self)
3830 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE, FALSE);
3833 void client_bring_modal_windows(ObClient *self)
3835 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE, TRUE);
3838 gboolean client_focused(ObClient *self)
3840 return self == focus_client;
3843 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
3846 gulong min_diff, min_i;
3848 if (!self->nicons) {
3849 ObClientIcon *parent = NULL;
3852 for (it = self->parents; it; it = g_slist_next(it)) {
3853 ObClient *c = it->data;
3854 if ((parent = client_icon_recursive(c, w, h)))
3861 /* some kind of crappy approximation to find the icon closest in size to
3862 what we requested, but icons are generally all the same ratio as
3863 eachother so it's good enough. */
3865 min_diff = ABS(self->icons[0].width - w) + ABS(self->icons[0].height - h);
3868 for (i = 1; i < self->nicons; ++i) {
3871 diff = ABS(self->icons[i].width - w) + ABS(self->icons[i].height - h);
3872 if (diff < min_diff) {
3877 return &self->icons[min_i];
3880 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
3883 static ObClientIcon deficon;
3885 if (!(ret = client_icon_recursive(self, w, h))) {
3886 deficon.width = deficon.height = 48;
3887 deficon.data = ob_rr_theme->def_win_icon;
3893 void client_set_layer(ObClient *self, gint layer)
3897 self->above = FALSE;
3898 } else if (layer == 0) {
3899 self->below = self->above = FALSE;
3901 self->below = FALSE;
3904 client_calc_layer(self);
3905 client_change_state(self); /* reflect this in the state hints */
3908 void client_set_undecorated(ObClient *self, gboolean undecorated)
3910 if (self->undecorated != undecorated &&
3911 /* don't let it undecorate if the function is missing, but let
3913 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
3915 self->undecorated = undecorated;
3916 client_setup_decor_and_functions(self, TRUE);
3917 client_change_state(self); /* reflect this in the state hints */
3921 guint client_monitor(ObClient *self)
3923 return screen_find_monitor(&self->frame->area);
3926 ObClient *client_direct_parent(ObClient *self)
3928 if (!self->parents) return NULL;
3929 if (self->transient_for_group) return NULL;
3930 return self->parents->data;
3933 ObClient *client_search_top_direct_parent(ObClient *self)
3936 while ((p = client_direct_parent(self))) self = p;
3940 static GSList *client_search_all_top_parents_internal(ObClient *self,
3942 ObStackingLayer layer)
3947 /* move up the direct transient chain as far as possible */
3948 while ((p = client_direct_parent(self)) &&
3949 (!bylayer || p->layer == layer))
3953 ret = g_slist_prepend(NULL, self);
3955 ret = g_slist_copy(self->parents);
3960 GSList *client_search_all_top_parents(ObClient *self)
3962 return client_search_all_top_parents_internal(self, FALSE, 0);
3965 GSList *client_search_all_top_parents_layer(ObClient *self)
3967 return client_search_all_top_parents_internal(self, TRUE, self->layer);
3970 ObClient *client_search_focus_parent(ObClient *self)
3974 for (it = self->parents; it; it = g_slist_next(it))
3975 if (client_focused(it->data)) return it->data;
3980 ObClient *client_search_parent(ObClient *self, ObClient *search)
3984 for (it = self->parents; it; it = g_slist_next(it))
3985 if (it->data == search) return search;
3990 ObClient *client_search_transient(ObClient *self, ObClient *search)
3994 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
3995 if (sit->data == search)
3997 if (client_search_transient(sit->data, search))
4003 static void detect_edge(Rect area, ObDirection dir,
4004 gint my_head, gint my_size,
4005 gint my_edge_start, gint my_edge_size,
4006 gint *dest, gboolean *near_edge)
4008 gint edge_start, edge_size, head, tail;
4009 gboolean skip_head = FALSE, skip_tail = FALSE;
4012 case OB_DIRECTION_NORTH:
4013 case OB_DIRECTION_SOUTH:
4014 edge_start = area.x;
4015 edge_size = area.width;
4017 case OB_DIRECTION_EAST:
4018 case OB_DIRECTION_WEST:
4019 edge_start = area.y;
4020 edge_size = area.height;
4023 g_assert_not_reached();
4026 /* do we collide with this window? */
4027 if (!RANGES_INTERSECT(my_edge_start, my_edge_size,
4028 edge_start, edge_size))
4032 case OB_DIRECTION_NORTH:
4033 head = RECT_BOTTOM(area);
4034 tail = RECT_TOP(area);
4036 case OB_DIRECTION_SOUTH:
4037 head = RECT_TOP(area);
4038 tail = RECT_BOTTOM(area);
4040 case OB_DIRECTION_WEST:
4041 head = RECT_RIGHT(area);
4042 tail = RECT_LEFT(area);
4044 case OB_DIRECTION_EAST:
4045 head = RECT_LEFT(area);
4046 tail = RECT_RIGHT(area);
4049 g_assert_not_reached();
4052 case OB_DIRECTION_NORTH:
4053 case OB_DIRECTION_WEST:
4054 /* check if our window is past the head of this window */
4055 if (my_head <= head + 1)
4057 /* check if our window's tail is past the tail of this window */
4058 if (my_head + my_size - 1 <= tail)
4060 /* check if the head of this window is closer than the previously
4061 chosen edge (take into account that the previously chosen
4062 edge might have been a tail, not a head) */
4063 if (head + (*near_edge ? 0 : my_size) < *dest)
4065 /* check if the tail of this window is closer than the previously
4066 chosen edge (take into account that the previously chosen
4067 edge might have been a head, not a tail) */
4068 if (tail - (!*near_edge ? 0 : my_size) < *dest)
4071 case OB_DIRECTION_SOUTH:
4072 case OB_DIRECTION_EAST:
4073 /* check if our window is past the head of this window */
4074 if (my_head >= head - 1)
4076 /* check if our window's tail is past the tail of this window */
4077 if (my_head - my_size + 1 >= tail)
4079 /* check if the head of this window is closer than the previously
4080 chosen edge (take into account that the previously chosen
4081 edge might have been a tail, not a head) */
4082 if (head - (*near_edge ? 0 : my_size) > *dest)
4084 /* check if the tail of this window is closer than the previously
4085 chosen edge (take into account that the previously chosen
4086 edge might have been a head, not a tail) */
4087 if (tail + (!*near_edge ? 0 : my_size) > *dest)
4091 g_assert_not_reached();
4094 ob_debug("my head %d size %d", my_head, my_size);
4095 ob_debug("head %d tail %d deest %d", head, tail, *dest);
4097 ob_debug("using near edge %d", head);
4101 else if (!skip_tail) {
4102 ob_debug("using far edge %d", tail);
4108 void client_find_edge_directional(ObClient *self, ObDirection dir,
4109 gint my_head, gint my_size,
4110 gint my_edge_start, gint my_edge_size,
4111 gint *dest, gboolean *near_edge)
4118 a = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS,
4119 &self->frame->area);
4120 mon = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR,
4121 &self->frame->area);
4124 case OB_DIRECTION_NORTH:
4125 if (my_head >= RECT_TOP(*mon) + 1)
4126 edge = RECT_TOP(*mon) - 1;
4128 edge = RECT_TOP(*a) - 1;
4130 case OB_DIRECTION_SOUTH:
4131 if (my_head <= RECT_BOTTOM(*mon) - 1)
4132 edge = RECT_BOTTOM(*mon) + 1;
4134 edge = RECT_BOTTOM(*a) + 1;
4136 case OB_DIRECTION_EAST:
4137 if (my_head <= RECT_RIGHT(*mon) - 1)
4138 edge = RECT_RIGHT(*mon) + 1;
4140 edge = RECT_RIGHT(*a) + 1;
4142 case OB_DIRECTION_WEST:
4143 if (my_head >= RECT_LEFT(*mon) + 1)
4144 edge = RECT_LEFT(*mon) - 1;
4146 edge = RECT_LEFT(*a) - 1;
4149 g_assert_not_reached();
4151 /* default to the far edge, then narrow it down */
4155 for (it = client_list; it; it = g_list_next(it)) {
4156 ObClient *cur = it->data;
4158 /* skip windows to not bump into */
4163 if (self->desktop != cur->desktop && cur->desktop != DESKTOP_ALL &&
4164 cur->desktop != screen_desktop)
4167 ob_debug("trying window %s", cur->title);
4169 detect_edge(cur->frame->area, dir, my_head, my_size, my_edge_start,
4170 my_edge_size, dest, near_edge);
4172 dock_get_area(&dock_area);
4173 detect_edge(dock_area, dir, my_head, my_size, my_edge_start,
4174 my_edge_size, dest, near_edge);
4179 void client_find_move_directional(ObClient *self, ObDirection dir,
4183 gint e, e_start, e_size;
4187 case OB_DIRECTION_EAST:
4188 head = RECT_RIGHT(self->frame->area);
4189 size = self->frame->area.width;
4190 e_start = RECT_TOP(self->frame->area);
4191 e_size = self->frame->area.height;
4193 case OB_DIRECTION_WEST:
4194 head = RECT_LEFT(self->frame->area);
4195 size = self->frame->area.width;
4196 e_start = RECT_TOP(self->frame->area);
4197 e_size = self->frame->area.height;
4199 case OB_DIRECTION_NORTH:
4200 head = RECT_TOP(self->frame->area);
4201 size = self->frame->area.height;
4202 e_start = RECT_LEFT(self->frame->area);
4203 e_size = self->frame->area.width;
4205 case OB_DIRECTION_SOUTH:
4206 head = RECT_BOTTOM(self->frame->area);
4207 size = self->frame->area.height;
4208 e_start = RECT_LEFT(self->frame->area);
4209 e_size = self->frame->area.width;
4212 g_assert_not_reached();
4215 client_find_edge_directional(self, dir, head, size,
4216 e_start, e_size, &e, &near);
4217 *x = self->frame->area.x;
4218 *y = self->frame->area.y;
4220 case OB_DIRECTION_EAST:
4221 if (near) e -= self->frame->area.width;
4225 case OB_DIRECTION_WEST:
4227 else e -= self->frame->area.width;
4230 case OB_DIRECTION_NORTH:
4232 else e -= self->frame->area.height;
4235 case OB_DIRECTION_SOUTH:
4236 if (near) e -= self->frame->area.height;
4241 g_assert_not_reached();
4243 frame_frame_gravity(self->frame, x, y);
4246 void client_find_resize_directional(ObClient *self, ObDirection side,
4248 gint *x, gint *y, gint *w, gint *h)
4251 gint e, e_start, e_size, delta;
4256 case OB_DIRECTION_EAST:
4257 head = RECT_RIGHT(self->frame->area) +
4258 (self->size_inc.width - 1) * (grow ? 1 : -1);
4259 e_start = RECT_TOP(self->frame->area);
4260 e_size = self->frame->area.height;
4261 dir = grow ? OB_DIRECTION_EAST : OB_DIRECTION_WEST;
4263 case OB_DIRECTION_WEST:
4264 head = RECT_LEFT(self->frame->area) -
4265 (self->size_inc.width - 1) * (grow ? 1 : -1);
4266 e_start = RECT_TOP(self->frame->area);
4267 e_size = self->frame->area.height;
4268 dir = grow ? OB_DIRECTION_WEST : OB_DIRECTION_EAST;
4270 case OB_DIRECTION_NORTH:
4271 head = RECT_TOP(self->frame->area) -
4272 (self->size_inc.height - 1) * (grow ? 1 : -1);
4273 e_start = RECT_LEFT(self->frame->area);
4274 e_size = self->frame->area.width;
4275 dir = grow ? OB_DIRECTION_NORTH : OB_DIRECTION_SOUTH;
4277 case OB_DIRECTION_SOUTH:
4278 head = RECT_BOTTOM(self->frame->area) +
4279 (self->size_inc.height - 1) * (grow ? 1 : -1);
4280 e_start = RECT_LEFT(self->frame->area);
4281 e_size = self->frame->area.width;
4282 dir = grow ? OB_DIRECTION_SOUTH : OB_DIRECTION_NORTH;
4285 g_assert_not_reached();
4288 ob_debug("head %d dir %d", head, dir);
4289 client_find_edge_directional(self, dir, head, 1,
4290 e_start, e_size, &e, &near);
4291 ob_debug("edge %d", e);
4292 *x = self->frame->area.x;
4293 *y = self->frame->area.y;
4294 *w = self->frame->area.width;
4295 *h = self->frame->area.height;
4297 case OB_DIRECTION_EAST:
4298 if (grow == near) --e;
4299 delta = e - RECT_RIGHT(self->frame->area);
4302 case OB_DIRECTION_WEST:
4303 if (grow == near) ++e;
4304 delta = RECT_LEFT(self->frame->area) - e;
4308 case OB_DIRECTION_NORTH:
4309 if (grow == near) ++e;
4310 delta = RECT_TOP(self->frame->area) - e;
4314 case OB_DIRECTION_SOUTH:
4315 if (grow == near) --e;
4316 delta = e - RECT_BOTTOM(self->frame->area);
4320 g_assert_not_reached();
4322 frame_frame_gravity(self->frame, x, y);
4323 *w -= self->frame->size.left + self->frame->size.right;
4324 *h -= self->frame->size.top + self->frame->size.bottom;
4327 ObClient* client_under_pointer(void)
4331 ObClient *ret = NULL;
4333 if (screen_pointer_pos(&x, &y)) {
4334 for (it = stacking_list; it; it = g_list_next(it)) {
4335 if (WINDOW_IS_CLIENT(it->data)) {
4336 ObClient *c = WINDOW_AS_CLIENT(it->data);
4337 if (c->frame->visible &&
4338 /* check the desktop, this is done during desktop
4339 switching and windows are shown/hidden status is not
4341 (c->desktop == screen_desktop ||
4342 c->desktop == DESKTOP_ALL) &&
4343 /* ignore all animating windows */
4344 !frame_iconify_animating(c->frame) &&
4345 RECT_CONTAINS(c->frame->area, x, y))
4356 gboolean client_has_group_siblings(ObClient *self)
4358 return self->group && self->group->members->next;
4361 /*! Returns TRUE if the client is running on the same machine as Openbox */
4362 gboolean client_on_localhost(ObClient *self)
4364 return self->client_machine == NULL;