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_apply_startup_state(Client
*self
);
43 static guint
map_hash(Window
*w
) { return *w
; }
44 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
48 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
49 (GEqualFunc
)map_key_comp
);
54 void client_shutdown()
56 g_hash_table_destroy(client_map
);
59 void client_set_list()
61 Window
*windows
, *win_it
;
63 guint size
= g_list_length(client_list
);
65 /* create an array of the window ids */
67 windows
= g_new(Window
, size
);
69 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
70 *win_it
= ((Client
*)it
->data
)->window
;
74 PROP_SETA32(ob_root
, net_client_list
, window
, (guint32
*)windows
, size
);
83 void client_foreach_transient(Client *self, ClientForeachFunc func, void *data)
87 for (it = self->transients; it; it = it->next) {
88 if (!func(it->data, data)) return;
89 client_foreach_transient(it->data, func, data);
93 void client_foreach_ancestor(Client *self, ClientForeachFunc func, void *data)
95 if (self->transient_for) {
96 if (self->transient_for != TRAN_GROUP) {
97 if (!func(self->transient_for, data)) return;
98 client_foreach_ancestor(self->transient_for, func, data);
102 for (it = self->group->members; it; it = it->next)
103 if (it->data != self &&
104 ((Client*)it->data)->transient_for != TRAN_GROUP) {
105 if (!func(it->data, data)) return;
106 client_foreach_ancestor(it->data, func, data);
113 void client_manage_all()
115 unsigned int i
, j
, nchild
;
118 XWindowAttributes attrib
;
121 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
123 /* remove all icon windows from the list */
124 for (i
= 0; i
< nchild
; i
++) {
125 if (children
[i
] == None
) continue;
126 wmhints
= XGetWMHints(ob_display
, children
[i
]);
128 if ((wmhints
->flags
& IconWindowHint
) &&
129 (wmhints
->icon_window
!= children
[i
]))
130 for (j
= 0; j
< nchild
; j
++)
131 if (children
[j
] == wmhints
->icon_window
) {
139 for (i
= 0; i
< nchild
; ++i
) {
140 if (children
[i
] == None
)
142 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
143 if (attrib
.override_redirect
) continue;
145 if (attrib
.map_state
!= IsUnmapped
)
146 client_manage(children
[i
]);
151 /* stack them as they were on startup!
152 why with stacking_lower? Why, because then windows who aren't in the
153 stacking list are on the top where you can see them instead of buried
155 for (i
= startup_stack_size
; i
> 0; --i
) {
158 w
= startup_stack_order
[i
-1];
159 c
= g_hash_table_lookup(client_map
, &w
);
160 if (c
) stacking_lower(c
);
162 g_free(startup_stack_order
);
163 startup_stack_order
= NULL
;
164 startup_stack_size
= 0;
166 if (config_focus_new
) {
167 active
= g_hash_table_lookup(client_map
, &startup_active
);
168 if (!(active
&& client_focus(active
)))
169 focus_fallback(Fallback_NoFocus
);
173 void client_manage(Window window
)
177 XWindowAttributes attrib
;
178 XSetWindowAttributes attrib_set
;
179 /* XWMHints *wmhint; */
183 /* check if it has already been unmapped by the time we started mapping
184 the grab does a sync so we don't have to here */
185 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
186 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
187 XPutBackEvent(ob_display
, &e
);
190 return; /* don't manage it */
193 /* make sure it isn't an override-redirect window */
194 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
195 attrib
.override_redirect
) {
197 return; /* don't manage it */
200 /* /\* is the window a docking app *\/
201 if ((wmhint = XGetWMHints(ob_display, window))) {
202 if ((wmhint->flags & StateHint) &&
203 wmhint->initial_state == WithdrawnState) {
204 /\* XXX: make dock apps work! *\/
212 g_message("Managing window: %lx", window
);
214 /* choose the events we want to receive on the CLIENT window */
215 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
216 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
217 XChangeWindowAttributes(ob_display
, window
,
218 CWEventMask
|CWDontPropagate
, &attrib_set
);
221 /* create the Client struct, and populate it from the hints on the
223 self
= g_new(Client
, 1);
224 self
->window
= window
;
225 client_get_all(self
);
227 /* remove the client's border (and adjust re gravity) */
228 client_toggle_border(self
, FALSE
);
230 /* specify that if we exit, the window should not be destroyed and should
231 be reparented back to root automatically */
232 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
234 /* create the decoration frame for the client window */
235 self
->frame
= frame_new();
237 frame_grab_client(self
->frame
, self
);
239 client_apply_startup_state(self
);
243 client_list
= g_list_append(client_list
, self
);
244 stacking_list
= g_list_append(stacking_list
, self
);
245 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
246 g_hash_table_insert(client_map
, &self
->window
, self
);
248 /* update the focus lists */
249 focus_order_add_new(self
);
251 stacking_raise(self
);
253 screen_update_struts();
255 dispatch_client(Event_Client_New
, self
, 0, 0);
257 client_showhide(self
);
259 /* focus the new window? */
260 if (ob_state
!= State_Starting
) {
262 gboolean group_foc
= FALSE
;
269 for (it
= self
->group
->members
; it
; it
= it
->next
)
270 if (client_focused(it
->data
)) {
275 if (!group_foc
&& self
->transient_for
) {
276 if (self
->transient_for
!= TRAN_GROUP
) {/* transient of a window */
277 parent
= self
->transient_for
;
278 } else { /* transient of a group */
281 for (it
= self
->group
->members
; it
; it
= it
->next
)
282 if (it
->data
!= self
&&
283 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
)
287 /* note the check against Type_Normal, not client_normal(self), which
288 would also include dialog types. in this case we want more strict
290 if ((config_focus_new
&&
291 (self
->type
== Type_Normal
||
292 (self
->type
== Type_Dialog
&&
294 (!parent
&& (!self
->group
||
295 !self
->group
->members
->next
)))))) ||
296 (parent
&& (client_focused(parent
) ||
297 client_search_focus_tree(parent
)))) {
302 /* update the list hints */
305 /* make sure the window is visible */
306 client_move_onscreen(self
);
308 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
310 g_message("Managed window 0x%lx", window
);
313 void client_unmanage_all()
315 while (client_list
!= NULL
)
316 client_unmanage(client_list
->data
);
319 void client_unmanage(Client
*self
)
324 g_message("Unmanaging window: %lx", self
->window
);
326 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
327 g_assert(self
!= NULL
);
329 /* remove the window from our save set */
330 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
332 /* we dont want events no more */
333 XSelectInput(ob_display
, self
->window
, NoEventMask
);
335 frame_hide(self
->frame
);
337 client_list
= g_list_remove(client_list
, self
);
338 stacking_list
= g_list_remove(stacking_list
, self
);
339 g_hash_table_remove(client_map
, &self
->window
);
341 /* update the focus lists */
342 focus_order_remove(self
);
344 /* once the client is out of the list, update the struts to remove it's
346 screen_update_struts();
348 /* tell our parent(s) that we're gone */
349 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
352 for (it
= self
->group
->members
; it
; it
= it
->next
)
353 if (it
->data
!= self
)
354 ((Client
*)it
->data
)->transients
=
355 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
356 } else if (self
->transient_for
) { /* transient of window */
357 self
->transient_for
->transients
=
358 g_slist_remove(self
->transient_for
->transients
, self
);
361 /* tell our transients that we're gone */
362 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
363 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
364 ((Client
*)it
->data
)->transient_for
= NULL
;
365 client_calc_layer(it
->data
);
369 if (moveresize_client
== self
)
370 moveresize_end(TRUE
);
372 if (focus_client
== self
) {
375 /* focus the last focused window on the desktop, and ignore enter
376 events from the unmap so it doesnt mess with the focus */
377 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
378 client_unfocus(self
);
381 /* remove from its group */
383 group_remove(self
->group
, self
);
387 /* dispatch the unmapped event */
388 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
389 g_assert(self
!= NULL
);
391 /* give the client its border back */
392 client_toggle_border(self
, TRUE
);
394 /* reparent the window out of the frame, and free the frame */
395 frame_release_client(self
->frame
, self
);
398 if (ob_state
!= State_Exiting
) {
399 /* these values should not be persisted across a window
401 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
402 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
404 /* if we're left in an iconic state, the client wont be mapped. this is
405 bad, since we will no longer be managing the window on restart */
407 XMapWindow(ob_display
, self
->window
);
411 g_message("Unmanaged window 0x%lx", self
->window
);
413 /* free all data allocated in the client struct */
414 g_slist_free(self
->transients
);
415 for (j
= 0; j
< self
->nicons
; ++j
)
416 g_free(self
->icons
[j
].data
);
417 if (self
->nicons
> 0)
420 g_free(self
->icon_title
);
426 /* update the list hints */
430 void client_move_onscreen(Client
*self
)
433 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
435 a
= screen_area(self
->desktop
);
436 if (x
>= a
->x
+ a
->width
- 1)
437 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
438 if (y
>= a
->y
+ a
->height
- 1)
439 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
440 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
442 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
445 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
447 client_configure(self
, Corner_TopLeft
, x
, y
,
448 self
->area
.width
, self
->area
.height
,
452 static void client_toggle_border(Client
*self
, gboolean show
)
454 /* adjust our idea of where the client is, based on its border. When the
455 border is removed, the client should now be considered to be in a
457 when re-adding the border to the client, the same operation needs to be
459 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
460 int x
= oldx
, y
= oldy
;
461 switch(self
->gravity
) {
463 case NorthWestGravity
:
465 case SouthWestGravity
:
467 case NorthEastGravity
:
469 case SouthEastGravity
:
470 if (show
) x
-= self
->border_width
* 2;
471 else x
+= self
->border_width
* 2;
478 if (show
) x
-= self
->border_width
;
479 else x
+= self
->border_width
;
482 switch(self
->gravity
) {
484 case NorthWestGravity
:
486 case NorthEastGravity
:
488 case SouthWestGravity
:
490 case SouthEastGravity
:
491 if (show
) y
-= self
->border_width
* 2;
492 else y
+= self
->border_width
* 2;
499 if (show
) y
-= self
->border_width
;
500 else y
+= self
->border_width
;
507 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
509 /* move the client so it is back it the right spot _with_ its
511 if (x
!= oldx
|| y
!= oldy
)
512 XMoveWindow(ob_display
, self
->window
, x
, y
);
514 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
518 static void client_get_all(Client
*self
)
520 /* update EVERYTHING!! */
522 self
->ignore_unmaps
= 0;
526 self
->title
= self
->icon_title
= NULL
;
527 self
->title_count
= 1;
528 self
->name
= self
->class = self
->role
= NULL
;
529 self
->wmstate
= NormalState
;
530 self
->transient
= FALSE
;
531 self
->transients
= NULL
;
532 self
->transient_for
= NULL
;
534 self
->urgent
= FALSE
;
535 self
->positioned
= FALSE
;
536 self
->disabled_decorations
= 0;
540 client_get_area(self
);
541 client_update_transient_for(self
);
542 client_update_wmhints(self
);
543 client_get_desktop(self
);
544 client_get_state(self
);
545 client_get_shaped(self
);
547 client_get_mwm_hints(self
);
548 client_get_type(self
);/* this can change the mwmhints for special cases */
550 client_update_protocols(self
);
552 client_get_gravity(self
); /* get the attribute gravity */
553 client_update_normal_hints(self
); /* this may override the attribute
556 /* got the type, the mwmhints, the protocols, and the normal hints
557 (min/max sizes), so we're ready to set up the decorations/functions */
558 client_setup_decor_and_functions(self
);
560 client_update_title(self
);
561 client_update_class(self
);
562 client_update_strut(self
);
563 client_update_icons(self
);
564 client_update_kwm_icon(self
);
566 client_change_state(self
);
569 static void client_get_area(Client
*self
)
571 XWindowAttributes wattrib
;
574 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
575 g_assert(ret
!= BadWindow
);
577 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
578 self
->border_width
= wattrib
.border_width
;
581 static void client_get_desktop(Client
*self
)
585 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
586 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
587 d
= screen_num_desktops
- 1;
590 gboolean trdesk
= FALSE
;
592 if (self
->transient_for
) {
593 if (self
->transient_for
!= TRAN_GROUP
) {
594 self
->desktop
= self
->transient_for
->desktop
;
599 for (it
= self
->group
->members
; it
; it
= it
->next
)
600 if (it
->data
!= self
&&
601 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
602 self
->desktop
= ((Client
*)it
->data
)->desktop
;
609 /* defaults to the current desktop */
610 self
->desktop
= screen_desktop
;
612 /* set the desktop hint, to make sure that it always exists */
613 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
617 static void client_get_state(Client
*self
)
622 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
623 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
624 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
626 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
628 for (i
= 0; i
< num
; ++i
) {
629 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
631 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
633 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
635 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
636 self
->skip_taskbar
= TRUE
;
637 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
638 self
->skip_pager
= TRUE
;
639 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
640 self
->fullscreen
= TRUE
;
641 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
642 self
->max_vert
= TRUE
;
643 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
644 self
->max_horz
= TRUE
;
645 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
647 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
655 static void client_get_shaped(Client
*self
)
657 self
->shaped
= FALSE
;
659 if (extensions_shape
) {
664 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
666 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
667 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
669 self
->shaped
= (s
!= 0);
674 void client_update_transient_for(Client
*self
)
679 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
680 self
->transient
= TRUE
;
681 if (t
!= self
->window
) { /* cant be transient to itself! */
682 c
= g_hash_table_lookup(client_map
, &t
);
683 /* if this happens then we need to check for it*/
686 if (!c
&& self
->group
) {
687 /* not transient to a client, see if it is transient for a
689 if (t
== self
->group
->leader
||
692 /* window is a transient for its group! */
698 self
->transient
= FALSE
;
700 /* if anything has changed... */
701 if (c
!= self
->transient_for
) {
702 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
705 /* remove from old parents */
706 for (it
= self
->group
->members
; it
; it
= it
->next
)
707 if (it
->data
!= self
&&
708 (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
))
709 ((Client
*)it
->data
)->transients
=
710 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
711 } else if (self
->transient_for
!= NULL
) { /* transient of window */
712 /* remove from old parent */
713 self
->transient_for
->transients
=
714 g_slist_remove(self
->transient_for
->transients
, self
);
716 self
->transient_for
= c
;
717 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
720 /* add to new parents */
721 for (it
= self
->group
->members
; it
; it
= it
->next
)
722 if (it
->data
!= self
&&
723 (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
))
724 ((Client
*)it
->data
)->transients
=
725 g_slist_append(((Client
*)it
->data
)->transients
, self
);
727 /* remove all transients which are in the group, that causes
728 circlular pointer hell of doom */
729 for (it
= self
->group
->members
; it
; it
= it
->next
) {
731 for (sit
= self
->transients
; sit
; sit
= next
) {
733 if (sit
->data
== it
->data
)
734 self
->transients
= g_slist_remove(self
->transients
,
738 } else if (self
->transient_for
!= NULL
) { /* transient of window */
739 /* add to new parent */
740 self
->transient_for
->transients
=
741 g_slist_append(self
->transient_for
->transients
, self
);
746 static void client_get_mwm_hints(Client
*self
)
751 self
->mwmhints
.flags
= 0; /* default to none */
753 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
755 if (num
>= MWM_ELEMENTS
) {
756 self
->mwmhints
.flags
= hints
[0];
757 self
->mwmhints
.functions
= hints
[1];
758 self
->mwmhints
.decorations
= hints
[2];
764 void client_get_type(Client
*self
)
771 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
772 /* use the first value that we know about in the array */
773 for (i
= 0; i
< num
; ++i
) {
774 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
775 self
->type
= Type_Desktop
;
776 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
777 self
->type
= Type_Dock
;
778 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
779 self
->type
= Type_Toolbar
;
780 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
781 self
->type
= Type_Menu
;
782 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
783 self
->type
= Type_Utility
;
784 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
785 self
->type
= Type_Splash
;
786 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
787 self
->type
= Type_Dialog
;
788 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
789 self
->type
= Type_Normal
;
790 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
791 /* prevent this window from getting any decor or
793 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
794 MwmFlag_Decorations
);
795 self
->mwmhints
.decorations
= 0;
796 self
->mwmhints
.functions
= 0;
798 if (self
->type
!= (WindowType
) -1)
799 break; /* grab the first legit type */
804 if (self
->type
== (WindowType
) -1) {
805 /*the window type hint was not set, which means we either classify
806 ourself as a normal window or a dialog, depending on if we are a
809 self
->type
= Type_Dialog
;
811 self
->type
= Type_Normal
;
815 void client_update_protocols(Client
*self
)
820 self
->focus_notify
= FALSE
;
821 self
->delete_window
= FALSE
;
823 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
824 for (i
= 0; i
< num_return
; ++i
) {
825 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
826 /* this means we can request the window to close */
827 self
->delete_window
= TRUE
;
828 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
829 /* if this protocol is requested, then the window will be
830 notified whenever we want it to receive focus */
831 self
->focus_notify
= TRUE
;
837 static void client_get_gravity(Client
*self
)
839 XWindowAttributes wattrib
;
842 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
843 g_assert(ret
!= BadWindow
);
844 self
->gravity
= wattrib
.win_gravity
;
847 void client_update_normal_hints(Client
*self
)
851 int oldgravity
= self
->gravity
;
854 self
->min_ratio
= 0.0f
;
855 self
->max_ratio
= 0.0f
;
856 SIZE_SET(self
->size_inc
, 1, 1);
857 SIZE_SET(self
->base_size
, 0, 0);
858 SIZE_SET(self
->min_size
, 0, 0);
859 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
861 /* get the hints from the window */
862 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
863 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
865 if (size
.flags
& PWinGravity
) {
866 self
->gravity
= size
.win_gravity
;
868 /* if the client has a frame, i.e. has already been mapped and
869 is changing its gravity */
870 if (self
->frame
&& self
->gravity
!= oldgravity
) {
871 /* move our idea of the client's position based on its new
873 self
->area
.x
= self
->frame
->area
.x
;
874 self
->area
.y
= self
->frame
->area
.y
;
875 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
879 if (size
.flags
& PAspect
) {
880 if (size
.min_aspect
.y
)
881 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
882 if (size
.max_aspect
.y
)
883 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
886 if (size
.flags
& PMinSize
)
887 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
889 if (size
.flags
& PMaxSize
)
890 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
892 if (size
.flags
& PBaseSize
)
893 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
895 if (size
.flags
& PResizeInc
)
896 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
900 void client_setup_decor_and_functions(Client
*self
)
902 /* start with everything (cept fullscreen) */
903 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
904 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
906 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
908 if (self
->delete_window
) {
909 self
->decorations
|= Decor_Close
;
910 self
->functions
|= Func_Close
;
913 if (!(self
->min_size
.width
< self
->max_size
.width
||
914 self
->min_size
.height
< self
->max_size
.height
)) {
915 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
916 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
919 switch (self
->type
) {
921 /* normal windows retain all of the possible decorations and
922 functionality, and are the only windows that you can fullscreen */
923 self
->functions
|= Func_Fullscreen
;
928 /* these windows cannot be maximized */
929 self
->decorations
&= ~Decor_Maximize
;
930 self
->functions
&= ~Func_Maximize
;
935 /* these windows get less functionality */
936 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
937 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
943 /* none of these windows are manipulated by the window manager */
944 self
->decorations
= 0;
949 /* Mwm Hints are applied subtractively to what has already been chosen for
950 decor and functionality */
951 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
952 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
953 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
954 self
->decorations
&= ~Decor_Border
;
955 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
956 self
->decorations
&= ~Decor_Handle
;
957 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
958 self
->decorations
&= ~Decor_Titlebar
;
959 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
960 self
->decorations
&= ~Decor_Iconify
;
961 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
962 self
->decorations
&= ~Decor_Maximize
;
966 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
967 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
968 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
969 self
->functions
&= ~Func_Resize
;
970 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
971 self
->functions
&= ~Func_Move
;
972 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
973 self
->functions
&= ~Func_Iconify
;
974 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
975 self
->functions
&= ~Func_Maximize
;
976 /* dont let mwm hints kill the close button
977 if (! (self->mwmhints.functions & MwmFunc_Close))
978 self->functions &= ~Func_Close; */
982 /* can't maximize without moving/resizing */
983 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
984 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
986 /* finally, user specified disabled decorations are applied to subtract
988 if (self
->disabled_decorations
& Decor_Titlebar
)
989 self
->decorations
&= ~Decor_Titlebar
;
990 if (self
->disabled_decorations
& Decor_Handle
)
991 self
->decorations
&= ~Decor_Handle
;
992 if (self
->disabled_decorations
& Decor_Border
)
993 self
->decorations
&= ~Decor_Border
;
994 if (self
->disabled_decorations
& Decor_Iconify
)
995 self
->decorations
&= ~Decor_Iconify
;
996 if (self
->disabled_decorations
& Decor_Maximize
)
997 self
->decorations
&= ~Decor_Maximize
;
998 if (self
->disabled_decorations
& Decor_AllDesktops
)
999 self
->decorations
&= ~Decor_AllDesktops
;
1000 if (self
->disabled_decorations
& Decor_Shade
)
1001 self
->decorations
&= ~Decor_Shade
;
1002 if (self
->disabled_decorations
& Decor_Close
)
1003 self
->decorations
&= ~Decor_Close
;
1005 /* if we don't have a titlebar, then we cannot shade! */
1006 if (!(self
->decorations
& Decor_Titlebar
))
1007 self
->functions
&= ~Func_Shade
;
1009 /* now we need to check against rules for the client's current state */
1010 if (self
->fullscreen
) {
1011 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
1012 self
->decorations
= 0;
1015 client_change_allowed_actions(self
);
1018 /* this makes sure that these windows appear on all desktops */
1019 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1020 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1022 /* change the decors on the frame, and with more/less decorations,
1023 we may also need to be repositioned */
1024 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
1025 /* with new decor, the window's maximized size may change */
1026 client_remaximize(self
);
1028 /* this makes sure that these windows appear on all desktops */
1029 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1030 self
->desktop
= DESKTOP_ALL
;
1034 static void client_change_allowed_actions(Client
*self
)
1039 /* desktop windows are kept on all desktops */
1040 if (self
->type
!= Type_Desktop
)
1041 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1043 if (self
->functions
& Func_Shade
)
1044 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1045 if (self
->functions
& Func_Close
)
1046 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1047 if (self
->functions
& Func_Move
)
1048 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1049 if (self
->functions
& Func_Iconify
)
1050 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1051 if (self
->functions
& Func_Resize
)
1052 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1053 if (self
->functions
& Func_Fullscreen
)
1054 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1055 if (self
->functions
& Func_Maximize
) {
1056 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1057 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1060 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1062 /* make sure the window isn't breaking any rules now */
1064 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1065 if (self
->frame
) client_shade(self
, FALSE
);
1066 else self
->shaded
= FALSE
;
1068 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1069 g_message("UNSETTING ICONIC");
1070 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1071 else self
->iconic
= FALSE
;
1073 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1074 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1075 else self
->fullscreen
= FALSE
;
1077 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1079 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1080 else self
->max_vert
= self
->max_horz
= FALSE
;
1084 void client_remaximize(Client
*self
)
1087 if (self
->max_horz
&& self
->max_vert
)
1089 else if (self
->max_horz
)
1091 else if (self
->max_vert
)
1094 return; /* not maximized */
1095 self
->max_horz
= self
->max_vert
= FALSE
;
1096 client_maximize(self
, TRUE
, dir
, FALSE
);
1099 void client_update_wmhints(Client
*self
)
1102 gboolean ur
= FALSE
;
1105 /* assume a window takes input if it doesnt specify */
1106 self
->can_focus
= TRUE
;
1108 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1109 if (hints
->flags
& InputHint
)
1110 self
->can_focus
= hints
->input
;
1112 /* only do this when first managing the window *AND* when we aren't
1114 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1115 if (hints
->flags
& StateHint
)
1116 self
->iconic
= hints
->initial_state
== IconicState
;
1118 if (hints
->flags
& XUrgencyHint
)
1121 if (!(hints
->flags
& WindowGroupHint
))
1122 hints
->window_group
= None
;
1124 /* did the group state change? */
1125 if (hints
->window_group
!=
1126 (self
->group
? self
->group
->leader
: None
)) {
1127 /* remove from the old group if there was one */
1128 if (self
->group
!= NULL
) {
1129 /* remove transients of the group */
1130 for (it
= self
->group
->members
; it
; it
= it
->next
)
1131 if (it
->data
!= self
&&
1132 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
) {
1133 self
->transients
= g_slist_remove(self
->transients
,
1136 group_remove(self
->group
, self
);
1139 if (hints
->window_group
!= None
) {
1140 self
->group
= group_add(hints
->window_group
, self
);
1142 /* add other transients of the group that are already
1144 for (it
= self
->group
->members
; it
; it
= it
->next
)
1145 if (it
->data
!= self
&&
1146 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1147 self
->transients
= g_slist_append(self
->transients
,
1151 /* because the self->transient flag wont change from this call,
1152 we don't need to update the window's type and such, only its
1153 transient_for, and the transients lists of other windows in
1154 the group may be affected */
1155 client_update_transient_for(self
);
1158 client_update_kwm_icon(self
);
1159 /* try get the kwm icon first, this is a fallback only */
1160 if (self
->pixmap_icon
== None
) {
1161 if (hints
->flags
& IconPixmapHint
) {
1162 if (self
->pixmap_icon
== None
) {
1163 self
->pixmap_icon
= hints
->icon_pixmap
;
1164 if (hints
->flags
& IconMaskHint
)
1165 self
->pixmap_icon_mask
= hints
->icon_mask
;
1167 self
->pixmap_icon_mask
= None
;
1170 frame_adjust_icon(self
->frame
);
1178 if (ur
!= self
->urgent
) {
1180 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1182 /* fire the urgent callback if we're mapped, otherwise, wait until
1183 after we're mapped */
1185 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1189 void client_update_title(Client
*self
)
1195 gboolean read_title
;
1197 g_free(self
->title
);
1200 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1201 /* try old x stuff */
1202 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1203 data
= g_strdup("Unnamed Window");
1205 /* look for duplicates and append a number */
1207 for (it
= client_list
; it
; it
= it
->next
)
1208 if (it
->data
!= self
) {
1209 Client
*c
= it
->data
;
1210 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1211 nums
|= 1 << c
->title_count
;
1213 /* find first free number */
1214 for (i
= 1; i
<= 32; ++i
)
1215 if (!(nums
& (1 << i
))) {
1216 if (self
->title_count
== 1 || i
== 1)
1217 self
->title_count
= i
;
1220 /* dont display the number for the first window */
1221 if (self
->title_count
> 1) {
1222 char *vdata
, *ndata
;
1223 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1224 vdata
= g_strconcat(data
, ndata
, NULL
);
1230 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1235 frame_adjust_title(self
->frame
);
1237 /* update the icon title */
1239 g_free(self
->icon_title
);
1243 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1244 /* try old x stuff */
1245 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1246 data
= g_strdup(self
->title
);
1250 /* append the title count, dont display the number for the first window */
1251 if (read_title
&& self
->title_count
> 1) {
1252 char *vdata
, *ndata
;
1253 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1254 vdata
= g_strconcat(data
, ndata
, NULL
);
1260 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1262 self
->icon_title
= data
;
1265 void client_update_class(Client
*self
)
1270 if (self
->name
) g_free(self
->name
);
1271 if (self
->class) g_free(self
->class);
1272 if (self
->role
) g_free(self
->role
);
1274 self
->name
= self
->class = self
->role
= NULL
;
1276 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1278 self
->name
= g_strdup(data
[0]);
1280 self
->class = g_strdup(data
[1]);
1285 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1286 self
->role
= g_strdup(s
);
1288 if (self
->name
== NULL
) self
->name
= g_strdup("");
1289 if (self
->class == NULL
) self
->class = g_strdup("");
1290 if (self
->role
== NULL
) self
->role
= g_strdup("");
1293 void client_update_strut(Client
*self
)
1298 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1299 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1302 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1304 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1308 /* updating here is pointless while we're being mapped cuz we're not in
1309 the client list yet */
1311 screen_update_struts();
1314 void client_update_icons(Client
*self
)
1321 for (j
= 0; j
< self
->nicons
; ++j
)
1322 g_free(self
->icons
[j
].data
);
1323 if (self
->nicons
> 0)
1324 g_free(self
->icons
);
1327 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1328 /* figure out how many valid icons are in here */
1330 while (num
- i
> 2) {
1338 self
->icons
= g_new(Icon
, self
->nicons
);
1340 /* store the icons */
1342 for (j
= 0; j
< self
->nicons
; ++j
) {
1343 w
= self
->icons
[j
].width
= data
[i
++];
1344 h
= self
->icons
[j
].height
= data
[i
++];
1345 self
->icons
[j
].data
=
1346 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1355 frame_adjust_icon(self
->frame
);
1358 void client_update_kwm_icon(Client
*self
)
1363 if (!PROP_GETA32(self
->window
, kwm_win_icon
, kwm_win_icon
, &data
, &num
)) {
1364 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1367 self
->pixmap_icon
= data
[0];
1368 self
->pixmap_icon_mask
= data
[1];
1370 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1374 frame_adjust_icon(self
->frame
);
1377 static void client_change_state(Client
*self
)
1380 guint32 netstate
[10];
1383 state
[0] = self
->wmstate
;
1385 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1389 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1391 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1393 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1394 if (self
->skip_taskbar
)
1395 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1396 if (self
->skip_pager
)
1397 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1398 if (self
->fullscreen
)
1399 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1401 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1403 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1405 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1407 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1408 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1410 client_calc_layer(self
);
1413 frame_adjust_state(self
->frame
);
1416 Client
*client_search_focus_tree(Client
*self
)
1421 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1422 if (client_focused(it
->data
)) return it
->data
;
1423 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1428 Client
*client_search_focus_tree_full(Client
*self
)
1430 if (self
->transient_for
) {
1431 if (self
->transient_for
!= TRAN_GROUP
) {
1432 return client_search_focus_tree_full(self
->transient_for
);
1436 for (it
= self
->group
->members
; it
; it
= it
->next
)
1437 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1439 if ((c
= client_search_focus_tree_full(it
->data
)))
1445 /* this function checks the whole tree, the client_search_focus_tree
1446 does not, so we need to check this window */
1447 if (client_focused(self
))
1449 return client_search_focus_tree(self
);
1453 static StackLayer
calc_layer(Client
*self
)
1457 if (self
->iconic
) l
= Layer_Icon
;
1458 else if (self
->fullscreen
) l
= Layer_Fullscreen
;
1459 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1460 else if (self
->type
== Type_Dock
) {
1461 if (!self
->below
) l
= Layer_Top
;
1462 else l
= Layer_Normal
;
1464 else if (self
->above
) l
= Layer_Above
;
1465 else if (self
->below
) l
= Layer_Below
;
1466 else l
= Layer_Normal
;
1471 static void calc_recursive(Client
*self
, Client
*orig
, StackLayer l
,
1474 StackLayer old
, own
;
1478 own
= calc_layer(self
);
1479 self
->layer
= l
> own
? l
: own
;
1481 for (it
= self
->transients
; it
; it
= it
->next
)
1482 calc_recursive(it
->data
, orig
, l
, raised
? raised
: l
!= old
);
1484 if (!raised
&& l
!= old
)
1485 if (orig
->frame
) /* only restack if the original window is managed */
1486 stacking_raise(self
);
1489 void client_calc_layer(Client
*self
)
1496 /* transients take on the layer of their parents */
1497 if (self
->transient_for
) {
1498 if (self
->transient_for
!= TRAN_GROUP
) {
1499 self
= self
->transient_for
;
1503 for (it
= self
->group
->members
; it
; it
= it
->next
)
1504 if (it
->data
!= self
&&
1505 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1512 l
= calc_layer(self
);
1514 calc_recursive(self
, orig
, l
, FALSE
);
1517 gboolean
client_should_show(Client
*self
)
1519 if (self
->iconic
) return FALSE
;
1520 else if (!(self
->desktop
== screen_desktop
||
1521 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1522 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1527 static void client_showhide(Client
*self
)
1530 if (client_should_show(self
))
1531 frame_show(self
->frame
);
1533 frame_hide(self
->frame
);
1536 gboolean
client_normal(Client
*self
) {
1537 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1538 self
->type
== Type_Splash
);
1541 static void client_apply_startup_state(Client
*self
)
1543 /* these are in a carefully crafted order.. */
1546 self
->iconic
= FALSE
;
1547 client_iconify(self
, TRUE
, FALSE
);
1549 if (self
->fullscreen
) {
1550 self
->fullscreen
= FALSE
;
1551 client_fullscreen(self
, TRUE
, FALSE
);
1554 self
->shaded
= FALSE
;
1555 client_shade(self
, TRUE
);
1558 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1560 if (self
->max_vert
&& self
->max_horz
) {
1561 self
->max_vert
= self
->max_horz
= FALSE
;
1562 client_maximize(self
, TRUE
, 0, FALSE
);
1563 } else if (self
->max_vert
) {
1564 self
->max_vert
= FALSE
;
1565 client_maximize(self
, TRUE
, 2, FALSE
);
1566 } else if (self
->max_horz
) {
1567 self
->max_horz
= FALSE
;
1568 client_maximize(self
, TRUE
, 1, FALSE
);
1571 /* nothing to do for the other states:
1580 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1581 gboolean user
, gboolean final
)
1583 gboolean moved
= FALSE
, resized
= FALSE
;
1585 /* gets the frame's position */
1586 frame_client_gravity(self
->frame
, &x
, &y
);
1588 /* these positions are frame positions, not client positions */
1590 /* set the size and position if fullscreen */
1591 if (self
->fullscreen
) {
1594 w
= screen_physical_size
.width
;
1595 h
= screen_physical_size
.height
;
1596 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1598 /* set the size and position if maximized */
1599 if (self
->max_horz
) {
1600 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1601 w
= screen_area(self
->desktop
)->width
;
1603 if (self
->max_vert
) {
1604 y
= screen_area(self
->desktop
)->y
;
1605 h
= screen_area(self
->desktop
)->height
-
1606 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1610 /* gets the client's position */
1611 frame_frame_gravity(self
->frame
, &x
, &y
);
1613 /* these override the above states! if you cant move you can't move! */
1615 if (!(self
->functions
& Func_Move
)) {
1619 if (!(self
->functions
& Func_Resize
)) {
1620 w
= self
->area
.width
;
1621 h
= self
->area
.height
;
1625 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1626 w
-= self
->base_size
.width
;
1627 h
-= self
->base_size
.height
;
1630 /* for interactive resizing. have to move half an increment in each
1633 /* how far we are towards the next size inc */
1634 int mw
= w
% self
->size_inc
.width
;
1635 int mh
= h
% self
->size_inc
.height
;
1637 int aw
= self
->size_inc
.width
/ 2;
1638 int ah
= self
->size_inc
.height
/ 2;
1639 /* don't let us move into a new size increment */
1640 if (mw
+ aw
>= self
->size_inc
.width
)
1641 aw
= self
->size_inc
.width
- mw
- 1;
1642 if (mh
+ ah
>= self
->size_inc
.height
)
1643 ah
= self
->size_inc
.height
- mh
- 1;
1647 /* if this is a user-requested resize, then check against min/max
1648 sizes and aspect ratios */
1650 /* smaller than min size or bigger than max size? */
1651 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1652 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1653 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1654 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1656 /* adjust the height ot match the width for the aspect ratios */
1657 if (self
->min_ratio
)
1658 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1659 if (self
->max_ratio
)
1660 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1663 /* keep to the increments */
1664 w
/= self
->size_inc
.width
;
1665 h
/= self
->size_inc
.height
;
1667 /* you cannot resize to nothing */
1671 /* store the logical size */
1672 SIZE_SET(self
->logical_size
, w
, h
);
1674 w
*= self
->size_inc
.width
;
1675 h
*= self
->size_inc
.height
;
1677 w
+= self
->base_size
.width
;
1678 h
+= self
->base_size
.height
;
1682 case Corner_TopLeft
:
1684 case Corner_TopRight
:
1685 x
-= w
- self
->area
.width
;
1687 case Corner_BottomLeft
:
1688 y
-= h
- self
->area
.height
;
1690 case Corner_BottomRight
:
1691 x
-= w
- self
->area
.width
;
1692 y
-= h
- self
->area
.height
;
1696 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1697 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1699 RECT_SET(self
->area
, x
, y
, w
, h
);
1702 XResizeWindow(ob_display
, self
->window
, w
, h
);
1704 /* move/resize the frame to match the request */
1706 if (moved
|| resized
)
1707 frame_adjust_area(self
->frame
, moved
, resized
);
1709 if (!user
|| final
) {
1711 event
.type
= ConfigureNotify
;
1712 event
.xconfigure
.display
= ob_display
;
1713 event
.xconfigure
.event
= self
->window
;
1714 event
.xconfigure
.window
= self
->window
;
1716 /* root window coords with border in mind */
1717 event
.xconfigure
.x
= x
- self
->border_width
+
1718 self
->frame
->size
.left
;
1719 event
.xconfigure
.y
= y
- self
->border_width
+
1720 self
->frame
->size
.top
;
1722 event
.xconfigure
.width
= self
->area
.width
;
1723 event
.xconfigure
.height
= self
->area
.height
;
1724 event
.xconfigure
.border_width
= self
->border_width
;
1725 event
.xconfigure
.above
= self
->frame
->plate
;
1726 event
.xconfigure
.override_redirect
= FALSE
;
1727 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1728 FALSE
, StructureNotifyMask
, &event
);
1733 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1737 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1738 self
->fullscreen
== fs
) return; /* already done */
1740 self
->fullscreen
= fs
;
1741 client_change_state(self
); /* change the state hints on the client,
1742 and adjust out layer/stacking */
1746 guint32 dimensions
[4];
1747 dimensions
[0] = self
->area
.x
;
1748 dimensions
[1] = self
->area
.y
;
1749 dimensions
[2] = self
->area
.width
;
1750 dimensions
[3] = self
->area
.height
;
1752 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1756 /* these are not actually used cuz client_configure will set them
1757 as appropriate when the window is fullscreened */
1763 /* pick some fallbacks... */
1764 x
= screen_area(self
->desktop
)->x
+
1765 screen_area(self
->desktop
)->width
/ 4;
1766 y
= screen_area(self
->desktop
)->y
+
1767 screen_area(self
->desktop
)->height
/ 4;
1768 w
= screen_area(self
->desktop
)->width
/ 2;
1769 h
= screen_area(self
->desktop
)->height
/ 2;
1771 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1772 (guint32
**)&dimensions
, &num
)) {
1783 client_setup_decor_and_functions(self
);
1785 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1787 /* try focus us when we go into fullscreen mode */
1791 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1795 /* move up the transient chain as far as possible first */
1796 if (self
->transient_for
) {
1797 if (self
->transient_for
!= TRAN_GROUP
) {
1798 if (self
->transient_for
->iconic
!= iconic
) {
1799 client_iconify(self
->transient_for
, iconic
, curdesk
);
1805 /* the check for TRAN_GROUP is to prevent an infinate loop with
1806 2 transients of the same group at the head of the group's
1808 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1809 Client
*c
= it
->data
;
1810 if (c
!= self
&& c
->iconic
!= iconic
&&
1811 c
->transient_for
!= TRAN_GROUP
) {
1812 client_iconify(it
->data
, iconic
, curdesk
);
1816 if (it
!= NULL
) return;
1820 if (self
->iconic
== iconic
) return; /* nothing to do */
1822 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1825 self
->iconic
= iconic
;
1828 self
->wmstate
= IconicState
;
1829 self
->ignore_unmaps
++;
1830 /* we unmap the client itself so that we can get MapRequest events,
1831 and because the ICCCM tells us to! */
1832 XUnmapWindow(ob_display
, self
->window
);
1834 /* update the focus lists.. iconic windows go to the bottom of the
1835 list, put the new iconic window at the 'top of the bottom'. */
1836 focus_order_to_top(self
);
1839 client_set_desktop(self
, screen_desktop
, FALSE
);
1840 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1841 XMapWindow(ob_display
, self
->window
);
1843 /* this puts it after the current focused window */
1844 focus_order_remove(self
);
1845 focus_order_add_new(self
);
1847 client_change_state(self
);
1848 client_showhide(self
);
1849 screen_update_struts();
1851 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1854 /* iconify all transients */
1855 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1856 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1859 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1863 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1864 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1866 /* check if already done */
1868 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1869 if (dir
== 1 && self
->max_horz
) return;
1870 if (dir
== 2 && self
->max_vert
) return;
1872 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1873 if (dir
== 1 && !self
->max_horz
) return;
1874 if (dir
== 2 && !self
->max_vert
) return;
1877 /* work with the frame's coords */
1878 x
= self
->frame
->area
.x
;
1879 y
= self
->frame
->area
.y
;
1880 w
= self
->area
.width
;
1881 h
= self
->area
.height
;
1885 gint32 dimensions
[4];
1894 /* get the property off the window and use it for the dimensions
1895 we are already maxed on */
1896 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1897 (guint32
**)&readdim
, &num
)) {
1899 if (self
->max_horz
) {
1900 dimensions
[0] = readdim
[0];
1901 dimensions
[2] = readdim
[2];
1903 if (self
->max_vert
) {
1904 dimensions
[1] = readdim
[1];
1905 dimensions
[3] = readdim
[3];
1911 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1912 (guint32
*)dimensions
, 4);
1918 /* pick some fallbacks... */
1919 if (dir
== 0 || dir
== 1) { /* horz */
1920 x
= screen_area(self
->desktop
)->x
+
1921 screen_area(self
->desktop
)->width
/ 4;
1922 w
= screen_area(self
->desktop
)->width
/ 2;
1924 if (dir
== 0 || dir
== 2) { /* vert */
1925 y
= screen_area(self
->desktop
)->y
+
1926 screen_area(self
->desktop
)->height
/ 4;
1927 h
= screen_area(self
->desktop
)->height
/ 2;
1930 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1931 (guint32
**)&dimensions
, &num
)) {
1933 if (dir
== 0 || dir
== 1) { /* horz */
1937 if (dir
== 0 || dir
== 2) { /* vert */
1946 if (dir
== 0 || dir
== 1) /* horz */
1947 self
->max_horz
= max
;
1948 if (dir
== 0 || dir
== 2) /* vert */
1949 self
->max_vert
= max
;
1951 if (!self
->max_horz
&& !self
->max_vert
)
1952 PROP_ERASE(self
->window
, openbox_premax
);
1954 client_change_state(self
); /* change the state hints on the client */
1956 /* figure out where the client should be going */
1957 frame_frame_gravity(self
->frame
, &x
, &y
);
1958 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1961 void client_shade(Client
*self
, gboolean shade
)
1963 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1964 self
->shaded
== shade
) return; /* already done */
1966 /* when we're iconic, don't change the wmstate */
1968 self
->wmstate
= shade
? IconicState
: NormalState
;
1969 self
->shaded
= shade
;
1970 client_change_state(self
);
1971 /* resize the frame to just the titlebar */
1972 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1975 void client_close(Client
*self
)
1979 if (!(self
->functions
& Func_Close
)) return;
1982 XXX: itd be cool to do timeouts and shit here for killing the client's
1984 like... if the window is around after 5 seconds, then the close button
1985 turns a nice red, and if this function is called again, the client is
1989 ce
.xclient
.type
= ClientMessage
;
1990 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1991 ce
.xclient
.display
= ob_display
;
1992 ce
.xclient
.window
= self
->window
;
1993 ce
.xclient
.format
= 32;
1994 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1995 ce
.xclient
.data
.l
[1] = event_lasttime
;
1996 ce
.xclient
.data
.l
[2] = 0l;
1997 ce
.xclient
.data
.l
[3] = 0l;
1998 ce
.xclient
.data
.l
[4] = 0l;
1999 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2002 void client_kill(Client
*self
)
2004 XKillClient(ob_display
, self
->window
);
2007 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
2011 if (target
== self
->desktop
) return;
2013 g_message("Setting desktop %u", target
);
2015 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2017 /* remove from the old desktop(s) */
2018 focus_order_remove(self
);
2020 old
= self
->desktop
;
2021 self
->desktop
= target
;
2022 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2023 /* the frame can display the current desktop state */
2024 frame_adjust_state(self
->frame
);
2025 /* 'move' the window to the new desktop */
2027 client_showhide(self
);
2028 /* raise if it was not already on the desktop */
2029 if (old
!= DESKTOP_ALL
)
2030 stacking_raise(self
);
2031 screen_update_struts();
2033 /* add to the new desktop(s) */
2034 if (config_focus_new
)
2035 focus_order_to_top(self
);
2037 focus_order_to_bottom(self
);
2039 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2042 Client
*client_search_modal_child(Client
*self
)
2047 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2048 Client
*c
= it
->data
;
2049 if ((ret
= client_search_modal_child(c
))) return ret
;
2050 if (c
->modal
) return c
;
2055 gboolean
client_validate(Client
*self
)
2059 XSync(ob_display
, FALSE
); /* get all events on the server */
2061 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2062 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2063 XPutBackEvent(ob_display
, &e
);
2070 void client_set_wm_state(Client
*self
, long state
)
2072 if (state
== self
->wmstate
) return; /* no change */
2076 client_iconify(self
, TRUE
, TRUE
);
2079 client_iconify(self
, FALSE
, TRUE
);
2084 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
2086 gboolean shaded
= self
->shaded
;
2087 gboolean fullscreen
= self
->fullscreen
;
2088 gboolean max_horz
= self
->max_horz
;
2089 gboolean max_vert
= self
->max_vert
;
2092 if (!(action
== prop_atoms
.net_wm_state_add
||
2093 action
== prop_atoms
.net_wm_state_remove
||
2094 action
== prop_atoms
.net_wm_state_toggle
))
2095 /* an invalid action was passed to the client message, ignore it */
2098 for (i
= 0; i
< 2; ++i
) {
2099 Atom state
= i
== 0 ? data1
: data2
;
2101 if (!state
) continue;
2103 /* if toggling, then pick whether we're adding or removing */
2104 if (action
== prop_atoms
.net_wm_state_toggle
) {
2105 if (state
== prop_atoms
.net_wm_state_modal
)
2106 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2107 prop_atoms
.net_wm_state_add
;
2108 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2109 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2110 prop_atoms
.net_wm_state_add
;
2111 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2112 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2113 prop_atoms
.net_wm_state_add
;
2114 else if (state
== prop_atoms
.net_wm_state_shaded
)
2115 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2116 prop_atoms
.net_wm_state_add
;
2117 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2118 action
= self
->skip_taskbar
?
2119 prop_atoms
.net_wm_state_remove
:
2120 prop_atoms
.net_wm_state_add
;
2121 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2122 action
= self
->skip_pager
?
2123 prop_atoms
.net_wm_state_remove
:
2124 prop_atoms
.net_wm_state_add
;
2125 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2126 action
= self
->fullscreen
?
2127 prop_atoms
.net_wm_state_remove
:
2128 prop_atoms
.net_wm_state_add
;
2129 else if (state
== prop_atoms
.net_wm_state_above
)
2130 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2131 prop_atoms
.net_wm_state_add
;
2132 else if (state
== prop_atoms
.net_wm_state_below
)
2133 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2134 prop_atoms
.net_wm_state_add
;
2137 if (action
== prop_atoms
.net_wm_state_add
) {
2138 if (state
== prop_atoms
.net_wm_state_modal
) {
2139 /* XXX raise here or something? */
2141 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2143 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2145 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2147 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2148 self
->skip_taskbar
= TRUE
;
2149 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2150 self
->skip_pager
= TRUE
;
2151 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2153 } else if (state
== prop_atoms
.net_wm_state_above
) {
2155 } else if (state
== prop_atoms
.net_wm_state_below
) {
2159 } else { /* action == prop_atoms.net_wm_state_remove */
2160 if (state
== prop_atoms
.net_wm_state_modal
) {
2161 self
->modal
= FALSE
;
2162 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2164 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2166 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2168 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2169 self
->skip_taskbar
= FALSE
;
2170 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2171 self
->skip_pager
= FALSE
;
2172 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2174 } else if (state
== prop_atoms
.net_wm_state_above
) {
2175 self
->above
= FALSE
;
2176 } else if (state
== prop_atoms
.net_wm_state_below
) {
2177 self
->below
= FALSE
;
2181 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2182 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2184 if (max_horz
== max_vert
) { /* both going the same way */
2185 client_maximize(self
, max_horz
, 0, TRUE
);
2187 client_maximize(self
, max_horz
, 1, TRUE
);
2188 client_maximize(self
, max_vert
, 2, TRUE
);
2192 if (max_horz
!= self
->max_horz
)
2193 client_maximize(self
, max_horz
, 1, TRUE
);
2195 client_maximize(self
, max_vert
, 2, TRUE
);
2198 /* change fullscreen state before shading, as it will affect if the window
2200 if (fullscreen
!= self
->fullscreen
)
2201 client_fullscreen(self
, fullscreen
, TRUE
);
2202 if (shaded
!= self
->shaded
)
2203 client_shade(self
, shaded
);
2204 client_calc_layer(self
);
2205 client_change_state(self
); /* change the hint to relect these changes */
2208 Client
*client_focus_target(Client
*self
)
2212 /* if we have a modal child, then focus it, not us */
2213 child
= client_search_modal_child(self
);
2214 if (child
) return child
;
2218 gboolean
client_focus(Client
*self
)
2222 /* choose the correct target */
2223 self
= client_focus_target(self
);
2225 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2226 /* update the focus lists */
2227 focus_order_to_top(self
);
2231 if (!((self
->can_focus
|| self
->focus_notify
) &&
2232 (self
->desktop
== screen_desktop
||
2233 self
->desktop
== DESKTOP_ALL
) &&
2237 /* do a check to see if the window has already been unmapped or destroyed
2238 do this intelligently while watching out for unmaps we've generated
2239 (ignore_unmaps > 0) */
2240 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2241 DestroyNotify
, &ev
)) {
2242 XPutBackEvent(ob_display
, &ev
);
2245 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2246 UnmapNotify
, &ev
)) {
2247 if (self
->ignore_unmaps
) {
2248 self
->ignore_unmaps
--;
2250 XPutBackEvent(ob_display
, &ev
);
2255 if (self
->can_focus
)
2256 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2257 I choose to use it always, hopefully to find errors quicker, if any
2258 are left. (I hate X. I hate focus events.) */
2259 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2262 if (self
->focus_notify
) {
2264 ce
.xclient
.type
= ClientMessage
;
2265 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2266 ce
.xclient
.display
= ob_display
;
2267 ce
.xclient
.window
= self
->window
;
2268 ce
.xclient
.format
= 32;
2269 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2270 ce
.xclient
.data
.l
[1] = event_lasttime
;
2271 ce
.xclient
.data
.l
[2] = 0l;
2272 ce
.xclient
.data
.l
[3] = 0l;
2273 ce
.xclient
.data
.l
[4] = 0l;
2274 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2278 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2283 /* Cause the FocusIn to come back to us. Important for desktop switches,
2284 since otherwise we'll have no FocusIn on the queue and send it off to
2285 the focus_backup. */
2286 XSync(ob_display
, FALSE
);
2290 void client_unfocus(Client
*self
)
2292 g_assert(focus_client
== self
);
2294 g_message("client_unfocus for %lx", self
->window
);
2296 focus_fallback(Fallback_Unfocusing
);
2299 void client_activate(Client
*self
)
2301 if (client_normal(self
) && screen_showing_desktop
)
2302 screen_show_desktop(FALSE
);
2304 client_iconify(self
, FALSE
, TRUE
);
2305 else if (!self
->frame
->visible
)
2306 /* if its not visible for other reasons, then don't mess
2310 client_shade(self
, FALSE
);
2312 stacking_raise(self
);
2315 gboolean
client_focused(Client
*self
)
2317 return self
== focus_client
;
2320 Icon
*client_icon(Client
*self
, int w
, int h
)
2323 /* si is the smallest image >= req */
2324 /* li is the largest image < req */
2325 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2327 if (!self
->nicons
) return NULL
;
2329 for (i
= 0; i
< self
->nicons
; ++i
) {
2330 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2331 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2335 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2340 if (largest
== 0) /* didnt find one smaller than the requested size */
2341 return &self
->icons
[si
];
2342 return &self
->icons
[li
];