5 #include "moveresize.h"
7 #include "extensions.h"
19 #include <X11/Xutil.h>
21 /*! The event mask to grab on client windows */
22 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
25 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
28 GList
*client_list
= 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
);
48 void client_shutdown()
52 void client_set_list()
54 Window
*windows
, *win_it
;
56 guint size
= g_list_length(client_list
);
58 /* create an array of the window ids */
60 windows
= g_new(Window
, size
);
62 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
63 *win_it
= ((Client
*)it
->data
)->window
;
67 PROP_SETA32(ob_root
, net_client_list
, window
, (guint32
*)windows
, size
);
76 void client_foreach_transient(Client *self, ClientForeachFunc func, void *data)
80 for (it = self->transients; it; it = it->next) {
81 if (!func(it->data, data)) return;
82 client_foreach_transient(it->data, func, data);
86 void client_foreach_ancestor(Client *self, ClientForeachFunc func, void *data)
88 if (self->transient_for) {
89 if (self->transient_for != TRAN_GROUP) {
90 if (!func(self->transient_for, data)) return;
91 client_foreach_ancestor(self->transient_for, func, data);
95 for (it = self->group->members; it; it = it->next)
96 if (it->data != self &&
97 ((Client*)it->data)->transient_for != TRAN_GROUP) {
98 if (!func(it->data, data)) return;
99 client_foreach_ancestor(it->data, func, data);
106 void client_manage_all()
108 unsigned int i
, j
, nchild
;
111 XWindowAttributes attrib
;
113 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
115 /* remove all icon windows from the list */
116 for (i
= 0; i
< nchild
; i
++) {
117 if (children
[i
] == None
) continue;
118 wmhints
= XGetWMHints(ob_display
, children
[i
]);
120 if ((wmhints
->flags
& IconWindowHint
) &&
121 (wmhints
->icon_window
!= children
[i
]))
122 for (j
= 0; j
< nchild
; j
++)
123 if (children
[j
] == wmhints
->icon_window
) {
131 for (i
= 0; i
< nchild
; ++i
) {
132 if (children
[i
] == None
)
134 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
135 if (attrib
.override_redirect
) continue;
137 if (attrib
.map_state
!= IsUnmapped
)
138 client_manage(children
[i
]);
143 /* stack them as they were on startup!
144 why with stacking_lower? Why, because then windows who aren't in the
145 stacking list are on the top where you can see them instead of buried
147 for (i
= startup_stack_size
; i
> 0; --i
) {
150 w
= startup_stack_order
[i
-1];
151 obw
= g_hash_table_lookup(window_map
, &w
);
153 g_assert(WINDOW_IS_CLIENT(obw
));
154 stacking_lower(CLIENT_AS_WINDOW(obw
));
157 g_free(startup_stack_order
);
158 startup_stack_order
= NULL
;
159 startup_stack_size
= 0;
161 if (config_focus_new
) {
164 active
= g_hash_table_lookup(window_map
, &startup_active
);
166 g_assert(WINDOW_IS_CLIENT(active
));
167 if (!client_focus(WINDOW_AS_CLIENT(active
)))
168 focus_fallback(Fallback_NoFocus
);
170 focus_fallback(Fallback_NoFocus
);
174 void client_manage(Window window
)
178 XWindowAttributes attrib
;
179 XSetWindowAttributes attrib_set
;
181 gboolean activate
= FALSE
;
185 /* check if it has already been unmapped by the time we started mapping
186 the grab does a sync so we don't have to here */
187 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
188 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
189 XPutBackEvent(ob_display
, &e
);
192 return; /* don't manage it */
195 /* make sure it isn't an override-redirect window */
196 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
197 attrib
.override_redirect
) {
199 return; /* don't manage it */
202 /* is the window a docking app */
203 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
204 if ((wmhint
->flags
& StateHint
) &&
205 wmhint
->initial_state
== WithdrawnState
) {
206 dock_add(window
, wmhint
);
214 g_message("Managing window: %lx", window
);
216 /* choose the events we want to receive on the CLIENT window */
217 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
218 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
219 XChangeWindowAttributes(ob_display
, window
,
220 CWEventMask
|CWDontPropagate
, &attrib_set
);
223 /* create the Client struct, and populate it from the hints on the
225 self
= g_new(Client
, 1);
226 self
->obwin
.type
= Window_Client
;
227 self
->window
= window
;
228 client_get_all(self
);
230 /* remove the client's border (and adjust re gravity) */
231 client_toggle_border(self
, FALSE
);
233 /* specify that if we exit, the window should not be destroyed and should
234 be reparented back to root automatically */
235 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
237 /* create the decoration frame for the client window */
238 self
->frame
= frame_new();
240 frame_grab_client(self
->frame
, self
);
242 client_apply_startup_state(self
);
246 /* add to client list/map */
247 client_list
= g_list_append(client_list
, self
);
248 g_hash_table_insert(window_map
, &self
->window
, self
);
250 /* update the focus lists */
251 focus_order_add_new(self
);
253 /* focus the new window? */
254 if (ob_state
!= State_Starting
&& config_focus_new
) {
255 gboolean group_foc
= FALSE
;
260 for (it
= self
->group
->members
; it
; it
= it
->next
)
261 if (client_focused(it
->data
)) {
266 /* note the check against Type_Normal/Dialog, not client_normal(self),
267 which would also include other types. in this case we want more
268 strict rules for focus */
269 if (((self
->type
== Type_Normal
||
270 (self
->type
== Type_Dialog
&&
272 (!self
->transient_for
&& (!self
->group
||
273 !self
->group
->members
->next
)))))) ||
274 client_search_focus_tree_full(self
) ||
276 !client_normal(focus_client
)) {
277 /* activate the window */
278 stacking_add(CLIENT_AS_WINDOW(self
));
281 /* try to not get in the way */
282 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
285 stacking_add(CLIENT_AS_WINDOW(self
));
288 screen_update_struts();
290 /* make sure the window is visible */
291 client_move_onscreen(self
);
293 dispatch_client(Event_Client_New
, self
, 0, 0);
295 client_showhide(self
);
297 if (activate
) client_activate(self
);
299 /* update the list hints */
302 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
304 g_message("Managed window 0x%lx", window
);
307 void client_unmanage_all()
309 while (client_list
!= NULL
)
310 client_unmanage(client_list
->data
);
313 void client_unmanage(Client
*self
)
318 g_message("Unmanaging window: %lx", self
->window
);
320 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
321 g_assert(self
!= NULL
);
323 /* remove the window from our save set */
324 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
326 /* we dont want events no more */
327 XSelectInput(ob_display
, self
->window
, NoEventMask
);
329 frame_hide(self
->frame
);
331 client_list
= g_list_remove(client_list
, self
);
332 stacking_remove(self
);
333 g_hash_table_remove(window_map
, &self
->window
);
335 /* update the focus lists */
336 focus_order_remove(self
);
338 /* once the client is out of the list, update the struts to remove it's
340 screen_update_struts();
342 /* tell our parent(s) that we're gone */
343 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
346 for (it
= self
->group
->members
; it
; it
= it
->next
)
347 if (it
->data
!= self
)
348 ((Client
*)it
->data
)->transients
=
349 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
350 } else if (self
->transient_for
) { /* transient of window */
351 self
->transient_for
->transients
=
352 g_slist_remove(self
->transient_for
->transients
, self
);
355 /* tell our transients that we're gone */
356 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
357 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
358 ((Client
*)it
->data
)->transient_for
= NULL
;
359 client_calc_layer(it
->data
);
363 if (moveresize_client
== self
)
364 moveresize_end(TRUE
);
366 if (focus_client
== self
) {
369 /* focus the last focused window on the desktop, and ignore enter
370 events from the unmap so it doesnt mess with the focus */
371 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
372 client_unfocus(self
);
375 /* remove from its group */
377 group_remove(self
->group
, self
);
381 /* dispatch the unmapped event */
382 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
383 g_assert(self
!= NULL
);
385 /* give the client its border back */
386 client_toggle_border(self
, TRUE
);
388 /* reparent the window out of the frame, and free the frame */
389 frame_release_client(self
->frame
, self
);
392 if (ob_state
!= State_Exiting
) {
393 /* these values should not be persisted across a window
395 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
396 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
398 /* if we're left in an iconic state, the client wont be mapped. this is
399 bad, since we will no longer be managing the window on restart */
401 XMapWindow(ob_display
, self
->window
);
405 g_message("Unmanaged window 0x%lx", self
->window
);
407 /* free all data allocated in the client struct */
408 g_slist_free(self
->transients
);
409 for (j
= 0; j
< self
->nicons
; ++j
)
410 g_free(self
->icons
[j
].data
);
411 if (self
->nicons
> 0)
414 g_free(self
->icon_title
);
420 /* update the list hints */
424 void client_move_onscreen(Client
*self
)
427 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
429 a
= screen_area(self
->desktop
);
430 if (x
>= a
->x
+ a
->width
- 1)
431 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
432 if (y
>= a
->y
+ a
->height
- 1)
433 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
434 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
436 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
439 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
441 client_configure(self
, Corner_TopLeft
, x
, y
,
442 self
->area
.width
, self
->area
.height
,
446 static void client_toggle_border(Client
*self
, gboolean show
)
448 /* adjust our idea of where the client is, based on its border. When the
449 border is removed, the client should now be considered to be in a
451 when re-adding the border to the client, the same operation needs to be
453 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
454 int x
= oldx
, y
= oldy
;
455 switch(self
->gravity
) {
457 case NorthWestGravity
:
459 case SouthWestGravity
:
461 case NorthEastGravity
:
463 case SouthEastGravity
:
464 if (show
) x
-= self
->border_width
* 2;
465 else x
+= self
->border_width
* 2;
472 if (show
) x
-= self
->border_width
;
473 else x
+= self
->border_width
;
476 switch(self
->gravity
) {
478 case NorthWestGravity
:
480 case NorthEastGravity
:
482 case SouthWestGravity
:
484 case SouthEastGravity
:
485 if (show
) y
-= self
->border_width
* 2;
486 else y
+= self
->border_width
* 2;
493 if (show
) y
-= self
->border_width
;
494 else y
+= self
->border_width
;
501 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
503 /* move the client so it is back it the right spot _with_ its
505 if (x
!= oldx
|| y
!= oldy
)
506 XMoveWindow(ob_display
, self
->window
, x
, y
);
508 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
512 static void client_get_all(Client
*self
)
514 /* update EVERYTHING!! */
516 self
->ignore_unmaps
= 0;
520 self
->title
= self
->icon_title
= NULL
;
521 self
->title_count
= 1;
522 self
->name
= self
->class = self
->role
= NULL
;
523 self
->wmstate
= NormalState
;
524 self
->transient
= FALSE
;
525 self
->transients
= NULL
;
526 self
->transient_for
= NULL
;
528 self
->urgent
= FALSE
;
529 self
->positioned
= FALSE
;
530 self
->disabled_decorations
= 0;
534 client_get_area(self
);
535 client_update_transient_for(self
);
536 client_update_wmhints(self
);
537 client_get_desktop(self
);
538 client_get_state(self
);
539 client_get_shaped(self
);
541 client_get_mwm_hints(self
);
542 client_get_type(self
);/* this can change the mwmhints for special cases */
544 client_update_protocols(self
);
546 client_get_gravity(self
); /* get the attribute gravity */
547 client_update_normal_hints(self
); /* this may override the attribute
550 /* got the type, the mwmhints, the protocols, and the normal hints
551 (min/max sizes), so we're ready to set up the decorations/functions */
552 client_setup_decor_and_functions(self
);
554 client_update_title(self
);
555 client_update_class(self
);
556 client_update_strut(self
);
557 client_update_icons(self
);
558 client_update_kwm_icon(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
!= TRAN_GROUP
) {
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
!= TRAN_GROUP
))
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
!= TRAN_GROUP
))
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 if (it
->data
!= self
&&
1127 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
) {
1128 self
->transients
= g_slist_remove(self
->transients
,
1131 group_remove(self
->group
, self
);
1134 if (hints
->window_group
!= None
) {
1135 self
->group
= group_add(hints
->window_group
, self
);
1137 /* add other transients of the group that are already
1139 for (it
= self
->group
->members
; it
; it
= it
->next
)
1140 if (it
->data
!= self
&&
1141 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1142 self
->transients
= g_slist_append(self
->transients
,
1146 /* because the self->transient flag wont change from this call,
1147 we don't need to update the window's type and such, only its
1148 transient_for, and the transients lists of other windows in
1149 the group may be affected */
1150 client_update_transient_for(self
);
1153 client_update_kwm_icon(self
);
1154 /* try get the kwm icon first, this is a fallback only */
1155 if (self
->pixmap_icon
== None
) {
1156 if (hints
->flags
& IconPixmapHint
) {
1157 if (self
->pixmap_icon
== None
) {
1158 self
->pixmap_icon
= hints
->icon_pixmap
;
1159 if (hints
->flags
& IconMaskHint
)
1160 self
->pixmap_icon_mask
= hints
->icon_mask
;
1162 self
->pixmap_icon_mask
= None
;
1165 frame_adjust_icon(self
->frame
);
1173 if (ur
!= self
->urgent
) {
1175 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1177 /* fire the urgent callback if we're mapped, otherwise, wait until
1178 after we're mapped */
1180 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1184 void client_update_title(Client
*self
)
1190 gboolean read_title
;
1192 g_free(self
->title
);
1195 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1196 /* try old x stuff */
1197 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1198 data
= g_strdup("Unnamed Window");
1200 /* look for duplicates and append a number */
1202 for (it
= client_list
; it
; it
= it
->next
)
1203 if (it
->data
!= self
) {
1204 Client
*c
= it
->data
;
1205 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1206 nums
|= 1 << c
->title_count
;
1208 /* find first free number */
1209 for (i
= 1; i
<= 32; ++i
)
1210 if (!(nums
& (1 << i
))) {
1211 if (self
->title_count
== 1 || i
== 1)
1212 self
->title_count
= i
;
1215 /* dont display the number for the first window */
1216 if (self
->title_count
> 1) {
1217 char *vdata
, *ndata
;
1218 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1219 vdata
= g_strconcat(data
, ndata
, NULL
);
1225 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1230 frame_adjust_title(self
->frame
);
1232 /* update the icon title */
1234 g_free(self
->icon_title
);
1238 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1239 /* try old x stuff */
1240 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1241 data
= g_strdup(self
->title
);
1245 /* append the title count, dont display the number for the first window */
1246 if (read_title
&& self
->title_count
> 1) {
1247 char *vdata
, *ndata
;
1248 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1249 vdata
= g_strconcat(data
, ndata
, NULL
);
1255 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1257 self
->icon_title
= data
;
1260 void client_update_class(Client
*self
)
1265 if (self
->name
) g_free(self
->name
);
1266 if (self
->class) g_free(self
->class);
1267 if (self
->role
) g_free(self
->role
);
1269 self
->name
= self
->class = self
->role
= NULL
;
1271 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1273 self
->name
= g_strdup(data
[0]);
1275 self
->class = g_strdup(data
[1]);
1280 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1281 self
->role
= g_strdup(s
);
1283 if (self
->name
== NULL
) self
->name
= g_strdup("");
1284 if (self
->class == NULL
) self
->class = g_strdup("");
1285 if (self
->role
== NULL
) self
->role
= g_strdup("");
1288 void client_update_strut(Client
*self
)
1293 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1294 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1297 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1299 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1303 /* updating here is pointless while we're being mapped cuz we're not in
1304 the client list yet */
1306 screen_update_struts();
1309 void client_update_icons(Client
*self
)
1316 for (j
= 0; j
< self
->nicons
; ++j
)
1317 g_free(self
->icons
[j
].data
);
1318 if (self
->nicons
> 0)
1319 g_free(self
->icons
);
1322 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1323 /* figure out how many valid icons are in here */
1325 while (num
- i
> 2) {
1333 self
->icons
= g_new(Icon
, self
->nicons
);
1335 /* store the icons */
1337 for (j
= 0; j
< self
->nicons
; ++j
) {
1338 w
= self
->icons
[j
].width
= data
[i
++];
1339 h
= self
->icons
[j
].height
= data
[i
++];
1340 self
->icons
[j
].data
=
1341 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1350 frame_adjust_icon(self
->frame
);
1353 void client_update_kwm_icon(Client
*self
)
1358 if (!PROP_GETA32(self
->window
, kwm_win_icon
, kwm_win_icon
, &data
, &num
)) {
1359 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1362 self
->pixmap_icon
= data
[0];
1363 self
->pixmap_icon_mask
= data
[1];
1365 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1369 frame_adjust_icon(self
->frame
);
1372 static void client_change_state(Client
*self
)
1375 guint32 netstate
[10];
1378 state
[0] = self
->wmstate
;
1380 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1384 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1386 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1388 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1389 if (self
->skip_taskbar
)
1390 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1391 if (self
->skip_pager
)
1392 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1393 if (self
->fullscreen
)
1394 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1396 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1398 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1400 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1402 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1403 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1405 client_calc_layer(self
);
1408 frame_adjust_state(self
->frame
);
1411 Client
*client_search_focus_tree(Client
*self
)
1416 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1417 if (client_focused(it
->data
)) return it
->data
;
1418 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1423 Client
*client_search_focus_tree_full(Client
*self
)
1425 if (self
->transient_for
) {
1426 if (self
->transient_for
!= TRAN_GROUP
) {
1427 return client_search_focus_tree_full(self
->transient_for
);
1431 for (it
= self
->group
->members
; it
; it
= it
->next
)
1432 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1434 if ((c
= client_search_focus_tree_full(it
->data
)))
1440 /* this function checks the whole tree, the client_search_focus_tree
1441 does not, so we need to check this window */
1442 if (client_focused(self
))
1444 return client_search_focus_tree(self
);
1448 static StackLayer
calc_layer(Client
*self
)
1452 if (self
->fullscreen
) l
= Layer_Fullscreen
;
1453 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1454 else if (self
->type
== Type_Dock
) {
1455 if (!self
->below
) l
= Layer_Top
;
1456 else l
= Layer_Normal
;
1458 else if (self
->above
) l
= Layer_Above
;
1459 else if (self
->below
) l
= Layer_Below
;
1460 else l
= Layer_Normal
;
1465 static void calc_recursive(Client
*self
, Client
*orig
, StackLayer l
,
1468 StackLayer old
, own
;
1472 own
= calc_layer(self
);
1473 self
->layer
= l
> own
? l
: own
;
1475 for (it
= self
->transients
; it
; it
= it
->next
)
1476 calc_recursive(it
->data
, orig
, l
, raised
? raised
: l
!= old
);
1478 if (!raised
&& l
!= old
)
1479 if (orig
->frame
) /* only restack if the original window is managed */
1480 stacking_raise(CLIENT_AS_WINDOW(self
));
1483 void client_calc_layer(Client
*self
)
1490 /* transients take on the layer of their parents */
1491 if (self
->transient_for
) {
1492 if (self
->transient_for
!= TRAN_GROUP
) {
1493 self
= self
->transient_for
;
1497 for (it
= self
->group
->members
; it
; it
= it
->next
)
1498 if (it
->data
!= self
&&
1499 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1506 l
= calc_layer(self
);
1508 calc_recursive(self
, orig
, l
, FALSE
);
1511 gboolean
client_should_show(Client
*self
)
1513 if (self
->iconic
) return FALSE
;
1514 else if (!(self
->desktop
== screen_desktop
||
1515 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1516 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1521 static void client_showhide(Client
*self
)
1524 if (client_should_show(self
))
1525 frame_show(self
->frame
);
1527 frame_hide(self
->frame
);
1530 gboolean
client_normal(Client
*self
) {
1531 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1532 self
->type
== Type_Splash
);
1535 static void client_apply_startup_state(Client
*self
)
1537 /* these are in a carefully crafted order.. */
1540 self
->iconic
= FALSE
;
1541 client_iconify(self
, TRUE
, FALSE
);
1543 if (self
->fullscreen
) {
1544 self
->fullscreen
= FALSE
;
1545 client_fullscreen(self
, TRUE
, FALSE
);
1548 self
->shaded
= FALSE
;
1549 client_shade(self
, TRUE
);
1552 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1554 if (self
->max_vert
&& self
->max_horz
) {
1555 self
->max_vert
= self
->max_horz
= FALSE
;
1556 client_maximize(self
, TRUE
, 0, FALSE
);
1557 } else if (self
->max_vert
) {
1558 self
->max_vert
= FALSE
;
1559 client_maximize(self
, TRUE
, 2, FALSE
);
1560 } else if (self
->max_horz
) {
1561 self
->max_horz
= FALSE
;
1562 client_maximize(self
, TRUE
, 1, FALSE
);
1565 /* nothing to do for the other states:
1574 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1575 gboolean user
, gboolean final
)
1577 gboolean moved
= FALSE
, resized
= FALSE
;
1579 /* gets the frame's position */
1580 frame_client_gravity(self
->frame
, &x
, &y
);
1582 /* these positions are frame positions, not client positions */
1584 /* set the size and position if fullscreen */
1585 if (self
->fullscreen
) {
1588 w
= screen_physical_size
.width
;
1589 h
= screen_physical_size
.height
;
1590 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1592 /* set the size and position if maximized */
1593 if (self
->max_horz
) {
1594 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1595 w
= screen_area(self
->desktop
)->width
;
1597 if (self
->max_vert
) {
1598 y
= screen_area(self
->desktop
)->y
;
1599 h
= screen_area(self
->desktop
)->height
-
1600 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1604 /* gets the client's position */
1605 frame_frame_gravity(self
->frame
, &x
, &y
);
1607 /* these override the above states! if you cant move you can't move! */
1609 if (!(self
->functions
& Func_Move
)) {
1613 if (!(self
->functions
& Func_Resize
)) {
1614 w
= self
->area
.width
;
1615 h
= self
->area
.height
;
1619 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1620 w
-= self
->base_size
.width
;
1621 h
-= self
->base_size
.height
;
1624 /* for interactive resizing. have to move half an increment in each
1627 /* how far we are towards the next size inc */
1628 int mw
= w
% self
->size_inc
.width
;
1629 int mh
= h
% self
->size_inc
.height
;
1631 int aw
= self
->size_inc
.width
/ 2;
1632 int ah
= self
->size_inc
.height
/ 2;
1633 /* don't let us move into a new size increment */
1634 if (mw
+ aw
>= self
->size_inc
.width
)
1635 aw
= self
->size_inc
.width
- mw
- 1;
1636 if (mh
+ ah
>= self
->size_inc
.height
)
1637 ah
= self
->size_inc
.height
- mh
- 1;
1641 /* if this is a user-requested resize, then check against min/max
1642 sizes and aspect ratios */
1644 /* smaller than min size or bigger than max size? */
1645 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1646 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1647 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1648 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1650 /* adjust the height ot match the width for the aspect ratios */
1651 if (self
->min_ratio
)
1652 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1653 if (self
->max_ratio
)
1654 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1657 /* keep to the increments */
1658 w
/= self
->size_inc
.width
;
1659 h
/= self
->size_inc
.height
;
1661 /* you cannot resize to nothing */
1665 /* store the logical size */
1666 SIZE_SET(self
->logical_size
, w
, h
);
1668 w
*= self
->size_inc
.width
;
1669 h
*= self
->size_inc
.height
;
1671 w
+= self
->base_size
.width
;
1672 h
+= self
->base_size
.height
;
1676 case Corner_TopLeft
:
1678 case Corner_TopRight
:
1679 x
-= w
- self
->area
.width
;
1681 case Corner_BottomLeft
:
1682 y
-= h
- self
->area
.height
;
1684 case Corner_BottomRight
:
1685 x
-= w
- self
->area
.width
;
1686 y
-= h
- self
->area
.height
;
1690 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1691 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1693 RECT_SET(self
->area
, x
, y
, w
, h
);
1696 XResizeWindow(ob_display
, self
->window
, w
, h
);
1698 /* move/resize the frame to match the request */
1700 if (moved
|| resized
)
1701 frame_adjust_area(self
->frame
, moved
, resized
);
1703 if (!user
|| final
) {
1705 event
.type
= ConfigureNotify
;
1706 event
.xconfigure
.display
= ob_display
;
1707 event
.xconfigure
.event
= self
->window
;
1708 event
.xconfigure
.window
= self
->window
;
1710 /* root window real coords */
1711 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
;
1712 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
;
1714 event
.xconfigure
.width
= w
;
1715 event
.xconfigure
.height
= h
;
1716 event
.xconfigure
.border_width
= 0;
1717 event
.xconfigure
.above
= self
->frame
->plate
;
1718 event
.xconfigure
.override_redirect
= FALSE
;
1719 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1720 FALSE
, StructureNotifyMask
, &event
);
1725 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1729 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1730 self
->fullscreen
== fs
) return; /* already done */
1732 self
->fullscreen
= fs
;
1733 client_change_state(self
); /* change the state hints on the client,
1734 and adjust out layer/stacking */
1738 guint32 dimensions
[4];
1739 dimensions
[0] = self
->area
.x
;
1740 dimensions
[1] = self
->area
.y
;
1741 dimensions
[2] = self
->area
.width
;
1742 dimensions
[3] = self
->area
.height
;
1744 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1748 /* these are not actually used cuz client_configure will set them
1749 as appropriate when the window is fullscreened */
1755 /* pick some fallbacks... */
1756 x
= screen_area(self
->desktop
)->x
+
1757 screen_area(self
->desktop
)->width
/ 4;
1758 y
= screen_area(self
->desktop
)->y
+
1759 screen_area(self
->desktop
)->height
/ 4;
1760 w
= screen_area(self
->desktop
)->width
/ 2;
1761 h
= screen_area(self
->desktop
)->height
/ 2;
1763 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1764 (guint32
**)&dimensions
, &num
)) {
1775 client_setup_decor_and_functions(self
);
1777 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1779 /* try focus us when we go into fullscreen mode */
1783 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1787 /* move up the transient chain as far as possible first */
1788 if (self
->transient_for
) {
1789 if (self
->transient_for
!= TRAN_GROUP
) {
1790 if (self
->transient_for
->iconic
!= iconic
) {
1791 client_iconify(self
->transient_for
, iconic
, curdesk
);
1797 /* the check for TRAN_GROUP is to prevent an infinate loop with
1798 2 transients of the same group at the head of the group's
1800 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1801 Client
*c
= it
->data
;
1802 if (c
!= self
&& c
->iconic
!= iconic
&&
1803 c
->transient_for
!= TRAN_GROUP
) {
1804 client_iconify(it
->data
, iconic
, curdesk
);
1808 if (it
!= NULL
) return;
1812 if (self
->iconic
== iconic
) return; /* nothing to do */
1814 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1817 self
->iconic
= iconic
;
1820 self
->wmstate
= IconicState
;
1821 self
->ignore_unmaps
++;
1822 /* we unmap the client itself so that we can get MapRequest events,
1823 and because the ICCCM tells us to! */
1824 XUnmapWindow(ob_display
, self
->window
);
1826 /* update the focus lists.. iconic windows go to the bottom of the
1827 list, put the new iconic window at the 'top of the bottom'. */
1828 focus_order_to_top(self
);
1831 client_set_desktop(self
, screen_desktop
, FALSE
);
1832 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1833 XMapWindow(ob_display
, self
->window
);
1835 /* this puts it after the current focused window */
1836 focus_order_remove(self
);
1837 focus_order_add_new(self
);
1839 client_change_state(self
);
1840 client_showhide(self
);
1841 screen_update_struts();
1843 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1846 /* iconify all transients */
1847 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1848 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1851 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1855 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1856 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1858 /* check if already done */
1860 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1861 if (dir
== 1 && self
->max_horz
) return;
1862 if (dir
== 2 && self
->max_vert
) return;
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;
1869 /* work with the frame's coords */
1870 x
= self
->frame
->area
.x
;
1871 y
= self
->frame
->area
.y
;
1872 w
= self
->area
.width
;
1873 h
= self
->area
.height
;
1877 gint32 dimensions
[4];
1886 /* get the property off the window and use it for the dimensions
1887 we are already maxed on */
1888 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1889 (guint32
**)&readdim
, &num
)) {
1891 if (self
->max_horz
) {
1892 dimensions
[0] = readdim
[0];
1893 dimensions
[2] = readdim
[2];
1895 if (self
->max_vert
) {
1896 dimensions
[1] = readdim
[1];
1897 dimensions
[3] = readdim
[3];
1903 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1904 (guint32
*)dimensions
, 4);
1910 /* pick some fallbacks... */
1911 if (dir
== 0 || dir
== 1) { /* horz */
1912 x
= screen_area(self
->desktop
)->x
+
1913 screen_area(self
->desktop
)->width
/ 4;
1914 w
= screen_area(self
->desktop
)->width
/ 2;
1916 if (dir
== 0 || dir
== 2) { /* vert */
1917 y
= screen_area(self
->desktop
)->y
+
1918 screen_area(self
->desktop
)->height
/ 4;
1919 h
= screen_area(self
->desktop
)->height
/ 2;
1922 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1923 (guint32
**)&dimensions
, &num
)) {
1925 if (dir
== 0 || dir
== 1) { /* horz */
1929 if (dir
== 0 || dir
== 2) { /* vert */
1938 if (dir
== 0 || dir
== 1) /* horz */
1939 self
->max_horz
= max
;
1940 if (dir
== 0 || dir
== 2) /* vert */
1941 self
->max_vert
= max
;
1943 if (!self
->max_horz
&& !self
->max_vert
)
1944 PROP_ERASE(self
->window
, openbox_premax
);
1946 client_change_state(self
); /* change the state hints on the client */
1948 /* figure out where the client should be going */
1949 frame_frame_gravity(self
->frame
, &x
, &y
);
1950 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1953 void client_shade(Client
*self
, gboolean shade
)
1955 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1956 self
->shaded
== shade
) return; /* already done */
1958 /* when we're iconic, don't change the wmstate */
1960 self
->wmstate
= shade
? IconicState
: NormalState
;
1961 self
->shaded
= shade
;
1962 client_change_state(self
);
1963 /* resize the frame to just the titlebar */
1964 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1967 void client_close(Client
*self
)
1971 if (!(self
->functions
& Func_Close
)) return;
1974 XXX: itd be cool to do timeouts and shit here for killing the client's
1976 like... if the window is around after 5 seconds, then the close button
1977 turns a nice red, and if this function is called again, the client is
1981 ce
.xclient
.type
= ClientMessage
;
1982 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1983 ce
.xclient
.display
= ob_display
;
1984 ce
.xclient
.window
= self
->window
;
1985 ce
.xclient
.format
= 32;
1986 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1987 ce
.xclient
.data
.l
[1] = event_lasttime
;
1988 ce
.xclient
.data
.l
[2] = 0l;
1989 ce
.xclient
.data
.l
[3] = 0l;
1990 ce
.xclient
.data
.l
[4] = 0l;
1991 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1994 void client_kill(Client
*self
)
1996 XKillClient(ob_display
, self
->window
);
1999 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
2003 if (target
== self
->desktop
) return;
2005 g_message("Setting desktop %u", target
);
2007 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2009 /* remove from the old desktop(s) */
2010 focus_order_remove(self
);
2012 old
= self
->desktop
;
2013 self
->desktop
= target
;
2014 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2015 /* the frame can display the current desktop state */
2016 frame_adjust_state(self
->frame
);
2017 /* 'move' the window to the new desktop */
2019 client_showhide(self
);
2020 /* raise if it was not already on the desktop */
2021 if (old
!= DESKTOP_ALL
)
2022 stacking_raise(CLIENT_AS_WINDOW(self
));
2023 screen_update_struts();
2025 /* add to the new desktop(s) */
2026 if (config_focus_new
)
2027 focus_order_to_top(self
);
2029 focus_order_to_bottom(self
);
2031 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2034 Client
*client_search_modal_child(Client
*self
)
2039 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2040 Client
*c
= it
->data
;
2041 if ((ret
= client_search_modal_child(c
))) return ret
;
2042 if (c
->modal
) return c
;
2047 gboolean
client_validate(Client
*self
)
2051 XSync(ob_display
, FALSE
); /* get all events on the server */
2053 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2054 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2055 XPutBackEvent(ob_display
, &e
);
2062 void client_set_wm_state(Client
*self
, long state
)
2064 if (state
== self
->wmstate
) return; /* no change */
2068 client_iconify(self
, TRUE
, TRUE
);
2071 client_iconify(self
, FALSE
, TRUE
);
2076 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
2078 gboolean shaded
= self
->shaded
;
2079 gboolean fullscreen
= self
->fullscreen
;
2080 gboolean max_horz
= self
->max_horz
;
2081 gboolean max_vert
= self
->max_vert
;
2084 if (!(action
== prop_atoms
.net_wm_state_add
||
2085 action
== prop_atoms
.net_wm_state_remove
||
2086 action
== prop_atoms
.net_wm_state_toggle
))
2087 /* an invalid action was passed to the client message, ignore it */
2090 for (i
= 0; i
< 2; ++i
) {
2091 Atom state
= i
== 0 ? data1
: data2
;
2093 if (!state
) continue;
2095 /* if toggling, then pick whether we're adding or removing */
2096 if (action
== prop_atoms
.net_wm_state_toggle
) {
2097 if (state
== prop_atoms
.net_wm_state_modal
)
2098 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2099 prop_atoms
.net_wm_state_add
;
2100 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2101 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2102 prop_atoms
.net_wm_state_add
;
2103 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2104 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2105 prop_atoms
.net_wm_state_add
;
2106 else if (state
== prop_atoms
.net_wm_state_shaded
)
2107 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2108 prop_atoms
.net_wm_state_add
;
2109 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2110 action
= self
->skip_taskbar
?
2111 prop_atoms
.net_wm_state_remove
:
2112 prop_atoms
.net_wm_state_add
;
2113 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2114 action
= self
->skip_pager
?
2115 prop_atoms
.net_wm_state_remove
:
2116 prop_atoms
.net_wm_state_add
;
2117 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2118 action
= self
->fullscreen
?
2119 prop_atoms
.net_wm_state_remove
:
2120 prop_atoms
.net_wm_state_add
;
2121 else if (state
== prop_atoms
.net_wm_state_above
)
2122 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2123 prop_atoms
.net_wm_state_add
;
2124 else if (state
== prop_atoms
.net_wm_state_below
)
2125 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2126 prop_atoms
.net_wm_state_add
;
2129 if (action
== prop_atoms
.net_wm_state_add
) {
2130 if (state
== prop_atoms
.net_wm_state_modal
) {
2131 /* XXX raise here or something? */
2133 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2135 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2137 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2139 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2140 self
->skip_taskbar
= TRUE
;
2141 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2142 self
->skip_pager
= TRUE
;
2143 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2145 } else if (state
== prop_atoms
.net_wm_state_above
) {
2147 } else if (state
== prop_atoms
.net_wm_state_below
) {
2151 } else { /* action == prop_atoms.net_wm_state_remove */
2152 if (state
== prop_atoms
.net_wm_state_modal
) {
2153 self
->modal
= FALSE
;
2154 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2156 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2158 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2160 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2161 self
->skip_taskbar
= FALSE
;
2162 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2163 self
->skip_pager
= FALSE
;
2164 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2166 } else if (state
== prop_atoms
.net_wm_state_above
) {
2167 self
->above
= FALSE
;
2168 } else if (state
== prop_atoms
.net_wm_state_below
) {
2169 self
->below
= FALSE
;
2173 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2174 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2176 if (max_horz
== max_vert
) { /* both going the same way */
2177 client_maximize(self
, max_horz
, 0, TRUE
);
2179 client_maximize(self
, max_horz
, 1, TRUE
);
2180 client_maximize(self
, max_vert
, 2, TRUE
);
2184 if (max_horz
!= self
->max_horz
)
2185 client_maximize(self
, max_horz
, 1, TRUE
);
2187 client_maximize(self
, max_vert
, 2, TRUE
);
2190 /* change fullscreen state before shading, as it will affect if the window
2192 if (fullscreen
!= self
->fullscreen
)
2193 client_fullscreen(self
, fullscreen
, TRUE
);
2194 if (shaded
!= self
->shaded
)
2195 client_shade(self
, shaded
);
2196 client_calc_layer(self
);
2197 client_change_state(self
); /* change the hint to relect these changes */
2200 Client
*client_focus_target(Client
*self
)
2204 /* if we have a modal child, then focus it, not us */
2205 child
= client_search_modal_child(self
);
2206 if (child
) return child
;
2210 gboolean
client_focus(Client
*self
)
2214 /* choose the correct target */
2215 self
= client_focus_target(self
);
2217 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2218 /* update the focus lists */
2219 focus_order_to_top(self
);
2223 if (!((self
->can_focus
|| self
->focus_notify
) &&
2224 (self
->desktop
== screen_desktop
||
2225 self
->desktop
== DESKTOP_ALL
) &&
2229 /* do a check to see if the window has already been unmapped or destroyed
2230 do this intelligently while watching out for unmaps we've generated
2231 (ignore_unmaps > 0) */
2232 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2233 DestroyNotify
, &ev
)) {
2234 XPutBackEvent(ob_display
, &ev
);
2237 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2238 UnmapNotify
, &ev
)) {
2239 if (self
->ignore_unmaps
) {
2240 self
->ignore_unmaps
--;
2242 XPutBackEvent(ob_display
, &ev
);
2247 if (self
->can_focus
)
2248 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2249 I choose to use it always, hopefully to find errors quicker, if any
2250 are left. (I hate X. I hate focus events.) */
2251 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2254 if (self
->focus_notify
) {
2256 ce
.xclient
.type
= ClientMessage
;
2257 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2258 ce
.xclient
.display
= ob_display
;
2259 ce
.xclient
.window
= self
->window
;
2260 ce
.xclient
.format
= 32;
2261 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2262 ce
.xclient
.data
.l
[1] = event_lasttime
;
2263 ce
.xclient
.data
.l
[2] = 0l;
2264 ce
.xclient
.data
.l
[3] = 0l;
2265 ce
.xclient
.data
.l
[4] = 0l;
2266 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2270 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2275 /* Cause the FocusIn to come back to us. Important for desktop switches,
2276 since otherwise we'll have no FocusIn on the queue and send it off to
2277 the focus_backup. */
2278 XSync(ob_display
, FALSE
);
2282 void client_unfocus(Client
*self
)
2284 g_assert(focus_client
== self
);
2286 g_message("client_unfocus for %lx", self
->window
);
2288 focus_fallback(Fallback_Unfocusing
);
2291 void client_activate(Client
*self
)
2293 if (client_normal(self
) && screen_showing_desktop
)
2294 screen_show_desktop(FALSE
);
2296 client_iconify(self
, FALSE
, TRUE
);
2297 else if (!self
->frame
->visible
)
2298 /* if its not visible for other reasons, then don't mess
2302 client_shade(self
, FALSE
);
2304 stacking_raise(CLIENT_AS_WINDOW(self
));
2307 gboolean
client_focused(Client
*self
)
2309 return self
== focus_client
;
2312 Icon
*client_icon(Client
*self
, int w
, int h
)
2315 /* si is the smallest image >= req */
2316 /* li is the largest image < req */
2317 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2319 if (!self
->nicons
) return NULL
;
2321 for (i
= 0; i
< self
->nicons
; ++i
) {
2322 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2323 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2327 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2332 if (largest
== 0) /* didnt find one smaller than the requested size */
2333 return &self
->icons
[si
];
2334 return &self
->icons
[li
];