1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
21 #include "startupnotify.h"
25 #include "moveresize.h"
28 #include "extensions.h"
38 #include "menuframe.h"
41 #include "render/render.h"
44 #include <X11/Xutil.h>
46 /*! The event mask to grab on client windows */
47 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
50 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
55 ObClientDestructor func
;
59 GList
*client_list
= NULL
;
60 GSList
*client_destructors
= NULL
;
62 static void client_get_all(ObClient
*self
);
63 static void client_toggle_border(ObClient
*self
, gboolean show
);
64 static void client_get_startup_id(ObClient
*self
);
65 static void client_get_area(ObClient
*self
);
66 static void client_get_desktop(ObClient
*self
);
67 static void client_get_state(ObClient
*self
);
68 static void client_get_shaped(ObClient
*self
);
69 static void client_get_mwm_hints(ObClient
*self
);
70 static void client_get_gravity(ObClient
*self
);
71 static void client_showhide(ObClient
*self
);
72 static void client_change_allowed_actions(ObClient
*self
);
73 static void client_change_state(ObClient
*self
);
74 static void client_apply_startup_state(ObClient
*self
);
75 static void client_restore_session_state(ObClient
*self
);
76 static void client_restore_session_stacking(ObClient
*self
);
77 static void client_urgent_notify(ObClient
*self
);
79 void client_startup(gboolean reconfig
)
86 void client_shutdown(gboolean reconfig
)
90 void client_add_destructor(ObClientDestructor func
, gpointer data
)
92 Destructor
*d
= g_new(Destructor
, 1);
95 client_destructors
= g_slist_prepend(client_destructors
, d
);
98 void client_remove_destructor(ObClientDestructor func
)
102 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
103 Destructor
*d
= it
->data
;
104 if (d
->func
== func
) {
106 client_destructors
= g_slist_delete_link(client_destructors
, it
);
112 void client_set_list()
114 Window
*windows
, *win_it
;
116 guint size
= g_list_length(client_list
);
118 /* create an array of the window ids */
120 windows
= g_new(Window
, size
);
122 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
123 *win_it
= ((ObClient
*)it
->data
)->window
;
127 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
128 net_client_list
, window
, (guint32
*)windows
, size
);
137 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
141 for (it = self->transients; it; it = g_slist_next(it)) {
142 if (!func(it->data, data)) return;
143 client_foreach_transient(it->data, func, data);
147 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
149 if (self->transient_for) {
150 if (self->transient_for != OB_TRAN_GROUP) {
151 if (!func(self->transient_for, data)) return;
152 client_foreach_ancestor(self->transient_for, func, data);
156 for (it = self->group->members; it; it = g_slist_next(it))
157 if (it->data != self &&
158 !((ObClient*)it->data)->transient_for) {
159 if (!func(it->data, data)) return;
160 client_foreach_ancestor(it->data, func, data);
167 void client_manage_all()
172 XWindowAttributes attrib
;
174 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
175 &w
, &w
, &children
, &nchild
);
177 /* remove all icon windows from the list */
178 for (i
= 0; i
< nchild
; i
++) {
179 if (children
[i
] == None
) continue;
180 wmhints
= XGetWMHints(ob_display
, children
[i
]);
182 if ((wmhints
->flags
& IconWindowHint
) &&
183 (wmhints
->icon_window
!= children
[i
]))
184 for (j
= 0; j
< nchild
; j
++)
185 if (children
[j
] == wmhints
->icon_window
) {
193 for (i
= 0; i
< nchild
; ++i
) {
194 if (children
[i
] == None
)
196 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
197 if (attrib
.override_redirect
) continue;
199 if (attrib
.map_state
!= IsUnmapped
)
200 client_manage(children
[i
]);
206 void client_manage(Window window
)
210 XWindowAttributes attrib
;
211 XSetWindowAttributes attrib_set
;
213 gboolean activate
= FALSE
;
217 /* check if it has already been unmapped by the time we started mapping
218 the grab does a sync so we don't have to here */
219 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
220 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
221 XPutBackEvent(ob_display
, &e
);
224 return; /* don't manage it */
227 /* make sure it isn't an override-redirect window */
228 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
229 attrib
.override_redirect
) {
231 return; /* don't manage it */
234 /* is the window a docking app */
235 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
236 if ((wmhint
->flags
& StateHint
) &&
237 wmhint
->initial_state
== WithdrawnState
) {
238 dock_add(window
, wmhint
);
246 ob_debug("Managing window: %lx\n", window
);
248 /* choose the events we want to receive on the CLIENT window */
249 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
250 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
251 XChangeWindowAttributes(ob_display
, window
,
252 CWEventMask
|CWDontPropagate
, &attrib_set
);
255 /* create the ObClient struct, and populate it from the hints on the
257 self
= g_new0(ObClient
, 1);
258 self
->obwin
.type
= Window_Client
;
259 self
->window
= window
;
261 /* non-zero defaults */
262 self
->title_count
= 1;
263 self
->wmstate
= NormalState
;
265 self
->desktop
= screen_num_desktops
; /* always an invalid value */
267 client_get_all(self
);
268 client_restore_session_state(self
);
270 sn_app_started(self
->class);
272 /* update the focus lists, do this before the call to change_state or
273 it can end up in the list twice! */
274 focus_order_add_new(self
);
276 client_change_state(self
);
278 /* remove the client's border (and adjust re gravity) */
279 client_toggle_border(self
, FALSE
);
281 /* specify that if we exit, the window should not be destroyed and should
282 be reparented back to root automatically */
283 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
285 /* create the decoration frame for the client window */
286 self
->frame
= frame_new();
288 frame_grab_client(self
->frame
, self
);
292 client_apply_startup_state(self
);
294 stacking_add(CLIENT_AS_WINDOW(self
));
295 client_restore_session_stacking(self
);
297 /* focus the new window? */
298 if (ob_state() != OB_STATE_STARTING
&&
299 (config_focus_new
|| client_search_focus_parent(self
)) &&
300 /* note the check against Type_Normal/Dialog, not client_normal(self),
301 which would also include other types. in this case we want more
302 strict rules for focus */
303 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
304 self
->type
== OB_CLIENT_TYPE_DIALOG
))
308 if (self
->desktop
!= screen_desktop
) {
309 /* activate the window */
312 gboolean group_foc
= FALSE
;
317 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
319 if (client_focused(it
->data
))
327 (!self
->transient_for
&& (!self
->group
||
328 !self
->group
->members
->next
))) ||
329 client_search_focus_tree_full(self
) ||
331 !client_normal(focus_client
))
333 /* activate the window */
340 if (ob_state() == OB_STATE_RUNNING
) {
341 gint x
= self
->area
.x
, ox
= x
;
342 gint y
= self
->area
.y
, oy
= y
;
344 place_client(self
, &x
, &y
);
346 /* make sure the window is visible */
347 client_find_onscreen(self
, &x
, &y
,
348 self
->frame
->area
.width
,
349 self
->frame
->area
.height
,
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_normal(self
) && !self
->session
);
356 if (x
!= ox
|| y
!= oy
)
357 client_move(self
, x
, y
);
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 keyboard_grab_for_client(self
, TRUE
);
395 mouse_grab_for_client(self
, TRUE
);
397 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
400 void client_unmanage_all()
402 while (client_list
!= NULL
)
403 client_unmanage(client_list
->data
);
406 void client_unmanage(ObClient
*self
)
411 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
413 g_assert(self
!= NULL
);
415 keyboard_grab_for_client(self
, FALSE
);
416 mouse_grab_for_client(self
, FALSE
);
418 /* potentially fix focusLast */
419 if (config_focus_last
)
420 grab_pointer(TRUE
, OB_CURSOR_NONE
);
422 /* remove the window from our save set */
423 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
425 /* we dont want events no more */
426 XSelectInput(ob_display
, self
->window
, NoEventMask
);
428 frame_hide(self
->frame
);
430 client_list
= g_list_remove(client_list
, self
);
431 stacking_remove(self
);
432 g_hash_table_remove(window_map
, &self
->window
);
434 /* update the focus lists */
435 focus_order_remove(self
);
437 /* once the client is out of the list, update the struts to remove it's
439 screen_update_areas();
441 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
442 Destructor
*d
= it
->data
;
443 d
->func(self
, d
->data
);
446 if (focus_client
== self
) {
449 /* focus the last focused window on the desktop, and ignore enter
450 events from the unmap so it doesnt mess with the focus */
451 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
452 /* remove these flags so we don't end up getting focused in the
454 self
->can_focus
= FALSE
;
455 self
->focus_notify
= FALSE
;
457 client_unfocus(self
);
460 /* tell our parent(s) that we're gone */
461 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
464 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
465 if (it
->data
!= self
)
466 ((ObClient
*)it
->data
)->transients
=
467 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
468 } else if (self
->transient_for
) { /* transient of window */
469 self
->transient_for
->transients
=
470 g_slist_remove(self
->transient_for
->transients
, self
);
473 /* tell our transients that we're gone */
474 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
475 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
476 ((ObClient
*)it
->data
)->transient_for
= NULL
;
477 client_calc_layer(it
->data
);
481 /* remove from its group */
483 group_remove(self
->group
, self
);
487 /* give the client its border back */
488 client_toggle_border(self
, TRUE
);
490 /* reparent the window out of the frame, and free the frame */
491 frame_release_client(self
->frame
, self
);
494 if (ob_state() != OB_STATE_EXITING
) {
495 /* these values should not be persisted across a window
497 PROP_ERASE(self
->window
, net_wm_desktop
);
498 PROP_ERASE(self
->window
, net_wm_state
);
499 PROP_ERASE(self
->window
, wm_state
);
501 /* if we're left in an unmapped state, the client wont be mapped. this
502 is bad, since we will no longer be managing the window on restart */
503 XMapWindow(ob_display
, self
->window
);
507 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
509 /* free all data allocated in the client struct */
510 g_slist_free(self
->transients
);
511 for (j
= 0; j
< self
->nicons
; ++j
)
512 g_free(self
->icons
[j
].data
);
513 if (self
->nicons
> 0)
516 g_free(self
->icon_title
);
520 g_free(self
->sm_client_id
);
523 /* update the list hints */
526 if (config_focus_last
)
527 grab_pointer(FALSE
, OB_CURSOR_NONE
);
530 static void client_urgent_notify(ObClient
*self
)
533 frame_flash_start(self
->frame
);
535 frame_flash_stop(self
->frame
);
538 static void client_restore_session_state(ObClient
*self
)
542 if (!(it
= session_state_find(self
)))
545 self
->session
= it
->data
;
547 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
548 self
->positioned
= TRUE
;
549 if (self
->session
->w
> 0)
550 self
->area
.width
= self
->session
->w
;
551 if (self
->session
->h
> 0)
552 self
->area
.height
= self
->session
->h
;
553 XResizeWindow(ob_display
, self
->window
,
554 self
->area
.width
, self
->area
.height
);
556 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
557 self
->session
->desktop
:
558 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
559 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
561 self
->shaded
= self
->session
->shaded
;
562 self
->iconic
= self
->session
->iconic
;
563 self
->skip_pager
= self
->session
->skip_pager
;
564 self
->skip_taskbar
= self
->session
->skip_taskbar
;
565 self
->fullscreen
= self
->session
->fullscreen
;
566 self
->above
= self
->session
->above
;
567 self
->below
= self
->session
->below
;
568 self
->max_horz
= self
->session
->max_horz
;
569 self
->max_vert
= self
->session
->max_vert
;
572 static void client_restore_session_stacking(ObClient
*self
)
576 if (!self
->session
) return;
578 it
= g_list_find(session_saved_state
, self
->session
);
579 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
582 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
583 if (session_state_cmp(it
->data
, cit
->data
))
586 client_calc_layer(self
);
587 stacking_below(CLIENT_AS_WINDOW(self
),
588 CLIENT_AS_WINDOW(cit
->data
));
594 void client_move_onscreen(ObClient
*self
, gboolean rude
)
596 gint x
= self
->area
.x
;
597 gint y
= self
->area
.y
;
598 if (client_find_onscreen(self
, &x
, &y
,
599 self
->frame
->area
.width
,
600 self
->frame
->area
.height
, rude
)) {
601 client_move(self
, x
, y
);
605 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
609 gint ox
= *x
, oy
= *y
;
611 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
614 /* XXX watch for xinerama dead areas */
616 a
= screen_area(self
->desktop
);
617 if (client_normal(self
)) {
618 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
619 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
620 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
621 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
622 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
624 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
629 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
630 Java can suck it too. */
632 /* dont let windows map/move into the strut unless they
633 are bigger than the available area */
635 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
636 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
637 *x
= a
->x
+ a
->width
- w
;
639 if (h
<= a
->height
) {
640 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
641 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
642 *y
= a
->y
+ a
->height
- h
;
646 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
649 return ox
!= *x
|| oy
!= *y
;
652 static void client_toggle_border(ObClient
*self
, gboolean show
)
654 /* adjust our idea of where the client is, based on its border. When the
655 border is removed, the client should now be considered to be in a
657 when re-adding the border to the client, the same operation needs to be
659 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
660 gint x
= oldx
, y
= oldy
;
661 switch(self
->gravity
) {
663 case NorthWestGravity
:
665 case SouthWestGravity
:
667 case NorthEastGravity
:
669 case SouthEastGravity
:
670 if (show
) x
-= self
->border_width
* 2;
671 else x
+= self
->border_width
* 2;
678 if (show
) x
-= self
->border_width
;
679 else x
+= self
->border_width
;
682 switch(self
->gravity
) {
684 case NorthWestGravity
:
686 case NorthEastGravity
:
688 case SouthWestGravity
:
690 case SouthEastGravity
:
691 if (show
) y
-= self
->border_width
* 2;
692 else y
+= self
->border_width
* 2;
699 if (show
) y
-= self
->border_width
;
700 else y
+= self
->border_width
;
707 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
709 /* move the client so it is back it the right spot _with_ its
711 if (x
!= oldx
|| y
!= oldy
)
712 XMoveWindow(ob_display
, self
->window
, x
, y
);
714 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
718 static void client_get_all(ObClient
*self
)
720 client_get_area(self
);
721 client_update_transient_for(self
);
722 client_update_wmhints(self
);
723 client_get_startup_id(self
);
724 client_get_desktop(self
);
725 client_get_shaped(self
);
727 client_get_mwm_hints(self
);
728 client_get_type(self
);/* this can change the mwmhints for special cases */
730 /* The transient hint is used to pick a type, but the type can also affect
731 transiency (dialogs are always made transients). This is Havoc's idea,
732 but it is needed to make some apps work right (eg tsclient). */
733 client_update_transient_for(self
);
735 client_get_state(self
);
738 /* a couple type-based defaults for new windows */
740 /* this makes sure that these windows appear on all desktops */
741 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
742 self
->desktop
= DESKTOP_ALL
;
745 client_update_protocols(self
);
747 client_get_gravity(self
); /* get the attribute gravity */
748 client_update_normal_hints(self
); /* this may override the attribute
751 /* got the type, the mwmhints, the protocols, and the normal hints
752 (min/max sizes), so we're ready to set up the decorations/functions */
753 client_setup_decor_and_functions(self
);
755 client_update_title(self
);
756 client_update_class(self
);
757 client_update_sm_client_id(self
);
758 client_update_strut(self
);
759 client_update_icons(self
);
762 static void client_get_startup_id(ObClient
*self
)
764 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
766 PROP_GETS(self
->group
->leader
,
767 net_startup_id
, utf8
, &self
->startup_id
);
770 static void client_get_area(ObClient
*self
)
772 XWindowAttributes wattrib
;
775 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
776 g_assert(ret
!= BadWindow
);
778 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
779 self
->border_width
= wattrib
.border_width
;
782 static void client_get_desktop(ObClient
*self
)
784 guint32 d
= screen_num_desktops
; /* an always-invalid value */
786 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
787 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
788 self
->desktop
= screen_num_desktops
- 1;
792 gboolean trdesk
= FALSE
;
794 if (self
->transient_for
) {
795 if (self
->transient_for
!= OB_TRAN_GROUP
) {
796 self
->desktop
= self
->transient_for
->desktop
;
801 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
802 if (it
->data
!= self
&&
803 !((ObClient
*)it
->data
)->transient_for
) {
804 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
811 /* try get from the startup-notification protocol */
812 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
813 if (self
->desktop
>= screen_num_desktops
&&
814 self
->desktop
!= DESKTOP_ALL
)
815 self
->desktop
= screen_num_desktops
- 1;
817 /* defaults to the current desktop */
818 self
->desktop
= screen_desktop
;
821 if (self
->desktop
!= d
) {
822 /* set the desktop hint, to make sure that it always exists */
823 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
827 static void client_get_state(ObClient
*self
)
832 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
834 for (i
= 0; i
< num
; ++i
) {
835 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
837 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
839 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
841 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
842 self
->skip_taskbar
= TRUE
;
843 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
844 self
->skip_pager
= TRUE
;
845 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
846 self
->fullscreen
= TRUE
;
847 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
848 self
->max_vert
= TRUE
;
849 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
850 self
->max_horz
= TRUE
;
851 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
853 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
855 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
856 self
->undecorated
= TRUE
;
862 if (!(self
->above
|| self
->below
)) {
864 /* apply stuff from the group */
868 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
869 ObClient
*c
= it
->data
;
870 if (c
!= self
&& !client_search_transient(self
, c
) &&
871 client_normal(self
) && client_normal(c
))
874 (c
->above
? 1 : (c
->below
? -1 : 0)));
888 g_assert_not_reached();
895 static void client_get_shaped(ObClient
*self
)
897 self
->shaped
= FALSE
;
899 if (extensions_shape
) {
904 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
906 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
907 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
909 self
->shaped
= (s
!= 0);
914 void client_update_transient_for(ObClient
*self
)
917 ObClient
*target
= NULL
;
919 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
920 self
->transient
= TRUE
;
921 if (t
!= self
->window
) { /* cant be transient to itself! */
922 target
= g_hash_table_lookup(window_map
, &t
);
923 /* if this happens then we need to check for it*/
924 g_assert(target
!= self
);
925 if (target
&& !WINDOW_IS_CLIENT(target
)) {
926 /* this can happen when a dialog is a child of
927 a dockapp, for example */
931 if (!target
&& self
->group
) {
932 /* not transient to a client, see if it is transient for a
934 if (t
== self
->group
->leader
||
936 t
== RootWindow(ob_display
, ob_screen
))
938 /* window is a transient for its group! */
939 target
= OB_TRAN_GROUP
;
943 } else if (self
->type
== OB_CLIENT_TYPE_DIALOG
&& self
->group
) {
944 self
->transient
= TRUE
;
945 target
= OB_TRAN_GROUP
;
947 self
->transient
= FALSE
;
949 /* if anything has changed... */
950 if (target
!= self
->transient_for
) {
951 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
954 /* remove from old parents */
955 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
956 ObClient
*c
= it
->data
;
957 if (c
!= self
&& !c
->transient_for
)
958 c
->transients
= g_slist_remove(c
->transients
, self
);
960 } else if (self
->transient_for
!= NULL
) { /* transient of window */
961 /* remove from old parent */
962 self
->transient_for
->transients
=
963 g_slist_remove(self
->transient_for
->transients
, self
);
965 self
->transient_for
= target
;
966 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
969 /* add to new 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_append(c
->transients
, self
);
976 /* remove all transients which are in the group, that causes
977 circlular pointer hell of doom */
978 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
980 for (sit
= self
->transients
; sit
; sit
= next
) {
981 next
= g_slist_next(sit
);
982 if (sit
->data
== it
->data
)
984 g_slist_delete_link(self
->transients
, sit
);
987 } else if (self
->transient_for
!= NULL
) { /* transient of window */
988 /* add to new parent */
989 self
->transient_for
->transients
=
990 g_slist_append(self
->transient_for
->transients
, self
);
995 static void client_get_mwm_hints(ObClient
*self
)
1000 self
->mwmhints
.flags
= 0; /* default to none */
1002 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1004 if (num
>= OB_MWM_ELEMENTS
) {
1005 self
->mwmhints
.flags
= hints
[0];
1006 self
->mwmhints
.functions
= hints
[1];
1007 self
->mwmhints
.decorations
= hints
[2];
1013 void client_get_type(ObClient
*self
)
1020 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1021 /* use the first value that we know about in the array */
1022 for (i
= 0; i
< num
; ++i
) {
1023 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1024 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1025 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1026 self
->type
= OB_CLIENT_TYPE_DOCK
;
1027 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1028 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1029 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1030 self
->type
= OB_CLIENT_TYPE_MENU
;
1031 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1032 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1033 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1034 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1035 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1036 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1037 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1038 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1039 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1040 /* prevent this window from getting any decor or
1042 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1043 OB_MWM_FLAG_DECORATIONS
);
1044 self
->mwmhints
.decorations
= 0;
1045 self
->mwmhints
.functions
= 0;
1047 if (self
->type
!= (ObClientType
) -1)
1048 break; /* grab the first legit type */
1053 if (self
->type
== (ObClientType
) -1) {
1054 /*the window type hint was not set, which means we either classify
1055 ourself as a normal window or a dialog, depending on if we are a
1057 if (self
->transient
)
1058 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1060 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1064 void client_update_protocols(ObClient
*self
)
1067 guint num_return
, i
;
1069 self
->focus_notify
= FALSE
;
1070 self
->delete_window
= FALSE
;
1072 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1073 for (i
= 0; i
< num_return
; ++i
) {
1074 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1075 /* this means we can request the window to close */
1076 self
->delete_window
= TRUE
;
1077 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1078 /* if this protocol is requested, then the window will be
1079 notified whenever we want it to receive focus */
1080 self
->focus_notify
= TRUE
;
1086 static void client_get_gravity(ObClient
*self
)
1088 XWindowAttributes wattrib
;
1091 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1092 g_assert(ret
!= BadWindow
);
1093 self
->gravity
= wattrib
.win_gravity
;
1096 void client_update_normal_hints(ObClient
*self
)
1100 gint oldgravity
= self
->gravity
;
1103 self
->min_ratio
= 0.0f
;
1104 self
->max_ratio
= 0.0f
;
1105 SIZE_SET(self
->size_inc
, 1, 1);
1106 SIZE_SET(self
->base_size
, 0, 0);
1107 SIZE_SET(self
->min_size
, 0, 0);
1108 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1110 /* get the hints from the window */
1111 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1112 /* normal windows can't request placement! har har
1113 if (!client_normal(self))
1115 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1117 if (size
.flags
& PWinGravity
) {
1118 self
->gravity
= size
.win_gravity
;
1120 /* if the client has a frame, i.e. has already been mapped and
1121 is changing its gravity */
1122 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1123 /* move our idea of the client's position based on its new
1125 self
->area
.x
= self
->frame
->area
.x
;
1126 self
->area
.y
= self
->frame
->area
.y
;
1127 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1131 if (size
.flags
& PAspect
) {
1132 if (size
.min_aspect
.y
)
1134 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1135 if (size
.max_aspect
.y
)
1137 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1140 if (size
.flags
& PMinSize
)
1141 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1143 if (size
.flags
& PMaxSize
)
1144 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1146 if (size
.flags
& PBaseSize
)
1147 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1149 if (size
.flags
& PResizeInc
)
1150 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1154 void client_setup_decor_and_functions(ObClient
*self
)
1156 /* start with everything (cept fullscreen) */
1158 (OB_FRAME_DECOR_TITLEBAR
|
1159 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1160 OB_FRAME_DECOR_GRIPS
|
1161 OB_FRAME_DECOR_BORDER
|
1162 OB_FRAME_DECOR_ICON
|
1163 OB_FRAME_DECOR_ALLDESKTOPS
|
1164 OB_FRAME_DECOR_ICONIFY
|
1165 OB_FRAME_DECOR_MAXIMIZE
|
1166 OB_FRAME_DECOR_SHADE
|
1167 OB_FRAME_DECOR_CLOSE
);
1169 (OB_CLIENT_FUNC_RESIZE
|
1170 OB_CLIENT_FUNC_MOVE
|
1171 OB_CLIENT_FUNC_ICONIFY
|
1172 OB_CLIENT_FUNC_MAXIMIZE
|
1173 OB_CLIENT_FUNC_SHADE
|
1174 OB_CLIENT_FUNC_CLOSE
);
1176 if (!(self
->min_size
.width
< self
->max_size
.width
||
1177 self
->min_size
.height
< self
->max_size
.height
))
1178 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1180 switch (self
->type
) {
1181 case OB_CLIENT_TYPE_NORMAL
:
1182 /* normal windows retain all of the possible decorations and
1183 functionality, and are the only windows that you can fullscreen */
1184 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1187 case OB_CLIENT_TYPE_DIALOG
:
1188 case OB_CLIENT_TYPE_UTILITY
:
1189 /* these windows cannot be maximized */
1190 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1193 case OB_CLIENT_TYPE_MENU
:
1194 case OB_CLIENT_TYPE_TOOLBAR
:
1195 /* these windows get less functionality */
1196 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1199 case OB_CLIENT_TYPE_DESKTOP
:
1200 case OB_CLIENT_TYPE_DOCK
:
1201 case OB_CLIENT_TYPE_SPLASH
:
1202 /* none of these windows are manipulated by the window manager */
1203 self
->decorations
= 0;
1204 self
->functions
= 0;
1208 /* Mwm Hints are applied subtractively to what has already been chosen for
1209 decor and functionality */
1210 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1211 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1212 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1213 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1214 /* if the mwm hints request no handle or title, then all
1215 decorations are disabled */
1216 self
->decorations
= 0;
1220 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1221 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1222 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1223 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1224 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1225 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1226 /* dont let mwm hints kill any buttons
1227 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1228 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1229 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1230 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1232 /* dont let mwm hints kill the close button
1233 if (! (self->mwmhints.functions & MwmFunc_Close))
1234 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1238 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1239 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1240 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1241 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1242 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1243 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1245 /* can't maximize without moving/resizing */
1246 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1247 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1248 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1249 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1250 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1253 /* kill the handle on fully maxed windows */
1254 if (self
->max_vert
&& self
->max_horz
)
1255 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1257 /* finally, the user can have requested no decorations, which overrides
1258 everything (but doesnt give it a border if it doesnt have one) */
1259 if (self
->undecorated
)
1260 self
->decorations
= 0; //&= OB_FRAME_DECOR_BORDER;
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 data
= g_strdup("Unnamed Window");
1449 /* did the title change? then reset the title_count */
1450 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1451 self
->title_count
= 1;
1453 /* look for duplicates and append a number */
1455 for (it
= client_list
; it
; it
= g_list_next(it
))
1456 if (it
->data
!= self
) {
1457 ObClient
*c
= it
->data
;
1458 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1459 nums
|= 1 << c
->title_count
;
1461 /* find first free number */
1462 for (i
= 1; i
<= 32; ++i
)
1463 if (!(nums
& (1 << i
))) {
1464 if (self
->title_count
== 1 || i
== 1)
1465 self
->title_count
= i
;
1468 /* dont display the number for the first window */
1469 if (self
->title_count
> 1) {
1471 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1476 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1481 frame_adjust_title(self
->frame
);
1485 /* update the icon title */
1487 g_free(self
->icon_title
);
1491 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1492 /* try old x stuff */
1493 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1494 data
= g_strdup(self
->title
);
1498 /* append the title count, dont display the number for the first window */
1499 if (read_title
&& self
->title_count
> 1) {
1500 gchar
*vdata
, *ndata
;
1501 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1502 vdata
= g_strconcat(data
, ndata
, NULL
);
1508 // http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1509 if (self
->transient
)
1512 data
= g_strdup("Unnamed Window");
1514 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1516 self
->icon_title
= data
;
1519 void client_update_class(ObClient
*self
)
1524 if (self
->name
) g_free(self
->name
);
1525 if (self
->class) g_free(self
->class);
1526 if (self
->role
) g_free(self
->role
);
1528 self
->name
= self
->class = self
->role
= NULL
;
1530 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1532 self
->name
= g_strdup(data
[0]);
1534 self
->class = g_strdup(data
[1]);
1539 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1542 if (self
->name
== NULL
) self
->name
= g_strdup("");
1543 if (self
->class == NULL
) self
->class = g_strdup("");
1544 if (self
->role
== NULL
) self
->role
= g_strdup("");
1547 void client_update_strut(ObClient
*self
)
1551 gboolean got
= FALSE
;
1554 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1558 STRUT_PARTIAL_SET(strut
,
1559 data
[0], data
[2], data
[1], data
[3],
1560 data
[4], data
[5], data
[8], data
[9],
1561 data
[6], data
[7], data
[10], data
[11]);
1567 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1573 /* use the screen's width/height */
1574 a
= screen_physical_area();
1576 STRUT_PARTIAL_SET(strut
,
1577 data
[0], data
[2], data
[1], data
[3],
1578 a
->y
, a
->y
+ a
->height
- 1,
1579 a
->x
, a
->x
+ a
->width
- 1,
1580 a
->y
, a
->y
+ a
->height
- 1,
1581 a
->x
, a
->x
+ a
->width
- 1);
1587 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1588 0, 0, 0, 0, 0, 0, 0, 0);
1590 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1591 self
->strut
= strut
;
1593 /* updating here is pointless while we're being mapped cuz we're not in
1594 the client list yet */
1596 screen_update_areas();
1600 void client_update_icons(ObClient
*self
)
1606 for (i
= 0; i
< self
->nicons
; ++i
)
1607 g_free(self
->icons
[i
].data
);
1608 if (self
->nicons
> 0)
1609 g_free(self
->icons
);
1612 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1613 /* figure out how many valid icons are in here */
1615 while (num
- i
> 2) {
1619 if (i
> num
|| w
*h
== 0) break;
1623 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1625 /* store the icons */
1627 for (j
= 0; j
< self
->nicons
; ++j
) {
1630 w
= self
->icons
[j
].width
= data
[i
++];
1631 h
= self
->icons
[j
].height
= data
[i
++];
1633 if (w
*h
== 0) continue;
1635 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1636 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1641 self
->icons
[j
].data
[t
] =
1642 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1643 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1644 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1645 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1651 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1652 kwm_win_icon
, &data
, &num
)) {
1655 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1656 xerror_set_ignore(TRUE
);
1657 if (!RrPixmapToRGBA(ob_rr_inst
,
1659 &self
->icons
[self
->nicons
-1].width
,
1660 &self
->icons
[self
->nicons
-1].height
,
1661 &self
->icons
[self
->nicons
-1].data
)) {
1662 g_free(&self
->icons
[self
->nicons
-1]);
1665 xerror_set_ignore(FALSE
);
1671 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1672 if (hints
->flags
& IconPixmapHint
) {
1674 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1675 xerror_set_ignore(TRUE
);
1676 if (!RrPixmapToRGBA(ob_rr_inst
,
1678 (hints
->flags
& IconMaskHint
?
1679 hints
->icon_mask
: None
),
1680 &self
->icons
[self
->nicons
-1].width
,
1681 &self
->icons
[self
->nicons
-1].height
,
1682 &self
->icons
[self
->nicons
-1].data
)){
1683 g_free(&self
->icons
[self
->nicons
-1]);
1686 xerror_set_ignore(FALSE
);
1693 frame_adjust_icon(self
->frame
);
1696 static void client_change_state(ObClient
*self
)
1699 guint32 netstate
[11];
1702 state
[0] = self
->wmstate
;
1704 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1708 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1710 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1712 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1713 if (self
->skip_taskbar
)
1714 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1715 if (self
->skip_pager
)
1716 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1717 if (self
->fullscreen
)
1718 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1720 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1722 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1724 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1726 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1727 if (self
->undecorated
)
1728 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1729 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1731 client_calc_layer(self
);
1734 frame_adjust_state(self
->frame
);
1737 ObClient
*client_search_focus_tree(ObClient
*self
)
1742 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1743 if (client_focused(it
->data
)) return it
->data
;
1744 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1749 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1751 if (self
->transient_for
) {
1752 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1753 return client_search_focus_tree_full(self
->transient_for
);
1756 gboolean recursed
= FALSE
;
1758 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
1759 if (!((ObClient
*)it
->data
)->transient_for
) {
1761 if ((c
= client_search_focus_tree_full(it
->data
)))
1770 /* this function checks the whole tree, the client_search_focus_tree~
1771 does not, so we need to check this window */
1772 if (client_focused(self
))
1774 return client_search_focus_tree(self
);
1777 static ObStackingLayer
calc_layer(ObClient
*self
)
1781 if (self
->fullscreen
&&
1782 (client_focused(self
) || client_search_focus_tree(self
)))
1783 l
= OB_STACKING_LAYER_FULLSCREEN
;
1784 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1785 l
= OB_STACKING_LAYER_DESKTOP
;
1786 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1787 if (self
->above
) l
= OB_STACKING_LAYER_DOCK_ABOVE
;
1788 else if (self
->below
) l
= OB_STACKING_LAYER_DOCK_BELOW
;
1789 else l
= OB_STACKING_LAYER_DOCK_NORMAL
;
1791 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1792 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1793 else l
= OB_STACKING_LAYER_NORMAL
;
1798 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1799 ObStackingLayer l
, gboolean raised
)
1801 ObStackingLayer old
, own
;
1805 own
= calc_layer(self
);
1806 self
->layer
= l
> own
? l
: own
;
1808 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
1809 client_calc_layer_recursive(it
->data
, orig
,
1810 l
, raised
? raised
: l
!= old
);
1812 if (!raised
&& l
!= old
)
1813 if (orig
->frame
) { /* only restack if the original window is managed */
1814 stacking_remove(CLIENT_AS_WINDOW(self
));
1815 stacking_add(CLIENT_AS_WINDOW(self
));
1819 void client_calc_layer(ObClient
*self
)
1826 /* transients take on the layer of their parents */
1827 self
= client_search_top_transient(self
);
1829 l
= calc_layer(self
);
1831 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1834 gboolean
client_should_show(ObClient
*self
)
1838 if (client_normal(self
) && screen_showing_desktop
)
1841 if (self->transient_for) {
1842 if (self->transient_for != OB_TRAN_GROUP)
1843 return client_should_show(self->transient_for);
1847 for (it = self->group->members; it; it = g_slist_next(it)) {
1848 ObClient *c = it->data;
1849 if (c != self && !c->transient_for) {
1850 if (client_should_show(c))
1857 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
1863 static void client_showhide(ObClient
*self
)
1866 if (client_should_show(self
))
1867 frame_show(self
->frame
);
1869 frame_hide(self
->frame
);
1872 gboolean
client_normal(ObClient
*self
) {
1873 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1874 self
->type
== OB_CLIENT_TYPE_DOCK
||
1875 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1878 static void client_apply_startup_state(ObClient
*self
)
1880 /* these are in a carefully crafted order.. */
1883 self
->iconic
= FALSE
;
1884 client_iconify(self
, TRUE
, FALSE
);
1886 if (self
->fullscreen
) {
1887 self
->fullscreen
= FALSE
;
1888 client_fullscreen(self
, TRUE
, FALSE
);
1890 if (self
->undecorated
) {
1891 self
->undecorated
= FALSE
;
1892 client_set_undecorated(self
, TRUE
);
1895 self
->shaded
= FALSE
;
1896 client_shade(self
, TRUE
);
1899 client_urgent_notify(self
);
1901 if (self
->max_vert
&& self
->max_horz
) {
1902 self
->max_vert
= self
->max_horz
= FALSE
;
1903 client_maximize(self
, TRUE
, 0, FALSE
);
1904 } else if (self
->max_vert
) {
1905 self
->max_vert
= FALSE
;
1906 client_maximize(self
, TRUE
, 2, FALSE
);
1907 } else if (self
->max_horz
) {
1908 self
->max_horz
= FALSE
;
1909 client_maximize(self
, TRUE
, 1, FALSE
);
1912 /* nothing to do for the other states:
1921 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1922 gint x
, gint y
, gint w
, gint h
,
1923 gboolean user
, gboolean final
,
1924 gboolean force_reply
)
1927 gboolean send_resize_client
;
1928 gboolean moved
= FALSE
, resized
= FALSE
;
1929 guint fdecor
= self
->frame
->decorations
;
1930 gboolean fhorz
= self
->frame
->max_horz
;
1932 /* make the frame recalculate its dimentions n shit without changing
1933 anything visible for real, this way the constraints below can work with
1934 the updated frame dimensions. */
1935 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1937 /* gets the frame's position */
1938 frame_client_gravity(self
->frame
, &x
, &y
);
1940 /* these positions are frame positions, not client positions */
1942 /* set the size and position if fullscreen */
1943 if (self
->fullscreen
) {
1946 XF86VidModeModeLine mode
;
1951 i
= client_monitor(self
);
1952 a
= screen_physical_area_monitor(i
);
1955 if (i
== 0 && /* primary head */
1956 extensions_vidmode
&&
1957 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1958 /* get the mode last so the mode.privsize isnt freed incorrectly */
1959 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1964 if (mode
.privsize
) XFree(mode
.private);
1974 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1978 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1980 /* set the size and position if maximized */
1981 if (self
->max_horz
) {
1983 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1985 if (self
->max_vert
) {
1987 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1991 /* gets the client's position */
1992 frame_frame_gravity(self
->frame
, &x
, &y
);
1994 /* these override the above states! if you cant move you can't move! */
1996 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2000 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2001 w
= self
->area
.width
;
2002 h
= self
->area
.height
;
2006 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
2007 gint basew
, baseh
, minw
, minh
;
2009 /* base size is substituted with min size if not specified */
2010 if (self
->base_size
.width
|| self
->base_size
.height
) {
2011 basew
= self
->base_size
.width
;
2012 baseh
= self
->base_size
.height
;
2014 basew
= self
->min_size
.width
;
2015 baseh
= self
->min_size
.height
;
2017 /* min size is substituted with base size if not specified */
2018 if (self
->min_size
.width
|| self
->min_size
.height
) {
2019 minw
= self
->min_size
.width
;
2020 minh
= self
->min_size
.height
;
2022 minw
= self
->base_size
.width
;
2023 minh
= self
->base_size
.height
;
2026 /* if this is a user-requested resize, then check against min/max
2029 /* smaller than min size or bigger than max size? */
2030 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
2031 if (w
< minw
) w
= minw
;
2032 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
2033 if (h
< minh
) h
= minh
;
2038 /* keep to the increments */
2039 w
/= self
->size_inc
.width
;
2040 h
/= self
->size_inc
.height
;
2042 /* you cannot resize to nothing */
2043 if (basew
+ w
< 1) w
= 1 - basew
;
2044 if (baseh
+ h
< 1) h
= 1 - baseh
;
2046 /* store the logical size */
2047 SIZE_SET(self
->logical_size
,
2048 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
2049 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
2051 w
*= self
->size_inc
.width
;
2052 h
*= self
->size_inc
.height
;
2057 /* adjust the height to match the width for the aspect ratios.
2058 for this, min size is not substituted for base size ever. */
2059 w
-= self
->base_size
.width
;
2060 h
-= self
->base_size
.height
;
2062 if (!self
->fullscreen
) {
2063 if (self
->min_ratio
)
2064 if (h
* self
->min_ratio
> w
) {
2065 h
= (gint
)(w
/ self
->min_ratio
);
2067 /* you cannot resize to nothing */
2070 w
= (gint
)(h
* self
->min_ratio
);
2073 if (self
->max_ratio
)
2074 if (h
* self
->max_ratio
< w
) {
2075 h
= (gint
)(w
/ self
->max_ratio
);
2077 /* you cannot resize to nothing */
2080 w
= (gint
)(h
* self
->min_ratio
);
2085 w
+= self
->base_size
.width
;
2086 h
+= self
->base_size
.height
;
2093 case OB_CORNER_TOPLEFT
:
2095 case OB_CORNER_TOPRIGHT
:
2096 x
-= w
- self
->area
.width
;
2098 case OB_CORNER_BOTTOMLEFT
:
2099 y
-= h
- self
->area
.height
;
2101 case OB_CORNER_BOTTOMRIGHT
:
2102 x
-= w
- self
->area
.width
;
2103 y
-= h
- self
->area
.height
;
2107 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2108 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2110 oldw
= self
->area
.width
;
2111 oldh
= self
->area
.height
;
2112 RECT_SET(self
->area
, x
, y
, w
, h
);
2114 /* for app-requested resizes, always resize if 'resized' is true.
2115 for user-requested ones, only resize if final is true, or when
2116 resizing in redraw mode */
2117 send_resize_client
= ((!user
&& resized
) ||
2119 (resized
&& config_resize_redraw
))));
2121 /* if the client is enlarging, then resize the client before the frame */
2122 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2123 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2125 /* move/resize the frame to match the request */
2127 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2128 moved
= resized
= TRUE
;
2130 if (moved
|| resized
)
2131 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2133 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2136 event
.type
= ConfigureNotify
;
2137 event
.xconfigure
.display
= ob_display
;
2138 event
.xconfigure
.event
= self
->window
;
2139 event
.xconfigure
.window
= self
->window
;
2141 /* root window real coords */
2142 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2144 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2146 event
.xconfigure
.width
= w
;
2147 event
.xconfigure
.height
= h
;
2148 event
.xconfigure
.border_width
= 0;
2149 event
.xconfigure
.above
= self
->frame
->plate
;
2150 event
.xconfigure
.override_redirect
= FALSE
;
2151 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2152 FALSE
, StructureNotifyMask
, &event
);
2156 /* if the client is shrinking, then resize the frame before the client */
2157 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2158 XResizeWindow(ob_display
, self
->window
, w
, h
);
2163 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2167 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2168 self
->fullscreen
== fs
) return; /* already done */
2170 self
->fullscreen
= fs
;
2171 client_change_state(self
); /* change the state hints on the client,
2172 and adjust out layer/stacking */
2176 self
->pre_fullscreen_area
= self
->area
;
2178 /* these are not actually used cuz client_configure will set them
2179 as appropriate when the window is fullscreened */
2184 if (self
->pre_fullscreen_area
.width
> 0 &&
2185 self
->pre_fullscreen_area
.height
> 0)
2187 x
= self
->pre_fullscreen_area
.x
;
2188 y
= self
->pre_fullscreen_area
.y
;
2189 w
= self
->pre_fullscreen_area
.width
;
2190 h
= self
->pre_fullscreen_area
.height
;
2191 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2193 /* pick some fallbacks... */
2194 a
= screen_area_monitor(self
->desktop
, 0);
2195 x
= a
->x
+ a
->width
/ 4;
2196 y
= a
->y
+ a
->height
/ 4;
2202 client_setup_decor_and_functions(self
);
2204 client_move_resize(self
, x
, y
, w
, h
);
2206 /* try focus us when we go into fullscreen mode */
2210 static void client_iconify_recursive(ObClient
*self
,
2211 gboolean iconic
, gboolean curdesk
)
2214 gboolean changed
= FALSE
;
2217 if (self
->iconic
!= iconic
) {
2218 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2221 self
->iconic
= iconic
;
2224 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2227 old
= self
->wmstate
;
2228 self
->wmstate
= IconicState
;
2229 if (old
!= self
->wmstate
)
2230 PROP_MSG(self
->window
, kde_wm_change_state
,
2231 self
->wmstate
, 1, 0, 0);
2233 /* update the focus lists.. iconic windows go to the bottom of
2234 the list, put the new iconic window at the 'top of the
2236 focus_order_to_top(self
);
2244 client_set_desktop(self
, screen_desktop
, FALSE
);
2246 old
= self
->wmstate
;
2247 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2248 if (old
!= self
->wmstate
)
2249 PROP_MSG(self
->window
, kde_wm_change_state
,
2250 self
->wmstate
, 1, 0, 0);
2252 /* this puts it after the current focused window */
2253 focus_order_remove(self
);
2254 focus_order_add_new(self
);
2256 /* this is here cuz with the VIDMODE extension, the viewport can
2257 change while a fullscreen window is iconic, and when it
2258 uniconifies, it would be nice if it did so to the new position
2260 client_reconfigure(self
);
2267 client_change_state(self
);
2268 client_showhide(self
);
2269 screen_update_areas();
2272 /* iconify all transients */
2273 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2274 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2278 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2280 /* move up the transient chain as far as possible first */
2281 self
= client_search_top_transient(self
);
2283 client_iconify_recursive(client_search_top_transient(self
),
2287 void client_maximize(ObClient
*self
, gboolean max
, gint dir
, gboolean savearea
)
2291 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2292 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2294 /* check if already done */
2296 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2297 if (dir
== 1 && self
->max_horz
) return;
2298 if (dir
== 2 && self
->max_vert
) return;
2300 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2301 if (dir
== 1 && !self
->max_horz
) return;
2302 if (dir
== 2 && !self
->max_vert
) return;
2305 /* we just tell it to configure in the same place and client_configure
2306 worries about filling the screen with the window */
2309 w
= self
->area
.width
;
2310 h
= self
->area
.height
;
2314 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2315 RECT_SET(self
->pre_max_area
,
2316 self
->area
.x
, self
->pre_max_area
.y
,
2317 self
->area
.width
, self
->pre_max_area
.height
);
2319 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2320 RECT_SET(self
->pre_max_area
,
2321 self
->pre_max_area
.x
, self
->area
.y
,
2322 self
->pre_max_area
.width
, self
->area
.height
);
2328 a
= screen_area_monitor(self
->desktop
, 0);
2329 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2330 if (self
->pre_max_area
.width
> 0) {
2331 x
= self
->pre_max_area
.x
;
2332 w
= self
->pre_max_area
.width
;
2334 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2335 0, self
->pre_max_area
.height
);
2337 /* pick some fallbacks... */
2338 x
= a
->x
+ a
->width
/ 4;
2342 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2343 if (self
->pre_max_area
.height
> 0) {
2344 y
= self
->pre_max_area
.y
;
2345 h
= self
->pre_max_area
.height
;
2347 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2348 self
->pre_max_area
.width
, 0);
2350 /* pick some fallbacks... */
2351 y
= a
->y
+ a
->height
/ 4;
2357 if (dir
== 0 || dir
== 1) /* horz */
2358 self
->max_horz
= max
;
2359 if (dir
== 0 || dir
== 2) /* vert */
2360 self
->max_vert
= max
;
2362 client_change_state(self
); /* change the state hints on the client */
2364 client_setup_decor_and_functions(self
);
2366 client_move_resize(self
, x
, y
, w
, h
);
2369 void client_shade(ObClient
*self
, gboolean shade
)
2371 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2372 shade
) || /* can't shade */
2373 self
->shaded
== shade
) return; /* already done */
2375 /* when we're iconic, don't change the wmstate */
2376 if (!self
->iconic
) {
2379 old
= self
->wmstate
;
2380 self
->wmstate
= shade
? IconicState
: NormalState
;
2381 if (old
!= self
->wmstate
)
2382 PROP_MSG(self
->window
, kde_wm_change_state
,
2383 self
->wmstate
, 1, 0, 0);
2386 self
->shaded
= shade
;
2387 client_change_state(self
);
2388 /* resize the frame to just the titlebar */
2389 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2392 void client_close(ObClient
*self
)
2396 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2398 /* in the case that the client provides no means to requesting that it
2399 close, we just kill it */
2400 if (!self
->delete_window
)
2404 XXX: itd be cool to do timeouts and shit here for killing the client's
2406 like... if the window is around after 5 seconds, then the close button
2407 turns a nice red, and if this function is called again, the client is
2411 ce
.xclient
.type
= ClientMessage
;
2412 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2413 ce
.xclient
.display
= ob_display
;
2414 ce
.xclient
.window
= self
->window
;
2415 ce
.xclient
.format
= 32;
2416 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2417 ce
.xclient
.data
.l
[1] = event_lasttime
;
2418 ce
.xclient
.data
.l
[2] = 0l;
2419 ce
.xclient
.data
.l
[3] = 0l;
2420 ce
.xclient
.data
.l
[4] = 0l;
2421 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2424 void client_kill(ObClient
*self
)
2426 XKillClient(ob_display
, self
->window
);
2429 void client_set_desktop_recursive(ObClient
*self
,
2430 guint target
, gboolean donthide
)
2435 if (target
!= self
->desktop
) {
2437 ob_debug("Setting desktop %u\n", target
+1);
2439 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2441 /* remove from the old desktop(s) */
2442 focus_order_remove(self
);
2444 old
= self
->desktop
;
2445 self
->desktop
= target
;
2446 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2447 /* the frame can display the current desktop state */
2448 frame_adjust_state(self
->frame
);
2449 /* 'move' the window to the new desktop */
2451 client_showhide(self
);
2452 /* raise if it was not already on the desktop */
2453 if (old
!= DESKTOP_ALL
)
2455 screen_update_areas();
2457 /* add to the new desktop(s) */
2458 if (config_focus_new
)
2459 focus_order_to_top(self
);
2461 focus_order_to_bottom(self
);
2464 /* move all transients */
2465 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2466 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2470 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2472 client_set_desktop_recursive(client_search_top_transient(self
),
2476 ObClient
*client_search_modal_child(ObClient
*self
)
2481 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2482 ObClient
*c
= it
->data
;
2483 if ((ret
= client_search_modal_child(c
))) return ret
;
2484 if (c
->modal
) return c
;
2489 gboolean
client_validate(ObClient
*self
)
2493 XSync(ob_display
, FALSE
); /* get all events on the server */
2495 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2496 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2497 XPutBackEvent(ob_display
, &e
);
2504 void client_set_wm_state(ObClient
*self
, glong state
)
2506 if (state
== self
->wmstate
) return; /* no change */
2510 client_iconify(self
, TRUE
, TRUE
);
2513 client_iconify(self
, FALSE
, TRUE
);
2518 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
2520 gboolean shaded
= self
->shaded
;
2521 gboolean fullscreen
= self
->fullscreen
;
2522 gboolean undecorated
= self
->undecorated
;
2523 gboolean max_horz
= self
->max_horz
;
2524 gboolean max_vert
= self
->max_vert
;
2525 gboolean modal
= self
->modal
;
2528 if (!(action
== prop_atoms
.net_wm_state_add
||
2529 action
== prop_atoms
.net_wm_state_remove
||
2530 action
== prop_atoms
.net_wm_state_toggle
))
2531 /* an invalid action was passed to the client message, ignore it */
2534 for (i
= 0; i
< 2; ++i
) {
2535 Atom state
= i
== 0 ? data1
: data2
;
2537 if (!state
) continue;
2539 /* if toggling, then pick whether we're adding or removing */
2540 if (action
== prop_atoms
.net_wm_state_toggle
) {
2541 if (state
== prop_atoms
.net_wm_state_modal
)
2542 action
= modal
? prop_atoms
.net_wm_state_remove
:
2543 prop_atoms
.net_wm_state_add
;
2544 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2545 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2546 prop_atoms
.net_wm_state_add
;
2547 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2548 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2549 prop_atoms
.net_wm_state_add
;
2550 else if (state
== prop_atoms
.net_wm_state_shaded
)
2551 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2552 prop_atoms
.net_wm_state_add
;
2553 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2554 action
= self
->skip_taskbar
?
2555 prop_atoms
.net_wm_state_remove
:
2556 prop_atoms
.net_wm_state_add
;
2557 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2558 action
= self
->skip_pager
?
2559 prop_atoms
.net_wm_state_remove
:
2560 prop_atoms
.net_wm_state_add
;
2561 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2562 action
= fullscreen
?
2563 prop_atoms
.net_wm_state_remove
:
2564 prop_atoms
.net_wm_state_add
;
2565 else if (state
== prop_atoms
.net_wm_state_above
)
2566 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2567 prop_atoms
.net_wm_state_add
;
2568 else if (state
== prop_atoms
.net_wm_state_below
)
2569 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2570 prop_atoms
.net_wm_state_add
;
2571 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2572 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2573 prop_atoms
.net_wm_state_add
;
2576 if (action
== prop_atoms
.net_wm_state_add
) {
2577 if (state
== prop_atoms
.net_wm_state_modal
) {
2579 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2581 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2583 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2585 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2586 self
->skip_taskbar
= TRUE
;
2587 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2588 self
->skip_pager
= TRUE
;
2589 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2591 } else if (state
== prop_atoms
.net_wm_state_above
) {
2593 self
->below
= FALSE
;
2594 } else if (state
== prop_atoms
.net_wm_state_below
) {
2595 self
->above
= FALSE
;
2597 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2601 } else { /* action == prop_atoms.net_wm_state_remove */
2602 if (state
== prop_atoms
.net_wm_state_modal
) {
2604 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2606 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2608 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2610 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2611 self
->skip_taskbar
= FALSE
;
2612 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2613 self
->skip_pager
= FALSE
;
2614 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2616 } else if (state
== prop_atoms
.net_wm_state_above
) {
2617 self
->above
= FALSE
;
2618 } else if (state
== prop_atoms
.net_wm_state_below
) {
2619 self
->below
= FALSE
;
2620 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2621 undecorated
= FALSE
;
2625 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2626 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2628 if (max_horz
== max_vert
) { /* both going the same way */
2629 client_maximize(self
, max_horz
, 0, TRUE
);
2631 client_maximize(self
, max_horz
, 1, TRUE
);
2632 client_maximize(self
, max_vert
, 2, TRUE
);
2636 if (max_horz
!= self
->max_horz
)
2637 client_maximize(self
, max_horz
, 1, TRUE
);
2639 client_maximize(self
, max_vert
, 2, TRUE
);
2642 /* change fullscreen state before shading, as it will affect if the window
2644 if (fullscreen
!= self
->fullscreen
)
2645 client_fullscreen(self
, fullscreen
, TRUE
);
2646 if (shaded
!= self
->shaded
)
2647 client_shade(self
, shaded
);
2648 if (undecorated
!= self
->undecorated
)
2649 client_set_undecorated(self
, undecorated
);
2650 if (modal
!= self
->modal
) {
2651 self
->modal
= modal
;
2652 /* when a window changes modality, then its stacking order with its
2653 transients needs to change */
2656 client_calc_layer(self
);
2657 client_change_state(self
); /* change the hint to reflect these changes */
2660 ObClient
*client_focus_target(ObClient
*self
)
2664 /* if we have a modal child, then focus it, not us */
2665 child
= client_search_modal_child(client_search_top_transient(self
));
2666 if (child
) return child
;
2670 gboolean
client_can_focus(ObClient
*self
)
2674 /* choose the correct target */
2675 self
= client_focus_target(self
);
2677 if (!self
->frame
->visible
)
2680 if (!(self
->can_focus
|| self
->focus_notify
))
2683 /* do a check to see if the window has already been unmapped or destroyed
2684 do this intelligently while watching out for unmaps we've generated
2685 (ignore_unmaps > 0) */
2686 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2687 DestroyNotify
, &ev
)) {
2688 XPutBackEvent(ob_display
, &ev
);
2691 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2692 UnmapNotify
, &ev
)) {
2693 if (self
->ignore_unmaps
) {
2694 self
->ignore_unmaps
--;
2696 XPutBackEvent(ob_display
, &ev
);
2704 gboolean
client_focus(ObClient
*self
)
2706 /* choose the correct target */
2707 self
= client_focus_target(self
);
2709 if (!client_can_focus(self
)) {
2710 if (!self
->frame
->visible
) {
2711 /* update the focus lists */
2712 focus_order_to_top(self
);
2717 if (self
->can_focus
) {
2718 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2719 I choose to use it always, hopefully to find errors quicker, if any
2720 are left. (I hate X. I hate focus events.)
2722 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2723 #799. So now it is RevertToNone again.
2725 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2729 if (self
->focus_notify
) {
2731 ce
.xclient
.type
= ClientMessage
;
2732 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2733 ce
.xclient
.display
= ob_display
;
2734 ce
.xclient
.window
= self
->window
;
2735 ce
.xclient
.format
= 32;
2736 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2737 ce
.xclient
.data
.l
[1] = event_lasttime
;
2738 ce
.xclient
.data
.l
[2] = 0l;
2739 ce
.xclient
.data
.l
[3] = 0l;
2740 ce
.xclient
.data
.l
[4] = 0l;
2741 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2745 ob_debug("%sively focusing %lx at %d\n",
2746 (self
->can_focus
? "act" : "pass"),
2747 self
->window
, (gint
) event_lasttime
);
2750 /* Cause the FocusIn to come back to us. Important for desktop switches,
2751 since otherwise we'll have no FocusIn on the queue and send it off to
2752 the focus_backup. */
2753 XSync(ob_display
, FALSE
);
2757 void client_unfocus(ObClient
*self
)
2759 if (focus_client
== self
) {
2761 ob_debug("client_unfocus for %lx\n", self
->window
);
2763 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2767 void client_activate(ObClient
*self
, gboolean here
)
2769 if (client_normal(self
) && screen_showing_desktop
)
2770 screen_show_desktop(FALSE
);
2772 client_iconify(self
, FALSE
, here
);
2773 if (self
->desktop
!= DESKTOP_ALL
&&
2774 self
->desktop
!= screen_desktop
) {
2776 client_set_desktop(self
, screen_desktop
, FALSE
);
2778 screen_set_desktop(self
->desktop
);
2779 } else if (!self
->frame
->visible
)
2780 /* if its not visible for other reasons, then don't mess
2784 client_shade(self
, FALSE
);
2788 /* we do this an action here. this is rather important. this is because
2789 we want the results from the focus change to take place BEFORE we go
2790 about raising the window. when a fullscreen window loses focus, we need
2791 this or else the raise wont be able to raise above the to-lose-focus
2792 fullscreen window. */
2796 void client_raise(ObClient
*self
)
2798 action_run_string("Raise", self
);
2801 void client_lower(ObClient
*self
)
2803 action_run_string("Lower", self
);
2806 gboolean
client_focused(ObClient
*self
)
2808 return self
== focus_client
;
2811 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
2814 /* si is the smallest image >= req */
2815 /* li is the largest image < req */
2816 gulong size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2818 if (!self
->nicons
) {
2819 ObClientIcon
*parent
= NULL
;
2821 if (self
->transient_for
) {
2822 if (self
->transient_for
!= OB_TRAN_GROUP
)
2823 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2826 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2827 ObClient
*c
= it
->data
;
2828 if (c
!= self
&& !c
->transient_for
) {
2829 if ((parent
= client_icon_recursive(c
, w
, h
)))
2839 for (i
= 0; i
< self
->nicons
; ++i
) {
2840 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2841 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2845 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2850 if (largest
== 0) /* didnt find one smaller than the requested size */
2851 return &self
->icons
[si
];
2852 return &self
->icons
[li
];
2855 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
2858 static ObClientIcon deficon
;
2860 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2861 deficon
.width
= deficon
.height
= 48;
2862 deficon
.data
= ob_rr_theme
->def_win_icon
;
2868 /* this be mostly ripped from fvwm */
2869 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2871 gint my_cx
, my_cy
, his_cx
, his_cy
;
2874 gint score
, best_score
;
2875 ObClient
*best_client
, *cur
;
2881 /* first, find the centre coords of the currently focused window */
2882 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2883 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2888 for(it
= g_list_first(client_list
); it
; it
= g_list_next(it
)) {
2891 /* the currently selected window isn't interesting */
2894 if (!client_normal(cur
))
2896 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2900 if(client_focus_target(cur
) == cur
&&
2901 !(cur
->can_focus
|| cur
->focus_notify
))
2904 /* find the centre coords of this window, from the
2905 * currently focused window's point of view */
2906 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2907 + cur
->frame
->area
.width
/ 2;
2908 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2909 + cur
->frame
->area
.height
/ 2;
2911 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2912 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2914 /* Rotate the diagonals 45 degrees counterclockwise.
2915 * To do this, multiply the matrix /+h +h\ with the
2916 * vector (x y). \-h +h/
2917 * h = sqrt(0.5). We can set h := 1 since absolute
2918 * distance doesn't matter here. */
2919 tx
= his_cx
+ his_cy
;
2920 his_cy
= -his_cx
+ his_cy
;
2925 case OB_DIRECTION_NORTH
:
2926 case OB_DIRECTION_SOUTH
:
2927 case OB_DIRECTION_NORTHEAST
:
2928 case OB_DIRECTION_SOUTHWEST
:
2929 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2930 distance
= ((dir
== OB_DIRECTION_NORTH
||
2931 dir
== OB_DIRECTION_NORTHEAST
) ?
2934 case OB_DIRECTION_EAST
:
2935 case OB_DIRECTION_WEST
:
2936 case OB_DIRECTION_SOUTHEAST
:
2937 case OB_DIRECTION_NORTHWEST
:
2938 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2939 distance
= ((dir
== OB_DIRECTION_WEST
||
2940 dir
== OB_DIRECTION_NORTHWEST
) ?
2945 /* the target must be in the requested direction */
2949 /* Calculate score for this window. The smaller the better. */
2950 score
= distance
+ offset
;
2952 /* windows more than 45 degrees off the direction are
2953 * heavily penalized and will only be chosen if nothing
2954 * else within a million pixels */
2955 if(offset
> distance
)
2958 if(best_score
== -1 || score
< best_score
)
2966 void client_set_layer(ObClient
*self
, gint layer
)
2970 self
->above
= FALSE
;
2971 } else if (layer
== 0) {
2972 self
->below
= self
->above
= FALSE
;
2974 self
->below
= FALSE
;
2977 client_calc_layer(self
);
2978 client_change_state(self
); /* reflect this in the state hints */
2981 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
2983 if (self
->undecorated
!= undecorated
) {
2984 self
->undecorated
= undecorated
;
2985 client_setup_decor_and_functions(self
);
2986 client_change_state(self
); /* reflect this in the state hints */
2990 guint
client_monitor(ObClient
*self
)
2996 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2997 Rect
*area
= screen_physical_area_monitor(i
);
2998 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
)) {
3002 RECT_SET_INTERSECTION(r
, *area
, self
->frame
->area
);
3003 v
= r
.width
* r
.height
;
3014 ObClient
*client_search_top_transient(ObClient
*self
)
3016 /* move up the transient chain as far as possible */
3017 if (self
->transient_for
) {
3018 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3019 return client_search_top_transient(self
->transient_for
);
3023 g_assert(self
->group
);
3025 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3026 ObClient
*c
= it
->data
;
3028 /* checking transient_for prevents infinate loops! */
3029 if (c
!= self
&& !c
->transient_for
)
3040 ObClient
*client_search_focus_parent(ObClient
*self
)
3042 if (self
->transient_for
) {
3043 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3044 if (client_focused(self
->transient_for
))
3045 return self
->transient_for
;
3049 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3050 ObClient
*c
= it
->data
;
3052 /* checking transient_for prevents infinate loops! */
3053 if (c
!= self
&& !c
->transient_for
)
3054 if (client_focused(c
))
3063 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3065 if (self
->transient_for
) {
3066 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3067 if (self
->transient_for
== search
)
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
)
3086 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3090 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3091 if (sit
->data
== search
)
3093 if (client_search_transient(sit
->data
, search
))
3099 void client_update_sm_client_id(ObClient
*self
)
3101 g_free(self
->sm_client_id
);
3102 self
->sm_client_id
= NULL
;
3104 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3106 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3107 &self
->sm_client_id
);
3110 /* finds the nearest edge in the given direction from the current client
3111 * note to self: the edge is the -frame- edge (the actual one), not the
3114 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3117 gint my_edge_start
, my_edge_end
, my_offset
;
3124 a
= screen_area(c
->desktop
);
3127 case OB_DIRECTION_NORTH
:
3128 my_edge_start
= c
->frame
->area
.x
;
3129 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3130 my_offset
= c
->frame
->area
.y
;
3132 /* default: top of screen */
3135 for(it
= client_list
; it
; it
= g_list_next(it
)) {
3136 gint his_edge_start
, his_edge_end
, his_offset
;
3137 ObClient
*cur
= it
->data
;
3141 if(!client_normal(cur
))
3143 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3148 his_edge_start
= cur
->frame
->area
.x
;
3149 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3150 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3152 if(his_offset
+ 1 > my_offset
)
3155 if(his_offset
< dest
)
3158 if(his_edge_start
>= my_edge_start
&&
3159 his_edge_start
<= my_edge_end
)
3162 if(my_edge_start
>= his_edge_start
&&
3163 my_edge_start
<= his_edge_end
)
3168 case OB_DIRECTION_SOUTH
:
3169 my_edge_start
= c
->frame
->area
.x
;
3170 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3171 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3173 /* default: bottom of screen */
3174 dest
= a
->y
+ a
->height
;
3176 for(it
= client_list
; it
; it
= g_list_next(it
)) {
3177 gint his_edge_start
, his_edge_end
, his_offset
;
3178 ObClient
*cur
= it
->data
;
3182 if(!client_normal(cur
))
3184 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3189 his_edge_start
= cur
->frame
->area
.x
;
3190 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3191 his_offset
= cur
->frame
->area
.y
;
3194 if(his_offset
- 1 < my_offset
)
3197 if(his_offset
> dest
)
3200 if(his_edge_start
>= my_edge_start
&&
3201 his_edge_start
<= my_edge_end
)
3204 if(my_edge_start
>= his_edge_start
&&
3205 my_edge_start
<= his_edge_end
)
3210 case OB_DIRECTION_WEST
:
3211 my_edge_start
= c
->frame
->area
.y
;
3212 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3213 my_offset
= c
->frame
->area
.x
;
3215 /* default: leftmost egde of screen */
3218 for(it
= client_list
; it
; it
= g_list_next(it
)) {
3219 gint his_edge_start
, his_edge_end
, his_offset
;
3220 ObClient
*cur
= it
->data
;
3224 if(!client_normal(cur
))
3226 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3231 his_edge_start
= cur
->frame
->area
.y
;
3232 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3233 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3235 if(his_offset
+ 1 > my_offset
)
3238 if(his_offset
< dest
)
3241 if(his_edge_start
>= my_edge_start
&&
3242 his_edge_start
<= my_edge_end
)
3245 if(my_edge_start
>= his_edge_start
&&
3246 my_edge_start
<= his_edge_end
)
3252 case OB_DIRECTION_EAST
:
3253 my_edge_start
= c
->frame
->area
.y
;
3254 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3255 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3257 /* default: rightmost edge of screen */
3258 dest
= a
->x
+ a
->width
;
3260 for(it
= client_list
; it
; it
= g_list_next(it
)) {
3261 gint his_edge_start
, his_edge_end
, his_offset
;
3262 ObClient
*cur
= it
->data
;
3266 if(!client_normal(cur
))
3268 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3273 his_edge_start
= cur
->frame
->area
.y
;
3274 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3275 his_offset
= cur
->frame
->area
.x
;
3277 if(his_offset
- 1 < my_offset
)
3280 if(his_offset
> dest
)
3283 if(his_edge_start
>= my_edge_start
&&
3284 his_edge_start
<= my_edge_end
)
3287 if(my_edge_start
>= his_edge_start
&&
3288 my_edge_start
<= his_edge_end
)
3293 case OB_DIRECTION_NORTHEAST
:
3294 case OB_DIRECTION_SOUTHEAST
:
3295 case OB_DIRECTION_NORTHWEST
:
3296 case OB_DIRECTION_SOUTHWEST
:
3297 /* not implemented */
3299 g_assert_not_reached();
3304 ObClient
* client_under_pointer()
3308 ObClient
*ret
= NULL
;
3310 if (screen_pointer_pos(&x
, &y
)) {
3311 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
3312 if (WINDOW_IS_CLIENT(it
->data
)) {
3313 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3314 if (c
->frame
->visible
&&
3315 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3325 gboolean
client_has_group_siblings(ObClient
*self
)
3327 return self
->group
&& self
->group
->members
->next
;