3 #include "moveresize.h"
5 #include "extensions.h"
17 #include <X11/Xutil.h>
19 /*! The event mask to grab on client windows */
20 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
23 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
26 GList
*client_list
= NULL
;
27 GHashTable
*client_map
= NULL
;
29 static Window
*client_startup_stack_order
= NULL
;
30 static guint client_startup_stack_size
= 0;
32 static void client_get_all(Client
*self
);
33 static void client_toggle_border(Client
*self
, gboolean show
);
34 static void client_get_area(Client
*self
);
35 static void client_get_desktop(Client
*self
);
36 static void client_get_state(Client
*self
);
37 static void client_get_shaped(Client
*self
);
38 static void client_get_mwm_hints(Client
*self
);
39 static void client_get_gravity(Client
*self
);
40 static void client_showhide(Client
*self
);
41 static void client_change_allowed_actions(Client
*self
);
42 static void client_change_state(Client
*self
);
43 static void client_move_onscreen(Client
*self
);
44 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
45 static void client_apply_startup_state(Client
*self
);
46 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
48 static guint
map_hash(Window
*w
) { return *w
; }
49 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
53 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
54 (GEqualFunc
)map_key_comp
);
56 /* save the stacking order on startup! */
57 PROP_GETA32(ob_root
, net_client_list_stacking
, window
,
58 (guint32
**)&client_startup_stack_order
,
59 &client_startup_stack_size
);
64 void client_shutdown()
66 g_hash_table_destroy(client_map
);
69 void client_set_list()
71 Window
*windows
, *win_it
;
73 guint size
= g_list_length(client_list
);
75 /* create an array of the window ids */
77 windows
= g_new(Window
, size
);
79 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
80 *win_it
= ((Client
*)it
->data
)->window
;
84 PROP_SETA32(ob_root
, net_client_list
, window
, (guint32
*)windows
, size
);
92 void client_manage_all()
94 unsigned int i
, j
, nchild
;
97 XWindowAttributes attrib
;
99 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
101 /* remove all icon windows from the list */
102 for (i
= 0; i
< nchild
; i
++) {
103 if (children
[i
] == None
) continue;
104 wmhints
= XGetWMHints(ob_display
, children
[i
]);
106 if ((wmhints
->flags
& IconWindowHint
) &&
107 (wmhints
->icon_window
!= children
[i
]))
108 for (j
= 0; j
< nchild
; j
++)
109 if (children
[j
] == wmhints
->icon_window
) {
117 for (i
= 0; i
< nchild
; ++i
) {
118 if (children
[i
] == None
)
120 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
121 if (attrib
.override_redirect
) continue;
123 if (attrib
.map_state
!= IsUnmapped
)
124 client_manage(children
[i
]);
129 /* stack them as they were on startup!
130 why with stacking_lower? Why, because then windows who aren't in the
131 stacking list are on the top where you can see them instead of buried
133 for (i
= client_startup_stack_size
; i
> 0; --i
) {
136 w
= client_startup_stack_order
[i
-1];
137 c
= g_hash_table_lookup(client_map
, &w
);
138 if (c
) stacking_lower(c
);
140 g_free(client_startup_stack_order
);
141 client_startup_stack_order
= NULL
;
142 client_startup_stack_size
= 0;
144 if (config_focus_new
)
145 focus_fallback(Fallback_NoFocus
);
148 void client_manage(Window window
)
152 XWindowAttributes attrib
;
153 XSetWindowAttributes attrib_set
;
154 /* XWMHints *wmhint; */
159 /* check if it has already been unmapped by the time we started mapping
160 the grab does a sync so we don't have to here */
161 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
162 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
163 XPutBackEvent(ob_display
, &e
);
166 return; /* don't manage it */
169 /* make sure it isn't an override-redirect window */
170 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
171 attrib
.override_redirect
) {
173 return; /* don't manage it */
176 /* /\* is the window a docking app *\/
177 if ((wmhint = XGetWMHints(ob_display, window))) {
178 if ((wmhint->flags & StateHint) &&
179 wmhint->initial_state == WithdrawnState) {
180 /\* XXX: make dock apps work! *\/
188 g_message("Managing window: %lx", window
);
190 /* choose the events we want to receive on the CLIENT window */
191 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
192 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
193 XChangeWindowAttributes(ob_display
, window
,
194 CWEventMask
|CWDontPropagate
, &attrib_set
);
197 /* create the Client struct, and populate it from the hints on the
199 self
= g_new(Client
, 1);
200 self
->window
= window
;
201 client_get_all(self
);
203 /* remove the client's border (and adjust re gravity) */
204 client_toggle_border(self
, FALSE
);
206 /* specify that if we exit, the window should not be destroyed and should
207 be reparented back to root automatically */
208 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
210 /* create the decoration frame for the client window */
211 self
->frame
= frame_new();
213 frame_grab_client(self
->frame
, self
);
215 client_apply_startup_state(self
);
219 client_list
= g_list_append(client_list
, self
);
220 stacking_list
= g_list_append(stacking_list
, self
);
221 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
222 g_hash_table_insert(client_map
, &self
->window
, self
);
224 /* update the focus lists */
225 if (self
->desktop
== DESKTOP_ALL
) {
226 for (i
= 0; i
< screen_num_desktops
; ++i
)
227 focus_order
[i
] = g_list_insert(focus_order
[i
], self
, 1);
230 focus_order
[i
] = g_list_insert(focus_order
[i
], self
, 1);
233 stacking_raise(self
);
235 screen_update_struts();
237 dispatch_client(Event_Client_New
, self
, 0, 0);
239 client_showhide(self
);
241 /* focus the new window? */
242 if (ob_state
!= State_Starting
) {
244 gboolean group_foc
= FALSE
;
251 for (it
= self
->group
->members
; it
; it
= it
->next
)
252 if (client_focused(it
->data
)) {
257 if (!group_foc
&& self
->transient_for
) {
258 if (self
->transient_for
!= TRAN_GROUP
) {/* transient of a window */
259 parent
= self
->transient_for
;
260 } else { /* transient of a group */
263 for (it
= self
->group
->members
; it
; it
= it
->next
)
264 if (it
->data
!= self
&&
265 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
)
269 /* note the check against Type_Normal, not client_normal(self), which
270 would also include dialog types. in this case we want more strict
272 if ((config_focus_new
&&
273 (self
->type
== Type_Normal
||
274 (self
->type
== Type_Dialog
&& (group_foc
||
275 (!parent
&& !self
->group
))))) ||
276 (parent
&& (client_focused(parent
) ||
277 search_focus_tree(parent
, parent
)))) {
282 /* update the list hints */
285 /* make sure the window is visible */
286 client_move_onscreen(self
);
288 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
290 g_message("Managed window 0x%lx", window
);
293 void client_unmanage_all()
295 while (client_list
!= NULL
)
296 client_unmanage(client_list
->data
);
299 void client_unmanage(Client
*self
)
305 g_message("Unmanaging window: %lx", self
->window
);
307 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
308 g_assert(self
!= NULL
);
310 /* remove the window from our save set */
311 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
313 /* we dont want events no more */
314 XSelectInput(ob_display
, self
->window
, NoEventMask
);
316 frame_hide(self
->frame
);
318 client_list
= g_list_remove(client_list
, self
);
319 stacking_list
= g_list_remove(stacking_list
, self
);
320 g_hash_table_remove(client_map
, &self
->window
);
322 /* update the focus lists */
323 if (self
->desktop
== DESKTOP_ALL
) {
324 for (i
= 0; i
< screen_num_desktops
; ++i
)
325 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
328 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
331 /* once the client is out of the list, update the struts to remove it's
333 screen_update_struts();
335 /* tell our parent(s) that we're gone */
336 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
339 for (it
= self
->group
->members
; it
; it
= it
->next
)
340 if (it
->data
!= self
)
341 ((Client
*)it
->data
)->transients
=
342 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
343 } else if (self
->transient_for
) { /* transient of window */
344 self
->transient_for
->transients
=
345 g_slist_remove(self
->transient_for
->transients
, self
);
348 /* tell our transients that we're gone */
349 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
350 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
351 ((Client
*)it
->data
)->transient_for
= NULL
;
352 client_calc_layer(it
->data
);
356 if (moveresize_client
== self
)
357 moveresize_end(TRUE
);
359 if (focus_client
== self
) {
362 /* focus the last focused window on the desktop, and ignore enter
363 events from the unmap so it doesnt mess with the focus */
364 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
365 client_unfocus(self
);
368 /* remove from its group */
370 group_remove(self
->group
, self
);
374 /* dispatch the unmapped event */
375 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
376 g_assert(self
!= NULL
);
378 /* give the client its border back */
379 client_toggle_border(self
, TRUE
);
381 /* reparent the window out of the frame, and free the frame */
382 frame_release_client(self
->frame
, self
);
385 if (ob_state
!= State_Exiting
) {
386 /* these values should not be persisted across a window
388 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
389 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
391 /* if we're left in an iconic state, the client wont be mapped. this is
392 bad, since we will no longer be managing the window on restart */
394 XMapWindow(ob_display
, self
->window
);
398 g_message("Unmanaged window 0x%lx", self
->window
);
400 /* free all data allocated in the client struct */
401 g_slist_free(self
->transients
);
402 for (j
= 0; j
< self
->nicons
; ++j
)
403 g_free(self
->icons
[j
].data
);
404 if (self
->nicons
> 0)
407 g_free(self
->icon_title
);
413 /* update the list hints */
417 static void client_move_onscreen(Client
*self
)
420 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
422 a
= screen_area(self
->desktop
);
423 if (x
>= a
->x
+ a
->width
- 1)
424 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
425 if (y
>= a
->y
+ a
->height
- 1)
426 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
427 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
429 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
432 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
434 client_configure(self
, Corner_TopLeft
, x
, y
,
435 self
->area
.width
, self
->area
.height
,
439 static void client_toggle_border(Client
*self
, gboolean show
)
441 /* adjust our idea of where the client is, based on its border. When the
442 border is removed, the client should now be considered to be in a
444 when re-adding the border to the client, the same operation needs to be
446 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
447 int x
= oldx
, y
= oldy
;
448 switch(self
->gravity
) {
450 case NorthWestGravity
:
452 case SouthWestGravity
:
454 case NorthEastGravity
:
456 case SouthEastGravity
:
457 if (show
) x
-= self
->border_width
* 2;
458 else x
+= self
->border_width
* 2;
465 if (show
) x
-= self
->border_width
;
466 else x
+= self
->border_width
;
469 switch(self
->gravity
) {
471 case NorthWestGravity
:
473 case NorthEastGravity
:
475 case SouthWestGravity
:
477 case SouthEastGravity
:
478 if (show
) y
-= self
->border_width
* 2;
479 else y
+= self
->border_width
* 2;
486 if (show
) y
-= self
->border_width
;
487 else y
+= self
->border_width
;
494 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
496 /* move the client so it is back it the right spot _with_ its
498 if (x
!= oldx
|| y
!= oldy
)
499 XMoveWindow(ob_display
, self
->window
, x
, y
);
501 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
505 static void client_get_all(Client
*self
)
507 /* update EVERYTHING!! */
509 self
->ignore_unmaps
= 0;
513 self
->title
= self
->icon_title
= NULL
;
514 self
->name
= self
->class = self
->role
= NULL
;
515 self
->wmstate
= NormalState
;
516 self
->transient
= FALSE
;
517 self
->transients
= NULL
;
518 self
->transient_for
= NULL
;
520 self
->urgent
= FALSE
;
521 self
->positioned
= FALSE
;
522 self
->disabled_decorations
= 0;
526 client_get_area(self
);
527 client_update_transient_for(self
);
528 client_update_wmhints(self
);
529 client_get_desktop(self
);
530 client_get_state(self
);
531 client_get_shaped(self
);
533 client_get_mwm_hints(self
);
534 client_get_type(self
);/* this can change the mwmhints for special cases */
536 client_update_protocols(self
);
538 client_get_gravity(self
); /* get the attribute gravity */
539 client_update_normal_hints(self
); /* this may override the attribute
542 /* got the type, the mwmhints, the protocols, and the normal hints
543 (min/max sizes), so we're ready to set up the decorations/functions */
544 client_setup_decor_and_functions(self
);
546 client_update_title(self
);
547 client_update_icon_title(self
);
548 client_update_class(self
);
549 client_update_strut(self
);
550 client_update_icons(self
);
551 client_update_kwm_icon(self
);
553 client_change_state(self
);
556 static void client_get_area(Client
*self
)
558 XWindowAttributes wattrib
;
561 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
562 g_assert(ret
!= BadWindow
);
564 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
565 self
->border_width
= wattrib
.border_width
;
568 static void client_get_desktop(Client
*self
)
572 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
573 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
574 d
= screen_num_desktops
- 1;
577 gboolean trdesk
= FALSE
;
579 if (self
->transient_for
) {
580 if (self
->transient_for
!= TRAN_GROUP
) {
581 self
->desktop
= self
->transient_for
->desktop
;
586 for (it
= self
->group
->members
; it
; it
= it
->next
)
587 if (it
->data
!= self
&&
588 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
589 self
->desktop
= ((Client
*)it
->data
)->desktop
;
596 /* defaults to the current desktop */
597 self
->desktop
= screen_desktop
;
599 /* set the desktop hint, to make sure that it always exists */
600 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
604 static void client_get_state(Client
*self
)
609 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
610 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
611 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
613 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
615 for (i
= 0; i
< num
; ++i
) {
616 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
618 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
620 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
622 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
623 self
->skip_taskbar
= TRUE
;
624 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
625 self
->skip_pager
= TRUE
;
626 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
627 self
->fullscreen
= TRUE
;
628 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
629 self
->max_vert
= TRUE
;
630 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
631 self
->max_horz
= TRUE
;
632 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
634 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
642 static void client_get_shaped(Client
*self
)
644 self
->shaped
= FALSE
;
646 if (extensions_shape
) {
651 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
653 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
654 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
656 self
->shaped
= (s
!= 0);
661 void client_update_transient_for(Client
*self
)
666 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
667 t
!= self
->window
) { /* cant be transient to itself! */
668 self
->transient
= TRUE
;
669 c
= g_hash_table_lookup(client_map
, &t
);
670 g_assert(c
!= self
);/* if this happens then we need to check for it*/
672 if (!c
&& self
->group
) {
673 /* not transient to a client, see if it is transient for a
675 if (t
== self
->group
->leader
||
678 /* window is a transient for its group! */
683 self
->transient
= FALSE
;
685 /* if anything has changed... */
686 if (c
!= self
->transient_for
) {
687 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
690 /* remove from old parents */
691 for (it
= self
->group
->members
; it
; it
= it
->next
)
692 if (it
->data
!= self
)
693 ((Client
*)it
->data
)->transients
=
694 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
695 } else if (self
->transient_for
!= NULL
) { /* transient of window */
696 /* remove from old parent */
697 self
->transient_for
->transients
=
698 g_slist_remove(self
->transient_for
->transients
, self
);
700 self
->transient_for
= c
;
701 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
704 /* add to new parents */
705 for (it
= self
->group
->members
; it
; it
= it
->next
)
706 if (it
->data
!= self
)
707 ((Client
*)it
->data
)->transients
=
708 g_slist_append(((Client
*)it
->data
)->transients
, self
);
709 } else if (self
->transient_for
!= NULL
) { /* transient of window */
710 /* add to new parent */
711 self
->transient_for
->transients
=
712 g_slist_append(self
->transient_for
->transients
, self
);
717 static void client_get_mwm_hints(Client
*self
)
722 self
->mwmhints
.flags
= 0; /* default to none */
724 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
726 if (num
>= MWM_ELEMENTS
) {
727 self
->mwmhints
.flags
= hints
[0];
728 self
->mwmhints
.functions
= hints
[1];
729 self
->mwmhints
.decorations
= hints
[2];
735 void client_get_type(Client
*self
)
742 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
743 /* use the first value that we know about in the array */
744 for (i
= 0; i
< num
; ++i
) {
745 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
746 self
->type
= Type_Desktop
;
747 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
748 self
->type
= Type_Dock
;
749 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
750 self
->type
= Type_Toolbar
;
751 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
752 self
->type
= Type_Menu
;
753 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
754 self
->type
= Type_Utility
;
755 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
756 self
->type
= Type_Splash
;
757 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
758 self
->type
= Type_Dialog
;
759 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
760 self
->type
= Type_Normal
;
761 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
762 /* prevent this window from getting any decor or
764 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
765 MwmFlag_Decorations
);
766 self
->mwmhints
.decorations
= 0;
767 self
->mwmhints
.functions
= 0;
769 if (self
->type
!= (WindowType
) -1)
770 break; /* grab the first legit type */
775 if (self
->type
== (WindowType
) -1) {
776 /*the window type hint was not set, which means we either classify
777 ourself as a normal window or a dialog, depending on if we are a
780 self
->type
= Type_Dialog
;
782 self
->type
= Type_Normal
;
785 /* this makes sure that these windows appear on all desktops */
786 if (self
->type
== Type_Desktop
)
787 self
->desktop
= DESKTOP_ALL
;
790 void client_update_protocols(Client
*self
)
795 self
->focus_notify
= FALSE
;
796 self
->delete_window
= FALSE
;
798 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
799 for (i
= 0; i
< num_return
; ++i
) {
800 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
801 /* this means we can request the window to close */
802 self
->delete_window
= TRUE
;
803 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
804 /* if this protocol is requested, then the window will be
805 notified whenever we want it to receive focus */
806 self
->focus_notify
= TRUE
;
812 static void client_get_gravity(Client
*self
)
814 XWindowAttributes wattrib
;
817 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
818 g_assert(ret
!= BadWindow
);
819 self
->gravity
= wattrib
.win_gravity
;
822 void client_update_normal_hints(Client
*self
)
826 int oldgravity
= self
->gravity
;
829 self
->min_ratio
= 0.0f
;
830 self
->max_ratio
= 0.0f
;
831 SIZE_SET(self
->size_inc
, 1, 1);
832 SIZE_SET(self
->base_size
, 0, 0);
833 SIZE_SET(self
->min_size
, 0, 0);
834 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
836 /* get the hints from the window */
837 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
838 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
840 if (size
.flags
& PWinGravity
) {
841 self
->gravity
= size
.win_gravity
;
843 /* if the client has a frame, i.e. has already been mapped and
844 is changing its gravity */
845 if (self
->frame
&& self
->gravity
!= oldgravity
) {
846 /* move our idea of the client's position based on its new
848 self
->area
.x
= self
->frame
->area
.x
;
849 self
->area
.y
= self
->frame
->area
.y
;
850 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
854 if (size
.flags
& PAspect
) {
855 if (size
.min_aspect
.y
)
856 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
857 if (size
.max_aspect
.y
)
858 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
861 if (size
.flags
& PMinSize
)
862 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
864 if (size
.flags
& PMaxSize
)
865 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
867 if (size
.flags
& PBaseSize
)
868 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
870 if (size
.flags
& PResizeInc
)
871 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
875 void client_setup_decor_and_functions(Client
*self
)
877 /* start with everything (cept fullscreen) */
878 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
879 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
881 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
883 if (self
->delete_window
) {
884 self
->decorations
|= Decor_Close
;
885 self
->functions
|= Func_Close
;
888 if (!(self
->min_size
.width
< self
->max_size
.width
||
889 self
->min_size
.height
< self
->max_size
.height
)) {
890 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
891 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
894 switch (self
->type
) {
896 /* normal windows retain all of the possible decorations and
897 functionality, and are the only windows that you can fullscreen */
898 self
->functions
|= Func_Fullscreen
;
903 /* these windows cannot be maximized */
904 self
->decorations
&= ~Decor_Maximize
;
905 self
->functions
&= ~Func_Maximize
;
910 /* these windows get less functionality */
911 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
912 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
918 /* none of these windows are manipulated by the window manager */
919 self
->decorations
= 0;
924 /* Mwm Hints are applied subtractively to what has already been chosen for
925 decor and functionality */
926 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
927 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
928 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
929 self
->decorations
&= ~Decor_Border
;
930 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
931 self
->decorations
&= ~Decor_Handle
;
932 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
933 self
->decorations
&= ~Decor_Titlebar
;
934 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
935 self
->decorations
&= ~Decor_Iconify
;
936 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
937 self
->decorations
&= ~Decor_Maximize
;
941 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
942 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
943 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
944 self
->functions
&= ~Func_Resize
;
945 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
946 self
->functions
&= ~Func_Move
;
947 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
948 self
->functions
&= ~Func_Iconify
;
949 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
950 self
->functions
&= ~Func_Maximize
;
951 /* dont let mwm hints kill the close button
952 if (! (self->mwmhints.functions & MwmFunc_Close))
953 self->functions &= ~Func_Close; */
957 /* can't maximize without moving/resizing */
958 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
959 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
961 /* finally, user specified disabled decorations are applied to subtract
963 if (self
->disabled_decorations
& Decor_Titlebar
)
964 self
->decorations
&= ~Decor_Titlebar
;
965 if (self
->disabled_decorations
& Decor_Handle
)
966 self
->decorations
&= ~Decor_Handle
;
967 if (self
->disabled_decorations
& Decor_Border
)
968 self
->decorations
&= ~Decor_Border
;
969 if (self
->disabled_decorations
& Decor_Iconify
)
970 self
->decorations
&= ~Decor_Iconify
;
971 if (self
->disabled_decorations
& Decor_Maximize
)
972 self
->decorations
&= ~Decor_Maximize
;
973 if (self
->disabled_decorations
& Decor_AllDesktops
)
974 self
->decorations
&= ~Decor_AllDesktops
;
975 if (self
->disabled_decorations
& Decor_Shade
)
976 self
->decorations
&= ~Decor_Shade
;
977 if (self
->disabled_decorations
& Decor_Close
)
978 self
->decorations
&= ~Decor_Close
;
980 /* if we don't have a titlebar, then we cannot shade! */
981 if (!(self
->decorations
& Decor_Titlebar
))
982 self
->functions
&= ~Func_Shade
;
984 /* now we need to check against rules for the client's current state */
985 if (self
->fullscreen
) {
986 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
987 self
->decorations
= 0;
990 client_change_allowed_actions(self
);
993 /* change the decors on the frame, and with more/less decorations,
994 we may also need to be repositioned */
995 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
996 /* with new decor, the window's maximized size may change */
997 client_remaximize(self
);
1001 static void client_change_allowed_actions(Client
*self
)
1006 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1008 if (self
->functions
& Func_Shade
)
1009 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1010 if (self
->functions
& Func_Close
)
1011 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1012 if (self
->functions
& Func_Move
)
1013 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1014 if (self
->functions
& Func_Iconify
)
1015 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1016 if (self
->functions
& Func_Resize
)
1017 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1018 if (self
->functions
& Func_Fullscreen
)
1019 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1020 if (self
->functions
& Func_Maximize
) {
1021 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1022 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1025 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1027 /* make sure the window isn't breaking any rules now */
1029 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1030 if (self
->frame
) client_shade(self
, FALSE
);
1031 else self
->shaded
= FALSE
;
1033 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1034 g_message("UNSETTING ICONIC");
1035 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1036 else self
->iconic
= FALSE
;
1038 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1039 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1040 else self
->fullscreen
= FALSE
;
1042 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1044 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1045 else self
->max_vert
= self
->max_horz
= FALSE
;
1049 void client_remaximize(Client
*self
)
1052 if (self
->max_horz
&& self
->max_vert
)
1054 else if (self
->max_horz
)
1056 else if (self
->max_vert
)
1059 return; /* not maximized */
1060 self
->max_horz
= self
->max_vert
= FALSE
;
1061 client_maximize(self
, TRUE
, dir
, FALSE
);
1064 void client_update_wmhints(Client
*self
)
1067 gboolean ur
= FALSE
;
1070 /* assume a window takes input if it doesnt specify */
1071 self
->can_focus
= TRUE
;
1073 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1074 if (hints
->flags
& InputHint
)
1075 self
->can_focus
= hints
->input
;
1077 /* only do this when first managing the window *AND* when we aren't
1079 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1080 if (hints
->flags
& StateHint
)
1081 self
->iconic
= hints
->initial_state
== IconicState
;
1083 if (hints
->flags
& XUrgencyHint
)
1086 if (!(hints
->flags
& WindowGroupHint
))
1087 hints
->window_group
= None
;
1089 /* did the group state change? */
1090 if (hints
->window_group
!=
1091 (self
->group
? self
->group
->leader
: None
)) {
1092 /* remove from the old group if there was one */
1093 if (self
->group
!= NULL
) {
1094 /* remove transients of the group */
1095 for (it
= self
->group
->members
; it
; it
= it
->next
)
1096 if (it
->data
!= self
&&
1097 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
) {
1098 self
->transients
= g_slist_remove(self
->transients
,
1101 group_remove(self
->group
, self
);
1104 if (hints
->window_group
!= None
) {
1105 self
->group
= group_add(hints
->window_group
, self
);
1107 /* add other transients of the group that are already
1109 for (it
= self
->group
->members
; it
; it
= it
->next
)
1110 if (it
->data
!= self
&&
1111 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1112 self
->transients
= g_slist_append(self
->transients
,
1116 /* because the self->transient flag wont change from this call,
1117 we don't need to update the window's type and such, only its
1118 transient_for, and the transients lists of other windows in
1119 the group may be affected */
1120 client_update_transient_for(self
);
1123 client_update_kwm_icon(self
);
1124 /* try get the kwm icon first, this is a fallback only */
1125 if (self
->pixmap_icon
== None
) {
1126 if (hints
->flags
& IconPixmapHint
) {
1127 if (self
->pixmap_icon
== None
) {
1128 self
->pixmap_icon
= hints
->icon_pixmap
;
1129 if (hints
->flags
& IconMaskHint
)
1130 self
->pixmap_icon_mask
= hints
->icon_mask
;
1132 self
->pixmap_icon_mask
= None
;
1135 frame_adjust_icon(self
->frame
);
1143 if (ur
!= self
->urgent
) {
1145 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1147 /* fire the urgent callback if we're mapped, otherwise, wait until
1148 after we're mapped */
1150 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1154 void client_update_title(Client
*self
)
1158 g_free(self
->title
);
1161 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1162 /* try old x stuff */
1163 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1164 data
= g_strdup("Unnamed Window");
1166 /* look for duplicates and append a number */
1168 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1173 frame_adjust_title(self
->frame
);
1176 void client_update_icon_title(Client
*self
)
1180 g_free(self
->icon_title
);
1183 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1184 /* try old x stuff */
1185 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
))
1186 data
= g_strdup("Unnamed Window");
1188 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1190 self
->icon_title
= data
;
1193 void client_update_class(Client
*self
)
1198 if (self
->name
) g_free(self
->name
);
1199 if (self
->class) g_free(self
->class);
1200 if (self
->role
) g_free(self
->role
);
1202 self
->name
= self
->class = self
->role
= NULL
;
1204 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1206 self
->name
= g_strdup(data
[0]);
1208 self
->class = g_strdup(data
[1]);
1213 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1214 self
->role
= g_strdup(s
);
1216 if (self
->name
== NULL
) self
->name
= g_strdup("");
1217 if (self
->class == NULL
) self
->class = g_strdup("");
1218 if (self
->role
== NULL
) self
->role
= g_strdup("");
1221 void client_update_strut(Client
*self
)
1226 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1227 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1230 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1232 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1236 /* updating here is pointless while we're being mapped cuz we're not in
1237 the client list yet */
1239 screen_update_struts();
1242 void client_update_icons(Client
*self
)
1249 for (j
= 0; j
< self
->nicons
; ++j
)
1250 g_free(self
->icons
[j
].data
);
1251 if (self
->nicons
> 0)
1252 g_free(self
->icons
);
1255 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1256 /* figure out how many valid icons are in here */
1258 while (num
- i
> 2) {
1266 self
->icons
= g_new(Icon
, self
->nicons
);
1268 /* store the icons */
1270 for (j
= 0; j
< self
->nicons
; ++j
) {
1271 w
= self
->icons
[j
].width
= data
[i
++];
1272 h
= self
->icons
[j
].height
= data
[i
++];
1273 self
->icons
[j
].data
=
1274 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1283 frame_adjust_icon(self
->frame
);
1286 void client_update_kwm_icon(Client
*self
)
1291 if (!PROP_GETA32(self
->window
, kwm_win_icon
, kwm_win_icon
, &data
, &num
)) {
1292 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1295 self
->pixmap_icon
= data
[0];
1296 self
->pixmap_icon_mask
= data
[1];
1298 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1302 frame_adjust_icon(self
->frame
);
1305 static void client_change_state(Client
*self
)
1308 guint32 netstate
[10];
1311 state
[0] = self
->wmstate
;
1313 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1317 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1319 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1321 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1322 if (self
->skip_taskbar
)
1323 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1324 if (self
->skip_pager
)
1325 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1326 if (self
->fullscreen
)
1327 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1329 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1331 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1333 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1335 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1336 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1338 client_calc_layer(self
);
1341 frame_adjust_state(self
->frame
);
1344 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1349 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1350 Client
*c
= it
->data
;
1351 if (c
== skip
) continue; /* circular? */
1352 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1353 if (client_focused(c
)) return c
;
1358 static void calc_recursive(Client
*self
, StackLayer l
, gboolean raised
)
1366 for (it
= self
->transients
; it
; it
= it
->next
)
1367 calc_recursive(it
->data
, l
, raised
? raised
: l
!= old
);
1369 if (!raised
&& l
!= old
)
1371 stacking_raise(self
);
1374 void client_calc_layer(Client
*self
)
1379 /* transients take on the layer of their parents */
1380 if (self
->transient_for
) {
1381 if (self
->transient_for
!= TRAN_GROUP
) {
1382 self
= self
->transient_for
;
1386 for (it
= self
->group
->members
; it
; it
= it
->next
)
1387 if (it
->data
!= self
&&
1388 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1395 /* is us or one of our transients focused? */
1396 if (client_focused(self
))
1398 else if (search_focus_tree(self
, self
))
1403 if (self
->iconic
) l
= Layer_Icon
;
1404 /* fullscreen windows are only in the fullscreen layer while focused */
1405 else if (self
->fullscreen
&& f
) l
= Layer_Fullscreen
;
1406 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1407 else if (self
->type
== Type_Dock
) {
1408 if (!self
->below
) l
= Layer_Top
;
1409 else l
= Layer_Normal
;
1411 else if (self
->above
) l
= Layer_Above
;
1412 else if (self
->below
) l
= Layer_Below
;
1413 else l
= Layer_Normal
;
1415 calc_recursive(self
, l
, FALSE
);
1418 gboolean
client_should_show(Client
*self
)
1420 if (self
->iconic
) return FALSE
;
1421 else if (!(self
->desktop
== screen_desktop
||
1422 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1423 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1428 static void client_showhide(Client
*self
)
1431 if (client_should_show(self
))
1432 frame_show(self
->frame
);
1434 frame_hide(self
->frame
);
1437 gboolean
client_normal(Client
*self
) {
1438 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1439 self
->type
== Type_Splash
);
1442 static void client_apply_startup_state(Client
*self
)
1444 /* these are in a carefully crafted order.. */
1447 self
->iconic
= FALSE
;
1448 client_iconify(self
, TRUE
, FALSE
);
1450 if (self
->fullscreen
) {
1451 self
->fullscreen
= FALSE
;
1452 client_fullscreen(self
, TRUE
, FALSE
);
1455 self
->shaded
= FALSE
;
1456 client_shade(self
, TRUE
);
1459 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1461 if (self
->max_vert
&& self
->max_horz
) {
1462 self
->max_vert
= self
->max_horz
= FALSE
;
1463 client_maximize(self
, TRUE
, 0, FALSE
);
1464 } else if (self
->max_vert
) {
1465 self
->max_vert
= FALSE
;
1466 client_maximize(self
, TRUE
, 2, FALSE
);
1467 } else if (self
->max_horz
) {
1468 self
->max_horz
= FALSE
;
1469 client_maximize(self
, TRUE
, 1, FALSE
);
1472 /* nothing to do for the other states:
1481 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1482 gboolean user
, gboolean final
)
1484 gboolean moved
= FALSE
, resized
= FALSE
;
1486 /* gets the frame's position */
1487 frame_client_gravity(self
->frame
, &x
, &y
);
1489 /* these positions are frame positions, not client positions */
1491 /* set the size and position if fullscreen */
1492 if (self
->fullscreen
) {
1495 w
= screen_physical_size
.width
;
1496 h
= screen_physical_size
.height
;
1497 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1499 /* set the size and position if maximized */
1500 if (self
->max_horz
) {
1501 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1502 w
= screen_area(self
->desktop
)->width
;
1504 if (self
->max_vert
) {
1505 y
= screen_area(self
->desktop
)->y
;
1506 h
= screen_area(self
->desktop
)->height
-
1507 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1511 /* gets the client's position */
1512 frame_frame_gravity(self
->frame
, &x
, &y
);
1514 /* these override the above states! if you cant move you can't move! */
1516 if (!(self
->functions
& Func_Move
)) {
1520 if (!(self
->functions
& Func_Resize
)) {
1521 w
= self
->area
.width
;
1522 h
= self
->area
.height
;
1526 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1527 w
-= self
->base_size
.width
;
1528 h
-= self
->base_size
.height
;
1531 /* for interactive resizing. have to move half an increment in each
1534 /* how far we are towards the next size inc */
1535 int mw
= w
% self
->size_inc
.width
;
1536 int mh
= h
% self
->size_inc
.height
;
1538 int aw
= self
->size_inc
.width
/ 2;
1539 int ah
= self
->size_inc
.height
/ 2;
1540 /* don't let us move into a new size increment */
1541 if (mw
+ aw
>= self
->size_inc
.width
)
1542 aw
= self
->size_inc
.width
- mw
- 1;
1543 if (mh
+ ah
>= self
->size_inc
.height
)
1544 ah
= self
->size_inc
.height
- mh
- 1;
1548 /* if this is a user-requested resize, then check against min/max
1549 sizes and aspect ratios */
1551 /* smaller than min size or bigger than max size? */
1552 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1553 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1554 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1555 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1557 /* adjust the height ot match the width for the aspect ratios */
1558 if (self
->min_ratio
)
1559 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1560 if (self
->max_ratio
)
1561 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1564 /* keep to the increments */
1565 w
/= self
->size_inc
.width
;
1566 h
/= self
->size_inc
.height
;
1568 /* you cannot resize to nothing */
1572 /* store the logical size */
1573 SIZE_SET(self
->logical_size
, w
, h
);
1575 w
*= self
->size_inc
.width
;
1576 h
*= self
->size_inc
.height
;
1578 w
+= self
->base_size
.width
;
1579 h
+= self
->base_size
.height
;
1583 case Corner_TopLeft
:
1585 case Corner_TopRight
:
1586 x
-= w
- self
->area
.width
;
1588 case Corner_BottomLeft
:
1589 y
-= h
- self
->area
.height
;
1591 case Corner_BottomRight
:
1592 x
-= w
- self
->area
.width
;
1593 y
-= h
- self
->area
.height
;
1597 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1598 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1600 RECT_SET(self
->area
, x
, y
, w
, h
);
1603 XResizeWindow(ob_display
, self
->window
, w
, h
);
1605 /* move/resize the frame to match the request */
1607 if (moved
|| resized
)
1608 frame_adjust_area(self
->frame
, moved
, resized
);
1610 if (!user
|| final
) {
1612 event
.type
= ConfigureNotify
;
1613 event
.xconfigure
.display
= ob_display
;
1614 event
.xconfigure
.event
= self
->window
;
1615 event
.xconfigure
.window
= self
->window
;
1617 /* root window coords with border in mind */
1618 event
.xconfigure
.x
= x
- self
->border_width
+
1619 self
->frame
->size
.left
;
1620 event
.xconfigure
.y
= y
- self
->border_width
+
1621 self
->frame
->size
.top
;
1623 event
.xconfigure
.width
= self
->area
.width
;
1624 event
.xconfigure
.height
= self
->area
.height
;
1625 event
.xconfigure
.border_width
= self
->border_width
;
1626 event
.xconfigure
.above
= self
->frame
->plate
;
1627 event
.xconfigure
.override_redirect
= FALSE
;
1628 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1629 FALSE
, StructureNotifyMask
, &event
);
1634 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1638 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1639 self
->fullscreen
== fs
) return; /* already done */
1641 self
->fullscreen
= fs
;
1642 client_change_state(self
); /* change the state hints on the client,
1643 and adjust out layer/stacking */
1647 guint32 dimensions
[4];
1648 dimensions
[0] = self
->area
.x
;
1649 dimensions
[1] = self
->area
.y
;
1650 dimensions
[2] = self
->area
.width
;
1651 dimensions
[3] = self
->area
.height
;
1653 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1657 /* these are not actually used cuz client_configure will set them
1658 as appropriate when the window is fullscreened */
1664 /* pick some fallbacks... */
1665 x
= screen_area(self
->desktop
)->x
+
1666 screen_area(self
->desktop
)->width
/ 4;
1667 y
= screen_area(self
->desktop
)->y
+
1668 screen_area(self
->desktop
)->height
/ 4;
1669 w
= screen_area(self
->desktop
)->width
/ 2;
1670 h
= screen_area(self
->desktop
)->height
/ 2;
1672 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1673 (guint32
**)&dimensions
, &num
)) {
1684 client_setup_decor_and_functions(self
);
1686 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1688 /* try focus us when we go into fullscreen mode */
1692 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1696 /* move up the transient chain as far as possible first if deiconifying */
1698 while (self
->transient_for
) {
1699 if (self
->transient_for
!= TRAN_GROUP
) {
1700 if (self
->transient_for
->iconic
== iconic
)
1702 self
= self
->transient_for
;
1706 /* the check for TRAN_GROUP is to prevent an infinate loop with
1707 2 transients of the same group at the head of the group's
1709 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1710 Client
*c
= it
->data
;
1712 if (c
!= self
&& c
->transient_for
->iconic
!= iconic
&&
1713 c
->transient_for
!= TRAN_GROUP
) {
1718 if (it
== NULL
) break;
1722 if (self
->iconic
== iconic
) return; /* nothing to do */
1724 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1727 self
->iconic
= iconic
;
1730 self
->wmstate
= IconicState
;
1731 self
->ignore_unmaps
++;
1732 /* we unmap the client itself so that we can get MapRequest events,
1733 and because the ICCCM tells us to! */
1734 XUnmapWindow(ob_display
, self
->window
);
1737 client_set_desktop(self
, screen_desktop
, FALSE
);
1738 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1739 XMapWindow(ob_display
, self
->window
);
1741 client_change_state(self
);
1742 client_showhide(self
);
1743 screen_update_struts();
1745 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1748 /* iconify all transients */
1749 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1750 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1753 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1757 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1758 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1760 /* check if already done */
1762 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1763 if (dir
== 1 && self
->max_horz
) return;
1764 if (dir
== 2 && self
->max_vert
) return;
1766 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1767 if (dir
== 1 && !self
->max_horz
) return;
1768 if (dir
== 2 && !self
->max_vert
) return;
1771 /* work with the frame's coords */
1772 x
= self
->frame
->area
.x
;
1773 y
= self
->frame
->area
.y
;
1774 w
= self
->area
.width
;
1775 h
= self
->area
.height
;
1779 gint32 dimensions
[4];
1788 /* get the property off the window and use it for the dimensions
1789 we are already maxed on */
1790 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1791 (guint32
**)&readdim
, &num
)) {
1793 if (self
->max_horz
) {
1794 dimensions
[0] = readdim
[0];
1795 dimensions
[2] = readdim
[2];
1797 if (self
->max_vert
) {
1798 dimensions
[1] = readdim
[1];
1799 dimensions
[3] = readdim
[3];
1805 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1806 (guint32
*)dimensions
, 4);
1812 /* pick some fallbacks... */
1813 if (dir
== 0 || dir
== 1) { /* horz */
1814 x
= screen_area(self
->desktop
)->x
+
1815 screen_area(self
->desktop
)->width
/ 4;
1816 w
= screen_area(self
->desktop
)->width
/ 2;
1818 if (dir
== 0 || dir
== 2) { /* vert */
1819 y
= screen_area(self
->desktop
)->y
+
1820 screen_area(self
->desktop
)->height
/ 4;
1821 h
= screen_area(self
->desktop
)->height
/ 2;
1824 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1825 (guint32
**)&dimensions
, &num
)) {
1827 if (dir
== 0 || dir
== 1) { /* horz */
1831 if (dir
== 0 || dir
== 2) { /* vert */
1840 if (dir
== 0 || dir
== 1) /* horz */
1841 self
->max_horz
= max
;
1842 if (dir
== 0 || dir
== 2) /* vert */
1843 self
->max_vert
= max
;
1845 if (!self
->max_horz
&& !self
->max_vert
)
1846 PROP_ERASE(self
->window
, openbox_premax
);
1848 client_change_state(self
); /* change the state hints on the client */
1850 /* figure out where the client should be going */
1851 frame_frame_gravity(self
->frame
, &x
, &y
);
1852 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1855 void client_shade(Client
*self
, gboolean shade
)
1857 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1858 self
->shaded
== shade
) return; /* already done */
1860 /* when we're iconic, don't change the wmstate */
1862 self
->wmstate
= shade
? IconicState
: NormalState
;
1863 self
->shaded
= shade
;
1864 client_change_state(self
);
1865 /* resize the frame to just the titlebar */
1866 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1869 void client_close(Client
*self
)
1873 if (!(self
->functions
& Func_Close
)) return;
1876 XXX: itd be cool to do timeouts and shit here for killing the client's
1878 like... if the window is around after 5 seconds, then the close button
1879 turns a nice red, and if this function is called again, the client is
1883 ce
.xclient
.type
= ClientMessage
;
1884 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1885 ce
.xclient
.display
= ob_display
;
1886 ce
.xclient
.window
= self
->window
;
1887 ce
.xclient
.format
= 32;
1888 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1889 ce
.xclient
.data
.l
[1] = event_lasttime
;
1890 ce
.xclient
.data
.l
[2] = 0l;
1891 ce
.xclient
.data
.l
[3] = 0l;
1892 ce
.xclient
.data
.l
[4] = 0l;
1893 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1896 void client_kill(Client
*self
)
1898 XKillClient(ob_display
, self
->window
);
1901 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1905 if (target
== self
->desktop
) return;
1907 g_message("Setting desktop %u", target
);
1909 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1911 old
= self
->desktop
;
1912 self
->desktop
= target
;
1913 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1914 /* the frame can display the current desktop state */
1915 frame_adjust_state(self
->frame
);
1916 /* 'move' the window to the new desktop */
1918 client_showhide(self
);
1919 /* raise if it was not already on the desktop */
1920 if (old
!= DESKTOP_ALL
)
1921 stacking_raise(self
);
1922 screen_update_struts();
1924 /* update the focus lists */
1925 if (old
== DESKTOP_ALL
) {
1926 for (i
= 0; i
< screen_num_desktops
; ++i
)
1927 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1929 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1930 if (target
== DESKTOP_ALL
) {
1931 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1932 if (config_focus_new
)
1933 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1935 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1938 if (config_focus_new
)
1939 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1941 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1944 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1947 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1952 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1953 Client
*c
= it
->data
;
1954 if (c
== skip
) continue; /* circular? */
1955 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1956 if (c
->modal
) return c
;
1961 Client
*client_find_modal_child(Client
*self
)
1963 return search_modal_tree(self
, self
);
1966 gboolean
client_validate(Client
*self
)
1970 XSync(ob_display
, FALSE
); /* get all events on the server */
1972 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1973 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1974 XPutBackEvent(ob_display
, &e
);
1981 void client_set_wm_state(Client
*self
, long state
)
1983 if (state
== self
->wmstate
) return; /* no change */
1987 client_iconify(self
, TRUE
, TRUE
);
1990 client_iconify(self
, FALSE
, TRUE
);
1995 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1997 gboolean shaded
= self
->shaded
;
1998 gboolean fullscreen
= self
->fullscreen
;
1999 gboolean max_horz
= self
->max_horz
;
2000 gboolean max_vert
= self
->max_vert
;
2003 if (!(action
== prop_atoms
.net_wm_state_add
||
2004 action
== prop_atoms
.net_wm_state_remove
||
2005 action
== prop_atoms
.net_wm_state_toggle
))
2006 /* an invalid action was passed to the client message, ignore it */
2009 for (i
= 0; i
< 2; ++i
) {
2010 Atom state
= i
== 0 ? data1
: data2
;
2012 if (!state
) continue;
2014 /* if toggling, then pick whether we're adding or removing */
2015 if (action
== prop_atoms
.net_wm_state_toggle
) {
2016 if (state
== prop_atoms
.net_wm_state_modal
)
2017 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2018 prop_atoms
.net_wm_state_add
;
2019 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2020 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2021 prop_atoms
.net_wm_state_add
;
2022 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2023 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2024 prop_atoms
.net_wm_state_add
;
2025 else if (state
== prop_atoms
.net_wm_state_shaded
)
2026 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2027 prop_atoms
.net_wm_state_add
;
2028 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2029 action
= self
->skip_taskbar
?
2030 prop_atoms
.net_wm_state_remove
:
2031 prop_atoms
.net_wm_state_add
;
2032 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2033 action
= self
->skip_pager
?
2034 prop_atoms
.net_wm_state_remove
:
2035 prop_atoms
.net_wm_state_add
;
2036 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2037 action
= self
->fullscreen
?
2038 prop_atoms
.net_wm_state_remove
:
2039 prop_atoms
.net_wm_state_add
;
2040 else if (state
== prop_atoms
.net_wm_state_above
)
2041 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2042 prop_atoms
.net_wm_state_add
;
2043 else if (state
== prop_atoms
.net_wm_state_below
)
2044 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2045 prop_atoms
.net_wm_state_add
;
2048 if (action
== prop_atoms
.net_wm_state_add
) {
2049 if (state
== prop_atoms
.net_wm_state_modal
) {
2050 /* XXX raise here or something? */
2052 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2054 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2056 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2058 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2059 self
->skip_taskbar
= TRUE
;
2060 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2061 self
->skip_pager
= TRUE
;
2062 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2064 } else if (state
== prop_atoms
.net_wm_state_above
) {
2066 } else if (state
== prop_atoms
.net_wm_state_below
) {
2070 } else { /* action == prop_atoms.net_wm_state_remove */
2071 if (state
== prop_atoms
.net_wm_state_modal
) {
2072 self
->modal
= FALSE
;
2073 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2075 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2077 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2079 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2080 self
->skip_taskbar
= FALSE
;
2081 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2082 self
->skip_pager
= FALSE
;
2083 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2085 } else if (state
== prop_atoms
.net_wm_state_above
) {
2086 self
->above
= FALSE
;
2087 } else if (state
== prop_atoms
.net_wm_state_below
) {
2088 self
->below
= FALSE
;
2092 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2093 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2095 if (max_horz
== max_vert
) { /* both going the same way */
2096 client_maximize(self
, max_horz
, 0, TRUE
);
2098 client_maximize(self
, max_horz
, 1, TRUE
);
2099 client_maximize(self
, max_vert
, 2, TRUE
);
2103 if (max_horz
!= self
->max_horz
)
2104 client_maximize(self
, max_horz
, 1, TRUE
);
2106 client_maximize(self
, max_vert
, 2, TRUE
);
2109 /* change fullscreen state before shading, as it will affect if the window
2111 if (fullscreen
!= self
->fullscreen
)
2112 client_fullscreen(self
, fullscreen
, TRUE
);
2113 if (shaded
!= self
->shaded
)
2114 client_shade(self
, shaded
);
2115 client_calc_layer(self
);
2116 client_change_state(self
); /* change the hint to relect these changes */
2119 Client
*client_focus_target(Client
*self
)
2123 /* if we have a modal child, then focus it, not us */
2124 child
= client_find_modal_child(self
);
2125 if (child
) return child
;
2129 gboolean
client_focusable(Client
*self
)
2131 /* won't try focus if the client doesn't want it, or if the window isn't
2132 visible on the screen */
2133 return self
->frame
->visible
&&
2134 (self
->can_focus
|| self
->focus_notify
);
2137 gboolean
client_focus(Client
*self
)
2142 /* choose the correct target */
2143 self
= client_focus_target(self
);
2145 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2146 /* update the focus lists */
2147 if (self
->desktop
== DESKTOP_ALL
) {
2148 for (i
= 0; i
< screen_num_desktops
; ++i
) {
2149 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
2150 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
2154 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
2155 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
2160 if (!client_focusable(self
))
2163 /* do a check to see if the window has already been unmapped or destroyed
2164 do this intelligently while watching out for unmaps we've generated
2165 (ignore_unmaps > 0) */
2166 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2167 DestroyNotify
, &ev
)) {
2168 XPutBackEvent(ob_display
, &ev
);
2171 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2172 UnmapNotify
, &ev
)) {
2173 if (self
->ignore_unmaps
) {
2174 self
->ignore_unmaps
--;
2176 XPutBackEvent(ob_display
, &ev
);
2181 if (self
->can_focus
)
2182 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2183 I choose to use it always, hopefully to find errors quicker, if any
2184 are left. (I hate X. I hate focus events.) */
2185 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2188 if (self
->focus_notify
) {
2190 ce
.xclient
.type
= ClientMessage
;
2191 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2192 ce
.xclient
.display
= ob_display
;
2193 ce
.xclient
.window
= self
->window
;
2194 ce
.xclient
.format
= 32;
2195 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2196 ce
.xclient
.data
.l
[1] = event_lasttime
;
2197 ce
.xclient
.data
.l
[2] = 0l;
2198 ce
.xclient
.data
.l
[3] = 0l;
2199 ce
.xclient
.data
.l
[4] = 0l;
2200 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2204 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2209 /* Cause the FocusIn to come back to us. Important for desktop switches,
2210 since otherwise we'll have no FocusIn on the queue and send it off to
2211 the focus_backup. */
2212 XSync(ob_display
, FALSE
);
2216 void client_unfocus(Client
*self
)
2218 g_assert(focus_client
== self
);
2220 g_message("client_unfocus for %lx", self
->window
);
2222 focus_fallback(Fallback_Unfocusing
);
2225 gboolean
client_focused(Client
*self
)
2227 return self
== focus_client
;
2230 Icon
*client_icon(Client
*self
, int w
, int h
)
2233 /* si is the smallest image >= req */
2234 /* li is the largest image < req */
2235 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2237 if (!self
->nicons
) return NULL
;
2239 for (i
= 0; i
< self
->nicons
; ++i
) {
2240 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2241 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2245 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2250 if (largest
== 0) /* didnt find one smaller than the requested size */
2251 return &self
->icons
[si
];
2252 return &self
->icons
[li
];