5 #include "moveresize.h"
7 #include "extensions.h"
17 #include "render/render.h"
20 #include <X11/Xutil.h>
22 /*! The event mask to grab on client windows */
23 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
26 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
29 GList
*client_list
= NULL
;
31 static void client_get_all(Client
*self
);
32 static void client_toggle_border(Client
*self
, gboolean show
);
33 static void client_get_area(Client
*self
);
34 static void client_get_desktop(Client
*self
);
35 static void client_get_state(Client
*self
);
36 static void client_get_shaped(Client
*self
);
37 static void client_get_mwm_hints(Client
*self
);
38 static void client_get_gravity(Client
*self
);
39 static void client_showhide(Client
*self
);
40 static void client_change_allowed_actions(Client
*self
);
41 static void client_change_state(Client
*self
);
42 static void client_apply_startup_state(Client
*self
);
49 void client_shutdown()
53 void client_set_list()
55 Window
*windows
, *win_it
;
57 guint size
= g_list_length(client_list
);
59 /* create an array of the window ids */
61 windows
= g_new(Window
, size
);
63 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
64 *win_it
= ((Client
*)it
->data
)->window
;
68 PROP_SETA32(ob_root
, net_client_list
, window
, (guint32
*)windows
, size
);
77 void client_foreach_transient(Client *self, ClientForeachFunc func, void *data)
81 for (it = self->transients; it; it = it->next) {
82 if (!func(it->data, data)) return;
83 client_foreach_transient(it->data, func, data);
87 void client_foreach_ancestor(Client *self, ClientForeachFunc func, void *data)
89 if (self->transient_for) {
90 if (self->transient_for != TRAN_GROUP) {
91 if (!func(self->transient_for, data)) return;
92 client_foreach_ancestor(self->transient_for, func, data);
96 for (it = self->group->members; it; it = it->next)
97 if (it->data != self &&
98 !((Client*)it->data)->transient_for) {
99 if (!func(it->data, data)) return;
100 client_foreach_ancestor(it->data, func, data);
107 void client_manage_all()
109 unsigned int i
, j
, nchild
;
112 XWindowAttributes attrib
;
114 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
116 /* remove all icon windows from the list */
117 for (i
= 0; i
< nchild
; i
++) {
118 if (children
[i
] == None
) continue;
119 wmhints
= XGetWMHints(ob_display
, children
[i
]);
121 if ((wmhints
->flags
& IconWindowHint
) &&
122 (wmhints
->icon_window
!= children
[i
]))
123 for (j
= 0; j
< nchild
; j
++)
124 if (children
[j
] == wmhints
->icon_window
) {
132 for (i
= 0; i
< nchild
; ++i
) {
133 if (children
[i
] == None
)
135 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
136 if (attrib
.override_redirect
) continue;
138 if (attrib
.map_state
!= IsUnmapped
)
139 client_manage(children
[i
]);
144 /* stack them as they were on startup!
145 why with stacking_lower? Why, because then windows who aren't in the
146 stacking list are on the top where you can see them instead of buried
148 for (i
= startup_stack_size
; i
> 0; --i
) {
151 w
= startup_stack_order
[i
-1];
152 obw
= g_hash_table_lookup(window_map
, &w
);
154 g_assert(WINDOW_IS_CLIENT(obw
));
155 stacking_lower(CLIENT_AS_WINDOW(obw
));
158 g_free(startup_stack_order
);
159 startup_stack_order
= NULL
;
160 startup_stack_size
= 0;
162 if (config_focus_new
) {
165 active
= g_hash_table_lookup(window_map
, &startup_active
);
167 g_assert(WINDOW_IS_CLIENT(active
));
168 if (!client_focus(WINDOW_AS_CLIENT(active
)))
169 focus_fallback(Fallback_NoFocus
);
171 focus_fallback(Fallback_NoFocus
);
175 void client_manage(Window window
)
179 XWindowAttributes attrib
;
180 XSetWindowAttributes attrib_set
;
182 gboolean activate
= FALSE
;
186 /* check if it has already been unmapped by the time we started mapping
187 the grab does a sync so we don't have to here */
188 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
189 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
190 XPutBackEvent(ob_display
, &e
);
193 return; /* don't manage it */
196 /* make sure it isn't an override-redirect window */
197 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
198 attrib
.override_redirect
) {
200 return; /* don't manage it */
203 /* is the window a docking app */
204 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
205 if ((wmhint
->flags
& StateHint
) &&
206 wmhint
->initial_state
== WithdrawnState
) {
207 dock_add(window
, wmhint
);
215 g_message("Managing window: %lx", window
);
217 /* choose the events we want to receive on the CLIENT window */
218 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
219 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
220 XChangeWindowAttributes(ob_display
, window
,
221 CWEventMask
|CWDontPropagate
, &attrib_set
);
224 /* create the Client struct, and populate it from the hints on the
226 self
= g_new(Client
, 1);
227 self
->obwin
.type
= Window_Client
;
228 self
->window
= window
;
229 client_get_all(self
);
231 /* remove the client's border (and adjust re gravity) */
232 client_toggle_border(self
, FALSE
);
234 /* specify that if we exit, the window should not be destroyed and should
235 be reparented back to root automatically */
236 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
238 /* create the decoration frame for the client window */
239 self
->frame
= frame_new();
241 frame_grab_client(self
->frame
, self
);
243 client_apply_startup_state(self
);
247 /* add to client list/map */
248 client_list
= g_list_append(client_list
, self
);
249 g_hash_table_insert(window_map
, &self
->window
, self
);
251 /* update the focus lists */
252 focus_order_add_new(self
);
254 /* focus the new window? */
255 if (ob_state
!= State_Starting
&& config_focus_new
) {
256 gboolean group_foc
= FALSE
;
261 for (it
= self
->group
->members
; it
; it
= it
->next
)
262 if (client_focused(it
->data
)) {
267 /* note the check against Type_Normal/Dialog, not client_normal(self),
268 which would also include other types. in this case we want more
269 strict rules for focus */
270 if (((self
->type
== Type_Normal
||
271 (self
->type
== Type_Dialog
&&
273 (!self
->transient_for
&& (!self
->group
||
274 !self
->group
->members
->next
)))))) ||
275 client_search_focus_tree_full(self
) ||
277 !client_normal(focus_client
)) {
278 /* activate the window */
279 stacking_add(CLIENT_AS_WINDOW(self
));
282 /* try to not get in the way */
283 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
286 stacking_add(CLIENT_AS_WINDOW(self
));
289 screen_update_struts();
291 /* make sure the window is visible */
292 client_move_onscreen(self
);
294 dispatch_client(Event_Client_New
, self
, 0, 0);
296 client_showhide(self
);
298 if (activate
) client_activate(self
);
300 /* update the list hints */
303 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
305 g_message("Managed window 0x%lx (%s)", window
, self
->class);
308 void client_unmanage_all()
310 while (client_list
!= NULL
)
311 client_unmanage(client_list
->data
);
314 void client_unmanage(Client
*self
)
319 g_message("Unmanaging window: %lx (%s)", self
->window
, self
->class);
321 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
322 g_assert(self
!= NULL
);
324 /* remove the window from our save set */
325 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
327 /* we dont want events no more */
328 XSelectInput(ob_display
, self
->window
, NoEventMask
);
330 frame_hide(self
->frame
);
332 client_list
= g_list_remove(client_list
, self
);
333 stacking_remove(self
);
334 g_hash_table_remove(window_map
, &self
->window
);
336 /* update the focus lists */
337 focus_order_remove(self
);
339 /* once the client is out of the list, update the struts to remove it's
341 screen_update_struts();
343 /* tell our parent(s) that we're gone */
344 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
347 for (it
= self
->group
->members
; it
; it
= it
->next
)
348 if (it
->data
!= self
)
349 ((Client
*)it
->data
)->transients
=
350 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
351 } else if (self
->transient_for
) { /* transient of window */
352 self
->transient_for
->transients
=
353 g_slist_remove(self
->transient_for
->transients
, self
);
356 /* tell our transients that we're gone */
357 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
358 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
359 ((Client
*)it
->data
)->transient_for
= NULL
;
360 client_calc_layer(it
->data
);
364 if (moveresize_client
== self
)
365 moveresize_end(TRUE
);
367 if (focus_client
== self
) {
370 /* focus the last focused window on the desktop, and ignore enter
371 events from the unmap so it doesnt mess with the focus */
372 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
373 client_unfocus(self
);
376 /* remove from its group */
378 group_remove(self
->group
, self
);
382 /* dispatch the unmapped event */
383 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
384 g_assert(self
!= NULL
);
386 /* give the client its border back */
387 client_toggle_border(self
, TRUE
);
389 /* reparent the window out of the frame, and free the frame */
390 frame_release_client(self
->frame
, self
);
393 if (ob_state
!= State_Exiting
) {
394 /* these values should not be persisted across a window
396 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
397 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
399 /* if we're left in an iconic state, the client wont be mapped. this is
400 bad, since we will no longer be managing the window on restart */
402 XMapWindow(ob_display
, self
->window
);
406 g_message("Unmanaged window 0x%lx", self
->window
);
408 /* free all data allocated in the client struct */
409 g_slist_free(self
->transients
);
410 for (j
= 0; j
< self
->nicons
; ++j
)
411 g_free(self
->icons
[j
].data
);
412 if (self
->nicons
> 0)
415 g_free(self
->icon_title
);
421 /* update the list hints */
425 void client_move_onscreen(Client
*self
)
428 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
430 a
= screen_area(self
->desktop
);
431 if (x
>= a
->x
+ a
->width
- 1)
432 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
433 if (y
>= a
->y
+ a
->height
- 1)
434 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
435 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
437 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
440 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
442 client_configure(self
, Corner_TopLeft
, x
, y
,
443 self
->area
.width
, self
->area
.height
,
447 static void client_toggle_border(Client
*self
, gboolean show
)
449 /* adjust our idea of where the client is, based on its border. When the
450 border is removed, the client should now be considered to be in a
452 when re-adding the border to the client, the same operation needs to be
454 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
455 int x
= oldx
, y
= oldy
;
456 switch(self
->gravity
) {
458 case NorthWestGravity
:
460 case SouthWestGravity
:
462 case NorthEastGravity
:
464 case SouthEastGravity
:
465 if (show
) x
-= self
->border_width
* 2;
466 else x
+= self
->border_width
* 2;
473 if (show
) x
-= self
->border_width
;
474 else x
+= self
->border_width
;
477 switch(self
->gravity
) {
479 case NorthWestGravity
:
481 case NorthEastGravity
:
483 case SouthWestGravity
:
485 case SouthEastGravity
:
486 if (show
) y
-= self
->border_width
* 2;
487 else y
+= self
->border_width
* 2;
494 if (show
) y
-= self
->border_width
;
495 else y
+= self
->border_width
;
502 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
504 /* move the client so it is back it the right spot _with_ its
506 if (x
!= oldx
|| y
!= oldy
)
507 XMoveWindow(ob_display
, self
->window
, x
, y
);
509 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
513 static void client_get_all(Client
*self
)
515 /* update EVERYTHING!! */
517 self
->ignore_unmaps
= 0;
521 self
->title
= self
->icon_title
= NULL
;
522 self
->title_count
= 1;
523 self
->name
= self
->class = self
->role
= NULL
;
524 self
->wmstate
= NormalState
;
525 self
->transient
= FALSE
;
526 self
->transients
= NULL
;
527 self
->transient_for
= NULL
;
529 self
->urgent
= FALSE
;
530 self
->positioned
= FALSE
;
531 self
->disabled_decorations
= 0;
535 client_get_area(self
);
536 client_update_transient_for(self
);
537 client_update_wmhints(self
);
538 client_get_desktop(self
);
539 client_get_state(self
);
540 client_get_shaped(self
);
542 client_get_mwm_hints(self
);
543 client_get_type(self
);/* this can change the mwmhints for special cases */
545 client_update_protocols(self
);
547 client_get_gravity(self
); /* get the attribute gravity */
548 client_update_normal_hints(self
); /* this may override the attribute
551 /* got the type, the mwmhints, the protocols, and the normal hints
552 (min/max sizes), so we're ready to set up the decorations/functions */
553 client_setup_decor_and_functions(self
);
555 client_update_title(self
);
556 client_update_class(self
);
557 client_update_strut(self
);
558 client_update_icons(self
);
560 client_change_state(self
);
563 static void client_get_area(Client
*self
)
565 XWindowAttributes wattrib
;
568 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
569 g_assert(ret
!= BadWindow
);
571 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
572 self
->border_width
= wattrib
.border_width
;
575 static void client_get_desktop(Client
*self
)
579 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
580 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
581 d
= screen_num_desktops
- 1;
584 gboolean trdesk
= FALSE
;
586 if (self
->transient_for
) {
587 if (self
->transient_for
!= TRAN_GROUP
) {
588 self
->desktop
= self
->transient_for
->desktop
;
593 for (it
= self
->group
->members
; it
; it
= it
->next
)
594 if (it
->data
!= self
&&
595 !((Client
*)it
->data
)->transient_for
) {
596 self
->desktop
= ((Client
*)it
->data
)->desktop
;
603 /* defaults to the current desktop */
604 self
->desktop
= screen_desktop
;
606 /* set the desktop hint, to make sure that it always exists */
607 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
611 static void client_get_state(Client
*self
)
616 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
617 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
618 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
620 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
622 for (i
= 0; i
< num
; ++i
) {
623 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
625 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
627 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
629 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
630 self
->skip_taskbar
= TRUE
;
631 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
632 self
->skip_pager
= TRUE
;
633 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
634 self
->fullscreen
= TRUE
;
635 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
636 self
->max_vert
= TRUE
;
637 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
638 self
->max_horz
= TRUE
;
639 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
641 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
649 static void client_get_shaped(Client
*self
)
651 self
->shaped
= FALSE
;
653 if (extensions_shape
) {
658 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
660 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
661 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
663 self
->shaped
= (s
!= 0);
668 void client_update_transient_for(Client
*self
)
673 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
674 self
->transient
= TRUE
;
675 if (t
!= self
->window
) { /* cant be transient to itself! */
676 c
= g_hash_table_lookup(window_map
, &t
);
677 /* if this happens then we need to check for it*/
679 g_assert(!c
|| WINDOW_IS_CLIENT(c
));
681 if (!c
&& self
->group
) {
682 /* not transient to a client, see if it is transient for a
684 if (t
== self
->group
->leader
||
687 /* window is a transient for its group! */
693 self
->transient
= FALSE
;
695 /* if anything has changed... */
696 if (c
!= self
->transient_for
) {
697 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
700 /* remove from old parents */
701 for (it
= self
->group
->members
; it
; it
= it
->next
)
702 if (it
->data
!= self
&&
703 !((Client
*)it
->data
)->transient_for
)
704 ((Client
*)it
->data
)->transients
=
705 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
706 } else if (self
->transient_for
!= NULL
) { /* transient of window */
707 /* remove from old parent */
708 self
->transient_for
->transients
=
709 g_slist_remove(self
->transient_for
->transients
, self
);
711 self
->transient_for
= c
;
712 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
715 /* add to new parents */
716 for (it
= self
->group
->members
; it
; it
= it
->next
)
717 if (it
->data
!= self
&&
718 !((Client
*)it
->data
)->transient_for
)
719 ((Client
*)it
->data
)->transients
=
720 g_slist_append(((Client
*)it
->data
)->transients
, self
);
722 /* remove all transients which are in the group, that causes
723 circlular pointer hell of doom */
724 for (it
= self
->group
->members
; it
; it
= it
->next
) {
726 for (sit
= self
->transients
; sit
; sit
= next
) {
728 if (sit
->data
== it
->data
)
729 self
->transients
= g_slist_remove(self
->transients
,
733 } else if (self
->transient_for
!= NULL
) { /* transient of window */
734 /* add to new parent */
735 self
->transient_for
->transients
=
736 g_slist_append(self
->transient_for
->transients
, self
);
741 static void client_get_mwm_hints(Client
*self
)
746 self
->mwmhints
.flags
= 0; /* default to none */
748 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
750 if (num
>= MWM_ELEMENTS
) {
751 self
->mwmhints
.flags
= hints
[0];
752 self
->mwmhints
.functions
= hints
[1];
753 self
->mwmhints
.decorations
= hints
[2];
759 void client_get_type(Client
*self
)
766 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
767 /* use the first value that we know about in the array */
768 for (i
= 0; i
< num
; ++i
) {
769 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
770 self
->type
= Type_Desktop
;
771 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
772 self
->type
= Type_Dock
;
773 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
774 self
->type
= Type_Toolbar
;
775 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
776 self
->type
= Type_Menu
;
777 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
778 self
->type
= Type_Utility
;
779 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
780 self
->type
= Type_Splash
;
781 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
782 self
->type
= Type_Dialog
;
783 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
784 self
->type
= Type_Normal
;
785 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
786 /* prevent this window from getting any decor or
788 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
789 MwmFlag_Decorations
);
790 self
->mwmhints
.decorations
= 0;
791 self
->mwmhints
.functions
= 0;
793 if (self
->type
!= (WindowType
) -1)
794 break; /* grab the first legit type */
799 if (self
->type
== (WindowType
) -1) {
800 /*the window type hint was not set, which means we either classify
801 ourself as a normal window or a dialog, depending on if we are a
804 self
->type
= Type_Dialog
;
806 self
->type
= Type_Normal
;
810 void client_update_protocols(Client
*self
)
815 self
->focus_notify
= FALSE
;
816 self
->delete_window
= FALSE
;
818 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
819 for (i
= 0; i
< num_return
; ++i
) {
820 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
821 /* this means we can request the window to close */
822 self
->delete_window
= TRUE
;
823 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
824 /* if this protocol is requested, then the window will be
825 notified whenever we want it to receive focus */
826 self
->focus_notify
= TRUE
;
832 static void client_get_gravity(Client
*self
)
834 XWindowAttributes wattrib
;
837 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
838 g_assert(ret
!= BadWindow
);
839 self
->gravity
= wattrib
.win_gravity
;
842 void client_update_normal_hints(Client
*self
)
846 int oldgravity
= self
->gravity
;
849 self
->min_ratio
= 0.0f
;
850 self
->max_ratio
= 0.0f
;
851 SIZE_SET(self
->size_inc
, 1, 1);
852 SIZE_SET(self
->base_size
, 0, 0);
853 SIZE_SET(self
->min_size
, 0, 0);
854 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
856 /* get the hints from the window */
857 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
858 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
860 if (size
.flags
& PWinGravity
) {
861 self
->gravity
= size
.win_gravity
;
863 /* if the client has a frame, i.e. has already been mapped and
864 is changing its gravity */
865 if (self
->frame
&& self
->gravity
!= oldgravity
) {
866 /* move our idea of the client's position based on its new
868 self
->area
.x
= self
->frame
->area
.x
;
869 self
->area
.y
= self
->frame
->area
.y
;
870 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
874 if (size
.flags
& PAspect
) {
875 if (size
.min_aspect
.y
)
876 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
877 if (size
.max_aspect
.y
)
878 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
881 if (size
.flags
& PMinSize
)
882 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
884 if (size
.flags
& PMaxSize
)
885 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
887 if (size
.flags
& PBaseSize
)
888 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
890 if (size
.flags
& PResizeInc
)
891 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
895 void client_setup_decor_and_functions(Client
*self
)
897 /* start with everything (cept fullscreen) */
898 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
899 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
901 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
903 if (self
->delete_window
) {
904 self
->decorations
|= Decor_Close
;
905 self
->functions
|= Func_Close
;
908 if (!(self
->min_size
.width
< self
->max_size
.width
||
909 self
->min_size
.height
< self
->max_size
.height
)) {
910 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
911 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
914 switch (self
->type
) {
916 /* normal windows retain all of the possible decorations and
917 functionality, and are the only windows that you can fullscreen */
918 self
->functions
|= Func_Fullscreen
;
923 /* these windows cannot be maximized */
924 self
->decorations
&= ~Decor_Maximize
;
925 self
->functions
&= ~Func_Maximize
;
930 /* these windows get less functionality */
931 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
932 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
938 /* none of these windows are manipulated by the window manager */
939 self
->decorations
= 0;
944 /* Mwm Hints are applied subtractively to what has already been chosen for
945 decor and functionality */
946 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
947 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
948 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
949 self
->decorations
&= ~Decor_Border
;
950 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
951 self
->decorations
&= ~Decor_Handle
;
952 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
953 self
->decorations
&= ~Decor_Titlebar
;
954 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
955 self
->decorations
&= ~Decor_Iconify
;
956 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
957 self
->decorations
&= ~Decor_Maximize
;
961 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
962 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
963 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
964 self
->functions
&= ~Func_Resize
;
965 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
966 self
->functions
&= ~Func_Move
;
967 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
968 self
->functions
&= ~Func_Iconify
;
969 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
970 self
->functions
&= ~Func_Maximize
;
971 /* dont let mwm hints kill the close button
972 if (! (self->mwmhints.functions & MwmFunc_Close))
973 self->functions &= ~Func_Close; */
977 /* can't maximize without moving/resizing */
978 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
979 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
981 /* finally, user specified disabled decorations are applied to subtract
983 if (self
->disabled_decorations
& Decor_Titlebar
)
984 self
->decorations
&= ~Decor_Titlebar
;
985 if (self
->disabled_decorations
& Decor_Handle
)
986 self
->decorations
&= ~Decor_Handle
;
987 if (self
->disabled_decorations
& Decor_Border
)
988 self
->decorations
&= ~Decor_Border
;
989 if (self
->disabled_decorations
& Decor_Iconify
)
990 self
->decorations
&= ~Decor_Iconify
;
991 if (self
->disabled_decorations
& Decor_Maximize
)
992 self
->decorations
&= ~Decor_Maximize
;
993 if (self
->disabled_decorations
& Decor_AllDesktops
)
994 self
->decorations
&= ~Decor_AllDesktops
;
995 if (self
->disabled_decorations
& Decor_Shade
)
996 self
->decorations
&= ~Decor_Shade
;
997 if (self
->disabled_decorations
& Decor_Close
)
998 self
->decorations
&= ~Decor_Close
;
1000 /* if we don't have a titlebar, then we cannot shade! */
1001 if (!(self
->decorations
& Decor_Titlebar
))
1002 self
->functions
&= ~Func_Shade
;
1004 /* now we need to check against rules for the client's current state */
1005 if (self
->fullscreen
) {
1006 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
1007 self
->decorations
= 0;
1010 client_change_allowed_actions(self
);
1013 /* this makes sure that these windows appear on all desktops */
1014 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1015 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1017 /* change the decors on the frame, and with more/less decorations,
1018 we may also need to be repositioned */
1019 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
1020 /* with new decor, the window's maximized size may change */
1021 client_remaximize(self
);
1023 /* this makes sure that these windows appear on all desktops */
1024 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1025 self
->desktop
= DESKTOP_ALL
;
1029 static void client_change_allowed_actions(Client
*self
)
1034 /* desktop windows are kept on all desktops */
1035 if (self
->type
!= Type_Desktop
)
1036 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1038 if (self
->functions
& Func_Shade
)
1039 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1040 if (self
->functions
& Func_Close
)
1041 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1042 if (self
->functions
& Func_Move
)
1043 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1044 if (self
->functions
& Func_Iconify
)
1045 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1046 if (self
->functions
& Func_Resize
)
1047 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1048 if (self
->functions
& Func_Fullscreen
)
1049 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1050 if (self
->functions
& Func_Maximize
) {
1051 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1052 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1055 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1057 /* make sure the window isn't breaking any rules now */
1059 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1060 if (self
->frame
) client_shade(self
, FALSE
);
1061 else self
->shaded
= FALSE
;
1063 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1064 g_message("UNSETTING ICONIC");
1065 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1066 else self
->iconic
= FALSE
;
1068 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1069 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1070 else self
->fullscreen
= FALSE
;
1072 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1074 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1075 else self
->max_vert
= self
->max_horz
= FALSE
;
1079 void client_remaximize(Client
*self
)
1082 if (self
->max_horz
&& self
->max_vert
)
1084 else if (self
->max_horz
)
1086 else if (self
->max_vert
)
1089 return; /* not maximized */
1090 self
->max_horz
= self
->max_vert
= FALSE
;
1091 client_maximize(self
, TRUE
, dir
, FALSE
);
1094 void client_update_wmhints(Client
*self
)
1097 gboolean ur
= FALSE
;
1100 /* assume a window takes input if it doesnt specify */
1101 self
->can_focus
= TRUE
;
1103 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1104 if (hints
->flags
& InputHint
)
1105 self
->can_focus
= hints
->input
;
1107 /* only do this when first managing the window *AND* when we aren't
1109 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1110 if (hints
->flags
& StateHint
)
1111 self
->iconic
= hints
->initial_state
== IconicState
;
1113 if (hints
->flags
& XUrgencyHint
)
1116 if (!(hints
->flags
& WindowGroupHint
))
1117 hints
->window_group
= None
;
1119 /* did the group state change? */
1120 if (hints
->window_group
!=
1121 (self
->group
? self
->group
->leader
: None
)) {
1122 /* remove from the old group if there was one */
1123 if (self
->group
!= NULL
) {
1124 /* remove transients of the group */
1125 for (it
= self
->group
->members
; it
; it
= it
->next
)
1126 self
->transients
= g_slist_remove(self
->transients
,
1128 group_remove(self
->group
, self
);
1131 /* i can only have transients from the group if i am not transient
1133 if (hints
->window_group
!= None
&& !self
->transient_for
) {
1134 self
->group
= group_add(hints
->window_group
, self
);
1136 /* add other transients of the group that are already
1138 for (it
= self
->group
->members
; it
; it
= it
->next
)
1139 if (it
->data
!= self
&&
1140 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1141 self
->transients
= g_slist_append(self
->transients
,
1145 /* because the self->transient flag wont change from this call,
1146 we don't need to update the window's type and such, only its
1147 transient_for, and the transients lists of other windows in
1148 the group may be affected */
1149 client_update_transient_for(self
);
1155 if (ur
!= self
->urgent
) {
1157 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1159 /* fire the urgent callback if we're mapped, otherwise, wait until
1160 after we're mapped */
1162 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1166 void client_update_title(Client
*self
)
1172 gboolean read_title
;
1174 g_free(self
->title
);
1177 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1178 /* try old x stuff */
1179 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1180 data
= g_strdup("Unnamed Window");
1182 /* look for duplicates and append a number */
1184 for (it
= client_list
; it
; it
= it
->next
)
1185 if (it
->data
!= self
) {
1186 Client
*c
= it
->data
;
1187 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1188 nums
|= 1 << c
->title_count
;
1190 /* find first free number */
1191 for (i
= 1; i
<= 32; ++i
)
1192 if (!(nums
& (1 << i
))) {
1193 if (self
->title_count
== 1 || i
== 1)
1194 self
->title_count
= i
;
1197 /* dont display the number for the first window */
1198 if (self
->title_count
> 1) {
1199 char *vdata
, *ndata
;
1200 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1201 vdata
= g_strconcat(data
, ndata
, NULL
);
1207 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1212 frame_adjust_title(self
->frame
);
1214 /* update the icon title */
1216 g_free(self
->icon_title
);
1220 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1221 /* try old x stuff */
1222 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1223 data
= g_strdup(self
->title
);
1227 /* append the title count, dont display the number for the first window */
1228 if (read_title
&& self
->title_count
> 1) {
1229 char *vdata
, *ndata
;
1230 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1231 vdata
= g_strconcat(data
, ndata
, NULL
);
1237 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1239 self
->icon_title
= data
;
1242 void client_update_class(Client
*self
)
1247 if (self
->name
) g_free(self
->name
);
1248 if (self
->class) g_free(self
->class);
1249 if (self
->role
) g_free(self
->role
);
1251 self
->name
= self
->class = self
->role
= NULL
;
1253 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1255 self
->name
= g_strdup(data
[0]);
1257 self
->class = g_strdup(data
[1]);
1262 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1263 self
->role
= g_strdup(s
);
1265 if (self
->name
== NULL
) self
->name
= g_strdup("");
1266 if (self
->class == NULL
) self
->class = g_strdup("");
1267 if (self
->role
== NULL
) self
->role
= g_strdup("");
1270 void client_update_strut(Client
*self
)
1275 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1276 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1279 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1281 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1285 /* updating here is pointless while we're being mapped cuz we're not in
1286 the client list yet */
1288 screen_update_struts();
1291 void client_update_icons(Client
*self
)
1298 for (j
= 0; j
< self
->nicons
; ++j
)
1299 g_free(self
->icons
[j
].data
);
1300 if (self
->nicons
> 0)
1301 g_free(self
->icons
);
1304 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1305 /* figure out how many valid icons are in here */
1307 while (num
- i
> 2) {
1315 self
->icons
= g_new(Icon
, self
->nicons
);
1317 /* store the icons */
1319 for (j
= 0; j
< self
->nicons
; ++j
) {
1320 w
= self
->icons
[j
].width
= data
[i
++];
1321 h
= self
->icons
[j
].height
= data
[i
++];
1322 self
->icons
[j
].data
=
1323 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1329 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1330 kwm_win_icon
, &data
, &num
)) {
1333 self
->icons
= g_new(Icon
, self
->nicons
);
1334 /* XXX WHAT IF THIS FAILS YOU TWIT!@!*()@ */
1335 render_pixmap_to_rgba(data
[0], data
[1],
1336 &self
->icons
[self
->nicons
-1].width
,
1337 &self
->icons
[self
->nicons
-1].height
,
1338 &self
->icons
[self
->nicons
-1].data
);
1344 frame_adjust_icon(self
->frame
);
1347 static void client_change_state(Client
*self
)
1350 guint32 netstate
[10];
1353 state
[0] = self
->wmstate
;
1355 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1359 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1361 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1363 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1364 if (self
->skip_taskbar
)
1365 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1366 if (self
->skip_pager
)
1367 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1368 if (self
->fullscreen
)
1369 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1371 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1373 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1375 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1377 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1378 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1380 client_calc_layer(self
);
1383 frame_adjust_state(self
->frame
);
1386 Client
*client_search_focus_tree(Client
*self
)
1391 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1392 if (client_focused(it
->data
)) return it
->data
;
1393 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1398 Client
*client_search_focus_tree_full(Client
*self
)
1400 if (self
->transient_for
) {
1401 if (self
->transient_for
!= TRAN_GROUP
) {
1402 return client_search_focus_tree_full(self
->transient_for
);
1406 for (it
= self
->group
->members
; it
; it
= it
->next
)
1407 if (!((Client
*)it
->data
)->transient_for
) {
1409 if ((c
= client_search_focus_tree_full(it
->data
)))
1415 /* this function checks the whole tree, the client_search_focus_tree
1416 does not, so we need to check this window */
1417 if (client_focused(self
))
1419 return client_search_focus_tree(self
);
1423 static StackLayer
calc_layer(Client
*self
)
1427 if (self
->fullscreen
) l
= Layer_Fullscreen
;
1428 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1429 else if (self
->type
== Type_Dock
) {
1430 if (!self
->below
) l
= Layer_Top
;
1431 else l
= Layer_Normal
;
1433 else if (self
->above
) l
= Layer_Above
;
1434 else if (self
->below
) l
= Layer_Below
;
1435 else l
= Layer_Normal
;
1440 static void calc_recursive(Client
*self
, Client
*orig
, StackLayer l
,
1443 StackLayer old
, own
;
1447 own
= calc_layer(self
);
1448 self
->layer
= l
> own
? l
: own
;
1450 for (it
= self
->transients
; it
; it
= it
->next
)
1451 calc_recursive(it
->data
, orig
, l
, raised
? raised
: l
!= old
);
1453 if (!raised
&& l
!= old
)
1454 if (orig
->frame
) /* only restack if the original window is managed */
1455 stacking_raise(CLIENT_AS_WINDOW(self
));
1458 void client_calc_layer(Client
*self
)
1465 /* transients take on the layer of their parents */
1466 if (self
->transient_for
) {
1467 if (self
->transient_for
!= TRAN_GROUP
) {
1468 self
= self
->transient_for
;
1472 for (it
= self
->group
->members
; it
; it
= it
->next
)
1473 if (it
->data
!= self
&&
1474 !((Client
*)it
->data
)->transient_for
) {
1481 l
= calc_layer(self
);
1483 calc_recursive(self
, orig
, l
, FALSE
);
1486 gboolean
client_should_show(Client
*self
)
1488 if (self
->iconic
) return FALSE
;
1489 else if (!(self
->desktop
== screen_desktop
||
1490 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1491 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1496 static void client_showhide(Client
*self
)
1499 if (client_should_show(self
))
1500 frame_show(self
->frame
);
1502 frame_hide(self
->frame
);
1505 gboolean
client_normal(Client
*self
) {
1506 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1507 self
->type
== Type_Splash
);
1510 static void client_apply_startup_state(Client
*self
)
1512 /* these are in a carefully crafted order.. */
1515 self
->iconic
= FALSE
;
1516 client_iconify(self
, TRUE
, FALSE
);
1518 if (self
->fullscreen
) {
1519 self
->fullscreen
= FALSE
;
1520 client_fullscreen(self
, TRUE
, FALSE
);
1523 self
->shaded
= FALSE
;
1524 client_shade(self
, TRUE
);
1527 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1529 if (self
->max_vert
&& self
->max_horz
) {
1530 self
->max_vert
= self
->max_horz
= FALSE
;
1531 client_maximize(self
, TRUE
, 0, FALSE
);
1532 } else if (self
->max_vert
) {
1533 self
->max_vert
= FALSE
;
1534 client_maximize(self
, TRUE
, 2, FALSE
);
1535 } else if (self
->max_horz
) {
1536 self
->max_horz
= FALSE
;
1537 client_maximize(self
, TRUE
, 1, FALSE
);
1540 /* nothing to do for the other states:
1549 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1550 gboolean user
, gboolean final
)
1552 gboolean moved
= FALSE
, resized
= FALSE
;
1554 /* gets the frame's position */
1555 frame_client_gravity(self
->frame
, &x
, &y
);
1557 /* these positions are frame positions, not client positions */
1559 /* set the size and position if fullscreen */
1560 if (self
->fullscreen
) {
1563 w
= screen_physical_size
.width
;
1564 h
= screen_physical_size
.height
;
1565 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1567 /* set the size and position if maximized */
1568 if (self
->max_horz
) {
1569 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1570 w
= screen_area(self
->desktop
)->width
;
1572 if (self
->max_vert
) {
1573 y
= screen_area(self
->desktop
)->y
;
1574 h
= screen_area(self
->desktop
)->height
-
1575 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1579 /* gets the client's position */
1580 frame_frame_gravity(self
->frame
, &x
, &y
);
1582 /* these override the above states! if you cant move you can't move! */
1584 if (!(self
->functions
& Func_Move
)) {
1588 if (!(self
->functions
& Func_Resize
)) {
1589 w
= self
->area
.width
;
1590 h
= self
->area
.height
;
1594 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1595 w
-= self
->base_size
.width
;
1596 h
-= self
->base_size
.height
;
1599 /* for interactive resizing. have to move half an increment in each
1602 /* how far we are towards the next size inc */
1603 int mw
= w
% self
->size_inc
.width
;
1604 int mh
= h
% self
->size_inc
.height
;
1606 int aw
= self
->size_inc
.width
/ 2;
1607 int ah
= self
->size_inc
.height
/ 2;
1608 /* don't let us move into a new size increment */
1609 if (mw
+ aw
>= self
->size_inc
.width
)
1610 aw
= self
->size_inc
.width
- mw
- 1;
1611 if (mh
+ ah
>= self
->size_inc
.height
)
1612 ah
= self
->size_inc
.height
- mh
- 1;
1616 /* if this is a user-requested resize, then check against min/max
1617 sizes and aspect ratios */
1619 /* smaller than min size or bigger than max size? */
1620 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1621 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1622 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1623 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1625 /* adjust the height ot match the width for the aspect ratios */
1626 if (self
->min_ratio
)
1627 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1628 if (self
->max_ratio
)
1629 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1632 /* keep to the increments */
1633 w
/= self
->size_inc
.width
;
1634 h
/= self
->size_inc
.height
;
1636 /* you cannot resize to nothing */
1640 /* store the logical size */
1641 SIZE_SET(self
->logical_size
, w
, h
);
1643 w
*= self
->size_inc
.width
;
1644 h
*= self
->size_inc
.height
;
1646 w
+= self
->base_size
.width
;
1647 h
+= self
->base_size
.height
;
1651 case Corner_TopLeft
:
1653 case Corner_TopRight
:
1654 x
-= w
- self
->area
.width
;
1656 case Corner_BottomLeft
:
1657 y
-= h
- self
->area
.height
;
1659 case Corner_BottomRight
:
1660 x
-= w
- self
->area
.width
;
1661 y
-= h
- self
->area
.height
;
1665 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1666 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1668 RECT_SET(self
->area
, x
, y
, w
, h
);
1671 XResizeWindow(ob_display
, self
->window
, w
, h
);
1673 /* move/resize the frame to match the request */
1675 if (moved
|| resized
)
1676 frame_adjust_area(self
->frame
, moved
, resized
);
1678 if (!user
|| final
) {
1680 event
.type
= ConfigureNotify
;
1681 event
.xconfigure
.display
= ob_display
;
1682 event
.xconfigure
.event
= self
->window
;
1683 event
.xconfigure
.window
= self
->window
;
1685 /* root window real coords */
1686 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
;
1687 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
;
1689 event
.xconfigure
.width
= w
;
1690 event
.xconfigure
.height
= h
;
1691 event
.xconfigure
.border_width
= 0;
1692 event
.xconfigure
.above
= self
->frame
->plate
;
1693 event
.xconfigure
.override_redirect
= FALSE
;
1694 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1695 FALSE
, StructureNotifyMask
, &event
);
1700 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1704 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1705 self
->fullscreen
== fs
) return; /* already done */
1707 self
->fullscreen
= fs
;
1708 client_change_state(self
); /* change the state hints on the client,
1709 and adjust out layer/stacking */
1713 guint32 dimensions
[4];
1714 dimensions
[0] = self
->area
.x
;
1715 dimensions
[1] = self
->area
.y
;
1716 dimensions
[2] = self
->area
.width
;
1717 dimensions
[3] = self
->area
.height
;
1719 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1723 /* these are not actually used cuz client_configure will set them
1724 as appropriate when the window is fullscreened */
1730 /* pick some fallbacks... */
1731 x
= screen_area(self
->desktop
)->x
+
1732 screen_area(self
->desktop
)->width
/ 4;
1733 y
= screen_area(self
->desktop
)->y
+
1734 screen_area(self
->desktop
)->height
/ 4;
1735 w
= screen_area(self
->desktop
)->width
/ 2;
1736 h
= screen_area(self
->desktop
)->height
/ 2;
1738 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1739 (guint32
**)&dimensions
, &num
)) {
1750 client_setup_decor_and_functions(self
);
1752 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1754 /* try focus us when we go into fullscreen mode */
1758 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1762 /* move up the transient chain as far as possible first */
1763 if (self
->transient_for
) {
1764 if (self
->transient_for
!= TRAN_GROUP
) {
1765 if (self
->transient_for
->iconic
!= iconic
) {
1766 client_iconify(self
->transient_for
, iconic
, curdesk
);
1772 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1773 Client
*c
= it
->data
;
1774 if (c
!= self
&& c
->iconic
!= iconic
&&
1775 !c
->transient_for
) {
1776 client_iconify(it
->data
, iconic
, curdesk
);
1780 if (it
!= NULL
) return;
1784 if (self
->iconic
== iconic
) return; /* nothing to do */
1786 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1789 self
->iconic
= iconic
;
1792 self
->wmstate
= IconicState
;
1793 self
->ignore_unmaps
++;
1794 /* we unmap the client itself so that we can get MapRequest events,
1795 and because the ICCCM tells us to! */
1796 XUnmapWindow(ob_display
, self
->window
);
1798 /* update the focus lists.. iconic windows go to the bottom of the
1799 list, put the new iconic window at the 'top of the bottom'. */
1800 focus_order_to_top(self
);
1803 client_set_desktop(self
, screen_desktop
, FALSE
);
1804 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1805 XMapWindow(ob_display
, self
->window
);
1807 /* this puts it after the current focused window */
1808 focus_order_remove(self
);
1809 focus_order_add_new(self
);
1811 client_change_state(self
);
1812 client_showhide(self
);
1813 screen_update_struts();
1815 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1818 /* iconify all transients */
1819 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1820 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1823 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1827 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1828 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1830 /* check if already done */
1832 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1833 if (dir
== 1 && self
->max_horz
) return;
1834 if (dir
== 2 && self
->max_vert
) return;
1836 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1837 if (dir
== 1 && !self
->max_horz
) return;
1838 if (dir
== 2 && !self
->max_vert
) return;
1841 /* work with the frame's coords */
1842 x
= self
->frame
->area
.x
;
1843 y
= self
->frame
->area
.y
;
1844 w
= self
->area
.width
;
1845 h
= self
->area
.height
;
1849 gint32 dimensions
[4];
1858 /* get the property off the window and use it for the dimensions
1859 we are already maxed on */
1860 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1861 (guint32
**)&readdim
, &num
)) {
1863 if (self
->max_horz
) {
1864 dimensions
[0] = readdim
[0];
1865 dimensions
[2] = readdim
[2];
1867 if (self
->max_vert
) {
1868 dimensions
[1] = readdim
[1];
1869 dimensions
[3] = readdim
[3];
1875 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1876 (guint32
*)dimensions
, 4);
1882 /* pick some fallbacks... */
1883 if (dir
== 0 || dir
== 1) { /* horz */
1884 x
= screen_area(self
->desktop
)->x
+
1885 screen_area(self
->desktop
)->width
/ 4;
1886 w
= screen_area(self
->desktop
)->width
/ 2;
1888 if (dir
== 0 || dir
== 2) { /* vert */
1889 y
= screen_area(self
->desktop
)->y
+
1890 screen_area(self
->desktop
)->height
/ 4;
1891 h
= screen_area(self
->desktop
)->height
/ 2;
1894 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1895 (guint32
**)&dimensions
, &num
)) {
1897 if (dir
== 0 || dir
== 1) { /* horz */
1901 if (dir
== 0 || dir
== 2) { /* vert */
1910 if (dir
== 0 || dir
== 1) /* horz */
1911 self
->max_horz
= max
;
1912 if (dir
== 0 || dir
== 2) /* vert */
1913 self
->max_vert
= max
;
1915 if (!self
->max_horz
&& !self
->max_vert
)
1916 PROP_ERASE(self
->window
, openbox_premax
);
1918 client_change_state(self
); /* change the state hints on the client */
1920 /* figure out where the client should be going */
1921 frame_frame_gravity(self
->frame
, &x
, &y
);
1922 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1925 void client_shade(Client
*self
, gboolean shade
)
1927 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1928 self
->shaded
== shade
) return; /* already done */
1930 /* when we're iconic, don't change the wmstate */
1932 self
->wmstate
= shade
? IconicState
: NormalState
;
1933 self
->shaded
= shade
;
1934 client_change_state(self
);
1935 /* resize the frame to just the titlebar */
1936 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1939 void client_close(Client
*self
)
1943 if (!(self
->functions
& Func_Close
)) return;
1946 XXX: itd be cool to do timeouts and shit here for killing the client's
1948 like... if the window is around after 5 seconds, then the close button
1949 turns a nice red, and if this function is called again, the client is
1953 ce
.xclient
.type
= ClientMessage
;
1954 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1955 ce
.xclient
.display
= ob_display
;
1956 ce
.xclient
.window
= self
->window
;
1957 ce
.xclient
.format
= 32;
1958 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1959 ce
.xclient
.data
.l
[1] = event_lasttime
;
1960 ce
.xclient
.data
.l
[2] = 0l;
1961 ce
.xclient
.data
.l
[3] = 0l;
1962 ce
.xclient
.data
.l
[4] = 0l;
1963 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1966 void client_kill(Client
*self
)
1968 XKillClient(ob_display
, self
->window
);
1971 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1975 if (target
== self
->desktop
) return;
1977 g_message("Setting desktop %u", target
);
1979 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1981 /* remove from the old desktop(s) */
1982 focus_order_remove(self
);
1984 old
= self
->desktop
;
1985 self
->desktop
= target
;
1986 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1987 /* the frame can display the current desktop state */
1988 frame_adjust_state(self
->frame
);
1989 /* 'move' the window to the new desktop */
1991 client_showhide(self
);
1992 /* raise if it was not already on the desktop */
1993 if (old
!= DESKTOP_ALL
)
1994 stacking_raise(CLIENT_AS_WINDOW(self
));
1995 screen_update_struts();
1997 /* add to the new desktop(s) */
1998 if (config_focus_new
)
1999 focus_order_to_top(self
);
2001 focus_order_to_bottom(self
);
2003 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2006 Client
*client_search_modal_child(Client
*self
)
2011 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2012 Client
*c
= it
->data
;
2013 if ((ret
= client_search_modal_child(c
))) return ret
;
2014 if (c
->modal
) return c
;
2019 gboolean
client_validate(Client
*self
)
2023 XSync(ob_display
, FALSE
); /* get all events on the server */
2025 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2026 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2027 XPutBackEvent(ob_display
, &e
);
2034 void client_set_wm_state(Client
*self
, long state
)
2036 if (state
== self
->wmstate
) return; /* no change */
2040 client_iconify(self
, TRUE
, TRUE
);
2043 client_iconify(self
, FALSE
, TRUE
);
2048 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
2050 gboolean shaded
= self
->shaded
;
2051 gboolean fullscreen
= self
->fullscreen
;
2052 gboolean max_horz
= self
->max_horz
;
2053 gboolean max_vert
= self
->max_vert
;
2056 if (!(action
== prop_atoms
.net_wm_state_add
||
2057 action
== prop_atoms
.net_wm_state_remove
||
2058 action
== prop_atoms
.net_wm_state_toggle
))
2059 /* an invalid action was passed to the client message, ignore it */
2062 for (i
= 0; i
< 2; ++i
) {
2063 Atom state
= i
== 0 ? data1
: data2
;
2065 if (!state
) continue;
2067 /* if toggling, then pick whether we're adding or removing */
2068 if (action
== prop_atoms
.net_wm_state_toggle
) {
2069 if (state
== prop_atoms
.net_wm_state_modal
)
2070 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2071 prop_atoms
.net_wm_state_add
;
2072 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2073 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2074 prop_atoms
.net_wm_state_add
;
2075 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2076 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2077 prop_atoms
.net_wm_state_add
;
2078 else if (state
== prop_atoms
.net_wm_state_shaded
)
2079 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2080 prop_atoms
.net_wm_state_add
;
2081 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2082 action
= self
->skip_taskbar
?
2083 prop_atoms
.net_wm_state_remove
:
2084 prop_atoms
.net_wm_state_add
;
2085 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2086 action
= self
->skip_pager
?
2087 prop_atoms
.net_wm_state_remove
:
2088 prop_atoms
.net_wm_state_add
;
2089 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2090 action
= self
->fullscreen
?
2091 prop_atoms
.net_wm_state_remove
:
2092 prop_atoms
.net_wm_state_add
;
2093 else if (state
== prop_atoms
.net_wm_state_above
)
2094 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2095 prop_atoms
.net_wm_state_add
;
2096 else if (state
== prop_atoms
.net_wm_state_below
)
2097 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2098 prop_atoms
.net_wm_state_add
;
2101 if (action
== prop_atoms
.net_wm_state_add
) {
2102 if (state
== prop_atoms
.net_wm_state_modal
) {
2103 /* XXX raise here or something? */
2105 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2107 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2109 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2111 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2112 self
->skip_taskbar
= TRUE
;
2113 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2114 self
->skip_pager
= TRUE
;
2115 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2117 } else if (state
== prop_atoms
.net_wm_state_above
) {
2119 } else if (state
== prop_atoms
.net_wm_state_below
) {
2123 } else { /* action == prop_atoms.net_wm_state_remove */
2124 if (state
== prop_atoms
.net_wm_state_modal
) {
2125 self
->modal
= FALSE
;
2126 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2128 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2130 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2132 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2133 self
->skip_taskbar
= FALSE
;
2134 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2135 self
->skip_pager
= FALSE
;
2136 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2138 } else if (state
== prop_atoms
.net_wm_state_above
) {
2139 self
->above
= FALSE
;
2140 } else if (state
== prop_atoms
.net_wm_state_below
) {
2141 self
->below
= FALSE
;
2145 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2146 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2148 if (max_horz
== max_vert
) { /* both going the same way */
2149 client_maximize(self
, max_horz
, 0, TRUE
);
2151 client_maximize(self
, max_horz
, 1, TRUE
);
2152 client_maximize(self
, max_vert
, 2, TRUE
);
2156 if (max_horz
!= self
->max_horz
)
2157 client_maximize(self
, max_horz
, 1, TRUE
);
2159 client_maximize(self
, max_vert
, 2, TRUE
);
2162 /* change fullscreen state before shading, as it will affect if the window
2164 if (fullscreen
!= self
->fullscreen
)
2165 client_fullscreen(self
, fullscreen
, TRUE
);
2166 if (shaded
!= self
->shaded
)
2167 client_shade(self
, shaded
);
2168 client_calc_layer(self
);
2169 client_change_state(self
); /* change the hint to relect these changes */
2172 Client
*client_focus_target(Client
*self
)
2176 /* if we have a modal child, then focus it, not us */
2177 child
= client_search_modal_child(self
);
2178 if (child
) return child
;
2182 gboolean
client_focus(Client
*self
)
2186 /* choose the correct target */
2187 self
= client_focus_target(self
);
2189 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2190 /* update the focus lists */
2191 focus_order_to_top(self
);
2195 if (!((self
->can_focus
|| self
->focus_notify
) &&
2196 (self
->desktop
== screen_desktop
||
2197 self
->desktop
== DESKTOP_ALL
) &&
2201 /* do a check to see if the window has already been unmapped or destroyed
2202 do this intelligently while watching out for unmaps we've generated
2203 (ignore_unmaps > 0) */
2204 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2205 DestroyNotify
, &ev
)) {
2206 XPutBackEvent(ob_display
, &ev
);
2209 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2210 UnmapNotify
, &ev
)) {
2211 if (self
->ignore_unmaps
) {
2212 self
->ignore_unmaps
--;
2214 XPutBackEvent(ob_display
, &ev
);
2219 if (self
->can_focus
)
2220 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2221 I choose to use it always, hopefully to find errors quicker, if any
2222 are left. (I hate X. I hate focus events.) */
2223 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2226 if (self
->focus_notify
) {
2228 ce
.xclient
.type
= ClientMessage
;
2229 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2230 ce
.xclient
.display
= ob_display
;
2231 ce
.xclient
.window
= self
->window
;
2232 ce
.xclient
.format
= 32;
2233 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2234 ce
.xclient
.data
.l
[1] = event_lasttime
;
2235 ce
.xclient
.data
.l
[2] = 0l;
2236 ce
.xclient
.data
.l
[3] = 0l;
2237 ce
.xclient
.data
.l
[4] = 0l;
2238 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2242 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2247 /* Cause the FocusIn to come back to us. Important for desktop switches,
2248 since otherwise we'll have no FocusIn on the queue and send it off to
2249 the focus_backup. */
2250 XSync(ob_display
, FALSE
);
2254 void client_unfocus(Client
*self
)
2256 g_assert(focus_client
== self
);
2258 g_message("client_unfocus for %lx", self
->window
);
2260 focus_fallback(Fallback_Unfocusing
);
2263 void client_activate(Client
*self
)
2265 if (client_normal(self
) && screen_showing_desktop
)
2266 screen_show_desktop(FALSE
);
2268 client_iconify(self
, FALSE
, TRUE
);
2269 else if (!self
->frame
->visible
)
2270 /* if its not visible for other reasons, then don't mess
2274 client_shade(self
, FALSE
);
2276 stacking_raise(CLIENT_AS_WINDOW(self
));
2279 gboolean
client_focused(Client
*self
)
2281 return self
== focus_client
;
2284 Icon
*client_icon(Client
*self
, int w
, int h
)
2287 /* si is the smallest image >= req */
2288 /* li is the largest image < req */
2289 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2291 if (!self
->nicons
) return NULL
;
2293 for (i
= 0; i
< self
->nicons
; ++i
) {
2294 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2295 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2299 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2304 if (largest
== 0) /* didnt find one smaller than the requested size */
2305 return &self
->icons
[si
];
2306 return &self
->icons
[li
];