4 #include "moveresize.h"
6 #include "extensions.h"
18 #include <X11/Xutil.h>
20 /*! The event mask to grab on client windows */
21 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
24 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
27 GList
*client_list
= NULL
;
28 GHashTable
*client_map
= NULL
;
30 static void client_get_all(Client
*self
);
31 static void client_toggle_border(Client
*self
, gboolean show
);
32 static void client_get_area(Client
*self
);
33 static void client_get_desktop(Client
*self
);
34 static void client_get_state(Client
*self
);
35 static void client_get_shaped(Client
*self
);
36 static void client_get_mwm_hints(Client
*self
);
37 static void client_get_gravity(Client
*self
);
38 static void client_showhide(Client
*self
);
39 static void client_change_allowed_actions(Client
*self
);
40 static void client_change_state(Client
*self
);
41 static void client_move_onscreen(Client
*self
);
42 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
43 static void client_apply_startup_state(Client
*self
);
44 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
46 static guint
map_hash(Window
*w
) { return *w
; }
47 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
51 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
52 (GEqualFunc
)map_key_comp
);
57 void client_shutdown()
59 g_hash_table_destroy(client_map
);
62 void client_set_list()
64 Window
*windows
, *win_it
;
66 guint size
= g_list_length(client_list
);
68 /* create an array of the window ids */
70 windows
= g_new(Window
, size
);
72 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
73 *win_it
= ((Client
*)it
->data
)->window
;
77 PROP_SETA32(ob_root
, net_client_list
, window
, (guint32
*)windows
, size
);
85 void client_manage_all()
87 unsigned int i
, j
, nchild
;
90 XWindowAttributes attrib
;
93 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
95 /* remove all icon windows from the list */
96 for (i
= 0; i
< nchild
; i
++) {
97 if (children
[i
] == None
) continue;
98 wmhints
= XGetWMHints(ob_display
, children
[i
]);
100 if ((wmhints
->flags
& IconWindowHint
) &&
101 (wmhints
->icon_window
!= children
[i
]))
102 for (j
= 0; j
< nchild
; j
++)
103 if (children
[j
] == wmhints
->icon_window
) {
111 for (i
= 0; i
< nchild
; ++i
) {
112 if (children
[i
] == None
)
114 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
115 if (attrib
.override_redirect
) continue;
117 if (attrib
.map_state
!= IsUnmapped
)
118 client_manage(children
[i
]);
123 /* stack them as they were on startup!
124 why with stacking_lower? Why, because then windows who aren't in the
125 stacking list are on the top where you can see them instead of buried
127 for (i
= startup_stack_size
; i
> 0; --i
) {
130 w
= startup_stack_order
[i
-1];
131 c
= g_hash_table_lookup(client_map
, &w
);
132 if (c
) stacking_lower(c
);
134 g_free(startup_stack_order
);
135 startup_stack_order
= NULL
;
136 startup_stack_size
= 0;
138 if (config_focus_new
) {
139 active
= g_hash_table_lookup(client_map
, &startup_active
);
140 if (!active
|| !client_focus(active
))
141 focus_fallback(Fallback_NoFocus
);
145 void client_manage(Window window
)
149 XWindowAttributes attrib
;
150 XSetWindowAttributes attrib_set
;
151 /* XWMHints *wmhint; */
155 /* check if it has already been unmapped by the time we started mapping
156 the grab does a sync so we don't have to here */
157 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
158 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
159 XPutBackEvent(ob_display
, &e
);
162 return; /* don't manage it */
165 /* make sure it isn't an override-redirect window */
166 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
167 attrib
.override_redirect
) {
169 return; /* don't manage it */
172 /* /\* is the window a docking app *\/
173 if ((wmhint = XGetWMHints(ob_display, window))) {
174 if ((wmhint->flags & StateHint) &&
175 wmhint->initial_state == WithdrawnState) {
176 /\* XXX: make dock apps work! *\/
184 g_message("Managing window: %lx", window
);
186 /* choose the events we want to receive on the CLIENT window */
187 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
188 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
189 XChangeWindowAttributes(ob_display
, window
,
190 CWEventMask
|CWDontPropagate
, &attrib_set
);
193 /* create the Client struct, and populate it from the hints on the
195 self
= g_new(Client
, 1);
196 self
->window
= window
;
197 client_get_all(self
);
199 /* remove the client's border (and adjust re gravity) */
200 client_toggle_border(self
, FALSE
);
202 /* specify that if we exit, the window should not be destroyed and should
203 be reparented back to root automatically */
204 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
206 /* create the decoration frame for the client window */
207 self
->frame
= frame_new();
209 frame_grab_client(self
->frame
, self
);
211 client_apply_startup_state(self
);
215 client_list
= g_list_append(client_list
, self
);
216 stacking_list
= g_list_append(stacking_list
, self
);
217 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
218 g_hash_table_insert(client_map
, &self
->window
, self
);
220 /* update the focus lists */
221 focus_order_add_new(self
);
223 stacking_raise(self
);
225 screen_update_struts();
227 dispatch_client(Event_Client_New
, self
, 0, 0);
229 client_showhide(self
);
231 /* focus the new window? */
232 if (ob_state
!= State_Starting
) {
234 gboolean group_foc
= FALSE
;
241 for (it
= self
->group
->members
; it
; it
= it
->next
)
242 if (client_focused(it
->data
)) {
247 if (!group_foc
&& self
->transient_for
) {
248 if (self
->transient_for
!= TRAN_GROUP
) {/* transient of a window */
249 parent
= self
->transient_for
;
250 } else { /* transient of a group */
253 for (it
= self
->group
->members
; it
; it
= it
->next
)
254 if (it
->data
!= self
&&
255 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
)
259 /* note the check against Type_Normal, not client_normal(self), which
260 would also include dialog types. in this case we want more strict
262 if ((config_focus_new
&&
263 (self
->type
== Type_Normal
||
264 (self
->type
== Type_Dialog
&&
266 (!parent
&& (!self
->group
||
267 !self
->group
->members
->next
)))))) ||
268 (parent
&& (client_focused(parent
) ||
269 search_focus_tree(parent
, parent
)))) {
274 /* update the list hints */
277 /* make sure the window is visible */
278 client_move_onscreen(self
);
280 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
282 g_message("Managed window 0x%lx", window
);
285 void client_unmanage_all()
287 while (client_list
!= NULL
)
288 client_unmanage(client_list
->data
);
291 void client_unmanage(Client
*self
)
296 g_message("Unmanaging window: %lx", self
->window
);
298 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
299 g_assert(self
!= NULL
);
301 /* remove the window from our save set */
302 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
304 /* we dont want events no more */
305 XSelectInput(ob_display
, self
->window
, NoEventMask
);
307 frame_hide(self
->frame
);
309 client_list
= g_list_remove(client_list
, self
);
310 stacking_list
= g_list_remove(stacking_list
, self
);
311 g_hash_table_remove(client_map
, &self
->window
);
313 /* update the focus lists */
314 focus_order_remove(self
);
316 /* once the client is out of the list, update the struts to remove it's
318 screen_update_struts();
320 /* tell our parent(s) that we're gone */
321 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
324 for (it
= self
->group
->members
; it
; it
= it
->next
)
325 if (it
->data
!= self
)
326 ((Client
*)it
->data
)->transients
=
327 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
328 } else if (self
->transient_for
) { /* transient of window */
329 self
->transient_for
->transients
=
330 g_slist_remove(self
->transient_for
->transients
, self
);
333 /* tell our transients that we're gone */
334 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
335 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
336 ((Client
*)it
->data
)->transient_for
= NULL
;
337 client_calc_layer(it
->data
);
341 if (moveresize_client
== self
)
342 moveresize_end(TRUE
);
344 if (focus_client
== self
) {
347 /* focus the last focused window on the desktop, and ignore enter
348 events from the unmap so it doesnt mess with the focus */
349 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
350 client_unfocus(self
);
353 /* remove from its group */
355 group_remove(self
->group
, self
);
359 /* dispatch the unmapped event */
360 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
361 g_assert(self
!= NULL
);
363 /* give the client its border back */
364 client_toggle_border(self
, TRUE
);
366 /* reparent the window out of the frame, and free the frame */
367 frame_release_client(self
->frame
, self
);
370 if (ob_state
!= State_Exiting
) {
371 /* these values should not be persisted across a window
373 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
374 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
376 /* if we're left in an iconic state, the client wont be mapped. this is
377 bad, since we will no longer be managing the window on restart */
379 XMapWindow(ob_display
, self
->window
);
383 g_message("Unmanaged window 0x%lx", self
->window
);
385 /* free all data allocated in the client struct */
386 g_slist_free(self
->transients
);
387 for (j
= 0; j
< self
->nicons
; ++j
)
388 g_free(self
->icons
[j
].data
);
389 if (self
->nicons
> 0)
392 g_free(self
->icon_title
);
398 /* update the list hints */
402 static void client_move_onscreen(Client
*self
)
405 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
407 a
= screen_area(self
->desktop
);
408 if (x
>= a
->x
+ a
->width
- 1)
409 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
410 if (y
>= a
->y
+ a
->height
- 1)
411 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
412 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
414 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
417 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
419 client_configure(self
, Corner_TopLeft
, x
, y
,
420 self
->area
.width
, self
->area
.height
,
424 static void client_toggle_border(Client
*self
, gboolean show
)
426 /* adjust our idea of where the client is, based on its border. When the
427 border is removed, the client should now be considered to be in a
429 when re-adding the border to the client, the same operation needs to be
431 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
432 int x
= oldx
, y
= oldy
;
433 switch(self
->gravity
) {
435 case NorthWestGravity
:
437 case SouthWestGravity
:
439 case NorthEastGravity
:
441 case SouthEastGravity
:
442 if (show
) x
-= self
->border_width
* 2;
443 else x
+= self
->border_width
* 2;
450 if (show
) x
-= self
->border_width
;
451 else x
+= self
->border_width
;
454 switch(self
->gravity
) {
456 case NorthWestGravity
:
458 case NorthEastGravity
:
460 case SouthWestGravity
:
462 case SouthEastGravity
:
463 if (show
) y
-= self
->border_width
* 2;
464 else y
+= self
->border_width
* 2;
471 if (show
) y
-= self
->border_width
;
472 else y
+= self
->border_width
;
479 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
481 /* move the client so it is back it the right spot _with_ its
483 if (x
!= oldx
|| y
!= oldy
)
484 XMoveWindow(ob_display
, self
->window
, x
, y
);
486 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
490 static void client_get_all(Client
*self
)
492 /* update EVERYTHING!! */
494 self
->ignore_unmaps
= 0;
498 self
->title
= self
->icon_title
= NULL
;
499 self
->name
= self
->class = self
->role
= NULL
;
500 self
->wmstate
= NormalState
;
501 self
->transient
= FALSE
;
502 self
->transients
= NULL
;
503 self
->transient_for
= NULL
;
505 self
->urgent
= FALSE
;
506 self
->positioned
= FALSE
;
507 self
->disabled_decorations
= 0;
511 client_get_area(self
);
512 client_update_transient_for(self
);
513 client_update_wmhints(self
);
514 client_get_desktop(self
);
515 client_get_state(self
);
516 client_get_shaped(self
);
518 client_get_mwm_hints(self
);
519 client_get_type(self
);/* this can change the mwmhints for special cases */
521 client_update_protocols(self
);
523 client_get_gravity(self
); /* get the attribute gravity */
524 client_update_normal_hints(self
); /* this may override the attribute
527 /* got the type, the mwmhints, the protocols, and the normal hints
528 (min/max sizes), so we're ready to set up the decorations/functions */
529 client_setup_decor_and_functions(self
);
531 client_update_title(self
);
532 client_update_icon_title(self
);
533 client_update_class(self
);
534 client_update_strut(self
);
535 client_update_icons(self
);
536 client_update_kwm_icon(self
);
538 client_change_state(self
);
541 static void client_get_area(Client
*self
)
543 XWindowAttributes wattrib
;
546 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
547 g_assert(ret
!= BadWindow
);
549 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
550 self
->border_width
= wattrib
.border_width
;
553 static void client_get_desktop(Client
*self
)
557 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
558 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
559 d
= screen_num_desktops
- 1;
562 gboolean trdesk
= FALSE
;
564 if (self
->transient_for
) {
565 if (self
->transient_for
!= TRAN_GROUP
) {
566 self
->desktop
= self
->transient_for
->desktop
;
571 for (it
= self
->group
->members
; it
; it
= it
->next
)
572 if (it
->data
!= self
&&
573 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
574 self
->desktop
= ((Client
*)it
->data
)->desktop
;
581 /* defaults to the current desktop */
582 self
->desktop
= screen_desktop
;
584 /* set the desktop hint, to make sure that it always exists */
585 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
589 static void client_get_state(Client
*self
)
594 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
595 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
596 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
598 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
600 for (i
= 0; i
< num
; ++i
) {
601 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
603 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
605 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
607 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
608 self
->skip_taskbar
= TRUE
;
609 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
610 self
->skip_pager
= TRUE
;
611 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
612 self
->fullscreen
= TRUE
;
613 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
614 self
->max_vert
= TRUE
;
615 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
616 self
->max_horz
= TRUE
;
617 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
619 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
627 static void client_get_shaped(Client
*self
)
629 self
->shaped
= FALSE
;
631 if (extensions_shape
) {
636 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
638 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
639 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
641 self
->shaped
= (s
!= 0);
646 void client_update_transient_for(Client
*self
)
651 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
652 self
->transient
= TRUE
;
653 if (t
!= self
->window
) { /* cant be transient to itself! */
654 c
= g_hash_table_lookup(client_map
, &t
);
655 /* if this happens then we need to check for it*/
658 if (!c
&& self
->group
) {
659 /* not transient to a client, see if it is transient for a
661 if (t
== self
->group
->leader
||
664 /* window is a transient for its group! */
670 self
->transient
= FALSE
;
672 /* if anything has changed... */
673 if (c
!= self
->transient_for
) {
674 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
677 /* remove from old parents */
678 for (it
= self
->group
->members
; it
; it
= it
->next
)
679 if (it
->data
!= self
&&
680 (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
))
681 ((Client
*)it
->data
)->transients
=
682 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
683 } else if (self
->transient_for
!= NULL
) { /* transient of window */
684 /* remove from old parent */
685 self
->transient_for
->transients
=
686 g_slist_remove(self
->transient_for
->transients
, self
);
688 self
->transient_for
= c
;
689 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
692 /* add to new parents */
693 for (it
= self
->group
->members
; it
; it
= it
->next
)
694 if (it
->data
!= self
&&
695 (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
))
696 ((Client
*)it
->data
)->transients
=
697 g_slist_append(((Client
*)it
->data
)->transients
, self
);
699 /* remove all transients which are in the group, that causes
700 circlular pointer hell of doom */
701 for (it
= self
->group
->members
; it
; it
= it
->next
) {
703 for (sit
= self
->transients
; sit
; sit
= next
) {
705 if (sit
->data
== it
->data
)
706 self
->transients
= g_slist_remove(self
->transients
,
710 } else if (self
->transient_for
!= NULL
) { /* transient of window */
711 /* add to new parent */
712 self
->transient_for
->transients
=
713 g_slist_append(self
->transient_for
->transients
, self
);
718 static void client_get_mwm_hints(Client
*self
)
723 self
->mwmhints
.flags
= 0; /* default to none */
725 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
727 if (num
>= MWM_ELEMENTS
) {
728 self
->mwmhints
.flags
= hints
[0];
729 self
->mwmhints
.functions
= hints
[1];
730 self
->mwmhints
.decorations
= hints
[2];
736 void client_get_type(Client
*self
)
743 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
744 /* use the first value that we know about in the array */
745 for (i
= 0; i
< num
; ++i
) {
746 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
747 self
->type
= Type_Desktop
;
748 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
749 self
->type
= Type_Dock
;
750 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
751 self
->type
= Type_Toolbar
;
752 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
753 self
->type
= Type_Menu
;
754 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
755 self
->type
= Type_Utility
;
756 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
757 self
->type
= Type_Splash
;
758 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
759 self
->type
= Type_Dialog
;
760 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
761 self
->type
= Type_Normal
;
762 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
763 /* prevent this window from getting any decor or
765 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
766 MwmFlag_Decorations
);
767 self
->mwmhints
.decorations
= 0;
768 self
->mwmhints
.functions
= 0;
770 if (self
->type
!= (WindowType
) -1)
771 break; /* grab the first legit type */
776 if (self
->type
== (WindowType
) -1) {
777 /*the window type hint was not set, which means we either classify
778 ourself as a normal window or a dialog, depending on if we are a
781 self
->type
= Type_Dialog
;
783 self
->type
= Type_Normal
;
786 /* this makes sure that these windows appear on all desktops */
787 if (self
->type
== Type_Desktop
)
788 self
->desktop
= DESKTOP_ALL
;
791 void client_update_protocols(Client
*self
)
796 self
->focus_notify
= FALSE
;
797 self
->delete_window
= FALSE
;
799 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
800 for (i
= 0; i
< num_return
; ++i
) {
801 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
802 /* this means we can request the window to close */
803 self
->delete_window
= TRUE
;
804 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
805 /* if this protocol is requested, then the window will be
806 notified whenever we want it to receive focus */
807 self
->focus_notify
= TRUE
;
813 static void client_get_gravity(Client
*self
)
815 XWindowAttributes wattrib
;
818 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
819 g_assert(ret
!= BadWindow
);
820 self
->gravity
= wattrib
.win_gravity
;
823 void client_update_normal_hints(Client
*self
)
827 int oldgravity
= self
->gravity
;
830 self
->min_ratio
= 0.0f
;
831 self
->max_ratio
= 0.0f
;
832 SIZE_SET(self
->size_inc
, 1, 1);
833 SIZE_SET(self
->base_size
, 0, 0);
834 SIZE_SET(self
->min_size
, 0, 0);
835 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
837 /* get the hints from the window */
838 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
839 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
841 if (size
.flags
& PWinGravity
) {
842 self
->gravity
= size
.win_gravity
;
844 /* if the client has a frame, i.e. has already been mapped and
845 is changing its gravity */
846 if (self
->frame
&& self
->gravity
!= oldgravity
) {
847 /* move our idea of the client's position based on its new
849 self
->area
.x
= self
->frame
->area
.x
;
850 self
->area
.y
= self
->frame
->area
.y
;
851 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
855 if (size
.flags
& PAspect
) {
856 if (size
.min_aspect
.y
)
857 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
858 if (size
.max_aspect
.y
)
859 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
862 if (size
.flags
& PMinSize
)
863 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
865 if (size
.flags
& PMaxSize
)
866 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
868 if (size
.flags
& PBaseSize
)
869 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
871 if (size
.flags
& PResizeInc
)
872 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
876 void client_setup_decor_and_functions(Client
*self
)
878 /* start with everything (cept fullscreen) */
879 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
880 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
882 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
884 if (self
->delete_window
) {
885 self
->decorations
|= Decor_Close
;
886 self
->functions
|= Func_Close
;
889 if (!(self
->min_size
.width
< self
->max_size
.width
||
890 self
->min_size
.height
< self
->max_size
.height
)) {
891 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
892 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
895 switch (self
->type
) {
897 /* normal windows retain all of the possible decorations and
898 functionality, and are the only windows that you can fullscreen */
899 self
->functions
|= Func_Fullscreen
;
904 /* these windows cannot be maximized */
905 self
->decorations
&= ~Decor_Maximize
;
906 self
->functions
&= ~Func_Maximize
;
911 /* these windows get less functionality */
912 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
913 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
919 /* none of these windows are manipulated by the window manager */
920 self
->decorations
= 0;
925 /* Mwm Hints are applied subtractively to what has already been chosen for
926 decor and functionality */
927 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
928 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
929 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
930 self
->decorations
&= ~Decor_Border
;
931 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
932 self
->decorations
&= ~Decor_Handle
;
933 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
934 self
->decorations
&= ~Decor_Titlebar
;
935 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
936 self
->decorations
&= ~Decor_Iconify
;
937 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
938 self
->decorations
&= ~Decor_Maximize
;
942 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
943 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
944 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
945 self
->functions
&= ~Func_Resize
;
946 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
947 self
->functions
&= ~Func_Move
;
948 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
949 self
->functions
&= ~Func_Iconify
;
950 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
951 self
->functions
&= ~Func_Maximize
;
952 /* dont let mwm hints kill the close button
953 if (! (self->mwmhints.functions & MwmFunc_Close))
954 self->functions &= ~Func_Close; */
958 /* can't maximize without moving/resizing */
959 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
960 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
962 /* finally, user specified disabled decorations are applied to subtract
964 if (self
->disabled_decorations
& Decor_Titlebar
)
965 self
->decorations
&= ~Decor_Titlebar
;
966 if (self
->disabled_decorations
& Decor_Handle
)
967 self
->decorations
&= ~Decor_Handle
;
968 if (self
->disabled_decorations
& Decor_Border
)
969 self
->decorations
&= ~Decor_Border
;
970 if (self
->disabled_decorations
& Decor_Iconify
)
971 self
->decorations
&= ~Decor_Iconify
;
972 if (self
->disabled_decorations
& Decor_Maximize
)
973 self
->decorations
&= ~Decor_Maximize
;
974 if (self
->disabled_decorations
& Decor_AllDesktops
)
975 self
->decorations
&= ~Decor_AllDesktops
;
976 if (self
->disabled_decorations
& Decor_Shade
)
977 self
->decorations
&= ~Decor_Shade
;
978 if (self
->disabled_decorations
& Decor_Close
)
979 self
->decorations
&= ~Decor_Close
;
981 /* if we don't have a titlebar, then we cannot shade! */
982 if (!(self
->decorations
& Decor_Titlebar
))
983 self
->functions
&= ~Func_Shade
;
985 /* now we need to check against rules for the client's current state */
986 if (self
->fullscreen
) {
987 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
988 self
->decorations
= 0;
991 client_change_allowed_actions(self
);
994 /* change the decors on the frame, and with more/less decorations,
995 we may also need to be repositioned */
996 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
997 /* with new decor, the window's maximized size may change */
998 client_remaximize(self
);
1002 static void client_change_allowed_actions(Client
*self
)
1007 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1009 if (self
->functions
& Func_Shade
)
1010 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1011 if (self
->functions
& Func_Close
)
1012 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1013 if (self
->functions
& Func_Move
)
1014 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1015 if (self
->functions
& Func_Iconify
)
1016 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1017 if (self
->functions
& Func_Resize
)
1018 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1019 if (self
->functions
& Func_Fullscreen
)
1020 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1021 if (self
->functions
& Func_Maximize
) {
1022 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1023 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1026 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1028 /* make sure the window isn't breaking any rules now */
1030 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1031 if (self
->frame
) client_shade(self
, FALSE
);
1032 else self
->shaded
= FALSE
;
1034 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1035 g_message("UNSETTING ICONIC");
1036 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1037 else self
->iconic
= FALSE
;
1039 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1040 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1041 else self
->fullscreen
= FALSE
;
1043 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1045 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1046 else self
->max_vert
= self
->max_horz
= FALSE
;
1050 void client_remaximize(Client
*self
)
1053 if (self
->max_horz
&& self
->max_vert
)
1055 else if (self
->max_horz
)
1057 else if (self
->max_vert
)
1060 return; /* not maximized */
1061 self
->max_horz
= self
->max_vert
= FALSE
;
1062 client_maximize(self
, TRUE
, dir
, FALSE
);
1065 void client_update_wmhints(Client
*self
)
1068 gboolean ur
= FALSE
;
1071 /* assume a window takes input if it doesnt specify */
1072 self
->can_focus
= TRUE
;
1074 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1075 if (hints
->flags
& InputHint
)
1076 self
->can_focus
= hints
->input
;
1078 /* only do this when first managing the window *AND* when we aren't
1080 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1081 if (hints
->flags
& StateHint
)
1082 self
->iconic
= hints
->initial_state
== IconicState
;
1084 if (hints
->flags
& XUrgencyHint
)
1087 if (!(hints
->flags
& WindowGroupHint
))
1088 hints
->window_group
= None
;
1090 /* did the group state change? */
1091 if (hints
->window_group
!=
1092 (self
->group
? self
->group
->leader
: None
)) {
1093 /* remove from the old group if there was one */
1094 if (self
->group
!= NULL
) {
1095 /* remove transients of the group */
1096 for (it
= self
->group
->members
; it
; it
= it
->next
)
1097 if (it
->data
!= self
&&
1098 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
) {
1099 self
->transients
= g_slist_remove(self
->transients
,
1102 group_remove(self
->group
, self
);
1105 if (hints
->window_group
!= None
) {
1106 self
->group
= group_add(hints
->window_group
, self
);
1108 /* add other transients of the group that are already
1110 for (it
= self
->group
->members
; it
; it
= it
->next
)
1111 if (it
->data
!= self
&&
1112 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1113 self
->transients
= g_slist_append(self
->transients
,
1117 /* because the self->transient flag wont change from this call,
1118 we don't need to update the window's type and such, only its
1119 transient_for, and the transients lists of other windows in
1120 the group may be affected */
1121 client_update_transient_for(self
);
1124 client_update_kwm_icon(self
);
1125 /* try get the kwm icon first, this is a fallback only */
1126 if (self
->pixmap_icon
== None
) {
1127 if (hints
->flags
& IconPixmapHint
) {
1128 if (self
->pixmap_icon
== None
) {
1129 self
->pixmap_icon
= hints
->icon_pixmap
;
1130 if (hints
->flags
& IconMaskHint
)
1131 self
->pixmap_icon_mask
= hints
->icon_mask
;
1133 self
->pixmap_icon_mask
= None
;
1136 frame_adjust_icon(self
->frame
);
1144 if (ur
!= self
->urgent
) {
1146 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1148 /* fire the urgent callback if we're mapped, otherwise, wait until
1149 after we're mapped */
1151 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1155 void client_update_title(Client
*self
)
1159 g_free(self
->title
);
1162 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1163 /* try old x stuff */
1164 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1165 data
= g_strdup("Unnamed Window");
1167 /* look for duplicates and append a number */
1169 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1174 frame_adjust_title(self
->frame
);
1177 void client_update_icon_title(Client
*self
)
1181 g_free(self
->icon_title
);
1184 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1185 /* try old x stuff */
1186 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
))
1187 data
= g_strdup("Unnamed Window");
1189 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1191 self
->icon_title
= data
;
1194 void client_update_class(Client
*self
)
1199 if (self
->name
) g_free(self
->name
);
1200 if (self
->class) g_free(self
->class);
1201 if (self
->role
) g_free(self
->role
);
1203 self
->name
= self
->class = self
->role
= NULL
;
1205 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1207 self
->name
= g_strdup(data
[0]);
1209 self
->class = g_strdup(data
[1]);
1214 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1215 self
->role
= g_strdup(s
);
1217 if (self
->name
== NULL
) self
->name
= g_strdup("");
1218 if (self
->class == NULL
) self
->class = g_strdup("");
1219 if (self
->role
== NULL
) self
->role
= g_strdup("");
1222 void client_update_strut(Client
*self
)
1227 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1228 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1231 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1233 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1237 /* updating here is pointless while we're being mapped cuz we're not in
1238 the client list yet */
1240 screen_update_struts();
1243 void client_update_icons(Client
*self
)
1250 for (j
= 0; j
< self
->nicons
; ++j
)
1251 g_free(self
->icons
[j
].data
);
1252 if (self
->nicons
> 0)
1253 g_free(self
->icons
);
1256 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1257 /* figure out how many valid icons are in here */
1259 while (num
- i
> 2) {
1267 self
->icons
= g_new(Icon
, self
->nicons
);
1269 /* store the icons */
1271 for (j
= 0; j
< self
->nicons
; ++j
) {
1272 w
= self
->icons
[j
].width
= data
[i
++];
1273 h
= self
->icons
[j
].height
= data
[i
++];
1274 self
->icons
[j
].data
=
1275 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1284 frame_adjust_icon(self
->frame
);
1287 void client_update_kwm_icon(Client
*self
)
1292 if (!PROP_GETA32(self
->window
, kwm_win_icon
, kwm_win_icon
, &data
, &num
)) {
1293 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1296 self
->pixmap_icon
= data
[0];
1297 self
->pixmap_icon_mask
= data
[1];
1299 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1303 frame_adjust_icon(self
->frame
);
1306 static void client_change_state(Client
*self
)
1309 guint32 netstate
[10];
1312 state
[0] = self
->wmstate
;
1314 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1318 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1320 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1322 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1323 if (self
->skip_taskbar
)
1324 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1325 if (self
->skip_pager
)
1326 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1327 if (self
->fullscreen
)
1328 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1330 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1332 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1334 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1336 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1337 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1339 client_calc_layer(self
);
1342 frame_adjust_state(self
->frame
);
1345 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1350 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1351 Client
*c
= it
->data
;
1352 if (c
== skip
) continue; /* circular? */
1353 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1354 if (client_focused(c
)) return c
;
1359 static void calc_recursive(Client
*self
, StackLayer l
, gboolean raised
)
1367 for (it
= self
->transients
; it
; it
= it
->next
)
1368 calc_recursive(it
->data
, l
, raised
? raised
: l
!= old
);
1370 if (!raised
&& l
!= old
)
1372 stacking_raise(self
);
1375 void client_calc_layer(Client
*self
)
1380 /* transients take on the layer of their parents */
1381 if (self
->transient_for
) {
1382 if (self
->transient_for
!= TRAN_GROUP
) {
1383 self
= self
->transient_for
;
1387 for (it
= self
->group
->members
; it
; it
= it
->next
)
1388 if (it
->data
!= self
&&
1389 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1396 /* is us or one of our transients focused? */
1397 if (client_focused(self
))
1399 else if (search_focus_tree(self
, self
))
1404 if (self
->iconic
) l
= Layer_Icon
;
1405 /* fullscreen windows are only in the fullscreen layer while focused */
1406 else if (self
->fullscreen
&& f
) l
= Layer_Fullscreen
;
1407 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1408 else if (self
->type
== Type_Dock
) {
1409 if (!self
->below
) l
= Layer_Top
;
1410 else l
= Layer_Normal
;
1412 else if (self
->above
) l
= Layer_Above
;
1413 else if (self
->below
) l
= Layer_Below
;
1414 else l
= Layer_Normal
;
1416 calc_recursive(self
, l
, FALSE
);
1419 gboolean
client_should_show(Client
*self
)
1421 if (self
->iconic
) return FALSE
;
1422 else if (!(self
->desktop
== screen_desktop
||
1423 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1424 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1429 static void client_showhide(Client
*self
)
1432 if (client_should_show(self
))
1433 frame_show(self
->frame
);
1435 frame_hide(self
->frame
);
1438 gboolean
client_normal(Client
*self
) {
1439 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1440 self
->type
== Type_Splash
);
1443 static void client_apply_startup_state(Client
*self
)
1445 /* these are in a carefully crafted order.. */
1448 self
->iconic
= FALSE
;
1449 client_iconify(self
, TRUE
, FALSE
);
1451 if (self
->fullscreen
) {
1452 self
->fullscreen
= FALSE
;
1453 client_fullscreen(self
, TRUE
, FALSE
);
1456 self
->shaded
= FALSE
;
1457 client_shade(self
, TRUE
);
1460 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1462 if (self
->max_vert
&& self
->max_horz
) {
1463 self
->max_vert
= self
->max_horz
= FALSE
;
1464 client_maximize(self
, TRUE
, 0, FALSE
);
1465 } else if (self
->max_vert
) {
1466 self
->max_vert
= FALSE
;
1467 client_maximize(self
, TRUE
, 2, FALSE
);
1468 } else if (self
->max_horz
) {
1469 self
->max_horz
= FALSE
;
1470 client_maximize(self
, TRUE
, 1, FALSE
);
1473 /* nothing to do for the other states:
1482 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1483 gboolean user
, gboolean final
)
1485 gboolean moved
= FALSE
, resized
= FALSE
;
1487 /* gets the frame's position */
1488 frame_client_gravity(self
->frame
, &x
, &y
);
1490 /* these positions are frame positions, not client positions */
1492 /* set the size and position if fullscreen */
1493 if (self
->fullscreen
) {
1496 w
= screen_physical_size
.width
;
1497 h
= screen_physical_size
.height
;
1498 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1500 /* set the size and position if maximized */
1501 if (self
->max_horz
) {
1502 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1503 w
= screen_area(self
->desktop
)->width
;
1505 if (self
->max_vert
) {
1506 y
= screen_area(self
->desktop
)->y
;
1507 h
= screen_area(self
->desktop
)->height
-
1508 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1512 /* gets the client's position */
1513 frame_frame_gravity(self
->frame
, &x
, &y
);
1515 /* these override the above states! if you cant move you can't move! */
1517 if (!(self
->functions
& Func_Move
)) {
1521 if (!(self
->functions
& Func_Resize
)) {
1522 w
= self
->area
.width
;
1523 h
= self
->area
.height
;
1527 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1528 w
-= self
->base_size
.width
;
1529 h
-= self
->base_size
.height
;
1532 /* for interactive resizing. have to move half an increment in each
1535 /* how far we are towards the next size inc */
1536 int mw
= w
% self
->size_inc
.width
;
1537 int mh
= h
% self
->size_inc
.height
;
1539 int aw
= self
->size_inc
.width
/ 2;
1540 int ah
= self
->size_inc
.height
/ 2;
1541 /* don't let us move into a new size increment */
1542 if (mw
+ aw
>= self
->size_inc
.width
)
1543 aw
= self
->size_inc
.width
- mw
- 1;
1544 if (mh
+ ah
>= self
->size_inc
.height
)
1545 ah
= self
->size_inc
.height
- mh
- 1;
1549 /* if this is a user-requested resize, then check against min/max
1550 sizes and aspect ratios */
1552 /* smaller than min size or bigger than max size? */
1553 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1554 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1555 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1556 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1558 /* adjust the height ot match the width for the aspect ratios */
1559 if (self
->min_ratio
)
1560 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1561 if (self
->max_ratio
)
1562 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1565 /* keep to the increments */
1566 w
/= self
->size_inc
.width
;
1567 h
/= self
->size_inc
.height
;
1569 /* you cannot resize to nothing */
1573 /* store the logical size */
1574 SIZE_SET(self
->logical_size
, w
, h
);
1576 w
*= self
->size_inc
.width
;
1577 h
*= self
->size_inc
.height
;
1579 w
+= self
->base_size
.width
;
1580 h
+= self
->base_size
.height
;
1584 case Corner_TopLeft
:
1586 case Corner_TopRight
:
1587 x
-= w
- self
->area
.width
;
1589 case Corner_BottomLeft
:
1590 y
-= h
- self
->area
.height
;
1592 case Corner_BottomRight
:
1593 x
-= w
- self
->area
.width
;
1594 y
-= h
- self
->area
.height
;
1598 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1599 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1601 RECT_SET(self
->area
, x
, y
, w
, h
);
1604 XResizeWindow(ob_display
, self
->window
, w
, h
);
1606 /* move/resize the frame to match the request */
1608 if (moved
|| resized
)
1609 frame_adjust_area(self
->frame
, moved
, resized
);
1611 if (!user
|| final
) {
1613 event
.type
= ConfigureNotify
;
1614 event
.xconfigure
.display
= ob_display
;
1615 event
.xconfigure
.event
= self
->window
;
1616 event
.xconfigure
.window
= self
->window
;
1618 /* root window coords with border in mind */
1619 event
.xconfigure
.x
= x
- self
->border_width
+
1620 self
->frame
->size
.left
;
1621 event
.xconfigure
.y
= y
- self
->border_width
+
1622 self
->frame
->size
.top
;
1624 event
.xconfigure
.width
= self
->area
.width
;
1625 event
.xconfigure
.height
= self
->area
.height
;
1626 event
.xconfigure
.border_width
= self
->border_width
;
1627 event
.xconfigure
.above
= self
->frame
->plate
;
1628 event
.xconfigure
.override_redirect
= FALSE
;
1629 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1630 FALSE
, StructureNotifyMask
, &event
);
1635 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1639 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1640 self
->fullscreen
== fs
) return; /* already done */
1642 self
->fullscreen
= fs
;
1643 client_change_state(self
); /* change the state hints on the client,
1644 and adjust out layer/stacking */
1648 guint32 dimensions
[4];
1649 dimensions
[0] = self
->area
.x
;
1650 dimensions
[1] = self
->area
.y
;
1651 dimensions
[2] = self
->area
.width
;
1652 dimensions
[3] = self
->area
.height
;
1654 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1658 /* these are not actually used cuz client_configure will set them
1659 as appropriate when the window is fullscreened */
1665 /* pick some fallbacks... */
1666 x
= screen_area(self
->desktop
)->x
+
1667 screen_area(self
->desktop
)->width
/ 4;
1668 y
= screen_area(self
->desktop
)->y
+
1669 screen_area(self
->desktop
)->height
/ 4;
1670 w
= screen_area(self
->desktop
)->width
/ 2;
1671 h
= screen_area(self
->desktop
)->height
/ 2;
1673 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1674 (guint32
**)&dimensions
, &num
)) {
1685 client_setup_decor_and_functions(self
);
1687 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1689 /* try focus us when we go into fullscreen mode */
1693 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1697 /* move up the transient chain as far as possible first if deiconifying */
1699 while (self
->transient_for
) {
1700 if (self
->transient_for
!= TRAN_GROUP
) {
1701 if (self
->transient_for
->iconic
== iconic
)
1703 self
= self
->transient_for
;
1707 /* the check for TRAN_GROUP is to prevent an infinate loop with
1708 2 transients of the same group at the head of the group's
1710 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1711 Client
*c
= it
->data
;
1713 if (c
!= self
&& c
->transient_for
->iconic
!= iconic
&&
1714 c
->transient_for
!= TRAN_GROUP
) {
1719 if (it
== NULL
) break;
1723 if (self
->iconic
== iconic
) return; /* nothing to do */
1725 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1728 self
->iconic
= iconic
;
1731 self
->wmstate
= IconicState
;
1732 self
->ignore_unmaps
++;
1733 /* we unmap the client itself so that we can get MapRequest events,
1734 and because the ICCCM tells us to! */
1735 XUnmapWindow(ob_display
, self
->window
);
1737 /* update the focus lists.. iconic windows go to the bottom */
1738 focus_order_to_bottom(self
);
1741 client_set_desktop(self
, screen_desktop
, FALSE
);
1742 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1743 XMapWindow(ob_display
, self
->window
);
1745 client_change_state(self
);
1746 client_showhide(self
);
1747 screen_update_struts();
1749 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1752 /* iconify all transients */
1753 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1754 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1757 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1761 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1762 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1764 /* check if already done */
1766 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1767 if (dir
== 1 && self
->max_horz
) return;
1768 if (dir
== 2 && self
->max_vert
) return;
1770 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1771 if (dir
== 1 && !self
->max_horz
) return;
1772 if (dir
== 2 && !self
->max_vert
) return;
1775 /* work with the frame's coords */
1776 x
= self
->frame
->area
.x
;
1777 y
= self
->frame
->area
.y
;
1778 w
= self
->area
.width
;
1779 h
= self
->area
.height
;
1783 gint32 dimensions
[4];
1792 /* get the property off the window and use it for the dimensions
1793 we are already maxed on */
1794 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1795 (guint32
**)&readdim
, &num
)) {
1797 if (self
->max_horz
) {
1798 dimensions
[0] = readdim
[0];
1799 dimensions
[2] = readdim
[2];
1801 if (self
->max_vert
) {
1802 dimensions
[1] = readdim
[1];
1803 dimensions
[3] = readdim
[3];
1809 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1810 (guint32
*)dimensions
, 4);
1816 /* pick some fallbacks... */
1817 if (dir
== 0 || dir
== 1) { /* horz */
1818 x
= screen_area(self
->desktop
)->x
+
1819 screen_area(self
->desktop
)->width
/ 4;
1820 w
= screen_area(self
->desktop
)->width
/ 2;
1822 if (dir
== 0 || dir
== 2) { /* vert */
1823 y
= screen_area(self
->desktop
)->y
+
1824 screen_area(self
->desktop
)->height
/ 4;
1825 h
= screen_area(self
->desktop
)->height
/ 2;
1828 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1829 (guint32
**)&dimensions
, &num
)) {
1831 if (dir
== 0 || dir
== 1) { /* horz */
1835 if (dir
== 0 || dir
== 2) { /* vert */
1844 if (dir
== 0 || dir
== 1) /* horz */
1845 self
->max_horz
= max
;
1846 if (dir
== 0 || dir
== 2) /* vert */
1847 self
->max_vert
= max
;
1849 if (!self
->max_horz
&& !self
->max_vert
)
1850 PROP_ERASE(self
->window
, openbox_premax
);
1852 client_change_state(self
); /* change the state hints on the client */
1854 /* figure out where the client should be going */
1855 frame_frame_gravity(self
->frame
, &x
, &y
);
1856 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1859 void client_shade(Client
*self
, gboolean shade
)
1861 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1862 self
->shaded
== shade
) return; /* already done */
1864 /* when we're iconic, don't change the wmstate */
1866 self
->wmstate
= shade
? IconicState
: NormalState
;
1867 self
->shaded
= shade
;
1868 client_change_state(self
);
1869 /* resize the frame to just the titlebar */
1870 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1873 void client_close(Client
*self
)
1877 if (!(self
->functions
& Func_Close
)) return;
1880 XXX: itd be cool to do timeouts and shit here for killing the client's
1882 like... if the window is around after 5 seconds, then the close button
1883 turns a nice red, and if this function is called again, the client is
1887 ce
.xclient
.type
= ClientMessage
;
1888 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1889 ce
.xclient
.display
= ob_display
;
1890 ce
.xclient
.window
= self
->window
;
1891 ce
.xclient
.format
= 32;
1892 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1893 ce
.xclient
.data
.l
[1] = event_lasttime
;
1894 ce
.xclient
.data
.l
[2] = 0l;
1895 ce
.xclient
.data
.l
[3] = 0l;
1896 ce
.xclient
.data
.l
[4] = 0l;
1897 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1900 void client_kill(Client
*self
)
1902 XKillClient(ob_display
, self
->window
);
1905 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1909 if (target
== self
->desktop
) return;
1911 g_message("Setting desktop %u", target
);
1913 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1915 /* remove from the old desktop(s) */
1916 focus_order_remove(self
);
1918 old
= self
->desktop
;
1919 self
->desktop
= target
;
1920 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1921 /* the frame can display the current desktop state */
1922 frame_adjust_state(self
->frame
);
1923 /* 'move' the window to the new desktop */
1925 client_showhide(self
);
1926 /* raise if it was not already on the desktop */
1927 if (old
!= DESKTOP_ALL
)
1928 stacking_raise(self
);
1929 screen_update_struts();
1931 /* add to the new desktop(s) */
1932 if (config_focus_new
)
1933 focus_order_to_top(self
);
1935 focus_order_to_bottom(self
);
1937 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1940 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1945 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1946 Client
*c
= it
->data
;
1947 if (c
== skip
) continue; /* circular? */
1948 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1949 if (c
->modal
) return c
;
1954 Client
*client_find_modal_child(Client
*self
)
1956 return search_modal_tree(self
, self
);
1959 gboolean
client_validate(Client
*self
)
1963 XSync(ob_display
, FALSE
); /* get all events on the server */
1965 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1966 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1967 XPutBackEvent(ob_display
, &e
);
1974 void client_set_wm_state(Client
*self
, long state
)
1976 if (state
== self
->wmstate
) return; /* no change */
1980 client_iconify(self
, TRUE
, TRUE
);
1983 client_iconify(self
, FALSE
, TRUE
);
1988 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1990 gboolean shaded
= self
->shaded
;
1991 gboolean fullscreen
= self
->fullscreen
;
1992 gboolean max_horz
= self
->max_horz
;
1993 gboolean max_vert
= self
->max_vert
;
1996 if (!(action
== prop_atoms
.net_wm_state_add
||
1997 action
== prop_atoms
.net_wm_state_remove
||
1998 action
== prop_atoms
.net_wm_state_toggle
))
1999 /* an invalid action was passed to the client message, ignore it */
2002 for (i
= 0; i
< 2; ++i
) {
2003 Atom state
= i
== 0 ? data1
: data2
;
2005 if (!state
) continue;
2007 /* if toggling, then pick whether we're adding or removing */
2008 if (action
== prop_atoms
.net_wm_state_toggle
) {
2009 if (state
== prop_atoms
.net_wm_state_modal
)
2010 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2011 prop_atoms
.net_wm_state_add
;
2012 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2013 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2014 prop_atoms
.net_wm_state_add
;
2015 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2016 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2017 prop_atoms
.net_wm_state_add
;
2018 else if (state
== prop_atoms
.net_wm_state_shaded
)
2019 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2020 prop_atoms
.net_wm_state_add
;
2021 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2022 action
= self
->skip_taskbar
?
2023 prop_atoms
.net_wm_state_remove
:
2024 prop_atoms
.net_wm_state_add
;
2025 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2026 action
= self
->skip_pager
?
2027 prop_atoms
.net_wm_state_remove
:
2028 prop_atoms
.net_wm_state_add
;
2029 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2030 action
= self
->fullscreen
?
2031 prop_atoms
.net_wm_state_remove
:
2032 prop_atoms
.net_wm_state_add
;
2033 else if (state
== prop_atoms
.net_wm_state_above
)
2034 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2035 prop_atoms
.net_wm_state_add
;
2036 else if (state
== prop_atoms
.net_wm_state_below
)
2037 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2038 prop_atoms
.net_wm_state_add
;
2041 if (action
== prop_atoms
.net_wm_state_add
) {
2042 if (state
== prop_atoms
.net_wm_state_modal
) {
2043 /* XXX raise here or something? */
2045 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2047 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2049 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2051 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2052 self
->skip_taskbar
= TRUE
;
2053 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2054 self
->skip_pager
= TRUE
;
2055 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2057 } else if (state
== prop_atoms
.net_wm_state_above
) {
2059 } else if (state
== prop_atoms
.net_wm_state_below
) {
2063 } else { /* action == prop_atoms.net_wm_state_remove */
2064 if (state
== prop_atoms
.net_wm_state_modal
) {
2065 self
->modal
= FALSE
;
2066 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2068 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2070 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2072 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2073 self
->skip_taskbar
= FALSE
;
2074 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2075 self
->skip_pager
= FALSE
;
2076 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2078 } else if (state
== prop_atoms
.net_wm_state_above
) {
2079 self
->above
= FALSE
;
2080 } else if (state
== prop_atoms
.net_wm_state_below
) {
2081 self
->below
= FALSE
;
2085 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2086 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2088 if (max_horz
== max_vert
) { /* both going the same way */
2089 client_maximize(self
, max_horz
, 0, TRUE
);
2091 client_maximize(self
, max_horz
, 1, TRUE
);
2092 client_maximize(self
, max_vert
, 2, TRUE
);
2096 if (max_horz
!= self
->max_horz
)
2097 client_maximize(self
, max_horz
, 1, TRUE
);
2099 client_maximize(self
, max_vert
, 2, TRUE
);
2102 /* change fullscreen state before shading, as it will affect if the window
2104 if (fullscreen
!= self
->fullscreen
)
2105 client_fullscreen(self
, fullscreen
, TRUE
);
2106 if (shaded
!= self
->shaded
)
2107 client_shade(self
, shaded
);
2108 client_calc_layer(self
);
2109 client_change_state(self
); /* change the hint to relect these changes */
2112 Client
*client_focus_target(Client
*self
)
2116 /* if we have a modal child, then focus it, not us */
2117 child
= client_find_modal_child(self
);
2118 if (child
) return child
;
2122 gboolean
client_focus(Client
*self
)
2126 /* choose the correct target */
2127 self
= client_focus_target(self
);
2129 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2130 /* update the focus lists */
2131 focus_order_to_top(self
);
2135 if (!((self
->can_focus
|| self
->focus_notify
) &&
2136 (self
->desktop
== screen_desktop
||
2137 self
->desktop
== DESKTOP_ALL
) &&
2141 /* do a check to see if the window has already been unmapped or destroyed
2142 do this intelligently while watching out for unmaps we've generated
2143 (ignore_unmaps > 0) */
2144 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2145 DestroyNotify
, &ev
)) {
2146 XPutBackEvent(ob_display
, &ev
);
2149 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2150 UnmapNotify
, &ev
)) {
2151 if (self
->ignore_unmaps
) {
2152 self
->ignore_unmaps
--;
2154 XPutBackEvent(ob_display
, &ev
);
2159 if (self
->can_focus
)
2160 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2161 I choose to use it always, hopefully to find errors quicker, if any
2162 are left. (I hate X. I hate focus events.) */
2163 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2166 if (self
->focus_notify
) {
2168 ce
.xclient
.type
= ClientMessage
;
2169 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2170 ce
.xclient
.display
= ob_display
;
2171 ce
.xclient
.window
= self
->window
;
2172 ce
.xclient
.format
= 32;
2173 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2174 ce
.xclient
.data
.l
[1] = event_lasttime
;
2175 ce
.xclient
.data
.l
[2] = 0l;
2176 ce
.xclient
.data
.l
[3] = 0l;
2177 ce
.xclient
.data
.l
[4] = 0l;
2178 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2182 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2187 /* Cause the FocusIn to come back to us. Important for desktop switches,
2188 since otherwise we'll have no FocusIn on the queue and send it off to
2189 the focus_backup. */
2190 XSync(ob_display
, FALSE
);
2194 void client_unfocus(Client
*self
)
2196 g_assert(focus_client
== self
);
2198 g_message("client_unfocus for %lx", self
->window
);
2200 focus_fallback(Fallback_Unfocusing
);
2203 gboolean
client_focused(Client
*self
)
2205 return self
== focus_client
;
2208 Icon
*client_icon(Client
*self
, int w
, int h
)
2211 /* si is the smallest image >= req */
2212 /* li is the largest image < req */
2213 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2215 if (!self
->nicons
) return NULL
;
2217 for (i
= 0; i
< self
->nicons
; ++i
) {
2218 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2219 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2223 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2228 if (largest
== 0) /* didnt find one smaller than the requested size */
2229 return &self
->icons
[si
];
2230 return &self
->icons
[li
];