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
->decorate
= TRUE
;
248 self
->desktop
= screen_num_desktops
; /* always an invalid value */
250 client_get_all(self
);
251 client_restore_session_state(self
);
253 sn_app_started(self
->class);
255 client_change_state(self
);
257 /* remove the client's border (and adjust re gravity) */
258 client_toggle_border(self
, FALSE
);
260 /* specify that if we exit, the window should not be destroyed and should
261 be reparented back to root automatically */
262 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
264 /* create the decoration frame for the client window */
265 self
->frame
= frame_new();
267 frame_grab_client(self
->frame
, self
);
271 client_apply_startup_state(self
);
273 /* update the focus lists */
274 focus_order_add_new(self
);
276 stacking_add(CLIENT_AS_WINDOW(self
));
277 client_restore_session_stacking(self
);
279 /* focus the new window? */
280 if (ob_state() != OB_STATE_STARTING
&&
281 (config_focus_new
|| (self
->transient_for
&&
282 self
->transient_for
!= OB_TRAN_GROUP
&&
283 client_focused(self
->transient_for
))) &&
284 /* note the check against Type_Normal/Dialog, not client_normal(self),
285 which would also include other types. in this case we want more
286 strict rules for focus */
287 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
288 self
->type
== OB_CLIENT_TYPE_DIALOG
))
292 if (self
->desktop
!= screen_desktop
) {
293 /* activate the window */
296 gboolean group_foc
= FALSE
;
301 for (it
= self
->group
->members
; it
; it
= it
->next
)
303 if (client_focused(it
->data
))
311 (!self
->transient_for
&& (!self
->group
||
312 !self
->group
->members
->next
))) ||
313 client_search_focus_tree_full(self
) ||
315 !client_normal(focus_client
))
317 /* activate the window */
324 if (ob_state() == OB_STATE_RUNNING
) {
325 int x
= self
->area
.x
, ox
= x
;
326 int y
= self
->area
.y
, oy
= y
;
328 place_client(self
, &x
, &y
);
330 /* make sure the window is visible */
331 client_find_onscreen(self
, &x
, &y
,
332 self
->frame
->area
.width
,
333 self
->frame
->area
.height
,
334 client_normal(self
));
336 if (x
!= ox
|| y
!= oy
)
337 client_move(self
, x
, y
);
340 client_showhide(self
);
342 /* use client_focus instead of client_activate cuz client_activate does
343 stuff like switch desktops etc and I'm not interested in all that when
344 a window maps since its not based on an action from the user like
345 clicking a window to activate is. so keep the new window out of the way
347 if (activate
) client_focus(self
);
349 /* client_activate does this but we aret using it so we have to do it
351 if (screen_showing_desktop
)
352 screen_show_desktop(FALSE
);
354 /* add to client list/map */
355 client_list
= g_list_append(client_list
, self
);
356 g_hash_table_insert(window_map
, &self
->window
, self
);
358 /* this has to happen after we're in the client_list */
359 screen_update_areas();
361 /* update the list hints */
364 keyboard_grab_for_client(self
, TRUE
);
365 mouse_grab_for_client(self
, TRUE
);
367 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
370 void client_unmanage_all()
372 while (client_list
!= NULL
)
373 client_unmanage(client_list
->data
);
376 void client_unmanage(ObClient
*self
)
381 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
383 g_assert(self
!= NULL
);
385 keyboard_grab_for_client(self
, FALSE
);
386 mouse_grab_for_client(self
, FALSE
);
388 /* remove the window from our save set */
389 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
391 /* we dont want events no more */
392 XSelectInput(ob_display
, self
->window
, NoEventMask
);
394 frame_hide(self
->frame
);
396 client_list
= g_list_remove(client_list
, self
);
397 stacking_remove(self
);
398 g_hash_table_remove(window_map
, &self
->window
);
400 /* update the focus lists */
401 focus_order_remove(self
);
403 /* once the client is out of the list, update the struts to remove it's
405 screen_update_areas();
407 /* tell our parent(s) that we're gone */
408 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
411 for (it
= self
->group
->members
; it
; it
= it
->next
)
412 if (it
->data
!= self
)
413 ((ObClient
*)it
->data
)->transients
=
414 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
415 } else if (self
->transient_for
) { /* transient of window */
416 self
->transient_for
->transients
=
417 g_slist_remove(self
->transient_for
->transients
, self
);
420 /* tell our transients that we're gone */
421 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
422 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
423 ((ObClient
*)it
->data
)->transient_for
= NULL
;
424 client_calc_layer(it
->data
);
428 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
429 GDestroyNotify func
= (GDestroyNotify
) it
->data
;
433 if (focus_client
== self
) {
436 /* focus the last focused window on the desktop, and ignore enter
437 events from the unmap so it doesnt mess with the focus */
438 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
439 client_unfocus(self
);
442 /* remove from its group */
444 group_remove(self
->group
, self
);
448 /* give the client its border back */
449 client_toggle_border(self
, TRUE
);
451 /* reparent the window out of the frame, and free the frame */
452 frame_release_client(self
->frame
, self
);
455 if (ob_state() != OB_STATE_EXITING
) {
456 /* these values should not be persisted across a window
458 PROP_ERASE(self
->window
, net_wm_desktop
);
459 PROP_ERASE(self
->window
, net_wm_state
);
460 PROP_ERASE(self
->window
, wm_state
);
462 /* if we're left in an iconic state, the client wont be mapped. this is
463 bad, since we will no longer be managing the window on restart */
465 XMapWindow(ob_display
, self
->window
);
469 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
471 /* free all data allocated in the client struct */
472 g_slist_free(self
->transients
);
473 for (j
= 0; j
< self
->nicons
; ++j
)
474 g_free(self
->icons
[j
].data
);
475 if (self
->nicons
> 0)
478 g_free(self
->icon_title
);
482 g_free(self
->sm_client_id
);
485 /* update the list hints */
489 static void client_urgent_notify(ObClient
*self
)
492 frame_flash_start(self
->frame
);
494 frame_flash_stop(self
->frame
);
497 static void client_restore_session_state(ObClient
*self
)
501 if (!(it
= session_state_find(self
)))
504 self
->session
= it
->data
;
506 RECT_SET(self
->area
, self
->session
->x
, self
->session
->y
,
507 self
->session
->w
, self
->session
->h
);
508 self
->positioned
= TRUE
;
509 XResizeWindow(ob_display
, self
->window
,
510 self
->session
->w
, self
->session
->h
);
512 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
513 self
->session
->desktop
:
514 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
515 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
517 self
->shaded
= self
->session
->shaded
;
518 self
->iconic
= self
->session
->iconic
;
519 self
->skip_pager
= self
->session
->skip_pager
;
520 self
->skip_taskbar
= self
->session
->skip_taskbar
;
521 self
->fullscreen
= self
->session
->fullscreen
;
522 self
->above
= self
->session
->above
;
523 self
->below
= self
->session
->below
;
524 self
->max_horz
= self
->session
->max_horz
;
525 self
->max_vert
= self
->session
->max_vert
;
528 static void client_restore_session_stacking(ObClient
*self
)
532 if (!self
->session
) return;
534 it
= g_list_find(session_saved_state
, self
->session
);
535 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
538 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
539 if (session_state_cmp(it
->data
, cit
->data
))
542 client_calc_layer(self
);
543 stacking_below(CLIENT_AS_WINDOW(self
),
544 CLIENT_AS_WINDOW(cit
->data
));
550 void client_move_onscreen(ObClient
*self
, gboolean rude
)
552 int x
= self
->area
.x
;
553 int y
= self
->area
.y
;
554 if (client_find_onscreen(self
, &x
, &y
,
555 self
->frame
->area
.width
,
556 self
->frame
->area
.height
, rude
)) {
557 client_move(self
, x
, y
);
561 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
565 int ox
= *x
, oy
= *y
;
567 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
570 /* XXX watch for xinerama dead areas */
572 a
= screen_area(self
->desktop
);
573 if (client_normal(self
)) {
574 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
575 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
576 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
577 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
578 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
580 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
585 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
586 Java can suck it too. */
588 /* dont let windows map/move into the strut unless they
589 are bigger than the available area */
591 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
592 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
593 *x
= a
->x
+ a
->width
- w
;
595 if (h
<= a
->height
) {
596 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
597 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
598 *y
= a
->y
+ a
->height
- h
;
602 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
605 return ox
!= *x
|| oy
!= *y
;
608 static void client_toggle_border(ObClient
*self
, gboolean show
)
610 /* adjust our idea of where the client is, based on its border. When the
611 border is removed, the client should now be considered to be in a
613 when re-adding the border to the client, the same operation needs to be
615 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
616 int x
= oldx
, y
= oldy
;
617 switch(self
->gravity
) {
619 case NorthWestGravity
:
621 case SouthWestGravity
:
623 case NorthEastGravity
:
625 case SouthEastGravity
:
626 if (show
) x
-= self
->border_width
* 2;
627 else x
+= self
->border_width
* 2;
634 if (show
) x
-= self
->border_width
;
635 else x
+= self
->border_width
;
638 switch(self
->gravity
) {
640 case NorthWestGravity
:
642 case NorthEastGravity
:
644 case SouthWestGravity
:
646 case SouthEastGravity
:
647 if (show
) y
-= self
->border_width
* 2;
648 else y
+= self
->border_width
* 2;
655 if (show
) y
-= self
->border_width
;
656 else y
+= self
->border_width
;
663 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
665 /* move the client so it is back it the right spot _with_ its
667 if (x
!= oldx
|| y
!= oldy
)
668 XMoveWindow(ob_display
, self
->window
, x
, y
);
670 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
674 static void client_get_all(ObClient
*self
)
676 client_get_area(self
);
677 client_update_transient_for(self
);
678 client_update_wmhints(self
);
679 client_get_startup_id(self
);
680 client_get_desktop(self
);
681 client_get_state(self
);
682 client_get_shaped(self
);
684 client_get_mwm_hints(self
);
685 client_get_type(self
);/* this can change the mwmhints for special cases */
687 client_update_protocols(self
);
689 client_get_gravity(self
); /* get the attribute gravity */
690 client_update_normal_hints(self
); /* this may override the attribute
693 /* got the type, the mwmhints, the protocols, and the normal hints
694 (min/max sizes), so we're ready to set up the decorations/functions */
695 client_setup_decor_and_functions(self
);
697 client_update_title(self
);
698 client_update_class(self
);
699 client_update_sm_client_id(self
);
700 client_update_strut(self
);
701 client_update_icons(self
);
704 static void client_get_startup_id(ObClient
*self
)
706 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
708 PROP_GETS(self
->group
->leader
,
709 net_startup_id
, utf8
, &self
->startup_id
);
712 static void client_get_area(ObClient
*self
)
714 XWindowAttributes wattrib
;
717 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
718 g_assert(ret
!= BadWindow
);
720 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
721 self
->border_width
= wattrib
.border_width
;
724 static void client_get_desktop(ObClient
*self
)
726 guint32 d
= screen_num_desktops
; /* an always-invalid value */
728 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
729 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
730 self
->desktop
= screen_num_desktops
- 1;
734 gboolean trdesk
= FALSE
;
736 if (self
->transient_for
) {
737 if (self
->transient_for
!= OB_TRAN_GROUP
) {
738 self
->desktop
= self
->transient_for
->desktop
;
743 for (it
= self
->group
->members
; it
; it
= it
->next
)
744 if (it
->data
!= self
&&
745 !((ObClient
*)it
->data
)->transient_for
) {
746 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
753 /* try get from the startup-notification protocol */
754 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
755 if (self
->desktop
>= screen_num_desktops
&&
756 self
->desktop
!= DESKTOP_ALL
)
757 self
->desktop
= screen_num_desktops
- 1;
759 /* defaults to the current desktop */
760 self
->desktop
= screen_desktop
;
763 if (self
->desktop
!= d
) {
764 /* set the desktop hint, to make sure that it always exists */
765 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
769 static void client_get_state(ObClient
*self
)
774 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
776 for (i
= 0; i
< num
; ++i
) {
777 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
779 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
781 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
783 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
784 self
->skip_taskbar
= TRUE
;
785 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
786 self
->skip_pager
= TRUE
;
787 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
788 self
->fullscreen
= TRUE
;
789 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
790 self
->max_vert
= TRUE
;
791 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
792 self
->max_horz
= TRUE
;
793 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
795 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
803 static void client_get_shaped(ObClient
*self
)
805 self
->shaped
= FALSE
;
807 if (extensions_shape
) {
812 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
814 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
815 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
817 self
->shaped
= (s
!= 0);
822 void client_update_transient_for(ObClient
*self
)
825 ObClient
*target
= NULL
;
827 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
828 self
->transient
= TRUE
;
829 if (t
!= self
->window
) { /* cant be transient to itself! */
830 target
= g_hash_table_lookup(window_map
, &t
);
831 /* if this happens then we need to check for it*/
832 g_assert(target
!= self
);
833 if (target
&& !WINDOW_IS_CLIENT(target
)) {
834 /* this can happen when a dialog is a child of
835 a dockapp, for example */
839 if (!target
&& self
->group
) {
840 /* not transient to a client, see if it is transient for a
842 if (t
== self
->group
->leader
||
844 t
== RootWindow(ob_display
, ob_screen
)) {
845 /* window is a transient for its group! */
846 target
= OB_TRAN_GROUP
;
851 self
->transient
= FALSE
;
853 /* if anything has changed... */
854 if (target
!= self
->transient_for
) {
855 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
858 /* remove from old parents */
859 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
860 ObClient
*c
= it
->data
;
861 if (c
!= self
&& !c
->transient_for
)
862 c
->transients
= g_slist_remove(c
->transients
, self
);
864 } else if (self
->transient_for
!= NULL
) { /* transient of window */
865 /* remove from old parent */
866 self
->transient_for
->transients
=
867 g_slist_remove(self
->transient_for
->transients
, self
);
869 self
->transient_for
= target
;
870 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
873 /* add to new parents */
874 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
875 ObClient
*c
= it
->data
;
876 if (c
!= self
&& !c
->transient_for
)
877 c
->transients
= g_slist_append(c
->transients
, self
);
880 /* remove all transients which are in the group, that causes
881 circlular pointer hell of doom */
882 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
884 for (sit
= self
->transients
; sit
; sit
= next
) {
885 next
= g_slist_next(sit
);
886 if (sit
->data
== it
->data
)
888 g_slist_delete_link(self
->transients
, sit
);
891 } else if (self
->transient_for
!= NULL
) { /* transient of window */
892 /* add to new parent */
893 self
->transient_for
->transients
=
894 g_slist_append(self
->transient_for
->transients
, self
);
899 static void client_get_mwm_hints(ObClient
*self
)
904 self
->mwmhints
.flags
= 0; /* default to none */
906 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
908 if (num
>= OB_MWM_ELEMENTS
) {
909 self
->mwmhints
.flags
= hints
[0];
910 self
->mwmhints
.functions
= hints
[1];
911 self
->mwmhints
.decorations
= hints
[2];
917 void client_get_type(ObClient
*self
)
924 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
925 /* use the first value that we know about in the array */
926 for (i
= 0; i
< num
; ++i
) {
927 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
928 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
929 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
930 self
->type
= OB_CLIENT_TYPE_DOCK
;
931 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
932 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
933 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
934 self
->type
= OB_CLIENT_TYPE_MENU
;
935 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
936 self
->type
= OB_CLIENT_TYPE_UTILITY
;
937 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
938 self
->type
= OB_CLIENT_TYPE_SPLASH
;
939 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
940 self
->type
= OB_CLIENT_TYPE_DIALOG
;
941 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
942 self
->type
= OB_CLIENT_TYPE_NORMAL
;
943 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
944 /* prevent this window from getting any decor or
946 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
947 OB_MWM_FLAG_DECORATIONS
);
948 self
->mwmhints
.decorations
= 0;
949 self
->mwmhints
.functions
= 0;
951 if (self
->type
!= (ObClientType
) -1)
952 break; /* grab the first legit type */
957 if (self
->type
== (ObClientType
) -1) {
958 /*the window type hint was not set, which means we either classify
959 ourself as a normal window or a dialog, depending on if we are a
962 self
->type
= OB_CLIENT_TYPE_DIALOG
;
964 self
->type
= OB_CLIENT_TYPE_NORMAL
;
968 void client_update_protocols(ObClient
*self
)
973 self
->focus_notify
= FALSE
;
974 self
->delete_window
= FALSE
;
976 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
977 for (i
= 0; i
< num_return
; ++i
) {
978 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
979 /* this means we can request the window to close */
980 self
->delete_window
= TRUE
;
981 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
982 /* if this protocol is requested, then the window will be
983 notified whenever we want it to receive focus */
984 self
->focus_notify
= TRUE
;
990 static void client_get_gravity(ObClient
*self
)
992 XWindowAttributes wattrib
;
995 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
996 g_assert(ret
!= BadWindow
);
997 self
->gravity
= wattrib
.win_gravity
;
1000 void client_update_normal_hints(ObClient
*self
)
1004 int oldgravity
= self
->gravity
;
1007 self
->min_ratio
= 0.0f
;
1008 self
->max_ratio
= 0.0f
;
1009 SIZE_SET(self
->size_inc
, 1, 1);
1010 SIZE_SET(self
->base_size
, 0, 0);
1011 SIZE_SET(self
->min_size
, 0, 0);
1012 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1014 /* get the hints from the window */
1015 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1016 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1018 if (size
.flags
& PWinGravity
) {
1019 self
->gravity
= size
.win_gravity
;
1021 /* if the client has a frame, i.e. has already been mapped and
1022 is changing its gravity */
1023 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1024 /* move our idea of the client's position based on its new
1026 self
->area
.x
= self
->frame
->area
.x
;
1027 self
->area
.y
= self
->frame
->area
.y
;
1028 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1032 if (size
.flags
& PAspect
) {
1033 if (size
.min_aspect
.y
)
1034 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1035 if (size
.max_aspect
.y
)
1036 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1039 if (size
.flags
& PMinSize
)
1040 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1042 if (size
.flags
& PMaxSize
)
1043 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1045 if (size
.flags
& PBaseSize
)
1046 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1048 if (size
.flags
& PResizeInc
)
1049 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1053 void client_setup_decor_and_functions(ObClient
*self
)
1055 /* start with everything (cept fullscreen) */
1057 (OB_FRAME_DECOR_TITLEBAR
|
1058 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1059 OB_FRAME_DECOR_GRIPS
|
1060 OB_FRAME_DECOR_BORDER
|
1061 OB_FRAME_DECOR_ICON
|
1062 OB_FRAME_DECOR_ALLDESKTOPS
|
1063 OB_FRAME_DECOR_ICONIFY
|
1064 OB_FRAME_DECOR_MAXIMIZE
|
1065 OB_FRAME_DECOR_SHADE
);
1067 (OB_CLIENT_FUNC_RESIZE
|
1068 OB_CLIENT_FUNC_MOVE
|
1069 OB_CLIENT_FUNC_ICONIFY
|
1070 OB_CLIENT_FUNC_MAXIMIZE
|
1071 OB_CLIENT_FUNC_SHADE
);
1072 if (self
->delete_window
) {
1073 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1074 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1077 if (!(self
->min_size
.width
< self
->max_size
.width
||
1078 self
->min_size
.height
< self
->max_size
.height
))
1079 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1081 switch (self
->type
) {
1082 case OB_CLIENT_TYPE_NORMAL
:
1083 /* normal windows retain all of the possible decorations and
1084 functionality, and are the only windows that you can fullscreen */
1085 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1088 case OB_CLIENT_TYPE_DIALOG
:
1089 case OB_CLIENT_TYPE_UTILITY
:
1090 /* these windows cannot be maximized */
1091 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1094 case OB_CLIENT_TYPE_MENU
:
1095 case OB_CLIENT_TYPE_TOOLBAR
:
1096 /* these windows get less functionality */
1097 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1100 case OB_CLIENT_TYPE_DESKTOP
:
1101 case OB_CLIENT_TYPE_DOCK
:
1102 case OB_CLIENT_TYPE_SPLASH
:
1103 /* none of these windows are manipulated by the window manager */
1104 self
->decorations
= 0;
1105 self
->functions
= 0;
1109 /* Mwm Hints are applied subtractively to what has already been chosen for
1110 decor and functionality */
1111 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1112 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1113 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1114 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1115 /* if the mwm hints request no handle or title, then all
1116 decorations are disabled */
1117 self
->decorations
= 0;
1121 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1122 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1123 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1124 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1125 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1126 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1127 /* dont let mwm hints kill any buttons
1128 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1129 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1130 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1131 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1133 /* dont let mwm hints kill the close button
1134 if (! (self->mwmhints.functions & MwmFunc_Close))
1135 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1139 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1140 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1141 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1142 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1143 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1144 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1146 /* can't maximize without moving/resizing */
1147 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1148 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1149 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1150 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1151 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1154 /* kill the handle on fully maxed windows */
1155 if (self
->max_vert
&& self
->max_horz
)
1156 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1158 /* finally, the user can have requested no decorations, which overrides
1160 if (!self
->decorate
)
1161 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1163 /* if we don't have a titlebar, then we cannot shade! */
1164 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1165 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1167 /* now we need to check against rules for the client's current state */
1168 if (self
->fullscreen
) {
1169 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1170 OB_CLIENT_FUNC_FULLSCREEN
|
1171 OB_CLIENT_FUNC_ICONIFY
);
1172 self
->decorations
= 0;
1175 client_change_allowed_actions(self
);
1178 /* adjust the client's decorations, etc. */
1179 client_reconfigure(self
);
1181 /* this makes sure that these windows appear on all desktops */
1182 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1183 self
->desktop
!= DESKTOP_ALL
)
1185 self
->desktop
= DESKTOP_ALL
;
1190 static void client_change_allowed_actions(ObClient
*self
)
1195 /* desktop windows are kept on all desktops */
1196 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1197 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1199 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1200 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1201 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1202 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1203 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1204 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1205 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1206 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1207 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1208 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1209 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1210 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1211 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1212 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1213 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1216 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1218 /* make sure the window isn't breaking any rules now */
1220 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1221 if (self
->frame
) client_shade(self
, FALSE
);
1222 else self
->shaded
= FALSE
;
1224 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1225 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1226 else self
->iconic
= FALSE
;
1228 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1229 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1230 else self
->fullscreen
= FALSE
;
1232 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1234 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1235 else self
->max_vert
= self
->max_horz
= FALSE
;
1239 void client_reconfigure(ObClient
*self
)
1241 /* by making this pass FALSE for user, we avoid the emacs event storm where
1242 every configurenotify causes an update in its normal hints, i think this
1243 is generally what we want anyways... */
1244 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1245 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1248 void client_update_wmhints(ObClient
*self
)
1251 gboolean ur
= FALSE
;
1254 /* assume a window takes input if it doesnt specify */
1255 self
->can_focus
= TRUE
;
1257 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1258 if (hints
->flags
& InputHint
)
1259 self
->can_focus
= hints
->input
;
1261 /* only do this when first managing the window *AND* when we aren't
1263 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1264 if (hints
->flags
& StateHint
)
1265 self
->iconic
= hints
->initial_state
== IconicState
;
1267 if (hints
->flags
& XUrgencyHint
)
1270 if (!(hints
->flags
& WindowGroupHint
))
1271 hints
->window_group
= None
;
1273 /* did the group state change? */
1274 if (hints
->window_group
!=
1275 (self
->group
? self
->group
->leader
: None
)) {
1276 /* remove from the old group if there was one */
1277 if (self
->group
!= NULL
) {
1278 /* remove transients of the group */
1279 for (it
= self
->group
->members
; it
; it
= it
->next
)
1280 self
->transients
= g_slist_remove(self
->transients
,
1282 group_remove(self
->group
, self
);
1285 if (hints
->window_group
!= None
) {
1286 self
->group
= group_add(hints
->window_group
, self
);
1288 /* i can only have transients from the group if i am not
1290 if (!self
->transient_for
) {
1291 /* add other transients of the group that are already
1293 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1294 ObClient
*c
= it
->data
;
1295 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1297 g_slist_append(self
->transients
, c
);
1302 /* because the self->transient flag wont change from this call,
1303 we don't need to update the window's type and such, only its
1304 transient_for, and the transients lists of other windows in
1305 the group may be affected */
1306 client_update_transient_for(self
);
1309 /* the WM_HINTS can contain an icon */
1310 client_update_icons(self
);
1315 if (ur
!= self
->urgent
) {
1317 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1319 /* fire the urgent callback if we're mapped, otherwise, wait until
1320 after we're mapped */
1322 client_urgent_notify(self
);
1326 void client_update_title(ObClient
*self
)
1332 gboolean read_title
;
1335 old_title
= self
->title
;
1338 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1339 /* try old x stuff */
1340 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1341 data
= g_strdup("Unnamed Window");
1343 /* did the title change? then reset the title_count */
1344 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1345 self
->title_count
= 1;
1347 /* look for duplicates and append a number */
1349 for (it
= client_list
; it
; it
= it
->next
)
1350 if (it
->data
!= self
) {
1351 ObClient
*c
= it
->data
;
1352 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1353 nums
|= 1 << c
->title_count
;
1355 /* find first free number */
1356 for (i
= 1; i
<= 32; ++i
)
1357 if (!(nums
& (1 << i
))) {
1358 if (self
->title_count
== 1 || i
== 1)
1359 self
->title_count
= i
;
1362 /* dont display the number for the first window */
1363 if (self
->title_count
> 1) {
1365 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1370 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1375 frame_adjust_title(self
->frame
);
1379 /* update the icon title */
1381 g_free(self
->icon_title
);
1385 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1386 /* try old x stuff */
1387 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1388 data
= g_strdup(self
->title
);
1392 /* append the title count, dont display the number for the first window */
1393 if (read_title
&& self
->title_count
> 1) {
1394 char *vdata
, *ndata
;
1395 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1396 vdata
= g_strconcat(data
, ndata
, NULL
);
1402 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1404 self
->icon_title
= data
;
1407 void client_update_class(ObClient
*self
)
1412 if (self
->name
) g_free(self
->name
);
1413 if (self
->class) g_free(self
->class);
1414 if (self
->role
) g_free(self
->role
);
1416 self
->name
= self
->class = self
->role
= NULL
;
1418 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1420 self
->name
= g_strdup(data
[0]);
1422 self
->class = g_strdup(data
[1]);
1427 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1430 if (self
->name
== NULL
) self
->name
= g_strdup("");
1431 if (self
->class == NULL
) self
->class = g_strdup("");
1432 if (self
->role
== NULL
) self
->role
= g_strdup("");
1435 void client_update_strut(ObClient
*self
)
1439 gboolean got
= FALSE
;
1442 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1446 STRUT_PARTIAL_SET(strut
,
1447 data
[0], data
[2], data
[1], data
[3],
1448 data
[4], data
[5], data
[8], data
[9],
1449 data
[6], data
[7], data
[10], data
[11]);
1455 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1458 STRUT_PARTIAL_SET(strut
,
1459 data
[0], data
[2], data
[1], data
[3],
1460 0, 0, 0, 0, 0, 0, 0, 0);
1466 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1467 0, 0, 0, 0, 0, 0, 0, 0);
1469 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1470 self
->strut
= strut
;
1472 /* updating here is pointless while we're being mapped cuz we're not in
1473 the client list yet */
1475 screen_update_areas();
1479 void client_update_icons(ObClient
*self
)
1485 for (i
= 0; i
< self
->nicons
; ++i
)
1486 g_free(self
->icons
[i
].data
);
1487 if (self
->nicons
> 0)
1488 g_free(self
->icons
);
1491 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1492 /* figure out how many valid icons are in here */
1494 while (num
- i
> 2) {
1498 if (i
> num
|| w
*h
== 0) break;
1502 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1504 /* store the icons */
1506 for (j
= 0; j
< self
->nicons
; ++j
) {
1509 w
= self
->icons
[j
].width
= data
[i
++];
1510 h
= self
->icons
[j
].height
= data
[i
++];
1512 if (w
*h
== 0) continue;
1514 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1515 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1520 self
->icons
[j
].data
[t
] =
1521 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1522 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1523 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1524 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1530 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1531 kwm_win_icon
, &data
, &num
)) {
1534 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1535 xerror_set_ignore(TRUE
);
1536 if (!RrPixmapToRGBA(ob_rr_inst
,
1538 &self
->icons
[self
->nicons
-1].width
,
1539 &self
->icons
[self
->nicons
-1].height
,
1540 &self
->icons
[self
->nicons
-1].data
)) {
1541 g_free(&self
->icons
[self
->nicons
-1]);
1544 xerror_set_ignore(FALSE
);
1550 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1551 if (hints
->flags
& IconPixmapHint
) {
1553 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1554 xerror_set_ignore(TRUE
);
1555 if (!RrPixmapToRGBA(ob_rr_inst
,
1557 (hints
->flags
& IconMaskHint
?
1558 hints
->icon_mask
: None
),
1559 &self
->icons
[self
->nicons
-1].width
,
1560 &self
->icons
[self
->nicons
-1].height
,
1561 &self
->icons
[self
->nicons
-1].data
)){
1562 g_free(&self
->icons
[self
->nicons
-1]);
1565 xerror_set_ignore(FALSE
);
1571 if (!self
->nicons
) {
1573 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1574 self
->icons
[self
->nicons
-1].width
= 48;
1575 self
->icons
[self
->nicons
-1].height
= 48;
1576 self
->icons
[self
->nicons
-1].data
= g_memdup(ob_rr_theme
->def_win_icon
,
1582 frame_adjust_icon(self
->frame
);
1585 static void client_change_state(ObClient
*self
)
1588 guint32 netstate
[10];
1591 state
[0] = self
->wmstate
;
1593 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1597 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1599 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1601 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1602 if (self
->skip_taskbar
)
1603 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1604 if (self
->skip_pager
)
1605 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1606 if (self
->fullscreen
)
1607 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1609 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1611 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1613 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1615 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1616 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1618 client_calc_layer(self
);
1621 frame_adjust_state(self
->frame
);
1624 ObClient
*client_search_focus_tree(ObClient
*self
)
1629 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1630 if (client_focused(it
->data
)) return it
->data
;
1631 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1636 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1638 if (self
->transient_for
) {
1639 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1640 return client_search_focus_tree_full(self
->transient_for
);
1643 gboolean recursed
= FALSE
;
1645 for (it
= self
->group
->members
; it
; it
= it
->next
)
1646 if (!((ObClient
*)it
->data
)->transient_for
) {
1648 if ((c
= client_search_focus_tree_full(it
->data
)))
1657 /* this function checks the whole tree, the client_search_focus_tree~
1658 does not, so we need to check this window */
1659 if (client_focused(self
))
1661 return client_search_focus_tree(self
);
1664 static ObStackingLayer
calc_layer(ObClient
*self
)
1668 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1669 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1670 l
= OB_STACKING_LAYER_DESKTOP
;
1671 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1672 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1673 else l
= OB_STACKING_LAYER_NORMAL
;
1675 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1676 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1677 else l
= OB_STACKING_LAYER_NORMAL
;
1682 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1683 ObStackingLayer l
, gboolean raised
)
1685 ObStackingLayer old
, own
;
1689 own
= calc_layer(self
);
1690 self
->layer
= l
> own
? l
: own
;
1692 for (it
= self
->transients
; it
; it
= it
->next
)
1693 client_calc_layer_recursive(it
->data
, orig
,
1694 l
, raised
? raised
: l
!= old
);
1696 if (!raised
&& l
!= old
)
1697 if (orig
->frame
) { /* only restack if the original window is managed */
1698 /* XXX add_non_intrusive ever? */
1699 stacking_remove(CLIENT_AS_WINDOW(self
));
1700 stacking_add(CLIENT_AS_WINDOW(self
));
1704 void client_calc_layer(ObClient
*self
)
1711 /* transients take on the layer of their parents */
1712 self
= client_search_top_transient(self
);
1714 l
= calc_layer(self
);
1716 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1719 gboolean
client_should_show(ObClient
*self
)
1721 if (self
->iconic
) return FALSE
;
1722 else if (!(self
->desktop
== screen_desktop
||
1723 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1724 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1729 static void client_showhide(ObClient
*self
)
1732 if (client_should_show(self
))
1733 frame_show(self
->frame
);
1735 frame_hide(self
->frame
);
1738 gboolean
client_normal(ObClient
*self
) {
1739 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1740 self
->type
== OB_CLIENT_TYPE_DOCK
||
1741 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1744 static void client_apply_startup_state(ObClient
*self
)
1746 /* these are in a carefully crafted order.. */
1749 self
->iconic
= FALSE
;
1750 client_iconify(self
, TRUE
, FALSE
);
1752 if (self
->fullscreen
) {
1753 self
->fullscreen
= FALSE
;
1754 client_fullscreen(self
, TRUE
, FALSE
);
1757 self
->shaded
= FALSE
;
1758 client_shade(self
, TRUE
);
1761 client_urgent_notify(self
);
1763 if (self
->max_vert
&& self
->max_horz
) {
1764 self
->max_vert
= self
->max_horz
= FALSE
;
1765 client_maximize(self
, TRUE
, 0, FALSE
);
1766 } else if (self
->max_vert
) {
1767 self
->max_vert
= FALSE
;
1768 client_maximize(self
, TRUE
, 2, FALSE
);
1769 } else if (self
->max_horz
) {
1770 self
->max_horz
= FALSE
;
1771 client_maximize(self
, TRUE
, 1, FALSE
);
1774 /* nothing to do for the other states:
1783 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1784 int x
, int y
, int w
, int h
,
1785 gboolean user
, gboolean final
,
1786 gboolean force_reply
)
1789 gboolean send_resize_client
;
1790 gboolean moved
= FALSE
, resized
= FALSE
;
1791 guint fdecor
= self
->frame
->decorations
;
1792 gboolean fhorz
= self
->frame
->max_horz
;
1794 /* make the frame recalculate its dimentions n shit without changing
1795 anything visible for real, this way the constraints below can work with
1796 the updated frame dimensions. */
1797 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1799 /* gets the frame's position */
1800 frame_client_gravity(self
->frame
, &x
, &y
);
1802 /* these positions are frame positions, not client positions */
1804 /* set the size and position if fullscreen */
1805 if (self
->fullscreen
) {
1808 XF86VidModeModeLine mode
;
1813 i
= client_monitor(self
);
1814 a
= screen_physical_area_monitor(i
);
1817 if (i
== 0 && /* primary head */
1818 extensions_vidmode
&&
1819 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1820 /* get the mode last so the mode.privsize isnt freed incorrectly */
1821 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1826 if (mode
.privsize
) XFree(mode
.private);
1836 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1840 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1842 /* set the size and position if maximized */
1843 if (self
->max_horz
) {
1845 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1847 if (self
->max_vert
) {
1849 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1853 /* gets the client's position */
1854 frame_frame_gravity(self
->frame
, &x
, &y
);
1856 /* these override the above states! if you cant move you can't move! */
1858 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1862 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1863 w
= self
->area
.width
;
1864 h
= self
->area
.height
;
1868 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1869 int basew
, baseh
, minw
, minh
;
1871 /* base size is substituted with min size if not specified */
1872 if (self
->base_size
.width
|| self
->base_size
.height
) {
1873 basew
= self
->base_size
.width
;
1874 baseh
= self
->base_size
.height
;
1876 basew
= self
->min_size
.width
;
1877 baseh
= self
->min_size
.height
;
1879 /* min size is substituted with base size if not specified */
1880 if (self
->min_size
.width
|| self
->min_size
.height
) {
1881 minw
= self
->min_size
.width
;
1882 minh
= self
->min_size
.height
;
1884 minw
= self
->base_size
.width
;
1885 minh
= self
->base_size
.height
;
1888 /* if this is a user-requested resize, then check against min/max
1891 /* smaller than min size or bigger than max size? */
1892 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1893 if (w
< minw
) w
= minw
;
1894 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1895 if (h
< minh
) h
= minh
;
1900 /* keep to the increments */
1901 w
/= self
->size_inc
.width
;
1902 h
/= self
->size_inc
.height
;
1904 /* you cannot resize to nothing */
1905 if (basew
+ w
< 1) w
= 1 - basew
;
1906 if (baseh
+ h
< 1) h
= 1 - baseh
;
1908 /* store the logical size */
1909 SIZE_SET(self
->logical_size
,
1910 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1911 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1913 w
*= self
->size_inc
.width
;
1914 h
*= self
->size_inc
.height
;
1919 /* adjust the height to match the width for the aspect ratios.
1920 for this, min size is not substituted for base size ever. */
1921 w
-= self
->base_size
.width
;
1922 h
-= self
->base_size
.height
;
1924 if (self
->min_ratio
)
1925 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1926 if (self
->max_ratio
)
1927 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1929 w
+= self
->base_size
.width
;
1930 h
+= self
->base_size
.height
;
1934 case OB_CORNER_TOPLEFT
:
1936 case OB_CORNER_TOPRIGHT
:
1937 x
-= w
- self
->area
.width
;
1939 case OB_CORNER_BOTTOMLEFT
:
1940 y
-= h
- self
->area
.height
;
1942 case OB_CORNER_BOTTOMRIGHT
:
1943 x
-= w
- self
->area
.width
;
1944 y
-= h
- self
->area
.height
;
1948 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1949 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1951 oldw
= self
->area
.width
;
1952 oldh
= self
->area
.height
;
1953 RECT_SET(self
->area
, x
, y
, w
, h
);
1955 /* for app-requested resizes, always resize if 'resized' is true.
1956 for user-requested ones, only resize if final is true, or when
1957 resizing in redraw mode */
1958 send_resize_client
= ((!user
&& resized
) ||
1960 (resized
&& config_redraw_resize
))));
1962 /* if the client is enlarging, the resize the client before the frame */
1963 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
1964 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
1966 /* move/resize the frame to match the request */
1968 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
1969 moved
= resized
= TRUE
;
1971 if (moved
|| resized
)
1972 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
1974 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1977 event
.type
= ConfigureNotify
;
1978 event
.xconfigure
.display
= ob_display
;
1979 event
.xconfigure
.event
= self
->window
;
1980 event
.xconfigure
.window
= self
->window
;
1982 /* root window real coords */
1983 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1985 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1987 event
.xconfigure
.width
= w
;
1988 event
.xconfigure
.height
= h
;
1989 event
.xconfigure
.border_width
= 0;
1990 event
.xconfigure
.above
= self
->frame
->plate
;
1991 event
.xconfigure
.override_redirect
= FALSE
;
1992 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1993 FALSE
, StructureNotifyMask
, &event
);
1997 /* if the client is shrinking, then resize the frame before the client */
1998 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
1999 XResizeWindow(ob_display
, self
->window
, w
, h
);
2004 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2008 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2009 self
->fullscreen
== fs
) return; /* already done */
2011 self
->fullscreen
= fs
;
2012 client_change_state(self
); /* change the state hints on the client,
2013 and adjust out layer/stacking */
2017 guint32 dimensions
[4];
2018 dimensions
[0] = self
->area
.x
;
2019 dimensions
[1] = self
->area
.y
;
2020 dimensions
[2] = self
->area
.width
;
2021 dimensions
[3] = self
->area
.height
;
2023 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2027 /* these are not actually used cuz client_configure will set them
2028 as appropriate when the window is fullscreened */
2035 /* pick some fallbacks... */
2036 a
= screen_area_monitor(self
->desktop
, 0);
2037 x
= a
->x
+ a
->width
/ 4;
2038 y
= a
->y
+ a
->height
/ 4;
2042 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2043 (guint32
**)&dimensions
, &num
)) {
2054 client_setup_decor_and_functions(self
);
2056 client_move_resize(self
, x
, y
, w
, h
);
2058 /* try focus us when we go into fullscreen mode */
2062 static void client_iconify_recursive(ObClient
*self
,
2063 gboolean iconic
, gboolean curdesk
)
2066 gboolean changed
= FALSE
;
2069 if (self
->iconic
!= iconic
) {
2070 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2073 self
->iconic
= iconic
;
2076 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2079 old
= self
->wmstate
;
2080 self
->wmstate
= IconicState
;
2081 if (old
!= self
->wmstate
)
2082 PROP_MSG(self
->window
, kde_wm_change_state
,
2083 self
->wmstate
, 1, 0, 0);
2085 self
->ignore_unmaps
++;
2086 /* we unmap the client itself so that we can get MapRequest
2087 events, and because the ICCCM tells us to! */
2088 XUnmapWindow(ob_display
, self
->window
);
2090 /* update the focus lists.. iconic windows go to the bottom of
2091 the list, put the new iconic window at the 'top of the
2093 focus_order_to_top(self
);
2101 client_set_desktop(self
, screen_desktop
, FALSE
);
2103 old
= self
->wmstate
;
2104 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2105 if (old
!= self
->wmstate
)
2106 PROP_MSG(self
->window
, kde_wm_change_state
,
2107 self
->wmstate
, 1, 0, 0);
2109 XMapWindow(ob_display
, self
->window
);
2111 /* this puts it after the current focused window */
2112 focus_order_remove(self
);
2113 focus_order_add_new(self
);
2115 /* this is here cuz with the VIDMODE extension, the viewport can
2116 change while a fullscreen window is iconic, and when it
2117 uniconifies, it would be nice if it did so to the new position
2119 client_reconfigure(self
);
2126 client_change_state(self
);
2127 client_showhide(self
);
2128 screen_update_areas();
2131 /* iconify all transients */
2132 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2133 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2137 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2139 /* move up the transient chain as far as possible first */
2140 self
= client_search_top_transient(self
);
2142 client_iconify_recursive(client_search_top_transient(self
),
2146 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2150 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2151 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2153 /* check if already done */
2155 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2156 if (dir
== 1 && self
->max_horz
) return;
2157 if (dir
== 2 && self
->max_vert
) return;
2159 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2160 if (dir
== 1 && !self
->max_horz
) return;
2161 if (dir
== 2 && !self
->max_vert
) return;
2164 /* work with the frame's coords */
2165 x
= self
->frame
->area
.x
;
2166 y
= self
->frame
->area
.y
;
2167 w
= self
->area
.width
;
2168 h
= self
->area
.height
;
2172 gint32 dimensions
[4];
2181 /* get the property off the window and use it for the dimensions
2182 we are already maxed on */
2183 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2184 (guint32
**)&readdim
, &num
)) {
2186 if (self
->max_horz
) {
2187 dimensions
[0] = readdim
[0];
2188 dimensions
[2] = readdim
[2];
2190 if (self
->max_vert
) {
2191 dimensions
[1] = readdim
[1];
2192 dimensions
[3] = readdim
[3];
2198 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2199 (guint32
*)dimensions
, 4);
2206 /* pick some fallbacks... */
2207 a
= screen_area_monitor(self
->desktop
, 0);
2208 if (dir
== 0 || dir
== 1) { /* horz */
2209 x
= a
->x
+ a
->width
/ 4;
2212 if (dir
== 0 || dir
== 2) { /* vert */
2213 y
= a
->y
+ a
->height
/ 4;
2217 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2218 (guint32
**)&dimensions
, &num
)) {
2220 if (dir
== 0 || dir
== 1) { /* horz */
2224 if (dir
== 0 || dir
== 2) { /* vert */
2233 if (dir
== 0 || dir
== 1) /* horz */
2234 self
->max_horz
= max
;
2235 if (dir
== 0 || dir
== 2) /* vert */
2236 self
->max_vert
= max
;
2238 if (!self
->max_horz
&& !self
->max_vert
)
2239 PROP_ERASE(self
->window
, openbox_premax
);
2241 client_change_state(self
); /* change the state hints on the client */
2243 client_setup_decor_and_functions(self
);
2245 /* figure out where the client should be going */
2246 frame_frame_gravity(self
->frame
, &x
, &y
);
2247 client_move_resize(self
, x
, y
, w
, h
);
2250 void client_shade(ObClient
*self
, gboolean shade
)
2252 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2253 shade
) || /* can't shade */
2254 self
->shaded
== shade
) return; /* already done */
2256 /* when we're iconic, don't change the wmstate */
2257 if (!self
->iconic
) {
2260 old
= self
->wmstate
;
2261 self
->wmstate
= shade
? IconicState
: NormalState
;
2262 if (old
!= self
->wmstate
)
2263 PROP_MSG(self
->window
, kde_wm_change_state
,
2264 self
->wmstate
, 1, 0, 0);
2267 self
->shaded
= shade
;
2268 client_change_state(self
);
2269 /* resize the frame to just the titlebar */
2270 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2273 void client_close(ObClient
*self
)
2277 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2280 XXX: itd be cool to do timeouts and shit here for killing the client's
2282 like... if the window is around after 5 seconds, then the close button
2283 turns a nice red, and if this function is called again, the client is
2287 ce
.xclient
.type
= ClientMessage
;
2288 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2289 ce
.xclient
.display
= ob_display
;
2290 ce
.xclient
.window
= self
->window
;
2291 ce
.xclient
.format
= 32;
2292 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2293 ce
.xclient
.data
.l
[1] = event_lasttime
;
2294 ce
.xclient
.data
.l
[2] = 0l;
2295 ce
.xclient
.data
.l
[3] = 0l;
2296 ce
.xclient
.data
.l
[4] = 0l;
2297 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2300 void client_kill(ObClient
*self
)
2302 XKillClient(ob_display
, self
->window
);
2305 void client_set_desktop_recursive(ObClient
*self
,
2306 guint target
, gboolean donthide
)
2311 if (target
!= self
->desktop
) {
2313 ob_debug("Setting desktop %u\n", target
+1);
2315 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2317 /* remove from the old desktop(s) */
2318 focus_order_remove(self
);
2320 old
= self
->desktop
;
2321 self
->desktop
= target
;
2322 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2323 /* the frame can display the current desktop state */
2324 frame_adjust_state(self
->frame
);
2325 /* 'move' the window to the new desktop */
2327 client_showhide(self
);
2328 /* raise if it was not already on the desktop */
2329 if (old
!= DESKTOP_ALL
)
2330 stacking_raise(CLIENT_AS_WINDOW(self
));
2331 screen_update_areas();
2333 /* add to the new desktop(s) */
2334 if (config_focus_new
)
2335 focus_order_to_top(self
);
2337 focus_order_to_bottom(self
);
2340 /* move all transients */
2341 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2342 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2346 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2348 client_set_desktop_recursive(client_search_top_transient(self
),
2352 ObClient
*client_search_modal_child(ObClient
*self
)
2357 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2358 ObClient
*c
= it
->data
;
2359 if ((ret
= client_search_modal_child(c
))) return ret
;
2360 if (c
->modal
) return c
;
2365 gboolean
client_validate(ObClient
*self
)
2369 XSync(ob_display
, FALSE
); /* get all events on the server */
2371 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2372 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2373 XPutBackEvent(ob_display
, &e
);
2380 void client_set_wm_state(ObClient
*self
, long state
)
2382 if (state
== self
->wmstate
) return; /* no change */
2386 client_iconify(self
, TRUE
, TRUE
);
2389 client_iconify(self
, FALSE
, TRUE
);
2394 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2396 gboolean shaded
= self
->shaded
;
2397 gboolean fullscreen
= self
->fullscreen
;
2398 gboolean max_horz
= self
->max_horz
;
2399 gboolean max_vert
= self
->max_vert
;
2402 if (!(action
== prop_atoms
.net_wm_state_add
||
2403 action
== prop_atoms
.net_wm_state_remove
||
2404 action
== prop_atoms
.net_wm_state_toggle
))
2405 /* an invalid action was passed to the client message, ignore it */
2408 for (i
= 0; i
< 2; ++i
) {
2409 Atom state
= i
== 0 ? data1
: data2
;
2411 if (!state
) continue;
2413 /* if toggling, then pick whether we're adding or removing */
2414 if (action
== prop_atoms
.net_wm_state_toggle
) {
2415 if (state
== prop_atoms
.net_wm_state_modal
)
2416 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2417 prop_atoms
.net_wm_state_add
;
2418 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2419 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2420 prop_atoms
.net_wm_state_add
;
2421 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2422 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2423 prop_atoms
.net_wm_state_add
;
2424 else if (state
== prop_atoms
.net_wm_state_shaded
)
2425 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2426 prop_atoms
.net_wm_state_add
;
2427 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2428 action
= self
->skip_taskbar
?
2429 prop_atoms
.net_wm_state_remove
:
2430 prop_atoms
.net_wm_state_add
;
2431 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2432 action
= self
->skip_pager
?
2433 prop_atoms
.net_wm_state_remove
:
2434 prop_atoms
.net_wm_state_add
;
2435 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2436 action
= self
->fullscreen
?
2437 prop_atoms
.net_wm_state_remove
:
2438 prop_atoms
.net_wm_state_add
;
2439 else if (state
== prop_atoms
.net_wm_state_above
)
2440 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2441 prop_atoms
.net_wm_state_add
;
2442 else if (state
== prop_atoms
.net_wm_state_below
)
2443 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2444 prop_atoms
.net_wm_state_add
;
2447 if (action
== prop_atoms
.net_wm_state_add
) {
2448 if (state
== prop_atoms
.net_wm_state_modal
) {
2449 /* XXX raise here or something? */
2451 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2453 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2455 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2457 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2458 self
->skip_taskbar
= TRUE
;
2459 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2460 self
->skip_pager
= TRUE
;
2461 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2463 } else if (state
== prop_atoms
.net_wm_state_above
) {
2465 } else if (state
== prop_atoms
.net_wm_state_below
) {
2469 } else { /* action == prop_atoms.net_wm_state_remove */
2470 if (state
== prop_atoms
.net_wm_state_modal
) {
2471 self
->modal
= FALSE
;
2472 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2474 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2476 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2478 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2479 self
->skip_taskbar
= FALSE
;
2480 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2481 self
->skip_pager
= FALSE
;
2482 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2484 } else if (state
== prop_atoms
.net_wm_state_above
) {
2485 self
->above
= FALSE
;
2486 } else if (state
== prop_atoms
.net_wm_state_below
) {
2487 self
->below
= FALSE
;
2491 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2492 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2494 if (max_horz
== max_vert
) { /* both going the same way */
2495 client_maximize(self
, max_horz
, 0, TRUE
);
2497 client_maximize(self
, max_horz
, 1, TRUE
);
2498 client_maximize(self
, max_vert
, 2, TRUE
);
2502 if (max_horz
!= self
->max_horz
)
2503 client_maximize(self
, max_horz
, 1, TRUE
);
2505 client_maximize(self
, max_vert
, 2, TRUE
);
2508 /* change fullscreen state before shading, as it will affect if the window
2510 if (fullscreen
!= self
->fullscreen
)
2511 client_fullscreen(self
, fullscreen
, TRUE
);
2512 if (shaded
!= self
->shaded
)
2513 client_shade(self
, shaded
);
2514 client_calc_layer(self
);
2515 client_change_state(self
); /* change the hint to reflect these changes */
2518 ObClient
*client_focus_target(ObClient
*self
)
2522 /* if we have a modal child, then focus it, not us */
2523 child
= client_search_modal_child(self
);
2524 if (child
) return child
;
2528 gboolean
client_can_focus(ObClient
*self
)
2532 /* choose the correct target */
2533 self
= client_focus_target(self
);
2535 if (!self
->frame
->visible
)
2538 if (!((self
->can_focus
|| self
->focus_notify
) &&
2539 (self
->desktop
== screen_desktop
||
2540 self
->desktop
== DESKTOP_ALL
) &&
2544 /* do a check to see if the window has already been unmapped or destroyed
2545 do this intelligently while watching out for unmaps we've generated
2546 (ignore_unmaps > 0) */
2547 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2548 DestroyNotify
, &ev
)) {
2549 XPutBackEvent(ob_display
, &ev
);
2552 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2553 UnmapNotify
, &ev
)) {
2554 if (self
->ignore_unmaps
) {
2555 self
->ignore_unmaps
--;
2557 XPutBackEvent(ob_display
, &ev
);
2565 gboolean
client_focus(ObClient
*self
)
2567 /* choose the correct target */
2568 self
= client_focus_target(self
);
2570 if (!client_can_focus(self
)) {
2571 if (!self
->frame
->visible
) {
2572 /* update the focus lists */
2573 focus_order_to_top(self
);
2578 if (self
->can_focus
) {
2579 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2580 I choose to use it always, hopefully to find errors quicker, if any
2581 are left. (I hate X. I hate focus events.)
2583 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2584 #799. So now it is RevertToNone again.
2586 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2590 if (self
->focus_notify
) {
2592 ce
.xclient
.type
= ClientMessage
;
2593 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2594 ce
.xclient
.display
= ob_display
;
2595 ce
.xclient
.window
= self
->window
;
2596 ce
.xclient
.format
= 32;
2597 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2598 ce
.xclient
.data
.l
[1] = event_lasttime
;
2599 ce
.xclient
.data
.l
[2] = 0l;
2600 ce
.xclient
.data
.l
[3] = 0l;
2601 ce
.xclient
.data
.l
[4] = 0l;
2602 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2606 ob_debug("%sively focusing %lx at %d\n",
2607 (self
->can_focus
? "act" : "pass"),
2608 self
->window
, (int) event_lasttime
);
2611 /* Cause the FocusIn to come back to us. Important for desktop switches,
2612 since otherwise we'll have no FocusIn on the queue and send it off to
2613 the focus_backup. */
2614 XSync(ob_display
, FALSE
);
2618 void client_unfocus(ObClient
*self
)
2620 if (focus_client
== self
) {
2622 ob_debug("client_unfocus for %lx\n", self
->window
);
2624 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2628 void client_activate(ObClient
*self
, gboolean here
)
2630 if (client_normal(self
) && screen_showing_desktop
)
2631 screen_show_desktop(FALSE
);
2633 client_iconify(self
, FALSE
, FALSE
);
2634 if (self
->desktop
!= DESKTOP_ALL
&&
2635 self
->desktop
!= screen_desktop
) {
2637 client_set_desktop(self
, screen_desktop
, FALSE
);
2639 screen_set_desktop(self
->desktop
);
2640 } else if (!self
->frame
->visible
)
2641 /* if its not visible for other reasons, then don't mess
2645 client_shade(self
, FALSE
);
2647 stacking_raise(CLIENT_AS_WINDOW(self
));
2650 gboolean
client_focused(ObClient
*self
)
2652 return self
== focus_client
;
2655 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2658 /* si is the smallest image >= req */
2659 /* li is the largest image < req */
2660 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2662 for (i
= 0; i
< self
->nicons
; ++i
) {
2663 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2664 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2668 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2673 if (largest
== 0) /* didnt find one smaller than the requested size */
2674 return &self
->icons
[si
];
2675 return &self
->icons
[li
];
2678 /* this be mostly ripped from fvwm */
2679 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2681 int my_cx
, my_cy
, his_cx
, his_cy
;
2684 int score
, best_score
;
2685 ObClient
*best_client
, *cur
;
2691 /* first, find the centre coords of the currently focused window */
2692 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2693 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2698 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2701 /* the currently selected window isn't interesting */
2704 if (!client_normal(cur
))
2706 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2710 if(client_focus_target(cur
) == cur
&&
2711 !(cur
->can_focus
|| cur
->focus_notify
))
2714 /* find the centre coords of this window, from the
2715 * currently focused window's point of view */
2716 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2717 + cur
->frame
->area
.width
/ 2;
2718 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2719 + cur
->frame
->area
.height
/ 2;
2721 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2722 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2724 /* Rotate the diagonals 45 degrees counterclockwise.
2725 * To do this, multiply the matrix /+h +h\ with the
2726 * vector (x y). \-h +h/
2727 * h = sqrt(0.5). We can set h := 1 since absolute
2728 * distance doesn't matter here. */
2729 tx
= his_cx
+ his_cy
;
2730 his_cy
= -his_cx
+ his_cy
;
2735 case OB_DIRECTION_NORTH
:
2736 case OB_DIRECTION_SOUTH
:
2737 case OB_DIRECTION_NORTHEAST
:
2738 case OB_DIRECTION_SOUTHWEST
:
2739 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2740 distance
= ((dir
== OB_DIRECTION_NORTH
||
2741 dir
== OB_DIRECTION_NORTHEAST
) ?
2744 case OB_DIRECTION_EAST
:
2745 case OB_DIRECTION_WEST
:
2746 case OB_DIRECTION_SOUTHEAST
:
2747 case OB_DIRECTION_NORTHWEST
:
2748 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2749 distance
= ((dir
== OB_DIRECTION_WEST
||
2750 dir
== OB_DIRECTION_NORTHWEST
) ?
2755 /* the target must be in the requested direction */
2759 /* Calculate score for this window. The smaller the better. */
2760 score
= distance
+ offset
;
2762 /* windows more than 45 degrees off the direction are
2763 * heavily penalized and will only be chosen if nothing
2764 * else within a million pixels */
2765 if(offset
> distance
)
2768 if(best_score
== -1 || score
< best_score
)
2776 void client_set_layer(ObClient
*self
, int layer
)
2780 self
->above
= FALSE
;
2781 } else if (layer
== 0) {
2782 self
->below
= self
->above
= FALSE
;
2784 self
->below
= FALSE
;
2787 client_calc_layer(self
);
2788 client_change_state(self
); /* reflect this in the state hints */
2791 guint
client_monitor(ObClient
*self
)
2795 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2796 Rect
*area
= screen_physical_area_monitor(i
);
2797 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2800 if (i
== screen_num_monitors
) i
= 0;
2801 g_assert(i
< screen_num_monitors
);
2805 ObClient
*client_search_top_transient(ObClient
*self
)
2807 /* move up the transient chain as far as possible */
2808 if (self
->transient_for
) {
2809 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2810 return client_search_top_transient(self
->transient_for
);
2814 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2815 ObClient
*c
= it
->data
;
2817 /* checking transient_for prevents infinate loops! */
2818 if (c
!= self
&& !c
->transient_for
)
2829 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2833 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2834 if (sit
->data
== search
)
2836 if (client_search_transient(sit
->data
, search
))
2842 void client_update_sm_client_id(ObClient
*self
)
2844 g_free(self
->sm_client_id
);
2845 self
->sm_client_id
= NULL
;
2847 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
2849 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
2850 &self
->sm_client_id
);
2853 /* finds the nearest edge in the given direction from the current client
2854 * note to self: the edge is the -frame- edge (the actual one), not the
2857 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
2860 int my_edge_start
, my_edge_end
, my_offset
;
2867 a
= screen_area(c
->desktop
);
2870 case OB_DIRECTION_NORTH
:
2871 my_edge_start
= c
->frame
->area
.x
;
2872 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2873 my_offset
= c
->frame
->area
.y
;
2875 dest
= a
->y
; /* default: top of screen */
2877 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2878 int his_edge_start
, his_edge_end
, his_offset
;
2879 ObClient
*cur
= it
->data
;
2883 if(!client_normal(cur
))
2885 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2890 his_edge_start
= cur
->frame
->area
.x
;
2891 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2892 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2894 if(his_offset
+ 1 > my_offset
)
2897 if(his_offset
< dest
)
2900 if(his_edge_start
>= my_edge_start
&&
2901 his_edge_start
<= my_edge_end
)
2904 if(my_edge_start
>= his_edge_start
&&
2905 my_edge_start
<= his_edge_end
)
2910 case OB_DIRECTION_SOUTH
:
2911 my_edge_start
= c
->frame
->area
.x
;
2912 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2913 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2915 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
2917 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2918 int his_edge_start
, his_edge_end
, his_offset
;
2919 ObClient
*cur
= it
->data
;
2923 if(!client_normal(cur
))
2925 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2930 his_edge_start
= cur
->frame
->area
.x
;
2931 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2932 his_offset
= cur
->frame
->area
.y
;
2935 if(his_offset
- 1 < my_offset
)
2938 if(his_offset
> dest
)
2941 if(his_edge_start
>= my_edge_start
&&
2942 his_edge_start
<= my_edge_end
)
2945 if(my_edge_start
>= his_edge_start
&&
2946 my_edge_start
<= his_edge_end
)
2951 case OB_DIRECTION_WEST
:
2952 my_edge_start
= c
->frame
->area
.y
;
2953 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2954 my_offset
= c
->frame
->area
.x
;
2956 dest
= a
->x
; /* default: leftmost egde of screen */
2958 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2959 int his_edge_start
, his_edge_end
, his_offset
;
2960 ObClient
*cur
= it
->data
;
2964 if(!client_normal(cur
))
2966 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2971 his_edge_start
= cur
->frame
->area
.y
;
2972 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2973 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2975 if(his_offset
+ 1 > my_offset
)
2978 if(his_offset
< dest
)
2981 if(his_edge_start
>= my_edge_start
&&
2982 his_edge_start
<= my_edge_end
)
2985 if(my_edge_start
>= his_edge_start
&&
2986 my_edge_start
<= his_edge_end
)
2992 case OB_DIRECTION_EAST
:
2993 my_edge_start
= c
->frame
->area
.y
;
2994 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2995 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2997 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
2999 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
3000 int his_edge_start
, his_edge_end
, his_offset
;
3001 ObClient
*cur
= it
->data
;
3005 if(!client_normal(cur
))
3007 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3012 his_edge_start
= cur
->frame
->area
.y
;
3013 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3014 his_offset
= cur
->frame
->area
.x
;
3016 if(his_offset
- 1 < my_offset
)
3019 if(his_offset
> dest
)
3022 if(his_edge_start
>= my_edge_start
&&
3023 his_edge_start
<= my_edge_end
)
3026 if(my_edge_start
>= his_edge_start
&&
3027 my_edge_start
<= his_edge_end
)
3032 case OB_DIRECTION_NORTHEAST
:
3033 case OB_DIRECTION_SOUTHEAST
:
3034 case OB_DIRECTION_NORTHWEST
:
3035 case OB_DIRECTION_SOUTHWEST
:
3036 /* not implemented */
3038 g_assert_not_reached();
3043 ObClient
* client_under_pointer()
3047 ObClient
*ret
= NULL
;
3049 if (screen_pointer_pos(&x
, &y
)) {
3050 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
3051 if (WINDOW_IS_CLIENT(it
->data
)) {
3052 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3053 if (c
->desktop
== screen_desktop
&&
3054 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {