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);
116 void client_startup(gboolean reconfig)
118 client_default_icon = RrImageNewFromData(
119 ob_rr_icons, ob_rr_theme->def_win_icon,
120 ob_rr_theme->def_win_icon_w, ob_rr_theme->def_win_icon_h);
122 if (reconfig) return;
127 void client_shutdown(gboolean reconfig)
129 RrImageUnref(client_default_icon);
130 client_default_icon = NULL;
132 if (reconfig) return;
135 static void client_call_notifies(ObClient *self, GSList *list)
139 for (it = list; it; it = g_slist_next(it)) {
140 ClientCallback *d = it->data;
141 d->func(self, d->data);
145 void client_add_destroy_notify(ObClientCallback func, gpointer data)
147 ClientCallback *d = g_slice_new(ClientCallback);
150 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
153 void client_remove_destroy_notify(ObClientCallback func)
157 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
158 ClientCallback *d = it->data;
159 if (d->func == func) {
160 g_slice_free(ClientCallback, d);
161 client_destroy_notifies =
162 g_slist_delete_link(client_destroy_notifies, it);
168 void client_set_list(void)
170 Window *windows, *win_it;
172 guint size = g_list_length(client_list);
174 /* create an array of the window ids */
176 windows = g_new(Window, size);
178 for (it = client_list; it; it = g_list_next(it), ++win_it)
179 *win_it = ((ObClient*)it->data)->window;
183 OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW,
184 (gulong*)windows, size);
192 void client_manage(Window window, ObPrompt *prompt)
195 XSetWindowAttributes attrib_set;
196 gboolean try_activate = FALSE;
197 gboolean do_activate;
198 ObAppSettings *settings;
199 gboolean transient = FALSE;
205 ob_debug("Managing window: 0x%lx", window);
207 /* choose the events we want to receive on the CLIENT window
208 (ObPrompt windows can request events too) */
209 attrib_set.event_mask = CLIENT_EVENTMASK |
210 (prompt ? prompt->event_mask : 0);
211 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
212 XChangeWindowAttributes(obt_display, window,
213 CWEventMask|CWDontPropagate, &attrib_set);
215 /* create the ObClient struct, and populate it from the hints on the
217 self = g_slice_new0(ObClient);
218 self->obwin.type = OB_WINDOW_CLASS_CLIENT;
219 self->window = window;
220 self->prompt = prompt;
221 self->managed = TRUE;
223 /* non-zero defaults */
224 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
225 self->gravity = NorthWestGravity;
226 self->desktop = screen_num_desktops; /* always an invalid value */
228 /* get all the stuff off the window */
229 client_get_all(self, TRUE);
231 ob_debug("Window type: %d", self->type);
232 ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
233 ob_debug("Window name: %s class: %s role: %s title: %s",
234 self->name, self->class, self->role, self->title);
236 /* per-app settings override stuff from client_get_all, and return the
237 settings for other uses too. the returned settings is a shallow copy,
238 that needs to be freed with g_free(). */
239 settings = client_get_settings_state(self);
241 /* specify that if we exit, the window should not be destroyed and
242 should be reparented back to root automatically, unless we are managing
243 an internal ObPrompt window */
245 XChangeSaveSet(obt_display, window, SetModeInsert);
247 /* create the decoration frame for the client window */
248 self->frame = frame_new(self);
250 frame_grab_client(self->frame);
252 /* we've grabbed everything and set everything that we need to at mapping
256 /* the session should get the last say though */
257 client_restore_session_state(self);
259 /* tell startup notification that this app started */
260 launch_time = sn_app_started(self->startup_id, self->class, self->name);
262 if (!OBT_PROP_GET32(self->window, NET_WM_USER_TIME, CARDINAL, &user_time))
263 user_time = event_time();
265 /* do this after we have a frame.. it uses the frame to help determine the
266 WM_STATE to apply. */
267 client_change_state(self);
269 /* add ourselves to the focus order */
270 focus_order_add_new(self);
272 /* do this to add ourselves to the stacking list in a non-intrusive way */
273 client_calc_layer(self);
275 /* focus the new window? */
276 if (ob_state() != OB_STATE_STARTING &&
277 (!self->session || self->session->focused) &&
278 /* this means focus=true for window is same as config_focus_new=true */
279 ((config_focus_new || settings->focus == 1) ||
280 client_search_focus_tree_full(self)) &&
281 /* NET_WM_USER_TIME 0 when mapping means don't focus */
283 /* this checks for focus=false for the window */
284 settings->focus != 0 &&
285 focus_valid_target(self, self->desktop,
286 FALSE, FALSE, TRUE, TRUE, FALSE, FALSE,
287 settings->focus == 1))
292 /* remove the client's border */
293 XSetWindowBorderWidth(obt_display, self->window, 0);
295 /* adjust the frame to the client's size before showing or placing
297 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
298 frame_adjust_client_area(self->frame);
300 /* where the frame was placed is where the window was originally */
303 ob_debug("Going to try activate new window? %s",
304 try_activate ? "yes" : "no");
306 do_activate = client_can_steal_focus(
307 self, settings->focus == 1,
308 (!!launch_time || settings->focus == 1),
309 event_time(), launch_time);
313 /* figure out placement for the window if the window is new */
314 if (ob_state() == OB_STATE_RUNNING) {
315 ob_debug("Positioned: %s @ %d %d",
316 (!self->positioned ? "no" :
317 (self->positioned == PPosition ? "program specified" :
318 (self->positioned == USPosition ? "user specified" :
319 (self->positioned == (PPosition | USPosition) ?
320 "program + user specified" :
321 "BADNESS !?")))), place.x, place.y);
323 ob_debug("Sized: %s @ %d %d",
324 (!self->sized ? "no" :
325 (self->sized == PSize ? "program specified" :
326 (self->sized == USSize ? "user specified" :
327 (self->sized == (PSize | USSize) ?
328 "program + user specified" :
329 "BADNESS !?")))), place.width, place.height);
331 obplaced = place_client(self, do_activate, &place.x, &place.y,
334 /* watch for buggy apps that ask to be placed at (0,0) when there is
336 if (!obplaced && place.x == 0 && place.y == 0 &&
337 /* non-normal windows are allowed */
338 client_normal(self) &&
339 /* oldschool fullscreen windows are allowed */
340 !client_is_oldfullscreen(self, &place))
344 r = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS, NULL);
348 ob_debug("Moving buggy app from (0,0) to (%d,%d)", r->x, r->y);
350 g_slice_free(Rect, r);
353 /* make sure the window is visible. */
354 client_find_onscreen(self, &place.x, &place.y,
355 place.width, place.height,
356 /* non-normal clients has less rules, and
357 windows that are being restored from a
358 session do also. we can assume you want
359 it back where you saved it. Clients saying
360 they placed themselves are subjected to
361 harder rules, ones that are placed by
362 place.c or by the user are allowed partially
363 off-screen and on xinerama divides (ie,
364 it is up to the placement routines to avoid
365 the xinerama divides)
367 children and splash screens are forced on
368 screen, but i don't remember why i decided to
371 ob_state() == OB_STATE_RUNNING &&
372 (self->type == OB_CLIENT_TYPE_DIALOG ||
373 self->type == OB_CLIENT_TYPE_SPLASH ||
374 (!((self->positioned & USPosition) ||
375 settings->pos_given) &&
376 client_normal(self) &&
378 /* don't move oldschool fullscreen windows to
379 fit inside the struts (fixes Acroread, which
380 makes its fullscreen window fit the screen
381 but it is not USSize'd or USPosition'd) */
382 !client_is_oldfullscreen(self, &place))));
385 /* if the window isn't user-sized, then make it fit inside
386 the visible screen area on its monitor. Use basically the same rules
387 for forcing the window on screen in the client_find_onscreen call.
389 do this after place_client, it chooses the monitor!
391 splash screens get "transient" set to TRUE by
392 the place_client call
394 if (ob_state() == OB_STATE_RUNNING &&
396 (!(self->sized & USSize || self->positioned & USPosition) &&
397 client_normal(self) &&
399 /* don't shrink oldschool fullscreen windows to fit inside the
400 struts (fixes Acroread, which makes its fullscreen window
401 fit the screen but it is not USSize'd or USPosition'd) */
402 !client_is_oldfullscreen(self, &place))))
404 Rect *a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &place);
406 /* get the size of the frame */
407 place.width += self->frame->size.left + self->frame->size.right;
408 place.height += self->frame->size.top + self->frame->size.bottom;
410 /* fit the window inside the area */
411 place.width = MIN(place.width, a->width);
412 place.height = MIN(place.height, a->height);
414 ob_debug("setting window size to %dx%d", place.width, place.height);
416 /* get the size of the client back */
417 place.width -= self->frame->size.left + self->frame->size.right;
418 place.height -= self->frame->size.top + self->frame->size.bottom;
420 g_slice_free(Rect, a);
423 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
424 "some restrictions may apply",
425 self->window, place.x, place.y, place.width, place.height);
427 ob_debug(" but session requested %d, %d %d x %d instead, "
429 self->session->x, self->session->y,
430 self->session->w, self->session->h);
432 /* do this after the window is placed, so the premax/prefullscreen numbers
435 this also places the window
437 client_apply_startup_state(self, place.x, place.y,
438 place.width, place.height);
440 /* set the initial value of the desktop hint, when one wasn't requested
442 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
444 /* grab mouse bindings before showing the window */
445 mouse_grab_for_client(self, TRUE);
447 /* this has to happen before we try focus the window, but we want it to
448 happen after the client's stacking has been determined or it looks bad
452 if (!config_focus_under_mouse)
453 ignore_start = event_start_ignore_all_enters();
457 if (!config_focus_under_mouse)
458 event_end_ignore_all_enters(ignore_start);
461 /* activate/hilight/raise the window */
464 gboolean stacked = client_restore_session_stacking(self);
465 client_present(self, FALSE, !stacked, TRUE);
468 /* if the client isn't stealing focus, then hilite it so the user
469 knows it is there, but don't do this if we're restoring from a
471 if (!client_restore_session_stacking(self))
472 client_hilite(self, TRUE);
476 /* This may look rather odd. Well it's because new windows are added
477 to the stacking order non-intrusively. If we're not going to focus
478 the new window or hilite it, then we raise it to the top. This will
479 take affect for things that don't get focused like splash screens.
480 Also if you don't have focus_new enabled, then it's going to get
481 raised to the top. Legacy begets legacy I guess?
483 if (!client_restore_session_stacking(self))
484 stacking_raise(CLIENT_AS_WINDOW(self));
487 /* add to client list/map */
488 client_list = g_list_append(client_list, self);
489 window_add(&self->window, CLIENT_AS_WINDOW(self));
491 /* this has to happen after we're in the client_list */
492 if (STRUT_EXISTS(self->strut))
493 screen_update_areas();
495 /* update the list hints */
498 /* free the ObAppSettings shallow copy */
499 g_slice_free(ObAppSettings, settings);
501 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
502 window, self->frame->window, self->class);
505 ObClient *client_fake_manage(Window window)
508 ObAppSettings *settings;
510 ob_debug("Pretend-managing window: %lx", window);
512 /* do this minimal stuff to figure out the client's decorations */
514 self = g_slice_new0(ObClient);
515 self->window = window;
517 client_get_all(self, FALSE);
518 /* per-app settings override stuff, and return the settings for other
519 uses too. this returns a shallow copy that needs to be freed */
520 settings = client_get_settings_state(self);
522 /* create the decoration frame for the client window and adjust its size */
523 self->frame = frame_new(self);
525 client_apply_startup_state(self, self->area.x, self->area.y,
526 self->area.width, self->area.height);
528 ob_debug("gave extents left %d right %d top %d bottom %d",
529 self->frame->size.left, self->frame->size.right,
530 self->frame->size.top, self->frame->size.bottom);
532 /* free the ObAppSettings shallow copy */
533 g_slice_free(ObAppSettings, settings);
538 void client_unmanage_all(void)
541 client_unmanage(client_list->data);
544 void client_unmanage(ObClient *self)
549 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
550 self->window, self->frame->window,
551 self->class, self->title ? self->title : "");
553 g_assert(self != NULL);
555 /* we dont want events no more. do this before hiding the frame so we
556 don't generate more events */
557 XSelectInput(obt_display, self->window, NoEventMask);
559 /* ignore enter events from the unmap so it doesnt mess with the focus */
560 if (!config_focus_under_mouse)
561 ignore_start = event_start_ignore_all_enters();
563 frame_hide(self->frame);
564 /* flush to send the hide to the server quickly */
567 if (!config_focus_under_mouse)
568 event_end_ignore_all_enters(ignore_start);
570 mouse_grab_for_client(self, FALSE);
572 self->managed = FALSE;
574 /* remove the window from our save set, unless we are managing an internal
577 XChangeSaveSet(obt_display, self->window, SetModeDelete);
579 /* update the focus lists */
580 focus_order_remove(self);
581 if (client_focused(self)) {
582 /* don't leave an invalid focus_client */
586 /* if we're prompting to kill the client, close that */
587 prompt_unref(self->kill_prompt);
588 self->kill_prompt = NULL;
590 client_list = g_list_remove(client_list, self);
591 stacking_remove(self);
592 window_remove(self->window);
594 /* once the client is out of the list, update the struts to remove its
596 if (STRUT_EXISTS(self->strut))
597 screen_update_areas();
599 client_call_notifies(self, client_destroy_notifies);
601 /* tell our parent(s) that we're gone */
602 for (it = self->parents; it; it = g_slist_next(it))
603 ((ObClient*)it->data)->transients =
604 g_slist_remove(((ObClient*)it->data)->transients,self);
606 /* tell our transients that we're gone */
607 for (it = self->transients; it; it = g_slist_next(it)) {
608 ((ObClient*)it->data)->parents =
609 g_slist_remove(((ObClient*)it->data)->parents, self);
610 /* we could be keeping our children in a higher layer */
611 client_calc_layer(it->data);
614 /* remove from its group */
616 group_remove(self->group, self);
620 /* restore the window's original geometry so it is not lost */
626 if (self->fullscreen)
627 a = self->pre_fullscreen_area;
628 else if (self->max_horz || self->max_vert) {
629 if (self->max_horz) {
630 a.x = self->pre_max_area.x;
631 a.width = self->pre_max_area.width;
633 if (self->max_vert) {
634 a.y = self->pre_max_area.y;
635 a.height = self->pre_max_area.height;
639 self->fullscreen = self->max_horz = self->max_vert = FALSE;
640 /* let it be moved and resized no matter what */
641 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
642 self->decorations = 0; /* unmanaged windows have no decor */
644 /* give the client its border back */
645 XSetWindowBorderWidth(obt_display, self->window, self->border_width);
647 client_move_resize(self, a.x, a.y, a.width, a.height);
650 /* reparent the window out of the frame, and free the frame */
651 frame_release_client(self->frame);
652 frame_free(self->frame);
655 if (ob_state() != OB_STATE_EXITING) {
656 /* these values should not be persisted across a window
658 OBT_PROP_ERASE(self->window, NET_WM_DESKTOP);
659 OBT_PROP_ERASE(self->window, NET_WM_STATE);
660 OBT_PROP_ERASE(self->window, WM_STATE);
662 /* if we're left in an unmapped state, the client wont be mapped.
663 this is bad, since we will no longer be managing the window on
665 XMapWindow(obt_display, self->window);
668 /* these should not be left on the window ever. other window managers
669 don't necessarily use them and it will mess them up (like compiz) */
670 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_NAME);
671 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_ICON_NAME);
673 /* update the list hints */
676 ob_debug("Unmanaged window 0x%lx", self->window);
678 /* free all data allocated in the client struct */
679 RrImageUnref(self->icon_set);
680 g_slist_free(self->transients);
681 g_free(self->startup_id);
682 g_free(self->wm_command);
684 g_free(self->icon_title);
685 g_free(self->original_title);
689 g_free(self->client_machine);
690 g_free(self->sm_client_id);
691 g_slice_free(ObClient, self);
694 void client_fake_unmanage(ObClient *self)
696 /* this is all that got allocated to get the decorations */
698 frame_free(self->frame);
699 g_slice_free(ObClient, self);
702 static gboolean client_can_steal_focus(ObClient *self,
703 gboolean allow_other_desktop,
704 gboolean request_from_user,
709 gboolean relative_focused;
713 relative_focused = (focus_client != NULL &&
714 (client_search_focus_tree_full(self) != NULL ||
715 client_search_focus_group_full(self) != NULL));
717 /* This is focus stealing prevention */
718 ob_debug("Want to focus window 0x%x at time %u "
719 "launched at %u (last user interaction time %u) "
720 "request from %s, allow other desktop: %s, "
721 "desktop switch time %u",
722 self->window, steal_time, launch_time,
723 event_last_user_time,
724 (request_from_user ? "user" : "other"),
725 (allow_other_desktop ? "yes" : "no"),
726 screen_desktop_user_time);
729 if no launch time is provided for an application, make one up.
731 if the window is related to other existing windows
732 and one of those windows was the last used
733 then we will give it a launch time equal to the last user time,
734 which will end up giving the window focus probably.
736 the window is related to other windows, but you are not working in
738 seems suspicious, so we will give it a launch time of
739 NOW - STEAL_INTERVAL,
740 so it will be given focus only if we didn't use something else
741 during the steal interval.
743 the window is all on its own, so we can't judge it. give it a launch
744 time equal to the last user time, so it will probably take focus.
746 this way running things from a terminal will give them focus, but popups
747 without a launch time shouldn't steal focus so easily.
751 if (client_has_relative(self)) {
752 if (event_last_user_time && client_search_focus_group_full(self)) {
753 /* our relative is focused */
754 launch_time = event_last_user_time;
755 ob_debug("Unknown launch time, using %u - window in active "
756 "group", launch_time);
758 else if (!request_from_user) {
759 /* has relatives which are not being used. suspicious */
760 launch_time = event_time() - OB_EVENT_USER_TIME_DELAY;
761 ob_debug("Unknown launch time, using %u - window in inactive "
762 "group", launch_time);
765 /* has relatives which are not being used, but the user seems
766 to want to go there! */
767 launch_time = event_last_user_time;
768 ob_debug("Unknown launch time, using %u - user request",
773 /* the window is on its own, probably the user knows it is going
775 launch_time = event_last_user_time;
776 ob_debug("Unknown launch time, using %u - independent window",
781 /* if it's on another desktop
782 and if allow_other_desktop is true, we generally let it steal focus.
783 but if it didn't come from the user, don't let it steal unless it was
784 launched before the user switched desktops.
785 focus, unless it was launched after we changed desktops and the request
788 if (!screen_compare_desktops(screen_desktop, self->desktop)) {
789 /* must be allowed */
790 if (!allow_other_desktop) {
792 ob_debug("Not focusing the window because its on another desktop");
794 /* if we don't know when the desktop changed, but request is from an
795 application, don't let it change desktop on you */
796 else if (!request_from_user) {
798 ob_debug("Not focusing the window because non-user request");
801 /* If something is focused... */
802 else if (focus_client) {
803 /* If the user is working in another window right now, then don't
805 if (!relative_focused &&
806 event_last_user_time &&
807 /* last user time must be strictly > launch_time to block focus */
808 (event_time_after(event_last_user_time, launch_time) &&
809 event_last_user_time != launch_time) &&
810 event_time_after(event_last_user_time,
811 steal_time - OB_EVENT_USER_TIME_DELAY))
814 ob_debug("Not focusing the window because the user is "
815 "working in another window that is not its relative");
817 /* Don't move focus if it's not going to go to this window
819 else if (client_focus_target(self) != self) {
821 ob_debug("Not focusing the window because another window "
822 "would get the focus anyway");
824 /* For requests that don't come from the user */
825 else if (!request_from_user) {
826 /* If the new window is a transient (and its relatives aren't
828 if (client_has_parent(self) && !relative_focused) {
830 ob_debug("Not focusing the window because it is a "
831 "transient, and its relatives aren't focused");
833 /* Don't steal focus from globally active clients.
834 I stole this idea from KWin. It seems nice.
836 else if (!(focus_client->can_focus || focus_client->focus_notify))
839 ob_debug("Not focusing the window because a globally "
840 "active client has focus");
842 /* Don't move focus if the window is not visible on the current
843 desktop and none of its relatives are focused */
844 else if (!allow_other_desktop &&
845 !screen_compare_desktops(self->desktop, screen_desktop) &&
849 ob_debug("Not focusing the window because it is on "
850 "another desktop and no relatives are focused ");
856 ob_debug("Focus stealing prevention activated for %s at "
857 "time %u (last user interaction time %u)",
858 self->title, steal_time, event_last_user_time);
860 ob_debug("Allowing focus stealing for %s at time %u (last user "
861 "interaction time %u)",
862 self->title, steal_time, event_last_user_time);
866 /*! Returns a new structure containing the per-app settings for this client.
867 The returned structure needs to be freed with g_free. */
868 static ObAppSettings *client_get_settings_state(ObClient *self)
870 ObAppSettings *settings;
873 settings = config_create_app_settings();
875 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
876 ObAppSettings *app = it->data;
877 gboolean match = TRUE;
879 g_assert(app->name != NULL || app->class != NULL ||
880 app->role != NULL || app->title != NULL ||
881 (signed)app->type >= 0);
884 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
886 else if (app->class &&
887 !g_pattern_match(app->class,
888 strlen(self->class), self->class, NULL))
890 else if (app->role &&
891 !g_pattern_match(app->role,
892 strlen(self->role), self->role, NULL))
894 else if (app->title &&
895 !g_pattern_match(app->title,
896 strlen(self->title), self->title, NULL))
898 else if ((signed)app->type >= 0 && app->type != self->type) {
903 ob_debug("Window matching: %s", app->name);
905 /* copy the settings to our struct, overriding the existing
906 settings if they are not defaults */
907 config_app_settings_copy_non_defaults(app, settings);
911 if (settings->shade != -1)
912 self->shaded = !!settings->shade;
913 if (settings->decor != -1)
914 self->undecorated = !settings->decor;
915 if (settings->iconic != -1)
916 self->iconic = !!settings->iconic;
917 if (settings->skip_pager != -1)
918 self->skip_pager = !!settings->skip_pager;
919 if (settings->skip_taskbar != -1)
920 self->skip_taskbar = !!settings->skip_taskbar;
922 if (settings->max_vert != -1)
923 self->max_vert = !!settings->max_vert;
924 if (settings->max_horz != -1)
925 self->max_horz = !!settings->max_horz;
927 if (settings->fullscreen != -1)
928 self->fullscreen = !!settings->fullscreen;
930 if (settings->desktop) {
931 if (settings->desktop == DESKTOP_ALL)
932 self->desktop = settings->desktop;
933 else if (settings->desktop > 0 &&
934 settings->desktop <= screen_num_desktops)
935 self->desktop = settings->desktop - 1;
938 if (settings->layer == -1) {
942 else if (settings->layer == 0) {
946 else if (settings->layer == 1) {
953 static void client_restore_session_state(ObClient *self)
957 ob_debug_type(OB_DEBUG_SM,
958 "Restore session for client %s", self->title);
960 if (!(it = session_state_find(self))) {
961 ob_debug_type(OB_DEBUG_SM,
962 "Session data not found for client %s", self->title);
966 self->session = it->data;
968 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s",
971 RECT_SET_POINT(self->area, self->session->x, self->session->y);
972 self->positioned = USPosition;
973 self->sized = USSize;
974 if (self->session->w > 0)
975 self->area.width = self->session->w;
976 if (self->session->h > 0)
977 self->area.height = self->session->h;
978 XResizeWindow(obt_display, self->window,
979 self->area.width, self->area.height);
981 self->desktop = (self->session->desktop == DESKTOP_ALL ?
982 self->session->desktop :
983 MIN(screen_num_desktops - 1, self->session->desktop));
984 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
986 self->shaded = self->session->shaded;
987 self->iconic = self->session->iconic;
988 self->skip_pager = self->session->skip_pager;
989 self->skip_taskbar = self->session->skip_taskbar;
990 self->fullscreen = self->session->fullscreen;
991 self->above = self->session->above;
992 self->below = self->session->below;
993 self->max_horz = self->session->max_horz;
994 self->max_vert = self->session->max_vert;
995 self->undecorated = self->session->undecorated;
998 static gboolean client_restore_session_stacking(ObClient *self)
1002 if (!self->session) return FALSE;
1004 mypos = g_list_find(session_saved_state, self->session);
1005 if (!mypos) return FALSE;
1007 /* start above me and look for the first client */
1008 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
1011 for (cit = client_list; cit; cit = g_list_next(cit)) {
1012 ObClient *c = cit->data;
1013 /* found a client that was in the session, so go below it */
1014 if (c->session == it->data) {
1015 stacking_below(CLIENT_AS_WINDOW(self),
1016 CLIENT_AS_WINDOW(cit->data));
1024 void client_move_onscreen(ObClient *self, gboolean rude)
1026 gint x = self->area.x;
1027 gint y = self->area.y;
1028 if (client_find_onscreen(self, &x, &y,
1030 self->area.height, rude)) {
1031 client_move(self, x, y);
1035 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
1038 gint ox = *x, oy = *y;
1039 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
1045 RECT_SET(desired, *x, *y, w, h);
1046 frame_rect_to_frame(self->frame, &desired);
1048 /* get where the frame would be */
1049 frame_client_gravity(self->frame, x, y);
1051 /* get the requested size of the window with decorations */
1052 fw = self->frame->size.left + w + self->frame->size.right;
1053 fh = self->frame->size.top + h + self->frame->size.bottom;
1055 /* If rudeness wasn't requested, then still be rude in a given direction
1056 if the client is not moving, only resizing in that direction */
1058 Point oldtl, oldtr, oldbl, oldbr;
1059 Point newtl, newtr, newbl, newbr;
1060 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
1062 POINT_SET(oldtl, self->frame->area.x, self->frame->area.y);
1063 POINT_SET(oldbr, self->frame->area.x + self->frame->area.width - 1,
1064 self->frame->area.y + self->frame->area.height - 1);
1065 POINT_SET(oldtr, oldbr.x, oldtl.y);
1066 POINT_SET(oldbl, oldtl.x, oldbr.y);
1068 POINT_SET(newtl, *x, *y);
1069 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
1070 POINT_SET(newtr, newbr.x, newtl.y);
1071 POINT_SET(newbl, newtl.x, newbr.y);
1073 /* is it moving or just resizing from some corner? */
1074 stationary_l = oldtl.x == newtl.x;
1075 stationary_r = oldtr.x == newtr.x;
1076 stationary_t = oldtl.y == newtl.y;
1077 stationary_b = oldbl.y == newbl.y;
1079 /* if left edge is growing and didnt move right edge */
1080 if (stationary_r && newtl.x < oldtl.x)
1082 /* if right edge is growing and didnt move left edge */
1083 if (stationary_l && newtr.x > oldtr.x)
1085 /* if top edge is growing and didnt move bottom edge */
1086 if (stationary_b && newtl.y < oldtl.y)
1088 /* if bottom edge is growing and didnt move top edge */
1089 if (stationary_t && newbl.y > oldbl.y)
1093 /* we iterate through every monitor that the window is at least partially
1094 on, to make sure it is obeying the rules on them all
1096 if the window does not appear on any monitors, then use the first one
1099 for (i = 0; i < screen_num_monitors; ++i) {
1102 if (!screen_physical_area_monitor_contains(i, &desired)) {
1103 if (i < screen_num_monitors - 1 || found_mon)
1106 /* the window is not inside any monitor! so just use the first
1108 a = screen_area(self->desktop, 0, NULL);
1111 a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &desired);
1114 /* This makes sure windows aren't entirely outside of the screen so you
1115 can't see them at all.
1116 It makes sure 10% of the window is on the screen at least. And don't
1117 let it move itself off the top of the screen, which would hide the
1118 titlebar on you. (The user can still do this if they want too, it's
1119 only limiting the application.
1121 if (client_normal(self)) {
1122 if (!self->strut.right && *x + fw/10 >= a->x + a->width - 1)
1123 *x = a->x + a->width - fw/10;
1124 if (!self->strut.bottom && *y + fh/10 >= a->y + a->height - 1)
1125 *y = a->y + a->height - fh/10;
1126 if (!self->strut.left && *x + fw*9/10 - 1 < a->x)
1127 *x = a->x - fw*9/10;
1128 if (!self->strut.top && *y + fh*9/10 - 1 < a->y)
1129 *y = a->y - fh*9/10;
1132 /* This here doesn't let windows even a pixel outside the
1133 struts/screen. When called from client_manage, programs placing
1134 themselves are forced completely onscreen, while things like
1135 xterm -geometry resolution-width/2 will work fine. Trying to
1136 place it completely offscreen will be handled in the above code.
1137 Sorry for this confused comment, i am tired. */
1138 if (rudel && !self->strut.left && *x < a->x) *x = a->x;
1139 if (ruder && !self->strut.right && *x + fw > a->x + a->width)
1140 *x = a->x + MAX(0, a->width - fw);
1142 if (rudet && !self->strut.top && *y < a->y) *y = a->y;
1143 if (rudeb && !self->strut.bottom && *y + fh > a->y + a->height)
1144 *y = a->y + MAX(0, a->height - fh);
1146 g_slice_free(Rect, a);
1149 /* get where the client should be */
1150 frame_frame_gravity(self->frame, x, y);
1152 return ox != *x || oy != *y;
1155 static void client_get_all(ObClient *self, gboolean real)
1157 /* this is needed for the frame to set itself up */
1158 client_get_area(self);
1160 /* these things can change the decor and functions of the window */
1162 client_get_mwm_hints(self);
1163 /* this can change the mwmhints for special cases */
1164 client_get_type_and_transientness(self);
1165 client_update_normal_hints(self);
1167 /* set up the decor/functions before getting the state. the states may
1168 affect which functions are available, but we want to know the maximum
1169 decor/functions are available to this window, so we can then apply them
1170 in client_apply_startup_state() */
1171 client_setup_decor_and_functions(self, FALSE);
1173 client_get_state(self);
1175 /* get the session related properties, these can change decorations
1176 from per-app settings */
1177 client_get_session_ids(self);
1179 /* now we got everything that can affect the decorations */
1183 /* get this early so we have it for debugging */
1184 client_update_title(self);
1186 /* save the values of the variables used for app rule matching */
1187 client_save_app_rule_values(self);
1189 client_update_protocols(self);
1191 client_update_wmhints(self);
1192 /* this may have already been called from client_update_wmhints */
1193 if (!self->parents && !self->transient_for_group)
1194 client_update_transient_for(self);
1196 client_get_startup_id(self);
1197 client_get_desktop(self);/* uses transient data/group/startup id if a
1198 desktop is not specified */
1199 client_get_shaped(self);
1202 /* a couple type-based defaults for new windows */
1204 /* this makes sure that these windows appear on all desktops */
1205 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1206 self->desktop = DESKTOP_ALL;
1210 client_update_sync_request_counter(self);
1213 client_get_colormap(self);
1214 client_update_strut(self);
1215 client_update_icons(self);
1216 client_update_icon_geometry(self);
1219 static void client_get_startup_id(ObClient *self)
1221 if (!(OBT_PROP_GETS_UTF8(self->window, NET_STARTUP_ID, &self->startup_id)))
1223 OBT_PROP_GETS_UTF8(self->group->leader, NET_STARTUP_ID,
1227 static void client_get_area(ObClient *self)
1229 XWindowAttributes wattrib;
1232 ret = XGetWindowAttributes(obt_display, self->window, &wattrib);
1233 g_assert(ret != BadWindow);
1235 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1236 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1237 self->border_width = wattrib.border_width;
1239 ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y,
1240 wattrib.width, wattrib.height, wattrib.border_width);
1243 static void client_get_desktop(ObClient *self)
1245 guint32 d = screen_num_desktops; /* an always-invalid value */
1247 if (OBT_PROP_GET32(self->window, NET_WM_DESKTOP, CARDINAL, &d)) {
1248 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1249 self->desktop = screen_num_desktops - 1;
1252 ob_debug("client requested desktop 0x%x", self->desktop);
1255 gboolean first = TRUE;
1256 guint all = screen_num_desktops; /* not a valid value */
1258 /* if they are all on one desktop, then open it on the
1260 for (it = self->parents; it; it = g_slist_next(it)) {
1261 ObClient *c = it->data;
1263 if (c->desktop == DESKTOP_ALL) continue;
1269 else if (all != c->desktop)
1270 all = screen_num_desktops; /* make it invalid */
1272 if (all != screen_num_desktops) {
1273 self->desktop = all;
1275 ob_debug("client desktop set from parents: 0x%x",
1278 /* try get from the startup-notification protocol */
1279 else if (sn_get_desktop(self->startup_id, &self->desktop)) {
1280 if (self->desktop >= screen_num_desktops &&
1281 self->desktop != DESKTOP_ALL)
1282 self->desktop = screen_num_desktops - 1;
1283 ob_debug("client desktop set from startup-notification: 0x%x",
1286 /* defaults to the current desktop */
1288 self->desktop = screen_desktop;
1289 ob_debug("client desktop set to the current desktop: %d",
1295 static void client_get_state(ObClient *self)
1300 if (OBT_PROP_GETA32(self->window, NET_WM_STATE, ATOM, &state, &num)) {
1302 for (i = 0; i < num; ++i) {
1303 if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
1305 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
1306 self->shaded = TRUE;
1307 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
1308 self->iconic = TRUE;
1309 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
1310 self->skip_taskbar = TRUE;
1311 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
1312 self->skip_pager = TRUE;
1313 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
1314 self->fullscreen = TRUE;
1315 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
1316 self->max_vert = TRUE;
1317 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
1318 self->max_horz = TRUE;
1319 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
1321 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
1323 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
1324 self->demands_attention = TRUE;
1325 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
1326 self->undecorated = TRUE;
1333 static void client_get_shaped(ObClient *self)
1335 self->shaped = FALSE;
1337 if (obt_display_extension_shape) {
1342 XShapeSelectInput(obt_display, self->window, ShapeNotifyMask);
1344 XShapeQueryExtents(obt_display, self->window, &s, &foo,
1345 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1352 void client_update_transient_for(ObClient *self)
1355 ObClient *target = NULL;
1356 gboolean trangroup = FALSE;
1358 if (XGetTransientForHint(obt_display, self->window, &t)) {
1359 if (t != self->window) { /* can't be transient to itself! */
1360 ObWindow *tw = window_find(t);
1361 /* if this happens then we need to check for it */
1362 g_assert(tw != CLIENT_AS_WINDOW(self));
1363 if (tw && WINDOW_IS_CLIENT(tw)) {
1364 /* watch out for windows with a parent that is something
1365 different, like a dockapp for example */
1366 target = WINDOW_AS_CLIENT(tw);
1370 /* Setting the transient_for to Root is actually illegal, however
1371 applications from time have done this to specify transient for
1373 if (!target && self->group && t == obt_root(ob_screen))
1375 } else if (self->group && self->transient)
1378 client_update_transient_tree(self, self->group, self->group,
1379 self->transient_for_group, trangroup,
1380 client_direct_parent(self), target);
1381 self->transient_for_group = trangroup;
1385 static void client_update_transient_tree(ObClient *self,
1386 ObGroup *oldgroup, ObGroup *newgroup,
1387 gboolean oldgtran, gboolean newgtran,
1388 ObClient* oldparent,
1389 ObClient *newparent)
1394 g_assert(!oldgtran || oldgroup);
1395 g_assert(!newgtran || newgroup);
1396 g_assert((!oldgtran && !oldparent) ||
1397 (oldgtran && !oldparent) ||
1398 (!oldgtran && oldparent));
1399 g_assert((!newgtran && !newparent) ||
1400 (newgtran && !newparent) ||
1401 (!newgtran && newparent));
1404 Group transient windows are not allowed to have other group
1405 transient windows as their children.
1408 /* No change has occured */
1409 if (oldgroup == newgroup &&
1410 oldgtran == newgtran &&
1411 oldparent == newparent) return;
1413 /** Remove the client from the transient tree **/
1415 for (it = self->transients; it; it = next) {
1416 next = g_slist_next(it);
1418 self->transients = g_slist_delete_link(self->transients, it);
1419 c->parents = g_slist_remove(c->parents, self);
1421 for (it = self->parents; it; it = next) {
1422 next = g_slist_next(it);
1424 self->parents = g_slist_delete_link(self->parents, it);
1425 c->transients = g_slist_remove(c->transients, self);
1428 /** Re-add the client to the transient tree **/
1430 /* If we're transient for a group then we need to add ourselves to all our
1433 for (it = newgroup->members; it; it = g_slist_next(it)) {
1436 !client_search_top_direct_parent(c)->transient_for_group &&
1439 c->transients = g_slist_prepend(c->transients, self);
1440 self->parents = g_slist_prepend(self->parents, c);
1445 /* If we are now transient for a single window we need to add ourselves to
1448 WARNING: Cyclical transient-ness is possible if two windows are
1449 transient for eachother.
1451 else if (newparent &&
1452 /* don't make ourself its child if it is already our child */
1453 !client_is_direct_child(self, newparent) &&
1454 client_normal(newparent))
1456 newparent->transients = g_slist_prepend(newparent->transients, self);
1457 self->parents = g_slist_prepend(self->parents, newparent);
1460 /* Add any group transient windows to our children. But if we're transient
1461 for the group, then other group transients are not our children.
1463 WARNING: Cyclical transient-ness is possible. For e.g. if:
1464 A is transient for the group
1465 B is transient for A
1466 C is transient for B
1467 A can't be transient for C or we have a cycle
1469 if (!newgtran && newgroup &&
1471 !client_search_top_direct_parent(newparent)->transient_for_group) &&
1472 client_normal(self))
1474 for (it = newgroup->members; it; it = g_slist_next(it)) {
1476 if (c != self && c->transient_for_group &&
1477 /* Don't make it our child if it is already our parent */
1478 !client_is_direct_child(c, self))
1480 self->transients = g_slist_prepend(self->transients, c);
1481 c->parents = g_slist_prepend(c->parents, self);
1486 /** If we change our group transient-ness, our children change their
1487 effective group transient-ness, which affects how they relate to other
1490 for (it = self->transients; it; it = g_slist_next(it)) {
1492 if (!c->transient_for_group)
1493 client_update_transient_tree(c, c->group, c->group,
1494 c->transient_for_group,
1495 c->transient_for_group,
1496 client_direct_parent(c),
1497 client_direct_parent(c));
1501 void client_get_mwm_hints(ObClient *self)
1506 self->mwmhints.flags = 0; /* default to none */
1508 if (OBT_PROP_GETA32(self->window, MOTIF_WM_HINTS, MOTIF_WM_HINTS,
1510 if (num >= OB_MWM_ELEMENTS) {
1511 self->mwmhints.flags = hints[0];
1512 self->mwmhints.functions = hints[1];
1513 self->mwmhints.decorations = hints[2];
1519 void client_get_type_and_transientness(ObClient *self)
1526 self->transient = FALSE;
1528 if (OBT_PROP_GETA32(self->window, NET_WM_WINDOW_TYPE, ATOM, &val, &num)) {
1529 /* use the first value that we know about in the array */
1530 for (i = 0; i < num; ++i) {
1531 if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
1532 self->type = OB_CLIENT_TYPE_DESKTOP;
1533 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK))
1534 self->type = OB_CLIENT_TYPE_DOCK;
1535 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR))
1536 self->type = OB_CLIENT_TYPE_TOOLBAR;
1537 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
1538 self->type = OB_CLIENT_TYPE_MENU;
1539 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY))
1540 self->type = OB_CLIENT_TYPE_UTILITY;
1541 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH))
1542 self->type = OB_CLIENT_TYPE_SPLASH;
1543 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG))
1544 self->type = OB_CLIENT_TYPE_DIALOG;
1545 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL))
1546 self->type = OB_CLIENT_TYPE_NORMAL;
1547 else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE))
1549 /* prevent this window from getting any decor or
1551 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1552 OB_MWM_FLAG_DECORATIONS);
1553 self->mwmhints.decorations = 0;
1554 self->mwmhints.functions = 0;
1556 if (self->type != (ObClientType) -1)
1557 break; /* grab the first legit type */
1562 if (XGetTransientForHint(obt_display, self->window, &t))
1563 self->transient = TRUE;
1565 if (self->type == (ObClientType) -1) {
1566 /*the window type hint was not set, which means we either classify
1567 ourself as a normal window or a dialog, depending on if we are a
1569 if (self->transient)
1570 self->type = OB_CLIENT_TYPE_DIALOG;
1572 self->type = OB_CLIENT_TYPE_NORMAL;
1575 /* then, based on our type, we can update our transientness.. */
1576 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1577 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1578 self->type == OB_CLIENT_TYPE_MENU ||
1579 self->type == OB_CLIENT_TYPE_UTILITY)
1581 self->transient = TRUE;
1585 void client_update_protocols(ObClient *self)
1590 self->focus_notify = FALSE;
1591 self->delete_window = FALSE;
1593 if (OBT_PROP_GETA32(self->window, WM_PROTOCOLS, ATOM, &proto, &num_ret)) {
1594 for (i = 0; i < num_ret; ++i) {
1595 if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW))
1596 /* this means we can request the window to close */
1597 self->delete_window = TRUE;
1598 else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS))
1599 /* if this protocol is requested, then the window will be
1600 notified whenever we want it to receive focus */
1601 self->focus_notify = TRUE;
1602 else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING))
1603 /* if this protocol is requested, then the window will allow
1604 pings to determine if it is still alive */
1607 else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST))
1608 /* if this protocol is requested, then resizing the
1609 window will be synchronized between the frame and the
1611 self->sync_request = TRUE;
1619 void client_update_sync_request_counter(ObClient *self)
1623 if (OBT_PROP_GET32(self->window, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i))
1627 self->sync_counter = i;
1629 /* this must be set when managing a new window according to EWMH */
1630 XSyncIntToValue(&val, 0);
1631 XSyncSetCounter(obt_display, self->sync_counter, val);
1633 self->sync_counter = None;
1637 static void client_get_colormap(ObClient *self)
1639 XWindowAttributes wa;
1641 if (XGetWindowAttributes(obt_display, self->window, &wa))
1642 client_update_colormap(self, wa.colormap);
1645 void client_update_colormap(ObClient *self, Colormap colormap)
1647 if (colormap == self->colormap) return;
1649 ob_debug("Setting client %s colormap: 0x%x", self->title, colormap);
1651 if (client_focused(self)) {
1652 screen_install_colormap(self, FALSE); /* uninstall old one */
1653 self->colormap = colormap;
1654 screen_install_colormap(self, TRUE); /* install new one */
1656 self->colormap = colormap;
1659 void client_update_normal_hints(ObClient *self)
1665 self->min_ratio = 0.0f;
1666 self->max_ratio = 0.0f;
1667 SIZE_SET(self->size_inc, 1, 1);
1668 SIZE_SET(self->base_size, -1, -1);
1669 SIZE_SET(self->min_size, 0, 0);
1670 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1672 /* get the hints from the window */
1673 if (XGetWMNormalHints(obt_display, self->window, &size, &ret)) {
1674 /* normal windows can't request placement! har har
1675 if (!client_normal(self))
1677 self->positioned = (size.flags & (PPosition|USPosition));
1678 self->sized = (size.flags & (PSize|USSize));
1680 if (size.flags & PWinGravity)
1681 self->gravity = size.win_gravity;
1683 if (size.flags & PAspect) {
1684 if (size.min_aspect.y)
1686 (gfloat) size.min_aspect.x / size.min_aspect.y;
1687 if (size.max_aspect.y)
1689 (gfloat) size.max_aspect.x / size.max_aspect.y;
1692 if (size.flags & PMinSize)
1693 SIZE_SET(self->min_size, size.min_width, size.min_height);
1695 if (size.flags & PMaxSize)
1696 SIZE_SET(self->max_size, size.max_width, size.max_height);
1698 if (size.flags & PBaseSize)
1699 SIZE_SET(self->base_size, size.base_width, size.base_height);
1701 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1702 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1704 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1705 self->min_size.width, self->min_size.height,
1706 self->max_size.width, self->max_size.height);
1707 ob_debug("size inc (%d %d) base size (%d %d)",
1708 self->size_inc.width, self->size_inc.height,
1709 self->base_size.width, self->base_size.height);
1712 ob_debug("Normal hints: not set");
1715 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1717 /* start with everything (cept fullscreen) */
1719 (OB_FRAME_DECOR_TITLEBAR |
1720 OB_FRAME_DECOR_HANDLE |
1721 OB_FRAME_DECOR_GRIPS |
1722 OB_FRAME_DECOR_BORDER |
1723 OB_FRAME_DECOR_ICON |
1724 OB_FRAME_DECOR_ALLDESKTOPS |
1725 OB_FRAME_DECOR_ICONIFY |
1726 OB_FRAME_DECOR_MAXIMIZE |
1727 OB_FRAME_DECOR_SHADE |
1728 OB_FRAME_DECOR_CLOSE);
1730 (OB_CLIENT_FUNC_RESIZE |
1731 OB_CLIENT_FUNC_MOVE |
1732 OB_CLIENT_FUNC_ICONIFY |
1733 OB_CLIENT_FUNC_MAXIMIZE |
1734 OB_CLIENT_FUNC_SHADE |
1735 OB_CLIENT_FUNC_CLOSE |
1736 OB_CLIENT_FUNC_BELOW |
1737 OB_CLIENT_FUNC_ABOVE |
1738 OB_CLIENT_FUNC_UNDECORATE);
1740 if (!(self->min_size.width < self->max_size.width ||
1741 self->min_size.height < self->max_size.height))
1742 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1744 switch (self->type) {
1745 case OB_CLIENT_TYPE_NORMAL:
1746 /* normal windows retain all of the possible decorations and
1747 functionality, and can be fullscreen */
1748 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1751 case OB_CLIENT_TYPE_DIALOG:
1752 /* sometimes apps make dialog windows fullscreen for some reason (for
1753 e.g. kpdf does this..) */
1754 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1757 case OB_CLIENT_TYPE_UTILITY:
1758 /* these windows don't have anything added or removed by default */
1761 case OB_CLIENT_TYPE_MENU:
1762 case OB_CLIENT_TYPE_TOOLBAR:
1763 /* these windows can't iconify or maximize */
1764 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1765 OB_FRAME_DECOR_MAXIMIZE);
1766 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1767 OB_CLIENT_FUNC_MAXIMIZE);
1770 case OB_CLIENT_TYPE_SPLASH:
1771 /* these don't get get any decorations, and the only thing you can
1772 do with them is move them */
1773 self->decorations = 0;
1774 self->functions = OB_CLIENT_FUNC_MOVE;
1777 case OB_CLIENT_TYPE_DESKTOP:
1778 /* these windows are not manipulated by the window manager */
1779 self->decorations = 0;
1780 self->functions = 0;
1783 case OB_CLIENT_TYPE_DOCK:
1784 /* these windows are not manipulated by the window manager, but they
1785 can set below layer which has a special meaning */
1786 self->decorations = 0;
1787 self->functions = OB_CLIENT_FUNC_BELOW;
1791 /* If the client has no decor from its type (which never changes) then
1792 don't allow the user to "undecorate" the window. Otherwise, allow them
1793 to, even if there are motif hints removing the decor, because those
1794 may change these days (e.g. chromium) */
1795 if (self->decorations == 0)
1796 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1798 /* Mwm Hints are applied subtractively to what has already been chosen for
1799 decor and functionality */
1800 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1801 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1802 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1803 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1805 /* if the mwm hints request no handle or title, then all
1806 decorations are disabled, but keep the border if that's
1808 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1809 self->decorations = OB_FRAME_DECOR_BORDER;
1811 self->decorations = 0;
1816 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1817 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1818 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1819 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1820 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1821 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1822 /* dont let mwm hints kill any buttons
1823 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1824 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1825 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1826 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1828 /* dont let mwm hints kill the close button
1829 if (! (self->mwmhints.functions & MwmFunc_Close))
1830 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1834 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1835 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1836 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1837 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1838 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1839 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1841 /* can't maximize without moving/resizing */
1842 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1843 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1844 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1845 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1846 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1849 if (self->max_horz && self->max_vert) {
1850 /* once upon a time you couldn't resize maximized windows, that is not
1851 the case any more though !
1853 but do kill the handle on fully maxed windows */
1854 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1857 /* finally, the user can have requested no decorations, which overrides
1858 everything (but doesnt give it a border if it doesnt have one) */
1859 if (self->undecorated)
1860 self->decorations &= (config_theme_keepborder ?
1861 OB_FRAME_DECOR_BORDER : 0);
1863 /* if we don't have a titlebar, then we cannot shade! */
1864 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1865 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1867 /* now we need to check against rules for the client's current state */
1868 if (self->fullscreen) {
1869 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1870 OB_CLIENT_FUNC_FULLSCREEN |
1871 OB_CLIENT_FUNC_ICONIFY);
1872 self->decorations = 0;
1875 client_change_allowed_actions(self);
1878 /* reconfigure to make sure decorations are updated */
1879 client_reconfigure(self, FALSE);
1882 static void client_change_allowed_actions(ObClient *self)
1887 /* desktop windows are kept on all desktops */
1888 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1889 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP);
1891 if (self->functions & OB_CLIENT_FUNC_SHADE)
1892 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE);
1893 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1894 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE);
1895 if (self->functions & OB_CLIENT_FUNC_MOVE)
1896 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE);
1897 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1898 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE);
1899 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1900 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE);
1901 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1902 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN);
1903 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1904 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ);
1905 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT);
1907 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1908 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE);
1909 if (self->functions & OB_CLIENT_FUNC_BELOW)
1910 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW);
1911 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1912 actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE);
1914 OBT_PROP_SETA32(self->window, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num);
1916 /* make sure the window isn't breaking any rules now
1918 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1919 it can't be iconified with its parent
1922 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1923 if (self->frame) client_shade(self, FALSE);
1924 else self->shaded = FALSE;
1926 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
1927 if (self->frame) client_fullscreen(self, FALSE);
1928 else self->fullscreen = FALSE;
1930 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
1932 if (self->frame) client_maximize(self, FALSE, 0);
1933 else self->max_vert = self->max_horz = FALSE;
1937 void client_update_wmhints(ObClient *self)
1941 /* assume a window takes input if it doesn't specify */
1942 self->can_focus = TRUE;
1944 if ((hints = XGetWMHints(obt_display, self->window)) != NULL) {
1947 if (hints->flags & InputHint)
1948 self->can_focus = hints->input;
1950 /* only do this when first managing the window *AND* when we aren't
1952 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
1953 if (hints->flags & StateHint)
1954 self->iconic = hints->initial_state == IconicState;
1957 self->urgent = (hints->flags & XUrgencyHint);
1958 if (self->urgent && !ur)
1959 client_hilite(self, TRUE);
1960 else if (!self->urgent && ur && self->demands_attention)
1961 client_hilite(self, FALSE);
1963 if (!(hints->flags & WindowGroupHint))
1964 hints->window_group = None;
1966 /* did the group state change? */
1967 if (hints->window_group !=
1968 (self->group ? self->group->leader : None))
1970 ObGroup *oldgroup = self->group;
1972 /* remove from the old group if there was one */
1974 group_remove(self->group, self);
1978 /* add ourself to the group if we have one */
1979 if (hints->window_group != None) {
1980 self->group = group_add(hints->window_group, self);
1983 /* Put ourselves into the new group's transient tree, and remove
1984 ourselves from the old group's */
1985 client_update_transient_tree(self, oldgroup, self->group,
1986 self->transient_for_group,
1987 self->transient_for_group,
1988 client_direct_parent(self),
1989 client_direct_parent(self));
1991 /* Lastly, being in a group, or not, can change if the window is
1992 transient for anything.
1994 The logic for this is:
1995 self->transient = TRUE always if the window wants to be
1996 transient for something, even if transient_for was NULL because
1997 it wasn't in a group before.
1999 If parents was NULL and oldgroup was NULL we can assume
2000 that when we add the new group, it will become transient for
2003 If transient_for_group is TRUE, then it must have already
2004 had a group. If it is getting a new group, the above call to
2005 client_update_transient_tree has already taken care of
2006 everything ! If it is losing all group status then it will
2007 no longer be transient for anything and that needs to be
2010 if (self->transient &&
2011 ((self->parents == NULL && oldgroup == NULL) ||
2012 (self->transient_for_group && !self->group)))
2013 client_update_transient_for(self);
2016 /* the WM_HINTS can contain an icon */
2017 if (hints->flags & IconPixmapHint)
2018 client_update_icons(self);
2023 focus_cycle_addremove(self, TRUE);
2026 void client_update_title(ObClient *self)
2029 gchar *visible = NULL;
2031 g_free(self->title);
2032 g_free(self->original_title);
2035 if (!OBT_PROP_GETS_UTF8(self->window, NET_WM_NAME, &data)) {
2036 /* try old x stuff */
2037 if (!OBT_PROP_GETS(self->window, WM_NAME, &data)) {
2038 if (self->transient) {
2040 GNOME alert windows are not given titles:
2041 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
2043 data = g_strdup("");
2045 data = g_strdup(_("Unnamed Window"));
2048 self->original_title = g_strdup(data);
2050 if (self->client_machine) {
2051 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
2056 if (self->not_responding) {
2058 if (self->kill_level > 0)
2059 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
2061 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
2065 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_NAME, visible);
2066 self->title = visible;
2069 frame_adjust_title(self->frame);
2071 /* update the icon title */
2073 g_free(self->icon_title);
2076 if (!OBT_PROP_GETS_UTF8(self->window, NET_WM_ICON_NAME, &data))
2077 /* try old x stuff */
2078 if (!OBT_PROP_GETS(self->window, WM_ICON_NAME, &data))
2079 data = g_strdup(self->title);
2081 if (self->client_machine) {
2082 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
2087 if (self->not_responding) {
2089 if (self->kill_level > 0)
2090 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
2092 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
2096 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_ICON_NAME, visible);
2097 self->icon_title = visible;
2100 void client_update_strut(ObClient *self)
2104 gboolean got = FALSE;
2107 if (OBT_PROP_GETA32(self->window, NET_WM_STRUT_PARTIAL, CARDINAL,
2112 STRUT_PARTIAL_SET(strut,
2113 data[0], data[2], data[1], data[3],
2114 data[4], data[5], data[8], data[9],
2115 data[6], data[7], data[10], data[11]);
2121 OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) {
2127 /* use the screen's width/height */
2128 a = screen_physical_area_all_monitors();
2130 STRUT_PARTIAL_SET(strut,
2131 data[0], data[2], data[1], data[3],
2132 a->y, a->y + a->height - 1,
2133 a->x, a->x + a->width - 1,
2134 a->y, a->y + a->height - 1,
2135 a->x, a->x + a->width - 1);
2141 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2142 0, 0, 0, 0, 0, 0, 0, 0);
2144 if (!PARTIAL_STRUT_EQUAL(strut, self->strut)) {
2145 self->strut = strut;
2147 /* updating here is pointless while we're being mapped cuz we're not in
2148 the client list yet */
2150 screen_update_areas();
2154 void client_update_icons(ObClient *self)
2163 /* grab the server, because we might be setting the window's icon and
2164 we don't want them to set it in between and we overwrite their own
2168 if (OBT_PROP_GETA32(self->window, NET_WM_ICON, CARDINAL, &data, &num)) {
2169 /* figure out how many valid icons are in here */
2171 while (i + 2 < num) { /* +2 is to make sure there is a w and h */
2174 /* watch for the data being too small for the specified size,
2175 or for zero sized icons. */
2176 if (i + w*h > num || w == 0 || h == 0) {
2181 /* convert it to the right bit order for ObRender */
2182 for (j = 0; j < w*h; ++j)
2184 (((data[i+j] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2185 (((data[i+j] >> 16) & 0xff) << RrDefaultRedOffset) +
2186 (((data[i+j] >> 8) & 0xff) << RrDefaultGreenOffset) +
2187 (((data[i+j] >> 0) & 0xff) << RrDefaultBlueOffset);
2189 /* add it to the image cache as an original */
2191 img = RrImageNewFromData(ob_rr_icons, &data[i], w, h);
2193 RrImageAddFromData(img, &data[i], w, h);
2201 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2206 if ((hints = XGetWMHints(obt_display, self->window))) {
2207 if (hints->flags & IconPixmapHint) {
2209 obt_display_ignore_errors(TRUE);
2210 xicon = RrPixmapToRGBA(ob_rr_inst,
2212 (hints->flags & IconMaskHint ?
2213 hints->icon_mask : None),
2214 (gint*)&w, (gint*)&h, &data);
2215 obt_display_ignore_errors(FALSE);
2218 if (w > 0 && h > 0) {
2220 img = RrImageNewFromData(ob_rr_icons, data, w, h);
2222 RrImageAddFromData(img, data, w, h);
2232 /* set the client's icons to be whatever we found */
2233 RrImageUnref(self->icon_set);
2234 self->icon_set = img;
2236 /* if the client has no icon at all, then we set a default icon onto it.
2237 but, if it has parents, then one of them will have an icon already
2239 if (!self->icon_set && !self->parents) {
2240 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2241 gulong *ldata; /* use a long here to satisfy OBT_PROP_SETA32 */
2243 w = ob_rr_theme->def_win_icon_w;
2244 h = ob_rr_theme->def_win_icon_h;
2245 ldata = g_new(gulong, w*h+2);
2248 for (i = 0; i < w*h; ++i)
2249 ldata[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2250 (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) +
2251 (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) +
2252 (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0);
2253 OBT_PROP_SETA32(self->window, NET_WM_ICON, CARDINAL, ldata, w*h+2);
2255 } else if (self->frame)
2256 /* don't draw the icon empty if we're just setting one now anyways,
2257 we'll get the property change any second */
2258 frame_adjust_icon(self->frame);
2263 void client_update_icon_geometry(ObClient *self)
2268 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2270 if (OBT_PROP_GETA32(self->window, NET_WM_ICON_GEOMETRY, CARDINAL,
2274 /* don't let them set it with an area < 0 */
2275 RECT_SET(self->icon_geometry, data[0], data[1],
2276 MAX(data[2],0), MAX(data[3],0));
2281 static void client_get_session_ids(ObClient *self)
2288 if (!OBT_PROP_GET32(self->window, WM_CLIENT_LEADER, WINDOW, &leader))
2291 /* get the SM_CLIENT_ID */
2292 if (leader && leader != self->window)
2293 OBT_PROP_GETS_XPCS(leader, SM_CLIENT_ID, &self->sm_client_id);
2295 OBT_PROP_GETS_XPCS(self->window, SM_CLIENT_ID, &self->sm_client_id);
2297 /* get the WM_CLASS (name and class). make them "" if they are not
2299 got = OBT_PROP_GETSS_TYPE(self->window, WM_CLASS, STRING_NO_CC, &ss);
2303 self->name = g_strdup(ss[0]);
2305 self->class = g_strdup(ss[1]);
2310 if (self->name == NULL) self->name = g_strdup("");
2311 if (self->class == NULL) self->class = g_strdup("");
2313 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2314 got = OBT_PROP_GETS_XPCS(self->window, WM_WINDOW_ROLE, &s);
2319 self->role = g_strdup("");
2321 /* get the WM_COMMAND */
2325 got = OBT_PROP_GETSS(leader, WM_COMMAND, &ss);
2327 got = OBT_PROP_GETSS(self->window, WM_COMMAND, &ss);
2330 /* merge/mash them all together */
2331 gchar *merge = NULL;
2334 for (i = 0; ss[i]; ++i) {
2337 merge = g_strconcat(merge, ss[i], NULL);
2339 merge = g_strconcat(ss[i], NULL);
2344 self->wm_command = merge;
2347 /* get the WM_CLIENT_MACHINE */
2350 got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, &s);
2352 got = OBT_PROP_GETS(self->window, WM_CLIENT_MACHINE, &s);
2355 gchar localhost[128];
2358 gethostname(localhost, 127);
2359 localhost[127] = '\0';
2360 if (strcmp(localhost, s) != 0)
2361 self->client_machine = s;
2365 /* see if it has the PID set too (the PID requires that the
2366 WM_CLIENT_MACHINE be set) */
2367 if (OBT_PROP_GET32(self->window, NET_WM_PID, CARDINAL, &pid))
2372 /*! Save the properties used for app matching rules, as seen by Openbox when
2373 the window mapped, so that users can still access them later if the app
2375 static void client_save_app_rule_values(ObClient *self)
2379 OBT_PROP_SETS(self->window, OB_APP_ROLE, self->role);
2380 OBT_PROP_SETS(self->window, OB_APP_NAME, self->name);
2381 OBT_PROP_SETS(self->window, OB_APP_CLASS, self->class);
2382 OBT_PROP_SETS(self->window, OB_APP_TITLE, self->original_title);
2384 switch (self->type) {
2385 case OB_CLIENT_TYPE_NORMAL:
2386 type = "normal"; break;
2387 case OB_CLIENT_TYPE_DIALOG:
2388 type = "dialog"; break;
2389 case OB_CLIENT_TYPE_UTILITY:
2390 type = "utility"; break;
2391 case OB_CLIENT_TYPE_MENU:
2392 type = "menu"; break;
2393 case OB_CLIENT_TYPE_TOOLBAR:
2394 type = "toolbar"; break;
2395 case OB_CLIENT_TYPE_SPLASH:
2396 type = "splash"; break;
2397 case OB_CLIENT_TYPE_DESKTOP:
2398 type = "desktop"; break;
2399 case OB_CLIENT_TYPE_DOCK:
2400 type = "dock"; break;
2402 OBT_PROP_SETS(self->window, OB_APP_TYPE, type);
2405 static void client_change_wm_state(ObClient *self)
2410 old = self->wmstate;
2412 if (self->shaded || self->iconic ||
2413 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2415 self->wmstate = IconicState;
2417 self->wmstate = NormalState;
2419 if (old != self->wmstate) {
2420 OBT_PROP_MSG(ob_screen, self->window, KDE_WM_CHANGE_STATE,
2421 self->wmstate, 1, 0, 0, 0);
2423 state[0] = self->wmstate;
2425 OBT_PROP_SETA32(self->window, WM_STATE, WM_STATE, state, 2);
2429 static void client_change_state(ObClient *self)
2431 gulong netstate[12];
2436 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
2438 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED);
2440 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN);
2441 if (self->skip_taskbar)
2442 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR);
2443 if (self->skip_pager)
2444 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER);
2445 if (self->fullscreen)
2446 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN);
2448 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT);
2450 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ);
2452 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE);
2454 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW);
2455 if (self->demands_attention)
2456 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION);
2457 if (self->undecorated)
2458 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED);
2459 OBT_PROP_SETA32(self->window, NET_WM_STATE, ATOM, netstate, num);
2462 frame_adjust_state(self->frame);
2465 ObClient *client_search_focus_tree(ObClient *self)
2470 for (it = self->transients; it; it = g_slist_next(it)) {
2471 if (client_focused(it->data)) return it->data;
2472 if ((ret = client_search_focus_tree(it->data))) return ret;
2477 ObClient *client_search_focus_tree_full(ObClient *self)
2479 if (self->parents) {
2482 for (it = self->parents; it; it = g_slist_next(it)) {
2483 ObClient *c = it->data;
2484 if ((c = client_search_focus_tree_full(c))) return c;
2490 /* this function checks the whole tree, the client_search_focus_tree
2491 does not, so we need to check this window */
2492 if (client_focused(self))
2494 return client_search_focus_tree(self);
2498 ObClient *client_search_focus_group_full(ObClient *self)
2503 for (it = self->group->members; it; it = g_slist_next(it)) {
2504 ObClient *c = it->data;
2506 if (client_focused(c)) return c;
2507 if ((c = client_search_focus_tree(it->data))) return c;
2510 if (client_focused(self)) return self;
2514 gboolean client_has_parent(ObClient *self)
2516 return self->parents != NULL;
2519 gboolean client_has_children(ObClient *self)
2521 return self->transients != NULL;
2524 gboolean client_is_oldfullscreen(const ObClient *self,
2527 const Rect *monitor, *allmonitors;
2529 /* No decorations and fills the monitor = oldskool fullscreen.
2530 But not for maximized windows.
2533 if (self->decorations || self->max_horz || self->max_vert) return FALSE;
2535 monitor = screen_physical_area_monitor(screen_find_monitor(area));
2536 allmonitors = screen_physical_area_all_monitors();
2538 return (RECT_EQUAL(*area, *monitor) ||
2539 RECT_EQUAL(*area, *allmonitors));
2542 static ObStackingLayer calc_layer(ObClient *self)
2546 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2547 l = OB_STACKING_LAYER_DESKTOP;
2548 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2549 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2550 else l = OB_STACKING_LAYER_ABOVE;
2552 else if ((self->fullscreen ||
2553 client_is_oldfullscreen(self, &self->area)) &&
2554 /* you are fullscreen while you or your children are focused.. */
2555 (client_focused(self) || client_search_focus_tree(self) ||
2556 /* you can be fullscreen if you're on another desktop */
2557 (self->desktop != screen_desktop &&
2558 self->desktop != DESKTOP_ALL) ||
2559 /* and you can also be fullscreen if the focused client is on
2560 another monitor, or nothing else is focused */
2562 client_monitor(focus_client) != client_monitor(self))))
2563 l = OB_STACKING_LAYER_FULLSCREEN;
2564 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2565 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2566 else l = OB_STACKING_LAYER_NORMAL;
2571 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2572 ObStackingLayer min)
2574 ObStackingLayer old, own;
2578 own = calc_layer(self);
2579 self->layer = MAX(own, min);
2581 if (self->layer != old) {
2582 stacking_remove(CLIENT_AS_WINDOW(self));
2583 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2586 /* we've been restacked */
2587 self->visited = TRUE;
2589 for (it = self->transients; it; it = g_slist_next(it))
2590 client_calc_layer_recursive(it->data, orig,
2594 static void client_calc_layer_internal(ObClient *self)
2598 /* transients take on the layer of their parents */
2599 sit = client_search_all_top_parents(self);
2601 for (; sit; sit = g_slist_next(sit))
2602 client_calc_layer_recursive(sit->data, self, 0);
2605 void client_calc_layer(ObClient *self)
2609 /* skip over stuff above fullscreen layer */
2610 for (it = stacking_list; it; it = g_list_next(it))
2611 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2613 /* find the windows in the fullscreen layer, and mark them not-visited */
2614 for (; it; it = g_list_next(it)) {
2615 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2616 else if (WINDOW_IS_CLIENT(it->data))
2617 WINDOW_AS_CLIENT(it->data)->visited = FALSE;
2620 client_calc_layer_internal(self);
2622 /* skip over stuff above fullscreen layer */
2623 for (it = stacking_list; it; it = g_list_next(it))
2624 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2626 /* now recalc any windows in the fullscreen layer which have not
2627 had their layer recalced already */
2628 for (; it; it = g_list_next(it)) {
2629 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2630 else if (WINDOW_IS_CLIENT(it->data) &&
2631 !WINDOW_AS_CLIENT(it->data)->visited)
2632 client_calc_layer_internal(it->data);
2636 gboolean client_should_show(ObClient *self)
2640 if (client_normal(self) && screen_showing_desktop)
2642 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2648 gboolean client_show(ObClient *self)
2650 gboolean show = FALSE;
2652 if (client_should_show(self)) {
2653 /* replay pending pointer event before showing the window, in case it
2654 should be going to something under the window */
2655 mouse_replay_pointer();
2657 frame_show(self->frame);
2660 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2661 it needs to be in IconicState. This includes when it is on another
2664 client_change_wm_state(self);
2669 gboolean client_hide(ObClient *self)
2671 gboolean hide = FALSE;
2673 if (!client_should_show(self)) {
2674 /* We don't need to ignore enter events here.
2675 The window can hide/iconify in 3 different ways:
2676 1 - through an x message. in this case we ignore all enter events
2677 caused by responding to the x message (unless underMouse)
2678 2 - by a keyboard action. in this case we ignore all enter events
2679 caused by the action
2680 3 - by a mouse action. in this case they are doing stuff with the
2681 mouse and focus _should_ move.
2683 Also in action_end, we simulate an enter event that can't be ignored
2684 so trying to ignore them is futile in case 3 anyways
2687 /* replay pending pointer event before hiding the window, in case it
2688 should be going to the window */
2689 mouse_replay_pointer();
2691 frame_hide(self->frame);
2694 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2695 it needs to be in IconicState. This includes when it is on another
2698 client_change_wm_state(self);
2703 void client_showhide(ObClient *self)
2705 if (!client_show(self))
2709 gboolean client_normal(ObClient *self) {
2710 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2711 self->type == OB_CLIENT_TYPE_DOCK ||
2712 self->type == OB_CLIENT_TYPE_SPLASH);
2715 gboolean client_helper(ObClient *self)
2717 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2718 self->type == OB_CLIENT_TYPE_MENU ||
2719 self->type == OB_CLIENT_TYPE_TOOLBAR);
2722 gboolean client_mouse_focusable(ObClient *self)
2724 return !(self->type == OB_CLIENT_TYPE_MENU ||
2725 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2726 self->type == OB_CLIENT_TYPE_SPLASH ||
2727 self->type == OB_CLIENT_TYPE_DOCK);
2730 gboolean client_enter_focusable(ObClient *self)
2732 /* you can focus desktops but it shouldn't on enter */
2733 return (client_mouse_focusable(self) &&
2734 self->type != OB_CLIENT_TYPE_DESKTOP);
2737 static void client_apply_startup_state(ObClient *self,
2738 gint x, gint y, gint w, gint h)
2740 /* save the states that we are going to apply */
2741 gboolean iconic = self->iconic;
2742 gboolean fullscreen = self->fullscreen;
2743 gboolean undecorated = self->undecorated;
2744 gboolean shaded = self->shaded;
2745 gboolean demands_attention = self->demands_attention;
2746 gboolean max_horz = self->max_horz;
2747 gboolean max_vert = self->max_vert;
2751 /* turn them all off in the client, so they won't affect the window
2753 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2754 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2756 /* move the client to its placed position, or it it's already there,
2757 generate a ConfigureNotify telling the client where it is.
2759 do this after adjusting the frame. otherwise it gets all weird and
2760 clients don't work right
2762 do this before applying the states so they have the correct
2763 pre-max/pre-fullscreen values
2765 client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
2766 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2767 self->window, x, y, w, h);
2768 /* save the area, and make it where it should be for the premax stuff */
2769 oldarea = self->area;
2770 RECT_SET(self->area, x, y, w, h);
2772 /* apply the states. these are in a carefully crafted order.. */
2775 client_iconify(self, TRUE, FALSE, TRUE);
2777 client_set_undecorated(self, TRUE);
2779 client_shade(self, TRUE);
2780 if (demands_attention)
2781 client_hilite(self, TRUE);
2783 if (max_vert && max_horz)
2784 client_maximize(self, TRUE, 0);
2786 client_maximize(self, TRUE, 2);
2788 client_maximize(self, TRUE, 1);
2790 /* fullscreen removes the ability to apply other states */
2792 client_fullscreen(self, TRUE);
2794 /* if the window hasn't been configured yet, then do so now, in fact the
2795 x,y,w,h may _not_ be the same as the area rect, which can end up
2796 meaning that the client isn't properly moved/resized by the fullscreen
2798 pho can cause this because it maps at size of the screen but not 0,0
2799 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2800 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2801 cuz thats where the pre-fullscreen will be. however the actual area is
2802 not, so this needs to be called even if we have fullscreened/maxed
2804 self->area = oldarea;
2805 client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
2807 /* nothing to do for the other states:
2816 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2818 /* these should be the current values. this is for when you're not moving,
2820 g_assert(*x == self->area.x);
2821 g_assert(oldw == self->area.width);
2824 switch (self->gravity) {
2826 case NorthWestGravity:
2828 case SouthWestGravity:
2835 *x -= (neww - oldw) / 2;
2837 case NorthEastGravity:
2839 case SouthEastGravity:
2845 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2847 /* these should be the current values. this is for when you're not moving,
2849 g_assert(*y == self->area.y);
2850 g_assert(oldh == self->area.height);
2853 switch (self->gravity) {
2855 case NorthWestGravity:
2857 case NorthEastGravity:
2864 *y -= (newh - oldh) / 2;
2866 case SouthWestGravity:
2868 case SouthEastGravity:
2874 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2875 gint *logicalw, gint *logicalh,
2878 Rect desired = {*x, *y, *w, *h};
2879 frame_rect_to_frame(self->frame, &desired);
2881 /* make the frame recalculate its dimensions n shit without changing
2882 anything visible for real, this way the constraints below can work with
2883 the updated frame dimensions. */
2884 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
2886 /* cap any X windows at the size of an unsigned short */
2888 G_MAXUSHORT - self->frame->size.left - self->frame->size.right);
2890 G_MAXUSHORT - self->frame->size.top - self->frame->size.bottom);
2893 /* gets the frame's position */
2894 frame_client_gravity(self->frame, x, y);
2896 /* these positions are frame positions, not client positions */
2898 /* set the size and position if fullscreen */
2899 if (self->fullscreen) {
2903 i = screen_find_monitor(&desired);
2904 a = screen_physical_area_monitor(i);
2911 user = FALSE; /* ignore if the client can't be moved/resized when it
2913 } else if (self->max_horz || self->max_vert) {
2917 /* use all possible struts when maximizing to the full screen */
2918 i = screen_find_monitor(&desired);
2919 a = screen_area(self->desktop, i,
2920 (self->max_horz && self->max_vert ? NULL : &desired));
2922 /* set the size and position if maximized */
2923 if (self->max_horz) {
2925 *w = a->width - self->frame->size.left - self->frame->size.right;
2927 if (self->max_vert) {
2929 *h = a->height - self->frame->size.top - self->frame->size.bottom;
2932 user = FALSE; /* ignore if the client can't be moved/resized when it
2935 g_slice_free(Rect, a);
2938 /* gets the client's position */
2939 frame_frame_gravity(self->frame, x, y);
2941 /* work within the preferred sizes given by the window, these may have
2942 changed rather than it's requested width and height, so always run
2943 through this code */
2945 gint basew, baseh, minw, minh;
2946 gint incw, inch, maxw, maxh;
2947 gfloat minratio, maxratio;
2949 incw = self->size_inc.width;
2950 inch = self->size_inc.height;
2951 minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2952 0 : self->min_ratio;
2953 maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
2954 0 : self->max_ratio;
2956 /* base size is substituted with min size if not specified */
2957 if (self->base_size.width >= 0 || self->base_size.height >= 0) {
2958 basew = self->base_size.width;
2959 baseh = self->base_size.height;
2961 basew = self->min_size.width;
2962 baseh = self->min_size.height;
2964 /* min size is substituted with base size if not specified */
2965 if (self->min_size.width || self->min_size.height) {
2966 minw = self->min_size.width;
2967 minh = self->min_size.height;
2969 minw = self->base_size.width;
2970 minh = self->base_size.height;
2973 /* This comment is no longer true */
2974 /* if this is a user-requested resize, then check against min/max
2977 /* smaller than min size or bigger than max size? */
2978 if (*w > self->max_size.width) *w = self->max_size.width;
2979 if (*w < minw) *w = minw;
2980 if (*h > self->max_size.height) *h = self->max_size.height;
2981 if (*h < minh) *h = minh;
2986 /* the sizes to used for maximized */
2990 /* keep to the increments */
2994 /* you cannot resize to nothing */
2995 if (basew + *w < 1) *w = 1 - basew;
2996 if (baseh + *h < 1) *h = 1 - baseh;
2998 /* save the logical size */
2999 *logicalw = incw > 1 ? *w : *w + basew;
3000 *logicalh = inch > 1 ? *h : *h + baseh;
3005 /* if maximized/fs then don't use the size increments */
3006 if (self->fullscreen || self->max_horz) *w = maxw;
3007 if (self->fullscreen || self->max_vert) *h = maxh;
3012 /* adjust the height to match the width for the aspect ratios.
3013 for this, min size is not substituted for base size ever. */
3014 *w -= self->base_size.width;
3015 *h -= self->base_size.height;
3018 if (*h * minratio > *w) {
3019 *h = (gint)(*w / minratio);
3021 /* you cannot resize to nothing */
3024 *w = (gint)(*h * minratio);
3028 if (*h * maxratio < *w) {
3029 *h = (gint)(*w / maxratio);
3031 /* you cannot resize to nothing */
3034 *w = (gint)(*h * minratio);
3038 *w += self->base_size.width;
3039 *h += self->base_size.height;
3042 /* these override the above states! if you cant move you can't move! */
3044 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
3048 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
3049 *w = self->area.width;
3050 *h = self->area.height;
3058 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
3059 gboolean user, gboolean final, gboolean force_reply)
3061 Rect oldframe, oldclient;
3062 gboolean send_resize_client;
3063 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
3064 gboolean fmoved, fresized;
3065 guint fdecor = self->frame->decorations;
3066 gboolean fhorz = self->frame->max_horz;
3067 gboolean fvert = self->frame->max_vert;
3068 gint logicalw, logicalh;
3070 /* find the new x, y, width, and height (and logical size) */
3071 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
3073 /* set the logical size if things changed */
3074 if (!(w == self->area.width && h == self->area.height))
3075 SIZE_SET(self->logical_size, logicalw, logicalh);
3077 /* figure out if we moved or resized or what */
3078 moved = (x != self->area.x || y != self->area.y);
3079 resized = (w != self->area.width || h != self->area.height);
3081 oldframe = self->frame->area;
3082 oldclient = self->area;
3083 RECT_SET(self->area, x, y, w, h);
3085 /* for app-requested resizes, always resize if 'resized' is true.
3086 for user-requested ones, only resize if final is true, or when
3087 resizing in redraw mode */
3088 send_resize_client = ((!user && resized) ||
3090 (resized && config_resize_redraw))));
3092 /* if the client is enlarging, then resize the client before the frame */
3093 if (send_resize_client && (w > oldclient.width || h > oldclient.height)) {
3094 XMoveResizeWindow(obt_display, self->window,
3095 self->frame->size.left, self->frame->size.top,
3096 MAX(w, oldclient.width), MAX(h, oldclient.height));
3097 frame_adjust_client_area(self->frame);
3100 /* find the frame's dimensions and move/resize it */
3104 /* if decorations changed, then readjust everything for the frame */
3105 if (self->decorations != fdecor ||
3106 self->max_horz != fhorz || self->max_vert != fvert)
3108 fmoved = fresized = TRUE;
3111 /* adjust the frame */
3112 if (fmoved || fresized) {
3113 gulong ignore_start;
3115 ignore_start = event_start_ignore_all_enters();
3117 /* replay pending pointer event before move the window, in case it
3118 would change what window gets the event */
3119 mouse_replay_pointer();
3121 frame_adjust_area(self->frame, fmoved, fresized, FALSE);
3124 event_end_ignore_all_enters(ignore_start);
3127 if (!user || final) {
3128 gint oldrx = self->root_pos.x;
3129 gint oldry = self->root_pos.y;
3130 /* we have reset the client to 0 border width, so don't include
3131 it in these coords */
3132 POINT_SET(self->root_pos,
3133 self->frame->area.x + self->frame->size.left -
3135 self->frame->area.y + self->frame->size.top -
3136 self->border_width);
3137 if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
3141 /* This is kinda tricky and should not be changed.. let me explain!
3143 When user = FALSE, then the request is coming from the application
3144 itself, and we are more strict about when to send a synthetic
3145 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3146 in this case (or send one if force_reply is true)
3148 When user = TRUE, then the request is coming from "us", like when we
3149 maximize a window or something. In this case we are more lenient. We
3150 used to follow the same rules as above, but _Java_ Swing can't handle
3151 this. So just to appease Swing, when user = TRUE, we always send
3152 a synthetic ConfigureNotify to give the window its root coordinates.
3153 Lastly, if force_reply is TRUE, we always send a
3154 ConfigureNotify, which is needed during a resize with XSYNCronization.
3156 if ((!user && !resized && (rootmoved || force_reply)) ||
3157 (user && ((!resized && force_reply) || (final && rootmoved))))
3161 event.type = ConfigureNotify;
3162 event.xconfigure.display = obt_display;
3163 event.xconfigure.event = self->window;
3164 event.xconfigure.window = self->window;
3166 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3167 self->title, self->root_pos.x, self->root_pos.y, w, h);
3169 /* root window real coords */
3170 event.xconfigure.x = self->root_pos.x;
3171 event.xconfigure.y = self->root_pos.y;
3172 event.xconfigure.width = w;
3173 event.xconfigure.height = h;
3174 event.xconfigure.border_width = self->border_width;
3175 event.xconfigure.above = None;
3176 event.xconfigure.override_redirect = FALSE;
3177 XSendEvent(event.xconfigure.display, event.xconfigure.window,
3178 FALSE, StructureNotifyMask, &event);
3181 /* if the client is shrinking, then resize the frame before the client.
3183 both of these resize sections may run, because the top one only resizes
3184 in the direction that is growing
3186 if (send_resize_client && (w <= oldclient.width || h <= oldclient.height))
3188 frame_adjust_client_area(self->frame);
3189 XMoveResizeWindow(obt_display, self->window,
3190 self->frame->size.left, self->frame->size.top, w, h);
3193 XFlush(obt_display);
3195 /* if it moved between monitors, then this can affect the stacking
3196 layer of this window or others - for fullscreen windows.
3197 also if it changed to/from oldschool fullscreen then its layer may
3200 watch out tho, don't try change stacking stuff if the window is no
3201 longer being managed !
3203 if (self->managed &&
3204 (screen_find_monitor(&self->frame->area) !=
3205 screen_find_monitor(&oldframe) ||
3206 (final && (client_is_oldfullscreen(self, &oldclient) !=
3207 client_is_oldfullscreen(self, &self->area)))))
3209 client_calc_layer(self);
3213 void client_fullscreen(ObClient *self, gboolean fs)
3217 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
3218 self->fullscreen == fs) return; /* already done */
3220 self->fullscreen = fs;
3221 client_change_state(self); /* change the state hints on the client */
3224 self->pre_fullscreen_area = self->area;
3225 self->pre_fullscreen_max_horz = self->max_horz;
3226 self->pre_fullscreen_max_vert = self->max_vert;
3228 /* if the window is maximized, its area isn't all that meaningful.
3229 save its premax area instead. */
3230 if (self->max_horz) {
3231 self->pre_fullscreen_area.x = self->pre_max_area.x;
3232 self->pre_fullscreen_area.width = self->pre_max_area.width;
3234 if (self->max_vert) {
3235 self->pre_fullscreen_area.y = self->pre_max_area.y;
3236 self->pre_fullscreen_area.height = self->pre_max_area.height;
3239 /* these will help configure_full figure out where to fullscreen
3243 w = self->area.width;
3244 h = self->area.height;
3246 g_assert(self->pre_fullscreen_area.width > 0 &&
3247 self->pre_fullscreen_area.height > 0);
3249 self->max_horz = self->pre_fullscreen_max_horz;
3250 self->max_vert = self->pre_fullscreen_max_vert;
3251 if (self->max_horz) {
3252 self->pre_max_area.x = self->pre_fullscreen_area.x;
3253 self->pre_max_area.width = self->pre_fullscreen_area.width;
3255 if (self->max_vert) {
3256 self->pre_max_area.y = self->pre_fullscreen_area.y;
3257 self->pre_max_area.height = self->pre_fullscreen_area.height;
3260 x = self->pre_fullscreen_area.x;
3261 y = self->pre_fullscreen_area.y;
3262 w = self->pre_fullscreen_area.width;
3263 h = self->pre_fullscreen_area.height;
3264 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
3267 ob_debug("Window %s going fullscreen (%d)",
3268 self->title, self->fullscreen);
3271 /* make sure the window is on some monitor */
3272 client_find_onscreen(self, &x, &y, w, h, FALSE);
3275 client_setup_decor_and_functions(self, FALSE);
3276 client_move_resize(self, x, y, w, h);
3278 /* and adjust our layer/stacking. do this after resizing the window,
3279 and applying decorations, because windows which fill the screen are
3280 considered "fullscreen" and it affects their layer */
3281 client_calc_layer(self);
3284 /* try focus us when we go into fullscreen mode */
3289 static void client_iconify_recursive(ObClient *self,
3290 gboolean iconic, gboolean curdesk,
3291 gboolean hide_animation)
3294 gboolean changed = FALSE;
3296 if (self->iconic != iconic) {
3297 ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
3301 /* don't let non-normal windows iconify along with their parents
3303 if (client_normal(self)) {
3304 self->iconic = iconic;
3306 /* update the focus lists.. iconic windows go to the bottom of
3307 the list. this will also call focus_cycle_addremove(). */
3308 focus_order_to_bottom(self);
3313 self->iconic = iconic;
3315 if (curdesk && self->desktop != screen_desktop &&
3316 self->desktop != DESKTOP_ALL)
3317 client_set_desktop(self, screen_desktop, FALSE, FALSE);
3319 /* this puts it after the current focused window, this will
3320 also cause focus_cycle_addremove() to be called for the
3322 focus_order_like_new(self);
3329 client_change_state(self);
3330 if (config_animate_iconify && !hide_animation)
3331 frame_begin_iconify_animation(self->frame, iconic);
3332 /* do this after starting the animation so it doesn't flash */
3333 client_showhide(self);
3336 /* iconify all direct transients, and deiconify all transients
3338 for (it = self->transients; it; it = g_slist_next(it))
3339 if (it->data != self)
3340 if (client_is_direct_child(self, it->data) || !iconic)
3341 client_iconify_recursive(it->data, iconic, curdesk,
3345 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3346 gboolean hide_animation)
3348 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3349 /* move up the transient chain as far as possible first */
3350 self = client_search_top_direct_parent(self);
3351 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3355 void client_maximize(ObClient *self, gboolean max, gint dir)
3359 g_assert(dir == 0 || dir == 1 || dir == 2);
3360 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && max) return;/* can't */
3362 /* check if already done */
3364 if (dir == 0 && self->max_horz && self->max_vert) return;
3365 if (dir == 1 && self->max_horz) return;
3366 if (dir == 2 && self->max_vert) return;
3368 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3369 if (dir == 1 && !self->max_horz) return;
3370 if (dir == 2 && !self->max_vert) return;
3373 /* these will help configure_full figure out which screen to fill with
3377 w = self->area.width;
3378 h = self->area.height;
3381 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3382 RECT_SET(self->pre_max_area,
3383 self->area.x, self->pre_max_area.y,
3384 self->area.width, self->pre_max_area.height);
3386 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3387 RECT_SET(self->pre_max_area,
3388 self->pre_max_area.x, self->area.y,
3389 self->pre_max_area.width, self->area.height);
3392 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3393 g_assert(self->pre_max_area.width > 0);
3395 x = self->pre_max_area.x;
3396 w = self->pre_max_area.width;
3398 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3399 0, self->pre_max_area.height);
3401 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3402 g_assert(self->pre_max_area.height > 0);
3404 y = self->pre_max_area.y;
3405 h = self->pre_max_area.height;
3407 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3408 self->pre_max_area.width, 0);
3412 if (dir == 0 || dir == 1) /* horz */
3413 self->max_horz = max;
3414 if (dir == 0 || dir == 2) /* vert */
3415 self->max_vert = max;
3418 /* make sure the window is on some monitor */
3419 client_find_onscreen(self, &x, &y, w, h, FALSE);
3422 client_change_state(self); /* change the state hints on the client */
3424 client_setup_decor_and_functions(self, FALSE);
3425 client_move_resize(self, x, y, w, h);
3428 void client_shade(ObClient *self, gboolean shade)
3430 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3431 shade) || /* can't shade */
3432 self->shaded == shade) return; /* already done */
3434 self->shaded = shade;
3435 client_change_state(self);
3436 client_change_wm_state(self); /* the window is being hidden/shown */
3437 /* resize the frame to just the titlebar */
3438 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
3441 static void client_ping_event(ObClient *self, gboolean dead)
3443 if (self->not_responding != dead) {
3444 self->not_responding = dead;
3445 client_update_title(self);
3448 /* the client isn't responding, so ask to kill it */
3449 client_prompt_kill(self);
3451 /* it came back to life ! */
3453 if (self->kill_prompt) {
3454 prompt_unref(self->kill_prompt);
3455 self->kill_prompt = NULL;
3458 self->kill_level = 0;
3463 void client_close(ObClient *self)
3465 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3467 /* if closing an internal obprompt, that is just cancelling it */
3469 prompt_cancel(self->prompt);
3473 /* in the case that the client provides no means to requesting that it
3474 close, we just kill it */
3475 if (!self->delete_window)
3476 /* don't use client_kill(), we should only kill based on PID in
3477 response to a lack of PING replies */
3478 XKillClient(obt_display, self->window);
3480 /* request the client to close with WM_DELETE_WINDOW */
3481 OBT_PROP_MSG_TO(self->window, self->window, WM_PROTOCOLS,
3482 OBT_PROP_ATOM(WM_DELETE_WINDOW), event_time(),
3483 0, 0, 0, NoEventMask);
3485 /* we're trying to close the window, so see if it is responding. if it
3486 is not, then we will let them kill the window */
3488 ping_start(self, client_ping_event);
3490 /* if we already know the window isn't responding (maybe they clicked
3491 no in the kill dialog but it hasn't come back to life), then show
3493 if (self->not_responding)
3494 client_prompt_kill(self);
3498 #define OB_KILL_RESULT_NO 0
3499 #define OB_KILL_RESULT_YES 1
3501 static gboolean client_kill_requested(ObPrompt *p, gint result, gpointer data)
3503 ObClient *self = data;
3505 if (result == OB_KILL_RESULT_YES)
3507 return TRUE; /* call the cleanup func */
3510 static void client_kill_cleanup(ObPrompt *p, gpointer data)
3512 ObClient *self = data;
3514 g_assert(p == self->kill_prompt);
3516 prompt_unref(self->kill_prompt);
3517 self->kill_prompt = NULL;
3520 static void client_prompt_kill(ObClient *self)
3522 /* check if we're already prompting */
3523 if (!self->kill_prompt) {
3524 ObPromptAnswer answers[] = {
3525 { 0, OB_KILL_RESULT_NO },
3526 { 0, OB_KILL_RESULT_YES }
3529 const gchar *y, *title;
3531 title = self->original_title;
3532 if (title[0] == '\0') {
3533 /* empty string, so use its parent */
3534 ObClient *p = client_search_top_direct_parent(self);
3535 if (p) title = p->original_title;
3538 if (client_on_localhost(self)) {
3541 if (self->kill_level == 0)
3547 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3549 y = _("End Process");
3553 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3555 y = _("Disconnect");
3557 /* set the dialog buttons' text */
3558 answers[0].text = _("Cancel"); /* "no" */
3559 answers[1].text = y; /* "yes" */
3561 self->kill_prompt = prompt_new(m, NULL, answers,
3562 sizeof(answers)/sizeof(answers[0]),
3563 OB_KILL_RESULT_NO, /* default = no */
3564 OB_KILL_RESULT_NO, /* cancel = no */
3565 client_kill_requested,
3566 client_kill_cleanup,
3571 prompt_show(self->kill_prompt, self, TRUE);
3574 void client_kill(ObClient *self)
3576 /* don't kill our own windows */
3577 if (self->prompt) return;
3579 if (client_on_localhost(self) && self->pid) {
3580 /* running on the local host */
3581 if (self->kill_level == 0) {
3582 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3583 self->window, self->pid);
3584 kill(self->pid, SIGTERM);
3587 /* show that we're trying to kill it */
3588 client_update_title(self);
3591 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3592 self->window, self->pid);
3593 kill(self->pid, SIGKILL); /* kill -9 */
3597 /* running on a remote host */
3598 XKillClient(obt_display, self->window);
3602 void client_hilite(ObClient *self, gboolean hilite)
3604 if (self->demands_attention == hilite)
3605 return; /* no change */
3607 /* don't allow focused windows to hilite */
3608 self->demands_attention = hilite && !client_focused(self);
3609 if (self->frame != NULL) { /* if we're mapping, just set the state */
3610 if (self->demands_attention) {
3611 frame_flash_start(self->frame);
3613 /* if the window is on another desktop then raise it and make it
3614 the most recently used window */
3615 if (self->desktop != screen_desktop &&
3616 self->desktop != DESKTOP_ALL)
3618 stacking_raise(CLIENT_AS_WINDOW(self));
3619 focus_order_to_top(self);
3623 frame_flash_stop(self->frame);
3624 client_change_state(self);
3628 static void client_set_desktop_recursive(ObClient *self,
3636 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3638 ob_debug("Setting desktop %u", target+1);
3640 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3642 old = self->desktop;
3643 self->desktop = target;
3644 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, target);
3645 /* the frame can display the current desktop state */
3646 frame_adjust_state(self->frame);
3647 /* 'move' the window to the new desktop */
3651 /* raise if it was not already on the desktop */
3652 if (old != DESKTOP_ALL && !dontraise)
3653 stacking_raise(CLIENT_AS_WINDOW(self));
3654 if (STRUT_EXISTS(self->strut))
3655 screen_update_areas();
3657 /* the new desktop's geometry may be different, so we may need to
3658 resize, for example if we are maximized */
3659 client_reconfigure(self, FALSE);
3661 focus_cycle_addremove(self, FALSE);
3664 /* move all transients */
3665 for (it = self->transients; it; it = g_slist_next(it))
3666 if (it->data != self)
3667 if (client_is_direct_child(self, it->data))
3668 client_set_desktop_recursive(it->data, target,
3669 donthide, dontraise);
3672 void client_set_desktop(ObClient *self, guint target,
3673 gboolean donthide, gboolean dontraise)
3675 self = client_search_top_direct_parent(self);
3676 client_set_desktop_recursive(self, target, donthide, dontraise);
3678 focus_cycle_addremove(NULL, TRUE);
3681 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3683 while (child != parent && (child = client_direct_parent(child)));
3684 return child == parent;
3687 ObClient *client_search_modal_child(ObClient *self)
3692 for (it = self->transients; it; it = g_slist_next(it)) {
3693 ObClient *c = it->data;
3694 if ((ret = client_search_modal_child(c))) return ret;
3695 if (c->modal) return c;
3700 struct ObClientFindDestroyUnmap {
3705 static gboolean find_destroy_unmap(XEvent *e, gpointer data)
3707 struct ObClientFindDestroyUnmap *find = data;
3708 if (e->type == DestroyNotify)
3709 return e->xdestroywindow.window == find->window;
3710 if (e->type == UnmapNotify && e->xunmap.window == find->window)
3711 /* ignore the first $find->ignore_unmaps$ many unmap events */
3712 return --find->ignore_unmaps < 0;
3716 gboolean client_validate(ObClient *self)
3718 struct ObClientFindDestroyUnmap find;
3720 XSync(obt_display, FALSE); /* get all events on the server */
3722 find.window = self->window;
3723 find.ignore_unmaps = self->ignore_unmaps;
3724 if (xqueue_exists_local(find_destroy_unmap, &find))
3730 void client_set_wm_state(ObClient *self, glong state)
3732 if (state == self->wmstate) return; /* no change */
3736 client_iconify(self, TRUE, TRUE, FALSE);
3739 client_iconify(self, FALSE, TRUE, FALSE);
3744 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3746 gboolean shaded = self->shaded;
3747 gboolean fullscreen = self->fullscreen;
3748 gboolean undecorated = self->undecorated;
3749 gboolean max_horz = self->max_horz;
3750 gboolean max_vert = self->max_vert;
3751 gboolean modal = self->modal;
3752 gboolean iconic = self->iconic;
3753 gboolean demands_attention = self->demands_attention;
3754 gboolean above = self->above;
3755 gboolean below = self->below;
3759 if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) ||
3760 action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) ||
3761 action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)))
3762 /* an invalid action was passed to the client message, ignore it */
3765 for (i = 0; i < 2; ++i) {
3766 Atom state = i == 0 ? data1 : data2;
3768 if (!state) continue;
3770 /* if toggling, then pick whether we're adding or removing */
3771 if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) {
3772 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
3774 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
3775 value = self->max_vert;
3776 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
3777 value = self->max_horz;
3778 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
3780 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
3781 value = self->skip_taskbar;
3782 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
3783 value = self->skip_pager;
3784 else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
3785 value = self->iconic;
3786 else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
3788 else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
3789 value = self->above;
3790 else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
3791 value = self->below;
3792 else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
3793 value = self->demands_attention;
3794 else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
3795 value = undecorated;
3797 g_assert_not_reached();
3798 action = value ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3799 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3802 value = action == OBT_PROP_ATOM(NET_WM_STATE_ADD);
3803 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3805 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3807 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3809 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3811 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3812 self->skip_taskbar = value;
3813 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3814 self->skip_pager = value;
3815 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3817 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3819 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3821 /* only unset below when setting above, otherwise you can't get to
3825 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3826 /* and vice versa */
3830 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3831 demands_attention = value;
3832 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3833 undecorated = value;
3837 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3838 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3840 if (max_horz == max_vert) { /* both going the same way */
3841 client_maximize(self, max_horz, 0);
3843 client_maximize(self, max_horz, 1);
3844 client_maximize(self, max_vert, 2);
3848 if (max_horz != self->max_horz)
3849 client_maximize(self, max_horz, 1);
3851 client_maximize(self, max_vert, 2);
3854 /* change fullscreen state before shading, as it will affect if the window
3856 if (fullscreen != self->fullscreen)
3857 client_fullscreen(self, fullscreen);
3858 if (shaded != self->shaded)
3859 client_shade(self, shaded);
3860 if (undecorated != self->undecorated)
3861 client_set_undecorated(self, undecorated);
3862 if (above != self->above || below != self->below) {
3863 self->above = above;
3864 self->below = below;
3865 client_calc_layer(self);
3868 if (modal != self->modal) {
3869 self->modal = modal;
3870 /* when a window changes modality, then its stacking order with its
3871 transients needs to change */
3872 stacking_raise(CLIENT_AS_WINDOW(self));
3874 /* it also may get focused. if something is focused that shouldn't
3875 be focused anymore, then move the focus */
3876 if (focus_client && client_focus_target(focus_client) != focus_client)
3877 client_focus(focus_client);
3880 if (iconic != self->iconic)
3881 client_iconify(self, iconic, FALSE, FALSE);
3883 if (demands_attention != self->demands_attention)
3884 client_hilite(self, demands_attention);
3886 client_change_state(self); /* change the hint to reflect these changes */
3888 focus_cycle_addremove(self, TRUE);
3891 ObClient *client_focus_target(ObClient *self)
3893 ObClient *child = NULL;
3895 child = client_search_modal_child(self);
3896 if (child) return child;
3900 gboolean client_can_focus(ObClient *self)
3902 /* choose the correct target */
3903 self = client_focus_target(self);
3905 if (!self->frame->visible)
3908 if (!(self->can_focus || self->focus_notify))
3914 gboolean client_focus(ObClient *self)
3916 if (!client_validate(self)) return FALSE;
3918 /* we might not focus this window, so if we have modal children which would
3919 be focused instead, bring them to this desktop */
3920 client_bring_modal_windows(self);
3922 /* choose the correct target */
3923 self = client_focus_target(self);
3925 if (!client_can_focus(self)) {
3926 ob_debug_type(OB_DEBUG_FOCUS,
3927 "Client %s can't be focused", self->title);
3931 ob_debug_type(OB_DEBUG_FOCUS,
3932 "Focusing client \"%s\" (0x%x) at time %u",
3933 self->title, self->window, event_time());
3935 /* if using focus_delay, stop the timer now so that focus doesn't
3937 event_halt_focus_delay();
3939 obt_display_ignore_errors(TRUE);
3941 if (self->can_focus) {
3942 /* This can cause a BadMatch error with CurrentTime, or if an app
3943 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3944 XSetInputFocus(obt_display, self->window, RevertToPointerRoot,
3948 if (self->focus_notify) {
3950 ce.xclient.type = ClientMessage;
3951 ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
3952 ce.xclient.display = obt_display;
3953 ce.xclient.window = self->window;
3954 ce.xclient.format = 32;
3955 ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS);
3956 ce.xclient.data.l[1] = event_time();
3957 ce.xclient.data.l[2] = 0l;
3958 ce.xclient.data.l[3] = 0l;
3959 ce.xclient.data.l[4] = 0l;
3960 XSendEvent(obt_display, self->window, FALSE, NoEventMask, &ce);
3963 obt_display_ignore_errors(FALSE);
3965 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d",
3966 obt_display_error_occured);
3967 return !obt_display_error_occured;
3970 static void client_present(ObClient *self, gboolean here, gboolean raise,
3973 if (client_normal(self) && screen_showing_desktop)
3974 screen_show_desktop(FALSE, self);
3976 client_iconify(self, FALSE, here, FALSE);
3977 if (self->desktop != DESKTOP_ALL &&
3978 self->desktop != screen_desktop)
3981 client_set_desktop(self, screen_desktop, FALSE, TRUE);
3983 screen_set_desktop(self->desktop, FALSE);
3984 } else if (!self->frame->visible)
3985 /* if its not visible for other reasons, then don't mess
3988 if (self->shaded && unshade)
3989 client_shade(self, FALSE);
3991 stacking_raise(CLIENT_AS_WINDOW(self));
3996 /* this function exists to map to the net_active_window message in the ewmh */
3997 void client_activate(ObClient *self, gboolean desktop,
3998 gboolean here, gboolean raise,
3999 gboolean unshade, gboolean user)
4001 self = client_focus_target(self);
4003 if (client_can_steal_focus(self, desktop, user, event_time(), CurrentTime))
4004 client_present(self, here, raise, unshade);
4006 client_hilite(self, TRUE);
4009 static void client_bring_windows_recursive(ObClient *self,
4017 for (it = self->transients; it; it = g_slist_next(it))
4018 client_bring_windows_recursive(it->data, desktop,
4019 helpers, modals, iconic);
4021 if (((helpers && client_helper(self)) ||
4022 (modals && self->modal)) &&
4023 ((self->desktop != desktop && self->desktop != DESKTOP_ALL) ||
4024 (iconic && self->iconic)))
4026 if (iconic && self->iconic)
4027 client_iconify(self, FALSE, TRUE, FALSE);
4029 client_set_desktop(self, desktop, FALSE, FALSE);
4033 void client_bring_helper_windows(ObClient *self)
4035 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE, FALSE);
4038 void client_bring_modal_windows(ObClient *self)
4040 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE, TRUE);
4043 gboolean client_focused(ObClient *self)
4045 return self == focus_client;
4048 RrImage* client_icon(ObClient *self)
4050 RrImage *ret = NULL;
4053 ret = self->icon_set;
4054 else if (self->parents) {
4056 for (it = self->parents; it && !ret; it = g_slist_next(it))
4057 ret = client_icon(it->data);
4060 ret = client_default_icon;
4064 void client_set_layer(ObClient *self, gint layer)
4068 self->above = FALSE;
4069 } else if (layer == 0) {
4070 self->below = self->above = FALSE;
4072 self->below = FALSE;
4075 client_calc_layer(self);
4076 client_change_state(self); /* reflect this in the state hints */
4079 void client_set_undecorated(ObClient *self, gboolean undecorated)
4081 if (self->undecorated != undecorated &&
4082 /* don't let it undecorate if the function is missing, but let
4084 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
4086 self->undecorated = undecorated;
4087 client_setup_decor_and_functions(self, TRUE);
4088 client_change_state(self); /* reflect this in the state hints */
4092 guint client_monitor(ObClient *self)
4094 return screen_find_monitor(&self->frame->area);
4097 ObClient *client_direct_parent(ObClient *self)
4099 if (!self->parents) return NULL;
4100 if (self->transient_for_group) return NULL;
4101 return self->parents->data;
4104 ObClient *client_search_top_direct_parent(ObClient *self)
4107 while ((p = client_direct_parent(self))) self = p;
4111 static GSList *client_search_all_top_parents_internal(ObClient *self,
4113 ObStackingLayer layer)
4118 /* move up the direct transient chain as far as possible */
4119 while ((p = client_direct_parent(self)) &&
4120 (!bylayer || p->layer == layer))
4124 ret = g_slist_prepend(NULL, self);
4126 ret = g_slist_copy(self->parents);
4131 GSList *client_search_all_top_parents(ObClient *self)
4133 return client_search_all_top_parents_internal(self, FALSE, 0);
4136 GSList *client_search_all_top_parents_layer(ObClient *self)
4138 return client_search_all_top_parents_internal(self, TRUE, self->layer);
4141 ObClient *client_search_focus_parent(ObClient *self)
4145 for (it = self->parents; it; it = g_slist_next(it))
4146 if (client_focused(it->data)) return it->data;
4151 ObClient *client_search_focus_parent_full(ObClient *self)
4154 ObClient *ret = NULL;
4156 for (it = self->parents; it; it = g_slist_next(it)) {
4157 if (client_focused(it->data))
4160 ret = client_search_focus_parent_full(it->data);
4166 ObClient *client_search_parent(ObClient *self, ObClient *search)
4170 for (it = self->parents; it; it = g_slist_next(it))
4171 if (it->data == search) return search;
4176 ObClient *client_search_transient(ObClient *self, ObClient *search)
4180 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
4181 if (sit->data == search)
4183 if (client_search_transient(sit->data, search))
4189 static void detect_edge(Rect area, ObDirection dir,
4190 gint my_head, gint my_size,
4191 gint my_edge_start, gint my_edge_size,
4192 gint *dest, gboolean *near_edge)
4194 gint edge_start, edge_size, head, tail;
4195 gboolean skip_head = FALSE, skip_tail = FALSE;
4198 case OB_DIRECTION_NORTH:
4199 case OB_DIRECTION_SOUTH:
4200 edge_start = area.x;
4201 edge_size = area.width;
4203 case OB_DIRECTION_EAST:
4204 case OB_DIRECTION_WEST:
4205 edge_start = area.y;
4206 edge_size = area.height;
4209 g_assert_not_reached();
4212 /* do we collide with this window? */
4213 if (!RANGES_INTERSECT(my_edge_start, my_edge_size,
4214 edge_start, edge_size))
4218 case OB_DIRECTION_NORTH:
4219 head = RECT_BOTTOM(area);
4220 tail = RECT_TOP(area);
4222 case OB_DIRECTION_SOUTH:
4223 head = RECT_TOP(area);
4224 tail = RECT_BOTTOM(area);
4226 case OB_DIRECTION_WEST:
4227 head = RECT_RIGHT(area);
4228 tail = RECT_LEFT(area);
4230 case OB_DIRECTION_EAST:
4231 head = RECT_LEFT(area);
4232 tail = RECT_RIGHT(area);
4235 g_assert_not_reached();
4238 case OB_DIRECTION_NORTH:
4239 case OB_DIRECTION_WEST:
4240 /* check if our window is past the head of this window */
4241 if (my_head <= head + 1)
4243 /* check if our window's tail is past the tail of this window */
4244 if (my_head + my_size - 1 <= tail)
4246 /* check if the head of this window is closer than the previously
4247 chosen edge (take into account that the previously chosen
4248 edge might have been a tail, not a head) */
4249 if (head + (*near_edge ? 0 : my_size) <= *dest)
4251 /* check if the tail of this window is closer than the previously
4252 chosen edge (take into account that the previously chosen
4253 edge might have been a head, not a tail) */
4254 if (tail - (!*near_edge ? 0 : my_size) <= *dest)
4257 case OB_DIRECTION_SOUTH:
4258 case OB_DIRECTION_EAST:
4259 /* check if our window is past the head of this window */
4260 if (my_head >= head - 1)
4262 /* check if our window's tail is past the tail of this window */
4263 if (my_head - my_size + 1 >= tail)
4265 /* check if the head of this window is closer than the previously
4266 chosen edge (take into account that the previously chosen
4267 edge might have been a tail, not a head) */
4268 if (head - (*near_edge ? 0 : my_size) >= *dest)
4270 /* check if the tail of this window is closer than the previously
4271 chosen edge (take into account that the previously chosen
4272 edge might have been a head, not a tail) */
4273 if (tail + (!*near_edge ? 0 : my_size) >= *dest)
4277 g_assert_not_reached();
4280 ob_debug("my head %d size %d", my_head, my_size);
4281 ob_debug("head %d tail %d dest %d", head, tail, *dest);
4283 ob_debug("using near edge %d", head);
4287 else if (!skip_tail) {
4288 ob_debug("using far edge %d", tail);
4294 void client_find_edge_directional(ObClient *self, ObDirection dir,
4295 gint my_head, gint my_size,
4296 gint my_edge_start, gint my_edge_size,
4297 gint *dest, gboolean *near_edge)
4305 a = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS,
4306 &self->frame->area);
4309 case OB_DIRECTION_NORTH:
4310 edge = RECT_TOP(*a) - 1;
4312 case OB_DIRECTION_SOUTH:
4313 edge = RECT_BOTTOM(*a) + 1;
4315 case OB_DIRECTION_EAST:
4316 edge = RECT_RIGHT(*a) + 1;
4318 case OB_DIRECTION_WEST:
4319 edge = RECT_LEFT(*a) - 1;
4322 g_assert_not_reached();
4324 /* default to the far edge, then narrow it down */
4328 /* search for edges of monitors */
4329 for (i = 0; i < screen_num_monitors; ++i) {
4330 Rect *area = screen_area(self->desktop, i, NULL);
4331 detect_edge(*area, dir, my_head, my_size, my_edge_start,
4332 my_edge_size, dest, near_edge);
4333 g_slice_free(Rect, area);
4336 /* search for edges of clients */
4337 for (it = client_list; it; it = g_list_next(it)) {
4338 ObClient *cur = it->data;
4340 /* skip windows to not bump into */
4345 if (self->desktop != cur->desktop && cur->desktop != DESKTOP_ALL &&
4346 cur->desktop != screen_desktop)
4349 ob_debug("trying window %s", cur->title);
4351 detect_edge(cur->frame->area, dir, my_head, my_size, my_edge_start,
4352 my_edge_size, dest, near_edge);
4354 dock_get_area(&dock_area);
4355 detect_edge(dock_area, dir, my_head, my_size, my_edge_start,
4356 my_edge_size, dest, near_edge);
4358 g_slice_free(Rect, a);
4361 void client_find_move_directional(ObClient *self, ObDirection dir,
4365 gint e, e_start, e_size;
4369 case OB_DIRECTION_EAST:
4370 head = RECT_RIGHT(self->frame->area);
4371 size = self->frame->area.width;
4372 e_start = RECT_TOP(self->frame->area);
4373 e_size = self->frame->area.height;
4375 case OB_DIRECTION_WEST:
4376 head = RECT_LEFT(self->frame->area);
4377 size = self->frame->area.width;
4378 e_start = RECT_TOP(self->frame->area);
4379 e_size = self->frame->area.height;
4381 case OB_DIRECTION_NORTH:
4382 head = RECT_TOP(self->frame->area);
4383 size = self->frame->area.height;
4384 e_start = RECT_LEFT(self->frame->area);
4385 e_size = self->frame->area.width;
4387 case OB_DIRECTION_SOUTH:
4388 head = RECT_BOTTOM(self->frame->area);
4389 size = self->frame->area.height;
4390 e_start = RECT_LEFT(self->frame->area);
4391 e_size = self->frame->area.width;
4394 g_assert_not_reached();
4397 client_find_edge_directional(self, dir, head, size,
4398 e_start, e_size, &e, &near);
4399 *x = self->frame->area.x;
4400 *y = self->frame->area.y;
4402 case OB_DIRECTION_EAST:
4403 if (near) e -= self->frame->area.width;
4407 case OB_DIRECTION_WEST:
4409 else e -= self->frame->area.width;
4412 case OB_DIRECTION_NORTH:
4414 else e -= self->frame->area.height;
4417 case OB_DIRECTION_SOUTH:
4418 if (near) e -= self->frame->area.height;
4423 g_assert_not_reached();
4425 frame_frame_gravity(self->frame, x, y);
4428 void client_find_resize_directional(ObClient *self, ObDirection side,
4430 gint *x, gint *y, gint *w, gint *h)
4433 gint e, e_start, e_size, delta;
4438 case OB_DIRECTION_EAST:
4439 head = RECT_RIGHT(self->frame->area) +
4440 (self->size_inc.width - 1) * (grow ? 1 : 0);
4441 e_start = RECT_TOP(self->frame->area);
4442 e_size = self->frame->area.height;
4443 dir = grow ? OB_DIRECTION_EAST : OB_DIRECTION_WEST;
4445 case OB_DIRECTION_WEST:
4446 head = RECT_LEFT(self->frame->area) -
4447 (self->size_inc.width - 1) * (grow ? 1 : 0);
4448 e_start = RECT_TOP(self->frame->area);
4449 e_size = self->frame->area.height;
4450 dir = grow ? OB_DIRECTION_WEST : OB_DIRECTION_EAST;
4452 case OB_DIRECTION_NORTH:
4453 head = RECT_TOP(self->frame->area) -
4454 (self->size_inc.height - 1) * (grow ? 1 : 0);
4455 e_start = RECT_LEFT(self->frame->area);
4456 e_size = self->frame->area.width;
4457 dir = grow ? OB_DIRECTION_NORTH : OB_DIRECTION_SOUTH;
4459 case OB_DIRECTION_SOUTH:
4460 head = RECT_BOTTOM(self->frame->area) +
4461 (self->size_inc.height - 1) * (grow ? 1 : 0);
4462 e_start = RECT_LEFT(self->frame->area);
4463 e_size = self->frame->area.width;
4464 dir = grow ? OB_DIRECTION_SOUTH : OB_DIRECTION_NORTH;
4467 g_assert_not_reached();
4470 ob_debug("head %d dir %d", head, dir);
4471 client_find_edge_directional(self, dir, head, 1,
4472 e_start, e_size, &e, &near);
4473 ob_debug("edge %d", e);
4474 *x = self->frame->area.x;
4475 *y = self->frame->area.y;
4476 *w = self->frame->area.width;
4477 *h = self->frame->area.height;
4479 case OB_DIRECTION_EAST:
4480 if (grow == near) --e;
4481 delta = e - RECT_RIGHT(self->frame->area);
4484 case OB_DIRECTION_WEST:
4485 if (grow == near) ++e;
4486 delta = RECT_LEFT(self->frame->area) - e;
4490 case OB_DIRECTION_NORTH:
4491 if (grow == near) ++e;
4492 delta = RECT_TOP(self->frame->area) - e;
4496 case OB_DIRECTION_SOUTH:
4497 if (grow == near) --e;
4498 delta = e - RECT_BOTTOM(self->frame->area);
4502 g_assert_not_reached();
4504 frame_frame_gravity(self->frame, x, y);
4505 *w -= self->frame->size.left + self->frame->size.right;
4506 *h -= self->frame->size.top + self->frame->size.bottom;
4509 ObClient* client_under_pointer(void)
4513 ObClient *ret = NULL;
4515 if (screen_pointer_pos(&x, &y)) {
4516 for (it = stacking_list; it; it = g_list_next(it)) {
4517 if (WINDOW_IS_CLIENT(it->data)) {
4518 ObClient *c = WINDOW_AS_CLIENT(it->data);
4519 if (c->frame->visible &&
4520 /* check the desktop, this is done during desktop
4521 switching and windows are shown/hidden status is not
4523 (c->desktop == screen_desktop ||
4524 c->desktop == DESKTOP_ALL) &&
4525 /* ignore all animating windows */
4526 !frame_iconify_animating(c->frame) &&
4527 RECT_CONTAINS(c->frame->area, x, y))
4538 gboolean client_has_group_siblings(ObClient *self)
4540 return self->group && self->group->members->next;
4543 gboolean client_has_relative(ObClient *self)
4545 return client_has_parent(self) ||
4546 client_has_group_siblings(self) ||
4547 client_has_children(self);
4550 /*! Returns TRUE if the client is running on the same machine as Openbox */
4551 gboolean client_on_localhost(ObClient *self)
4553 return self->client_machine == NULL;