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
&& config_focus_new
&&
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
)
800 static void client_get_shaped(ObClient
*self
)
802 self
->shaped
= FALSE
;
804 if (extensions_shape
) {
809 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
811 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
812 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
814 self
->shaped
= (s
!= 0);
819 void client_update_transient_for(ObClient
*self
)
822 ObClient
*target
= NULL
;
824 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
825 self
->transient
= TRUE
;
826 if (t
!= self
->window
) { /* cant be transient to itself! */
827 target
= g_hash_table_lookup(window_map
, &t
);
828 /* if this happens then we need to check for it*/
829 g_assert(target
!= self
);
830 if (target
&& !WINDOW_IS_CLIENT(target
)) {
831 /* this can happen when a dialog is a child of
832 a dockapp, for example */
836 if (!target
&& self
->group
) {
837 /* not transient to a client, see if it is transient for a
839 if (t
== self
->group
->leader
||
841 t
== RootWindow(ob_display
, ob_screen
)) {
842 /* window is a transient for its group! */
843 target
= OB_TRAN_GROUP
;
848 self
->transient
= FALSE
;
850 /* if anything has changed... */
851 if (target
!= self
->transient_for
) {
852 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
855 /* remove from old parents */
856 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
857 ObClient
*c
= it
->data
;
858 if (c
!= self
&& !c
->transient_for
)
859 c
->transients
= g_slist_remove(c
->transients
, self
);
861 } else if (self
->transient_for
!= NULL
) { /* transient of window */
862 /* remove from old parent */
863 self
->transient_for
->transients
=
864 g_slist_remove(self
->transient_for
->transients
, self
);
866 self
->transient_for
= target
;
867 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
870 /* add to new parents */
871 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
872 ObClient
*c
= it
->data
;
873 if (c
!= self
&& !c
->transient_for
)
874 c
->transients
= g_slist_append(c
->transients
, self
);
877 /* remove all transients which are in the group, that causes
878 circlular pointer hell of doom */
879 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
881 for (sit
= self
->transients
; sit
; sit
= next
) {
882 next
= g_slist_next(sit
);
883 if (sit
->data
== it
->data
)
885 g_slist_delete_link(self
->transients
, sit
);
888 } else if (self
->transient_for
!= NULL
) { /* transient of window */
889 /* add to new parent */
890 self
->transient_for
->transients
=
891 g_slist_append(self
->transient_for
->transients
, self
);
896 static void client_get_mwm_hints(ObClient
*self
)
901 self
->mwmhints
.flags
= 0; /* default to none */
903 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
905 if (num
>= OB_MWM_ELEMENTS
) {
906 self
->mwmhints
.flags
= hints
[0];
907 self
->mwmhints
.functions
= hints
[1];
908 self
->mwmhints
.decorations
= hints
[2];
914 void client_get_type(ObClient
*self
)
921 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
922 /* use the first value that we know about in the array */
923 for (i
= 0; i
< num
; ++i
) {
924 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
925 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
926 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
927 self
->type
= OB_CLIENT_TYPE_DOCK
;
928 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
929 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
930 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
931 self
->type
= OB_CLIENT_TYPE_MENU
;
932 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
933 self
->type
= OB_CLIENT_TYPE_UTILITY
;
934 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
935 self
->type
= OB_CLIENT_TYPE_SPLASH
;
936 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
937 self
->type
= OB_CLIENT_TYPE_DIALOG
;
938 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
939 self
->type
= OB_CLIENT_TYPE_NORMAL
;
940 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
941 /* prevent this window from getting any decor or
943 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
944 OB_MWM_FLAG_DECORATIONS
);
945 self
->mwmhints
.decorations
= 0;
946 self
->mwmhints
.functions
= 0;
948 if (self
->type
!= (ObClientType
) -1)
949 break; /* grab the first legit type */
954 if (self
->type
== (ObClientType
) -1) {
955 /*the window type hint was not set, which means we either classify
956 ourself as a normal window or a dialog, depending on if we are a
959 self
->type
= OB_CLIENT_TYPE_DIALOG
;
961 self
->type
= OB_CLIENT_TYPE_NORMAL
;
965 void client_update_protocols(ObClient
*self
)
970 self
->focus_notify
= FALSE
;
971 self
->delete_window
= FALSE
;
973 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
974 for (i
= 0; i
< num_return
; ++i
) {
975 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
976 /* this means we can request the window to close */
977 self
->delete_window
= TRUE
;
978 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
979 /* if this protocol is requested, then the window will be
980 notified whenever we want it to receive focus */
981 self
->focus_notify
= TRUE
;
987 static void client_get_gravity(ObClient
*self
)
989 XWindowAttributes wattrib
;
992 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
993 g_assert(ret
!= BadWindow
);
994 self
->gravity
= wattrib
.win_gravity
;
997 void client_update_normal_hints(ObClient
*self
)
1001 int oldgravity
= self
->gravity
;
1004 self
->min_ratio
= 0.0f
;
1005 self
->max_ratio
= 0.0f
;
1006 SIZE_SET(self
->size_inc
, 1, 1);
1007 SIZE_SET(self
->base_size
, 0, 0);
1008 SIZE_SET(self
->min_size
, 0, 0);
1009 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1011 /* get the hints from the window */
1012 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1013 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1015 if (size
.flags
& PWinGravity
) {
1016 self
->gravity
= size
.win_gravity
;
1018 /* if the client has a frame, i.e. has already been mapped and
1019 is changing its gravity */
1020 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1021 /* move our idea of the client's position based on its new
1023 self
->area
.x
= self
->frame
->area
.x
;
1024 self
->area
.y
= self
->frame
->area
.y
;
1025 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1029 if (size
.flags
& PAspect
) {
1030 if (size
.min_aspect
.y
)
1031 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1032 if (size
.max_aspect
.y
)
1033 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1036 if (size
.flags
& PMinSize
)
1037 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1039 if (size
.flags
& PMaxSize
)
1040 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1042 if (size
.flags
& PBaseSize
)
1043 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1045 if (size
.flags
& PResizeInc
)
1046 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1050 void client_setup_decor_and_functions(ObClient
*self
)
1052 /* start with everything (cept fullscreen) */
1054 (OB_FRAME_DECOR_TITLEBAR
|
1055 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1056 OB_FRAME_DECOR_GRIPS
|
1057 OB_FRAME_DECOR_BORDER
|
1058 OB_FRAME_DECOR_ICON
|
1059 OB_FRAME_DECOR_ALLDESKTOPS
|
1060 OB_FRAME_DECOR_ICONIFY
|
1061 OB_FRAME_DECOR_MAXIMIZE
|
1062 OB_FRAME_DECOR_SHADE
);
1064 (OB_CLIENT_FUNC_RESIZE
|
1065 OB_CLIENT_FUNC_MOVE
|
1066 OB_CLIENT_FUNC_ICONIFY
|
1067 OB_CLIENT_FUNC_MAXIMIZE
|
1068 OB_CLIENT_FUNC_SHADE
);
1069 if (self
->delete_window
) {
1070 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1071 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1074 if (!(self
->min_size
.width
< self
->max_size
.width
||
1075 self
->min_size
.height
< self
->max_size
.height
))
1076 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1078 switch (self
->type
) {
1079 case OB_CLIENT_TYPE_NORMAL
:
1080 /* normal windows retain all of the possible decorations and
1081 functionality, and are the only windows that you can fullscreen */
1082 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1085 case OB_CLIENT_TYPE_DIALOG
:
1086 case OB_CLIENT_TYPE_UTILITY
:
1087 /* these windows cannot be maximized */
1088 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1091 case OB_CLIENT_TYPE_MENU
:
1092 case OB_CLIENT_TYPE_TOOLBAR
:
1093 /* these windows get less functionality */
1094 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1097 case OB_CLIENT_TYPE_DESKTOP
:
1098 case OB_CLIENT_TYPE_DOCK
:
1099 case OB_CLIENT_TYPE_SPLASH
:
1100 /* none of these windows are manipulated by the window manager */
1101 self
->decorations
= 0;
1102 self
->functions
= 0;
1106 /* Mwm Hints are applied subtractively to what has already been chosen for
1107 decor and functionality */
1108 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1109 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1110 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1111 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1112 /* if the mwm hints request no handle or title, then all
1113 decorations are disabled */
1114 self
->decorations
= 0;
1118 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1119 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1120 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1121 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1122 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1123 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1124 /* dont let mwm hints kill any buttons
1125 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1126 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1127 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1128 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1130 /* dont let mwm hints kill the close button
1131 if (! (self->mwmhints.functions & MwmFunc_Close))
1132 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1136 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1137 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1138 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1139 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1140 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1141 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1143 /* can't maximize without moving/resizing */
1144 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1145 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1146 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1147 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1148 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1151 /* kill the handle on fully maxed windows */
1152 if (self
->max_vert
&& self
->max_horz
)
1153 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1155 /* finally, the user can have requested no decorations, which overrides
1157 if (!self
->decorate
)
1158 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1160 /* if we don't have a titlebar, then we cannot shade! */
1161 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1162 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1164 /* now we need to check against rules for the client's current state */
1165 if (self
->fullscreen
) {
1166 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1167 OB_CLIENT_FUNC_FULLSCREEN
|
1168 OB_CLIENT_FUNC_ICONIFY
);
1169 self
->decorations
= 0;
1172 client_change_allowed_actions(self
);
1175 /* adjust the client's decorations, etc. */
1176 client_reconfigure(self
);
1178 /* this makes sure that these windows appear on all desktops */
1179 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1180 self
->desktop
!= DESKTOP_ALL
)
1182 self
->desktop
= DESKTOP_ALL
;
1187 static void client_change_allowed_actions(ObClient
*self
)
1192 /* desktop windows are kept on all desktops */
1193 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1194 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1196 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1197 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1198 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1199 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1200 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1201 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1202 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1203 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1204 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1205 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1206 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1207 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1208 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1209 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1210 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1213 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1215 /* make sure the window isn't breaking any rules now */
1217 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1218 if (self
->frame
) client_shade(self
, FALSE
);
1219 else self
->shaded
= FALSE
;
1221 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1222 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1223 else self
->iconic
= FALSE
;
1225 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1226 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1227 else self
->fullscreen
= FALSE
;
1229 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1231 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1232 else self
->max_vert
= self
->max_horz
= FALSE
;
1236 void client_reconfigure(ObClient
*self
)
1238 /* by making this pass FALSE for user, we avoid the emacs event storm where
1239 every configurenotify causes an update in its normal hints, i think this
1240 is generally what we want anyways... */
1241 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1242 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1245 void client_update_wmhints(ObClient
*self
)
1248 gboolean ur
= FALSE
;
1251 /* assume a window takes input if it doesnt specify */
1252 self
->can_focus
= TRUE
;
1254 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1255 if (hints
->flags
& InputHint
)
1256 self
->can_focus
= hints
->input
;
1258 /* only do this when first managing the window *AND* when we aren't
1260 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1261 if (hints
->flags
& StateHint
)
1262 self
->iconic
= hints
->initial_state
== IconicState
;
1264 if (hints
->flags
& XUrgencyHint
)
1267 if (!(hints
->flags
& WindowGroupHint
))
1268 hints
->window_group
= None
;
1270 /* did the group state change? */
1271 if (hints
->window_group
!=
1272 (self
->group
? self
->group
->leader
: None
)) {
1273 /* remove from the old group if there was one */
1274 if (self
->group
!= NULL
) {
1275 /* remove transients of the group */
1276 for (it
= self
->group
->members
; it
; it
= it
->next
)
1277 self
->transients
= g_slist_remove(self
->transients
,
1279 group_remove(self
->group
, self
);
1282 if (hints
->window_group
!= None
) {
1283 self
->group
= group_add(hints
->window_group
, self
);
1285 /* i can only have transients from the group if i am not
1287 if (!self
->transient_for
) {
1288 /* add other transients of the group that are already
1290 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1291 ObClient
*c
= it
->data
;
1292 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1294 g_slist_append(self
->transients
, c
);
1299 /* because the self->transient flag wont change from this call,
1300 we don't need to update the window's type and such, only its
1301 transient_for, and the transients lists of other windows in
1302 the group may be affected */
1303 client_update_transient_for(self
);
1306 /* the WM_HINTS can contain an icon */
1307 client_update_icons(self
);
1312 if (ur
!= self
->urgent
) {
1314 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
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
[10];
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 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1615 client_calc_layer(self
);
1618 frame_adjust_state(self
->frame
);
1621 ObClient
*client_search_focus_tree(ObClient
*self
)
1626 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1627 if (client_focused(it
->data
)) return it
->data
;
1628 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1633 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1635 if (self
->transient_for
) {
1636 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1637 return client_search_focus_tree_full(self
->transient_for
);
1640 gboolean recursed
= FALSE
;
1642 for (it
= self
->group
->members
; it
; it
= it
->next
)
1643 if (!((ObClient
*)it
->data
)->transient_for
) {
1645 if ((c
= client_search_focus_tree_full(it
->data
)))
1654 /* this function checks the whole tree, the client_search_focus_tree~
1655 does not, so we need to check this window */
1656 if (client_focused(self
))
1658 return client_search_focus_tree(self
);
1661 static ObStackingLayer
calc_layer(ObClient
*self
)
1665 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1666 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1667 l
= OB_STACKING_LAYER_DESKTOP
;
1668 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1669 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1670 else l
= OB_STACKING_LAYER_NORMAL
;
1672 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1673 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1674 else l
= OB_STACKING_LAYER_NORMAL
;
1679 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1680 ObStackingLayer l
, gboolean raised
)
1682 ObStackingLayer old
, own
;
1686 own
= calc_layer(self
);
1687 self
->layer
= l
> own
? l
: own
;
1689 for (it
= self
->transients
; it
; it
= it
->next
)
1690 client_calc_layer_recursive(it
->data
, orig
,
1691 l
, raised
? raised
: l
!= old
);
1693 if (!raised
&& l
!= old
)
1694 if (orig
->frame
) { /* only restack if the original window is managed */
1695 /* XXX add_non_intrusive ever? */
1696 stacking_remove(CLIENT_AS_WINDOW(self
));
1697 stacking_add(CLIENT_AS_WINDOW(self
));
1701 void client_calc_layer(ObClient
*self
)
1708 /* transients take on the layer of their parents */
1709 self
= client_search_top_transient(self
);
1711 l
= calc_layer(self
);
1713 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1716 gboolean
client_should_show(ObClient
*self
)
1718 if (self
->iconic
) return FALSE
;
1719 else if (!(self
->desktop
== screen_desktop
||
1720 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1721 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1726 static void client_showhide(ObClient
*self
)
1729 if (client_should_show(self
))
1730 frame_show(self
->frame
);
1732 frame_hide(self
->frame
);
1735 gboolean
client_normal(ObClient
*self
) {
1736 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1737 self
->type
== OB_CLIENT_TYPE_DOCK
||
1738 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1741 static void client_apply_startup_state(ObClient
*self
)
1743 /* these are in a carefully crafted order.. */
1746 self
->iconic
= FALSE
;
1747 client_iconify(self
, TRUE
, FALSE
);
1749 if (self
->fullscreen
) {
1750 self
->fullscreen
= FALSE
;
1751 client_fullscreen(self
, TRUE
, FALSE
);
1754 self
->shaded
= FALSE
;
1755 client_shade(self
, TRUE
);
1758 client_urgent_notify(self
);
1760 if (self
->max_vert
&& self
->max_horz
) {
1761 self
->max_vert
= self
->max_horz
= FALSE
;
1762 client_maximize(self
, TRUE
, 0, FALSE
);
1763 } else if (self
->max_vert
) {
1764 self
->max_vert
= FALSE
;
1765 client_maximize(self
, TRUE
, 2, FALSE
);
1766 } else if (self
->max_horz
) {
1767 self
->max_horz
= FALSE
;
1768 client_maximize(self
, TRUE
, 1, FALSE
);
1771 /* nothing to do for the other states:
1780 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1781 int x
, int y
, int w
, int h
,
1782 gboolean user
, gboolean final
,
1783 gboolean force_reply
)
1786 gboolean send_resize_client
;
1787 gboolean moved
= FALSE
, resized
= FALSE
;
1788 guint fdecor
= self
->frame
->decorations
;
1789 gboolean fhorz
= self
->frame
->max_horz
;
1791 /* make the frame recalculate its dimentions n shit without changing
1792 anything visible for real, this way the constraints below can work with
1793 the updated frame dimensions. */
1794 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1796 /* gets the frame's position */
1797 frame_client_gravity(self
->frame
, &x
, &y
);
1799 /* these positions are frame positions, not client positions */
1801 /* set the size and position if fullscreen */
1802 if (self
->fullscreen
) {
1805 XF86VidModeModeLine mode
;
1810 i
= client_monitor(self
);
1811 a
= screen_physical_area_monitor(i
);
1814 if (i
== 0 && /* primary head */
1815 extensions_vidmode
&&
1816 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1817 /* get the mode last so the mode.privsize isnt freed incorrectly */
1818 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1823 if (mode
.privsize
) XFree(mode
.private);
1833 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1837 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1839 /* set the size and position if maximized */
1840 if (self
->max_horz
) {
1842 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1844 if (self
->max_vert
) {
1846 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1850 /* gets the client's position */
1851 frame_frame_gravity(self
->frame
, &x
, &y
);
1853 /* these override the above states! if you cant move you can't move! */
1855 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1859 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1860 w
= self
->area
.width
;
1861 h
= self
->area
.height
;
1865 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1866 int basew
, baseh
, minw
, minh
;
1868 /* base size is substituted with min size if not specified */
1869 if (self
->base_size
.width
|| self
->base_size
.height
) {
1870 basew
= self
->base_size
.width
;
1871 baseh
= self
->base_size
.height
;
1873 basew
= self
->min_size
.width
;
1874 baseh
= self
->min_size
.height
;
1876 /* min size is substituted with base size if not specified */
1877 if (self
->min_size
.width
|| self
->min_size
.height
) {
1878 minw
= self
->min_size
.width
;
1879 minh
= self
->min_size
.height
;
1881 minw
= self
->base_size
.width
;
1882 minh
= self
->base_size
.height
;
1885 /* if this is a user-requested resize, then check against min/max
1888 /* smaller than min size or bigger than max size? */
1889 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1890 if (w
< minw
) w
= minw
;
1891 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1892 if (h
< minh
) h
= minh
;
1897 /* keep to the increments */
1898 w
/= self
->size_inc
.width
;
1899 h
/= self
->size_inc
.height
;
1901 /* you cannot resize to nothing */
1902 if (basew
+ w
< 1) w
= 1 - basew
;
1903 if (baseh
+ h
< 1) h
= 1 - baseh
;
1905 /* store the logical size */
1906 SIZE_SET(self
->logical_size
,
1907 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1908 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1910 w
*= self
->size_inc
.width
;
1911 h
*= self
->size_inc
.height
;
1916 /* adjust the height to match the width for the aspect ratios.
1917 for this, min size is not substituted for base size ever. */
1918 w
-= self
->base_size
.width
;
1919 h
-= self
->base_size
.height
;
1921 if (self
->min_ratio
)
1922 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1923 if (self
->max_ratio
)
1924 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1926 w
+= self
->base_size
.width
;
1927 h
+= self
->base_size
.height
;
1931 case OB_CORNER_TOPLEFT
:
1933 case OB_CORNER_TOPRIGHT
:
1934 x
-= w
- self
->area
.width
;
1936 case OB_CORNER_BOTTOMLEFT
:
1937 y
-= h
- self
->area
.height
;
1939 case OB_CORNER_BOTTOMRIGHT
:
1940 x
-= w
- self
->area
.width
;
1941 y
-= h
- self
->area
.height
;
1945 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1946 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1948 oldw
= self
->area
.width
;
1949 oldh
= self
->area
.height
;
1950 RECT_SET(self
->area
, x
, y
, w
, h
);
1952 /* for app-requested resizes, always resize if 'resized' is true.
1953 for user-requested ones, only resize if final is true, or when
1954 resizing in redraw mode */
1955 send_resize_client
= ((!user
&& resized
) ||
1957 (resized
&& config_redraw_resize
))));
1959 /* if the client is enlarging, the resize the client before the frame */
1960 if (send_resize_client
&& user
&& (w
> oldw
|| h
> oldh
))
1961 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
1963 /* move/resize the frame to match the request */
1965 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
1966 moved
= resized
= TRUE
;
1968 if (moved
|| resized
)
1969 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
1971 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1974 event
.type
= ConfigureNotify
;
1975 event
.xconfigure
.display
= ob_display
;
1976 event
.xconfigure
.event
= self
->window
;
1977 event
.xconfigure
.window
= self
->window
;
1979 /* root window real coords */
1980 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1982 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1984 event
.xconfigure
.width
= w
;
1985 event
.xconfigure
.height
= h
;
1986 event
.xconfigure
.border_width
= 0;
1987 event
.xconfigure
.above
= self
->frame
->plate
;
1988 event
.xconfigure
.override_redirect
= FALSE
;
1989 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1990 FALSE
, StructureNotifyMask
, &event
);
1994 /* if the client is shrinking, then resize the frame before the client */
1995 if (send_resize_client
&& (!user
|| (w
<= oldw
|| h
<= oldh
)))
1996 XResizeWindow(ob_display
, self
->window
, w
, h
);
2001 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
2005 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2006 self
->fullscreen
== fs
) return; /* already done */
2008 self
->fullscreen
= fs
;
2009 client_change_state(self
); /* change the state hints on the client,
2010 and adjust out layer/stacking */
2014 guint32 dimensions
[4];
2015 dimensions
[0] = self
->area
.x
;
2016 dimensions
[1] = self
->area
.y
;
2017 dimensions
[2] = self
->area
.width
;
2018 dimensions
[3] = self
->area
.height
;
2020 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2024 /* these are not actually used cuz client_configure will set them
2025 as appropriate when the window is fullscreened */
2032 /* pick some fallbacks... */
2033 a
= screen_area_monitor(self
->desktop
, 0);
2034 x
= a
->x
+ a
->width
/ 4;
2035 y
= a
->y
+ a
->height
/ 4;
2039 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2040 (guint32
**)&dimensions
, &num
)) {
2051 client_setup_decor_and_functions(self
);
2053 client_move_resize(self
, x
, y
, w
, h
);
2055 /* try focus us when we go into fullscreen mode */
2059 static void client_iconify_recursive(ObClient
*self
,
2060 gboolean iconic
, gboolean curdesk
)
2063 gboolean changed
= FALSE
;
2066 if (self
->iconic
!= iconic
) {
2067 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2070 self
->iconic
= iconic
;
2073 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2076 old
= self
->wmstate
;
2077 self
->wmstate
= IconicState
;
2078 if (old
!= self
->wmstate
)
2079 PROP_MSG(self
->window
, kde_wm_change_state
,
2080 self
->wmstate
, 1, 0, 0);
2082 self
->ignore_unmaps
++;
2083 /* we unmap the client itself so that we can get MapRequest
2084 events, and because the ICCCM tells us to! */
2085 XUnmapWindow(ob_display
, self
->window
);
2087 /* update the focus lists.. iconic windows go to the bottom of
2088 the list, put the new iconic window at the 'top of the
2090 focus_order_to_top(self
);
2098 client_set_desktop(self
, screen_desktop
, FALSE
);
2100 old
= self
->wmstate
;
2101 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2102 if (old
!= self
->wmstate
)
2103 PROP_MSG(self
->window
, kde_wm_change_state
,
2104 self
->wmstate
, 1, 0, 0);
2106 XMapWindow(ob_display
, self
->window
);
2108 /* this puts it after the current focused window */
2109 focus_order_remove(self
);
2110 focus_order_add_new(self
);
2112 /* this is here cuz with the VIDMODE extension, the viewport can
2113 change while a fullscreen window is iconic, and when it
2114 uniconifies, it would be nice if it did so to the new position
2116 client_reconfigure(self
);
2123 client_change_state(self
);
2124 client_showhide(self
);
2125 screen_update_areas();
2128 /* iconify all transients */
2129 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2130 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2134 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2136 /* move up the transient chain as far as possible first */
2137 self
= client_search_top_transient(self
);
2139 client_iconify_recursive(client_search_top_transient(self
),
2143 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2147 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2148 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2150 /* check if already done */
2152 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2153 if (dir
== 1 && self
->max_horz
) return;
2154 if (dir
== 2 && self
->max_vert
) return;
2156 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2157 if (dir
== 1 && !self
->max_horz
) return;
2158 if (dir
== 2 && !self
->max_vert
) return;
2161 /* work with the frame's coords */
2162 x
= self
->frame
->area
.x
;
2163 y
= self
->frame
->area
.y
;
2164 w
= self
->area
.width
;
2165 h
= self
->area
.height
;
2169 gint32 dimensions
[4];
2178 /* get the property off the window and use it for the dimensions
2179 we are already maxed on */
2180 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2181 (guint32
**)&readdim
, &num
)) {
2183 if (self
->max_horz
) {
2184 dimensions
[0] = readdim
[0];
2185 dimensions
[2] = readdim
[2];
2187 if (self
->max_vert
) {
2188 dimensions
[1] = readdim
[1];
2189 dimensions
[3] = readdim
[3];
2195 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2196 (guint32
*)dimensions
, 4);
2203 /* pick some fallbacks... */
2204 a
= screen_area_monitor(self
->desktop
, 0);
2205 if (dir
== 0 || dir
== 1) { /* horz */
2206 x
= a
->x
+ a
->width
/ 4;
2209 if (dir
== 0 || dir
== 2) { /* vert */
2210 y
= a
->y
+ a
->height
/ 4;
2214 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2215 (guint32
**)&dimensions
, &num
)) {
2217 if (dir
== 0 || dir
== 1) { /* horz */
2221 if (dir
== 0 || dir
== 2) { /* vert */
2230 if (dir
== 0 || dir
== 1) /* horz */
2231 self
->max_horz
= max
;
2232 if (dir
== 0 || dir
== 2) /* vert */
2233 self
->max_vert
= max
;
2235 if (!self
->max_horz
&& !self
->max_vert
)
2236 PROP_ERASE(self
->window
, openbox_premax
);
2238 client_change_state(self
); /* change the state hints on the client */
2240 client_setup_decor_and_functions(self
);
2242 /* figure out where the client should be going */
2243 frame_frame_gravity(self
->frame
, &x
, &y
);
2244 client_move_resize(self
, x
, y
, w
, h
);
2247 void client_shade(ObClient
*self
, gboolean shade
)
2249 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2250 shade
) || /* can't shade */
2251 self
->shaded
== shade
) return; /* already done */
2253 /* when we're iconic, don't change the wmstate */
2254 if (!self
->iconic
) {
2257 old
= self
->wmstate
;
2258 self
->wmstate
= shade
? IconicState
: NormalState
;
2259 if (old
!= self
->wmstate
)
2260 PROP_MSG(self
->window
, kde_wm_change_state
,
2261 self
->wmstate
, 1, 0, 0);
2264 self
->shaded
= shade
;
2265 client_change_state(self
);
2266 /* resize the frame to just the titlebar */
2267 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2270 void client_close(ObClient
*self
)
2274 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2277 XXX: itd be cool to do timeouts and shit here for killing the client's
2279 like... if the window is around after 5 seconds, then the close button
2280 turns a nice red, and if this function is called again, the client is
2284 ce
.xclient
.type
= ClientMessage
;
2285 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2286 ce
.xclient
.display
= ob_display
;
2287 ce
.xclient
.window
= self
->window
;
2288 ce
.xclient
.format
= 32;
2289 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2290 ce
.xclient
.data
.l
[1] = event_lasttime
;
2291 ce
.xclient
.data
.l
[2] = 0l;
2292 ce
.xclient
.data
.l
[3] = 0l;
2293 ce
.xclient
.data
.l
[4] = 0l;
2294 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2297 void client_kill(ObClient
*self
)
2299 XKillClient(ob_display
, self
->window
);
2302 void client_set_desktop_recursive(ObClient
*self
,
2303 guint target
, gboolean donthide
)
2308 if (target
!= self
->desktop
) {
2310 ob_debug("Setting desktop %u\n", target
+1);
2312 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2314 /* remove from the old desktop(s) */
2315 focus_order_remove(self
);
2317 old
= self
->desktop
;
2318 self
->desktop
= target
;
2319 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2320 /* the frame can display the current desktop state */
2321 frame_adjust_state(self
->frame
);
2322 /* 'move' the window to the new desktop */
2324 client_showhide(self
);
2325 /* raise if it was not already on the desktop */
2326 if (old
!= DESKTOP_ALL
)
2327 stacking_raise(CLIENT_AS_WINDOW(self
));
2328 screen_update_areas();
2330 /* add to the new desktop(s) */
2331 if (config_focus_new
)
2332 focus_order_to_top(self
);
2334 focus_order_to_bottom(self
);
2337 /* move all transients */
2338 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2339 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2343 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2345 client_set_desktop_recursive(client_search_top_transient(self
),
2349 ObClient
*client_search_modal_child(ObClient
*self
)
2354 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2355 ObClient
*c
= it
->data
;
2356 if ((ret
= client_search_modal_child(c
))) return ret
;
2357 if (c
->modal
) return c
;
2362 gboolean
client_validate(ObClient
*self
)
2366 XSync(ob_display
, FALSE
); /* get all events on the server */
2368 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2369 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2370 XPutBackEvent(ob_display
, &e
);
2377 void client_set_wm_state(ObClient
*self
, long state
)
2379 if (state
== self
->wmstate
) return; /* no change */
2383 client_iconify(self
, TRUE
, TRUE
);
2386 client_iconify(self
, FALSE
, TRUE
);
2391 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2393 gboolean shaded
= self
->shaded
;
2394 gboolean fullscreen
= self
->fullscreen
;
2395 gboolean max_horz
= self
->max_horz
;
2396 gboolean max_vert
= self
->max_vert
;
2399 if (!(action
== prop_atoms
.net_wm_state_add
||
2400 action
== prop_atoms
.net_wm_state_remove
||
2401 action
== prop_atoms
.net_wm_state_toggle
))
2402 /* an invalid action was passed to the client message, ignore it */
2405 for (i
= 0; i
< 2; ++i
) {
2406 Atom state
= i
== 0 ? data1
: data2
;
2408 if (!state
) continue;
2410 /* if toggling, then pick whether we're adding or removing */
2411 if (action
== prop_atoms
.net_wm_state_toggle
) {
2412 if (state
== prop_atoms
.net_wm_state_modal
)
2413 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2414 prop_atoms
.net_wm_state_add
;
2415 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2416 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2417 prop_atoms
.net_wm_state_add
;
2418 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2419 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2420 prop_atoms
.net_wm_state_add
;
2421 else if (state
== prop_atoms
.net_wm_state_shaded
)
2422 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2423 prop_atoms
.net_wm_state_add
;
2424 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2425 action
= self
->skip_taskbar
?
2426 prop_atoms
.net_wm_state_remove
:
2427 prop_atoms
.net_wm_state_add
;
2428 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2429 action
= self
->skip_pager
?
2430 prop_atoms
.net_wm_state_remove
:
2431 prop_atoms
.net_wm_state_add
;
2432 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2433 action
= self
->fullscreen
?
2434 prop_atoms
.net_wm_state_remove
:
2435 prop_atoms
.net_wm_state_add
;
2436 else if (state
== prop_atoms
.net_wm_state_above
)
2437 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2438 prop_atoms
.net_wm_state_add
;
2439 else if (state
== prop_atoms
.net_wm_state_below
)
2440 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2441 prop_atoms
.net_wm_state_add
;
2444 if (action
== prop_atoms
.net_wm_state_add
) {
2445 if (state
== prop_atoms
.net_wm_state_modal
) {
2446 /* XXX raise here or something? */
2448 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2450 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2452 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2454 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2455 self
->skip_taskbar
= TRUE
;
2456 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2457 self
->skip_pager
= TRUE
;
2458 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2460 } else if (state
== prop_atoms
.net_wm_state_above
) {
2462 } else if (state
== prop_atoms
.net_wm_state_below
) {
2466 } else { /* action == prop_atoms.net_wm_state_remove */
2467 if (state
== prop_atoms
.net_wm_state_modal
) {
2468 self
->modal
= FALSE
;
2469 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2471 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2473 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2475 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2476 self
->skip_taskbar
= FALSE
;
2477 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2478 self
->skip_pager
= FALSE
;
2479 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2481 } else if (state
== prop_atoms
.net_wm_state_above
) {
2482 self
->above
= FALSE
;
2483 } else if (state
== prop_atoms
.net_wm_state_below
) {
2484 self
->below
= FALSE
;
2488 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2489 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2491 if (max_horz
== max_vert
) { /* both going the same way */
2492 client_maximize(self
, max_horz
, 0, TRUE
);
2494 client_maximize(self
, max_horz
, 1, TRUE
);
2495 client_maximize(self
, max_vert
, 2, TRUE
);
2499 if (max_horz
!= self
->max_horz
)
2500 client_maximize(self
, max_horz
, 1, TRUE
);
2502 client_maximize(self
, max_vert
, 2, TRUE
);
2505 /* change fullscreen state before shading, as it will affect if the window
2507 if (fullscreen
!= self
->fullscreen
)
2508 client_fullscreen(self
, fullscreen
, TRUE
);
2509 if (shaded
!= self
->shaded
)
2510 client_shade(self
, shaded
);
2511 client_calc_layer(self
);
2512 client_change_state(self
); /* change the hint to reflect these changes */
2515 ObClient
*client_focus_target(ObClient
*self
)
2519 /* if we have a modal child, then focus it, not us */
2520 child
= client_search_modal_child(self
);
2521 if (child
) return child
;
2525 gboolean
client_can_focus(ObClient
*self
)
2529 /* choose the correct target */
2530 self
= client_focus_target(self
);
2532 if (!self
->frame
->visible
)
2535 if (!((self
->can_focus
|| self
->focus_notify
) &&
2536 (self
->desktop
== screen_desktop
||
2537 self
->desktop
== DESKTOP_ALL
) &&
2541 /* do a check to see if the window has already been unmapped or destroyed
2542 do this intelligently while watching out for unmaps we've generated
2543 (ignore_unmaps > 0) */
2544 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2545 DestroyNotify
, &ev
)) {
2546 XPutBackEvent(ob_display
, &ev
);
2549 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2550 UnmapNotify
, &ev
)) {
2551 if (self
->ignore_unmaps
) {
2552 self
->ignore_unmaps
--;
2554 XPutBackEvent(ob_display
, &ev
);
2562 gboolean
client_focus(ObClient
*self
)
2564 /* choose the correct target */
2565 self
= client_focus_target(self
);
2567 if (!client_can_focus(self
)) {
2568 if (!self
->frame
->visible
) {
2569 /* update the focus lists */
2570 focus_order_to_top(self
);
2575 if (self
->can_focus
) {
2576 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2577 I choose to use it always, hopefully to find errors quicker, if any
2578 are left. (I hate X. I hate focus events.)
2580 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2581 #799. So now it is RevertToNone again.
2583 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2587 if (self
->focus_notify
) {
2589 ce
.xclient
.type
= ClientMessage
;
2590 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2591 ce
.xclient
.display
= ob_display
;
2592 ce
.xclient
.window
= self
->window
;
2593 ce
.xclient
.format
= 32;
2594 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2595 ce
.xclient
.data
.l
[1] = event_lasttime
;
2596 ce
.xclient
.data
.l
[2] = 0l;
2597 ce
.xclient
.data
.l
[3] = 0l;
2598 ce
.xclient
.data
.l
[4] = 0l;
2599 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2603 ob_debug("%sively focusing %lx at %d\n",
2604 (self
->can_focus
? "act" : "pass"),
2605 self
->window
, (int) event_lasttime
);
2608 /* Cause the FocusIn to come back to us. Important for desktop switches,
2609 since otherwise we'll have no FocusIn on the queue and send it off to
2610 the focus_backup. */
2611 XSync(ob_display
, FALSE
);
2615 void client_unfocus(ObClient
*self
)
2617 if (focus_client
== self
) {
2619 ob_debug("client_unfocus for %lx\n", self
->window
);
2621 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2625 void client_activate(ObClient
*self
, gboolean here
)
2627 if (client_normal(self
) && screen_showing_desktop
)
2628 screen_show_desktop(FALSE
);
2630 client_iconify(self
, FALSE
, FALSE
);
2631 if (self
->desktop
!= DESKTOP_ALL
&&
2632 self
->desktop
!= screen_desktop
) {
2634 client_set_desktop(self
, screen_desktop
, FALSE
);
2636 screen_set_desktop(self
->desktop
);
2637 } else if (!self
->frame
->visible
)
2638 /* if its not visible for other reasons, then don't mess
2642 client_shade(self
, FALSE
);
2644 stacking_raise(CLIENT_AS_WINDOW(self
));
2647 gboolean
client_focused(ObClient
*self
)
2649 return self
== focus_client
;
2652 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2655 /* si is the smallest image >= req */
2656 /* li is the largest image < req */
2657 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2659 for (i
= 0; i
< self
->nicons
; ++i
) {
2660 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2661 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2665 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2670 if (largest
== 0) /* didnt find one smaller than the requested size */
2671 return &self
->icons
[si
];
2672 return &self
->icons
[li
];
2675 /* this be mostly ripped from fvwm */
2676 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2678 int my_cx
, my_cy
, his_cx
, his_cy
;
2681 int score
, best_score
;
2682 ObClient
*best_client
, *cur
;
2688 /* first, find the centre coords of the currently focused window */
2689 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2690 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2695 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2698 /* the currently selected window isn't interesting */
2701 if (!client_normal(cur
))
2703 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2707 if(client_focus_target(cur
) == cur
&&
2708 !(cur
->can_focus
|| cur
->focus_notify
))
2711 /* find the centre coords of this window, from the
2712 * currently focused window's point of view */
2713 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2714 + cur
->frame
->area
.width
/ 2;
2715 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2716 + cur
->frame
->area
.height
/ 2;
2718 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2719 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2721 /* Rotate the diagonals 45 degrees counterclockwise.
2722 * To do this, multiply the matrix /+h +h\ with the
2723 * vector (x y). \-h +h/
2724 * h = sqrt(0.5). We can set h := 1 since absolute
2725 * distance doesn't matter here. */
2726 tx
= his_cx
+ his_cy
;
2727 his_cy
= -his_cx
+ his_cy
;
2732 case OB_DIRECTION_NORTH
:
2733 case OB_DIRECTION_SOUTH
:
2734 case OB_DIRECTION_NORTHEAST
:
2735 case OB_DIRECTION_SOUTHWEST
:
2736 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2737 distance
= ((dir
== OB_DIRECTION_NORTH
||
2738 dir
== OB_DIRECTION_NORTHEAST
) ?
2741 case OB_DIRECTION_EAST
:
2742 case OB_DIRECTION_WEST
:
2743 case OB_DIRECTION_SOUTHEAST
:
2744 case OB_DIRECTION_NORTHWEST
:
2745 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2746 distance
= ((dir
== OB_DIRECTION_WEST
||
2747 dir
== OB_DIRECTION_NORTHWEST
) ?
2752 /* the target must be in the requested direction */
2756 /* Calculate score for this window. The smaller the better. */
2757 score
= distance
+ offset
;
2759 /* windows more than 45 degrees off the direction are
2760 * heavily penalized and will only be chosen if nothing
2761 * else within a million pixels */
2762 if(offset
> distance
)
2765 if(best_score
== -1 || score
< best_score
)
2773 void client_set_layer(ObClient
*self
, int layer
)
2777 self
->above
= FALSE
;
2778 } else if (layer
== 0) {
2779 self
->below
= self
->above
= FALSE
;
2781 self
->below
= FALSE
;
2784 client_calc_layer(self
);
2785 client_change_state(self
); /* reflect this in the state hints */
2788 guint
client_monitor(ObClient
*self
)
2792 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2793 Rect
*area
= screen_physical_area_monitor(i
);
2794 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2797 if (i
== screen_num_monitors
) i
= 0;
2798 g_assert(i
< screen_num_monitors
);
2802 ObClient
*client_search_top_transient(ObClient
*self
)
2804 /* move up the transient chain as far as possible */
2805 if (self
->transient_for
) {
2806 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2807 return client_search_top_transient(self
->transient_for
);
2811 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2812 ObClient
*c
= it
->data
;
2814 /* checking transient_for prevents infinate loops! */
2815 if (c
!= self
&& !c
->transient_for
)
2826 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2830 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2831 if (sit
->data
== search
)
2833 if (client_search_transient(sit
->data
, search
))
2839 void client_update_sm_client_id(ObClient
*self
)
2841 g_free(self
->sm_client_id
);
2842 self
->sm_client_id
= NULL
;
2844 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
) &&
2846 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
,
2847 &self
->sm_client_id
);
2850 /* finds the nearest edge in the given direction from the current client
2851 * note to self: the edge is the -frame- edge (the actual one), not the
2854 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
2857 int my_edge_start
, my_edge_end
, my_offset
;
2864 a
= screen_area(c
->desktop
);
2867 case OB_DIRECTION_NORTH
:
2868 my_edge_start
= c
->frame
->area
.x
;
2869 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2870 my_offset
= c
->frame
->area
.y
;
2872 dest
= a
->y
; /* default: top of screen */
2874 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2875 int his_edge_start
, his_edge_end
, his_offset
;
2876 ObClient
*cur
= it
->data
;
2880 if(!client_normal(cur
))
2882 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2887 his_edge_start
= cur
->frame
->area
.x
;
2888 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2889 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2891 if(his_offset
+ 1 > my_offset
)
2894 if(his_offset
< dest
)
2897 if(his_edge_start
>= my_edge_start
&&
2898 his_edge_start
<= my_edge_end
)
2901 if(my_edge_start
>= his_edge_start
&&
2902 my_edge_start
<= his_edge_end
)
2907 case OB_DIRECTION_SOUTH
:
2908 my_edge_start
= c
->frame
->area
.x
;
2909 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2910 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2912 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
2914 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2915 int his_edge_start
, his_edge_end
, his_offset
;
2916 ObClient
*cur
= it
->data
;
2920 if(!client_normal(cur
))
2922 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2927 his_edge_start
= cur
->frame
->area
.x
;
2928 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2929 his_offset
= cur
->frame
->area
.y
;
2932 if(his_offset
- 1 < my_offset
)
2935 if(his_offset
> dest
)
2938 if(his_edge_start
>= my_edge_start
&&
2939 his_edge_start
<= my_edge_end
)
2942 if(my_edge_start
>= his_edge_start
&&
2943 my_edge_start
<= his_edge_end
)
2948 case OB_DIRECTION_WEST
:
2949 my_edge_start
= c
->frame
->area
.y
;
2950 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2951 my_offset
= c
->frame
->area
.x
;
2953 dest
= a
->x
; /* default: leftmost egde of screen */
2955 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2956 int his_edge_start
, his_edge_end
, his_offset
;
2957 ObClient
*cur
= it
->data
;
2961 if(!client_normal(cur
))
2963 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2968 his_edge_start
= cur
->frame
->area
.y
;
2969 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2970 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2972 if(his_offset
+ 1 > my_offset
)
2975 if(his_offset
< dest
)
2978 if(his_edge_start
>= my_edge_start
&&
2979 his_edge_start
<= my_edge_end
)
2982 if(my_edge_start
>= his_edge_start
&&
2983 my_edge_start
<= his_edge_end
)
2989 case OB_DIRECTION_EAST
:
2990 my_edge_start
= c
->frame
->area
.y
;
2991 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2992 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2994 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
2996 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2997 int his_edge_start
, his_edge_end
, his_offset
;
2998 ObClient
*cur
= it
->data
;
3002 if(!client_normal(cur
))
3004 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
3009 his_edge_start
= cur
->frame
->area
.y
;
3010 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3011 his_offset
= cur
->frame
->area
.x
;
3013 if(his_offset
- 1 < my_offset
)
3016 if(his_offset
> dest
)
3019 if(his_edge_start
>= my_edge_start
&&
3020 his_edge_start
<= my_edge_end
)
3023 if(my_edge_start
>= his_edge_start
&&
3024 my_edge_start
<= his_edge_end
)
3029 case OB_DIRECTION_NORTHEAST
:
3030 case OB_DIRECTION_SOUTHEAST
:
3031 case OB_DIRECTION_NORTHWEST
:
3032 case OB_DIRECTION_SOUTHWEST
:
3033 /* not implemented */
3036 g_assert_not_reached();
3041 ObClient
* client_under_pointer()
3045 ObClient
*ret
= NULL
;
3047 if (screen_pointer_pos(&x
, &y
)) {
3048 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
3049 if (WINDOW_IS_CLIENT(it
->data
)) {
3050 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
3051 if (c
->desktop
== screen_desktop
&&
3052 RECT_CONTAINS(c
->frame
->area
, x
, y
)) {