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
, (guint32
*)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.
349 this is about the rude parameter:
350 non-normal clients has less rules, and
351 windows that are being restored from a session
352 do also. we can assume you want it back where
354 client_move_onscreen(self
, client_normal(self
) && !self
->session
);
357 keyboard_grab_for_client(self
, TRUE
);
358 mouse_grab_for_client(self
, TRUE
);
360 client_showhide(self
);
362 /* use client_focus instead of client_activate cuz client_activate does
363 stuff like switch desktops etc and I'm not interested in all that when
364 a window maps since its not based on an action from the user like
365 clicking a window to activate is. so keep the new window out of the way
368 /* if using focus_delay, stop the timer now so that focus doesn't go
370 event_halt_focus_delay();
373 /* since focus can change the stacking orders, if we focus the window
374 then the standard raise it gets is not enough, we need to queue one
375 for after the focus change takes place */
379 /* client_activate does this but we aret using it so we have to do it
381 if (screen_showing_desktop
)
382 screen_show_desktop(FALSE
);
384 /* add to client list/map */
385 client_list
= g_list_append(client_list
, self
);
386 g_hash_table_insert(window_map
, &self
->window
, self
);
388 /* this has to happen after we're in the client_list */
389 screen_update_areas();
391 /* update the list hints */
394 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
397 void client_unmanage_all()
399 while (client_list
!= NULL
)
400 client_unmanage(client_list
->data
);
403 void client_unmanage(ObClient
*self
)
408 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
410 g_assert(self
!= NULL
);
412 keyboard_grab_for_client(self
, FALSE
);
413 mouse_grab_for_client(self
, FALSE
);
415 /* potentially fix focusLast */
416 if (config_focus_last
)
417 grab_pointer(TRUE
, OB_CURSOR_NONE
);
419 /* remove the window from our save set */
420 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
422 /* we dont want events no more */
423 XSelectInput(ob_display
, self
->window
, NoEventMask
);
425 frame_hide(self
->frame
);
427 client_list
= g_list_remove(client_list
, self
);
428 stacking_remove(self
);
429 g_hash_table_remove(window_map
, &self
->window
);
431 /* update the focus lists */
432 focus_order_remove(self
);
434 /* once the client is out of the list, update the struts to remove it's
436 screen_update_areas();
438 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
439 Destructor
*d
= it
->data
;
440 d
->func(self
, d
->data
);
443 if (focus_client
== self
) {
446 /* focus the last focused window on the desktop, and ignore enter
447 events from the unmap so it doesnt mess with the focus */
448 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
449 /* remove these flags so we don't end up getting focused in the
451 self
->can_focus
= FALSE
;
452 self
->focus_notify
= FALSE
;
454 client_unfocus(self
);
457 /* tell our parent(s) that we're gone */
458 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
459 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
460 if (it
->data
!= self
)
461 ((ObClient
*)it
->data
)->transients
=
462 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
463 } else if (self
->transient_for
) { /* transient of window */
464 self
->transient_for
->transients
=
465 g_slist_remove(self
->transient_for
->transients
, self
);
468 /* tell our transients that we're gone */
469 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
470 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
471 ((ObClient
*)it
->data
)->transient_for
= NULL
;
472 client_calc_layer(it
->data
);
476 /* remove from its group */
478 group_remove(self
->group
, self
);
482 /* give the client its border back */
483 client_toggle_border(self
, TRUE
);
485 /* reparent the window out of the frame, and free the frame */
486 frame_release_client(self
->frame
, self
);
489 if (ob_state() != OB_STATE_EXITING
) {
490 /* these values should not be persisted across a window
492 PROP_ERASE(self
->window
, net_wm_desktop
);
493 PROP_ERASE(self
->window
, net_wm_state
);
494 PROP_ERASE(self
->window
, wm_state
);
496 /* if we're left in an unmapped state, the client wont be mapped. this
497 is bad, since we will no longer be managing the window on restart */
498 XMapWindow(ob_display
, self
->window
);
502 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
504 /* free all data allocated in the client struct */
505 g_slist_free(self
->transients
);
506 for (j
= 0; j
< self
->nicons
; ++j
)
507 g_free(self
->icons
[j
].data
);
508 if (self
->nicons
> 0)
511 g_free(self
->icon_title
);
515 g_free(self
->sm_client_id
);
518 /* update the list hints */
521 if (config_focus_last
)
522 grab_pointer(FALSE
, OB_CURSOR_NONE
);
525 static void client_urgent_notify(ObClient
*self
)
528 frame_flash_start(self
->frame
);
530 frame_flash_stop(self
->frame
);
533 static void client_restore_session_state(ObClient
*self
)
537 if (!(it
= session_state_find(self
)))
540 self
->session
= it
->data
;
542 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
543 self
->positioned
= TRUE
;
544 if (self
->session
->w
> 0)
545 self
->area
.width
= self
->session
->w
;
546 if (self
->session
->h
> 0)
547 self
->area
.height
= self
->session
->h
;
548 XResizeWindow(ob_display
, self
->window
,
549 self
->area
.width
, self
->area
.height
);
551 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
552 self
->session
->desktop
:
553 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
554 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
556 self
->shaded
= self
->session
->shaded
;
557 self
->iconic
= self
->session
->iconic
;
558 self
->skip_pager
= self
->session
->skip_pager
;
559 self
->skip_taskbar
= self
->session
->skip_taskbar
;
560 self
->fullscreen
= self
->session
->fullscreen
;
561 self
->above
= self
->session
->above
;
562 self
->below
= self
->session
->below
;
563 self
->max_horz
= self
->session
->max_horz
;
564 self
->max_vert
= self
->session
->max_vert
;
567 static void client_restore_session_stacking(ObClient
*self
)
571 if (!self
->session
) return;
573 it
= g_list_find(session_saved_state
, self
->session
);
574 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
577 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
578 if (session_state_cmp(it
->data
, cit
->data
))
581 client_calc_layer(self
);
582 stacking_below(CLIENT_AS_WINDOW(self
),
583 CLIENT_AS_WINDOW(cit
->data
));
589 void client_move_onscreen(ObClient
*self
, gboolean rude
)
591 gint x
= self
->area
.x
;
592 gint y
= self
->area
.y
;
593 if (client_find_onscreen(self
, &x
, &y
,
594 self
->frame
->area
.width
,
595 self
->frame
->area
.height
, rude
)) {
596 client_move(self
, x
, y
);
600 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
604 gint ox
= *x
, oy
= *y
;
606 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
609 /* XXX watch for xinerama dead areas */
611 /* a = screen_area(self->desktop); */
612 a
= screen_physical_area_monitor(client_monitor(self
));
613 if (client_normal(self
)) {
614 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
615 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
616 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
617 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
618 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
620 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
625 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
626 Java can suck it too. */
628 /* dont let windows map/move into the strut unless they
629 are bigger than the available area */
631 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
632 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
633 *x
= a
->x
+ a
->width
- w
;
635 if (h
<= a
->height
) {
636 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
637 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
638 *y
= a
->y
+ a
->height
- h
;
642 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
645 return ox
!= *x
|| oy
!= *y
;
648 static void client_toggle_border(ObClient
*self
, gboolean show
)
650 /* adjust our idea of where the client is, based on its border. When the
651 border is removed, the client should now be considered to be in a
653 when re-adding the border to the client, the same operation needs to be
655 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
656 gint x
= oldx
, y
= oldy
;
657 switch(self
->gravity
) {
659 case NorthWestGravity
:
661 case SouthWestGravity
:
663 case NorthEastGravity
:
665 case SouthEastGravity
:
666 if (show
) x
-= self
->border_width
* 2;
667 else x
+= self
->border_width
* 2;
674 if (show
) x
-= self
->border_width
;
675 else x
+= self
->border_width
;
678 switch(self
->gravity
) {
680 case NorthWestGravity
:
682 case NorthEastGravity
:
684 case SouthWestGravity
:
686 case SouthEastGravity
:
687 if (show
) y
-= self
->border_width
* 2;
688 else y
+= self
->border_width
* 2;
695 if (show
) y
-= self
->border_width
;
696 else y
+= self
->border_width
;
703 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
705 /* move the client so it is back it the right spot _with_ its
707 if (x
!= oldx
|| y
!= oldy
)
708 XMoveWindow(ob_display
, self
->window
, x
, y
);
710 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
714 static void client_get_all(ObClient
*self
)
716 client_get_area(self
);
717 client_update_transient_for(self
);
718 client_update_wmhints(self
);
719 client_get_startup_id(self
);
720 client_get_desktop(self
);
721 client_get_shaped(self
);
723 client_get_mwm_hints(self
);
724 client_get_type(self
);/* this can change the mwmhints for special cases */
726 /* The transient hint is used to pick a type, but the type can also affect
727 transiency (dialogs are always made transients). This is Havoc's idea,
728 but it is needed to make some apps work right (eg tsclient). */
729 client_update_transient_for(self
);
731 client_get_state(self
);
734 /* a couple type-based defaults for new windows */
736 /* this makes sure that these windows appear on all desktops */
737 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
738 self
->desktop
= DESKTOP_ALL
;
741 client_update_protocols(self
);
743 client_get_gravity(self
); /* get the attribute gravity */
744 client_update_normal_hints(self
); /* this may override the attribute
747 /* got the type, the mwmhints, the protocols, and the normal hints
748 (min/max sizes), so we're ready to set up the decorations/functions */
749 client_setup_decor_and_functions(self
);
751 client_update_title(self
);
752 client_update_class(self
);
753 client_update_sm_client_id(self
);
754 client_update_strut(self
);
755 client_update_icons(self
);
758 static void client_get_startup_id(ObClient
*self
)
760 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
762 PROP_GETS(self
->group
->leader
,
763 net_startup_id
, utf8
, &self
->startup_id
);
766 static void client_get_area(ObClient
*self
)
768 XWindowAttributes wattrib
;
771 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
772 g_assert(ret
!= BadWindow
);
774 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
775 self
->border_width
= wattrib
.border_width
;
778 static void client_get_desktop(ObClient
*self
)
780 guint32 d
= screen_num_desktops
; /* an always-invalid value */
782 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
783 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
784 self
->desktop
= screen_num_desktops
- 1;
788 gboolean trdesk
= FALSE
;
790 if (self
->transient_for
) {
791 if (self
->transient_for
!= OB_TRAN_GROUP
) {
792 self
->desktop
= self
->transient_for
->desktop
;
797 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
798 if (it
->data
!= self
&&
799 !((ObClient
*)it
->data
)->transient_for
) {
800 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
807 /* try get from the startup-notification protocol */
808 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
809 if (self
->desktop
>= screen_num_desktops
&&
810 self
->desktop
!= DESKTOP_ALL
)
811 self
->desktop
= screen_num_desktops
- 1;
813 /* defaults to the current desktop */
814 self
->desktop
= screen_desktop
;
817 if (self
->desktop
!= d
) {
818 /* set the desktop hint, to make sure that it always exists */
819 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
823 static void client_get_state(ObClient
*self
)
828 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
830 for (i
= 0; i
< num
; ++i
) {
831 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
833 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
835 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
837 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
838 self
->skip_taskbar
= TRUE
;
839 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
840 self
->skip_pager
= TRUE
;
841 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
842 self
->fullscreen
= TRUE
;
843 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
844 self
->max_vert
= TRUE
;
845 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
846 self
->max_horz
= TRUE
;
847 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
849 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
851 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
852 self
->undecorated
= TRUE
;
858 if (!(self
->above
|| self
->below
)) {
860 /* apply stuff from the group */
864 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
865 ObClient
*c
= it
->data
;
866 if (c
!= self
&& !client_search_transient(self
, c
) &&
867 client_normal(self
) && client_normal(c
))
870 (c
->above
? 1 : (c
->below
? -1 : 0)));
884 g_assert_not_reached();
891 static void client_get_shaped(ObClient
*self
)
893 self
->shaped
= FALSE
;
895 if (extensions_shape
) {
900 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
902 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
903 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
905 self
->shaped
= (s
!= 0);
910 void client_update_transient_for(ObClient
*self
)
913 ObClient
*target
= NULL
;
915 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
916 self
->transient
= TRUE
;
917 if (t
!= self
->window
) { /* cant be transient to itself! */
918 target
= g_hash_table_lookup(window_map
, &t
);
919 /* if this happens then we need to check for it*/
920 g_assert(target
!= self
);
921 if (target
&& !WINDOW_IS_CLIENT(target
)) {
922 /* this can happen when a dialog is a child of
923 a dockapp, for example */
927 if (!target
&& self
->group
) {
928 /* not transient to a client, see if it is transient for a
930 if (t
== self
->group
->leader
||
932 t
== RootWindow(ob_display
, ob_screen
))
934 /* window is a transient for its group! */
935 target
= OB_TRAN_GROUP
;
939 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
&& self
->group
) {
940 self
->transient
= TRUE
;
941 target
= OB_TRAN_GROUP
;
943 self
->transient
= FALSE
;
945 /* if anything has changed... */
946 if (target
!= self
->transient_for
) {
947 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
950 /* remove from old parents */
951 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
952 ObClient
*c
= it
->data
;
953 if (c
!= self
&& !c
->transient_for
)
954 c
->transients
= g_slist_remove(c
->transients
, self
);
956 } else if (self
->transient_for
!= NULL
) { /* transient of window */
957 /* remove from old parent */
958 self
->transient_for
->transients
=
959 g_slist_remove(self
->transient_for
->transients
, self
);
961 self
->transient_for
= target
;
962 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
965 /* add to new parents */
966 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
967 ObClient
*c
= it
->data
;
968 if (c
!= self
&& !c
->transient_for
)
969 c
->transients
= g_slist_append(c
->transients
, self
);
972 /* remove all transients which are in the group, that causes
973 circlular pointer hell of doom */
974 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
976 for (sit
= self
->transients
; sit
; sit
= next
) {
977 next
= g_slist_next(sit
);
978 if (sit
->data
== it
->data
)
980 g_slist_delete_link(self
->transients
, sit
);
983 } else if (self
->transient_for
!= NULL
) { /* transient of window */
984 /* add to new parent */
985 self
->transient_for
->transients
=
986 g_slist_append(self
->transient_for
->transients
, self
);
991 static void client_get_mwm_hints(ObClient
*self
)
996 self
->mwmhints
.flags
= 0; /* default to none */
998 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1000 if (num
>= OB_MWM_ELEMENTS
) {
1001 self
->mwmhints
.flags
= hints
[0];
1002 self
->mwmhints
.functions
= hints
[1];
1003 self
->mwmhints
.decorations
= hints
[2];
1009 void client_get_type(ObClient
*self
)
1016 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1017 /* use the first value that we know about in the array */
1018 for (i
= 0; i
< num
; ++i
) {
1019 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1020 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1021 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1022 self
->type
= OB_CLIENT_TYPE_DOCK
;
1023 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1024 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1025 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1026 self
->type
= OB_CLIENT_TYPE_MENU
;
1027 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1028 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1029 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1030 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1031 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1032 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1033 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1034 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1035 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1036 /* prevent this window from getting any decor or
1038 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1039 OB_MWM_FLAG_DECORATIONS
);
1040 self
->mwmhints
.decorations
= 0;
1041 self
->mwmhints
.functions
= 0;
1043 if (self
->type
!= (ObClientType
) -1)
1044 break; /* grab the first legit type */
1049 if (self
->type
== (ObClientType
) -1) {
1050 /*the window type hint was not set, which means we either classify
1051 ourself as a normal window or a dialog, depending on if we are a
1053 if (self
->transient
)
1054 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1056 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1060 void client_update_protocols(ObClient
*self
)
1063 guint num_return
, i
;
1065 self
->focus_notify
= FALSE
;
1066 self
->delete_window
= FALSE
;
1068 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1069 for (i
= 0; i
< num_return
; ++i
) {
1070 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1071 /* this means we can request the window to close */
1072 self
->delete_window
= TRUE
;
1073 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1074 /* if this protocol is requested, then the window will be
1075 notified whenever we want it to receive focus */
1076 self
->focus_notify
= TRUE
;
1082 static void client_get_gravity(ObClient
*self
)
1084 XWindowAttributes wattrib
;
1087 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1088 g_assert(ret
!= BadWindow
);
1089 self
->gravity
= wattrib
.win_gravity
;
1092 void client_update_normal_hints(ObClient
*self
)
1096 gint oldgravity
= self
->gravity
;
1099 self
->min_ratio
= 0.0f
;
1100 self
->max_ratio
= 0.0f
;
1101 SIZE_SET(self
->size_inc
, 1, 1);
1102 SIZE_SET(self
->base_size
, 0, 0);
1103 SIZE_SET(self
->min_size
, 0, 0);
1104 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1106 /* get the hints from the window */
1107 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1108 /* normal windows can't request placement! har har
1109 if (!client_normal(self))
1111 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1113 if (size
.flags
& PWinGravity
) {
1114 self
->gravity
= size
.win_gravity
;
1116 /* if the client has a frame, i.e. has already been mapped and
1117 is changing its gravity */
1118 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1119 /* move our idea of the client's position based on its new
1121 self
->area
.x
= self
->frame
->area
.x
;
1122 self
->area
.y
= self
->frame
->area
.y
;
1123 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1127 if (size
.flags
& PAspect
) {
1128 if (size
.min_aspect
.y
)
1130 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1131 if (size
.max_aspect
.y
)
1133 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1136 if (size
.flags
& PMinSize
)
1137 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1139 if (size
.flags
& PMaxSize
)
1140 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1142 if (size
.flags
& PBaseSize
)
1143 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1145 if (size
.flags
& PResizeInc
)
1146 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1150 void client_setup_decor_and_functions(ObClient
*self
)
1152 /* start with everything (cept fullscreen) */
1154 (OB_FRAME_DECOR_TITLEBAR
|
1155 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1156 OB_FRAME_DECOR_GRIPS
|
1157 OB_FRAME_DECOR_BORDER
|
1158 OB_FRAME_DECOR_ICON
|
1159 OB_FRAME_DECOR_ALLDESKTOPS
|
1160 OB_FRAME_DECOR_ICONIFY
|
1161 OB_FRAME_DECOR_MAXIMIZE
|
1162 OB_FRAME_DECOR_SHADE
|
1163 OB_FRAME_DECOR_CLOSE
);
1165 (OB_CLIENT_FUNC_RESIZE
|
1166 OB_CLIENT_FUNC_MOVE
|
1167 OB_CLIENT_FUNC_ICONIFY
|
1168 OB_CLIENT_FUNC_MAXIMIZE
|
1169 OB_CLIENT_FUNC_SHADE
|
1170 OB_CLIENT_FUNC_CLOSE
);
1172 if (!(self
->min_size
.width
< self
->max_size
.width
||
1173 self
->min_size
.height
< self
->max_size
.height
))
1174 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1176 switch (self
->type
) {
1177 case OB_CLIENT_TYPE_NORMAL
:
1178 /* normal windows retain all of the possible decorations and
1179 functionality, and are the only windows that you can fullscreen */
1180 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1183 case OB_CLIENT_TYPE_DIALOG
:
1184 case OB_CLIENT_TYPE_UTILITY
:
1185 /* these windows cannot be maximized */
1186 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1189 case OB_CLIENT_TYPE_MENU
:
1190 case OB_CLIENT_TYPE_TOOLBAR
:
1191 /* these windows get less functionality */
1192 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1195 case OB_CLIENT_TYPE_DESKTOP
:
1196 case OB_CLIENT_TYPE_DOCK
:
1197 case OB_CLIENT_TYPE_SPLASH
:
1198 /* none of these windows are manipulated by the window manager */
1199 self
->decorations
= 0;
1200 self
->functions
= 0;
1204 /* Mwm Hints are applied subtractively to what has already been chosen for
1205 decor and functionality */
1206 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1207 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1208 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1209 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1210 /* if the mwm hints request no handle or title, then all
1211 decorations are disabled */
1212 self
->decorations
= 0;
1216 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1217 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1218 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1219 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1220 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1221 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1222 /* dont let mwm hints kill any buttons
1223 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1224 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1225 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1226 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1228 /* dont let mwm hints kill the close button
1229 if (! (self->mwmhints.functions & MwmFunc_Close))
1230 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1234 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1235 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1236 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1237 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1238 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1239 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1241 /* can't maximize without moving/resizing */
1242 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1243 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1244 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1245 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1246 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1249 /* kill the handle on fully maxed windows */
1250 if (self
->max_vert
&& self
->max_horz
)
1251 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1253 /* finally, the user can have requested no decorations, which overrides
1254 everything (but doesnt give it a border if it doesnt have one) */
1255 if (self
->undecorated
) {
1256 if (config_theme_keepborder
)
1257 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1259 self
->decorations
= 0;
1262 /* if we don't have a titlebar, then we cannot shade! */
1263 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1264 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1266 /* now we need to check against rules for the client's current state */
1267 if (self
->fullscreen
) {
1268 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1269 OB_CLIENT_FUNC_FULLSCREEN
|
1270 OB_CLIENT_FUNC_ICONIFY
);
1271 self
->decorations
= 0;
1274 client_change_allowed_actions(self
);
1277 /* adjust the client's decorations, etc. */
1278 client_reconfigure(self
);
1282 static void client_change_allowed_actions(ObClient
*self
)
1287 /* desktop windows are kept on all desktops */
1288 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1289 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1291 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1292 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1293 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1294 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1295 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1296 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1297 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1298 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1299 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1300 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1301 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1302 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1303 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1304 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1305 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1308 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1310 /* make sure the window isn't breaking any rules now */
1312 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1313 if (self
->frame
) client_shade(self
, FALSE
);
1314 else self
->shaded
= FALSE
;
1316 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1317 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1318 else self
->iconic
= FALSE
;
1320 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1321 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1322 else self
->fullscreen
= FALSE
;
1324 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1326 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1327 else self
->max_vert
= self
->max_horz
= FALSE
;
1331 void client_reconfigure(ObClient
*self
)
1333 /* by making this pass FALSE for user, we avoid the emacs event storm where
1334 every configurenotify causes an update in its normal hints, i think this
1335 is generally what we want anyways... */
1336 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1337 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1340 void client_update_wmhints(ObClient
*self
)
1343 gboolean ur
= FALSE
;
1346 /* assume a window takes input if it doesnt specify */
1347 self
->can_focus
= TRUE
;
1349 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1350 if (hints
->flags
& InputHint
)
1351 self
->can_focus
= hints
->input
;
1353 /* only do this when first managing the window *AND* when we aren't
1355 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1356 if (hints
->flags
& StateHint
)
1357 self
->iconic
= hints
->initial_state
== IconicState
;
1359 if (hints
->flags
& XUrgencyHint
)
1362 if (!(hints
->flags
& WindowGroupHint
))
1363 hints
->window_group
= None
;
1365 /* did the group state change? */
1366 if (hints
->window_group
!=
1367 (self
->group
? self
->group
->leader
: None
)) {
1368 /* remove from the old group if there was one */
1369 if (self
->group
!= NULL
) {
1370 /* remove transients of the group */
1371 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1372 self
->transients
= g_slist_remove(self
->transients
,
1375 /* remove myself from parents in the group */
1376 if (self
->transient_for
== OB_TRAN_GROUP
) {
1377 for (it
= self
->group
->members
; it
;
1378 it
= g_slist_next(it
))
1380 ObClient
*c
= it
->data
;
1382 if (c
!= self
&& !c
->transient_for
)
1383 c
->transients
= g_slist_remove(c
->transients
,
1388 group_remove(self
->group
, self
);
1391 if (hints
->window_group
!= None
) {
1392 self
->group
= group_add(hints
->window_group
, self
);
1394 /* i can only have transients from the group if i am not
1396 if (!self
->transient_for
) {
1397 /* add other transients of the group that are already
1399 for (it
= self
->group
->members
; it
;
1400 it
= g_slist_next(it
))
1402 ObClient
*c
= it
->data
;
1403 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1405 g_slist_append(self
->transients
, c
);
1410 /* because the self->transient flag wont change from this call,
1411 we don't need to update the window's type and such, only its
1412 transient_for, and the transients lists of other windows in
1413 the group may be affected */
1414 client_update_transient_for(self
);
1417 /* the WM_HINTS can contain an icon */
1418 client_update_icons(self
);
1423 if (ur
!= self
->urgent
) {
1425 /* fire the urgent callback if we're mapped, otherwise, wait until
1426 after we're mapped */
1428 client_urgent_notify(self
);
1432 void client_update_title(ObClient
*self
)
1438 gboolean read_title
;
1441 old_title
= self
->title
;
1444 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1445 /* try old x stuff */
1446 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
)) {
1447 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1448 if (self
->transient
) {
1449 data
= g_strdup("");
1452 data
= g_strdup("Unnamed Window");
1456 /* did the title change? then reset the title_count */
1457 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1458 self
->title_count
= 1;
1460 /* look for duplicates and append a number */
1462 for (it
= client_list
; it
; it
= g_list_next(it
))
1463 if (it
->data
!= self
) {
1464 ObClient
*c
= it
->data
;
1465 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1466 nums
|= 1 << c
->title_count
;
1468 /* find first free number */
1469 for (i
= 1; i
<= 32; ++i
)
1470 if (!(nums
& (1 << i
))) {
1471 if (self
->title_count
== 1 || i
== 1)
1472 self
->title_count
= i
;
1475 /* dont display the number for the first window */
1476 if (self
->title_count
> 1) {
1478 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1483 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1488 frame_adjust_title(self
->frame
);
1492 /* update the icon title */
1494 g_free(self
->icon_title
);
1498 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1499 /* try old x stuff */
1500 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1501 data
= g_strdup(self
->title
);
1505 /* append the title count, dont display the number for the first window */
1506 if (read_title
&& self
->title_count
> 1) {
1507 gchar
*vdata
, *ndata
;
1508 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1509 vdata
= g_strconcat(data
, ndata
, NULL
);
1515 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1517 self
->icon_title
= data
;
1520 void client_update_class(ObClient
*self
)
1525 if (self
->name
) g_free(self
->name
);
1526 if (self
->class) g_free(self
->class);
1527 if (self
->role
) g_free(self
->role
);
1529 self
->name
= self
->class = self
->role
= NULL
;
1531 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1533 self
->name
= g_strdup(data
[0]);
1535 self
->class = g_strdup(data
[1]);
1540 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1543 if (self
->name
== NULL
) self
->name
= g_strdup("");
1544 if (self
->class == NULL
) self
->class = g_strdup("");
1545 if (self
->role
== NULL
) self
->role
= g_strdup("");
1548 void client_update_strut(ObClient
*self
)
1552 gboolean got
= FALSE
;
1555 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1559 STRUT_PARTIAL_SET(strut
,
1560 data
[0], data
[2], data
[1], data
[3],
1561 data
[4], data
[5], data
[8], data
[9],
1562 data
[6], data
[7], data
[10], data
[11]);
1568 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1574 /* use the screen's width/height */
1575 a
= screen_physical_area();
1577 STRUT_PARTIAL_SET(strut
,
1578 data
[0], data
[2], data
[1], data
[3],
1579 a
->y
, a
->y
+ a
->height
- 1,
1580 a
->x
, a
->x
+ a
->width
- 1,
1581 a
->y
, a
->y
+ a
->height
- 1,
1582 a
->x
, a
->x
+ a
->width
- 1);
1588 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1589 0, 0, 0, 0, 0, 0, 0, 0);
1591 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1592 self
->strut
= strut
;
1594 /* updating here is pointless while we're being mapped cuz we're not in
1595 the client list yet */
1597 screen_update_areas();
1601 void client_update_icons(ObClient
*self
)
1607 for (i
= 0; i
< self
->nicons
; ++i
)
1608 g_free(self
->icons
[i
].data
);
1609 if (self
->nicons
> 0)
1610 g_free(self
->icons
);
1613 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1614 /* figure out how many valid icons are in here */
1616 while (num
- i
> 2) {
1620 if (i
> num
|| w
*h
== 0) break;
1624 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1626 /* store the icons */
1628 for (j
= 0; j
< self
->nicons
; ++j
) {
1631 w
= self
->icons
[j
].width
= data
[i
++];
1632 h
= self
->icons
[j
].height
= data
[i
++];
1634 if (w
*h
== 0) continue;
1636 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1637 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1642 self
->icons
[j
].data
[t
] =
1643 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1644 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1645 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1646 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1652 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1653 kwm_win_icon
, &data
, &num
)) {
1656 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1657 xerror_set_ignore(TRUE
);
1658 if (!RrPixmapToRGBA(ob_rr_inst
,
1660 &self
->icons
[self
->nicons
-1].width
,
1661 &self
->icons
[self
->nicons
-1].height
,
1662 &self
->icons
[self
->nicons
-1].data
)) {
1663 g_free(&self
->icons
[self
->nicons
-1]);
1666 xerror_set_ignore(FALSE
);
1672 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1673 if (hints
->flags
& IconPixmapHint
) {
1675 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1676 xerror_set_ignore(TRUE
);
1677 if (!RrPixmapToRGBA(ob_rr_inst
,
1679 (hints
->flags
& IconMaskHint
?
1680 hints
->icon_mask
: None
),
1681 &self
->icons
[self
->nicons
-1].width
,
1682 &self
->icons
[self
->nicons
-1].height
,
1683 &self
->icons
[self
->nicons
-1].data
)){
1684 g_free(&self
->icons
[self
->nicons
-1]);
1687 xerror_set_ignore(FALSE
);
1694 frame_adjust_icon(self
->frame
);
1697 static void client_change_state(ObClient
*self
)
1700 guint32 netstate
[11];
1703 state
[0] = self
->wmstate
;
1705 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1709 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1711 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1713 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1714 if (self
->skip_taskbar
)
1715 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1716 if (self
->skip_pager
)
1717 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1718 if (self
->fullscreen
)
1719 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1721 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1723 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1725 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1727 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1728 if (self
->undecorated
)
1729 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1730 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1732 client_calc_layer(self
);
1735 frame_adjust_state(self
->frame
);
1738 ObClient
*client_search_focus_tree(ObClient
*self
)
1743 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1744 if (client_focused(it
->data
)) return it
->data
;
1745 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1750 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1752 if (self
->transient_for
) {
1753 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1754 return client_search_focus_tree_full(self
->transient_for
);
1757 gboolean recursed
= FALSE
;
1759 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1760 if (!((ObClient
*)it
->data
)->transient_for
) {
1762 if ((c
= client_search_focus_tree_full(it
->data
)))
1771 /* this function checks the whole tree, the client_search_focus_tree~
1772 does not, so we need to check this window */
1773 if (client_focused(self
))
1775 return client_search_focus_tree(self
);
1778 static ObStackingLayer
calc_layer(ObClient
*self
)
1782 if (self
->fullscreen
&&
1783 (client_focused(self
) || client_search_focus_tree(self
)))
1784 l
= OB_STACKING_LAYER_FULLSCREEN
;
1785 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1786 l
= OB_STACKING_LAYER_DESKTOP
;
1787 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1788 if (self
->above
) l
= OB_STACKING_LAYER_DOCK_ABOVE
;
1789 else if (self
->below
) l
= OB_STACKING_LAYER_DOCK_BELOW
;
1790 else l
= OB_STACKING_LAYER_DOCK_NORMAL
;
1792 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1793 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1794 else l
= OB_STACKING_LAYER_NORMAL
;
1799 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1800 ObStackingLayer l
, gboolean raised
)
1802 ObStackingLayer old
, own
;
1806 own
= calc_layer(self
);
1807 self
->layer
= l
> own
? l
: own
;
1809 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
1810 client_calc_layer_recursive(it
->data
, orig
,
1811 l
, raised
? raised
: l
!= old
);
1813 if (!raised
&& l
!= old
)
1814 if (orig
->frame
) { /* only restack if the original window is managed */
1815 stacking_remove(CLIENT_AS_WINDOW(self
));
1816 stacking_add(CLIENT_AS_WINDOW(self
));
1820 void client_calc_layer(ObClient
*self
)
1827 /* transients take on the layer of their parents */
1828 self
= client_search_top_transient(self
);
1830 l
= calc_layer(self
);
1832 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1835 gboolean
client_should_show(ObClient
*self
)
1839 if (client_normal(self
) && screen_showing_desktop
)
1842 if (self->transient_for) {
1843 if (self->transient_for != OB_TRAN_GROUP)
1844 return client_should_show(self->transient_for);
1848 for (it = self->group->members; it; it = g_slist_next(it)) {
1849 ObClient *c = it->data;
1850 if (c != self && !c->transient_for) {
1851 if (client_should_show(c))
1858 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
1864 static void client_showhide(ObClient
*self
)
1867 if (client_should_show(self
))
1868 frame_show(self
->frame
);
1870 frame_hide(self
->frame
);
1873 gboolean
client_normal(ObClient
*self
) {
1874 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1875 self
->type
== OB_CLIENT_TYPE_DOCK
||
1876 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1879 static void client_apply_startup_state(ObClient
*self
)
1881 /* these are in a carefully crafted order.. */
1884 self
->iconic
= FALSE
;
1885 client_iconify(self
, TRUE
, FALSE
);
1887 if (self
->fullscreen
) {
1888 self
->fullscreen
= FALSE
;
1889 client_fullscreen(self
, TRUE
, FALSE
);
1891 if (self
->undecorated
) {
1892 self
->undecorated
= FALSE
;
1893 client_set_undecorated(self
, TRUE
);
1896 self
->shaded
= FALSE
;
1897 client_shade(self
, TRUE
);
1900 client_urgent_notify(self
);
1902 if (self
->max_vert
&& self
->max_horz
) {
1903 self
->max_vert
= self
->max_horz
= FALSE
;
1904 client_maximize(self
, TRUE
, 0, FALSE
);
1905 } else if (self
->max_vert
) {
1906 self
->max_vert
= FALSE
;
1907 client_maximize(self
, TRUE
, 2, FALSE
);
1908 } else if (self
->max_horz
) {
1909 self
->max_horz
= FALSE
;
1910 client_maximize(self
, TRUE
, 1, FALSE
);
1913 /* nothing to do for the other states:
1922 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1923 gint x
, gint y
, gint w
, gint h
,
1924 gboolean user
, gboolean final
,
1925 gboolean force_reply
)
1928 gboolean send_resize_client
;
1929 gboolean moved
= FALSE
, resized
= FALSE
;
1930 guint fdecor
= self
->frame
->decorations
;
1931 gboolean fhorz
= self
->frame
->max_horz
;
1933 /* make the frame recalculate its dimentions n shit without changing
1934 anything visible for real, this way the constraints below can work with
1935 the updated frame dimensions. */
1936 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1938 /* gets the frame's position */
1939 frame_client_gravity(self
->frame
, &x
, &y
);
1941 /* these positions are frame positions, not client positions */
1943 /* set the size and position if fullscreen */
1944 if (self
->fullscreen
) {
1947 XF86VidModeModeLine mode
;
1952 i
= client_monitor(self
);
1953 a
= screen_physical_area_monitor(i
);
1956 if (i
== 0 && /* primary head */
1957 extensions_vidmode
&&
1958 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1959 /* get the mode last so the mode.privsize isnt freed incorrectly */
1960 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1965 if (mode
.privsize
) XFree(mode
.private);
1975 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1979 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1981 /* set the size and position if maximized */
1982 if (self
->max_horz
) {
1984 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1986 if (self
->max_vert
) {
1988 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1992 /* gets the client's position */
1993 frame_frame_gravity(self
->frame
, &x
, &y
);
1995 /* these override the above states! if you cant move you can't move! */
1997 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2001 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2002 w
= self
->area
.width
;
2003 h
= self
->area
.height
;
2007 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
2008 gint basew
, baseh
, minw
, minh
;
2010 /* base size is substituted with min size if not specified */
2011 if (self
->base_size
.width
|| self
->base_size
.height
) {
2012 basew
= self
->base_size
.width
;
2013 baseh
= self
->base_size
.height
;
2015 basew
= self
->min_size
.width
;
2016 baseh
= self
->min_size
.height
;
2018 /* min size is substituted with base size if not specified */
2019 if (self
->min_size
.width
|| self
->min_size
.height
) {
2020 minw
= self
->min_size
.width
;
2021 minh
= self
->min_size
.height
;
2023 minw
= self
->base_size
.width
;
2024 minh
= self
->base_size
.height
;
2027 /* if this is a user-requested resize, then check against min/max
2030 /* smaller than min size or bigger than max size? */
2031 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
2032 if (w
< minw
) w
= minw
;
2033 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
2034 if (h
< minh
) h
= minh
;
2039 /* keep to the increments */
2040 w
/= self
->size_inc
.width
;
2041 h
/= self
->size_inc
.height
;
2043 /* you cannot resize to nothing */
2044 if (basew
+ w
< 1) w
= 1 - basew
;
2045 if (baseh
+ h
< 1) h
= 1 - baseh
;
2047 /* store the logical size */
2048 SIZE_SET(self
->logical_size
,
2049 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
2050 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
2052 w
*= self
->size_inc
.width
;
2053 h
*= self
->size_inc
.height
;
2058 /* adjust the height to match the width for the aspect ratios.
2059 for this, min size is not substituted for base size ever. */
2060 w
-= self
->base_size
.width
;
2061 h
-= self
->base_size
.height
;
2063 if (!self
->fullscreen
) {
2064 if (self
->min_ratio
)
2065 if (h
* self
->min_ratio
> w
) {
2066 h
= (gint
)(w
/ self
->min_ratio
);
2068 /* you cannot resize to nothing */
2071 w
= (gint
)(h
* self
->min_ratio
);
2074 if (self
->max_ratio
)
2075 if (h
* self
->max_ratio
< w
) {
2076 h
= (gint
)(w
/ self
->max_ratio
);
2078 /* you cannot resize to nothing */
2081 w
= (gint
)(h
* self
->min_ratio
);
2086 w
+= self
->base_size
.width
;
2087 h
+= self
->base_size
.height
;
2094 case OB_CORNER_TOPLEFT
:
2096 case OB_CORNER_TOPRIGHT
:
2097 x
-= w
- self
->area
.width
;
2099 case OB_CORNER_BOTTOMLEFT
:
2100 y
-= h
- self
->area
.height
;
2102 case OB_CORNER_BOTTOMRIGHT
:
2103 x
-= w
- self
->area
.width
;
2104 y
-= h
- self
->area
.height
;
2108 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2109 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2111 oldw
= self
->area
.width
;
2112 oldh
= self
->area
.height
;
2113 RECT_SET(self
->area
, x
, y
, w
, h
);
2115 /* for app-requested resizes, always resize if 'resized' is true.
2116 for user-requested ones, only resize if final is true, or when
2117 resizing in redraw mode */
2118 send_resize_client
= ((!user
&& resized
) ||
2120 (resized
&& config_resize_redraw
))));
2122 /* if the client is enlarging, then resize the client before the frame */
2123 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2124 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2126 /* move/resize the frame to match the request */
2128 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2129 moved
= resized
= TRUE
;
2131 if (moved
|| resized
)
2132 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2134 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2137 event
.type
= ConfigureNotify
;
2138 event
.xconfigure
.display
= ob_display
;
2139 event
.xconfigure
.event
= self
->window
;
2140 event
.xconfigure
.window
= self
->window
;
2142 /* root window real coords */
2143 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2145 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2147 event
.xconfigure
.width
= w
;
2148 event
.xconfigure
.height
= h
;
2149 event
.xconfigure
.border_width
= 0;
2150 event
.xconfigure
.above
= self
->frame
->plate
;
2151 event
.xconfigure
.override_redirect
= FALSE
;
2152 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2153 FALSE
, StructureNotifyMask
, &event
);
2157 /* if the client is shrinking, then resize the frame before the client */
2158 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2159 XResizeWindow(ob_display
, self
->window
, w
, h
);
2164 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2168 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2169 self
->fullscreen
== fs
) return; /* already done */
2171 self
->fullscreen
= fs
;
2172 client_change_state(self
); /* change the state hints on the client,
2173 and adjust out layer/stacking */
2177 self
->pre_fullscreen_area
= self
->area
;
2179 /* these are not actually used cuz client_configure will set them
2180 as appropriate when the window is fullscreened */
2185 if (self
->pre_fullscreen_area
.width
> 0 &&
2186 self
->pre_fullscreen_area
.height
> 0)
2188 x
= self
->pre_fullscreen_area
.x
;
2189 y
= self
->pre_fullscreen_area
.y
;
2190 w
= self
->pre_fullscreen_area
.width
;
2191 h
= self
->pre_fullscreen_area
.height
;
2192 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2194 /* pick some fallbacks... */
2195 a
= screen_area_monitor(self
->desktop
, 0);
2196 x
= a
->x
+ a
->width
/ 4;
2197 y
= a
->y
+ a
->height
/ 4;
2203 client_setup_decor_and_functions(self
);
2205 client_move_resize(self
, x
, y
, w
, h
);
2207 /* try focus us when we go into fullscreen mode */
2211 static void client_iconify_recursive(ObClient
*self
,
2212 gboolean iconic
, gboolean curdesk
)
2215 gboolean changed
= FALSE
;
2218 if (self
->iconic
!= iconic
) {
2219 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2222 self
->iconic
= iconic
;
2225 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2228 old
= self
->wmstate
;
2229 self
->wmstate
= IconicState
;
2230 if (old
!= self
->wmstate
)
2231 PROP_MSG(self
->window
, kde_wm_change_state
,
2232 self
->wmstate
, 1, 0, 0);
2234 /* update the focus lists.. iconic windows go to the bottom of
2235 the list, put the new iconic window at the 'top of the
2237 focus_order_to_top(self
);
2245 client_set_desktop(self
, screen_desktop
, FALSE
);
2247 old
= self
->wmstate
;
2248 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2249 if (old
!= self
->wmstate
)
2250 PROP_MSG(self
->window
, kde_wm_change_state
,
2251 self
->wmstate
, 1, 0, 0);
2253 /* this puts it after the current focused window */
2254 focus_order_remove(self
);
2255 focus_order_add_new(self
);
2257 /* this is here cuz with the VIDMODE extension, the viewport can
2258 change while a fullscreen window is iconic, and when it
2259 uniconifies, it would be nice if it did so to the new position
2261 client_reconfigure(self
);
2268 client_change_state(self
);
2269 client_showhide(self
);
2270 screen_update_areas();
2273 /* iconify all transients */
2274 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2275 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2279 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2281 /* move up the transient chain as far as possible first */
2282 self
= client_search_top_transient(self
);
2284 client_iconify_recursive(client_search_top_transient(self
),
2288 void client_maximize(ObClient
*self
, gboolean max
, gint dir
, gboolean savearea
)
2292 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2293 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2295 /* check if already done */
2297 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2298 if (dir
== 1 && self
->max_horz
) return;
2299 if (dir
== 2 && self
->max_vert
) return;
2301 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2302 if (dir
== 1 && !self
->max_horz
) return;
2303 if (dir
== 2 && !self
->max_vert
) return;
2306 /* we just tell it to configure in the same place and client_configure
2307 worries about filling the screen with the window */
2310 w
= self
->area
.width
;
2311 h
= self
->area
.height
;
2315 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2316 RECT_SET(self
->pre_max_area
,
2317 self
->area
.x
, self
->pre_max_area
.y
,
2318 self
->area
.width
, self
->pre_max_area
.height
);
2320 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2321 RECT_SET(self
->pre_max_area
,
2322 self
->pre_max_area
.x
, self
->area
.y
,
2323 self
->pre_max_area
.width
, self
->area
.height
);
2329 a
= screen_area_monitor(self
->desktop
, 0);
2330 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2331 if (self
->pre_max_area
.width
> 0) {
2332 x
= self
->pre_max_area
.x
;
2333 w
= self
->pre_max_area
.width
;
2335 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2336 0, self
->pre_max_area
.height
);
2338 /* pick some fallbacks... */
2339 x
= a
->x
+ a
->width
/ 4;
2343 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2344 if (self
->pre_max_area
.height
> 0) {
2345 y
= self
->pre_max_area
.y
;
2346 h
= self
->pre_max_area
.height
;
2348 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2349 self
->pre_max_area
.width
, 0);
2351 /* pick some fallbacks... */
2352 y
= a
->y
+ a
->height
/ 4;
2358 if (dir
== 0 || dir
== 1) /* horz */
2359 self
->max_horz
= max
;
2360 if (dir
== 0 || dir
== 2) /* vert */
2361 self
->max_vert
= max
;
2363 client_change_state(self
); /* change the state hints on the client */
2365 client_setup_decor_and_functions(self
);
2367 client_move_resize(self
, x
, y
, w
, h
);
2370 void client_shade(ObClient
*self
, gboolean shade
)
2372 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2373 shade
) || /* can't shade */
2374 self
->shaded
== shade
) return; /* already done */
2376 /* when we're iconic, don't change the wmstate */
2377 if (!self
->iconic
) {
2380 old
= self
->wmstate
;
2381 self
->wmstate
= shade
? IconicState
: NormalState
;
2382 if (old
!= self
->wmstate
)
2383 PROP_MSG(self
->window
, kde_wm_change_state
,
2384 self
->wmstate
, 1, 0, 0);
2387 self
->shaded
= shade
;
2388 client_change_state(self
);
2389 /* resize the frame to just the titlebar */
2390 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2393 void client_close(ObClient
*self
)
2397 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2399 /* in the case that the client provides no means to requesting that it
2400 close, we just kill it */
2401 if (!self
->delete_window
)
2405 XXX: itd be cool to do timeouts and shit here for killing the client's
2407 like... if the window is around after 5 seconds, then the close button
2408 turns a nice red, and if this function is called again, the client is
2412 ce
.xclient
.type
= ClientMessage
;
2413 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2414 ce
.xclient
.display
= ob_display
;
2415 ce
.xclient
.window
= self
->window
;
2416 ce
.xclient
.format
= 32;
2417 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2418 ce
.xclient
.data
.l
[1] = event_lasttime
;
2419 ce
.xclient
.data
.l
[2] = 0l;
2420 ce
.xclient
.data
.l
[3] = 0l;
2421 ce
.xclient
.data
.l
[4] = 0l;
2422 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2425 void client_kill(ObClient
*self
)
2427 XKillClient(ob_display
, self
->window
);
2430 void client_set_desktop_recursive(ObClient
*self
,
2431 guint target
, gboolean donthide
)
2436 if (target
!= self
->desktop
) {
2438 ob_debug("Setting desktop %u\n", target
+1);
2440 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2442 /* remove from the old desktop(s) */
2443 focus_order_remove(self
);
2445 old
= self
->desktop
;
2446 self
->desktop
= target
;
2447 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2448 /* the frame can display the current desktop state */
2449 frame_adjust_state(self
->frame
);
2450 /* 'move' the window to the new desktop */
2452 client_showhide(self
);
2453 /* raise if it was not already on the desktop */
2454 if (old
!= DESKTOP_ALL
)
2456 screen_update_areas();
2458 /* add to the new desktop(s) */
2459 if (config_focus_new
)
2460 focus_order_to_top(self
);
2462 focus_order_to_bottom(self
);
2465 /* move all transients */
2466 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2467 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2471 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2473 client_set_desktop_recursive(client_search_top_transient(self
),
2477 ObClient
*client_search_modal_child(ObClient
*self
)
2482 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2483 ObClient
*c
= it
->data
;
2484 if ((ret
= client_search_modal_child(c
))) return ret
;
2485 if (c
->modal
) return c
;
2490 gboolean
client_validate(ObClient
*self
)
2494 XSync(ob_display
, FALSE
); /* get all events on the server */
2496 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2497 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2498 XPutBackEvent(ob_display
, &e
);
2505 void client_set_wm_state(ObClient
*self
, glong state
)
2507 if (state
== self
->wmstate
) return; /* no change */
2511 client_iconify(self
, TRUE
, TRUE
);
2514 client_iconify(self
, FALSE
, TRUE
);
2519 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2521 gboolean shaded
= self
->shaded
;
2522 gboolean fullscreen
= self
->fullscreen
;
2523 gboolean undecorated
= self
->undecorated
;
2524 gboolean max_horz
= self
->max_horz
;
2525 gboolean max_vert
= self
->max_vert
;
2526 gboolean modal
= self
->modal
;
2527 gboolean iconic
= self
->iconic
;
2530 if (!(action
== prop_atoms
.net_wm_state_add
||
2531 action
== prop_atoms
.net_wm_state_remove
||
2532 action
== prop_atoms
.net_wm_state_toggle
))
2533 /* an invalid action was passed to the client message, ignore it */
2536 for (i
= 0; i
< 2; ++i
) {
2537 Atom state
= i
== 0 ? data1
: data2
;
2539 if (!state
) continue;
2541 /* if toggling, then pick whether we're adding or removing */
2542 if (action
== prop_atoms
.net_wm_state_toggle
) {
2543 if (state
== prop_atoms
.net_wm_state_modal
)
2544 action
= modal
? prop_atoms
.net_wm_state_remove
:
2545 prop_atoms
.net_wm_state_add
;
2546 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2547 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2548 prop_atoms
.net_wm_state_add
;
2549 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2550 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2551 prop_atoms
.net_wm_state_add
;
2552 else if (state
== prop_atoms
.net_wm_state_shaded
)
2553 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2554 prop_atoms
.net_wm_state_add
;
2555 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2556 action
= self
->skip_taskbar
?
2557 prop_atoms
.net_wm_state_remove
:
2558 prop_atoms
.net_wm_state_add
;
2559 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2560 action
= self
->skip_pager
?
2561 prop_atoms
.net_wm_state_remove
:
2562 prop_atoms
.net_wm_state_add
;
2563 else if (state
== prop_atoms
.net_wm_state_hidden
)
2564 action
= self
->iconic
?
2565 prop_atoms
.net_wm_state_remove
:
2566 prop_atoms
.net_wm_state_add
;
2567 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2568 action
= fullscreen
?
2569 prop_atoms
.net_wm_state_remove
:
2570 prop_atoms
.net_wm_state_add
;
2571 else if (state
== prop_atoms
.net_wm_state_above
)
2572 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2573 prop_atoms
.net_wm_state_add
;
2574 else if (state
== prop_atoms
.net_wm_state_below
)
2575 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2576 prop_atoms
.net_wm_state_add
;
2577 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2578 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2579 prop_atoms
.net_wm_state_add
;
2582 if (action
== prop_atoms
.net_wm_state_add
) {
2583 if (state
== prop_atoms
.net_wm_state_modal
) {
2585 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2587 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2589 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2591 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2592 self
->skip_taskbar
= TRUE
;
2593 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2594 self
->skip_pager
= TRUE
;
2595 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2597 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2599 } else if (state
== prop_atoms
.net_wm_state_above
) {
2601 self
->below
= FALSE
;
2602 } else if (state
== prop_atoms
.net_wm_state_below
) {
2603 self
->above
= FALSE
;
2605 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2609 } else { /* action == prop_atoms.net_wm_state_remove */
2610 if (state
== prop_atoms
.net_wm_state_modal
) {
2612 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2614 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2616 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2618 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2619 self
->skip_taskbar
= FALSE
;
2620 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2621 self
->skip_pager
= FALSE
;
2622 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
2624 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2626 } else if (state
== prop_atoms
.net_wm_state_above
) {
2627 self
->above
= FALSE
;
2628 } else if (state
== prop_atoms
.net_wm_state_below
) {
2629 self
->below
= FALSE
;
2630 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2631 undecorated
= FALSE
;
2635 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2636 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2638 if (max_horz
== max_vert
) { /* both going the same way */
2639 client_maximize(self
, max_horz
, 0, TRUE
);
2641 client_maximize(self
, max_horz
, 1, TRUE
);
2642 client_maximize(self
, max_vert
, 2, TRUE
);
2646 if (max_horz
!= self
->max_horz
)
2647 client_maximize(self
, max_horz
, 1, TRUE
);
2649 client_maximize(self
, max_vert
, 2, TRUE
);
2652 /* change fullscreen state before shading, as it will affect if the window
2654 if (fullscreen
!= self
->fullscreen
)
2655 client_fullscreen(self
, fullscreen
, TRUE
);
2656 if (shaded
!= self
->shaded
)
2657 client_shade(self
, shaded
);
2658 if (undecorated
!= self
->undecorated
)
2659 client_set_undecorated(self
, undecorated
);
2660 if (modal
!= self
->modal
) {
2661 self
->modal
= modal
;
2662 /* when a window changes modality, then its stacking order with its
2663 transients needs to change */
2666 if (iconic
!= self
->iconic
)
2667 client_iconify(self
, iconic
, FALSE
);
2669 client_calc_layer(self
);
2670 client_change_state(self
); /* change the hint to reflect these changes */
2673 ObClient
*client_focus_target(ObClient
*self
)
2677 /* if we have a modal child, then focus it, not us */
2678 child
= client_search_modal_child(client_search_top_transient(self
));
2679 if (child
) return child
;
2683 gboolean
client_can_focus(ObClient
*self
)
2687 /* choose the correct target */
2688 self
= client_focus_target(self
);
2690 if (!self
->frame
->visible
)
2693 if (!(self
->can_focus
|| self
->focus_notify
))
2696 /* do a check to see if the window has already been unmapped or destroyed
2697 do this intelligently while watching out for unmaps we've generated
2698 (ignore_unmaps > 0) */
2699 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2700 DestroyNotify
, &ev
)) {
2701 XPutBackEvent(ob_display
, &ev
);
2704 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2705 UnmapNotify
, &ev
)) {
2706 if (self
->ignore_unmaps
) {
2707 self
->ignore_unmaps
--;
2709 XPutBackEvent(ob_display
, &ev
);
2717 gboolean
client_focus(ObClient
*self
)
2719 /* choose the correct target */
2720 self
= client_focus_target(self
);
2722 if (!client_can_focus(self
)) {
2723 if (!self
->frame
->visible
) {
2724 /* update the focus lists */
2725 focus_order_to_top(self
);
2730 if (self
->can_focus
) {
2731 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2732 I choose to use it always, hopefully to find errors quicker, if any
2733 are left. (I hate X. I hate focus events.)
2735 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2736 #799. So now it is RevertToNone again.
2738 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2742 if (self
->focus_notify
) {
2744 ce
.xclient
.type
= ClientMessage
;
2745 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2746 ce
.xclient
.display
= ob_display
;
2747 ce
.xclient
.window
= self
->window
;
2748 ce
.xclient
.format
= 32;
2749 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2750 ce
.xclient
.data
.l
[1] = event_lasttime
;
2751 ce
.xclient
.data
.l
[2] = 0l;
2752 ce
.xclient
.data
.l
[3] = 0l;
2753 ce
.xclient
.data
.l
[4] = 0l;
2754 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2758 ob_debug("%sively focusing %lx at %d\n",
2759 (self
->can_focus
? "act" : "pass"),
2760 self
->window
, (gint
) event_lasttime
);
2763 /* Cause the FocusIn to come back to us. Important for desktop switches,
2764 since otherwise we'll have no FocusIn on the queue and send it off to
2765 the focus_backup. */
2766 XSync(ob_display
, FALSE
);
2770 void client_unfocus(ObClient
*self
)
2772 if (focus_client
== self
) {
2774 ob_debug("client_unfocus for %lx\n", self
->window
);
2776 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2780 void client_activate(ObClient
*self
, gboolean here
)
2782 if (client_normal(self
) && screen_showing_desktop
)
2783 screen_show_desktop(FALSE
);
2785 client_iconify(self
, FALSE
, here
);
2786 if (self
->desktop
!= DESKTOP_ALL
&&
2787 self
->desktop
!= screen_desktop
) {
2789 client_set_desktop(self
, screen_desktop
, FALSE
);
2791 screen_set_desktop(self
->desktop
);
2792 } else if (!self
->frame
->visible
)
2793 /* if its not visible for other reasons, then don't mess
2797 client_shade(self
, FALSE
);
2801 /* we do this an action here. this is rather important. this is because
2802 we want the results from the focus change to take place BEFORE we go
2803 about raising the window. when a fullscreen window loses focus, we need
2804 this or else the raise wont be able to raise above the to-lose-focus
2805 fullscreen window. */
2809 void client_raise(ObClient
*self
)
2811 action_run_string("Raise", self
);
2814 void client_lower(ObClient
*self
)
2816 action_run_string("Lower", self
);
2819 gboolean
client_focused(ObClient
*self
)
2821 return self
== focus_client
;
2824 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
2827 /* si is the smallest image >= req */
2828 /* li is the largest image < req */
2829 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2831 if (!self
->nicons
) {
2832 ObClientIcon
*parent
= NULL
;
2834 if (self
->transient_for
) {
2835 if (self
->transient_for
!= OB_TRAN_GROUP
)
2836 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2839 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2840 ObClient
*c
= it
->data
;
2841 if (c
!= self
&& !c
->transient_for
) {
2842 if ((parent
= client_icon_recursive(c
, w
, h
)))
2852 for (i
= 0; i
< self
->nicons
; ++i
) {
2853 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2854 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2858 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2863 if (largest
== 0) /* didnt find one smaller than the requested size */
2864 return &self
->icons
[si
];
2865 return &self
->icons
[li
];
2868 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
2871 static ObClientIcon deficon
;
2873 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2874 deficon
.width
= deficon
.height
= 48;
2875 deficon
.data
= ob_rr_theme
->def_win_icon
;
2881 /* this be mostly ripped from fvwm */
2882 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2884 gint my_cx
, my_cy
, his_cx
, his_cy
;
2887 gint score
, best_score
;
2888 ObClient
*best_client
, *cur
;
2894 /* first, find the centre coords of the currently focused window */
2895 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2896 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2901 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
2904 /* the currently selected window isn't interesting */
2907 if (!client_normal(cur
))
2909 /* using c->desktop instead of screen_desktop doesn't work if the
2910 * current window was omnipresent, hope this doesn't have any other
2912 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2916 if(client_focus_target(cur
) == cur
&&
2917 !(cur
->can_focus
|| cur
->focus_notify
))
2920 /* find the centre coords of this window, from the
2921 * currently focused window's point of view */
2922 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2923 + cur
->frame
->area
.width
/ 2;
2924 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2925 + cur
->frame
->area
.height
/ 2;
2927 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2928 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2930 /* Rotate the diagonals 45 degrees counterclockwise.
2931 * To do this, multiply the matrix /+h +h\ with the
2932 * vector (x y). \-h +h/
2933 * h = sqrt(0.5). We can set h := 1 since absolute
2934 * distance doesn't matter here. */
2935 tx
= his_cx
+ his_cy
;
2936 his_cy
= -his_cx
+ his_cy
;
2941 case OB_DIRECTION_NORTH
:
2942 case OB_DIRECTION_SOUTH
:
2943 case OB_DIRECTION_NORTHEAST
:
2944 case OB_DIRECTION_SOUTHWEST
:
2945 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2946 distance
= ((dir
== OB_DIRECTION_NORTH
||
2947 dir
== OB_DIRECTION_NORTHEAST
) ?
2950 case OB_DIRECTION_EAST
:
2951 case OB_DIRECTION_WEST
:
2952 case OB_DIRECTION_SOUTHEAST
:
2953 case OB_DIRECTION_NORTHWEST
:
2954 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2955 distance
= ((dir
== OB_DIRECTION_WEST
||
2956 dir
== OB_DIRECTION_NORTHWEST
) ?
2961 /* the target must be in the requested direction */
2965 /* Calculate score for this window. The smaller the better. */
2966 score
= distance
+ offset
;
2968 /* windows more than 45 degrees off the direction are
2969 * heavily penalized and will only be chosen if nothing
2970 * else within a million pixels */
2971 if(offset
> distance
)
2974 if(best_score
== -1 || score
< best_score
)
2982 void client_set_layer(ObClient
*self
, gint layer
)
2986 self
->above
= FALSE
;
2987 } else if (layer
== 0) {
2988 self
->below
= self
->above
= FALSE
;
2990 self
->below
= FALSE
;
2993 client_calc_layer(self
);
2994 client_change_state(self
); /* reflect this in the state hints */
2997 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
2999 if (self
->undecorated
!= undecorated
) {
3000 self
->undecorated
= undecorated
;
3001 client_setup_decor_and_functions(self
);
3002 client_change_state(self
); /* reflect this in the state hints */
3006 /* Determines which physical monitor a client is on by calculating the
3007 area of the part of the client on each monitor. The number of the
3008 monitor containing the greatest area of the client is returned.*/
3009 guint
client_monitor(ObClient
*self
)
3015 for (i
= 0; i
< screen_num_monitors
; ++i
) {
3016 Rect
*area
= screen_physical_area_monitor(i
);
3017 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
)) {
3021 RECT_SET_INTERSECTION(r
, *area
, self
->frame
->area
);
3022 v
= r
.width
* r
.height
;
3033 ObClient
*client_search_top_transient(ObClient
*self
)
3035 /* move up the transient chain as far as possible */
3036 if (self
->transient_for
) {
3037 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3038 return client_search_top_transient(self
->transient_for
);
3042 g_assert(self
->group
);
3044 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3045 ObClient
*c
= it
->data
;
3047 /* checking transient_for prevents infinate loops! */
3048 if (c
!= self
&& !c
->transient_for
)
3059 ObClient
*client_search_focus_parent(ObClient
*self
)
3061 if (self
->transient_for
) {
3062 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3063 if (client_focused(self
->transient_for
))
3064 return self
->transient_for
;
3068 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3069 ObClient
*c
= it
->data
;
3071 /* checking transient_for prevents infinate loops! */
3072 if (c
!= self
&& !c
->transient_for
)
3073 if (client_focused(c
))
3082 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3084 if (self
->transient_for
) {
3085 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3086 if (self
->transient_for
== search
)
3091 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3092 ObClient
*c
= it
->data
;
3094 /* checking transient_for prevents infinate loops! */
3095 if (c
!= self
&& !c
->transient_for
)
3105 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3109 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3110 if (sit
->data
== search
)
3112 if (client_search_transient(sit
->data
, search
))
3118 void client_update_sm_client_id(ObClient
*self
)
3120 g_free(self
->sm_client_id
);
3121 self
->sm_client_id
= NULL
;
3123 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3125 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3126 &self
->sm_client_id
);
3129 /* finds the nearest edge in the given direction from the current client
3130 * note to self: the edge is the -frame- edge (the actual one), not the
3133 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3135 gint dest
, monitor_dest
;
3136 gint my_edge_start
, my_edge_end
, my_offset
;
3143 a
= screen_area(c
->desktop
);
3144 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3147 case OB_DIRECTION_NORTH
:
3148 my_edge_start
= c
->frame
->area
.x
;
3149 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3150 my_offset
= c
->frame
->area
.y
;
3152 /* default: top of screen */
3154 monitor_dest
= monitor
->y
;
3155 /* if the monitor edge comes before the screen edge, */
3156 /* use that as the destination instead. (For xinerama) */
3157 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3158 dest
= monitor_dest
;
3160 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3161 gint his_edge_start
, his_edge_end
, his_offset
;
3162 ObClient
*cur
= it
->data
;
3166 if(!client_normal(cur
))
3168 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3172 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3175 his_edge_start
= cur
->frame
->area
.x
;
3176 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3177 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3179 if(his_offset
+ 1 > my_offset
)
3182 if(his_offset
< dest
)
3185 if(his_edge_start
>= my_edge_start
&&
3186 his_edge_start
<= my_edge_end
)
3189 if(my_edge_start
>= his_edge_start
&&
3190 my_edge_start
<= his_edge_end
)
3195 case OB_DIRECTION_SOUTH
:
3196 my_edge_start
= c
->frame
->area
.x
;
3197 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3198 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3200 /* default: bottom of screen */
3201 dest
= a
->y
+ a
->height
;
3202 monitor_dest
= monitor
->y
+ monitor
->height
;
3203 /* if the monitor edge comes before the screen edge, */
3204 /* use that as the destination instead. (For xinerama) */
3205 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3206 dest
= monitor_dest
;
3208 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3209 gint his_edge_start
, his_edge_end
, his_offset
;
3210 ObClient
*cur
= it
->data
;
3214 if(!client_normal(cur
))
3216 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3220 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3223 his_edge_start
= cur
->frame
->area
.x
;
3224 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3225 his_offset
= cur
->frame
->area
.y
;
3228 if(his_offset
- 1 < my_offset
)
3231 if(his_offset
> dest
)
3234 if(his_edge_start
>= my_edge_start
&&
3235 his_edge_start
<= my_edge_end
)
3238 if(my_edge_start
>= his_edge_start
&&
3239 my_edge_start
<= his_edge_end
)
3244 case OB_DIRECTION_WEST
:
3245 my_edge_start
= c
->frame
->area
.y
;
3246 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3247 my_offset
= c
->frame
->area
.x
;
3249 /* default: leftmost egde of screen */
3251 monitor_dest
= monitor
->x
;
3252 /* if the monitor edge comes before the screen edge, */
3253 /* use that as the destination instead. (For xinerama) */
3254 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3255 dest
= monitor_dest
;
3257 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3258 gint his_edge_start
, his_edge_end
, his_offset
;
3259 ObClient
*cur
= it
->data
;
3263 if(!client_normal(cur
))
3265 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3269 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3272 his_edge_start
= cur
->frame
->area
.y
;
3273 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3274 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3276 if(his_offset
+ 1 > my_offset
)
3279 if(his_offset
< dest
)
3282 if(his_edge_start
>= my_edge_start
&&
3283 his_edge_start
<= my_edge_end
)
3286 if(my_edge_start
>= his_edge_start
&&
3287 my_edge_start
<= his_edge_end
)
3293 case OB_DIRECTION_EAST
:
3294 my_edge_start
= c
->frame
->area
.y
;
3295 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3296 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3298 /* default: rightmost edge of screen */
3299 dest
= a
->x
+ a
->width
;
3300 monitor_dest
= monitor
->x
+ monitor
->width
;
3301 /* if the monitor edge comes before the screen edge, */
3302 /* use that as the destination instead. (For xinerama) */
3303 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3304 dest
= monitor_dest
;
3306 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3307 gint his_edge_start
, his_edge_end
, his_offset
;
3308 ObClient
*cur
= it
->data
;
3312 if(!client_normal(cur
))
3314 if(screen_desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3318 if(cur
->layer
< c
->layer
&& !config_resist_layers_below
)
3321 his_edge_start
= cur
->frame
->area
.y
;
3322 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3323 his_offset
= cur
->frame
->area
.x
;
3325 if(his_offset
- 1 < my_offset
)
3328 if(his_offset
> dest
)
3331 if(his_edge_start
>= my_edge_start
&&
3332 his_edge_start
<= my_edge_end
)
3335 if(my_edge_start
>= his_edge_start
&&
3336 my_edge_start
<= his_edge_end
)
3341 case OB_DIRECTION_NORTHEAST
:
3342 case OB_DIRECTION_SOUTHEAST
:
3343 case OB_DIRECTION_NORTHWEST
:
3344 case OB_DIRECTION_SOUTHWEST
:
3345 /* not implemented */
3347 g_assert_not_reached();
3348 dest
= 0; /* suppress warning */
3353 ObClient
* client_under_pointer()
3357 ObClient
*ret
= NULL
;
3359 if (screen_pointer_pos(&x
, &y
)) {
3360 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3361 if (WINDOW_IS_CLIENT(it
->data
)) {
3362 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3363 if (c
->frame
->visible
&&
3364 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3374 gboolean
client_has_group_siblings(ObClient
*self
)
3376 return self
->group
&& self
->group
->members
->next
;