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 void client_manage(Window window
)
211 XWindowAttributes attrib
;
212 XSetWindowAttributes attrib_set
;
214 gboolean activate
= FALSE
;
218 /* check if it has already been unmapped by the time we started mapping
219 the grab does a sync so we don't have to here */
220 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
221 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
222 XPutBackEvent(ob_display
, &e
);
225 return; /* don't manage it */
228 /* make sure it isn't an override-redirect window */
229 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
230 attrib
.override_redirect
) {
232 return; /* don't manage it */
235 /* is the window a docking app */
236 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
237 if ((wmhint
->flags
& StateHint
) &&
238 wmhint
->initial_state
== WithdrawnState
) {
239 dock_add(window
, wmhint
);
247 ob_debug("Managing window: %lx\n", window
);
249 /* choose the events we want to receive on the CLIENT window */
250 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
251 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
252 XChangeWindowAttributes(ob_display
, window
,
253 CWEventMask
|CWDontPropagate
, &attrib_set
);
256 /* create the ObClient struct, and populate it from the hints on the
258 self
= g_new0(ObClient
, 1);
259 self
->obwin
.type
= Window_Client
;
260 self
->window
= window
;
262 /* non-zero defaults */
263 self
->title_count
= 1;
264 self
->wmstate
= NormalState
;
266 self
->desktop
= screen_num_desktops
; /* always an invalid value */
268 client_get_all(self
);
269 client_restore_session_state(self
);
271 sn_app_started(self
->class);
273 /* update the focus lists, do this before the call to change_state or
274 it can end up in the list twice! */
275 focus_order_add_new(self
);
277 client_change_state(self
);
279 /* remove the client's border (and adjust re gravity) */
280 client_toggle_border(self
, FALSE
);
282 /* specify that if we exit, the window should not be destroyed and should
283 be reparented back to root automatically */
284 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
286 /* create the decoration frame for the client window */
287 self
->frame
= frame_new();
289 frame_grab_client(self
->frame
, self
);
293 client_apply_startup_state(self
);
295 stacking_add(CLIENT_AS_WINDOW(self
));
296 client_restore_session_stacking(self
);
298 /* focus the new window? */
299 if (ob_state() != OB_STATE_STARTING
&&
300 (config_focus_new
|| client_search_focus_parent(self
)) &&
301 /* note the check against Type_Normal/Dialog, not client_normal(self),
302 which would also include other types. in this case we want more
303 strict rules for focus */
304 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
305 self
->type
== OB_CLIENT_TYPE_DIALOG
))
309 if (self
->desktop
!= screen_desktop
) {
310 /* activate the window */
313 gboolean group_foc
= FALSE
;
318 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
320 if (client_focused(it
->data
))
328 (!self
->transient_for
&& (!self
->group
||
329 !self
->group
->members
->next
))) ||
330 client_search_focus_tree_full(self
) ||
332 !client_normal(focus_client
))
334 /* activate the window */
341 if (ob_state() == OB_STATE_RUNNING
) {
342 gint x
= self
->area
.x
, ox
= x
;
343 gint y
= self
->area
.y
, oy
= y
;
345 place_client(self
, &x
, &y
);
347 /* make sure the window is visible. */
348 client_find_onscreen(self
, &x
, &y
,
349 self
->frame
->area
.width
,
350 self
->frame
->area
.height
,
351 /* non-normal clients has less rules, and
352 windows that are being restored from a
353 session do also. we can assume you want
354 it back where you saved it. Clients saying
355 they placed themselves are subjected to
356 harder rules, ones that are placed by
357 place.c or by the user are allowed partially
358 off-screen and on xinerama divides (ie,
359 it is up to the placement routines to avoid
360 the xinerama divides) */
361 ((self
->positioned
& PPosition
) &&
362 !(self
->positioned
& USPosition
)) &&
363 client_normal(self
) &&
365 if (x
!= ox
|| y
!= oy
)
366 client_move(self
, x
, y
);
369 keyboard_grab_for_client(self
, TRUE
);
370 mouse_grab_for_client(self
, TRUE
);
372 client_showhide(self
);
374 /* use client_focus instead of client_activate cuz client_activate does
375 stuff like switch desktops etc and I'm not interested in all that when
376 a window maps since its not based on an action from the user like
377 clicking a window to activate is. so keep the new window out of the way
380 /* if using focus_delay, stop the timer now so that focus doesn't go
382 event_halt_focus_delay();
385 /* since focus can change the stacking orders, if we focus the window
386 then the standard raise it gets is not enough, we need to queue one
387 for after the focus change takes place */
391 /* client_activate does this but we aret using it so we have to do it
393 if (screen_showing_desktop
)
394 screen_show_desktop(FALSE
);
396 /* add to client list/map */
397 client_list
= g_list_append(client_list
, self
);
398 g_hash_table_insert(window_map
, &self
->window
, self
);
400 /* this has to happen after we're in the client_list */
401 screen_update_areas();
403 /* update the list hints */
406 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
409 void client_unmanage_all()
411 while (client_list
!= NULL
)
412 client_unmanage(client_list
->data
);
415 void client_unmanage(ObClient
*self
)
420 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
422 g_assert(self
!= NULL
);
424 keyboard_grab_for_client(self
, FALSE
);
425 mouse_grab_for_client(self
, FALSE
);
427 /* potentially fix focusLast */
428 if (config_focus_last
)
429 grab_pointer(TRUE
, OB_CURSOR_NONE
);
431 /* remove the window from our save set */
432 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
434 /* we dont want events no more */
435 XSelectInput(ob_display
, self
->window
, NoEventMask
);
437 frame_hide(self
->frame
);
439 client_list
= g_list_remove(client_list
, self
);
440 stacking_remove(self
);
441 g_hash_table_remove(window_map
, &self
->window
);
443 /* update the focus lists */
444 focus_order_remove(self
);
446 /* once the client is out of the list, update the struts to remove it's
448 screen_update_areas();
450 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
451 Destructor
*d
= it
->data
;
452 d
->func(self
, d
->data
);
455 if (focus_client
== self
) {
458 /* focus the last focused window on the desktop, and ignore enter
459 events from the unmap so it doesnt mess with the focus */
460 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
461 /* remove these flags so we don't end up getting focused in the
463 self
->can_focus
= FALSE
;
464 self
->focus_notify
= FALSE
;
466 client_unfocus(self
);
469 /* tell our parent(s) that we're gone */
470 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
471 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
472 if (it
->data
!= self
)
473 ((ObClient
*)it
->data
)->transients
=
474 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
475 } else if (self
->transient_for
) { /* transient of window */
476 self
->transient_for
->transients
=
477 g_slist_remove(self
->transient_for
->transients
, self
);
480 /* tell our transients that we're gone */
481 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
482 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
483 ((ObClient
*)it
->data
)->transient_for
= NULL
;
484 client_calc_layer(it
->data
);
488 /* remove from its group */
490 group_remove(self
->group
, self
);
494 /* give the client its border back */
495 client_toggle_border(self
, TRUE
);
497 /* reparent the window out of the frame, and free the frame */
498 frame_release_client(self
->frame
, self
);
501 if (ob_state() != OB_STATE_EXITING
) {
502 /* these values should not be persisted across a window
504 PROP_ERASE(self
->window
, net_wm_desktop
);
505 PROP_ERASE(self
->window
, net_wm_state
);
506 PROP_ERASE(self
->window
, wm_state
);
508 /* if we're left in an unmapped state, the client wont be mapped. this
509 is bad, since we will no longer be managing the window on restart */
510 XMapWindow(ob_display
, self
->window
);
514 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
516 /* free all data allocated in the client struct */
517 g_slist_free(self
->transients
);
518 for (j
= 0; j
< self
->nicons
; ++j
)
519 g_free(self
->icons
[j
].data
);
520 if (self
->nicons
> 0)
523 g_free(self
->icon_title
);
527 g_free(self
->sm_client_id
);
530 /* update the list hints */
533 if (config_focus_last
)
534 grab_pointer(FALSE
, OB_CURSOR_NONE
);
537 static void client_urgent_notify(ObClient
*self
)
540 frame_flash_start(self
->frame
);
542 frame_flash_stop(self
->frame
);
545 static void client_restore_session_state(ObClient
*self
)
549 if (!(it
= session_state_find(self
)))
552 self
->session
= it
->data
;
554 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
555 self
->positioned
= PPosition
;
556 if (self
->session
->w
> 0)
557 self
->area
.width
= self
->session
->w
;
558 if (self
->session
->h
> 0)
559 self
->area
.height
= self
->session
->h
;
560 XResizeWindow(ob_display
, self
->window
,
561 self
->area
.width
, self
->area
.height
);
563 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
564 self
->session
->desktop
:
565 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
566 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
568 self
->shaded
= self
->session
->shaded
;
569 self
->iconic
= self
->session
->iconic
;
570 self
->skip_pager
= self
->session
->skip_pager
;
571 self
->skip_taskbar
= self
->session
->skip_taskbar
;
572 self
->fullscreen
= self
->session
->fullscreen
;
573 self
->above
= self
->session
->above
;
574 self
->below
= self
->session
->below
;
575 self
->max_horz
= self
->session
->max_horz
;
576 self
->max_vert
= self
->session
->max_vert
;
579 static void client_restore_session_stacking(ObClient
*self
)
583 if (!self
->session
) return;
585 it
= g_list_find(session_saved_state
, self
->session
);
586 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
589 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
590 if (session_state_cmp(it
->data
, cit
->data
))
593 client_calc_layer(self
);
594 stacking_below(CLIENT_AS_WINDOW(self
),
595 CLIENT_AS_WINDOW(cit
->data
));
601 void client_move_onscreen(ObClient
*self
, gboolean rude
)
603 gint x
= self
->area
.x
;
604 gint y
= self
->area
.y
;
605 if (client_find_onscreen(self
, &x
, &y
,
606 self
->frame
->area
.width
,
607 self
->frame
->area
.height
, rude
)) {
608 client_move(self
, x
, y
);
612 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
616 gint ox
= *x
, oy
= *y
;
618 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
621 /* XXX watch for xinerama dead areas */
622 /* This makes sure windows aren't entirely outside of the screen so you
623 * can't see them at all */
624 if (client_normal(self
)) {
625 a
= screen_area(self
->desktop
);
626 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
627 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
628 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
629 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
630 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
632 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
636 /* This here doesn't let windows even a pixel outside the screen,
637 * when called from client_manage, programs placing themselves are
638 * forced completely onscreen, while things like
639 * xterm -geometry resolution-width/2 will work fine. Trying to
640 * place it completely offscreen will be handled in the above code.
641 * Sorry for this confused comment, i am tired. */
643 /* avoid the xinerama monitor divide while we're at it,
644 * remember to fix the placement stuff to avoid it also and
645 * then remove this XXX */
646 a
= screen_physical_area_monitor(client_monitor(self
));
647 /* dont let windows map/move into the strut unless they
648 are bigger than the available area */
650 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
651 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
652 *x
= a
->x
+ a
->width
- w
;
654 if (h
<= a
->height
) {
655 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
656 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
657 *y
= a
->y
+ a
->height
- h
;
661 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
664 return ox
!= *x
|| oy
!= *y
;
667 static void client_toggle_border(ObClient
*self
, gboolean show
)
669 /* adjust our idea of where the client is, based on its border. When the
670 border is removed, the client should now be considered to be in a
672 when re-adding the border to the client, the same operation needs to be
674 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
675 gint x
= oldx
, y
= oldy
;
676 switch(self
->gravity
) {
678 case NorthWestGravity
:
680 case SouthWestGravity
:
682 case NorthEastGravity
:
684 case SouthEastGravity
:
685 if (show
) x
-= self
->border_width
* 2;
686 else x
+= self
->border_width
* 2;
693 if (show
) x
-= self
->border_width
;
694 else x
+= self
->border_width
;
697 switch(self
->gravity
) {
699 case NorthWestGravity
:
701 case NorthEastGravity
:
703 case SouthWestGravity
:
705 case SouthEastGravity
:
706 if (show
) y
-= self
->border_width
* 2;
707 else y
+= self
->border_width
* 2;
714 if (show
) y
-= self
->border_width
;
715 else y
+= self
->border_width
;
722 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
724 /* move the client so it is back it the right spot _with_ its
726 if (x
!= oldx
|| y
!= oldy
)
727 XMoveWindow(ob_display
, self
->window
, x
, y
);
729 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
733 static void client_get_all(ObClient
*self
)
735 client_get_area(self
);
736 client_update_transient_for(self
);
737 client_update_wmhints(self
);
738 client_get_startup_id(self
);
739 client_get_desktop(self
);
740 client_get_shaped(self
);
742 client_get_mwm_hints(self
);
743 client_get_type(self
);/* this can change the mwmhints for special cases */
745 /* The transient hint is used to pick a type, but the type can also affect
746 transiency (dialogs are always made transients). This is Havoc's idea,
747 but it is needed to make some apps work right (eg tsclient). */
748 client_update_transient_for(self
);
750 client_get_state(self
);
753 /* a couple type-based defaults for new windows */
755 /* this makes sure that these windows appear on all desktops */
756 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
757 self
->desktop
= DESKTOP_ALL
;
760 client_update_protocols(self
);
762 client_get_gravity(self
); /* get the attribute gravity */
763 client_update_normal_hints(self
); /* this may override the attribute
766 /* got the type, the mwmhints, the protocols, and the normal hints
767 (min/max sizes), so we're ready to set up the decorations/functions */
768 client_setup_decor_and_functions(self
);
770 client_update_title(self
);
771 client_update_class(self
);
772 client_update_sm_client_id(self
);
773 client_update_strut(self
);
774 client_update_icons(self
);
777 static void client_get_startup_id(ObClient
*self
)
779 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
781 PROP_GETS(self
->group
->leader
,
782 net_startup_id
, utf8
, &self
->startup_id
);
785 static void client_get_area(ObClient
*self
)
787 XWindowAttributes wattrib
;
790 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
791 g_assert(ret
!= BadWindow
);
793 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
794 self
->border_width
= wattrib
.border_width
;
797 static void client_get_desktop(ObClient
*self
)
799 guint32 d
= screen_num_desktops
; /* an always-invalid value */
801 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
802 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
803 self
->desktop
= screen_num_desktops
- 1;
807 gboolean trdesk
= FALSE
;
809 if (self
->transient_for
) {
810 if (self
->transient_for
!= OB_TRAN_GROUP
) {
811 self
->desktop
= self
->transient_for
->desktop
;
816 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
817 if (it
->data
!= self
&&
818 !((ObClient
*)it
->data
)->transient_for
) {
819 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
826 /* try get from the startup-notification protocol */
827 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
828 if (self
->desktop
>= screen_num_desktops
&&
829 self
->desktop
!= DESKTOP_ALL
)
830 self
->desktop
= screen_num_desktops
- 1;
832 /* defaults to the current desktop */
833 self
->desktop
= screen_desktop
;
836 if (self
->desktop
!= d
) {
837 /* set the desktop hint, to make sure that it always exists */
838 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
842 static void client_get_state(ObClient
*self
)
847 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
849 for (i
= 0; i
< num
; ++i
) {
850 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
852 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
854 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
856 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
857 self
->skip_taskbar
= TRUE
;
858 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
859 self
->skip_pager
= TRUE
;
860 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
861 self
->fullscreen
= TRUE
;
862 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
863 self
->max_vert
= TRUE
;
864 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
865 self
->max_horz
= TRUE
;
866 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
868 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
870 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
871 self
->undecorated
= TRUE
;
877 if (!(self
->above
|| self
->below
)) {
879 /* apply stuff from the group */
883 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
884 ObClient
*c
= it
->data
;
885 if (c
!= self
&& !client_search_transient(self
, c
) &&
886 client_normal(self
) && client_normal(c
))
889 (c
->above
? 1 : (c
->below
? -1 : 0)));
903 g_assert_not_reached();
910 static void client_get_shaped(ObClient
*self
)
912 self
->shaped
= FALSE
;
914 if (extensions_shape
) {
919 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
921 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
922 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
924 self
->shaped
= (s
!= 0);
929 void client_update_transient_for(ObClient
*self
)
932 ObClient
*target
= NULL
;
934 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
935 self
->transient
= TRUE
;
936 if (t
!= self
->window
) { /* cant be transient to itself! */
937 target
= g_hash_table_lookup(window_map
, &t
);
938 /* if this happens then we need to check for it*/
939 g_assert(target
!= self
);
940 if (target
&& !WINDOW_IS_CLIENT(target
)) {
941 /* this can happen when a dialog is a child of
942 a dockapp, for example */
946 if (!target
&& self
->group
) {
947 /* not transient to a client, see if it is transient for a
949 if (t
== self
->group
->leader
||
951 t
== RootWindow(ob_display
, ob_screen
))
953 /* window is a transient for its group! */
954 target
= OB_TRAN_GROUP
;
958 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
&& self
->group
) {
959 self
->transient
= TRUE
;
960 target
= OB_TRAN_GROUP
;
962 self
->transient
= FALSE
;
964 /* if anything has changed... */
965 if (target
!= self
->transient_for
) {
966 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
969 /* remove from old parents */
970 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
971 ObClient
*c
= it
->data
;
972 if (c
!= self
&& !c
->transient_for
)
973 c
->transients
= g_slist_remove(c
->transients
, self
);
975 } else if (self
->transient_for
!= NULL
) { /* transient of window */
976 /* remove from old parent */
977 self
->transient_for
->transients
=
978 g_slist_remove(self
->transient_for
->transients
, self
);
980 self
->transient_for
= target
;
981 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
984 /* add to new parents */
985 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
986 ObClient
*c
= it
->data
;
987 if (c
!= self
&& !c
->transient_for
)
988 c
->transients
= g_slist_append(c
->transients
, self
);
991 /* remove all transients which are in the group, that causes
992 circlular pointer hell of doom */
993 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
995 for (sit
= self
->transients
; sit
; sit
= next
) {
996 next
= g_slist_next(sit
);
997 if (sit
->data
== it
->data
)
999 g_slist_delete_link(self
->transients
, sit
);
1002 } else if (self
->transient_for
!= NULL
) { /* transient of window */
1003 /* add to new parent */
1004 self
->transient_for
->transients
=
1005 g_slist_append(self
->transient_for
->transients
, self
);
1010 static void client_get_mwm_hints(ObClient
*self
)
1015 self
->mwmhints
.flags
= 0; /* default to none */
1017 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1019 if (num
>= OB_MWM_ELEMENTS
) {
1020 self
->mwmhints
.flags
= hints
[0];
1021 self
->mwmhints
.functions
= hints
[1];
1022 self
->mwmhints
.decorations
= hints
[2];
1028 void client_get_type(ObClient
*self
)
1035 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1036 /* use the first value that we know about in the array */
1037 for (i
= 0; i
< num
; ++i
) {
1038 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1039 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1040 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1041 self
->type
= OB_CLIENT_TYPE_DOCK
;
1042 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1043 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1044 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1045 self
->type
= OB_CLIENT_TYPE_MENU
;
1046 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1047 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1048 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1049 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1050 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1051 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1052 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1053 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1054 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1055 /* prevent this window from getting any decor or
1057 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1058 OB_MWM_FLAG_DECORATIONS
);
1059 self
->mwmhints
.decorations
= 0;
1060 self
->mwmhints
.functions
= 0;
1062 if (self
->type
!= (ObClientType
) -1)
1063 break; /* grab the first legit type */
1068 if (self
->type
== (ObClientType
) -1) {
1069 /*the window type hint was not set, which means we either classify
1070 ourself as a normal window or a dialog, depending on if we are a
1072 if (self
->transient
)
1073 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1075 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1079 void client_update_protocols(ObClient
*self
)
1082 guint num_return
, i
;
1084 self
->focus_notify
= FALSE
;
1085 self
->delete_window
= FALSE
;
1087 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1088 for (i
= 0; i
< num_return
; ++i
) {
1089 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1090 /* this means we can request the window to close */
1091 self
->delete_window
= TRUE
;
1092 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1093 /* if this protocol is requested, then the window will be
1094 notified whenever we want it to receive focus */
1095 self
->focus_notify
= TRUE
;
1101 static void client_get_gravity(ObClient
*self
)
1103 XWindowAttributes wattrib
;
1106 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1107 g_assert(ret
!= BadWindow
);
1108 self
->gravity
= wattrib
.win_gravity
;
1111 void client_update_normal_hints(ObClient
*self
)
1115 gint oldgravity
= self
->gravity
;
1118 self
->min_ratio
= 0.0f
;
1119 self
->max_ratio
= 0.0f
;
1120 SIZE_SET(self
->size_inc
, 1, 1);
1121 SIZE_SET(self
->base_size
, 0, 0);
1122 SIZE_SET(self
->min_size
, 0, 0);
1123 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1125 /* get the hints from the window */
1126 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1127 /* normal windows can't request placement! har har
1128 if (!client_normal(self))
1130 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1132 if (size
.flags
& PWinGravity
) {
1133 self
->gravity
= size
.win_gravity
;
1135 /* if the client has a frame, i.e. has already been mapped and
1136 is changing its gravity */
1137 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1138 /* move our idea of the client's position based on its new
1140 self
->area
.x
= self
->frame
->area
.x
;
1141 self
->area
.y
= self
->frame
->area
.y
;
1142 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1146 if (size
.flags
& PAspect
) {
1147 if (size
.min_aspect
.y
)
1149 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1150 if (size
.max_aspect
.y
)
1152 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1155 if (size
.flags
& PMinSize
)
1156 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1158 if (size
.flags
& PMaxSize
)
1159 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1161 if (size
.flags
& PBaseSize
)
1162 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1164 if (size
.flags
& PResizeInc
)
1165 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1169 void client_setup_decor_and_functions(ObClient
*self
)
1171 /* start with everything (cept fullscreen) */
1173 (OB_FRAME_DECOR_TITLEBAR
|
1174 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1175 OB_FRAME_DECOR_GRIPS
|
1176 OB_FRAME_DECOR_BORDER
|
1177 OB_FRAME_DECOR_ICON
|
1178 OB_FRAME_DECOR_ALLDESKTOPS
|
1179 OB_FRAME_DECOR_ICONIFY
|
1180 OB_FRAME_DECOR_MAXIMIZE
|
1181 OB_FRAME_DECOR_SHADE
|
1182 OB_FRAME_DECOR_CLOSE
);
1184 (OB_CLIENT_FUNC_RESIZE
|
1185 OB_CLIENT_FUNC_MOVE
|
1186 OB_CLIENT_FUNC_ICONIFY
|
1187 OB_CLIENT_FUNC_MAXIMIZE
|
1188 OB_CLIENT_FUNC_SHADE
|
1189 OB_CLIENT_FUNC_CLOSE
);
1191 if (!(self
->min_size
.width
< self
->max_size
.width
||
1192 self
->min_size
.height
< self
->max_size
.height
))
1193 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1195 switch (self
->type
) {
1196 case OB_CLIENT_TYPE_NORMAL
:
1197 /* normal windows retain all of the possible decorations and
1198 functionality, and are the only windows that you can fullscreen */
1199 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1202 case OB_CLIENT_TYPE_DIALOG
:
1203 case OB_CLIENT_TYPE_UTILITY
:
1204 /* these windows cannot be maximized */
1205 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1208 case OB_CLIENT_TYPE_MENU
:
1209 case OB_CLIENT_TYPE_TOOLBAR
:
1210 /* these windows get less functionality */
1211 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1214 case OB_CLIENT_TYPE_DESKTOP
:
1215 case OB_CLIENT_TYPE_DOCK
:
1216 case OB_CLIENT_TYPE_SPLASH
:
1217 /* none of these windows are manipulated by the window manager */
1218 self
->decorations
= 0;
1219 self
->functions
= 0;
1223 /* Mwm Hints are applied subtractively to what has already been chosen for
1224 decor and functionality */
1225 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1226 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1227 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1228 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1229 /* if the mwm hints request no handle or title, then all
1230 decorations are disabled */
1231 self
->decorations
= config_theme_keepborder
? OB_FRAME_DECOR_BORDER
: 0;
1235 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1236 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1237 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1238 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1239 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1240 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1241 /* dont let mwm hints kill any buttons
1242 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1243 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1244 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1245 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1247 /* dont let mwm hints kill the close button
1248 if (! (self->mwmhints.functions & MwmFunc_Close))
1249 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1253 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1254 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1255 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1256 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1257 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1258 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1260 /* can't maximize without moving/resizing */
1261 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1262 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1263 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1264 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1265 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1268 /* kill the handle on fully maxed windows */
1269 if (self
->max_vert
&& self
->max_horz
)
1270 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1272 /* finally, the user can have requested no decorations, which overrides
1273 everything (but doesnt give it a border if it doesnt have one) */
1274 if (self
->undecorated
) {
1275 if (config_theme_keepborder
)
1276 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1278 self
->decorations
= 0;
1281 /* if we don't have a titlebar, then we cannot shade! */
1282 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1283 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1285 /* now we need to check against rules for the client's current state */
1286 if (self
->fullscreen
) {
1287 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1288 OB_CLIENT_FUNC_FULLSCREEN
|
1289 OB_CLIENT_FUNC_ICONIFY
);
1290 self
->decorations
= 0;
1293 client_change_allowed_actions(self
);
1296 /* adjust the client's decorations, etc. */
1297 client_reconfigure(self
);
1301 static void client_change_allowed_actions(ObClient
*self
)
1306 /* desktop windows are kept on all desktops */
1307 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1308 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1310 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1311 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1312 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1313 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1314 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1315 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1316 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1317 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1318 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1319 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1320 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1321 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1322 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1323 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1324 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1327 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1329 /* make sure the window isn't breaking any rules now */
1331 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1332 if (self
->frame
) client_shade(self
, FALSE
);
1333 else self
->shaded
= FALSE
;
1335 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1336 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1337 else self
->iconic
= FALSE
;
1339 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1340 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1341 else self
->fullscreen
= FALSE
;
1343 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1345 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1346 else self
->max_vert
= self
->max_horz
= FALSE
;
1350 void client_reconfigure(ObClient
*self
)
1352 /* by making this pass FALSE for user, we avoid the emacs event storm where
1353 every configurenotify causes an update in its normal hints, i think this
1354 is generally what we want anyways... */
1355 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1356 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1359 void client_update_wmhints(ObClient
*self
)
1362 gboolean ur
= FALSE
;
1365 /* assume a window takes input if it doesnt specify */
1366 self
->can_focus
= TRUE
;
1368 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1369 if (hints
->flags
& InputHint
)
1370 self
->can_focus
= hints
->input
;
1372 /* only do this when first managing the window *AND* when we aren't
1374 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1375 if (hints
->flags
& StateHint
)
1376 self
->iconic
= hints
->initial_state
== IconicState
;
1378 if (hints
->flags
& XUrgencyHint
)
1381 if (!(hints
->flags
& WindowGroupHint
))
1382 hints
->window_group
= None
;
1384 /* did the group state change? */
1385 if (hints
->window_group
!=
1386 (self
->group
? self
->group
->leader
: None
)) {
1387 /* remove from the old group if there was one */
1388 if (self
->group
!= NULL
) {
1389 /* remove transients of the group */
1390 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1391 self
->transients
= g_slist_remove(self
->transients
,
1394 /* remove myself from parents in the group */
1395 if (self
->transient_for
== OB_TRAN_GROUP
) {
1396 for (it
= self
->group
->members
; it
;
1397 it
= g_slist_next(it
))
1399 ObClient
*c
= it
->data
;
1401 if (c
!= self
&& !c
->transient_for
)
1402 c
->transients
= g_slist_remove(c
->transients
,
1407 group_remove(self
->group
, self
);
1410 if (hints
->window_group
!= None
) {
1411 self
->group
= group_add(hints
->window_group
, self
);
1413 /* i can only have transients from the group if i am not
1415 if (!self
->transient_for
) {
1416 /* add other transients of the group that are already
1418 for (it
= self
->group
->members
; it
;
1419 it
= g_slist_next(it
))
1421 ObClient
*c
= it
->data
;
1422 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1424 g_slist_append(self
->transients
, c
);
1429 /* because the self->transient flag wont change from this call,
1430 we don't need to update the window's type and such, only its
1431 transient_for, and the transients lists of other windows in
1432 the group may be affected */
1433 client_update_transient_for(self
);
1436 /* the WM_HINTS can contain an icon */
1437 client_update_icons(self
);
1442 if (ur
!= self
->urgent
) {
1444 /* fire the urgent callback if we're mapped, otherwise, wait until
1445 after we're mapped */
1447 client_urgent_notify(self
);
1451 void client_update_title(ObClient
*self
)
1457 gboolean read_title
;
1460 old_title
= self
->title
;
1463 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1464 /* try old x stuff */
1465 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
)) {
1466 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1467 if (self
->transient
) {
1468 data
= g_strdup("");
1471 data
= g_strdup("Unnamed Window");
1475 /* did the title change? then reset the title_count */
1476 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1477 self
->title_count
= 1;
1479 /* look for duplicates and append a number */
1481 for (it
= client_list
; it
; it
= g_list_next(it
))
1482 if (it
->data
!= self
) {
1483 ObClient
*c
= it
->data
;
1484 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1485 nums
|= 1 << c
->title_count
;
1487 /* find first free number */
1488 for (i
= 1; i
<= 32; ++i
)
1489 if (!(nums
& (1 << i
))) {
1490 if (self
->title_count
== 1 || i
== 1)
1491 self
->title_count
= i
;
1494 /* dont display the number for the first window */
1495 if (self
->title_count
> 1) {
1497 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1502 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1507 frame_adjust_title(self
->frame
);
1511 /* update the icon title */
1513 g_free(self
->icon_title
);
1517 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1518 /* try old x stuff */
1519 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1520 data
= g_strdup(self
->title
);
1524 /* append the title count, dont display the number for the first window */
1525 if (read_title
&& self
->title_count
> 1) {
1526 gchar
*vdata
, *ndata
;
1527 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1528 vdata
= g_strconcat(data
, ndata
, NULL
);
1534 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1536 self
->icon_title
= data
;
1539 void client_update_class(ObClient
*self
)
1544 if (self
->name
) g_free(self
->name
);
1545 if (self
->class) g_free(self
->class);
1546 if (self
->role
) g_free(self
->role
);
1548 self
->name
= self
->class = self
->role
= NULL
;
1550 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1552 self
->name
= g_strdup(data
[0]);
1554 self
->class = g_strdup(data
[1]);
1559 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1562 if (self
->name
== NULL
) self
->name
= g_strdup("");
1563 if (self
->class == NULL
) self
->class = g_strdup("");
1564 if (self
->role
== NULL
) self
->role
= g_strdup("");
1567 void client_update_strut(ObClient
*self
)
1571 gboolean got
= FALSE
;
1574 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1578 STRUT_PARTIAL_SET(strut
,
1579 data
[0], data
[2], data
[1], data
[3],
1580 data
[4], data
[5], data
[8], data
[9],
1581 data
[6], data
[7], data
[10], data
[11]);
1587 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1593 /* use the screen's width/height */
1594 a
= screen_physical_area();
1596 STRUT_PARTIAL_SET(strut
,
1597 data
[0], data
[2], data
[1], data
[3],
1598 a
->y
, a
->y
+ a
->height
- 1,
1599 a
->x
, a
->x
+ a
->width
- 1,
1600 a
->y
, a
->y
+ a
->height
- 1,
1601 a
->x
, a
->x
+ a
->width
- 1);
1607 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1608 0, 0, 0, 0, 0, 0, 0, 0);
1610 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1611 self
->strut
= strut
;
1613 /* updating here is pointless while we're being mapped cuz we're not in
1614 the client list yet */
1616 screen_update_areas();
1620 void client_update_icons(ObClient
*self
)
1626 for (i
= 0; i
< self
->nicons
; ++i
)
1627 g_free(self
->icons
[i
].data
);
1628 if (self
->nicons
> 0)
1629 g_free(self
->icons
);
1632 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1633 /* figure out how many valid icons are in here */
1635 while (num
- i
> 2) {
1639 if (i
> num
|| w
*h
== 0) break;
1643 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1645 /* store the icons */
1647 for (j
= 0; j
< self
->nicons
; ++j
) {
1650 w
= self
->icons
[j
].width
= data
[i
++];
1651 h
= self
->icons
[j
].height
= data
[i
++];
1653 if (w
*h
== 0) continue;
1655 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1656 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1661 self
->icons
[j
].data
[t
] =
1662 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1663 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1664 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1665 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1671 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1672 kwm_win_icon
, &data
, &num
)) {
1675 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1676 xerror_set_ignore(TRUE
);
1677 if (!RrPixmapToRGBA(ob_rr_inst
,
1679 &self
->icons
[self
->nicons
-1].width
,
1680 &self
->icons
[self
->nicons
-1].height
,
1681 &self
->icons
[self
->nicons
-1].data
)) {
1682 g_free(&self
->icons
[self
->nicons
-1]);
1685 xerror_set_ignore(FALSE
);
1691 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1692 if (hints
->flags
& IconPixmapHint
) {
1694 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1695 xerror_set_ignore(TRUE
);
1696 if (!RrPixmapToRGBA(ob_rr_inst
,
1698 (hints
->flags
& IconMaskHint
?
1699 hints
->icon_mask
: None
),
1700 &self
->icons
[self
->nicons
-1].width
,
1701 &self
->icons
[self
->nicons
-1].height
,
1702 &self
->icons
[self
->nicons
-1].data
)){
1703 g_free(&self
->icons
[self
->nicons
-1]);
1706 xerror_set_ignore(FALSE
);
1713 frame_adjust_icon(self
->frame
);
1716 static void client_change_state(ObClient
*self
)
1719 gulong netstate
[11];
1722 state
[0] = self
->wmstate
;
1724 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1728 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1730 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1732 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1733 if (self
->skip_taskbar
)
1734 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1735 if (self
->skip_pager
)
1736 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1737 if (self
->fullscreen
)
1738 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1740 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1742 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1744 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1746 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1747 if (self
->undecorated
)
1748 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1749 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1751 client_calc_layer(self
);
1754 frame_adjust_state(self
->frame
);
1757 ObClient
*client_search_focus_tree(ObClient
*self
)
1762 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1763 if (client_focused(it
->data
)) return it
->data
;
1764 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1769 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1771 if (self
->transient_for
) {
1772 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1773 return client_search_focus_tree_full(self
->transient_for
);
1776 gboolean recursed
= FALSE
;
1778 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1779 if (!((ObClient
*)it
->data
)->transient_for
) {
1781 if ((c
= client_search_focus_tree_full(it
->data
)))
1790 /* this function checks the whole tree, the client_search_focus_tree~
1791 does not, so we need to check this window */
1792 if (client_focused(self
))
1794 return client_search_focus_tree(self
);
1797 static ObStackingLayer
calc_layer(ObClient
*self
)
1801 if (self
->fullscreen
&&
1802 (client_focused(self
) || client_search_focus_tree(self
)))
1803 l
= OB_STACKING_LAYER_FULLSCREEN
;
1804 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1805 l
= OB_STACKING_LAYER_DESKTOP
;
1806 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1807 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
1808 else l
= OB_STACKING_LAYER_ABOVE
;
1810 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1811 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1812 else l
= OB_STACKING_LAYER_NORMAL
;
1817 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1818 ObStackingLayer l
, gboolean raised
)
1820 ObStackingLayer old
, own
;
1824 own
= calc_layer(self
);
1825 self
->layer
= l
> own
? l
: own
;
1827 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
1828 client_calc_layer_recursive(it
->data
, orig
,
1829 l
, raised
? raised
: l
!= old
);
1831 if (!raised
&& l
!= old
)
1832 if (orig
->frame
) { /* only restack if the original window is managed */
1833 stacking_remove(CLIENT_AS_WINDOW(self
));
1834 stacking_add(CLIENT_AS_WINDOW(self
));
1838 void client_calc_layer(ObClient
*self
)
1845 /* transients take on the layer of their parents */
1846 self
= client_search_top_transient(self
);
1848 l
= calc_layer(self
);
1850 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1853 gboolean
client_should_show(ObClient
*self
)
1857 if (client_normal(self
) && screen_showing_desktop
)
1860 if (self->transient_for) {
1861 if (self->transient_for != OB_TRAN_GROUP)
1862 return client_should_show(self->transient_for);
1866 for (it = self->group->members; it; it = g_slist_next(it)) {
1867 ObClient *c = it->data;
1868 if (c != self && !c->transient_for) {
1869 if (client_should_show(c))
1876 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
1882 static void client_showhide(ObClient
*self
)
1885 if (client_should_show(self
))
1886 frame_show(self
->frame
);
1888 frame_hide(self
->frame
);
1891 gboolean
client_normal(ObClient
*self
) {
1892 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1893 self
->type
== OB_CLIENT_TYPE_DOCK
||
1894 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1897 static void client_apply_startup_state(ObClient
*self
)
1899 /* these are in a carefully crafted order.. */
1902 self
->iconic
= FALSE
;
1903 client_iconify(self
, TRUE
, FALSE
);
1905 if (self
->fullscreen
) {
1906 self
->fullscreen
= FALSE
;
1907 client_fullscreen(self
, TRUE
, FALSE
);
1909 if (self
->undecorated
) {
1910 self
->undecorated
= FALSE
;
1911 client_set_undecorated(self
, TRUE
);
1914 self
->shaded
= FALSE
;
1915 client_shade(self
, TRUE
);
1918 client_urgent_notify(self
);
1920 if (self
->max_vert
&& self
->max_horz
) {
1921 self
->max_vert
= self
->max_horz
= FALSE
;
1922 client_maximize(self
, TRUE
, 0, FALSE
);
1923 } else if (self
->max_vert
) {
1924 self
->max_vert
= FALSE
;
1925 client_maximize(self
, TRUE
, 2, FALSE
);
1926 } else if (self
->max_horz
) {
1927 self
->max_horz
= FALSE
;
1928 client_maximize(self
, TRUE
, 1, FALSE
);
1931 /* nothing to do for the other states:
1940 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1941 gint x
, gint y
, gint w
, gint h
,
1942 gboolean user
, gboolean final
,
1943 gboolean force_reply
)
1946 gboolean send_resize_client
;
1947 gboolean moved
= FALSE
, resized
= FALSE
;
1948 guint fdecor
= self
->frame
->decorations
;
1949 gboolean fhorz
= self
->frame
->max_horz
;
1951 /* make the frame recalculate its dimentions n shit without changing
1952 anything visible for real, this way the constraints below can work with
1953 the updated frame dimensions. */
1954 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1956 /* gets the frame's position */
1957 frame_client_gravity(self
->frame
, &x
, &y
);
1959 /* these positions are frame positions, not client positions */
1961 /* set the size and position if fullscreen */
1962 if (self
->fullscreen
) {
1965 XF86VidModeModeLine mode
;
1970 i
= client_monitor(self
);
1971 a
= screen_physical_area_monitor(i
);
1974 if (i
== 0 && /* primary head */
1975 extensions_vidmode
&&
1976 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1977 /* get the mode last so the mode.privsize isnt freed incorrectly */
1978 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1983 if (mode
.privsize
) XFree(mode
.private);
1993 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1997 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1999 /* set the size and position if maximized */
2000 if (self
->max_horz
) {
2002 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2004 if (self
->max_vert
) {
2006 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2010 /* gets the client's position */
2011 frame_frame_gravity(self
->frame
, &x
, &y
);
2013 /* these override the above states! if you cant move you can't move! */
2015 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2019 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2020 w
= self
->area
.width
;
2021 h
= self
->area
.height
;
2025 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
2026 gint basew
, baseh
, minw
, minh
;
2028 /* base size is substituted with min size if not specified */
2029 if (self
->base_size
.width
|| self
->base_size
.height
) {
2030 basew
= self
->base_size
.width
;
2031 baseh
= self
->base_size
.height
;
2033 basew
= self
->min_size
.width
;
2034 baseh
= self
->min_size
.height
;
2036 /* min size is substituted with base size if not specified */
2037 if (self
->min_size
.width
|| self
->min_size
.height
) {
2038 minw
= self
->min_size
.width
;
2039 minh
= self
->min_size
.height
;
2041 minw
= self
->base_size
.width
;
2042 minh
= self
->base_size
.height
;
2045 /* if this is a user-requested resize, then check against min/max
2048 /* smaller than min size or bigger than max size? */
2049 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
2050 if (w
< minw
) w
= minw
;
2051 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
2052 if (h
< minh
) h
= minh
;
2057 /* keep to the increments */
2058 w
/= self
->size_inc
.width
;
2059 h
/= self
->size_inc
.height
;
2061 /* you cannot resize to nothing */
2062 if (basew
+ w
< 1) w
= 1 - basew
;
2063 if (baseh
+ h
< 1) h
= 1 - baseh
;
2065 /* store the logical size */
2066 SIZE_SET(self
->logical_size
,
2067 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
2068 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
2070 w
*= self
->size_inc
.width
;
2071 h
*= self
->size_inc
.height
;
2076 /* adjust the height to match the width for the aspect ratios.
2077 for this, min size is not substituted for base size ever. */
2078 w
-= self
->base_size
.width
;
2079 h
-= self
->base_size
.height
;
2081 if (!self
->fullscreen
) {
2082 if (self
->min_ratio
)
2083 if (h
* self
->min_ratio
> w
) {
2084 h
= (gint
)(w
/ self
->min_ratio
);
2086 /* you cannot resize to nothing */
2089 w
= (gint
)(h
* self
->min_ratio
);
2092 if (self
->max_ratio
)
2093 if (h
* self
->max_ratio
< w
) {
2094 h
= (gint
)(w
/ self
->max_ratio
);
2096 /* you cannot resize to nothing */
2099 w
= (gint
)(h
* self
->min_ratio
);
2104 w
+= self
->base_size
.width
;
2105 h
+= self
->base_size
.height
;
2112 case OB_CORNER_TOPLEFT
:
2114 case OB_CORNER_TOPRIGHT
:
2115 x
-= w
- self
->area
.width
;
2117 case OB_CORNER_BOTTOMLEFT
:
2118 y
-= h
- self
->area
.height
;
2120 case OB_CORNER_BOTTOMRIGHT
:
2121 x
-= w
- self
->area
.width
;
2122 y
-= h
- self
->area
.height
;
2126 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2127 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2129 oldw
= self
->area
.width
;
2130 oldh
= self
->area
.height
;
2131 RECT_SET(self
->area
, x
, y
, w
, h
);
2133 /* for app-requested resizes, always resize if 'resized' is true.
2134 for user-requested ones, only resize if final is true, or when
2135 resizing in redraw mode */
2136 send_resize_client
= ((!user
&& resized
) ||
2138 (resized
&& config_resize_redraw
))));
2140 /* if the client is enlarging, then resize the client before the frame */
2141 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2142 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2144 /* move/resize the frame to match the request */
2146 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2147 moved
= resized
= TRUE
;
2149 if (moved
|| resized
)
2150 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2152 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2155 event
.type
= ConfigureNotify
;
2156 event
.xconfigure
.display
= ob_display
;
2157 event
.xconfigure
.event
= self
->window
;
2158 event
.xconfigure
.window
= self
->window
;
2160 /* root window real coords */
2161 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2163 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2165 event
.xconfigure
.width
= w
;
2166 event
.xconfigure
.height
= h
;
2167 event
.xconfigure
.border_width
= 0;
2168 event
.xconfigure
.above
= self
->frame
->plate
;
2169 event
.xconfigure
.override_redirect
= FALSE
;
2170 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2171 FALSE
, StructureNotifyMask
, &event
);
2175 /* if the client is shrinking, then resize the frame before the client */
2176 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2177 XResizeWindow(ob_display
, self
->window
, w
, h
);
2182 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2186 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2187 self
->fullscreen
== fs
) return; /* already done */
2189 self
->fullscreen
= fs
;
2190 client_change_state(self
); /* change the state hints on the client,
2191 and adjust out layer/stacking */
2195 self
->pre_fullscreen_area
= self
->area
;
2197 /* these are not actually used cuz client_configure will set them
2198 as appropriate when the window is fullscreened */
2203 if (self
->pre_fullscreen_area
.width
> 0 &&
2204 self
->pre_fullscreen_area
.height
> 0)
2206 x
= self
->pre_fullscreen_area
.x
;
2207 y
= self
->pre_fullscreen_area
.y
;
2208 w
= self
->pre_fullscreen_area
.width
;
2209 h
= self
->pre_fullscreen_area
.height
;
2210 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2212 /* pick some fallbacks... */
2213 a
= screen_area_monitor(self
->desktop
, 0);
2214 x
= a
->x
+ a
->width
/ 4;
2215 y
= a
->y
+ a
->height
/ 4;
2221 client_setup_decor_and_functions(self
);
2223 client_move_resize(self
, x
, y
, w
, h
);
2225 /* try focus us when we go into fullscreen mode */
2229 static void client_iconify_recursive(ObClient
*self
,
2230 gboolean iconic
, gboolean curdesk
)
2233 gboolean changed
= FALSE
;
2236 if (self
->iconic
!= iconic
) {
2237 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2240 self
->iconic
= iconic
;
2243 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2246 old
= self
->wmstate
;
2247 self
->wmstate
= IconicState
;
2248 if (old
!= self
->wmstate
)
2249 PROP_MSG(self
->window
, kde_wm_change_state
,
2250 self
->wmstate
, 1, 0, 0);
2252 /* update the focus lists.. iconic windows go to the bottom of
2253 the list, put the new iconic window at the 'top of the
2255 focus_order_to_top(self
);
2263 client_set_desktop(self
, screen_desktop
, FALSE
);
2265 old
= self
->wmstate
;
2266 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2267 if (old
!= self
->wmstate
)
2268 PROP_MSG(self
->window
, kde_wm_change_state
,
2269 self
->wmstate
, 1, 0, 0);
2271 /* this puts it after the current focused window */
2272 focus_order_remove(self
);
2273 focus_order_add_new(self
);
2275 /* this is here cuz with the VIDMODE extension, the viewport can
2276 change while a fullscreen window is iconic, and when it
2277 uniconifies, it would be nice if it did so to the new position
2279 client_reconfigure(self
);
2286 client_change_state(self
);
2287 client_showhide(self
);
2288 screen_update_areas();
2291 /* iconify all transients */
2292 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2293 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2297 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2299 /* move up the transient chain as far as possible first */
2300 self
= client_search_top_transient(self
);
2302 client_iconify_recursive(client_search_top_transient(self
),
2306 void client_maximize(ObClient
*self
, gboolean max
, gint dir
, gboolean savearea
)
2310 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2311 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2313 /* check if already done */
2315 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2316 if (dir
== 1 && self
->max_horz
) return;
2317 if (dir
== 2 && self
->max_vert
) return;
2319 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2320 if (dir
== 1 && !self
->max_horz
) return;
2321 if (dir
== 2 && !self
->max_vert
) return;
2324 /* we just tell it to configure in the same place and client_configure
2325 worries about filling the screen with the window */
2328 w
= self
->area
.width
;
2329 h
= self
->area
.height
;
2333 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2334 RECT_SET(self
->pre_max_area
,
2335 self
->area
.x
, self
->pre_max_area
.y
,
2336 self
->area
.width
, self
->pre_max_area
.height
);
2338 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2339 RECT_SET(self
->pre_max_area
,
2340 self
->pre_max_area
.x
, self
->area
.y
,
2341 self
->pre_max_area
.width
, self
->area
.height
);
2347 a
= screen_area_monitor(self
->desktop
, 0);
2348 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2349 if (self
->pre_max_area
.width
> 0) {
2350 x
= self
->pre_max_area
.x
;
2351 w
= self
->pre_max_area
.width
;
2353 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2354 0, self
->pre_max_area
.height
);
2356 /* pick some fallbacks... */
2357 x
= a
->x
+ a
->width
/ 4;
2361 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2362 if (self
->pre_max_area
.height
> 0) {
2363 y
= self
->pre_max_area
.y
;
2364 h
= self
->pre_max_area
.height
;
2366 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2367 self
->pre_max_area
.width
, 0);
2369 /* pick some fallbacks... */
2370 y
= a
->y
+ a
->height
/ 4;
2376 if (dir
== 0 || dir
== 1) /* horz */
2377 self
->max_horz
= max
;
2378 if (dir
== 0 || dir
== 2) /* vert */
2379 self
->max_vert
= max
;
2381 client_change_state(self
); /* change the state hints on the client */
2383 client_setup_decor_and_functions(self
);
2385 client_move_resize(self
, x
, y
, w
, h
);
2388 void client_shade(ObClient
*self
, gboolean shade
)
2390 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2391 shade
) || /* can't shade */
2392 self
->shaded
== shade
) return; /* already done */
2394 /* when we're iconic, don't change the wmstate */
2395 if (!self
->iconic
) {
2398 old
= self
->wmstate
;
2399 self
->wmstate
= shade
? IconicState
: NormalState
;
2400 if (old
!= self
->wmstate
)
2401 PROP_MSG(self
->window
, kde_wm_change_state
,
2402 self
->wmstate
, 1, 0, 0);
2405 self
->shaded
= shade
;
2406 client_change_state(self
);
2407 /* resize the frame to just the titlebar */
2408 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2411 void client_close(ObClient
*self
)
2415 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2417 /* in the case that the client provides no means to requesting that it
2418 close, we just kill it */
2419 if (!self
->delete_window
)
2423 XXX: itd be cool to do timeouts and shit here for killing the client's
2425 like... if the window is around after 5 seconds, then the close button
2426 turns a nice red, and if this function is called again, the client is
2430 ce
.xclient
.type
= ClientMessage
;
2431 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2432 ce
.xclient
.display
= ob_display
;
2433 ce
.xclient
.window
= self
->window
;
2434 ce
.xclient
.format
= 32;
2435 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2436 ce
.xclient
.data
.l
[1] = event_lasttime
;
2437 ce
.xclient
.data
.l
[2] = 0l;
2438 ce
.xclient
.data
.l
[3] = 0l;
2439 ce
.xclient
.data
.l
[4] = 0l;
2440 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2443 void client_kill(ObClient
*self
)
2445 XKillClient(ob_display
, self
->window
);
2448 void client_set_desktop_recursive(ObClient
*self
,
2449 guint target
, gboolean donthide
)
2454 if (target
!= self
->desktop
) {
2456 ob_debug("Setting desktop %u\n", target
+1);
2458 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2460 /* remove from the old desktop(s) */
2461 focus_order_remove(self
);
2463 old
= self
->desktop
;
2464 self
->desktop
= target
;
2465 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2466 /* the frame can display the current desktop state */
2467 frame_adjust_state(self
->frame
);
2468 /* 'move' the window to the new desktop */
2470 client_showhide(self
);
2471 /* raise if it was not already on the desktop */
2472 if (old
!= DESKTOP_ALL
)
2474 screen_update_areas();
2476 /* add to the new desktop(s) */
2477 if (config_focus_new
)
2478 focus_order_to_top(self
);
2480 focus_order_to_bottom(self
);
2483 /* move all transients */
2484 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2485 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2489 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2491 client_set_desktop_recursive(client_search_top_transient(self
),
2495 ObClient
*client_search_modal_child(ObClient
*self
)
2500 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2501 ObClient
*c
= it
->data
;
2502 if ((ret
= client_search_modal_child(c
))) return ret
;
2503 if (c
->modal
) return c
;
2508 gboolean
client_validate(ObClient
*self
)
2512 XSync(ob_display
, FALSE
); /* get all events on the server */
2514 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2515 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2516 XPutBackEvent(ob_display
, &e
);
2523 void client_set_wm_state(ObClient
*self
, glong state
)
2525 if (state
== self
->wmstate
) return; /* no change */
2529 client_iconify(self
, TRUE
, TRUE
);
2532 client_iconify(self
, FALSE
, TRUE
);
2537 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2539 gboolean shaded
= self
->shaded
;
2540 gboolean fullscreen
= self
->fullscreen
;
2541 gboolean undecorated
= self
->undecorated
;
2542 gboolean max_horz
= self
->max_horz
;
2543 gboolean max_vert
= self
->max_vert
;
2544 gboolean modal
= self
->modal
;
2545 gboolean iconic
= self
->iconic
;
2548 if (!(action
== prop_atoms
.net_wm_state_add
||
2549 action
== prop_atoms
.net_wm_state_remove
||
2550 action
== prop_atoms
.net_wm_state_toggle
))
2551 /* an invalid action was passed to the client message, ignore it */
2554 for (i
= 0; i
< 2; ++i
) {
2555 Atom state
= i
== 0 ? data1
: data2
;
2557 if (!state
) continue;
2559 /* if toggling, then pick whether we're adding or removing */
2560 if (action
== prop_atoms
.net_wm_state_toggle
) {
2561 if (state
== prop_atoms
.net_wm_state_modal
)
2562 action
= modal
? prop_atoms
.net_wm_state_remove
:
2563 prop_atoms
.net_wm_state_add
;
2564 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2565 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2566 prop_atoms
.net_wm_state_add
;
2567 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2568 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2569 prop_atoms
.net_wm_state_add
;
2570 else if (state
== prop_atoms
.net_wm_state_shaded
)
2571 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2572 prop_atoms
.net_wm_state_add
;
2573 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2574 action
= self
->skip_taskbar
?
2575 prop_atoms
.net_wm_state_remove
:
2576 prop_atoms
.net_wm_state_add
;
2577 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2578 action
= self
->skip_pager
?
2579 prop_atoms
.net_wm_state_remove
:
2580 prop_atoms
.net_wm_state_add
;
2581 else if (state
== prop_atoms
.net_wm_state_hidden
)
2582 action
= self
->iconic
?
2583 prop_atoms
.net_wm_state_remove
:
2584 prop_atoms
.net_wm_state_add
;
2585 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2586 action
= fullscreen
?
2587 prop_atoms
.net_wm_state_remove
:
2588 prop_atoms
.net_wm_state_add
;
2589 else if (state
== prop_atoms
.net_wm_state_above
)
2590 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2591 prop_atoms
.net_wm_state_add
;
2592 else if (state
== prop_atoms
.net_wm_state_below
)
2593 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2594 prop_atoms
.net_wm_state_add
;
2595 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2596 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2597 prop_atoms
.net_wm_state_add
;
2600 if (action
== prop_atoms
.net_wm_state_add
) {
2601 if (state
== prop_atoms
.net_wm_state_modal
) {
2603 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2605 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2607 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2609 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2610 self
->skip_taskbar
= TRUE
;
2611 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2612 self
->skip_pager
= TRUE
;
2613 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2615 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2617 } else if (state
== prop_atoms
.net_wm_state_above
) {
2619 self
->below
= FALSE
;
2620 } else if (state
== prop_atoms
.net_wm_state_below
) {
2621 self
->above
= FALSE
;
2623 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2627 } else { /* action == prop_atoms.net_wm_state_remove */
2628 if (state
== prop_atoms
.net_wm_state_modal
) {
2630 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2632 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2634 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2636 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2637 self
->skip_taskbar
= FALSE
;
2638 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2639 self
->skip_pager
= FALSE
;
2640 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2642 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2644 } else if (state
== prop_atoms
.net_wm_state_above
) {
2645 self
->above
= FALSE
;
2646 } else if (state
== prop_atoms
.net_wm_state_below
) {
2647 self
->below
= FALSE
;
2648 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2649 undecorated
= FALSE
;
2653 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2654 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2656 if (max_horz
== max_vert
) { /* both going the same way */
2657 client_maximize(self
, max_horz
, 0, TRUE
);
2659 client_maximize(self
, max_horz
, 1, TRUE
);
2660 client_maximize(self
, max_vert
, 2, TRUE
);
2664 if (max_horz
!= self
->max_horz
)
2665 client_maximize(self
, max_horz
, 1, TRUE
);
2667 client_maximize(self
, max_vert
, 2, TRUE
);
2670 /* change fullscreen state before shading, as it will affect if the window
2672 if (fullscreen
!= self
->fullscreen
)
2673 client_fullscreen(self
, fullscreen
, TRUE
);
2674 if (shaded
!= self
->shaded
)
2675 client_shade(self
, shaded
);
2676 if (undecorated
!= self
->undecorated
)
2677 client_set_undecorated(self
, undecorated
);
2678 if (modal
!= self
->modal
) {
2679 self
->modal
= modal
;
2680 /* when a window changes modality, then its stacking order with its
2681 transients needs to change */
2684 if (iconic
!= self
->iconic
)
2685 client_iconify(self
, iconic
, FALSE
);
2687 client_calc_layer(self
);
2688 client_change_state(self
); /* change the hint to reflect these changes */
2691 ObClient
*client_focus_target(ObClient
*self
)
2695 /* if we have a modal child, then focus it, not us */
2696 child
= client_search_modal_child(client_search_top_transient(self
));
2697 if (child
) return child
;
2701 gboolean
client_can_focus(ObClient
*self
)
2705 /* choose the correct target */
2706 self
= client_focus_target(self
);
2708 if (!self
->frame
->visible
)
2711 if (!(self
->can_focus
|| self
->focus_notify
))
2714 /* do a check to see if the window has already been unmapped or destroyed
2715 do this intelligently while watching out for unmaps we've generated
2716 (ignore_unmaps > 0) */
2717 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2718 DestroyNotify
, &ev
)) {
2719 XPutBackEvent(ob_display
, &ev
);
2722 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2723 UnmapNotify
, &ev
)) {
2724 if (self
->ignore_unmaps
) {
2725 self
->ignore_unmaps
--;
2727 XPutBackEvent(ob_display
, &ev
);
2735 gboolean
client_focus(ObClient
*self
)
2737 /* choose the correct target */
2738 self
= client_focus_target(self
);
2740 if (!client_can_focus(self
)) {
2741 if (!self
->frame
->visible
) {
2742 /* update the focus lists */
2743 focus_order_to_top(self
);
2748 if (self
->can_focus
) {
2749 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2750 I choose to use it always, hopefully to find errors quicker, if any
2751 are left. (I hate X. I hate focus events.)
2753 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2754 #799. So now it is RevertToNone again.
2756 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2760 if (self
->focus_notify
) {
2762 ce
.xclient
.type
= ClientMessage
;
2763 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2764 ce
.xclient
.display
= ob_display
;
2765 ce
.xclient
.window
= self
->window
;
2766 ce
.xclient
.format
= 32;
2767 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2768 ce
.xclient
.data
.l
[1] = event_lasttime
;
2769 ce
.xclient
.data
.l
[2] = 0l;
2770 ce
.xclient
.data
.l
[3] = 0l;
2771 ce
.xclient
.data
.l
[4] = 0l;
2772 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2776 ob_debug("%sively focusing %lx at %d\n",
2777 (self
->can_focus
? "act" : "pass"),
2778 self
->window
, (gint
) event_lasttime
);
2781 /* Cause the FocusIn to come back to us. Important for desktop switches,
2782 since otherwise we'll have no FocusIn on the queue and send it off to
2783 the focus_backup. */
2784 XSync(ob_display
, FALSE
);
2788 void client_unfocus(ObClient
*self
)
2790 if (focus_client
== self
) {
2792 ob_debug("client_unfocus for %lx\n", self
->window
);
2794 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2798 void client_activate(ObClient
*self
, gboolean here
)
2800 /* This check is for the client_list_menu trying to activate
2801 * a closed client. */
2802 if (!g_list_find(client_list
, self
)) return;
2803 if (client_normal(self
) && screen_showing_desktop
)
2804 screen_show_desktop(FALSE
);
2806 client_iconify(self
, FALSE
, here
);
2807 if (self
->desktop
!= DESKTOP_ALL
&&
2808 self
->desktop
!= screen_desktop
) {
2810 client_set_desktop(self
, screen_desktop
, FALSE
);
2812 screen_set_desktop(self
->desktop
);
2813 } else if (!self
->frame
->visible
)
2814 /* if its not visible for other reasons, then don't mess
2818 client_shade(self
, FALSE
);
2822 /* we do this an action here. this is rather important. this is because
2823 we want the results from the focus change to take place BEFORE we go
2824 about raising the window. when a fullscreen window loses focus, we need
2825 this or else the raise wont be able to raise above the to-lose-focus
2826 fullscreen window. */
2830 void client_raise(ObClient
*self
)
2832 action_run_string("Raise", self
);
2835 void client_lower(ObClient
*self
)
2837 action_run_string("Lower", self
);
2840 gboolean
client_focused(ObClient
*self
)
2842 return self
== focus_client
;
2845 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
2848 /* si is the smallest image >= req */
2849 /* li is the largest image < req */
2850 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2852 if (!self
->nicons
) {
2853 ObClientIcon
*parent
= NULL
;
2855 if (self
->transient_for
) {
2856 if (self
->transient_for
!= OB_TRAN_GROUP
)
2857 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2860 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2861 ObClient
*c
= it
->data
;
2862 if (c
!= self
&& !c
->transient_for
) {
2863 if ((parent
= client_icon_recursive(c
, w
, h
)))
2873 for (i
= 0; i
< self
->nicons
; ++i
) {
2874 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2875 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2879 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2884 if (largest
== 0) /* didnt find one smaller than the requested size */
2885 return &self
->icons
[si
];
2886 return &self
->icons
[li
];
2889 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
2892 static ObClientIcon deficon
;
2894 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2895 deficon
.width
= deficon
.height
= 48;
2896 deficon
.data
= ob_rr_theme
->def_win_icon
;
2902 /* this be mostly ripped from fvwm */
2903 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2905 gint my_cx
, my_cy
, his_cx
, his_cy
;
2908 gint score
, best_score
;
2909 ObClient
*best_client
, *cur
;
2915 /* first, find the centre coords of the currently focused window */
2916 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2917 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2922 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
2925 /* the currently selected window isn't interesting */
2928 if (!client_normal(cur
))
2930 /* using c->desktop instead of screen_desktop doesn't work if the
2931 * current window was omnipresent, hope this doesn't have any other
2933 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2937 if(client_focus_target(cur
) == cur
&&
2938 !(cur
->can_focus
|| cur
->focus_notify
))
2941 /* find the centre coords of this window, from the
2942 * currently focused window's point of view */
2943 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2944 + cur
->frame
->area
.width
/ 2;
2945 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2946 + cur
->frame
->area
.height
/ 2;
2948 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2949 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2951 /* Rotate the diagonals 45 degrees counterclockwise.
2952 * To do this, multiply the matrix /+h +h\ with the
2953 * vector (x y). \-h +h/
2954 * h = sqrt(0.5). We can set h := 1 since absolute
2955 * distance doesn't matter here. */
2956 tx
= his_cx
+ his_cy
;
2957 his_cy
= -his_cx
+ his_cy
;
2962 case OB_DIRECTION_NORTH
:
2963 case OB_DIRECTION_SOUTH
:
2964 case OB_DIRECTION_NORTHEAST
:
2965 case OB_DIRECTION_SOUTHWEST
:
2966 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2967 distance
= ((dir
== OB_DIRECTION_NORTH
||
2968 dir
== OB_DIRECTION_NORTHEAST
) ?
2971 case OB_DIRECTION_EAST
:
2972 case OB_DIRECTION_WEST
:
2973 case OB_DIRECTION_SOUTHEAST
:
2974 case OB_DIRECTION_NORTHWEST
:
2975 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2976 distance
= ((dir
== OB_DIRECTION_WEST
||
2977 dir
== OB_DIRECTION_NORTHWEST
) ?
2982 /* the target must be in the requested direction */
2986 /* Calculate score for this window. The smaller the better. */
2987 score
= distance
+ offset
;
2989 /* windows more than 45 degrees off the direction are
2990 * heavily penalized and will only be chosen if nothing
2991 * else within a million pixels */
2992 if(offset
> distance
)
2995 if(best_score
== -1 || score
< best_score
)
3003 void client_set_layer(ObClient
*self
, gint layer
)
3007 self
->above
= FALSE
;
3008 } else if (layer
== 0) {
3009 self
->below
= self
->above
= FALSE
;
3011 self
->below
= FALSE
;
3014 client_calc_layer(self
);
3015 client_change_state(self
); /* reflect this in the state hints */
3018 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3020 if (self
->undecorated
!= undecorated
) {
3021 self
->undecorated
= undecorated
;
3022 client_setup_decor_and_functions(self
);
3023 /* Make sure the client knows it might have moved. Maybe there is a
3024 * better way of doing this so only one client_configure is sent, but
3025 * since 125 of these are sent per second when moving the window (with
3026 * user = FALSE) i doubt it matters much.
3028 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
3029 self
->area
.width
, self
->area
.height
, TRUE
, TRUE
);
3030 client_change_state(self
); /* reflect this in the state hints */
3034 /* Determines which physical monitor a client is on by calculating the
3035 area of the part of the client on each monitor. The number of the
3036 monitor containing the greatest area of the client is returned.*/
3037 guint
client_monitor(ObClient
*self
)
3043 for (i
= 0; i
< screen_num_monitors
; ++i
) {
3044 Rect
*area
= screen_physical_area_monitor(i
);
3045 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
)) {
3049 RECT_SET_INTERSECTION(r
, *area
, self
->frame
->area
);
3050 v
= r
.width
* r
.height
;
3061 ObClient
*client_search_top_transient(ObClient
*self
)
3063 /* move up the transient chain as far as possible */
3064 if (self
->transient_for
) {
3065 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3066 return client_search_top_transient(self
->transient_for
);
3070 g_assert(self
->group
);
3072 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3073 ObClient
*c
= it
->data
;
3075 /* checking transient_for prevents infinate loops! */
3076 if (c
!= self
&& !c
->transient_for
)
3087 ObClient
*client_search_focus_parent(ObClient
*self
)
3089 if (self
->transient_for
) {
3090 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3091 if (client_focused(self
->transient_for
))
3092 return self
->transient_for
;
3096 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3097 ObClient
*c
= it
->data
;
3099 /* checking transient_for prevents infinate loops! */
3100 if (c
!= self
&& !c
->transient_for
)
3101 if (client_focused(c
))
3110 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3112 if (self
->transient_for
) {
3113 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3114 if (self
->transient_for
== search
)
3119 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3120 ObClient
*c
= it
->data
;
3122 /* checking transient_for prevents infinate loops! */
3123 if (c
!= self
&& !c
->transient_for
)
3133 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3137 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3138 if (sit
->data
== search
)
3140 if (client_search_transient(sit
->data
, search
))
3146 void client_update_sm_client_id(ObClient
*self
)
3148 g_free(self
->sm_client_id
);
3149 self
->sm_client_id
= NULL
;
3151 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3153 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3154 &self
->sm_client_id
);
3157 /* finds the nearest edge in the given direction from the current client
3158 * note to self: the edge is the -frame- edge (the actual one), not the
3161 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3163 gint dest
, monitor_dest
;
3164 gint my_edge_start
, my_edge_end
, my_offset
;
3171 a
= screen_area(c
->desktop
);
3172 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3175 case OB_DIRECTION_NORTH
:
3176 my_edge_start
= c
->frame
->area
.x
;
3177 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3178 my_offset
= c
->frame
->area
.y
;
3180 /* default: top of screen */
3182 monitor_dest
= monitor
->y
;
3183 /* if the monitor edge comes before the screen edge, */
3184 /* use that as the destination instead. (For xinerama) */
3185 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3186 dest
= monitor_dest
;
3188 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3189 gint his_edge_start
, his_edge_end
, his_offset
;
3190 ObClient
*cur
= it
->data
;
3194 if(!client_normal(cur
))
3196 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3200 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3203 his_edge_start
= cur
->frame
->area
.x
;
3204 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3205 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3207 if(his_offset
+ 1 > my_offset
)
3210 if(his_offset
< dest
)
3213 if(his_edge_start
>= my_edge_start
&&
3214 his_edge_start
<= my_edge_end
)
3217 if(my_edge_start
>= his_edge_start
&&
3218 my_edge_start
<= his_edge_end
)
3223 case OB_DIRECTION_SOUTH
:
3224 my_edge_start
= c
->frame
->area
.x
;
3225 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3226 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3228 /* default: bottom of screen */
3229 dest
= a
->y
+ a
->height
;
3230 monitor_dest
= monitor
->y
+ monitor
->height
;
3231 /* if the monitor edge comes before the screen edge, */
3232 /* use that as the destination instead. (For xinerama) */
3233 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3234 dest
= monitor_dest
;
3236 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3237 gint his_edge_start
, his_edge_end
, his_offset
;
3238 ObClient
*cur
= it
->data
;
3242 if(!client_normal(cur
))
3244 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3248 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3251 his_edge_start
= cur
->frame
->area
.x
;
3252 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3253 his_offset
= cur
->frame
->area
.y
;
3256 if(his_offset
- 1 < my_offset
)
3259 if(his_offset
> dest
)
3262 if(his_edge_start
>= my_edge_start
&&
3263 his_edge_start
<= my_edge_end
)
3266 if(my_edge_start
>= his_edge_start
&&
3267 my_edge_start
<= his_edge_end
)
3272 case OB_DIRECTION_WEST
:
3273 my_edge_start
= c
->frame
->area
.y
;
3274 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3275 my_offset
= c
->frame
->area
.x
;
3277 /* default: leftmost egde of screen */
3279 monitor_dest
= monitor
->x
;
3280 /* if the monitor edge comes before the screen edge, */
3281 /* use that as the destination instead. (For xinerama) */
3282 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3283 dest
= monitor_dest
;
3285 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3286 gint his_edge_start
, his_edge_end
, his_offset
;
3287 ObClient
*cur
= it
->data
;
3291 if(!client_normal(cur
))
3293 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3297 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3300 his_edge_start
= cur
->frame
->area
.y
;
3301 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3302 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3304 if(his_offset
+ 1 > my_offset
)
3307 if(his_offset
< dest
)
3310 if(his_edge_start
>= my_edge_start
&&
3311 his_edge_start
<= my_edge_end
)
3314 if(my_edge_start
>= his_edge_start
&&
3315 my_edge_start
<= his_edge_end
)
3321 case OB_DIRECTION_EAST
:
3322 my_edge_start
= c
->frame
->area
.y
;
3323 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3324 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3326 /* default: rightmost edge of screen */
3327 dest
= a
->x
+ a
->width
;
3328 monitor_dest
= monitor
->x
+ monitor
->width
;
3329 /* if the monitor edge comes before the screen edge, */
3330 /* use that as the destination instead. (For xinerama) */
3331 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3332 dest
= monitor_dest
;
3334 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3335 gint his_edge_start
, his_edge_end
, his_offset
;
3336 ObClient
*cur
= it
->data
;
3340 if(!client_normal(cur
))
3342 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3346 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3349 his_edge_start
= cur
->frame
->area
.y
;
3350 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3351 his_offset
= cur
->frame
->area
.x
;
3353 if(his_offset
- 1 < my_offset
)
3356 if(his_offset
> dest
)
3359 if(his_edge_start
>= my_edge_start
&&
3360 his_edge_start
<= my_edge_end
)
3363 if(my_edge_start
>= his_edge_start
&&
3364 my_edge_start
<= his_edge_end
)
3369 case OB_DIRECTION_NORTHEAST
:
3370 case OB_DIRECTION_SOUTHEAST
:
3371 case OB_DIRECTION_NORTHWEST
:
3372 case OB_DIRECTION_SOUTHWEST
:
3373 /* not implemented */
3375 g_assert_not_reached();
3376 dest
= 0; /* suppress warning */
3381 ObClient
* client_under_pointer()
3385 ObClient
*ret
= NULL
;
3387 if (screen_pointer_pos(&x
, &y
)) {
3388 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3389 if (WINDOW_IS_CLIENT(it
->data
)) {
3390 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3391 if (c
->frame
->visible
&&
3392 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3402 gboolean
client_has_group_siblings(ObClient
*self
)
3404 return self
->group
&& self
->group
->members
->next
;