1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
39 #include "menuframe.h"
42 #include "render/render.h"
45 #include <X11/Xutil.h>
47 /*! The event mask to grab on client windows */
48 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask)
50 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
55 ObClientDestructor func
;
59 GList
*client_list
= NULL
;
61 static GSList
*client_destructors
= NULL
;
62 static Time client_last_user_time
= CurrentTime
;
64 static void client_get_all(ObClient
*self
);
65 static void client_toggle_border(ObClient
*self
, gboolean show
);
66 static void client_get_startup_id(ObClient
*self
);
67 static void client_get_area(ObClient
*self
);
68 static void client_get_desktop(ObClient
*self
);
69 static void client_get_state(ObClient
*self
);
70 static void client_get_layer(ObClient
*self
);
71 static void client_get_shaped(ObClient
*self
);
72 static void client_get_mwm_hints(ObClient
*self
);
73 static void client_get_gravity(ObClient
*self
);
74 static void client_change_allowed_actions(ObClient
*self
);
75 static void client_change_state(ObClient
*self
);
76 static void client_change_wm_state(ObClient
*self
);
77 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
);
78 static void client_restore_session_state(ObClient
*self
);
79 static void client_restore_session_stacking(ObClient
*self
);
80 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
81 static void client_unfocus(ObClient
*self
);
83 void client_startup(gboolean reconfig
)
90 void client_shutdown(gboolean reconfig
)
94 void client_add_destructor(ObClientDestructor func
, gpointer data
)
96 Destructor
*d
= g_new(Destructor
, 1);
99 client_destructors
= g_slist_prepend(client_destructors
, d
);
102 void client_remove_destructor(ObClientDestructor func
)
106 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
107 Destructor
*d
= it
->data
;
108 if (d
->func
== func
) {
110 client_destructors
= g_slist_delete_link(client_destructors
, it
);
116 void client_set_list()
118 Window
*windows
, *win_it
;
120 guint size
= g_list_length(client_list
);
122 /* create an array of the window ids */
124 windows
= g_new(Window
, size
);
126 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
127 *win_it
= ((ObClient
*)it
->data
)->window
;
131 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
132 net_client_list
, window
, (gulong
*)windows
, size
);
141 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
145 for (it = self->transients; it; it = g_slist_next(it)) {
146 if (!func(it->data, data)) return;
147 client_foreach_transient(it->data, func, data);
151 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
153 if (self->transient_for) {
154 if (self->transient_for != OB_TRAN_GROUP) {
155 if (!func(self->transient_for, data)) return;
156 client_foreach_ancestor(self->transient_for, func, data);
160 for (it = self->group->members; it; it = g_slist_next(it))
161 if (it->data != self &&
162 !((ObClient*)it->data)->transient_for) {
163 if (!func(it->data, data)) return;
164 client_foreach_ancestor(it->data, func, data);
171 void client_manage_all()
176 XWindowAttributes attrib
;
178 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
179 &w
, &w
, &children
, &nchild
);
181 /* remove all icon windows from the list */
182 for (i
= 0; i
< nchild
; i
++) {
183 if (children
[i
] == None
) continue;
184 wmhints
= XGetWMHints(ob_display
, children
[i
]);
186 if ((wmhints
->flags
& IconWindowHint
) &&
187 (wmhints
->icon_window
!= children
[i
]))
188 for (j
= 0; j
< nchild
; j
++)
189 if (children
[j
] == wmhints
->icon_window
) {
197 for (i
= 0; i
< nchild
; ++i
) {
198 if (children
[i
] == None
)
200 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
201 if (attrib
.override_redirect
) continue;
203 if (attrib
.map_state
!= IsUnmapped
)
204 client_manage(children
[i
]);
210 void client_manage(Window window
)
214 XWindowAttributes attrib
;
215 XSetWindowAttributes attrib_set
;
217 gboolean activate
= FALSE
;
218 ObAppSettings
*settings
;
223 /* check if it has already been unmapped by the time we started mapping.
224 the grab does a sync so we don't have to here */
225 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
226 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
228 XPutBackEvent(ob_display
, &e
);
230 ob_debug("Trying to manage unmapped window. Aborting that.\n");
232 return; /* don't manage it */
235 /* make sure it isn't an override-redirect window */
236 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
237 attrib
.override_redirect
)
240 return; /* don't manage it */
243 /* is the window a docking app */
244 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
245 if ((wmhint
->flags
& StateHint
) &&
246 wmhint
->initial_state
== WithdrawnState
)
248 dock_add(window
, wmhint
);
256 ob_debug("Managing window: %lx\n", window
);
258 /* choose the events we want to receive on the CLIENT window */
259 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
260 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
261 XChangeWindowAttributes(ob_display
, window
,
262 CWEventMask
|CWDontPropagate
, &attrib_set
);
265 /* create the ObClient struct, and populate it from the hints on the
267 self
= g_new0(ObClient
, 1);
268 self
->obwin
.type
= Window_Client
;
269 self
->window
= window
;
271 /* non-zero defaults */
272 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
274 self
->desktop
= screen_num_desktops
; /* always an invalid value */
275 self
->user_time
= client_last_user_time
;
277 client_get_all(self
);
278 client_restore_session_state(self
);
279 /* per-app settings override stuff, and return the settings for other
281 settings
= client_get_settings_state(self
);
283 client_calc_layer(self
);
286 Time t
= sn_app_started(self
->startup_id
, self
->class);
287 if (t
) self
->user_time
= t
;
290 /* update the focus lists, do this before the call to change_state or
291 it can end up in the list twice! */
292 focus_order_add_new(self
);
294 /* remove the client's border (and adjust re gravity) */
295 client_toggle_border(self
, FALSE
);
297 /* specify that if we exit, the window should not be destroyed and should
298 be reparented back to root automatically */
299 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
301 /* create the decoration frame for the client window */
302 self
->frame
= frame_new(self
);
304 frame_grab_client(self
->frame
, self
);
306 /* do this after we have a frame.. it uses the frame to help determine the
307 WM_STATE to apply. */
308 client_change_state(self
);
312 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
313 client_restore_session_stacking(self
);
315 /* focus the new window? */
316 if (ob_state() != OB_STATE_STARTING
&&
317 /* this means focus=true for window is same as config_focus_new=true */
318 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
319 client_search_focus_parent(self
)) &&
320 /* this checks for focus=false for the window */
321 (!settings
|| settings
->focus
!= 0) &&
322 /* note the check against Type_Normal/Dialog, not client_normal(self),
323 which would also include other types. in this case we want more
324 strict rules for focus */
325 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
326 self
->type
== OB_CLIENT_TYPE_DIALOG
))
330 if (self
->desktop
!= screen_desktop
) {
331 /* activate the window */
334 gboolean group_foc
= FALSE
;
339 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
341 if (client_focused(it
->data
))
349 (!self
->transient_for
&& (!self
->group
||
350 !self
->group
->members
->next
))) ||
351 client_search_focus_tree_full(self
) ||
353 !client_normal(focus_client
))
355 /* activate the window */
362 /* get the current position */
366 /* figure out placement for the window */
367 if (ob_state() == OB_STATE_RUNNING
) {
370 transient
= place_client(self
, &newx
, &newy
, settings
);
372 /* make sure the window is visible. */
373 client_find_onscreen(self
, &newx
, &newy
,
374 self
->frame
->area
.width
,
375 self
->frame
->area
.height
,
376 /* non-normal clients has less rules, and
377 windows that are being restored from a
378 session do also. we can assume you want
379 it back where you saved it. Clients saying
380 they placed themselves are subjected to
381 harder rules, ones that are placed by
382 place.c or by the user are allowed partially
383 off-screen and on xinerama divides (ie,
384 it is up to the placement routines to avoid
385 the xinerama divides) */
387 (((self
->positioned
& PPosition
) &&
388 !(self
->positioned
& USPosition
)) &&
389 client_normal(self
) &&
393 /* do this after the window is placed, so the premax/prefullscreen numbers
395 also, this moves the window to the position where it has been placed
397 ob_debug("placing window 0x%x at %d, %d with size %d x %d\n",
398 self
->window
, newx
, newy
, self
->area
.width
, self
->area
.height
);
399 client_apply_startup_state(self
, newx
, newy
);
401 keyboard_grab_for_client(self
, TRUE
);
402 mouse_grab_for_client(self
, TRUE
);
405 /* This is focus stealing prevention */
406 ob_debug("Want to focus new window 0x%x with time %u (last time %u)\n",
407 self
->window
, self
->user_time
, client_last_user_time
);
409 /* If a nothing at all, or a parent was focused, then focus this
412 if (!focus_client
|| client_search_focus_parent(self
) != NULL
)
416 /* If time stamp is old, don't steal focus */
417 if (self
->user_time
&&
418 !event_time_after(self
->user_time
, client_last_user_time
))
422 /* Don't steal focus from globally active clients.
423 I stole this idea from KWin. It seems nice.
425 if (!(focus_client
->can_focus
|| focus_client
->focus_notify
))
431 /* since focus can change the stacking orders, if we focus the
432 window then the standard raise it gets is not enough, we need
433 to queue one for after the focus change takes place */
436 ob_debug("Focus stealing prevention activated for %s with time %u "
438 self
->title
, self
->user_time
, client_last_user_time
);
439 /* if the client isn't focused, then hilite it so the user
441 client_hilite(self
, TRUE
);
445 /* This may look rather odd. Well it's because new windows are added
446 to the stacking order non-intrusively. If we're not going to focus
447 the new window or hilite it, then we raise it to the top. This will
448 take affect for things that don't get focused like splash screens.
449 Also if you don't have focus_new enabled, then it's going to get
450 raised to the top. Legacy begets legacy I guess?
455 /* this has to happen before we try focus the window, but we want it to
456 happen after the client's stacking has been determined or it looks bad
458 client_showhide(self
);
460 /* use client_focus instead of client_activate cuz client_activate does
461 stuff like switch desktops etc and I'm not interested in all that when
462 a window maps since its not based on an action from the user like
463 clicking a window to activate it. so keep the new window out of the way
466 /* if using focus_delay, stop the timer now so that focus doesn't
468 event_halt_focus_delay();
472 /* client_activate does this but we aret using it so we have to do it
474 if (screen_showing_desktop
)
475 screen_show_desktop(FALSE
);
477 /* add to client list/map */
478 client_list
= g_list_append(client_list
, self
);
479 g_hash_table_insert(window_map
, &self
->window
, self
);
481 /* this has to happen after we're in the client_list */
482 if (STRUT_EXISTS(self
->strut
))
483 screen_update_areas();
485 /* update the list hints */
488 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
491 void client_unmanage_all()
493 while (client_list
!= NULL
)
494 client_unmanage(client_list
->data
);
497 void client_unmanage(ObClient
*self
)
502 ob_debug("Unmanaging window: %lx (%s) (%s)\n", self
->window
, self
->class,
503 self
->title
? self
->title
: "");
505 g_assert(self
!= NULL
);
507 /* update the focus lists */
508 focus_order_remove(self
);
510 if (focus_client
== self
) {
513 /* focus the last focused window on the desktop, and ignore enter
514 events from the unmap so it doesnt mess with the focus */
515 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
516 /* remove these flags so we don't end up getting focused in the
518 self
->can_focus
= FALSE
;
519 self
->focus_notify
= FALSE
;
521 client_unfocus(self
);
524 /* potentially fix focusLast */
525 if (config_focus_last
)
526 grab_pointer(TRUE
, OB_CURSOR_NONE
);
528 frame_hide(self
->frame
);
531 keyboard_grab_for_client(self
, FALSE
);
532 mouse_grab_for_client(self
, FALSE
);
534 /* remove the window from our save set */
535 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
537 /* we dont want events no more */
538 XSelectInput(ob_display
, self
->window
, NoEventMask
);
540 client_list
= g_list_remove(client_list
, self
);
541 stacking_remove(self
);
542 g_hash_table_remove(window_map
, &self
->window
);
544 /* once the client is out of the list, update the struts to remove its
546 if (STRUT_EXISTS(self
->strut
))
547 screen_update_areas();
549 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
550 Destructor
*d
= it
->data
;
551 d
->func(self
, d
->data
);
554 /* tell our parent(s) that we're gone */
555 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
556 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
557 if (it
->data
!= self
)
558 ((ObClient
*)it
->data
)->transients
=
559 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
560 } else if (self
->transient_for
) { /* transient of window */
561 self
->transient_for
->transients
=
562 g_slist_remove(self
->transient_for
->transients
, self
);
565 /* tell our transients that we're gone */
566 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
567 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
568 ((ObClient
*)it
->data
)->transient_for
= NULL
;
569 client_calc_layer(it
->data
);
573 /* remove from its group */
575 group_remove(self
->group
, self
);
579 /* give the client its border back */
580 client_toggle_border(self
, TRUE
);
582 /* reparent the window out of the frame, and free the frame */
583 frame_release_client(self
->frame
, self
);
586 /* restore the window's original geometry so it is not lost */
587 if (self
->fullscreen
)
588 XMoveResizeWindow(ob_display
, self
->window
,
589 self
->pre_fullscreen_area
.x
,
590 self
->pre_fullscreen_area
.y
,
591 self
->pre_fullscreen_area
.width
,
592 self
->pre_fullscreen_area
.height
);
593 else if (self
->max_horz
|| self
->max_vert
) {
595 if (self
->max_horz
) {
596 a
.x
= self
->pre_max_area
.x
;
597 a
.width
= self
->pre_max_area
.width
;
599 if (self
->max_vert
) {
600 a
.y
= self
->pre_max_area
.y
;
601 a
.height
= self
->pre_max_area
.height
;
603 XMoveResizeWindow(ob_display
, self
->window
,
604 a
.x
, a
.y
, a
.width
, a
.height
);
607 if (ob_state() != OB_STATE_EXITING
) {
608 /* these values should not be persisted across a window
610 PROP_ERASE(self
->window
, net_wm_desktop
);
611 PROP_ERASE(self
->window
, net_wm_state
);
612 PROP_ERASE(self
->window
, wm_state
);
614 /* if we're left in an unmapped state, the client wont be mapped. this
615 is bad, since we will no longer be managing the window on restart */
616 XMapWindow(ob_display
, self
->window
);
620 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
622 /* free all data allocated in the client struct */
623 g_slist_free(self
->transients
);
624 for (j
= 0; j
< self
->nicons
; ++j
)
625 g_free(self
->icons
[j
].data
);
626 if (self
->nicons
> 0)
629 g_free(self
->icon_title
);
633 g_free(self
->sm_client_id
);
636 /* update the list hints */
639 if (config_focus_last
)
640 grab_pointer(FALSE
, OB_CURSOR_NONE
);
643 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
645 ObAppSettings
*settings
= NULL
;
648 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
649 ObAppSettings
*app
= it
->data
;
651 if ((app
->name
&& !app
->class && !strcmp(app
->name
, self
->name
))
652 || (app
->class && !app
->name
&& !strcmp(app
->class, self
->class))
653 || (app
->class && app
->name
&& !strcmp(app
->class, self
->class)
654 && !strcmp(app
->name
, self
->name
)))
656 ob_debug("Window matching: %s\n", app
->name
);
657 /* Match if no role was specified in the per app setting, or if the
658 * string matches the beginning of the role, since apps like to set
659 * the role to things like browser-window-23c4b2f */
661 || !strncmp(app
->role
, self
->role
, strlen(app
->role
)))
671 if (settings
->shade
!= -1)
672 self
->shaded
= !!settings
->shade
;
673 if (settings
->decor
!= -1)
674 self
->undecorated
= !settings
->decor
;
675 if (settings
->iconic
!= -1)
676 self
->iconic
= !!settings
->iconic
;
677 if (settings
->skip_pager
!= -1)
678 self
->skip_pager
= !!settings
->skip_pager
;
679 if (settings
->skip_taskbar
!= -1)
680 self
->skip_taskbar
= !!settings
->skip_taskbar
;
682 if (settings
->max_vert
!= -1)
683 self
->max_vert
= !!settings
->max_vert
;
684 if (settings
->max_horz
!= -1)
685 self
->max_vert
= !!settings
->max_horz
;
687 if (settings
->fullscreen
!= -1)
688 self
->fullscreen
= !!settings
->fullscreen
;
690 if (settings
->desktop
< screen_num_desktops
691 || settings
->desktop
== DESKTOP_ALL
)
692 client_set_desktop(self
, settings
->desktop
, TRUE
);
694 if (settings
->layer
== -1) {
698 else if (settings
->layer
== 0) {
702 else if (settings
->layer
== 1) {
710 static void client_restore_session_state(ObClient
*self
)
714 if (!(it
= session_state_find(self
)))
717 self
->session
= it
->data
;
719 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
720 self
->positioned
= PPosition
;
721 if (self
->session
->w
> 0)
722 self
->area
.width
= self
->session
->w
;
723 if (self
->session
->h
> 0)
724 self
->area
.height
= self
->session
->h
;
725 XResizeWindow(ob_display
, self
->window
,
726 self
->area
.width
, self
->area
.height
);
728 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
729 self
->session
->desktop
:
730 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
731 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
733 self
->shaded
= self
->session
->shaded
;
734 self
->iconic
= self
->session
->iconic
;
735 self
->skip_pager
= self
->session
->skip_pager
;
736 self
->skip_taskbar
= self
->session
->skip_taskbar
;
737 self
->fullscreen
= self
->session
->fullscreen
;
738 self
->above
= self
->session
->above
;
739 self
->below
= self
->session
->below
;
740 self
->max_horz
= self
->session
->max_horz
;
741 self
->max_vert
= self
->session
->max_vert
;
744 static void client_restore_session_stacking(ObClient
*self
)
748 if (!self
->session
) return;
750 it
= g_list_find(session_saved_state
, self
->session
);
751 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
754 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
755 if (session_state_cmp(it
->data
, cit
->data
))
758 client_calc_layer(self
);
759 stacking_below(CLIENT_AS_WINDOW(self
),
760 CLIENT_AS_WINDOW(cit
->data
));
766 void client_move_onscreen(ObClient
*self
, gboolean rude
)
768 gint x
= self
->area
.x
;
769 gint y
= self
->area
.y
;
770 if (client_find_onscreen(self
, &x
, &y
,
771 self
->frame
->area
.width
,
772 self
->frame
->area
.height
, rude
)) {
773 client_move(self
, x
, y
);
777 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
781 gint ox
= *x
, oy
= *y
;
783 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
786 /* XXX watch for xinerama dead areas */
787 /* This makes sure windows aren't entirely outside of the screen so you
788 can't see them at all.
789 It makes sure 10% of the window is on the screen at least. At don't let
790 it move itself off the top of the screen, which would hide the titlebar
791 on you. (The user can still do this if they want too, it's only limiting
794 if (client_normal(self
)) {
795 a
= screen_area(self
->desktop
);
796 if (!self
->strut
.right
&&
797 *x
+ self
->frame
->area
.width
/10 >= a
->x
+ a
->width
- 1)
798 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
/10;
799 if (!self
->strut
.bottom
&&
800 *y
+ self
->frame
->area
.height
/10 >= a
->y
+ a
->height
- 1)
801 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
/10;
802 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
*9/10 - 1 < a
->x
)
803 *x
= a
->x
- self
->frame
->area
.width
*9/10;
804 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
*9/10 - 1 < a
->y
)
805 *y
= a
->y
- self
->frame
->area
.width
*9/10;
808 /* This here doesn't let windows even a pixel outside the screen,
809 * when called from client_manage, programs placing themselves are
810 * forced completely onscreen, while things like
811 * xterm -geometry resolution-width/2 will work fine. Trying to
812 * place it completely offscreen will be handled in the above code.
813 * Sorry for this confused comment, i am tired. */
815 /* avoid the xinerama monitor divide while we're at it,
816 * remember to fix the placement stuff to avoid it also and
817 * then remove this XXX */
818 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
819 /* dont let windows map into the strut unless they
820 are bigger than the available area */
822 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
823 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
824 *x
= a
->x
+ a
->width
- w
;
826 if (h
<= a
->height
) {
827 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
828 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
829 *y
= a
->y
+ a
->height
- h
;
833 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
836 return ox
!= *x
|| oy
!= *y
;
839 static void client_toggle_border(ObClient
*self
, gboolean show
)
841 /* adjust our idea of where the client is, based on its border. When the
842 border is removed, the client should now be considered to be in a
844 when re-adding the border to the client, the same operation needs to be
846 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
847 gint x
= oldx
, y
= oldy
;
848 switch(self
->gravity
) {
850 case NorthWestGravity
:
852 case SouthWestGravity
:
854 case NorthEastGravity
:
856 case SouthEastGravity
:
857 if (show
) x
-= self
->border_width
* 2;
858 else x
+= self
->border_width
* 2;
865 if (show
) x
-= self
->border_width
;
866 else x
+= self
->border_width
;
869 switch(self
->gravity
) {
871 case NorthWestGravity
:
873 case NorthEastGravity
:
875 case SouthWestGravity
:
877 case SouthEastGravity
:
878 if (show
) y
-= self
->border_width
* 2;
879 else y
+= self
->border_width
* 2;
886 if (show
) y
-= self
->border_width
;
887 else y
+= self
->border_width
;
894 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
896 /* move the client so it is back it the right spot _with_ its
898 if (x
!= oldx
|| y
!= oldy
)
899 XMoveWindow(ob_display
, self
->window
, x
, y
);
901 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
905 static void client_get_all(ObClient
*self
)
907 client_get_area(self
);
908 client_get_mwm_hints(self
);
910 /* The transient hint is used to pick a type, but the type can also affect
911 transiency (dialogs are always made transients of their group if they
912 have one). This is Havoc's idea, but it is needed to make some apps
913 work right (eg tsclient). */
914 client_update_transient_for(self
);
915 client_get_type(self
);/* this can change the mwmhints for special cases */
916 client_get_state(self
);
917 client_update_transient_for(self
);
919 client_update_wmhints(self
);
920 client_get_startup_id(self
);
921 client_get_desktop(self
);/* uses transient data/group/startup id if a
922 desktop is not specified */
923 client_get_shaped(self
);
925 client_get_layer(self
); /* if layer hasn't been specified, get it from
926 other sources if possible */
929 /* a couple type-based defaults for new windows */
931 /* this makes sure that these windows appear on all desktops */
932 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
933 self
->desktop
= DESKTOP_ALL
;
936 client_update_protocols(self
);
938 client_get_gravity(self
); /* get the attribute gravity */
939 client_update_normal_hints(self
); /* this may override the attribute
942 /* got the type, the mwmhints, the protocols, and the normal hints
943 (min/max sizes), so we're ready to set up the decorations/functions */
944 client_setup_decor_and_functions(self
);
946 client_update_title(self
);
947 client_update_class(self
);
948 client_update_sm_client_id(self
);
949 client_update_strut(self
);
950 client_update_icons(self
);
951 client_update_user_time(self
, FALSE
);
954 static void client_get_startup_id(ObClient
*self
)
956 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
958 PROP_GETS(self
->group
->leader
,
959 net_startup_id
, utf8
, &self
->startup_id
);
962 static void client_get_area(ObClient
*self
)
964 XWindowAttributes wattrib
;
967 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
968 g_assert(ret
!= BadWindow
);
970 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
971 self
->border_width
= wattrib
.border_width
;
973 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
974 wattrib
.width
, wattrib
.height
);
977 static void client_get_desktop(ObClient
*self
)
979 guint32 d
= screen_num_desktops
; /* an always-invalid value */
981 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
982 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
983 self
->desktop
= screen_num_desktops
- 1;
987 gboolean trdesk
= FALSE
;
989 if (self
->transient_for
) {
990 if (self
->transient_for
!= OB_TRAN_GROUP
) {
991 self
->desktop
= self
->transient_for
->desktop
;
996 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
997 if (it
->data
!= self
&&
998 !((ObClient
*)it
->data
)->transient_for
) {
999 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
1006 /* try get from the startup-notification protocol */
1007 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1008 if (self
->desktop
>= screen_num_desktops
&&
1009 self
->desktop
!= DESKTOP_ALL
)
1010 self
->desktop
= screen_num_desktops
- 1;
1012 /* defaults to the current desktop */
1013 self
->desktop
= screen_desktop
;
1016 if (self
->desktop
!= d
) {
1017 /* set the desktop hint, to make sure that it always exists */
1018 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
1022 static void client_get_layer(ObClient
*self
)
1024 if (!(self
->above
|| self
->below
)) {
1026 /* apply stuff from the group */
1030 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1031 ObClient
*c
= it
->data
;
1032 if (c
!= self
&& !client_search_transient(self
, c
) &&
1033 client_normal(self
) && client_normal(c
))
1036 (c
->above
? 1 : (c
->below
? -1 : 0)));
1050 g_assert_not_reached();
1057 static void client_get_state(ObClient
*self
)
1062 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1064 for (i
= 0; i
< num
; ++i
) {
1065 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1067 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1068 self
->shaded
= TRUE
;
1069 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1070 self
->iconic
= TRUE
;
1071 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1072 self
->skip_taskbar
= TRUE
;
1073 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1074 self
->skip_pager
= TRUE
;
1075 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1076 self
->fullscreen
= TRUE
;
1077 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1078 self
->max_vert
= TRUE
;
1079 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1080 self
->max_horz
= TRUE
;
1081 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1083 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1085 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1086 self
->demands_attention
= TRUE
;
1087 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1088 self
->undecorated
= TRUE
;
1095 static void client_get_shaped(ObClient
*self
)
1097 self
->shaped
= FALSE
;
1099 if (extensions_shape
) {
1104 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1106 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1107 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1109 self
->shaped
= (s
!= 0);
1114 void client_update_transient_for(ObClient
*self
)
1117 ObClient
*target
= NULL
;
1119 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1120 self
->transient
= TRUE
;
1121 if (t
!= self
->window
) { /* cant be transient to itself! */
1122 target
= g_hash_table_lookup(window_map
, &t
);
1123 /* if this happens then we need to check for it*/
1124 g_assert(target
!= self
);
1125 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1126 /* this can happen when a dialog is a child of
1127 a dockapp, for example */
1131 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1133 Setting the transient_for to Root is actually illegal, however
1134 applications from time have done this to specify transient for
1137 Now you can do that by being a TYPE_DIALOG and not setting
1138 the transient_for hint at all on your window. But people still
1139 use Root, and Kwin is very strange in this regard.
1141 KWin 3.0 will not consider windows with transient_for set to
1142 Root as transient for their group *UNLESS* they are also modal.
1143 In that case, it will make them transient for the group. This
1144 leads to all sorts of weird behavior from KDE apps which are
1145 only tested in KWin. I'd like to follow their behavior just to
1146 make this work right with KDE stuff, but that seems wrong.
1148 if (!target
&& self
->group
) {
1149 /* not transient to a client, see if it is transient for a
1151 if (t
== RootWindow(ob_display
, ob_screen
)) {
1152 /* window is a transient for its group! */
1153 target
= OB_TRAN_GROUP
;
1157 } else if (self
->group
) {
1158 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1159 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1160 self
->type
== OB_CLIENT_TYPE_MENU
||
1161 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1163 self
->transient
= TRUE
;
1164 target
= OB_TRAN_GROUP
;
1167 self
->transient
= FALSE
;
1169 /* if anything has changed... */
1170 if (target
!= self
->transient_for
) {
1171 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1174 /* remove from old parents */
1175 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1176 ObClient
*c
= it
->data
;
1177 if (c
!= self
&& !c
->transient_for
)
1178 c
->transients
= g_slist_remove(c
->transients
, self
);
1180 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1181 /* remove from old parent */
1182 self
->transient_for
->transients
=
1183 g_slist_remove(self
->transient_for
->transients
, self
);
1185 self
->transient_for
= target
;
1186 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1189 /* add to new parents */
1190 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1191 ObClient
*c
= it
->data
;
1192 if (c
!= self
&& !c
->transient_for
)
1193 c
->transients
= g_slist_append(c
->transients
, self
);
1196 /* remove all transients which are in the group, that causes
1197 circlular pointer hell of doom */
1198 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1200 for (sit
= self
->transients
; sit
; sit
= next
) {
1201 next
= g_slist_next(sit
);
1202 if (sit
->data
== it
->data
)
1204 g_slist_delete_link(self
->transients
, sit
);
1207 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1208 /* add to new parent */
1209 self
->transient_for
->transients
=
1210 g_slist_append(self
->transient_for
->transients
, self
);
1215 static void client_get_mwm_hints(ObClient
*self
)
1220 self
->mwmhints
.flags
= 0; /* default to none */
1222 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1224 if (num
>= OB_MWM_ELEMENTS
) {
1225 self
->mwmhints
.flags
= hints
[0];
1226 self
->mwmhints
.functions
= hints
[1];
1227 self
->mwmhints
.decorations
= hints
[2];
1233 void client_get_type(ObClient
*self
)
1240 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1241 /* use the first value that we know about in the array */
1242 for (i
= 0; i
< num
; ++i
) {
1243 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1244 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1245 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1246 self
->type
= OB_CLIENT_TYPE_DOCK
;
1247 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1248 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1249 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1250 self
->type
= OB_CLIENT_TYPE_MENU
;
1251 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1252 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1253 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1254 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1255 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1256 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1257 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1258 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1259 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1260 /* prevent this window from getting any decor or
1262 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1263 OB_MWM_FLAG_DECORATIONS
);
1264 self
->mwmhints
.decorations
= 0;
1265 self
->mwmhints
.functions
= 0;
1267 if (self
->type
!= (ObClientType
) -1)
1268 break; /* grab the first legit type */
1273 if (self
->type
== (ObClientType
) -1) {
1274 /*the window type hint was not set, which means we either classify
1275 ourself as a normal window or a dialog, depending on if we are a
1277 if (self
->transient
)
1278 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1280 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1284 void client_update_protocols(ObClient
*self
)
1287 guint num_return
, i
;
1289 self
->focus_notify
= FALSE
;
1290 self
->delete_window
= FALSE
;
1292 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1293 for (i
= 0; i
< num_return
; ++i
) {
1294 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1295 /* this means we can request the window to close */
1296 self
->delete_window
= TRUE
;
1297 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1298 /* if this protocol is requested, then the window will be
1299 notified whenever we want it to receive focus */
1300 self
->focus_notify
= TRUE
;
1306 static void client_get_gravity(ObClient
*self
)
1308 XWindowAttributes wattrib
;
1311 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1312 g_assert(ret
!= BadWindow
);
1313 self
->gravity
= wattrib
.win_gravity
;
1316 void client_update_normal_hints(ObClient
*self
)
1320 gint oldgravity
= self
->gravity
;
1323 self
->min_ratio
= 0.0f
;
1324 self
->max_ratio
= 0.0f
;
1325 SIZE_SET(self
->size_inc
, 1, 1);
1326 SIZE_SET(self
->base_size
, 0, 0);
1327 SIZE_SET(self
->min_size
, 0, 0);
1328 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1330 /* get the hints from the window */
1331 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1332 /* normal windows can't request placement! har har
1333 if (!client_normal(self))
1335 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1337 if (size
.flags
& PWinGravity
) {
1338 self
->gravity
= size
.win_gravity
;
1340 /* if the client has a frame, i.e. has already been mapped and
1341 is changing its gravity */
1342 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1343 /* move our idea of the client's position based on its new
1345 self
->area
.x
= self
->frame
->area
.x
;
1346 self
->area
.y
= self
->frame
->area
.y
;
1347 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1351 if (size
.flags
& PAspect
) {
1352 if (size
.min_aspect
.y
)
1354 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1355 if (size
.max_aspect
.y
)
1357 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1360 if (size
.flags
& PMinSize
)
1361 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1363 if (size
.flags
& PMaxSize
)
1364 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1366 if (size
.flags
& PBaseSize
)
1367 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1369 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1370 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1374 void client_setup_decor_and_functions(ObClient
*self
)
1376 /* start with everything (cept fullscreen) */
1378 (OB_FRAME_DECOR_TITLEBAR
|
1379 OB_FRAME_DECOR_HANDLE
|
1380 OB_FRAME_DECOR_GRIPS
|
1381 OB_FRAME_DECOR_BORDER
|
1382 OB_FRAME_DECOR_ICON
|
1383 OB_FRAME_DECOR_ALLDESKTOPS
|
1384 OB_FRAME_DECOR_ICONIFY
|
1385 OB_FRAME_DECOR_MAXIMIZE
|
1386 OB_FRAME_DECOR_SHADE
|
1387 OB_FRAME_DECOR_CLOSE
);
1389 (OB_CLIENT_FUNC_RESIZE
|
1390 OB_CLIENT_FUNC_MOVE
|
1391 OB_CLIENT_FUNC_ICONIFY
|
1392 OB_CLIENT_FUNC_MAXIMIZE
|
1393 OB_CLIENT_FUNC_SHADE
|
1394 OB_CLIENT_FUNC_CLOSE
);
1396 if (!(self
->min_size
.width
< self
->max_size
.width
||
1397 self
->min_size
.height
< self
->max_size
.height
))
1398 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1400 switch (self
->type
) {
1401 case OB_CLIENT_TYPE_NORMAL
:
1402 /* normal windows retain all of the possible decorations and
1403 functionality, and are the only windows that you can fullscreen */
1404 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1407 case OB_CLIENT_TYPE_DIALOG
:
1408 case OB_CLIENT_TYPE_UTILITY
:
1409 /* these windows cannot be maximized */
1410 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1413 case OB_CLIENT_TYPE_MENU
:
1414 case OB_CLIENT_TYPE_TOOLBAR
:
1415 /* these windows get less functionality */
1416 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1419 case OB_CLIENT_TYPE_DESKTOP
:
1420 case OB_CLIENT_TYPE_DOCK
:
1421 case OB_CLIENT_TYPE_SPLASH
:
1422 /* none of these windows are manipulated by the window manager */
1423 self
->decorations
= 0;
1424 self
->functions
= 0;
1428 /* Mwm Hints are applied subtractively to what has already been chosen for
1429 decor and functionality */
1430 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1431 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1432 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1433 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1435 /* if the mwm hints request no handle or title, then all
1436 decorations are disabled, but keep the border if that's
1438 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1439 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1441 self
->decorations
= 0;
1446 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1447 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1448 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1449 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1450 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1451 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1452 /* dont let mwm hints kill any buttons
1453 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1454 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1455 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1456 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1458 /* dont let mwm hints kill the close button
1459 if (! (self->mwmhints.functions & MwmFunc_Close))
1460 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1464 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1465 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1466 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1467 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1468 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1469 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1471 /* can't maximize without moving/resizing */
1472 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1473 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1474 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1475 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1476 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1479 /* kill the handle on fully maxed windows */
1480 if (self
->max_vert
&& self
->max_horz
)
1481 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1483 /* finally, the user can have requested no decorations, which overrides
1484 everything (but doesnt give it a border if it doesnt have one) */
1485 if (self
->undecorated
) {
1486 if (config_theme_keepborder
)
1487 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1489 self
->decorations
= 0;
1492 /* if we don't have a titlebar, then we cannot shade! */
1493 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1494 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1496 /* now we need to check against rules for the client's current state */
1497 if (self
->fullscreen
) {
1498 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1499 OB_CLIENT_FUNC_FULLSCREEN
|
1500 OB_CLIENT_FUNC_ICONIFY
);
1501 self
->decorations
= 0;
1504 client_change_allowed_actions(self
);
1507 /* adjust the client's decorations, etc. */
1508 client_reconfigure(self
);
1512 static void client_change_allowed_actions(ObClient
*self
)
1517 /* desktop windows are kept on all desktops */
1518 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1519 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1521 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1522 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1523 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1524 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1525 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1526 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1527 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1528 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1529 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1530 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1531 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1532 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1533 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1534 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1535 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1538 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1540 /* make sure the window isn't breaking any rules now */
1542 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1543 if (self
->frame
) client_shade(self
, FALSE
);
1544 else self
->shaded
= FALSE
;
1546 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1547 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1548 else self
->iconic
= FALSE
;
1550 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1551 if (self
->frame
) client_fullscreen(self
, FALSE
);
1552 else self
->fullscreen
= FALSE
;
1554 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1556 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1557 else self
->max_vert
= self
->max_horz
= FALSE
;
1561 void client_reconfigure(ObClient
*self
)
1563 /* by making this pass FALSE for user, we avoid the emacs event storm where
1564 every configurenotify causes an update in its normal hints, i think this
1565 is generally what we want anyways... */
1566 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1567 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1570 void client_update_wmhints(ObClient
*self
)
1575 /* assume a window takes input if it doesnt specify */
1576 self
->can_focus
= TRUE
;
1578 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1579 if (hints
->flags
& InputHint
)
1580 self
->can_focus
= hints
->input
;
1582 /* only do this when first managing the window *AND* when we aren't
1584 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1585 if (hints
->flags
& StateHint
)
1586 self
->iconic
= hints
->initial_state
== IconicState
;
1588 if (!(hints
->flags
& WindowGroupHint
))
1589 hints
->window_group
= None
;
1591 /* did the group state change? */
1592 if (hints
->window_group
!=
1593 (self
->group
? self
->group
->leader
: None
)) {
1594 /* remove from the old group if there was one */
1595 if (self
->group
!= NULL
) {
1596 /* remove transients of the group */
1597 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1598 self
->transients
= g_slist_remove(self
->transients
,
1601 /* remove myself from parents in the group */
1602 if (self
->transient_for
== OB_TRAN_GROUP
) {
1603 for (it
= self
->group
->members
; it
;
1604 it
= g_slist_next(it
))
1606 ObClient
*c
= it
->data
;
1608 if (c
!= self
&& !c
->transient_for
)
1609 c
->transients
= g_slist_remove(c
->transients
,
1614 group_remove(self
->group
, self
);
1617 if (hints
->window_group
!= None
) {
1618 self
->group
= group_add(hints
->window_group
, self
);
1620 /* i can only have transients from the group if i am not
1622 if (!self
->transient_for
) {
1623 /* add other transients of the group that are already
1625 for (it
= self
->group
->members
; it
;
1626 it
= g_slist_next(it
))
1628 ObClient
*c
= it
->data
;
1629 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1631 g_slist_append(self
->transients
, c
);
1636 /* because the self->transient flag wont change from this call,
1637 we don't need to update the window's type and such, only its
1638 transient_for, and the transients lists of other windows in
1639 the group may be affected */
1640 client_update_transient_for(self
);
1643 /* the WM_HINTS can contain an icon */
1644 client_update_icons(self
);
1650 void client_update_title(ObClient
*self
)
1654 g_free(self
->title
);
1657 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1658 /* try old x stuff */
1659 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1660 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1661 if (self
->transient
) {
1663 GNOME alert windows are not given titles:
1664 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1666 data
= g_strdup("");
1668 data
= g_strdup("Unnamed Window");
1672 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1676 frame_adjust_title(self
->frame
);
1678 /* update the icon title */
1680 g_free(self
->icon_title
);
1683 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1684 /* try old x stuff */
1685 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1686 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1687 data
= g_strdup(self
->title
);
1689 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1690 self
->icon_title
= data
;
1693 void client_update_class(ObClient
*self
)
1698 if (self
->name
) g_free(self
->name
);
1699 if (self
->class) g_free(self
->class);
1700 if (self
->role
) g_free(self
->role
);
1702 self
->name
= self
->class = self
->role
= NULL
;
1704 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1706 self
->name
= g_strdup(data
[0]);
1708 self
->class = g_strdup(data
[1]);
1713 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1716 if (self
->name
== NULL
) self
->name
= g_strdup("");
1717 if (self
->class == NULL
) self
->class = g_strdup("");
1718 if (self
->role
== NULL
) self
->role
= g_strdup("");
1721 void client_update_strut(ObClient
*self
)
1725 gboolean got
= FALSE
;
1728 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1732 STRUT_PARTIAL_SET(strut
,
1733 data
[0], data
[2], data
[1], data
[3],
1734 data
[4], data
[5], data
[8], data
[9],
1735 data
[6], data
[7], data
[10], data
[11]);
1741 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1747 /* use the screen's width/height */
1748 a
= screen_physical_area();
1750 STRUT_PARTIAL_SET(strut
,
1751 data
[0], data
[2], data
[1], data
[3],
1752 a
->y
, a
->y
+ a
->height
- 1,
1753 a
->x
, a
->x
+ a
->width
- 1,
1754 a
->y
, a
->y
+ a
->height
- 1,
1755 a
->x
, a
->x
+ a
->width
- 1);
1761 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1762 0, 0, 0, 0, 0, 0, 0, 0);
1764 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1765 self
->strut
= strut
;
1767 /* updating here is pointless while we're being mapped cuz we're not in
1768 the client list yet */
1770 screen_update_areas();
1774 void client_update_icons(ObClient
*self
)
1780 for (i
= 0; i
< self
->nicons
; ++i
)
1781 g_free(self
->icons
[i
].data
);
1782 if (self
->nicons
> 0)
1783 g_free(self
->icons
);
1786 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1787 /* figure out how many valid icons are in here */
1789 while (num
- i
> 2) {
1793 if (i
> num
|| w
*h
== 0) break;
1797 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1799 /* store the icons */
1801 for (j
= 0; j
< self
->nicons
; ++j
) {
1804 w
= self
->icons
[j
].width
= data
[i
++];
1805 h
= self
->icons
[j
].height
= data
[i
++];
1807 if (w
*h
== 0) continue;
1809 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1810 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1815 self
->icons
[j
].data
[t
] =
1816 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1817 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1818 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1819 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1828 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1829 if (hints
->flags
& IconPixmapHint
) {
1831 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1832 xerror_set_ignore(TRUE
);
1833 if (!RrPixmapToRGBA(ob_rr_inst
,
1835 (hints
->flags
& IconMaskHint
?
1836 hints
->icon_mask
: None
),
1837 &self
->icons
[self
->nicons
-1].width
,
1838 &self
->icons
[self
->nicons
-1].height
,
1839 &self
->icons
[self
->nicons
-1].data
)){
1840 g_free(&self
->icons
[self
->nicons
-1]);
1843 xerror_set_ignore(FALSE
);
1850 frame_adjust_icon(self
->frame
);
1853 void client_update_user_time(ObClient
*self
, gboolean new_event
)
1857 if (PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
)) {
1858 self
->user_time
= time
;
1859 /* we set this every time, not just when it grows, because in practice
1860 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
1861 backward we don't want all windows to stop focusing. we'll just
1862 assume noone is setting times older than the last one, cuz that
1863 would be pretty stupid anyways
1864 However! This is called when a window is mapped to get its user time
1865 but it's an old number, it's not changing it from new user
1866 interaction, so in that case, don't change the last user time.
1869 client_last_user_time
= time
;
1872 ob_debug("window %s user time %u\n", self->title, time);
1873 ob_debug("last user time %u\n", client_last_user_time);
1878 static void client_change_wm_state(ObClient
*self
)
1883 old
= self
->wmstate
;
1885 if (self
->shaded
|| self
->iconic
|| !self
->frame
->visible
)
1886 self
->wmstate
= IconicState
;
1888 self
->wmstate
= NormalState
;
1890 if (old
!= self
->wmstate
) {
1891 PROP_MSG(self
->window
, kde_wm_change_state
,
1892 self
->wmstate
, 1, 0, 0);
1894 state
[0] = self
->wmstate
;
1896 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1900 static void client_change_state(ObClient
*self
)
1902 gulong netstate
[11];
1907 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1909 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1911 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1912 if (self
->skip_taskbar
)
1913 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1914 if (self
->skip_pager
)
1915 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1916 if (self
->fullscreen
)
1917 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1919 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1921 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1923 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1925 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1926 if (self
->demands_attention
)
1927 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
1928 if (self
->undecorated
)
1929 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1930 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1933 frame_adjust_state(self
->frame
);
1936 ObClient
*client_search_focus_tree(ObClient
*self
)
1941 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1942 if (client_focused(it
->data
)) return it
->data
;
1943 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1948 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1950 if (self
->transient_for
) {
1951 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1952 return client_search_focus_tree_full(self
->transient_for
);
1955 gboolean recursed
= FALSE
;
1957 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1958 if (!((ObClient
*)it
->data
)->transient_for
) {
1960 if ((c
= client_search_focus_tree_full(it
->data
)))
1969 /* this function checks the whole tree, the client_search_focus_tree~
1970 does not, so we need to check this window */
1971 if (client_focused(self
))
1973 return client_search_focus_tree(self
);
1976 static ObStackingLayer
calc_layer(ObClient
*self
)
1980 if (self
->fullscreen
&&
1981 (client_focused(self
) || client_search_focus_tree(self
)))
1982 l
= OB_STACKING_LAYER_FULLSCREEN
;
1983 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1984 l
= OB_STACKING_LAYER_DESKTOP
;
1985 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1986 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
1987 else l
= OB_STACKING_LAYER_ABOVE
;
1989 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1990 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1991 else l
= OB_STACKING_LAYER_NORMAL
;
1996 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1997 ObStackingLayer min
, gboolean raised
)
1999 ObStackingLayer old
, own
;
2003 own
= calc_layer(self
);
2004 self
->layer
= MAX(own
, min
);
2006 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2007 client_calc_layer_recursive(it
->data
, orig
,
2009 raised
? raised
: self
->layer
!= old
);
2011 if (!raised
&& self
->layer
!= old
)
2012 if (orig
->frame
) { /* only restack if the original window is managed */
2013 stacking_remove(CLIENT_AS_WINDOW(self
));
2014 stacking_add(CLIENT_AS_WINDOW(self
));
2018 void client_calc_layer(ObClient
*self
)
2025 /* transients take on the layer of their parents */
2026 it
= client_search_all_top_parents(self
);
2028 for (; it
; it
= g_slist_next(it
))
2029 client_calc_layer_recursive(it
->data
, orig
, 0, FALSE
);
2032 gboolean
client_should_show(ObClient
*self
)
2036 if (client_normal(self
) && screen_showing_desktop
)
2039 if (self->transient_for) {
2040 if (self->transient_for != OB_TRAN_GROUP)
2041 return client_should_show(self->transient_for);
2045 for (it = self->group->members; it; it = g_slist_next(it)) {
2046 ObClient *c = it->data;
2047 if (c != self && !c->transient_for) {
2048 if (client_should_show(c))
2055 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2061 void client_showhide(ObClient
*self
)
2064 if (client_should_show(self
)) {
2065 frame_show(self
->frame
);
2068 frame_hide(self
->frame
);
2070 /* Fall back focus since we're disappearing */
2071 if (focus_client
== self
)
2072 client_unfocus(self
);
2075 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible, it
2076 needs to be in IconicState. This includes when it is on another
2079 client_change_wm_state(self
);
2082 gboolean
client_normal(ObClient
*self
) {
2083 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2084 self
->type
== OB_CLIENT_TYPE_DOCK
||
2085 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2088 static void client_apply_startup_state(ObClient
*self
, gint x
, gint y
)
2090 gboolean pos
= FALSE
; /* has the window's position been configured? */
2093 /* save the position, and set self->area for these to use */
2099 /* these are in a carefully crafted order.. */
2102 self
->iconic
= FALSE
;
2103 client_iconify(self
, TRUE
, FALSE
);
2105 if (self
->fullscreen
) {
2106 self
->fullscreen
= FALSE
;
2107 client_fullscreen(self
, TRUE
);
2110 if (self
->undecorated
) {
2111 self
->undecorated
= FALSE
;
2112 client_set_undecorated(self
, TRUE
);
2115 self
->shaded
= FALSE
;
2116 client_shade(self
, TRUE
);
2118 if (self
->demands_attention
) {
2119 self
->demands_attention
= FALSE
;
2120 client_hilite(self
, TRUE
);
2123 if (self
->max_vert
&& self
->max_horz
) {
2124 self
->max_vert
= self
->max_horz
= FALSE
;
2125 client_maximize(self
, TRUE
, 0);
2127 } else if (self
->max_vert
) {
2128 self
->max_vert
= FALSE
;
2129 client_maximize(self
, TRUE
, 2);
2131 } else if (self
->max_horz
) {
2132 self
->max_horz
= FALSE
;
2133 client_maximize(self
, TRUE
, 1);
2137 /* if the client didn't get positioned yet, then do so now
2138 call client_move even if the window is not being moved anywhere, because
2139 when we reparent it and decorate it, it is getting moved and we need to
2140 be telling it so with a ConfigureNotify event.
2143 /* use the saved position */
2146 client_move(self
, x
, y
);
2149 /* nothing to do for the other states:
2158 void client_try_configure(ObClient
*self
, ObCorner anchor
,
2159 gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2160 gint
*logicalw
, gint
*logicalh
,
2163 Rect desired_area
= {*x
, *y
, *w
, *h
};
2165 /* make the frame recalculate its dimentions n shit without changing
2166 anything visible for real, this way the constraints below can work with
2167 the updated frame dimensions. */
2168 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2170 /* work within the prefered sizes given by the window */
2171 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2172 gint basew
, baseh
, minw
, minh
;
2174 /* base size is substituted with min size if not specified */
2175 if (self
->base_size
.width
|| self
->base_size
.height
) {
2176 basew
= self
->base_size
.width
;
2177 baseh
= self
->base_size
.height
;
2179 basew
= self
->min_size
.width
;
2180 baseh
= self
->min_size
.height
;
2182 /* min size is substituted with base size if not specified */
2183 if (self
->min_size
.width
|| self
->min_size
.height
) {
2184 minw
= self
->min_size
.width
;
2185 minh
= self
->min_size
.height
;
2187 minw
= self
->base_size
.width
;
2188 minh
= self
->base_size
.height
;
2191 /* if this is a user-requested resize, then check against min/max
2194 /* smaller than min size or bigger than max size? */
2195 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2196 if (*w
< minw
) *w
= minw
;
2197 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2198 if (*h
< minh
) *h
= minh
;
2203 /* keep to the increments */
2204 *w
/= self
->size_inc
.width
;
2205 *h
/= self
->size_inc
.height
;
2207 /* you cannot resize to nothing */
2208 if (basew
+ *w
< 1) *w
= 1 - basew
;
2209 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2211 /* save the logical size */
2212 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2213 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2215 *w
*= self
->size_inc
.width
;
2216 *h
*= self
->size_inc
.height
;
2221 /* adjust the height to match the width for the aspect ratios.
2222 for this, min size is not substituted for base size ever. */
2223 *w
-= self
->base_size
.width
;
2224 *h
-= self
->base_size
.height
;
2226 if (!self
->fullscreen
) {
2227 if (self
->min_ratio
)
2228 if (*h
* self
->min_ratio
> *w
) {
2229 *h
= (gint
)(*w
/ self
->min_ratio
);
2231 /* you cannot resize to nothing */
2234 *w
= (gint
)(*h
* self
->min_ratio
);
2237 if (self
->max_ratio
)
2238 if (*h
* self
->max_ratio
< *w
) {
2239 *h
= (gint
)(*w
/ self
->max_ratio
);
2241 /* you cannot resize to nothing */
2244 *w
= (gint
)(*h
* self
->min_ratio
);
2249 *w
+= self
->base_size
.width
;
2250 *h
+= self
->base_size
.height
;
2253 /* gets the frame's position */
2254 frame_client_gravity(self
->frame
, x
, y
);
2256 /* these positions are frame positions, not client positions */
2258 /* set the size and position if fullscreen */
2259 if (self
->fullscreen
) {
2263 i
= screen_find_monitor(&desired_area
);
2264 a
= screen_physical_area_monitor(i
);
2271 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2272 is entering fullscreen */
2273 } else if (self
->max_horz
|| self
->max_vert
) {
2277 i
= screen_find_monitor(&desired_area
);
2278 a
= screen_area_monitor(self
->desktop
, i
);
2280 /* set the size and position if maximized */
2281 if (self
->max_horz
) {
2283 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2285 if (self
->max_vert
) {
2287 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2290 /* maximizing is not allowed if the user can't move+resize the window
2294 /* gets the client's position */
2295 frame_frame_gravity(self
->frame
, x
, y
);
2297 /* these override the above states! if you cant move you can't move! */
2299 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2303 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2304 *w
= self
->area
.width
;
2305 *h
= self
->area
.height
;
2313 case OB_CORNER_TOPLEFT
:
2315 case OB_CORNER_TOPRIGHT
:
2316 *x
-= *w
- self
->area
.width
;
2318 case OB_CORNER_BOTTOMLEFT
:
2319 *y
-= *h
- self
->area
.height
;
2321 case OB_CORNER_BOTTOMRIGHT
:
2322 *x
-= *w
- self
->area
.width
;
2323 *y
-= *h
- self
->area
.height
;
2329 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2330 gint x
, gint y
, gint w
, gint h
,
2331 gboolean user
, gboolean final
,
2332 gboolean force_reply
)
2335 gboolean send_resize_client
;
2336 gboolean moved
= FALSE
, resized
= FALSE
;
2337 guint fdecor
= self
->frame
->decorations
;
2338 gboolean fhorz
= self
->frame
->max_horz
;
2339 gint logicalw
, logicalh
;
2341 /* find the new x, y, width, and height (and logical size) */
2342 client_try_configure(self
, anchor
, &x
, &y
, &w
, &h
,
2343 &logicalw
, &logicalh
, user
);
2345 /* set the logical size if things changed */
2346 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2347 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2349 /* figure out if we moved or resized or what */
2350 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2351 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2353 oldw
= self
->area
.width
;
2354 oldh
= self
->area
.height
;
2355 RECT_SET(self
->area
, x
, y
, w
, h
);
2357 /* for app-requested resizes, always resize if 'resized' is true.
2358 for user-requested ones, only resize if final is true, or when
2359 resizing in redraw mode */
2360 send_resize_client
= ((!user
&& resized
) ||
2362 (resized
&& config_resize_redraw
))));
2364 /* if the client is enlarging, then resize the client before the frame */
2365 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2366 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2368 /* move/resize the frame to match the request */
2370 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2371 moved
= resized
= TRUE
;
2373 if (moved
|| resized
)
2374 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2376 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2379 event
.type
= ConfigureNotify
;
2380 event
.xconfigure
.display
= ob_display
;
2381 event
.xconfigure
.event
= self
->window
;
2382 event
.xconfigure
.window
= self
->window
;
2384 /* root window real coords */
2385 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2387 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2389 event
.xconfigure
.width
= w
;
2390 event
.xconfigure
.height
= h
;
2391 event
.xconfigure
.border_width
= 0;
2392 event
.xconfigure
.above
= self
->frame
->plate
;
2393 event
.xconfigure
.override_redirect
= FALSE
;
2394 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2395 FALSE
, StructureNotifyMask
, &event
);
2399 /* if the client is shrinking, then resize the frame before the client */
2400 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2401 XResizeWindow(ob_display
, self
->window
, w
, h
);
2406 void client_fullscreen(ObClient
*self
, gboolean fs
)
2410 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2411 self
->fullscreen
== fs
) return; /* already done */
2413 self
->fullscreen
= fs
;
2414 client_change_state(self
); /* change the state hints on the client */
2415 client_calc_layer(self
); /* and adjust out layer/stacking */
2418 self
->pre_fullscreen_area
= self
->area
;
2419 /* if the window is maximized, its area isn't all that meaningful.
2420 save it's premax area instead. */
2421 if (self
->max_horz
) {
2422 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2423 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2425 if (self
->max_vert
) {
2426 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2427 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2430 /* these are not actually used cuz client_configure will set them
2431 as appropriate when the window is fullscreened */
2436 if (self
->pre_fullscreen_area
.width
> 0 &&
2437 self
->pre_fullscreen_area
.height
> 0)
2439 x
= self
->pre_fullscreen_area
.x
;
2440 y
= self
->pre_fullscreen_area
.y
;
2441 w
= self
->pre_fullscreen_area
.width
;
2442 h
= self
->pre_fullscreen_area
.height
;
2443 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2445 /* pick some fallbacks... */
2446 a
= screen_area_monitor(self
->desktop
, 0);
2447 x
= a
->x
+ a
->width
/ 4;
2448 y
= a
->y
+ a
->height
/ 4;
2454 client_setup_decor_and_functions(self
);
2456 client_move_resize(self
, x
, y
, w
, h
);
2458 /* try focus us when we go into fullscreen mode */
2462 static void client_iconify_recursive(ObClient
*self
,
2463 gboolean iconic
, gboolean curdesk
)
2466 gboolean changed
= FALSE
;
2469 if (self
->iconic
!= iconic
) {
2470 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2474 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2475 self
->iconic
= iconic
;
2477 /* update the focus lists.. iconic windows go to the bottom of
2478 the list, put the new iconic window at the 'top of the
2480 focus_order_to_top(self
);
2485 self
->iconic
= iconic
;
2488 client_set_desktop(self
, screen_desktop
, FALSE
);
2490 /* this puts it after the current focused window */
2491 focus_order_remove(self
);
2492 focus_order_add_new(self
);
2499 client_change_state(self
);
2500 client_showhide(self
);
2501 if (STRUT_EXISTS(self
->strut
))
2502 screen_update_areas();
2505 /* iconify all direct transients */
2506 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2507 if (it
->data
!= self
)
2508 if (client_is_direct_child(self
, it
->data
))
2509 client_iconify_recursive(it
->data
, iconic
, curdesk
);
2512 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2514 /* move up the transient chain as far as possible first */
2515 self
= client_search_top_parent(self
);
2516 client_iconify_recursive(self
, iconic
, curdesk
);
2519 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
2523 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2524 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2526 /* check if already done */
2528 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2529 if (dir
== 1 && self
->max_horz
) return;
2530 if (dir
== 2 && self
->max_vert
) return;
2532 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2533 if (dir
== 1 && !self
->max_horz
) return;
2534 if (dir
== 2 && !self
->max_vert
) return;
2537 /* we just tell it to configure in the same place and client_configure
2538 worries about filling the screen with the window */
2541 w
= self
->area
.width
;
2542 h
= self
->area
.height
;
2545 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2546 RECT_SET(self
->pre_max_area
,
2547 self
->area
.x
, self
->pre_max_area
.y
,
2548 self
->area
.width
, self
->pre_max_area
.height
);
2550 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2551 RECT_SET(self
->pre_max_area
,
2552 self
->pre_max_area
.x
, self
->area
.y
,
2553 self
->pre_max_area
.width
, self
->area
.height
);
2558 a
= screen_area_monitor(self
->desktop
, 0);
2559 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2560 if (self
->pre_max_area
.width
> 0) {
2561 x
= self
->pre_max_area
.x
;
2562 w
= self
->pre_max_area
.width
;
2564 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2565 0, self
->pre_max_area
.height
);
2567 /* pick some fallbacks... */
2568 x
= a
->x
+ a
->width
/ 4;
2572 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2573 if (self
->pre_max_area
.height
> 0) {
2574 y
= self
->pre_max_area
.y
;
2575 h
= self
->pre_max_area
.height
;
2577 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2578 self
->pre_max_area
.width
, 0);
2580 /* pick some fallbacks... */
2581 y
= a
->y
+ a
->height
/ 4;
2587 if (dir
== 0 || dir
== 1) /* horz */
2588 self
->max_horz
= max
;
2589 if (dir
== 0 || dir
== 2) /* vert */
2590 self
->max_vert
= max
;
2592 client_change_state(self
); /* change the state hints on the client */
2594 client_setup_decor_and_functions(self
);
2596 client_move_resize(self
, x
, y
, w
, h
);
2599 void client_shade(ObClient
*self
, gboolean shade
)
2601 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2602 shade
) || /* can't shade */
2603 self
->shaded
== shade
) return; /* already done */
2605 self
->shaded
= shade
;
2606 client_change_state(self
);
2607 client_change_wm_state(self
); /* the window is being hidden/shown */
2608 /* resize the frame to just the titlebar */
2609 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2612 void client_close(ObClient
*self
)
2616 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2618 /* in the case that the client provides no means to requesting that it
2619 close, we just kill it */
2620 if (!self
->delete_window
)
2624 XXX: itd be cool to do timeouts and shit here for killing the client's
2626 like... if the window is around after 5 seconds, then the close button
2627 turns a nice red, and if this function is called again, the client is
2631 ce
.xclient
.type
= ClientMessage
;
2632 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2633 ce
.xclient
.display
= ob_display
;
2634 ce
.xclient
.window
= self
->window
;
2635 ce
.xclient
.format
= 32;
2636 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2637 ce
.xclient
.data
.l
[1] = event_curtime
;
2638 ce
.xclient
.data
.l
[2] = 0l;
2639 ce
.xclient
.data
.l
[3] = 0l;
2640 ce
.xclient
.data
.l
[4] = 0l;
2641 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2644 void client_kill(ObClient
*self
)
2646 XKillClient(ob_display
, self
->window
);
2649 void client_hilite(ObClient
*self
, gboolean hilite
)
2651 if (self
->demands_attention
== hilite
)
2652 return; /* no change */
2654 /* don't allow focused windows to hilite */
2655 self
->demands_attention
= hilite
&& !client_focused(self
);
2656 if (self
->demands_attention
)
2657 frame_flash_start(self
->frame
);
2659 frame_flash_stop(self
->frame
);
2660 client_change_state(self
);
2663 void client_set_desktop_recursive(ObClient
*self
,
2664 guint target
, gboolean donthide
)
2669 if (target
!= self
->desktop
) {
2671 ob_debug("Setting desktop %u\n", target
+1);
2673 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2675 /* remove from the old desktop(s) */
2676 focus_order_remove(self
);
2678 old
= self
->desktop
;
2679 self
->desktop
= target
;
2680 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2681 /* the frame can display the current desktop state */
2682 frame_adjust_state(self
->frame
);
2683 /* 'move' the window to the new desktop */
2685 client_showhide(self
);
2686 /* raise if it was not already on the desktop */
2687 if (old
!= DESKTOP_ALL
)
2689 if (STRUT_EXISTS(self
->strut
))
2690 screen_update_areas();
2692 /* add to the new desktop(s) */
2693 if (config_focus_new
)
2694 focus_order_to_top(self
);
2696 focus_order_to_bottom(self
);
2699 /* move all transients */
2700 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2701 if (it
->data
!= self
)
2702 if (client_is_direct_child(self
, it
->data
))
2703 client_set_desktop_recursive(it
->data
, target
, donthide
);
2706 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2708 self
= client_search_top_parent(self
);
2709 client_set_desktop_recursive(self
, target
, donthide
);
2712 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
2714 while (child
!= parent
&&
2715 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
2716 child
= child
->transient_for
;
2717 return child
== parent
;
2720 ObClient
*client_search_modal_child(ObClient
*self
)
2725 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2726 ObClient
*c
= it
->data
;
2727 if ((ret
= client_search_modal_child(c
))) return ret
;
2728 if (c
->modal
) return c
;
2733 gboolean
client_validate(ObClient
*self
)
2737 XSync(ob_display
, FALSE
); /* get all events on the server */
2739 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2740 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2741 XPutBackEvent(ob_display
, &e
);
2748 void client_set_wm_state(ObClient
*self
, glong state
)
2750 if (state
== self
->wmstate
) return; /* no change */
2754 client_iconify(self
, TRUE
, TRUE
);
2757 client_iconify(self
, FALSE
, TRUE
);
2762 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2764 gboolean shaded
= self
->shaded
;
2765 gboolean fullscreen
= self
->fullscreen
;
2766 gboolean undecorated
= self
->undecorated
;
2767 gboolean max_horz
= self
->max_horz
;
2768 gboolean max_vert
= self
->max_vert
;
2769 gboolean modal
= self
->modal
;
2770 gboolean iconic
= self
->iconic
;
2771 gboolean demands_attention
= self
->demands_attention
;
2774 if (!(action
== prop_atoms
.net_wm_state_add
||
2775 action
== prop_atoms
.net_wm_state_remove
||
2776 action
== prop_atoms
.net_wm_state_toggle
))
2777 /* an invalid action was passed to the client message, ignore it */
2780 for (i
= 0; i
< 2; ++i
) {
2781 Atom state
= i
== 0 ? data1
: data2
;
2783 if (!state
) continue;
2785 /* if toggling, then pick whether we're adding or removing */
2786 if (action
== prop_atoms
.net_wm_state_toggle
) {
2787 if (state
== prop_atoms
.net_wm_state_modal
)
2788 action
= modal
? prop_atoms
.net_wm_state_remove
:
2789 prop_atoms
.net_wm_state_add
;
2790 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2791 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2792 prop_atoms
.net_wm_state_add
;
2793 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2794 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2795 prop_atoms
.net_wm_state_add
;
2796 else if (state
== prop_atoms
.net_wm_state_shaded
)
2797 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2798 prop_atoms
.net_wm_state_add
;
2799 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2800 action
= self
->skip_taskbar
?
2801 prop_atoms
.net_wm_state_remove
:
2802 prop_atoms
.net_wm_state_add
;
2803 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2804 action
= self
->skip_pager
?
2805 prop_atoms
.net_wm_state_remove
:
2806 prop_atoms
.net_wm_state_add
;
2807 else if (state
== prop_atoms
.net_wm_state_hidden
)
2808 action
= self
->iconic
?
2809 prop_atoms
.net_wm_state_remove
:
2810 prop_atoms
.net_wm_state_add
;
2811 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2812 action
= fullscreen
?
2813 prop_atoms
.net_wm_state_remove
:
2814 prop_atoms
.net_wm_state_add
;
2815 else if (state
== prop_atoms
.net_wm_state_above
)
2816 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2817 prop_atoms
.net_wm_state_add
;
2818 else if (state
== prop_atoms
.net_wm_state_below
)
2819 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2820 prop_atoms
.net_wm_state_add
;
2821 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
2822 action
= self
->demands_attention
?
2823 prop_atoms
.net_wm_state_remove
:
2824 prop_atoms
.net_wm_state_add
;
2825 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2826 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2827 prop_atoms
.net_wm_state_add
;
2830 if (action
== prop_atoms
.net_wm_state_add
) {
2831 if (state
== prop_atoms
.net_wm_state_modal
) {
2833 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2835 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2837 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2839 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2840 self
->skip_taskbar
= TRUE
;
2841 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2842 self
->skip_pager
= TRUE
;
2843 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2845 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2847 } else if (state
== prop_atoms
.net_wm_state_above
) {
2849 self
->below
= FALSE
;
2850 } else if (state
== prop_atoms
.net_wm_state_below
) {
2851 self
->above
= FALSE
;
2853 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2854 demands_attention
= TRUE
;
2855 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2859 } else { /* action == prop_atoms.net_wm_state_remove */
2860 if (state
== prop_atoms
.net_wm_state_modal
) {
2862 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2864 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2866 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2868 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2869 self
->skip_taskbar
= FALSE
;
2870 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2871 self
->skip_pager
= FALSE
;
2872 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2874 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2876 } else if (state
== prop_atoms
.net_wm_state_above
) {
2877 self
->above
= FALSE
;
2878 } else if (state
== prop_atoms
.net_wm_state_below
) {
2879 self
->below
= FALSE
;
2880 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
2881 demands_attention
= FALSE
;
2882 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2883 undecorated
= FALSE
;
2887 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2888 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2890 if (max_horz
== max_vert
) { /* both going the same way */
2891 client_maximize(self
, max_horz
, 0);
2893 client_maximize(self
, max_horz
, 1);
2894 client_maximize(self
, max_vert
, 2);
2898 if (max_horz
!= self
->max_horz
)
2899 client_maximize(self
, max_horz
, 1);
2901 client_maximize(self
, max_vert
, 2);
2904 /* change fullscreen state before shading, as it will affect if the window
2906 if (fullscreen
!= self
->fullscreen
)
2907 client_fullscreen(self
, fullscreen
);
2908 if (shaded
!= self
->shaded
)
2909 client_shade(self
, shaded
);
2910 if (undecorated
!= self
->undecorated
)
2911 client_set_undecorated(self
, undecorated
);
2912 if (modal
!= self
->modal
) {
2913 self
->modal
= modal
;
2914 /* when a window changes modality, then its stacking order with its
2915 transients needs to change */
2918 if (iconic
!= self
->iconic
)
2919 client_iconify(self
, iconic
, FALSE
);
2921 if (demands_attention
!= self
->demands_attention
)
2922 client_hilite(self
, demands_attention
);
2924 client_change_state(self
); /* change the hint to reflect these changes */
2927 ObClient
*client_focus_target(ObClient
*self
)
2929 ObClient
*child
= NULL
;
2931 child
= client_search_modal_child(self
);
2932 if (child
) return child
;
2936 gboolean
client_can_focus(ObClient
*self
)
2940 /* choose the correct target */
2941 self
= client_focus_target(self
);
2943 if (!self
->frame
->visible
)
2946 if (!(self
->can_focus
|| self
->focus_notify
))
2949 /* do a check to see if the window has already been unmapped or destroyed
2950 do this intelligently while watching out for unmaps we've generated
2951 (ignore_unmaps > 0) */
2952 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2953 DestroyNotify
, &ev
)) {
2954 XPutBackEvent(ob_display
, &ev
);
2957 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2958 UnmapNotify
, &ev
)) {
2959 if (self
->ignore_unmaps
) {
2960 self
->ignore_unmaps
--;
2962 XPutBackEvent(ob_display
, &ev
);
2970 gboolean
client_focus(ObClient
*self
)
2972 /* choose the correct target */
2973 self
= client_focus_target(self
);
2975 if (!client_can_focus(self
)) {
2976 if (!self
->frame
->visible
) {
2977 /* update the focus lists */
2978 focus_order_to_top(self
);
2983 ob_debug("Focusing client \"%s\" at time %u\n", self
->title
, event_curtime
);
2985 if (self
->can_focus
) {
2986 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2990 if (self
->focus_notify
) {
2992 ce
.xclient
.type
= ClientMessage
;
2993 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2994 ce
.xclient
.display
= ob_display
;
2995 ce
.xclient
.window
= self
->window
;
2996 ce
.xclient
.format
= 32;
2997 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2998 ce
.xclient
.data
.l
[1] = event_curtime
;
2999 ce
.xclient
.data
.l
[2] = 0l;
3000 ce
.xclient
.data
.l
[3] = 0l;
3001 ce
.xclient
.data
.l
[4] = 0l;
3002 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3006 ob_debug("%sively focusing %lx at %d\n",
3007 (self
->can_focus
? "act" : "pass"),
3008 self
->window
, (gint
) event_curtime
);
3011 /* Cause the FocusIn to come back to us. Important for desktop switches,
3012 since otherwise we'll have no FocusIn on the queue and send it off to
3013 the focus_backup. */
3014 XSync(ob_display
, FALSE
);
3018 /* Used when the current client is closed or otherwise hidden, focus_last will
3019 then prevent focus from going to the mouse pointer
3021 static void client_unfocus(ObClient
*self
)
3023 if (focus_client
== self
) {
3025 ob_debug("client_unfocus for %lx\n", self
->window
);
3027 focus_fallback(FALSE
);
3031 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3033 /* XXX do some stuff here if user is false to determine if we really want
3034 to activate it or not (a parent or group member is currently
3037 ob_debug("Want to activate window 0x%x with time %u (last time %u), "
3039 self
->window
, event_curtime
, client_last_user_time
,
3040 (user
? "user" : "application"));
3041 if (!user
&& event_curtime
&&
3042 !event_time_after(event_curtime
, client_last_user_time
))
3044 client_hilite(self
, TRUE
);
3046 if (client_normal(self
) && screen_showing_desktop
)
3047 screen_show_desktop(FALSE
);
3049 client_iconify(self
, FALSE
, here
);
3050 if (self
->desktop
!= DESKTOP_ALL
&&
3051 self
->desktop
!= screen_desktop
) {
3053 client_set_desktop(self
, screen_desktop
, FALSE
);
3055 screen_set_desktop(self
->desktop
);
3056 } else if (!self
->frame
->visible
)
3057 /* if its not visible for other reasons, then don't mess
3061 client_shade(self
, FALSE
);
3065 /* we do this an action here. this is rather important. this is because
3066 we want the results from the focus change to take place BEFORE we go
3067 about raising the window. when a fullscreen window loses focus, we
3068 need this or else the raise wont be able to raise above the
3069 to-lose-focus fullscreen window. */
3074 void client_raise(ObClient
*self
)
3076 action_run_string("Raise", self
, CurrentTime
);
3079 void client_lower(ObClient
*self
)
3081 action_run_string("Lower", self
, CurrentTime
);
3084 gboolean
client_focused(ObClient
*self
)
3086 return self
== focus_client
;
3089 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3092 /* si is the smallest image >= req */
3093 /* li is the largest image < req */
3094 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
3096 if (!self
->nicons
) {
3097 ObClientIcon
*parent
= NULL
;
3099 if (self
->transient_for
) {
3100 if (self
->transient_for
!= OB_TRAN_GROUP
)
3101 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3104 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3105 ObClient
*c
= it
->data
;
3106 if (c
!= self
&& !c
->transient_for
) {
3107 if ((parent
= client_icon_recursive(c
, w
, h
)))
3117 for (i
= 0; i
< self
->nicons
; ++i
) {
3118 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
3119 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
3123 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
3128 if (largest
== 0) /* didnt find one smaller than the requested size */
3129 return &self
->icons
[si
];
3130 return &self
->icons
[li
];
3133 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3136 static ObClientIcon deficon
;
3138 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3139 deficon
.width
= deficon
.height
= 48;
3140 deficon
.data
= ob_rr_theme
->def_win_icon
;
3146 /* this be mostly ripped from fvwm */
3147 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
3149 gint my_cx
, my_cy
, his_cx
, his_cy
;
3152 gint score
, best_score
;
3153 ObClient
*best_client
, *cur
;
3159 /* first, find the centre coords of the currently focused window */
3160 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
3161 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
3166 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
3169 /* the currently selected window isn't interesting */
3172 if (!client_normal(cur
))
3174 /* using c->desktop instead of screen_desktop doesn't work if the
3175 * current window was omnipresent, hope this doesn't have any other
3177 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3181 if(!(client_focus_target(cur
) == cur
&&
3182 client_can_focus(cur
)))
3185 /* find the centre coords of this window, from the
3186 * currently focused window's point of view */
3187 his_cx
= (cur
->frame
->area
.x
- my_cx
)
3188 + cur
->frame
->area
.width
/ 2;
3189 his_cy
= (cur
->frame
->area
.y
- my_cy
)
3190 + cur
->frame
->area
.height
/ 2;
3192 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
3193 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
3195 /* Rotate the diagonals 45 degrees counterclockwise.
3196 * To do this, multiply the matrix /+h +h\ with the
3197 * vector (x y). \-h +h/
3198 * h = sqrt(0.5). We can set h := 1 since absolute
3199 * distance doesn't matter here. */
3200 tx
= his_cx
+ his_cy
;
3201 his_cy
= -his_cx
+ his_cy
;
3206 case OB_DIRECTION_NORTH
:
3207 case OB_DIRECTION_SOUTH
:
3208 case OB_DIRECTION_NORTHEAST
:
3209 case OB_DIRECTION_SOUTHWEST
:
3210 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
3211 distance
= ((dir
== OB_DIRECTION_NORTH
||
3212 dir
== OB_DIRECTION_NORTHEAST
) ?
3215 case OB_DIRECTION_EAST
:
3216 case OB_DIRECTION_WEST
:
3217 case OB_DIRECTION_SOUTHEAST
:
3218 case OB_DIRECTION_NORTHWEST
:
3219 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
3220 distance
= ((dir
== OB_DIRECTION_WEST
||
3221 dir
== OB_DIRECTION_NORTHWEST
) ?
3226 /* the target must be in the requested direction */
3230 /* Calculate score for this window. The smaller the better. */
3231 score
= distance
+ offset
;
3233 /* windows more than 45 degrees off the direction are
3234 * heavily penalized and will only be chosen if nothing
3235 * else within a million pixels */
3236 if(offset
> distance
)
3239 if(best_score
== -1 || score
< best_score
)
3247 void client_set_layer(ObClient
*self
, gint layer
)
3251 self
->above
= FALSE
;
3252 } else if (layer
== 0) {
3253 self
->below
= self
->above
= FALSE
;
3255 self
->below
= FALSE
;
3258 client_calc_layer(self
);
3259 client_change_state(self
); /* reflect this in the state hints */
3262 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3264 if (self
->undecorated
!= undecorated
) {
3265 self
->undecorated
= undecorated
;
3266 client_setup_decor_and_functions(self
);
3267 /* Make sure the client knows it might have moved. Maybe there is a
3268 * better way of doing this so only one client_configure is sent, but
3269 * since 125 of these are sent per second when moving the window (with
3270 * user = FALSE) i doubt it matters much.
3272 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3273 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3274 client_change_state(self
); /* reflect this in the state hints */
3278 guint
client_monitor(ObClient
*self
)
3280 return screen_find_monitor(&self
->frame
->area
);
3283 ObClient
*client_search_top_parent(ObClient
*self
)
3285 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3286 self
= self
->transient_for
;
3290 GSList
*client_search_all_top_parents(ObClient
*self
)
3294 /* move up the direct transient chain as far as possible */
3295 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
)
3296 self
= self
->transient_for
;
3298 if (!self
->transient_for
)
3299 ret
= g_slist_prepend(ret
, self
);
3303 g_assert(self
->group
);
3305 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3306 ObClient
*c
= it
->data
;
3308 if (!c
->transient_for
)
3309 ret
= g_slist_prepend(ret
, c
);
3312 if (ret
== NULL
) /* no group parents */
3313 ret
= g_slist_prepend(ret
, self
);
3319 ObClient
*client_search_focus_parent(ObClient
*self
)
3321 if (self
->transient_for
) {
3322 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3323 if (client_focused(self
->transient_for
))
3324 return self
->transient_for
;
3328 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3329 ObClient
*c
= it
->data
;
3331 /* checking transient_for prevents infinate loops! */
3332 if (c
!= self
&& !c
->transient_for
)
3333 if (client_focused(c
))
3342 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3344 if (self
->transient_for
) {
3345 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3346 if (self
->transient_for
== search
)
3351 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3352 ObClient
*c
= it
->data
;
3354 /* checking transient_for prevents infinate loops! */
3355 if (c
!= self
&& !c
->transient_for
)
3365 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3369 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3370 if (sit
->data
== search
)
3372 if (client_search_transient(sit
->data
, search
))
3378 void client_update_sm_client_id(ObClient
*self
)
3380 g_free(self
->sm_client_id
);
3381 self
->sm_client_id
= NULL
;
3383 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3385 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3386 &self
->sm_client_id
);
3389 #define WANT_EDGE(cur, c) \
3392 if(!client_normal(cur)) \
3394 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3398 if(cur->layer < c->layer && !config_resist_layers_below) \
3401 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3402 if ((his_edge_start >= my_edge_start && \
3403 his_edge_start <= my_edge_end) || \
3404 (my_edge_start >= his_edge_start && \
3405 my_edge_start <= his_edge_end)) \
3408 /* finds the nearest edge in the given direction from the current client
3409 * note to self: the edge is the -frame- edge (the actual one), not the
3412 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3414 gint dest
, monitor_dest
;
3415 gint my_edge_start
, my_edge_end
, my_offset
;
3422 a
= screen_area(c
->desktop
);
3423 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3426 case OB_DIRECTION_NORTH
:
3427 my_edge_start
= c
->frame
->area
.x
;
3428 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3429 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3431 /* default: top of screen */
3432 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3433 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3434 /* if the monitor edge comes before the screen edge, */
3435 /* use that as the destination instead. (For xinerama) */
3436 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3437 dest
= monitor_dest
;
3439 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3440 gint his_edge_start
, his_edge_end
, his_offset
;
3441 ObClient
*cur
= it
->data
;
3445 his_edge_start
= cur
->frame
->area
.x
;
3446 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3447 his_offset
= cur
->frame
->area
.y
+
3448 (hang
? 0 : cur
->frame
->area
.height
);
3450 if(his_offset
+ 1 > my_offset
)
3453 if(his_offset
< dest
)
3456 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3459 case OB_DIRECTION_SOUTH
:
3460 my_edge_start
= c
->frame
->area
.x
;
3461 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3462 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3464 /* default: bottom of screen */
3465 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3466 monitor_dest
= monitor
->y
+ monitor
->height
-
3467 (hang
? c
->frame
->area
.height
: 0);
3468 /* if the monitor edge comes before the screen edge, */
3469 /* use that as the destination instead. (For xinerama) */
3470 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3471 dest
= monitor_dest
;
3473 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3474 gint his_edge_start
, his_edge_end
, his_offset
;
3475 ObClient
*cur
= it
->data
;
3479 his_edge_start
= cur
->frame
->area
.x
;
3480 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3481 his_offset
= cur
->frame
->area
.y
+
3482 (hang
? cur
->frame
->area
.height
: 0);
3485 if(his_offset
- 1 < my_offset
)
3488 if(his_offset
> dest
)
3491 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3494 case OB_DIRECTION_WEST
:
3495 my_edge_start
= c
->frame
->area
.y
;
3496 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3497 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3499 /* default: leftmost egde of screen */
3500 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3501 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3502 /* if the monitor edge comes before the screen edge, */
3503 /* use that as the destination instead. (For xinerama) */
3504 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3505 dest
= monitor_dest
;
3507 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3508 gint his_edge_start
, his_edge_end
, his_offset
;
3509 ObClient
*cur
= it
->data
;
3513 his_edge_start
= cur
->frame
->area
.y
;
3514 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3515 his_offset
= cur
->frame
->area
.x
+
3516 (hang
? 0 : cur
->frame
->area
.width
);
3518 if(his_offset
+ 1 > my_offset
)
3521 if(his_offset
< dest
)
3524 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3527 case OB_DIRECTION_EAST
:
3528 my_edge_start
= c
->frame
->area
.y
;
3529 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3530 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3532 /* default: rightmost edge of screen */
3533 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3534 monitor_dest
= monitor
->x
+ monitor
->width
-
3535 (hang
? c
->frame
->area
.width
: 0);
3536 /* if the monitor edge comes before the screen edge, */
3537 /* use that as the destination instead. (For xinerama) */
3538 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3539 dest
= monitor_dest
;
3541 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3542 gint his_edge_start
, his_edge_end
, his_offset
;
3543 ObClient
*cur
= it
->data
;
3547 his_edge_start
= cur
->frame
->area
.y
;
3548 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3549 his_offset
= cur
->frame
->area
.x
+
3550 (hang
? cur
->frame
->area
.width
: 0);
3552 if(his_offset
- 1 < my_offset
)
3555 if(his_offset
> dest
)
3558 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3561 case OB_DIRECTION_NORTHEAST
:
3562 case OB_DIRECTION_SOUTHEAST
:
3563 case OB_DIRECTION_NORTHWEST
:
3564 case OB_DIRECTION_SOUTHWEST
:
3565 /* not implemented */
3567 g_assert_not_reached();
3568 dest
= 0; /* suppress warning */
3573 ObClient
* client_under_pointer()
3577 ObClient
*ret
= NULL
;
3579 if (screen_pointer_pos(&x
, &y
)) {
3580 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3581 if (WINDOW_IS_CLIENT(it
->data
)) {
3582 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3583 if (c
->frame
->visible
&&
3584 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3594 gboolean
client_has_group_siblings(ObClient
*self
)
3596 return self
->group
&& self
->group
->members
->next
;