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"
34 #include "focus_cycle.h"
39 #include "menuframe.h"
42 #include "obrender/render.h"
44 #include "obt/display.h"
45 #include "obt/xqueue.h"
53 # include <signal.h> /* for kill() */
57 #include <X11/Xutil.h>
59 /*! The event mask to grab on client windows */
60 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
63 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
68 ObClientCallback func;
72 GList *client_list = NULL;
74 static GSList *client_destroy_notifies = NULL;
75 static RrImage *client_default_icon = NULL;
77 static void client_get_all(ObClient *self, gboolean real);
78 static void client_get_startup_id(ObClient *self);
79 static void client_get_session_ids(ObClient *self);
80 static void client_save_app_rule_values(ObClient *self);
81 static void client_get_area(ObClient *self);
82 static void client_get_desktop(ObClient *self);
83 static void client_get_state(ObClient *self);
84 static void client_get_shaped(ObClient *self);
85 static void client_get_colormap(ObClient *self);
86 static void client_set_desktop_recursive(ObClient *self,
90 static void client_change_allowed_actions(ObClient *self);
91 static void client_change_state(ObClient *self);
92 static void client_change_wm_state(ObClient *self);
93 static void client_apply_startup_state(ObClient *self,
94 gint x, gint y, gint w, gint h);
95 static void client_restore_session_state(ObClient *self);
96 static gboolean client_restore_session_stacking(ObClient *self);
97 static ObAppSettings *client_get_settings_state(ObClient *self);
98 static void client_update_transient_tree(ObClient *self,
99 ObGroup *oldgroup, ObGroup *newgroup,
100 gboolean oldgtran, gboolean newgtran,
102 ObClient *newparent);
103 static void client_present(ObClient *self, gboolean here, gboolean raise,
105 static GSList *client_search_all_top_parents_internal(ObClient *self,
107 ObStackingLayer layer);
108 static void client_call_notifies(ObClient *self, GSList *list);
109 static void client_ping_event(ObClient *self, gboolean dead);
110 static void client_prompt_kill(ObClient *self);
111 static gboolean client_can_steal_focus(ObClient *self,
112 gboolean allow_other_desktop,
113 gboolean request_from_user,
114 Time steal_time, Time launch_time);
115 static void client_setup_default_decor_and_functions(ObClient *self);
116 static void client_setup_decor_undecorated(ObClient *self);
118 void client_startup(gboolean reconfig)
120 client_default_icon = RrImageNewFromData(
121 ob_rr_icons, ob_rr_theme->def_win_icon,
122 ob_rr_theme->def_win_icon_w, ob_rr_theme->def_win_icon_h);
124 if (reconfig) return;
129 void client_shutdown(gboolean reconfig)
131 RrImageUnref(client_default_icon);
132 client_default_icon = NULL;
134 if (reconfig) return;
137 static void client_call_notifies(ObClient *self, GSList *list)
141 for (it = list; it; it = g_slist_next(it)) {
142 ClientCallback *d = it->data;
143 d->func(self, d->data);
147 void client_add_destroy_notify(ObClientCallback func, gpointer data)
149 ClientCallback *d = g_slice_new(ClientCallback);
152 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
155 void client_remove_destroy_notify(ObClientCallback func)
159 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
160 ClientCallback *d = it->data;
161 if (d->func == func) {
162 g_slice_free(ClientCallback, d);
163 client_destroy_notifies =
164 g_slist_delete_link(client_destroy_notifies, it);
170 void client_remove_destroy_notify_data(ObClientCallback func, gpointer data)
174 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
175 ClientCallback *d = it->data;
176 if (d->func == func && d->data == data) {
177 g_slice_free(ClientCallback, d);
178 client_destroy_notifies =
179 g_slist_delete_link(client_destroy_notifies, it);
185 void client_set_list(void)
187 Window *windows, *win_it;
189 guint size = g_list_length(client_list);
191 /* create an array of the window ids */
193 windows = g_new(Window, size);
195 for (it = client_list; it; it = g_list_next(it), ++win_it)
196 *win_it = ((ObClient*)it->data)->window;
200 OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW,
201 (gulong*)windows, size);
209 void client_manage(Window window, ObPrompt *prompt)
212 XSetWindowAttributes attrib_set;
213 gboolean try_activate = FALSE;
214 gboolean do_activate;
215 ObAppSettings *settings;
216 gboolean transient = FALSE;
221 gulong ignore_start = FALSE;
223 ob_debug("Managing window: 0x%lx", window);
225 /* choose the events we want to receive on the CLIENT window
226 (ObPrompt windows can request events too) */
227 attrib_set.event_mask = CLIENT_EVENTMASK |
228 (prompt ? prompt->event_mask : 0);
229 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
230 XChangeWindowAttributes(obt_display, window,
231 CWEventMask|CWDontPropagate, &attrib_set);
233 /* create the ObClient struct, and populate it from the hints on the
235 self = g_slice_new0(ObClient);
236 self->obwin.type = OB_WINDOW_CLASS_CLIENT;
237 self->window = window;
238 self->prompt = prompt;
239 self->managed = TRUE;
241 /* non-zero defaults */
242 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
243 self->gravity = NorthWestGravity;
244 self->desktop = screen_num_desktops; /* always an invalid value */
246 /* get all the stuff off the window */
247 client_get_all(self, TRUE);
249 ob_debug("Window type: %d", self->type);
250 ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
251 ob_debug("Window name: %s class: %s role: %s title: %s",
252 self->name, self->class, self->role, self->title);
253 ob_debug("Window group name: %s group class: %s",
254 self->group_name, self->group_class);
256 /* per-app settings override stuff from client_get_all, and return the
257 settings for other uses too. the returned settings is a shallow copy,
258 that needs to be freed with g_free(). */
259 settings = client_get_settings_state(self);
261 /* the session should get the last say though */
262 client_restore_session_state(self);
264 /* the per-app settings/session may have changed the decorations for
265 the window, so we setup decorations for that here. this is a special
266 case because we want to place the window according to these decoration
268 we do this before setting up the frame so that it will reflect the
269 decorations of the window as it will be placed on screen.
271 client_setup_decor_undecorated(self);
273 /* specify that if we exit, the window should not be destroyed and
274 should be reparented back to root automatically, unless we are managing
275 an internal ObPrompt window */
277 XChangeSaveSet(obt_display, window, SetModeInsert);
279 /* create the decoration frame for the client window */
280 self->frame = frame_new(self);
282 frame_grab_client(self->frame);
284 /* we've grabbed everything and set everything that we need to at mapping
288 /* this needs to occur once we have a frame, since it sets a property on
290 client_update_opacity(self);
292 /* don't put helper/modal windows on a different desktop if they are
293 related to the focused window. */
294 if (!screen_compare_desktops(self->desktop, screen_desktop) &&
295 focus_client && client_search_transient(focus_client, self) &&
296 (client_helper(self) || self->modal))
298 self->desktop = screen_desktop;
301 /* tell startup notification that this app started */
302 launch_time = sn_app_started(self->startup_id, self->class, self->name);
304 if (!OBT_PROP_GET32(self->window, NET_WM_USER_TIME, CARDINAL, &user_time))
305 user_time = event_time();
307 /* do this after we have a frame.. it uses the frame to help determine the
308 WM_STATE to apply. */
309 client_change_state(self);
311 /* add ourselves to the focus order */
312 focus_order_add_new(self);
314 /* do this to add ourselves to the stacking list in a non-intrusive way */
315 client_calc_layer(self);
317 /* focus the new window? */
318 if (ob_state() != OB_STATE_STARTING &&
319 (!self->session || self->session->focused) &&
320 /* this means focus=true for window is same as config_focus_new=true */
321 ((config_focus_new || settings->focus == 1) ||
322 client_search_focus_tree_full(self)) &&
323 /* NET_WM_USER_TIME 0 when mapping means don't focus */
325 /* this checks for focus=false for the window */
326 settings->focus != 0 &&
327 focus_valid_target(self, self->desktop,
328 FALSE, FALSE, TRUE, TRUE, FALSE, FALSE,
329 settings->focus == 1))
334 /* remove the client's border */
335 XSetWindowBorderWidth(obt_display, self->window, 0);
337 /* adjust the frame to the client's size before showing or placing
339 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
340 frame_adjust_client_area(self->frame);
342 /* where the frame was placed is where the window was originally */
345 ob_debug("Going to try activate new window? %s",
346 try_activate ? "yes" : "no");
348 do_activate = client_can_steal_focus(
349 self, settings->focus == 1,
350 (!!launch_time || settings->focus == 1),
351 event_time(), launch_time);
355 /* figure out placement for the window if the window is new */
356 if (ob_state() == OB_STATE_RUNNING) {
357 ob_debug("Positioned: %s @ %d %d",
358 (!self->positioned ? "no" :
359 (self->positioned == PPosition ? "program specified" :
360 (self->positioned == USPosition ? "user specified" :
361 (self->positioned == (PPosition | USPosition) ?
362 "program + user specified" :
363 "BADNESS !?")))), place.x, place.y);
365 ob_debug("Sized: %s @ %d %d",
366 (!self->sized ? "no" :
367 (self->sized == PSize ? "program specified" :
368 (self->sized == USSize ? "user specified" :
369 (self->sized == (PSize | USSize) ?
370 "program + user specified" :
371 "BADNESS !?")))), place.width, place.height);
373 obplaced = place_client(self, do_activate, &place, settings);
375 /* watch for buggy apps that ask to be placed at (0,0) when there is
377 if (!obplaced && place.x == 0 && place.y == 0 &&
378 /* non-normal windows are allowed */
379 client_normal(self) &&
380 /* oldschool fullscreen windows are allowed */
381 !client_is_oldfullscreen(self, &place))
385 r = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS, NULL);
389 ob_debug("Moving buggy app from (0,0) to (%d,%d)", r->x, r->y);
391 g_slice_free(Rect, r);
394 /* make sure the window is visible. */
395 client_find_onscreen(self, &place.x, &place.y,
396 place.width, place.height,
397 /* non-normal clients has less rules, and
398 windows that are being restored from a
399 session do also. we can assume you want
400 it back where you saved it. Clients saying
401 they placed themselves are subjected to
402 harder rules, ones that are placed by
403 place.c or by the user are allowed partially
404 off-screen and on xinerama divides (ie,
405 it is up to the placement routines to avoid
406 the xinerama divides)
408 children and splash screens are forced on
409 screen, but i don't remember why i decided to
412 ob_state() == OB_STATE_RUNNING &&
413 (self->type == OB_CLIENT_TYPE_DIALOG ||
414 self->type == OB_CLIENT_TYPE_SPLASH ||
415 (!((self->positioned & USPosition) ||
416 settings->pos_given) &&
417 client_normal(self) &&
419 /* don't move oldschool fullscreen windows to
420 fit inside the struts (fixes Acroread, which
421 makes its fullscreen window fit the screen
422 but it is not USSize'd or USPosition'd) */
423 !client_is_oldfullscreen(self, &place))));
426 /* if the window isn't user-sized, then make it fit inside
427 the visible screen area on its monitor. Use basically the same rules
428 for forcing the window on screen in the client_find_onscreen call.
430 do this after place_client, it chooses the monitor!
432 splash screens get "transient" set to TRUE by
433 the place_client call
435 if (ob_state() == OB_STATE_RUNNING &&
437 (!(self->sized & USSize || self->positioned & USPosition) &&
438 client_normal(self) &&
440 /* don't shrink oldschool fullscreen windows to fit inside the
441 struts (fixes Acroread, which makes its fullscreen window
442 fit the screen but it is not USSize'd or USPosition'd) */
443 !client_is_oldfullscreen(self, &place))))
445 Rect *a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &place);
447 /* get the size of the frame */
448 place.width += self->frame->size.left + self->frame->size.right;
449 place.height += self->frame->size.top + self->frame->size.bottom;
451 /* fit the window inside the area */
452 place.width = MIN(place.width, a->width);
453 place.height = MIN(place.height, a->height);
455 ob_debug("setting window size to %dx%d", place.width, place.height);
457 /* get the size of the client back */
458 place.width -= self->frame->size.left + self->frame->size.right;
459 place.height -= self->frame->size.top + self->frame->size.bottom;
461 g_slice_free(Rect, a);
464 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
465 "some restrictions may apply",
466 self->window, place.x, place.y, place.width, place.height);
468 ob_debug(" but session requested %d, %d %d x %d instead, "
470 self->session->x, self->session->y,
471 self->session->w, self->session->h);
473 /* do this after the window is placed, so the premax/prefullscreen numbers
476 this also places the window
478 client_apply_startup_state(self, place.x, place.y,
479 place.width, place.height);
481 /* set the initial value of the desktop hint, when one wasn't requested
483 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
485 /* grab mouse bindings before showing the window */
486 mouse_grab_for_client(self, TRUE);
488 if (!config_focus_under_mouse)
489 ignore_start = event_start_ignore_all_enters();
491 /* this has to happen before we try focus the window, but we want it to
492 happen after the client's stacking has been determined or it looks bad
496 /* activate/hilight/raise the window */
499 gboolean stacked = client_restore_session_stacking(self);
500 client_present(self, FALSE, !stacked, TRUE);
503 /* if the client isn't stealing focus, then hilite it so the user
504 knows it is there, but don't do this if we're restoring from a
506 if (!client_restore_session_stacking(self))
507 client_hilite(self, TRUE);
511 /* This may look rather odd. Well it's because new windows are added
512 to the stacking order non-intrusively. If we're not going to focus
513 the new window or hilite it, then we raise it to the top. This will
514 take affect for things that don't get focused like splash screens.
515 Also if you don't have focus_new enabled, then it's going to get
516 raised to the top. Legacy begets legacy I guess?
518 if (!client_restore_session_stacking(self))
519 stacking_raise(CLIENT_AS_WINDOW(self));
522 if (!config_focus_under_mouse)
523 event_end_ignore_all_enters(ignore_start);
525 /* add to client list/map */
526 client_list = g_list_append(client_list, self);
527 window_add(&self->window, CLIENT_AS_WINDOW(self));
529 /* this has to happen after we're in the client_list */
530 if (STRUT_EXISTS(self->strut))
531 screen_update_areas();
533 /* update the list hints */
536 /* free the ObAppSettings shallow copy */
537 g_slice_free(ObAppSettings, settings);
539 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
540 window, self->frame->window, self->class);
543 ObClient *client_fake_manage(Window window)
546 ObAppSettings *settings;
548 ob_debug("Pretend-managing window: %lx", window);
550 /* do this minimal stuff to figure out the client's decorations */
552 self = g_slice_new0(ObClient);
553 self->window = window;
555 client_get_all(self, FALSE);
556 /* per-app settings override stuff, and return the settings for other
557 uses too. this returns a shallow copy that needs to be freed */
558 settings = client_get_settings_state(self);
560 /* create the decoration frame for the client window and adjust its size */
561 self->frame = frame_new(self);
563 client_apply_startup_state(self, self->area.x, self->area.y,
564 self->area.width, self->area.height);
566 ob_debug("gave extents left %d right %d top %d bottom %d",
567 self->frame->size.left, self->frame->size.right,
568 self->frame->size.top, self->frame->size.bottom);
570 /* free the ObAppSettings shallow copy */
571 g_slice_free(ObAppSettings, settings);
576 void client_unmanage_all(void)
579 client_unmanage(client_list->data);
582 void client_unmanage(ObClient *self)
587 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
588 self->window, self->frame->window,
589 self->class, self->title ? self->title : "");
591 g_assert(self != NULL);
593 /* we dont want events no more. do this before hiding the frame so we
594 don't generate more events */
595 XSelectInput(obt_display, self->window, NoEventMask);
597 /* ignore enter events from the unmap so it doesnt mess with the focus */
598 if (!config_focus_under_mouse)
599 ignore_start = event_start_ignore_all_enters();
601 frame_hide(self->frame);
602 /* flush to send the hide to the server quickly */
605 if (!config_focus_under_mouse)
606 event_end_ignore_all_enters(ignore_start);
608 mouse_grab_for_client(self, FALSE);
610 self->managed = FALSE;
612 /* remove the window from our save set, unless we are managing an internal
615 XChangeSaveSet(obt_display, self->window, SetModeDelete);
617 /* update the focus lists */
618 focus_order_remove(self);
619 if (client_focused(self)) {
620 /* don't leave an invalid focus_client */
624 /* if we're prompting to kill the client, close that */
625 prompt_unref(self->kill_prompt);
626 self->kill_prompt = NULL;
628 client_list = g_list_remove(client_list, self);
629 stacking_remove(self);
630 window_remove(self->window);
632 /* once the client is out of the list, update the struts to remove its
634 if (STRUT_EXISTS(self->strut))
635 screen_update_areas();
637 client_call_notifies(self, client_destroy_notifies);
639 /* tell our parent(s) that we're gone */
640 for (it = self->parents; it; it = g_slist_next(it))
641 ((ObClient*)it->data)->transients =
642 g_slist_remove(((ObClient*)it->data)->transients,self);
644 /* tell our transients that we're gone */
645 for (it = self->transients; it; it = g_slist_next(it)) {
646 ((ObClient*)it->data)->parents =
647 g_slist_remove(((ObClient*)it->data)->parents, self);
648 /* we could be keeping our children in a higher layer */
649 client_calc_layer(it->data);
652 /* remove from its group */
654 group_remove(self->group, self);
658 /* restore the window's original geometry so it is not lost */
664 if (self->fullscreen)
665 a = self->pre_fullscreen_area;
666 else if (self->max_horz || self->max_vert) {
667 if (self->max_horz) {
668 a.x = self->pre_max_area.x;
669 a.width = self->pre_max_area.width;
671 if (self->max_vert) {
672 a.y = self->pre_max_area.y;
673 a.height = self->pre_max_area.height;
677 self->fullscreen = self->max_horz = self->max_vert = FALSE;
678 /* let it be moved and resized no matter what */
679 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
680 self->decorations = 0; /* unmanaged windows have no decor */
682 /* give the client its border back */
683 XSetWindowBorderWidth(obt_display, self->window, self->border_width);
685 client_move_resize(self, a.x, a.y, a.width, a.height);
688 /* reparent the window out of the frame, and free the frame */
689 frame_release_client(self->frame);
690 frame_free(self->frame);
693 if (ob_state() != OB_STATE_EXITING) {
694 /* these values should not be persisted across a window
696 OBT_PROP_ERASE(self->window, NET_WM_DESKTOP);
697 OBT_PROP_ERASE(self->window, NET_WM_STATE);
698 OBT_PROP_ERASE(self->window, WM_STATE);
700 /* if we're left in an unmapped state, the client wont be mapped.
701 this is bad, since we will no longer be managing the window on
703 XMapWindow(obt_display, self->window);
706 /* these should not be left on the window ever. other window managers
707 don't necessarily use them and it will mess them up (like compiz) */
708 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_NAME);
709 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_ICON_NAME);
711 /* update the list hints */
714 ob_debug("Unmanaged window 0x%lx", self->window);
716 /* free all data allocated in the client struct */
717 RrImageUnref(self->icon_set);
718 g_slist_free(self->transients);
719 g_free(self->startup_id);
720 g_free(self->wm_command);
722 g_free(self->icon_title);
723 g_free(self->original_title);
727 g_free(self->group_name);
728 g_free(self->group_class);
729 g_free(self->client_machine);
730 g_free(self->sm_client_id);
731 g_slice_free(ObClient, self);
734 void client_fake_unmanage(ObClient *self)
736 /* this is all that got allocated to get the decorations */
738 frame_free(self->frame);
739 g_slice_free(ObClient, self);
742 static gboolean client_can_steal_focus(ObClient *self,
743 gboolean allow_other_desktop,
744 gboolean request_from_user,
749 gboolean relative_focused;
753 relative_focused = (focus_client != NULL &&
754 (client_search_focus_tree_full(self) != NULL ||
755 client_search_focus_group_full(self) != NULL));
757 /* This is focus stealing prevention */
758 ob_debug("Want to focus window 0x%x at time %u "
759 "launched at %u (last user interaction time %u) "
760 "request from %s, allow other desktop: %s, "
761 "desktop switch time %u",
762 self->window, steal_time, launch_time,
763 event_last_user_time,
764 (request_from_user ? "user" : "other"),
765 (allow_other_desktop ? "yes" : "no"),
766 screen_desktop_user_time);
769 if no launch time is provided for an application, make one up.
771 if the window is related to other existing windows
772 and one of those windows was the last used
773 then we will give it a launch time equal to the last user time,
774 which will end up giving the window focus probably.
776 the window is related to other windows, but you are not working in
778 seems suspicious, so we will give it a launch time of
779 NOW - STEAL_INTERVAL,
780 so it will be given focus only if we didn't use something else
781 during the steal interval.
783 the window is all on its own, so we can't judge it. give it a launch
784 time equal to the last user time, so it will probably take focus.
786 this way running things from a terminal will give them focus, but popups
787 without a launch time shouldn't steal focus so easily.
791 if (client_has_relative(self)) {
792 if (event_last_user_time && client_search_focus_group_full(self)) {
793 /* our relative is focused */
794 launch_time = event_last_user_time;
795 ob_debug("Unknown launch time, using %u - window in active "
796 "group", launch_time);
798 else if (!request_from_user) {
799 /* has relatives which are not being used. suspicious */
800 launch_time = event_time() - OB_EVENT_USER_TIME_DELAY;
801 ob_debug("Unknown launch time, using %u - window in inactive "
802 "group", launch_time);
805 /* has relatives which are not being used, but the user seems
806 to want to go there! */
807 launch_time = event_last_user_time;
808 ob_debug("Unknown launch time, using %u - user request",
813 /* the window is on its own, probably the user knows it is going
815 launch_time = event_last_user_time;
816 ob_debug("Unknown launch time, using %u - independent window",
821 /* if it's on another desktop
822 and if allow_other_desktop is true, we generally let it steal focus.
823 but if it didn't come from the user, don't let it steal unless it was
824 launched before the user switched desktops.
825 focus, unless it was launched after we changed desktops and the request
828 if (!screen_compare_desktops(screen_desktop, self->desktop)) {
829 /* must be allowed */
830 if (!allow_other_desktop) {
832 ob_debug("Not focusing the window because its on another desktop");
834 /* if we don't know when the desktop changed, but request is from an
835 application, don't let it change desktop on you */
836 else if (!request_from_user) {
838 ob_debug("Not focusing the window because non-user request");
841 /* If something is focused... */
842 else if (focus_client) {
843 /* If the user is working in another window right now, then don't
845 if (!relative_focused &&
846 event_last_user_time &&
847 /* last user time must be strictly > launch_time to block focus */
848 (event_time_after(event_last_user_time, launch_time) &&
849 event_last_user_time != launch_time) &&
850 event_time_after(event_last_user_time,
851 steal_time - OB_EVENT_USER_TIME_DELAY))
854 ob_debug("Not focusing the window because the user is "
855 "working in another window that is not its relative");
857 /* Don't move focus if it's not going to go to this window
859 else if (client_focus_target(self) != self) {
861 ob_debug("Not focusing the window because another window "
862 "would get the focus anyway");
864 /* For requests that don't come from the user */
865 else if (!request_from_user) {
866 /* If the new window is a transient (and its relatives aren't
868 if (client_has_parent(self) && !relative_focused) {
870 ob_debug("Not focusing the window because it is a "
871 "transient, and its relatives aren't focused");
873 /* Don't steal focus from globally active clients.
874 I stole this idea from KWin. It seems nice.
876 else if (!(focus_client->can_focus || focus_client->focus_notify))
879 ob_debug("Not focusing the window because a globally "
880 "active client has focus");
882 /* Don't move focus if the window is not visible on the current
883 desktop and none of its relatives are focused */
884 else if (!allow_other_desktop &&
885 !screen_compare_desktops(self->desktop, screen_desktop) &&
889 ob_debug("Not focusing the window because it is on "
890 "another desktop and no relatives are focused ");
896 ob_debug("Focus stealing prevention activated for %s at "
897 "time %u (last user interaction time %u)",
898 self->title, steal_time, event_last_user_time);
900 ob_debug("Allowing focus stealing for %s at time %u (last user "
901 "interaction time %u)",
902 self->title, steal_time, event_last_user_time);
906 /*! Returns a new structure containing the per-app settings for this client.
907 The returned structure needs to be freed with g_free. */
908 static ObAppSettings *client_get_settings_state(ObClient *self)
910 ObAppSettings *settings;
913 settings = config_create_app_settings();
915 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
916 ObAppSettings *app = it->data;
917 gboolean match = TRUE;
919 g_assert(app->name != NULL || app->class != NULL ||
920 app->role != NULL || app->title != NULL ||
921 app->group_name != NULL || app->group_class != NULL ||
922 (signed)app->type >= 0);
925 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
927 else if (app->group_name &&
928 !g_pattern_match(app->group_name,
929 strlen(self->group_name), self->group_name, NULL))
931 else if (app->class &&
932 !g_pattern_match(app->class,
933 strlen(self->class), self->class, NULL))
935 else if (app->group_class &&
936 !g_pattern_match(app->group_class,
937 strlen(self->group_class), self->group_class,
940 else if (app->role &&
941 !g_pattern_match(app->role,
942 strlen(self->role), self->role, NULL))
944 else if (app->title &&
945 !g_pattern_match(app->title,
946 strlen(self->title), self->title, NULL))
948 else if ((signed)app->type >= 0 && app->type != self->type) {
953 ob_debug("Window matching: %s", app->name);
955 /* copy the settings to our struct, overriding the existing
956 settings if they are not defaults */
957 config_app_settings_copy_non_defaults(app, settings);
961 if (settings->shade != -1)
962 self->shaded = !!settings->shade;
963 if (settings->decor != -1)
964 self->undecorated = !settings->decor;
965 if (settings->iconic != -1)
966 self->iconic = !!settings->iconic;
967 if (settings->skip_pager != -1)
968 self->skip_pager = !!settings->skip_pager;
969 if (settings->skip_taskbar != -1)
970 self->skip_taskbar = !!settings->skip_taskbar;
972 if (settings->max_vert != -1)
973 self->max_vert = !!settings->max_vert;
974 if (settings->max_horz != -1)
975 self->max_horz = !!settings->max_horz;
977 if (settings->fullscreen != -1)
978 self->fullscreen = !!settings->fullscreen;
980 if (settings->desktop) {
981 if (settings->desktop == DESKTOP_ALL)
982 self->desktop = settings->desktop;
983 else if (settings->desktop > 0 &&
984 settings->desktop <= screen_num_desktops)
985 self->desktop = settings->desktop - 1;
988 if (settings->layer == -1) {
992 else if (settings->layer == 0) {
996 else if (settings->layer == 1) {
1003 static void client_restore_session_state(ObClient *self)
1007 ob_debug_type(OB_DEBUG_SM,
1008 "Restore session for client %s", self->title);
1010 if (!(it = session_state_find(self))) {
1011 ob_debug_type(OB_DEBUG_SM,
1012 "Session data not found for client %s", self->title);
1016 self->session = it->data;
1018 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s",
1021 RECT_SET_POINT(self->area, self->session->x, self->session->y);
1022 self->positioned = USPosition;
1023 self->sized = USSize;
1024 if (self->session->w > 0)
1025 self->area.width = self->session->w;
1026 if (self->session->h > 0)
1027 self->area.height = self->session->h;
1028 XResizeWindow(obt_display, self->window,
1029 self->area.width, self->area.height);
1031 self->desktop = (self->session->desktop == DESKTOP_ALL ?
1032 self->session->desktop :
1033 MIN(screen_num_desktops - 1, self->session->desktop));
1034 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
1036 self->shaded = self->session->shaded;
1037 self->iconic = self->session->iconic;
1038 self->skip_pager = self->session->skip_pager;
1039 self->skip_taskbar = self->session->skip_taskbar;
1040 self->fullscreen = self->session->fullscreen;
1041 self->above = self->session->above;
1042 self->below = self->session->below;
1043 self->max_horz = self->session->max_horz;
1044 self->max_vert = self->session->max_vert;
1045 self->undecorated = self->session->undecorated;
1048 static gboolean client_restore_session_stacking(ObClient *self)
1052 if (!self->session) return FALSE;
1054 mypos = g_list_find(session_saved_state, self->session);
1055 if (!mypos) return FALSE;
1057 /* start above me and look for the first client */
1058 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
1061 for (cit = client_list; cit; cit = g_list_next(cit)) {
1062 ObClient *c = cit->data;
1063 /* found a client that was in the session, so go below it */
1064 if (c->session == it->data) {
1065 stacking_below(CLIENT_AS_WINDOW(self),
1066 CLIENT_AS_WINDOW(cit->data));
1074 void client_move_onscreen(ObClient *self, gboolean rude)
1076 gint x = self->area.x;
1077 gint y = self->area.y;
1078 if (client_find_onscreen(self, &x, &y,
1080 self->area.height, rude)) {
1081 client_move(self, x, y);
1085 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
1088 gint ox = *x, oy = *y;
1089 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
1095 RECT_SET(desired, *x, *y, w, h);
1096 frame_rect_to_frame(self->frame, &desired);
1098 /* get where the frame would be */
1099 frame_client_gravity(self->frame, x, y);
1101 /* get the requested size of the window with decorations */
1102 fw = self->frame->size.left + w + self->frame->size.right;
1103 fh = self->frame->size.top + h + self->frame->size.bottom;
1105 /* If rudeness wasn't requested, then still be rude in a given direction
1106 if the client is not moving, only resizing in that direction */
1108 Point oldtl, oldtr, oldbl, oldbr;
1109 Point newtl, newtr, newbl, newbr;
1110 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
1112 POINT_SET(oldtl, self->frame->area.x, self->frame->area.y);
1113 POINT_SET(oldbr, self->frame->area.x + self->frame->area.width - 1,
1114 self->frame->area.y + self->frame->area.height - 1);
1115 POINT_SET(oldtr, oldbr.x, oldtl.y);
1116 POINT_SET(oldbl, oldtl.x, oldbr.y);
1118 POINT_SET(newtl, *x, *y);
1119 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
1120 POINT_SET(newtr, newbr.x, newtl.y);
1121 POINT_SET(newbl, newtl.x, newbr.y);
1123 /* is it moving or just resizing from some corner? */
1124 stationary_l = oldtl.x == newtl.x;
1125 stationary_r = oldtr.x == newtr.x;
1126 stationary_t = oldtl.y == newtl.y;
1127 stationary_b = oldbl.y == newbl.y;
1129 /* if left edge is growing and didnt move right edge */
1130 if (stationary_r && newtl.x < oldtl.x)
1132 /* if right edge is growing and didnt move left edge */
1133 if (stationary_l && newtr.x > oldtr.x)
1135 /* if top edge is growing and didnt move bottom edge */
1136 if (stationary_b && newtl.y < oldtl.y)
1138 /* if bottom edge is growing and didnt move top edge */
1139 if (stationary_t && newbl.y > oldbl.y)
1143 /* we iterate through every monitor that the window is at least partially
1144 on, to make sure it is obeying the rules on them all
1146 if the window does not appear on any monitors, then use the first one
1149 for (i = 0; i < screen_num_monitors; ++i) {
1152 if (!screen_physical_area_monitor_contains(i, &desired)) {
1153 if (i < screen_num_monitors - 1 || found_mon)
1156 /* the window is not inside any monitor! so just use the first
1158 a = screen_area(self->desktop, 0, NULL);
1161 a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &desired);
1164 /* This makes sure windows aren't entirely outside of the screen so you
1165 can't see them at all.
1166 It makes sure 10% of the window is on the screen at least. And don't
1167 let it move itself off the top of the screen, which would hide the
1168 titlebar on you. (The user can still do this if they want too, it's
1169 only limiting the application.
1171 if (client_normal(self)) {
1172 if (!self->strut.right && *x + fw/100 >= a->x + a->width - 1)
1173 *x = a->x + a->width - fw/100;
1174 if (!self->strut.bottom && *y + fh/100 >= a->y + a->height - 1)
1175 *y = a->y + a->height - fh/100;
1176 if (!self->strut.left && *x + fw*99/100 - 1 < a->x)
1177 *x = a->x - fw*99/100;
1178 if (!self->strut.top && *y + fh*99/100 - 1 < a->y)
1179 *y = a->y - fh*99/100;
1182 /* This here doesn't let windows even a pixel outside the
1183 struts/screen. When called from client_manage, programs placing
1184 themselves are forced completely onscreen, while things like
1185 xterm -geometry resolution-width/2 will work fine. Trying to
1186 place it completely offscreen will be handled in the above code.
1187 Sorry for this confused comment, i am tired. */
1188 if (rudel && !self->strut.left && *x < a->x) *x = a->x;
1189 if (ruder && !self->strut.right && *x + fw > a->x + a->width)
1190 *x = a->x + MAX(0, a->width - fw);
1192 if (rudet && !self->strut.top && *y < a->y) *y = a->y;
1193 if (rudeb && !self->strut.bottom && *y + fh > a->y + a->height)
1194 *y = a->y + MAX(0, a->height - fh);
1196 g_slice_free(Rect, a);
1199 /* get where the client should be */
1200 frame_frame_gravity(self->frame, x, y);
1202 return ox != *x || oy != *y;
1205 static void client_get_all(ObClient *self, gboolean real)
1207 /* this is needed for the frame to set itself up */
1208 client_get_area(self);
1210 /* these things can change the decor and functions of the window */
1212 client_get_mwm_hints(self);
1213 /* this can change the mwmhints for special cases */
1214 client_get_type_and_transientness(self);
1215 client_update_normal_hints(self);
1217 /* set up the maximum possible decor/functions */
1218 client_setup_default_decor_and_functions(self);
1220 client_get_state(self);
1222 /* get the session related properties, these can change decorations
1223 from per-app settings */
1224 client_get_session_ids(self);
1226 /* get this early so we have it for debugging, also this can be used
1227 by app rule matching */
1228 client_update_title(self);
1230 /* now we got everything that can affect the decorations or app rule
1235 /* save the values of the variables used for app rule matching */
1236 client_save_app_rule_values(self);
1238 client_update_protocols(self);
1240 client_update_wmhints(self);
1241 /* this may have already been called from client_update_wmhints */
1242 if (!self->parents && !self->transient_for_group)
1243 client_update_transient_for(self);
1245 client_get_startup_id(self);
1246 client_get_desktop(self);/* uses transient data/group/startup id if a
1247 desktop is not specified */
1248 client_get_shaped(self);
1251 /* a couple type-based defaults for new windows */
1253 /* this makes sure that these windows appear on all desktops */
1254 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1255 self->desktop = DESKTOP_ALL;
1259 client_update_sync_request_counter(self);
1262 client_get_colormap(self);
1263 client_update_strut(self);
1264 client_update_icons(self);
1265 client_update_icon_geometry(self);
1268 static void client_get_startup_id(ObClient *self)
1270 if (!(OBT_PROP_GETS_UTF8(self->window, NET_STARTUP_ID, &self->startup_id)))
1272 OBT_PROP_GETS_UTF8(self->group->leader, NET_STARTUP_ID,
1276 static void client_get_area(ObClient *self)
1278 XWindowAttributes wattrib;
1281 ret = XGetWindowAttributes(obt_display, self->window, &wattrib);
1282 g_assert(ret != BadWindow);
1284 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1285 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1286 self->border_width = wattrib.border_width;
1288 ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y,
1289 wattrib.width, wattrib.height, wattrib.border_width);
1292 static void client_get_desktop(ObClient *self)
1294 guint32 d = screen_num_desktops; /* an always-invalid value */
1296 if (OBT_PROP_GET32(self->window, NET_WM_DESKTOP, CARDINAL, &d)) {
1297 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1298 self->desktop = screen_num_desktops - 1;
1301 ob_debug("client requested desktop 0x%x", self->desktop);
1304 gboolean first = TRUE;
1305 guint all = screen_num_desktops; /* not a valid value */
1307 /* if they are all on one desktop, then open it on the
1309 for (it = self->parents; it; it = g_slist_next(it)) {
1310 ObClient *c = it->data;
1312 if (c->desktop == DESKTOP_ALL) continue;
1318 else if (all != c->desktop)
1319 all = screen_num_desktops; /* make it invalid */
1321 if (all != screen_num_desktops) {
1322 self->desktop = all;
1324 ob_debug("client desktop set from parents: 0x%x",
1327 /* try get from the startup-notification protocol */
1328 else if (sn_get_desktop(self->startup_id, &self->desktop)) {
1329 if (self->desktop >= screen_num_desktops &&
1330 self->desktop != DESKTOP_ALL)
1331 self->desktop = screen_num_desktops - 1;
1332 ob_debug("client desktop set from startup-notification: 0x%x",
1335 /* defaults to the current desktop */
1337 self->desktop = screen_desktop;
1338 ob_debug("client desktop set to the current desktop: %d",
1344 static void client_get_state(ObClient *self)
1349 if (OBT_PROP_GETA32(self->window, NET_WM_STATE, ATOM, &state, &num)) {
1351 for (i = 0; i < num; ++i) {
1352 if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
1354 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
1355 self->shaded = TRUE;
1356 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
1357 self->iconic = TRUE;
1358 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
1359 self->skip_taskbar = TRUE;
1360 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
1361 self->skip_pager = TRUE;
1362 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
1363 self->fullscreen = TRUE;
1364 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
1365 self->max_vert = TRUE;
1366 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
1367 self->max_horz = TRUE;
1368 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
1370 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
1372 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
1373 self->demands_attention = TRUE;
1374 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
1375 self->undecorated = TRUE;
1376 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_LOCKED))
1377 self->locked = TRUE;
1384 static void client_get_shaped(ObClient *self)
1386 self->shaped = FALSE;
1388 if (obt_display_extension_shape) {
1393 XShapeSelectInput(obt_display, self->window, ShapeNotifyMask);
1395 XShapeQueryExtents(obt_display, self->window, &s, &foo,
1396 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1403 void client_update_transient_for(ObClient *self)
1406 ObClient *target = NULL;
1407 gboolean trangroup = FALSE;
1409 if (XGetTransientForHint(obt_display, self->window, &t)) {
1410 if (t != self->window) { /* can't be transient to itself! */
1411 ObWindow *tw = window_find(t);
1412 /* if this happens then we need to check for it */
1413 g_assert(tw != CLIENT_AS_WINDOW(self));
1414 if (tw && WINDOW_IS_CLIENT(tw)) {
1415 /* watch out for windows with a parent that is something
1416 different, like a dockapp for example */
1417 target = WINDOW_AS_CLIENT(tw);
1421 /* Setting the transient_for to Root is actually illegal, however
1422 applications from time have done this to specify transient for
1424 if (!target && self->group && t == obt_root(ob_screen))
1426 } else if (self->group && self->transient)
1429 client_update_transient_tree(self, self->group, self->group,
1430 self->transient_for_group, trangroup,
1431 client_direct_parent(self), target);
1432 self->transient_for_group = trangroup;
1436 static void client_update_transient_tree(ObClient *self,
1437 ObGroup *oldgroup, ObGroup *newgroup,
1438 gboolean oldgtran, gboolean newgtran,
1439 ObClient* oldparent,
1440 ObClient *newparent)
1445 g_assert(!oldgtran || oldgroup);
1446 g_assert(!newgtran || newgroup);
1447 g_assert((!oldgtran && !oldparent) ||
1448 (oldgtran && !oldparent) ||
1449 (!oldgtran && oldparent));
1450 g_assert((!newgtran && !newparent) ||
1451 (newgtran && !newparent) ||
1452 (!newgtran && newparent));
1455 Group transient windows are not allowed to have other group
1456 transient windows as their children.
1459 /* No change has occured */
1460 if (oldgroup == newgroup &&
1461 oldgtran == newgtran &&
1462 oldparent == newparent) return;
1464 /** Remove the client from the transient tree **/
1466 for (it = self->transients; it; it = next) {
1467 next = g_slist_next(it);
1469 self->transients = g_slist_delete_link(self->transients, it);
1470 c->parents = g_slist_remove(c->parents, self);
1472 for (it = self->parents; it; it = next) {
1473 next = g_slist_next(it);
1475 self->parents = g_slist_delete_link(self->parents, it);
1476 c->transients = g_slist_remove(c->transients, self);
1479 /** Re-add the client to the transient tree **/
1481 /* If we're transient for a group then we need to add ourselves to all our
1484 for (it = newgroup->members; it; it = g_slist_next(it)) {
1487 !client_search_top_direct_parent(c)->transient_for_group &&
1490 c->transients = g_slist_prepend(c->transients, self);
1491 self->parents = g_slist_prepend(self->parents, c);
1496 /* If we are now transient for a single window we need to add ourselves to
1499 WARNING: Cyclical transient-ness is possible if two windows are
1500 transient for eachother.
1502 else if (newparent &&
1503 /* don't make ourself its child if it is already our child */
1504 !client_is_direct_child(self, newparent) &&
1505 client_normal(newparent))
1507 newparent->transients = g_slist_prepend(newparent->transients, self);
1508 self->parents = g_slist_prepend(self->parents, newparent);
1511 /* Add any group transient windows to our children. But if we're transient
1512 for the group, then other group transients are not our children.
1514 WARNING: Cyclical transient-ness is possible. For e.g. if:
1515 A is transient for the group
1516 B is transient for A
1517 C is transient for B
1518 A can't be transient for C or we have a cycle
1520 if (!newgtran && newgroup &&
1522 !client_search_top_direct_parent(newparent)->transient_for_group) &&
1523 client_normal(self))
1525 for (it = newgroup->members; it; it = g_slist_next(it)) {
1527 if (c != self && c->transient_for_group &&
1528 /* Don't make it our child if it is already our parent */
1529 !client_is_direct_child(c, self))
1531 self->transients = g_slist_prepend(self->transients, c);
1532 c->parents = g_slist_prepend(c->parents, self);
1537 /** If we change our group transient-ness, our children change their
1538 effective group transient-ness, which affects how they relate to other
1541 for (it = self->transients; it; it = g_slist_next(it)) {
1543 if (!c->transient_for_group)
1544 client_update_transient_tree(c, c->group, c->group,
1545 c->transient_for_group,
1546 c->transient_for_group,
1547 client_direct_parent(c),
1548 client_direct_parent(c));
1552 void client_get_mwm_hints(ObClient *self)
1557 self->mwmhints.flags = 0; /* default to none */
1559 if (OBT_PROP_GETA32(self->window, MOTIF_WM_HINTS, MOTIF_WM_HINTS,
1561 if (num >= OB_MWM_ELEMENTS) {
1562 self->mwmhints.flags = hints[0];
1563 self->mwmhints.functions = hints[1];
1564 self->mwmhints.decorations = hints[2];
1570 void client_get_type_and_transientness(ObClient *self)
1577 self->transient = FALSE;
1579 if (OBT_PROP_GETA32(self->window, NET_WM_WINDOW_TYPE, ATOM, &val, &num)) {
1580 /* use the first value that we know about in the array */
1581 for (i = 0; i < num; ++i) {
1582 if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
1583 self->type = OB_CLIENT_TYPE_DESKTOP;
1584 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK))
1585 self->type = OB_CLIENT_TYPE_DOCK;
1586 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR))
1587 self->type = OB_CLIENT_TYPE_TOOLBAR;
1588 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
1589 self->type = OB_CLIENT_TYPE_MENU;
1590 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY))
1591 self->type = OB_CLIENT_TYPE_UTILITY;
1592 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH))
1593 self->type = OB_CLIENT_TYPE_SPLASH;
1594 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG))
1595 self->type = OB_CLIENT_TYPE_DIALOG;
1596 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL))
1597 self->type = OB_CLIENT_TYPE_NORMAL;
1598 else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE))
1600 /* prevent this window from getting any decor or
1602 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1603 OB_MWM_FLAG_DECORATIONS);
1604 self->mwmhints.decorations = 0;
1605 self->mwmhints.functions = 0;
1607 if (self->type != (ObClientType) -1)
1608 break; /* grab the first legit type */
1613 if (XGetTransientForHint(obt_display, self->window, &t))
1614 self->transient = TRUE;
1616 if (self->type == (ObClientType) -1) {
1617 /*the window type hint was not set, which means we either classify
1618 ourself as a normal window or a dialog, depending on if we are a
1620 if (self->transient)
1621 self->type = OB_CLIENT_TYPE_DIALOG;
1623 self->type = OB_CLIENT_TYPE_NORMAL;
1626 /* then, based on our type, we can update our transientness.. */
1627 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1628 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1629 self->type == OB_CLIENT_TYPE_MENU ||
1630 self->type == OB_CLIENT_TYPE_UTILITY)
1632 self->transient = TRUE;
1636 void client_update_protocols(ObClient *self)
1641 self->focus_notify = FALSE;
1642 self->delete_window = FALSE;
1644 if (OBT_PROP_GETA32(self->window, WM_PROTOCOLS, ATOM, &proto, &num_ret)) {
1645 for (i = 0; i < num_ret; ++i) {
1646 if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW))
1647 /* this means we can request the window to close */
1648 self->delete_window = TRUE;
1649 else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS))
1650 /* if this protocol is requested, then the window will be
1651 notified whenever we want it to receive focus */
1652 self->focus_notify = TRUE;
1653 else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING))
1654 /* if this protocol is requested, then the window will allow
1655 pings to determine if it is still alive */
1658 else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST))
1659 /* if this protocol is requested, then resizing the
1660 window will be synchronized between the frame and the
1662 self->sync_request = TRUE;
1670 void client_update_sync_request_counter(ObClient *self)
1674 if (OBT_PROP_GET32(self->window, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i))
1678 self->sync_counter = i;
1680 /* this must be set when managing a new window according to EWMH */
1681 XSyncIntToValue(&val, 0);
1682 XSyncSetCounter(obt_display, self->sync_counter, val);
1684 self->sync_counter = None;
1688 static void client_get_colormap(ObClient *self)
1690 XWindowAttributes wa;
1692 if (XGetWindowAttributes(obt_display, self->window, &wa))
1693 client_update_colormap(self, wa.colormap);
1696 void client_update_colormap(ObClient *self, Colormap colormap)
1698 if (colormap == self->colormap) return;
1700 ob_debug("Setting client %s colormap: 0x%x", self->title, colormap);
1702 if (client_focused(self)) {
1703 screen_install_colormap(self, FALSE); /* uninstall old one */
1704 self->colormap = colormap;
1705 screen_install_colormap(self, TRUE); /* install new one */
1707 self->colormap = colormap;
1710 void client_update_opacity(ObClient *self)
1714 if (OBT_PROP_GET32(self->window, NET_WM_WINDOW_OPACITY, CARDINAL, &o))
1715 OBT_PROP_SET32(self->frame->window, NET_WM_WINDOW_OPACITY, CARDINAL, o);
1717 OBT_PROP_ERASE(self->frame->window, NET_WM_WINDOW_OPACITY);
1720 void client_update_normal_hints(ObClient *self)
1726 self->min_ratio = 0.0f;
1727 self->max_ratio = 0.0f;
1728 SIZE_SET(self->size_inc, 1, 1);
1729 SIZE_SET(self->base_size, -1, -1);
1730 SIZE_SET(self->min_size, 0, 0);
1731 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1733 /* get the hints from the window */
1734 if (XGetWMNormalHints(obt_display, self->window, &size, &ret)) {
1735 /* normal windows can't request placement! har har
1736 if (!client_normal(self))
1738 self->positioned = (size.flags & (PPosition|USPosition));
1739 self->sized = (size.flags & (PSize|USSize));
1741 if (size.flags & PWinGravity)
1742 self->gravity = size.win_gravity;
1744 if (size.flags & PAspect) {
1745 if (size.min_aspect.y)
1747 (gfloat) size.min_aspect.x / size.min_aspect.y;
1748 if (size.max_aspect.y)
1750 (gfloat) size.max_aspect.x / size.max_aspect.y;
1753 if (size.flags & PMinSize)
1754 SIZE_SET(self->min_size, size.min_width, size.min_height);
1756 if (size.flags & PMaxSize)
1757 SIZE_SET(self->max_size, size.max_width, size.max_height);
1759 if (size.flags & PBaseSize)
1760 SIZE_SET(self->base_size, size.base_width, size.base_height);
1762 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1763 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1765 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1766 self->min_size.width, self->min_size.height,
1767 self->max_size.width, self->max_size.height);
1768 ob_debug("size inc (%d %d) base size (%d %d)",
1769 self->size_inc.width, self->size_inc.height,
1770 self->base_size.width, self->base_size.height);
1773 ob_debug("Normal hints: not set");
1776 static void client_setup_default_decor_and_functions(ObClient *self)
1778 /* start with everything (cept fullscreen) */
1780 (OB_FRAME_DECOR_TITLEBAR |
1781 OB_FRAME_DECOR_HANDLE |
1782 OB_FRAME_DECOR_GRIPS |
1783 OB_FRAME_DECOR_BORDER |
1784 OB_FRAME_DECOR_ICON |
1785 OB_FRAME_DECOR_ALLDESKTOPS |
1786 OB_FRAME_DECOR_ICONIFY |
1787 OB_FRAME_DECOR_MAXIMIZE |
1788 OB_FRAME_DECOR_SHADE |
1789 OB_FRAME_DECOR_CLOSE);
1791 (OB_CLIENT_FUNC_RESIZE |
1792 OB_CLIENT_FUNC_MOVE |
1793 OB_CLIENT_FUNC_ICONIFY |
1794 OB_CLIENT_FUNC_MAXIMIZE |
1795 OB_CLIENT_FUNC_SHADE |
1796 OB_CLIENT_FUNC_CLOSE |
1797 OB_CLIENT_FUNC_BELOW |
1798 OB_CLIENT_FUNC_ABOVE |
1799 OB_CLIENT_FUNC_UNDECORATE);
1801 if (!(self->min_size.width < self->max_size.width ||
1802 self->min_size.height < self->max_size.height))
1803 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1805 switch (self->type) {
1806 case OB_CLIENT_TYPE_NORMAL:
1807 /* normal windows retain all of the possible decorations and
1808 functionality, and can be fullscreen */
1809 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1812 case OB_CLIENT_TYPE_DIALOG:
1813 /* sometimes apps make dialog windows fullscreen for some reason (for
1814 e.g. kpdf does this..) */
1815 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1818 case OB_CLIENT_TYPE_UTILITY:
1819 /* these windows don't have anything added or removed by default */
1822 case OB_CLIENT_TYPE_MENU:
1823 case OB_CLIENT_TYPE_TOOLBAR:
1824 /* these windows can't iconify or maximize */
1825 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1826 OB_FRAME_DECOR_MAXIMIZE);
1827 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1828 OB_CLIENT_FUNC_MAXIMIZE);
1831 case OB_CLIENT_TYPE_SPLASH:
1832 /* these don't get get any decorations, and the only thing you can
1833 do with them is move them */
1834 self->decorations = 0;
1835 self->functions = OB_CLIENT_FUNC_MOVE;
1838 case OB_CLIENT_TYPE_DESKTOP:
1839 /* these windows are not manipulated by the window manager */
1840 self->decorations = 0;
1841 self->functions = 0;
1844 case OB_CLIENT_TYPE_DOCK:
1845 /* these windows are not manipulated by the window manager, but they
1846 can set below layer which has a special meaning */
1847 self->decorations = 0;
1848 self->functions = OB_CLIENT_FUNC_BELOW;
1852 /* If the client has no decor from its type (which never changes) then
1853 don't allow the user to "undecorate" the window. Otherwise, allow them
1854 to, even if there are motif hints removing the decor, because those
1855 may change these days (e.g. chromium) */
1856 if (self->decorations == 0)
1857 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1859 /* Mwm Hints are applied subtractively to what has already been chosen for
1860 decor and functionality */
1861 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1862 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1863 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1864 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1866 /* if the mwm hints request no handle or title, then all
1867 decorations are disabled, but keep the border if that's
1869 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1870 self->decorations = OB_FRAME_DECOR_BORDER;
1872 self->decorations = 0;
1877 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1878 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1879 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1880 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1881 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1882 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1883 /* dont let mwm hints kill any buttons
1884 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1885 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1886 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1887 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1889 /* dont let mwm hints kill the close button
1890 if (! (self->mwmhints.functions & MwmFunc_Close))
1891 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1895 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1896 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1897 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1898 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1899 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1900 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1902 /* can't maximize without moving/resizing */
1903 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1904 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1905 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1906 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1907 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1911 /*! Set up decor for a client based on its undecorated state. */
1912 static void client_setup_decor_undecorated(ObClient *self)
1914 /* If the user requested no decorations, then remove all the decorations,
1915 except the border. But don't add a border if there wasn't one. */
1916 if (self->undecorated)
1917 self->decorations &= (config_theme_keepborder ?
1918 OB_FRAME_DECOR_BORDER : 0);
1921 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1923 client_setup_default_decor_and_functions(self);
1925 client_setup_decor_undecorated(self);
1927 if (self->max_horz && self->max_vert) {
1928 /* once upon a time you couldn't resize maximized windows, that is not
1929 the case any more though !
1931 but do kill the handle on fully maxed windows */
1932 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1935 /* if we don't have a titlebar, then we cannot shade! */
1936 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1937 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1939 /* now we need to check against rules for the client's current state */
1940 if (self->fullscreen) {
1941 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1942 OB_CLIENT_FUNC_FULLSCREEN |
1943 OB_CLIENT_FUNC_ICONIFY);
1944 self->decorations = 0;
1947 client_change_allowed_actions(self);
1950 /* reconfigure to make sure decorations are updated */
1951 client_reconfigure(self, FALSE);
1954 static void client_change_allowed_actions(ObClient *self)
1959 /* desktop windows are kept on all desktops */
1960 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1961 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP);
1963 if (self->functions & OB_CLIENT_FUNC_SHADE)
1964 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE);
1965 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1966 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE);
1967 if (self->functions & OB_CLIENT_FUNC_MOVE)
1968 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE);
1969 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1970 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE);
1971 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1972 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE);
1973 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1974 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN);
1975 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1976 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ);
1977 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT);
1979 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1980 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE);
1981 if (self->functions & OB_CLIENT_FUNC_BELOW)
1982 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW);
1983 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1984 actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE);
1986 OBT_PROP_SETA32(self->window, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num);
1988 /* make sure the window isn't breaking any rules now
1990 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1991 it can't be iconified with its parent
1994 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1995 if (self->frame) client_shade(self, FALSE);
1996 else self->shaded = FALSE;
1998 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1999 if (self->frame) client_fullscreen(self, FALSE);
2000 else self->fullscreen = FALSE;
2002 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
2004 if (self->frame) client_maximize(self, FALSE, 0);
2005 else self->max_vert = self->max_horz = FALSE;
2009 void client_update_wmhints(ObClient *self)
2013 /* assume a window takes input if it doesn't specify */
2014 self->can_focus = TRUE;
2016 if ((hints = XGetWMHints(obt_display, self->window)) != NULL) {
2019 if (hints->flags & InputHint)
2020 self->can_focus = hints->input;
2022 /* only do this when first managing the window *AND* when we aren't
2024 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
2025 if (hints->flags & StateHint)
2026 self->iconic = hints->initial_state == IconicState;
2029 self->urgent = (hints->flags & XUrgencyHint);
2030 if (self->urgent && !ur)
2031 client_hilite(self, TRUE);
2032 else if (!self->urgent && ur && self->demands_attention)
2033 client_hilite(self, FALSE);
2035 if (!(hints->flags & WindowGroupHint))
2036 hints->window_group = None;
2038 /* did the group state change? */
2039 if (hints->window_group !=
2040 (self->group ? self->group->leader : None))
2042 ObGroup *oldgroup = self->group;
2044 /* remove from the old group if there was one */
2046 group_remove(self->group, self);
2050 /* add ourself to the group if we have one */
2051 if (hints->window_group != None) {
2052 self->group = group_add(hints->window_group, self);
2055 /* Put ourselves into the new group's transient tree, and remove
2056 ourselves from the old group's */
2057 client_update_transient_tree(self, oldgroup, self->group,
2058 self->transient_for_group,
2059 self->transient_for_group,
2060 client_direct_parent(self),
2061 client_direct_parent(self));
2063 /* Lastly, being in a group, or not, can change if the window is
2064 transient for anything.
2066 The logic for this is:
2067 self->transient = TRUE always if the window wants to be
2068 transient for something, even if transient_for was NULL because
2069 it wasn't in a group before.
2071 If parents was NULL and oldgroup was NULL we can assume
2072 that when we add the new group, it will become transient for
2075 If transient_for_group is TRUE, then it must have already
2076 had a group. If it is getting a new group, the above call to
2077 client_update_transient_tree has already taken care of
2078 everything ! If it is losing all group status then it will
2079 no longer be transient for anything and that needs to be
2082 if (self->transient &&
2083 ((self->parents == NULL && oldgroup == NULL) ||
2084 (self->transient_for_group && !self->group)))
2085 client_update_transient_for(self);
2088 /* the WM_HINTS can contain an icon */
2089 if (hints->flags & IconPixmapHint)
2090 client_update_icons(self);
2095 focus_cycle_addremove(self, TRUE);
2098 void client_update_title(ObClient *self)
2101 gchar *visible = NULL;
2103 g_free(self->original_title);
2106 if (!OBT_PROP_GETS_UTF8(self->window, NET_WM_NAME, &data)) {
2107 /* try old x stuff */
2108 if (!OBT_PROP_GETS(self->window, WM_NAME, &data)) {
2109 if (self->transient) {
2111 GNOME alert windows are not given titles:
2112 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
2114 data = g_strdup("");
2116 if (self->class && *self->class)
2117 data = g_strdup(self->class);
2118 else if (self->name && *self->name)
2119 data = g_strdup(self->name);
2121 data = g_strdup(_("Unnamed Window"));
2125 self->original_title = g_strdup(data);
2127 if (self->client_machine) {
2128 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
2133 if (self->not_responding) {
2135 if (self->kill_level > 0)
2136 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
2138 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
2142 if (!self->title || strcmp(self->title, visible)) {
2143 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_NAME, visible);
2144 g_free(self->title);
2145 self->title = visible;
2150 frame_adjust_title(self->frame);
2152 /* update the icon title */
2156 if (!OBT_PROP_GETS_UTF8(self->window, NET_WM_ICON_NAME, &data))
2157 /* try old x stuff */
2158 if (!OBT_PROP_GETS(self->window, WM_ICON_NAME, &data))
2159 data = g_strdup(self->title);
2161 if (self->client_machine) {
2162 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
2167 if (self->not_responding) {
2169 if (self->kill_level > 0)
2170 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
2172 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
2176 if (!self->icon_title || strcmp(self->icon_title, visible)) {
2177 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_ICON_NAME, visible);
2178 g_free(self->icon_title);
2179 self->icon_title = visible;
2184 void client_update_strut(ObClient *self)
2188 gboolean got = FALSE;
2191 if (OBT_PROP_GETA32(self->window, NET_WM_STRUT_PARTIAL, CARDINAL,
2196 STRUT_PARTIAL_SET(strut,
2197 data[0], data[2], data[1], data[3],
2198 data[4], data[5], data[8], data[9],
2199 data[6], data[7], data[10], data[11]);
2205 OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) {
2211 /* use the screen's width/height */
2212 a = screen_physical_area_all_monitors();
2214 STRUT_PARTIAL_SET(strut,
2215 data[0], data[2], data[1], data[3],
2216 a->y, a->y + a->height - 1,
2217 a->x, a->x + a->width - 1,
2218 a->y, a->y + a->height - 1,
2219 a->x, a->x + a->width - 1);
2225 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2226 0, 0, 0, 0, 0, 0, 0, 0);
2228 if (!PARTIAL_STRUT_EQUAL(strut, self->strut)) {
2229 self->strut = strut;
2231 /* updating here is pointless while we're being mapped cuz we're not in
2232 the client list yet */
2234 screen_update_areas();
2238 void client_update_icons(ObClient *self)
2247 /* grab the server, because we might be setting the window's icon and
2248 we don't want them to set it in between and we overwrite their own
2252 if (OBT_PROP_GETA32(self->window, NET_WM_ICON, CARDINAL, &data, &num)) {
2253 /* figure out how many valid icons are in here */
2255 while (i + 2 < num) { /* +2 is to make sure there is a w and h */
2258 /* watch for the data being too small for the specified size,
2259 or for zero sized icons. */
2260 if (i + w*h > num || w == 0 || h == 0) {
2265 /* convert it to the right bit order for ObRender */
2266 for (j = 0; j < w*h; ++j)
2268 (((data[i+j] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2269 (((data[i+j] >> 16) & 0xff) << RrDefaultRedOffset) +
2270 (((data[i+j] >> 8) & 0xff) << RrDefaultGreenOffset) +
2271 (((data[i+j] >> 0) & 0xff) << RrDefaultBlueOffset);
2273 /* add it to the image cache as an original */
2275 img = RrImageNewFromData(ob_rr_icons, &data[i], w, h);
2277 RrImageAddFromData(img, &data[i], w, h);
2285 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2290 if ((hints = XGetWMHints(obt_display, self->window))) {
2291 if (hints->flags & IconPixmapHint) {
2293 obt_display_ignore_errors(TRUE);
2294 xicon = RrPixmapToRGBA(ob_rr_inst,
2296 (hints->flags & IconMaskHint ?
2297 hints->icon_mask : None),
2298 (gint*)&w, (gint*)&h, &data);
2299 obt_display_ignore_errors(FALSE);
2302 if (w > 0 && h > 0) {
2304 img = RrImageNewFromData(ob_rr_icons, data, w, h);
2306 RrImageAddFromData(img, data, w, h);
2316 /* set the client's icons to be whatever we found */
2317 RrImageUnref(self->icon_set);
2318 self->icon_set = img;
2320 /* if the client has no icon at all, then we set a default icon onto it.
2321 but, if it has parents, then one of them will have an icon already
2323 if (!self->icon_set && !self->parents) {
2324 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2325 gulong *ldata; /* use a long here to satisfy OBT_PROP_SETA32 */
2327 r = g_random_int_range(0,255);
2328 g = g_random_int_range(0,255);
2329 b = g_random_int_range(0,255);
2331 w = ob_rr_theme->def_win_icon_w;
2332 h = ob_rr_theme->def_win_icon_h;
2333 ldata = g_new(gulong, w*h+2);
2336 for (i = 0; i < w*h; ++i)
2337 ldata[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2338 ((((icon[i] >> RrDefaultRedOffset) & 0xff)*r/255) << 16) +
2339 ((((icon[i] >> RrDefaultGreenOffset) & 0xff)*g/255) << 8) +
2340 ((((icon[i] >> RrDefaultBlueOffset) & 0xff)*b/255) << 0);
2341 OBT_PROP_SETA32(self->window, NET_WM_ICON, CARDINAL, ldata, w*h+2);
2343 } else if (self->frame)
2344 /* don't draw the icon empty if we're just setting one now anyways,
2345 we'll get the property change any second */
2346 frame_adjust_icon(self->frame);
2351 void client_update_icon_geometry(ObClient *self)
2356 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2358 if (OBT_PROP_GETA32(self->window, NET_WM_ICON_GEOMETRY, CARDINAL,
2362 /* don't let them set it with an area < 0 */
2363 RECT_SET(self->icon_geometry, data[0], data[1],
2364 MAX(data[2],0), MAX(data[3],0));
2369 static void client_get_session_ids(ObClient *self)
2376 if (!OBT_PROP_GET32(self->window, WM_CLIENT_LEADER, WINDOW, &leader))
2379 /* get the SM_CLIENT_ID */
2380 if (leader && leader != self->window)
2381 OBT_PROP_GETS_XPCS(leader, SM_CLIENT_ID, &self->sm_client_id);
2383 OBT_PROP_GETS_XPCS(self->window, SM_CLIENT_ID, &self->sm_client_id);
2385 /* get the WM_CLASS (name and class). make them "" if they are not
2387 got = OBT_PROP_GETSS_TYPE(self->window, WM_CLASS, STRING_NO_CC, &ss);
2391 self->name = g_strdup(ss[0]);
2393 self->class = g_strdup(ss[1]);
2398 if (self->name == NULL) self->name = g_strdup("");
2399 if (self->class == NULL) self->class = g_strdup("");
2401 /* get the WM_CLASS (name and class) from the group leader. make them "" if
2402 they are not provided */
2404 got = OBT_PROP_GETSS_TYPE(leader, WM_CLASS, STRING_NO_CC, &ss);
2410 self->group_name = g_strdup(ss[0]);
2412 self->group_class = g_strdup(ss[1]);
2417 if (self->group_name == NULL) self->group_name = g_strdup("");
2418 if (self->group_class == NULL) self->group_class = g_strdup("");
2420 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2421 got = OBT_PROP_GETS_XPCS(self->window, WM_WINDOW_ROLE, &s);
2426 self->role = g_strdup("");
2428 /* get the WM_COMMAND */
2432 got = OBT_PROP_GETSS(leader, WM_COMMAND, &ss);
2434 got = OBT_PROP_GETSS(self->window, WM_COMMAND, &ss);
2437 /* merge/mash them all together */
2438 gchar *merge = NULL;
2441 for (i = 0; ss[i]; ++i) {
2444 merge = g_strconcat(merge, ss[i], NULL);
2446 merge = g_strconcat(ss[i], NULL);
2451 self->wm_command = merge;
2454 /* get the WM_CLIENT_MACHINE */
2457 got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, &s);
2459 got = OBT_PROP_GETS(self->window, WM_CLIENT_MACHINE, &s);
2462 gchar localhost[128];
2465 gethostname(localhost, 127);
2466 localhost[127] = '\0';
2467 if (strcmp(localhost, s) != 0)
2468 self->client_machine = s;
2472 /* see if it has the PID set too (the PID requires that the
2473 WM_CLIENT_MACHINE be set) */
2474 if (OBT_PROP_GET32(self->window, NET_WM_PID, CARDINAL, &pid))
2479 const gchar *client_type_to_string(ObClient *self)
2483 switch (self->type) {
2484 case OB_CLIENT_TYPE_NORMAL:
2485 type = "normal"; break;
2486 case OB_CLIENT_TYPE_DIALOG:
2487 type = "dialog"; break;
2488 case OB_CLIENT_TYPE_UTILITY:
2489 type = "utility"; break;
2490 case OB_CLIENT_TYPE_MENU:
2491 type = "menu"; break;
2492 case OB_CLIENT_TYPE_TOOLBAR:
2493 type = "toolbar"; break;
2494 case OB_CLIENT_TYPE_SPLASH:
2495 type = "splash"; break;
2496 case OB_CLIENT_TYPE_DESKTOP:
2497 type = "desktop"; break;
2498 case OB_CLIENT_TYPE_DOCK:
2499 type = "dock"; break;
2505 /*! Save the properties used for app matching rules, as seen by Openbox when
2506 the window mapped, so that users can still access them later if the app
2508 static void client_save_app_rule_values(ObClient *self)
2510 OBT_PROP_SETS(self->window, OB_APP_ROLE, self->role);
2511 OBT_PROP_SETS(self->window, OB_APP_NAME, self->name);
2512 OBT_PROP_SETS(self->window, OB_APP_CLASS, self->class);
2513 OBT_PROP_SETS(self->window, OB_APP_GROUP_NAME, self->group_name);
2514 OBT_PROP_SETS(self->window, OB_APP_GROUP_CLASS, self->group_class);
2515 OBT_PROP_SETS(self->window, OB_APP_TITLE, self->original_title);
2517 OBT_PROP_SETS(self->window, OB_APP_TYPE, client_type_to_string(self));
2520 static void client_change_wm_state(ObClient *self)
2525 old = self->wmstate;
2527 if (self->shaded || self->iconic ||
2528 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2530 self->wmstate = IconicState;
2532 self->wmstate = NormalState;
2534 if (old != self->wmstate) {
2535 OBT_PROP_MSG(ob_screen, self->window, KDE_WM_CHANGE_STATE,
2536 self->wmstate, 1, 0, 0, 0);
2538 state[0] = self->wmstate;
2540 OBT_PROP_SETA32(self->window, WM_STATE, WM_STATE, state, 2);
2544 static void client_change_state(ObClient *self)
2546 gulong netstate[13];
2551 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
2553 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED);
2555 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN);
2556 if (self->skip_taskbar)
2557 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR);
2558 if (self->skip_pager)
2559 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER);
2560 if (self->fullscreen)
2561 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN);
2563 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT);
2565 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ);
2567 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE);
2569 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW);
2570 if (self->demands_attention)
2571 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION);
2572 if (self->undecorated)
2573 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED);
2575 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_LOCKED);
2576 OBT_PROP_SETA32(self->window, NET_WM_STATE, ATOM, netstate, num);
2579 frame_adjust_state(self->frame);
2582 ObClient *client_search_focus_tree(ObClient *self)
2587 for (it = self->transients; it; it = g_slist_next(it)) {
2588 if (client_focused(it->data)) return it->data;
2589 if ((ret = client_search_focus_tree(it->data))) return ret;
2594 ObClient *client_search_focus_tree_full(ObClient *self)
2596 if (self->parents) {
2599 for (it = self->parents; it; it = g_slist_next(it)) {
2600 ObClient *c = it->data;
2601 if ((c = client_search_focus_tree_full(c))) return c;
2607 /* this function checks the whole tree, the client_search_focus_tree
2608 does not, so we need to check this window */
2609 if (client_focused(self))
2611 return client_search_focus_tree(self);
2615 ObClient *client_search_focus_group_full(ObClient *self)
2620 for (it = self->group->members; it; it = g_slist_next(it)) {
2621 ObClient *c = it->data;
2623 if (client_focused(c)) return c;
2624 if ((c = client_search_focus_tree(it->data))) return c;
2627 if (client_focused(self)) return self;
2631 gboolean client_has_parent(ObClient *self)
2633 return self->parents != NULL;
2636 gboolean client_has_children(ObClient *self)
2638 return self->transients != NULL;
2641 gboolean client_is_oldfullscreen(const ObClient *self,
2644 const Rect *monitor, *allmonitors;
2646 /* No decorations and fills the monitor = oldskool fullscreen.
2647 But not for maximized windows.
2650 if (self->decorations || self->max_horz || self->max_vert) return FALSE;
2652 monitor = screen_physical_area_monitor(screen_find_monitor(area));
2653 allmonitors = screen_physical_area_all_monitors();
2655 return (RECT_EQUAL(*area, *monitor) ||
2656 RECT_EQUAL(*area, *allmonitors));
2659 static ObStackingLayer calc_layer(ObClient *self)
2663 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2664 l = OB_STACKING_LAYER_DESKTOP;
2665 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2666 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2667 else l = OB_STACKING_LAYER_ABOVE;
2669 else if ((self->fullscreen ||
2670 client_is_oldfullscreen(self, &self->area)) &&
2671 /* you are fullscreen while you or your children are focused.. */
2672 (client_focused(self) || client_search_focus_tree(self) ||
2673 /* you can be fullscreen if you're on another desktop */
2674 (self->desktop != screen_desktop &&
2675 self->desktop != DESKTOP_ALL) ||
2676 /* and you can also be fullscreen if the focused client is on
2677 another monitor, or nothing else is focused */
2679 client_monitor(focus_client) != client_monitor(self))))
2680 l = OB_STACKING_LAYER_FULLSCREEN;
2681 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2682 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2683 else l = OB_STACKING_LAYER_NORMAL;
2688 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2689 ObStackingLayer min)
2691 ObStackingLayer old, own;
2695 own = calc_layer(self);
2696 self->layer = MAX(own, min);
2698 if (self->layer != old) {
2699 stacking_remove(CLIENT_AS_WINDOW(self));
2700 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2703 /* we've been restacked */
2704 self->visited = TRUE;
2706 for (it = self->transients; it; it = g_slist_next(it))
2707 client_calc_layer_recursive(it->data, orig,
2711 static void client_calc_layer_internal(ObClient *self)
2715 /* transients take on the layer of their parents */
2716 sit = client_search_all_top_parents(self);
2718 for (; sit; sit = g_slist_next(sit))
2719 client_calc_layer_recursive(sit->data, self, 0);
2722 void client_calc_layer(ObClient *self)
2726 /* skip over stuff above fullscreen layer */
2727 for (it = stacking_list; it; it = g_list_next(it))
2728 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2730 /* find the windows in the fullscreen layer, and mark them not-visited */
2731 for (; it; it = g_list_next(it)) {
2732 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2733 else if (WINDOW_IS_CLIENT(it->data))
2734 WINDOW_AS_CLIENT(it->data)->visited = FALSE;
2737 client_calc_layer_internal(self);
2739 /* skip over stuff above fullscreen layer */
2740 for (it = stacking_list; it; it = g_list_next(it))
2741 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2743 /* now recalc any windows in the fullscreen layer which have not
2744 had their layer recalced already */
2745 for (; it; it = g_list_next(it)) {
2746 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2747 else if (WINDOW_IS_CLIENT(it->data) &&
2748 !WINDOW_AS_CLIENT(it->data)->visited)
2749 client_calc_layer_internal(it->data);
2753 gboolean client_should_show(ObClient *self)
2757 if (client_normal(self) && screen_showing_desktop())
2759 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2765 gboolean client_show(ObClient *self)
2767 gboolean show = FALSE;
2769 if (client_should_show(self)) {
2770 /* replay pending pointer event before showing the window, in case it
2771 should be going to something under the window */
2772 mouse_replay_pointer();
2774 frame_show(self->frame);
2777 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2778 it needs to be in IconicState. This includes when it is on another
2781 client_change_wm_state(self);
2786 gboolean client_hide(ObClient *self)
2788 gboolean hide = FALSE;
2790 if (!client_should_show(self)) {
2791 /* We don't need to ignore enter events here.
2792 The window can hide/iconify in 3 different ways:
2793 1 - through an x message. in this case we ignore all enter events
2794 caused by responding to the x message (unless underMouse)
2795 2 - by a keyboard action. in this case we ignore all enter events
2796 caused by the action
2797 3 - by a mouse action. in this case they are doing stuff with the
2798 mouse and focus _should_ move.
2800 Also in action_end, we simulate an enter event that can't be ignored
2801 so trying to ignore them is futile in case 3 anyways
2804 /* replay pending pointer event before hiding the window, in case it
2805 should be going to the window */
2806 mouse_replay_pointer();
2808 frame_hide(self->frame);
2811 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2812 it needs to be in IconicState. This includes when it is on another
2815 client_change_wm_state(self);
2820 void client_showhide(ObClient *self)
2822 if (!client_show(self))
2826 gboolean client_normal(ObClient *self) {
2827 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2828 self->type == OB_CLIENT_TYPE_DOCK ||
2829 self->type == OB_CLIENT_TYPE_SPLASH);
2832 gboolean client_helper(ObClient *self)
2834 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2835 self->type == OB_CLIENT_TYPE_MENU ||
2836 self->type == OB_CLIENT_TYPE_TOOLBAR);
2839 gboolean client_occupies_space(ObClient *self)
2841 return !(self->type == OB_CLIENT_TYPE_DESKTOP ||
2842 self->type == OB_CLIENT_TYPE_SPLASH);
2845 gboolean client_mouse_focusable(ObClient *self)
2847 return !(/*self->type == OB_CLIENT_TYPE_MENU ||*/
2848 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2849 self->type == OB_CLIENT_TYPE_SPLASH ||
2850 self->type == OB_CLIENT_TYPE_DOCK);
2853 gboolean client_enter_focusable(ObClient *self)
2855 /* you can focus desktops but it shouldn't on enter */
2856 return (client_mouse_focusable(self) &&
2857 self->type != OB_CLIENT_TYPE_DESKTOP);
2860 static void client_apply_startup_state(ObClient *self,
2861 gint x, gint y, gint w, gint h)
2863 /* save the states that we are going to apply */
2864 gboolean iconic = self->iconic;
2865 gboolean fullscreen = self->fullscreen;
2866 gboolean undecorated = self->undecorated;
2867 gboolean shaded = self->shaded;
2868 gboolean demands_attention = self->demands_attention;
2869 gboolean max_horz = self->max_horz;
2870 gboolean max_vert = self->max_vert;
2874 /* turn them all off in the client, so they won't affect the window
2876 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2877 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2879 /* move the client to its placed position, or it it's already there,
2880 generate a ConfigureNotify telling the client where it is.
2882 do this after adjusting the frame. otherwise it gets all weird and
2883 clients don't work right
2885 do this before applying the states so they have the correct
2886 pre-max/pre-fullscreen values
2888 client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
2889 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2890 self->window, x, y, w, h);
2891 /* save the area, and make it where it should be for the premax stuff */
2892 oldarea = self->area;
2893 RECT_SET(self->area, x, y, w, h);
2895 /* apply the states. these are in a carefully crafted order.. */
2898 client_iconify(self, TRUE, FALSE, TRUE);
2900 client_set_undecorated(self, TRUE);
2902 client_shade(self, TRUE);
2903 if (demands_attention)
2904 client_hilite(self, TRUE);
2906 if (max_vert && max_horz)
2907 client_maximize(self, TRUE, 0);
2909 client_maximize(self, TRUE, 2);
2911 client_maximize(self, TRUE, 1);
2913 /* fullscreen removes the ability to apply other states */
2915 client_fullscreen(self, TRUE);
2917 /* make sure client_setup_decor_and_functions() is called at least once */
2918 client_setup_decor_and_functions(self, FALSE);
2920 /* if the window hasn't been configured yet, then do so now, in fact the
2921 x,y,w,h may _not_ be the same as the area rect, which can end up
2922 meaning that the client isn't properly moved/resized by the fullscreen
2924 pho can cause this because it maps at size of the screen but not 0,0
2925 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2926 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2927 cuz thats where the pre-fullscreen will be. however the actual area is
2928 not, so this needs to be called even if we have fullscreened/maxed
2930 self->area = oldarea;
2931 client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
2933 /* nothing to do for the other states:
2942 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2944 /* these should be the current values. this is for when you're not moving,
2946 g_assert(*x == self->area.x);
2947 g_assert(oldw == self->area.width);
2950 switch (self->gravity) {
2952 case NorthWestGravity:
2954 case SouthWestGravity:
2961 *x -= (neww - oldw) / 2;
2963 case NorthEastGravity:
2965 case SouthEastGravity:
2971 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2973 /* these should be the current values. this is for when you're not moving,
2975 g_assert(*y == self->area.y);
2976 g_assert(oldh == self->area.height);
2979 switch (self->gravity) {
2981 case NorthWestGravity:
2983 case NorthEastGravity:
2990 *y -= (newh - oldh) / 2;
2992 case SouthWestGravity:
2994 case SouthEastGravity:
3000 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
3001 gint *logicalw, gint *logicalh,
3004 Rect desired = {*x, *y, *w, *h};
3005 frame_rect_to_frame(self->frame, &desired);
3007 /* make the frame recalculate its dimensions n shit without changing
3008 anything visible for real, this way the constraints below can work with
3009 the updated frame dimensions. */
3010 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
3012 /* cap any X windows at the size of an unsigned short */
3015 - self->frame->size.left - self->frame->size.right);
3018 - self->frame->size.top - self->frame->size.bottom);
3020 /* gets the frame's position */
3021 frame_client_gravity(self->frame, x, y);
3023 /* these positions are frame positions, not client positions */
3025 /* set the size and position if fullscreen */
3026 if (self->fullscreen) {
3030 i = screen_find_monitor(&desired);
3031 a = screen_physical_area_monitor(i);
3038 user = FALSE; /* ignore if the client can't be moved/resized when it
3040 } else if (self->max_horz || self->max_vert) {
3044 /* use all possible struts when maximizing to the full screen */
3045 i = screen_find_monitor(&desired);
3046 a = screen_area(self->desktop, i,
3047 (self->max_horz && self->max_vert ? NULL : &desired));
3049 /* set the size and position if maximized */
3050 if (self->max_horz) {
3052 *w = a->width - self->frame->size.left - self->frame->size.right;
3054 if (self->max_vert) {
3056 *h = a->height - self->frame->size.top - self->frame->size.bottom;
3059 user = FALSE; /* ignore if the client can't be moved/resized when it
3062 g_slice_free(Rect, a);
3065 /* gets the client's position */
3066 frame_frame_gravity(self->frame, x, y);
3068 /* work within the preferred sizes given by the window, these may have
3069 changed rather than it's requested width and height, so always run
3070 through this code */
3072 gint basew, baseh, minw, minh;
3073 gint incw, inch, maxw, maxh;
3074 gfloat minratio, maxratio;
3076 incw = self->size_inc.width;
3077 inch = self->size_inc.height;
3078 minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
3079 0 : self->min_ratio;
3080 maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
3081 0 : self->max_ratio;
3083 /* XXX TODO FIXME these two fallbacks don't check that the fallback
3084 * value itself is specified before using it */
3085 /* base size is substituted with min size if not specified */
3086 if (self->base_size.width >= 0 || self->base_size.height >= 0) {
3087 basew = self->base_size.width;
3088 baseh = self->base_size.height;
3090 basew = self->min_size.width;
3091 baseh = self->min_size.height;
3093 /* min size is substituted with base size if not specified */
3094 if (self->min_size.width || self->min_size.height) {
3095 minw = self->min_size.width;
3096 minh = self->min_size.height;
3098 minw = self->base_size.width;
3099 minh = self->base_size.height;
3102 /* This comment is no longer true */
3103 /* if this is a user-requested resize, then check against min/max
3106 /* smaller than min size or bigger than max size? */
3107 if (*w > self->max_size.width) *w = self->max_size.width;
3108 if (*w < minw) *w = minw;
3109 if (*h > self->max_size.height) *h = self->max_size.height;
3110 if (*h < minh) *h = minh;
3115 /* the sizes to used for maximized */
3119 /* keep to the increments */
3123 /* you cannot resize to nothing */
3124 if (basew + *w < 1) *w = 1 - basew;
3125 if (baseh + *h < 1) *h = 1 - baseh;
3127 /* save the logical size */
3128 *logicalw = incw > 1 ? *w : *w + basew;
3129 *logicalh = inch > 1 ? *h : *h + baseh;
3134 /* if maximized/fs then don't use the size increments */
3135 if (self->fullscreen || self->max_horz) *w = maxw;
3136 if (self->fullscreen || self->max_vert) *h = maxh;
3141 /* adjust the height to match the width for the aspect ratios.
3142 for this, min size is not substituted for base size ever. */
3143 if (self->base_size.width >= 0 && self->base_size.height >= 0) {
3144 *w -= self->base_size.width;
3145 *h -= self->base_size.height;
3149 if (*h * minratio > *w) {
3150 *h = (gint)(*w / minratio);
3152 /* you cannot resize to nothing */
3155 *w = (gint)(*h * minratio);
3159 if (*h * maxratio < *w) {
3160 *h = (gint)(*w / maxratio);
3162 /* you cannot resize to nothing */
3165 *w = (gint)(*h * minratio);
3169 if (self->base_size.width >= 0 && self->base_size.height >= 0) {
3170 *w += self->base_size.width;
3171 *h += self->base_size.height;
3175 /* these override the above states! if you cant move you can't move! */
3177 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
3181 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
3182 *w = self->area.width;
3183 *h = self->area.height;
3191 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
3192 gboolean user, gboolean final, gboolean force_reply)
3194 Rect oldframe, oldclient;
3195 gboolean send_resize_client;
3196 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
3197 gboolean fmoved, fresized;
3198 guint fdecor = self->frame->decorations;
3199 gboolean fhorz = self->frame->max_horz;
3200 gboolean fvert = self->frame->max_vert;
3201 gint logicalw, logicalh;
3203 /* find the new x, y, width, and height (and logical size) */
3204 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
3206 /* set the logical size if things changed */
3207 if (!(w == self->area.width && h == self->area.height))
3208 SIZE_SET(self->logical_size, logicalw, logicalh);
3210 /* figure out if we moved or resized or what */
3211 moved = (x != self->area.x || y != self->area.y);
3212 resized = (w != self->area.width || h != self->area.height);
3214 oldframe = self->frame->area;
3215 oldclient = self->area;
3216 RECT_SET(self->area, x, y, w, h);
3218 /* for app-requested resizes, always resize if 'resized' is true.
3219 for user-requested ones, only resize if final is true, or when
3220 resizing in redraw mode */
3221 send_resize_client = ((!user && resized) ||
3223 (resized && config_resize_redraw))));
3225 /* if the client is enlarging, then resize the client before the frame */
3226 if (send_resize_client && (w > oldclient.width || h > oldclient.height)) {
3227 XMoveResizeWindow(obt_display, self->window,
3228 self->frame->size.left, self->frame->size.top,
3229 MAX(w, oldclient.width), MAX(h, oldclient.height));
3230 frame_adjust_client_area(self->frame);
3233 /* find the frame's dimensions and move/resize it */
3237 /* if decorations changed, then readjust everything for the frame */
3238 if (self->decorations != fdecor ||
3239 self->max_horz != fhorz || self->max_vert != fvert)
3241 fmoved = fresized = TRUE;
3244 /* adjust the frame */
3245 if (fmoved || fresized) {
3246 gulong ignore_start;
3248 ignore_start = event_start_ignore_all_enters();
3250 /* replay pending pointer event before move the window, in case it
3251 would change what window gets the event */
3252 mouse_replay_pointer();
3254 frame_adjust_area(self->frame, fmoved, fresized, FALSE);
3257 event_end_ignore_all_enters(ignore_start);
3260 if (!user || final) {
3261 gint oldrx = self->root_pos.x;
3262 gint oldry = self->root_pos.y;
3263 /* we have reset the client to 0 border width, so don't include
3264 it in these coords */
3265 POINT_SET(self->root_pos,
3266 self->frame->area.x + self->frame->size.left -
3268 self->frame->area.y + self->frame->size.top -
3269 self->border_width);
3270 if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
3274 /* This is kinda tricky and should not be changed.. let me explain!
3276 When user = FALSE, then the request is coming from the application
3277 itself, and we are more strict about when to send a synthetic
3278 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3279 in this case (or send one if force_reply is true)
3281 When user = TRUE, then the request is coming from "us", like when we
3282 maximize a window or something. In this case we are more lenient. We
3283 used to follow the same rules as above, but _Java_ Swing can't handle
3284 this. So just to appease Swing, when user = TRUE, we always send
3285 a synthetic ConfigureNotify to give the window its root coordinates.
3286 Lastly, if force_reply is TRUE, we always send a
3287 ConfigureNotify, which is needed during a resize with XSYNCronization.
3289 if ((!user && !resized && (rootmoved || force_reply)) ||
3290 (user && ((!resized && force_reply) || (final && rootmoved))))
3294 event.type = ConfigureNotify;
3295 event.xconfigure.display = obt_display;
3296 event.xconfigure.event = self->window;
3297 event.xconfigure.window = self->window;
3299 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3300 self->title, self->root_pos.x, self->root_pos.y, w, h);
3302 /* root window real coords */
3303 event.xconfigure.x = self->root_pos.x;
3304 event.xconfigure.y = self->root_pos.y;
3305 event.xconfigure.width = w;
3306 event.xconfigure.height = h;
3307 event.xconfigure.border_width = self->border_width;
3308 event.xconfigure.above = None;
3309 event.xconfigure.override_redirect = FALSE;
3310 XSendEvent(event.xconfigure.display, event.xconfigure.window,
3311 FALSE, StructureNotifyMask, &event);
3314 /* if the client is shrinking, then resize the frame before the client.
3316 both of these resize sections may run, because the top one only resizes
3317 in the direction that is growing
3319 if (send_resize_client && (w <= oldclient.width || h <= oldclient.height))
3321 frame_adjust_client_area(self->frame);
3322 XMoveResizeWindow(obt_display, self->window,
3323 self->frame->size.left, self->frame->size.top, w, h);
3326 XFlush(obt_display);
3328 /* if it moved between monitors, then this can affect the stacking
3329 layer of this window or others - for fullscreen windows.
3330 also if it changed to/from oldschool fullscreen then its layer may
3333 watch out tho, don't try change stacking stuff if the window is no
3334 longer being managed !
3336 if (self->managed &&
3337 (screen_find_monitor(&self->frame->area) !=
3338 screen_find_monitor(&oldframe) ||
3339 (final && (client_is_oldfullscreen(self, &oldclient) !=
3340 client_is_oldfullscreen(self, &self->area)))))
3342 client_calc_layer(self);
3346 void client_fullscreen(ObClient *self, gboolean fs)
3350 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
3351 self->fullscreen == fs) return; /* already done */
3353 self->fullscreen = fs;
3354 client_change_state(self); /* change the state hints on the client */
3357 self->pre_fullscreen_area = self->area;
3358 self->pre_fullscreen_max_horz = self->max_horz;
3359 self->pre_fullscreen_max_vert = self->max_vert;
3361 /* if the window is maximized, its area isn't all that meaningful.
3362 save its premax area instead. */
3363 if (self->max_horz) {
3364 self->pre_fullscreen_area.x = self->pre_max_area.x;
3365 self->pre_fullscreen_area.width = self->pre_max_area.width;
3367 if (self->max_vert) {
3368 self->pre_fullscreen_area.y = self->pre_max_area.y;
3369 self->pre_fullscreen_area.height = self->pre_max_area.height;
3372 /* these will help configure_full figure out where to fullscreen
3376 w = self->area.width;
3377 h = self->area.height;
3379 g_assert(self->pre_fullscreen_area.width > 0 &&
3380 self->pre_fullscreen_area.height > 0);
3382 self->max_horz = self->pre_fullscreen_max_horz;
3383 self->max_vert = self->pre_fullscreen_max_vert;
3384 if (self->max_horz) {
3385 self->pre_max_area.x = self->pre_fullscreen_area.x;
3386 self->pre_max_area.width = self->pre_fullscreen_area.width;
3388 if (self->max_vert) {
3389 self->pre_max_area.y = self->pre_fullscreen_area.y;
3390 self->pre_max_area.height = self->pre_fullscreen_area.height;
3393 x = self->pre_fullscreen_area.x;
3394 y = self->pre_fullscreen_area.y;
3395 w = self->pre_fullscreen_area.width;
3396 h = self->pre_fullscreen_area.height;
3397 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
3400 ob_debug("Window %s going fullscreen (%d)",
3401 self->title, self->fullscreen);
3404 /* make sure the window is on some monitor */
3405 client_find_onscreen(self, &x, &y, w, h, FALSE);
3408 client_setup_decor_and_functions(self, FALSE);
3409 client_move_resize(self, x, y, w, h);
3411 /* and adjust our layer/stacking. do this after resizing the window,
3412 and applying decorations, because windows which fill the screen are
3413 considered "fullscreen" and it affects their layer */
3414 client_calc_layer(self);
3417 /* try focus us when we go into fullscreen mode */
3422 static void client_iconify_recursive(ObClient *self,
3423 gboolean iconic, gboolean curdesk,
3424 gboolean hide_animation)
3427 gboolean changed = FALSE;
3429 if (self->iconic != iconic) {
3430 ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
3434 /* don't let non-normal windows iconify along with their parents
3436 if (client_normal(self)) {
3437 self->iconic = iconic;
3439 /* update the focus lists.. iconic windows go to the bottom of
3440 the list. this will also call focus_cycle_addremove(). */
3441 focus_order_to_bottom(self);
3446 self->iconic = iconic;
3448 if (curdesk && self->desktop != screen_desktop &&
3449 self->desktop != DESKTOP_ALL)
3450 client_set_desktop(self, screen_desktop, FALSE, FALSE);
3452 /* this puts it after the current focused window, this will
3453 also cause focus_cycle_addremove() to be called for the
3455 focus_order_like_new(self);
3462 client_change_state(self);
3463 if (config_animate_iconify && !hide_animation)
3464 frame_begin_iconify_animation(self->frame, iconic);
3465 /* do this after starting the animation so it doesn't flash */
3466 client_showhide(self);
3469 /* iconify all direct transients, and deiconify all transients
3471 for (it = self->transients; it; it = g_slist_next(it))
3472 if (it->data != self)
3473 if (client_is_direct_child(self, it->data) || !iconic)
3474 client_iconify_recursive(it->data, iconic, curdesk,
3478 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3479 gboolean hide_animation)
3481 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3482 /* move up the transient chain as far as possible first */
3483 self = client_search_top_direct_parent(self);
3484 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3488 void client_maximize(ObClient *self, gboolean max, gint dir)
3492 g_assert(dir == 0 || dir == 1 || dir == 2);
3493 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && max) return;/* can't */
3495 /* check if already done */
3497 if (dir == 0 && self->max_horz && self->max_vert) return;
3498 if (dir == 1 && self->max_horz) return;
3499 if (dir == 2 && self->max_vert) return;
3501 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3502 if (dir == 1 && !self->max_horz) return;
3503 if (dir == 2 && !self->max_vert) return;
3506 /* these will help configure_full figure out which screen to fill with
3510 w = self->area.width;
3511 h = self->area.height;
3514 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3515 RECT_SET(self->pre_max_area,
3516 self->area.x, self->pre_max_area.y,
3517 self->area.width, self->pre_max_area.height);
3519 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3520 RECT_SET(self->pre_max_area,
3521 self->pre_max_area.x, self->area.y,
3522 self->pre_max_area.width, self->area.height);
3525 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3526 g_assert(self->pre_max_area.width > 0);
3528 x = self->pre_max_area.x;
3529 w = self->pre_max_area.width;
3531 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3532 0, self->pre_max_area.height);
3534 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3535 g_assert(self->pre_max_area.height > 0);
3537 y = self->pre_max_area.y;
3538 h = self->pre_max_area.height;
3540 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3541 self->pre_max_area.width, 0);
3545 if (dir == 0 || dir == 1) /* horz */
3546 self->max_horz = max;
3547 if (dir == 0 || dir == 2) /* vert */
3548 self->max_vert = max;
3551 /* make sure the window is on some monitor */
3552 client_find_onscreen(self, &x, &y, w, h, FALSE);
3555 client_change_state(self); /* change the state hints on the client */
3557 client_setup_decor_and_functions(self, FALSE);
3558 client_move_resize(self, x, y, w, h);
3561 void client_shade(ObClient *self, gboolean shade)
3563 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3564 shade) || /* can't shade */
3565 self->shaded == shade) return; /* already done */
3567 self->shaded = shade;
3568 client_change_state(self);
3569 client_change_wm_state(self); /* the window is being hidden/shown */
3570 /* resize the frame to just the titlebar */
3571 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
3574 static void client_ping_event(ObClient *self, gboolean dead)
3576 if (self->not_responding != dead) {
3577 self->not_responding = dead;
3578 client_update_title(self);
3581 /* the client isn't responding, so ask to kill it */
3582 client_prompt_kill(self);
3584 /* it came back to life ! */
3586 if (self->kill_prompt) {
3587 prompt_unref(self->kill_prompt);
3588 self->kill_prompt = NULL;
3591 self->kill_level = 0;
3596 void client_close(ObClient *self)
3598 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3600 /* if closing an internal obprompt, that is just cancelling it */
3602 prompt_cancel(self->prompt);
3606 /* in the case that the client provides no means to requesting that it
3607 close, we just kill it */
3608 if (!self->delete_window)
3609 /* don't use client_kill(), we should only kill based on PID in
3610 response to a lack of PING replies */
3611 XKillClient(obt_display, self->window);
3613 /* request the client to close with WM_DELETE_WINDOW */
3614 OBT_PROP_MSG_TO(self->window, self->window, WM_PROTOCOLS,
3615 OBT_PROP_ATOM(WM_DELETE_WINDOW), event_time(),
3616 0, 0, 0, NoEventMask);
3618 /* we're trying to close the window, so see if it is responding. if it
3619 is not, then we will let them kill the window */
3621 ping_start(self, client_ping_event);
3623 /* if we already know the window isn't responding (maybe they clicked
3624 no in the kill dialog but it hasn't come back to life), then show
3626 if (self->not_responding)
3627 client_prompt_kill(self);
3631 #define OB_KILL_RESULT_NO 0
3632 #define OB_KILL_RESULT_YES 1
3634 static gboolean client_kill_requested(ObPrompt *p, gint result, gpointer data)
3636 ObClient *self = data;
3638 if (result == OB_KILL_RESULT_YES)
3640 return TRUE; /* call the cleanup func */
3643 static void client_kill_cleanup(ObPrompt *p, gpointer data)
3645 ObClient *self = data;
3647 g_assert(p == self->kill_prompt);
3649 prompt_unref(self->kill_prompt);
3650 self->kill_prompt = NULL;
3653 static void client_prompt_kill(ObClient *self)
3655 /* check if we're already prompting */
3656 if (!self->kill_prompt) {
3657 ObPromptAnswer answers[] = {
3658 { 0, OB_KILL_RESULT_NO },
3659 { 0, OB_KILL_RESULT_YES }
3662 const gchar *y, *title;
3664 title = self->original_title;
3665 if (title[0] == '\0') {
3666 /* empty string, so use its parent */
3667 ObClient *p = client_search_top_direct_parent(self);
3668 if (p) title = p->original_title;
3671 if (client_on_localhost(self)) {
3674 if (self->kill_level == 0)
3680 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3682 y = _("End Process");
3686 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3688 y = _("Disconnect");
3690 /* set the dialog buttons' text */
3691 answers[0].text = _("Cancel"); /* "no" */
3692 answers[1].text = y; /* "yes" */
3694 self->kill_prompt = prompt_new(m, NULL, answers,
3695 sizeof(answers)/sizeof(answers[0]),
3696 OB_KILL_RESULT_NO, /* default = no */
3697 OB_KILL_RESULT_NO, /* cancel = no */
3698 client_kill_requested,
3699 client_kill_cleanup,
3704 prompt_show(self->kill_prompt, self, TRUE);
3707 void client_kill(ObClient *self)
3709 /* don't kill our own windows */
3710 if (self->prompt) return;
3712 if (client_on_localhost(self) && self->pid) {
3713 /* running on the local host */
3714 if (self->kill_level == 0) {
3715 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3716 self->window, self->pid);
3717 kill(self->pid, SIGTERM);
3720 /* show that we're trying to kill it */
3721 client_update_title(self);
3724 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3725 self->window, self->pid);
3726 kill(self->pid, SIGKILL); /* kill -9 */
3730 /* running on a remote host */
3731 XKillClient(obt_display, self->window);
3735 void client_hilite(ObClient *self, gboolean hilite)
3737 if (self->demands_attention == hilite)
3738 return; /* no change */
3740 /* don't allow focused windows to hilite */
3741 self->demands_attention = hilite && !client_focused(self);
3742 if (self->frame != NULL) { /* if we're mapping, just set the state */
3743 if (self->demands_attention) {
3744 frame_flash_start(self->frame);
3746 /* if the window is on another desktop then raise it and make it
3747 the most recently used window */
3748 if (self->desktop != screen_desktop &&
3749 self->desktop != DESKTOP_ALL)
3751 stacking_raise(CLIENT_AS_WINDOW(self));
3752 focus_order_to_top(self);
3756 frame_flash_stop(self->frame);
3757 client_change_state(self);
3761 static void client_set_desktop_recursive(ObClient *self,
3769 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3771 ob_debug("Setting desktop %u", target+1);
3773 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3775 old = self->desktop;
3776 self->desktop = target;
3777 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, target);
3778 /* the frame can display the current desktop state */
3779 frame_adjust_state(self->frame);
3780 /* 'move' the window to the new desktop */
3784 /* raise if it was not already on the desktop */
3785 if (old != DESKTOP_ALL && !dontraise)
3786 stacking_raise(CLIENT_AS_WINDOW(self));
3787 if (STRUT_EXISTS(self->strut))
3788 screen_update_areas();
3790 /* the new desktop's geometry may be different, so we may need to
3791 resize, for example if we are maximized */
3792 client_reconfigure(self, FALSE);
3794 focus_cycle_addremove(self, FALSE);
3797 /* move all transients */
3798 for (it = self->transients; it; it = g_slist_next(it))
3799 if (it->data != self)
3800 if (client_is_direct_child(self, it->data))
3801 client_set_desktop_recursive(it->data, target,
3802 donthide, dontraise);
3805 void client_set_desktop(ObClient *self, guint target,
3806 gboolean donthide, gboolean dontraise)
3808 self = client_search_top_direct_parent(self);
3809 client_set_desktop_recursive(self, target, donthide, dontraise);
3811 focus_cycle_addremove(NULL, TRUE);
3814 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3816 while (child != parent && (child = client_direct_parent(child)));
3817 return child == parent;
3820 ObClient *client_search_modal_child(ObClient *self)
3825 for (it = self->transients; it; it = g_slist_next(it)) {
3826 ObClient *c = it->data;
3827 if ((ret = client_search_modal_child(c))) return ret;
3828 if (c->modal) return c;
3833 struct ObClientFindDestroyUnmap {
3838 static gboolean find_destroy_unmap(XEvent *e, gpointer data)
3840 struct ObClientFindDestroyUnmap *find = data;
3841 if (e->type == DestroyNotify)
3842 return e->xdestroywindow.window == find->window;
3843 if (e->type == UnmapNotify && e->xunmap.window == find->window)
3844 /* ignore the first $find->ignore_unmaps$ many unmap events */
3845 return --find->ignore_unmaps < 0;
3849 gboolean client_validate(ObClient *self)
3851 struct ObClientFindDestroyUnmap find;
3853 XSync(obt_display, FALSE); /* get all events on the server */
3855 find.window = self->window;
3856 find.ignore_unmaps = self->ignore_unmaps;
3857 if (xqueue_exists_local(find_destroy_unmap, &find))
3863 void client_set_wm_state(ObClient *self, glong state)
3865 if (state == self->wmstate) return; /* no change */
3869 client_iconify(self, TRUE, TRUE, FALSE);
3872 client_iconify(self, FALSE, TRUE, FALSE);
3877 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3879 gboolean shaded = self->shaded;
3880 gboolean fullscreen = self->fullscreen;
3881 gboolean undecorated = self->undecorated;
3882 gboolean locked = self->locked;
3883 gboolean max_horz = self->max_horz;
3884 gboolean max_vert = self->max_vert;
3885 gboolean modal = self->modal;
3886 gboolean iconic = self->iconic;
3887 gboolean demands_attention = self->demands_attention;
3888 gboolean above = self->above;
3889 gboolean below = self->below;
3893 if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) ||
3894 action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) ||
3895 action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)))
3896 /* an invalid action was passed to the client message, ignore it */
3899 for (i = 0; i < 2; ++i) {
3900 Atom state = i == 0 ? data1 : data2;
3902 if (!state) continue;
3904 /* if toggling, then pick whether we're adding or removing */
3905 if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) {
3906 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
3908 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
3909 value = self->max_vert;
3910 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
3911 value = self->max_horz;
3912 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
3914 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
3915 value = self->skip_taskbar;
3916 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
3917 value = self->skip_pager;
3918 else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
3919 value = self->iconic;
3920 else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
3922 else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
3923 value = self->above;
3924 else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
3925 value = self->below;
3926 else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
3927 value = self->demands_attention;
3928 else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
3929 value = undecorated;
3930 else if (state == OBT_PROP_ATOM(OB_WM_STATE_LOCKED))
3933 g_assert_not_reached();
3934 action = value ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3935 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3938 value = action == OBT_PROP_ATOM(NET_WM_STATE_ADD);
3939 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3941 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3943 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3945 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3947 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3948 self->skip_taskbar = value;
3949 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3950 self->skip_pager = value;
3951 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3953 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3955 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3957 /* only unset below when setting above, otherwise you can't get to
3961 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3962 /* and vice versa */
3966 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3967 demands_attention = value;
3968 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3969 undecorated = value;
3970 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_LOCKED)) {
3975 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3976 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3978 if (max_horz == max_vert) { /* both going the same way */
3979 client_maximize(self, max_horz, 0);
3981 client_maximize(self, max_horz, 1);
3982 client_maximize(self, max_vert, 2);
3986 if (max_horz != self->max_horz)
3987 client_maximize(self, max_horz, 1);
3989 client_maximize(self, max_vert, 2);
3992 /* change fullscreen state before shading, as it will affect if the window
3994 if (fullscreen != self->fullscreen)
3995 client_fullscreen(self, fullscreen);
3996 if (shaded != self->shaded)
3997 client_shade(self, shaded);
3998 if (undecorated != self->undecorated)
3999 client_set_undecorated(self, undecorated);
4000 if (locked != self->locked)
4001 client_set_locked(self, locked);
4002 if (above != self->above || below != self->below) {
4003 self->above = above;
4004 self->below = below;
4005 client_calc_layer(self);
4008 if (modal != self->modal) {
4009 self->modal = modal;
4010 /* when a window changes modality, then its stacking order with its
4011 transients needs to change */
4012 stacking_raise(CLIENT_AS_WINDOW(self));
4014 /* it also may get focused. if something is focused that shouldn't
4015 be focused anymore, then move the focus */
4016 if (focus_client && client_focus_target(focus_client) != focus_client)
4017 client_focus(focus_client);
4020 if (iconic != self->iconic)
4021 client_iconify(self, iconic, FALSE, FALSE);
4023 if (demands_attention != self->demands_attention)
4024 client_hilite(self, demands_attention);
4026 client_change_state(self); /* change the hint to reflect these changes */
4028 focus_cycle_addremove(self, TRUE);
4031 ObClient *client_focus_target(ObClient *self)
4033 ObClient *child = NULL;
4035 child = client_search_modal_child(self);
4036 if (child) return child;
4040 gboolean client_can_focus(ObClient *self)
4042 /* choose the correct target */
4043 self = client_focus_target(self);
4045 if (!self->frame->visible)
4048 if (!(self->can_focus || self->focus_notify))
4054 gboolean client_focus(ObClient *self)
4056 if (!client_validate(self)) return FALSE;
4060 XkbGetState(obt_display, XkbUseCoreKbd, &state);
4061 if (state.locked_mods & 128)
4065 /* we might not focus this window, so if we have modal children which would
4066 be focused instead, bring them to this desktop */
4067 client_bring_modal_windows(self);
4069 /* choose the correct target */
4070 self = client_focus_target(self);
4072 if (!client_can_focus(self)) {
4073 ob_debug_type(OB_DEBUG_FOCUS,
4074 "Client %s can't be focused", self->title);
4078 /* if we have helper windows they should be there with the window */
4079 client_bring_helper_windows(self);
4081 ob_debug_type(OB_DEBUG_FOCUS,
4082 "Focusing client \"%s\" (0x%x) at time %u",
4083 self->title, self->window, event_time());
4085 /* if using focus_delay, stop the timer now so that focus doesn't
4087 event_halt_focus_delay();
4089 obt_display_ignore_errors(TRUE);
4091 if (self->can_focus) {
4092 /* This can cause a BadMatch error with CurrentTime, or if an app
4093 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
4094 XSetInputFocus(obt_display, self->window, RevertToPointerRoot,
4098 if (self->focus_notify) {
4100 ce.xclient.type = ClientMessage;
4101 ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
4102 ce.xclient.display = obt_display;
4103 ce.xclient.window = self->window;
4104 ce.xclient.format = 32;
4105 ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS);
4106 ce.xclient.data.l[1] = event_time();
4107 ce.xclient.data.l[2] = 0l;
4108 ce.xclient.data.l[3] = 0l;
4109 ce.xclient.data.l[4] = 0l;
4110 XSendEvent(obt_display, self->window, FALSE, NoEventMask, &ce);
4113 obt_display_ignore_errors(FALSE);
4115 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d",
4116 obt_display_error_occured);
4117 return !obt_display_error_occured;
4120 static void client_present(ObClient *self, gboolean here, gboolean raise,
4123 if (client_normal(self) && screen_showing_desktop())
4124 screen_show_desktop(FALSE, self);
4126 client_iconify(self, FALSE, here, FALSE);
4127 if (self->desktop != DESKTOP_ALL &&
4128 self->desktop != screen_desktop)
4131 client_set_desktop(self, screen_desktop, FALSE, TRUE);
4133 screen_set_desktop(self->desktop, FALSE);
4134 } else if (!self->frame->visible)
4135 /* if its not visible for other reasons, then don't mess
4138 if (self->shaded && unshade)
4139 client_shade(self, FALSE);
4141 stacking_raise(CLIENT_AS_WINDOW(self));
4146 /* this function exists to map to the net_active_window message in the ewmh */
4147 void client_activate(ObClient *self, gboolean desktop,
4148 gboolean here, gboolean raise,
4149 gboolean unshade, gboolean user)
4151 self = client_focus_target(self);
4153 if (client_can_steal_focus(self, desktop, user, event_time(), CurrentTime))
4154 client_present(self, here, raise, unshade);
4156 client_hilite(self, TRUE);
4159 static void client_bring_windows_recursive(ObClient *self,
4167 for (it = self->transients; it; it = g_slist_next(it))
4168 client_bring_windows_recursive(it->data, desktop,
4169 helpers, modals, iconic);
4171 if (((helpers && client_helper(self)) ||
4172 (modals && self->modal)) &&
4173 (!screen_compare_desktops(self->desktop, desktop) ||
4174 (iconic && self->iconic)))
4176 if (iconic && self->iconic)
4177 client_iconify(self, FALSE, TRUE, FALSE);
4179 client_set_desktop(self, desktop, FALSE, FALSE);
4183 void client_bring_helper_windows(ObClient *self)
4185 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE, FALSE);
4188 void client_bring_modal_windows(ObClient *self)
4190 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE, TRUE);
4193 gboolean client_focused(ObClient *self)
4195 return self == focus_client;
4198 RrImage* client_icon(ObClient *self)
4200 RrImage *ret = NULL;
4203 ret = self->icon_set;
4204 else if (self->parents) {
4206 for (it = self->parents; it && !ret; it = g_slist_next(it))
4207 ret = client_icon(it->data);
4210 ret = client_default_icon;
4214 void client_set_layer(ObClient *self, gint layer)
4218 self->above = FALSE;
4219 } else if (layer == 0) {
4220 self->below = self->above = FALSE;
4222 self->below = FALSE;
4225 client_calc_layer(self);
4226 client_change_state(self); /* reflect this in the state hints */
4229 void client_set_locked(ObClient *self, gboolean locked)
4231 if (self->locked != locked) {
4232 self->locked = locked;
4233 client_change_state(self);
4237 void client_set_undecorated(ObClient *self, gboolean undecorated)
4239 if (self->undecorated != undecorated &&
4240 /* don't let it undecorate if the function is missing, but let
4242 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
4244 self->undecorated = undecorated;
4245 client_setup_decor_and_functions(self, TRUE);
4246 client_change_state(self); /* reflect this in the state hints */
4250 guint client_monitor(ObClient *self)
4252 return screen_find_monitor(&self->frame->area);
4255 ObClient *client_direct_parent(ObClient *self)
4257 if (!self->parents) return NULL;
4258 if (self->transient_for_group) return NULL;
4259 return self->parents->data;
4262 ObClient *client_search_top_direct_parent(ObClient *self)
4265 while ((p = client_direct_parent(self))) self = p;
4269 static GSList *client_search_all_top_parents_internal(ObClient *self,
4271 ObStackingLayer layer)
4276 /* move up the direct transient chain as far as possible */
4277 while ((p = client_direct_parent(self)) &&
4278 (!bylayer || p->layer == layer))
4282 ret = g_slist_prepend(NULL, self);
4284 ret = g_slist_copy(self->parents);
4289 GSList *client_search_all_top_parents(ObClient *self)
4291 return client_search_all_top_parents_internal(self, FALSE, 0);
4294 GSList *client_search_all_top_parents_layer(ObClient *self)
4296 return client_search_all_top_parents_internal(self, TRUE, self->layer);
4299 ObClient *client_search_focus_parent(ObClient *self)
4303 for (it = self->parents; it; it = g_slist_next(it))
4304 if (client_focused(it->data)) return it->data;
4309 ObClient *client_search_focus_parent_full(ObClient *self)
4312 ObClient *ret = NULL;
4314 for (it = self->parents; it; it = g_slist_next(it)) {
4315 if (client_focused(it->data))
4318 ret = client_search_focus_parent_full(it->data);
4324 ObClient *client_search_parent(ObClient *self, ObClient *search)
4328 for (it = self->parents; it; it = g_slist_next(it))
4329 if (it->data == search) return search;
4334 ObClient *client_search_transient(ObClient *self, ObClient *search)
4338 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
4339 if (sit->data == search)
4341 if (client_search_transient(sit->data, search))
4347 static void detect_edge(Rect area, ObDirection dir,
4348 gint my_head, gint my_size,
4349 gint my_edge_start, gint my_edge_size,
4350 gint *dest, gboolean *near_edge)
4352 gint edge_start, edge_size, head, tail;
4353 gboolean skip_head = FALSE, skip_tail = FALSE;
4356 case OB_DIRECTION_NORTH:
4357 case OB_DIRECTION_SOUTH:
4358 edge_start = area.x;
4359 edge_size = area.width;
4361 case OB_DIRECTION_EAST:
4362 case OB_DIRECTION_WEST:
4363 edge_start = area.y;
4364 edge_size = area.height;
4367 g_assert_not_reached();
4370 /* do we collide with this window? */
4371 if (!RANGES_INTERSECT(my_edge_start, my_edge_size,
4372 edge_start, edge_size))
4376 case OB_DIRECTION_NORTH:
4377 head = RECT_BOTTOM(area);
4378 tail = RECT_TOP(area);
4380 case OB_DIRECTION_SOUTH:
4381 head = RECT_TOP(area);
4382 tail = RECT_BOTTOM(area);
4384 case OB_DIRECTION_WEST:
4385 head = RECT_RIGHT(area);
4386 tail = RECT_LEFT(area);
4388 case OB_DIRECTION_EAST:
4389 head = RECT_LEFT(area);
4390 tail = RECT_RIGHT(area);
4393 g_assert_not_reached();
4396 case OB_DIRECTION_NORTH:
4397 case OB_DIRECTION_WEST:
4398 /* check if our window is past the head of this window */
4399 if (my_head <= head + 1)
4401 /* check if our window's tail is past the tail of this window */
4402 if (my_head + my_size - 1 <= tail)
4404 /* check if the head of this window is closer than the previously
4405 chosen edge (take into account that the previously chosen
4406 edge might have been a tail, not a head) */
4407 if (head + (*near_edge ? 0 : my_size) <= *dest)
4409 /* check if the tail of this window is closer than the previously
4410 chosen edge (take into account that the previously chosen
4411 edge might have been a head, not a tail) */
4412 if (tail - (!*near_edge ? 0 : my_size) <= *dest)
4415 case OB_DIRECTION_SOUTH:
4416 case OB_DIRECTION_EAST:
4417 /* check if our window is past the head of this window */
4418 if (my_head >= head - 1)
4420 /* check if our window's tail is past the tail of this window */
4421 if (my_head - my_size + 1 >= tail)
4423 /* check if the head of this window is closer than the previously
4424 chosen edge (take into account that the previously chosen
4425 edge might have been a tail, not a head) */
4426 if (head - (*near_edge ? 0 : my_size) >= *dest)
4428 /* check if the tail of this window is closer than the previously
4429 chosen edge (take into account that the previously chosen
4430 edge might have been a head, not a tail) */
4431 if (tail + (!*near_edge ? 0 : my_size) >= *dest)
4435 g_assert_not_reached();
4438 ob_debug("my head %d size %d", my_head, my_size);
4439 ob_debug("head %d tail %d dest %d", head, tail, *dest);
4441 ob_debug("using near edge %d", head);
4445 else if (!skip_tail) {
4446 ob_debug("using far edge %d", tail);
4452 void client_find_edge_directional(ObClient *self, ObDirection dir,
4453 gint my_head, gint my_size,
4454 gint my_edge_start, gint my_edge_size,
4455 gint *dest, gboolean *near_edge)
4463 a = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS,
4464 &self->frame->area);
4467 case OB_DIRECTION_NORTH:
4468 edge = RECT_TOP(*a) - 1;
4470 case OB_DIRECTION_SOUTH:
4471 edge = RECT_BOTTOM(*a) + 1;
4473 case OB_DIRECTION_EAST:
4474 edge = RECT_RIGHT(*a) + 1;
4476 case OB_DIRECTION_WEST:
4477 edge = RECT_LEFT(*a) - 1;
4480 g_assert_not_reached();
4482 /* default to the far edge, then narrow it down */
4486 /* search for edges of monitors */
4487 for (i = 0; i < screen_num_monitors; ++i) {
4488 Rect *area = screen_area(self->desktop, i, NULL);
4489 detect_edge(*area, dir, my_head, my_size, my_edge_start,
4490 my_edge_size, dest, near_edge);
4491 g_slice_free(Rect, area);
4494 /* search for edges of clients */
4495 for (it = client_list; it; it = g_list_next(it)) {
4496 ObClient *cur = it->data;
4498 /* skip windows to not bump into */
4503 if (self->desktop != cur->desktop && cur->desktop != DESKTOP_ALL &&
4504 cur->desktop != screen_desktop)
4507 ob_debug("trying window %s", cur->title);
4509 detect_edge(cur->frame->area, dir, my_head, my_size, my_edge_start,
4510 my_edge_size, dest, near_edge);
4512 dock_get_area(&dock_area);
4513 detect_edge(dock_area, dir, my_head, my_size, my_edge_start,
4514 my_edge_size, dest, near_edge);
4516 g_slice_free(Rect, a);
4519 void client_find_move_directional(ObClient *self, ObDirection dir,
4523 gint e, e_start, e_size;
4527 case OB_DIRECTION_EAST:
4528 head = RECT_RIGHT(self->frame->area);
4529 size = self->frame->area.width;
4530 e_start = RECT_TOP(self->frame->area);
4531 e_size = self->frame->area.height;
4533 case OB_DIRECTION_WEST:
4534 head = RECT_LEFT(self->frame->area);
4535 size = self->frame->area.width;
4536 e_start = RECT_TOP(self->frame->area);
4537 e_size = self->frame->area.height;
4539 case OB_DIRECTION_NORTH:
4540 head = RECT_TOP(self->frame->area);
4541 size = self->frame->area.height;
4542 e_start = RECT_LEFT(self->frame->area);
4543 e_size = self->frame->area.width;
4545 case OB_DIRECTION_SOUTH:
4546 head = RECT_BOTTOM(self->frame->area);
4547 size = self->frame->area.height;
4548 e_start = RECT_LEFT(self->frame->area);
4549 e_size = self->frame->area.width;
4552 g_assert_not_reached();
4555 client_find_edge_directional(self, dir, head, size,
4556 e_start, e_size, &e, &near);
4557 *x = self->frame->area.x;
4558 *y = self->frame->area.y;
4560 case OB_DIRECTION_EAST:
4561 if (near) e -= self->frame->area.width;
4565 case OB_DIRECTION_WEST:
4567 else e -= self->frame->area.width;
4570 case OB_DIRECTION_NORTH:
4572 else e -= self->frame->area.height;
4575 case OB_DIRECTION_SOUTH:
4576 if (near) e -= self->frame->area.height;
4581 g_assert_not_reached();
4583 frame_frame_gravity(self->frame, x, y);
4586 void client_find_resize_directional(ObClient *self,
4588 ObClientDirectionalResizeType resize_type,
4589 gint *x, gint *y, gint *w, gint *h)
4592 gint e, e_start, e_size, delta;
4597 switch (resize_type) {
4598 case CLIENT_RESIZE_GROW:
4601 case CLIENT_RESIZE_GROW_IF_NOT_ON_EDGE:
4604 case CLIENT_RESIZE_SHRINK:
4610 case OB_DIRECTION_EAST:
4611 head = RECT_RIGHT(self->frame->area);
4612 switch (resize_type) {
4613 case CLIENT_RESIZE_GROW:
4614 head += self->size_inc.width - 1;
4616 case CLIENT_RESIZE_GROW_IF_NOT_ON_EDGE:
4619 case CLIENT_RESIZE_SHRINK:
4623 e_start = RECT_TOP(self->frame->area);
4624 e_size = self->frame->area.height;
4625 dir = grow ? OB_DIRECTION_EAST : OB_DIRECTION_WEST;
4627 case OB_DIRECTION_WEST:
4628 head = RECT_LEFT(self->frame->area);
4629 switch (resize_type) {
4630 case CLIENT_RESIZE_GROW:
4631 head -= self->size_inc.width - 1;
4633 case CLIENT_RESIZE_GROW_IF_NOT_ON_EDGE:
4636 case CLIENT_RESIZE_SHRINK:
4640 e_start = RECT_TOP(self->frame->area);
4641 e_size = self->frame->area.height;
4642 dir = grow ? OB_DIRECTION_WEST : OB_DIRECTION_EAST;
4644 case OB_DIRECTION_NORTH:
4645 head = RECT_TOP(self->frame->area);
4646 switch (resize_type) {
4647 case CLIENT_RESIZE_GROW:
4648 head -= self->size_inc.height - 1;
4650 case CLIENT_RESIZE_GROW_IF_NOT_ON_EDGE:
4653 case CLIENT_RESIZE_SHRINK:
4657 e_start = RECT_LEFT(self->frame->area);
4658 e_size = self->frame->area.width;
4659 dir = grow ? OB_DIRECTION_NORTH : OB_DIRECTION_SOUTH;
4661 case OB_DIRECTION_SOUTH:
4662 head = RECT_BOTTOM(self->frame->area);
4663 switch (resize_type) {
4664 case CLIENT_RESIZE_GROW:
4665 head += self->size_inc.height - 1;
4667 case CLIENT_RESIZE_GROW_IF_NOT_ON_EDGE:
4670 case CLIENT_RESIZE_SHRINK:
4674 e_start = RECT_LEFT(self->frame->area);
4675 e_size = self->frame->area.width;
4676 dir = grow ? OB_DIRECTION_SOUTH : OB_DIRECTION_NORTH;
4679 g_assert_not_reached();
4682 ob_debug("head %d dir %d", head, dir);
4683 client_find_edge_directional(self, dir, head, 1,
4684 e_start, e_size, &e, &near);
4685 ob_debug("edge %d", e);
4686 *x = self->frame->area.x;
4687 *y = self->frame->area.y;
4688 *w = self->frame->area.width;
4689 *h = self->frame->area.height;
4691 case OB_DIRECTION_EAST:
4692 if (grow == near) --e;
4693 delta = e - RECT_RIGHT(self->frame->area);
4696 case OB_DIRECTION_WEST:
4697 if (grow == near) ++e;
4698 delta = RECT_LEFT(self->frame->area) - e;
4702 case OB_DIRECTION_NORTH:
4703 if (grow == near) ++e;
4704 delta = RECT_TOP(self->frame->area) - e;
4708 case OB_DIRECTION_SOUTH:
4709 if (grow == near) --e;
4710 delta = e - RECT_BOTTOM(self->frame->area);
4714 g_assert_not_reached();
4716 frame_frame_gravity(self->frame, x, y);
4717 *w -= self->frame->size.left + self->frame->size.right;
4718 *h -= self->frame->size.top + self->frame->size.bottom;
4721 ObClient* client_under_pointer(void)
4725 ObClient *ret = NULL;
4727 if (screen_pointer_pos(&x, &y)) {
4728 for (it = stacking_list; it; it = g_list_next(it)) {
4729 if (WINDOW_IS_CLIENT(it->data)) {
4730 ObClient *c = WINDOW_AS_CLIENT(it->data);
4731 if (c->frame->visible &&
4732 /* check the desktop, this is done during desktop
4733 switching and windows are shown/hidden status is not
4735 (c->desktop == screen_desktop ||
4736 c->desktop == DESKTOP_ALL) &&
4737 /* ignore all animating windows */
4738 !frame_iconify_animating(c->frame) &&
4739 RECT_CONTAINS(c->frame->area, x, y))
4750 gboolean client_has_group_siblings(ObClient *self)
4752 return self->group && self->group->members->next;
4755 gboolean client_has_relative(ObClient *self)
4757 return client_has_parent(self) ||
4758 client_has_group_siblings(self) ||
4759 client_has_children(self);
4762 /*! Returns TRUE if the client is running on the same machine as Openbox */
4763 gboolean client_on_localhost(ObClient *self)
4765 return self->client_machine == NULL;