4 #include "extensions.h"
15 #include <X11/Xutil.h>
17 /*! The event mask to grab on client windows */
18 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
21 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
24 GList
*client_list
= NULL
;
25 GHashTable
*client_map
= NULL
;
27 static Window
*client_startup_stack_order
= NULL
;
28 static gulong client_startup_stack_size
= 0;
30 static void client_get_all(Client
*self
);
31 static void client_toggle_border(Client
*self
, gboolean show
);
32 static void client_get_area(Client
*self
);
33 static void client_get_desktop(Client
*self
);
34 static void client_get_state(Client
*self
);
35 static void client_get_shaped(Client
*self
);
36 static void client_get_mwm_hints(Client
*self
);
37 static void client_get_gravity(Client
*self
);
38 static void client_showhide(Client
*self
);
39 static void client_change_allowed_actions(Client
*self
);
40 static void client_change_state(Client
*self
);
41 static void client_move_onscreen(Client
*self
);
42 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
43 static void client_apply_startup_state(Client
*self
);
44 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
46 static guint
map_hash(Window
*w
) { return *w
; }
47 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
51 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
52 (GEqualFunc
)map_key_comp
);
54 /* save the stacking order on startup! */
55 PROP_GET32U(ob_root
, net_client_list_stacking
, window
,
56 client_startup_stack_order
, client_startup_stack_size
);
61 void client_shutdown()
63 g_hash_table_destroy(client_map
);
66 void client_set_list()
68 Window
*windows
, *win_it
;
70 guint size
= g_list_length(client_list
);
72 /* create an array of the window ids */
74 windows
= g_new(Window
, size
);
76 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
77 *win_it
= ((Client
*)it
->data
)->window
;
81 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
89 void client_manage_all()
91 unsigned int i
, j
, nchild
;
94 XWindowAttributes attrib
;
96 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
98 /* remove all icon windows from the list */
99 for (i
= 0; i
< nchild
; i
++) {
100 if (children
[i
] == None
) continue;
101 wmhints
= XGetWMHints(ob_display
, children
[i
]);
103 if ((wmhints
->flags
& IconWindowHint
) &&
104 (wmhints
->icon_window
!= children
[i
]))
105 for (j
= 0; j
< nchild
; j
++)
106 if (children
[j
] == wmhints
->icon_window
) {
114 for (i
= 0; i
< nchild
; ++i
) {
115 if (children
[i
] == None
)
117 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
118 if (attrib
.override_redirect
) continue;
120 if (attrib
.map_state
!= IsUnmapped
)
121 client_manage(children
[i
]);
126 /* stack them as they were on startup!
127 why with stacking_lower? Why, because then windows who aren't in the
128 stacking list are on the top where you can see them instead of buried
130 for (i
= client_startup_stack_size
; i
> 0; --i
) {
133 w
= client_startup_stack_order
[i
-1];
134 c
= g_hash_table_lookup(client_map
, &w
);
135 if (c
) stacking_lower(c
);
137 g_free(client_startup_stack_order
);
138 client_startup_stack_order
= NULL
;
139 client_startup_stack_size
= 0;
142 focus_fallback(Fallback_NoFocus
);
145 void client_manage(Window window
)
149 XWindowAttributes attrib
;
150 XSetWindowAttributes attrib_set
;
151 /* XWMHints *wmhint; */
156 /* check if it has already been unmapped by the time we started mapping
157 the grab does a sync so we don't have to here */
158 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
159 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
160 XPutBackEvent(ob_display
, &e
);
163 return; /* don't manage it */
166 /* make sure it isn't an override-redirect window */
167 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
168 attrib
.override_redirect
) {
170 return; /* don't manage it */
173 /* /\* is the window a docking app *\/
174 if ((wmhint = XGetWMHints(ob_display, window))) {
175 if ((wmhint->flags & StateHint) &&
176 wmhint->initial_state == WithdrawnState) {
177 /\* XXX: make dock apps work! *\/
185 g_message("Managing window: %lx", window
);
187 /* choose the events we want to receive on the CLIENT window */
188 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
189 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
190 XChangeWindowAttributes(ob_display
, window
,
191 CWEventMask
|CWDontPropagate
, &attrib_set
);
194 /* create the Client struct, and populate it from the hints on the
196 self
= g_new(Client
, 1);
197 self
->window
= window
;
198 client_get_all(self
);
200 /* remove the client's border (and adjust re gravity) */
201 client_toggle_border(self
, FALSE
);
203 /* specify that if we exit, the window should not be destroyed and should
204 be reparented back to root automatically */
205 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
207 /* create the decoration frame for the client window */
208 self
->frame
= engine_frame_new();
210 engine_frame_grab_client(self
->frame
, self
);
212 client_apply_startup_state(self
);
216 client_list
= g_list_append(client_list
, self
);
217 stacking_list
= g_list_append(stacking_list
, self
);
218 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
219 g_hash_table_insert(client_map
, &self
->window
, self
);
221 /* update the focus lists */
222 if (self
->desktop
== DESKTOP_ALL
) {
223 for (i
= 0; i
< screen_num_desktops
; ++i
)
224 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
227 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
230 stacking_raise(self
);
232 screen_update_struts();
234 dispatch_client(Event_Client_New
, self
, 0, 0);
236 client_showhide(self
);
238 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
240 if (ob_state
!= State_Starting
&& focus_new
)
243 /* update the list hints */
246 /* make sure the window is visible */
247 client_move_onscreen(self
);
249 g_message("Managed window 0x%lx", window
);
252 void client_unmanage_all()
254 while (client_list
!= NULL
)
255 client_unmanage(client_list
->data
);
258 void client_unmanage(Client
*self
)
264 g_message("Unmanaging window: %lx", self
->window
);
266 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
267 g_assert(self
!= NULL
);
269 /* remove the window from our save set */
270 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
272 /* we dont want events no more */
273 XSelectInput(ob_display
, self
->window
, NoEventMask
);
275 engine_frame_hide(self
->frame
);
277 client_list
= g_list_remove(client_list
, self
);
278 stacking_list
= g_list_remove(stacking_list
, self
);
279 g_hash_table_remove(client_map
, &self
->window
);
281 /* update the focus lists */
282 if (self
->desktop
== DESKTOP_ALL
) {
283 for (i
= 0; i
< screen_num_desktops
; ++i
)
284 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
287 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
290 /* once the client is out of the list, update the struts to remove it's
292 screen_update_struts();
294 /* tell our parent(s) that we're gone */
295 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
298 for (it
= self
->group
->members
; it
; it
= it
->next
)
299 if (it
->data
!= self
)
300 ((Client
*)it
->data
)->transients
=
301 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
302 } else if (self
->transient_for
) { /* transient of window */
303 self
->transient_for
->transients
=
304 g_slist_remove(self
->transient_for
->transients
, self
);
307 /* tell our transients that we're gone */
308 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
309 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
310 ((Client
*)it
->data
)->transient_for
= NULL
;
311 client_calc_layer(it
->data
);
315 if (focus_client
== self
)
316 client_unfocus(self
);
318 /* remove from its group */
320 group_remove(self
->group
, self
);
324 /* dispatch the unmapped event */
325 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
326 g_assert(self
!= NULL
);
328 /* give the client its border back */
329 client_toggle_border(self
, TRUE
);
331 /* reparent the window out of the frame, and free the frame */
332 engine_frame_release_client(self
->frame
, self
);
335 if (ob_state
!= State_Exiting
) {
336 /* these values should not be persisted across a window
338 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
339 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
341 /* if we're left in an iconic state, the client wont be mapped. this is
342 bad, since we will no longer be managing the window on restart */
344 XMapWindow(ob_display
, self
->window
);
347 g_message("Unmanaged window 0x%lx", self
->window
);
349 /* free all data allocated in the client struct */
350 g_slist_free(self
->transients
);
351 for (j
= 0; j
< self
->nicons
; ++j
)
352 g_free(self
->icons
[j
].data
);
353 if (self
->nicons
> 0)
356 g_free(self
->icon_title
);
362 /* update the list hints */
366 static void client_move_onscreen(Client
*self
)
369 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
371 a
= screen_area(self
->desktop
);
372 if (x
>= a
->x
+ a
->width
- 1)
373 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
374 if (y
>= a
->y
+ a
->height
- 1)
375 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
376 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
378 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
381 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
383 client_configure(self
, Corner_TopLeft
, x
, y
,
384 self
->area
.width
, self
->area
.height
,
388 static void client_toggle_border(Client
*self
, gboolean show
)
390 /* adjust our idea of where the client is, based on its border. When the
391 border is removed, the client should now be considered to be in a
393 when re-adding the border to the client, the same operation needs to be
395 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
396 int x
= oldx
, y
= oldy
;
397 switch(self
->gravity
) {
399 case NorthWestGravity
:
401 case SouthWestGravity
:
403 case NorthEastGravity
:
405 case SouthEastGravity
:
406 if (show
) x
-= self
->border_width
* 2;
407 else x
+= self
->border_width
* 2;
414 if (show
) x
-= self
->border_width
;
415 else x
+= self
->border_width
;
418 switch(self
->gravity
) {
420 case NorthWestGravity
:
422 case NorthEastGravity
:
424 case SouthWestGravity
:
426 case SouthEastGravity
:
427 if (show
) y
-= self
->border_width
* 2;
428 else y
+= self
->border_width
* 2;
435 if (show
) y
-= self
->border_width
;
436 else y
+= self
->border_width
;
443 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
445 /* move the client so it is back it the right spot _with_ its
447 if (x
!= oldx
|| y
!= oldy
)
448 XMoveWindow(ob_display
, self
->window
, x
, y
);
450 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
454 static void client_get_all(Client
*self
)
456 /* update EVERYTHING!! */
458 self
->ignore_unmaps
= 0;
462 self
->title
= self
->icon_title
= NULL
;
463 self
->name
= self
->class = self
->role
= NULL
;
464 self
->wmstate
= NormalState
;
465 self
->transient
= FALSE
;
466 self
->transients
= NULL
;
467 self
->transient_for
= NULL
;
469 self
->urgent
= FALSE
;
470 self
->positioned
= FALSE
;
471 self
->disabled_decorations
= 0;
475 client_get_area(self
);
476 client_get_desktop(self
);
477 client_get_state(self
);
478 client_get_shaped(self
);
480 client_update_transient_for(self
);
481 client_get_mwm_hints(self
);
482 client_get_type(self
);/* this can change the mwmhints for special cases */
484 client_update_protocols(self
);
486 client_get_gravity(self
); /* get the attribute gravity */
487 client_update_normal_hints(self
); /* this may override the attribute
490 /* got the type, the mwmhints, the protocols, and the normal hints
491 (min/max sizes), so we're ready to set up the decorations/functions */
492 client_setup_decor_and_functions(self
);
494 client_update_wmhints(self
);
495 client_update_title(self
);
496 client_update_icon_title(self
);
497 client_update_class(self
);
498 client_update_strut(self
);
499 client_update_icons(self
);
500 client_update_kwm_icon(self
);
502 /* this makes sure that these windows appear on all desktops */
503 if (self
->type
== Type_Desktop
)
504 self
->desktop
= DESKTOP_ALL
;
506 /* set the desktop hint, to make sure that it always exists, and to
507 reflect any changes we've made here */
508 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
510 client_change_state(self
);
513 static void client_get_area(Client
*self
)
515 XWindowAttributes wattrib
;
518 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
519 g_assert(ret
!= BadWindow
);
521 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
522 self
->border_width
= wattrib
.border_width
;
525 static void client_get_desktop(Client
*self
)
529 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
530 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
531 d
= screen_num_desktops
- 1;
534 /* defaults to the current desktop */
535 self
->desktop
= screen_desktop
;
539 static void client_get_state(Client
*self
)
544 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
545 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
546 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
548 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
550 for (i
= 0; i
< num
; ++i
) {
551 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
553 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
555 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
557 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
558 self
->skip_taskbar
= TRUE
;
559 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
560 self
->skip_pager
= TRUE
;
561 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
562 self
->fullscreen
= TRUE
;
563 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
564 self
->max_vert
= TRUE
;
565 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
566 self
->max_horz
= TRUE
;
567 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
569 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
577 static void client_get_shaped(Client
*self
)
579 self
->shaped
= FALSE
;
581 if (extensions_shape
) {
586 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
588 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
589 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
591 self
->shaped
= (s
!= 0);
596 void client_update_transient_for(Client
*self
)
601 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
602 t
!= self
->window
) { /* cant be transient to itself! */
603 self
->transient
= TRUE
;
604 c
= g_hash_table_lookup(client_map
, &t
);
605 g_assert(c
!= self
);/* if this happens then we need to check for it*/
607 if (!c
&& self
->group
) {
608 /* not transient to a client, see if it is transient for a
610 if (t
== self
->group
->leader
||
613 /* window is a transient for its group! */
618 self
->transient
= FALSE
;
620 /* if anything has changed... */
621 if (c
!= self
->transient_for
) {
622 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
625 /* remove from old parents */
626 for (it
= self
->group
->members
; it
; it
= it
->next
)
627 if (it
->data
!= self
)
628 ((Client
*)it
->data
)->transients
=
629 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
630 } else if (self
->transient_for
!= NULL
) { /* transient of window */
631 /* remove from old parent */
632 self
->transient_for
->transients
=
633 g_slist_remove(self
->transient_for
->transients
, self
);
635 self
->transient_for
= c
;
636 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
639 /* add to new parents */
640 for (it
= self
->group
->members
; it
; it
= it
->next
)
641 if (it
->data
!= self
)
642 ((Client
*)it
->data
)->transients
=
643 g_slist_append(((Client
*)it
->data
)->transients
, self
);
644 } else if (self
->transient_for
!= NULL
) { /* transient of window */
645 /* add to new parent */
646 self
->transient_for
->transients
=
647 g_slist_append(self
->transient_for
->transients
, self
);
652 static void client_get_mwm_hints(Client
*self
)
655 unsigned long *hints
;
657 self
->mwmhints
.flags
= 0; /* default to none */
659 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
660 if (num
>= MWM_ELEMENTS
) {
661 self
->mwmhints
.flags
= hints
[0];
662 self
->mwmhints
.functions
= hints
[1];
663 self
->mwmhints
.decorations
= hints
[2];
669 void client_get_type(Client
*self
)
675 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
676 /* use the first value that we know about in the array */
677 for (i
= 0; i
< num
; ++i
) {
678 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
679 self
->type
= Type_Desktop
;
680 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
681 self
->type
= Type_Dock
;
682 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
683 self
->type
= Type_Toolbar
;
684 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
685 self
->type
= Type_Menu
;
686 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
687 self
->type
= Type_Utility
;
688 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
689 self
->type
= Type_Splash
;
690 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
691 self
->type
= Type_Dialog
;
692 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
693 self
->type
= Type_Normal
;
694 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
695 /* prevent this window from getting any decor or
697 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
698 MwmFlag_Decorations
);
699 self
->mwmhints
.decorations
= 0;
700 self
->mwmhints
.functions
= 0;
702 if (self
->type
!= (WindowType
) -1)
703 break; /* grab the first legit type */
708 if (self
->type
== (WindowType
) -1) {
709 /*the window type hint was not set, which means we either classify
710 ourself as a normal window or a dialog, depending on if we are a
713 self
->type
= Type_Dialog
;
715 self
->type
= Type_Normal
;
719 void client_update_protocols(Client
*self
)
722 gulong num_return
, i
;
724 self
->focus_notify
= FALSE
;
725 self
->delete_window
= FALSE
;
727 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
728 for (i
= 0; i
< num_return
; ++i
) {
729 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
730 /* this means we can request the window to close */
731 self
->delete_window
= TRUE
;
732 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
733 /* if this protocol is requested, then the window will be
734 notified whenever we want it to receive focus */
735 self
->focus_notify
= TRUE
;
741 static void client_get_gravity(Client
*self
)
743 XWindowAttributes wattrib
;
746 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
747 g_assert(ret
!= BadWindow
);
748 self
->gravity
= wattrib
.win_gravity
;
751 void client_update_normal_hints(Client
*self
)
755 int oldgravity
= self
->gravity
;
758 self
->min_ratio
= 0.0f
;
759 self
->max_ratio
= 0.0f
;
760 SIZE_SET(self
->size_inc
, 1, 1);
761 SIZE_SET(self
->base_size
, 0, 0);
762 SIZE_SET(self
->min_size
, 0, 0);
763 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
765 /* get the hints from the window */
766 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
767 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
769 if (size
.flags
& PWinGravity
) {
770 self
->gravity
= size
.win_gravity
;
772 /* if the client has a frame, i.e. has already been mapped and
773 is changing its gravity */
774 if (self
->frame
&& self
->gravity
!= oldgravity
) {
775 /* move our idea of the client's position based on its new
777 self
->area
.x
= self
->frame
->area
.x
;
778 self
->area
.y
= self
->frame
->area
.y
;
779 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
783 if (size
.flags
& PAspect
) {
784 if (size
.min_aspect
.y
)
785 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
786 if (size
.max_aspect
.y
)
787 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
790 if (size
.flags
& PMinSize
)
791 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
793 if (size
.flags
& PMaxSize
)
794 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
796 if (size
.flags
& PBaseSize
)
797 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
799 if (size
.flags
& PResizeInc
)
800 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
804 void client_setup_decor_and_functions(Client
*self
)
806 /* start with everything (cept fullscreen) */
807 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
808 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
810 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
812 if (self
->delete_window
) {
813 self
->decorations
|= Decor_Close
;
814 self
->functions
|= Func_Close
;
817 if (!(self
->min_size
.width
< self
->max_size
.width
||
818 self
->min_size
.height
< self
->max_size
.height
)) {
819 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
820 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
823 switch (self
->type
) {
825 /* normal windows retain all of the possible decorations and
826 functionality, and are the only windows that you can fullscreen */
827 self
->functions
|= Func_Fullscreen
;
831 /* dialogs cannot be maximized */
832 self
->decorations
&= ~Decor_Maximize
;
833 self
->functions
&= ~Func_Maximize
;
839 /* these windows get less functionality */
840 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
841 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
847 /* none of these windows are manipulated by the window manager */
848 self
->decorations
= 0;
853 /* Mwm Hints are applied subtractively to what has already been chosen for
854 decor and functionality */
855 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
856 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
857 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
858 self
->decorations
&= ~Decor_Border
;
859 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
860 self
->decorations
&= ~Decor_Handle
;
861 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
862 self
->decorations
&= ~Decor_Titlebar
;
863 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
864 self
->decorations
&= ~Decor_Iconify
;
865 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
866 self
->decorations
&= ~Decor_Maximize
;
870 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
871 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
872 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
873 self
->functions
&= ~Func_Resize
;
874 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
875 self
->functions
&= ~Func_Move
;
876 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
877 self
->functions
&= ~Func_Iconify
;
878 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
879 self
->functions
&= ~Func_Maximize
;
880 /* dont let mwm hints kill the close button
881 if (! (self->mwmhints.functions & MwmFunc_Close))
882 self->functions &= ~Func_Close; */
886 /* can't maximize without moving/resizing */
887 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
888 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
890 /* finally, user specified disabled decorations are applied to subtract
892 if (self
->disabled_decorations
& Decor_Titlebar
)
893 self
->decorations
&= ~Decor_Titlebar
;
894 if (self
->disabled_decorations
& Decor_Handle
)
895 self
->decorations
&= ~Decor_Handle
;
896 if (self
->disabled_decorations
& Decor_Border
)
897 self
->decorations
&= ~Decor_Border
;
898 if (self
->disabled_decorations
& Decor_Iconify
)
899 self
->decorations
&= ~Decor_Iconify
;
900 if (self
->disabled_decorations
& Decor_Maximize
)
901 self
->decorations
&= ~Decor_Maximize
;
902 if (self
->disabled_decorations
& Decor_AllDesktops
)
903 self
->decorations
&= ~Decor_AllDesktops
;
904 if (self
->disabled_decorations
& Decor_Shade
)
905 self
->decorations
&= ~Decor_Shade
;
906 if (self
->disabled_decorations
& Decor_Close
)
907 self
->decorations
&= ~Decor_Close
;
909 /* if we don't have a titlebar, then we cannot shade! */
910 if (!(self
->decorations
& Decor_Titlebar
))
911 self
->functions
&= ~Func_Shade
;
913 client_change_allowed_actions(self
);
916 /* change the decors on the frame, and with more/less decorations,
917 we may also need to be repositioned */
918 engine_frame_adjust_area(self
->frame
, TRUE
, TRUE
);
919 /* with new decor, the window's maximized size may change */
920 client_remaximize(self
);
924 static void client_change_allowed_actions(Client
*self
)
929 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
931 if (self
->functions
& Func_Shade
)
932 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
933 if (self
->functions
& Func_Close
)
934 actions
[num
++] = prop_atoms
.net_wm_action_close
;
935 if (self
->functions
& Func_Move
)
936 actions
[num
++] = prop_atoms
.net_wm_action_move
;
937 if (self
->functions
& Func_Iconify
)
938 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
939 if (self
->functions
& Func_Resize
)
940 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
941 if (self
->functions
& Func_Fullscreen
)
942 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
943 if (self
->functions
& Func_Maximize
) {
944 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
945 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
948 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
950 /* make sure the window isn't breaking any rules now */
952 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
953 if (self
->frame
) client_shade(self
, FALSE
);
954 else self
->shaded
= FALSE
;
956 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
957 g_message("UNSETTING ICONIC");
958 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
959 else self
->iconic
= FALSE
;
961 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
962 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
963 else self
->fullscreen
= FALSE
;
965 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
967 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
968 else self
->max_vert
= self
->max_horz
= FALSE
;
972 void client_remaximize(Client
*self
)
975 if (self
->max_horz
&& self
->max_vert
)
977 else if (self
->max_horz
)
979 else if (self
->max_vert
)
982 return; /* not maximized */
983 self
->max_horz
= self
->max_vert
= FALSE
;
984 client_maximize(self
, TRUE
, dir
, FALSE
);
987 void client_update_wmhints(Client
*self
)
992 /* assume a window takes input if it doesnt specify */
993 self
->can_focus
= TRUE
;
995 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
996 if (hints
->flags
& InputHint
)
997 self
->can_focus
= hints
->input
;
999 /* only do this when first managing the window *AND* when we aren't
1001 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1002 if (hints
->flags
& StateHint
)
1003 self
->iconic
= hints
->initial_state
== IconicState
;
1005 if (hints
->flags
& XUrgencyHint
)
1008 if (!(hints
->flags
& WindowGroupHint
))
1009 hints
->window_group
= None
; /* no group */
1010 /* did the group state change? */
1011 if (hints
->window_group
!= (self
->group
? self
->group
->leader
: None
)){
1012 /* remove from the old group if there was one */
1013 if (self
->group
!= NULL
)
1014 group_remove(self
->group
, self
);
1015 if (hints
->window_group
!= None
)
1016 self
->group
= group_add(hints
->window_group
, self
);
1018 /* because the self->transient flag wont change from this call,
1019 we don't need to update the window's type and such, only its
1020 transient_for, and the transients lists of other windows in the
1021 group may be affected */
1022 client_update_transient_for(self
);
1025 if (hints
->flags
& IconPixmapHint
) {
1026 client_update_kwm_icon(self
);
1027 /* try get the kwm icon first, this is a fallback only */
1028 if (self
->pixmap_icon
== None
) {
1029 self
->pixmap_icon
= hints
->icon_pixmap
;
1030 if (hints
->flags
& IconMaskHint
)
1031 self
->pixmap_icon_mask
= hints
->icon_mask
;
1033 self
->pixmap_icon_mask
= None
;
1036 engine_frame_adjust_icon(self
->frame
);
1043 if (ur
!= self
->urgent
) {
1045 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1047 /* fire the urgent callback if we're mapped, otherwise, wait until
1048 after we're mapped */
1050 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1054 void client_update_title(Client
*self
)
1058 g_free(self
->title
);
1061 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
1062 /* try old x stuff */
1063 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
1064 /* convert it to UTF-8 */
1068 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1070 g_warning("Unable to convert string to UTF-8");
1077 data
= g_strdup("Unnamed Window");
1079 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1085 engine_frame_adjust_title(self
->frame
);
1088 void client_update_icon_title(Client
*self
)
1092 g_free(self
->icon_title
);
1095 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1096 /* try old x stuff */
1097 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1098 /* convert it to UTF-8 */
1102 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1104 g_warning("Unable to convert string to UTF-8");
1111 data
= g_strdup("Unnamed Window");
1113 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1116 self
->icon_title
= data
;
1119 void client_update_class(Client
*self
)
1125 if (self
->name
) g_free(self
->name
);
1126 if (self
->class) g_free(self
->class);
1127 if (self
->role
) g_free(self
->role
);
1129 self
->name
= self
->class = self
->role
= NULL
;
1131 data
= g_ptr_array_new();
1133 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1135 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1137 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1140 for (i
= 0; i
< data
->len
; ++i
)
1141 g_free(g_ptr_array_index(data
, i
));
1142 g_ptr_array_free(data
, TRUE
);
1144 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1145 self
->role
= g_strdup(s
);
1147 if (self
->name
== NULL
) self
->name
= g_strdup("");
1148 if (self
->class == NULL
) self
->class = g_strdup("");
1149 if (self
->role
== NULL
) self
->role
= g_strdup("");
1152 void client_update_strut(Client
*self
)
1156 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1157 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1160 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1162 /* updating here is pointless while we're being mapped cuz we're not in
1163 the client list yet */
1165 screen_update_struts();
1168 void client_update_icons(Client
*self
)
1171 unsigned long *data
;
1172 unsigned long w
, h
, i
;
1175 for (j
= 0; j
< self
->nicons
; ++j
)
1176 g_free(self
->icons
[j
].data
);
1177 if (self
->nicons
> 0)
1178 g_free(self
->icons
);
1181 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1182 /* figure out how many valid icons are in here */
1184 while (num
- i
> 2) {
1192 self
->icons
= g_new(Icon
, self
->nicons
);
1194 /* store the icons */
1196 for (j
= 0; j
< self
->nicons
; ++j
) {
1197 w
= self
->icons
[j
].width
= data
[i
++];
1198 h
= self
->icons
[j
].height
= data
[i
++];
1199 self
->icons
[j
].data
=
1200 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1209 engine_frame_adjust_icon(self
->frame
);
1212 void client_update_kwm_icon(Client
*self
)
1216 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1217 self
->pixmap_icon
= data
[0];
1218 self
->pixmap_icon_mask
= data
[1];
1221 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1224 engine_frame_adjust_icon(self
->frame
);
1227 static void client_change_state(Client
*self
)
1229 unsigned long state
[2];
1233 state
[0] = self
->wmstate
;
1235 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1239 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1241 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1243 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1244 if (self
->skip_taskbar
)
1245 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1246 if (self
->skip_pager
)
1247 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1248 if (self
->fullscreen
)
1249 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1251 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1253 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1255 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1257 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1258 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1260 client_calc_layer(self
);
1263 engine_frame_adjust_state(self
->frame
);
1266 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1271 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1272 Client
*c
= it
->data
;
1273 if (c
== skip
) continue; /* circular? */
1274 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1275 if (client_focused(c
)) return c
;
1280 void client_calc_layer(Client
*self
)
1286 /* are we fullscreen, or do we have a fullscreen transient parent? */
1289 while (c
&& c
!= TRAN_GROUP
) { /* XXX do smthng with the TRAN_GROUP case?*/
1290 if (c
->fullscreen
) {
1294 c
= c
->transient_for
;
1296 if (!fs
&& self
->fullscreen
) {
1297 /* is one of our transients focused? */
1298 c
= search_focus_tree(self
, self
);
1299 if (c
!= NULL
) fs
= TRUE
;
1302 if (self
->iconic
) l
= Layer_Icon
;
1303 else if (fs
) l
= Layer_Fullscreen
;
1304 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1305 else if (self
->type
== Type_Dock
) {
1306 if (!self
->below
) l
= Layer_Top
;
1307 else l
= Layer_Normal
;
1309 else if (self
->above
) l
= Layer_Above
;
1310 else if (self
->below
) l
= Layer_Below
;
1311 else l
= Layer_Normal
;
1313 if (l
!= self
->layer
) {
1316 stacking_raise(self
);
1320 gboolean
client_should_show(Client
*self
)
1322 if (self
->iconic
) return FALSE
;
1323 else if (!(self
->desktop
== screen_desktop
||
1324 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1325 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1330 static void client_showhide(Client
*self
)
1333 if (client_should_show(self
))
1334 engine_frame_show(self
->frame
);
1336 engine_frame_hide(self
->frame
);
1339 gboolean
client_normal(Client
*self
) {
1340 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1341 self
->type
== Type_Splash
);
1344 static void client_apply_startup_state(Client
*self
)
1346 /* these are in a carefully crafted order.. */
1349 self
->iconic
= FALSE
;
1350 client_iconify(self
, TRUE
, FALSE
);
1352 if (self
->fullscreen
) {
1353 self
->fullscreen
= FALSE
;
1354 client_fullscreen(self
, TRUE
, FALSE
);
1357 self
->shaded
= FALSE
;
1358 client_shade(self
, TRUE
);
1361 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1363 if (self
->max_vert
&& self
->max_horz
) {
1364 self
->max_vert
= self
->max_horz
= FALSE
;
1365 client_maximize(self
, TRUE
, 0, FALSE
);
1366 } else if (self
->max_vert
) {
1367 self
->max_vert
= FALSE
;
1368 client_maximize(self
, TRUE
, 2, FALSE
);
1369 } else if (self
->max_horz
) {
1370 self
->max_horz
= FALSE
;
1371 client_maximize(self
, TRUE
, 1, FALSE
);
1374 /* nothing to do for the other states:
1383 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1384 gboolean user
, gboolean final
)
1386 gboolean moved
= FALSE
, resized
= FALSE
;
1388 /* gets the frame's position */
1389 frame_client_gravity(self
->frame
, &x
, &y
);
1391 /* these positions are frame positions, not client positions */
1393 /* set the size and position if fullscreen */
1394 if (self
->fullscreen
) {
1397 w
= screen_physical_size
.width
;
1398 h
= screen_physical_size
.height
;
1400 /* set the size and position if maximized */
1401 if (self
->max_horz
) {
1402 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1403 w
= screen_area(self
->desktop
)->width
;
1405 if (self
->max_vert
) {
1406 y
= screen_area(self
->desktop
)->y
;
1407 h
= screen_area(self
->desktop
)->height
-
1408 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1412 /* gets the client's position */
1413 frame_frame_gravity(self
->frame
, &x
, &y
);
1415 /* these override the above states! if you cant move you can't move! */
1417 if (!(self
->functions
& Func_Move
)) {
1421 if (!(self
->functions
& Func_Resize
)) {
1422 w
= self
->area
.width
;
1423 h
= self
->area
.height
;
1427 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1428 w
-= self
->base_size
.width
;
1429 h
-= self
->base_size
.height
;
1432 /* for interactive resizing. have to move half an increment in each
1435 /* how far we are towards the next size inc */
1436 int mw
= w
% self
->size_inc
.width
;
1437 int mh
= h
% self
->size_inc
.height
;
1439 int aw
= self
->size_inc
.width
/ 2;
1440 int ah
= self
->size_inc
.height
/ 2;
1441 /* don't let us move into a new size increment */
1442 if (mw
+ aw
>= self
->size_inc
.width
)
1443 aw
= self
->size_inc
.width
- mw
- 1;
1444 if (mh
+ ah
>= self
->size_inc
.height
)
1445 ah
= self
->size_inc
.height
- mh
- 1;
1449 /* if this is a user-requested resize, then check against min/max
1450 sizes and aspect ratios */
1452 /* smaller than min size or bigger than max size? */
1453 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1454 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1455 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1456 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1458 /* adjust the height ot match the width for the aspect ratios */
1459 if (self
->min_ratio
)
1460 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1461 if (self
->max_ratio
)
1462 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1465 /* keep to the increments */
1466 w
/= self
->size_inc
.width
;
1467 h
/= self
->size_inc
.height
;
1469 /* you cannot resize to nothing */
1473 /* store the logical size */
1474 SIZE_SET(self
->logical_size
, w
, h
);
1476 w
*= self
->size_inc
.width
;
1477 h
*= self
->size_inc
.height
;
1479 w
+= self
->base_size
.width
;
1480 h
+= self
->base_size
.height
;
1484 case Corner_TopLeft
:
1486 case Corner_TopRight
:
1487 x
-= w
- self
->area
.width
;
1489 case Corner_BottomLeft
:
1490 y
-= h
- self
->area
.height
;
1492 case Corner_BottomRight
:
1493 x
-= w
- self
->area
.width
;
1494 y
-= h
- self
->area
.height
;
1498 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1499 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1501 RECT_SET(self
->area
, x
, y
, w
, h
);
1504 XResizeWindow(ob_display
, self
->window
, w
, h
);
1506 /* move/resize the frame to match the request */
1508 if (moved
|| resized
)
1509 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1511 if (!user
|| final
) {
1513 event
.type
= ConfigureNotify
;
1514 event
.xconfigure
.display
= ob_display
;
1515 event
.xconfigure
.event
= self
->window
;
1516 event
.xconfigure
.window
= self
->window
;
1518 /* root window coords with border in mind */
1519 event
.xconfigure
.x
= x
- self
->border_width
+
1520 self
->frame
->size
.left
;
1521 event
.xconfigure
.y
= y
- self
->border_width
+
1522 self
->frame
->size
.top
;
1524 event
.xconfigure
.width
= self
->area
.width
;
1525 event
.xconfigure
.height
= self
->area
.height
;
1526 event
.xconfigure
.border_width
= self
->border_width
;
1527 event
.xconfigure
.above
= self
->frame
->plate
;
1528 event
.xconfigure
.override_redirect
= FALSE
;
1529 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1530 FALSE
, StructureNotifyMask
, &event
);
1535 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1539 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1540 self
->fullscreen
== fs
) return; /* already done */
1542 self
->fullscreen
= fs
;
1543 client_change_state(self
); /* change the state hints on the client */
1546 /* save the functions and remove them */
1547 self
->pre_fs_func
= self
->functions
;
1548 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1550 /* save the decorations and remove them */
1551 self
->pre_fs_decor
= self
->decorations
;
1552 self
->decorations
= 0;
1555 dimensions
[0] = self
->area
.x
;
1556 dimensions
[1] = self
->area
.y
;
1557 dimensions
[2] = self
->area
.width
;
1558 dimensions
[3] = self
->area
.height
;
1560 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1564 /* these are not actually used cuz client_configure will set them
1565 as appropriate when the window is fullscreened */
1570 self
->functions
= self
->pre_fs_func
;
1571 self
->decorations
= self
->pre_fs_decor
;
1573 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1581 /* pick some fallbacks... */
1582 x
= screen_area(self
->desktop
)->x
+
1583 screen_area(self
->desktop
)->width
/ 4;
1584 y
= screen_area(self
->desktop
)->y
+
1585 screen_area(self
->desktop
)->height
/ 4;
1586 w
= screen_area(self
->desktop
)->width
/ 2;
1587 h
= screen_area(self
->desktop
)->height
/ 2;
1591 client_change_allowed_actions(self
); /* based on the new _functions */
1593 /* when fullscreening, don't obey things like increments, fill the
1595 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1597 /* raise (back) into our stacking layer */
1598 stacking_raise(self
);
1600 /* try focus us when we go into fullscreen mode */
1604 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1606 if (self
->iconic
== iconic
) return; /* nothing to do */
1608 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1611 self
->iconic
= iconic
;
1614 self
->wmstate
= IconicState
;
1615 self
->ignore_unmaps
++;
1616 /* we unmap the client itself so that we can get MapRequest events,
1617 and because the ICCCM tells us to! */
1618 XUnmapWindow(ob_display
, self
->window
);
1621 client_set_desktop(self
, screen_desktop
, FALSE
);
1622 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1623 XMapWindow(ob_display
, self
->window
);
1625 client_change_state(self
);
1626 client_showhide(self
);
1627 screen_update_struts();
1629 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1632 /* iconify all transients */
1633 if (self
->transients
) {
1636 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1637 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1641 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1645 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1646 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1648 /* check if already done */
1650 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1651 if (dir
== 1 && self
->max_horz
) return;
1652 if (dir
== 2 && self
->max_vert
) return;
1654 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1655 if (dir
== 1 && !self
->max_horz
) return;
1656 if (dir
== 2 && !self
->max_vert
) return;
1659 /* work with the frame's coords */
1660 x
= self
->frame
->area
.x
;
1661 y
= self
->frame
->area
.y
;
1662 w
= self
->area
.width
;
1663 h
= self
->area
.height
;
1675 /* get the property off the window and use it for the dimensions
1676 we are already maxed on */
1677 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1679 if (self
->max_horz
) {
1680 dimensions
[0] = readdim
[0];
1681 dimensions
[2] = readdim
[2];
1683 if (self
->max_vert
) {
1684 dimensions
[1] = readdim
[1];
1685 dimensions
[3] = readdim
[3];
1690 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1696 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1698 if (dir
== 0 || dir
== 1) { /* horz */
1702 if (dir
== 0 || dir
== 2) { /* vert */
1708 /* pick some fallbacks... */
1709 if (dir
== 0 || dir
== 1) { /* horz */
1710 x
= screen_area(self
->desktop
)->x
+
1711 screen_area(self
->desktop
)->width
/ 4;
1712 w
= screen_area(self
->desktop
)->width
/ 2;
1714 if (dir
== 0 || dir
== 2) { /* vert */
1715 y
= screen_area(self
->desktop
)->y
+
1716 screen_area(self
->desktop
)->height
/ 4;
1717 h
= screen_area(self
->desktop
)->height
/ 2;
1722 if (dir
== 0 || dir
== 1) /* horz */
1723 self
->max_horz
= max
;
1724 if (dir
== 0 || dir
== 2) /* vert */
1725 self
->max_vert
= max
;
1727 if (!self
->max_horz
&& !self
->max_vert
)
1728 PROP_ERASE(self
->window
, openbox_premax
);
1730 client_change_state(self
); /* change the state hints on the client */
1732 /* figure out where the client should be going */
1733 frame_frame_gravity(self
->frame
, &x
, &y
);
1734 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1737 void client_shade(Client
*self
, gboolean shade
)
1739 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1740 self
->shaded
== shade
) return; /* already done */
1742 /* when we're iconic, don't change the wmstate */
1744 self
->wmstate
= shade
? IconicState
: NormalState
;
1745 self
->shaded
= shade
;
1746 client_change_state(self
);
1747 /* resize the frame to just the titlebar */
1748 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1751 void client_close(Client
*self
)
1755 if (!(self
->functions
& Func_Close
)) return;
1758 XXX: itd be cool to do timeouts and shit here for killing the client's
1760 like... if the window is around after 5 seconds, then the close button
1761 turns a nice red, and if this function is called again, the client is
1765 ce
.xclient
.type
= ClientMessage
;
1766 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1767 ce
.xclient
.display
= ob_display
;
1768 ce
.xclient
.window
= self
->window
;
1769 ce
.xclient
.format
= 32;
1770 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1771 ce
.xclient
.data
.l
[1] = event_lasttime
;
1772 ce
.xclient
.data
.l
[2] = 0l;
1773 ce
.xclient
.data
.l
[3] = 0l;
1774 ce
.xclient
.data
.l
[4] = 0l;
1775 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1778 void client_kill(Client
*self
)
1780 XKillClient(ob_display
, self
->window
);
1783 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1787 if (target
== self
->desktop
) return;
1789 g_message("Setting desktop %u", target
);
1791 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1793 old
= self
->desktop
;
1794 self
->desktop
= target
;
1795 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1796 /* the frame can display the current desktop state */
1797 engine_frame_adjust_state(self
->frame
);
1798 /* 'move' the window to the new desktop */
1800 client_showhide(self
);
1801 /* raise if it was not already on the desktop */
1802 if (old
!= DESKTOP_ALL
)
1803 stacking_raise(self
);
1804 screen_update_struts();
1806 /* update the focus lists */
1807 if (old
== DESKTOP_ALL
) {
1808 for (i
= 0; i
< screen_num_desktops
; ++i
)
1809 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1811 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1812 if (target
== DESKTOP_ALL
) {
1813 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1815 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1817 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1821 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1823 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1826 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1829 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1834 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1835 Client
*c
= it
->data
;
1836 if (c
== skip
) continue; /* circular? */
1837 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1838 if (c
->modal
) return c
;
1843 Client
*client_find_modal_child(Client
*self
)
1845 return search_modal_tree(self
, self
);
1848 gboolean
client_validate(Client
*self
)
1852 XSync(ob_display
, FALSE
); /* get all events on the server */
1854 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1855 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1856 XPutBackEvent(ob_display
, &e
);
1863 void client_set_wm_state(Client
*self
, long state
)
1865 if (state
== self
->wmstate
) return; /* no change */
1869 client_iconify(self
, TRUE
, TRUE
);
1872 client_iconify(self
, FALSE
, TRUE
);
1877 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1879 gboolean shaded
= self
->shaded
;
1880 gboolean fullscreen
= self
->fullscreen
;
1881 gboolean max_horz
= self
->max_horz
;
1882 gboolean max_vert
= self
->max_vert
;
1885 if (!(action
== prop_atoms
.net_wm_state_add
||
1886 action
== prop_atoms
.net_wm_state_remove
||
1887 action
== prop_atoms
.net_wm_state_toggle
))
1888 /* an invalid action was passed to the client message, ignore it */
1891 for (i
= 0; i
< 2; ++i
) {
1892 Atom state
= i
== 0 ? data1
: data2
;
1894 if (!state
) continue;
1896 /* if toggling, then pick whether we're adding or removing */
1897 if (action
== prop_atoms
.net_wm_state_toggle
) {
1898 if (state
== prop_atoms
.net_wm_state_modal
)
1899 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1900 prop_atoms
.net_wm_state_add
;
1901 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1902 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1903 prop_atoms
.net_wm_state_add
;
1904 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1905 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1906 prop_atoms
.net_wm_state_add
;
1907 else if (state
== prop_atoms
.net_wm_state_shaded
)
1908 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1909 prop_atoms
.net_wm_state_add
;
1910 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1911 action
= self
->skip_taskbar
?
1912 prop_atoms
.net_wm_state_remove
:
1913 prop_atoms
.net_wm_state_add
;
1914 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1915 action
= self
->skip_pager
?
1916 prop_atoms
.net_wm_state_remove
:
1917 prop_atoms
.net_wm_state_add
;
1918 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1919 action
= self
->fullscreen
?
1920 prop_atoms
.net_wm_state_remove
:
1921 prop_atoms
.net_wm_state_add
;
1922 else if (state
== prop_atoms
.net_wm_state_above
)
1923 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1924 prop_atoms
.net_wm_state_add
;
1925 else if (state
== prop_atoms
.net_wm_state_below
)
1926 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1927 prop_atoms
.net_wm_state_add
;
1930 if (action
== prop_atoms
.net_wm_state_add
) {
1931 if (state
== prop_atoms
.net_wm_state_modal
) {
1932 /* XXX raise here or something? */
1934 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1936 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1938 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1940 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1941 self
->skip_taskbar
= TRUE
;
1942 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1943 self
->skip_pager
= TRUE
;
1944 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1946 } else if (state
== prop_atoms
.net_wm_state_above
) {
1948 } else if (state
== prop_atoms
.net_wm_state_below
) {
1952 } else { /* action == prop_atoms.net_wm_state_remove */
1953 if (state
== prop_atoms
.net_wm_state_modal
) {
1954 self
->modal
= FALSE
;
1955 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1957 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1959 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1961 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1962 self
->skip_taskbar
= FALSE
;
1963 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1964 self
->skip_pager
= FALSE
;
1965 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1967 } else if (state
== prop_atoms
.net_wm_state_above
) {
1968 self
->above
= FALSE
;
1969 } else if (state
== prop_atoms
.net_wm_state_below
) {
1970 self
->below
= FALSE
;
1974 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1975 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1977 if (max_horz
== max_vert
) { /* both going the same way */
1978 client_maximize(self
, max_horz
, 0, TRUE
);
1980 client_maximize(self
, max_horz
, 1, TRUE
);
1981 client_maximize(self
, max_vert
, 2, TRUE
);
1985 if (max_horz
!= self
->max_horz
)
1986 client_maximize(self
, max_horz
, 1, TRUE
);
1988 client_maximize(self
, max_vert
, 2, TRUE
);
1991 /* change fullscreen state before shading, as it will affect if the window
1993 if (fullscreen
!= self
->fullscreen
)
1994 client_fullscreen(self
, fullscreen
, TRUE
);
1995 if (shaded
!= self
->shaded
)
1996 client_shade(self
, shaded
);
1997 client_calc_layer(self
);
1998 client_change_state(self
); /* change the hint to relect these changes */
2001 Client
*client_focus_target(Client
*self
)
2005 /* if we have a modal child, then focus it, not us */
2006 child
= client_find_modal_child(self
);
2007 if (child
) return child
;
2011 gboolean
client_focusable(Client
*self
)
2013 /* won't try focus if the client doesn't want it, or if the window isn't
2014 visible on the screen */
2015 return self
->frame
->visible
&&
2016 (self
->can_focus
|| self
->focus_notify
);
2019 gboolean
client_focus(Client
*self
)
2023 /* choose the correct target */
2024 self
= client_focus_target(self
);
2026 if (!client_focusable(self
))
2029 /* do a check to see if the window has already been unmapped or destroyed
2030 do this intelligently while watching out for unmaps we've generated
2031 (ignore_unmaps > 0) */
2032 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2033 DestroyNotify
, &ev
)) {
2034 XPutBackEvent(ob_display
, &ev
);
2037 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2038 UnmapNotify
, &ev
)) {
2039 if (self
->ignore_unmaps
) {
2040 self
->ignore_unmaps
--;
2042 XPutBackEvent(ob_display
, &ev
);
2047 if (self
->can_focus
)
2048 /* RevertToPointerRoot causes much more headache than TevertToNone, so
2049 I choose to use it always, hopefully to find errors quicker, if any
2050 are left. (I hate X. I hate focus events.) */
2051 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2054 if (self
->focus_notify
) {
2056 ce
.xclient
.type
= ClientMessage
;
2057 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2058 ce
.xclient
.display
= ob_display
;
2059 ce
.xclient
.window
= self
->window
;
2060 ce
.xclient
.format
= 32;
2061 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2062 ce
.xclient
.data
.l
[1] = event_lasttime
;
2063 ce
.xclient
.data
.l
[2] = 0l;
2064 ce
.xclient
.data
.l
[3] = 0l;
2065 ce
.xclient
.data
.l
[4] = 0l;
2066 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2070 g_message("focusing %lx", self
->window
);
2073 /* Cause the FocusIn to come back to us. Important for desktop switches,
2074 since otherwise we'll have no FocusIn on the queue and send it off to
2075 the focus_backup. */
2076 XSync(ob_display
, FALSE
);
2080 void client_unfocus(Client
*self
)
2082 g_assert(focus_client
== self
);
2083 g_message("client_unfocus");
2084 focus_fallback(Fallback_Unfocusing
);
2087 gboolean
client_focused(Client
*self
)
2089 return self
== focus_client
;
2092 Icon
*client_icon(Client
*self
, int w
, int h
)
2095 /* si is the smallest image >= req */
2096 /* li is the largest image < req */
2097 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2099 if (!self
->nicons
) return NULL
;
2101 for (i
= 0; i
< self
->nicons
; ++i
) {
2102 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2103 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2107 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2112 if (largest
== 0) /* didnt find one smaller than the requested size */
2113 return &self
->icons
[si
];
2114 return &self
->icons
[li
];