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
!= NULL
; it
= it
->next
, ++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, void *data)
141 for (it = self->transients; it; it = it->next) {
142 if (!func(it->data, data)) return;
143 client_foreach_transient(it->data, func, data);
147 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *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 = it->next)
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()
169 unsigned int i
, j
, nchild
;
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 client_change_state(self
);
274 /* remove the client's border (and adjust re gravity) */
275 client_toggle_border(self
, FALSE
);
277 /* specify that if we exit, the window should not be destroyed and should
278 be reparented back to root automatically */
279 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
281 /* create the decoration frame for the client window */
282 self
->frame
= frame_new();
284 frame_grab_client(self
->frame
, self
);
288 client_apply_startup_state(self
);
290 /* update the focus lists */
291 focus_order_add_new(self
);
293 stacking_add(CLIENT_AS_WINDOW(self
));
294 client_restore_session_stacking(self
);
296 /* focus the new window? */
297 if (ob_state() != OB_STATE_STARTING
&&
298 (config_focus_new
|| client_search_focus_parent(self
)) &&
299 /* note the check against Type_Normal/Dialog, not client_normal(self),
300 which would also include other types. in this case we want more
301 strict rules for focus */
302 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
303 self
->type
== OB_CLIENT_TYPE_DIALOG
))
307 if (self
->desktop
!= screen_desktop
) {
308 /* activate the window */
311 gboolean group_foc
= FALSE
;
316 for (it
= self
->group
->members
; it
; it
= it
->next
)
318 if (client_focused(it
->data
))
326 (!self
->transient_for
&& (!self
->group
||
327 !self
->group
->members
->next
))) ||
328 client_search_focus_tree_full(self
) ||
330 !client_normal(focus_client
))
332 /* activate the window */
339 if (ob_state() == OB_STATE_RUNNING
) {
340 int x
= self
->area
.x
, ox
= x
;
341 int y
= self
->area
.y
, oy
= y
;
343 place_client(self
, &x
, &y
);
345 /* make sure the window is visible */
346 client_find_onscreen(self
, &x
, &y
,
347 self
->frame
->area
.width
,
348 self
->frame
->area
.height
,
349 /* non-normal clients has less rules, and
350 windows that are being restored from a session
351 do also. we can assume you want it back where
353 client_normal(self
) && !self
->session
);
355 if (x
!= ox
|| y
!= oy
)
356 client_move(self
, x
, y
);
359 client_showhide(self
);
361 /* use client_focus instead of client_activate cuz client_activate does
362 stuff like switch desktops etc and I'm not interested in all that when
363 a window maps since its not based on an action from the user like
364 clicking a window to activate is. so keep the new window out of the way
367 /* if using focus_delay, stop the timer now so that focus doesn't go
369 event_halt_focus_delay();
372 /* since focus can change the stacking orders, if we focus the window
373 then the standard raise it gets is not enough, we need to queue one
374 for after the focus change takes place */
378 /* client_activate does this but we aret using it so we have to do it
380 if (screen_showing_desktop
)
381 screen_show_desktop(FALSE
);
383 /* add to client list/map */
384 client_list
= g_list_append(client_list
, self
);
385 g_hash_table_insert(window_map
, &self
->window
, self
);
387 /* this has to happen after we're in the client_list */
388 screen_update_areas();
390 /* update the list hints */
393 keyboard_grab_for_client(self
, TRUE
);
394 mouse_grab_for_client(self
, TRUE
);
396 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
399 void client_unmanage_all()
401 while (client_list
!= NULL
)
402 client_unmanage(client_list
->data
);
405 void client_unmanage(ObClient
*self
)
410 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
412 g_assert(self
!= NULL
);
414 keyboard_grab_for_client(self
, FALSE
);
415 mouse_grab_for_client(self
, FALSE
);
417 /* remove the window from our save set */
418 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
420 /* we dont want events no more */
421 XSelectInput(ob_display
, self
->window
, NoEventMask
);
423 frame_hide(self
->frame
);
425 client_list
= g_list_remove(client_list
, self
);
426 stacking_remove(self
);
427 g_hash_table_remove(window_map
, &self
->window
);
429 /* update the focus lists */
430 focus_order_remove(self
);
432 /* once the client is out of the list, update the struts to remove it's
434 screen_update_areas();
436 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
437 Destructor
*d
= it
->data
;
438 d
->func(self
, d
->data
);
441 if (focus_client
== self
) {
444 /* focus the last focused window on the desktop, and ignore enter
445 events from the unmap so it doesnt mess with the focus */
446 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
447 /* remove these flags so we don't end up getting focused in the
449 self
->can_focus
= FALSE
;
450 self
->focus_notify
= FALSE
;
452 client_unfocus(self
);
455 /* tell our parent(s) that we're gone */
456 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
459 for (it
= self
->group
->members
; it
; it
= it
->next
)
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
!= NULL
; it
= it
->next
) {
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 iconic state, the client wont be mapped. this is
497 bad, since we will no longer be managing the window on restart */
499 XMapWindow(ob_display
, self
->window
);
503 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
505 /* free all data allocated in the client struct */
506 g_slist_free(self
->transients
);
507 for (j
= 0; j
< self
->nicons
; ++j
)
508 g_free(self
->icons
[j
].data
);
509 if (self
->nicons
> 0)
512 g_free(self
->icon_title
);
516 g_free(self
->sm_client_id
);
519 /* update the list hints */
523 static void client_urgent_notify(ObClient
*self
)
526 frame_flash_start(self
->frame
);
528 frame_flash_stop(self
->frame
);
531 static void client_restore_session_state(ObClient
*self
)
535 if (!(it
= session_state_find(self
)))
538 self
->session
= it
->data
;
540 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
541 self
->positioned
= TRUE
;
542 if (self
->session
->w
> 0)
543 self
->area
.width
= self
->session
->w
;
544 if (self
->session
->h
> 0)
545 self
->area
.height
= self
->session
->h
;
546 XResizeWindow(ob_display
, self
->window
,
547 self
->area
.width
, self
->area
.height
);
549 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
550 self
->session
->desktop
:
551 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
552 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
554 self
->shaded
= self
->session
->shaded
;
555 self
->iconic
= self
->session
->iconic
;
556 self
->skip_pager
= self
->session
->skip_pager
;
557 self
->skip_taskbar
= self
->session
->skip_taskbar
;
558 self
->fullscreen
= self
->session
->fullscreen
;
559 self
->above
= self
->session
->above
;
560 self
->below
= self
->session
->below
;
561 self
->max_horz
= self
->session
->max_horz
;
562 self
->max_vert
= self
->session
->max_vert
;
565 static void client_restore_session_stacking(ObClient
*self
)
569 if (!self
->session
) return;
571 it
= g_list_find(session_saved_state
, self
->session
);
572 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
575 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
576 if (session_state_cmp(it
->data
, cit
->data
))
579 client_calc_layer(self
);
580 stacking_below(CLIENT_AS_WINDOW(self
),
581 CLIENT_AS_WINDOW(cit
->data
));
587 void client_move_onscreen(ObClient
*self
, gboolean rude
)
589 int x
= self
->area
.x
;
590 int y
= self
->area
.y
;
591 if (client_find_onscreen(self
, &x
, &y
,
592 self
->frame
->area
.width
,
593 self
->frame
->area
.height
, rude
)) {
594 client_move(self
, x
, y
);
598 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
602 int ox
= *x
, oy
= *y
;
604 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
607 /* XXX watch for xinerama dead areas */
609 a
= screen_area(self
->desktop
);
610 if (client_normal(self
)) {
611 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
612 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
613 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
614 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
615 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
617 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
622 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
623 Java can suck it too. */
625 /* dont let windows map/move into the strut unless they
626 are bigger than the available area */
628 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
629 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
630 *x
= a
->x
+ a
->width
- w
;
632 if (h
<= a
->height
) {
633 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
634 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
635 *y
= a
->y
+ a
->height
- h
;
639 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
642 return ox
!= *x
|| oy
!= *y
;
645 static void client_toggle_border(ObClient
*self
, gboolean show
)
647 /* adjust our idea of where the client is, based on its border. When the
648 border is removed, the client should now be considered to be in a
650 when re-adding the border to the client, the same operation needs to be
652 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
653 int x
= oldx
, y
= oldy
;
654 switch(self
->gravity
) {
656 case NorthWestGravity
:
658 case SouthWestGravity
:
660 case NorthEastGravity
:
662 case SouthEastGravity
:
663 if (show
) x
-= self
->border_width
* 2;
664 else x
+= self
->border_width
* 2;
671 if (show
) x
-= self
->border_width
;
672 else x
+= self
->border_width
;
675 switch(self
->gravity
) {
677 case NorthWestGravity
:
679 case NorthEastGravity
:
681 case SouthWestGravity
:
683 case SouthEastGravity
:
684 if (show
) y
-= self
->border_width
* 2;
685 else y
+= self
->border_width
* 2;
692 if (show
) y
-= self
->border_width
;
693 else y
+= self
->border_width
;
700 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
702 /* move the client so it is back it the right spot _with_ its
704 if (x
!= oldx
|| y
!= oldy
)
705 XMoveWindow(ob_display
, self
->window
, x
, y
);
707 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
711 static void client_get_all(ObClient
*self
)
713 client_get_area(self
);
714 client_update_transient_for(self
);
715 client_update_wmhints(self
);
716 client_get_startup_id(self
);
717 client_get_desktop(self
);
718 client_get_state(self
);
719 client_get_shaped(self
);
721 client_get_mwm_hints(self
);
722 client_get_type(self
);/* this can change the mwmhints for special cases */
725 /* a couple type-based defaults for new windows */
727 /* this makes sure that these windows appear on all desktops */
728 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
729 self
->desktop
= DESKTOP_ALL
;
731 /* dock windows default to ABOVE */
732 if (self
->type
== OB_CLIENT_TYPE_DOCK
&& !self
->below
)
736 client_update_protocols(self
);
738 client_get_gravity(self
); /* get the attribute gravity */
739 client_update_normal_hints(self
); /* this may override the attribute
742 /* got the type, the mwmhints, the protocols, and the normal hints
743 (min/max sizes), so we're ready to set up the decorations/functions */
744 client_setup_decor_and_functions(self
);
746 client_update_title(self
);
747 client_update_class(self
);
748 client_update_sm_client_id(self
);
749 client_update_strut(self
);
750 client_update_icons(self
);
753 static void client_get_startup_id(ObClient
*self
)
755 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
757 PROP_GETS(self
->group
->leader
,
758 net_startup_id
, utf8
, &self
->startup_id
);
761 static void client_get_area(ObClient
*self
)
763 XWindowAttributes wattrib
;
766 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
767 g_assert(ret
!= BadWindow
);
769 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
770 self
->border_width
= wattrib
.border_width
;
773 static void client_get_desktop(ObClient
*self
)
775 guint32 d
= screen_num_desktops
; /* an always-invalid value */
777 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
778 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
779 self
->desktop
= screen_num_desktops
- 1;
783 gboolean trdesk
= FALSE
;
785 if (self
->transient_for
) {
786 if (self
->transient_for
!= OB_TRAN_GROUP
) {
787 self
->desktop
= self
->transient_for
->desktop
;
792 for (it
= self
->group
->members
; it
; it
= it
->next
)
793 if (it
->data
!= self
&&
794 !((ObClient
*)it
->data
)->transient_for
) {
795 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
802 /* try get from the startup-notification protocol */
803 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
804 if (self
->desktop
>= screen_num_desktops
&&
805 self
->desktop
!= DESKTOP_ALL
)
806 self
->desktop
= screen_num_desktops
- 1;
808 /* defaults to the current desktop */
809 self
->desktop
= screen_desktop
;
812 if (self
->desktop
!= d
) {
813 /* set the desktop hint, to make sure that it always exists */
814 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
818 static void client_get_state(ObClient
*self
)
823 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
825 for (i
= 0; i
< num
; ++i
) {
826 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
828 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
830 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
832 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
833 self
->skip_taskbar
= TRUE
;
834 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
835 self
->skip_pager
= TRUE
;
836 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
837 self
->fullscreen
= TRUE
;
838 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
839 self
->max_vert
= TRUE
;
840 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
841 self
->max_horz
= TRUE
;
842 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
844 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
846 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
847 self
->undecorated
= TRUE
;
853 if (!(self
->above
|| self
->below
)) {
854 if (client_has_group_siblings(self
)) {
855 /* apply stuff from the group */
859 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
860 ObClient
*c
= it
->data
;
861 if (c
!= self
&& !client_search_transient(self
, c
))
863 (c
->above
? 1 : (c
->below
? -1 : 0)));
875 g_assert_not_reached();
882 static void client_get_shaped(ObClient
*self
)
884 self
->shaped
= FALSE
;
886 if (extensions_shape
) {
891 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
893 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
894 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
896 self
->shaped
= (s
!= 0);
901 void client_update_transient_for(ObClient
*self
)
904 ObClient
*target
= NULL
;
906 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
907 self
->transient
= TRUE
;
908 if (t
!= self
->window
) { /* cant be transient to itself! */
909 target
= g_hash_table_lookup(window_map
, &t
);
910 /* if this happens then we need to check for it*/
911 g_assert(target
!= self
);
912 if (target
&& !WINDOW_IS_CLIENT(target
)) {
913 /* this can happen when a dialog is a child of
914 a dockapp, for example */
918 if (!target
&& self
->group
) {
919 /* not transient to a client, see if it is transient for a
921 if (t
== self
->group
->leader
||
923 t
== RootWindow(ob_display
, ob_screen
))
925 /* window is a transient for its group! */
926 target
= OB_TRAN_GROUP
;
931 self
->transient
= FALSE
;
933 /* if anything has changed... */
934 if (target
!= self
->transient_for
) {
935 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
938 /* remove from old parents */
939 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
940 ObClient
*c
= it
->data
;
941 if (c
!= self
&& !c
->transient_for
)
942 c
->transients
= g_slist_remove(c
->transients
, self
);
944 } else if (self
->transient_for
!= NULL
) { /* transient of window */
945 /* remove from old parent */
946 self
->transient_for
->transients
=
947 g_slist_remove(self
->transient_for
->transients
, self
);
949 self
->transient_for
= target
;
950 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
953 /* add to new parents */
954 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
955 ObClient
*c
= it
->data
;
956 if (c
!= self
&& !c
->transient_for
)
957 c
->transients
= g_slist_append(c
->transients
, self
);
960 /* remove all transients which are in the group, that causes
961 circlular pointer hell of doom */
962 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
964 for (sit
= self
->transients
; sit
; sit
= next
) {
965 next
= g_slist_next(sit
);
966 if (sit
->data
== it
->data
)
968 g_slist_delete_link(self
->transients
, sit
);
971 } else if (self
->transient_for
!= NULL
) { /* transient of window */
972 /* add to new parent */
973 self
->transient_for
->transients
=
974 g_slist_append(self
->transient_for
->transients
, self
);
979 static void client_get_mwm_hints(ObClient
*self
)
984 self
->mwmhints
.flags
= 0; /* default to none */
986 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
988 if (num
>= OB_MWM_ELEMENTS
) {
989 self
->mwmhints
.flags
= hints
[0];
990 self
->mwmhints
.functions
= hints
[1];
991 self
->mwmhints
.decorations
= hints
[2];
997 void client_get_type(ObClient
*self
)
1004 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1005 /* use the first value that we know about in the array */
1006 for (i
= 0; i
< num
; ++i
) {
1007 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1008 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1009 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1010 self
->type
= OB_CLIENT_TYPE_DOCK
;
1011 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1012 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1013 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1014 self
->type
= OB_CLIENT_TYPE_MENU
;
1015 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1016 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1017 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1018 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1019 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1020 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1021 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1022 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1023 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1024 /* prevent this window from getting any decor or
1026 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1027 OB_MWM_FLAG_DECORATIONS
);
1028 self
->mwmhints
.decorations
= 0;
1029 self
->mwmhints
.functions
= 0;
1031 if (self
->type
!= (ObClientType
) -1)
1032 break; /* grab the first legit type */
1037 if (self
->type
== (ObClientType
) -1) {
1038 /*the window type hint was not set, which means we either classify
1039 ourself as a normal window or a dialog, depending on if we are a
1041 if (self
->transient
)
1042 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1044 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1048 void client_update_protocols(ObClient
*self
)
1051 guint num_return
, i
;
1053 self
->focus_notify
= FALSE
;
1054 self
->delete_window
= FALSE
;
1056 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1057 for (i
= 0; i
< num_return
; ++i
) {
1058 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1059 /* this means we can request the window to close */
1060 self
->delete_window
= TRUE
;
1061 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1062 /* if this protocol is requested, then the window will be
1063 notified whenever we want it to receive focus */
1064 self
->focus_notify
= TRUE
;
1070 static void client_get_gravity(ObClient
*self
)
1072 XWindowAttributes wattrib
;
1075 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1076 g_assert(ret
!= BadWindow
);
1077 self
->gravity
= wattrib
.win_gravity
;
1080 void client_update_normal_hints(ObClient
*self
)
1084 int oldgravity
= self
->gravity
;
1087 self
->min_ratio
= 0.0f
;
1088 self
->max_ratio
= 0.0f
;
1089 SIZE_SET(self
->size_inc
, 1, 1);
1090 SIZE_SET(self
->base_size
, 0, 0);
1091 SIZE_SET(self
->min_size
, 0, 0);
1092 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1094 /* get the hints from the window */
1095 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1096 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1098 if (size
.flags
& PWinGravity
) {
1099 self
->gravity
= size
.win_gravity
;
1101 /* if the client has a frame, i.e. has already been mapped and
1102 is changing its gravity */
1103 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1104 /* move our idea of the client's position based on its new
1106 self
->area
.x
= self
->frame
->area
.x
;
1107 self
->area
.y
= self
->frame
->area
.y
;
1108 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1112 if (size
.flags
& PAspect
) {
1113 if (size
.min_aspect
.y
)
1114 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1115 if (size
.max_aspect
.y
)
1116 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1119 if (size
.flags
& PMinSize
)
1120 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1122 if (size
.flags
& PMaxSize
)
1123 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1125 if (size
.flags
& PBaseSize
)
1126 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1128 if (size
.flags
& PResizeInc
)
1129 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1133 void client_setup_decor_and_functions(ObClient
*self
)
1135 /* start with everything (cept fullscreen) */
1137 (OB_FRAME_DECOR_TITLEBAR
|
1138 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1139 OB_FRAME_DECOR_GRIPS
|
1140 OB_FRAME_DECOR_BORDER
|
1141 OB_FRAME_DECOR_ICON
|
1142 OB_FRAME_DECOR_ALLDESKTOPS
|
1143 OB_FRAME_DECOR_ICONIFY
|
1144 OB_FRAME_DECOR_MAXIMIZE
|
1145 OB_FRAME_DECOR_SHADE
|
1146 OB_FRAME_DECOR_CLOSE
);
1148 (OB_CLIENT_FUNC_RESIZE
|
1149 OB_CLIENT_FUNC_MOVE
|
1150 OB_CLIENT_FUNC_ICONIFY
|
1151 OB_CLIENT_FUNC_MAXIMIZE
|
1152 OB_CLIENT_FUNC_SHADE
|
1153 OB_CLIENT_FUNC_CLOSE
);
1155 if (!(self
->min_size
.width
< self
->max_size
.width
||
1156 self
->min_size
.height
< self
->max_size
.height
))
1157 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1159 switch (self
->type
) {
1160 case OB_CLIENT_TYPE_NORMAL
:
1161 /* normal windows retain all of the possible decorations and
1162 functionality, and are the only windows that you can fullscreen */
1163 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1166 case OB_CLIENT_TYPE_DIALOG
:
1167 case OB_CLIENT_TYPE_UTILITY
:
1168 /* these windows cannot be maximized */
1169 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1172 case OB_CLIENT_TYPE_MENU
:
1173 case OB_CLIENT_TYPE_TOOLBAR
:
1174 /* these windows get less functionality */
1175 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1178 case OB_CLIENT_TYPE_DESKTOP
:
1179 case OB_CLIENT_TYPE_DOCK
:
1180 case OB_CLIENT_TYPE_SPLASH
:
1181 /* none of these windows are manipulated by the window manager */
1182 self
->decorations
= 0;
1183 self
->functions
= 0;
1187 /* Mwm Hints are applied subtractively to what has already been chosen for
1188 decor and functionality */
1189 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1190 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1191 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1192 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1193 /* if the mwm hints request no handle or title, then all
1194 decorations are disabled */
1195 self
->decorations
= 0;
1199 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1200 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1201 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1202 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1203 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1204 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1205 /* dont let mwm hints kill any buttons
1206 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1207 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1208 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1209 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1211 /* dont let mwm hints kill the close button
1212 if (! (self->mwmhints.functions & MwmFunc_Close))
1213 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1217 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1218 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1219 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1220 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1221 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1222 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1224 /* can't maximize without moving/resizing */
1225 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1226 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1227 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1228 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1229 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1232 /* kill the handle on fully maxed windows */
1233 if (self
->max_vert
&& self
->max_horz
)
1234 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1236 /* finally, the user can have requested no decorations, which overrides
1237 everything (but doesnt give it a border if it doesnt have one) */
1238 if (self
->undecorated
)
1239 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1241 /* if we don't have a titlebar, then we cannot shade! */
1242 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1243 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1245 /* now we need to check against rules for the client's current state */
1246 if (self
->fullscreen
) {
1247 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1248 OB_CLIENT_FUNC_FULLSCREEN
|
1249 OB_CLIENT_FUNC_ICONIFY
);
1250 self
->decorations
= 0;
1253 client_change_allowed_actions(self
);
1256 /* adjust the client's decorations, etc. */
1257 client_reconfigure(self
);
1261 static void client_change_allowed_actions(ObClient
*self
)
1266 /* desktop windows are kept on all desktops */
1267 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1268 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1270 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1271 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1272 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1273 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1274 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1275 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1276 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1277 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1278 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1279 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1280 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1281 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1282 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1283 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1284 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1287 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1289 /* make sure the window isn't breaking any rules now */
1291 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1292 if (self
->frame
) client_shade(self
, FALSE
);
1293 else self
->shaded
= FALSE
;
1295 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1296 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1297 else self
->iconic
= FALSE
;
1299 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1300 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1301 else self
->fullscreen
= FALSE
;
1303 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1305 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1306 else self
->max_vert
= self
->max_horz
= FALSE
;
1310 void client_reconfigure(ObClient
*self
)
1312 /* by making this pass FALSE for user, we avoid the emacs event storm where
1313 every configurenotify causes an update in its normal hints, i think this
1314 is generally what we want anyways... */
1315 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1316 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1319 void client_update_wmhints(ObClient
*self
)
1322 gboolean ur
= FALSE
;
1325 /* assume a window takes input if it doesnt specify */
1326 self
->can_focus
= TRUE
;
1328 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1329 if (hints
->flags
& InputHint
)
1330 self
->can_focus
= hints
->input
;
1332 /* only do this when first managing the window *AND* when we aren't
1334 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1335 if (hints
->flags
& StateHint
)
1336 self
->iconic
= hints
->initial_state
== IconicState
;
1338 if (hints
->flags
& XUrgencyHint
)
1341 if (!(hints
->flags
& WindowGroupHint
))
1342 hints
->window_group
= None
;
1344 /* did the group state change? */
1345 if (hints
->window_group
!=
1346 (self
->group
? self
->group
->leader
: None
)) {
1347 /* remove from the old group if there was one */
1348 if (self
->group
!= NULL
) {
1349 /* remove transients of the group */
1350 for (it
= self
->group
->members
; it
; it
= it
->next
)
1351 self
->transients
= g_slist_remove(self
->transients
,
1354 /* remove myself from parents in the group */
1355 if (self
->transient_for
== OB_TRAN_GROUP
) {
1356 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1357 ObClient
*c
= it
->data
;
1359 if (c
!= self
&& !c
->transient_for
)
1360 c
->transients
= g_slist_remove(c
->transients
,
1365 group_remove(self
->group
, self
);
1368 if (hints
->window_group
!= None
) {
1369 self
->group
= group_add(hints
->window_group
, self
);
1371 /* i can only have transients from the group if i am not
1373 if (!self
->transient_for
) {
1374 /* add other transients of the group that are already
1376 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1377 ObClient
*c
= it
->data
;
1378 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1380 g_slist_append(self
->transients
, c
);
1385 /* because the self->transient flag wont change from this call,
1386 we don't need to update the window's type and such, only its
1387 transient_for, and the transients lists of other windows in
1388 the group may be affected */
1389 client_update_transient_for(self
);
1392 /* the WM_HINTS can contain an icon */
1393 client_update_icons(self
);
1398 if (ur
!= self
->urgent
) {
1400 /* fire the urgent callback if we're mapped, otherwise, wait until
1401 after we're mapped */
1403 client_urgent_notify(self
);
1407 void client_update_title(ObClient
*self
)
1413 gboolean read_title
;
1416 old_title
= self
->title
;
1419 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1420 /* try old x stuff */
1421 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1422 data
= g_strdup("Unnamed Window");
1424 /* did the title change? then reset the title_count */
1425 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1426 self
->title_count
= 1;
1428 /* look for duplicates and append a number */
1430 for (it
= client_list
; it
; it
= it
->next
)
1431 if (it
->data
!= self
) {
1432 ObClient
*c
= it
->data
;
1433 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1434 nums
|= 1 << c
->title_count
;
1436 /* find first free number */
1437 for (i
= 1; i
<= 32; ++i
)
1438 if (!(nums
& (1 << i
))) {
1439 if (self
->title_count
== 1 || i
== 1)
1440 self
->title_count
= i
;
1443 /* dont display the number for the first window */
1444 if (self
->title_count
> 1) {
1446 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1451 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1456 frame_adjust_title(self
->frame
);
1460 /* update the icon title */
1462 g_free(self
->icon_title
);
1466 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1467 /* try old x stuff */
1468 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1469 data
= g_strdup(self
->title
);
1473 /* append the title count, dont display the number for the first window */
1474 if (read_title
&& self
->title_count
> 1) {
1475 char *vdata
, *ndata
;
1476 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1477 vdata
= g_strconcat(data
, ndata
, NULL
);
1483 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1485 self
->icon_title
= data
;
1488 void client_update_class(ObClient
*self
)
1493 if (self
->name
) g_free(self
->name
);
1494 if (self
->class) g_free(self
->class);
1495 if (self
->role
) g_free(self
->role
);
1497 self
->name
= self
->class = self
->role
= NULL
;
1499 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1501 self
->name
= g_strdup(data
[0]);
1503 self
->class = g_strdup(data
[1]);
1508 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1511 if (self
->name
== NULL
) self
->name
= g_strdup("");
1512 if (self
->class == NULL
) self
->class = g_strdup("");
1513 if (self
->role
== NULL
) self
->role
= g_strdup("");
1516 void client_update_strut(ObClient
*self
)
1520 gboolean got
= FALSE
;
1523 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1527 STRUT_PARTIAL_SET(strut
,
1528 data
[0], data
[2], data
[1], data
[3],
1529 data
[4], data
[5], data
[8], data
[9],
1530 data
[6], data
[7], data
[10], data
[11]);
1536 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1539 STRUT_PARTIAL_SET(strut
,
1540 data
[0], data
[2], data
[1], data
[3],
1541 0, 0, 0, 0, 0, 0, 0, 0);
1547 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1548 0, 0, 0, 0, 0, 0, 0, 0);
1550 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1551 self
->strut
= strut
;
1553 /* updating here is pointless while we're being mapped cuz we're not in
1554 the client list yet */
1556 screen_update_areas();
1560 void client_update_icons(ObClient
*self
)
1566 for (i
= 0; i
< self
->nicons
; ++i
)
1567 g_free(self
->icons
[i
].data
);
1568 if (self
->nicons
> 0)
1569 g_free(self
->icons
);
1572 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1573 /* figure out how many valid icons are in here */
1575 while (num
- i
> 2) {
1579 if (i
> num
|| w
*h
== 0) break;
1583 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1585 /* store the icons */
1587 for (j
= 0; j
< self
->nicons
; ++j
) {
1590 w
= self
->icons
[j
].width
= data
[i
++];
1591 h
= self
->icons
[j
].height
= data
[i
++];
1593 if (w
*h
== 0) continue;
1595 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1596 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1601 self
->icons
[j
].data
[t
] =
1602 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1603 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1604 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1605 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1611 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1612 kwm_win_icon
, &data
, &num
)) {
1615 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1616 xerror_set_ignore(TRUE
);
1617 if (!RrPixmapToRGBA(ob_rr_inst
,
1619 &self
->icons
[self
->nicons
-1].width
,
1620 &self
->icons
[self
->nicons
-1].height
,
1621 &self
->icons
[self
->nicons
-1].data
)) {
1622 g_free(&self
->icons
[self
->nicons
-1]);
1625 xerror_set_ignore(FALSE
);
1631 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1632 if (hints
->flags
& IconPixmapHint
) {
1634 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1635 xerror_set_ignore(TRUE
);
1636 if (!RrPixmapToRGBA(ob_rr_inst
,
1638 (hints
->flags
& IconMaskHint
?
1639 hints
->icon_mask
: None
),
1640 &self
->icons
[self
->nicons
-1].width
,
1641 &self
->icons
[self
->nicons
-1].height
,
1642 &self
->icons
[self
->nicons
-1].data
)){
1643 g_free(&self
->icons
[self
->nicons
-1]);
1646 xerror_set_ignore(FALSE
);
1653 frame_adjust_icon(self
->frame
);
1656 static void client_change_state(ObClient
*self
)
1659 guint32 netstate
[11];
1662 state
[0] = self
->wmstate
;
1664 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1668 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1670 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1672 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1673 if (self
->skip_taskbar
)
1674 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1675 if (self
->skip_pager
)
1676 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1677 if (self
->fullscreen
)
1678 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1680 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1682 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1684 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1686 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1687 if (self
->undecorated
)
1688 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1689 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1691 client_calc_layer(self
);
1694 frame_adjust_state(self
->frame
);
1697 ObClient
*client_search_focus_tree(ObClient
*self
)
1702 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1703 if (client_focused(it
->data
)) return it
->data
;
1704 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1709 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1711 if (self
->transient_for
) {
1712 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1713 return client_search_focus_tree_full(self
->transient_for
);
1716 gboolean recursed
= FALSE
;
1718 for (it
= self
->group
->members
; it
; it
= it
->next
)
1719 if (!((ObClient
*)it
->data
)->transient_for
) {
1721 if ((c
= client_search_focus_tree_full(it
->data
)))
1730 /* this function checks the whole tree, the client_search_focus_tree~
1731 does not, so we need to check this window */
1732 if (client_focused(self
))
1734 return client_search_focus_tree(self
);
1737 static ObStackingLayer
calc_layer(ObClient
*self
)
1741 if (self
->fullscreen
&&
1742 (client_focused(self
) || client_search_focus_tree(self
)))
1743 l
= OB_STACKING_LAYER_FULLSCREEN
;
1744 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1745 l
= OB_STACKING_LAYER_DESKTOP
;
1746 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1747 if (self
->above
) l
= OB_STACKING_LAYER_DOCK_ABOVE
;
1748 else if (self
->below
) l
= OB_STACKING_LAYER_DOCK_BELOW
;
1749 else l
= OB_STACKING_LAYER_NORMAL
;
1751 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1752 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1753 else l
= OB_STACKING_LAYER_NORMAL
;
1758 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1759 ObStackingLayer l
, gboolean raised
)
1761 ObStackingLayer old
, own
;
1765 own
= calc_layer(self
);
1766 self
->layer
= l
> own
? l
: own
;
1768 for (it
= self
->transients
; it
; it
= it
->next
)
1769 client_calc_layer_recursive(it
->data
, orig
,
1770 l
, raised
? raised
: l
!= old
);
1772 if (!raised
&& l
!= old
)
1773 if (orig
->frame
) { /* only restack if the original window is managed */
1774 stacking_remove(CLIENT_AS_WINDOW(self
));
1775 stacking_add(CLIENT_AS_WINDOW(self
));
1779 void client_calc_layer(ObClient
*self
)
1786 /* transients take on the layer of their parents */
1787 self
= client_search_top_transient(self
);
1789 l
= calc_layer(self
);
1791 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1794 gboolean
client_should_show(ObClient
*self
)
1796 if (self
->iconic
) return FALSE
;
1797 else if (!(self
->desktop
== screen_desktop
||
1798 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1799 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1804 static void client_showhide(ObClient
*self
)
1807 if (client_should_show(self
))
1808 frame_show(self
->frame
);
1810 frame_hide(self
->frame
);
1813 gboolean
client_normal(ObClient
*self
) {
1814 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1815 self
->type
== OB_CLIENT_TYPE_DOCK
||
1816 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1819 static void client_apply_startup_state(ObClient
*self
)
1821 /* these are in a carefully crafted order.. */
1824 self
->iconic
= FALSE
;
1825 client_iconify(self
, TRUE
, FALSE
);
1827 if (self
->fullscreen
) {
1828 self
->fullscreen
= FALSE
;
1829 client_fullscreen(self
, TRUE
, FALSE
);
1831 if (self
->undecorated
) {
1832 self
->undecorated
= FALSE
;
1833 client_set_undecorated(self
, TRUE
);
1836 self
->shaded
= FALSE
;
1837 client_shade(self
, TRUE
);
1840 client_urgent_notify(self
);
1842 if (self
->max_vert
&& self
->max_horz
) {
1843 self
->max_vert
= self
->max_horz
= FALSE
;
1844 client_maximize(self
, TRUE
, 0, FALSE
);
1845 } else if (self
->max_vert
) {
1846 self
->max_vert
= FALSE
;
1847 client_maximize(self
, TRUE
, 2, FALSE
);
1848 } else if (self
->max_horz
) {
1849 self
->max_horz
= FALSE
;
1850 client_maximize(self
, TRUE
, 1, FALSE
);
1853 /* nothing to do for the other states:
1862 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1863 int x
, int y
, int w
, int h
,
1864 gboolean user
, gboolean final
,
1865 gboolean force_reply
)
1868 gboolean send_resize_client
;
1869 gboolean moved
= FALSE
, resized
= FALSE
;
1870 guint fdecor
= self
->frame
->decorations
;
1871 gboolean fhorz
= self
->frame
->max_horz
;
1873 /* make the frame recalculate its dimentions n shit without changing
1874 anything visible for real, this way the constraints below can work with
1875 the updated frame dimensions. */
1876 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1878 /* gets the frame's position */
1879 frame_client_gravity(self
->frame
, &x
, &y
);
1881 /* these positions are frame positions, not client positions */
1883 /* set the size and position if fullscreen */
1884 if (self
->fullscreen
) {
1887 XF86VidModeModeLine mode
;
1892 i
= client_monitor(self
);
1893 a
= screen_physical_area_monitor(i
);
1896 if (i
== 0 && /* primary head */
1897 extensions_vidmode
&&
1898 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1899 /* get the mode last so the mode.privsize isnt freed incorrectly */
1900 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1905 if (mode
.privsize
) XFree(mode
.private);
1915 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1919 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1921 /* set the size and position if maximized */
1922 if (self
->max_horz
) {
1924 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1926 if (self
->max_vert
) {
1928 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1932 /* gets the client's position */
1933 frame_frame_gravity(self
->frame
, &x
, &y
);
1935 /* these override the above states! if you cant move you can't move! */
1937 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1941 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1942 w
= self
->area
.width
;
1943 h
= self
->area
.height
;
1947 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1948 int basew
, baseh
, minw
, minh
;
1950 /* base size is substituted with min size if not specified */
1951 if (self
->base_size
.width
|| self
->base_size
.height
) {
1952 basew
= self
->base_size
.width
;
1953 baseh
= self
->base_size
.height
;
1955 basew
= self
->min_size
.width
;
1956 baseh
= self
->min_size
.height
;
1958 /* min size is substituted with base size if not specified */
1959 if (self
->min_size
.width
|| self
->min_size
.height
) {
1960 minw
= self
->min_size
.width
;
1961 minh
= self
->min_size
.height
;
1963 minw
= self
->base_size
.width
;
1964 minh
= self
->base_size
.height
;
1967 /* if this is a user-requested resize, then check against min/max
1970 /* smaller than min size or bigger than max size? */
1971 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1972 if (w
< minw
) w
= minw
;
1973 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1974 if (h
< minh
) h
= minh
;
1979 /* keep to the increments */
1980 w
/= self
->size_inc
.width
;
1981 h
/= self
->size_inc
.height
;
1983 /* you cannot resize to nothing */
1984 if (basew
+ w
< 1) w
= 1 - basew
;
1985 if (baseh
+ h
< 1) h
= 1 - baseh
;
1987 /* store the logical size */
1988 SIZE_SET(self
->logical_size
,
1989 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1990 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1992 w
*= self
->size_inc
.width
;
1993 h
*= self
->size_inc
.height
;
1998 /* adjust the height to match the width for the aspect ratios.
1999 for this, min size is not substituted for base size ever. */
2000 w
-= self
->base_size
.width
;
2001 h
-= self
->base_size
.height
;
2003 if (self
->min_ratio
)
2004 if (h
* self
->min_ratio
> w
) {
2005 h
= (int)(w
/ self
->min_ratio
);
2007 /* you cannot resize to nothing */
2010 w
= (int)(h
* self
->min_ratio
);
2013 if (self
->max_ratio
)
2014 if (h
* self
->max_ratio
< w
) {
2015 h
= (int)(w
/ self
->max_ratio
);
2017 /* you cannot resize to nothing */
2020 w
= (int)(h
* self
->min_ratio
);
2024 w
+= self
->base_size
.width
;
2025 h
+= self
->base_size
.height
;
2032 case OB_CORNER_TOPLEFT
:
2034 case OB_CORNER_TOPRIGHT
:
2035 x
-= w
- self
->area
.width
;
2037 case OB_CORNER_BOTTOMLEFT
:
2038 y
-= h
- self
->area
.height
;
2040 case OB_CORNER_BOTTOMRIGHT
:
2041 x
-= w
- self
->area
.width
;
2042 y
-= h
- self
->area
.height
;
2046 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2047 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2049 oldw
= self
->area
.width
;
2050 oldh
= self
->area
.height
;
2051 RECT_SET(self
->area
, x
, y
, w
, h
);
2053 /* for app-requested resizes, always resize if 'resized' is true.
2054 for user-requested ones, only resize if final is true, or when
2055 resizing in redraw mode */
2056 send_resize_client
= ((!user
&& resized
) ||
2058 (resized
&& config_redraw_resize
))));
2060 /* if the client is enlarging, the resize the client before the frame */
2061 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2062 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2064 /* move/resize the frame to match the request */
2066 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2067 moved
= resized
= TRUE
;
2069 if (moved
|| resized
)
2070 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2072 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2075 event
.type
= ConfigureNotify
;
2076 event
.xconfigure
.display
= ob_display
;
2077 event
.xconfigure
.event
= self
->window
;
2078 event
.xconfigure
.window
= self
->window
;
2080 /* root window real coords */
2081 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2083 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2085 event
.xconfigure
.width
= w
;
2086 event
.xconfigure
.height
= h
;
2087 event
.xconfigure
.border_width
= 0;
2088 event
.xconfigure
.above
= self
->frame
->plate
;
2089 event
.xconfigure
.override_redirect
= FALSE
;
2090 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2091 FALSE
, StructureNotifyMask
, &event
);
2095 /* if the client is shrinking, then resize the frame before the client */
2096 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2097 XResizeWindow(ob_display
, self
->window
, w
, h
);
2102 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2106 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2107 self
->fullscreen
== fs
) return; /* already done */
2109 self
->fullscreen
= fs
;
2110 client_change_state(self
); /* change the state hints on the client,
2111 and adjust out layer/stacking */
2115 self
->pre_fullscreen_area
= self
->area
;
2117 /* these are not actually used cuz client_configure will set them
2118 as appropriate when the window is fullscreened */
2123 if (self
->pre_fullscreen_area
.width
> 0 &&
2124 self
->pre_fullscreen_area
.height
> 0)
2126 x
= self
->pre_fullscreen_area
.x
;
2127 y
= self
->pre_fullscreen_area
.y
;
2128 w
= self
->pre_fullscreen_area
.width
;
2129 h
= self
->pre_fullscreen_area
.height
;
2130 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2132 /* pick some fallbacks... */
2133 a
= screen_area_monitor(self
->desktop
, 0);
2134 x
= a
->x
+ a
->width
/ 4;
2135 y
= a
->y
+ a
->height
/ 4;
2141 client_setup_decor_and_functions(self
);
2143 client_move_resize(self
, x
, y
, w
, h
);
2145 /* try focus us when we go into fullscreen mode */
2149 static void client_iconify_recursive(ObClient
*self
,
2150 gboolean iconic
, gboolean curdesk
)
2153 gboolean changed
= FALSE
;
2156 if (self
->iconic
!= iconic
) {
2157 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2160 self
->iconic
= iconic
;
2163 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2166 old
= self
->wmstate
;
2167 self
->wmstate
= IconicState
;
2168 if (old
!= self
->wmstate
)
2169 PROP_MSG(self
->window
, kde_wm_change_state
,
2170 self
->wmstate
, 1, 0, 0);
2172 self
->ignore_unmaps
++;
2173 /* we unmap the client itself so that we can get MapRequest
2174 events, and because the ICCCM tells us to! */
2175 XUnmapWindow(ob_display
, self
->window
);
2177 /* update the focus lists.. iconic windows go to the bottom of
2178 the list, put the new iconic window at the 'top of the
2180 focus_order_to_top(self
);
2188 client_set_desktop(self
, screen_desktop
, FALSE
);
2190 old
= self
->wmstate
;
2191 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2192 if (old
!= self
->wmstate
)
2193 PROP_MSG(self
->window
, kde_wm_change_state
,
2194 self
->wmstate
, 1, 0, 0);
2196 XMapWindow(ob_display
, self
->window
);
2198 /* this puts it after the current focused window */
2199 focus_order_remove(self
);
2200 focus_order_add_new(self
);
2202 /* this is here cuz with the VIDMODE extension, the viewport can
2203 change while a fullscreen window is iconic, and when it
2204 uniconifies, it would be nice if it did so to the new position
2206 client_reconfigure(self
);
2213 client_change_state(self
);
2214 client_showhide(self
);
2215 screen_update_areas();
2218 /* iconify all transients */
2219 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2220 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2224 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2226 /* move up the transient chain as far as possible first */
2227 self
= client_search_top_transient(self
);
2229 client_iconify_recursive(client_search_top_transient(self
),
2233 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2237 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2238 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2240 /* check if already done */
2242 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2243 if (dir
== 1 && self
->max_horz
) return;
2244 if (dir
== 2 && self
->max_vert
) return;
2246 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2247 if (dir
== 1 && !self
->max_horz
) return;
2248 if (dir
== 2 && !self
->max_vert
) return;
2251 /* we just tell it to configure in the same place and client_configure
2252 worries about filling the screen with the window */
2255 w
= self
->area
.width
;
2256 h
= self
->area
.height
;
2260 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2261 RECT_SET(self
->pre_max_area
,
2262 self
->area
.x
, self
->pre_max_area
.y
,
2263 self
->area
.width
, self
->pre_max_area
.height
);
2265 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2266 RECT_SET(self
->pre_max_area
,
2267 self
->pre_max_area
.x
, self
->area
.y
,
2268 self
->pre_max_area
.width
, self
->area
.height
);
2274 a
= screen_area_monitor(self
->desktop
, 0);
2275 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2276 if (self
->pre_max_area
.width
> 0) {
2277 x
= self
->pre_max_area
.x
;
2278 w
= self
->pre_max_area
.width
;
2280 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2281 0, self
->pre_max_area
.height
);
2283 /* pick some fallbacks... */
2284 x
= a
->x
+ a
->width
/ 4;
2288 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2289 if (self
->pre_max_area
.height
> 0) {
2290 y
= self
->pre_max_area
.y
;
2291 h
= self
->pre_max_area
.height
;
2293 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2294 self
->pre_max_area
.width
, 0);
2296 /* pick some fallbacks... */
2297 y
= a
->y
+ a
->height
/ 4;
2303 if (dir
== 0 || dir
== 1) /* horz */
2304 self
->max_horz
= max
;
2305 if (dir
== 0 || dir
== 2) /* vert */
2306 self
->max_vert
= max
;
2308 client_change_state(self
); /* change the state hints on the client */
2310 client_setup_decor_and_functions(self
);
2312 client_move_resize(self
, x
, y
, w
, h
);
2315 void client_shade(ObClient
*self
, gboolean shade
)
2317 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2318 shade
) || /* can't shade */
2319 self
->shaded
== shade
) return; /* already done */
2321 /* when we're iconic, don't change the wmstate */
2322 if (!self
->iconic
) {
2325 old
= self
->wmstate
;
2326 self
->wmstate
= shade
? IconicState
: NormalState
;
2327 if (old
!= self
->wmstate
)
2328 PROP_MSG(self
->window
, kde_wm_change_state
,
2329 self
->wmstate
, 1, 0, 0);
2332 self
->shaded
= shade
;
2333 client_change_state(self
);
2334 /* resize the frame to just the titlebar */
2335 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2338 void client_close(ObClient
*self
)
2342 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2344 /* in the case that the client provides no means to requesting that it
2345 close, we just kill it */
2346 if (!self
->delete_window
)
2350 XXX: itd be cool to do timeouts and shit here for killing the client's
2352 like... if the window is around after 5 seconds, then the close button
2353 turns a nice red, and if this function is called again, the client is
2357 ce
.xclient
.type
= ClientMessage
;
2358 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2359 ce
.xclient
.display
= ob_display
;
2360 ce
.xclient
.window
= self
->window
;
2361 ce
.xclient
.format
= 32;
2362 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2363 ce
.xclient
.data
.l
[1] = event_lasttime
;
2364 ce
.xclient
.data
.l
[2] = 0l;
2365 ce
.xclient
.data
.l
[3] = 0l;
2366 ce
.xclient
.data
.l
[4] = 0l;
2367 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2370 void client_kill(ObClient
*self
)
2372 XKillClient(ob_display
, self
->window
);
2375 void client_set_desktop_recursive(ObClient
*self
,
2376 guint target
, gboolean donthide
)
2381 if (target
!= self
->desktop
) {
2383 ob_debug("Setting desktop %u\n", target
+1);
2385 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2387 /* remove from the old desktop(s) */
2388 focus_order_remove(self
);
2390 old
= self
->desktop
;
2391 self
->desktop
= target
;
2392 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2393 /* the frame can display the current desktop state */
2394 frame_adjust_state(self
->frame
);
2395 /* 'move' the window to the new desktop */
2397 client_showhide(self
);
2398 /* raise if it was not already on the desktop */
2399 if (old
!= DESKTOP_ALL
)
2401 screen_update_areas();
2403 /* add to the new desktop(s) */
2404 if (config_focus_new
)
2405 focus_order_to_top(self
);
2407 focus_order_to_bottom(self
);
2410 /* move all transients */
2411 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2412 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2416 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2418 client_set_desktop_recursive(client_search_top_transient(self
),
2422 ObClient
*client_search_modal_child(ObClient
*self
)
2427 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2428 ObClient
*c
= it
->data
;
2429 if ((ret
= client_search_modal_child(c
))) return ret
;
2430 if (c
->modal
) return c
;
2435 gboolean
client_validate(ObClient
*self
)
2439 XSync(ob_display
, FALSE
); /* get all events on the server */
2441 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2442 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2443 XPutBackEvent(ob_display
, &e
);
2450 void client_set_wm_state(ObClient
*self
, long state
)
2452 if (state
== self
->wmstate
) return; /* no change */
2456 client_iconify(self
, TRUE
, TRUE
);
2459 client_iconify(self
, FALSE
, TRUE
);
2464 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2466 gboolean shaded
= self
->shaded
;
2467 gboolean fullscreen
= self
->fullscreen
;
2468 gboolean undecorated
= self
->undecorated
;
2469 gboolean max_horz
= self
->max_horz
;
2470 gboolean max_vert
= self
->max_vert
;
2471 gboolean modal
= self
->modal
;
2474 if (!(action
== prop_atoms
.net_wm_state_add
||
2475 action
== prop_atoms
.net_wm_state_remove
||
2476 action
== prop_atoms
.net_wm_state_toggle
))
2477 /* an invalid action was passed to the client message, ignore it */
2480 for (i
= 0; i
< 2; ++i
) {
2481 Atom state
= i
== 0 ? data1
: data2
;
2483 if (!state
) continue;
2485 /* if toggling, then pick whether we're adding or removing */
2486 if (action
== prop_atoms
.net_wm_state_toggle
) {
2487 if (state
== prop_atoms
.net_wm_state_modal
)
2488 action
= modal
? prop_atoms
.net_wm_state_remove
:
2489 prop_atoms
.net_wm_state_add
;
2490 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2491 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2492 prop_atoms
.net_wm_state_add
;
2493 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2494 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2495 prop_atoms
.net_wm_state_add
;
2496 else if (state
== prop_atoms
.net_wm_state_shaded
)
2497 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2498 prop_atoms
.net_wm_state_add
;
2499 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2500 action
= self
->skip_taskbar
?
2501 prop_atoms
.net_wm_state_remove
:
2502 prop_atoms
.net_wm_state_add
;
2503 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2504 action
= self
->skip_pager
?
2505 prop_atoms
.net_wm_state_remove
:
2506 prop_atoms
.net_wm_state_add
;
2507 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2508 action
= fullscreen
?
2509 prop_atoms
.net_wm_state_remove
:
2510 prop_atoms
.net_wm_state_add
;
2511 else if (state
== prop_atoms
.net_wm_state_above
)
2512 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2513 prop_atoms
.net_wm_state_add
;
2514 else if (state
== prop_atoms
.net_wm_state_below
)
2515 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2516 prop_atoms
.net_wm_state_add
;
2517 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2518 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2519 prop_atoms
.net_wm_state_add
;
2522 if (action
== prop_atoms
.net_wm_state_add
) {
2523 if (state
== prop_atoms
.net_wm_state_modal
) {
2525 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2527 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2529 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2531 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2532 self
->skip_taskbar
= TRUE
;
2533 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2534 self
->skip_pager
= TRUE
;
2535 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2537 } else if (state
== prop_atoms
.net_wm_state_above
) {
2539 } else if (state
== prop_atoms
.net_wm_state_below
) {
2541 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2545 } else { /* action == prop_atoms.net_wm_state_remove */
2546 if (state
== prop_atoms
.net_wm_state_modal
) {
2548 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2550 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2552 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2554 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2555 self
->skip_taskbar
= FALSE
;
2556 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2557 self
->skip_pager
= FALSE
;
2558 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2560 } else if (state
== prop_atoms
.net_wm_state_above
) {
2561 self
->above
= FALSE
;
2562 } else if (state
== prop_atoms
.net_wm_state_below
) {
2563 self
->below
= FALSE
;
2564 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2565 undecorated
= FALSE
;
2569 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2570 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2572 if (max_horz
== max_vert
) { /* both going the same way */
2573 client_maximize(self
, max_horz
, 0, TRUE
);
2575 client_maximize(self
, max_horz
, 1, TRUE
);
2576 client_maximize(self
, max_vert
, 2, TRUE
);
2580 if (max_horz
!= self
->max_horz
)
2581 client_maximize(self
, max_horz
, 1, TRUE
);
2583 client_maximize(self
, max_vert
, 2, TRUE
);
2586 /* change fullscreen state before shading, as it will affect if the window
2588 if (fullscreen
!= self
->fullscreen
)
2589 client_fullscreen(self
, fullscreen
, TRUE
);
2590 if (shaded
!= self
->shaded
)
2591 client_shade(self
, shaded
);
2592 if (undecorated
!= self
->undecorated
)
2593 client_set_undecorated(self
, undecorated
);
2594 if (modal
!= self
->modal
) {
2595 self
->modal
= modal
;
2596 /* when a window changes modality, then its stacking order with its
2597 transients needs to change */
2600 client_calc_layer(self
);
2601 client_change_state(self
); /* change the hint to reflect these changes */
2604 ObClient
*client_focus_target(ObClient
*self
)
2608 /* if we have a modal child, then focus it, not us */
2609 child
= client_search_modal_child(client_search_top_transient(self
));
2610 if (child
) return child
;
2614 gboolean
client_can_focus(ObClient
*self
)
2618 /* choose the correct target */
2619 self
= client_focus_target(self
);
2621 if (!self
->frame
->visible
)
2624 if (!(self
->can_focus
|| self
->focus_notify
))
2627 /* do a check to see if the window has already been unmapped or destroyed
2628 do this intelligently while watching out for unmaps we've generated
2629 (ignore_unmaps > 0) */
2630 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2631 DestroyNotify
, &ev
)) {
2632 XPutBackEvent(ob_display
, &ev
);
2635 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2636 UnmapNotify
, &ev
)) {
2637 if (self
->ignore_unmaps
) {
2638 self
->ignore_unmaps
--;
2640 XPutBackEvent(ob_display
, &ev
);
2648 gboolean
client_focus(ObClient
*self
)
2650 /* choose the correct target */
2651 self
= client_focus_target(self
);
2653 if (!client_can_focus(self
)) {
2654 if (!self
->frame
->visible
) {
2655 /* update the focus lists */
2656 focus_order_to_top(self
);
2661 if (self
->can_focus
) {
2662 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2663 I choose to use it always, hopefully to find errors quicker, if any
2664 are left. (I hate X. I hate focus events.)
2666 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2667 #799. So now it is RevertToNone again.
2669 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2673 if (self
->focus_notify
) {
2675 ce
.xclient
.type
= ClientMessage
;
2676 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2677 ce
.xclient
.display
= ob_display
;
2678 ce
.xclient
.window
= self
->window
;
2679 ce
.xclient
.format
= 32;
2680 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2681 ce
.xclient
.data
.l
[1] = event_lasttime
;
2682 ce
.xclient
.data
.l
[2] = 0l;
2683 ce
.xclient
.data
.l
[3] = 0l;
2684 ce
.xclient
.data
.l
[4] = 0l;
2685 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2689 ob_debug("%sively focusing %lx at %d\n",
2690 (self
->can_focus
? "act" : "pass"),
2691 self
->window
, (int) event_lasttime
);
2694 /* Cause the FocusIn to come back to us. Important for desktop switches,
2695 since otherwise we'll have no FocusIn on the queue and send it off to
2696 the focus_backup. */
2697 XSync(ob_display
, FALSE
);
2701 void client_unfocus(ObClient
*self
)
2703 if (focus_client
== self
) {
2705 ob_debug("client_unfocus for %lx\n", self
->window
);
2707 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2711 void client_activate(ObClient
*self
, gboolean here
)
2713 if (client_normal(self
) && screen_showing_desktop
)
2714 screen_show_desktop(FALSE
);
2716 client_iconify(self
, FALSE
, here
);
2717 if (self
->desktop
!= DESKTOP_ALL
&&
2718 self
->desktop
!= screen_desktop
) {
2720 client_set_desktop(self
, screen_desktop
, FALSE
);
2722 screen_set_desktop(self
->desktop
);
2723 } else if (!self
->frame
->visible
)
2724 /* if its not visible for other reasons, then don't mess
2728 client_shade(self
, FALSE
);
2732 /* we do this an action here. this is rather important. this is because
2733 we want the results from the focus change to take place BEFORE we go
2734 about raising the window. when a fullscreen window loses focus, we need
2735 this or else the raise wont be able to raise above the to-lose-focus
2736 fullscreen window. */
2740 void client_raise(ObClient
*self
)
2742 action_run_string("Raise", self
);
2745 void client_lower(ObClient
*self
)
2747 action_run_string("Raise", self
);
2750 gboolean
client_focused(ObClient
*self
)
2752 return self
== focus_client
;
2755 static ObClientIcon
* client_icon_recursive(ObClient
*self
, int w
, int h
)
2758 /* si is the smallest image >= req */
2759 /* li is the largest image < req */
2760 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2762 if (!self
->nicons
) {
2763 ObClientIcon
*parent
= NULL
;
2765 if (self
->transient_for
) {
2766 if (self
->transient_for
!= OB_TRAN_GROUP
)
2767 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2770 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2771 ObClient
*c
= it
->data
;
2772 if (c
!= self
&& !c
->transient_for
) {
2773 if ((parent
= client_icon_recursive(c
, w
, h
)))
2783 for (i
= 0; i
< self
->nicons
; ++i
) {
2784 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2785 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2789 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2794 if (largest
== 0) /* didnt find one smaller than the requested size */
2795 return &self
->icons
[si
];
2796 return &self
->icons
[li
];
2799 const ObClientIcon
* client_icon(ObClient
*self
, int w
, int h
)
2802 static ObClientIcon deficon
;
2804 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2805 deficon
.width
= deficon
.height
= 48;
2806 deficon
.data
= ob_rr_theme
->def_win_icon
;
2812 /* this be mostly ripped from fvwm */
2813 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2815 int my_cx
, my_cy
, his_cx
, his_cy
;
2818 int score
, best_score
;
2819 ObClient
*best_client
, *cur
;
2825 /* first, find the centre coords of the currently focused window */
2826 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2827 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2832 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2835 /* the currently selected window isn't interesting */
2838 if (!client_normal(cur
))
2840 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2844 if(client_focus_target(cur
) == cur
&&
2845 !(cur
->can_focus
|| cur
->focus_notify
))
2848 /* find the centre coords of this window, from the
2849 * currently focused window's point of view */
2850 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2851 + cur
->frame
->area
.width
/ 2;
2852 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2853 + cur
->frame
->area
.height
/ 2;
2855 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2856 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2858 /* Rotate the diagonals 45 degrees counterclockwise.
2859 * To do this, multiply the matrix /+h +h\ with the
2860 * vector (x y). \-h +h/
2861 * h = sqrt(0.5). We can set h := 1 since absolute
2862 * distance doesn't matter here. */
2863 tx
= his_cx
+ his_cy
;
2864 his_cy
= -his_cx
+ his_cy
;
2869 case OB_DIRECTION_NORTH
:
2870 case OB_DIRECTION_SOUTH
:
2871 case OB_DIRECTION_NORTHEAST
:
2872 case OB_DIRECTION_SOUTHWEST
:
2873 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2874 distance
= ((dir
== OB_DIRECTION_NORTH
||
2875 dir
== OB_DIRECTION_NORTHEAST
) ?
2878 case OB_DIRECTION_EAST
:
2879 case OB_DIRECTION_WEST
:
2880 case OB_DIRECTION_SOUTHEAST
:
2881 case OB_DIRECTION_NORTHWEST
:
2882 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2883 distance
= ((dir
== OB_DIRECTION_WEST
||
2884 dir
== OB_DIRECTION_NORTHWEST
) ?
2889 /* the target must be in the requested direction */
2893 /* Calculate score for this window. The smaller the better. */
2894 score
= distance
+ offset
;
2896 /* windows more than 45 degrees off the direction are
2897 * heavily penalized and will only be chosen if nothing
2898 * else within a million pixels */
2899 if(offset
> distance
)
2902 if(best_score
== -1 || score
< best_score
)
2910 void client_set_layer(ObClient
*self
, int layer
)
2914 self
->above
= FALSE
;
2915 } else if (layer
== 0) {
2916 self
->below
= self
->above
= FALSE
;
2918 self
->below
= FALSE
;
2921 client_calc_layer(self
);
2922 client_change_state(self
); /* reflect this in the state hints */
2925 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
2927 if (self
->undecorated
!= undecorated
) {
2928 self
->undecorated
= undecorated
;
2929 client_setup_decor_and_functions(self
);
2930 client_change_state(self
); /* reflect this in the state hints */
2934 guint
client_monitor(ObClient
*self
)
2940 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2941 Rect
*area
= screen_physical_area_monitor(i
);
2942 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
)) {
2946 RECT_SET_INTERSECTION(r
, *area
, self
->frame
->area
);
2947 v
= r
.width
* r
.height
;
2958 ObClient
*client_search_top_transient(ObClient
*self
)
2960 /* move up the transient chain as far as possible */
2961 if (self
->transient_for
) {
2962 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2963 return client_search_top_transient(self
->transient_for
);
2967 g_assert(self
->group
);
2969 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2970 ObClient
*c
= it
->data
;
2972 /* checking transient_for prevents infinate loops! */
2973 if (c
!= self
&& !c
->transient_for
)
2984 ObClient
*client_search_focus_parent(ObClient
*self
)
2986 if (self
->transient_for
) {
2987 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2988 if (client_focused(self
->transient_for
))
2989 return self
->transient_for
;
2993 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2994 ObClient
*c
= it
->data
;
2996 /* checking transient_for prevents infinate loops! */
2997 if (c
!= self
&& !c
->transient_for
)
2998 if (client_focused(c
))
3007 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3009 if (self
->transient_for
) {
3010 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3011 if (self
->transient_for
== search
)
3016 for (it
= self
->group
->members
; it
; it
= it
->next
) {
3017 ObClient
*c
= it
->data
;
3019 /* checking transient_for prevents infinate loops! */
3020 if (c
!= self
&& !c
->transient_for
)
3030 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3034 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3035 if (sit
->data
== search
)
3037 if (client_search_transient(sit
->data
, search
))
3043 void client_update_sm_client_id(ObClient
*self
)
3045 g_free(self
->sm_client_id
);
3046 self
->sm_client_id
= NULL
;
3048 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3050 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3051 &self
->sm_client_id
);
3054 /* finds the nearest edge in the given direction from the current client
3055 * note to self: the edge is the -frame- edge (the actual one), not the
3058 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3061 int my_edge_start
, my_edge_end
, my_offset
;
3068 a
= screen_area(c
->desktop
);
3071 case OB_DIRECTION_NORTH
:
3072 my_edge_start
= c
->frame
->area
.x
;
3073 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3074 my_offset
= c
->frame
->area
.y
;
3076 /* default: top of screen */
3079 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3080 int his_edge_start
, his_edge_end
, his_offset
;
3081 ObClient
*cur
= it
->data
;
3085 if(!client_normal(cur
))
3087 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3092 his_edge_start
= cur
->frame
->area
.x
;
3093 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3094 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3096 if(his_offset
+ 1 > my_offset
)
3099 if(his_offset
< dest
)
3102 if(his_edge_start
>= my_edge_start
&&
3103 his_edge_start
<= my_edge_end
)
3106 if(my_edge_start
>= his_edge_start
&&
3107 my_edge_start
<= his_edge_end
)
3112 case OB_DIRECTION_SOUTH
:
3113 my_edge_start
= c
->frame
->area
.x
;
3114 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3115 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3117 /* default: bottom of screen */
3118 dest
= a
->y
+ a
->height
;
3120 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3121 int his_edge_start
, his_edge_end
, his_offset
;
3122 ObClient
*cur
= it
->data
;
3126 if(!client_normal(cur
))
3128 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3133 his_edge_start
= cur
->frame
->area
.x
;
3134 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3135 his_offset
= cur
->frame
->area
.y
;
3138 if(his_offset
- 1 < my_offset
)
3141 if(his_offset
> dest
)
3144 if(his_edge_start
>= my_edge_start
&&
3145 his_edge_start
<= my_edge_end
)
3148 if(my_edge_start
>= his_edge_start
&&
3149 my_edge_start
<= his_edge_end
)
3154 case OB_DIRECTION_WEST
:
3155 my_edge_start
= c
->frame
->area
.y
;
3156 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3157 my_offset
= c
->frame
->area
.x
;
3159 /* default: leftmost egde of screen */
3162 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3163 int his_edge_start
, his_edge_end
, his_offset
;
3164 ObClient
*cur
= it
->data
;
3168 if(!client_normal(cur
))
3170 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3175 his_edge_start
= cur
->frame
->area
.y
;
3176 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3177 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
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
)
3196 case OB_DIRECTION_EAST
:
3197 my_edge_start
= c
->frame
->area
.y
;
3198 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3199 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3201 /* default: rightmost edge of screen */
3202 dest
= a
->x
+ a
->width
;
3204 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3205 int his_edge_start
, his_edge_end
, his_offset
;
3206 ObClient
*cur
= it
->data
;
3210 if(!client_normal(cur
))
3212 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3217 his_edge_start
= cur
->frame
->area
.y
;
3218 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3219 his_offset
= cur
->frame
->area
.x
;
3221 if(his_offset
- 1 < my_offset
)
3224 if(his_offset
> dest
)
3227 if(his_edge_start
>= my_edge_start
&&
3228 his_edge_start
<= my_edge_end
)
3231 if(my_edge_start
>= his_edge_start
&&
3232 my_edge_start
<= his_edge_end
)
3237 case OB_DIRECTION_NORTHEAST
:
3238 case OB_DIRECTION_SOUTHEAST
:
3239 case OB_DIRECTION_NORTHWEST
:
3240 case OB_DIRECTION_SOUTHWEST
:
3241 /* not implemented */
3243 g_assert_not_reached();
3248 ObClient
* client_under_pointer()
3252 ObClient
*ret
= NULL
;
3254 if (screen_pointer_pos(&x
, &y
)) {
3255 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
3256 if (WINDOW_IS_CLIENT(it
->data
)) {
3257 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3258 if (c
->frame
->visible
&&
3259 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3269 gboolean
client_has_group_siblings(ObClient
*self
)
3271 return self
->group
&& self
->group
->members
->next
;