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
)
1196 g_free(self
->title
);
1199 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1200 /* try old x stuff */
1201 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1202 data
= g_strdup("Unnamed Window");
1204 /* look for duplicates and append a number */
1206 for (it
= client_list
; it
; it
= it
->next
)
1207 if (it
->data
!= self
) {
1208 Client
*c
= it
->data
;
1209 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1210 nums
|= 1 << c
->title_count
;
1212 /* find first free number */
1213 for (i
= 1; i
<= 32; ++i
)
1214 if (!(nums
& (1 << i
))) {
1215 if (self
->title_count
== 1 || i
== 1)
1216 self
->title_count
= i
;
1219 /* dont display the number for the first window */
1220 if (self
->title_count
> 1) {
1221 char *vdata
, *ndata
;
1222 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1223 vdata
= g_strconcat(data
, ndata
, NULL
);
1229 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1234 frame_adjust_title(self
->frame
);
1236 /* update the icon title */
1238 g_free(self
->icon_title
);
1241 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1242 /* try old x stuff */
1243 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
))
1244 data
= g_strdup("Unnamed Window");
1246 /* append the title count, dont display the number for the first window */
1247 if (self
->title_count
> 1) {
1248 char *vdata
, *ndata
;
1249 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1250 vdata
= g_strconcat(data
, ndata
, NULL
);
1256 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1258 self
->icon_title
= data
;
1261 void client_update_class(Client
*self
)
1266 if (self
->name
) g_free(self
->name
);
1267 if (self
->class) g_free(self
->class);
1268 if (self
->role
) g_free(self
->role
);
1270 self
->name
= self
->class = self
->role
= NULL
;
1272 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1274 self
->name
= g_strdup(data
[0]);
1276 self
->class = g_strdup(data
[1]);
1281 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1282 self
->role
= g_strdup(s
);
1284 if (self
->name
== NULL
) self
->name
= g_strdup("");
1285 if (self
->class == NULL
) self
->class = g_strdup("");
1286 if (self
->role
== NULL
) self
->role
= g_strdup("");
1289 void client_update_strut(Client
*self
)
1294 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1295 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1298 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1300 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1304 /* updating here is pointless while we're being mapped cuz we're not in
1305 the client list yet */
1307 screen_update_struts();
1310 void client_update_icons(Client
*self
)
1317 for (j
= 0; j
< self
->nicons
; ++j
)
1318 g_free(self
->icons
[j
].data
);
1319 if (self
->nicons
> 0)
1320 g_free(self
->icons
);
1323 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1324 /* figure out how many valid icons are in here */
1326 while (num
- i
> 2) {
1334 self
->icons
= g_new(Icon
, self
->nicons
);
1336 /* store the icons */
1338 for (j
= 0; j
< self
->nicons
; ++j
) {
1339 w
= self
->icons
[j
].width
= data
[i
++];
1340 h
= self
->icons
[j
].height
= data
[i
++];
1341 self
->icons
[j
].data
=
1342 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1351 frame_adjust_icon(self
->frame
);
1354 void client_update_kwm_icon(Client
*self
)
1359 if (!PROP_GETA32(self
->window
, kwm_win_icon
, kwm_win_icon
, &data
, &num
)) {
1360 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1363 self
->pixmap_icon
= data
[0];
1364 self
->pixmap_icon_mask
= data
[1];
1366 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1370 frame_adjust_icon(self
->frame
);
1373 static void client_change_state(Client
*self
)
1376 guint32 netstate
[10];
1379 state
[0] = self
->wmstate
;
1381 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1385 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1387 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1389 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1390 if (self
->skip_taskbar
)
1391 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1392 if (self
->skip_pager
)
1393 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1394 if (self
->fullscreen
)
1395 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1397 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1399 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1401 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1403 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1404 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1406 client_calc_layer(self
);
1409 frame_adjust_state(self
->frame
);
1412 Client
*client_search_focus_tree(Client
*self
)
1417 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1418 if (client_focused(it
->data
)) return it
->data
;
1419 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1424 Client
*client_search_focus_tree_full(Client
*self
)
1426 if (self
->transient_for
) {
1427 if (self
->transient_for
!= TRAN_GROUP
) {
1428 return client_search_focus_tree_full(self
->transient_for
);
1432 for (it
= self
->group
->members
; it
; it
= it
->next
)
1433 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1435 if ((c
= client_search_focus_tree_full(it
->data
)))
1441 /* this function checks the whole tree, the client_search_focus_tree
1442 does not, so we need to check this window */
1443 if (client_focused(self
))
1445 return client_search_focus_tree(self
);
1449 static StackLayer
calc_layer(Client
*self
)
1453 if (self
->iconic
) l
= Layer_Icon
;
1454 else if (self
->fullscreen
) l
= Layer_Fullscreen
;
1455 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1456 else if (self
->type
== Type_Dock
) {
1457 if (!self
->below
) l
= Layer_Top
;
1458 else l
= Layer_Normal
;
1460 else if (self
->above
) l
= Layer_Above
;
1461 else if (self
->below
) l
= Layer_Below
;
1462 else l
= Layer_Normal
;
1467 static void calc_recursive(Client
*self
, Client
*orig
, StackLayer l
,
1470 StackLayer old
, own
;
1474 own
= calc_layer(self
);
1475 self
->layer
= l
> own
? l
: own
;
1477 for (it
= self
->transients
; it
; it
= it
->next
)
1478 calc_recursive(it
->data
, orig
, l
, raised
? raised
: l
!= old
);
1480 if (!raised
&& l
!= old
)
1481 if (orig
->frame
) /* only restack if the original window is managed */
1482 stacking_raise(self
);
1485 void client_calc_layer(Client
*self
)
1492 /* transients take on the layer of their parents */
1493 if (self
->transient_for
) {
1494 if (self
->transient_for
!= TRAN_GROUP
) {
1495 self
= self
->transient_for
;
1499 for (it
= self
->group
->members
; it
; it
= it
->next
)
1500 if (it
->data
!= self
&&
1501 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1508 l
= calc_layer(self
);
1510 calc_recursive(self
, orig
, l
, FALSE
);
1513 gboolean
client_should_show(Client
*self
)
1515 if (self
->iconic
) return FALSE
;
1516 else if (!(self
->desktop
== screen_desktop
||
1517 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1518 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1523 static void client_showhide(Client
*self
)
1526 if (client_should_show(self
))
1527 frame_show(self
->frame
);
1529 frame_hide(self
->frame
);
1532 gboolean
client_normal(Client
*self
) {
1533 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1534 self
->type
== Type_Splash
);
1537 static void client_apply_startup_state(Client
*self
)
1539 /* these are in a carefully crafted order.. */
1542 self
->iconic
= FALSE
;
1543 client_iconify(self
, TRUE
, FALSE
);
1545 if (self
->fullscreen
) {
1546 self
->fullscreen
= FALSE
;
1547 client_fullscreen(self
, TRUE
, FALSE
);
1550 self
->shaded
= FALSE
;
1551 client_shade(self
, TRUE
);
1554 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1556 if (self
->max_vert
&& self
->max_horz
) {
1557 self
->max_vert
= self
->max_horz
= FALSE
;
1558 client_maximize(self
, TRUE
, 0, FALSE
);
1559 } else if (self
->max_vert
) {
1560 self
->max_vert
= FALSE
;
1561 client_maximize(self
, TRUE
, 2, FALSE
);
1562 } else if (self
->max_horz
) {
1563 self
->max_horz
= FALSE
;
1564 client_maximize(self
, TRUE
, 1, FALSE
);
1567 /* nothing to do for the other states:
1576 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1577 gboolean user
, gboolean final
)
1579 gboolean moved
= FALSE
, resized
= FALSE
;
1581 /* gets the frame's position */
1582 frame_client_gravity(self
->frame
, &x
, &y
);
1584 /* these positions are frame positions, not client positions */
1586 /* set the size and position if fullscreen */
1587 if (self
->fullscreen
) {
1590 w
= screen_physical_size
.width
;
1591 h
= screen_physical_size
.height
;
1592 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1594 /* set the size and position if maximized */
1595 if (self
->max_horz
) {
1596 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1597 w
= screen_area(self
->desktop
)->width
;
1599 if (self
->max_vert
) {
1600 y
= screen_area(self
->desktop
)->y
;
1601 h
= screen_area(self
->desktop
)->height
-
1602 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1606 /* gets the client's position */
1607 frame_frame_gravity(self
->frame
, &x
, &y
);
1609 /* these override the above states! if you cant move you can't move! */
1611 if (!(self
->functions
& Func_Move
)) {
1615 if (!(self
->functions
& Func_Resize
)) {
1616 w
= self
->area
.width
;
1617 h
= self
->area
.height
;
1621 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1622 w
-= self
->base_size
.width
;
1623 h
-= self
->base_size
.height
;
1626 /* for interactive resizing. have to move half an increment in each
1629 /* how far we are towards the next size inc */
1630 int mw
= w
% self
->size_inc
.width
;
1631 int mh
= h
% self
->size_inc
.height
;
1633 int aw
= self
->size_inc
.width
/ 2;
1634 int ah
= self
->size_inc
.height
/ 2;
1635 /* don't let us move into a new size increment */
1636 if (mw
+ aw
>= self
->size_inc
.width
)
1637 aw
= self
->size_inc
.width
- mw
- 1;
1638 if (mh
+ ah
>= self
->size_inc
.height
)
1639 ah
= self
->size_inc
.height
- mh
- 1;
1643 /* if this is a user-requested resize, then check against min/max
1644 sizes and aspect ratios */
1646 /* smaller than min size or bigger than max size? */
1647 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1648 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1649 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1650 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1652 /* adjust the height ot match the width for the aspect ratios */
1653 if (self
->min_ratio
)
1654 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1655 if (self
->max_ratio
)
1656 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1659 /* keep to the increments */
1660 w
/= self
->size_inc
.width
;
1661 h
/= self
->size_inc
.height
;
1663 /* you cannot resize to nothing */
1667 /* store the logical size */
1668 SIZE_SET(self
->logical_size
, w
, h
);
1670 w
*= self
->size_inc
.width
;
1671 h
*= self
->size_inc
.height
;
1673 w
+= self
->base_size
.width
;
1674 h
+= self
->base_size
.height
;
1678 case Corner_TopLeft
:
1680 case Corner_TopRight
:
1681 x
-= w
- self
->area
.width
;
1683 case Corner_BottomLeft
:
1684 y
-= h
- self
->area
.height
;
1686 case Corner_BottomRight
:
1687 x
-= w
- self
->area
.width
;
1688 y
-= h
- self
->area
.height
;
1692 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1693 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1695 RECT_SET(self
->area
, x
, y
, w
, h
);
1698 XResizeWindow(ob_display
, self
->window
, w
, h
);
1700 /* move/resize the frame to match the request */
1702 if (moved
|| resized
)
1703 frame_adjust_area(self
->frame
, moved
, resized
);
1705 if (!user
|| final
) {
1707 event
.type
= ConfigureNotify
;
1708 event
.xconfigure
.display
= ob_display
;
1709 event
.xconfigure
.event
= self
->window
;
1710 event
.xconfigure
.window
= self
->window
;
1712 /* root window coords with border in mind */
1713 event
.xconfigure
.x
= x
- self
->border_width
+
1714 self
->frame
->size
.left
;
1715 event
.xconfigure
.y
= y
- self
->border_width
+
1716 self
->frame
->size
.top
;
1718 event
.xconfigure
.width
= self
->area
.width
;
1719 event
.xconfigure
.height
= self
->area
.height
;
1720 event
.xconfigure
.border_width
= self
->border_width
;
1721 event
.xconfigure
.above
= self
->frame
->plate
;
1722 event
.xconfigure
.override_redirect
= FALSE
;
1723 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1724 FALSE
, StructureNotifyMask
, &event
);
1729 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1733 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1734 self
->fullscreen
== fs
) return; /* already done */
1736 self
->fullscreen
= fs
;
1737 client_change_state(self
); /* change the state hints on the client,
1738 and adjust out layer/stacking */
1742 guint32 dimensions
[4];
1743 dimensions
[0] = self
->area
.x
;
1744 dimensions
[1] = self
->area
.y
;
1745 dimensions
[2] = self
->area
.width
;
1746 dimensions
[3] = self
->area
.height
;
1748 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1752 /* these are not actually used cuz client_configure will set them
1753 as appropriate when the window is fullscreened */
1759 /* pick some fallbacks... */
1760 x
= screen_area(self
->desktop
)->x
+
1761 screen_area(self
->desktop
)->width
/ 4;
1762 y
= screen_area(self
->desktop
)->y
+
1763 screen_area(self
->desktop
)->height
/ 4;
1764 w
= screen_area(self
->desktop
)->width
/ 2;
1765 h
= screen_area(self
->desktop
)->height
/ 2;
1767 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1768 (guint32
**)&dimensions
, &num
)) {
1779 client_setup_decor_and_functions(self
);
1781 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1783 /* try focus us when we go into fullscreen mode */
1787 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1791 /* move up the transient chain as far as possible first */
1792 if (self
->transient_for
) {
1793 if (self
->transient_for
!= TRAN_GROUP
) {
1794 if (self
->transient_for
->iconic
!= iconic
) {
1795 client_iconify(self
->transient_for
, iconic
, curdesk
);
1801 /* the check for TRAN_GROUP is to prevent an infinate loop with
1802 2 transients of the same group at the head of the group's
1804 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1805 Client
*c
= it
->data
;
1806 if (c
!= self
&& c
->iconic
!= iconic
&&
1807 c
->transient_for
!= TRAN_GROUP
) {
1808 client_iconify(it
->data
, iconic
, curdesk
);
1812 if (it
!= NULL
) return;
1816 if (self
->iconic
== iconic
) return; /* nothing to do */
1818 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1821 self
->iconic
= iconic
;
1824 self
->wmstate
= IconicState
;
1825 self
->ignore_unmaps
++;
1826 /* we unmap the client itself so that we can get MapRequest events,
1827 and because the ICCCM tells us to! */
1828 XUnmapWindow(ob_display
, self
->window
);
1830 /* update the focus lists.. iconic windows go to the bottom of the
1831 list, put the new iconic window at the 'top of the bottom'. */
1832 focus_order_to_top(self
);
1835 client_set_desktop(self
, screen_desktop
, FALSE
);
1836 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1837 XMapWindow(ob_display
, self
->window
);
1839 /* this puts it after the current focused window */
1840 focus_order_remove(self
);
1841 focus_order_add_new(self
);
1843 client_change_state(self
);
1844 client_showhide(self
);
1845 screen_update_struts();
1847 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1850 /* iconify all transients */
1851 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1852 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1855 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1859 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1860 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1862 /* check if already done */
1864 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1865 if (dir
== 1 && self
->max_horz
) return;
1866 if (dir
== 2 && self
->max_vert
) return;
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;
1873 /* work with the frame's coords */
1874 x
= self
->frame
->area
.x
;
1875 y
= self
->frame
->area
.y
;
1876 w
= self
->area
.width
;
1877 h
= self
->area
.height
;
1881 gint32 dimensions
[4];
1890 /* get the property off the window and use it for the dimensions
1891 we are already maxed on */
1892 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1893 (guint32
**)&readdim
, &num
)) {
1895 if (self
->max_horz
) {
1896 dimensions
[0] = readdim
[0];
1897 dimensions
[2] = readdim
[2];
1899 if (self
->max_vert
) {
1900 dimensions
[1] = readdim
[1];
1901 dimensions
[3] = readdim
[3];
1907 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1908 (guint32
*)dimensions
, 4);
1914 /* pick some fallbacks... */
1915 if (dir
== 0 || dir
== 1) { /* horz */
1916 x
= screen_area(self
->desktop
)->x
+
1917 screen_area(self
->desktop
)->width
/ 4;
1918 w
= screen_area(self
->desktop
)->width
/ 2;
1920 if (dir
== 0 || dir
== 2) { /* vert */
1921 y
= screen_area(self
->desktop
)->y
+
1922 screen_area(self
->desktop
)->height
/ 4;
1923 h
= screen_area(self
->desktop
)->height
/ 2;
1926 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1927 (guint32
**)&dimensions
, &num
)) {
1929 if (dir
== 0 || dir
== 1) { /* horz */
1933 if (dir
== 0 || dir
== 2) { /* vert */
1942 if (dir
== 0 || dir
== 1) /* horz */
1943 self
->max_horz
= max
;
1944 if (dir
== 0 || dir
== 2) /* vert */
1945 self
->max_vert
= max
;
1947 if (!self
->max_horz
&& !self
->max_vert
)
1948 PROP_ERASE(self
->window
, openbox_premax
);
1950 client_change_state(self
); /* change the state hints on the client */
1952 /* figure out where the client should be going */
1953 frame_frame_gravity(self
->frame
, &x
, &y
);
1954 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1957 void client_shade(Client
*self
, gboolean shade
)
1959 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1960 self
->shaded
== shade
) return; /* already done */
1962 /* when we're iconic, don't change the wmstate */
1964 self
->wmstate
= shade
? IconicState
: NormalState
;
1965 self
->shaded
= shade
;
1966 client_change_state(self
);
1967 /* resize the frame to just the titlebar */
1968 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1971 void client_close(Client
*self
)
1975 if (!(self
->functions
& Func_Close
)) return;
1978 XXX: itd be cool to do timeouts and shit here for killing the client's
1980 like... if the window is around after 5 seconds, then the close button
1981 turns a nice red, and if this function is called again, the client is
1985 ce
.xclient
.type
= ClientMessage
;
1986 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1987 ce
.xclient
.display
= ob_display
;
1988 ce
.xclient
.window
= self
->window
;
1989 ce
.xclient
.format
= 32;
1990 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1991 ce
.xclient
.data
.l
[1] = event_lasttime
;
1992 ce
.xclient
.data
.l
[2] = 0l;
1993 ce
.xclient
.data
.l
[3] = 0l;
1994 ce
.xclient
.data
.l
[4] = 0l;
1995 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1998 void client_kill(Client
*self
)
2000 XKillClient(ob_display
, self
->window
);
2003 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
2007 if (target
== self
->desktop
) return;
2009 g_message("Setting desktop %u", target
);
2011 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2013 /* remove from the old desktop(s) */
2014 focus_order_remove(self
);
2016 old
= self
->desktop
;
2017 self
->desktop
= target
;
2018 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2019 /* the frame can display the current desktop state */
2020 frame_adjust_state(self
->frame
);
2021 /* 'move' the window to the new desktop */
2023 client_showhide(self
);
2024 /* raise if it was not already on the desktop */
2025 if (old
!= DESKTOP_ALL
)
2026 stacking_raise(self
);
2027 screen_update_struts();
2029 /* add to the new desktop(s) */
2030 if (config_focus_new
)
2031 focus_order_to_top(self
);
2033 focus_order_to_bottom(self
);
2035 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2038 Client
*client_search_modal_child(Client
*self
)
2043 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2044 Client
*c
= it
->data
;
2045 if ((ret
= client_search_modal_child(c
))) return ret
;
2046 if (c
->modal
) return c
;
2051 gboolean
client_validate(Client
*self
)
2055 XSync(ob_display
, FALSE
); /* get all events on the server */
2057 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2058 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2059 XPutBackEvent(ob_display
, &e
);
2066 void client_set_wm_state(Client
*self
, long state
)
2068 if (state
== self
->wmstate
) return; /* no change */
2072 client_iconify(self
, TRUE
, TRUE
);
2075 client_iconify(self
, FALSE
, TRUE
);
2080 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
2082 gboolean shaded
= self
->shaded
;
2083 gboolean fullscreen
= self
->fullscreen
;
2084 gboolean max_horz
= self
->max_horz
;
2085 gboolean max_vert
= self
->max_vert
;
2088 if (!(action
== prop_atoms
.net_wm_state_add
||
2089 action
== prop_atoms
.net_wm_state_remove
||
2090 action
== prop_atoms
.net_wm_state_toggle
))
2091 /* an invalid action was passed to the client message, ignore it */
2094 for (i
= 0; i
< 2; ++i
) {
2095 Atom state
= i
== 0 ? data1
: data2
;
2097 if (!state
) continue;
2099 /* if toggling, then pick whether we're adding or removing */
2100 if (action
== prop_atoms
.net_wm_state_toggle
) {
2101 if (state
== prop_atoms
.net_wm_state_modal
)
2102 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2103 prop_atoms
.net_wm_state_add
;
2104 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2105 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2106 prop_atoms
.net_wm_state_add
;
2107 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2108 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2109 prop_atoms
.net_wm_state_add
;
2110 else if (state
== prop_atoms
.net_wm_state_shaded
)
2111 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2112 prop_atoms
.net_wm_state_add
;
2113 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2114 action
= self
->skip_taskbar
?
2115 prop_atoms
.net_wm_state_remove
:
2116 prop_atoms
.net_wm_state_add
;
2117 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2118 action
= self
->skip_pager
?
2119 prop_atoms
.net_wm_state_remove
:
2120 prop_atoms
.net_wm_state_add
;
2121 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2122 action
= self
->fullscreen
?
2123 prop_atoms
.net_wm_state_remove
:
2124 prop_atoms
.net_wm_state_add
;
2125 else if (state
== prop_atoms
.net_wm_state_above
)
2126 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2127 prop_atoms
.net_wm_state_add
;
2128 else if (state
== prop_atoms
.net_wm_state_below
)
2129 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2130 prop_atoms
.net_wm_state_add
;
2133 if (action
== prop_atoms
.net_wm_state_add
) {
2134 if (state
== prop_atoms
.net_wm_state_modal
) {
2135 /* XXX raise here or something? */
2137 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2139 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2141 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2143 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2144 self
->skip_taskbar
= TRUE
;
2145 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2146 self
->skip_pager
= TRUE
;
2147 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2149 } else if (state
== prop_atoms
.net_wm_state_above
) {
2151 } else if (state
== prop_atoms
.net_wm_state_below
) {
2155 } else { /* action == prop_atoms.net_wm_state_remove */
2156 if (state
== prop_atoms
.net_wm_state_modal
) {
2157 self
->modal
= FALSE
;
2158 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2160 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2162 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2164 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2165 self
->skip_taskbar
= FALSE
;
2166 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2167 self
->skip_pager
= FALSE
;
2168 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2170 } else if (state
== prop_atoms
.net_wm_state_above
) {
2171 self
->above
= FALSE
;
2172 } else if (state
== prop_atoms
.net_wm_state_below
) {
2173 self
->below
= FALSE
;
2177 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2178 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2180 if (max_horz
== max_vert
) { /* both going the same way */
2181 client_maximize(self
, max_horz
, 0, TRUE
);
2183 client_maximize(self
, max_horz
, 1, TRUE
);
2184 client_maximize(self
, max_vert
, 2, TRUE
);
2188 if (max_horz
!= self
->max_horz
)
2189 client_maximize(self
, max_horz
, 1, TRUE
);
2191 client_maximize(self
, max_vert
, 2, TRUE
);
2194 /* change fullscreen state before shading, as it will affect if the window
2196 if (fullscreen
!= self
->fullscreen
)
2197 client_fullscreen(self
, fullscreen
, TRUE
);
2198 if (shaded
!= self
->shaded
)
2199 client_shade(self
, shaded
);
2200 client_calc_layer(self
);
2201 client_change_state(self
); /* change the hint to relect these changes */
2204 Client
*client_focus_target(Client
*self
)
2208 /* if we have a modal child, then focus it, not us */
2209 child
= client_search_modal_child(self
);
2210 if (child
) return child
;
2214 gboolean
client_focus(Client
*self
)
2218 /* choose the correct target */
2219 self
= client_focus_target(self
);
2221 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2222 /* update the focus lists */
2223 focus_order_to_top(self
);
2227 if (!((self
->can_focus
|| self
->focus_notify
) &&
2228 (self
->desktop
== screen_desktop
||
2229 self
->desktop
== DESKTOP_ALL
) &&
2233 /* do a check to see if the window has already been unmapped or destroyed
2234 do this intelligently while watching out for unmaps we've generated
2235 (ignore_unmaps > 0) */
2236 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2237 DestroyNotify
, &ev
)) {
2238 XPutBackEvent(ob_display
, &ev
);
2241 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2242 UnmapNotify
, &ev
)) {
2243 if (self
->ignore_unmaps
) {
2244 self
->ignore_unmaps
--;
2246 XPutBackEvent(ob_display
, &ev
);
2251 if (self
->can_focus
)
2252 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2253 I choose to use it always, hopefully to find errors quicker, if any
2254 are left. (I hate X. I hate focus events.) */
2255 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2258 if (self
->focus_notify
) {
2260 ce
.xclient
.type
= ClientMessage
;
2261 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2262 ce
.xclient
.display
= ob_display
;
2263 ce
.xclient
.window
= self
->window
;
2264 ce
.xclient
.format
= 32;
2265 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2266 ce
.xclient
.data
.l
[1] = event_lasttime
;
2267 ce
.xclient
.data
.l
[2] = 0l;
2268 ce
.xclient
.data
.l
[3] = 0l;
2269 ce
.xclient
.data
.l
[4] = 0l;
2270 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2274 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2279 /* Cause the FocusIn to come back to us. Important for desktop switches,
2280 since otherwise we'll have no FocusIn on the queue and send it off to
2281 the focus_backup. */
2282 XSync(ob_display
, FALSE
);
2286 void client_unfocus(Client
*self
)
2288 g_assert(focus_client
== self
);
2290 g_message("client_unfocus for %lx", self
->window
);
2292 focus_fallback(Fallback_Unfocusing
);
2295 gboolean
client_focused(Client
*self
)
2297 return self
== focus_client
;
2300 Icon
*client_icon(Client
*self
, int w
, int h
)
2303 /* si is the smallest image >= req */
2304 /* li is the largest image < req */
2305 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2307 if (!self
->nicons
) return NULL
;
2309 for (i
= 0; i
< self
->nicons
; ++i
) {
2310 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2311 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2315 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2320 if (largest
== 0) /* didnt find one smaller than the requested size */
2321 return &self
->icons
[si
];
2322 return &self
->icons
[li
];