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 | \
53 GList
*client_list
= NULL
;
54 GSList
*client_destructors
= NULL
;
56 static void client_get_all(ObClient
*self
);
57 static void client_toggle_border(ObClient
*self
, gboolean show
);
58 static void client_get_startup_id(ObClient
*self
);
59 static void client_get_area(ObClient
*self
);
60 static void client_get_desktop(ObClient
*self
);
61 static void client_get_state(ObClient
*self
);
62 static void client_get_shaped(ObClient
*self
);
63 static void client_get_mwm_hints(ObClient
*self
);
64 static void client_get_gravity(ObClient
*self
);
65 static void client_showhide(ObClient
*self
);
66 static void client_change_allowed_actions(ObClient
*self
);
67 static void client_change_state(ObClient
*self
);
68 static void client_apply_startup_state(ObClient
*self
);
69 static void client_restore_session_state(ObClient
*self
);
70 static void client_restore_session_stacking(ObClient
*self
);
71 static void client_urgent_notify(ObClient
*self
);
73 void client_startup(gboolean reconfig
)
80 void client_shutdown(gboolean reconfig
)
84 void client_add_destructor(GDestroyNotify func
)
86 client_destructors
= g_slist_prepend(client_destructors
, (gpointer
)func
);
89 void client_remove_destructor(GDestroyNotify func
)
91 client_destructors
= g_slist_remove(client_destructors
, (gpointer
)func
);
94 void client_set_list()
96 Window
*windows
, *win_it
;
98 guint size
= g_list_length(client_list
);
100 /* create an array of the window ids */
102 windows
= g_new(Window
, size
);
104 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
105 *win_it
= ((ObClient
*)it
->data
)->window
;
109 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
110 net_client_list
, window
, (guint32
*)windows
, size
);
119 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
123 for (it = self->transients; it; it = it->next) {
124 if (!func(it->data, data)) return;
125 client_foreach_transient(it->data, func, data);
129 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
131 if (self->transient_for) {
132 if (self->transient_for != OB_TRAN_GROUP) {
133 if (!func(self->transient_for, data)) return;
134 client_foreach_ancestor(self->transient_for, func, data);
138 for (it = self->group->members; it; it = it->next)
139 if (it->data != self &&
140 !((ObClient*)it->data)->transient_for) {
141 if (!func(it->data, data)) return;
142 client_foreach_ancestor(it->data, func, data);
149 void client_manage_all()
151 unsigned int i
, j
, nchild
;
154 XWindowAttributes attrib
;
156 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
157 &w
, &w
, &children
, &nchild
);
159 /* remove all icon windows from the list */
160 for (i
= 0; i
< nchild
; i
++) {
161 if (children
[i
] == None
) continue;
162 wmhints
= XGetWMHints(ob_display
, children
[i
]);
164 if ((wmhints
->flags
& IconWindowHint
) &&
165 (wmhints
->icon_window
!= children
[i
]))
166 for (j
= 0; j
< nchild
; j
++)
167 if (children
[j
] == wmhints
->icon_window
) {
175 for (i
= 0; i
< nchild
; ++i
) {
176 if (children
[i
] == None
)
178 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
179 if (attrib
.override_redirect
) continue;
181 if (attrib
.map_state
!= IsUnmapped
)
182 client_manage(children
[i
]);
188 void client_manage(Window window
)
192 XWindowAttributes attrib
;
193 XSetWindowAttributes attrib_set
;
195 gboolean activate
= FALSE
;
199 /* check if it has already been unmapped by the time we started mapping
200 the grab does a sync so we don't have to here */
201 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
202 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
203 XPutBackEvent(ob_display
, &e
);
206 return; /* don't manage it */
209 /* make sure it isn't an override-redirect window */
210 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
211 attrib
.override_redirect
) {
213 return; /* don't manage it */
216 /* is the window a docking app */
217 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
218 if ((wmhint
->flags
& StateHint
) &&
219 wmhint
->initial_state
== WithdrawnState
) {
220 dock_add(window
, wmhint
);
228 ob_debug("Managing window: %lx\n", window
);
230 /* choose the events we want to receive on the CLIENT window */
231 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
232 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
233 XChangeWindowAttributes(ob_display
, window
,
234 CWEventMask
|CWDontPropagate
, &attrib_set
);
237 /* create the ObClient struct, and populate it from the hints on the
239 self
= g_new0(ObClient
, 1);
240 self
->obwin
.type
= Window_Client
;
241 self
->window
= window
;
243 /* non-zero defaults */
244 self
->title_count
= 1;
245 self
->wmstate
= NormalState
;
247 self
->desktop
= screen_num_desktops
; /* always an invalid value */
249 client_get_all(self
);
250 client_restore_session_state(self
);
252 sn_app_started(self
->class);
254 client_change_state(self
);
256 /* remove the client's border (and adjust re gravity) */
257 client_toggle_border(self
, FALSE
);
259 /* specify that if we exit, the window should not be destroyed and should
260 be reparented back to root automatically */
261 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
263 /* create the decoration frame for the client window */
264 self
->frame
= frame_new();
266 frame_grab_client(self
->frame
, self
);
270 client_apply_startup_state(self
);
272 /* update the focus lists */
273 focus_order_add_new(self
);
275 stacking_add(CLIENT_AS_WINDOW(self
));
276 client_restore_session_stacking(self
);
278 /* focus the new window? */
279 if (ob_state() != OB_STATE_STARTING
&&
280 (config_focus_new
|| client_search_focus_parent(self
)) &&
281 /* note the check against Type_Normal/Dialog, not client_normal(self),
282 which would also include other types. in this case we want more
283 strict rules for focus */
284 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
285 self
->type
== OB_CLIENT_TYPE_DIALOG
))
289 if (self
->desktop
!= screen_desktop
) {
290 /* activate the window */
293 gboolean group_foc
= FALSE
;
298 for (it
= self
->group
->members
; it
; it
= it
->next
)
300 if (client_focused(it
->data
))
308 (!self
->transient_for
&& (!self
->group
||
309 !self
->group
->members
->next
))) ||
310 client_search_focus_tree_full(self
) ||
312 !client_normal(focus_client
))
314 /* activate the window */
321 if (ob_state() == OB_STATE_RUNNING
) {
322 int x
= self
->area
.x
, ox
= x
;
323 int y
= self
->area
.y
, oy
= y
;
325 place_client(self
, &x
, &y
);
327 /* make sure the window is visible */
328 client_find_onscreen(self
, &x
, &y
,
329 self
->frame
->area
.width
,
330 self
->frame
->area
.height
,
331 client_normal(self
));
333 if (x
!= ox
|| y
!= oy
)
334 client_move(self
, x
, y
);
337 client_showhide(self
);
339 /* use client_focus instead of client_activate cuz client_activate does
340 stuff like switch desktops etc and I'm not interested in all that when
341 a window maps since its not based on an action from the user like
342 clicking a window to activate is. so keep the new window out of the way
344 if (activate
) client_focus(self
);
346 /* client_activate does this but we aret using it so we have to do it
348 if (screen_showing_desktop
)
349 screen_show_desktop(FALSE
);
351 /* add to client list/map */
352 client_list
= g_list_append(client_list
, self
);
353 g_hash_table_insert(window_map
, &self
->window
, self
);
355 /* this has to happen after we're in the client_list */
356 screen_update_areas();
358 /* update the list hints */
361 keyboard_grab_for_client(self
, TRUE
);
362 mouse_grab_for_client(self
, TRUE
);
364 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
367 void client_unmanage_all()
369 while (client_list
!= NULL
)
370 client_unmanage(client_list
->data
);
373 void client_unmanage(ObClient
*self
)
378 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
380 g_assert(self
!= NULL
);
382 keyboard_grab_for_client(self
, FALSE
);
383 mouse_grab_for_client(self
, FALSE
);
385 /* remove the window from our save set */
386 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
388 /* we dont want events no more */
389 XSelectInput(ob_display
, self
->window
, NoEventMask
);
391 frame_hide(self
->frame
);
393 client_list
= g_list_remove(client_list
, self
);
394 stacking_remove(self
);
395 g_hash_table_remove(window_map
, &self
->window
);
397 /* update the focus lists */
398 focus_order_remove(self
);
400 /* once the client is out of the list, update the struts to remove it's
402 screen_update_areas();
404 /* tell our parent(s) that we're gone */
405 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
408 for (it
= self
->group
->members
; it
; it
= it
->next
)
409 if (it
->data
!= self
)
410 ((ObClient
*)it
->data
)->transients
=
411 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
412 } else if (self
->transient_for
) { /* transient of window */
413 self
->transient_for
->transients
=
414 g_slist_remove(self
->transient_for
->transients
, self
);
417 /* tell our transients that we're gone */
418 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
419 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
420 ((ObClient
*)it
->data
)->transient_for
= NULL
;
421 client_calc_layer(it
->data
);
425 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
426 GDestroyNotify func
= (GDestroyNotify
) it
->data
;
430 if (focus_client
== self
) {
433 /* focus the last focused window on the desktop, and ignore enter
434 events from the unmap so it doesnt mess with the focus */
435 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
436 client_unfocus(self
);
439 /* remove from its group */
441 group_remove(self
->group
, self
);
445 /* give the client its border back */
446 client_toggle_border(self
, TRUE
);
448 /* reparent the window out of the frame, and free the frame */
449 frame_release_client(self
->frame
, self
);
452 if (ob_state() != OB_STATE_EXITING
) {
453 /* these values should not be persisted across a window
455 PROP_ERASE(self
->window
, net_wm_desktop
);
456 PROP_ERASE(self
->window
, net_wm_state
);
457 PROP_ERASE(self
->window
, wm_state
);
459 /* if we're left in an iconic state, the client wont be mapped. this is
460 bad, since we will no longer be managing the window on restart */
462 XMapWindow(ob_display
, self
->window
);
466 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
468 /* free all data allocated in the client struct */
469 g_slist_free(self
->transients
);
470 for (j
= 0; j
< self
->nicons
; ++j
)
471 g_free(self
->icons
[j
].data
);
472 if (self
->nicons
> 0)
475 g_free(self
->icon_title
);
479 g_free(self
->sm_client_id
);
482 /* update the list hints */
486 static void client_urgent_notify(ObClient
*self
)
489 frame_flash_start(self
->frame
);
491 frame_flash_stop(self
->frame
);
494 static void client_restore_session_state(ObClient
*self
)
498 if (!(it
= session_state_find(self
)))
501 self
->session
= it
->data
;
503 RECT_SET(self
->area
, self
->session
->x
, self
->session
->y
,
504 self
->session
->w
, self
->session
->h
);
505 self
->positioned
= TRUE
;
506 XResizeWindow(ob_display
, self
->window
,
507 self
->session
->w
, self
->session
->h
);
509 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
510 self
->session
->desktop
:
511 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
512 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
514 self
->shaded
= self
->session
->shaded
;
515 self
->iconic
= self
->session
->iconic
;
516 self
->skip_pager
= self
->session
->skip_pager
;
517 self
->skip_taskbar
= self
->session
->skip_taskbar
;
518 self
->fullscreen
= self
->session
->fullscreen
;
519 self
->above
= self
->session
->above
;
520 self
->below
= self
->session
->below
;
521 self
->max_horz
= self
->session
->max_horz
;
522 self
->max_vert
= self
->session
->max_vert
;
525 static void client_restore_session_stacking(ObClient
*self
)
529 if (!self
->session
) return;
531 it
= g_list_find(session_saved_state
, self
->session
);
532 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
535 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
536 if (session_state_cmp(it
->data
, cit
->data
))
539 client_calc_layer(self
);
540 stacking_below(CLIENT_AS_WINDOW(self
),
541 CLIENT_AS_WINDOW(cit
->data
));
547 void client_move_onscreen(ObClient
*self
, gboolean rude
)
549 int x
= self
->area
.x
;
550 int y
= self
->area
.y
;
551 if (client_find_onscreen(self
, &x
, &y
,
552 self
->frame
->area
.width
,
553 self
->frame
->area
.height
, rude
)) {
554 client_move(self
, x
, y
);
558 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
562 int ox
= *x
, oy
= *y
;
564 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
567 /* XXX watch for xinerama dead areas */
569 a
= screen_area(self
->desktop
);
570 if (client_normal(self
)) {
571 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
572 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
573 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
574 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
575 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
577 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
582 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
583 Java can suck it too. */
585 /* dont let windows map/move into the strut unless they
586 are bigger than the available area */
588 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
589 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
590 *x
= a
->x
+ a
->width
- w
;
592 if (h
<= a
->height
) {
593 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
594 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
595 *y
= a
->y
+ a
->height
- h
;
599 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
602 return ox
!= *x
|| oy
!= *y
;
605 static void client_toggle_border(ObClient
*self
, gboolean show
)
607 /* adjust our idea of where the client is, based on its border. When the
608 border is removed, the client should now be considered to be in a
610 when re-adding the border to the client, the same operation needs to be
612 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
613 int x
= oldx
, y
= oldy
;
614 switch(self
->gravity
) {
616 case NorthWestGravity
:
618 case SouthWestGravity
:
620 case NorthEastGravity
:
622 case SouthEastGravity
:
623 if (show
) x
-= self
->border_width
* 2;
624 else x
+= self
->border_width
* 2;
631 if (show
) x
-= self
->border_width
;
632 else x
+= self
->border_width
;
635 switch(self
->gravity
) {
637 case NorthWestGravity
:
639 case NorthEastGravity
:
641 case SouthWestGravity
:
643 case SouthEastGravity
:
644 if (show
) y
-= self
->border_width
* 2;
645 else y
+= self
->border_width
* 2;
652 if (show
) y
-= self
->border_width
;
653 else y
+= self
->border_width
;
660 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
662 /* move the client so it is back it the right spot _with_ its
664 if (x
!= oldx
|| y
!= oldy
)
665 XMoveWindow(ob_display
, self
->window
, x
, y
);
667 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
671 static void client_get_all(ObClient
*self
)
673 client_get_area(self
);
674 client_update_transient_for(self
);
675 client_update_wmhints(self
);
676 client_get_startup_id(self
);
677 client_get_desktop(self
);
678 client_get_state(self
);
679 client_get_shaped(self
);
681 client_get_mwm_hints(self
);
682 client_get_type(self
);/* this can change the mwmhints for special cases */
684 client_update_protocols(self
);
686 client_get_gravity(self
); /* get the attribute gravity */
687 client_update_normal_hints(self
); /* this may override the attribute
690 /* got the type, the mwmhints, the protocols, and the normal hints
691 (min/max sizes), so we're ready to set up the decorations/functions */
692 client_setup_decor_and_functions(self
);
694 client_update_title(self
);
695 client_update_class(self
);
696 client_update_sm_client_id(self
);
697 client_update_strut(self
);
698 client_update_icons(self
);
701 static void client_get_startup_id(ObClient
*self
)
703 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
705 PROP_GETS(self
->group
->leader
,
706 net_startup_id
, utf8
, &self
->startup_id
);
709 static void client_get_area(ObClient
*self
)
711 XWindowAttributes wattrib
;
714 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
715 g_assert(ret
!= BadWindow
);
717 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
718 self
->border_width
= wattrib
.border_width
;
721 static void client_get_desktop(ObClient
*self
)
723 guint32 d
= screen_num_desktops
; /* an always-invalid value */
725 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
726 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
727 self
->desktop
= screen_num_desktops
- 1;
731 gboolean trdesk
= FALSE
;
733 if (self
->transient_for
) {
734 if (self
->transient_for
!= OB_TRAN_GROUP
) {
735 self
->desktop
= self
->transient_for
->desktop
;
740 for (it
= self
->group
->members
; it
; it
= it
->next
)
741 if (it
->data
!= self
&&
742 !((ObClient
*)it
->data
)->transient_for
) {
743 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
750 /* try get from the startup-notification protocol */
751 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
752 if (self
->desktop
>= screen_num_desktops
&&
753 self
->desktop
!= DESKTOP_ALL
)
754 self
->desktop
= screen_num_desktops
- 1;
756 /* defaults to the current desktop */
757 self
->desktop
= screen_desktop
;
760 if (self
->desktop
!= d
) {
761 /* set the desktop hint, to make sure that it always exists */
762 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
766 static void client_get_state(ObClient
*self
)
771 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
773 for (i
= 0; i
< num
; ++i
) {
774 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
776 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
778 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
780 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
781 self
->skip_taskbar
= TRUE
;
782 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
783 self
->skip_pager
= TRUE
;
784 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
785 self
->fullscreen
= TRUE
;
786 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
787 self
->max_vert
= TRUE
;
788 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
789 self
->max_horz
= TRUE
;
790 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
792 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
794 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
795 self
->undecorated
= TRUE
;
802 static void client_get_shaped(ObClient
*self
)
804 self
->shaped
= FALSE
;
806 if (extensions_shape
) {
811 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
813 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
814 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
816 self
->shaped
= (s
!= 0);
821 void client_update_transient_for(ObClient
*self
)
824 ObClient
*target
= NULL
;
826 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
827 self
->transient
= TRUE
;
828 if (t
!= self
->window
) { /* cant be transient to itself! */
829 target
= g_hash_table_lookup(window_map
, &t
);
830 /* if this happens then we need to check for it*/
831 g_assert(target
!= self
);
832 if (target
&& !WINDOW_IS_CLIENT(target
)) {
833 /* this can happen when a dialog is a child of
834 a dockapp, for example */
838 if (!target
&& self
->group
) {
839 /* not transient to a client, see if it is transient for a
841 if (t
== self
->group
->leader
||
843 t
== RootWindow(ob_display
, ob_screen
)) {
844 /* window is a transient for its group! */
845 target
= OB_TRAN_GROUP
;
850 self
->transient
= FALSE
;
852 /* if anything has changed... */
853 if (target
!= self
->transient_for
) {
854 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
857 /* remove from old parents */
858 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
859 ObClient
*c
= it
->data
;
860 if (c
!= self
&& !c
->transient_for
)
861 c
->transients
= g_slist_remove(c
->transients
, self
);
863 } else if (self
->transient_for
!= NULL
) { /* transient of window */
864 /* remove from old parent */
865 self
->transient_for
->transients
=
866 g_slist_remove(self
->transient_for
->transients
, self
);
868 self
->transient_for
= target
;
869 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
872 /* add to new parents */
873 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
874 ObClient
*c
= it
->data
;
875 if (c
!= self
&& !c
->transient_for
)
876 c
->transients
= g_slist_append(c
->transients
, self
);
879 /* remove all transients which are in the group, that causes
880 circlular pointer hell of doom */
881 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
883 for (sit
= self
->transients
; sit
; sit
= next
) {
884 next
= g_slist_next(sit
);
885 if (sit
->data
== it
->data
)
887 g_slist_delete_link(self
->transients
, sit
);
890 } else if (self
->transient_for
!= NULL
) { /* transient of window */
891 /* add to new parent */
892 self
->transient_for
->transients
=
893 g_slist_append(self
->transient_for
->transients
, self
);
898 static void client_get_mwm_hints(ObClient
*self
)
903 self
->mwmhints
.flags
= 0; /* default to none */
905 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
907 if (num
>= OB_MWM_ELEMENTS
) {
908 self
->mwmhints
.flags
= hints
[0];
909 self
->mwmhints
.functions
= hints
[1];
910 self
->mwmhints
.decorations
= hints
[2];
916 void client_get_type(ObClient
*self
)
923 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
924 /* use the first value that we know about in the array */
925 for (i
= 0; i
< num
; ++i
) {
926 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
927 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
928 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
929 self
->type
= OB_CLIENT_TYPE_DOCK
;
930 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
931 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
932 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
933 self
->type
= OB_CLIENT_TYPE_MENU
;
934 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
935 self
->type
= OB_CLIENT_TYPE_UTILITY
;
936 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
937 self
->type
= OB_CLIENT_TYPE_SPLASH
;
938 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
939 self
->type
= OB_CLIENT_TYPE_DIALOG
;
940 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
941 self
->type
= OB_CLIENT_TYPE_NORMAL
;
942 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
943 /* prevent this window from getting any decor or
945 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
946 OB_MWM_FLAG_DECORATIONS
);
947 self
->mwmhints
.decorations
= 0;
948 self
->mwmhints
.functions
= 0;
950 if (self
->type
!= (ObClientType
) -1)
951 break; /* grab the first legit type */
956 if (self
->type
== (ObClientType
) -1) {
957 /*the window type hint was not set, which means we either classify
958 ourself as a normal window or a dialog, depending on if we are a
961 self
->type
= OB_CLIENT_TYPE_DIALOG
;
963 self
->type
= OB_CLIENT_TYPE_NORMAL
;
967 void client_update_protocols(ObClient
*self
)
972 self
->focus_notify
= FALSE
;
973 self
->delete_window
= FALSE
;
975 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
976 for (i
= 0; i
< num_return
; ++i
) {
977 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
978 /* this means we can request the window to close */
979 self
->delete_window
= TRUE
;
980 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
981 /* if this protocol is requested, then the window will be
982 notified whenever we want it to receive focus */
983 self
->focus_notify
= TRUE
;
989 static void client_get_gravity(ObClient
*self
)
991 XWindowAttributes wattrib
;
994 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
995 g_assert(ret
!= BadWindow
);
996 self
->gravity
= wattrib
.win_gravity
;
999 void client_update_normal_hints(ObClient
*self
)
1003 int oldgravity
= self
->gravity
;
1006 self
->min_ratio
= 0.0f
;
1007 self
->max_ratio
= 0.0f
;
1008 SIZE_SET(self
->size_inc
, 1, 1);
1009 SIZE_SET(self
->base_size
, 0, 0);
1010 SIZE_SET(self
->min_size
, 0, 0);
1011 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1013 /* get the hints from the window */
1014 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1015 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1017 if (size
.flags
& PWinGravity
) {
1018 self
->gravity
= size
.win_gravity
;
1020 /* if the client has a frame, i.e. has already been mapped and
1021 is changing its gravity */
1022 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1023 /* move our idea of the client's position based on its new
1025 self
->area
.x
= self
->frame
->area
.x
;
1026 self
->area
.y
= self
->frame
->area
.y
;
1027 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1031 if (size
.flags
& PAspect
) {
1032 if (size
.min_aspect
.y
)
1033 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1034 if (size
.max_aspect
.y
)
1035 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1038 if (size
.flags
& PMinSize
)
1039 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1041 if (size
.flags
& PMaxSize
)
1042 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1044 if (size
.flags
& PBaseSize
)
1045 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1047 if (size
.flags
& PResizeInc
)
1048 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1052 void client_setup_decor_and_functions(ObClient
*self
)
1054 /* start with everything (cept fullscreen) */
1056 (OB_FRAME_DECOR_TITLEBAR
|
1057 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1058 OB_FRAME_DECOR_GRIPS
|
1059 OB_FRAME_DECOR_BORDER
|
1060 OB_FRAME_DECOR_ICON
|
1061 OB_FRAME_DECOR_ALLDESKTOPS
|
1062 OB_FRAME_DECOR_ICONIFY
|
1063 OB_FRAME_DECOR_MAXIMIZE
|
1064 OB_FRAME_DECOR_SHADE
);
1066 (OB_CLIENT_FUNC_RESIZE
|
1067 OB_CLIENT_FUNC_MOVE
|
1068 OB_CLIENT_FUNC_ICONIFY
|
1069 OB_CLIENT_FUNC_MAXIMIZE
|
1070 OB_CLIENT_FUNC_SHADE
);
1071 if (self
->delete_window
) {
1072 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1073 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1076 if (!(self
->min_size
.width
< self
->max_size
.width
||
1077 self
->min_size
.height
< self
->max_size
.height
))
1078 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1080 switch (self
->type
) {
1081 case OB_CLIENT_TYPE_NORMAL
:
1082 /* normal windows retain all of the possible decorations and
1083 functionality, and are the only windows that you can fullscreen */
1084 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1087 case OB_CLIENT_TYPE_DIALOG
:
1088 case OB_CLIENT_TYPE_UTILITY
:
1089 /* these windows cannot be maximized */
1090 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1093 case OB_CLIENT_TYPE_MENU
:
1094 case OB_CLIENT_TYPE_TOOLBAR
:
1095 /* these windows get less functionality */
1096 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1099 case OB_CLIENT_TYPE_DESKTOP
:
1100 case OB_CLIENT_TYPE_DOCK
:
1101 case OB_CLIENT_TYPE_SPLASH
:
1102 /* none of these windows are manipulated by the window manager */
1103 self
->decorations
= 0;
1104 self
->functions
= 0;
1108 /* Mwm Hints are applied subtractively to what has already been chosen for
1109 decor and functionality */
1110 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1111 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1112 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1113 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1114 /* if the mwm hints request no handle or title, then all
1115 decorations are disabled */
1116 self
->decorations
= 0;
1120 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1121 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1122 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1123 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1124 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1125 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1126 /* dont let mwm hints kill any buttons
1127 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1128 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1129 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1130 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1132 /* dont let mwm hints kill the close button
1133 if (! (self->mwmhints.functions & MwmFunc_Close))
1134 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1138 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1139 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1140 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1141 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1142 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1143 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1145 /* can't maximize without moving/resizing */
1146 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1147 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1148 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1149 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1150 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1153 /* kill the handle on fully maxed windows */
1154 if (self
->max_vert
&& self
->max_horz
)
1155 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1157 /* finally, the user can have requested no decorations, which overrides
1159 if (self
->undecorated
)
1160 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1162 /* if we don't have a titlebar, then we cannot shade! */
1163 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1164 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1166 /* now we need to check against rules for the client's current state */
1167 if (self
->fullscreen
) {
1168 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1169 OB_CLIENT_FUNC_FULLSCREEN
|
1170 OB_CLIENT_FUNC_ICONIFY
);
1171 self
->decorations
= 0;
1174 client_change_allowed_actions(self
);
1177 /* adjust the client's decorations, etc. */
1178 client_reconfigure(self
);
1180 /* this makes sure that these windows appear on all desktops */
1181 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1182 self
->desktop
!= DESKTOP_ALL
)
1184 self
->desktop
= DESKTOP_ALL
;
1189 static void client_change_allowed_actions(ObClient
*self
)
1194 /* desktop windows are kept on all desktops */
1195 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1196 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1198 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1199 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1200 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1201 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1202 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1203 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1204 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1205 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1206 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1207 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1208 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1209 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1210 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1211 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1212 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1215 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1217 /* make sure the window isn't breaking any rules now */
1219 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1220 if (self
->frame
) client_shade(self
, FALSE
);
1221 else self
->shaded
= FALSE
;
1223 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1224 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1225 else self
->iconic
= FALSE
;
1227 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1228 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1229 else self
->fullscreen
= FALSE
;
1231 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1233 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1234 else self
->max_vert
= self
->max_horz
= FALSE
;
1238 void client_reconfigure(ObClient
*self
)
1240 /* by making this pass FALSE for user, we avoid the emacs event storm where
1241 every configurenotify causes an update in its normal hints, i think this
1242 is generally what we want anyways... */
1243 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1244 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1247 void client_update_wmhints(ObClient
*self
)
1250 gboolean ur
= FALSE
;
1253 /* assume a window takes input if it doesnt specify */
1254 self
->can_focus
= TRUE
;
1256 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1257 if (hints
->flags
& InputHint
)
1258 self
->can_focus
= hints
->input
;
1260 /* only do this when first managing the window *AND* when we aren't
1262 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1263 if (hints
->flags
& StateHint
)
1264 self
->iconic
= hints
->initial_state
== IconicState
;
1266 if (hints
->flags
& XUrgencyHint
)
1269 if (!(hints
->flags
& WindowGroupHint
))
1270 hints
->window_group
= None
;
1272 /* did the group state change? */
1273 if (hints
->window_group
!=
1274 (self
->group
? self
->group
->leader
: None
)) {
1275 /* remove from the old group if there was one */
1276 if (self
->group
!= NULL
) {
1277 /* remove transients of the group */
1278 for (it
= self
->group
->members
; it
; it
= it
->next
)
1279 self
->transients
= g_slist_remove(self
->transients
,
1281 group_remove(self
->group
, self
);
1284 if (hints
->window_group
!= None
) {
1285 self
->group
= group_add(hints
->window_group
, self
);
1287 /* i can only have transients from the group if i am not
1289 if (!self
->transient_for
) {
1290 /* add other transients of the group that are already
1292 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1293 ObClient
*c
= it
->data
;
1294 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1296 g_slist_append(self
->transients
, c
);
1301 /* because the self->transient flag wont change from this call,
1302 we don't need to update the window's type and such, only its
1303 transient_for, and the transients lists of other windows in
1304 the group may be affected */
1305 client_update_transient_for(self
);
1308 /* the WM_HINTS can contain an icon */
1309 client_update_icons(self
);
1314 if (ur
!= self
->urgent
) {
1316 /* fire the urgent callback if we're mapped, otherwise, wait until
1317 after we're mapped */
1319 client_urgent_notify(self
);
1323 void client_update_title(ObClient
*self
)
1329 gboolean read_title
;
1332 old_title
= self
->title
;
1335 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1336 /* try old x stuff */
1337 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1338 data
= g_strdup("Unnamed Window");
1340 /* did the title change? then reset the title_count */
1341 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1342 self
->title_count
= 1;
1344 /* look for duplicates and append a number */
1346 for (it
= client_list
; it
; it
= it
->next
)
1347 if (it
->data
!= self
) {
1348 ObClient
*c
= it
->data
;
1349 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1350 nums
|= 1 << c
->title_count
;
1352 /* find first free number */
1353 for (i
= 1; i
<= 32; ++i
)
1354 if (!(nums
& (1 << i
))) {
1355 if (self
->title_count
== 1 || i
== 1)
1356 self
->title_count
= i
;
1359 /* dont display the number for the first window */
1360 if (self
->title_count
> 1) {
1362 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1367 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1372 frame_adjust_title(self
->frame
);
1376 /* update the icon title */
1378 g_free(self
->icon_title
);
1382 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1383 /* try old x stuff */
1384 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1385 data
= g_strdup(self
->title
);
1389 /* append the title count, dont display the number for the first window */
1390 if (read_title
&& self
->title_count
> 1) {
1391 char *vdata
, *ndata
;
1392 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1393 vdata
= g_strconcat(data
, ndata
, NULL
);
1399 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1401 self
->icon_title
= data
;
1404 void client_update_class(ObClient
*self
)
1409 if (self
->name
) g_free(self
->name
);
1410 if (self
->class) g_free(self
->class);
1411 if (self
->role
) g_free(self
->role
);
1413 self
->name
= self
->class = self
->role
= NULL
;
1415 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1417 self
->name
= g_strdup(data
[0]);
1419 self
->class = g_strdup(data
[1]);
1424 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1427 if (self
->name
== NULL
) self
->name
= g_strdup("");
1428 if (self
->class == NULL
) self
->class = g_strdup("");
1429 if (self
->role
== NULL
) self
->role
= g_strdup("");
1432 void client_update_strut(ObClient
*self
)
1436 gboolean got
= FALSE
;
1439 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1443 STRUT_PARTIAL_SET(strut
,
1444 data
[0], data
[2], data
[1], data
[3],
1445 data
[4], data
[5], data
[8], data
[9],
1446 data
[6], data
[7], data
[10], data
[11]);
1452 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1455 STRUT_PARTIAL_SET(strut
,
1456 data
[0], data
[2], data
[1], data
[3],
1457 0, 0, 0, 0, 0, 0, 0, 0);
1463 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1464 0, 0, 0, 0, 0, 0, 0, 0);
1466 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1467 self
->strut
= strut
;
1469 /* updating here is pointless while we're being mapped cuz we're not in
1470 the client list yet */
1472 screen_update_areas();
1476 void client_update_icons(ObClient
*self
)
1482 for (i
= 0; i
< self
->nicons
; ++i
)
1483 g_free(self
->icons
[i
].data
);
1484 if (self
->nicons
> 0)
1485 g_free(self
->icons
);
1488 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1489 /* figure out how many valid icons are in here */
1491 while (num
- i
> 2) {
1495 if (i
> num
|| w
*h
== 0) break;
1499 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1501 /* store the icons */
1503 for (j
= 0; j
< self
->nicons
; ++j
) {
1506 w
= self
->icons
[j
].width
= data
[i
++];
1507 h
= self
->icons
[j
].height
= data
[i
++];
1509 if (w
*h
== 0) continue;
1511 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1512 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1517 self
->icons
[j
].data
[t
] =
1518 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1519 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1520 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1521 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1527 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1528 kwm_win_icon
, &data
, &num
)) {
1531 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1532 xerror_set_ignore(TRUE
);
1533 if (!RrPixmapToRGBA(ob_rr_inst
,
1535 &self
->icons
[self
->nicons
-1].width
,
1536 &self
->icons
[self
->nicons
-1].height
,
1537 &self
->icons
[self
->nicons
-1].data
)) {
1538 g_free(&self
->icons
[self
->nicons
-1]);
1541 xerror_set_ignore(FALSE
);
1547 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1548 if (hints
->flags
& IconPixmapHint
) {
1550 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1551 xerror_set_ignore(TRUE
);
1552 if (!RrPixmapToRGBA(ob_rr_inst
,
1554 (hints
->flags
& IconMaskHint
?
1555 hints
->icon_mask
: None
),
1556 &self
->icons
[self
->nicons
-1].width
,
1557 &self
->icons
[self
->nicons
-1].height
,
1558 &self
->icons
[self
->nicons
-1].data
)){
1559 g_free(&self
->icons
[self
->nicons
-1]);
1562 xerror_set_ignore(FALSE
);
1568 if (!self
->nicons
) {
1570 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1571 self
->icons
[self
->nicons
-1].width
= 48;
1572 self
->icons
[self
->nicons
-1].height
= 48;
1573 self
->icons
[self
->nicons
-1].data
= g_memdup(ob_rr_theme
->def_win_icon
,
1579 frame_adjust_icon(self
->frame
);
1582 static void client_change_state(ObClient
*self
)
1585 guint32 netstate
[11];
1588 state
[0] = self
->wmstate
;
1590 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1594 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1596 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1598 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1599 if (self
->skip_taskbar
)
1600 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1601 if (self
->skip_pager
)
1602 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1603 if (self
->fullscreen
)
1604 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1606 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1608 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1610 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1612 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1613 if (self
->undecorated
)
1614 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
1615 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1617 client_calc_layer(self
);
1620 frame_adjust_state(self
->frame
);
1623 ObClient
*client_search_focus_tree(ObClient
*self
)
1628 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1629 if (client_focused(it
->data
)) return it
->data
;
1630 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1635 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1637 if (self
->transient_for
) {
1638 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1639 return client_search_focus_tree_full(self
->transient_for
);
1642 gboolean recursed
= FALSE
;
1644 for (it
= self
->group
->members
; it
; it
= it
->next
)
1645 if (!((ObClient
*)it
->data
)->transient_for
) {
1647 if ((c
= client_search_focus_tree_full(it
->data
)))
1656 /* this function checks the whole tree, the client_search_focus_tree~
1657 does not, so we need to check this window */
1658 if (client_focused(self
))
1660 return client_search_focus_tree(self
);
1663 static ObStackingLayer
calc_layer(ObClient
*self
)
1667 if (self
->fullscreen
&&
1668 (client_focused(self
) || client_search_focus_tree(self
)))
1669 l
= OB_STACKING_LAYER_FULLSCREEN
;
1670 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1671 l
= OB_STACKING_LAYER_DESKTOP
;
1672 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1673 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1674 else l
= OB_STACKING_LAYER_NORMAL
;
1676 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1677 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1678 else l
= OB_STACKING_LAYER_NORMAL
;
1683 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1684 ObStackingLayer l
, gboolean raised
)
1686 ObStackingLayer old
, own
;
1690 own
= calc_layer(self
);
1691 self
->layer
= l
> own
? l
: own
;
1693 for (it
= self
->transients
; it
; it
= it
->next
)
1694 client_calc_layer_recursive(it
->data
, orig
,
1695 l
, raised
? raised
: l
!= old
);
1697 if (!raised
&& l
!= old
)
1698 if (orig
->frame
) { /* only restack if the original window is managed */
1699 /* XXX add_non_intrusive ever? */
1700 stacking_remove(CLIENT_AS_WINDOW(self
));
1701 stacking_add(CLIENT_AS_WINDOW(self
));
1705 void client_calc_layer(ObClient
*self
)
1712 /* transients take on the layer of their parents */
1713 self
= client_search_top_transient(self
);
1715 l
= calc_layer(self
);
1717 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1720 gboolean
client_should_show(ObClient
*self
)
1722 if (self
->iconic
) return FALSE
;
1723 else if (!(self
->desktop
== screen_desktop
||
1724 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1725 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1730 static void client_showhide(ObClient
*self
)
1733 if (client_should_show(self
))
1734 frame_show(self
->frame
);
1736 frame_hide(self
->frame
);
1739 gboolean
client_normal(ObClient
*self
) {
1740 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1741 self
->type
== OB_CLIENT_TYPE_DOCK
||
1742 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1745 static void client_apply_startup_state(ObClient
*self
)
1747 /* these are in a carefully crafted order.. */
1750 self
->iconic
= FALSE
;
1751 client_iconify(self
, TRUE
, FALSE
);
1753 if (self
->fullscreen
) {
1754 self
->fullscreen
= FALSE
;
1755 client_fullscreen(self
, TRUE
, FALSE
);
1757 if (self
->undecorated
) {
1758 self
->undecorated
= FALSE
;
1759 client_set_undecorated(self
, TRUE
);
1762 self
->shaded
= FALSE
;
1763 client_shade(self
, TRUE
);
1766 client_urgent_notify(self
);
1768 if (self
->max_vert
&& self
->max_horz
) {
1769 self
->max_vert
= self
->max_horz
= FALSE
;
1770 client_maximize(self
, TRUE
, 0, FALSE
);
1771 } else if (self
->max_vert
) {
1772 self
->max_vert
= FALSE
;
1773 client_maximize(self
, TRUE
, 2, FALSE
);
1774 } else if (self
->max_horz
) {
1775 self
->max_horz
= FALSE
;
1776 client_maximize(self
, TRUE
, 1, FALSE
);
1779 /* nothing to do for the other states:
1788 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1789 int x
, int y
, int w
, int h
,
1790 gboolean user
, gboolean final
,
1791 gboolean force_reply
)
1794 gboolean send_resize_client
;
1795 gboolean moved
= FALSE
, resized
= FALSE
;
1796 guint fdecor
= self
->frame
->decorations
;
1797 gboolean fhorz
= self
->frame
->max_horz
;
1799 /* make the frame recalculate its dimentions n shit without changing
1800 anything visible for real, this way the constraints below can work with
1801 the updated frame dimensions. */
1802 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1804 /* gets the frame's position */
1805 frame_client_gravity(self
->frame
, &x
, &y
);
1807 /* these positions are frame positions, not client positions */
1809 /* set the size and position if fullscreen */
1810 if (self
->fullscreen
) {
1813 XF86VidModeModeLine mode
;
1818 i
= client_monitor(self
);
1819 a
= screen_physical_area_monitor(i
);
1822 if (i
== 0 && /* primary head */
1823 extensions_vidmode
&&
1824 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1825 /* get the mode last so the mode.privsize isnt freed incorrectly */
1826 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1831 if (mode
.privsize
) XFree(mode
.private);
1841 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1845 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1847 /* set the size and position if maximized */
1848 if (self
->max_horz
) {
1850 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1852 if (self
->max_vert
) {
1854 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1858 /* gets the client's position */
1859 frame_frame_gravity(self
->frame
, &x
, &y
);
1861 /* these override the above states! if you cant move you can't move! */
1863 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1867 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1868 w
= self
->area
.width
;
1869 h
= self
->area
.height
;
1873 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1874 int basew
, baseh
, minw
, minh
;
1876 /* base size is substituted with min size if not specified */
1877 if (self
->base_size
.width
|| self
->base_size
.height
) {
1878 basew
= self
->base_size
.width
;
1879 baseh
= self
->base_size
.height
;
1881 basew
= self
->min_size
.width
;
1882 baseh
= self
->min_size
.height
;
1884 /* min size is substituted with base size if not specified */
1885 if (self
->min_size
.width
|| self
->min_size
.height
) {
1886 minw
= self
->min_size
.width
;
1887 minh
= self
->min_size
.height
;
1889 minw
= self
->base_size
.width
;
1890 minh
= self
->base_size
.height
;
1893 /* if this is a user-requested resize, then check against min/max
1896 /* smaller than min size or bigger than max size? */
1897 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1898 if (w
< minw
) w
= minw
;
1899 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1900 if (h
< minh
) h
= minh
;
1905 /* keep to the increments */
1906 w
/= self
->size_inc
.width
;
1907 h
/= self
->size_inc
.height
;
1909 /* you cannot resize to nothing */
1910 if (basew
+ w
< 1) w
= 1 - basew
;
1911 if (baseh
+ h
< 1) h
= 1 - baseh
;
1913 /* store the logical size */
1914 SIZE_SET(self
->logical_size
,
1915 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1916 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1918 w
*= self
->size_inc
.width
;
1919 h
*= self
->size_inc
.height
;
1924 /* adjust the height to match the width for the aspect ratios.
1925 for this, min size is not substituted for base size ever. */
1926 w
-= self
->base_size
.width
;
1927 h
-= self
->base_size
.height
;
1929 if (self
->min_ratio
)
1930 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1931 if (self
->max_ratio
)
1932 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1934 w
+= self
->base_size
.width
;
1935 h
+= self
->base_size
.height
;
1939 case OB_CORNER_TOPLEFT
:
1941 case OB_CORNER_TOPRIGHT
:
1942 x
-= w
- self
->area
.width
;
1944 case OB_CORNER_BOTTOMLEFT
:
1945 y
-= h
- self
->area
.height
;
1947 case OB_CORNER_BOTTOMRIGHT
:
1948 x
-= w
- self
->area
.width
;
1949 y
-= h
- self
->area
.height
;
1953 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1954 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1956 oldw
= self
->area
.width
;
1957 oldh
= self
->area
.height
;
1958 RECT_SET(self
->area
, x
, y
, w
, h
);
1960 /* for app-requested resizes, always resize if 'resized' is true.
1961 for user-requested ones, only resize if final is true, or when
1962 resizing in redraw mode */
1963 send_resize_client
= ((!user
&& resized
) ||
1965 (resized
&& config_redraw_resize
))));
1967 /* if the client is enlarging, the resize the client before the frame */
1968 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
1969 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
1971 /* move/resize the frame to match the request */
1973 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
1974 moved
= resized
= TRUE
;
1976 if (moved
|| resized
)
1977 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
1979 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1982 event
.type
= ConfigureNotify
;
1983 event
.xconfigure
.display
= ob_display
;
1984 event
.xconfigure
.event
= self
->window
;
1985 event
.xconfigure
.window
= self
->window
;
1987 /* root window real coords */
1988 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1990 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1992 event
.xconfigure
.width
= w
;
1993 event
.xconfigure
.height
= h
;
1994 event
.xconfigure
.border_width
= 0;
1995 event
.xconfigure
.above
= self
->frame
->plate
;
1996 event
.xconfigure
.override_redirect
= FALSE
;
1997 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1998 FALSE
, StructureNotifyMask
, &event
);
2002 /* if the client is shrinking, then resize the frame before the client */
2003 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
2004 XResizeWindow(ob_display
, self
->window
, w
, h
);
2009 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2013 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2014 self
->fullscreen
== fs
) return; /* already done */
2016 self
->fullscreen
= fs
;
2017 client_change_state(self
); /* change the state hints on the client,
2018 and adjust out layer/stacking */
2022 self
->pre_fullscreen_area
= self
->area
;
2024 /* these are not actually used cuz client_configure will set them
2025 as appropriate when the window is fullscreened */
2030 if (self
->pre_fullscreen_area
.width
> 0 &&
2031 self
->pre_fullscreen_area
.height
> 0)
2033 x
= self
->pre_fullscreen_area
.x
;
2034 y
= self
->pre_fullscreen_area
.y
;
2035 w
= self
->pre_fullscreen_area
.width
;
2036 h
= self
->pre_fullscreen_area
.height
;
2037 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2039 /* pick some fallbacks... */
2040 a
= screen_area_monitor(self
->desktop
, 0);
2041 x
= a
->x
+ a
->width
/ 4;
2042 y
= a
->y
+ a
->height
/ 4;
2048 client_setup_decor_and_functions(self
);
2050 client_move_resize(self
, x
, y
, w
, h
);
2052 /* try focus us when we go into fullscreen mode */
2056 static void client_iconify_recursive(ObClient
*self
,
2057 gboolean iconic
, gboolean curdesk
)
2060 gboolean changed
= FALSE
;
2063 if (self
->iconic
!= iconic
) {
2064 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2067 self
->iconic
= iconic
;
2070 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2073 old
= self
->wmstate
;
2074 self
->wmstate
= IconicState
;
2075 if (old
!= self
->wmstate
)
2076 PROP_MSG(self
->window
, kde_wm_change_state
,
2077 self
->wmstate
, 1, 0, 0);
2079 self
->ignore_unmaps
++;
2080 /* we unmap the client itself so that we can get MapRequest
2081 events, and because the ICCCM tells us to! */
2082 XUnmapWindow(ob_display
, self
->window
);
2084 /* update the focus lists.. iconic windows go to the bottom of
2085 the list, put the new iconic window at the 'top of the
2087 focus_order_to_top(self
);
2095 client_set_desktop(self
, screen_desktop
, FALSE
);
2097 old
= self
->wmstate
;
2098 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2099 if (old
!= self
->wmstate
)
2100 PROP_MSG(self
->window
, kde_wm_change_state
,
2101 self
->wmstate
, 1, 0, 0);
2103 XMapWindow(ob_display
, self
->window
);
2105 /* this puts it after the current focused window */
2106 focus_order_remove(self
);
2107 focus_order_add_new(self
);
2109 /* this is here cuz with the VIDMODE extension, the viewport can
2110 change while a fullscreen window is iconic, and when it
2111 uniconifies, it would be nice if it did so to the new position
2113 client_reconfigure(self
);
2120 client_change_state(self
);
2121 client_showhide(self
);
2122 screen_update_areas();
2125 /* iconify all transients */
2126 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2127 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2131 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2133 /* move up the transient chain as far as possible first */
2134 self
= client_search_top_transient(self
);
2136 client_iconify_recursive(client_search_top_transient(self
),
2140 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2144 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2145 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2147 /* check if already done */
2149 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2150 if (dir
== 1 && self
->max_horz
) return;
2151 if (dir
== 2 && self
->max_vert
) return;
2153 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2154 if (dir
== 1 && !self
->max_horz
) return;
2155 if (dir
== 2 && !self
->max_vert
) return;
2158 /* we just tell it to configure in the same place and client_configure
2159 worries about filling the screen with the window */
2162 w
= self
->area
.width
;
2163 h
= self
->area
.height
;
2167 self
->pre_max_area
= self
->area
;
2171 a
= screen_area_monitor(self
->desktop
, 0);
2172 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
2173 if (self
->pre_max_area
.width
> 0) {
2174 x
= self
->pre_max_area
.x
;
2175 w
= self
->pre_max_area
.width
;
2177 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
2178 0, self
->pre_max_area
.height
);
2180 /* pick some fallbacks... */
2181 x
= a
->x
+ a
->width
/ 4;
2185 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
2186 if (self
->pre_max_area
.height
> 0) {
2187 y
= self
->pre_max_area
.y
;
2188 h
= self
->pre_max_area
.height
;
2190 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
2191 self
->pre_max_area
.width
, 0);
2193 /* pick some fallbacks... */
2194 y
= a
->y
+ a
->height
/ 4;
2200 if (dir
== 0 || dir
== 1) /* horz */
2201 self
->max_horz
= max
;
2202 if (dir
== 0 || dir
== 2) /* vert */
2203 self
->max_vert
= max
;
2205 client_change_state(self
); /* change the state hints on the client */
2207 client_setup_decor_and_functions(self
);
2209 client_move_resize(self
, x
, y
, w
, h
);
2212 void client_shade(ObClient
*self
, gboolean shade
)
2214 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2215 shade
) || /* can't shade */
2216 self
->shaded
== shade
) return; /* already done */
2218 /* when we're iconic, don't change the wmstate */
2219 if (!self
->iconic
) {
2222 old
= self
->wmstate
;
2223 self
->wmstate
= shade
? IconicState
: NormalState
;
2224 if (old
!= self
->wmstate
)
2225 PROP_MSG(self
->window
, kde_wm_change_state
,
2226 self
->wmstate
, 1, 0, 0);
2229 self
->shaded
= shade
;
2230 client_change_state(self
);
2231 /* resize the frame to just the titlebar */
2232 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2235 void client_close(ObClient
*self
)
2239 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2242 XXX: itd be cool to do timeouts and shit here for killing the client's
2244 like... if the window is around after 5 seconds, then the close button
2245 turns a nice red, and if this function is called again, the client is
2249 ce
.xclient
.type
= ClientMessage
;
2250 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2251 ce
.xclient
.display
= ob_display
;
2252 ce
.xclient
.window
= self
->window
;
2253 ce
.xclient
.format
= 32;
2254 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2255 ce
.xclient
.data
.l
[1] = event_lasttime
;
2256 ce
.xclient
.data
.l
[2] = 0l;
2257 ce
.xclient
.data
.l
[3] = 0l;
2258 ce
.xclient
.data
.l
[4] = 0l;
2259 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2262 void client_kill(ObClient
*self
)
2264 XKillClient(ob_display
, self
->window
);
2267 void client_set_desktop_recursive(ObClient
*self
,
2268 guint target
, gboolean donthide
)
2273 if (target
!= self
->desktop
) {
2275 ob_debug("Setting desktop %u\n", target
+1);
2277 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2279 /* remove from the old desktop(s) */
2280 focus_order_remove(self
);
2282 old
= self
->desktop
;
2283 self
->desktop
= target
;
2284 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2285 /* the frame can display the current desktop state */
2286 frame_adjust_state(self
->frame
);
2287 /* 'move' the window to the new desktop */
2289 client_showhide(self
);
2290 /* raise if it was not already on the desktop */
2291 if (old
!= DESKTOP_ALL
)
2292 stacking_raise(CLIENT_AS_WINDOW(self
));
2293 screen_update_areas();
2295 /* add to the new desktop(s) */
2296 if (config_focus_new
)
2297 focus_order_to_top(self
);
2299 focus_order_to_bottom(self
);
2302 /* move all transients */
2303 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2304 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2308 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2310 client_set_desktop_recursive(client_search_top_transient(self
),
2314 ObClient
*client_search_modal_child(ObClient
*self
)
2319 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2320 ObClient
*c
= it
->data
;
2321 if ((ret
= client_search_modal_child(c
))) return ret
;
2322 if (c
->modal
) return c
;
2327 gboolean
client_validate(ObClient
*self
)
2331 XSync(ob_display
, FALSE
); /* get all events on the server */
2333 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2334 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2335 XPutBackEvent(ob_display
, &e
);
2342 void client_set_wm_state(ObClient
*self
, long state
)
2344 if (state
== self
->wmstate
) return; /* no change */
2348 client_iconify(self
, TRUE
, TRUE
);
2351 client_iconify(self
, FALSE
, TRUE
);
2356 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2358 gboolean shaded
= self
->shaded
;
2359 gboolean fullscreen
= self
->fullscreen
;
2360 gboolean undecorated
= self
->undecorated
;
2361 gboolean max_horz
= self
->max_horz
;
2362 gboolean max_vert
= self
->max_vert
;
2365 if (!(action
== prop_atoms
.net_wm_state_add
||
2366 action
== prop_atoms
.net_wm_state_remove
||
2367 action
== prop_atoms
.net_wm_state_toggle
))
2368 /* an invalid action was passed to the client message, ignore it */
2371 for (i
= 0; i
< 2; ++i
) {
2372 Atom state
= i
== 0 ? data1
: data2
;
2374 if (!state
) continue;
2376 /* if toggling, then pick whether we're adding or removing */
2377 if (action
== prop_atoms
.net_wm_state_toggle
) {
2378 if (state
== prop_atoms
.net_wm_state_modal
)
2379 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2380 prop_atoms
.net_wm_state_add
;
2381 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2382 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2383 prop_atoms
.net_wm_state_add
;
2384 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2385 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2386 prop_atoms
.net_wm_state_add
;
2387 else if (state
== prop_atoms
.net_wm_state_shaded
)
2388 action
= shaded
? prop_atoms
.net_wm_state_remove
:
2389 prop_atoms
.net_wm_state_add
;
2390 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2391 action
= self
->skip_taskbar
?
2392 prop_atoms
.net_wm_state_remove
:
2393 prop_atoms
.net_wm_state_add
;
2394 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2395 action
= self
->skip_pager
?
2396 prop_atoms
.net_wm_state_remove
:
2397 prop_atoms
.net_wm_state_add
;
2398 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2399 action
= fullscreen
?
2400 prop_atoms
.net_wm_state_remove
:
2401 prop_atoms
.net_wm_state_add
;
2402 else if (state
== prop_atoms
.net_wm_state_above
)
2403 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2404 prop_atoms
.net_wm_state_add
;
2405 else if (state
== prop_atoms
.net_wm_state_below
)
2406 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2407 prop_atoms
.net_wm_state_add
;
2408 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
2409 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
2410 prop_atoms
.net_wm_state_add
;
2413 if (action
== prop_atoms
.net_wm_state_add
) {
2414 if (state
== prop_atoms
.net_wm_state_modal
) {
2415 /* XXX raise here or something? */
2417 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2419 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2421 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2423 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2424 self
->skip_taskbar
= TRUE
;
2425 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2426 self
->skip_pager
= TRUE
;
2427 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2429 } else if (state
== prop_atoms
.net_wm_state_above
) {
2431 } else if (state
== prop_atoms
.net_wm_state_below
) {
2433 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2437 } else { /* action == prop_atoms.net_wm_state_remove */
2438 if (state
== prop_atoms
.net_wm_state_modal
) {
2439 self
->modal
= FALSE
;
2440 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2442 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2444 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2446 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2447 self
->skip_taskbar
= FALSE
;
2448 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2449 self
->skip_pager
= FALSE
;
2450 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2452 } else if (state
== prop_atoms
.net_wm_state_above
) {
2453 self
->above
= FALSE
;
2454 } else if (state
== prop_atoms
.net_wm_state_below
) {
2455 self
->below
= FALSE
;
2456 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
2457 undecorated
= FALSE
;
2461 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2462 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2464 if (max_horz
== max_vert
) { /* both going the same way */
2465 client_maximize(self
, max_horz
, 0, TRUE
);
2467 client_maximize(self
, max_horz
, 1, TRUE
);
2468 client_maximize(self
, max_vert
, 2, TRUE
);
2472 if (max_horz
!= self
->max_horz
)
2473 client_maximize(self
, max_horz
, 1, TRUE
);
2475 client_maximize(self
, max_vert
, 2, TRUE
);
2478 /* change fullscreen state before shading, as it will affect if the window
2480 if (fullscreen
!= self
->fullscreen
)
2481 client_fullscreen(self
, fullscreen
, TRUE
);
2482 if (shaded
!= self
->shaded
)
2483 client_shade(self
, shaded
);
2484 if (undecorated
!= self
->undecorated
)
2485 client_set_undecorated(self
, undecorated
);
2486 client_calc_layer(self
);
2487 client_change_state(self
); /* change the hint to reflect these changes */
2490 ObClient
*client_focus_target(ObClient
*self
)
2494 /* if we have a modal child, then focus it, not us */
2495 child
= client_search_modal_child(self
);
2496 if (child
) return child
;
2500 gboolean
client_can_focus(ObClient
*self
)
2504 /* choose the correct target */
2505 self
= client_focus_target(self
);
2507 if (!self
->frame
->visible
)
2510 if (!((self
->can_focus
|| self
->focus_notify
) &&
2511 (self
->desktop
== screen_desktop
||
2512 self
->desktop
== DESKTOP_ALL
) &&
2516 /* do a check to see if the window has already been unmapped or destroyed
2517 do this intelligently while watching out for unmaps we've generated
2518 (ignore_unmaps > 0) */
2519 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2520 DestroyNotify
, &ev
)) {
2521 XPutBackEvent(ob_display
, &ev
);
2524 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2525 UnmapNotify
, &ev
)) {
2526 if (self
->ignore_unmaps
) {
2527 self
->ignore_unmaps
--;
2529 XPutBackEvent(ob_display
, &ev
);
2537 gboolean
client_focus(ObClient
*self
)
2539 /* choose the correct target */
2540 self
= client_focus_target(self
);
2542 if (!client_can_focus(self
)) {
2543 if (!self
->frame
->visible
) {
2544 /* update the focus lists */
2545 focus_order_to_top(self
);
2550 if (self
->can_focus
) {
2551 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2552 I choose to use it always, hopefully to find errors quicker, if any
2553 are left. (I hate X. I hate focus events.)
2555 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2556 #799. So now it is RevertToNone again.
2558 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2562 if (self
->focus_notify
) {
2564 ce
.xclient
.type
= ClientMessage
;
2565 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2566 ce
.xclient
.display
= ob_display
;
2567 ce
.xclient
.window
= self
->window
;
2568 ce
.xclient
.format
= 32;
2569 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2570 ce
.xclient
.data
.l
[1] = event_lasttime
;
2571 ce
.xclient
.data
.l
[2] = 0l;
2572 ce
.xclient
.data
.l
[3] = 0l;
2573 ce
.xclient
.data
.l
[4] = 0l;
2574 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2578 ob_debug("%sively focusing %lx at %d\n",
2579 (self
->can_focus
? "act" : "pass"),
2580 self
->window
, (int) event_lasttime
);
2583 /* Cause the FocusIn to come back to us. Important for desktop switches,
2584 since otherwise we'll have no FocusIn on the queue and send it off to
2585 the focus_backup. */
2586 XSync(ob_display
, FALSE
);
2590 void client_unfocus(ObClient
*self
)
2592 if (focus_client
== self
) {
2594 ob_debug("client_unfocus for %lx\n", self
->window
);
2596 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2600 void client_activate(ObClient
*self
, gboolean here
)
2602 if (client_normal(self
) && screen_showing_desktop
)
2603 screen_show_desktop(FALSE
);
2605 client_iconify(self
, FALSE
, FALSE
);
2606 if (self
->desktop
!= DESKTOP_ALL
&&
2607 self
->desktop
!= screen_desktop
) {
2609 client_set_desktop(self
, screen_desktop
, FALSE
);
2611 screen_set_desktop(self
->desktop
);
2612 } else if (!self
->frame
->visible
)
2613 /* if its not visible for other reasons, then don't mess
2617 client_shade(self
, FALSE
);
2618 action_run_string("Focus", self
);
2619 action_run_string("Raise", self
);
2622 gboolean
client_focused(ObClient
*self
)
2624 return self
== focus_client
;
2627 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2630 /* si is the smallest image >= req */
2631 /* li is the largest image < req */
2632 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2634 for (i
= 0; i
< self
->nicons
; ++i
) {
2635 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2636 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2640 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2645 if (largest
== 0) /* didnt find one smaller than the requested size */
2646 return &self
->icons
[si
];
2647 return &self
->icons
[li
];
2650 /* this be mostly ripped from fvwm */
2651 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2653 int my_cx
, my_cy
, his_cx
, his_cy
;
2656 int score
, best_score
;
2657 ObClient
*best_client
, *cur
;
2663 /* first, find the centre coords of the currently focused window */
2664 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2665 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2670 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2673 /* the currently selected window isn't interesting */
2676 if (!client_normal(cur
))
2678 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2682 if(client_focus_target(cur
) == cur
&&
2683 !(cur
->can_focus
|| cur
->focus_notify
))
2686 /* find the centre coords of this window, from the
2687 * currently focused window's point of view */
2688 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2689 + cur
->frame
->area
.width
/ 2;
2690 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2691 + cur
->frame
->area
.height
/ 2;
2693 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2694 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2696 /* Rotate the diagonals 45 degrees counterclockwise.
2697 * To do this, multiply the matrix /+h +h\ with the
2698 * vector (x y). \-h +h/
2699 * h = sqrt(0.5). We can set h := 1 since absolute
2700 * distance doesn't matter here. */
2701 tx
= his_cx
+ his_cy
;
2702 his_cy
= -his_cx
+ his_cy
;
2707 case OB_DIRECTION_NORTH
:
2708 case OB_DIRECTION_SOUTH
:
2709 case OB_DIRECTION_NORTHEAST
:
2710 case OB_DIRECTION_SOUTHWEST
:
2711 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2712 distance
= ((dir
== OB_DIRECTION_NORTH
||
2713 dir
== OB_DIRECTION_NORTHEAST
) ?
2716 case OB_DIRECTION_EAST
:
2717 case OB_DIRECTION_WEST
:
2718 case OB_DIRECTION_SOUTHEAST
:
2719 case OB_DIRECTION_NORTHWEST
:
2720 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2721 distance
= ((dir
== OB_DIRECTION_WEST
||
2722 dir
== OB_DIRECTION_NORTHWEST
) ?
2727 /* the target must be in the requested direction */
2731 /* Calculate score for this window. The smaller the better. */
2732 score
= distance
+ offset
;
2734 /* windows more than 45 degrees off the direction are
2735 * heavily penalized and will only be chosen if nothing
2736 * else within a million pixels */
2737 if(offset
> distance
)
2740 if(best_score
== -1 || score
< best_score
)
2748 void client_set_layer(ObClient
*self
, int layer
)
2752 self
->above
= FALSE
;
2753 } else if (layer
== 0) {
2754 self
->below
= self
->above
= FALSE
;
2756 self
->below
= FALSE
;
2759 client_calc_layer(self
);
2760 client_change_state(self
); /* reflect this in the state hints */
2763 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
2765 if (self
->undecorated
!= undecorated
) {
2766 self
->undecorated
= undecorated
;
2767 client_setup_decor_and_functions(self
);
2768 client_change_state(self
); /* reflect this in the state hints */
2772 guint
client_monitor(ObClient
*self
)
2776 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2777 Rect
*area
= screen_physical_area_monitor(i
);
2778 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2781 if (i
== screen_num_monitors
) i
= 0;
2782 g_assert(i
< screen_num_monitors
);
2786 ObClient
*client_search_top_transient(ObClient
*self
)
2788 /* move up the transient chain as far as possible */
2789 if (self
->transient_for
) {
2790 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2791 return client_search_top_transient(self
->transient_for
);
2795 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2796 ObClient
*c
= it
->data
;
2798 /* checking transient_for prevents infinate loops! */
2799 if (c
!= self
&& !c
->transient_for
)
2810 ObClient
*client_search_focus_parent(ObClient
*self
)
2812 if (self
->transient_for
) {
2813 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2814 if (client_focused(self
->transient_for
))
2815 return self
->transient_for
;
2819 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2820 ObClient
*c
= it
->data
;
2822 /* checking transient_for prevents infinate loops! */
2823 if (c
!= self
&& !c
->transient_for
)
2824 if (client_focused(c
))
2833 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
2835 if (self
->transient_for
) {
2836 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2837 if (self
->transient_for
== search
)
2842 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2843 ObClient
*c
= it
->data
;
2845 /* checking transient_for prevents infinate loops! */
2846 if (c
!= self
&& !c
->transient_for
)
2856 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2860 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2861 if (sit
->data
== search
)
2863 if (client_search_transient(sit
->data
, search
))
2869 void client_update_sm_client_id(ObClient
*self
)
2871 g_free(self
->sm_client_id
);
2872 self
->sm_client_id
= NULL
;
2874 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
2876 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
2877 &self
->sm_client_id
);
2880 /* finds the nearest edge in the given direction from the current client
2881 * note to self: the edge is the -frame- edge (the actual one), not the
2884 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
2887 int my_edge_start
, my_edge_end
, my_offset
;
2894 a
= screen_area(c
->desktop
);
2897 case OB_DIRECTION_NORTH
:
2898 my_edge_start
= c
->frame
->area
.x
;
2899 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2900 my_offset
= c
->frame
->area
.y
;
2902 dest
= a
->y
; /* default: top of screen */
2904 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2905 int his_edge_start
, his_edge_end
, his_offset
;
2906 ObClient
*cur
= it
->data
;
2910 if(!client_normal(cur
))
2912 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2917 his_edge_start
= cur
->frame
->area
.x
;
2918 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2919 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2921 if(his_offset
+ 1 > my_offset
)
2924 if(his_offset
< dest
)
2927 if(his_edge_start
>= my_edge_start
&&
2928 his_edge_start
<= my_edge_end
)
2931 if(my_edge_start
>= his_edge_start
&&
2932 my_edge_start
<= his_edge_end
)
2937 case OB_DIRECTION_SOUTH
:
2938 my_edge_start
= c
->frame
->area
.x
;
2939 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2940 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2942 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
2944 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2945 int his_edge_start
, his_edge_end
, his_offset
;
2946 ObClient
*cur
= it
->data
;
2950 if(!client_normal(cur
))
2952 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2957 his_edge_start
= cur
->frame
->area
.x
;
2958 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2959 his_offset
= cur
->frame
->area
.y
;
2962 if(his_offset
- 1 < my_offset
)
2965 if(his_offset
> dest
)
2968 if(his_edge_start
>= my_edge_start
&&
2969 his_edge_start
<= my_edge_end
)
2972 if(my_edge_start
>= his_edge_start
&&
2973 my_edge_start
<= his_edge_end
)
2978 case OB_DIRECTION_WEST
:
2979 my_edge_start
= c
->frame
->area
.y
;
2980 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2981 my_offset
= c
->frame
->area
.x
;
2983 dest
= a
->x
; /* default: leftmost egde of screen */
2985 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2986 int his_edge_start
, his_edge_end
, his_offset
;
2987 ObClient
*cur
= it
->data
;
2991 if(!client_normal(cur
))
2993 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2998 his_edge_start
= cur
->frame
->area
.y
;
2999 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3000 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3002 if(his_offset
+ 1 > my_offset
)
3005 if(his_offset
< dest
)
3008 if(his_edge_start
>= my_edge_start
&&
3009 his_edge_start
<= my_edge_end
)
3012 if(my_edge_start
>= his_edge_start
&&
3013 my_edge_start
<= his_edge_end
)
3019 case OB_DIRECTION_EAST
:
3020 my_edge_start
= c
->frame
->area
.y
;
3021 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3022 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3024 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
3026 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3027 int his_edge_start
, his_edge_end
, his_offset
;
3028 ObClient
*cur
= it
->data
;
3032 if(!client_normal(cur
))
3034 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3039 his_edge_start
= cur
->frame
->area
.y
;
3040 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3041 his_offset
= cur
->frame
->area
.x
;
3043 if(his_offset
- 1 < my_offset
)
3046 if(his_offset
> dest
)
3049 if(his_edge_start
>= my_edge_start
&&
3050 his_edge_start
<= my_edge_end
)
3053 if(my_edge_start
>= his_edge_start
&&
3054 my_edge_start
<= his_edge_end
)
3059 case OB_DIRECTION_NORTHEAST
:
3060 case OB_DIRECTION_SOUTHEAST
:
3061 case OB_DIRECTION_NORTHWEST
:
3062 case OB_DIRECTION_SOUTHWEST
:
3063 /* not implemented */
3065 g_assert_not_reached();
3070 ObClient
* client_under_pointer()
3074 ObClient
*ret
= NULL
;
3076 if (screen_pointer_pos(&x
, &y
)) {
3077 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
3078 if (WINDOW_IS_CLIENT(it
->data
)) {
3079 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3080 if (c
->desktop
== screen_desktop
&&
3081 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {