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; */
158 /* check if it has already been unmapped by the time we started mapping
159 the grab does a sync so we don't have to here */
160 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
161 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
162 XPutBackEvent(ob_display
, &e
);
165 return; /* don't manage it */
168 /* make sure it isn't an override-redirect window */
169 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
170 attrib
.override_redirect
) {
172 return; /* don't manage it */
175 /* /\* is the window a docking app *\/
176 if ((wmhint = XGetWMHints(ob_display, window))) {
177 if ((wmhint->flags & StateHint) &&
178 wmhint->initial_state == WithdrawnState) {
179 /\* XXX: make dock apps work! *\/
187 g_message("Managing window: %lx", window
);
189 /* choose the events we want to receive on the CLIENT window */
190 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
191 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
192 XChangeWindowAttributes(ob_display
, window
,
193 CWEventMask
|CWDontPropagate
, &attrib_set
);
196 /* create the Client struct, and populate it from the hints on the
198 self
= g_new(Client
, 1);
199 self
->window
= window
;
200 client_get_all(self
);
202 /* remove the client's border (and adjust re gravity) */
203 client_toggle_border(self
, FALSE
);
205 /* specify that if we exit, the window should not be destroyed and should
206 be reparented back to root automatically */
207 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
209 /* create the decoration frame for the client window */
210 self
->frame
= frame_new();
212 frame_grab_client(self
->frame
, self
);
214 client_apply_startup_state(self
);
218 client_list
= g_list_append(client_list
, self
);
219 stacking_list
= g_list_append(stacking_list
, self
);
220 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
221 g_hash_table_insert(client_map
, &self
->window
, self
);
223 /* update the focus lists */
224 focus_order_add_new(self
);
226 stacking_raise(self
);
228 screen_update_struts();
230 dispatch_client(Event_Client_New
, self
, 0, 0);
232 client_showhide(self
);
234 /* focus the new window? */
235 if (ob_state
!= State_Starting
) {
237 gboolean group_foc
= FALSE
;
244 for (it
= self
->group
->members
; it
; it
= it
->next
)
245 if (client_focused(it
->data
)) {
250 if (!group_foc
&& self
->transient_for
) {
251 if (self
->transient_for
!= TRAN_GROUP
) {/* transient of a window */
252 parent
= self
->transient_for
;
253 } else { /* transient of a group */
256 for (it
= self
->group
->members
; it
; it
= it
->next
)
257 if (it
->data
!= self
&&
258 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
)
262 /* note the check against Type_Normal, not client_normal(self), which
263 would also include dialog types. in this case we want more strict
265 if ((config_focus_new
&&
266 (self
->type
== Type_Normal
||
267 (self
->type
== Type_Dialog
&&
269 (!parent
&& (!self
->group
||
270 !self
->group
->members
->next
)))))) ||
271 (parent
&& (client_focused(parent
) ||
272 search_focus_tree(parent
, parent
)))) {
277 /* update the list hints */
280 /* make sure the window is visible */
281 client_move_onscreen(self
);
283 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
285 g_message("Managed window 0x%lx", window
);
288 void client_unmanage_all()
290 while (client_list
!= NULL
)
291 client_unmanage(client_list
->data
);
294 void client_unmanage(Client
*self
)
299 g_message("Unmanaging window: %lx", self
->window
);
301 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
302 g_assert(self
!= NULL
);
304 /* remove the window from our save set */
305 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
307 /* we dont want events no more */
308 XSelectInput(ob_display
, self
->window
, NoEventMask
);
310 frame_hide(self
->frame
);
312 client_list
= g_list_remove(client_list
, self
);
313 stacking_list
= g_list_remove(stacking_list
, self
);
314 g_hash_table_remove(client_map
, &self
->window
);
316 /* update the focus lists */
317 focus_order_remove(self
);
319 /* once the client is out of the list, update the struts to remove it's
321 screen_update_struts();
323 /* tell our parent(s) that we're gone */
324 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
327 for (it
= self
->group
->members
; it
; it
= it
->next
)
328 if (it
->data
!= self
)
329 ((Client
*)it
->data
)->transients
=
330 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
331 } else if (self
->transient_for
) { /* transient of window */
332 self
->transient_for
->transients
=
333 g_slist_remove(self
->transient_for
->transients
, self
);
336 /* tell our transients that we're gone */
337 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
338 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
339 ((Client
*)it
->data
)->transient_for
= NULL
;
340 client_calc_layer(it
->data
);
344 if (moveresize_client
== self
)
345 moveresize_end(TRUE
);
347 if (focus_client
== self
) {
350 /* focus the last focused window on the desktop, and ignore enter
351 events from the unmap so it doesnt mess with the focus */
352 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
353 client_unfocus(self
);
356 /* remove from its group */
358 group_remove(self
->group
, self
);
362 /* dispatch the unmapped event */
363 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
364 g_assert(self
!= NULL
);
366 /* give the client its border back */
367 client_toggle_border(self
, TRUE
);
369 /* reparent the window out of the frame, and free the frame */
370 frame_release_client(self
->frame
, self
);
373 if (ob_state
!= State_Exiting
) {
374 /* these values should not be persisted across a window
376 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
377 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
379 /* if we're left in an iconic state, the client wont be mapped. this is
380 bad, since we will no longer be managing the window on restart */
382 XMapWindow(ob_display
, self
->window
);
386 g_message("Unmanaged window 0x%lx", self
->window
);
388 /* free all data allocated in the client struct */
389 g_slist_free(self
->transients
);
390 for (j
= 0; j
< self
->nicons
; ++j
)
391 g_free(self
->icons
[j
].data
);
392 if (self
->nicons
> 0)
395 g_free(self
->icon_title
);
401 /* update the list hints */
405 static void client_move_onscreen(Client
*self
)
408 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
410 a
= screen_area(self
->desktop
);
411 if (x
>= a
->x
+ a
->width
- 1)
412 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
413 if (y
>= a
->y
+ a
->height
- 1)
414 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
415 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
417 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
420 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
422 client_configure(self
, Corner_TopLeft
, x
, y
,
423 self
->area
.width
, self
->area
.height
,
427 static void client_toggle_border(Client
*self
, gboolean show
)
429 /* adjust our idea of where the client is, based on its border. When the
430 border is removed, the client should now be considered to be in a
432 when re-adding the border to the client, the same operation needs to be
434 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
435 int x
= oldx
, y
= oldy
;
436 switch(self
->gravity
) {
438 case NorthWestGravity
:
440 case SouthWestGravity
:
442 case NorthEastGravity
:
444 case SouthEastGravity
:
445 if (show
) x
-= self
->border_width
* 2;
446 else x
+= self
->border_width
* 2;
453 if (show
) x
-= self
->border_width
;
454 else x
+= self
->border_width
;
457 switch(self
->gravity
) {
459 case NorthWestGravity
:
461 case NorthEastGravity
:
463 case SouthWestGravity
:
465 case SouthEastGravity
:
466 if (show
) y
-= self
->border_width
* 2;
467 else y
+= self
->border_width
* 2;
474 if (show
) y
-= self
->border_width
;
475 else y
+= self
->border_width
;
482 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
484 /* move the client so it is back it the right spot _with_ its
486 if (x
!= oldx
|| y
!= oldy
)
487 XMoveWindow(ob_display
, self
->window
, x
, y
);
489 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
493 static void client_get_all(Client
*self
)
495 /* update EVERYTHING!! */
497 self
->ignore_unmaps
= 0;
501 self
->title
= self
->icon_title
= NULL
;
502 self
->name
= self
->class = self
->role
= NULL
;
503 self
->wmstate
= NormalState
;
504 self
->transient
= FALSE
;
505 self
->transients
= NULL
;
506 self
->transient_for
= NULL
;
508 self
->urgent
= FALSE
;
509 self
->positioned
= FALSE
;
510 self
->disabled_decorations
= 0;
514 client_get_area(self
);
515 client_update_transient_for(self
);
516 client_update_wmhints(self
);
517 client_get_desktop(self
);
518 client_get_state(self
);
519 client_get_shaped(self
);
521 client_get_mwm_hints(self
);
522 client_get_type(self
);/* this can change the mwmhints for special cases */
524 client_update_protocols(self
);
526 client_get_gravity(self
); /* get the attribute gravity */
527 client_update_normal_hints(self
); /* this may override the attribute
530 /* got the type, the mwmhints, the protocols, and the normal hints
531 (min/max sizes), so we're ready to set up the decorations/functions */
532 client_setup_decor_and_functions(self
);
534 client_update_title(self
);
535 client_update_icon_title(self
);
536 client_update_class(self
);
537 client_update_strut(self
);
538 client_update_icons(self
);
539 client_update_kwm_icon(self
);
541 client_change_state(self
);
544 static void client_get_area(Client
*self
)
546 XWindowAttributes wattrib
;
549 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
550 g_assert(ret
!= BadWindow
);
552 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
553 self
->border_width
= wattrib
.border_width
;
556 static void client_get_desktop(Client
*self
)
560 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
561 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
562 d
= screen_num_desktops
- 1;
565 gboolean trdesk
= FALSE
;
567 if (self
->transient_for
) {
568 if (self
->transient_for
!= TRAN_GROUP
) {
569 self
->desktop
= self
->transient_for
->desktop
;
574 for (it
= self
->group
->members
; it
; it
= it
->next
)
575 if (it
->data
!= self
&&
576 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
577 self
->desktop
= ((Client
*)it
->data
)->desktop
;
584 /* defaults to the current desktop */
585 self
->desktop
= screen_desktop
;
587 /* set the desktop hint, to make sure that it always exists */
588 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
592 static void client_get_state(Client
*self
)
597 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
598 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
599 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
601 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
603 for (i
= 0; i
< num
; ++i
) {
604 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
606 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
608 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
610 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
611 self
->skip_taskbar
= TRUE
;
612 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
613 self
->skip_pager
= TRUE
;
614 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
615 self
->fullscreen
= TRUE
;
616 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
617 self
->max_vert
= TRUE
;
618 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
619 self
->max_horz
= TRUE
;
620 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
622 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
630 static void client_get_shaped(Client
*self
)
632 self
->shaped
= FALSE
;
634 if (extensions_shape
) {
639 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
641 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
642 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
644 self
->shaped
= (s
!= 0);
649 void client_update_transient_for(Client
*self
)
654 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
655 self
->transient
= TRUE
;
656 if (t
!= self
->window
) { /* cant be transient to itself! */
657 c
= g_hash_table_lookup(client_map
, &t
);
658 /* if this happens then we need to check for it*/
661 if (!c
&& self
->group
) {
662 /* not transient to a client, see if it is transient for a
664 if (t
== self
->group
->leader
||
667 /* window is a transient for its group! */
673 self
->transient
= FALSE
;
675 /* if anything has changed... */
676 if (c
!= self
->transient_for
) {
677 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
680 /* remove from old parents */
681 for (it
= self
->group
->members
; it
; it
= it
->next
)
682 if (it
->data
!= self
&&
683 (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
))
684 ((Client
*)it
->data
)->transients
=
685 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
686 } else if (self
->transient_for
!= NULL
) { /* transient of window */
687 /* remove from old parent */
688 self
->transient_for
->transients
=
689 g_slist_remove(self
->transient_for
->transients
, self
);
691 self
->transient_for
= c
;
692 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
695 /* add to new parents */
696 for (it
= self
->group
->members
; it
; it
= it
->next
)
697 if (it
->data
!= self
&&
698 (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
))
699 ((Client
*)it
->data
)->transients
=
700 g_slist_append(((Client
*)it
->data
)->transients
, self
);
702 /* remove all transients which are in the group, that causes
703 circlular pointer hell of doom */
704 for (it
= self
->group
->members
; it
; it
= it
->next
) {
706 for (sit
= self
->transients
; sit
; sit
= next
) {
708 if (sit
->data
== it
->data
)
709 self
->transients
= g_slist_remove(self
->transients
,
713 } else if (self
->transient_for
!= NULL
) { /* transient of window */
714 /* add to new parent */
715 self
->transient_for
->transients
=
716 g_slist_append(self
->transient_for
->transients
, self
);
721 static void client_get_mwm_hints(Client
*self
)
726 self
->mwmhints
.flags
= 0; /* default to none */
728 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
730 if (num
>= MWM_ELEMENTS
) {
731 self
->mwmhints
.flags
= hints
[0];
732 self
->mwmhints
.functions
= hints
[1];
733 self
->mwmhints
.decorations
= hints
[2];
739 void client_get_type(Client
*self
)
746 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
747 /* use the first value that we know about in the array */
748 for (i
= 0; i
< num
; ++i
) {
749 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
750 self
->type
= Type_Desktop
;
751 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
752 self
->type
= Type_Dock
;
753 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
754 self
->type
= Type_Toolbar
;
755 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
756 self
->type
= Type_Menu
;
757 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
758 self
->type
= Type_Utility
;
759 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
760 self
->type
= Type_Splash
;
761 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
762 self
->type
= Type_Dialog
;
763 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
764 self
->type
= Type_Normal
;
765 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
766 /* prevent this window from getting any decor or
768 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
769 MwmFlag_Decorations
);
770 self
->mwmhints
.decorations
= 0;
771 self
->mwmhints
.functions
= 0;
773 if (self
->type
!= (WindowType
) -1)
774 break; /* grab the first legit type */
779 if (self
->type
== (WindowType
) -1) {
780 /*the window type hint was not set, which means we either classify
781 ourself as a normal window or a dialog, depending on if we are a
784 self
->type
= Type_Dialog
;
786 self
->type
= Type_Normal
;
789 /* this makes sure that these windows appear on all desktops */
790 if (self
->type
== Type_Desktop
)
791 self
->desktop
= DESKTOP_ALL
;
794 void client_update_protocols(Client
*self
)
799 self
->focus_notify
= FALSE
;
800 self
->delete_window
= FALSE
;
802 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
803 for (i
= 0; i
< num_return
; ++i
) {
804 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
805 /* this means we can request the window to close */
806 self
->delete_window
= TRUE
;
807 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
808 /* if this protocol is requested, then the window will be
809 notified whenever we want it to receive focus */
810 self
->focus_notify
= TRUE
;
816 static void client_get_gravity(Client
*self
)
818 XWindowAttributes wattrib
;
821 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
822 g_assert(ret
!= BadWindow
);
823 self
->gravity
= wattrib
.win_gravity
;
826 void client_update_normal_hints(Client
*self
)
830 int oldgravity
= self
->gravity
;
833 self
->min_ratio
= 0.0f
;
834 self
->max_ratio
= 0.0f
;
835 SIZE_SET(self
->size_inc
, 1, 1);
836 SIZE_SET(self
->base_size
, 0, 0);
837 SIZE_SET(self
->min_size
, 0, 0);
838 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
840 /* get the hints from the window */
841 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
842 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
844 if (size
.flags
& PWinGravity
) {
845 self
->gravity
= size
.win_gravity
;
847 /* if the client has a frame, i.e. has already been mapped and
848 is changing its gravity */
849 if (self
->frame
&& self
->gravity
!= oldgravity
) {
850 /* move our idea of the client's position based on its new
852 self
->area
.x
= self
->frame
->area
.x
;
853 self
->area
.y
= self
->frame
->area
.y
;
854 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
858 if (size
.flags
& PAspect
) {
859 if (size
.min_aspect
.y
)
860 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
861 if (size
.max_aspect
.y
)
862 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
865 if (size
.flags
& PMinSize
)
866 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
868 if (size
.flags
& PMaxSize
)
869 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
871 if (size
.flags
& PBaseSize
)
872 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
874 if (size
.flags
& PResizeInc
)
875 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
879 void client_setup_decor_and_functions(Client
*self
)
881 /* start with everything (cept fullscreen) */
882 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
883 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
885 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
887 if (self
->delete_window
) {
888 self
->decorations
|= Decor_Close
;
889 self
->functions
|= Func_Close
;
892 if (!(self
->min_size
.width
< self
->max_size
.width
||
893 self
->min_size
.height
< self
->max_size
.height
)) {
894 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
895 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
898 switch (self
->type
) {
900 /* normal windows retain all of the possible decorations and
901 functionality, and are the only windows that you can fullscreen */
902 self
->functions
|= Func_Fullscreen
;
907 /* these windows cannot be maximized */
908 self
->decorations
&= ~Decor_Maximize
;
909 self
->functions
&= ~Func_Maximize
;
914 /* these windows get less functionality */
915 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
916 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
922 /* none of these windows are manipulated by the window manager */
923 self
->decorations
= 0;
928 /* Mwm Hints are applied subtractively to what has already been chosen for
929 decor and functionality */
930 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
931 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
932 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
933 self
->decorations
&= ~Decor_Border
;
934 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
935 self
->decorations
&= ~Decor_Handle
;
936 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
937 self
->decorations
&= ~Decor_Titlebar
;
938 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
939 self
->decorations
&= ~Decor_Iconify
;
940 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
941 self
->decorations
&= ~Decor_Maximize
;
945 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
946 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
947 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
948 self
->functions
&= ~Func_Resize
;
949 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
950 self
->functions
&= ~Func_Move
;
951 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
952 self
->functions
&= ~Func_Iconify
;
953 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
954 self
->functions
&= ~Func_Maximize
;
955 /* dont let mwm hints kill the close button
956 if (! (self->mwmhints.functions & MwmFunc_Close))
957 self->functions &= ~Func_Close; */
961 /* can't maximize without moving/resizing */
962 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
963 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
965 /* finally, user specified disabled decorations are applied to subtract
967 if (self
->disabled_decorations
& Decor_Titlebar
)
968 self
->decorations
&= ~Decor_Titlebar
;
969 if (self
->disabled_decorations
& Decor_Handle
)
970 self
->decorations
&= ~Decor_Handle
;
971 if (self
->disabled_decorations
& Decor_Border
)
972 self
->decorations
&= ~Decor_Border
;
973 if (self
->disabled_decorations
& Decor_Iconify
)
974 self
->decorations
&= ~Decor_Iconify
;
975 if (self
->disabled_decorations
& Decor_Maximize
)
976 self
->decorations
&= ~Decor_Maximize
;
977 if (self
->disabled_decorations
& Decor_AllDesktops
)
978 self
->decorations
&= ~Decor_AllDesktops
;
979 if (self
->disabled_decorations
& Decor_Shade
)
980 self
->decorations
&= ~Decor_Shade
;
981 if (self
->disabled_decorations
& Decor_Close
)
982 self
->decorations
&= ~Decor_Close
;
984 /* if we don't have a titlebar, then we cannot shade! */
985 if (!(self
->decorations
& Decor_Titlebar
))
986 self
->functions
&= ~Func_Shade
;
988 /* now we need to check against rules for the client's current state */
989 if (self
->fullscreen
) {
990 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
991 self
->decorations
= 0;
994 client_change_allowed_actions(self
);
997 /* change the decors on the frame, and with more/less decorations,
998 we may also need to be repositioned */
999 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
1000 /* with new decor, the window's maximized size may change */
1001 client_remaximize(self
);
1005 static void client_change_allowed_actions(Client
*self
)
1010 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1012 if (self
->functions
& Func_Shade
)
1013 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1014 if (self
->functions
& Func_Close
)
1015 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1016 if (self
->functions
& Func_Move
)
1017 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1018 if (self
->functions
& Func_Iconify
)
1019 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1020 if (self
->functions
& Func_Resize
)
1021 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1022 if (self
->functions
& Func_Fullscreen
)
1023 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1024 if (self
->functions
& Func_Maximize
) {
1025 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1026 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1029 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1031 /* make sure the window isn't breaking any rules now */
1033 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1034 if (self
->frame
) client_shade(self
, FALSE
);
1035 else self
->shaded
= FALSE
;
1037 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1038 g_message("UNSETTING ICONIC");
1039 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1040 else self
->iconic
= FALSE
;
1042 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1043 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1044 else self
->fullscreen
= FALSE
;
1046 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1048 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1049 else self
->max_vert
= self
->max_horz
= FALSE
;
1053 void client_remaximize(Client
*self
)
1056 if (self
->max_horz
&& self
->max_vert
)
1058 else if (self
->max_horz
)
1060 else if (self
->max_vert
)
1063 return; /* not maximized */
1064 self
->max_horz
= self
->max_vert
= FALSE
;
1065 client_maximize(self
, TRUE
, dir
, FALSE
);
1068 void client_update_wmhints(Client
*self
)
1071 gboolean ur
= FALSE
;
1074 /* assume a window takes input if it doesnt specify */
1075 self
->can_focus
= TRUE
;
1077 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1078 if (hints
->flags
& InputHint
)
1079 self
->can_focus
= hints
->input
;
1081 /* only do this when first managing the window *AND* when we aren't
1083 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1084 if (hints
->flags
& StateHint
)
1085 self
->iconic
= hints
->initial_state
== IconicState
;
1087 if (hints
->flags
& XUrgencyHint
)
1090 if (!(hints
->flags
& WindowGroupHint
))
1091 hints
->window_group
= None
;
1093 /* did the group state change? */
1094 if (hints
->window_group
!=
1095 (self
->group
? self
->group
->leader
: None
)) {
1096 /* remove from the old group if there was one */
1097 if (self
->group
!= NULL
) {
1098 /* remove transients of the group */
1099 for (it
= self
->group
->members
; it
; it
= it
->next
)
1100 if (it
->data
!= self
&&
1101 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
) {
1102 self
->transients
= g_slist_remove(self
->transients
,
1105 group_remove(self
->group
, self
);
1108 if (hints
->window_group
!= None
) {
1109 self
->group
= group_add(hints
->window_group
, self
);
1111 /* add other transients of the group that are already
1113 for (it
= self
->group
->members
; it
; it
= it
->next
)
1114 if (it
->data
!= self
&&
1115 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1116 self
->transients
= g_slist_append(self
->transients
,
1120 /* because the self->transient flag wont change from this call,
1121 we don't need to update the window's type and such, only its
1122 transient_for, and the transients lists of other windows in
1123 the group may be affected */
1124 client_update_transient_for(self
);
1127 client_update_kwm_icon(self
);
1128 /* try get the kwm icon first, this is a fallback only */
1129 if (self
->pixmap_icon
== None
) {
1130 if (hints
->flags
& IconPixmapHint
) {
1131 if (self
->pixmap_icon
== None
) {
1132 self
->pixmap_icon
= hints
->icon_pixmap
;
1133 if (hints
->flags
& IconMaskHint
)
1134 self
->pixmap_icon_mask
= hints
->icon_mask
;
1136 self
->pixmap_icon_mask
= None
;
1139 frame_adjust_icon(self
->frame
);
1147 if (ur
!= self
->urgent
) {
1149 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1151 /* fire the urgent callback if we're mapped, otherwise, wait until
1152 after we're mapped */
1154 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1158 void client_update_title(Client
*self
)
1162 g_free(self
->title
);
1165 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1166 /* try old x stuff */
1167 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1168 data
= g_strdup("Unnamed Window");
1170 /* look for duplicates and append a number */
1172 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1177 frame_adjust_title(self
->frame
);
1180 void client_update_icon_title(Client
*self
)
1184 g_free(self
->icon_title
);
1187 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1188 /* try old x stuff */
1189 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
))
1190 data
= g_strdup("Unnamed Window");
1192 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1194 self
->icon_title
= data
;
1197 void client_update_class(Client
*self
)
1202 if (self
->name
) g_free(self
->name
);
1203 if (self
->class) g_free(self
->class);
1204 if (self
->role
) g_free(self
->role
);
1206 self
->name
= self
->class = self
->role
= NULL
;
1208 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1210 self
->name
= g_strdup(data
[0]);
1212 self
->class = g_strdup(data
[1]);
1217 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1218 self
->role
= g_strdup(s
);
1220 if (self
->name
== NULL
) self
->name
= g_strdup("");
1221 if (self
->class == NULL
) self
->class = g_strdup("");
1222 if (self
->role
== NULL
) self
->role
= g_strdup("");
1225 void client_update_strut(Client
*self
)
1230 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1231 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1234 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1236 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1240 /* updating here is pointless while we're being mapped cuz we're not in
1241 the client list yet */
1243 screen_update_struts();
1246 void client_update_icons(Client
*self
)
1253 for (j
= 0; j
< self
->nicons
; ++j
)
1254 g_free(self
->icons
[j
].data
);
1255 if (self
->nicons
> 0)
1256 g_free(self
->icons
);
1259 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1260 /* figure out how many valid icons are in here */
1262 while (num
- i
> 2) {
1270 self
->icons
= g_new(Icon
, self
->nicons
);
1272 /* store the icons */
1274 for (j
= 0; j
< self
->nicons
; ++j
) {
1275 w
= self
->icons
[j
].width
= data
[i
++];
1276 h
= self
->icons
[j
].height
= data
[i
++];
1277 self
->icons
[j
].data
=
1278 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1287 frame_adjust_icon(self
->frame
);
1290 void client_update_kwm_icon(Client
*self
)
1295 if (!PROP_GETA32(self
->window
, kwm_win_icon
, kwm_win_icon
, &data
, &num
)) {
1296 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1299 self
->pixmap_icon
= data
[0];
1300 self
->pixmap_icon_mask
= data
[1];
1302 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1306 frame_adjust_icon(self
->frame
);
1309 static void client_change_state(Client
*self
)
1312 guint32 netstate
[10];
1315 state
[0] = self
->wmstate
;
1317 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1321 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1323 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1325 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1326 if (self
->skip_taskbar
)
1327 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1328 if (self
->skip_pager
)
1329 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1330 if (self
->fullscreen
)
1331 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1333 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1335 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1337 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1339 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1340 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1342 client_calc_layer(self
);
1345 frame_adjust_state(self
->frame
);
1348 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1353 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1354 Client
*c
= it
->data
;
1355 if (c
== skip
) continue; /* circular? */
1356 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1357 if (client_focused(c
)) return c
;
1362 static void calc_recursive(Client
*self
, StackLayer l
, gboolean raised
)
1370 for (it
= self
->transients
; it
; it
= it
->next
)
1371 calc_recursive(it
->data
, l
, raised
? raised
: l
!= old
);
1373 if (!raised
&& l
!= old
)
1375 stacking_raise(self
);
1378 void client_calc_layer(Client
*self
)
1383 /* transients take on the layer of their parents */
1384 if (self
->transient_for
) {
1385 if (self
->transient_for
!= TRAN_GROUP
) {
1386 self
= self
->transient_for
;
1390 for (it
= self
->group
->members
; it
; it
= it
->next
)
1391 if (it
->data
!= self
&&
1392 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1399 /* is us or one of our transients focused? */
1400 if (client_focused(self
))
1402 else if (search_focus_tree(self
, self
))
1407 if (self
->iconic
) l
= Layer_Icon
;
1408 /* fullscreen windows are only in the fullscreen layer while focused */
1409 else if (self
->fullscreen
&& f
) l
= Layer_Fullscreen
;
1410 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1411 else if (self
->type
== Type_Dock
) {
1412 if (!self
->below
) l
= Layer_Top
;
1413 else l
= Layer_Normal
;
1415 else if (self
->above
) l
= Layer_Above
;
1416 else if (self
->below
) l
= Layer_Below
;
1417 else l
= Layer_Normal
;
1419 calc_recursive(self
, l
, FALSE
);
1422 gboolean
client_should_show(Client
*self
)
1424 if (self
->iconic
) return FALSE
;
1425 else if (!(self
->desktop
== screen_desktop
||
1426 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1427 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1432 static void client_showhide(Client
*self
)
1435 if (client_should_show(self
))
1436 frame_show(self
->frame
);
1438 frame_hide(self
->frame
);
1441 gboolean
client_normal(Client
*self
) {
1442 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1443 self
->type
== Type_Splash
);
1446 static void client_apply_startup_state(Client
*self
)
1448 /* these are in a carefully crafted order.. */
1451 self
->iconic
= FALSE
;
1452 client_iconify(self
, TRUE
, FALSE
);
1454 if (self
->fullscreen
) {
1455 self
->fullscreen
= FALSE
;
1456 client_fullscreen(self
, TRUE
, FALSE
);
1459 self
->shaded
= FALSE
;
1460 client_shade(self
, TRUE
);
1463 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1465 if (self
->max_vert
&& self
->max_horz
) {
1466 self
->max_vert
= self
->max_horz
= FALSE
;
1467 client_maximize(self
, TRUE
, 0, FALSE
);
1468 } else if (self
->max_vert
) {
1469 self
->max_vert
= FALSE
;
1470 client_maximize(self
, TRUE
, 2, FALSE
);
1471 } else if (self
->max_horz
) {
1472 self
->max_horz
= FALSE
;
1473 client_maximize(self
, TRUE
, 1, FALSE
);
1476 /* nothing to do for the other states:
1485 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1486 gboolean user
, gboolean final
)
1488 gboolean moved
= FALSE
, resized
= FALSE
;
1490 /* gets the frame's position */
1491 frame_client_gravity(self
->frame
, &x
, &y
);
1493 /* these positions are frame positions, not client positions */
1495 /* set the size and position if fullscreen */
1496 if (self
->fullscreen
) {
1499 w
= screen_physical_size
.width
;
1500 h
= screen_physical_size
.height
;
1501 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1503 /* set the size and position if maximized */
1504 if (self
->max_horz
) {
1505 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1506 w
= screen_area(self
->desktop
)->width
;
1508 if (self
->max_vert
) {
1509 y
= screen_area(self
->desktop
)->y
;
1510 h
= screen_area(self
->desktop
)->height
-
1511 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1515 /* gets the client's position */
1516 frame_frame_gravity(self
->frame
, &x
, &y
);
1518 /* these override the above states! if you cant move you can't move! */
1520 if (!(self
->functions
& Func_Move
)) {
1524 if (!(self
->functions
& Func_Resize
)) {
1525 w
= self
->area
.width
;
1526 h
= self
->area
.height
;
1530 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1531 w
-= self
->base_size
.width
;
1532 h
-= self
->base_size
.height
;
1535 /* for interactive resizing. have to move half an increment in each
1538 /* how far we are towards the next size inc */
1539 int mw
= w
% self
->size_inc
.width
;
1540 int mh
= h
% self
->size_inc
.height
;
1542 int aw
= self
->size_inc
.width
/ 2;
1543 int ah
= self
->size_inc
.height
/ 2;
1544 /* don't let us move into a new size increment */
1545 if (mw
+ aw
>= self
->size_inc
.width
)
1546 aw
= self
->size_inc
.width
- mw
- 1;
1547 if (mh
+ ah
>= self
->size_inc
.height
)
1548 ah
= self
->size_inc
.height
- mh
- 1;
1552 /* if this is a user-requested resize, then check against min/max
1553 sizes and aspect ratios */
1555 /* smaller than min size or bigger than max size? */
1556 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1557 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1558 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1559 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1561 /* adjust the height ot match the width for the aspect ratios */
1562 if (self
->min_ratio
)
1563 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1564 if (self
->max_ratio
)
1565 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1568 /* keep to the increments */
1569 w
/= self
->size_inc
.width
;
1570 h
/= self
->size_inc
.height
;
1572 /* you cannot resize to nothing */
1576 /* store the logical size */
1577 SIZE_SET(self
->logical_size
, w
, h
);
1579 w
*= self
->size_inc
.width
;
1580 h
*= self
->size_inc
.height
;
1582 w
+= self
->base_size
.width
;
1583 h
+= self
->base_size
.height
;
1587 case Corner_TopLeft
:
1589 case Corner_TopRight
:
1590 x
-= w
- self
->area
.width
;
1592 case Corner_BottomLeft
:
1593 y
-= h
- self
->area
.height
;
1595 case Corner_BottomRight
:
1596 x
-= w
- self
->area
.width
;
1597 y
-= h
- self
->area
.height
;
1601 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1602 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1604 RECT_SET(self
->area
, x
, y
, w
, h
);
1607 XResizeWindow(ob_display
, self
->window
, w
, h
);
1609 /* move/resize the frame to match the request */
1611 if (moved
|| resized
)
1612 frame_adjust_area(self
->frame
, moved
, resized
);
1614 if (!user
|| final
) {
1616 event
.type
= ConfigureNotify
;
1617 event
.xconfigure
.display
= ob_display
;
1618 event
.xconfigure
.event
= self
->window
;
1619 event
.xconfigure
.window
= self
->window
;
1621 /* root window coords with border in mind */
1622 event
.xconfigure
.x
= x
- self
->border_width
+
1623 self
->frame
->size
.left
;
1624 event
.xconfigure
.y
= y
- self
->border_width
+
1625 self
->frame
->size
.top
;
1627 event
.xconfigure
.width
= self
->area
.width
;
1628 event
.xconfigure
.height
= self
->area
.height
;
1629 event
.xconfigure
.border_width
= self
->border_width
;
1630 event
.xconfigure
.above
= self
->frame
->plate
;
1631 event
.xconfigure
.override_redirect
= FALSE
;
1632 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1633 FALSE
, StructureNotifyMask
, &event
);
1638 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1642 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1643 self
->fullscreen
== fs
) return; /* already done */
1645 self
->fullscreen
= fs
;
1646 client_change_state(self
); /* change the state hints on the client,
1647 and adjust out layer/stacking */
1651 guint32 dimensions
[4];
1652 dimensions
[0] = self
->area
.x
;
1653 dimensions
[1] = self
->area
.y
;
1654 dimensions
[2] = self
->area
.width
;
1655 dimensions
[3] = self
->area
.height
;
1657 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1661 /* these are not actually used cuz client_configure will set them
1662 as appropriate when the window is fullscreened */
1668 /* pick some fallbacks... */
1669 x
= screen_area(self
->desktop
)->x
+
1670 screen_area(self
->desktop
)->width
/ 4;
1671 y
= screen_area(self
->desktop
)->y
+
1672 screen_area(self
->desktop
)->height
/ 4;
1673 w
= screen_area(self
->desktop
)->width
/ 2;
1674 h
= screen_area(self
->desktop
)->height
/ 2;
1676 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1677 (guint32
**)&dimensions
, &num
)) {
1688 client_setup_decor_and_functions(self
);
1690 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1692 /* try focus us when we go into fullscreen mode */
1696 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1700 /* move up the transient chain as far as possible first if deiconifying */
1702 while (self
->transient_for
) {
1703 if (self
->transient_for
!= TRAN_GROUP
) {
1704 if (self
->transient_for
->iconic
== iconic
)
1706 self
= self
->transient_for
;
1710 /* the check for TRAN_GROUP is to prevent an infinate loop with
1711 2 transients of the same group at the head of the group's
1713 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1714 Client
*c
= it
->data
;
1716 if (c
!= self
&& c
->transient_for
->iconic
!= iconic
&&
1717 c
->transient_for
!= TRAN_GROUP
) {
1722 if (it
== NULL
) break;
1726 if (self
->iconic
== iconic
) return; /* nothing to do */
1728 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1731 self
->iconic
= iconic
;
1734 self
->wmstate
= IconicState
;
1735 self
->ignore_unmaps
++;
1736 /* we unmap the client itself so that we can get MapRequest events,
1737 and because the ICCCM tells us to! */
1738 XUnmapWindow(ob_display
, self
->window
);
1740 /* update the focus lists.. iconic windows go to the bottom */
1741 focus_order_to_bottom(self
);
1744 client_set_desktop(self
, screen_desktop
, FALSE
);
1745 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1746 XMapWindow(ob_display
, self
->window
);
1748 client_change_state(self
);
1749 client_showhide(self
);
1750 screen_update_struts();
1752 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1755 /* iconify all transients */
1756 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1757 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1760 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1764 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1765 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1767 /* check if already done */
1769 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1770 if (dir
== 1 && self
->max_horz
) return;
1771 if (dir
== 2 && self
->max_vert
) return;
1773 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1774 if (dir
== 1 && !self
->max_horz
) return;
1775 if (dir
== 2 && !self
->max_vert
) return;
1778 /* work with the frame's coords */
1779 x
= self
->frame
->area
.x
;
1780 y
= self
->frame
->area
.y
;
1781 w
= self
->area
.width
;
1782 h
= self
->area
.height
;
1786 gint32 dimensions
[4];
1795 /* get the property off the window and use it for the dimensions
1796 we are already maxed on */
1797 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1798 (guint32
**)&readdim
, &num
)) {
1800 if (self
->max_horz
) {
1801 dimensions
[0] = readdim
[0];
1802 dimensions
[2] = readdim
[2];
1804 if (self
->max_vert
) {
1805 dimensions
[1] = readdim
[1];
1806 dimensions
[3] = readdim
[3];
1812 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1813 (guint32
*)dimensions
, 4);
1819 /* pick some fallbacks... */
1820 if (dir
== 0 || dir
== 1) { /* horz */
1821 x
= screen_area(self
->desktop
)->x
+
1822 screen_area(self
->desktop
)->width
/ 4;
1823 w
= screen_area(self
->desktop
)->width
/ 2;
1825 if (dir
== 0 || dir
== 2) { /* vert */
1826 y
= screen_area(self
->desktop
)->y
+
1827 screen_area(self
->desktop
)->height
/ 4;
1828 h
= screen_area(self
->desktop
)->height
/ 2;
1831 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1832 (guint32
**)&dimensions
, &num
)) {
1834 if (dir
== 0 || dir
== 1) { /* horz */
1838 if (dir
== 0 || dir
== 2) { /* vert */
1847 if (dir
== 0 || dir
== 1) /* horz */
1848 self
->max_horz
= max
;
1849 if (dir
== 0 || dir
== 2) /* vert */
1850 self
->max_vert
= max
;
1852 if (!self
->max_horz
&& !self
->max_vert
)
1853 PROP_ERASE(self
->window
, openbox_premax
);
1855 client_change_state(self
); /* change the state hints on the client */
1857 /* figure out where the client should be going */
1858 frame_frame_gravity(self
->frame
, &x
, &y
);
1859 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1862 void client_shade(Client
*self
, gboolean shade
)
1864 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1865 self
->shaded
== shade
) return; /* already done */
1867 /* when we're iconic, don't change the wmstate */
1869 self
->wmstate
= shade
? IconicState
: NormalState
;
1870 self
->shaded
= shade
;
1871 client_change_state(self
);
1872 /* resize the frame to just the titlebar */
1873 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1876 void client_close(Client
*self
)
1880 if (!(self
->functions
& Func_Close
)) return;
1883 XXX: itd be cool to do timeouts and shit here for killing the client's
1885 like... if the window is around after 5 seconds, then the close button
1886 turns a nice red, and if this function is called again, the client is
1890 ce
.xclient
.type
= ClientMessage
;
1891 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1892 ce
.xclient
.display
= ob_display
;
1893 ce
.xclient
.window
= self
->window
;
1894 ce
.xclient
.format
= 32;
1895 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1896 ce
.xclient
.data
.l
[1] = event_lasttime
;
1897 ce
.xclient
.data
.l
[2] = 0l;
1898 ce
.xclient
.data
.l
[3] = 0l;
1899 ce
.xclient
.data
.l
[4] = 0l;
1900 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1903 void client_kill(Client
*self
)
1905 XKillClient(ob_display
, self
->window
);
1908 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1912 if (target
== self
->desktop
) return;
1914 g_message("Setting desktop %u", target
);
1916 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1918 /* remove from the old desktop(s) */
1919 focus_order_remove(self
);
1921 old
= self
->desktop
;
1922 self
->desktop
= target
;
1923 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1924 /* the frame can display the current desktop state */
1925 frame_adjust_state(self
->frame
);
1926 /* 'move' the window to the new desktop */
1928 client_showhide(self
);
1929 /* raise if it was not already on the desktop */
1930 if (old
!= DESKTOP_ALL
)
1931 stacking_raise(self
);
1932 screen_update_struts();
1934 /* add to the new desktop(s) */
1935 if (config_focus_new
)
1936 focus_order_to_top(self
);
1938 focus_order_to_bottom(self
);
1940 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1943 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1948 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1949 Client
*c
= it
->data
;
1950 if (c
== skip
) continue; /* circular? */
1951 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1952 if (c
->modal
) return c
;
1957 Client
*client_find_modal_child(Client
*self
)
1959 return search_modal_tree(self
, self
);
1962 gboolean
client_validate(Client
*self
)
1966 XSync(ob_display
, FALSE
); /* get all events on the server */
1968 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1969 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1970 XPutBackEvent(ob_display
, &e
);
1977 void client_set_wm_state(Client
*self
, long state
)
1979 if (state
== self
->wmstate
) return; /* no change */
1983 client_iconify(self
, TRUE
, TRUE
);
1986 client_iconify(self
, FALSE
, TRUE
);
1991 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1993 gboolean shaded
= self
->shaded
;
1994 gboolean fullscreen
= self
->fullscreen
;
1995 gboolean max_horz
= self
->max_horz
;
1996 gboolean max_vert
= self
->max_vert
;
1999 if (!(action
== prop_atoms
.net_wm_state_add
||
2000 action
== prop_atoms
.net_wm_state_remove
||
2001 action
== prop_atoms
.net_wm_state_toggle
))
2002 /* an invalid action was passed to the client message, ignore it */
2005 for (i
= 0; i
< 2; ++i
) {
2006 Atom state
= i
== 0 ? data1
: data2
;
2008 if (!state
) continue;
2010 /* if toggling, then pick whether we're adding or removing */
2011 if (action
== prop_atoms
.net_wm_state_toggle
) {
2012 if (state
== prop_atoms
.net_wm_state_modal
)
2013 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2014 prop_atoms
.net_wm_state_add
;
2015 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2016 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2017 prop_atoms
.net_wm_state_add
;
2018 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2019 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2020 prop_atoms
.net_wm_state_add
;
2021 else if (state
== prop_atoms
.net_wm_state_shaded
)
2022 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2023 prop_atoms
.net_wm_state_add
;
2024 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2025 action
= self
->skip_taskbar
?
2026 prop_atoms
.net_wm_state_remove
:
2027 prop_atoms
.net_wm_state_add
;
2028 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2029 action
= self
->skip_pager
?
2030 prop_atoms
.net_wm_state_remove
:
2031 prop_atoms
.net_wm_state_add
;
2032 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2033 action
= self
->fullscreen
?
2034 prop_atoms
.net_wm_state_remove
:
2035 prop_atoms
.net_wm_state_add
;
2036 else if (state
== prop_atoms
.net_wm_state_above
)
2037 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2038 prop_atoms
.net_wm_state_add
;
2039 else if (state
== prop_atoms
.net_wm_state_below
)
2040 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2041 prop_atoms
.net_wm_state_add
;
2044 if (action
== prop_atoms
.net_wm_state_add
) {
2045 if (state
== prop_atoms
.net_wm_state_modal
) {
2046 /* XXX raise here or something? */
2048 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2050 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2052 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2054 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2055 self
->skip_taskbar
= TRUE
;
2056 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2057 self
->skip_pager
= TRUE
;
2058 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2060 } else if (state
== prop_atoms
.net_wm_state_above
) {
2062 } else if (state
== prop_atoms
.net_wm_state_below
) {
2066 } else { /* action == prop_atoms.net_wm_state_remove */
2067 if (state
== prop_atoms
.net_wm_state_modal
) {
2068 self
->modal
= FALSE
;
2069 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2071 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2073 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2075 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2076 self
->skip_taskbar
= FALSE
;
2077 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2078 self
->skip_pager
= FALSE
;
2079 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2081 } else if (state
== prop_atoms
.net_wm_state_above
) {
2082 self
->above
= FALSE
;
2083 } else if (state
== prop_atoms
.net_wm_state_below
) {
2084 self
->below
= FALSE
;
2088 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2089 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2091 if (max_horz
== max_vert
) { /* both going the same way */
2092 client_maximize(self
, max_horz
, 0, TRUE
);
2094 client_maximize(self
, max_horz
, 1, TRUE
);
2095 client_maximize(self
, max_vert
, 2, TRUE
);
2099 if (max_horz
!= self
->max_horz
)
2100 client_maximize(self
, max_horz
, 1, TRUE
);
2102 client_maximize(self
, max_vert
, 2, TRUE
);
2105 /* change fullscreen state before shading, as it will affect if the window
2107 if (fullscreen
!= self
->fullscreen
)
2108 client_fullscreen(self
, fullscreen
, TRUE
);
2109 if (shaded
!= self
->shaded
)
2110 client_shade(self
, shaded
);
2111 client_calc_layer(self
);
2112 client_change_state(self
); /* change the hint to relect these changes */
2115 Client
*client_focus_target(Client
*self
)
2119 /* if we have a modal child, then focus it, not us */
2120 child
= client_find_modal_child(self
);
2121 if (child
) return child
;
2125 gboolean
client_focus(Client
*self
)
2129 /* choose the correct target */
2130 self
= client_focus_target(self
);
2132 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2133 /* update the focus lists */
2134 focus_order_to_top(self
);
2138 if (!((self
->can_focus
|| self
->focus_notify
) &&
2139 (self
->desktop
== screen_desktop
||
2140 self
->desktop
== DESKTOP_ALL
) &&
2144 /* do a check to see if the window has already been unmapped or destroyed
2145 do this intelligently while watching out for unmaps we've generated
2146 (ignore_unmaps > 0) */
2147 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2148 DestroyNotify
, &ev
)) {
2149 XPutBackEvent(ob_display
, &ev
);
2152 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2153 UnmapNotify
, &ev
)) {
2154 if (self
->ignore_unmaps
) {
2155 self
->ignore_unmaps
--;
2157 XPutBackEvent(ob_display
, &ev
);
2162 if (self
->can_focus
)
2163 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2164 I choose to use it always, hopefully to find errors quicker, if any
2165 are left. (I hate X. I hate focus events.) */
2166 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2169 if (self
->focus_notify
) {
2171 ce
.xclient
.type
= ClientMessage
;
2172 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2173 ce
.xclient
.display
= ob_display
;
2174 ce
.xclient
.window
= self
->window
;
2175 ce
.xclient
.format
= 32;
2176 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2177 ce
.xclient
.data
.l
[1] = event_lasttime
;
2178 ce
.xclient
.data
.l
[2] = 0l;
2179 ce
.xclient
.data
.l
[3] = 0l;
2180 ce
.xclient
.data
.l
[4] = 0l;
2181 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2185 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2190 /* Cause the FocusIn to come back to us. Important for desktop switches,
2191 since otherwise we'll have no FocusIn on the queue and send it off to
2192 the focus_backup. */
2193 XSync(ob_display
, FALSE
);
2197 void client_unfocus(Client
*self
)
2199 g_assert(focus_client
== self
);
2201 g_message("client_unfocus for %lx", self
->window
);
2203 focus_fallback(Fallback_Unfocusing
);
2206 gboolean
client_focused(Client
*self
)
2208 return self
== focus_client
;
2211 Icon
*client_icon(Client
*self
, int w
, int h
)
2214 /* si is the smallest image >= req */
2215 /* li is the largest image < req */
2216 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2218 if (!self
->nicons
) return NULL
;
2220 for (i
= 0; i
< self
->nicons
; ++i
) {
2221 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2222 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2226 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2231 if (largest
== 0) /* didnt find one smaller than the requested size */
2232 return &self
->icons
[si
];
2233 return &self
->icons
[li
];