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; */
160 /* check if it has already been unmapped by the time we started mapping
161 the grab does a sync so we don't have to here */
162 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
163 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
164 XPutBackEvent(ob_display
, &e
);
167 return; /* don't manage it */
170 /* make sure it isn't an override-redirect window */
171 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
172 attrib
.override_redirect
) {
174 return; /* don't manage it */
177 /* /\* is the window a docking app *\/
178 if ((wmhint = XGetWMHints(ob_display, window))) {
179 if ((wmhint->flags & StateHint) &&
180 wmhint->initial_state == WithdrawnState) {
181 /\* XXX: make dock apps work! *\/
189 g_message("Managing window: %lx", window
);
191 /* choose the events we want to receive on the CLIENT window */
192 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
193 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
194 XChangeWindowAttributes(ob_display
, window
,
195 CWEventMask
|CWDontPropagate
, &attrib_set
);
198 /* create the Client struct, and populate it from the hints on the
200 self
= g_new(Client
, 1);
201 self
->window
= window
;
202 client_get_all(self
);
204 /* remove the client's border (and adjust re gravity) */
205 client_toggle_border(self
, FALSE
);
207 /* specify that if we exit, the window should not be destroyed and should
208 be reparented back to root automatically */
209 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
211 /* create the decoration frame for the client window */
212 self
->frame
= frame_new();
214 frame_grab_client(self
->frame
, self
);
216 client_apply_startup_state(self
);
220 client_list
= g_list_append(client_list
, self
);
221 stacking_list
= g_list_append(stacking_list
, self
);
222 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
223 g_hash_table_insert(client_map
, &self
->window
, self
);
225 /* update the focus lists */
226 if (self
->desktop
== DESKTOP_ALL
) {
227 for (i
= 0; i
< screen_num_desktops
; ++i
)
228 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
231 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
234 stacking_raise(self
);
236 screen_update_struts();
238 dispatch_client(Event_Client_New
, self
, 0, 0);
240 client_showhide(self
);
242 /* focus the new window? */
243 if (ob_state
!= State_Starting
&& client_normal(self
)) {
246 if (self
->transient_for
) {
247 if (self
->transient_for
!= TRAN_GROUP
) {/* transient of a window */
248 if (focus_client
== self
->transient_for
) {
252 } else { /* transient of a group */
255 for (it
= self
->group
->members
; it
; it
= it
->next
)
256 if (focus_client
== it
->data
) {
263 /* note the check against Type_Normal, not client_normal(self), which
264 would also include dialog types. in this case we want more strict
266 if (!f
&& config_focus_new
&& self
->type
== Type_Normal
)
270 /* update the list hints */
273 /* make sure the window is visible */
274 client_move_onscreen(self
);
276 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
278 g_message("Managed window 0x%lx", window
);
281 void client_unmanage_all()
283 while (client_list
!= NULL
)
284 client_unmanage(client_list
->data
);
287 void client_unmanage(Client
*self
)
293 g_message("Unmanaging window: %lx", self
->window
);
295 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
296 g_assert(self
!= NULL
);
298 /* remove the window from our save set */
299 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
301 /* we dont want events no more */
302 XSelectInput(ob_display
, self
->window
, NoEventMask
);
304 frame_hide(self
->frame
);
306 client_list
= g_list_remove(client_list
, self
);
307 stacking_list
= g_list_remove(stacking_list
, self
);
308 g_hash_table_remove(client_map
, &self
->window
);
310 /* update the focus lists */
311 if (self
->desktop
== DESKTOP_ALL
) {
312 for (i
= 0; i
< screen_num_desktops
; ++i
)
313 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
316 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
319 /* once the client is out of the list, update the struts to remove it's
321 screen_update_struts();
323 /* tell our parent(s) that we're gone */
324 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
327 for (it
= self
->group
->members
; it
; it
= it
->next
)
328 if (it
->data
!= self
)
329 ((Client
*)it
->data
)->transients
=
330 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
331 } else if (self
->transient_for
) { /* transient of window */
332 self
->transient_for
->transients
=
333 g_slist_remove(self
->transient_for
->transients
, self
);
336 /* tell our transients that we're gone */
337 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
338 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
339 ((Client
*)it
->data
)->transient_for
= NULL
;
340 client_calc_layer(it
->data
);
344 if (moveresize_client
== self
)
345 moveresize_end(TRUE
);
347 if (focus_client
== self
)
348 client_unfocus(self
);
350 /* remove from its group */
352 group_remove(self
->group
, self
);
356 /* dispatch the unmapped event */
357 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
358 g_assert(self
!= NULL
);
360 /* give the client its border back */
361 client_toggle_border(self
, TRUE
);
363 /* reparent the window out of the frame, and free the frame */
364 frame_release_client(self
->frame
, self
);
367 if (ob_state
!= State_Exiting
) {
368 /* these values should not be persisted across a window
370 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
371 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
373 /* if we're left in an iconic state, the client wont be mapped. this is
374 bad, since we will no longer be managing the window on restart */
376 XMapWindow(ob_display
, self
->window
);
379 g_message("Unmanaged window 0x%lx", self
->window
);
381 /* free all data allocated in the client struct */
382 g_slist_free(self
->transients
);
383 for (j
= 0; j
< self
->nicons
; ++j
)
384 g_free(self
->icons
[j
].data
);
385 if (self
->nicons
> 0)
388 g_free(self
->icon_title
);
394 /* update the list hints */
398 static void client_move_onscreen(Client
*self
)
401 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
403 a
= screen_area(self
->desktop
);
404 if (x
>= a
->x
+ a
->width
- 1)
405 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
406 if (y
>= a
->y
+ a
->height
- 1)
407 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
408 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
410 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
413 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
415 client_configure(self
, Corner_TopLeft
, x
, y
,
416 self
->area
.width
, self
->area
.height
,
420 static void client_toggle_border(Client
*self
, gboolean show
)
422 /* adjust our idea of where the client is, based on its border. When the
423 border is removed, the client should now be considered to be in a
425 when re-adding the border to the client, the same operation needs to be
427 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
428 int x
= oldx
, y
= oldy
;
429 switch(self
->gravity
) {
431 case NorthWestGravity
:
433 case SouthWestGravity
:
435 case NorthEastGravity
:
437 case SouthEastGravity
:
438 if (show
) x
-= self
->border_width
* 2;
439 else x
+= self
->border_width
* 2;
446 if (show
) x
-= self
->border_width
;
447 else x
+= self
->border_width
;
450 switch(self
->gravity
) {
452 case NorthWestGravity
:
454 case NorthEastGravity
:
456 case SouthWestGravity
:
458 case SouthEastGravity
:
459 if (show
) y
-= self
->border_width
* 2;
460 else y
+= self
->border_width
* 2;
467 if (show
) y
-= self
->border_width
;
468 else y
+= self
->border_width
;
475 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
477 /* move the client so it is back it the right spot _with_ its
479 if (x
!= oldx
|| y
!= oldy
)
480 XMoveWindow(ob_display
, self
->window
, x
, y
);
482 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
486 static void client_get_all(Client
*self
)
488 /* update EVERYTHING!! */
490 self
->ignore_unmaps
= 0;
494 self
->title
= self
->icon_title
= NULL
;
495 self
->name
= self
->class = self
->role
= NULL
;
496 self
->wmstate
= NormalState
;
497 self
->transient
= FALSE
;
498 self
->transients
= NULL
;
499 self
->transient_for
= NULL
;
501 self
->urgent
= FALSE
;
502 self
->positioned
= FALSE
;
503 self
->disabled_decorations
= 0;
507 client_get_area(self
);
508 client_update_transient_for(self
);
509 client_update_wmhints(self
);
510 client_get_desktop(self
);
511 client_get_state(self
);
512 client_get_shaped(self
);
514 client_get_mwm_hints(self
);
515 client_get_type(self
);/* this can change the mwmhints for special cases */
517 client_update_protocols(self
);
519 client_get_gravity(self
); /* get the attribute gravity */
520 client_update_normal_hints(self
); /* this may override the attribute
523 /* got the type, the mwmhints, the protocols, and the normal hints
524 (min/max sizes), so we're ready to set up the decorations/functions */
525 client_setup_decor_and_functions(self
);
527 client_update_title(self
);
528 client_update_icon_title(self
);
529 client_update_class(self
);
530 client_update_strut(self
);
531 client_update_icons(self
);
532 client_update_kwm_icon(self
);
534 client_change_state(self
);
537 static void client_get_area(Client
*self
)
539 XWindowAttributes wattrib
;
542 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
543 g_assert(ret
!= BadWindow
);
545 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
546 self
->border_width
= wattrib
.border_width
;
549 static void client_get_desktop(Client
*self
)
553 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
554 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
555 d
= screen_num_desktops
- 1;
558 gboolean trdesk
= FALSE
;
560 if (self
->transient_for
) {
561 if (self
->transient_for
!= TRAN_GROUP
) {
562 self
->desktop
= self
->transient_for
->desktop
;
567 for (it
= self
->group
->members
; it
; it
= it
->next
)
568 if (it
->data
!= self
&&
569 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
570 self
->desktop
= ((Client
*)it
->data
)->desktop
;
577 /* defaults to the current desktop */
578 self
->desktop
= screen_desktop
;
580 /* set the desktop hint, to make sure that it always exists */
581 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
585 static void client_get_state(Client
*self
)
590 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
591 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
592 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
594 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
596 for (i
= 0; i
< num
; ++i
) {
597 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
599 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
601 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
603 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
604 self
->skip_taskbar
= TRUE
;
605 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
606 self
->skip_pager
= TRUE
;
607 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
608 self
->fullscreen
= TRUE
;
609 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
610 self
->max_vert
= TRUE
;
611 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
612 self
->max_horz
= TRUE
;
613 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
615 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
623 static void client_get_shaped(Client
*self
)
625 self
->shaped
= FALSE
;
627 if (extensions_shape
) {
632 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
634 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
635 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
637 self
->shaped
= (s
!= 0);
642 void client_update_transient_for(Client
*self
)
647 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
648 t
!= self
->window
) { /* cant be transient to itself! */
649 self
->transient
= TRUE
;
650 c
= g_hash_table_lookup(client_map
, &t
);
651 g_assert(c
!= self
);/* if this happens then we need to check for it*/
653 if (!c
&& self
->group
) {
654 /* not transient to a client, see if it is transient for a
656 if (t
== self
->group
->leader
||
659 /* window is a transient for its group! */
664 self
->transient
= FALSE
;
666 /* if anything has changed... */
667 if (c
!= self
->transient_for
) {
668 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
671 /* remove from old parents */
672 for (it
= self
->group
->members
; it
; it
= it
->next
)
673 if (it
->data
!= self
)
674 ((Client
*)it
->data
)->transients
=
675 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
676 } else if (self
->transient_for
!= NULL
) { /* transient of window */
677 /* remove from old parent */
678 self
->transient_for
->transients
=
679 g_slist_remove(self
->transient_for
->transients
, self
);
681 self
->transient_for
= c
;
682 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
685 /* add to new parents */
686 for (it
= self
->group
->members
; it
; it
= it
->next
)
687 if (it
->data
!= self
)
688 ((Client
*)it
->data
)->transients
=
689 g_slist_append(((Client
*)it
->data
)->transients
, self
);
690 } else if (self
->transient_for
!= NULL
) { /* transient of window */
691 /* add to new parent */
692 self
->transient_for
->transients
=
693 g_slist_append(self
->transient_for
->transients
, self
);
698 static void client_get_mwm_hints(Client
*self
)
703 self
->mwmhints
.flags
= 0; /* default to none */
705 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
707 if (num
>= MWM_ELEMENTS
) {
708 self
->mwmhints
.flags
= hints
[0];
709 self
->mwmhints
.functions
= hints
[1];
710 self
->mwmhints
.decorations
= hints
[2];
716 void client_get_type(Client
*self
)
723 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
724 /* use the first value that we know about in the array */
725 for (i
= 0; i
< num
; ++i
) {
726 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
727 self
->type
= Type_Desktop
;
728 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
729 self
->type
= Type_Dock
;
730 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
731 self
->type
= Type_Toolbar
;
732 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
733 self
->type
= Type_Menu
;
734 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
735 self
->type
= Type_Utility
;
736 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
737 self
->type
= Type_Splash
;
738 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
739 self
->type
= Type_Dialog
;
740 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
741 self
->type
= Type_Normal
;
742 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
743 /* prevent this window from getting any decor or
745 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
746 MwmFlag_Decorations
);
747 self
->mwmhints
.decorations
= 0;
748 self
->mwmhints
.functions
= 0;
750 if (self
->type
!= (WindowType
) -1)
751 break; /* grab the first legit type */
756 if (self
->type
== (WindowType
) -1) {
757 /*the window type hint was not set, which means we either classify
758 ourself as a normal window or a dialog, depending on if we are a
761 self
->type
= Type_Dialog
;
763 self
->type
= Type_Normal
;
766 /* this makes sure that these windows appear on all desktops */
767 if (self
->type
== Type_Desktop
)
768 self
->desktop
= DESKTOP_ALL
;
771 void client_update_protocols(Client
*self
)
776 self
->focus_notify
= FALSE
;
777 self
->delete_window
= FALSE
;
779 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
780 for (i
= 0; i
< num_return
; ++i
) {
781 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
782 /* this means we can request the window to close */
783 self
->delete_window
= TRUE
;
784 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
785 /* if this protocol is requested, then the window will be
786 notified whenever we want it to receive focus */
787 self
->focus_notify
= TRUE
;
793 static void client_get_gravity(Client
*self
)
795 XWindowAttributes wattrib
;
798 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
799 g_assert(ret
!= BadWindow
);
800 self
->gravity
= wattrib
.win_gravity
;
803 void client_update_normal_hints(Client
*self
)
807 int oldgravity
= self
->gravity
;
810 self
->min_ratio
= 0.0f
;
811 self
->max_ratio
= 0.0f
;
812 SIZE_SET(self
->size_inc
, 1, 1);
813 SIZE_SET(self
->base_size
, 0, 0);
814 SIZE_SET(self
->min_size
, 0, 0);
815 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
817 /* get the hints from the window */
818 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
819 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
821 if (size
.flags
& PWinGravity
) {
822 self
->gravity
= size
.win_gravity
;
824 /* if the client has a frame, i.e. has already been mapped and
825 is changing its gravity */
826 if (self
->frame
&& self
->gravity
!= oldgravity
) {
827 /* move our idea of the client's position based on its new
829 self
->area
.x
= self
->frame
->area
.x
;
830 self
->area
.y
= self
->frame
->area
.y
;
831 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
835 if (size
.flags
& PAspect
) {
836 if (size
.min_aspect
.y
)
837 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
838 if (size
.max_aspect
.y
)
839 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
842 if (size
.flags
& PMinSize
)
843 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
845 if (size
.flags
& PMaxSize
)
846 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
848 if (size
.flags
& PBaseSize
)
849 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
851 if (size
.flags
& PResizeInc
)
852 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
856 void client_setup_decor_and_functions(Client
*self
)
858 /* start with everything (cept fullscreen) */
859 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
860 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
862 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
864 if (self
->delete_window
) {
865 self
->decorations
|= Decor_Close
;
866 self
->functions
|= Func_Close
;
869 if (!(self
->min_size
.width
< self
->max_size
.width
||
870 self
->min_size
.height
< self
->max_size
.height
)) {
871 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
872 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
875 switch (self
->type
) {
877 /* normal windows retain all of the possible decorations and
878 functionality, and are the only windows that you can fullscreen */
879 self
->functions
|= Func_Fullscreen
;
884 /* these windows cannot be maximized */
885 self
->decorations
&= ~Decor_Maximize
;
886 self
->functions
&= ~Func_Maximize
;
891 /* these windows get less functionality */
892 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
893 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
899 /* none of these windows are manipulated by the window manager */
900 self
->decorations
= 0;
905 /* Mwm Hints are applied subtractively to what has already been chosen for
906 decor and functionality */
907 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
908 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
909 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
910 self
->decorations
&= ~Decor_Border
;
911 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
912 self
->decorations
&= ~Decor_Handle
;
913 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
914 self
->decorations
&= ~Decor_Titlebar
;
915 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
916 self
->decorations
&= ~Decor_Iconify
;
917 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
918 self
->decorations
&= ~Decor_Maximize
;
922 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
923 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
924 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
925 self
->functions
&= ~Func_Resize
;
926 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
927 self
->functions
&= ~Func_Move
;
928 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
929 self
->functions
&= ~Func_Iconify
;
930 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
931 self
->functions
&= ~Func_Maximize
;
932 /* dont let mwm hints kill the close button
933 if (! (self->mwmhints.functions & MwmFunc_Close))
934 self->functions &= ~Func_Close; */
938 /* can't maximize without moving/resizing */
939 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
940 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
942 /* finally, user specified disabled decorations are applied to subtract
944 if (self
->disabled_decorations
& Decor_Titlebar
)
945 self
->decorations
&= ~Decor_Titlebar
;
946 if (self
->disabled_decorations
& Decor_Handle
)
947 self
->decorations
&= ~Decor_Handle
;
948 if (self
->disabled_decorations
& Decor_Border
)
949 self
->decorations
&= ~Decor_Border
;
950 if (self
->disabled_decorations
& Decor_Iconify
)
951 self
->decorations
&= ~Decor_Iconify
;
952 if (self
->disabled_decorations
& Decor_Maximize
)
953 self
->decorations
&= ~Decor_Maximize
;
954 if (self
->disabled_decorations
& Decor_AllDesktops
)
955 self
->decorations
&= ~Decor_AllDesktops
;
956 if (self
->disabled_decorations
& Decor_Shade
)
957 self
->decorations
&= ~Decor_Shade
;
958 if (self
->disabled_decorations
& Decor_Close
)
959 self
->decorations
&= ~Decor_Close
;
961 /* if we don't have a titlebar, then we cannot shade! */
962 if (!(self
->decorations
& Decor_Titlebar
))
963 self
->functions
&= ~Func_Shade
;
965 /* now we need to check against rules for the client's current state */
966 if (self
->fullscreen
) {
967 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
968 self
->decorations
= 0;
971 client_change_allowed_actions(self
);
974 /* change the decors on the frame, and with more/less decorations,
975 we may also need to be repositioned */
976 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
977 /* with new decor, the window's maximized size may change */
978 client_remaximize(self
);
982 static void client_change_allowed_actions(Client
*self
)
987 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
989 if (self
->functions
& Func_Shade
)
990 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
991 if (self
->functions
& Func_Close
)
992 actions
[num
++] = prop_atoms
.net_wm_action_close
;
993 if (self
->functions
& Func_Move
)
994 actions
[num
++] = prop_atoms
.net_wm_action_move
;
995 if (self
->functions
& Func_Iconify
)
996 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
997 if (self
->functions
& Func_Resize
)
998 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
999 if (self
->functions
& Func_Fullscreen
)
1000 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1001 if (self
->functions
& Func_Maximize
) {
1002 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1003 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1006 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1008 /* make sure the window isn't breaking any rules now */
1010 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1011 if (self
->frame
) client_shade(self
, FALSE
);
1012 else self
->shaded
= FALSE
;
1014 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1015 g_message("UNSETTING ICONIC");
1016 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1017 else self
->iconic
= FALSE
;
1019 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1020 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1021 else self
->fullscreen
= FALSE
;
1023 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1025 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1026 else self
->max_vert
= self
->max_horz
= FALSE
;
1030 void client_remaximize(Client
*self
)
1033 if (self
->max_horz
&& self
->max_vert
)
1035 else if (self
->max_horz
)
1037 else if (self
->max_vert
)
1040 return; /* not maximized */
1041 self
->max_horz
= self
->max_vert
= FALSE
;
1042 client_maximize(self
, TRUE
, dir
, FALSE
);
1045 void client_update_wmhints(Client
*self
)
1048 gboolean ur
= FALSE
;
1051 /* assume a window takes input if it doesnt specify */
1052 self
->can_focus
= TRUE
;
1054 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1055 if (hints
->flags
& InputHint
)
1056 self
->can_focus
= hints
->input
;
1058 /* only do this when first managing the window *AND* when we aren't
1060 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1061 if (hints
->flags
& StateHint
)
1062 self
->iconic
= hints
->initial_state
== IconicState
;
1064 if (hints
->flags
& XUrgencyHint
)
1067 if (!(hints
->flags
& WindowGroupHint
))
1068 hints
->window_group
= None
;
1070 /* did the group state change? */
1071 if (hints
->window_group
!=
1072 (self
->group
? self
->group
->leader
: None
)) {
1073 /* remove from the old group if there was one */
1074 if (self
->group
!= NULL
) {
1075 /* remove transients of the group */
1076 for (it
= self
->group
->members
; it
; it
= it
->next
)
1077 if (it
->data
!= self
&&
1078 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
) {
1079 self
->transients
= g_slist_remove(self
->transients
,
1082 group_remove(self
->group
, self
);
1085 if (hints
->window_group
!= None
) {
1086 self
->group
= group_add(hints
->window_group
, self
);
1088 /* add other transients of the group that are already
1090 for (it
= self
->group
->members
; it
; it
= it
->next
)
1091 if (it
->data
!= self
&&
1092 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1093 self
->transients
= g_slist_append(self
->transients
,
1097 /* because the self->transient flag wont change from this call,
1098 we don't need to update the window's type and such, only its
1099 transient_for, and the transients lists of other windows in
1100 the group may be affected */
1101 client_update_transient_for(self
);
1104 client_update_kwm_icon(self
);
1105 /* try get the kwm icon first, this is a fallback only */
1106 if (self
->pixmap_icon
== None
) {
1107 if (hints
->flags
& IconPixmapHint
) {
1108 if (self
->pixmap_icon
== None
) {
1109 self
->pixmap_icon
= hints
->icon_pixmap
;
1110 if (hints
->flags
& IconMaskHint
)
1111 self
->pixmap_icon_mask
= hints
->icon_mask
;
1113 self
->pixmap_icon_mask
= None
;
1116 frame_adjust_icon(self
->frame
);
1124 if (ur
!= self
->urgent
) {
1126 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1128 /* fire the urgent callback if we're mapped, otherwise, wait until
1129 after we're mapped */
1131 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1135 void client_update_title(Client
*self
)
1139 g_free(self
->title
);
1142 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1143 /* try old x stuff */
1144 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1145 data
= g_strdup("Unnamed Window");
1147 /* look for duplicates and append a number */
1149 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1154 frame_adjust_title(self
->frame
);
1157 void client_update_icon_title(Client
*self
)
1161 g_free(self
->icon_title
);
1164 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1165 /* try old x stuff */
1166 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
))
1167 data
= g_strdup("Unnamed Window");
1169 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1171 self
->icon_title
= data
;
1174 void client_update_class(Client
*self
)
1179 if (self
->name
) g_free(self
->name
);
1180 if (self
->class) g_free(self
->class);
1181 if (self
->role
) g_free(self
->role
);
1183 self
->name
= self
->class = self
->role
= NULL
;
1185 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1187 self
->name
= g_strdup(data
[0]);
1189 self
->class = g_strdup(data
[1]);
1194 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1195 self
->role
= g_strdup(s
);
1197 if (self
->name
== NULL
) self
->name
= g_strdup("");
1198 if (self
->class == NULL
) self
->class = g_strdup("");
1199 if (self
->role
== NULL
) self
->role
= g_strdup("");
1202 void client_update_strut(Client
*self
)
1207 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1208 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1211 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1213 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1217 /* updating here is pointless while we're being mapped cuz we're not in
1218 the client list yet */
1220 screen_update_struts();
1223 void client_update_icons(Client
*self
)
1230 for (j
= 0; j
< self
->nicons
; ++j
)
1231 g_free(self
->icons
[j
].data
);
1232 if (self
->nicons
> 0)
1233 g_free(self
->icons
);
1236 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1237 /* figure out how many valid icons are in here */
1239 while (num
- i
> 2) {
1247 self
->icons
= g_new(Icon
, self
->nicons
);
1249 /* store the icons */
1251 for (j
= 0; j
< self
->nicons
; ++j
) {
1252 w
= self
->icons
[j
].width
= data
[i
++];
1253 h
= self
->icons
[j
].height
= data
[i
++];
1254 self
->icons
[j
].data
=
1255 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1264 frame_adjust_icon(self
->frame
);
1267 void client_update_kwm_icon(Client
*self
)
1272 if (!PROP_GETA32(self
->window
, kwm_win_icon
, kwm_win_icon
, &data
, &num
)) {
1273 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1276 self
->pixmap_icon
= data
[0];
1277 self
->pixmap_icon_mask
= data
[1];
1279 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1283 frame_adjust_icon(self
->frame
);
1286 static void client_change_state(Client
*self
)
1289 guint32 netstate
[10];
1292 state
[0] = self
->wmstate
;
1294 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1298 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1300 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1302 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1303 if (self
->skip_taskbar
)
1304 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1305 if (self
->skip_pager
)
1306 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1307 if (self
->fullscreen
)
1308 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1310 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1312 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1314 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1316 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1317 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1319 client_calc_layer(self
);
1322 frame_adjust_state(self
->frame
);
1325 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1330 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1331 Client
*c
= it
->data
;
1332 if (c
== skip
) continue; /* circular? */
1333 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1334 if (client_focused(c
)) return c
;
1339 static void calc_recursive(Client
*self
, StackLayer l
, gboolean raised
)
1347 for (it
= self
->transients
; it
; it
= it
->next
)
1348 calc_recursive(it
->data
, l
, raised
? raised
: l
!= old
);
1350 if (!raised
&& l
!= old
)
1352 stacking_raise(self
);
1355 void client_calc_layer(Client
*self
)
1360 /* transients take on the layer of their parents */
1361 if (self
->transient_for
) {
1362 if (self
->transient_for
!= TRAN_GROUP
) {
1363 self
= self
->transient_for
;
1367 for (it
= self
->group
->members
; it
; it
= it
->next
)
1368 if (it
->data
!= self
&&
1369 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1376 /* is us or one of our transients focused? */
1377 if (client_focused(self
))
1379 else if (search_focus_tree(self
, self
))
1384 if (self
->iconic
) l
= Layer_Icon
;
1385 /* fullscreen windows are only in the fullscreen layer while focused */
1386 else if (self
->fullscreen
&& f
) l
= Layer_Fullscreen
;
1387 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1388 else if (self
->type
== Type_Dock
) {
1389 if (!self
->below
) l
= Layer_Top
;
1390 else l
= Layer_Normal
;
1392 else if (self
->above
) l
= Layer_Above
;
1393 else if (self
->below
) l
= Layer_Below
;
1394 else l
= Layer_Normal
;
1396 calc_recursive(self
, l
, FALSE
);
1399 gboolean
client_should_show(Client
*self
)
1401 if (self
->iconic
) return FALSE
;
1402 else if (!(self
->desktop
== screen_desktop
||
1403 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1404 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1409 static void client_showhide(Client
*self
)
1412 if (client_should_show(self
))
1413 frame_show(self
->frame
);
1415 frame_hide(self
->frame
);
1418 gboolean
client_normal(Client
*self
) {
1419 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1420 self
->type
== Type_Splash
);
1423 static void client_apply_startup_state(Client
*self
)
1425 /* these are in a carefully crafted order.. */
1428 self
->iconic
= FALSE
;
1429 client_iconify(self
, TRUE
, FALSE
);
1431 if (self
->fullscreen
) {
1432 self
->fullscreen
= FALSE
;
1433 client_fullscreen(self
, TRUE
, FALSE
);
1436 self
->shaded
= FALSE
;
1437 client_shade(self
, TRUE
);
1440 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1442 if (self
->max_vert
&& self
->max_horz
) {
1443 self
->max_vert
= self
->max_horz
= FALSE
;
1444 client_maximize(self
, TRUE
, 0, FALSE
);
1445 } else if (self
->max_vert
) {
1446 self
->max_vert
= FALSE
;
1447 client_maximize(self
, TRUE
, 2, FALSE
);
1448 } else if (self
->max_horz
) {
1449 self
->max_horz
= FALSE
;
1450 client_maximize(self
, TRUE
, 1, FALSE
);
1453 /* nothing to do for the other states:
1462 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1463 gboolean user
, gboolean final
)
1465 gboolean moved
= FALSE
, resized
= FALSE
;
1467 /* gets the frame's position */
1468 frame_client_gravity(self
->frame
, &x
, &y
);
1470 /* these positions are frame positions, not client positions */
1472 /* set the size and position if fullscreen */
1473 if (self
->fullscreen
) {
1476 w
= screen_physical_size
.width
;
1477 h
= screen_physical_size
.height
;
1478 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1480 /* set the size and position if maximized */
1481 if (self
->max_horz
) {
1482 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1483 w
= screen_area(self
->desktop
)->width
;
1485 if (self
->max_vert
) {
1486 y
= screen_area(self
->desktop
)->y
;
1487 h
= screen_area(self
->desktop
)->height
-
1488 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1492 /* gets the client's position */
1493 frame_frame_gravity(self
->frame
, &x
, &y
);
1495 /* these override the above states! if you cant move you can't move! */
1497 if (!(self
->functions
& Func_Move
)) {
1501 if (!(self
->functions
& Func_Resize
)) {
1502 w
= self
->area
.width
;
1503 h
= self
->area
.height
;
1507 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1508 w
-= self
->base_size
.width
;
1509 h
-= self
->base_size
.height
;
1512 /* for interactive resizing. have to move half an increment in each
1515 /* how far we are towards the next size inc */
1516 int mw
= w
% self
->size_inc
.width
;
1517 int mh
= h
% self
->size_inc
.height
;
1519 int aw
= self
->size_inc
.width
/ 2;
1520 int ah
= self
->size_inc
.height
/ 2;
1521 /* don't let us move into a new size increment */
1522 if (mw
+ aw
>= self
->size_inc
.width
)
1523 aw
= self
->size_inc
.width
- mw
- 1;
1524 if (mh
+ ah
>= self
->size_inc
.height
)
1525 ah
= self
->size_inc
.height
- mh
- 1;
1529 /* if this is a user-requested resize, then check against min/max
1530 sizes and aspect ratios */
1532 /* smaller than min size or bigger than max size? */
1533 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1534 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1535 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1536 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1538 /* adjust the height ot match the width for the aspect ratios */
1539 if (self
->min_ratio
)
1540 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1541 if (self
->max_ratio
)
1542 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1545 /* keep to the increments */
1546 w
/= self
->size_inc
.width
;
1547 h
/= self
->size_inc
.height
;
1549 /* you cannot resize to nothing */
1553 /* store the logical size */
1554 SIZE_SET(self
->logical_size
, w
, h
);
1556 w
*= self
->size_inc
.width
;
1557 h
*= self
->size_inc
.height
;
1559 w
+= self
->base_size
.width
;
1560 h
+= self
->base_size
.height
;
1564 case Corner_TopLeft
:
1566 case Corner_TopRight
:
1567 x
-= w
- self
->area
.width
;
1569 case Corner_BottomLeft
:
1570 y
-= h
- self
->area
.height
;
1572 case Corner_BottomRight
:
1573 x
-= w
- self
->area
.width
;
1574 y
-= h
- self
->area
.height
;
1578 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1579 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1581 RECT_SET(self
->area
, x
, y
, w
, h
);
1584 XResizeWindow(ob_display
, self
->window
, w
, h
);
1586 /* move/resize the frame to match the request */
1588 if (moved
|| resized
)
1589 frame_adjust_area(self
->frame
, moved
, resized
);
1591 if (!user
|| final
) {
1593 event
.type
= ConfigureNotify
;
1594 event
.xconfigure
.display
= ob_display
;
1595 event
.xconfigure
.event
= self
->window
;
1596 event
.xconfigure
.window
= self
->window
;
1598 /* root window coords with border in mind */
1599 event
.xconfigure
.x
= x
- self
->border_width
+
1600 self
->frame
->size
.left
;
1601 event
.xconfigure
.y
= y
- self
->border_width
+
1602 self
->frame
->size
.top
;
1604 event
.xconfigure
.width
= self
->area
.width
;
1605 event
.xconfigure
.height
= self
->area
.height
;
1606 event
.xconfigure
.border_width
= self
->border_width
;
1607 event
.xconfigure
.above
= self
->frame
->plate
;
1608 event
.xconfigure
.override_redirect
= FALSE
;
1609 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1610 FALSE
, StructureNotifyMask
, &event
);
1615 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1619 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1620 self
->fullscreen
== fs
) return; /* already done */
1622 self
->fullscreen
= fs
;
1623 client_change_state(self
); /* change the state hints on the client,
1624 and adjust out layer/stacking */
1628 guint32 dimensions
[4];
1629 dimensions
[0] = self
->area
.x
;
1630 dimensions
[1] = self
->area
.y
;
1631 dimensions
[2] = self
->area
.width
;
1632 dimensions
[3] = self
->area
.height
;
1634 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1638 /* these are not actually used cuz client_configure will set them
1639 as appropriate when the window is fullscreened */
1645 /* pick some fallbacks... */
1646 x
= screen_area(self
->desktop
)->x
+
1647 screen_area(self
->desktop
)->width
/ 4;
1648 y
= screen_area(self
->desktop
)->y
+
1649 screen_area(self
->desktop
)->height
/ 4;
1650 w
= screen_area(self
->desktop
)->width
/ 2;
1651 h
= screen_area(self
->desktop
)->height
/ 2;
1653 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1654 (guint32
**)&dimensions
, &num
)) {
1665 client_setup_decor_and_functions(self
);
1667 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1669 /* try focus us when we go into fullscreen mode */
1673 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1677 /* move up the transient chain as far as possible first if deiconifying */
1679 while (self
->transient_for
) {
1680 if (self
->transient_for
!= TRAN_GROUP
) {
1681 if (self
->transient_for
->iconic
== iconic
)
1683 self
= self
->transient_for
;
1687 /* the check for TRAN_GROUP is to prevent an infinate loop with
1688 2 transients of the same group at the head of the group's
1690 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1691 Client
*c
= it
->data
;
1693 if (c
!= self
&& c
->transient_for
->iconic
!= iconic
&&
1694 c
->transient_for
!= TRAN_GROUP
) {
1699 if (it
== NULL
) break;
1703 if (self
->iconic
== iconic
) return; /* nothing to do */
1705 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1708 self
->iconic
= iconic
;
1711 self
->wmstate
= IconicState
;
1712 self
->ignore_unmaps
++;
1713 /* we unmap the client itself so that we can get MapRequest events,
1714 and because the ICCCM tells us to! */
1715 XUnmapWindow(ob_display
, self
->window
);
1718 client_set_desktop(self
, screen_desktop
, FALSE
);
1719 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1720 XMapWindow(ob_display
, self
->window
);
1722 client_change_state(self
);
1723 client_showhide(self
);
1724 screen_update_struts();
1726 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1729 /* iconify all transients */
1730 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1731 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1734 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1738 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1739 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1741 /* check if already done */
1743 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1744 if (dir
== 1 && self
->max_horz
) return;
1745 if (dir
== 2 && self
->max_vert
) return;
1747 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1748 if (dir
== 1 && !self
->max_horz
) return;
1749 if (dir
== 2 && !self
->max_vert
) return;
1752 /* work with the frame's coords */
1753 x
= self
->frame
->area
.x
;
1754 y
= self
->frame
->area
.y
;
1755 w
= self
->area
.width
;
1756 h
= self
->area
.height
;
1760 gint32 dimensions
[4];
1769 /* get the property off the window and use it for the dimensions
1770 we are already maxed on */
1771 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1772 (guint32
**)&readdim
, &num
)) {
1774 if (self
->max_horz
) {
1775 dimensions
[0] = readdim
[0];
1776 dimensions
[2] = readdim
[2];
1778 if (self
->max_vert
) {
1779 dimensions
[1] = readdim
[1];
1780 dimensions
[3] = readdim
[3];
1786 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1787 (guint32
*)dimensions
, 4);
1793 /* pick some fallbacks... */
1794 if (dir
== 0 || dir
== 1) { /* horz */
1795 x
= screen_area(self
->desktop
)->x
+
1796 screen_area(self
->desktop
)->width
/ 4;
1797 w
= screen_area(self
->desktop
)->width
/ 2;
1799 if (dir
== 0 || dir
== 2) { /* vert */
1800 y
= screen_area(self
->desktop
)->y
+
1801 screen_area(self
->desktop
)->height
/ 4;
1802 h
= screen_area(self
->desktop
)->height
/ 2;
1805 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1806 (guint32
**)&dimensions
, &num
)) {
1808 if (dir
== 0 || dir
== 1) { /* horz */
1812 if (dir
== 0 || dir
== 2) { /* vert */
1821 if (dir
== 0 || dir
== 1) /* horz */
1822 self
->max_horz
= max
;
1823 if (dir
== 0 || dir
== 2) /* vert */
1824 self
->max_vert
= max
;
1826 if (!self
->max_horz
&& !self
->max_vert
)
1827 PROP_ERASE(self
->window
, openbox_premax
);
1829 client_change_state(self
); /* change the state hints on the client */
1831 /* figure out where the client should be going */
1832 frame_frame_gravity(self
->frame
, &x
, &y
);
1833 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1836 void client_shade(Client
*self
, gboolean shade
)
1838 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1839 self
->shaded
== shade
) return; /* already done */
1841 /* when we're iconic, don't change the wmstate */
1843 self
->wmstate
= shade
? IconicState
: NormalState
;
1844 self
->shaded
= shade
;
1845 client_change_state(self
);
1846 /* resize the frame to just the titlebar */
1847 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1850 void client_close(Client
*self
)
1854 if (!(self
->functions
& Func_Close
)) return;
1857 XXX: itd be cool to do timeouts and shit here for killing the client's
1859 like... if the window is around after 5 seconds, then the close button
1860 turns a nice red, and if this function is called again, the client is
1864 ce
.xclient
.type
= ClientMessage
;
1865 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1866 ce
.xclient
.display
= ob_display
;
1867 ce
.xclient
.window
= self
->window
;
1868 ce
.xclient
.format
= 32;
1869 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1870 ce
.xclient
.data
.l
[1] = event_lasttime
;
1871 ce
.xclient
.data
.l
[2] = 0l;
1872 ce
.xclient
.data
.l
[3] = 0l;
1873 ce
.xclient
.data
.l
[4] = 0l;
1874 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1877 void client_kill(Client
*self
)
1879 XKillClient(ob_display
, self
->window
);
1882 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1886 if (target
== self
->desktop
) return;
1888 g_message("Setting desktop %u", target
);
1890 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1892 old
= self
->desktop
;
1893 self
->desktop
= target
;
1894 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1895 /* the frame can display the current desktop state */
1896 frame_adjust_state(self
->frame
);
1897 /* 'move' the window to the new desktop */
1899 client_showhide(self
);
1900 /* raise if it was not already on the desktop */
1901 if (old
!= DESKTOP_ALL
)
1902 stacking_raise(self
);
1903 screen_update_struts();
1905 /* update the focus lists */
1906 if (old
== DESKTOP_ALL
) {
1907 for (i
= 0; i
< screen_num_desktops
; ++i
)
1908 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1910 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1911 if (target
== DESKTOP_ALL
) {
1912 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1913 if (config_focus_new
)
1914 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1916 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1919 if (config_focus_new
)
1920 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1922 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1925 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1928 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1933 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1934 Client
*c
= it
->data
;
1935 if (c
== skip
) continue; /* circular? */
1936 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1937 if (c
->modal
) return c
;
1942 Client
*client_find_modal_child(Client
*self
)
1944 return search_modal_tree(self
, self
);
1947 gboolean
client_validate(Client
*self
)
1951 XSync(ob_display
, FALSE
); /* get all events on the server */
1953 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1954 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1955 XPutBackEvent(ob_display
, &e
);
1962 void client_set_wm_state(Client
*self
, long state
)
1964 if (state
== self
->wmstate
) return; /* no change */
1968 client_iconify(self
, TRUE
, TRUE
);
1971 client_iconify(self
, FALSE
, TRUE
);
1976 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1978 gboolean shaded
= self
->shaded
;
1979 gboolean fullscreen
= self
->fullscreen
;
1980 gboolean max_horz
= self
->max_horz
;
1981 gboolean max_vert
= self
->max_vert
;
1984 if (!(action
== prop_atoms
.net_wm_state_add
||
1985 action
== prop_atoms
.net_wm_state_remove
||
1986 action
== prop_atoms
.net_wm_state_toggle
))
1987 /* an invalid action was passed to the client message, ignore it */
1990 for (i
= 0; i
< 2; ++i
) {
1991 Atom state
= i
== 0 ? data1
: data2
;
1993 if (!state
) continue;
1995 /* if toggling, then pick whether we're adding or removing */
1996 if (action
== prop_atoms
.net_wm_state_toggle
) {
1997 if (state
== prop_atoms
.net_wm_state_modal
)
1998 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1999 prop_atoms
.net_wm_state_add
;
2000 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2001 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2002 prop_atoms
.net_wm_state_add
;
2003 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2004 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2005 prop_atoms
.net_wm_state_add
;
2006 else if (state
== prop_atoms
.net_wm_state_shaded
)
2007 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2008 prop_atoms
.net_wm_state_add
;
2009 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2010 action
= self
->skip_taskbar
?
2011 prop_atoms
.net_wm_state_remove
:
2012 prop_atoms
.net_wm_state_add
;
2013 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2014 action
= self
->skip_pager
?
2015 prop_atoms
.net_wm_state_remove
:
2016 prop_atoms
.net_wm_state_add
;
2017 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2018 action
= self
->fullscreen
?
2019 prop_atoms
.net_wm_state_remove
:
2020 prop_atoms
.net_wm_state_add
;
2021 else if (state
== prop_atoms
.net_wm_state_above
)
2022 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2023 prop_atoms
.net_wm_state_add
;
2024 else if (state
== prop_atoms
.net_wm_state_below
)
2025 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2026 prop_atoms
.net_wm_state_add
;
2029 if (action
== prop_atoms
.net_wm_state_add
) {
2030 if (state
== prop_atoms
.net_wm_state_modal
) {
2031 /* XXX raise here or something? */
2033 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2035 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2037 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2039 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2040 self
->skip_taskbar
= TRUE
;
2041 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2042 self
->skip_pager
= TRUE
;
2043 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2045 } else if (state
== prop_atoms
.net_wm_state_above
) {
2047 } else if (state
== prop_atoms
.net_wm_state_below
) {
2051 } else { /* action == prop_atoms.net_wm_state_remove */
2052 if (state
== prop_atoms
.net_wm_state_modal
) {
2053 self
->modal
= FALSE
;
2054 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2056 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2058 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2060 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2061 self
->skip_taskbar
= FALSE
;
2062 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2063 self
->skip_pager
= FALSE
;
2064 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2066 } else if (state
== prop_atoms
.net_wm_state_above
) {
2067 self
->above
= FALSE
;
2068 } else if (state
== prop_atoms
.net_wm_state_below
) {
2069 self
->below
= FALSE
;
2073 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2074 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2076 if (max_horz
== max_vert
) { /* both going the same way */
2077 client_maximize(self
, max_horz
, 0, TRUE
);
2079 client_maximize(self
, max_horz
, 1, TRUE
);
2080 client_maximize(self
, max_vert
, 2, TRUE
);
2084 if (max_horz
!= self
->max_horz
)
2085 client_maximize(self
, max_horz
, 1, TRUE
);
2087 client_maximize(self
, max_vert
, 2, TRUE
);
2090 /* change fullscreen state before shading, as it will affect if the window
2092 if (fullscreen
!= self
->fullscreen
)
2093 client_fullscreen(self
, fullscreen
, TRUE
);
2094 if (shaded
!= self
->shaded
)
2095 client_shade(self
, shaded
);
2096 client_calc_layer(self
);
2097 client_change_state(self
); /* change the hint to relect these changes */
2100 Client
*client_focus_target(Client
*self
)
2104 /* if we have a modal child, then focus it, not us */
2105 child
= client_find_modal_child(self
);
2106 if (child
) return child
;
2110 gboolean
client_focusable(Client
*self
)
2112 /* won't try focus if the client doesn't want it, or if the window isn't
2113 visible on the screen */
2114 return self
->frame
->visible
&&
2115 (self
->can_focus
|| self
->focus_notify
);
2118 gboolean
client_focus(Client
*self
)
2123 /* choose the correct target */
2124 self
= client_focus_target(self
);
2126 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2127 /* update the focus lists */
2128 if (self
->desktop
== DESKTOP_ALL
) {
2129 for (i
= 0; i
< screen_num_desktops
; ++i
) {
2130 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
2131 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
2135 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
2136 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
2141 if (!client_focusable(self
))
2144 /* do a check to see if the window has already been unmapped or destroyed
2145 do this intelligently while watching out for unmaps we've generated
2146 (ignore_unmaps > 0) */
2147 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2148 DestroyNotify
, &ev
)) {
2149 XPutBackEvent(ob_display
, &ev
);
2152 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2153 UnmapNotify
, &ev
)) {
2154 if (self
->ignore_unmaps
) {
2155 self
->ignore_unmaps
--;
2157 XPutBackEvent(ob_display
, &ev
);
2162 if (self
->can_focus
)
2163 /* RevertToPointerRoot causes much more headache than TevertToNone, so
2164 I choose to use it always, hopefully to find errors quicker, if any
2165 are left. (I hate X. I hate focus events.) */
2166 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2169 if (self
->focus_notify
) {
2171 ce
.xclient
.type
= ClientMessage
;
2172 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2173 ce
.xclient
.display
= ob_display
;
2174 ce
.xclient
.window
= self
->window
;
2175 ce
.xclient
.format
= 32;
2176 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2177 ce
.xclient
.data
.l
[1] = event_lasttime
;
2178 ce
.xclient
.data
.l
[2] = 0l;
2179 ce
.xclient
.data
.l
[3] = 0l;
2180 ce
.xclient
.data
.l
[4] = 0l;
2181 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2185 g_message("focusing %lx", self
->window
);
2188 /* Cause the FocusIn to come back to us. Important for desktop switches,
2189 since otherwise we'll have no FocusIn on the queue and send it off to
2190 the focus_backup. */
2191 XSync(ob_display
, FALSE
);
2195 void client_unfocus(Client
*self
)
2197 g_assert(focus_client
== self
);
2199 g_message("client_unfocus");
2201 focus_fallback(Fallback_Unfocusing
);
2204 gboolean
client_focused(Client
*self
)
2206 return self
== focus_client
;
2209 Icon
*client_icon(Client
*self
, int w
, int h
)
2212 /* si is the smallest image >= req */
2213 /* li is the largest image < req */
2214 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2216 if (!self
->nicons
) return NULL
;
2218 for (i
= 0; i
< self
->nicons
; ++i
) {
2219 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2220 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2224 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2229 if (largest
== 0) /* didnt find one smaller than the requested size */
2230 return &self
->icons
[si
];
2231 return &self
->icons
[li
];