1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2004 Mikael Magnusson
5 Copyright (c) 2003 Ben 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 | FocusChangeMask | \
51 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
56 ObClientDestructor func
;
60 GList
*client_list
= NULL
;
61 GSList
*client_destructors
= NULL
;
63 static void client_get_all(ObClient
*self
);
64 static void client_toggle_border(ObClient
*self
, gboolean show
);
65 static void client_get_startup_id(ObClient
*self
);
66 static void client_get_area(ObClient
*self
);
67 static void client_get_desktop(ObClient
*self
);
68 static void client_get_state(ObClient
*self
);
69 static void client_get_shaped(ObClient
*self
);
70 static void client_get_mwm_hints(ObClient
*self
);
71 static void client_get_gravity(ObClient
*self
);
72 static void client_showhide(ObClient
*self
);
73 static void client_change_allowed_actions(ObClient
*self
);
74 static void client_change_state(ObClient
*self
);
75 static void client_apply_startup_state(ObClient
*self
);
76 static void client_restore_session_state(ObClient
*self
);
77 static void client_restore_session_stacking(ObClient
*self
);
78 static void client_urgent_notify(ObClient
*self
);
80 void client_startup(gboolean reconfig
)
87 void client_shutdown(gboolean reconfig
)
91 void client_add_destructor(ObClientDestructor func
, gpointer data
)
93 Destructor
*d
= g_new(Destructor
, 1);
96 client_destructors
= g_slist_prepend(client_destructors
, d
);
99 void client_remove_destructor(ObClientDestructor func
)
103 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
104 Destructor
*d
= it
->data
;
105 if (d
->func
== func
) {
107 client_destructors
= g_slist_delete_link(client_destructors
, it
);
113 void client_set_list()
115 Window
*windows
, *win_it
;
117 guint size
= g_list_length(client_list
);
119 /* create an array of the window ids */
121 windows
= g_new(Window
, size
);
123 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
124 *win_it
= ((ObClient
*)it
->data
)->window
;
128 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
129 net_client_list
, window
, (gulong
*)windows
, size
);
138 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
142 for (it = self->transients; it; it = g_slist_next(it)) {
143 if (!func(it->data, data)) return;
144 client_foreach_transient(it->data, func, data);
148 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
150 if (self->transient_for) {
151 if (self->transient_for != OB_TRAN_GROUP) {
152 if (!func(self->transient_for, data)) return;
153 client_foreach_ancestor(self->transient_for, func, data);
157 for (it = self->group->members; it; it = g_slist_next(it))
158 if (it->data != self &&
159 !((ObClient*)it->data)->transient_for) {
160 if (!func(it->data, data)) return;
161 client_foreach_ancestor(it->data, func, data);
168 void client_manage_all()
173 XWindowAttributes attrib
;
175 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
176 &w
, &w
, &children
, &nchild
);
178 /* remove all icon windows from the list */
179 for (i
= 0; i
< nchild
; i
++) {
180 if (children
[i
] == None
) continue;
181 wmhints
= XGetWMHints(ob_display
, children
[i
]);
183 if ((wmhints
->flags
& IconWindowHint
) &&
184 (wmhints
->icon_window
!= children
[i
]))
185 for (j
= 0; j
< nchild
; j
++)
186 if (children
[j
] == wmhints
->icon_window
) {
194 for (i
= 0; i
< nchild
; ++i
) {
195 if (children
[i
] == None
)
197 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
198 if (attrib
.override_redirect
) continue;
200 if (attrib
.map_state
!= IsUnmapped
)
201 client_manage(children
[i
]);
207 /* This should possibly do something more interesting than just match
208 * against WM_CLASS literally. */
209 static ObAppSettings
*get_settings(ObClient
*client
)
211 GSList
*a
= config_per_app_settings
;
214 ObAppSettings
*app
= (ObAppSettings
*) a
->data
;
216 if (!strcmp(app
->name
, client
->name
)) {
217 ob_debug("Window matching: %s\n", app
->name
);
218 /* Match if no role was specified in the per app setting, or if the string
219 * matches the beginning of the role, since apps like to set the role to
220 * things like browser-window-23c4b2f */
221 if (!app
->role
|| !strncmp(app
->role
, client
->role
, strlen(app
->role
)))
230 void client_manage(Window window
)
234 XWindowAttributes attrib
;
235 XSetWindowAttributes attrib_set
;
237 gboolean activate
= FALSE
;
238 ObAppSettings
*settings
;
242 /* check if it has already been unmapped by the time we started mapping
243 the grab does a sync so we don't have to here */
244 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
245 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
246 XPutBackEvent(ob_display
, &e
);
249 return; /* don't manage it */
252 /* make sure it isn't an override-redirect window */
253 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
254 attrib
.override_redirect
) {
256 return; /* don't manage it */
259 /* is the window a docking app */
260 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
261 if ((wmhint
->flags
& StateHint
) &&
262 wmhint
->initial_state
== WithdrawnState
) {
263 dock_add(window
, wmhint
);
271 ob_debug("Managing window: %lx\n", window
);
273 /* choose the events we want to receive on the CLIENT window */
274 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
275 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
276 XChangeWindowAttributes(ob_display
, window
,
277 CWEventMask
|CWDontPropagate
, &attrib_set
);
280 /* create the ObClient struct, and populate it from the hints on the
282 self
= g_new0(ObClient
, 1);
283 self
->obwin
.type
= Window_Client
;
284 self
->window
= window
;
286 /* non-zero defaults */
287 self
->title_count
= 1;
288 self
->wmstate
= NormalState
;
290 self
->desktop
= screen_num_desktops
; /* always an invalid value */
292 client_get_all(self
);
293 client_restore_session_state(self
);
295 sn_app_started(self
->class);
297 /* update the focus lists, do this before the call to change_state or
298 it can end up in the list twice! */
299 focus_order_add_new(self
);
301 client_change_state(self
);
303 /* remove the client's border (and adjust re gravity) */
304 client_toggle_border(self
, FALSE
);
306 /* specify that if we exit, the window should not be destroyed and should
307 be reparented back to root automatically */
308 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
310 /* create the decoration frame for the client window */
311 self
->frame
= frame_new();
313 frame_grab_client(self
->frame
, self
);
317 client_apply_startup_state(self
);
319 /* get and set application level settings */
320 settings
= get_settings(self
);
323 /* Don't worry, we won't actually both shade and undecorate the
324 * window when push comes to shove. */
325 if (settings
->shade
!= -1)
326 client_shade(self
, settings
->shade
);
327 if (settings
->decor
!= -1)
328 client_set_undecorated(self
, !settings
->decor
);
329 if (settings
->iconic
!= -1)
330 client_iconify(self
, settings
->iconic
);
331 if (settings
->skip_pager
!= -1)
332 client
->skip_pager
= !!settings
->skip_pager
;
333 if (settings
->skip_taskbar
!= -1)
334 client
->skip_taskbar
= !!settings
->skip_taskbar
;
336 /* 1 && -1 shouldn't be possible by the code in config.c */
337 if (settings
->max_vert
== 1 && self
->max_horz
== 1)
338 client_maximize(self
, TRUE
, 0, TRUE
);
339 else if (settings
->max_vert
== 0 && self
->max_horz
== 0)
340 client_maximize(self
, FALSE
, 0, TRUE
);
341 else if (settings
->max_vert
== 1 && self
->max_horz
== 0) {
342 client_maximize(self
, TRUE
, 2, TRUE
);
343 client_maximize(self
, FALSE
, 1, TRUE
);
344 } else if (settings
->max_vert
== 0 && self
->max_horz
== 1) {
345 client_maximize(self
, TRUE
, 1, TRUE
);
346 client_maximize(self
, FALSE
, 2, TRUE
);
349 if (settings
->fullscreen
!= -1)
350 client_fullscreen(self
, !!settings
->fullscreen
, TRUE
);
352 if (settings
->desktop
< screen_num_desktops
)
353 client_set_desktop(self
, settings
->desktop
, FALSE
);
355 if (settings
->layer
> -2 && settings
->layer
< 2)
356 client_set_layer(self
, settings
->layer
);
360 stacking_add(CLIENT_AS_WINDOW(self
));
361 client_restore_session_stacking(self
);
363 /* focus the new window? */
364 if (ob_state() != OB_STATE_STARTING
&&
365 (config_focus_new
|| client_search_focus_parent(self
)) ||
366 (settings
&& settings
->focus
== TRUE
) &&
367 /* note the check against Type_Normal/Dialog, not client_normal(self),
368 which would also include other types. in this case we want more
369 strict rules for focus */
370 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
371 self
->type
== OB_CLIENT_TYPE_DIALOG
))
375 if (self
->desktop
!= screen_desktop
) {
376 /* activate the window */
379 gboolean group_foc
= FALSE
;
384 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
386 if (client_focused(it
->data
))
394 (!self
->transient_for
&& (!self
->group
||
395 !self
->group
->members
->next
))) ||
396 client_search_focus_tree_full(self
) ||
398 !client_normal(focus_client
))
400 /* activate the window */
407 if (ob_state() == OB_STATE_RUNNING
) {
408 gint x
= self
->area
.x
, ox
= x
;
409 gint y
= self
->area
.y
, oy
= y
;
411 place_client(self
, &x
, &y
, settings
);
413 /* make sure the window is visible. */
414 client_find_onscreen(self
, &x
, &y
,
415 self
->frame
->area
.width
,
416 self
->frame
->area
.height
,
417 /* non-normal clients has less rules, and
418 windows that are being restored from a
419 session do also. we can assume you want
420 it back where you saved it. Clients saying
421 they placed themselves are subjected to
422 harder rules, ones that are placed by
423 place.c or by the user are allowed partially
424 off-screen and on xinerama divides (ie,
425 it is up to the placement routines to avoid
426 the xinerama divides) */
427 ((self
->positioned
& PPosition
) &&
428 !(self
->positioned
& USPosition
)) &&
429 client_normal(self
) &&
431 if (x
!= ox
|| y
!= oy
)
432 client_move(self
, x
, y
);
435 keyboard_grab_for_client(self
, TRUE
);
436 mouse_grab_for_client(self
, TRUE
);
438 client_showhide(self
);
440 /* use client_focus instead of client_activate cuz client_activate does
441 stuff like switch desktops etc and I'm not interested in all that when
442 a window maps since its not based on an action from the user like
443 clicking a window to activate is. so keep the new window out of the way
446 /* if using focus_delay, stop the timer now so that focus doesn't go
448 event_halt_focus_delay();
451 /* since focus can change the stacking orders, if we focus the window
452 then the standard raise it gets is not enough, we need to queue one
453 for after the focus change takes place */
457 /* client_activate does this but we aret using it so we have to do it
459 if (screen_showing_desktop
)
460 screen_show_desktop(FALSE
);
462 /* add to client list/map */
463 client_list
= g_list_append(client_list
, self
);
464 g_hash_table_insert(window_map
, &self
->window
, self
);
466 /* this has to happen after we're in the client_list */
467 screen_update_areas();
469 /* update the list hints */
472 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
475 void client_unmanage_all()
477 while (client_list
!= NULL
)
478 client_unmanage(client_list
->data
);
481 void client_unmanage(ObClient
*self
)
486 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
488 g_assert(self
!= NULL
);
490 keyboard_grab_for_client(self
, FALSE
);
491 mouse_grab_for_client(self
, FALSE
);
493 /* potentially fix focusLast */
494 if (config_focus_last
)
495 grab_pointer(TRUE
, OB_CURSOR_NONE
);
497 /* remove the window from our save set */
498 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
500 /* we dont want events no more */
501 XSelectInput(ob_display
, self
->window
, NoEventMask
);
503 frame_hide(self
->frame
);
505 client_list
= g_list_remove(client_list
, self
);
506 stacking_remove(self
);
507 g_hash_table_remove(window_map
, &self
->window
);
509 /* update the focus lists */
510 focus_order_remove(self
);
512 /* once the client is out of the list, update the struts to remove it's
514 screen_update_areas();
516 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
517 Destructor
*d
= it
->data
;
518 d
->func(self
, d
->data
);
521 if (focus_client
== self
) {
524 /* focus the last focused window on the desktop, and ignore enter
525 events from the unmap so it doesnt mess with the focus */
526 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
527 /* remove these flags so we don't end up getting focused in the
529 self
->can_focus
= FALSE
;
530 self
->focus_notify
= FALSE
;
532 client_unfocus(self
);
535 /* tell our parent(s) that we're gone */
536 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
537 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
538 if (it
->data
!= self
)
539 ((ObClient
*)it
->data
)->transients
=
540 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
541 } else if (self
->transient_for
) { /* transient of window */
542 self
->transient_for
->transients
=
543 g_slist_remove(self
->transient_for
->transients
, self
);
546 /* tell our transients that we're gone */
547 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
548 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
549 ((ObClient
*)it
->data
)->transient_for
= NULL
;
550 client_calc_layer(it
->data
);
554 /* remove from its group */
556 group_remove(self
->group
, self
);
560 /* give the client its border back */
561 client_toggle_border(self
, TRUE
);
563 /* reparent the window out of the frame, and free the frame */
564 frame_release_client(self
->frame
, self
);
567 if (ob_state() != OB_STATE_EXITING
) {
568 /* these values should not be persisted across a window
570 PROP_ERASE(self
->window
, net_wm_desktop
);
571 PROP_ERASE(self
->window
, net_wm_state
);
572 PROP_ERASE(self
->window
, wm_state
);
574 /* if we're left in an unmapped state, the client wont be mapped. this
575 is bad, since we will no longer be managing the window on restart */
576 XMapWindow(ob_display
, self
->window
);
580 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
582 /* free all data allocated in the client struct */
583 g_slist_free(self
->transients
);
584 for (j
= 0; j
< self
->nicons
; ++j
)
585 g_free(self
->icons
[j
].data
);
586 if (self
->nicons
> 0)
589 g_free(self
->icon_title
);
593 g_free(self
->sm_client_id
);
596 /* update the list hints */
599 if (config_focus_last
)
600 grab_pointer(FALSE
, OB_CURSOR_NONE
);
603 static void client_urgent_notify(ObClient
*self
)
606 frame_flash_start(self
->frame
);
608 frame_flash_stop(self
->frame
);
611 static void client_restore_session_state(ObClient
*self
)
615 if (!(it
= session_state_find(self
)))
618 self
->session
= it
->data
;
620 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
621 self
->positioned
= PPosition
;
622 if (self
->session
->w
> 0)
623 self
->area
.width
= self
->session
->w
;
624 if (self
->session
->h
> 0)
625 self
->area
.height
= self
->session
->h
;
626 XResizeWindow(ob_display
, self
->window
,
627 self
->area
.width
, self
->area
.height
);
629 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
630 self
->session
->desktop
:
631 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
632 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
634 self
->shaded
= self
->session
->shaded
;
635 self
->iconic
= self
->session
->iconic
;
636 self
->skip_pager
= self
->session
->skip_pager
;
637 self
->skip_taskbar
= self
->session
->skip_taskbar
;
638 self
->fullscreen
= self
->session
->fullscreen
;
639 self
->above
= self
->session
->above
;
640 self
->below
= self
->session
->below
;
641 self
->max_horz
= self
->session
->max_horz
;
642 self
->max_vert
= self
->session
->max_vert
;
645 static void client_restore_session_stacking(ObClient
*self
)
649 if (!self
->session
) return;
651 it
= g_list_find(session_saved_state
, self
->session
);
652 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
655 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
656 if (session_state_cmp(it
->data
, cit
->data
))
659 client_calc_layer(self
);
660 stacking_below(CLIENT_AS_WINDOW(self
),
661 CLIENT_AS_WINDOW(cit
->data
));
667 void client_move_onscreen(ObClient
*self
, gboolean rude
)
669 gint x
= self
->area
.x
;
670 gint y
= self
->area
.y
;
671 if (client_find_onscreen(self
, &x
, &y
,
672 self
->frame
->area
.width
,
673 self
->frame
->area
.height
, rude
)) {
674 client_move(self
, x
, y
);
678 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
682 gint ox
= *x
, oy
= *y
;
684 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
687 /* XXX watch for xinerama dead areas */
688 /* This makes sure windows aren't entirely outside of the screen so you
689 * can't see them at all */
690 if (client_normal(self
)) {
691 a
= screen_area(self
->desktop
);
692 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
693 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
694 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
695 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
696 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
698 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
702 /* This here doesn't let windows even a pixel outside the screen,
703 * when called from client_manage, programs placing themselves are
704 * forced completely onscreen, while things like
705 * xterm -geometry resolution-width/2 will work fine. Trying to
706 * place it completely offscreen will be handled in the above code.
707 * Sorry for this confused comment, i am tired. */
709 /* avoid the xinerama monitor divide while we're at it,
710 * remember to fix the placement stuff to avoid it also and
711 * then remove this XXX */
712 a
= screen_physical_area_monitor(client_monitor(self
));
713 /* dont let windows map/move into the strut unless they
714 are bigger than the available area */
716 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
717 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
718 *x
= a
->x
+ a
->width
- w
;
720 if (h
<= a
->height
) {
721 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
722 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
723 *y
= a
->y
+ a
->height
- h
;
727 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
730 return ox
!= *x
|| oy
!= *y
;
733 static void client_toggle_border(ObClient
*self
, gboolean show
)
735 /* adjust our idea of where the client is, based on its border. When the
736 border is removed, the client should now be considered to be in a
738 when re-adding the border to the client, the same operation needs to be
740 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
741 gint x
= oldx
, y
= oldy
;
742 switch(self
->gravity
) {
744 case NorthWestGravity
:
746 case SouthWestGravity
:
748 case NorthEastGravity
:
750 case SouthEastGravity
:
751 if (show
) x
-= self
->border_width
* 2;
752 else x
+= self
->border_width
* 2;
759 if (show
) x
-= self
->border_width
;
760 else x
+= self
->border_width
;
763 switch(self
->gravity
) {
765 case NorthWestGravity
:
767 case NorthEastGravity
:
769 case SouthWestGravity
:
771 case SouthEastGravity
:
772 if (show
) y
-= self
->border_width
* 2;
773 else y
+= self
->border_width
* 2;
780 if (show
) y
-= self
->border_width
;
781 else y
+= self
->border_width
;
788 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
790 /* move the client so it is back it the right spot _with_ its
792 if (x
!= oldx
|| y
!= oldy
)
793 XMoveWindow(ob_display
, self
->window
, x
, y
);
795 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
799 static void client_get_all(ObClient
*self
)
801 client_get_area(self
);
802 client_update_transient_for(self
);
803 client_update_wmhints(self
);
804 client_get_startup_id(self
);
805 client_get_desktop(self
);
806 client_get_shaped(self
);
808 client_get_mwm_hints(self
);
809 client_get_type(self
);/* this can change the mwmhints for special cases */
811 /* The transient hint is used to pick a type, but the type can also affect
812 transiency (dialogs are always made transients). This is Havoc's idea,
813 but it is needed to make some apps work right (eg tsclient). */
814 client_update_transient_for(self
);
816 client_get_state(self
);
819 /* a couple type-based defaults for new windows */
821 /* this makes sure that these windows appear on all desktops */
822 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
823 self
->desktop
= DESKTOP_ALL
;
826 client_update_protocols(self
);
828 client_get_gravity(self
); /* get the attribute gravity */
829 client_update_normal_hints(self
); /* this may override the attribute
832 /* got the type, the mwmhints, the protocols, and the normal hints
833 (min/max sizes), so we're ready to set up the decorations/functions */
834 client_setup_decor_and_functions(self
);
836 client_update_title(self
);
837 client_update_class(self
);
838 client_update_sm_client_id(self
);
839 client_update_strut(self
);
840 client_update_icons(self
);
843 static void client_get_startup_id(ObClient
*self
)
845 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
847 PROP_GETS(self
->group
->leader
,
848 net_startup_id
, utf8
, &self
->startup_id
);
851 static void client_get_area(ObClient
*self
)
853 XWindowAttributes wattrib
;
856 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
857 g_assert(ret
!= BadWindow
);
859 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
860 self
->border_width
= wattrib
.border_width
;
863 static void client_get_desktop(ObClient
*self
)
865 guint32 d
= screen_num_desktops
; /* an always-invalid value */
867 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
868 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
869 self
->desktop
= screen_num_desktops
- 1;
873 gboolean trdesk
= FALSE
;
875 if (self
->transient_for
) {
876 if (self
->transient_for
!= OB_TRAN_GROUP
) {
877 self
->desktop
= self
->transient_for
->desktop
;
882 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
883 if (it
->data
!= self
&&
884 !((ObClient
*)it
->data
)->transient_for
) {
885 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
892 /* try get from the startup-notification protocol */
893 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
894 if (self
->desktop
>= screen_num_desktops
&&
895 self
->desktop
!= DESKTOP_ALL
)
896 self
->desktop
= screen_num_desktops
- 1;
898 /* defaults to the current desktop */
899 self
->desktop
= screen_desktop
;
902 if (self
->desktop
!= d
) {
903 /* set the desktop hint, to make sure that it always exists */
904 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
908 static void client_get_state(ObClient
*self
)
913 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
915 for (i
= 0; i
< num
; ++i
) {
916 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
918 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
920 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
922 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
923 self
->skip_taskbar
= TRUE
;
924 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
925 self
->skip_pager
= TRUE
;
926 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
927 self
->fullscreen
= TRUE
;
928 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
929 self
->max_vert
= TRUE
;
930 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
931 self
->max_horz
= TRUE
;
932 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
934 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
936 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
937 self
->undecorated
= TRUE
;
943 if (!(self
->above
|| self
->below
)) {
945 /* apply stuff from the group */
949 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
950 ObClient
*c
= it
->data
;
951 if (c
!= self
&& !client_search_transient(self
, c
) &&
952 client_normal(self
) && client_normal(c
))
955 (c
->above
? 1 : (c
->below
? -1 : 0)));
969 g_assert_not_reached();
976 static void client_get_shaped(ObClient
*self
)
978 self
->shaped
= FALSE
;
980 if (extensions_shape
) {
985 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
987 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
988 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
990 self
->shaped
= (s
!= 0);
995 void client_update_transient_for(ObClient
*self
)
998 ObClient
*target
= NULL
;
1000 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1001 self
->transient
= TRUE
;
1002 if (t
!= self
->window
) { /* cant be transient to itself! */
1003 target
= g_hash_table_lookup(window_map
, &t
);
1004 /* if this happens then we need to check for it*/
1005 g_assert(target
!= self
);
1006 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1007 /* this can happen when a dialog is a child of
1008 a dockapp, for example */
1012 if (!target
&& self
->group
) {
1013 /* not transient to a client, see if it is transient for a
1015 if (t
== self
->group
->leader
||
1017 t
== RootWindow(ob_display
, ob_screen
))
1019 /* window is a transient for its group! */
1020 target
= OB_TRAN_GROUP
;
1024 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
&& self
->group
) {
1025 self
->transient
= TRUE
;
1026 target
= OB_TRAN_GROUP
;
1028 self
->transient
= FALSE
;
1030 /* if anything has changed... */
1031 if (target
!= self
->transient_for
) {
1032 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1035 /* remove from old parents */
1036 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1037 ObClient
*c
= it
->data
;
1038 if (c
!= self
&& !c
->transient_for
)
1039 c
->transients
= g_slist_remove(c
->transients
, self
);
1041 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1042 /* remove from old parent */
1043 self
->transient_for
->transients
=
1044 g_slist_remove(self
->transient_for
->transients
, self
);
1046 self
->transient_for
= target
;
1047 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
1050 /* add to new parents */
1051 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1052 ObClient
*c
= it
->data
;
1053 if (c
!= self
&& !c
->transient_for
)
1054 c
->transients
= g_slist_append(c
->transients
, self
);
1057 /* remove all transients which are in the group, that causes
1058 circlular pointer hell of doom */
1059 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1061 for (sit
= self
->transients
; sit
; sit
= next
) {
1062 next
= g_slist_next(sit
);
1063 if (sit
->data
== it
->data
)
1065 g_slist_delete_link(self
->transients
, sit
);
1068 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1069 /* add to new parent */
1070 self
->transient_for
->transients
=
1071 g_slist_append(self
->transient_for
->transients
, self
);
1076 static void client_get_mwm_hints(ObClient
*self
)
1081 self
->mwmhints
.flags
= 0; /* default to none */
1083 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1085 if (num
>= OB_MWM_ELEMENTS
) {
1086 self
->mwmhints
.flags
= hints
[0];
1087 self
->mwmhints
.functions
= hints
[1];
1088 self
->mwmhints
.decorations
= hints
[2];
1094 void client_get_type(ObClient
*self
)
1101 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1102 /* use the first value that we know about in the array */
1103 for (i
= 0; i
< num
; ++i
) {
1104 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1105 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1106 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1107 self
->type
= OB_CLIENT_TYPE_DOCK
;
1108 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1109 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1110 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1111 self
->type
= OB_CLIENT_TYPE_MENU
;
1112 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1113 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1114 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1115 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1116 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1117 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1118 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1119 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1120 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1121 /* prevent this window from getting any decor or
1123 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1124 OB_MWM_FLAG_DECORATIONS
);
1125 self
->mwmhints
.decorations
= 0;
1126 self
->mwmhints
.functions
= 0;
1128 if (self
->type
!= (ObClientType
) -1)
1129 break; /* grab the first legit type */
1134 if (self
->type
== (ObClientType
) -1) {
1135 /*the window type hint was not set, which means we either classify
1136 ourself as a normal window or a dialog, depending on if we are a
1138 if (self
->transient
)
1139 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1141 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1145 void client_update_protocols(ObClient
*self
)
1148 guint num_return
, i
;
1150 self
->focus_notify
= FALSE
;
1151 self
->delete_window
= FALSE
;
1153 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1154 for (i
= 0; i
< num_return
; ++i
) {
1155 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1156 /* this means we can request the window to close */
1157 self
->delete_window
= TRUE
;
1158 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1159 /* if this protocol is requested, then the window will be
1160 notified whenever we want it to receive focus */
1161 self
->focus_notify
= TRUE
;
1167 static void client_get_gravity(ObClient
*self
)
1169 XWindowAttributes wattrib
;
1172 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1173 g_assert(ret
!= BadWindow
);
1174 self
->gravity
= wattrib
.win_gravity
;
1177 void client_update_normal_hints(ObClient
*self
)
1181 gint oldgravity
= self
->gravity
;
1184 self
->min_ratio
= 0.0f
;
1185 self
->max_ratio
= 0.0f
;
1186 SIZE_SET(self
->size_inc
, 1, 1);
1187 SIZE_SET(self
->base_size
, 0, 0);
1188 SIZE_SET(self
->min_size
, 0, 0);
1189 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1191 /* get the hints from the window */
1192 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1193 /* normal windows can't request placement! har har
1194 if (!client_normal(self))
1196 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1198 if (size
.flags
& PWinGravity
) {
1199 self
->gravity
= size
.win_gravity
;
1201 /* if the client has a frame, i.e. has already been mapped and
1202 is changing its gravity */
1203 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1204 /* move our idea of the client's position based on its new
1206 self
->area
.x
= self
->frame
->area
.x
;
1207 self
->area
.y
= self
->frame
->area
.y
;
1208 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1212 if (size
.flags
& PAspect
) {
1213 if (size
.min_aspect
.y
)
1215 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1216 if (size
.max_aspect
.y
)
1218 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1221 if (size
.flags
& PMinSize
)
1222 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1224 if (size
.flags
& PMaxSize
)
1225 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1227 if (size
.flags
& PBaseSize
)
1228 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1230 if (size
.flags
& PResizeInc
)
1231 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1235 void client_setup_decor_and_functions(ObClient
*self
)
1237 /* start with everything (cept fullscreen) */
1239 (OB_FRAME_DECOR_TITLEBAR
|
1240 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1241 OB_FRAME_DECOR_GRIPS
|
1242 OB_FRAME_DECOR_BORDER
|
1243 OB_FRAME_DECOR_ICON
|
1244 OB_FRAME_DECOR_ALLDESKTOPS
|
1245 OB_FRAME_DECOR_ICONIFY
|
1246 OB_FRAME_DECOR_MAXIMIZE
|
1247 OB_FRAME_DECOR_SHADE
|
1248 OB_FRAME_DECOR_CLOSE
);
1250 (OB_CLIENT_FUNC_RESIZE
|
1251 OB_CLIENT_FUNC_MOVE
|
1252 OB_CLIENT_FUNC_ICONIFY
|
1253 OB_CLIENT_FUNC_MAXIMIZE
|
1254 OB_CLIENT_FUNC_SHADE
|
1255 OB_CLIENT_FUNC_CLOSE
);
1257 if (!(self
->min_size
.width
< self
->max_size
.width
||
1258 self
->min_size
.height
< self
->max_size
.height
))
1259 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1261 switch (self
->type
) {
1262 case OB_CLIENT_TYPE_NORMAL
:
1263 /* normal windows retain all of the possible decorations and
1264 functionality, and are the only windows that you can fullscreen */
1265 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1268 case OB_CLIENT_TYPE_DIALOG
:
1269 case OB_CLIENT_TYPE_UTILITY
:
1270 /* these windows cannot be maximized */
1271 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1274 case OB_CLIENT_TYPE_MENU
:
1275 case OB_CLIENT_TYPE_TOOLBAR
:
1276 /* these windows get less functionality */
1277 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1280 case OB_CLIENT_TYPE_DESKTOP
:
1281 case OB_CLIENT_TYPE_DOCK
:
1282 case OB_CLIENT_TYPE_SPLASH
:
1283 /* none of these windows are manipulated by the window manager */
1284 self
->decorations
= 0;
1285 self
->functions
= 0;
1289 /* Mwm Hints are applied subtractively to what has already been chosen for
1290 decor and functionality */
1291 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1292 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1293 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1294 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1295 /* if the mwm hints request no handle or title, then all
1296 decorations are disabled */
1297 self
->decorations
= config_theme_keepborder
? OB_FRAME_DECOR_BORDER
: 0;
1301 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1302 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1303 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1304 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1305 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1306 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1307 /* dont let mwm hints kill any buttons
1308 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1309 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1310 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1311 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1313 /* dont let mwm hints kill the close button
1314 if (! (self->mwmhints.functions & MwmFunc_Close))
1315 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1319 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1320 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1321 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1322 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1323 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1324 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1326 /* can't maximize without moving/resizing */
1327 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1328 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1329 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1330 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1331 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1334 /* kill the handle on fully maxed windows */
1335 if (self
->max_vert
&& self
->max_horz
)
1336 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1338 /* finally, the user can have requested no decorations, which overrides
1339 everything (but doesnt give it a border if it doesnt have one) */
1340 if (self
->undecorated
) {
1341 if (config_theme_keepborder
)
1342 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1344 self
->decorations
= 0;
1347 /* if we don't have a titlebar, then we cannot shade! */
1348 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1349 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1351 /* now we need to check against rules for the client's current state */
1352 if (self
->fullscreen
) {
1353 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1354 OB_CLIENT_FUNC_FULLSCREEN
|
1355 OB_CLIENT_FUNC_ICONIFY
);
1356 self
->decorations
= 0;
1359 client_change_allowed_actions(self
);
1362 /* adjust the client's decorations, etc. */
1363 client_reconfigure(self
);
1367 static void client_change_allowed_actions(ObClient
*self
)
1372 /* desktop windows are kept on all desktops */
1373 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1374 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1376 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1377 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1378 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1379 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1380 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1381 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1382 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1383 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1384 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1385 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1386 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1387 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1388 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1389 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1390 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1393 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1395 /* make sure the window isn't breaking any rules now */
1397 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1398 if (self
->frame
) client_shade(self
, FALSE
);
1399 else self
->shaded
= FALSE
;
1401 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1402 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1403 else self
->iconic
= FALSE
;
1405 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1406 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1407 else self
->fullscreen
= FALSE
;
1409 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1411 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1412 else self
->max_vert
= self
->max_horz
= FALSE
;
1416 void client_reconfigure(ObClient
*self
)
1418 /* by making this pass FALSE for user, we avoid the emacs event storm where
1419 every configurenotify causes an update in its normal hints, i think this
1420 is generally what we want anyways... */
1421 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1422 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1425 void client_update_wmhints(ObClient
*self
)
1428 gboolean ur
= FALSE
;
1431 /* assume a window takes input if it doesnt specify */
1432 self
->can_focus
= TRUE
;
1434 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1435 if (hints
->flags
& InputHint
)
1436 self
->can_focus
= hints
->input
;
1438 /* only do this when first managing the window *AND* when we aren't
1440 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1441 if (hints
->flags
& StateHint
)
1442 self
->iconic
= hints
->initial_state
== IconicState
;
1444 if (hints
->flags
& XUrgencyHint
)
1447 if (!(hints
->flags
& WindowGroupHint
))
1448 hints
->window_group
= None
;
1450 /* did the group state change? */
1451 if (hints
->window_group
!=
1452 (self
->group
? self
->group
->leader
: None
)) {
1453 /* remove from the old group if there was one */
1454 if (self
->group
!= NULL
) {
1455 /* remove transients of the group */
1456 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1457 self
->transients
= g_slist_remove(self
->transients
,
1460 /* remove myself from parents in the group */
1461 if (self
->transient_for
== OB_TRAN_GROUP
) {
1462 for (it
= self
->group
->members
; it
;
1463 it
= g_slist_next(it
))
1465 ObClient
*c
= it
->data
;
1467 if (c
!= self
&& !c
->transient_for
)
1468 c
->transients
= g_slist_remove(c
->transients
,
1473 group_remove(self
->group
, self
);
1476 if (hints
->window_group
!= None
) {
1477 self
->group
= group_add(hints
->window_group
, self
);
1479 /* i can only have transients from the group if i am not
1481 if (!self
->transient_for
) {
1482 /* add other transients of the group that are already
1484 for (it
= self
->group
->members
; it
;
1485 it
= g_slist_next(it
))
1487 ObClient
*c
= it
->data
;
1488 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1490 g_slist_append(self
->transients
, c
);
1495 /* because the self->transient flag wont change from this call,
1496 we don't need to update the window's type and such, only its
1497 transient_for, and the transients lists of other windows in
1498 the group may be affected */
1499 client_update_transient_for(self
);
1502 /* the WM_HINTS can contain an icon */
1503 client_update_icons(self
);
1508 if (ur
!= self
->urgent
) {
1510 /* fire the urgent callback if we're mapped, otherwise, wait until
1511 after we're mapped */
1513 client_urgent_notify(self
);
1517 void client_update_title(ObClient
*self
)
1523 gboolean read_title
;
1526 old_title
= self
->title
;
1529 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1530 /* try old x stuff */
1531 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
)) {
1532 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1533 if (self
->transient
) {
1534 data
= g_strdup("");
1537 data
= g_strdup("Unnamed Window");
1541 /* did the title change? then reset the title_count */
1542 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1543 self
->title_count
= 1;
1545 /* look for duplicates and append a number */
1547 for (it
= client_list
; it
; it
= g_list_next(it
))
1548 if (it
->data
!= self
) {
1549 ObClient
*c
= it
->data
;
1550 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1551 nums
|= 1 << c
->title_count
;
1553 /* find first free number */
1554 for (i
= 1; i
<= 32; ++i
)
1555 if (!(nums
& (1 << i
))) {
1556 if (self
->title_count
== 1 || i
== 1)
1557 self
->title_count
= i
;
1560 /* dont display the number for the first window */
1561 if (self
->title_count
> 1) {
1563 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1568 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1573 frame_adjust_title(self
->frame
);
1577 /* update the icon title */
1579 g_free(self
->icon_title
);
1583 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1584 /* try old x stuff */
1585 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1586 data
= g_strdup(self
->title
);
1590 /* append the title count, dont display the number for the first window */
1591 if (read_title
&& self
->title_count
> 1) {
1592 gchar
*vdata
, *ndata
;
1593 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1594 vdata
= g_strconcat(data
, ndata
, NULL
);
1600 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1602 self
->icon_title
= data
;
1605 void client_update_class(ObClient
*self
)
1610 if (self
->name
) g_free(self
->name
);
1611 if (self
->class) g_free(self
->class);
1612 if (self
->role
) g_free(self
->role
);
1614 self
->name
= self
->class = self
->role
= NULL
;
1616 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1618 self
->name
= g_strdup(data
[0]);
1620 self
->class = g_strdup(data
[1]);
1625 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1628 if (self
->name
== NULL
) self
->name
= g_strdup("");
1629 if (self
->class == NULL
) self
->class = g_strdup("");
1630 if (self
->role
== NULL
) self
->role
= g_strdup("");
1633 void client_update_strut(ObClient
*self
)
1637 gboolean got
= FALSE
;
1640 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1644 STRUT_PARTIAL_SET(strut
,
1645 data
[0], data
[2], data
[1], data
[3],
1646 data
[4], data
[5], data
[8], data
[9],
1647 data
[6], data
[7], data
[10], data
[11]);
1653 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1659 /* use the screen's width/height */
1660 a
= screen_physical_area();
1662 STRUT_PARTIAL_SET(strut
,
1663 data
[0], data
[2], data
[1], data
[3],
1664 a
->y
, a
->y
+ a
->height
- 1,
1665 a
->x
, a
->x
+ a
->width
- 1,
1666 a
->y
, a
->y
+ a
->height
- 1,
1667 a
->x
, a
->x
+ a
->width
- 1);
1673 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1674 0, 0, 0, 0, 0, 0, 0, 0);
1676 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1677 self
->strut
= strut
;
1679 /* updating here is pointless while we're being mapped cuz we're not in
1680 the client list yet */
1682 screen_update_areas();
1686 void client_update_icons(ObClient
*self
)
1692 for (i
= 0; i
< self
->nicons
; ++i
)
1693 g_free(self
->icons
[i
].data
);
1694 if (self
->nicons
> 0)
1695 g_free(self
->icons
);
1698 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1699 /* figure out how many valid icons are in here */
1701 while (num
- i
> 2) {
1705 if (i
> num
|| w
*h
== 0) break;
1709 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1711 /* store the icons */
1713 for (j
= 0; j
< self
->nicons
; ++j
) {
1716 w
= self
->icons
[j
].width
= data
[i
++];
1717 h
= self
->icons
[j
].height
= data
[i
++];
1719 if (w
*h
== 0) continue;
1721 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1722 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1727 self
->icons
[j
].data
[t
] =
1728 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1729 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1730 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1731 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1737 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1738 kwm_win_icon
, &data
, &num
)) {
1741 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1742 xerror_set_ignore(TRUE
);
1743 if (!RrPixmapToRGBA(ob_rr_inst
,
1745 &self
->icons
[self
->nicons
-1].width
,
1746 &self
->icons
[self
->nicons
-1].height
,
1747 &self
->icons
[self
->nicons
-1].data
)) {
1748 g_free(&self
->icons
[self
->nicons
-1]);
1751 xerror_set_ignore(FALSE
);
1757 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1758 if (hints
->flags
& IconPixmapHint
) {
1760 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1761 xerror_set_ignore(TRUE
);
1762 if (!RrPixmapToRGBA(ob_rr_inst
,
1764 (hints
->flags
& IconMaskHint
?
1765 hints
->icon_mask
: None
),
1766 &self
->icons
[self
->nicons
-1].width
,
1767 &self
->icons
[self
->nicons
-1].height
,
1768 &self
->icons
[self
->nicons
-1].data
)){
1769 g_free(&self
->icons
[self
->nicons
-1]);
1772 xerror_set_ignore(FALSE
);
1779 frame_adjust_icon(self
->frame
);
1782 static void client_change_state(ObClient
*self
)
1785 gulong netstate
[11];
1788 state
[0] = self
->wmstate
;
1790 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1794 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1796 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1798 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1799 if (self
->skip_taskbar
)
1800 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1801 if (self
->skip_pager
)
1802 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1803 if (self
->fullscreen
)
1804 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1806 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1808 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1810 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1812 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1813 if (self
->undecorated
)
1814 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1815 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1817 client_calc_layer(self
);
1820 frame_adjust_state(self
->frame
);
1823 ObClient
*client_search_focus_tree(ObClient
*self
)
1828 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1829 if (client_focused(it
->data
)) return it
->data
;
1830 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1835 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1837 if (self
->transient_for
) {
1838 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1839 return client_search_focus_tree_full(self
->transient_for
);
1842 gboolean recursed
= FALSE
;
1844 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1845 if (!((ObClient
*)it
->data
)->transient_for
) {
1847 if ((c
= client_search_focus_tree_full(it
->data
)))
1856 /* this function checks the whole tree, the client_search_focus_tree~
1857 does not, so we need to check this window */
1858 if (client_focused(self
))
1860 return client_search_focus_tree(self
);
1863 static ObStackingLayer
calc_layer(ObClient
*self
)
1867 if (self
->fullscreen
&&
1868 (client_focused(self
) || client_search_focus_tree(self
)))
1869 l
= OB_STACKING_LAYER_FULLSCREEN
;
1870 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1871 l
= OB_STACKING_LAYER_DESKTOP
;
1872 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1873 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
1874 else l
= OB_STACKING_LAYER_ABOVE
;
1876 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1877 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1878 else l
= OB_STACKING_LAYER_NORMAL
;
1883 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1884 ObStackingLayer l
, gboolean raised
)
1886 ObStackingLayer old
, own
;
1890 own
= calc_layer(self
);
1891 self
->layer
= l
> own
? l
: own
;
1893 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
1894 client_calc_layer_recursive(it
->data
, orig
,
1895 l
, raised
? raised
: l
!= old
);
1897 if (!raised
&& l
!= old
)
1898 if (orig
->frame
) { /* only restack if the original window is managed */
1899 stacking_remove(CLIENT_AS_WINDOW(self
));
1900 stacking_add(CLIENT_AS_WINDOW(self
));
1904 void client_calc_layer(ObClient
*self
)
1911 /* transients take on the layer of their parents */
1912 self
= client_search_top_transient(self
);
1914 l
= calc_layer(self
);
1916 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1919 gboolean
client_should_show(ObClient
*self
)
1923 if (client_normal(self
) && screen_showing_desktop
)
1926 if (self->transient_for) {
1927 if (self->transient_for != OB_TRAN_GROUP)
1928 return client_should_show(self->transient_for);
1932 for (it = self->group->members; it; it = g_slist_next(it)) {
1933 ObClient *c = it->data;
1934 if (c != self && !c->transient_for) {
1935 if (client_should_show(c))
1942 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
1948 static void client_showhide(ObClient
*self
)
1951 if (client_should_show(self
))
1952 frame_show(self
->frame
);
1954 frame_hide(self
->frame
);
1957 gboolean
client_normal(ObClient
*self
) {
1958 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1959 self
->type
== OB_CLIENT_TYPE_DOCK
||
1960 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1963 static void client_apply_startup_state(ObClient
*self
)
1965 /* these are in a carefully crafted order.. */
1968 self
->iconic
= FALSE
;
1969 client_iconify(self
, TRUE
, FALSE
);
1971 if (self
->fullscreen
) {
1972 self
->fullscreen
= FALSE
;
1973 client_fullscreen(self
, TRUE
, FALSE
);
1975 if (self
->undecorated
) {
1976 self
->undecorated
= FALSE
;
1977 client_set_undecorated(self
, TRUE
);
1980 self
->shaded
= FALSE
;
1981 client_shade(self
, TRUE
);
1984 client_urgent_notify(self
);
1986 if (self
->max_vert
&& self
->max_horz
) {
1987 self
->max_vert
= self
->max_horz
= FALSE
;
1988 client_maximize(self
, TRUE
, 0, FALSE
);
1989 } else if (self
->max_vert
) {
1990 self
->max_vert
= FALSE
;
1991 client_maximize(self
, TRUE
, 2, FALSE
);
1992 } else if (self
->max_horz
) {
1993 self
->max_horz
= FALSE
;
1994 client_maximize(self
, TRUE
, 1, FALSE
);
1997 /* nothing to do for the other states:
2006 void client_configure_full(ObClient
*self
, ObCorner anchor
,
2007 gint x
, gint y
, gint w
, gint h
,
2008 gboolean user
, gboolean final
,
2009 gboolean force_reply
)
2012 gboolean send_resize_client
;
2013 gboolean moved
= FALSE
, resized
= FALSE
;
2014 guint fdecor
= self
->frame
->decorations
;
2015 gboolean fhorz
= self
->frame
->max_horz
;
2017 /* make the frame recalculate its dimentions n shit without changing
2018 anything visible for real, this way the constraints below can work with
2019 the updated frame dimensions. */
2020 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
2022 /* gets the frame's position */
2023 frame_client_gravity(self
->frame
, &x
, &y
);
2025 /* these positions are frame positions, not client positions */
2027 /* set the size and position if fullscreen */
2028 if (self
->fullscreen
) {
2031 XF86VidModeModeLine mode
;
2036 i
= client_monitor(self
);
2037 a
= screen_physical_area_monitor(i
);
2040 if (i
== 0 && /* primary head */
2041 extensions_vidmode
&&
2042 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
2043 /* get the mode last so the mode.privsize isnt freed incorrectly */
2044 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
2049 if (mode
.privsize
) XFree(mode
.private);
2059 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
2063 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
2065 /* set the size and position if maximized */
2066 if (self
->max_horz
) {
2068 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2070 if (self
->max_vert
) {
2072 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2076 /* gets the client's position */
2077 frame_frame_gravity(self
->frame
, &x
, &y
);
2079 /* these override the above states! if you cant move you can't move! */
2081 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2085 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2086 w
= self
->area
.width
;
2087 h
= self
->area
.height
;
2091 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
2092 gint basew
, baseh
, minw
, minh
;
2094 /* base size is substituted with min size if not specified */
2095 if (self
->base_size
.width
|| self
->base_size
.height
) {
2096 basew
= self
->base_size
.width
;
2097 baseh
= self
->base_size
.height
;
2099 basew
= self
->min_size
.width
;
2100 baseh
= self
->min_size
.height
;
2102 /* min size is substituted with base size if not specified */
2103 if (self
->min_size
.width
|| self
->min_size
.height
) {
2104 minw
= self
->min_size
.width
;
2105 minh
= self
->min_size
.height
;
2107 minw
= self
->base_size
.width
;
2108 minh
= self
->base_size
.height
;
2111 /* if this is a user-requested resize, then check against min/max
2114 /* smaller than min size or bigger than max size? */
2115 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
2116 if (w
< minw
) w
= minw
;
2117 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
2118 if (h
< minh
) h
= minh
;
2123 /* keep to the increments */
2124 w
/= self
->size_inc
.width
;
2125 h
/= self
->size_inc
.height
;
2127 /* you cannot resize to nothing */
2128 if (basew
+ w
< 1) w
= 1 - basew
;
2129 if (baseh
+ h
< 1) h
= 1 - baseh
;
2131 /* store the logical size */
2132 SIZE_SET(self
->logical_size
,
2133 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
2134 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
2136 w
*= self
->size_inc
.width
;
2137 h
*= self
->size_inc
.height
;
2142 /* adjust the height to match the width for the aspect ratios.
2143 for this, min size is not substituted for base size ever. */
2144 w
-= self
->base_size
.width
;
2145 h
-= self
->base_size
.height
;
2147 if (!self
->fullscreen
) {
2148 if (self
->min_ratio
)
2149 if (h
* self
->min_ratio
> w
) {
2150 h
= (gint
)(w
/ self
->min_ratio
);
2152 /* you cannot resize to nothing */
2155 w
= (gint
)(h
* self
->min_ratio
);
2158 if (self
->max_ratio
)
2159 if (h
* self
->max_ratio
< w
) {
2160 h
= (gint
)(w
/ self
->max_ratio
);
2162 /* you cannot resize to nothing */
2165 w
= (gint
)(h
* self
->min_ratio
);
2170 w
+= self
->base_size
.width
;
2171 h
+= self
->base_size
.height
;
2178 case OB_CORNER_TOPLEFT
:
2180 case OB_CORNER_TOPRIGHT
:
2181 x
-= w
- self
->area
.width
;
2183 case OB_CORNER_BOTTOMLEFT
:
2184 y
-= h
- self
->area
.height
;
2186 case OB_CORNER_BOTTOMRIGHT
:
2187 x
-= w
- self
->area
.width
;
2188 y
-= h
- self
->area
.height
;
2192 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2193 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2195 oldw
= self
->area
.width
;
2196 oldh
= self
->area
.height
;
2197 RECT_SET(self
->area
, x
, y
, w
, h
);
2199 /* for app-requested resizes, always resize if 'resized' is true.
2200 for user-requested ones, only resize if final is true, or when
2201 resizing in redraw mode */
2202 send_resize_client
= ((!user
&& resized
) ||
2204 (resized
&& config_resize_redraw
))));
2206 /* if the client is enlarging, then resize the client before the frame */
2207 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2208 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2210 /* move/resize the frame to match the request */
2212 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2213 moved
= resized
= TRUE
;
2215 if (moved
|| resized
)
2216 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2218 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2221 event
.type
= ConfigureNotify
;
2222 event
.xconfigure
.display
= ob_display
;
2223 event
.xconfigure
.event
= self
->window
;
2224 event
.xconfigure
.window
= self
->window
;
2226 /* root window real coords */
2227 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2229 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2231 event
.xconfigure
.width
= w
;
2232 event
.xconfigure
.height
= h
;
2233 event
.xconfigure
.border_width
= 0;
2234 event
.xconfigure
.above
= self
->frame
->plate
;
2235 event
.xconfigure
.override_redirect
= FALSE
;
2236 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2237 FALSE
, StructureNotifyMask
, &event
);
2241 /* if the client is shrinking, then resize the frame before the client */
2242 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2243 XResizeWindow(ob_display
, self
->window
, w
, h
);
2248 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2252 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2253 self
->fullscreen
== fs
) return; /* already done */
2255 self
->fullscreen
= fs
;
2256 client_change_state(self
); /* change the state hints on the client,
2257 and adjust out layer/stacking */
2261 self
->pre_fullscreen_area
= self
->area
;
2263 /* these are not actually used cuz client_configure will set them
2264 as appropriate when the window is fullscreened */
2269 if (self
->pre_fullscreen_area
.width
> 0 &&
2270 self
->pre_fullscreen_area
.height
> 0)
2272 x
= self
->pre_fullscreen_area
.x
;
2273 y
= self
->pre_fullscreen_area
.y
;
2274 w
= self
->pre_fullscreen_area
.width
;
2275 h
= self
->pre_fullscreen_area
.height
;
2276 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2278 /* pick some fallbacks... */
2279 a
= screen_area_monitor(self
->desktop
, 0);
2280 x
= a
->x
+ a
->width
/ 4;
2281 y
= a
->y
+ a
->height
/ 4;
2287 client_setup_decor_and_functions(self
);
2289 client_move_resize(self
, x
, y
, w
, h
);
2291 /* try focus us when we go into fullscreen mode */
2295 static void client_iconify_recursive(ObClient
*self
,
2296 gboolean iconic
, gboolean curdesk
)
2299 gboolean changed
= FALSE
;
2302 if (self
->iconic
!= iconic
) {
2303 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2306 self
->iconic
= iconic
;
2309 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2312 old
= self
->wmstate
;
2313 self
->wmstate
= IconicState
;
2314 if (old
!= self
->wmstate
)
2315 PROP_MSG(self
->window
, kde_wm_change_state
,
2316 self
->wmstate
, 1, 0, 0);
2318 /* update the focus lists.. iconic windows go to the bottom of
2319 the list, put the new iconic window at the 'top of the
2321 focus_order_to_top(self
);
2329 client_set_desktop(self
, screen_desktop
, FALSE
);
2331 old
= self
->wmstate
;
2332 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2333 if (old
!= self
->wmstate
)
2334 PROP_MSG(self
->window
, kde_wm_change_state
,
2335 self
->wmstate
, 1, 0, 0);
2337 /* this puts it after the current focused window */
2338 focus_order_remove(self
);
2339 focus_order_add_new(self
);
2341 /* this is here cuz with the VIDMODE extension, the viewport can
2342 change while a fullscreen window is iconic, and when it
2343 uniconifies, it would be nice if it did so to the new position
2345 client_reconfigure(self
);
2352 client_change_state(self
);
2353 client_showhide(self
);
2354 screen_update_areas();
2357 /* iconify all transients */
2358 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2359 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2363 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2365 /* move up the transient chain as far as possible first */
2366 self
= client_search_top_transient(self
);
2368 client_iconify_recursive(client_search_top_transient(self
),
2372 void client_maximize(ObClient
*self
, gboolean max
, gint dir
, gboolean savearea
)
2376 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2377 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2379 /* check if already done */
2381 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2382 if (dir
== 1 && self
->max_horz
) return;
2383 if (dir
== 2 && self
->max_vert
) return;
2385 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2386 if (dir
== 1 && !self
->max_horz
) return;
2387 if (dir
== 2 && !self
->max_vert
) return;
2390 /* we just tell it to configure in the same place and client_configure
2391 worries about filling the screen with the window */
2394 w
= self
->area
.width
;
2395 h
= self
->area
.height
;
2399 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2400 RECT_SET(self
->pre_max_area
,
2401 self
->area
.x
, self
->pre_max_area
.y
,
2402 self
->area
.width
, self
->pre_max_area
.height
);
2404 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2405 RECT_SET(self
->pre_max_area
,
2406 self
->pre_max_area
.x
, self
->area
.y
,
2407 self
->pre_max_area
.width
, self
->area
.height
);
2413 a
= screen_area_monitor(self
->desktop
, 0);
2414 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2415 if (self
->pre_max_area
.width
> 0) {
2416 x
= self
->pre_max_area
.x
;
2417 w
= self
->pre_max_area
.width
;
2419 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2420 0, self
->pre_max_area
.height
);
2422 /* pick some fallbacks... */
2423 x
= a
->x
+ a
->width
/ 4;
2427 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2428 if (self
->pre_max_area
.height
> 0) {
2429 y
= self
->pre_max_area
.y
;
2430 h
= self
->pre_max_area
.height
;
2432 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2433 self
->pre_max_area
.width
, 0);
2435 /* pick some fallbacks... */
2436 y
= a
->y
+ a
->height
/ 4;
2442 if (dir
== 0 || dir
== 1) /* horz */
2443 self
->max_horz
= max
;
2444 if (dir
== 0 || dir
== 2) /* vert */
2445 self
->max_vert
= max
;
2447 client_change_state(self
); /* change the state hints on the client */
2449 client_setup_decor_and_functions(self
);
2451 client_move_resize(self
, x
, y
, w
, h
);
2454 void client_shade(ObClient
*self
, gboolean shade
)
2456 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2457 shade
) || /* can't shade */
2458 self
->shaded
== shade
) return; /* already done */
2460 /* when we're iconic, don't change the wmstate */
2461 if (!self
->iconic
) {
2464 old
= self
->wmstate
;
2465 self
->wmstate
= shade
? IconicState
: NormalState
;
2466 if (old
!= self
->wmstate
)
2467 PROP_MSG(self
->window
, kde_wm_change_state
,
2468 self
->wmstate
, 1, 0, 0);
2471 self
->shaded
= shade
;
2472 client_change_state(self
);
2473 /* resize the frame to just the titlebar */
2474 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2477 void client_close(ObClient
*self
)
2481 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2483 /* in the case that the client provides no means to requesting that it
2484 close, we just kill it */
2485 if (!self
->delete_window
)
2489 XXX: itd be cool to do timeouts and shit here for killing the client's
2491 like... if the window is around after 5 seconds, then the close button
2492 turns a nice red, and if this function is called again, the client is
2496 ce
.xclient
.type
= ClientMessage
;
2497 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2498 ce
.xclient
.display
= ob_display
;
2499 ce
.xclient
.window
= self
->window
;
2500 ce
.xclient
.format
= 32;
2501 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2502 ce
.xclient
.data
.l
[1] = event_lasttime
;
2503 ce
.xclient
.data
.l
[2] = 0l;
2504 ce
.xclient
.data
.l
[3] = 0l;
2505 ce
.xclient
.data
.l
[4] = 0l;
2506 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2509 void client_kill(ObClient
*self
)
2511 XKillClient(ob_display
, self
->window
);
2514 void client_set_desktop_recursive(ObClient
*self
,
2515 guint target
, gboolean donthide
)
2520 if (target
!= self
->desktop
) {
2522 ob_debug("Setting desktop %u\n", target
+1);
2524 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2526 /* remove from the old desktop(s) */
2527 focus_order_remove(self
);
2529 old
= self
->desktop
;
2530 self
->desktop
= target
;
2531 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2532 /* the frame can display the current desktop state */
2533 frame_adjust_state(self
->frame
);
2534 /* 'move' the window to the new desktop */
2536 client_showhide(self
);
2537 /* raise if it was not already on the desktop */
2538 if (old
!= DESKTOP_ALL
)
2540 screen_update_areas();
2542 /* add to the new desktop(s) */
2543 if (config_focus_new
)
2544 focus_order_to_top(self
);
2546 focus_order_to_bottom(self
);
2549 /* move all transients */
2550 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2551 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2555 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2557 client_set_desktop_recursive(client_search_top_transient(self
),
2561 ObClient
*client_search_modal_child(ObClient
*self
)
2566 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2567 ObClient
*c
= it
->data
;
2568 if ((ret
= client_search_modal_child(c
))) return ret
;
2569 if (c
->modal
) return c
;
2574 gboolean
client_validate(ObClient
*self
)
2578 XSync(ob_display
, FALSE
); /* get all events on the server */
2580 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2581 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2582 XPutBackEvent(ob_display
, &e
);
2589 void client_set_wm_state(ObClient
*self
, glong state
)
2591 if (state
== self
->wmstate
) return; /* no change */
2595 client_iconify(self
, TRUE
, TRUE
);
2598 client_iconify(self
, FALSE
, TRUE
);
2603 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2605 gboolean shaded
= self
->shaded
;
2606 gboolean fullscreen
= self
->fullscreen
;
2607 gboolean undecorated
= self
->undecorated
;
2608 gboolean max_horz
= self
->max_horz
;
2609 gboolean max_vert
= self
->max_vert
;
2610 gboolean modal
= self
->modal
;
2611 gboolean iconic
= self
->iconic
;
2614 if (!(action
== prop_atoms
.net_wm_state_add
||
2615 action
== prop_atoms
.net_wm_state_remove
||
2616 action
== prop_atoms
.net_wm_state_toggle
))
2617 /* an invalid action was passed to the client message, ignore it */
2620 for (i
= 0; i
< 2; ++i
) {
2621 Atom state
= i
== 0 ? data1
: data2
;
2623 if (!state
) continue;
2625 /* if toggling, then pick whether we're adding or removing */
2626 if (action
== prop_atoms
.net_wm_state_toggle
) {
2627 if (state
== prop_atoms
.net_wm_state_modal
)
2628 action
= modal
? prop_atoms
.net_wm_state_remove
:
2629 prop_atoms
.net_wm_state_add
;
2630 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2631 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2632 prop_atoms
.net_wm_state_add
;
2633 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2634 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2635 prop_atoms
.net_wm_state_add
;
2636 else if (state
== prop_atoms
.net_wm_state_shaded
)
2637 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2638 prop_atoms
.net_wm_state_add
;
2639 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2640 action
= self
->skip_taskbar
?
2641 prop_atoms
.net_wm_state_remove
:
2642 prop_atoms
.net_wm_state_add
;
2643 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2644 action
= self
->skip_pager
?
2645 prop_atoms
.net_wm_state_remove
:
2646 prop_atoms
.net_wm_state_add
;
2647 else if (state
== prop_atoms
.net_wm_state_hidden
)
2648 action
= self
->iconic
?
2649 prop_atoms
.net_wm_state_remove
:
2650 prop_atoms
.net_wm_state_add
;
2651 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2652 action
= fullscreen
?
2653 prop_atoms
.net_wm_state_remove
:
2654 prop_atoms
.net_wm_state_add
;
2655 else if (state
== prop_atoms
.net_wm_state_above
)
2656 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2657 prop_atoms
.net_wm_state_add
;
2658 else if (state
== prop_atoms
.net_wm_state_below
)
2659 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2660 prop_atoms
.net_wm_state_add
;
2661 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2662 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2663 prop_atoms
.net_wm_state_add
;
2666 if (action
== prop_atoms
.net_wm_state_add
) {
2667 if (state
== prop_atoms
.net_wm_state_modal
) {
2669 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2671 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2673 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2675 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2676 self
->skip_taskbar
= TRUE
;
2677 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2678 self
->skip_pager
= TRUE
;
2679 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2681 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2683 } else if (state
== prop_atoms
.net_wm_state_above
) {
2685 self
->below
= FALSE
;
2686 } else if (state
== prop_atoms
.net_wm_state_below
) {
2687 self
->above
= FALSE
;
2689 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2693 } else { /* action == prop_atoms.net_wm_state_remove */
2694 if (state
== prop_atoms
.net_wm_state_modal
) {
2696 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2698 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2700 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2702 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2703 self
->skip_taskbar
= FALSE
;
2704 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2705 self
->skip_pager
= FALSE
;
2706 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2708 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2710 } else if (state
== prop_atoms
.net_wm_state_above
) {
2711 self
->above
= FALSE
;
2712 } else if (state
== prop_atoms
.net_wm_state_below
) {
2713 self
->below
= FALSE
;
2714 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2715 undecorated
= FALSE
;
2719 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2720 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2722 if (max_horz
== max_vert
) { /* both going the same way */
2723 client_maximize(self
, max_horz
, 0, TRUE
);
2725 client_maximize(self
, max_horz
, 1, TRUE
);
2726 client_maximize(self
, max_vert
, 2, TRUE
);
2730 if (max_horz
!= self
->max_horz
)
2731 client_maximize(self
, max_horz
, 1, TRUE
);
2733 client_maximize(self
, max_vert
, 2, TRUE
);
2736 /* change fullscreen state before shading, as it will affect if the window
2738 if (fullscreen
!= self
->fullscreen
)
2739 client_fullscreen(self
, fullscreen
, TRUE
);
2740 if (shaded
!= self
->shaded
)
2741 client_shade(self
, shaded
);
2742 if (undecorated
!= self
->undecorated
)
2743 client_set_undecorated(self
, undecorated
);
2744 if (modal
!= self
->modal
) {
2745 self
->modal
= modal
;
2746 /* when a window changes modality, then its stacking order with its
2747 transients needs to change */
2750 if (iconic
!= self
->iconic
)
2751 client_iconify(self
, iconic
, FALSE
);
2753 client_calc_layer(self
);
2754 client_change_state(self
); /* change the hint to reflect these changes */
2757 ObClient
*client_focus_target(ObClient
*self
)
2761 /* if we have a modal child, then focus it, not us */
2762 child
= client_search_modal_child(client_search_top_transient(self
));
2763 if (child
) return child
;
2767 gboolean
client_can_focus(ObClient
*self
)
2771 /* choose the correct target */
2772 self
= client_focus_target(self
);
2774 if (!self
->frame
->visible
)
2777 if (!(self
->can_focus
|| self
->focus_notify
))
2780 /* do a check to see if the window has already been unmapped or destroyed
2781 do this intelligently while watching out for unmaps we've generated
2782 (ignore_unmaps > 0) */
2783 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2784 DestroyNotify
, &ev
)) {
2785 XPutBackEvent(ob_display
, &ev
);
2788 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2789 UnmapNotify
, &ev
)) {
2790 if (self
->ignore_unmaps
) {
2791 self
->ignore_unmaps
--;
2793 XPutBackEvent(ob_display
, &ev
);
2801 gboolean
client_focus(ObClient
*self
)
2803 /* choose the correct target */
2804 self
= client_focus_target(self
);
2806 if (!client_can_focus(self
)) {
2807 if (!self
->frame
->visible
) {
2808 /* update the focus lists */
2809 focus_order_to_top(self
);
2814 if (self
->can_focus
) {
2815 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2816 I choose to use it always, hopefully to find errors quicker, if any
2817 are left. (I hate X. I hate focus events.)
2819 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2820 #799. So now it is RevertToNone again.
2822 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2826 if (self
->focus_notify
) {
2828 ce
.xclient
.type
= ClientMessage
;
2829 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2830 ce
.xclient
.display
= ob_display
;
2831 ce
.xclient
.window
= self
->window
;
2832 ce
.xclient
.format
= 32;
2833 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2834 ce
.xclient
.data
.l
[1] = event_lasttime
;
2835 ce
.xclient
.data
.l
[2] = 0l;
2836 ce
.xclient
.data
.l
[3] = 0l;
2837 ce
.xclient
.data
.l
[4] = 0l;
2838 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2842 ob_debug("%sively focusing %lx at %d\n",
2843 (self
->can_focus
? "act" : "pass"),
2844 self
->window
, (gint
) event_lasttime
);
2847 /* Cause the FocusIn to come back to us. Important for desktop switches,
2848 since otherwise we'll have no FocusIn on the queue and send it off to
2849 the focus_backup. */
2850 XSync(ob_display
, FALSE
);
2854 void client_unfocus(ObClient
*self
)
2856 if (focus_client
== self
) {
2858 ob_debug("client_unfocus for %lx\n", self
->window
);
2860 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2864 void client_activate(ObClient
*self
, gboolean here
)
2866 /* This check is for the client_list_menu trying to activate
2867 * a closed client. */
2868 if (!g_list_find(client_list
, self
)) return;
2869 if (client_normal(self
) && screen_showing_desktop
)
2870 screen_show_desktop(FALSE
);
2872 client_iconify(self
, FALSE
, here
);
2873 if (self
->desktop
!= DESKTOP_ALL
&&
2874 self
->desktop
!= screen_desktop
) {
2876 client_set_desktop(self
, screen_desktop
, FALSE
);
2878 screen_set_desktop(self
->desktop
);
2879 } else if (!self
->frame
->visible
)
2880 /* if its not visible for other reasons, then don't mess
2884 client_shade(self
, FALSE
);
2888 /* we do this an action here. this is rather important. this is because
2889 we want the results from the focus change to take place BEFORE we go
2890 about raising the window. when a fullscreen window loses focus, we need
2891 this or else the raise wont be able to raise above the to-lose-focus
2892 fullscreen window. */
2896 void client_raise(ObClient
*self
)
2898 action_run_string("Raise", self
);
2901 void client_lower(ObClient
*self
)
2903 action_run_string("Lower", self
);
2906 gboolean
client_focused(ObClient
*self
)
2908 return self
== focus_client
;
2911 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
2914 /* si is the smallest image >= req */
2915 /* li is the largest image < req */
2916 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2918 if (!self
->nicons
) {
2919 ObClientIcon
*parent
= NULL
;
2921 if (self
->transient_for
) {
2922 if (self
->transient_for
!= OB_TRAN_GROUP
)
2923 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2926 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2927 ObClient
*c
= it
->data
;
2928 if (c
!= self
&& !c
->transient_for
) {
2929 if ((parent
= client_icon_recursive(c
, w
, h
)))
2939 for (i
= 0; i
< self
->nicons
; ++i
) {
2940 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2941 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2945 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2950 if (largest
== 0) /* didnt find one smaller than the requested size */
2951 return &self
->icons
[si
];
2952 return &self
->icons
[li
];
2955 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
2958 static ObClientIcon deficon
;
2960 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2961 deficon
.width
= deficon
.height
= 48;
2962 deficon
.data
= ob_rr_theme
->def_win_icon
;
2968 /* this be mostly ripped from fvwm */
2969 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2971 gint my_cx
, my_cy
, his_cx
, his_cy
;
2974 gint score
, best_score
;
2975 ObClient
*best_client
, *cur
;
2981 /* first, find the centre coords of the currently focused window */
2982 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2983 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2988 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
2991 /* the currently selected window isn't interesting */
2994 if (!client_normal(cur
))
2996 /* using c->desktop instead of screen_desktop doesn't work if the
2997 * current window was omnipresent, hope this doesn't have any other
2999 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3003 if(client_focus_target(cur
) == cur
&&
3004 !(cur
->can_focus
|| cur
->focus_notify
))
3007 /* find the centre coords of this window, from the
3008 * currently focused window's point of view */
3009 his_cx
= (cur
->frame
->area
.x
- my_cx
)
3010 + cur
->frame
->area
.width
/ 2;
3011 his_cy
= (cur
->frame
->area
.y
- my_cy
)
3012 + cur
->frame
->area
.height
/ 2;
3014 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
3015 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
3017 /* Rotate the diagonals 45 degrees counterclockwise.
3018 * To do this, multiply the matrix /+h +h\ with the
3019 * vector (x y). \-h +h/
3020 * h = sqrt(0.5). We can set h := 1 since absolute
3021 * distance doesn't matter here. */
3022 tx
= his_cx
+ his_cy
;
3023 his_cy
= -his_cx
+ his_cy
;
3028 case OB_DIRECTION_NORTH
:
3029 case OB_DIRECTION_SOUTH
:
3030 case OB_DIRECTION_NORTHEAST
:
3031 case OB_DIRECTION_SOUTHWEST
:
3032 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
3033 distance
= ((dir
== OB_DIRECTION_NORTH
||
3034 dir
== OB_DIRECTION_NORTHEAST
) ?
3037 case OB_DIRECTION_EAST
:
3038 case OB_DIRECTION_WEST
:
3039 case OB_DIRECTION_SOUTHEAST
:
3040 case OB_DIRECTION_NORTHWEST
:
3041 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
3042 distance
= ((dir
== OB_DIRECTION_WEST
||
3043 dir
== OB_DIRECTION_NORTHWEST
) ?
3048 /* the target must be in the requested direction */
3052 /* Calculate score for this window. The smaller the better. */
3053 score
= distance
+ offset
;
3055 /* windows more than 45 degrees off the direction are
3056 * heavily penalized and will only be chosen if nothing
3057 * else within a million pixels */
3058 if(offset
> distance
)
3061 if(best_score
== -1 || score
< best_score
)
3069 void client_set_layer(ObClient
*self
, gint layer
)
3073 self
->above
= FALSE
;
3074 } else if (layer
== 0) {
3075 self
->below
= self
->above
= FALSE
;
3077 self
->below
= FALSE
;
3080 client_calc_layer(self
);
3081 client_change_state(self
); /* reflect this in the state hints */
3084 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3086 if (self
->undecorated
!= undecorated
) {
3087 self
->undecorated
= undecorated
;
3088 client_setup_decor_and_functions(self
);
3089 /* Make sure the client knows it might have moved. Maybe there is a
3090 * better way of doing this so only one client_configure is sent, but
3091 * since 125 of these are sent per second when moving the window (with
3092 * user = FALSE) i doubt it matters much.
3094 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3095 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3096 client_change_state(self
); /* reflect this in the state hints */
3100 /* Determines which physical monitor a client is on by calculating the
3101 area of the part of the client on each monitor. The number of the
3102 monitor containing the greatest area of the client is returned.*/
3103 guint
client_monitor(ObClient
*self
)
3109 for (i
= 0; i
< screen_num_monitors
; ++i
) {
3110 Rect
*area
= screen_physical_area_monitor(i
);
3111 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
)) {
3115 RECT_SET_INTERSECTION(r
, *area
, self
->frame
->area
);
3116 v
= r
.width
* r
.height
;
3127 ObClient
*client_search_top_transient(ObClient
*self
)
3129 /* move up the transient chain as far as possible */
3130 if (self
->transient_for
) {
3131 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3132 return client_search_top_transient(self
->transient_for
);
3136 g_assert(self
->group
);
3138 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3139 ObClient
*c
= it
->data
;
3141 /* checking transient_for prevents infinate loops! */
3142 if (c
!= self
&& !c
->transient_for
)
3153 ObClient
*client_search_focus_parent(ObClient
*self
)
3155 if (self
->transient_for
) {
3156 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3157 if (client_focused(self
->transient_for
))
3158 return self
->transient_for
;
3162 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3163 ObClient
*c
= it
->data
;
3165 /* checking transient_for prevents infinate loops! */
3166 if (c
!= self
&& !c
->transient_for
)
3167 if (client_focused(c
))
3176 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3178 if (self
->transient_for
) {
3179 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3180 if (self
->transient_for
== search
)
3185 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3186 ObClient
*c
= it
->data
;
3188 /* checking transient_for prevents infinate loops! */
3189 if (c
!= self
&& !c
->transient_for
)
3199 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3203 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3204 if (sit
->data
== search
)
3206 if (client_search_transient(sit
->data
, search
))
3212 void client_update_sm_client_id(ObClient
*self
)
3214 g_free(self
->sm_client_id
);
3215 self
->sm_client_id
= NULL
;
3217 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3219 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3220 &self
->sm_client_id
);
3223 /* finds the nearest edge in the given direction from the current client
3224 * note to self: the edge is the -frame- edge (the actual one), not the
3227 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3229 gint dest
, monitor_dest
;
3230 gint my_edge_start
, my_edge_end
, my_offset
;
3237 a
= screen_area(c
->desktop
);
3238 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3241 case OB_DIRECTION_NORTH
:
3242 my_edge_start
= c
->frame
->area
.x
;
3243 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3244 my_offset
= c
->frame
->area
.y
;
3246 /* default: top of screen */
3248 monitor_dest
= monitor
->y
;
3249 /* if the monitor edge comes before the screen edge, */
3250 /* use that as the destination instead. (For xinerama) */
3251 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3252 dest
= monitor_dest
;
3254 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3255 gint his_edge_start
, his_edge_end
, his_offset
;
3256 ObClient
*cur
= it
->data
;
3260 if(!client_normal(cur
))
3262 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3266 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3269 his_edge_start
= cur
->frame
->area
.x
;
3270 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3271 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3273 if(his_offset
+ 1 > my_offset
)
3276 if(his_offset
< dest
)
3279 if(his_edge_start
>= my_edge_start
&&
3280 his_edge_start
<= my_edge_end
)
3283 if(my_edge_start
>= his_edge_start
&&
3284 my_edge_start
<= his_edge_end
)
3289 case OB_DIRECTION_SOUTH
:
3290 my_edge_start
= c
->frame
->area
.x
;
3291 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3292 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3294 /* default: bottom of screen */
3295 dest
= a
->y
+ a
->height
;
3296 monitor_dest
= monitor
->y
+ monitor
->height
;
3297 /* if the monitor edge comes before the screen edge, */
3298 /* use that as the destination instead. (For xinerama) */
3299 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3300 dest
= monitor_dest
;
3302 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3303 gint his_edge_start
, his_edge_end
, his_offset
;
3304 ObClient
*cur
= it
->data
;
3308 if(!client_normal(cur
))
3310 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3314 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3317 his_edge_start
= cur
->frame
->area
.x
;
3318 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3319 his_offset
= cur
->frame
->area
.y
;
3322 if(his_offset
- 1 < my_offset
)
3325 if(his_offset
> dest
)
3328 if(his_edge_start
>= my_edge_start
&&
3329 his_edge_start
<= my_edge_end
)
3332 if(my_edge_start
>= his_edge_start
&&
3333 my_edge_start
<= his_edge_end
)
3338 case OB_DIRECTION_WEST
:
3339 my_edge_start
= c
->frame
->area
.y
;
3340 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3341 my_offset
= c
->frame
->area
.x
;
3343 /* default: leftmost egde of screen */
3345 monitor_dest
= monitor
->x
;
3346 /* if the monitor edge comes before the screen edge, */
3347 /* use that as the destination instead. (For xinerama) */
3348 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3349 dest
= monitor_dest
;
3351 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3352 gint his_edge_start
, his_edge_end
, his_offset
;
3353 ObClient
*cur
= it
->data
;
3357 if(!client_normal(cur
))
3359 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3363 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3366 his_edge_start
= cur
->frame
->area
.y
;
3367 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3368 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3370 if(his_offset
+ 1 > my_offset
)
3373 if(his_offset
< dest
)
3376 if(his_edge_start
>= my_edge_start
&&
3377 his_edge_start
<= my_edge_end
)
3380 if(my_edge_start
>= his_edge_start
&&
3381 my_edge_start
<= his_edge_end
)
3387 case OB_DIRECTION_EAST
:
3388 my_edge_start
= c
->frame
->area
.y
;
3389 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3390 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3392 /* default: rightmost edge of screen */
3393 dest
= a
->x
+ a
->width
;
3394 monitor_dest
= monitor
->x
+ monitor
->width
;
3395 /* if the monitor edge comes before the screen edge, */
3396 /* use that as the destination instead. (For xinerama) */
3397 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3398 dest
= monitor_dest
;
3400 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3401 gint his_edge_start
, his_edge_end
, his_offset
;
3402 ObClient
*cur
= it
->data
;
3406 if(!client_normal(cur
))
3408 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3412 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3415 his_edge_start
= cur
->frame
->area
.y
;
3416 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3417 his_offset
= cur
->frame
->area
.x
;
3419 if(his_offset
- 1 < my_offset
)
3422 if(his_offset
> dest
)
3425 if(his_edge_start
>= my_edge_start
&&
3426 his_edge_start
<= my_edge_end
)
3429 if(my_edge_start
>= his_edge_start
&&
3430 my_edge_start
<= his_edge_end
)
3435 case OB_DIRECTION_NORTHEAST
:
3436 case OB_DIRECTION_SOUTHEAST
:
3437 case OB_DIRECTION_NORTHWEST
:
3438 case OB_DIRECTION_SOUTHWEST
:
3439 /* not implemented */
3441 g_assert_not_reached();
3442 dest
= 0; /* suppress warning */
3447 ObClient
* client_under_pointer()
3451 ObClient
*ret
= NULL
;
3453 if (screen_pointer_pos(&x
, &y
)) {
3454 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3455 if (WINDOW_IS_CLIENT(it
->data
)) {
3456 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3457 if (c
->frame
->visible
&&
3458 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3468 gboolean
client_has_group_siblings(ObClient
*self
)
3470 return self
->group
&& self
->group
->members
->next
;