3 #include "moveresize.h"
5 #include "extensions.h"
17 #include <X11/Xutil.h>
19 /*! The event mask to grab on client windows */
20 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
23 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
26 GList
*client_list
= NULL
;
27 GHashTable
*client_map
= NULL
;
29 static Window
*client_startup_stack_order
= NULL
;
30 static guint client_startup_stack_size
= 0;
32 static void client_get_all(Client
*self
);
33 static void client_toggle_border(Client
*self
, gboolean show
);
34 static void client_get_area(Client
*self
);
35 static void client_get_desktop(Client
*self
);
36 static void client_get_state(Client
*self
);
37 static void client_get_shaped(Client
*self
);
38 static void client_get_mwm_hints(Client
*self
);
39 static void client_get_gravity(Client
*self
);
40 static void client_showhide(Client
*self
);
41 static void client_change_allowed_actions(Client
*self
);
42 static void client_change_state(Client
*self
);
43 static void client_move_onscreen(Client
*self
);
44 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
45 static void client_apply_startup_state(Client
*self
);
46 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
48 static guint
map_hash(Window
*w
) { return *w
; }
49 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
53 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
54 (GEqualFunc
)map_key_comp
);
56 /* save the stacking order on startup! */
57 PROP_GETA32(ob_root
, net_client_list_stacking
, window
,
58 (guint32
**)&client_startup_stack_order
,
59 &client_startup_stack_size
);
64 void client_shutdown()
66 g_hash_table_destroy(client_map
);
69 void client_set_list()
71 Window
*windows
, *win_it
;
73 guint size
= g_list_length(client_list
);
75 /* create an array of the window ids */
77 windows
= g_new(Window
, size
);
79 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
80 *win_it
= ((Client
*)it
->data
)->window
;
84 PROP_SETA32(ob_root
, net_client_list
, window
, (guint32
*)windows
, size
);
92 void client_manage_all()
94 unsigned int i
, j
, nchild
;
97 XWindowAttributes attrib
;
99 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
101 /* remove all icon windows from the list */
102 for (i
= 0; i
< nchild
; i
++) {
103 if (children
[i
] == None
) continue;
104 wmhints
= XGetWMHints(ob_display
, children
[i
]);
106 if ((wmhints
->flags
& IconWindowHint
) &&
107 (wmhints
->icon_window
!= children
[i
]))
108 for (j
= 0; j
< nchild
; j
++)
109 if (children
[j
] == wmhints
->icon_window
) {
117 for (i
= 0; i
< nchild
; ++i
) {
118 if (children
[i
] == None
)
120 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
121 if (attrib
.override_redirect
) continue;
123 if (attrib
.map_state
!= IsUnmapped
)
124 client_manage(children
[i
]);
129 /* stack them as they were on startup!
130 why with stacking_lower? Why, because then windows who aren't in the
131 stacking list are on the top where you can see them instead of buried
133 for (i
= client_startup_stack_size
; i
> 0; --i
) {
136 w
= client_startup_stack_order
[i
-1];
137 c
= g_hash_table_lookup(client_map
, &w
);
138 if (c
) stacking_lower(c
);
140 g_free(client_startup_stack_order
);
141 client_startup_stack_order
= NULL
;
142 client_startup_stack_size
= 0;
144 if (config_focus_new
)
145 focus_fallback(Fallback_NoFocus
);
148 void client_manage(Window window
)
152 XWindowAttributes attrib
;
153 XSetWindowAttributes attrib_set
;
154 /* XWMHints *wmhint; */
159 /* check if it has already been unmapped by the time we started mapping
160 the grab does a sync so we don't have to here */
161 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
162 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
163 XPutBackEvent(ob_display
, &e
);
166 return; /* don't manage it */
169 /* make sure it isn't an override-redirect window */
170 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
171 attrib
.override_redirect
) {
173 return; /* don't manage it */
176 /* /\* is the window a docking app *\/
177 if ((wmhint = XGetWMHints(ob_display, window))) {
178 if ((wmhint->flags & StateHint) &&
179 wmhint->initial_state == WithdrawnState) {
180 /\* XXX: make dock apps work! *\/
188 g_message("Managing window: %lx", window
);
190 /* choose the events we want to receive on the CLIENT window */
191 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
192 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
193 XChangeWindowAttributes(ob_display
, window
,
194 CWEventMask
|CWDontPropagate
, &attrib_set
);
197 /* create the Client struct, and populate it from the hints on the
199 self
= g_new(Client
, 1);
200 self
->window
= window
;
201 client_get_all(self
);
203 /* remove the client's border (and adjust re gravity) */
204 client_toggle_border(self
, FALSE
);
206 /* specify that if we exit, the window should not be destroyed and should
207 be reparented back to root automatically */
208 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
210 /* create the decoration frame for the client window */
211 self
->frame
= frame_new();
213 frame_grab_client(self
->frame
, self
);
215 client_apply_startup_state(self
);
219 client_list
= g_list_append(client_list
, self
);
220 stacking_list
= g_list_append(stacking_list
, self
);
221 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
222 g_hash_table_insert(client_map
, &self
->window
, self
);
224 /* update the focus lists */
225 if (self
->desktop
== DESKTOP_ALL
) {
226 for (i
= 0; i
< screen_num_desktops
; ++i
)
227 focus_order
[i
] = g_list_insert(focus_order
[i
], self
, 1);
230 focus_order
[i
] = g_list_insert(focus_order
[i
], self
, 1);
233 stacking_raise(self
);
235 screen_update_struts();
237 dispatch_client(Event_Client_New
, self
, 0, 0);
239 client_showhide(self
);
241 /* focus the new window? */
242 if (ob_state
!= State_Starting
) {
244 gboolean group_foc
= FALSE
;
251 for (it
= self
->group
->members
; it
; it
= it
->next
)
252 if (client_focused(it
->data
)) {
257 if (!group_foc
&& self
->transient_for
) {
258 if (self
->transient_for
!= TRAN_GROUP
) {/* transient of a window */
259 parent
= self
->transient_for
;
260 } else { /* transient of a group */
263 for (it
= self
->group
->members
; it
; it
= it
->next
)
264 if (it
->data
!= self
&&
265 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
)
269 /* note the check against Type_Normal, not client_normal(self), which
270 would also include dialog types. in this case we want more strict
272 if ((config_focus_new
&&
273 (self
->type
== Type_Normal
||
274 (self
->type
== Type_Dialog
&&
276 (!parent
&& (!self
->group
||
277 !self
->group
->members
->next
)))))) ||
278 (parent
&& (client_focused(parent
) ||
279 search_focus_tree(parent
, parent
)))) {
284 /* update the list hints */
287 /* make sure the window is visible */
288 client_move_onscreen(self
);
290 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
292 g_message("Managed window 0x%lx", window
);
295 void client_unmanage_all()
297 while (client_list
!= NULL
)
298 client_unmanage(client_list
->data
);
301 void client_unmanage(Client
*self
)
307 g_message("Unmanaging window: %lx", self
->window
);
309 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
310 g_assert(self
!= NULL
);
312 /* remove the window from our save set */
313 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
315 /* we dont want events no more */
316 XSelectInput(ob_display
, self
->window
, NoEventMask
);
318 frame_hide(self
->frame
);
320 client_list
= g_list_remove(client_list
, self
);
321 stacking_list
= g_list_remove(stacking_list
, self
);
322 g_hash_table_remove(client_map
, &self
->window
);
324 /* update the focus lists */
325 if (self
->desktop
== DESKTOP_ALL
) {
326 for (i
= 0; i
< screen_num_desktops
; ++i
)
327 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
330 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
333 /* once the client is out of the list, update the struts to remove it's
335 screen_update_struts();
337 /* tell our parent(s) that we're gone */
338 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
341 for (it
= self
->group
->members
; it
; it
= it
->next
)
342 if (it
->data
!= self
)
343 ((Client
*)it
->data
)->transients
=
344 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
345 } else if (self
->transient_for
) { /* transient of window */
346 self
->transient_for
->transients
=
347 g_slist_remove(self
->transient_for
->transients
, self
);
350 /* tell our transients that we're gone */
351 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
352 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
353 ((Client
*)it
->data
)->transient_for
= NULL
;
354 client_calc_layer(it
->data
);
358 if (moveresize_client
== self
)
359 moveresize_end(TRUE
);
361 if (focus_client
== self
) {
364 /* focus the last focused window on the desktop, and ignore enter
365 events from the unmap so it doesnt mess with the focus */
366 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
367 client_unfocus(self
);
370 /* remove from its group */
372 group_remove(self
->group
, self
);
376 /* dispatch the unmapped event */
377 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
378 g_assert(self
!= NULL
);
380 /* give the client its border back */
381 client_toggle_border(self
, TRUE
);
383 /* reparent the window out of the frame, and free the frame */
384 frame_release_client(self
->frame
, self
);
387 if (ob_state
!= State_Exiting
) {
388 /* these values should not be persisted across a window
390 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
391 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
393 /* if we're left in an iconic state, the client wont be mapped. this is
394 bad, since we will no longer be managing the window on restart */
396 XMapWindow(ob_display
, self
->window
);
400 g_message("Unmanaged window 0x%lx", self
->window
);
402 /* free all data allocated in the client struct */
403 g_slist_free(self
->transients
);
404 for (j
= 0; j
< self
->nicons
; ++j
)
405 g_free(self
->icons
[j
].data
);
406 if (self
->nicons
> 0)
409 g_free(self
->icon_title
);
415 /* update the list hints */
419 static void client_move_onscreen(Client
*self
)
422 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
424 a
= screen_area(self
->desktop
);
425 if (x
>= a
->x
+ a
->width
- 1)
426 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
427 if (y
>= a
->y
+ a
->height
- 1)
428 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
429 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
431 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
434 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
436 client_configure(self
, Corner_TopLeft
, x
, y
,
437 self
->area
.width
, self
->area
.height
,
441 static void client_toggle_border(Client
*self
, gboolean show
)
443 /* adjust our idea of where the client is, based on its border. When the
444 border is removed, the client should now be considered to be in a
446 when re-adding the border to the client, the same operation needs to be
448 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
449 int x
= oldx
, y
= oldy
;
450 switch(self
->gravity
) {
452 case NorthWestGravity
:
454 case SouthWestGravity
:
456 case NorthEastGravity
:
458 case SouthEastGravity
:
459 if (show
) x
-= self
->border_width
* 2;
460 else x
+= self
->border_width
* 2;
467 if (show
) x
-= self
->border_width
;
468 else x
+= self
->border_width
;
471 switch(self
->gravity
) {
473 case NorthWestGravity
:
475 case NorthEastGravity
:
477 case SouthWestGravity
:
479 case SouthEastGravity
:
480 if (show
) y
-= self
->border_width
* 2;
481 else y
+= self
->border_width
* 2;
488 if (show
) y
-= self
->border_width
;
489 else y
+= self
->border_width
;
496 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
498 /* move the client so it is back it the right spot _with_ its
500 if (x
!= oldx
|| y
!= oldy
)
501 XMoveWindow(ob_display
, self
->window
, x
, y
);
503 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
507 static void client_get_all(Client
*self
)
509 /* update EVERYTHING!! */
511 self
->ignore_unmaps
= 0;
515 self
->title
= self
->icon_title
= NULL
;
516 self
->name
= self
->class = self
->role
= NULL
;
517 self
->wmstate
= NormalState
;
518 self
->transient
= FALSE
;
519 self
->transients
= NULL
;
520 self
->transient_for
= NULL
;
522 self
->urgent
= FALSE
;
523 self
->positioned
= FALSE
;
524 self
->disabled_decorations
= 0;
528 client_get_area(self
);
529 client_update_transient_for(self
);
530 client_update_wmhints(self
);
531 client_get_desktop(self
);
532 client_get_state(self
);
533 client_get_shaped(self
);
535 client_get_mwm_hints(self
);
536 client_get_type(self
);/* this can change the mwmhints for special cases */
538 client_update_protocols(self
);
540 client_get_gravity(self
); /* get the attribute gravity */
541 client_update_normal_hints(self
); /* this may override the attribute
544 /* got the type, the mwmhints, the protocols, and the normal hints
545 (min/max sizes), so we're ready to set up the decorations/functions */
546 client_setup_decor_and_functions(self
);
548 client_update_title(self
);
549 client_update_icon_title(self
);
550 client_update_class(self
);
551 client_update_strut(self
);
552 client_update_icons(self
);
553 client_update_kwm_icon(self
);
555 client_change_state(self
);
558 static void client_get_area(Client
*self
)
560 XWindowAttributes wattrib
;
563 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
564 g_assert(ret
!= BadWindow
);
566 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
567 self
->border_width
= wattrib
.border_width
;
570 static void client_get_desktop(Client
*self
)
574 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
575 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
576 d
= screen_num_desktops
- 1;
579 gboolean trdesk
= FALSE
;
581 if (self
->transient_for
) {
582 if (self
->transient_for
!= TRAN_GROUP
) {
583 self
->desktop
= self
->transient_for
->desktop
;
588 for (it
= self
->group
->members
; it
; it
= it
->next
)
589 if (it
->data
!= self
&&
590 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
591 self
->desktop
= ((Client
*)it
->data
)->desktop
;
598 /* defaults to the current desktop */
599 self
->desktop
= screen_desktop
;
601 /* set the desktop hint, to make sure that it always exists */
602 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
606 static void client_get_state(Client
*self
)
611 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
612 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
613 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
615 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
617 for (i
= 0; i
< num
; ++i
) {
618 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
620 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
622 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
624 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
625 self
->skip_taskbar
= TRUE
;
626 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
627 self
->skip_pager
= TRUE
;
628 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
629 self
->fullscreen
= TRUE
;
630 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
631 self
->max_vert
= TRUE
;
632 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
633 self
->max_horz
= TRUE
;
634 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
636 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
644 static void client_get_shaped(Client
*self
)
646 self
->shaped
= FALSE
;
648 if (extensions_shape
) {
653 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
655 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
656 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
658 self
->shaped
= (s
!= 0);
663 void client_update_transient_for(Client
*self
)
668 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
669 self
->transient
= TRUE
;
670 if (t
!= self
->window
) { /* cant be transient to itself! */
671 c
= g_hash_table_lookup(client_map
, &t
);
672 /* if this happens then we need to check for it*/
675 if (!c
&& self
->group
) {
676 /* not transient to a client, see if it is transient for a
678 if (t
== self
->group
->leader
||
681 /* window is a transient for its group! */
687 self
->transient
= FALSE
;
689 /* if anything has changed... */
690 if (c
!= self
->transient_for
) {
691 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
694 /* remove from old parents */
695 for (it
= self
->group
->members
; it
; it
= it
->next
)
696 if (it
->data
!= self
&&
697 (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
))
698 ((Client
*)it
->data
)->transients
=
699 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
700 } else if (self
->transient_for
!= NULL
) { /* transient of window */
701 /* remove from old parent */
702 self
->transient_for
->transients
=
703 g_slist_remove(self
->transient_for
->transients
, self
);
705 self
->transient_for
= c
;
706 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
709 /* add to new parents */
710 for (it
= self
->group
->members
; it
; it
= it
->next
)
711 if (it
->data
!= self
&&
712 (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
))
713 ((Client
*)it
->data
)->transients
=
714 g_slist_append(((Client
*)it
->data
)->transients
, self
);
716 /* remove all transients which are in the group, that causes
717 circlular pointer hell of doom */
718 for (it
= self
->group
->members
; it
; it
= it
->next
) {
720 for (sit
= self
->transients
; sit
; sit
= next
) {
722 if (sit
->data
== it
->data
)
723 self
->transients
= g_slist_remove(self
->transients
,
727 } else if (self
->transient_for
!= NULL
) { /* transient of window */
728 /* add to new parent */
729 self
->transient_for
->transients
=
730 g_slist_append(self
->transient_for
->transients
, self
);
735 static void client_get_mwm_hints(Client
*self
)
740 self
->mwmhints
.flags
= 0; /* default to none */
742 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
744 if (num
>= MWM_ELEMENTS
) {
745 self
->mwmhints
.flags
= hints
[0];
746 self
->mwmhints
.functions
= hints
[1];
747 self
->mwmhints
.decorations
= hints
[2];
753 void client_get_type(Client
*self
)
760 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
761 /* use the first value that we know about in the array */
762 for (i
= 0; i
< num
; ++i
) {
763 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
764 self
->type
= Type_Desktop
;
765 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
766 self
->type
= Type_Dock
;
767 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
768 self
->type
= Type_Toolbar
;
769 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
770 self
->type
= Type_Menu
;
771 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
772 self
->type
= Type_Utility
;
773 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
774 self
->type
= Type_Splash
;
775 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
776 self
->type
= Type_Dialog
;
777 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
778 self
->type
= Type_Normal
;
779 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
780 /* prevent this window from getting any decor or
782 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
783 MwmFlag_Decorations
);
784 self
->mwmhints
.decorations
= 0;
785 self
->mwmhints
.functions
= 0;
787 if (self
->type
!= (WindowType
) -1)
788 break; /* grab the first legit type */
793 if (self
->type
== (WindowType
) -1) {
794 /*the window type hint was not set, which means we either classify
795 ourself as a normal window or a dialog, depending on if we are a
798 self
->type
= Type_Dialog
;
800 self
->type
= Type_Normal
;
803 /* this makes sure that these windows appear on all desktops */
804 if (self
->type
== Type_Desktop
)
805 self
->desktop
= DESKTOP_ALL
;
808 void client_update_protocols(Client
*self
)
813 self
->focus_notify
= FALSE
;
814 self
->delete_window
= FALSE
;
816 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
817 for (i
= 0; i
< num_return
; ++i
) {
818 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
819 /* this means we can request the window to close */
820 self
->delete_window
= TRUE
;
821 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
822 /* if this protocol is requested, then the window will be
823 notified whenever we want it to receive focus */
824 self
->focus_notify
= TRUE
;
830 static void client_get_gravity(Client
*self
)
832 XWindowAttributes wattrib
;
835 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
836 g_assert(ret
!= BadWindow
);
837 self
->gravity
= wattrib
.win_gravity
;
840 void client_update_normal_hints(Client
*self
)
844 int oldgravity
= self
->gravity
;
847 self
->min_ratio
= 0.0f
;
848 self
->max_ratio
= 0.0f
;
849 SIZE_SET(self
->size_inc
, 1, 1);
850 SIZE_SET(self
->base_size
, 0, 0);
851 SIZE_SET(self
->min_size
, 0, 0);
852 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
854 /* get the hints from the window */
855 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
856 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
858 if (size
.flags
& PWinGravity
) {
859 self
->gravity
= size
.win_gravity
;
861 /* if the client has a frame, i.e. has already been mapped and
862 is changing its gravity */
863 if (self
->frame
&& self
->gravity
!= oldgravity
) {
864 /* move our idea of the client's position based on its new
866 self
->area
.x
= self
->frame
->area
.x
;
867 self
->area
.y
= self
->frame
->area
.y
;
868 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
872 if (size
.flags
& PAspect
) {
873 if (size
.min_aspect
.y
)
874 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
875 if (size
.max_aspect
.y
)
876 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
879 if (size
.flags
& PMinSize
)
880 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
882 if (size
.flags
& PMaxSize
)
883 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
885 if (size
.flags
& PBaseSize
)
886 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
888 if (size
.flags
& PResizeInc
)
889 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
893 void client_setup_decor_and_functions(Client
*self
)
895 /* start with everything (cept fullscreen) */
896 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
897 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
899 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
901 if (self
->delete_window
) {
902 self
->decorations
|= Decor_Close
;
903 self
->functions
|= Func_Close
;
906 if (!(self
->min_size
.width
< self
->max_size
.width
||
907 self
->min_size
.height
< self
->max_size
.height
)) {
908 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
909 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
912 switch (self
->type
) {
914 /* normal windows retain all of the possible decorations and
915 functionality, and are the only windows that you can fullscreen */
916 self
->functions
|= Func_Fullscreen
;
921 /* these windows cannot be maximized */
922 self
->decorations
&= ~Decor_Maximize
;
923 self
->functions
&= ~Func_Maximize
;
928 /* these windows get less functionality */
929 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
930 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
936 /* none of these windows are manipulated by the window manager */
937 self
->decorations
= 0;
942 /* Mwm Hints are applied subtractively to what has already been chosen for
943 decor and functionality */
944 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
945 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
946 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
947 self
->decorations
&= ~Decor_Border
;
948 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
949 self
->decorations
&= ~Decor_Handle
;
950 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
951 self
->decorations
&= ~Decor_Titlebar
;
952 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
953 self
->decorations
&= ~Decor_Iconify
;
954 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
955 self
->decorations
&= ~Decor_Maximize
;
959 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
960 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
961 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
962 self
->functions
&= ~Func_Resize
;
963 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
964 self
->functions
&= ~Func_Move
;
965 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
966 self
->functions
&= ~Func_Iconify
;
967 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
968 self
->functions
&= ~Func_Maximize
;
969 /* dont let mwm hints kill the close button
970 if (! (self->mwmhints.functions & MwmFunc_Close))
971 self->functions &= ~Func_Close; */
975 /* can't maximize without moving/resizing */
976 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
977 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
979 /* finally, user specified disabled decorations are applied to subtract
981 if (self
->disabled_decorations
& Decor_Titlebar
)
982 self
->decorations
&= ~Decor_Titlebar
;
983 if (self
->disabled_decorations
& Decor_Handle
)
984 self
->decorations
&= ~Decor_Handle
;
985 if (self
->disabled_decorations
& Decor_Border
)
986 self
->decorations
&= ~Decor_Border
;
987 if (self
->disabled_decorations
& Decor_Iconify
)
988 self
->decorations
&= ~Decor_Iconify
;
989 if (self
->disabled_decorations
& Decor_Maximize
)
990 self
->decorations
&= ~Decor_Maximize
;
991 if (self
->disabled_decorations
& Decor_AllDesktops
)
992 self
->decorations
&= ~Decor_AllDesktops
;
993 if (self
->disabled_decorations
& Decor_Shade
)
994 self
->decorations
&= ~Decor_Shade
;
995 if (self
->disabled_decorations
& Decor_Close
)
996 self
->decorations
&= ~Decor_Close
;
998 /* if we don't have a titlebar, then we cannot shade! */
999 if (!(self
->decorations
& Decor_Titlebar
))
1000 self
->functions
&= ~Func_Shade
;
1002 /* now we need to check against rules for the client's current state */
1003 if (self
->fullscreen
) {
1004 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
1005 self
->decorations
= 0;
1008 client_change_allowed_actions(self
);
1011 /* change the decors on the frame, and with more/less decorations,
1012 we may also need to be repositioned */
1013 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
1014 /* with new decor, the window's maximized size may change */
1015 client_remaximize(self
);
1019 static void client_change_allowed_actions(Client
*self
)
1024 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1026 if (self
->functions
& Func_Shade
)
1027 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1028 if (self
->functions
& Func_Close
)
1029 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1030 if (self
->functions
& Func_Move
)
1031 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1032 if (self
->functions
& Func_Iconify
)
1033 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1034 if (self
->functions
& Func_Resize
)
1035 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1036 if (self
->functions
& Func_Fullscreen
)
1037 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1038 if (self
->functions
& Func_Maximize
) {
1039 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1040 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1043 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1045 /* make sure the window isn't breaking any rules now */
1047 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1048 if (self
->frame
) client_shade(self
, FALSE
);
1049 else self
->shaded
= FALSE
;
1051 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1052 g_message("UNSETTING ICONIC");
1053 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1054 else self
->iconic
= FALSE
;
1056 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1057 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1058 else self
->fullscreen
= FALSE
;
1060 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1062 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1063 else self
->max_vert
= self
->max_horz
= FALSE
;
1067 void client_remaximize(Client
*self
)
1070 if (self
->max_horz
&& self
->max_vert
)
1072 else if (self
->max_horz
)
1074 else if (self
->max_vert
)
1077 return; /* not maximized */
1078 self
->max_horz
= self
->max_vert
= FALSE
;
1079 client_maximize(self
, TRUE
, dir
, FALSE
);
1082 void client_update_wmhints(Client
*self
)
1085 gboolean ur
= FALSE
;
1088 /* assume a window takes input if it doesnt specify */
1089 self
->can_focus
= TRUE
;
1091 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1092 if (hints
->flags
& InputHint
)
1093 self
->can_focus
= hints
->input
;
1095 /* only do this when first managing the window *AND* when we aren't
1097 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1098 if (hints
->flags
& StateHint
)
1099 self
->iconic
= hints
->initial_state
== IconicState
;
1101 if (hints
->flags
& XUrgencyHint
)
1104 if (!(hints
->flags
& WindowGroupHint
))
1105 hints
->window_group
= None
;
1107 /* did the group state change? */
1108 if (hints
->window_group
!=
1109 (self
->group
? self
->group
->leader
: None
)) {
1110 /* remove from the old group if there was one */
1111 if (self
->group
!= NULL
) {
1112 /* remove transients of the group */
1113 for (it
= self
->group
->members
; it
; it
= it
->next
)
1114 if (it
->data
!= self
&&
1115 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
) {
1116 self
->transients
= g_slist_remove(self
->transients
,
1119 group_remove(self
->group
, self
);
1122 if (hints
->window_group
!= None
) {
1123 self
->group
= group_add(hints
->window_group
, self
);
1125 /* add other transients of the group that are already
1127 for (it
= self
->group
->members
; it
; it
= it
->next
)
1128 if (it
->data
!= self
&&
1129 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1130 self
->transients
= g_slist_append(self
->transients
,
1134 /* because the self->transient flag wont change from this call,
1135 we don't need to update the window's type and such, only its
1136 transient_for, and the transients lists of other windows in
1137 the group may be affected */
1138 client_update_transient_for(self
);
1141 client_update_kwm_icon(self
);
1142 /* try get the kwm icon first, this is a fallback only */
1143 if (self
->pixmap_icon
== None
) {
1144 if (hints
->flags
& IconPixmapHint
) {
1145 if (self
->pixmap_icon
== None
) {
1146 self
->pixmap_icon
= hints
->icon_pixmap
;
1147 if (hints
->flags
& IconMaskHint
)
1148 self
->pixmap_icon_mask
= hints
->icon_mask
;
1150 self
->pixmap_icon_mask
= None
;
1153 frame_adjust_icon(self
->frame
);
1161 if (ur
!= self
->urgent
) {
1163 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1165 /* fire the urgent callback if we're mapped, otherwise, wait until
1166 after we're mapped */
1168 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1172 void client_update_title(Client
*self
)
1176 g_free(self
->title
);
1179 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1180 /* try old x stuff */
1181 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1182 data
= g_strdup("Unnamed Window");
1184 /* look for duplicates and append a number */
1186 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1191 frame_adjust_title(self
->frame
);
1194 void client_update_icon_title(Client
*self
)
1198 g_free(self
->icon_title
);
1201 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1202 /* try old x stuff */
1203 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
))
1204 data
= g_strdup("Unnamed Window");
1206 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1208 self
->icon_title
= data
;
1211 void client_update_class(Client
*self
)
1216 if (self
->name
) g_free(self
->name
);
1217 if (self
->class) g_free(self
->class);
1218 if (self
->role
) g_free(self
->role
);
1220 self
->name
= self
->class = self
->role
= NULL
;
1222 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1224 self
->name
= g_strdup(data
[0]);
1226 self
->class = g_strdup(data
[1]);
1231 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1232 self
->role
= g_strdup(s
);
1234 if (self
->name
== NULL
) self
->name
= g_strdup("");
1235 if (self
->class == NULL
) self
->class = g_strdup("");
1236 if (self
->role
== NULL
) self
->role
= g_strdup("");
1239 void client_update_strut(Client
*self
)
1244 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1245 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1248 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1250 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1254 /* updating here is pointless while we're being mapped cuz we're not in
1255 the client list yet */
1257 screen_update_struts();
1260 void client_update_icons(Client
*self
)
1267 for (j
= 0; j
< self
->nicons
; ++j
)
1268 g_free(self
->icons
[j
].data
);
1269 if (self
->nicons
> 0)
1270 g_free(self
->icons
);
1273 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1274 /* figure out how many valid icons are in here */
1276 while (num
- i
> 2) {
1284 self
->icons
= g_new(Icon
, self
->nicons
);
1286 /* store the icons */
1288 for (j
= 0; j
< self
->nicons
; ++j
) {
1289 w
= self
->icons
[j
].width
= data
[i
++];
1290 h
= self
->icons
[j
].height
= data
[i
++];
1291 self
->icons
[j
].data
=
1292 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1301 frame_adjust_icon(self
->frame
);
1304 void client_update_kwm_icon(Client
*self
)
1309 if (!PROP_GETA32(self
->window
, kwm_win_icon
, kwm_win_icon
, &data
, &num
)) {
1310 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1313 self
->pixmap_icon
= data
[0];
1314 self
->pixmap_icon_mask
= data
[1];
1316 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1320 frame_adjust_icon(self
->frame
);
1323 static void client_change_state(Client
*self
)
1326 guint32 netstate
[10];
1329 state
[0] = self
->wmstate
;
1331 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1335 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1337 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1339 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1340 if (self
->skip_taskbar
)
1341 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1342 if (self
->skip_pager
)
1343 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1344 if (self
->fullscreen
)
1345 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1347 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1349 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1351 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1353 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1354 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1356 client_calc_layer(self
);
1359 frame_adjust_state(self
->frame
);
1362 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1367 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1368 Client
*c
= it
->data
;
1369 if (c
== skip
) continue; /* circular? */
1370 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1371 if (client_focused(c
)) return c
;
1376 static void calc_recursive(Client
*self
, StackLayer l
, gboolean raised
)
1384 for (it
= self
->transients
; it
; it
= it
->next
)
1385 calc_recursive(it
->data
, l
, raised
? raised
: l
!= old
);
1387 if (!raised
&& l
!= old
)
1389 stacking_raise(self
);
1392 void client_calc_layer(Client
*self
)
1397 /* transients take on the layer of their parents */
1398 if (self
->transient_for
) {
1399 if (self
->transient_for
!= TRAN_GROUP
) {
1400 self
= self
->transient_for
;
1404 for (it
= self
->group
->members
; it
; it
= it
->next
)
1405 if (it
->data
!= self
&&
1406 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1413 /* is us or one of our transients focused? */
1414 if (client_focused(self
))
1416 else if (search_focus_tree(self
, self
))
1421 if (self
->iconic
) l
= Layer_Icon
;
1422 /* fullscreen windows are only in the fullscreen layer while focused */
1423 else if (self
->fullscreen
&& f
) l
= Layer_Fullscreen
;
1424 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1425 else if (self
->type
== Type_Dock
) {
1426 if (!self
->below
) l
= Layer_Top
;
1427 else l
= Layer_Normal
;
1429 else if (self
->above
) l
= Layer_Above
;
1430 else if (self
->below
) l
= Layer_Below
;
1431 else l
= Layer_Normal
;
1433 calc_recursive(self
, l
, FALSE
);
1436 gboolean
client_should_show(Client
*self
)
1438 if (self
->iconic
) return FALSE
;
1439 else if (!(self
->desktop
== screen_desktop
||
1440 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1441 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1446 static void client_showhide(Client
*self
)
1449 if (client_should_show(self
))
1450 frame_show(self
->frame
);
1452 frame_hide(self
->frame
);
1455 gboolean
client_normal(Client
*self
) {
1456 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1457 self
->type
== Type_Splash
);
1460 static void client_apply_startup_state(Client
*self
)
1462 /* these are in a carefully crafted order.. */
1465 self
->iconic
= FALSE
;
1466 client_iconify(self
, TRUE
, FALSE
);
1468 if (self
->fullscreen
) {
1469 self
->fullscreen
= FALSE
;
1470 client_fullscreen(self
, TRUE
, FALSE
);
1473 self
->shaded
= FALSE
;
1474 client_shade(self
, TRUE
);
1477 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1479 if (self
->max_vert
&& self
->max_horz
) {
1480 self
->max_vert
= self
->max_horz
= FALSE
;
1481 client_maximize(self
, TRUE
, 0, FALSE
);
1482 } else if (self
->max_vert
) {
1483 self
->max_vert
= FALSE
;
1484 client_maximize(self
, TRUE
, 2, FALSE
);
1485 } else if (self
->max_horz
) {
1486 self
->max_horz
= FALSE
;
1487 client_maximize(self
, TRUE
, 1, FALSE
);
1490 /* nothing to do for the other states:
1499 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1500 gboolean user
, gboolean final
)
1502 gboolean moved
= FALSE
, resized
= FALSE
;
1504 /* gets the frame's position */
1505 frame_client_gravity(self
->frame
, &x
, &y
);
1507 /* these positions are frame positions, not client positions */
1509 /* set the size and position if fullscreen */
1510 if (self
->fullscreen
) {
1513 w
= screen_physical_size
.width
;
1514 h
= screen_physical_size
.height
;
1515 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1517 /* set the size and position if maximized */
1518 if (self
->max_horz
) {
1519 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1520 w
= screen_area(self
->desktop
)->width
;
1522 if (self
->max_vert
) {
1523 y
= screen_area(self
->desktop
)->y
;
1524 h
= screen_area(self
->desktop
)->height
-
1525 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1529 /* gets the client's position */
1530 frame_frame_gravity(self
->frame
, &x
, &y
);
1532 /* these override the above states! if you cant move you can't move! */
1534 if (!(self
->functions
& Func_Move
)) {
1538 if (!(self
->functions
& Func_Resize
)) {
1539 w
= self
->area
.width
;
1540 h
= self
->area
.height
;
1544 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1545 w
-= self
->base_size
.width
;
1546 h
-= self
->base_size
.height
;
1549 /* for interactive resizing. have to move half an increment in each
1552 /* how far we are towards the next size inc */
1553 int mw
= w
% self
->size_inc
.width
;
1554 int mh
= h
% self
->size_inc
.height
;
1556 int aw
= self
->size_inc
.width
/ 2;
1557 int ah
= self
->size_inc
.height
/ 2;
1558 /* don't let us move into a new size increment */
1559 if (mw
+ aw
>= self
->size_inc
.width
)
1560 aw
= self
->size_inc
.width
- mw
- 1;
1561 if (mh
+ ah
>= self
->size_inc
.height
)
1562 ah
= self
->size_inc
.height
- mh
- 1;
1566 /* if this is a user-requested resize, then check against min/max
1567 sizes and aspect ratios */
1569 /* smaller than min size or bigger than max size? */
1570 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1571 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1572 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1573 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1575 /* adjust the height ot match the width for the aspect ratios */
1576 if (self
->min_ratio
)
1577 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1578 if (self
->max_ratio
)
1579 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1582 /* keep to the increments */
1583 w
/= self
->size_inc
.width
;
1584 h
/= self
->size_inc
.height
;
1586 /* you cannot resize to nothing */
1590 /* store the logical size */
1591 SIZE_SET(self
->logical_size
, w
, h
);
1593 w
*= self
->size_inc
.width
;
1594 h
*= self
->size_inc
.height
;
1596 w
+= self
->base_size
.width
;
1597 h
+= self
->base_size
.height
;
1601 case Corner_TopLeft
:
1603 case Corner_TopRight
:
1604 x
-= w
- self
->area
.width
;
1606 case Corner_BottomLeft
:
1607 y
-= h
- self
->area
.height
;
1609 case Corner_BottomRight
:
1610 x
-= w
- self
->area
.width
;
1611 y
-= h
- self
->area
.height
;
1615 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1616 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1618 RECT_SET(self
->area
, x
, y
, w
, h
);
1621 XResizeWindow(ob_display
, self
->window
, w
, h
);
1623 /* move/resize the frame to match the request */
1625 if (moved
|| resized
)
1626 frame_adjust_area(self
->frame
, moved
, resized
);
1628 if (!user
|| final
) {
1630 event
.type
= ConfigureNotify
;
1631 event
.xconfigure
.display
= ob_display
;
1632 event
.xconfigure
.event
= self
->window
;
1633 event
.xconfigure
.window
= self
->window
;
1635 /* root window coords with border in mind */
1636 event
.xconfigure
.x
= x
- self
->border_width
+
1637 self
->frame
->size
.left
;
1638 event
.xconfigure
.y
= y
- self
->border_width
+
1639 self
->frame
->size
.top
;
1641 event
.xconfigure
.width
= self
->area
.width
;
1642 event
.xconfigure
.height
= self
->area
.height
;
1643 event
.xconfigure
.border_width
= self
->border_width
;
1644 event
.xconfigure
.above
= self
->frame
->plate
;
1645 event
.xconfigure
.override_redirect
= FALSE
;
1646 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1647 FALSE
, StructureNotifyMask
, &event
);
1652 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1656 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1657 self
->fullscreen
== fs
) return; /* already done */
1659 self
->fullscreen
= fs
;
1660 client_change_state(self
); /* change the state hints on the client,
1661 and adjust out layer/stacking */
1665 guint32 dimensions
[4];
1666 dimensions
[0] = self
->area
.x
;
1667 dimensions
[1] = self
->area
.y
;
1668 dimensions
[2] = self
->area
.width
;
1669 dimensions
[3] = self
->area
.height
;
1671 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1675 /* these are not actually used cuz client_configure will set them
1676 as appropriate when the window is fullscreened */
1682 /* pick some fallbacks... */
1683 x
= screen_area(self
->desktop
)->x
+
1684 screen_area(self
->desktop
)->width
/ 4;
1685 y
= screen_area(self
->desktop
)->y
+
1686 screen_area(self
->desktop
)->height
/ 4;
1687 w
= screen_area(self
->desktop
)->width
/ 2;
1688 h
= screen_area(self
->desktop
)->height
/ 2;
1690 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1691 (guint32
**)&dimensions
, &num
)) {
1702 client_setup_decor_and_functions(self
);
1704 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1706 /* try focus us when we go into fullscreen mode */
1710 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1714 /* move up the transient chain as far as possible first if deiconifying */
1716 while (self
->transient_for
) {
1717 if (self
->transient_for
!= TRAN_GROUP
) {
1718 if (self
->transient_for
->iconic
== iconic
)
1720 self
= self
->transient_for
;
1724 /* the check for TRAN_GROUP is to prevent an infinate loop with
1725 2 transients of the same group at the head of the group's
1727 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1728 Client
*c
= it
->data
;
1730 if (c
!= self
&& c
->transient_for
->iconic
!= iconic
&&
1731 c
->transient_for
!= TRAN_GROUP
) {
1736 if (it
== NULL
) break;
1740 if (self
->iconic
== iconic
) return; /* nothing to do */
1742 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1745 self
->iconic
= iconic
;
1748 self
->wmstate
= IconicState
;
1749 self
->ignore_unmaps
++;
1750 /* we unmap the client itself so that we can get MapRequest events,
1751 and because the ICCCM tells us to! */
1752 XUnmapWindow(ob_display
, self
->window
);
1755 client_set_desktop(self
, screen_desktop
, FALSE
);
1756 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1757 XMapWindow(ob_display
, self
->window
);
1759 client_change_state(self
);
1760 client_showhide(self
);
1761 screen_update_struts();
1763 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1766 /* iconify all transients */
1767 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1768 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1771 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1775 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1776 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1778 /* check if already done */
1780 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1781 if (dir
== 1 && self
->max_horz
) return;
1782 if (dir
== 2 && self
->max_vert
) return;
1784 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1785 if (dir
== 1 && !self
->max_horz
) return;
1786 if (dir
== 2 && !self
->max_vert
) return;
1789 /* work with the frame's coords */
1790 x
= self
->frame
->area
.x
;
1791 y
= self
->frame
->area
.y
;
1792 w
= self
->area
.width
;
1793 h
= self
->area
.height
;
1797 gint32 dimensions
[4];
1806 /* get the property off the window and use it for the dimensions
1807 we are already maxed on */
1808 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1809 (guint32
**)&readdim
, &num
)) {
1811 if (self
->max_horz
) {
1812 dimensions
[0] = readdim
[0];
1813 dimensions
[2] = readdim
[2];
1815 if (self
->max_vert
) {
1816 dimensions
[1] = readdim
[1];
1817 dimensions
[3] = readdim
[3];
1823 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1824 (guint32
*)dimensions
, 4);
1830 /* pick some fallbacks... */
1831 if (dir
== 0 || dir
== 1) { /* horz */
1832 x
= screen_area(self
->desktop
)->x
+
1833 screen_area(self
->desktop
)->width
/ 4;
1834 w
= screen_area(self
->desktop
)->width
/ 2;
1836 if (dir
== 0 || dir
== 2) { /* vert */
1837 y
= screen_area(self
->desktop
)->y
+
1838 screen_area(self
->desktop
)->height
/ 4;
1839 h
= screen_area(self
->desktop
)->height
/ 2;
1842 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1843 (guint32
**)&dimensions
, &num
)) {
1845 if (dir
== 0 || dir
== 1) { /* horz */
1849 if (dir
== 0 || dir
== 2) { /* vert */
1858 if (dir
== 0 || dir
== 1) /* horz */
1859 self
->max_horz
= max
;
1860 if (dir
== 0 || dir
== 2) /* vert */
1861 self
->max_vert
= max
;
1863 if (!self
->max_horz
&& !self
->max_vert
)
1864 PROP_ERASE(self
->window
, openbox_premax
);
1866 client_change_state(self
); /* change the state hints on the client */
1868 /* figure out where the client should be going */
1869 frame_frame_gravity(self
->frame
, &x
, &y
);
1870 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1873 void client_shade(Client
*self
, gboolean shade
)
1875 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1876 self
->shaded
== shade
) return; /* already done */
1878 /* when we're iconic, don't change the wmstate */
1880 self
->wmstate
= shade
? IconicState
: NormalState
;
1881 self
->shaded
= shade
;
1882 client_change_state(self
);
1883 /* resize the frame to just the titlebar */
1884 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1887 void client_close(Client
*self
)
1891 if (!(self
->functions
& Func_Close
)) return;
1894 XXX: itd be cool to do timeouts and shit here for killing the client's
1896 like... if the window is around after 5 seconds, then the close button
1897 turns a nice red, and if this function is called again, the client is
1901 ce
.xclient
.type
= ClientMessage
;
1902 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1903 ce
.xclient
.display
= ob_display
;
1904 ce
.xclient
.window
= self
->window
;
1905 ce
.xclient
.format
= 32;
1906 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1907 ce
.xclient
.data
.l
[1] = event_lasttime
;
1908 ce
.xclient
.data
.l
[2] = 0l;
1909 ce
.xclient
.data
.l
[3] = 0l;
1910 ce
.xclient
.data
.l
[4] = 0l;
1911 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1914 void client_kill(Client
*self
)
1916 XKillClient(ob_display
, self
->window
);
1919 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1923 if (target
== self
->desktop
) return;
1925 g_message("Setting desktop %u", target
);
1927 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1929 old
= self
->desktop
;
1930 self
->desktop
= target
;
1931 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1932 /* the frame can display the current desktop state */
1933 frame_adjust_state(self
->frame
);
1934 /* 'move' the window to the new desktop */
1936 client_showhide(self
);
1937 /* raise if it was not already on the desktop */
1938 if (old
!= DESKTOP_ALL
)
1939 stacking_raise(self
);
1940 screen_update_struts();
1942 /* update the focus lists */
1943 if (old
== DESKTOP_ALL
) {
1944 for (i
= 0; i
< screen_num_desktops
; ++i
)
1945 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1947 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1948 if (target
== DESKTOP_ALL
) {
1949 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1950 if (config_focus_new
)
1951 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1953 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1956 if (config_focus_new
)
1957 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1959 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1962 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1965 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1970 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1971 Client
*c
= it
->data
;
1972 if (c
== skip
) continue; /* circular? */
1973 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1974 if (c
->modal
) return c
;
1979 Client
*client_find_modal_child(Client
*self
)
1981 return search_modal_tree(self
, self
);
1984 gboolean
client_validate(Client
*self
)
1988 XSync(ob_display
, FALSE
); /* get all events on the server */
1990 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1991 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1992 XPutBackEvent(ob_display
, &e
);
1999 void client_set_wm_state(Client
*self
, long state
)
2001 if (state
== self
->wmstate
) return; /* no change */
2005 client_iconify(self
, TRUE
, TRUE
);
2008 client_iconify(self
, FALSE
, TRUE
);
2013 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
2015 gboolean shaded
= self
->shaded
;
2016 gboolean fullscreen
= self
->fullscreen
;
2017 gboolean max_horz
= self
->max_horz
;
2018 gboolean max_vert
= self
->max_vert
;
2021 if (!(action
== prop_atoms
.net_wm_state_add
||
2022 action
== prop_atoms
.net_wm_state_remove
||
2023 action
== prop_atoms
.net_wm_state_toggle
))
2024 /* an invalid action was passed to the client message, ignore it */
2027 for (i
= 0; i
< 2; ++i
) {
2028 Atom state
= i
== 0 ? data1
: data2
;
2030 if (!state
) continue;
2032 /* if toggling, then pick whether we're adding or removing */
2033 if (action
== prop_atoms
.net_wm_state_toggle
) {
2034 if (state
== prop_atoms
.net_wm_state_modal
)
2035 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2036 prop_atoms
.net_wm_state_add
;
2037 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2038 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2039 prop_atoms
.net_wm_state_add
;
2040 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2041 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2042 prop_atoms
.net_wm_state_add
;
2043 else if (state
== prop_atoms
.net_wm_state_shaded
)
2044 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2045 prop_atoms
.net_wm_state_add
;
2046 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2047 action
= self
->skip_taskbar
?
2048 prop_atoms
.net_wm_state_remove
:
2049 prop_atoms
.net_wm_state_add
;
2050 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2051 action
= self
->skip_pager
?
2052 prop_atoms
.net_wm_state_remove
:
2053 prop_atoms
.net_wm_state_add
;
2054 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2055 action
= self
->fullscreen
?
2056 prop_atoms
.net_wm_state_remove
:
2057 prop_atoms
.net_wm_state_add
;
2058 else if (state
== prop_atoms
.net_wm_state_above
)
2059 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2060 prop_atoms
.net_wm_state_add
;
2061 else if (state
== prop_atoms
.net_wm_state_below
)
2062 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2063 prop_atoms
.net_wm_state_add
;
2066 if (action
== prop_atoms
.net_wm_state_add
) {
2067 if (state
== prop_atoms
.net_wm_state_modal
) {
2068 /* XXX raise here or something? */
2070 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2072 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2074 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2076 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2077 self
->skip_taskbar
= TRUE
;
2078 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2079 self
->skip_pager
= TRUE
;
2080 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2082 } else if (state
== prop_atoms
.net_wm_state_above
) {
2084 } else if (state
== prop_atoms
.net_wm_state_below
) {
2088 } else { /* action == prop_atoms.net_wm_state_remove */
2089 if (state
== prop_atoms
.net_wm_state_modal
) {
2090 self
->modal
= FALSE
;
2091 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2093 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2095 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2097 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2098 self
->skip_taskbar
= FALSE
;
2099 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2100 self
->skip_pager
= FALSE
;
2101 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2103 } else if (state
== prop_atoms
.net_wm_state_above
) {
2104 self
->above
= FALSE
;
2105 } else if (state
== prop_atoms
.net_wm_state_below
) {
2106 self
->below
= FALSE
;
2110 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2111 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2113 if (max_horz
== max_vert
) { /* both going the same way */
2114 client_maximize(self
, max_horz
, 0, TRUE
);
2116 client_maximize(self
, max_horz
, 1, TRUE
);
2117 client_maximize(self
, max_vert
, 2, TRUE
);
2121 if (max_horz
!= self
->max_horz
)
2122 client_maximize(self
, max_horz
, 1, TRUE
);
2124 client_maximize(self
, max_vert
, 2, TRUE
);
2127 /* change fullscreen state before shading, as it will affect if the window
2129 if (fullscreen
!= self
->fullscreen
)
2130 client_fullscreen(self
, fullscreen
, TRUE
);
2131 if (shaded
!= self
->shaded
)
2132 client_shade(self
, shaded
);
2133 client_calc_layer(self
);
2134 client_change_state(self
); /* change the hint to relect these changes */
2137 Client
*client_focus_target(Client
*self
)
2141 /* if we have a modal child, then focus it, not us */
2142 child
= client_find_modal_child(self
);
2143 if (child
) return child
;
2147 gboolean
client_focusable(Client
*self
)
2149 /* won't try focus if the client doesn't want it, or if the window isn't
2150 visible on the screen */
2151 return self
->frame
->visible
&&
2152 (self
->can_focus
|| self
->focus_notify
);
2155 gboolean
client_focus(Client
*self
)
2160 /* choose the correct target */
2161 self
= client_focus_target(self
);
2163 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2164 /* update the focus lists */
2165 if (self
->desktop
== DESKTOP_ALL
) {
2166 for (i
= 0; i
< screen_num_desktops
; ++i
) {
2167 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
2168 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
2172 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
2173 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
2178 if (!client_focusable(self
))
2181 /* do a check to see if the window has already been unmapped or destroyed
2182 do this intelligently while watching out for unmaps we've generated
2183 (ignore_unmaps > 0) */
2184 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2185 DestroyNotify
, &ev
)) {
2186 XPutBackEvent(ob_display
, &ev
);
2189 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2190 UnmapNotify
, &ev
)) {
2191 if (self
->ignore_unmaps
) {
2192 self
->ignore_unmaps
--;
2194 XPutBackEvent(ob_display
, &ev
);
2199 if (self
->can_focus
)
2200 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2201 I choose to use it always, hopefully to find errors quicker, if any
2202 are left. (I hate X. I hate focus events.) */
2203 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2206 if (self
->focus_notify
) {
2208 ce
.xclient
.type
= ClientMessage
;
2209 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2210 ce
.xclient
.display
= ob_display
;
2211 ce
.xclient
.window
= self
->window
;
2212 ce
.xclient
.format
= 32;
2213 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2214 ce
.xclient
.data
.l
[1] = event_lasttime
;
2215 ce
.xclient
.data
.l
[2] = 0l;
2216 ce
.xclient
.data
.l
[3] = 0l;
2217 ce
.xclient
.data
.l
[4] = 0l;
2218 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2222 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2227 /* Cause the FocusIn to come back to us. Important for desktop switches,
2228 since otherwise we'll have no FocusIn on the queue and send it off to
2229 the focus_backup. */
2230 XSync(ob_display
, FALSE
);
2234 void client_unfocus(Client
*self
)
2236 g_assert(focus_client
== self
);
2238 g_message("client_unfocus for %lx", self
->window
);
2240 focus_fallback(Fallback_Unfocusing
);
2243 gboolean
client_focused(Client
*self
)
2245 return self
== focus_client
;
2248 Icon
*client_icon(Client
*self
, int w
, int h
)
2251 /* si is the smallest image >= req */
2252 /* li is the largest image < req */
2253 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2255 if (!self
->nicons
) return NULL
;
2257 for (i
= 0; i
< self
->nicons
; ++i
) {
2258 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2259 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2263 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2268 if (largest
== 0) /* didnt find one smaller than the requested size */
2269 return &self
->icons
[si
];
2270 return &self
->icons
[li
];