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 client_normal(self
));
351 if (x
!= ox
|| y
!= oy
)
352 client_move(self
, x
, y
);
355 client_showhide(self
);
357 /* use client_focus instead of client_activate cuz client_activate does
358 stuff like switch desktops etc and I'm not interested in all that when
359 a window maps since its not based on an action from the user like
360 clicking a window to activate is. so keep the new window out of the way
363 /* if using focus_delay, stop the timer now so that focus doesn't go
365 event_halt_focus_delay();
368 /* since focus can change the stacking orders, if we focus the window
369 then the standard raise it gets is not enough, we need to queue one
370 for after the focus change takes place */
374 /* client_activate does this but we aret using it so we have to do it
376 if (screen_showing_desktop
)
377 screen_show_desktop(FALSE
);
379 /* add to client list/map */
380 client_list
= g_list_append(client_list
, self
);
381 g_hash_table_insert(window_map
, &self
->window
, self
);
383 /* this has to happen after we're in the client_list */
384 screen_update_areas();
386 /* update the list hints */
389 keyboard_grab_for_client(self
, TRUE
);
390 mouse_grab_for_client(self
, TRUE
);
392 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
395 void client_unmanage_all()
397 while (client_list
!= NULL
)
398 client_unmanage(client_list
->data
);
401 void client_unmanage(ObClient
*self
)
406 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
408 g_assert(self
!= NULL
);
410 keyboard_grab_for_client(self
, FALSE
);
411 mouse_grab_for_client(self
, FALSE
);
413 /* remove the window from our save set */
414 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
416 /* we dont want events no more */
417 XSelectInput(ob_display
, self
->window
, NoEventMask
);
419 frame_hide(self
->frame
);
421 client_list
= g_list_remove(client_list
, self
);
422 stacking_remove(self
);
423 g_hash_table_remove(window_map
, &self
->window
);
425 /* update the focus lists */
426 focus_order_remove(self
);
428 /* once the client is out of the list, update the struts to remove it's
430 screen_update_areas();
432 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
433 Destructor
*d
= it
->data
;
434 d
->func(self
, d
->data
);
437 if (focus_client
== self
) {
440 /* focus the last focused window on the desktop, and ignore enter
441 events from the unmap so it doesnt mess with the focus */
442 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
443 /* remove these flags so we don't end up getting focused in the
445 self
->can_focus
= FALSE
;
446 self
->focus_notify
= FALSE
;
448 client_unfocus(self
);
451 /* tell our parent(s) that we're gone */
452 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
455 for (it
= self
->group
->members
; it
; it
= it
->next
)
456 if (it
->data
!= self
)
457 ((ObClient
*)it
->data
)->transients
=
458 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
459 } else if (self
->transient_for
) { /* transient of window */
460 self
->transient_for
->transients
=
461 g_slist_remove(self
->transient_for
->transients
, self
);
464 /* tell our transients that we're gone */
465 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
466 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
467 ((ObClient
*)it
->data
)->transient_for
= NULL
;
468 client_calc_layer(it
->data
);
472 /* remove from its group */
474 group_remove(self
->group
, self
);
478 /* give the client its border back */
479 client_toggle_border(self
, TRUE
);
481 /* reparent the window out of the frame, and free the frame */
482 frame_release_client(self
->frame
, self
);
485 if (ob_state() != OB_STATE_EXITING
) {
486 /* these values should not be persisted across a window
488 PROP_ERASE(self
->window
, net_wm_desktop
);
489 PROP_ERASE(self
->window
, net_wm_state
);
490 PROP_ERASE(self
->window
, wm_state
);
492 /* if we're left in an iconic state, the client wont be mapped. this is
493 bad, since we will no longer be managing the window on restart */
495 XMapWindow(ob_display
, self
->window
);
499 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
501 /* free all data allocated in the client struct */
502 g_slist_free(self
->transients
);
503 for (j
= 0; j
< self
->nicons
; ++j
)
504 g_free(self
->icons
[j
].data
);
505 if (self
->nicons
> 0)
508 g_free(self
->icon_title
);
512 g_free(self
->sm_client_id
);
515 /* update the list hints */
519 static void client_urgent_notify(ObClient
*self
)
522 frame_flash_start(self
->frame
);
524 frame_flash_stop(self
->frame
);
527 static void client_restore_session_state(ObClient
*self
)
531 if (!(it
= session_state_find(self
)))
534 self
->session
= it
->data
;
536 RECT_SET(self
->area
, self
->session
->x
, self
->session
->y
,
537 self
->session
->w
, self
->session
->h
);
538 self
->positioned
= TRUE
;
539 if (self
->session
->w
> 0 && self
->session
->h
> 0)
540 XResizeWindow(ob_display
, self
->window
,
541 self
->session
->w
, self
->session
->h
);
543 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
544 self
->session
->desktop
:
545 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
546 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
548 self
->shaded
= self
->session
->shaded
;
549 self
->iconic
= self
->session
->iconic
;
550 self
->skip_pager
= self
->session
->skip_pager
;
551 self
->skip_taskbar
= self
->session
->skip_taskbar
;
552 self
->fullscreen
= self
->session
->fullscreen
;
553 self
->above
= self
->session
->above
;
554 self
->below
= self
->session
->below
;
555 self
->max_horz
= self
->session
->max_horz
;
556 self
->max_vert
= self
->session
->max_vert
;
559 static void client_restore_session_stacking(ObClient
*self
)
563 if (!self
->session
) return;
565 it
= g_list_find(session_saved_state
, self
->session
);
566 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
569 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
570 if (session_state_cmp(it
->data
, cit
->data
))
573 client_calc_layer(self
);
574 stacking_below(CLIENT_AS_WINDOW(self
),
575 CLIENT_AS_WINDOW(cit
->data
));
581 void client_move_onscreen(ObClient
*self
, gboolean rude
)
583 int x
= self
->area
.x
;
584 int y
= self
->area
.y
;
585 if (client_find_onscreen(self
, &x
, &y
,
586 self
->frame
->area
.width
,
587 self
->frame
->area
.height
, rude
)) {
588 client_move(self
, x
, y
);
592 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
596 int ox
= *x
, oy
= *y
;
598 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
601 /* XXX watch for xinerama dead areas */
603 a
= screen_area(self
->desktop
);
604 if (client_normal(self
)) {
605 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
606 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
607 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
608 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
609 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
611 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
616 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
617 Java can suck it too. */
619 /* dont let windows map/move into the strut unless they
620 are bigger than the available area */
622 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
623 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
624 *x
= a
->x
+ a
->width
- w
;
626 if (h
<= a
->height
) {
627 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
628 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
629 *y
= a
->y
+ a
->height
- h
;
633 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
636 return ox
!= *x
|| oy
!= *y
;
639 static void client_toggle_border(ObClient
*self
, gboolean show
)
641 /* adjust our idea of where the client is, based on its border. When the
642 border is removed, the client should now be considered to be in a
644 when re-adding the border to the client, the same operation needs to be
646 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
647 int x
= oldx
, y
= oldy
;
648 switch(self
->gravity
) {
650 case NorthWestGravity
:
652 case SouthWestGravity
:
654 case NorthEastGravity
:
656 case SouthEastGravity
:
657 if (show
) x
-= self
->border_width
* 2;
658 else x
+= self
->border_width
* 2;
665 if (show
) x
-= self
->border_width
;
666 else x
+= self
->border_width
;
669 switch(self
->gravity
) {
671 case NorthWestGravity
:
673 case NorthEastGravity
:
675 case SouthWestGravity
:
677 case SouthEastGravity
:
678 if (show
) y
-= self
->border_width
* 2;
679 else y
+= self
->border_width
* 2;
686 if (show
) y
-= self
->border_width
;
687 else y
+= self
->border_width
;
694 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
696 /* move the client so it is back it the right spot _with_ its
698 if (x
!= oldx
|| y
!= oldy
)
699 XMoveWindow(ob_display
, self
->window
, x
, y
);
701 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
705 static void client_get_all(ObClient
*self
)
707 client_get_area(self
);
708 client_update_transient_for(self
);
709 client_update_wmhints(self
);
710 client_get_startup_id(self
);
711 client_get_desktop(self
);
712 client_get_state(self
);
713 client_get_shaped(self
);
715 client_get_mwm_hints(self
);
716 client_get_type(self
);/* this can change the mwmhints for special cases */
719 /* a couple type-based defaults for new windows */
721 /* this makes sure that these windows appear on all desktops */
722 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
723 self
->desktop
= DESKTOP_ALL
;
725 /* dock windows default to ABOVE */
726 if (self
->type
== OB_CLIENT_TYPE_DOCK
&& !self
->below
)
730 client_update_protocols(self
);
732 client_get_gravity(self
); /* get the attribute gravity */
733 client_update_normal_hints(self
); /* this may override the attribute
736 /* got the type, the mwmhints, the protocols, and the normal hints
737 (min/max sizes), so we're ready to set up the decorations/functions */
738 client_setup_decor_and_functions(self
);
740 client_update_title(self
);
741 client_update_class(self
);
742 client_update_sm_client_id(self
);
743 client_update_strut(self
);
744 client_update_icons(self
);
747 static void client_get_startup_id(ObClient
*self
)
749 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
751 PROP_GETS(self
->group
->leader
,
752 net_startup_id
, utf8
, &self
->startup_id
);
755 static void client_get_area(ObClient
*self
)
757 XWindowAttributes wattrib
;
760 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
761 g_assert(ret
!= BadWindow
);
763 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
764 self
->border_width
= wattrib
.border_width
;
767 static void client_get_desktop(ObClient
*self
)
769 guint32 d
= screen_num_desktops
; /* an always-invalid value */
771 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
772 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
773 self
->desktop
= screen_num_desktops
- 1;
777 gboolean trdesk
= FALSE
;
779 if (self
->transient_for
) {
780 if (self
->transient_for
!= OB_TRAN_GROUP
) {
781 self
->desktop
= self
->transient_for
->desktop
;
786 for (it
= self
->group
->members
; it
; it
= it
->next
)
787 if (it
->data
!= self
&&
788 !((ObClient
*)it
->data
)->transient_for
) {
789 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
796 /* try get from the startup-notification protocol */
797 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
798 if (self
->desktop
>= screen_num_desktops
&&
799 self
->desktop
!= DESKTOP_ALL
)
800 self
->desktop
= screen_num_desktops
- 1;
802 /* defaults to the current desktop */
803 self
->desktop
= screen_desktop
;
806 if (self
->desktop
!= d
) {
807 /* set the desktop hint, to make sure that it always exists */
808 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
812 static void client_get_state(ObClient
*self
)
817 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
819 for (i
= 0; i
< num
; ++i
) {
820 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
822 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
824 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
826 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
827 self
->skip_taskbar
= TRUE
;
828 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
829 self
->skip_pager
= TRUE
;
830 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
831 self
->fullscreen
= TRUE
;
832 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
833 self
->max_vert
= TRUE
;
834 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
835 self
->max_horz
= TRUE
;
836 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
838 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
840 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
841 self
->undecorated
= TRUE
;
848 static void client_get_shaped(ObClient
*self
)
850 self
->shaped
= FALSE
;
852 if (extensions_shape
) {
857 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
859 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
860 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
862 self
->shaped
= (s
!= 0);
867 void client_update_transient_for(ObClient
*self
)
870 ObClient
*target
= NULL
;
872 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
873 self
->transient
= TRUE
;
874 if (t
!= self
->window
) { /* cant be transient to itself! */
875 target
= g_hash_table_lookup(window_map
, &t
);
876 /* if this happens then we need to check for it*/
877 g_assert(target
!= self
);
878 if (target
&& !WINDOW_IS_CLIENT(target
)) {
879 /* this can happen when a dialog is a child of
880 a dockapp, for example */
884 if (!target
&& self
->group
) {
885 /* not transient to a client, see if it is transient for a
887 if (t
== self
->group
->leader
||
889 t
== RootWindow(ob_display
, ob_screen
))
891 /* window is a transient for its group! */
892 target
= OB_TRAN_GROUP
;
897 self
->transient
= FALSE
;
899 /* if anything has changed... */
900 if (target
!= self
->transient_for
) {
901 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
904 /* remove from old parents */
905 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
906 ObClient
*c
= it
->data
;
907 if (c
!= self
&& !c
->transient_for
)
908 c
->transients
= g_slist_remove(c
->transients
, self
);
910 } else if (self
->transient_for
!= NULL
) { /* transient of window */
911 /* remove from old parent */
912 self
->transient_for
->transients
=
913 g_slist_remove(self
->transient_for
->transients
, self
);
915 self
->transient_for
= target
;
916 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
919 /* add to new parents */
920 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
921 ObClient
*c
= it
->data
;
922 if (c
!= self
&& !c
->transient_for
)
923 c
->transients
= g_slist_append(c
->transients
, self
);
926 /* remove all transients which are in the group, that causes
927 circlular pointer hell of doom */
928 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
930 for (sit
= self
->transients
; sit
; sit
= next
) {
931 next
= g_slist_next(sit
);
932 if (sit
->data
== it
->data
)
934 g_slist_delete_link(self
->transients
, sit
);
937 } else if (self
->transient_for
!= NULL
) { /* transient of window */
938 /* add to new parent */
939 self
->transient_for
->transients
=
940 g_slist_append(self
->transient_for
->transients
, self
);
945 static void client_get_mwm_hints(ObClient
*self
)
950 self
->mwmhints
.flags
= 0; /* default to none */
952 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
954 if (num
>= OB_MWM_ELEMENTS
) {
955 self
->mwmhints
.flags
= hints
[0];
956 self
->mwmhints
.functions
= hints
[1];
957 self
->mwmhints
.decorations
= hints
[2];
963 void client_get_type(ObClient
*self
)
970 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
971 /* use the first value that we know about in the array */
972 for (i
= 0; i
< num
; ++i
) {
973 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
974 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
975 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
976 self
->type
= OB_CLIENT_TYPE_DOCK
;
977 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
978 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
979 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
980 self
->type
= OB_CLIENT_TYPE_MENU
;
981 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
982 self
->type
= OB_CLIENT_TYPE_UTILITY
;
983 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
984 self
->type
= OB_CLIENT_TYPE_SPLASH
;
985 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
986 self
->type
= OB_CLIENT_TYPE_DIALOG
;
987 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
988 self
->type
= OB_CLIENT_TYPE_NORMAL
;
989 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
990 /* prevent this window from getting any decor or
992 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
993 OB_MWM_FLAG_DECORATIONS
);
994 self
->mwmhints
.decorations
= 0;
995 self
->mwmhints
.functions
= 0;
997 if (self
->type
!= (ObClientType
) -1)
998 break; /* grab the first legit type */
1003 if (self
->type
== (ObClientType
) -1) {
1004 /*the window type hint was not set, which means we either classify
1005 ourself as a normal window or a dialog, depending on if we are a
1007 if (self
->transient
)
1008 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1010 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1014 void client_update_protocols(ObClient
*self
)
1017 guint num_return
, i
;
1019 self
->focus_notify
= FALSE
;
1020 self
->delete_window
= FALSE
;
1022 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1023 for (i
= 0; i
< num_return
; ++i
) {
1024 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
1025 /* this means we can request the window to close */
1026 self
->delete_window
= TRUE
;
1027 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1028 /* if this protocol is requested, then the window will be
1029 notified whenever we want it to receive focus */
1030 self
->focus_notify
= TRUE
;
1036 static void client_get_gravity(ObClient
*self
)
1038 XWindowAttributes wattrib
;
1041 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1042 g_assert(ret
!= BadWindow
);
1043 self
->gravity
= wattrib
.win_gravity
;
1046 void client_update_normal_hints(ObClient
*self
)
1050 int oldgravity
= self
->gravity
;
1053 self
->min_ratio
= 0.0f
;
1054 self
->max_ratio
= 0.0f
;
1055 SIZE_SET(self
->size_inc
, 1, 1);
1056 SIZE_SET(self
->base_size
, 0, 0);
1057 SIZE_SET(self
->min_size
, 0, 0);
1058 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1060 /* get the hints from the window */
1061 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1062 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1064 if (size
.flags
& PWinGravity
) {
1065 self
->gravity
= size
.win_gravity
;
1067 /* if the client has a frame, i.e. has already been mapped and
1068 is changing its gravity */
1069 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1070 /* move our idea of the client's position based on its new
1072 self
->area
.x
= self
->frame
->area
.x
;
1073 self
->area
.y
= self
->frame
->area
.y
;
1074 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1078 if (size
.flags
& PAspect
) {
1079 if (size
.min_aspect
.y
)
1080 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1081 if (size
.max_aspect
.y
)
1082 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1085 if (size
.flags
& PMinSize
)
1086 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1088 if (size
.flags
& PMaxSize
)
1089 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1091 if (size
.flags
& PBaseSize
)
1092 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1094 if (size
.flags
& PResizeInc
)
1095 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1099 void client_setup_decor_and_functions(ObClient
*self
)
1101 /* start with everything (cept fullscreen) */
1103 (OB_FRAME_DECOR_TITLEBAR
|
1104 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1105 OB_FRAME_DECOR_GRIPS
|
1106 OB_FRAME_DECOR_BORDER
|
1107 OB_FRAME_DECOR_ICON
|
1108 OB_FRAME_DECOR_ALLDESKTOPS
|
1109 OB_FRAME_DECOR_ICONIFY
|
1110 OB_FRAME_DECOR_MAXIMIZE
|
1111 OB_FRAME_DECOR_SHADE
|
1112 OB_FRAME_DECOR_CLOSE
);
1114 (OB_CLIENT_FUNC_RESIZE
|
1115 OB_CLIENT_FUNC_MOVE
|
1116 OB_CLIENT_FUNC_ICONIFY
|
1117 OB_CLIENT_FUNC_MAXIMIZE
|
1118 OB_CLIENT_FUNC_SHADE
|
1119 OB_CLIENT_FUNC_CLOSE
);
1121 if (!(self
->min_size
.width
< self
->max_size
.width
||
1122 self
->min_size
.height
< self
->max_size
.height
))
1123 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1125 switch (self
->type
) {
1126 case OB_CLIENT_TYPE_NORMAL
:
1127 /* normal windows retain all of the possible decorations and
1128 functionality, and are the only windows that you can fullscreen */
1129 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1132 case OB_CLIENT_TYPE_DIALOG
:
1133 case OB_CLIENT_TYPE_UTILITY
:
1134 /* these windows cannot be maximized */
1135 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1138 case OB_CLIENT_TYPE_MENU
:
1139 case OB_CLIENT_TYPE_TOOLBAR
:
1140 /* these windows get less functionality */
1141 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1144 case OB_CLIENT_TYPE_DESKTOP
:
1145 case OB_CLIENT_TYPE_DOCK
:
1146 case OB_CLIENT_TYPE_SPLASH
:
1147 /* none of these windows are manipulated by the window manager */
1148 self
->decorations
= 0;
1149 self
->functions
= 0;
1153 /* Mwm Hints are applied subtractively to what has already been chosen for
1154 decor and functionality */
1155 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1156 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1157 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1158 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1159 /* if the mwm hints request no handle or title, then all
1160 decorations are disabled */
1161 self
->decorations
= 0;
1165 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1166 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1167 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1168 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1169 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1170 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1171 /* dont let mwm hints kill any buttons
1172 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1173 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1174 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1175 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1177 /* dont let mwm hints kill the close button
1178 if (! (self->mwmhints.functions & MwmFunc_Close))
1179 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1183 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1184 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1185 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1186 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1187 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1188 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1190 /* can't maximize without moving/resizing */
1191 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1192 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1193 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1194 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1195 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1198 /* kill the handle on fully maxed windows */
1199 if (self
->max_vert
&& self
->max_horz
)
1200 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1202 /* finally, the user can have requested no decorations, which overrides
1203 everything (but doesnt give it a border if it doesnt have one) */
1204 if (self
->undecorated
)
1205 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1207 /* if we don't have a titlebar, then we cannot shade! */
1208 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1209 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1211 /* now we need to check against rules for the client's current state */
1212 if (self
->fullscreen
) {
1213 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1214 OB_CLIENT_FUNC_FULLSCREEN
|
1215 OB_CLIENT_FUNC_ICONIFY
);
1216 self
->decorations
= 0;
1219 client_change_allowed_actions(self
);
1222 /* adjust the client's decorations, etc. */
1223 client_reconfigure(self
);
1227 static void client_change_allowed_actions(ObClient
*self
)
1232 /* desktop windows are kept on all desktops */
1233 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1234 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1236 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1237 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1238 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1239 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1240 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1241 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1242 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1243 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1244 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1245 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1246 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1247 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1248 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1249 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1250 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1253 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1255 /* make sure the window isn't breaking any rules now */
1257 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1258 if (self
->frame
) client_shade(self
, FALSE
);
1259 else self
->shaded
= FALSE
;
1261 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1262 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1263 else self
->iconic
= FALSE
;
1265 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1266 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1267 else self
->fullscreen
= FALSE
;
1269 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1271 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1272 else self
->max_vert
= self
->max_horz
= FALSE
;
1276 void client_reconfigure(ObClient
*self
)
1278 /* by making this pass FALSE for user, we avoid the emacs event storm where
1279 every configurenotify causes an update in its normal hints, i think this
1280 is generally what we want anyways... */
1281 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1282 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1285 void client_update_wmhints(ObClient
*self
)
1288 gboolean ur
= FALSE
;
1291 /* assume a window takes input if it doesnt specify */
1292 self
->can_focus
= TRUE
;
1294 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1295 if (hints
->flags
& InputHint
)
1296 self
->can_focus
= hints
->input
;
1298 /* only do this when first managing the window *AND* when we aren't
1300 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1301 if (hints
->flags
& StateHint
)
1302 self
->iconic
= hints
->initial_state
== IconicState
;
1304 if (hints
->flags
& XUrgencyHint
)
1307 if (!(hints
->flags
& WindowGroupHint
))
1308 hints
->window_group
= None
;
1310 /* did the group state change? */
1311 if (hints
->window_group
!=
1312 (self
->group
? self
->group
->leader
: None
)) {
1313 /* remove from the old group if there was one */
1314 if (self
->group
!= NULL
) {
1315 /* remove transients of the group */
1316 for (it
= self
->group
->members
; it
; it
= it
->next
)
1317 self
->transients
= g_slist_remove(self
->transients
,
1320 /* remove myself from parents in the group */
1321 if (self
->transient_for
== OB_TRAN_GROUP
) {
1322 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1323 ObClient
*c
= it
->data
;
1325 if (c
!= self
&& !c
->transient_for
)
1326 c
->transients
= g_slist_remove(c
->transients
,
1331 group_remove(self
->group
, self
);
1334 if (hints
->window_group
!= None
) {
1335 self
->group
= group_add(hints
->window_group
, self
);
1337 /* i can only have transients from the group if i am not
1339 if (!self
->transient_for
) {
1340 /* add other transients of the group that are already
1342 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1343 ObClient
*c
= it
->data
;
1344 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1346 g_slist_append(self
->transients
, c
);
1351 /* because the self->transient flag wont change from this call,
1352 we don't need to update the window's type and such, only its
1353 transient_for, and the transients lists of other windows in
1354 the group may be affected */
1355 client_update_transient_for(self
);
1358 /* the WM_HINTS can contain an icon */
1359 client_update_icons(self
);
1364 if (ur
!= self
->urgent
) {
1366 /* fire the urgent callback if we're mapped, otherwise, wait until
1367 after we're mapped */
1369 client_urgent_notify(self
);
1373 void client_update_title(ObClient
*self
)
1379 gboolean read_title
;
1382 old_title
= self
->title
;
1385 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1386 /* try old x stuff */
1387 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1388 data
= g_strdup("Unnamed Window");
1390 /* did the title change? then reset the title_count */
1391 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1392 self
->title_count
= 1;
1394 /* look for duplicates and append a number */
1396 for (it
= client_list
; it
; it
= it
->next
)
1397 if (it
->data
!= self
) {
1398 ObClient
*c
= it
->data
;
1399 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1400 nums
|= 1 << c
->title_count
;
1402 /* find first free number */
1403 for (i
= 1; i
<= 32; ++i
)
1404 if (!(nums
& (1 << i
))) {
1405 if (self
->title_count
== 1 || i
== 1)
1406 self
->title_count
= i
;
1409 /* dont display the number for the first window */
1410 if (self
->title_count
> 1) {
1412 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1417 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1422 frame_adjust_title(self
->frame
);
1426 /* update the icon title */
1428 g_free(self
->icon_title
);
1432 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1433 /* try old x stuff */
1434 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1435 data
= g_strdup(self
->title
);
1439 /* append the title count, dont display the number for the first window */
1440 if (read_title
&& self
->title_count
> 1) {
1441 char *vdata
, *ndata
;
1442 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1443 vdata
= g_strconcat(data
, ndata
, NULL
);
1449 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1451 self
->icon_title
= data
;
1454 void client_update_class(ObClient
*self
)
1459 if (self
->name
) g_free(self
->name
);
1460 if (self
->class) g_free(self
->class);
1461 if (self
->role
) g_free(self
->role
);
1463 self
->name
= self
->class = self
->role
= NULL
;
1465 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1467 self
->name
= g_strdup(data
[0]);
1469 self
->class = g_strdup(data
[1]);
1474 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1477 if (self
->name
== NULL
) self
->name
= g_strdup("");
1478 if (self
->class == NULL
) self
->class = g_strdup("");
1479 if (self
->role
== NULL
) self
->role
= g_strdup("");
1482 void client_update_strut(ObClient
*self
)
1486 gboolean got
= FALSE
;
1489 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1493 STRUT_PARTIAL_SET(strut
,
1494 data
[0], data
[2], data
[1], data
[3],
1495 data
[4], data
[5], data
[8], data
[9],
1496 data
[6], data
[7], data
[10], data
[11]);
1502 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1505 STRUT_PARTIAL_SET(strut
,
1506 data
[0], data
[2], data
[1], data
[3],
1507 0, 0, 0, 0, 0, 0, 0, 0);
1513 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1514 0, 0, 0, 0, 0, 0, 0, 0);
1516 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1517 self
->strut
= strut
;
1519 /* updating here is pointless while we're being mapped cuz we're not in
1520 the client list yet */
1522 screen_update_areas();
1526 void client_update_icons(ObClient
*self
)
1532 for (i
= 0; i
< self
->nicons
; ++i
)
1533 g_free(self
->icons
[i
].data
);
1534 if (self
->nicons
> 0)
1535 g_free(self
->icons
);
1538 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1539 /* figure out how many valid icons are in here */
1541 while (num
- i
> 2) {
1545 if (i
> num
|| w
*h
== 0) break;
1549 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1551 /* store the icons */
1553 for (j
= 0; j
< self
->nicons
; ++j
) {
1556 w
= self
->icons
[j
].width
= data
[i
++];
1557 h
= self
->icons
[j
].height
= data
[i
++];
1559 if (w
*h
== 0) continue;
1561 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1562 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1567 self
->icons
[j
].data
[t
] =
1568 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1569 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1570 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1571 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1577 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1578 kwm_win_icon
, &data
, &num
)) {
1581 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1582 xerror_set_ignore(TRUE
);
1583 if (!RrPixmapToRGBA(ob_rr_inst
,
1585 &self
->icons
[self
->nicons
-1].width
,
1586 &self
->icons
[self
->nicons
-1].height
,
1587 &self
->icons
[self
->nicons
-1].data
)) {
1588 g_free(&self
->icons
[self
->nicons
-1]);
1591 xerror_set_ignore(FALSE
);
1597 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1598 if (hints
->flags
& IconPixmapHint
) {
1600 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1601 xerror_set_ignore(TRUE
);
1602 if (!RrPixmapToRGBA(ob_rr_inst
,
1604 (hints
->flags
& IconMaskHint
?
1605 hints
->icon_mask
: None
),
1606 &self
->icons
[self
->nicons
-1].width
,
1607 &self
->icons
[self
->nicons
-1].height
,
1608 &self
->icons
[self
->nicons
-1].data
)){
1609 g_free(&self
->icons
[self
->nicons
-1]);
1612 xerror_set_ignore(FALSE
);
1619 frame_adjust_icon(self
->frame
);
1622 static void client_change_state(ObClient
*self
)
1625 guint32 netstate
[11];
1628 state
[0] = self
->wmstate
;
1630 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1634 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1636 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1638 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1639 if (self
->skip_taskbar
)
1640 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1641 if (self
->skip_pager
)
1642 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1643 if (self
->fullscreen
)
1644 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1646 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1648 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1650 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1652 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1653 if (self
->undecorated
)
1654 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1655 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1657 client_calc_layer(self
);
1660 frame_adjust_state(self
->frame
);
1663 ObClient
*client_search_focus_tree(ObClient
*self
)
1668 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1669 if (client_focused(it
->data
)) return it
->data
;
1670 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1675 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1677 if (self
->transient_for
) {
1678 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1679 return client_search_focus_tree_full(self
->transient_for
);
1682 gboolean recursed
= FALSE
;
1684 for (it
= self
->group
->members
; it
; it
= it
->next
)
1685 if (!((ObClient
*)it
->data
)->transient_for
) {
1687 if ((c
= client_search_focus_tree_full(it
->data
)))
1696 /* this function checks the whole tree, the client_search_focus_tree~
1697 does not, so we need to check this window */
1698 if (client_focused(self
))
1700 return client_search_focus_tree(self
);
1703 static ObStackingLayer
calc_layer(ObClient
*self
)
1707 if (self
->fullscreen
&&
1708 (client_focused(self
) || client_search_focus_tree(self
)))
1709 l
= OB_STACKING_LAYER_FULLSCREEN
;
1710 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1711 l
= OB_STACKING_LAYER_DESKTOP
;
1712 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1713 if (self
->above
) l
= OB_STACKING_LAYER_DOCK_ABOVE
;
1714 else if (self
->below
) l
= OB_STACKING_LAYER_DOCK_BELOW
;
1715 else l
= OB_STACKING_LAYER_NORMAL
;
1717 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1718 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1719 else l
= OB_STACKING_LAYER_NORMAL
;
1724 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1725 ObStackingLayer l
, gboolean raised
)
1727 ObStackingLayer old
, own
;
1731 own
= calc_layer(self
);
1732 self
->layer
= l
> own
? l
: own
;
1734 for (it
= self
->transients
; it
; it
= it
->next
)
1735 client_calc_layer_recursive(it
->data
, orig
,
1736 l
, raised
? raised
: l
!= old
);
1738 if (!raised
&& l
!= old
)
1739 if (orig
->frame
) { /* only restack if the original window is managed */
1740 /* XXX add_non_intrusive ever? */
1741 stacking_remove(CLIENT_AS_WINDOW(self
));
1742 stacking_add(CLIENT_AS_WINDOW(self
));
1746 void client_calc_layer(ObClient
*self
)
1753 /* transients take on the layer of their parents */
1754 self
= client_search_top_transient(self
);
1756 l
= calc_layer(self
);
1758 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1761 gboolean
client_should_show(ObClient
*self
)
1763 if (self
->iconic
) return FALSE
;
1764 else if (!(self
->desktop
== screen_desktop
||
1765 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1766 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1771 static void client_showhide(ObClient
*self
)
1774 if (client_should_show(self
))
1775 frame_show(self
->frame
);
1777 frame_hide(self
->frame
);
1780 gboolean
client_normal(ObClient
*self
) {
1781 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1782 self
->type
== OB_CLIENT_TYPE_DOCK
||
1783 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1786 static void client_apply_startup_state(ObClient
*self
)
1788 /* these are in a carefully crafted order.. */
1791 self
->iconic
= FALSE
;
1792 client_iconify(self
, TRUE
, FALSE
);
1794 if (self
->fullscreen
) {
1795 self
->fullscreen
= FALSE
;
1796 client_fullscreen(self
, TRUE
, FALSE
);
1798 if (self
->undecorated
) {
1799 self
->undecorated
= FALSE
;
1800 client_set_undecorated(self
, TRUE
);
1803 self
->shaded
= FALSE
;
1804 client_shade(self
, TRUE
);
1807 client_urgent_notify(self
);
1809 if (self
->max_vert
&& self
->max_horz
) {
1810 self
->max_vert
= self
->max_horz
= FALSE
;
1811 client_maximize(self
, TRUE
, 0, FALSE
);
1812 } else if (self
->max_vert
) {
1813 self
->max_vert
= FALSE
;
1814 client_maximize(self
, TRUE
, 2, FALSE
);
1815 } else if (self
->max_horz
) {
1816 self
->max_horz
= FALSE
;
1817 client_maximize(self
, TRUE
, 1, FALSE
);
1820 /* nothing to do for the other states:
1829 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1830 int x
, int y
, int w
, int h
,
1831 gboolean user
, gboolean final
,
1832 gboolean force_reply
)
1835 gboolean send_resize_client
;
1836 gboolean moved
= FALSE
, resized
= FALSE
;
1837 guint fdecor
= self
->frame
->decorations
;
1838 gboolean fhorz
= self
->frame
->max_horz
;
1840 /* make the frame recalculate its dimentions n shit without changing
1841 anything visible for real, this way the constraints below can work with
1842 the updated frame dimensions. */
1843 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1845 /* gets the frame's position */
1846 frame_client_gravity(self
->frame
, &x
, &y
);
1848 /* these positions are frame positions, not client positions */
1850 /* set the size and position if fullscreen */
1851 if (self
->fullscreen
) {
1854 XF86VidModeModeLine mode
;
1859 i
= client_monitor(self
);
1860 a
= screen_physical_area_monitor(i
);
1863 if (i
== 0 && /* primary head */
1864 extensions_vidmode
&&
1865 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1866 /* get the mode last so the mode.privsize isnt freed incorrectly */
1867 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1872 if (mode
.privsize
) XFree(mode
.private);
1882 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1886 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1888 /* set the size and position if maximized */
1889 if (self
->max_horz
) {
1891 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1893 if (self
->max_vert
) {
1895 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1899 /* gets the client's position */
1900 frame_frame_gravity(self
->frame
, &x
, &y
);
1902 /* these override the above states! if you cant move you can't move! */
1904 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1908 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1909 w
= self
->area
.width
;
1910 h
= self
->area
.height
;
1914 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1915 int basew
, baseh
, minw
, minh
;
1917 /* base size is substituted with min size if not specified */
1918 if (self
->base_size
.width
|| self
->base_size
.height
) {
1919 basew
= self
->base_size
.width
;
1920 baseh
= self
->base_size
.height
;
1922 basew
= self
->min_size
.width
;
1923 baseh
= self
->min_size
.height
;
1925 /* min size is substituted with base size if not specified */
1926 if (self
->min_size
.width
|| self
->min_size
.height
) {
1927 minw
= self
->min_size
.width
;
1928 minh
= self
->min_size
.height
;
1930 minw
= self
->base_size
.width
;
1931 minh
= self
->base_size
.height
;
1934 /* if this is a user-requested resize, then check against min/max
1937 /* smaller than min size or bigger than max size? */
1938 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1939 if (w
< minw
) w
= minw
;
1940 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1941 if (h
< minh
) h
= minh
;
1946 /* keep to the increments */
1947 w
/= self
->size_inc
.width
;
1948 h
/= self
->size_inc
.height
;
1950 /* you cannot resize to nothing */
1951 if (basew
+ w
< 1) w
= 1 - basew
;
1952 if (baseh
+ h
< 1) h
= 1 - baseh
;
1954 /* store the logical size */
1955 SIZE_SET(self
->logical_size
,
1956 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1957 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1959 w
*= self
->size_inc
.width
;
1960 h
*= self
->size_inc
.height
;
1965 /* adjust the height to match the width for the aspect ratios.
1966 for this, min size is not substituted for base size ever. */
1967 w
-= self
->base_size
.width
;
1968 h
-= self
->base_size
.height
;
1970 if (self
->min_ratio
)
1971 if (h
* self
->min_ratio
> w
) {
1972 h
= (int)(w
/ self
->min_ratio
);
1974 /* you cannot resize to nothing */
1977 w
= (int)(h
* self
->min_ratio
);
1980 if (self
->max_ratio
)
1981 if (h
* self
->max_ratio
< w
) {
1982 h
= (int)(w
/ self
->max_ratio
);
1984 /* you cannot resize to nothing */
1987 w
= (int)(h
* self
->min_ratio
);
1991 w
+= self
->base_size
.width
;
1992 h
+= self
->base_size
.height
;
1999 case OB_CORNER_TOPLEFT
:
2001 case OB_CORNER_TOPRIGHT
:
2002 x
-= w
- self
->area
.width
;
2004 case OB_CORNER_BOTTOMLEFT
:
2005 y
-= h
- self
->area
.height
;
2007 case OB_CORNER_BOTTOMRIGHT
:
2008 x
-= w
- self
->area
.width
;
2009 y
-= h
- self
->area
.height
;
2013 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2014 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2016 oldw
= self
->area
.width
;
2017 oldh
= self
->area
.height
;
2018 RECT_SET(self
->area
, x
, y
, w
, h
);
2020 /* for app-requested resizes, always resize if 'resized' is true.
2021 for user-requested ones, only resize if final is true, or when
2022 resizing in redraw mode */
2023 send_resize_client
= ((!user
&& resized
) ||
2025 (resized
&& config_redraw_resize
))));
2027 /* if the client is enlarging, the resize the client before the frame */
2028 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
2029 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2031 /* move/resize the frame to match the request */
2033 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
2034 moved
= resized
= TRUE
;
2036 if (moved
|| resized
)
2037 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
2039 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
2042 event
.type
= ConfigureNotify
;
2043 event
.xconfigure
.display
= ob_display
;
2044 event
.xconfigure
.event
= self
->window
;
2045 event
.xconfigure
.window
= self
->window
;
2047 /* root window real coords */
2048 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
2050 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
2052 event
.xconfigure
.width
= w
;
2053 event
.xconfigure
.height
= h
;
2054 event
.xconfigure
.border_width
= 0;
2055 event
.xconfigure
.above
= self
->frame
->plate
;
2056 event
.xconfigure
.override_redirect
= FALSE
;
2057 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2058 FALSE
, StructureNotifyMask
, &event
);
2062 /* if the client is shrinking, then resize the frame before the client */
2063 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2064 XResizeWindow(ob_display
, self
->window
, w
, h
);
2069 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2073 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2074 self
->fullscreen
== fs
) return; /* already done */
2076 self
->fullscreen
= fs
;
2077 client_change_state(self
); /* change the state hints on the client,
2078 and adjust out layer/stacking */
2082 self
->pre_fullscreen_area
= self
->area
;
2084 /* these are not actually used cuz client_configure will set them
2085 as appropriate when the window is fullscreened */
2090 if (self
->pre_fullscreen_area
.width
> 0 &&
2091 self
->pre_fullscreen_area
.height
> 0)
2093 x
= self
->pre_fullscreen_area
.x
;
2094 y
= self
->pre_fullscreen_area
.y
;
2095 w
= self
->pre_fullscreen_area
.width
;
2096 h
= self
->pre_fullscreen_area
.height
;
2097 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2099 /* pick some fallbacks... */
2100 a
= screen_area_monitor(self
->desktop
, 0);
2101 x
= a
->x
+ a
->width
/ 4;
2102 y
= a
->y
+ a
->height
/ 4;
2108 client_setup_decor_and_functions(self
);
2110 client_move_resize(self
, x
, y
, w
, h
);
2112 /* try focus us when we go into fullscreen mode */
2116 static void client_iconify_recursive(ObClient
*self
,
2117 gboolean iconic
, gboolean curdesk
)
2120 gboolean changed
= FALSE
;
2123 if (self
->iconic
!= iconic
) {
2124 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2127 self
->iconic
= iconic
;
2130 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2133 old
= self
->wmstate
;
2134 self
->wmstate
= IconicState
;
2135 if (old
!= self
->wmstate
)
2136 PROP_MSG(self
->window
, kde_wm_change_state
,
2137 self
->wmstate
, 1, 0, 0);
2139 self
->ignore_unmaps
++;
2140 /* we unmap the client itself so that we can get MapRequest
2141 events, and because the ICCCM tells us to! */
2142 XUnmapWindow(ob_display
, self
->window
);
2144 /* update the focus lists.. iconic windows go to the bottom of
2145 the list, put the new iconic window at the 'top of the
2147 focus_order_to_top(self
);
2155 client_set_desktop(self
, screen_desktop
, FALSE
);
2157 old
= self
->wmstate
;
2158 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2159 if (old
!= self
->wmstate
)
2160 PROP_MSG(self
->window
, kde_wm_change_state
,
2161 self
->wmstate
, 1, 0, 0);
2163 XMapWindow(ob_display
, self
->window
);
2165 /* this puts it after the current focused window */
2166 focus_order_remove(self
);
2167 focus_order_add_new(self
);
2169 /* this is here cuz with the VIDMODE extension, the viewport can
2170 change while a fullscreen window is iconic, and when it
2171 uniconifies, it would be nice if it did so to the new position
2173 client_reconfigure(self
);
2180 client_change_state(self
);
2181 client_showhide(self
);
2182 screen_update_areas();
2185 /* iconify all transients */
2186 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2187 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2191 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2193 /* move up the transient chain as far as possible first */
2194 self
= client_search_top_transient(self
);
2196 client_iconify_recursive(client_search_top_transient(self
),
2200 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2204 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2205 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2207 /* check if already done */
2209 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2210 if (dir
== 1 && self
->max_horz
) return;
2211 if (dir
== 2 && self
->max_vert
) return;
2213 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2214 if (dir
== 1 && !self
->max_horz
) return;
2215 if (dir
== 2 && !self
->max_vert
) return;
2218 /* we just tell it to configure in the same place and client_configure
2219 worries about filling the screen with the window */
2222 w
= self
->area
.width
;
2223 h
= self
->area
.height
;
2227 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
2228 RECT_SET(self
->pre_max_area
,
2229 self
->area
.x
, self
->pre_max_area
.y
,
2230 self
->area
.width
, self
->pre_max_area
.height
);
2232 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
2233 RECT_SET(self
->pre_max_area
,
2234 self
->pre_max_area
.x
, self
->area
.y
,
2235 self
->pre_max_area
.width
, self
->area
.height
);
2241 a
= screen_area_monitor(self
->desktop
, 0);
2242 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2243 if (self
->pre_max_area
.width
> 0) {
2244 x
= self
->pre_max_area
.x
;
2245 w
= self
->pre_max_area
.width
;
2247 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2248 0, self
->pre_max_area
.height
);
2250 /* pick some fallbacks... */
2251 x
= a
->x
+ a
->width
/ 4;
2255 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2256 if (self
->pre_max_area
.height
> 0) {
2257 y
= self
->pre_max_area
.y
;
2258 h
= self
->pre_max_area
.height
;
2260 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2261 self
->pre_max_area
.width
, 0);
2263 /* pick some fallbacks... */
2264 y
= a
->y
+ a
->height
/ 4;
2270 if (dir
== 0 || dir
== 1) /* horz */
2271 self
->max_horz
= max
;
2272 if (dir
== 0 || dir
== 2) /* vert */
2273 self
->max_vert
= max
;
2275 client_change_state(self
); /* change the state hints on the client */
2277 client_setup_decor_and_functions(self
);
2279 client_move_resize(self
, x
, y
, w
, h
);
2282 void client_shade(ObClient
*self
, gboolean shade
)
2284 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2285 shade
) || /* can't shade */
2286 self
->shaded
== shade
) return; /* already done */
2288 /* when we're iconic, don't change the wmstate */
2289 if (!self
->iconic
) {
2292 old
= self
->wmstate
;
2293 self
->wmstate
= shade
? IconicState
: NormalState
;
2294 if (old
!= self
->wmstate
)
2295 PROP_MSG(self
->window
, kde_wm_change_state
,
2296 self
->wmstate
, 1, 0, 0);
2299 self
->shaded
= shade
;
2300 client_change_state(self
);
2301 /* resize the frame to just the titlebar */
2302 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2305 void client_close(ObClient
*self
)
2309 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2311 /* in the case that the client provides no means to requesting that it
2312 close, we just kill it */
2313 if (!self
->delete_window
)
2317 XXX: itd be cool to do timeouts and shit here for killing the client's
2319 like... if the window is around after 5 seconds, then the close button
2320 turns a nice red, and if this function is called again, the client is
2324 ce
.xclient
.type
= ClientMessage
;
2325 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2326 ce
.xclient
.display
= ob_display
;
2327 ce
.xclient
.window
= self
->window
;
2328 ce
.xclient
.format
= 32;
2329 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2330 ce
.xclient
.data
.l
[1] = event_lasttime
;
2331 ce
.xclient
.data
.l
[2] = 0l;
2332 ce
.xclient
.data
.l
[3] = 0l;
2333 ce
.xclient
.data
.l
[4] = 0l;
2334 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2337 void client_kill(ObClient
*self
)
2339 XKillClient(ob_display
, self
->window
);
2342 void client_set_desktop_recursive(ObClient
*self
,
2343 guint target
, gboolean donthide
)
2348 if (target
!= self
->desktop
) {
2350 ob_debug("Setting desktop %u\n", target
+1);
2352 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2354 /* remove from the old desktop(s) */
2355 focus_order_remove(self
);
2357 old
= self
->desktop
;
2358 self
->desktop
= target
;
2359 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2360 /* the frame can display the current desktop state */
2361 frame_adjust_state(self
->frame
);
2362 /* 'move' the window to the new desktop */
2364 client_showhide(self
);
2365 /* raise if it was not already on the desktop */
2366 if (old
!= DESKTOP_ALL
)
2368 screen_update_areas();
2370 /* add to the new desktop(s) */
2371 if (config_focus_new
)
2372 focus_order_to_top(self
);
2374 focus_order_to_bottom(self
);
2377 /* move all transients */
2378 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2379 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2383 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2385 client_set_desktop_recursive(client_search_top_transient(self
),
2389 ObClient
*client_search_modal_child(ObClient
*self
)
2394 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2395 ObClient
*c
= it
->data
;
2396 if ((ret
= client_search_modal_child(c
))) return ret
;
2397 if (c
->modal
) return c
;
2402 gboolean
client_validate(ObClient
*self
)
2406 XSync(ob_display
, FALSE
); /* get all events on the server */
2408 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2409 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2410 XPutBackEvent(ob_display
, &e
);
2417 void client_set_wm_state(ObClient
*self
, long state
)
2419 if (state
== self
->wmstate
) return; /* no change */
2423 client_iconify(self
, TRUE
, TRUE
);
2426 client_iconify(self
, FALSE
, TRUE
);
2431 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2433 gboolean shaded
= self
->shaded
;
2434 gboolean fullscreen
= self
->fullscreen
;
2435 gboolean undecorated
= self
->undecorated
;
2436 gboolean max_horz
= self
->max_horz
;
2437 gboolean max_vert
= self
->max_vert
;
2440 if (!(action
== prop_atoms
.net_wm_state_add
||
2441 action
== prop_atoms
.net_wm_state_remove
||
2442 action
== prop_atoms
.net_wm_state_toggle
))
2443 /* an invalid action was passed to the client message, ignore it */
2446 for (i
= 0; i
< 2; ++i
) {
2447 Atom state
= i
== 0 ? data1
: data2
;
2449 if (!state
) continue;
2451 /* if toggling, then pick whether we're adding or removing */
2452 if (action
== prop_atoms
.net_wm_state_toggle
) {
2453 if (state
== prop_atoms
.net_wm_state_modal
)
2454 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2455 prop_atoms
.net_wm_state_add
;
2456 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2457 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2458 prop_atoms
.net_wm_state_add
;
2459 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2460 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2461 prop_atoms
.net_wm_state_add
;
2462 else if (state
== prop_atoms
.net_wm_state_shaded
)
2463 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2464 prop_atoms
.net_wm_state_add
;
2465 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2466 action
= self
->skip_taskbar
?
2467 prop_atoms
.net_wm_state_remove
:
2468 prop_atoms
.net_wm_state_add
;
2469 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2470 action
= self
->skip_pager
?
2471 prop_atoms
.net_wm_state_remove
:
2472 prop_atoms
.net_wm_state_add
;
2473 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2474 action
= fullscreen
?
2475 prop_atoms
.net_wm_state_remove
:
2476 prop_atoms
.net_wm_state_add
;
2477 else if (state
== prop_atoms
.net_wm_state_above
)
2478 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2479 prop_atoms
.net_wm_state_add
;
2480 else if (state
== prop_atoms
.net_wm_state_below
)
2481 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2482 prop_atoms
.net_wm_state_add
;
2483 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2484 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2485 prop_atoms
.net_wm_state_add
;
2488 if (action
== prop_atoms
.net_wm_state_add
) {
2489 if (state
== prop_atoms
.net_wm_state_modal
) {
2490 /* XXX raise here or something? */
2492 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2494 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2496 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2498 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2499 self
->skip_taskbar
= TRUE
;
2500 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2501 self
->skip_pager
= TRUE
;
2502 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2504 } else if (state
== prop_atoms
.net_wm_state_above
) {
2506 } else if (state
== prop_atoms
.net_wm_state_below
) {
2508 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2512 } else { /* action == prop_atoms.net_wm_state_remove */
2513 if (state
== prop_atoms
.net_wm_state_modal
) {
2514 self
->modal
= FALSE
;
2515 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2517 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2519 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2521 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2522 self
->skip_taskbar
= FALSE
;
2523 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2524 self
->skip_pager
= FALSE
;
2525 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2527 } else if (state
== prop_atoms
.net_wm_state_above
) {
2528 self
->above
= FALSE
;
2529 } else if (state
== prop_atoms
.net_wm_state_below
) {
2530 self
->below
= FALSE
;
2531 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2532 undecorated
= FALSE
;
2536 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2537 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2539 if (max_horz
== max_vert
) { /* both going the same way */
2540 client_maximize(self
, max_horz
, 0, TRUE
);
2542 client_maximize(self
, max_horz
, 1, TRUE
);
2543 client_maximize(self
, max_vert
, 2, TRUE
);
2547 if (max_horz
!= self
->max_horz
)
2548 client_maximize(self
, max_horz
, 1, TRUE
);
2550 client_maximize(self
, max_vert
, 2, TRUE
);
2553 /* change fullscreen state before shading, as it will affect if the window
2555 if (fullscreen
!= self
->fullscreen
)
2556 client_fullscreen(self
, fullscreen
, TRUE
);
2557 if (shaded
!= self
->shaded
)
2558 client_shade(self
, shaded
);
2559 if (undecorated
!= self
->undecorated
)
2560 client_set_undecorated(self
, undecorated
);
2561 client_calc_layer(self
);
2562 client_change_state(self
); /* change the hint to reflect these changes */
2565 ObClient
*client_focus_target(ObClient
*self
)
2569 /* if we have a modal child, then focus it, not us */
2570 child
= client_search_modal_child(client_search_top_transient(self
));
2571 if (child
) return child
;
2575 gboolean
client_can_focus(ObClient
*self
)
2579 /* choose the correct target */
2580 self
= client_focus_target(self
);
2582 if (!self
->frame
->visible
)
2585 if (!(self
->can_focus
|| self
->focus_notify
))
2588 /* do a check to see if the window has already been unmapped or destroyed
2589 do this intelligently while watching out for unmaps we've generated
2590 (ignore_unmaps > 0) */
2591 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2592 DestroyNotify
, &ev
)) {
2593 XPutBackEvent(ob_display
, &ev
);
2596 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2597 UnmapNotify
, &ev
)) {
2598 if (self
->ignore_unmaps
) {
2599 self
->ignore_unmaps
--;
2601 XPutBackEvent(ob_display
, &ev
);
2609 gboolean
client_focus(ObClient
*self
)
2611 /* choose the correct target */
2612 self
= client_focus_target(self
);
2614 if (!client_can_focus(self
)) {
2615 if (!self
->frame
->visible
) {
2616 /* update the focus lists */
2617 focus_order_to_top(self
);
2622 if (self
->can_focus
) {
2623 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2624 I choose to use it always, hopefully to find errors quicker, if any
2625 are left. (I hate X. I hate focus events.)
2627 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2628 #799. So now it is RevertToNone again.
2630 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2634 if (self
->focus_notify
) {
2636 ce
.xclient
.type
= ClientMessage
;
2637 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2638 ce
.xclient
.display
= ob_display
;
2639 ce
.xclient
.window
= self
->window
;
2640 ce
.xclient
.format
= 32;
2641 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2642 ce
.xclient
.data
.l
[1] = event_lasttime
;
2643 ce
.xclient
.data
.l
[2] = 0l;
2644 ce
.xclient
.data
.l
[3] = 0l;
2645 ce
.xclient
.data
.l
[4] = 0l;
2646 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2650 ob_debug("%sively focusing %lx at %d\n",
2651 (self
->can_focus
? "act" : "pass"),
2652 self
->window
, (int) event_lasttime
);
2655 /* Cause the FocusIn to come back to us. Important for desktop switches,
2656 since otherwise we'll have no FocusIn on the queue and send it off to
2657 the focus_backup. */
2658 XSync(ob_display
, FALSE
);
2662 void client_unfocus(ObClient
*self
)
2664 if (focus_client
== self
) {
2666 ob_debug("client_unfocus for %lx\n", self
->window
);
2668 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2672 void client_activate(ObClient
*self
, gboolean here
)
2674 if (client_normal(self
) && screen_showing_desktop
)
2675 screen_show_desktop(FALSE
);
2677 client_iconify(self
, FALSE
, here
);
2678 if (self
->desktop
!= DESKTOP_ALL
&&
2679 self
->desktop
!= screen_desktop
) {
2681 client_set_desktop(self
, screen_desktop
, FALSE
);
2683 screen_set_desktop(self
->desktop
);
2684 } else if (!self
->frame
->visible
)
2685 /* if its not visible for other reasons, then don't mess
2689 client_shade(self
, FALSE
);
2693 /* we do this an action here. this is rather important. this is because
2694 we want the results from the focus change to take place BEFORE we go
2695 about raising the window. when a fullscreen window loses focus, we need
2696 this or else the raise wont be able to raise above the to-lose-focus
2697 fullscreen window. */
2701 void client_raise(ObClient
*self
)
2703 action_run_string("Raise", self
);
2706 void client_lower(ObClient
*self
)
2708 action_run_string("Raise", self
);
2711 gboolean
client_focused(ObClient
*self
)
2713 return self
== focus_client
;
2716 static ObClientIcon
* client_icon_recursive(ObClient
*self
, int w
, int h
)
2719 /* si is the smallest image >= req */
2720 /* li is the largest image < req */
2721 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2723 if (!self
->nicons
) {
2724 ObClientIcon
*parent
= NULL
;
2726 if (self
->transient_for
) {
2727 if (self
->transient_for
!= OB_TRAN_GROUP
)
2728 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
2731 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2732 ObClient
*c
= it
->data
;
2733 if (c
!= self
&& !c
->transient_for
) {
2734 if ((parent
= client_icon_recursive(c
, w
, h
)))
2744 for (i
= 0; i
< self
->nicons
; ++i
) {
2745 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2746 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2750 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2755 if (largest
== 0) /* didnt find one smaller than the requested size */
2756 return &self
->icons
[si
];
2757 return &self
->icons
[li
];
2760 const ObClientIcon
* client_icon(ObClient
*self
, int w
, int h
)
2763 static ObClientIcon deficon
;
2765 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
2766 deficon
.width
= deficon
.height
= 48;
2767 deficon
.data
= ob_rr_theme
->def_win_icon
;
2773 /* this be mostly ripped from fvwm */
2774 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2776 int my_cx
, my_cy
, his_cx
, his_cy
;
2779 int score
, best_score
;
2780 ObClient
*best_client
, *cur
;
2786 /* first, find the centre coords of the currently focused window */
2787 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2788 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2793 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2796 /* the currently selected window isn't interesting */
2799 if (!client_normal(cur
))
2801 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2805 if(client_focus_target(cur
) == cur
&&
2806 !(cur
->can_focus
|| cur
->focus_notify
))
2809 /* find the centre coords of this window, from the
2810 * currently focused window's point of view */
2811 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2812 + cur
->frame
->area
.width
/ 2;
2813 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2814 + cur
->frame
->area
.height
/ 2;
2816 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2817 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2819 /* Rotate the diagonals 45 degrees counterclockwise.
2820 * To do this, multiply the matrix /+h +h\ with the
2821 * vector (x y). \-h +h/
2822 * h = sqrt(0.5). We can set h := 1 since absolute
2823 * distance doesn't matter here. */
2824 tx
= his_cx
+ his_cy
;
2825 his_cy
= -his_cx
+ his_cy
;
2830 case OB_DIRECTION_NORTH
:
2831 case OB_DIRECTION_SOUTH
:
2832 case OB_DIRECTION_NORTHEAST
:
2833 case OB_DIRECTION_SOUTHWEST
:
2834 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2835 distance
= ((dir
== OB_DIRECTION_NORTH
||
2836 dir
== OB_DIRECTION_NORTHEAST
) ?
2839 case OB_DIRECTION_EAST
:
2840 case OB_DIRECTION_WEST
:
2841 case OB_DIRECTION_SOUTHEAST
:
2842 case OB_DIRECTION_NORTHWEST
:
2843 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2844 distance
= ((dir
== OB_DIRECTION_WEST
||
2845 dir
== OB_DIRECTION_NORTHWEST
) ?
2850 /* the target must be in the requested direction */
2854 /* Calculate score for this window. The smaller the better. */
2855 score
= distance
+ offset
;
2857 /* windows more than 45 degrees off the direction are
2858 * heavily penalized and will only be chosen if nothing
2859 * else within a million pixels */
2860 if(offset
> distance
)
2863 if(best_score
== -1 || score
< best_score
)
2871 void client_set_layer(ObClient
*self
, int layer
)
2875 self
->above
= FALSE
;
2876 } else if (layer
== 0) {
2877 self
->below
= self
->above
= FALSE
;
2879 self
->below
= FALSE
;
2882 client_calc_layer(self
);
2883 client_change_state(self
); /* reflect this in the state hints */
2886 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
2888 if (self
->undecorated
!= undecorated
) {
2889 self
->undecorated
= undecorated
;
2890 client_setup_decor_and_functions(self
);
2891 client_change_state(self
); /* reflect this in the state hints */
2895 guint
client_monitor(ObClient
*self
)
2899 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2900 Rect
*area
= screen_physical_area_monitor(i
);
2901 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2904 if (i
== screen_num_monitors
) i
= 0;
2905 g_assert(i
< screen_num_monitors
);
2909 ObClient
*client_search_top_transient(ObClient
*self
)
2911 /* move up the transient chain as far as possible */
2912 if (self
->transient_for
) {
2913 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2914 return client_search_top_transient(self
->transient_for
);
2918 g_assert(self
->group
);
2920 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2921 ObClient
*c
= it
->data
;
2923 /* checking transient_for prevents infinate loops! */
2924 if (c
!= self
&& !c
->transient_for
)
2935 ObClient
*client_search_focus_parent(ObClient
*self
)
2937 if (self
->transient_for
) {
2938 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2939 if (client_focused(self
->transient_for
))
2940 return self
->transient_for
;
2944 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2945 ObClient
*c
= it
->data
;
2947 /* checking transient_for prevents infinate loops! */
2948 if (c
!= self
&& !c
->transient_for
)
2949 if (client_focused(c
))
2958 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
2960 if (self
->transient_for
) {
2961 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2962 if (self
->transient_for
== search
)
2967 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2968 ObClient
*c
= it
->data
;
2970 /* checking transient_for prevents infinate loops! */
2971 if (c
!= self
&& !c
->transient_for
)
2981 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2985 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2986 if (sit
->data
== search
)
2988 if (client_search_transient(sit
->data
, search
))
2994 void client_update_sm_client_id(ObClient
*self
)
2996 g_free(self
->sm_client_id
);
2997 self
->sm_client_id
= NULL
;
2999 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
3001 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
3002 &self
->sm_client_id
);
3005 /* finds the nearest edge in the given direction from the current client
3006 * note to self: the edge is the -frame- edge (the actual one), not the
3009 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
3012 int my_edge_start
, my_edge_end
, my_offset
;
3019 a
= screen_area(c
->desktop
);
3022 case OB_DIRECTION_NORTH
:
3023 my_edge_start
= c
->frame
->area
.x
;
3024 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3025 my_offset
= c
->frame
->area
.y
;
3027 dest
= a
->y
; /* default: top of screen */
3029 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3030 int his_edge_start
, his_edge_end
, his_offset
;
3031 ObClient
*cur
= it
->data
;
3035 if(!client_normal(cur
))
3037 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3042 his_edge_start
= cur
->frame
->area
.x
;
3043 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3044 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3046 if(his_offset
+ 1 > my_offset
)
3049 if(his_offset
< dest
)
3052 if(his_edge_start
>= my_edge_start
&&
3053 his_edge_start
<= my_edge_end
)
3056 if(my_edge_start
>= his_edge_start
&&
3057 my_edge_start
<= his_edge_end
)
3062 case OB_DIRECTION_SOUTH
:
3063 my_edge_start
= c
->frame
->area
.x
;
3064 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3065 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3067 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
3069 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3070 int his_edge_start
, his_edge_end
, his_offset
;
3071 ObClient
*cur
= it
->data
;
3075 if(!client_normal(cur
))
3077 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3082 his_edge_start
= cur
->frame
->area
.x
;
3083 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3084 his_offset
= cur
->frame
->area
.y
;
3087 if(his_offset
- 1 < my_offset
)
3090 if(his_offset
> dest
)
3093 if(his_edge_start
>= my_edge_start
&&
3094 his_edge_start
<= my_edge_end
)
3097 if(my_edge_start
>= his_edge_start
&&
3098 my_edge_start
<= his_edge_end
)
3103 case OB_DIRECTION_WEST
:
3104 my_edge_start
= c
->frame
->area
.y
;
3105 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3106 my_offset
= c
->frame
->area
.x
;
3108 dest
= a
->x
; /* default: leftmost egde of screen */
3110 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3111 int his_edge_start
, his_edge_end
, his_offset
;
3112 ObClient
*cur
= it
->data
;
3116 if(!client_normal(cur
))
3118 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3123 his_edge_start
= cur
->frame
->area
.y
;
3124 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3125 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3127 if(his_offset
+ 1 > my_offset
)
3130 if(his_offset
< dest
)
3133 if(his_edge_start
>= my_edge_start
&&
3134 his_edge_start
<= my_edge_end
)
3137 if(my_edge_start
>= his_edge_start
&&
3138 my_edge_start
<= his_edge_end
)
3144 case OB_DIRECTION_EAST
:
3145 my_edge_start
= c
->frame
->area
.y
;
3146 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3147 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3149 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
3151 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3152 int his_edge_start
, his_edge_end
, his_offset
;
3153 ObClient
*cur
= it
->data
;
3157 if(!client_normal(cur
))
3159 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3164 his_edge_start
= cur
->frame
->area
.y
;
3165 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3166 his_offset
= cur
->frame
->area
.x
;
3168 if(his_offset
- 1 < my_offset
)
3171 if(his_offset
> dest
)
3174 if(his_edge_start
>= my_edge_start
&&
3175 his_edge_start
<= my_edge_end
)
3178 if(my_edge_start
>= his_edge_start
&&
3179 my_edge_start
<= his_edge_end
)
3184 case OB_DIRECTION_NORTHEAST
:
3185 case OB_DIRECTION_SOUTHEAST
:
3186 case OB_DIRECTION_NORTHWEST
:
3187 case OB_DIRECTION_SOUTHWEST
:
3188 /* not implemented */
3190 g_assert_not_reached();
3195 ObClient
* client_under_pointer()
3199 ObClient
*ret
= NULL
;
3201 if (screen_pointer_pos(&x
, &y
)) {
3202 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
3203 if (WINDOW_IS_CLIENT(it
->data
)) {
3204 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3205 if (c
->frame
->visible
&&
3206 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {
3216 gboolean
client_has_group_siblings(ObClient
*self
)
3218 return self
->group
&& self
->group
->members
->next
;