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"
28 #include "engine_interface.h"
38 #include "menuframe.h"
41 #include "render/render.h"
43 #include "obt/display.h"
52 # include <signal.h> /* for kill() */
56 #include <X11/Xutil.h>
58 /*! The event mask to grab on client windows */
59 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
62 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
67 ObClientCallback func;
71 GList *client_list = NULL;
73 static GSList *client_destroy_notifies = NULL;
75 static void client_get_all(ObClient *self, gboolean real);
76 static void client_get_startup_id(ObClient *self);
77 static void client_get_session_ids(ObClient *self);
78 static void client_get_area(ObClient *self);
79 static void client_get_desktop(ObClient *self);
80 static void client_get_state(ObClient *self);
81 static void client_get_shaped(ObClient *self);
82 static void client_get_mwm_hints(ObClient *self);
83 static void client_get_colormap(ObClient *self);
84 static void client_set_desktop_recursive(ObClient *self,
88 static void client_change_allowed_actions(ObClient *self);
89 static void client_change_state(ObClient *self);
90 static void client_change_wm_state(ObClient *self);
91 static void client_apply_startup_state(ObClient *self,
92 gint x, gint y, gint w, gint h);
93 static void client_restore_session_state(ObClient *self);
94 static gboolean client_restore_session_stacking(ObClient *self);
95 static ObAppSettings *client_get_settings_state(ObClient *self);
96 static void client_update_transient_tree(ObClient *self,
97 ObGroup *oldgroup, ObGroup *newgroup,
98 gboolean oldgtran, gboolean newgtran,
100 ObClient *newparent);
101 static void client_present(ObClient *self, gboolean here, gboolean raise,
103 static GSList *client_search_all_top_parents_internal(ObClient *self,
105 ObStackingLayer layer);
106 static void client_call_notifies(ObClient *self, GSList *list);
107 static void client_ping_event(ObClient *self, gboolean dead);
108 static void client_prompt_kill(ObClient *self);
111 void client_startup(gboolean reconfig)
113 if (reconfig) return;
118 void client_shutdown(gboolean reconfig)
120 if (reconfig) return;
123 static void client_call_notifies(ObClient *self, GSList *list)
127 for (it = list; it; it = g_slist_next(it)) {
128 ClientCallback *d = it->data;
129 d->func(self, d->data);
133 void client_add_destroy_notify(ObClientCallback func, gpointer data)
135 ClientCallback *d = g_new(ClientCallback, 1);
138 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
141 void client_remove_destroy_notify(ObClientCallback func)
145 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
146 ClientCallback *d = it->data;
147 if (d->func == func) {
149 client_destroy_notifies =
150 g_slist_delete_link(client_destroy_notifies, it);
156 void client_set_list(void)
158 Window *windows, *win_it;
160 guint size = g_list_length(client_list);
162 /* create an array of the window ids */
164 windows = g_new(Window, size);
166 for (it = client_list; it; it = g_list_next(it), ++win_it)
167 *win_it = ((ObClient*)it->data)->window;
171 OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW,
172 (gulong*)windows, size);
180 void client_manage(Window window, ObPrompt *prompt)
183 XSetWindowAttributes attrib_set;
184 gboolean activate = FALSE;
185 ObAppSettings *settings;
186 gboolean transient = FALSE;
187 Rect place, *monitor;
188 Time launch_time, map_time;
190 ob_debug("Managing window: 0x%lx", window);
192 map_time = event_get_server_time();
194 /* choose the events we want to receive on the CLIENT window
195 (ObPrompt windows can request events too) */
196 attrib_set.event_mask = CLIENT_EVENTMASK |
197 (prompt ? prompt->event_mask : 0);
198 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
199 XChangeWindowAttributes(obt_display, window,
200 CWEventMask|CWDontPropagate, &attrib_set);
202 /* create the ObClient struct, and populate it from the hints on the
204 self = g_new0(ObClient, 1);
205 self->obwin.type = OB_WINDOW_CLASS_CLIENT;
206 self->window = window;
207 self->prompt = prompt;
209 /* non-zero defaults */
210 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
211 self->gravity = NorthWestGravity;
212 self->desktop = screen_num_desktops; /* always an invalid value */
214 /* get all the stuff off the window */
215 client_get_all(self, TRUE);
217 ob_debug("Window type: %d", self->type);
218 ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
220 /* now we have all of the window's information so we can set this up.
221 do this before creating the frame, so it can tell that we are still
222 mapping and doesn't go applying things right away */
223 client_setup_decor_and_functions(self, FALSE);
225 /* specify that if we exit, the window should not be destroyed and
226 should be reparented back to root automatically, unless we are managing
227 an internal ObPrompt window */
229 XChangeSaveSet(obt_display, window, SetModeInsert);
231 /* create the decoration frame for the client window */
232 self->frame = render_plugin->frame_new(self);
233 render_plugin->frame_grab(self->frame, window_map);
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 render_plugin->frame_set_client_area (self->frame, self->area);
278 render_plugin->frame_set_hover_flag (self->frame, OB_BUTTON_NONE);
279 render_plugin->frame_set_press_flag (self->frame, OB_BUTTON_NONE);
280 render_plugin->frame_set_is_focus (self->frame, FALSE);
281 render_plugin->frame_set_decorations (self->frame, self->decorations);
282 render_plugin->frame_update_layout (self->frame, FALSE, TRUE);
283 render_plugin->frame_update_skin (self->frame);
285 /* where the frame was placed is where the window was originally */
287 monitor = screen_physical_area_monitor(screen_find_monitor(&place));
289 /* figure out placement for the window if the window is new */
290 if (ob_state() == OB_STATE_RUNNING) {
291 ob_debug("Positioned: %s @ %d %d",
292 (!self->positioned ? "no" :
293 (self->positioned == PPosition ? "program specified" :
294 (self->positioned == USPosition ? "user specified" :
295 (self->positioned == (PPosition | USPosition) ?
296 "program + user specified" :
297 "BADNESS !?")))), place.x, place.y);
299 ob_debug("Sized: %s @ %d %d",
300 (!self->sized ? "no" :
301 (self->sized == PSize ? "program specified" :
302 (self->sized == USSize ? "user specified" :
303 (self->sized == (PSize | USSize) ?
304 "program + user specified" :
305 "BADNESS !?")))), place.width, place.height);
307 /* splash screens are also returned as TRUE for transient,
308 and so will be forced on screen below */
309 transient = place_client(self, &place.x, &place.y, settings);
311 /* make sure the window is visible. */
312 client_find_onscreen(self, &place.x, &place.y,
313 place.width, place.height,
314 /* non-normal clients has less rules, and
315 windows that are being restored from a
316 session do also. we can assume you want
317 it back where you saved it. Clients saying
318 they placed themselves are subjected to
319 harder rules, ones that are placed by
320 place.c or by the user are allowed partially
321 off-screen and on xinerama divides (ie,
322 it is up to the placement routines to avoid
323 the xinerama divides)
325 splash screens get "transient" set to TRUE by
326 the place_client call
328 ob_state() == OB_STATE_RUNNING &&
330 (!((self->positioned & USPosition) ||
331 (settings && settings->pos_given)) &&
332 client_normal(self) &&
334 /* don't move oldschool fullscreen windows to
335 fit inside the struts (fixes Acroread, which
336 makes its fullscreen window fit the screen
337 but it is not USSize'd or USPosition'd) */
338 !(self->decorations == 0 &&
339 RECT_EQUAL(place, *monitor)))));
342 /* if the window isn't user-sized, then make it fit inside
343 the visible screen area on its monitor. Use basically the same rules
344 for forcing the window on screen in the client_find_onscreen call.
346 do this after place_client, it chooses the monitor!
348 splash screens get "transient" set to TRUE by
349 the place_client call
351 if (ob_state() == OB_STATE_RUNNING &&
353 (!(self->sized & USSize || self->positioned & USPosition) &&
354 client_normal(self) &&
356 /* don't shrink oldschool fullscreen windows to fit inside the
357 struts (fixes Acroread, which makes its fullscreen window
358 fit the screen but it is not USSize'd or USPosition'd) */
359 !(self->decorations == 0 && RECT_EQUAL(place, *monitor)))))
361 Rect *a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &place);
363 Strut size = render_plugin->frame_get_size(self->frame);
364 /* get the size of the frame */
365 place.width += size.left + size.right;
366 place.height += size.top + size.bottom;
368 /* fit the window inside the area */
369 place.width = MIN(place.width, a->width);
370 place.height = MIN(place.height, a->height);
372 ob_debug("setting window size to %dx%d", place.width, place.height);
374 /* get the size of the client back */
375 place.width -= size.left + size.right;
376 place.height -= size.top + size.bottom;
381 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
382 "some restrictions may apply",
383 self->window, place.x, place.y, place.width, place.height);
385 ob_debug(" but session requested %d, %d %d x %d instead, "
387 self->session->x, self->session->y,
388 self->session->w, self->session->h);
390 /* do this after the window is placed, so the premax/prefullscreen numbers
393 this also places the window
395 client_apply_startup_state(self, place.x, place.y,
396 place.width, place.height);
401 ob_debug_type(OB_DEBUG_FOCUS, "Going to try activate new window? %s",
402 activate ? "yes" : "no");
404 gboolean raise = FALSE;
406 /* This is focus stealing prevention */
407 ob_debug_type(OB_DEBUG_FOCUS,
408 "Want to focus new window 0x%x at time %u "
409 "launched at %u (last user interaction time %u)",
410 self->window, map_time, launch_time,
411 event_last_user_time);
413 if (menu_frame_visible || render_plugin->moveresize_in_progress) {
416 ob_debug_type(OB_DEBUG_FOCUS,
417 "Not focusing the window because the user is inside "
418 "an Openbox menu or is move/resizing a window and "
419 "we don't want to interrupt them");
422 /* if it's on another desktop */
423 else if (!(self->desktop == screen_desktop ||
424 self->desktop == DESKTOP_ALL) &&
425 /* the timestamp is from before you changed desktops */
426 launch_time && screen_desktop_user_time &&
427 !event_time_after(launch_time, screen_desktop_user_time))
431 ob_debug_type(OB_DEBUG_FOCUS,
432 "Not focusing the window because its on another "
435 /* If something is focused, and it's not our relative... */
436 else if (focus_client && client_search_focus_tree_full(self) == NULL &&
437 client_search_focus_group_full(self) == NULL)
439 /* If the user is working in another window right now, then don't
441 if (event_last_user_time && launch_time &&
442 event_time_after(event_last_user_time, launch_time) &&
443 event_last_user_time != launch_time &&
444 event_time_after(event_last_user_time,
445 map_time - OB_EVENT_USER_TIME_DELAY))
448 ob_debug_type(OB_DEBUG_FOCUS,
449 "Not focusing the window because the user is "
450 "working in another window");
452 /* If its a transient (and its parents aren't focused) */
453 else if (client_has_parent(self)) {
455 ob_debug_type(OB_DEBUG_FOCUS,
456 "Not focusing the window because it is a "
457 "transient, and its relatives aren't focused");
459 /* Don't steal focus from globally active clients.
460 I stole this idea from KWin. It seems nice.
462 else if (!(focus_client->can_focus ||
463 focus_client->focus_notify))
466 ob_debug_type(OB_DEBUG_FOCUS,
467 "Not focusing the window because a globally "
468 "active client has focus");
470 /* Don't move focus if it's not going to go to this window
472 else if (client_focus_target(self) != self) {
475 ob_debug_type(OB_DEBUG_FOCUS,
476 "Not focusing the window because another window "
477 "would get the focus anyway");
479 else if (!(self->desktop == screen_desktop ||
480 self->desktop == DESKTOP_ALL))
484 ob_debug_type(OB_DEBUG_FOCUS,
485 "Not focusing the window because it is on "
486 "another desktop and no relatives are focused ");
491 ob_debug_type(OB_DEBUG_FOCUS,
492 "Focus stealing prevention activated for %s at "
493 "time %u (last user interactioon time %u)",
494 self->title, map_time, event_last_user_time);
495 /* if the client isn't focused, then hilite it so the user
497 client_hilite(self, TRUE);
498 /* we may want to raise it even tho we're not activating it */
499 if (raise && !client_restore_session_stacking(self))
500 stacking_raise(CLIENT_AS_WINDOW(self));
504 /* This may look rather odd. Well it's because new windows are added
505 to the stacking order non-intrusively. If we're not going to focus
506 the new window or hilite it, then we raise it to the top. This will
507 take affect for things that don't get focused like splash screens.
508 Also if you don't have focus_new enabled, then it's going to get
509 raised to the top. Legacy begets legacy I guess?
511 if (!client_restore_session_stacking(self))
512 stacking_raise(CLIENT_AS_WINDOW(self));
515 mouse_grab_for_client(self, TRUE);
517 /* this has to happen before we try focus the window, but we want it to
518 happen after the client's stacking has been determined or it looks bad
522 if (!config_focus_under_mouse)
523 ignore_start = event_start_ignore_all_enters();
527 if (!config_focus_under_mouse)
528 event_end_ignore_all_enters(ignore_start);
532 gboolean stacked = client_restore_session_stacking(self);
533 client_present(self, FALSE, !stacked, TRUE);
536 /* add to client list/map */
537 client_list = g_list_append(client_list, self);
538 window_add(&self->window, CLIENT_AS_WINDOW(self));
540 /* this has to happen after we're in the client_list */
541 if (STRUT_EXISTS(self->strut))
542 screen_update_areas();
544 /* update the list hints */
547 /* watch for when the application stops responding. only do this for
548 normal windows, i.e. windows which have titlebars and close buttons
549 and things like that.
550 we don't need to stop pinging on unmanage, because it will be handled
551 automatically by the destroy callback!
553 if (self->ping && client_normal(self))
554 ping_start(self, client_ping_event);
556 /* free the ObAppSettings shallow copy */
559 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
560 window, render_plugin->frame_get_window(self->frame), self->class);
564 ObClient *client_fake_manage(Window window)
567 ObAppSettings *settings;
569 ob_debug("Pretend-managing window: %lx", window);
571 /* do this minimal stuff to figure out the client's decorations */
573 self = g_new0(ObClient, 1);
574 self->window = window;
576 client_get_all(self, FALSE);
577 /* per-app settings override stuff, and return the settings for other
578 uses too. this returns a shallow copy that needs to be freed */
579 settings = client_get_settings_state(self);
581 client_setup_decor_and_functions(self, FALSE);
583 /* create the decoration frame for the client window and adjust its size */
584 self->frame = render_plugin->frame_new(self);
585 render_plugin->frame_set_decorations (self->frame, self->decorations);
586 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
588 ob_debug("gave extents left %d right %d top %d bottom %d",
589 render_plugin->frame_get_size(self->frame).left, render_plugin->frame_get_size(self->frame).right,
590 render_plugin->frame_get_size(self->frame).top, render_plugin->frame_get_size(self->frame).bottom);
592 /* free the ObAppSettings shallow copy */
598 void client_unmanage_all(void)
600 while (client_list != NULL)
601 client_unmanage(client_list->data);
604 void client_unmanage(ObClient *self)
610 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
611 self->window, render_plugin->frame_get_window(self->frame),
612 self->class, self->title ? self->title : "");
614 g_assert(self != NULL);
616 /* we dont want events no more. do this before hiding the frame so we
617 don't generate more events */
618 XSelectInput(obt_display, self->window, NoEventMask);
620 /* ignore enter events from the unmap so it doesnt mess with the focus */
621 if (!config_focus_under_mouse)
622 ignore_start = event_start_ignore_all_enters();
624 self->ignore_unmaps += render_plugin->frame_hide(self->frame);
625 /* flush to send the hide to the server quickly */
628 if (!config_focus_under_mouse)
629 event_end_ignore_all_enters(ignore_start);
631 mouse_grab_for_client(self, FALSE);
633 /* remove the window from our save set, unless we are managing an internal
636 XChangeSaveSet(obt_display, self->window, SetModeDelete);
638 /* update the focus lists */
639 focus_order_remove(self);
640 if (client_focused(self)) {
641 /* don't leave an invalid focus_client */
645 /* if we're prompting to kill the client, close that */
646 prompt_unref(self->kill_prompt);
647 self->kill_prompt = NULL;
649 client_list = g_list_remove(client_list, self);
650 stacking_remove(self);
651 window_remove(self->window);
653 /* once the client is out of the list, update the struts to remove its
655 if (STRUT_EXISTS(self->strut))
656 screen_update_areas();
658 client_call_notifies(self, client_destroy_notifies);
660 /* tell our parent(s) that we're gone */
661 for (it = self->parents; it; it = g_slist_next(it))
662 ((ObClient*)it->data)->transients =
663 g_slist_remove(((ObClient*)it->data)->transients,self);
665 /* tell our transients that we're gone */
666 for (it = self->transients; it; it = g_slist_next(it)) {
667 ((ObClient*)it->data)->parents =
668 g_slist_remove(((ObClient*)it->data)->parents, self);
669 /* we could be keeping our children in a higher layer */
670 client_calc_layer(it->data);
673 /* remove from its group */
675 group_remove(self->group, self);
679 /* restore the window's original geometry so it is not lost */
685 if (self->fullscreen)
686 a = self->pre_fullscreen_area;
687 else if (self->max_horz || self->max_vert) {
688 if (self->max_horz) {
689 a.x = self->pre_max_area.x;
690 a.width = self->pre_max_area.width;
692 if (self->max_vert) {
693 a.y = self->pre_max_area.y;
694 a.height = self->pre_max_area.height;
698 self->fullscreen = self->max_horz = self->max_vert = FALSE;
699 /* let it be moved and resized no matter what */
700 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
701 self->decorations = 0; /* unmanaged windows have no decor */
703 /* give the client its border back */
704 XSetWindowBorderWidth(obt_display, self->window, self->border_width);
706 client_move_resize(self, a.x, a.y, a.width, a.height);
709 /* reparent the window out of the frame, and free the frame */
710 render_plugin->frame_ungrab(self->frame, window_map);
711 render_plugin->frame_free(self->frame);
714 if (ob_state() != OB_STATE_EXITING) {
715 /* these values should not be persisted across a window
717 OBT_PROP_ERASE(self->window, NET_WM_DESKTOP);
718 OBT_PROP_ERASE(self->window, NET_WM_STATE);
719 OBT_PROP_ERASE(self->window, WM_STATE);
721 /* if we're left in an unmapped state, the client wont be mapped.
722 this is bad, since we will no longer be managing the window on
724 XMapWindow(obt_display, self->window);
727 /* these should not be left on the window ever. other window managers
728 don't necessarily use them and it will mess them up (like compiz) */
729 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_NAME);
730 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_ICON_NAME);
732 /* update the list hints */
735 ob_debug("Unmanaged window 0x%lx", self->window);
737 /* free all data allocated in the client struct */
738 g_slist_free(self->transients);
739 for (j = 0; j < self->nicons; ++j)
740 g_free(self->icons[j].data);
741 if (self->nicons > 0)
743 g_free(self->startup_id);
744 g_free(self->wm_command);
746 g_free(self->icon_title);
747 g_free(self->original_title);
751 g_free(self->client_machine);
752 g_free(self->sm_client_id);
756 void client_fake_unmanage(ObClient *self)
758 /* this is all that got allocated to get the decorations */
760 render_plugin->frame_free(self->frame);
764 /*! Returns a new structure containing the per-app settings for this client.
765 The returned structure needs to be freed with g_free. */
766 static ObAppSettings *client_get_settings_state(ObClient *self)
768 ObAppSettings *settings;
771 settings = config_create_app_settings();
773 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
774 ObAppSettings *app = it->data;
775 gboolean match = TRUE;
777 g_assert(app->name != NULL || app->class != NULL);
779 /* we know that either name or class is not NULL so it will have to
780 match to use the rule */
782 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
784 else if (app->class &&
785 !g_pattern_match(app->class,
786 strlen(self->class), self->class, NULL))
788 else if (app->role &&
789 !g_pattern_match(app->role,
790 strlen(self->role), self->role, NULL))
794 ob_debug("Window matching: %s", app->name);
796 /* copy the settings to our struct, overriding the existing
797 settings if they are not defaults */
798 config_app_settings_copy_non_defaults(app, settings);
802 if (settings->shade != -1)
803 self->shaded = !!settings->shade;
804 if (settings->decor != -1)
805 self->undecorated = !settings->decor;
806 if (settings->iconic != -1)
807 self->iconic = !!settings->iconic;
808 if (settings->skip_pager != -1)
809 self->skip_pager = !!settings->skip_pager;
810 if (settings->skip_taskbar != -1)
811 self->skip_taskbar = !!settings->skip_taskbar;
813 if (settings->max_vert != -1)
814 self->max_vert = !!settings->max_vert;
815 if (settings->max_horz != -1)
816 self->max_horz = !!settings->max_horz;
818 if (settings->fullscreen != -1)
819 self->fullscreen = !!settings->fullscreen;
821 if (settings->desktop) {
822 if (settings->desktop == DESKTOP_ALL)
823 self->desktop = settings->desktop;
824 else if (settings->desktop > 0 &&
825 settings->desktop <= screen_num_desktops)
826 self->desktop = settings->desktop - 1;
829 if (settings->layer == -1) {
833 else if (settings->layer == 0) {
837 else if (settings->layer == 1) {
844 static void client_restore_session_state(ObClient *self)
848 ob_debug_type(OB_DEBUG_SM,
849 "Restore session for client %s", self->title);
851 if (!(it = session_state_find(self))) {
852 ob_debug_type(OB_DEBUG_SM,
853 "Session data not found for client %s", self->title);
857 self->session = it->data;
859 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s",
862 RECT_SET_POINT(self->area, self->session->x, self->session->y);
863 self->positioned = USPosition;
864 self->sized = USSize;
865 if (self->session->w > 0)
866 self->area.width = self->session->w;
867 if (self->session->h > 0)
868 self->area.height = self->session->h;
869 XResizeWindow(obt_display, self->window,
870 self->area.width, self->area.height);
872 self->desktop = (self->session->desktop == DESKTOP_ALL ?
873 self->session->desktop :
874 MIN(screen_num_desktops - 1, self->session->desktop));
875 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
877 self->shaded = self->session->shaded;
878 self->iconic = self->session->iconic;
879 self->skip_pager = self->session->skip_pager;
880 self->skip_taskbar = self->session->skip_taskbar;
881 self->fullscreen = self->session->fullscreen;
882 self->above = self->session->above;
883 self->below = self->session->below;
884 self->max_horz = self->session->max_horz;
885 self->max_vert = self->session->max_vert;
886 self->undecorated = self->session->undecorated;
888 render_plugin->frame_set_is_max_horz (self->frame, self->max_horz);
889 render_plugin->frame_set_is_max_vert (self->frame, self->max_vert);
892 static gboolean client_restore_session_stacking(ObClient *self)
896 if (!self->session) return FALSE;
898 mypos = g_list_find(session_saved_state, self->session);
899 if (!mypos) return FALSE;
901 /* start above me and look for the first client */
902 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
905 for (cit = client_list; cit; cit = g_list_next(cit)) {
906 ObClient *c = cit->data;
907 /* found a client that was in the session, so go below it */
908 if (c->session == it->data) {
909 stacking_below(CLIENT_AS_WINDOW(self),
910 CLIENT_AS_WINDOW(cit->data));
918 void client_move_onscreen(ObClient *self, gboolean rude)
920 gint x = self->area.x;
921 gint y = self->area.y;
922 if (client_find_onscreen(self, &x, &y,
924 self->area.height, rude)) {
925 client_move(self, x, y);
929 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
932 gint ox = *x, oy = *y;
933 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
939 RECT_SET(desired, *x, *y, w, h);
940 frame_rect_to_frame(self, &desired);
942 /* get where the frame would be */
943 frame_client_gravity(self, x, y);
945 Strut size = render_plugin->frame_get_size(self->frame);
947 /* get the requested size of the window with decorations */
948 fw = size.left + w + size.right;
949 fh = size.top + h + size.bottom;
951 /* If rudeness wasn't requested, then still be rude in a given direction
952 if the client is not moving, only resizing in that direction */
954 Point oldtl, oldtr, oldbl, oldbr;
955 Point newtl, newtr, newbl, newbr;
956 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
958 Rect area = render_plugin->frame_get_window_area(self->frame);
959 POINT_SET(oldtl, area.x, area.y);
960 POINT_SET(oldbr, area.x + area.width - 1,
961 area.y + area.height - 1);
962 POINT_SET(oldtr, oldbr.x, oldtl.y);
963 POINT_SET(oldbl, oldtl.x, oldbr.y);
965 POINT_SET(newtl, *x, *y);
966 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
967 POINT_SET(newtr, newbr.x, newtl.y);
968 POINT_SET(newbl, newtl.x, newbr.y);
970 /* is it moving or just resizing from some corner? */
971 stationary_l = oldtl.x == newtl.x;
972 stationary_r = oldtr.x == newtr.x;
973 stationary_t = oldtl.y == newtl.y;
974 stationary_b = oldbl.y == newbl.y;
976 /* if left edge is growing and didnt move right edge */
977 if (stationary_r && newtl.x < oldtl.x)
979 /* if right edge is growing and didnt move left edge */
980 if (stationary_l && newtr.x > oldtr.x)
982 /* if top edge is growing and didnt move bottom edge */
983 if (stationary_b && newtl.y < oldtl.y)
985 /* if bottom edge is growing and didnt move top edge */
986 if (stationary_t && newbl.y > oldbl.y)
990 /* we iterate through every monitor that the window is at least partially
991 on, to make sure it is obeying the rules on them all
993 if the window does not appear on any monitors, then use the first one
996 for (i = 0; i < screen_num_monitors; ++i) {
999 if (!screen_physical_area_monitor_contains(i, &desired)) {
1000 if (i < screen_num_monitors - 1 || found_mon)
1003 /* the window is not inside any monitor! so just use the first
1005 a = screen_area(self->desktop, 0, NULL);
1008 a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &desired);
1011 /* This makes sure windows aren't entirely outside of the screen so you
1012 can't see them at all.
1013 It makes sure 10% of the window is on the screen at least. At don't
1014 let it move itself off the top of the screen, which would hide the
1015 titlebar on you. (The user can still do this if they want too, it's
1016 only limiting the application.
1018 if (client_normal(self)) {
1019 if (!self->strut.right && *x + fw/10 >= a->x + a->width - 1)
1020 *x = a->x + a->width - fw/10;
1021 if (!self->strut.bottom && *y + fh/10 >= a->y + a->height - 1)
1022 *y = a->y + a->height - fh/10;
1023 if (!self->strut.left && *x + fw*9/10 - 1 < a->x)
1024 *x = a->x - fw*9/10;
1025 if (!self->strut.top && *y + fh*9/10 - 1 < a->y)
1026 *y = a->y - fh*9/10;
1029 /* This here doesn't let windows even a pixel outside the
1030 struts/screen. When called from client_manage, programs placing
1031 themselves are forced completely onscreen, while things like
1032 xterm -geometry resolution-width/2 will work fine. Trying to
1033 place it completely offscreen will be handled in the above code.
1034 Sorry for this confused comment, i am tired. */
1035 if (rudel && !self->strut.left && *x < a->x) *x = a->x;
1036 if (ruder && !self->strut.right && *x + fw > a->x + a->width)
1037 *x = a->x + MAX(0, a->width - fw);
1039 if (rudet && !self->strut.top && *y < a->y) *y = a->y;
1040 if (rudeb && !self->strut.bottom && *y + fh > a->y + a->height)
1041 *y = a->y + MAX(0, a->height - fh);
1046 /* get where the client should be */
1047 frame_frame_gravity(self, x, y);
1049 return ox != *x || oy != *y;
1052 static void client_get_all(ObClient *self, gboolean real)
1054 /* this is needed for the frame to set itself up */
1055 client_get_area(self);
1057 /* these things can change the decor and functions of the window */
1059 client_get_mwm_hints(self);
1060 /* this can change the mwmhints for special cases */
1061 client_get_type_and_transientness(self);
1062 client_get_state(self);
1063 client_update_normal_hints(self);
1065 /* get the session related properties, these can change decorations
1066 from per-app settings */
1067 client_get_session_ids(self);
1069 /* now we got everything that can affect the decorations */
1073 /* get this early so we have it for debugging */
1074 client_update_title(self);
1076 client_update_protocols(self);
1078 client_update_wmhints(self);
1079 /* this may have already been called from client_update_wmhints */
1080 if (!self->parents && !self->transient_for_group)
1081 client_update_transient_for(self);
1083 client_get_startup_id(self);
1084 client_get_desktop(self);/* uses transient data/group/startup id if a
1085 desktop is not specified */
1086 client_get_shaped(self);
1089 /* a couple type-based defaults for new windows */
1091 /* this makes sure that these windows appear on all desktops */
1092 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1093 self->desktop = DESKTOP_ALL;
1097 client_update_sync_request_counter(self);
1100 client_get_colormap(self);
1101 client_update_strut(self);
1102 client_update_icons(self);
1103 client_update_icon_geometry(self);
1106 static void client_get_startup_id(ObClient *self)
1108 if (!(OBT_PROP_GETS(self->window, NET_STARTUP_ID, utf8,
1109 &self->startup_id)))
1111 OBT_PROP_GETS(self->group->leader,
1112 NET_STARTUP_ID, utf8, &self->startup_id);
1115 static void client_get_area(ObClient *self)
1117 XWindowAttributes wattrib;
1120 ret = XGetWindowAttributes(obt_display, self->window, &wattrib);
1121 g_assert(ret != BadWindow);
1123 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1124 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1125 self->border_width = wattrib.border_width;
1127 ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y,
1128 wattrib.width, wattrib.height, wattrib.border_width);
1131 static void client_get_desktop(ObClient *self)
1133 guint32 d = screen_num_desktops; /* an always-invalid value */
1135 if (OBT_PROP_GET32(self->window, NET_WM_DESKTOP, CARDINAL, &d)) {
1136 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1137 self->desktop = screen_num_desktops - 1;
1140 ob_debug("client requested desktop 0x%x", self->desktop);
1143 gboolean first = TRUE;
1144 guint all = screen_num_desktops; /* not a valid value */
1146 /* if they are all on one desktop, then open it on the
1148 for (it = self->parents; it; it = g_slist_next(it)) {
1149 ObClient *c = it->data;
1151 if (c->desktop == DESKTOP_ALL) continue;
1157 else if (all != c->desktop)
1158 all = screen_num_desktops; /* make it invalid */
1160 if (all != screen_num_desktops) {
1161 self->desktop = all;
1163 ob_debug("client desktop set from parents: 0x%x",
1166 /* try get from the startup-notification protocol */
1167 else if (sn_get_desktop(self->startup_id, &self->desktop)) {
1168 if (self->desktop >= screen_num_desktops &&
1169 self->desktop != DESKTOP_ALL)
1170 self->desktop = screen_num_desktops - 1;
1171 ob_debug("client desktop set from startup-notification: 0x%x",
1174 /* defaults to the current desktop */
1176 self->desktop = screen_desktop;
1177 ob_debug("client desktop set to the current desktop: %d",
1183 static void client_get_state(ObClient *self)
1188 if (OBT_PROP_GETA32(self->window, NET_WM_STATE, ATOM, &state, &num)) {
1190 for (i = 0; i < num; ++i) {
1191 if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
1193 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
1194 self->shaded = TRUE;
1195 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
1196 self->iconic = TRUE;
1197 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
1198 self->skip_taskbar = TRUE;
1199 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
1200 self->skip_pager = TRUE;
1201 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
1202 self->fullscreen = TRUE;
1203 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
1204 self->max_vert = TRUE;
1205 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
1206 self->max_horz = TRUE;
1207 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
1209 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
1211 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
1212 self->demands_attention = TRUE;
1213 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
1214 self->undecorated = TRUE;
1221 static void client_get_shaped(ObClient *self)
1223 self->shaped = FALSE;
1225 if (obt_display_extension_shape) {
1230 XShapeSelectInput(obt_display, self->window, ShapeNotifyMask);
1232 XShapeQueryExtents(obt_display, self->window, &s, &foo,
1233 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1235 self->shaped = (s != 0);
1240 void client_update_transient_for(ObClient *self)
1243 ObClient *target = NULL;
1244 gboolean trangroup = FALSE;
1246 if (XGetTransientForHint(obt_display, self->window, &t)) {
1247 if (t != self->window) { /* cant be transient to itself! */
1248 ObWindow *tw = window_find(t);
1249 /* if this happens then we need to check for it*/
1250 g_assert(tw != CLIENT_AS_WINDOW(self));
1251 if (tw && WINDOW_IS_CLIENT(tw)) {
1252 /* watch out for windows with a parent that is something
1253 different, like a dockapp for example */
1254 target = WINDOW_AS_CLIENT(tw);
1258 /* Setting the transient_for to Root is actually illegal, however
1259 applications from time have done this to specify transient for
1261 if (!target && self->group && t == obt_root(ob_screen))
1263 } else if (self->group && self->transient)
1266 client_update_transient_tree(self, self->group, self->group,
1267 self->transient_for_group, trangroup,
1268 client_direct_parent(self), target);
1269 self->transient_for_group = trangroup;
1273 static void client_update_transient_tree(ObClient *self,
1274 ObGroup *oldgroup, ObGroup *newgroup,
1275 gboolean oldgtran, gboolean newgtran,
1276 ObClient* oldparent,
1277 ObClient *newparent)
1282 g_assert(!oldgtran || oldgroup);
1283 g_assert(!newgtran || newgroup);
1284 g_assert((!oldgtran && !oldparent) ||
1285 (oldgtran && !oldparent) ||
1286 (!oldgtran && oldparent));
1287 g_assert((!newgtran && !newparent) ||
1288 (newgtran && !newparent) ||
1289 (!newgtran && newparent));
1292 Group transient windows are not allowed to have other group
1293 transient windows as their children.
1297 /* No change has occured */
1298 if (oldgroup == newgroup &&
1299 oldgtran == newgtran &&
1300 oldparent == newparent) return;
1302 /** Remove the client from the transient tree **/
1304 for (it = self->transients; it; it = next) {
1305 next = g_slist_next(it);
1307 self->transients = g_slist_delete_link(self->transients, it);
1308 c->parents = g_slist_remove(c->parents, self);
1310 for (it = self->parents; it; it = next) {
1311 next = g_slist_next(it);
1313 self->parents = g_slist_delete_link(self->parents, it);
1314 c->transients = g_slist_remove(c->transients, self);
1317 /** Re-add the client to the transient tree **/
1319 /* If we're transient for a group then we need to add ourselves to all our
1322 for (it = newgroup->members; it; it = g_slist_next(it)) {
1325 !client_search_top_direct_parent(c)->transient_for_group &&
1328 c->transients = g_slist_prepend(c->transients, self);
1329 self->parents = g_slist_prepend(self->parents, c);
1334 /* If we are now transient for a single window we need to add ourselves to
1337 WARNING: Cyclical transient ness is possible if two windows are
1338 transient for eachother.
1340 else if (newparent &&
1341 /* don't make ourself its child if it is already our child */
1342 !client_is_direct_child(self, newparent) &&
1343 client_normal(newparent))
1345 newparent->transients = g_slist_prepend(newparent->transients, self);
1346 self->parents = g_slist_prepend(self->parents, newparent);
1349 /* Add any group transient windows to our children. But if we're transient
1350 for the group, then other group transients are not our children.
1352 WARNING: Cyclical transient-ness is possible. For e.g. if:
1353 A is transient for the group
1354 B is transient for A
1355 C is transient for B
1356 A can't be transient for C or we have a cycle
1358 if (!newgtran && newgroup &&
1360 !client_search_top_direct_parent(newparent)->transient_for_group) &&
1361 client_normal(self))
1363 for (it = newgroup->members; it; it = g_slist_next(it)) {
1365 if (c != self && c->transient_for_group &&
1366 /* Don't make it our child if it is already our parent */
1367 !client_is_direct_child(c, self))
1369 self->transients = g_slist_prepend(self->transients, c);
1370 c->parents = g_slist_prepend(c->parents, self);
1375 /** If we change our group transient-ness, our children change their
1376 effect group transient-ness, which affects how they relate to other
1379 for (it = self->transients; it; it = g_slist_next(it)) {
1381 if (!c->transient_for_group)
1382 client_update_transient_tree(c, c->group, c->group,
1383 c->transient_for_group,
1384 c->transient_for_group,
1385 client_direct_parent(c),
1386 client_direct_parent(c));
1390 static void client_get_mwm_hints(ObClient *self)
1395 self->mwmhints.flags = 0; /* default to none */
1397 if (OBT_PROP_GETA32(self->window, MOTIF_WM_HINTS, MOTIF_WM_HINTS,
1399 if (num >= OB_MWM_ELEMENTS) {
1400 self->mwmhints.flags = hints[0];
1401 self->mwmhints.functions = hints[1];
1402 self->mwmhints.decorations = hints[2];
1408 void client_get_type_and_transientness(ObClient *self)
1415 self->transient = FALSE;
1417 if (OBT_PROP_GETA32(self->window, NET_WM_WINDOW_TYPE, ATOM, &val, &num)) {
1418 /* use the first value that we know about in the array */
1419 for (i = 0; i < num; ++i) {
1420 if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
1421 self->type = OB_CLIENT_TYPE_DESKTOP;
1422 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK))
1423 self->type = OB_CLIENT_TYPE_DOCK;
1424 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR))
1425 self->type = OB_CLIENT_TYPE_TOOLBAR;
1426 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
1427 self->type = OB_CLIENT_TYPE_MENU;
1428 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY))
1429 self->type = OB_CLIENT_TYPE_UTILITY;
1430 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH))
1431 self->type = OB_CLIENT_TYPE_SPLASH;
1432 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG))
1433 self->type = OB_CLIENT_TYPE_DIALOG;
1434 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL))
1435 self->type = OB_CLIENT_TYPE_NORMAL;
1436 else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE))
1438 /* prevent this window from getting any decor or
1440 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1441 OB_MWM_FLAG_DECORATIONS);
1442 self->mwmhints.decorations = 0;
1443 self->mwmhints.functions = 0;
1445 if (self->type != (ObClientType) -1)
1446 break; /* grab the first legit type */
1451 if (XGetTransientForHint(obt_display, self->window, &t))
1452 self->transient = TRUE;
1454 if (self->type == (ObClientType) -1) {
1455 /*the window type hint was not set, which means we either classify
1456 ourself as a normal window or a dialog, depending on if we are a
1458 if (self->transient)
1459 self->type = OB_CLIENT_TYPE_DIALOG;
1461 self->type = OB_CLIENT_TYPE_NORMAL;
1464 /* then, based on our type, we can update our transientness.. */
1465 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1466 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1467 self->type == OB_CLIENT_TYPE_MENU ||
1468 self->type == OB_CLIENT_TYPE_UTILITY)
1470 self->transient = TRUE;
1474 void client_update_protocols(ObClient *self)
1479 self->focus_notify = FALSE;
1480 self->delete_window = FALSE;
1482 if (OBT_PROP_GETA32(self->window, WM_PROTOCOLS, ATOM, &proto, &num_ret)) {
1483 for (i = 0; i < num_ret; ++i) {
1484 if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW))
1485 /* this means we can request the window to close */
1486 self->delete_window = TRUE;
1487 else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS))
1488 /* if this protocol is requested, then the window will be
1489 notified whenever we want it to receive focus */
1490 self->focus_notify = TRUE;
1491 else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING))
1492 /* if this protocol is requested, then the window will allow
1493 pings to determine if it is still alive */
1496 else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST))
1497 /* if this protocol is requested, then resizing the
1498 window will be synchronized between the frame and the
1500 self->sync_request = TRUE;
1508 void client_update_sync_request_counter(ObClient *self)
1512 if (OBT_PROP_GET32(self->window, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i))
1514 self->sync_counter = i;
1516 self->sync_counter = None;
1520 static void client_get_colormap(ObClient *self)
1522 XWindowAttributes wa;
1524 if (XGetWindowAttributes(obt_display, self->window, &wa))
1525 client_update_colormap(self, wa.colormap);
1528 void client_update_colormap(ObClient *self, Colormap colormap)
1530 if (colormap == self->colormap) return;
1532 ob_debug("Setting client %s colormap: 0x%x", self->title, colormap);
1534 if (client_focused(self)) {
1535 screen_install_colormap(self, FALSE); /* uninstall old one */
1536 self->colormap = colormap;
1537 screen_install_colormap(self, FALSE); /* install new one */
1539 self->colormap = colormap;
1542 void client_update_normal_hints(ObClient *self)
1548 self->min_ratio = 0.0f;
1549 self->max_ratio = 0.0f;
1550 SIZE_SET(self->size_inc, 1, 1);
1551 SIZE_SET(self->base_size, 0, 0);
1552 SIZE_SET(self->min_size, 0, 0);
1553 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1555 /* get the hints from the window */
1556 if (XGetWMNormalHints(obt_display, self->window, &size, &ret)) {
1557 /* normal windows can't request placement! har har
1558 if (!client_normal(self))
1560 self->positioned = (size.flags & (PPosition|USPosition));
1561 self->sized = (size.flags & (PSize|USSize));
1563 if (size.flags & PWinGravity)
1564 self->gravity = size.win_gravity;
1566 if (size.flags & PAspect) {
1567 if (size.min_aspect.y)
1569 (gfloat) size.min_aspect.x / size.min_aspect.y;
1570 if (size.max_aspect.y)
1572 (gfloat) size.max_aspect.x / size.max_aspect.y;
1575 if (size.flags & PMinSize)
1576 SIZE_SET(self->min_size, size.min_width, size.min_height);
1578 if (size.flags & PMaxSize)
1579 SIZE_SET(self->max_size, size.max_width, size.max_height);
1581 if (size.flags & PBaseSize)
1582 SIZE_SET(self->base_size, size.base_width, size.base_height);
1584 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1585 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1587 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1588 self->min_size.width, self->min_size.height,
1589 self->max_size.width, self->max_size.height);
1590 ob_debug("size inc (%d %d) base size (%d %d)",
1591 self->size_inc.width, self->size_inc.height,
1592 self->base_size.width, self->base_size.height);
1595 ob_debug("Normal hints: not set");
1598 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1600 /* start with everything (cept fullscreen) */
1602 (OB_FRAME_DECOR_TITLEBAR |
1603 OB_FRAME_DECOR_HANDLE |
1604 OB_FRAME_DECOR_GRIPS |
1605 OB_FRAME_DECOR_BORDER |
1606 OB_FRAME_DECOR_ICON |
1607 OB_FRAME_DECOR_ALLDESKTOPS |
1608 OB_FRAME_DECOR_ICONIFY |
1609 OB_FRAME_DECOR_MAXIMIZE |
1610 OB_FRAME_DECOR_SHADE |
1611 OB_FRAME_DECOR_CLOSE);
1613 (OB_CLIENT_FUNC_RESIZE |
1614 OB_CLIENT_FUNC_MOVE |
1615 OB_CLIENT_FUNC_ICONIFY |
1616 OB_CLIENT_FUNC_MAXIMIZE |
1617 OB_CLIENT_FUNC_SHADE |
1618 OB_CLIENT_FUNC_CLOSE |
1619 OB_CLIENT_FUNC_BELOW |
1620 OB_CLIENT_FUNC_ABOVE |
1621 OB_CLIENT_FUNC_UNDECORATE);
1623 if (!(self->min_size.width < self->max_size.width ||
1624 self->min_size.height < self->max_size.height))
1625 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1627 switch (self->type) {
1628 case OB_CLIENT_TYPE_NORMAL:
1629 /* normal windows retain all of the possible decorations and
1630 functionality, and can be fullscreen */
1631 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1634 case OB_CLIENT_TYPE_DIALOG:
1635 /* sometimes apps make dialog windows fullscreen for some reason (for
1636 e.g. kpdf does this..) */
1637 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1640 case OB_CLIENT_TYPE_UTILITY:
1641 /* these windows don't have anything added or removed by default */
1644 case OB_CLIENT_TYPE_MENU:
1645 case OB_CLIENT_TYPE_TOOLBAR:
1646 /* these windows can't iconify or maximize */
1647 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1648 OB_FRAME_DECOR_MAXIMIZE);
1649 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1650 OB_CLIENT_FUNC_MAXIMIZE);
1653 case OB_CLIENT_TYPE_SPLASH:
1654 /* these don't get get any decorations, and the only thing you can
1655 do with them is move them */
1656 self->decorations = 0;
1657 self->functions = OB_CLIENT_FUNC_MOVE;
1660 case OB_CLIENT_TYPE_DESKTOP:
1661 /* these windows are not manipulated by the window manager */
1662 self->decorations = 0;
1663 self->functions = 0;
1666 case OB_CLIENT_TYPE_DOCK:
1667 /* these windows are not manipulated by the window manager, but they
1668 can set below layer which has a special meaning */
1669 self->decorations = 0;
1670 self->functions = OB_CLIENT_FUNC_BELOW;
1674 /* Mwm Hints are applied subtractively to what has already been chosen for
1675 decor and functionality */
1676 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1677 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1678 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1679 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1681 /* if the mwm hints request no handle or title, then all
1682 decorations are disabled, but keep the border if that's
1684 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1685 self->decorations = OB_FRAME_DECOR_BORDER;
1687 self->decorations = 0;
1692 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1693 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1694 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1695 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1696 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1697 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1698 /* dont let mwm hints kill any buttons
1699 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1700 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1701 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1702 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1704 /* dont let mwm hints kill the close button
1705 if (! (self->mwmhints.functions & MwmFunc_Close))
1706 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1710 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1711 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1712 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1713 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1714 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1715 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1717 /* can't maximize without moving/resizing */
1718 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1719 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1720 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1721 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1722 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1725 if (self->max_horz && self->max_vert) {
1726 /* you can't resize fully maximized windows */
1727 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1728 /* kill the handle on fully maxed windows */
1729 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1732 /* If there are no decorations to remove, don't allow the user to try
1734 if (self->decorations == 0)
1735 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1737 /* finally, the user can have requested no decorations, which overrides
1738 everything (but doesnt give it a border if it doesnt have one) */
1739 if (self->undecorated)
1740 self->decorations = 0;
1742 /* if we don't have a titlebar, then we cannot shade! */
1743 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1744 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1746 /* now we need to check against rules for the client's current state */
1747 if (self->fullscreen) {
1748 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1749 OB_CLIENT_FUNC_FULLSCREEN |
1750 OB_CLIENT_FUNC_ICONIFY);
1751 self->decorations = 0;
1754 client_change_allowed_actions(self);
1757 /* force reconfigure to make sure decorations are updated */
1758 client_reconfigure(self, TRUE);
1761 static void client_change_allowed_actions(ObClient *self)
1766 /* desktop windows are kept on all desktops */
1767 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1768 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP);
1770 if (self->functions & OB_CLIENT_FUNC_SHADE)
1771 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE);
1772 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1773 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE);
1774 if (self->functions & OB_CLIENT_FUNC_MOVE)
1775 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE);
1776 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1777 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE);
1778 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1779 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE);
1780 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1781 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN);
1782 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1783 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ);
1784 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT);
1786 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1787 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE);
1788 if (self->functions & OB_CLIENT_FUNC_BELOW)
1789 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW);
1790 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1791 actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE);
1793 OBT_PROP_SETA32(self->window, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num);
1795 /* make sure the window isn't breaking any rules now
1797 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1798 it can't be iconified with its parent
1801 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1802 if (self->frame) client_shade(self, FALSE);
1803 else self->shaded = FALSE;
1805 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1806 if (self->frame) client_fullscreen(self, FALSE);
1807 else self->fullscreen = FALSE;
1809 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1811 if (self->frame) client_maximize(self, FALSE, 0);
1812 else self->max_vert = self->max_horz = FALSE;
1813 render_plugin->frame_set_is_max_horz (self->frame, self->max_horz);
1814 render_plugin->frame_set_is_max_vert (self->frame, self->max_vert);
1818 void client_update_wmhints(ObClient *self)
1822 /* assume a window takes input if it doesnt specify */
1823 self->can_focus = TRUE;
1825 if ((hints = XGetWMHints(obt_display, self->window)) != NULL) {
1828 if (hints->flags & InputHint)
1829 self->can_focus = hints->input;
1831 /* only do this when first managing the window *AND* when we aren't
1833 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1834 if (hints->flags & StateHint)
1835 self->iconic = hints->initial_state == IconicState;
1838 self->urgent = (hints->flags & XUrgencyHint);
1839 if (self->urgent && !ur)
1840 client_hilite(self, TRUE);
1841 else if (!self->urgent && ur && self->demands_attention)
1842 client_hilite(self, FALSE);
1844 if (!(hints->flags & WindowGroupHint))
1845 hints->window_group = None;
1847 /* did the group state change? */
1848 if (hints->window_group !=
1849 (self->group ? self->group->leader : None))
1851 ObGroup *oldgroup = self->group;
1853 /* remove from the old group if there was one */
1854 if (self->group != NULL) {
1855 group_remove(self->group, self);
1859 /* add ourself to the group if we have one */
1860 if (hints->window_group != None) {
1861 self->group = group_add(hints->window_group, self);
1864 /* Put ourselves into the new group's transient tree, and remove
1865 ourselves from the old group's */
1866 client_update_transient_tree(self, oldgroup, self->group,
1867 self->transient_for_group,
1868 self->transient_for_group,
1869 client_direct_parent(self),
1870 client_direct_parent(self));
1872 /* Lastly, being in a group, or not, can change if the window is
1873 transient for anything.
1875 The logic for this is:
1876 self->transient = TRUE always if the window wants to be
1877 transient for something, even if transient_for was NULL because
1878 it wasn't in a group before.
1880 If parents was NULL and oldgroup was NULL we can assume
1881 that when we add the new group, it will become transient for
1884 If transient_for_group is TRUE, then it must have already
1885 had a group. If it is getting a new group, the above call to
1886 client_update_transient_tree has already taken care of
1887 everything ! If it is losing all group status then it will
1888 no longer be transient for anything and that needs to be
1891 if (self->transient &&
1892 ((self->parents == NULL && oldgroup == NULL) ||
1893 (self->transient_for_group && !self->group)))
1894 client_update_transient_for(self);
1897 /* the WM_HINTS can contain an icon */
1898 if (hints->flags & IconPixmapHint)
1899 client_update_icons(self);
1905 void client_update_title(ObClient *self)
1908 gchar *visible = NULL;
1910 g_free(self->title);
1911 g_free(self->original_title);
1914 if (!OBT_PROP_GETS(self->window, NET_WM_NAME, utf8, &data)) {
1915 /* try old x stuff */
1916 if (!(OBT_PROP_GETS(self->window, WM_NAME, locale, &data)
1917 || OBT_PROP_GETS(self->window, WM_NAME, utf8, &data))) {
1918 if (self->transient) {
1920 GNOME alert windows are not given titles:
1921 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1923 data = g_strdup("");
1925 data = g_strdup("Unnamed Window");
1928 self->original_title = g_strdup(data);
1930 if (self->client_machine) {
1931 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1936 if (self->not_responding) {
1938 if (self->kill_level > 0)
1939 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1941 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1945 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_NAME, utf8, visible);
1946 self->title = visible;
1949 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
1951 /* update the icon title */
1953 g_free(self->icon_title);
1956 if (!OBT_PROP_GETS(self->window, NET_WM_ICON_NAME, utf8, &data))
1957 /* try old x stuff */
1958 if (!(OBT_PROP_GETS(self->window, WM_ICON_NAME, locale, &data) ||
1959 OBT_PROP_GETS(self->window, WM_ICON_NAME, utf8, &data)))
1960 data = g_strdup(self->title);
1962 if (self->client_machine) {
1963 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
1968 if (self->not_responding) {
1970 if (self->kill_level > 0)
1971 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
1973 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
1977 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_ICON_NAME, utf8, visible);
1978 self->icon_title = visible;
1981 void client_update_strut(ObClient *self)
1985 gboolean got = FALSE;
1988 if (OBT_PROP_GETA32(self->window, NET_WM_STRUT_PARTIAL, CARDINAL,
1993 STRUT_PARTIAL_SET(strut,
1994 data[0], data[2], data[1], data[3],
1995 data[4], data[5], data[8], data[9],
1996 data[6], data[7], data[10], data[11]);
2002 OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) {
2008 /* use the screen's width/height */
2009 a = screen_physical_area_all_monitors();
2011 STRUT_PARTIAL_SET(strut,
2012 data[0], data[2], data[1], data[3],
2013 a->y, a->y + a->height - 1,
2014 a->x, a->x + a->width - 1,
2015 a->y, a->y + a->height - 1,
2016 a->x, a->x + a->width - 1);
2023 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2024 0, 0, 0, 0, 0, 0, 0, 0);
2026 if (!STRUT_EQUAL(strut, self->strut)) {
2027 self->strut = strut;
2029 /* updating here is pointless while we're being mapped cuz we're not in
2030 the client list yet */
2032 screen_update_areas();
2036 /* Avoid storing icons above this size if possible */
2037 #define AVOID_ABOVE 64
2039 void client_update_icons(ObClient *self)
2044 guint num_seen; /* number of icons present */
2045 guint num_small_seen; /* number of icons small enough present */
2046 guint smallest, smallest_area;
2048 for (i = 0; i < self->nicons; ++i)
2049 g_free(self->icons[i].data);
2050 if (self->nicons > 0)
2051 g_free(self->icons);
2054 if (OBT_PROP_GETA32(self->window, NET_WM_ICON, CARDINAL, &data, &num)) {
2055 /* figure out how many valid icons are in here */
2057 num_seen = num_small_seen = 0;
2058 smallest = smallest_area = 0;
2064 /* watch for it being too small for the specified size, or for
2065 zero sized icons. */
2066 if (i > num || w == 0 || h == 0) break;
2068 if (!smallest_area || w*h < smallest_area) {
2069 smallest = num_seen;
2070 smallest_area = w*h;
2073 if (w <= AVOID_ABOVE && h <= AVOID_ABOVE)
2076 if (num_small_seen > 0)
2077 self->nicons = num_small_seen;
2081 self->icons = g_new(ObClientIcon, self->nicons);
2083 /* store the icons */
2085 for (j = 0; j < self->nicons;) {
2088 w = self->icons[j].width = data[i++];
2089 h = self->icons[j].height = data[i++];
2091 /* if there are some icons smaller than the threshold, we're
2092 skipping all the ones above */
2093 if (num_small_seen > 0) {
2094 if (w > AVOID_ABOVE || h > AVOID_ABOVE) {
2099 /* if there were no icons smaller than the threshold, then we are
2100 only taking the smallest available one we saw */
2101 else if (j != smallest) {
2106 self->icons[j].data = g_new(RrPixel32, w * h);
2107 for (x = 0, y = 0, t = 0; t < w * h; ++t, ++x, ++i) {
2112 self->icons[j].data[t] =
2113 (((data[i] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2114 (((data[i] >> 16) & 0xff) << RrDefaultRedOffset) +
2115 (((data[i] >> 8) & 0xff) << RrDefaultGreenOffset) +
2116 (((data[i] >> 0) & 0xff) << RrDefaultBlueOffset);
2127 if ((hints = XGetWMHints(obt_display, self->window))) {
2128 if (hints->flags & IconPixmapHint) {
2130 self->icons = g_new(ObClientIcon, self->nicons);
2131 obt_display_ignore_errors(TRUE);
2132 if (!RrPixmapToRGBA(ob_rr_inst,
2134 (hints->flags & IconMaskHint ?
2135 hints->icon_mask : None),
2136 &self->icons[0].width,
2137 &self->icons[0].height,
2138 &self->icons[0].data))
2140 g_free(self->icons);
2143 obt_display_ignore_errors(FALSE);
2149 /* set the default icon onto the window
2150 in theory, this could be a race, but if a window doesn't set an icon
2151 or removes it entirely, it's not very likely it is going to set one
2152 right away afterwards
2154 if it has parents, then one of them will have an icon already
2156 if (self->nicons == 0 && !self->parents) {
2157 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2160 data = g_new(gulong, 48*48+2);
2161 data[0] = data[1] = 48;
2162 for (i = 0; i < 48*48; ++i)
2163 data[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2164 (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) +
2165 (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) +
2166 (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0);
2167 OBT_PROP_SETA32(self->window, NET_WM_ICON, CARDINAL, data, 48*48+2);
2169 } else if (self->frame)
2170 render_plugin->frame_update_skin (self->frame);
2171 /* don't draw the icon empty if we're just setting one now anyways,
2172 we'll get the property change any second */
2173 //frame_adjust_icon(self->frame);
2176 void client_update_icon_geometry(ObClient *self)
2181 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2183 if (OBT_PROP_GETA32(self->window, NET_WM_ICON_GEOMETRY, CARDINAL,
2187 /* don't let them set it with an area < 0 */
2188 RECT_SET(self->icon_geometry, data[0], data[1],
2189 MAX(data[2],0), MAX(data[3],0));
2194 static void client_get_session_ids(ObClient *self)
2201 if (!OBT_PROP_GET32(self->window, WM_CLIENT_LEADER, WINDOW, &leader))
2204 /* get the SM_CLIENT_ID */
2207 got = OBT_PROP_GETS(leader, SM_CLIENT_ID, locale, &self->sm_client_id);
2209 OBT_PROP_GETS(self->window, SM_CLIENT_ID, locale, &self->sm_client_id);
2211 /* get the WM_CLASS (name and class). make them "" if they are not
2215 got = OBT_PROP_GETSS(leader, WM_CLASS, locale, &ss);
2217 got = OBT_PROP_GETSS(self->window, WM_CLASS, locale, &ss);
2221 self->name = g_strdup(ss[0]);
2223 self->class = g_strdup(ss[1]);
2228 if (self->name == NULL) self->name = g_strdup("");
2229 if (self->class == NULL) self->class = g_strdup("");
2231 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2234 got = OBT_PROP_GETS(leader, WM_WINDOW_ROLE, locale, &s);
2236 got = OBT_PROP_GETS(self->window, WM_WINDOW_ROLE, locale, &s);
2241 self->role = g_strdup("");
2243 /* get the WM_COMMAND */
2247 got = OBT_PROP_GETSS(leader, WM_COMMAND, locale, &ss);
2249 got = OBT_PROP_GETSS(self->window, WM_COMMAND, locale, &ss);
2252 /* merge/mash them all together */
2253 gchar *merge = NULL;
2256 for (i = 0; ss[i]; ++i) {
2259 merge = g_strconcat(merge, ss[i], NULL);
2261 merge = g_strconcat(ss[i], NULL);
2266 self->wm_command = merge;
2269 /* get the WM_CLIENT_MACHINE */
2272 got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, locale, &s);
2274 got = OBT_PROP_GETS(self->window, WM_CLIENT_MACHINE, locale, &s);
2277 gchar localhost[128];
2280 gethostname(localhost, 127);
2281 localhost[127] = '\0';
2282 if (strcmp(localhost, s) != 0)
2283 self->client_machine = s;
2287 /* see if it has the PID set too (the PID requires that the
2288 WM_CLIENT_MACHINE be set) */
2289 if (OBT_PROP_GET32(self->window, NET_WM_PID, CARDINAL, &pid))
2294 static void client_change_wm_state(ObClient *self)
2299 old = self->wmstate;
2301 if (self->shaded || self->iconic ||
2302 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2304 self->wmstate = IconicState;
2306 self->wmstate = NormalState;
2308 if (old != self->wmstate) {
2309 OBT_PROP_MSG(ob_screen, self->window, KDE_WM_CHANGE_STATE,
2310 self->wmstate, 1, 0, 0, 0);
2312 state[0] = self->wmstate;
2314 OBT_PROP_SETA32(self->window, WM_STATE, WM_STATE, state, 2);
2318 static void client_change_state(ObClient *self)
2320 gulong netstate[12];
2325 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
2327 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED);
2329 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN);
2330 if (self->skip_taskbar)
2331 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR);
2332 if (self->skip_pager)
2333 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER);
2334 if (self->fullscreen)
2335 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN);
2337 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT);
2339 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ);
2341 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE);
2343 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW);
2344 if (self->demands_attention)
2345 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION);
2346 if (self->undecorated)
2347 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED);
2348 OBT_PROP_SETA32(self->window, NET_WM_STATE, ATOM, netstate, num);
2351 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
2354 ObClient *client_search_focus_tree(ObClient *self)
2359 for (it = self->transients; it; it = g_slist_next(it)) {
2360 if (client_focused(it->data)) return it->data;
2361 if ((ret = client_search_focus_tree(it->data))) return ret;
2366 ObClient *client_search_focus_tree_full(ObClient *self)
2368 if (self->parents) {
2371 for (it = self->parents; it; it = g_slist_next(it)) {
2372 ObClient *c = it->data;
2373 if ((c = client_search_focus_tree_full(it->data))) return c;
2379 /* this function checks the whole tree, the client_search_focus_tree
2380 does not, so we need to check this window */
2381 if (client_focused(self))
2383 return client_search_focus_tree(self);
2387 ObClient *client_search_focus_group_full(ObClient *self)
2392 for (it = self->group->members; it; it = g_slist_next(it)) {
2393 ObClient *c = it->data;
2395 if (client_focused(c)) return c;
2396 if ((c = client_search_focus_tree(it->data))) return c;
2399 if (client_focused(self)) return self;
2403 gboolean client_has_parent(ObClient *self)
2405 return self->parents != NULL;
2408 static ObStackingLayer calc_layer(ObClient *self)
2413 monitor = screen_physical_area_monitor(client_monitor(self));
2415 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2416 l = OB_STACKING_LAYER_DESKTOP;
2417 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2418 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2419 else l = OB_STACKING_LAYER_ABOVE;
2421 else if ((self->fullscreen ||
2422 /* No decorations and fills the monitor = oldskool fullscreen.
2423 But not for maximized windows.
2425 (self->decorations == 0 &&
2426 !(self->max_horz && self->max_vert) &&
2427 RECT_EQUAL(self->area, *monitor))) &&
2428 /* you are fullscreen while you or your children are focused.. */
2429 (client_focused(self) || client_search_focus_tree(self) ||
2430 /* you can be fullscreen if you're on another desktop */
2431 (self->desktop != screen_desktop &&
2432 self->desktop != DESKTOP_ALL) ||
2433 /* and you can also be fullscreen if the focused client is on
2434 another monitor, or nothing else is focused */
2436 client_monitor(focus_client) != client_monitor(self))))
2437 l = OB_STACKING_LAYER_FULLSCREEN;
2438 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2439 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2440 else l = OB_STACKING_LAYER_NORMAL;
2447 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2448 ObStackingLayer min)
2450 ObStackingLayer old, own;
2454 own = calc_layer(self);
2455 self->layer = MAX(own, min);
2457 if (self->layer != old) {
2458 stacking_remove(CLIENT_AS_WINDOW(self));
2459 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2462 /* we've been restacked */
2463 self->visited = TRUE;
2465 for (it = self->transients; it; it = g_slist_next(it))
2466 client_calc_layer_recursive(it->data, orig,
2470 static void client_calc_layer_internal(ObClient *self)
2474 /* transients take on the layer of their parents */
2475 sit = client_search_all_top_parents(self);
2477 for (; sit; sit = g_slist_next(sit))
2478 client_calc_layer_recursive(sit->data, self, 0);
2481 void client_calc_layer(ObClient *self)
2485 /* skip over stuff above fullscreen layer */
2486 for (it = stacking_list; it; it = g_list_next(it))
2487 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2489 /* find the windows in the fullscreen layer, and mark them not-visited */
2490 for (; it; it = g_list_next(it)) {
2491 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2492 else if (WINDOW_IS_CLIENT(it->data))
2493 WINDOW_AS_CLIENT(it->data)->visited = FALSE;
2496 client_calc_layer_internal(self);
2498 /* skip over stuff above fullscreen layer */
2499 for (it = stacking_list; it; it = g_list_next(it))
2500 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2502 /* now recalc any windows in the fullscreen layer which have not
2503 had their layer recalced already */
2504 for (; it; it = g_list_next(it)) {
2505 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2506 else if (WINDOW_IS_CLIENT(it->data) &&
2507 !WINDOW_AS_CLIENT(it->data)->visited)
2508 client_calc_layer_internal(it->data);
2512 gboolean client_should_show(ObClient *self)
2516 if (client_normal(self) && screen_showing_desktop)
2518 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2524 gboolean client_show(ObClient *self)
2526 gboolean show = FALSE;
2528 if (client_should_show(self)) {
2529 /* replay pending pointer event before showing the window, in case it
2530 should be going to something under the window */
2531 mouse_replay_pointer();
2533 render_plugin->frame_show(self->frame);
2536 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2537 it needs to be in IconicState. This includes when it is on another
2540 client_change_wm_state(self);
2545 gboolean client_hide(ObClient *self)
2547 gboolean hide = FALSE;
2549 if (!client_should_show(self)) {
2550 if (self == focus_client) {
2551 /* if there is a grab going on, then we need to cancel it. if we
2552 move focus during the grab, applications will get
2553 NotifyWhileGrabbed events and ignore them !
2555 actions should not rely on being able to move focus during an
2558 event_cancel_all_key_grabs();
2561 /* We don't need to ignore enter events here.
2562 The window can hide/iconify in 3 different ways:
2563 1 - through an x message. in this case we ignore all enter events
2564 caused by responding to the x message (unless underMouse)
2565 2 - by a keyboard action. in this case we ignore all enter events
2566 caused by the action
2567 3 - by a mouse action. in this case they are doing stuff with the
2568 mouse and focus _should_ move.
2570 Also in action_end, we simulate an enter event that can't be ignored
2571 so trying to ignore them is futile in case 3 anyways
2574 /* replay pending pointer event before hiding the window, in case it
2575 should be going to the window */
2576 mouse_replay_pointer();
2578 self->ignore_unmaps += render_plugin->frame_hide(self->frame);
2581 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2582 it needs to be in IconicState. This includes when it is on another
2585 client_change_wm_state(self);
2590 void client_showhide(ObClient *self)
2592 if (!client_show(self))
2596 gboolean client_normal(ObClient *self) {
2597 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2598 self->type == OB_CLIENT_TYPE_DOCK ||
2599 self->type == OB_CLIENT_TYPE_SPLASH);
2602 gboolean client_helper(ObClient *self)
2604 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2605 self->type == OB_CLIENT_TYPE_MENU ||
2606 self->type == OB_CLIENT_TYPE_TOOLBAR);
2609 gboolean client_mouse_focusable(ObClient *self)
2611 return !(self->type == OB_CLIENT_TYPE_MENU ||
2612 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2613 self->type == OB_CLIENT_TYPE_SPLASH ||
2614 self->type == OB_CLIENT_TYPE_DOCK);
2617 gboolean client_enter_focusable(ObClient *self)
2619 /* you can focus desktops but it shouldn't on enter */
2620 return (client_mouse_focusable(self) &&
2621 self->type != OB_CLIENT_TYPE_DESKTOP);
2625 static void client_apply_startup_state(ObClient *self,
2626 gint x, gint y, gint w, gint h)
2628 /* save the states that we are going to apply */
2629 gboolean iconic = self->iconic;
2630 gboolean fullscreen = self->fullscreen;
2631 gboolean undecorated = self->undecorated;
2632 gboolean shaded = self->shaded;
2633 gboolean demands_attention = self->demands_attention;
2634 gboolean max_horz = self->max_horz;
2635 gboolean max_vert = self->max_vert;
2639 /* turn them all off in the client, so they won't affect the window
2641 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2642 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2644 /* move the client to its placed position, or it it's already there,
2645 generate a ConfigureNotify telling the client where it is.
2647 do this after adjusting the frame. otherwise it gets all weird and
2648 clients don't work right
2650 do this before applying the states so they have the correct
2651 pre-max/pre-fullscreen values
2653 client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
2654 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2655 self->window, x, y, w, h);
2656 /* save the area, and make it where it should be for the premax stuff */
2657 oldarea = self->area;
2658 RECT_SET(self->area, x, y, w, h);
2659 render_plugin->frame_set_client_area (self->frame, self->area);
2661 /* apply the states. these are in a carefully crafted order.. */
2664 client_iconify(self, TRUE, FALSE, TRUE);
2666 client_fullscreen(self, TRUE);
2668 client_set_undecorated(self, TRUE);
2670 client_shade(self, TRUE);
2671 if (demands_attention)
2672 client_hilite(self, TRUE);
2674 if (max_vert && max_horz)
2675 client_maximize(self, TRUE, 0);
2677 client_maximize(self, TRUE, 2);
2679 client_maximize(self, TRUE, 1);
2681 /* if the window hasn't been configured yet, then do so now, in fact the
2682 x,y,w,h may _not_ be the same as the area rect, which can end up
2683 meaning that the client isn't properly moved/resized by the fullscreen
2685 pho can cause this because it maps at size of the screen but not 0,0
2686 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2687 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2688 cuz thats where the pre-fullscreen will be. however the actual area is
2689 not, so this needs to be called even if we have fullscreened/maxed
2691 self->area = oldarea;
2692 render_plugin->frame_set_client_area (self->frame, self->area);
2693 render_plugin->frame_set_decorations (self->frame, self->decorations);
2694 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
2695 render_plugin->frame_set_is_max_horz (self->frame, self->max_horz);
2696 render_plugin->frame_set_is_max_vert (self->frame, self->max_vert);
2697 client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
2699 /* set the desktop hint, to make sure that it always exists */
2700 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
2702 /* nothing to do for the other states:
2711 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2713 /* these should be the current values. this is for when you're not moving,
2715 g_assert(*x == self->area.x);
2716 g_assert(oldw == self->area.width);
2719 switch (self->gravity) {
2721 case NorthWestGravity:
2723 case SouthWestGravity:
2730 *x -= (neww - oldw) / 2;
2732 case NorthEastGravity:
2734 case SouthEastGravity:
2740 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2742 /* these should be the current values. this is for when you're not moving,
2744 g_assert(*y == self->area.y);
2745 g_assert(oldh == self->area.height);
2748 switch (self->gravity) {
2750 case NorthWestGravity:
2752 case NorthEastGravity:
2759 *y -= (newh - oldh) / 2;
2761 case SouthWestGravity:
2763 case SouthEastGravity:
2769 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2770 gint *logicalw, gint *logicalh,
2773 Rect desired = {*x, *y, *w, *h};
2774 frame_rect_to_frame(self, &desired);
2776 /* make the frame recalculate its dimentions n shit without changing
2777 anything visible for real, this way the constraints below can work with
2778 the updated frame dimensions. */
2779 render_plugin->frame_set_decorations (self->frame, self->decorations);
2780 render_plugin->frame_update_layout (self->frame, FALSE, TRUE);
2782 /* gets the frame's position */
2783 frame_client_gravity(self, x, y);
2785 /* these positions are frame positions, not client positions */
2787 /* set the size and position if fullscreen */
2788 if (self->fullscreen) {
2792 i = screen_find_monitor(&desired);
2793 a = screen_physical_area_monitor(i);
2800 user = FALSE; /* ignore if the client can't be moved/resized when it
2804 } else if (self->max_horz || self->max_vert) {
2808 /* use all possible struts when maximizing to the full screen */
2809 i = screen_find_monitor(&desired);
2810 a = screen_area(self->desktop, i,
2811 (self->max_horz && self->max_vert ? NULL : &desired));
2813 Strut size = render_plugin->frame_get_size(self->frame);
2814 /* set the size and position if maximized */
2815 if (self->max_horz) {
2817 *w = a->width - size.left - size.right;
2819 if (self->max_vert) {
2821 *h = a->height - size.top - size.bottom;
2824 user = FALSE; /* ignore if the client can't be moved/resized when it
2830 /* gets the client's position */
2831 frame_frame_gravity(self, x, y);
2833 /* work within the prefered sizes given by the window */
2834 if (!(*w == self->area.width && *h == self->area.height)) {
2835 gint basew, baseh, minw, minh;
2837 gfloat minratio, maxratio;
2839 incw = self->fullscreen || self->max_horz ? 1 : self->size_inc.width;
2840 inch = self->fullscreen || self->max_vert ? 1 : self->size_inc.height;
2841 minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2842 0 : self->min_ratio;
2843 maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2844 0 : self->max_ratio;
2846 /* base size is substituted with min size if not specified */
2847 if (self->base_size.width || self->base_size.height) {
2848 basew = self->base_size.width;
2849 baseh = self->base_size.height;
2851 basew = self->min_size.width;
2852 baseh = self->min_size.height;
2854 /* min size is substituted with base size if not specified */
2855 if (self->min_size.width || self->min_size.height) {
2856 minw = self->min_size.width;
2857 minh = self->min_size.height;
2859 minw = self->base_size.width;
2860 minh = self->base_size.height;
2863 /* if this is a user-requested resize, then check against min/max
2866 /* smaller than min size or bigger than max size? */
2867 if (*w > self->max_size.width) *w = self->max_size.width;
2868 if (*w < minw) *w = minw;
2869 if (*h > self->max_size.height) *h = self->max_size.height;
2870 if (*h < minh) *h = minh;
2875 /* keep to the increments */
2879 /* you cannot resize to nothing */
2880 if (basew + *w < 1) *w = 1 - basew;
2881 if (baseh + *h < 1) *h = 1 - baseh;
2883 /* save the logical size */
2884 *logicalw = incw > 1 ? *w : *w + basew;
2885 *logicalh = inch > 1 ? *h : *h + baseh;
2893 /* adjust the height to match the width for the aspect ratios.
2894 for this, min size is not substituted for base size ever. */
2895 *w -= self->base_size.width;
2896 *h -= self->base_size.height;
2899 if (*h * minratio > *w) {
2900 *h = (gint)(*w / minratio);
2902 /* you cannot resize to nothing */
2905 *w = (gint)(*h * minratio);
2909 if (*h * maxratio < *w) {
2910 *h = (gint)(*w / maxratio);
2912 /* you cannot resize to nothing */
2915 *w = (gint)(*h * minratio);
2919 *w += self->base_size.width;
2920 *h += self->base_size.height;
2923 /* these override the above states! if you cant move you can't move! */
2925 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
2929 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
2930 *w = self->area.width;
2931 *h = self->area.height;
2940 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
2941 gboolean user, gboolean final, gboolean force_reply)
2945 gboolean send_resize_client;
2946 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
2947 gboolean fmoved, fresized;
2948 guint fdecor = render_plugin->frame_get_decorations(self->frame);
2949 gboolean fhorz = render_plugin->frame_is_max_horz(self->frame);
2950 gboolean fvert = render_plugin->frame_is_max_vert(self->frame);
2951 gint logicalw, logicalh;
2953 Strut size = render_plugin->frame_get_size(self->frame);
2954 Rect area = render_plugin->frame_get_window_area(self->frame);
2956 /* find the new x, y, width, and height (and logical size) */
2957 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
2959 /* set the logical size if things changed */
2960 if (!(w == self->area.width && h == self->area.height))
2961 SIZE_SET(self->logical_size, logicalw, logicalh);
2963 /* figure out if we moved or resized or what */
2964 moved = (x != self->area.x || y != self->area.y);
2965 resized = (w != self->area.width || h != self->area.height);
2967 oldw = self->area.width;
2968 oldh = self->area.height;
2969 oldframe = render_plugin->frame_get_window_area(self->frame);
2970 RECT_SET(self->area, x, y, w, h);
2972 render_plugin->frame_set_client_area (self->frame, self->area);
2974 /* for app-requested resizes, always resize if 'resized' is true.
2975 for user-requested ones, only resize if final is true, or when
2976 resizing in redraw mode */
2977 send_resize_client = ((!user && resized) ||
2979 (resized && config_resize_redraw))));
2981 /* if the client is enlarging, then resize the client before the frame */
2982 if (send_resize_client && (w > oldw || h > oldh)) {
2983 render_plugin->frame_set_decorations (self->frame, self->decorations);
2984 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
2987 /* find the frame's dimensions and move/resize it */
2991 /* if decorations changed, then readjust everything for the frame */
2992 if (self->decorations != fdecor ||
2993 self->max_horz != fhorz || self->max_vert != fvert)
2995 fmoved = fresized = TRUE;
2998 /* adjust the frame */
2999 if (fmoved || fresized) {
3000 gulong ignore_start;
3002 ignore_start = event_start_ignore_all_enters();
3004 /* replay pending pointer event before move the window, in case it
3005 would change what window gets the event */
3006 mouse_replay_pointer();
3008 render_plugin->frame_set_decorations (self->frame, self->decorations);
3009 render_plugin->frame_update_layout (self->frame, TRUE, FALSE);
3012 event_end_ignore_all_enters(ignore_start);
3015 if (!user || final) {
3016 gint oldrx = self->root_pos.x;
3017 gint oldry = self->root_pos.y;
3018 /* we have reset the client to 0 border width, so don't include
3019 it in these coords */
3020 POINT_SET(self->root_pos,
3021 area.x + size.left -
3024 self->border_width);
3025 if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
3029 /* This is kinda tricky and should not be changed.. let me explain!
3031 When user = FALSE, then the request is coming from the application
3032 itself, and we are more strict about when to send a synthetic
3033 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3034 in this case (if force_reply is true)
3036 When user = TRUE, then the request is coming from "us", like when we
3037 maximize a window or something. In this case we are more lenient. We
3038 used to follow the same rules as above, but _Java_ Swing can't handle
3039 this. So just to appease Swing, when user = TRUE, we always send
3040 a synthetic ConfigureNotify to give the window its root coordinates.
3042 if ((!user && !resized && (rootmoved || force_reply)) ||
3043 (user && final && rootmoved))
3047 event.type = ConfigureNotify;
3048 event.xconfigure.display = obt_display;
3049 event.xconfigure.event = self->window;
3050 event.xconfigure.window = self->window;
3052 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3053 self->title, self->root_pos.x, self->root_pos.y, w, h);
3055 /* root window real coords */
3056 event.xconfigure.x = self->root_pos.x;
3057 event.xconfigure.y = self->root_pos.y;
3058 event.xconfigure.width = w;
3059 event.xconfigure.height = h;
3060 event.xconfigure.border_width = self->border_width;
3061 event.xconfigure.above = None;
3062 event.xconfigure.override_redirect = FALSE;
3063 XSendEvent(event.xconfigure.display, event.xconfigure.window,
3064 FALSE, StructureNotifyMask, &event);
3067 /* if the client is shrinking, then resize the frame before the client.
3069 both of these resize sections may run, because the top one only resizes
3070 in the direction that is growing
3072 if (send_resize_client && (w <= oldw || h <= oldh)) {
3073 render_plugin->frame_set_decorations (self->frame, self->decorations);
3074 render_plugin->frame_update_layout (self->frame, FALSE, FALSE);
3077 XFlush(obt_display);
3079 /* if it moved between monitors, then this can affect the stacking
3080 layer of this window or others - for fullscreen windows */
3081 Rect current_frame = render_plugin->frame_get_window_area(self->frame);
3082 if (screen_find_monitor(¤t_frame) !=
3083 screen_find_monitor(&oldframe))
3085 client_calc_layer(self);
3089 void client_fullscreen(ObClient *self, gboolean fs)
3093 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
3094 self->fullscreen == fs) return; /* already done */
3096 self->fullscreen = fs;
3097 client_change_state(self); /* change the state hints on the client */
3100 self->pre_fullscreen_area = self->area;
3101 /* if the window is maximized, its area isn't all that meaningful.
3102 save it's premax area instead. */
3103 if (self->max_horz) {
3104 self->pre_fullscreen_area.x = self->pre_max_area.x;
3105 self->pre_fullscreen_area.width = self->pre_max_area.width;
3107 if (self->max_vert) {
3108 self->pre_fullscreen_area.y = self->pre_max_area.y;
3109 self->pre_fullscreen_area.height = self->pre_max_area.height;
3112 /* these will help configure_full figure out where to fullscreen
3116 w = self->area.width;
3117 h = self->area.height;
3119 g_assert(self->pre_fullscreen_area.width > 0 &&
3120 self->pre_fullscreen_area.height > 0);
3122 x = self->pre_fullscreen_area.x;
3123 y = self->pre_fullscreen_area.y;
3124 w = self->pre_fullscreen_area.width;
3125 h = self->pre_fullscreen_area.height;
3126 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
3129 ob_debug("Window %s going fullscreen (%d)",
3130 self->title, self->fullscreen);
3132 client_setup_decor_and_functions(self, FALSE);
3133 client_move_resize(self, x, y, w, h);
3135 /* and adjust our layer/stacking. do this after resizing the window,
3136 and applying decorations, because windows which fill the screen are
3137 considered "fullscreen" and it affects their layer */
3138 client_calc_layer(self);
3141 /* try focus us when we go into fullscreen mode */
3146 static void client_iconify_recursive(ObClient *self,
3147 gboolean iconic, gboolean curdesk,
3148 gboolean hide_animation)
3151 gboolean changed = FALSE;
3154 if (self->iconic != iconic) {
3155 ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
3159 /* don't let non-normal windows iconify along with their parents
3161 if (client_normal(self)) {
3162 self->iconic = iconic;
3164 /* update the focus lists.. iconic windows go to the bottom of
3166 focus_order_to_bottom(self);
3171 self->iconic = iconic;
3173 if (curdesk && self->desktop != screen_desktop &&
3174 self->desktop != DESKTOP_ALL)
3175 client_set_desktop(self, screen_desktop, FALSE, FALSE);
3177 /* this puts it after the current focused window */
3178 focus_order_remove(self);
3179 focus_order_add_new(self);
3186 client_change_state(self);
3187 if (config_animate_iconify && !hide_animation)
3188 render_plugin->frame_begin_iconify_animation(self->frame, iconic);
3189 /* do this after starting the animation so it doesn't flash */
3190 client_showhide(self);
3193 /* iconify all direct transients, and deiconify all transients
3195 for (it = self->transients; it; it = g_slist_next(it))
3196 if (it->data != self)
3197 if (client_is_direct_child(self, it->data) || !iconic)
3198 client_iconify_recursive(it->data, iconic, curdesk,
3202 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3203 gboolean hide_animation)
3205 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3206 /* move up the transient chain as far as possible first */
3207 self = client_search_top_direct_parent(self);
3208 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3212 void client_maximize(ObClient *self, gboolean max, gint dir)
3216 g_assert(dir == 0 || dir == 1 || dir == 2);
3217 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE)) return; /* can't */
3219 /* check if already done */
3221 if (dir == 0 && self->max_horz && self->max_vert) return;
3222 if (dir == 1 && self->max_horz) return;
3223 if (dir == 2 && self->max_vert) return;
3225 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3226 if (dir == 1 && !self->max_horz) return;
3227 if (dir == 2 && !self->max_vert) return;
3230 /* these will help configure_full figure out which screen to fill with
3234 w = self->area.width;
3235 h = self->area.height;
3238 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3239 RECT_SET(self->pre_max_area,
3240 self->area.x, self->pre_max_area.y,
3241 self->area.width, self->pre_max_area.height);
3243 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3244 RECT_SET(self->pre_max_area,
3245 self->pre_max_area.x, self->area.y,
3246 self->pre_max_area.width, self->area.height);
3249 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3250 g_assert(self->pre_max_area.width > 0);
3252 x = self->pre_max_area.x;
3253 w = self->pre_max_area.width;
3255 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3256 0, self->pre_max_area.height);
3258 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3259 g_assert(self->pre_max_area.height > 0);
3261 y = self->pre_max_area.y;
3262 h = self->pre_max_area.height;
3264 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3265 self->pre_max_area.width, 0);
3269 if (dir == 0 || dir == 1) /* horz */
3270 self->max_horz = max;
3271 if (dir == 0 || dir == 2) /* vert */
3272 self->max_vert = max;
3274 render_plugin->frame_set_is_max_horz (self->frame, self->max_horz);
3275 render_plugin->frame_set_is_max_vert (self->frame, self->max_vert);
3277 client_change_state(self); /* change the state hints on the client */
3279 client_setup_decor_and_functions(self, FALSE);
3280 client_move_resize(self, x, y, w, h);
3283 void client_shade(ObClient *self, gboolean shade)
3285 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3286 shade) || /* can't shade */
3287 self->shaded == shade) return; /* already done */
3289 self->shaded = shade;
3290 client_change_state(self);
3291 client_change_wm_state(self); /* the window is being hidden/shown */
3292 /* resize the frame to just the titlebar */
3293 render_plugin->frame_set_is_shaded (self->frame, self->shaded);
3294 render_plugin->frame_update_layout(self->frame, FALSE, FALSE);
3297 static void client_ping_event(ObClient *self, gboolean dead)
3299 self->not_responding = dead;
3300 client_update_title(self);
3303 /* it came back to life ! */
3305 if (self->kill_prompt) {
3306 prompt_unref(self->kill_prompt);
3307 self->kill_prompt = NULL;
3310 self->kill_level = 0;
3314 void client_close(ObClient *self)
3316 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3319 prompt_cancel(self->prompt);
3323 /* in the case that the client provides no means to requesting that it
3324 close, we just kill it */
3325 if (!self->delete_window)
3326 /* don't use client_kill(), we should only kill based on PID in
3327 response to a lack of PING replies */
3328 XKillClient(obt_display, self->window);
3330 /* request the client to close with WM_DELETE_WINDOW */
3331 OBT_PROP_MSG_TO(self->window, self->window, WM_PROTOCOLS,
3332 OBT_PROP_ATOM(WM_DELETE_WINDOW), event_curtime,
3333 0, 0, 0, NoEventMask);
3335 if (self->not_responding)
3336 client_prompt_kill(self);
3340 #define OB_KILL_RESULT_NO 0
3341 #define OB_KILL_RESULT_YES 1
3343 static void client_kill_requested(ObPrompt *p, gint result, gpointer data)
3345 ObClient *self = data;
3347 if (result == OB_KILL_RESULT_YES)
3350 prompt_unref(self->kill_prompt);
3351 self->kill_prompt = NULL;
3354 static void client_prompt_kill(ObClient *self)
3356 /* check if we're already prompting */
3357 if (!self->kill_prompt) {
3358 ObPromptAnswer answers[] = {
3359 { _("No"), OB_KILL_RESULT_NO },
3360 { _("Yes"), OB_KILL_RESULT_YES }
3365 if (self->kill_level == 0)
3371 (_("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);
3373 self->kill_prompt = prompt_new(m, answers,
3374 sizeof(answers)/sizeof(answers[0]),
3375 OB_KILL_RESULT_NO, /* default = no */
3376 OB_KILL_RESULT_NO, /* cancel = no */
3377 client_kill_requested, self);
3381 prompt_show(self->kill_prompt, self);
3384 void client_kill(ObClient *self)
3386 /* don't kill our own windows */
3387 if (self->prompt) return;
3389 if (!self->client_machine && self->pid) {
3390 /* running on the local host */
3391 if (self->kill_level == 0) {
3392 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3393 self->window, self->pid);
3394 kill(self->pid, SIGTERM);
3397 /* show that we're trying to kill it */
3398 client_update_title(self);
3401 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3402 self->window, self->pid);
3403 kill(self->pid, SIGKILL); /* kill -9 */
3407 /* running on a remote host */
3408 XKillClient(obt_display, self->window);
3412 void client_hilite(ObClient *self, gboolean hilite)
3414 if (self->demands_attention == hilite)
3415 return; /* no change */
3417 /* don't allow focused windows to hilite */
3418 self->demands_attention = hilite && !client_focused(self);
3419 if (self->frame != NULL) { /* if we're mapping, just set the state */
3420 if (self->demands_attention)
3421 render_plugin->frame_flash_start(self->frame);
3423 render_plugin->frame_flash_stop(self->frame);
3424 client_change_state(self);
3428 static void client_set_desktop_recursive(ObClient *self,
3436 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3438 ob_debug("Setting desktop %u", target+1);
3440 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3442 old = self->desktop;
3443 self->desktop = target;
3444 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, target);
3445 /* the frame can display the current desktop state */
3446 render_plugin->frame_set_decorations (self->frame, self->decorations);
3447 render_plugin->frame_update_layout(self->frame, FALSE, FALSE);
3448 /* 'move' the window to the new desktop */
3452 /* raise if it was not already on the desktop */
3453 if (old != DESKTOP_ALL && !dontraise)
3454 stacking_raise(CLIENT_AS_WINDOW(self));
3455 if (STRUT_EXISTS(self->strut))
3456 screen_update_areas();
3458 /* the new desktop's geometry may be different, so we may need to
3459 resize, for example if we are maximized */
3460 client_reconfigure(self, FALSE);
3463 /* move all transients */
3464 for (it = self->transients; it; it = g_slist_next(it))
3465 if (it->data != self)
3466 if (client_is_direct_child(self, it->data))
3467 client_set_desktop_recursive(it->data, target,
3468 donthide, dontraise);
3471 void client_set_desktop(ObClient *self, guint target,
3472 gboolean donthide, gboolean dontraise)
3474 self = client_search_top_direct_parent(self);
3475 client_set_desktop_recursive(self, target, donthide, dontraise);
3478 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3480 while (child != parent && (child = client_direct_parent(child)));
3481 return child == parent;
3484 ObClient *client_search_modal_child(ObClient *self)
3489 for (it = self->transients; it; it = g_slist_next(it)) {
3490 ObClient *c = it->data;
3491 if ((ret = client_search_modal_child(c))) return ret;
3492 if (c->modal) return c;
3497 gboolean client_validate(ObClient *self)
3501 XSync(obt_display, FALSE); /* get all events on the server */
3503 if (XCheckTypedWindowEvent(obt_display, self->window, DestroyNotify, &e) ||
3504 XCheckTypedWindowEvent(obt_display, self->window, UnmapNotify, &e))
3506 XPutBackEvent(obt_display, &e);
3513 void client_set_wm_state(ObClient *self, glong state)
3515 if (state == self->wmstate) return; /* no change */
3519 client_iconify(self, TRUE, TRUE, FALSE);
3522 client_iconify(self, FALSE, TRUE, FALSE);
3527 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3529 gboolean shaded = self->shaded;
3530 gboolean fullscreen = self->fullscreen;
3531 gboolean undecorated = self->undecorated;
3532 gboolean max_horz = self->max_horz;
3533 gboolean max_vert = self->max_vert;
3534 gboolean modal = self->modal;
3535 gboolean iconic = self->iconic;
3536 gboolean demands_attention = self->demands_attention;
3537 gboolean above = self->above;
3538 gboolean below = self->below;
3541 if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) ||
3542 action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) ||
3543 action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)))
3544 /* an invalid action was passed to the client message, ignore it */
3547 for (i = 0; i < 2; ++i) {
3548 Atom state = i == 0 ? data1 : data2;
3550 if (!state) continue;
3552 /* if toggling, then pick whether we're adding or removing */
3553 if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) {
3554 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
3555 action = modal ? 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_MAXIMIZED_VERT))
3558 action = self->max_vert ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3559 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3560 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
3561 action = self->max_horz ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3562 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3563 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
3564 action = shaded ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3565 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3566 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
3567 action = self->skip_taskbar ?
3568 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3569 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3570 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
3571 action = self->skip_pager ?
3572 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3573 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3574 else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
3575 action = self->iconic ?
3576 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3577 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3578 else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
3579 action = fullscreen ?
3580 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3581 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3582 else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
3583 action = self->above ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3584 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3585 else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
3586 action = self->below ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3587 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3588 else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
3589 action = self->demands_attention ?
3590 OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3591 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3592 else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
3593 action = undecorated ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3594 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3597 if (action == OBT_PROP_ATOM(NET_WM_STATE_ADD)) {
3598 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3600 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3602 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3604 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3606 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3607 self->skip_taskbar = TRUE;
3608 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3609 self->skip_pager = TRUE;
3610 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3612 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3614 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3617 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3620 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3621 demands_attention = TRUE;
3622 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3626 } else { /* action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) */
3627 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3629 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3631 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3633 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3635 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3636 self->skip_taskbar = FALSE;
3637 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3638 self->skip_pager = FALSE;
3639 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3641 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3643 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3645 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3647 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3648 demands_attention = FALSE;
3649 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3650 undecorated = FALSE;
3655 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3656 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3658 if (max_horz == max_vert) { /* both going the same way */
3659 client_maximize(self, max_horz, 0);
3661 client_maximize(self, max_horz, 1);
3662 client_maximize(self, max_vert, 2);
3666 if (max_horz != self->max_horz)
3667 client_maximize(self, max_horz, 1);
3669 client_maximize(self, max_vert, 2);
3672 /* change fullscreen state before shading, as it will affect if the window
3674 if (fullscreen != self->fullscreen)
3675 client_fullscreen(self, fullscreen);
3676 if (shaded != self->shaded)
3677 client_shade(self, shaded);
3678 if (undecorated != self->undecorated)
3679 client_set_undecorated(self, undecorated);
3680 if (above != self->above || below != self->below) {
3681 self->above = above;
3682 self->below = below;
3683 client_calc_layer(self);
3686 if (modal != self->modal) {
3687 self->modal = modal;
3688 /* when a window changes modality, then its stacking order with its
3689 transients needs to change */
3690 stacking_raise(CLIENT_AS_WINDOW(self));
3692 /* it also may get focused. if something is focused that shouldn't
3693 be focused anymore, then move the focus */
3694 if (focus_client && client_focus_target(focus_client) != focus_client)
3695 client_focus(focus_client);
3698 if (iconic != self->iconic)
3699 client_iconify(self, iconic, FALSE, FALSE);
3701 if (demands_attention != self->demands_attention)
3702 client_hilite(self, demands_attention);
3704 client_change_state(self); /* change the hint to reflect these changes */
3707 ObClient *client_focus_target(ObClient *self)
3709 ObClient *child = NULL;
3711 child = client_search_modal_child(self);
3712 if (child) return child;
3716 gboolean client_can_focus(ObClient *self)
3718 /* choose the correct target */
3719 self = client_focus_target(self);
3721 if (!render_plugin->frame_is_visible(self->frame))
3724 if (!(self->can_focus || self->focus_notify))
3730 gboolean client_focus(ObClient *self)
3732 /* we might not focus this window, so if we have modal children which would
3733 be focused instead, bring them to this desktop */
3734 client_bring_modal_windows(self);
3736 /* choose the correct target */
3737 self = client_focus_target(self);
3739 if (!client_can_focus(self)) {
3740 ob_debug_type(OB_DEBUG_FOCUS,
3741 "Client %s can't be focused", self->title);
3745 ob_debug_type(OB_DEBUG_FOCUS,
3746 "Focusing client \"%s\" (0x%x) at time %u",
3747 self->title, self->window, event_curtime);
3749 /* if using focus_delay, stop the timer now so that focus doesn't
3751 event_halt_focus_delay();
3753 /* if there is a grab going on, then we need to cancel it. if we move
3754 focus during the grab, applications will get NotifyWhileGrabbed events
3757 actions should not rely on being able to move focus during an
3760 event_cancel_all_key_grabs();
3762 obt_display_ignore_errors(TRUE);
3764 if (self->can_focus) {
3765 /* This can cause a BadMatch error with CurrentTime, or if an app
3766 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3767 XSetInputFocus(obt_display, self->window, RevertToPointerRoot,
3771 if (self->focus_notify) {
3773 ce.xclient.type = ClientMessage;
3774 ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
3775 ce.xclient.display = obt_display;
3776 ce.xclient.window = self->window;
3777 ce.xclient.format = 32;
3778 ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS);
3779 ce.xclient.data.l[1] = event_curtime;
3780 ce.xclient.data.l[2] = 0l;
3781 ce.xclient.data.l[3] = 0l;
3782 ce.xclient.data.l[4] = 0l;
3783 XSendEvent(obt_display, self->window, FALSE, NoEventMask, &ce);
3786 obt_display_ignore_errors(FALSE);
3788 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d",
3789 obt_display_error_occured);
3790 return !obt_display_error_occured;
3793 static void client_present(ObClient *self, gboolean here, gboolean raise,
3796 if (client_normal(self) && screen_showing_desktop)
3797 screen_show_desktop(FALSE, self);
3799 client_iconify(self, FALSE, here, FALSE);
3800 if (self->desktop != DESKTOP_ALL &&
3801 self->desktop != screen_desktop)
3804 client_set_desktop(self, screen_desktop, FALSE, TRUE);
3806 screen_set_desktop(self->desktop, FALSE);
3807 } else if (!render_plugin->frame_is_visible(self->frame))
3808 /* if its not visible for other reasons, then don't mess
3811 if (self->shaded && unshade)
3812 client_shade(self, FALSE);
3814 stacking_raise(CLIENT_AS_WINDOW(self));
3819 void client_activate(ObClient *self, gboolean here, gboolean raise,
3820 gboolean unshade, gboolean user)
3822 client_present(self, here, raise, unshade);
3825 static void client_bring_windows_recursive(ObClient *self,
3833 for (it = self->transients; it; it = g_slist_next(it))
3834 client_bring_windows_recursive(it->data, desktop,
3835 helpers, modals, iconic);
3837 if (((helpers && client_helper(self)) ||
3838 (modals && self->modal)) &&
3839 ((self->desktop != desktop && self->desktop != DESKTOP_ALL) ||
3840 (iconic && self->iconic)))
3842 if (iconic && self->iconic)
3843 client_iconify(self, FALSE, TRUE, FALSE);
3845 client_set_desktop(self, desktop, FALSE, FALSE);
3849 void client_bring_helper_windows(ObClient *self)
3851 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE, FALSE);
3854 void client_bring_modal_windows(ObClient *self)
3856 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE, TRUE);
3859 gboolean client_focused(ObClient *self)
3861 return self == focus_client;
3864 static ObClientIcon* client_icon_recursive(ObClient *self, gint w, gint h)
3867 gulong min_diff, min_i;
3869 if (!self->nicons) {
3870 ObClientIcon *parent = NULL;
3873 for (it = self->parents; it; it = g_slist_next(it)) {
3874 ObClient *c = it->data;
3875 if ((parent = client_icon_recursive(c, w, h)))
3882 /* some kind of crappy approximation to find the icon closest in size to
3883 what we requested, but icons are generally all the same ratio as
3884 eachother so it's good enough. */
3886 min_diff = ABS(self->icons[0].width - w) + ABS(self->icons[0].height - h);
3889 for (i = 1; i < self->nicons; ++i) {
3892 diff = ABS(self->icons[i].width - w) + ABS(self->icons[i].height - h);
3893 if (diff < min_diff) {
3898 return &self->icons[min_i];
3901 const ObClientIcon* client_icon(ObClient *self, gint w, gint h)
3904 static ObClientIcon deficon;
3906 if (!(ret = client_icon_recursive(self, w, h))) {
3907 deficon.width = deficon.height = 48;
3908 deficon.data = ob_rr_theme->def_win_icon;
3914 void client_set_layer(ObClient *self, gint layer)
3918 self->above = FALSE;
3919 } else if (layer == 0) {
3920 self->below = self->above = FALSE;
3922 self->below = FALSE;
3925 client_calc_layer(self);
3926 client_change_state(self); /* reflect this in the state hints */
3929 void client_set_undecorated(ObClient *self, gboolean undecorated)
3931 if (self->undecorated != undecorated &&
3932 /* don't let it undecorate if the function is missing, but let
3934 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
3936 self->undecorated = undecorated;
3937 client_setup_decor_and_functions(self, TRUE);
3938 client_change_state(self); /* reflect this in the state hints */
3942 guint client_monitor(ObClient *self)
3944 Rect area = render_plugin->frame_get_window_area(self->frame);
3945 return screen_find_monitor(&area);
3948 ObClient *client_direct_parent(ObClient *self)
3950 if (!self->parents) return NULL;
3951 if (self->transient_for_group) return NULL;
3952 return self->parents->data;
3955 ObClient *client_search_top_direct_parent(ObClient *self)
3958 while ((p = client_direct_parent(self))) self = p;
3962 static GSList *client_search_all_top_parents_internal(ObClient *self,
3964 ObStackingLayer layer)
3969 /* move up the direct transient chain as far as possible */
3970 while ((p = client_direct_parent(self)) &&
3971 (!bylayer || p->layer == layer))
3975 ret = g_slist_prepend(NULL, self);
3977 ret = g_slist_copy(self->parents);
3982 GSList *client_search_all_top_parents(ObClient *self)
3984 return client_search_all_top_parents_internal(self, FALSE, 0);
3987 GSList *client_search_all_top_parents_layer(ObClient *self)
3989 return client_search_all_top_parents_internal(self, TRUE, self->layer);
3992 ObClient *client_search_focus_parent(ObClient *self)
3996 for (it = self->parents; it; it = g_slist_next(it))
3997 if (client_focused(it->data)) return it->data;
4002 ObClient *client_search_parent(ObClient *self, ObClient *search)
4006 for (it = self->parents; it; it = g_slist_next(it))
4007 if (it->data == search) return search;
4012 ObClient *client_search_transient(ObClient *self, ObClient *search)
4016 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
4017 if (sit->data == search)
4019 if (client_search_transient(sit->data, search))
4025 static void detect_edge(Rect area, ObDirection dir,
4026 gint my_head, gint my_size,
4027 gint my_edge_start, gint my_edge_size,
4028 gint *dest, gboolean *near_edge)
4030 gint edge_start, edge_size, head, tail;
4031 gboolean skip_head = FALSE, skip_tail = FALSE;
4034 case OB_DIRECTION_NORTH:
4035 case OB_DIRECTION_SOUTH:
4036 edge_start = area.x;
4037 edge_size = area.width;
4039 case OB_DIRECTION_EAST:
4040 case OB_DIRECTION_WEST:
4041 edge_start = area.y;
4042 edge_size = area.height;
4045 g_assert_not_reached();
4048 /* do we collide with this window? */
4049 if (!RANGES_INTERSECT(my_edge_start, my_edge_size,
4050 edge_start, edge_size))
4054 case OB_DIRECTION_NORTH:
4055 head = RECT_BOTTOM(area);
4056 tail = RECT_TOP(area);
4058 case OB_DIRECTION_SOUTH:
4059 head = RECT_TOP(area);
4060 tail = RECT_BOTTOM(area);
4062 case OB_DIRECTION_WEST:
4063 head = RECT_RIGHT(area);
4064 tail = RECT_LEFT(area);
4066 case OB_DIRECTION_EAST:
4067 head = RECT_LEFT(area);
4068 tail = RECT_RIGHT(area);
4071 g_assert_not_reached();
4074 case OB_DIRECTION_NORTH:
4075 case OB_DIRECTION_WEST:
4076 /* check if our window is past the head of this window */
4077 if (my_head <= head + 1)
4079 /* check if our window's tail is past the tail of this window */
4080 if (my_head + my_size - 1 <= tail)
4082 /* check if the head of this window is closer than the previously
4083 chosen edge (take into account that the previously chosen
4084 edge might have been a tail, not a head) */
4085 if (head + (*near_edge ? 0 : my_size) < *dest)
4087 /* check if the tail of this window is closer than the previously
4088 chosen edge (take into account that the previously chosen
4089 edge might have been a head, not a tail) */
4090 if (tail - (!*near_edge ? 0 : my_size) < *dest)
4093 case OB_DIRECTION_SOUTH:
4094 case OB_DIRECTION_EAST:
4095 /* check if our window is past the head of this window */
4096 if (my_head >= head - 1)
4098 /* check if our window's tail is past the tail of this window */
4099 if (my_head - my_size + 1 >= tail)
4101 /* check if the head of this window is closer than the previously
4102 chosen edge (take into account that the previously chosen
4103 edge might have been a tail, not a head) */
4104 if (head - (*near_edge ? 0 : my_size) > *dest)
4106 /* check if the tail of this window is closer than the previously
4107 chosen edge (take into account that the previously chosen
4108 edge might have been a head, not a tail) */
4109 if (tail + (!*near_edge ? 0 : my_size) > *dest)
4113 g_assert_not_reached();
4116 ob_debug("my head %d size %d", my_head, my_size);
4117 ob_debug("head %d tail %d deest %d", head, tail, *dest);
4119 ob_debug("using near edge %d", head);
4123 else if (!skip_tail) {
4124 ob_debug("using far edge %d", tail);
4130 void client_find_edge_directional(ObClient *self, ObDirection dir,
4131 gint my_head, gint my_size,
4132 gint my_edge_start, gint my_edge_size,
4133 gint *dest, gboolean *near_edge)
4140 Strut size = render_plugin->frame_get_size(self->frame);
4141 Rect area = render_plugin->frame_get_window_area(self->frame);
4143 a = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS,
4145 mon = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR,
4149 case OB_DIRECTION_NORTH:
4150 if (my_head >= RECT_TOP(*mon) + 1)
4151 edge = RECT_TOP(*mon) - 1;
4153 edge = RECT_TOP(*a) - 1;
4155 case OB_DIRECTION_SOUTH:
4156 if (my_head <= RECT_BOTTOM(*mon) - 1)
4157 edge = RECT_BOTTOM(*mon) + 1;
4159 edge = RECT_BOTTOM(*a) + 1;
4161 case OB_DIRECTION_EAST:
4162 if (my_head <= RECT_RIGHT(*mon) - 1)
4163 edge = RECT_RIGHT(*mon) + 1;
4165 edge = RECT_RIGHT(*a) + 1;
4167 case OB_DIRECTION_WEST:
4168 if (my_head >= RECT_LEFT(*mon) + 1)
4169 edge = RECT_LEFT(*mon) - 1;
4171 edge = RECT_LEFT(*a) - 1;
4174 g_assert_not_reached();
4176 /* default to the far edge, then narrow it down */
4180 for (it = client_list; it; it = g_list_next(it)) {
4181 ObClient *cur = it->data;
4183 /* skip windows to not bump into */
4188 if (self->desktop != cur->desktop && cur->desktop != DESKTOP_ALL &&
4189 cur->desktop != screen_desktop)
4192 ob_debug("trying window %s", cur->title);
4194 detect_edge(render_plugin->frame_get_window_area(cur->frame), dir, my_head, my_size, my_edge_start,
4195 my_edge_size, dest, near_edge);
4197 dock_get_area(&dock_area);
4198 detect_edge(dock_area, dir, my_head, my_size, my_edge_start,
4199 my_edge_size, dest, near_edge);
4204 void client_find_move_directional(ObClient *self, ObDirection dir,
4208 gint e, e_start, e_size;
4212 Rect area = render_plugin->frame_get_window_area(self->frame);
4215 case OB_DIRECTION_EAST:
4216 head = RECT_RIGHT(area);
4218 e_start = RECT_TOP(area);
4219 e_size = area.height;
4221 case OB_DIRECTION_WEST:
4222 head = RECT_LEFT(area);
4224 e_start = RECT_TOP(area);
4225 e_size = area.height;
4227 case OB_DIRECTION_NORTH:
4228 head = RECT_TOP(area);
4230 e_start = RECT_LEFT(area);
4231 e_size = area.width;
4233 case OB_DIRECTION_SOUTH:
4234 head = RECT_BOTTOM(area);
4236 e_start = RECT_LEFT(area);
4237 e_size = area.width;
4240 g_assert_not_reached();
4243 client_find_edge_directional(self, dir, head, size,
4244 e_start, e_size, &e, &near);
4248 case OB_DIRECTION_EAST:
4249 if (near) e -= area.width;
4253 case OB_DIRECTION_WEST:
4255 else e -= area.width;
4258 case OB_DIRECTION_NORTH:
4260 else e -= area.height;
4263 case OB_DIRECTION_SOUTH:
4264 if (near) e -= area.height;
4269 g_assert_not_reached();
4271 frame_frame_gravity(self, x, y);
4274 void client_find_resize_directional(ObClient *self, ObDirection side,
4276 gint *x, gint *y, gint *w, gint *h)
4279 gint e, e_start, e_size, delta;
4283 Rect area = render_plugin->frame_get_window_area(self->frame);
4284 Strut size = render_plugin->frame_get_size(self->frame);
4287 case OB_DIRECTION_EAST:
4288 head = RECT_RIGHT(area) +
4289 (self->size_inc.width - 1) * (grow ? 1 : -1);
4290 e_start = RECT_TOP(area);
4291 e_size = area.height;
4292 dir = grow ? OB_DIRECTION_EAST : OB_DIRECTION_WEST;
4294 case OB_DIRECTION_WEST:
4295 head = RECT_LEFT(area) -
4296 (self->size_inc.width - 1) * (grow ? 1 : -1);
4297 e_start = RECT_TOP(area);
4298 e_size = area.height;
4299 dir = grow ? OB_DIRECTION_WEST : OB_DIRECTION_EAST;
4301 case OB_DIRECTION_NORTH:
4302 head = RECT_TOP(area) -
4303 (self->size_inc.height - 1) * (grow ? 1 : -1);
4304 e_start = RECT_LEFT(area);
4305 e_size = area.width;
4306 dir = grow ? OB_DIRECTION_NORTH : OB_DIRECTION_SOUTH;
4308 case OB_DIRECTION_SOUTH:
4309 head = RECT_BOTTOM(area) +
4310 (self->size_inc.height - 1) * (grow ? 1 : -1);
4311 e_start = RECT_LEFT(area);
4312 e_size = area.width;
4313 dir = grow ? OB_DIRECTION_SOUTH : OB_DIRECTION_NORTH;
4316 g_assert_not_reached();
4319 ob_debug("head %d dir %d", head, dir);
4320 client_find_edge_directional(self, dir, head, 1,
4321 e_start, e_size, &e, &near);
4322 ob_debug("edge %d", e);
4328 case OB_DIRECTION_EAST:
4329 if (grow == near) --e;
4330 delta = e - RECT_RIGHT(area);
4333 case OB_DIRECTION_WEST:
4334 if (grow == near) ++e;
4335 delta = RECT_LEFT(area) - e;
4339 case OB_DIRECTION_NORTH:
4340 if (grow == near) ++e;
4341 delta = RECT_TOP(area) - e;
4345 case OB_DIRECTION_SOUTH:
4346 if (grow == near) --e;
4347 delta = e - RECT_BOTTOM(area);
4351 g_assert_not_reached();
4353 frame_frame_gravity(self, x, y);
4354 *w -= size.left + size.right;
4355 *h -= size.top + size.bottom;
4358 ObClient* client_under_pointer(void)
4362 ObClient *ret = NULL;
4364 if (screen_pointer_pos(&x, &y)) {
4365 for (it = stacking_list; it; it = g_list_next(it)) {
4366 if (WINDOW_IS_CLIENT(it->data)) {
4367 ObClient *c = WINDOW_AS_CLIENT(it->data);
4368 if (render_plugin->frame_is_visible(c->frame) &&
4369 /* check the desktop, this is done during desktop
4370 switching and windows are shown/hidden status is not
4372 (c->desktop == screen_desktop ||
4373 c->desktop == DESKTOP_ALL) &&
4374 /* ignore all animating windows */
4375 !(render_plugin->frame_iconify_animating(c->frame)) &&
4376 RECT_CONTAINS(render_plugin->frame_get_window_area(c->frame), x, y))
4387 gboolean client_has_group_siblings(ObClient *self)
4389 return self->group && self->group->members->next;