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 client_unfocus(self
);
317 /* remove from its group */
319 group_remove(self
->group
, self
);
323 /* dispatch the unmapped event */
324 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
325 g_assert(self
!= NULL
);
327 /* give the client its border back */
328 client_toggle_border(self
, TRUE
);
330 /* reparent the window out of the frame, and free the frame */
331 engine_frame_release_client(self
->frame
, self
);
334 if (ob_state
!= State_Exiting
) {
335 /* these values should not be persisted across a window
337 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
338 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
340 /* if we're left in an iconic state, the client wont be mapped. this is
341 bad, since we will no longer be managing the window on restart */
343 XMapWindow(ob_display
, self
->window
);
346 g_message("Unmanaged window 0x%lx", self
->window
);
348 /* free all data allocated in the client struct */
349 g_slist_free(self
->transients
);
350 for (j
= 0; j
< self
->nicons
; ++j
)
351 g_free(self
->icons
[j
].data
);
352 if (self
->nicons
> 0)
355 g_free(self
->icon_title
);
361 /* update the list hints */
365 static void client_move_onscreen(Client
*self
)
368 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
370 a
= screen_area(self
->desktop
);
371 if (x
>= a
->x
+ a
->width
- 1)
372 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
373 if (y
>= a
->y
+ a
->height
- 1)
374 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
375 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
377 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
380 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
382 client_configure(self
, Corner_TopLeft
, x
, y
,
383 self
->area
.width
, self
->area
.height
,
387 static void client_toggle_border(Client
*self
, gboolean show
)
389 /* adjust our idea of where the client is, based on its border. When the
390 border is removed, the client should now be considered to be in a
392 when re-adding the border to the client, the same operation needs to be
394 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
395 int x
= oldx
, y
= oldy
;
396 switch(self
->gravity
) {
398 case NorthWestGravity
:
400 case SouthWestGravity
:
402 case NorthEastGravity
:
404 case SouthEastGravity
:
405 if (show
) x
-= self
->border_width
* 2;
406 else x
+= self
->border_width
* 2;
413 if (show
) x
-= self
->border_width
;
414 else x
+= self
->border_width
;
417 switch(self
->gravity
) {
419 case NorthWestGravity
:
421 case NorthEastGravity
:
423 case SouthWestGravity
:
425 case SouthEastGravity
:
426 if (show
) y
-= self
->border_width
* 2;
427 else y
+= self
->border_width
* 2;
434 if (show
) y
-= self
->border_width
;
435 else y
+= self
->border_width
;
442 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
444 /* move the client so it is back it the right spot _with_ its
446 if (x
!= oldx
|| y
!= oldy
)
447 XMoveWindow(ob_display
, self
->window
, x
, y
);
449 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
453 static void client_get_all(Client
*self
)
455 /* update EVERYTHING!! */
457 self
->ignore_unmaps
= 0;
461 self
->title
= self
->icon_title
= NULL
;
462 self
->name
= self
->class = self
->role
= NULL
;
463 self
->wmstate
= NormalState
;
464 self
->transient
= FALSE
;
465 self
->transients
= NULL
;
466 self
->transient_for
= NULL
;
468 self
->urgent
= FALSE
;
469 self
->positioned
= FALSE
;
470 self
->disabled_decorations
= 0;
474 client_get_area(self
);
475 client_get_desktop(self
);
476 client_get_state(self
);
477 client_get_shaped(self
);
479 client_update_transient_for(self
);
480 client_get_mwm_hints(self
);
481 client_get_type(self
);/* this can change the mwmhints for special cases */
483 client_update_protocols(self
);
485 client_get_gravity(self
); /* get the attribute gravity */
486 client_update_normal_hints(self
); /* this may override the attribute
489 /* got the type, the mwmhints, the protocols, and the normal hints
490 (min/max sizes), so we're ready to set up the decorations/functions */
491 client_setup_decor_and_functions(self
);
493 client_update_wmhints(self
);
494 client_update_title(self
);
495 client_update_icon_title(self
);
496 client_update_class(self
);
497 client_update_strut(self
);
498 client_update_icons(self
);
499 client_update_kwm_icon(self
);
501 /* this makes sure that these windows appear on all desktops */
502 if (self
->type
== Type_Desktop
)
503 self
->desktop
= DESKTOP_ALL
;
505 /* set the desktop hint, to make sure that it always exists, and to
506 reflect any changes we've made here */
507 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
509 client_change_state(self
);
512 static void client_get_area(Client
*self
)
514 XWindowAttributes wattrib
;
517 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
518 g_assert(ret
!= BadWindow
);
520 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
521 self
->border_width
= wattrib
.border_width
;
524 static void client_get_desktop(Client
*self
)
528 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
529 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
530 d
= screen_num_desktops
- 1;
533 /* defaults to the current desktop */
534 self
->desktop
= screen_desktop
;
538 static void client_get_state(Client
*self
)
543 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
544 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
545 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
547 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
549 for (i
= 0; i
< num
; ++i
) {
550 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
552 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
554 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
556 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
557 self
->skip_taskbar
= TRUE
;
558 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
559 self
->skip_pager
= TRUE
;
560 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
561 self
->fullscreen
= TRUE
;
562 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
563 self
->max_vert
= TRUE
;
564 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
565 self
->max_horz
= TRUE
;
566 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
568 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
576 static void client_get_shaped(Client
*self
)
578 self
->shaped
= FALSE
;
580 if (extensions_shape
) {
585 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
587 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
588 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
590 self
->shaped
= (s
!= 0);
595 void client_update_transient_for(Client
*self
)
600 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
601 t
!= self
->window
) { /* cant be transient to itself! */
602 self
->transient
= TRUE
;
603 c
= g_hash_table_lookup(client_map
, &t
);
604 g_assert(c
!= self
);/* if this happens then we need to check for it*/
606 if (!c
&& self
->group
) {
607 /* not transient to a client, see if it is transient for a
609 if (t
== self
->group
->leader
||
612 /* window is a transient for its group! */
617 self
->transient
= FALSE
;
619 /* if anything has changed... */
620 if (c
!= self
->transient_for
) {
621 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
624 /* remove from old parents */
625 for (it
= self
->group
->members
; it
; it
= it
->next
)
626 if (it
->data
!= self
)
627 ((Client
*)it
->data
)->transients
=
628 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
629 } else if (self
->transient_for
!= NULL
) { /* transient of window */
630 /* remove from old parent */
631 self
->transient_for
->transients
=
632 g_slist_remove(self
->transient_for
->transients
, self
);
634 self
->transient_for
= c
;
635 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
638 /* add to new parents */
639 for (it
= self
->group
->members
; it
; it
= it
->next
)
640 if (it
->data
!= self
)
641 ((Client
*)it
->data
)->transients
=
642 g_slist_append(((Client
*)it
->data
)->transients
, self
);
643 } else if (self
->transient_for
!= NULL
) { /* transient of window */
644 /* add to new parent */
645 self
->transient_for
->transients
=
646 g_slist_append(self
->transient_for
->transients
, self
);
651 static void client_get_mwm_hints(Client
*self
)
654 unsigned long *hints
;
656 self
->mwmhints
.flags
= 0; /* default to none */
658 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
659 if (num
>= MWM_ELEMENTS
) {
660 self
->mwmhints
.flags
= hints
[0];
661 self
->mwmhints
.functions
= hints
[1];
662 self
->mwmhints
.decorations
= hints
[2];
668 void client_get_type(Client
*self
)
674 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
675 /* use the first value that we know about in the array */
676 for (i
= 0; i
< num
; ++i
) {
677 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
678 self
->type
= Type_Desktop
;
679 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
680 self
->type
= Type_Dock
;
681 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
682 self
->type
= Type_Toolbar
;
683 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
684 self
->type
= Type_Menu
;
685 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
686 self
->type
= Type_Utility
;
687 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
688 self
->type
= Type_Splash
;
689 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
690 self
->type
= Type_Dialog
;
691 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
692 self
->type
= Type_Normal
;
693 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
694 /* prevent this window from getting any decor or
696 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
697 MwmFlag_Decorations
);
698 self
->mwmhints
.decorations
= 0;
699 self
->mwmhints
.functions
= 0;
701 if (self
->type
!= (WindowType
) -1)
702 break; /* grab the first legit type */
707 if (self
->type
== (WindowType
) -1) {
708 /*the window type hint was not set, which means we either classify
709 ourself as a normal window or a dialog, depending on if we are a
712 self
->type
= Type_Dialog
;
714 self
->type
= Type_Normal
;
718 void client_update_protocols(Client
*self
)
721 gulong num_return
, i
;
723 self
->focus_notify
= FALSE
;
724 self
->delete_window
= FALSE
;
726 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
727 for (i
= 0; i
< num_return
; ++i
) {
728 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
729 /* this means we can request the window to close */
730 self
->delete_window
= TRUE
;
731 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
732 /* if this protocol is requested, then the window will be
733 notified whenever we want it to receive focus */
734 self
->focus_notify
= TRUE
;
740 static void client_get_gravity(Client
*self
)
742 XWindowAttributes wattrib
;
745 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
746 g_assert(ret
!= BadWindow
);
747 self
->gravity
= wattrib
.win_gravity
;
750 void client_update_normal_hints(Client
*self
)
754 int oldgravity
= self
->gravity
;
757 self
->min_ratio
= 0.0f
;
758 self
->max_ratio
= 0.0f
;
759 SIZE_SET(self
->size_inc
, 1, 1);
760 SIZE_SET(self
->base_size
, 0, 0);
761 SIZE_SET(self
->min_size
, 0, 0);
762 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
764 /* get the hints from the window */
765 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
766 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
768 if (size
.flags
& PWinGravity
) {
769 self
->gravity
= size
.win_gravity
;
771 /* if the client has a frame, i.e. has already been mapped and
772 is changing its gravity */
773 if (self
->frame
&& self
->gravity
!= oldgravity
) {
774 /* move our idea of the client's position based on its new
776 self
->area
.x
= self
->frame
->area
.x
;
777 self
->area
.y
= self
->frame
->area
.y
;
778 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
782 if (size
.flags
& PAspect
) {
783 if (size
.min_aspect
.y
)
784 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
785 if (size
.max_aspect
.y
)
786 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
789 if (size
.flags
& PMinSize
)
790 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
792 if (size
.flags
& PMaxSize
)
793 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
795 if (size
.flags
& PBaseSize
)
796 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
798 if (size
.flags
& PResizeInc
)
799 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
803 void client_setup_decor_and_functions(Client
*self
)
805 /* start with everything (cept fullscreen) */
806 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
807 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
809 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
811 if (self
->delete_window
) {
812 self
->decorations
|= Decor_Close
;
813 self
->functions
|= Func_Close
;
816 if (!(self
->min_size
.width
< self
->max_size
.width
||
817 self
->min_size
.height
< self
->max_size
.height
)) {
818 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
819 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
822 switch (self
->type
) {
824 /* normal windows retain all of the possible decorations and
825 functionality, and are the only windows that you can fullscreen */
826 self
->functions
|= Func_Fullscreen
;
830 /* dialogs cannot be maximized */
831 self
->decorations
&= ~Decor_Maximize
;
832 self
->functions
&= ~Func_Maximize
;
838 /* these windows get less functionality */
839 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
840 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
846 /* none of these windows are manipulated by the window manager */
847 self
->decorations
= 0;
852 /* Mwm Hints are applied subtractively to what has already been chosen for
853 decor and functionality */
854 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
855 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
856 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
857 self
->decorations
&= ~Decor_Border
;
858 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
859 self
->decorations
&= ~Decor_Handle
;
860 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
861 self
->decorations
&= ~Decor_Titlebar
;
862 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
863 self
->decorations
&= ~Decor_Iconify
;
864 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
865 self
->decorations
&= ~Decor_Maximize
;
869 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
870 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
871 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
872 self
->functions
&= ~Func_Resize
;
873 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
874 self
->functions
&= ~Func_Move
;
875 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
876 self
->functions
&= ~Func_Iconify
;
877 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
878 self
->functions
&= ~Func_Maximize
;
879 /* dont let mwm hints kill the close button
880 if (! (self->mwmhints.functions & MwmFunc_Close))
881 self->functions &= ~Func_Close; */
885 /* can't maximize without moving/resizing */
886 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
887 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
889 /* finally, user specified disabled decorations are applied to subtract
891 if (self
->disabled_decorations
& Decor_Titlebar
)
892 self
->decorations
&= ~Decor_Titlebar
;
893 if (self
->disabled_decorations
& Decor_Handle
)
894 self
->decorations
&= ~Decor_Handle
;
895 if (self
->disabled_decorations
& Decor_Border
)
896 self
->decorations
&= ~Decor_Border
;
897 if (self
->disabled_decorations
& Decor_Iconify
)
898 self
->decorations
&= ~Decor_Iconify
;
899 if (self
->disabled_decorations
& Decor_Maximize
)
900 self
->decorations
&= ~Decor_Maximize
;
901 if (self
->disabled_decorations
& Decor_AllDesktops
)
902 self
->decorations
&= ~Decor_AllDesktops
;
903 if (self
->disabled_decorations
& Decor_Shade
)
904 self
->decorations
&= ~Decor_Shade
;
905 if (self
->disabled_decorations
& Decor_Close
)
906 self
->decorations
&= ~Decor_Close
;
908 /* if we don't have a titlebar, then we cannot shade! */
909 if (!(self
->decorations
& Decor_Titlebar
))
910 self
->functions
&= ~Func_Shade
;
912 client_change_allowed_actions(self
);
915 /* change the decors on the frame, and with more/less decorations,
916 we may also need to be repositioned */
917 engine_frame_adjust_area(self
->frame
, TRUE
, TRUE
);
918 /* with new decor, the window's maximized size may change */
919 client_remaximize(self
);
923 static void client_change_allowed_actions(Client
*self
)
928 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
930 if (self
->functions
& Func_Shade
)
931 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
932 if (self
->functions
& Func_Close
)
933 actions
[num
++] = prop_atoms
.net_wm_action_close
;
934 if (self
->functions
& Func_Move
)
935 actions
[num
++] = prop_atoms
.net_wm_action_move
;
936 if (self
->functions
& Func_Iconify
)
937 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
938 if (self
->functions
& Func_Resize
)
939 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
940 if (self
->functions
& Func_Fullscreen
)
941 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
942 if (self
->functions
& Func_Maximize
) {
943 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
944 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
947 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
949 /* make sure the window isn't breaking any rules now */
951 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
952 if (self
->frame
) client_shade(self
, FALSE
);
953 else self
->shaded
= FALSE
;
955 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
956 g_message("UNSETTING ICONIC");
957 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
958 else self
->iconic
= FALSE
;
960 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
961 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
962 else self
->fullscreen
= FALSE
;
964 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
966 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
967 else self
->max_vert
= self
->max_horz
= FALSE
;
971 void client_remaximize(Client
*self
)
974 if (self
->max_horz
&& self
->max_vert
)
976 else if (self
->max_horz
)
978 else if (self
->max_vert
)
981 return; /* not maximized */
982 self
->max_horz
= self
->max_vert
= FALSE
;
983 client_maximize(self
, TRUE
, dir
, FALSE
);
986 void client_update_wmhints(Client
*self
)
991 /* assume a window takes input if it doesnt specify */
992 self
->can_focus
= TRUE
;
994 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
995 if (hints
->flags
& InputHint
)
996 self
->can_focus
= hints
->input
;
998 /* only do this when first managing the window *AND* when we aren't
1000 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1001 if (hints
->flags
& StateHint
)
1002 self
->iconic
= hints
->initial_state
== IconicState
;
1004 if (hints
->flags
& XUrgencyHint
)
1007 if (!(hints
->flags
& WindowGroupHint
))
1008 hints
->window_group
= None
; /* no group */
1009 /* did the group state change? */
1010 if (hints
->window_group
!= (self
->group
? self
->group
->leader
: None
)){
1011 /* remove from the old group if there was one */
1012 if (self
->group
!= NULL
)
1013 group_remove(self
->group
, self
);
1014 if (hints
->window_group
!= None
)
1015 self
->group
= group_add(hints
->window_group
, self
);
1017 /* because the self->transient flag wont change from this call,
1018 we don't need to update the window's type and such, only its
1019 transient_for, and the transients lists of other windows in the
1020 group may be affected */
1021 client_update_transient_for(self
);
1024 if (hints
->flags
& IconPixmapHint
) {
1025 client_update_kwm_icon(self
);
1026 /* try get the kwm icon first, this is a fallback only */
1027 if (self
->pixmap_icon
== None
) {
1028 self
->pixmap_icon
= hints
->icon_pixmap
;
1029 if (hints
->flags
& IconMaskHint
)
1030 self
->pixmap_icon_mask
= hints
->icon_mask
;
1032 self
->pixmap_icon_mask
= None
;
1035 engine_frame_adjust_icon(self
->frame
);
1042 if (ur
!= self
->urgent
) {
1044 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1046 /* fire the urgent callback if we're mapped, otherwise, wait until
1047 after we're mapped */
1049 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1053 void client_update_title(Client
*self
)
1057 g_free(self
->title
);
1060 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
1061 /* try old x stuff */
1062 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
1063 /* convert it to UTF-8 */
1067 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1069 g_warning("Unable to convert string to UTF-8");
1076 data
= g_strdup("Unnamed Window");
1078 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1084 engine_frame_adjust_title(self
->frame
);
1087 void client_update_icon_title(Client
*self
)
1091 g_free(self
->icon_title
);
1094 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1095 /* try old x stuff */
1096 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1097 /* convert it to UTF-8 */
1101 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1103 g_warning("Unable to convert string to UTF-8");
1110 data
= g_strdup("Unnamed Window");
1112 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1115 self
->icon_title
= data
;
1118 void client_update_class(Client
*self
)
1124 if (self
->name
) g_free(self
->name
);
1125 if (self
->class) g_free(self
->class);
1126 if (self
->role
) g_free(self
->role
);
1128 self
->name
= self
->class = self
->role
= NULL
;
1130 data
= g_ptr_array_new();
1132 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1134 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1136 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1139 for (i
= 0; i
< data
->len
; ++i
)
1140 g_free(g_ptr_array_index(data
, i
));
1141 g_ptr_array_free(data
, TRUE
);
1143 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1144 self
->role
= g_strdup(s
);
1146 if (self
->name
== NULL
) self
->name
= g_strdup("");
1147 if (self
->class == NULL
) self
->class = g_strdup("");
1148 if (self
->role
== NULL
) self
->role
= g_strdup("");
1151 void client_update_strut(Client
*self
)
1155 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1156 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1159 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1161 /* updating here is pointless while we're being mapped cuz we're not in
1162 the client list yet */
1164 screen_update_struts();
1167 void client_update_icons(Client
*self
)
1170 unsigned long *data
;
1171 unsigned long w
, h
, i
;
1174 for (j
= 0; j
< self
->nicons
; ++j
)
1175 g_free(self
->icons
[j
].data
);
1176 if (self
->nicons
> 0)
1177 g_free(self
->icons
);
1180 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1181 /* figure out how many valid icons are in here */
1183 while (num
- i
> 2) {
1191 self
->icons
= g_new(Icon
, self
->nicons
);
1193 /* store the icons */
1195 for (j
= 0; j
< self
->nicons
; ++j
) {
1196 w
= self
->icons
[j
].width
= data
[i
++];
1197 h
= self
->icons
[j
].height
= data
[i
++];
1198 self
->icons
[j
].data
=
1199 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1208 engine_frame_adjust_icon(self
->frame
);
1211 void client_update_kwm_icon(Client
*self
)
1215 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1216 self
->pixmap_icon
= data
[0];
1217 self
->pixmap_icon_mask
= data
[1];
1220 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1223 engine_frame_adjust_icon(self
->frame
);
1226 static void client_change_state(Client
*self
)
1228 unsigned long state
[2];
1232 state
[0] = self
->wmstate
;
1234 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1238 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1240 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1242 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1243 if (self
->skip_taskbar
)
1244 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1245 if (self
->skip_pager
)
1246 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1247 if (self
->fullscreen
)
1248 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1250 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1252 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1254 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1256 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1257 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1259 client_calc_layer(self
);
1262 engine_frame_adjust_state(self
->frame
);
1265 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1270 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1271 Client
*c
= it
->data
;
1272 if (c
== skip
) continue; /* circular? */
1273 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1274 if (client_focused(c
)) return c
;
1279 void client_calc_layer(Client
*self
)
1285 /* are we fullscreen, or do we have a fullscreen transient parent? */
1288 while (c
&& c
!= TRAN_GROUP
) { /* XXX do smthng with the TRAN_GROUP case?*/
1289 if (c
->fullscreen
) {
1293 c
= c
->transient_for
;
1295 if (!fs
&& self
->fullscreen
) {
1296 /* is one of our transients focused? */
1297 c
= search_focus_tree(self
, self
);
1298 if (c
!= NULL
) fs
= TRUE
;
1301 if (self
->iconic
) l
= Layer_Icon
;
1302 else if (fs
) l
= Layer_Fullscreen
;
1303 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1304 else if (self
->type
== Type_Dock
) {
1305 if (!self
->below
) l
= Layer_Top
;
1306 else l
= Layer_Normal
;
1308 else if (self
->above
) l
= Layer_Above
;
1309 else if (self
->below
) l
= Layer_Below
;
1310 else l
= Layer_Normal
;
1312 if (l
!= self
->layer
) {
1315 stacking_raise(self
);
1319 gboolean
client_should_show(Client
*self
)
1321 if (self
->iconic
) return FALSE
;
1322 else if (!(self
->desktop
== screen_desktop
||
1323 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1324 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1329 static void client_showhide(Client
*self
)
1332 if (client_should_show(self
))
1333 engine_frame_show(self
->frame
);
1335 engine_frame_hide(self
->frame
);
1338 gboolean
client_normal(Client
*self
) {
1339 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1340 self
->type
== Type_Splash
);
1343 static void client_apply_startup_state(Client
*self
)
1345 /* these are in a carefully crafted order.. */
1348 self
->iconic
= FALSE
;
1349 client_iconify(self
, TRUE
, FALSE
);
1351 if (self
->fullscreen
) {
1352 self
->fullscreen
= FALSE
;
1353 client_fullscreen(self
, TRUE
, FALSE
);
1356 self
->shaded
= FALSE
;
1357 client_shade(self
, TRUE
);
1360 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1362 if (self
->max_vert
&& self
->max_horz
) {
1363 self
->max_vert
= self
->max_horz
= FALSE
;
1364 client_maximize(self
, TRUE
, 0, FALSE
);
1365 } else if (self
->max_vert
) {
1366 self
->max_vert
= FALSE
;
1367 client_maximize(self
, TRUE
, 2, FALSE
);
1368 } else if (self
->max_horz
) {
1369 self
->max_horz
= FALSE
;
1370 client_maximize(self
, TRUE
, 1, FALSE
);
1373 /* nothing to do for the other states:
1382 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1383 gboolean user
, gboolean final
)
1385 gboolean moved
= FALSE
, resized
= FALSE
;
1387 /* gets the frame's position */
1388 frame_client_gravity(self
->frame
, &x
, &y
);
1390 /* these positions are frame positions, not client positions */
1392 /* set the size and position if fullscreen */
1393 if (self
->fullscreen
) {
1396 w
= screen_physical_size
.width
;
1397 h
= screen_physical_size
.height
;
1399 /* set the size and position if maximized */
1400 if (self
->max_horz
) {
1401 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1402 w
= screen_area(self
->desktop
)->width
;
1404 if (self
->max_vert
) {
1405 y
= screen_area(self
->desktop
)->y
;
1406 h
= screen_area(self
->desktop
)->height
-
1407 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1411 /* gets the client's position */
1412 frame_frame_gravity(self
->frame
, &x
, &y
);
1414 /* these override the above states! if you cant move you can't move! */
1416 if (!(self
->functions
& Func_Move
)) {
1420 if (!(self
->functions
& Func_Resize
)) {
1421 w
= self
->area
.width
;
1422 h
= self
->area
.height
;
1426 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1427 w
-= self
->base_size
.width
;
1428 h
-= self
->base_size
.height
;
1431 /* for interactive resizing. have to move half an increment in each
1434 /* how far we are towards the next size inc */
1435 int mw
= w
% self
->size_inc
.width
;
1436 int mh
= h
% self
->size_inc
.height
;
1438 int aw
= self
->size_inc
.width
/ 2;
1439 int ah
= self
->size_inc
.height
/ 2;
1440 /* don't let us move into a new size increment */
1441 if (mw
+ aw
>= self
->size_inc
.width
)
1442 aw
= self
->size_inc
.width
- mw
- 1;
1443 if (mh
+ ah
>= self
->size_inc
.height
)
1444 ah
= self
->size_inc
.height
- mh
- 1;
1448 /* if this is a user-requested resize, then check against min/max
1449 sizes and aspect ratios */
1451 /* smaller than min size or bigger than max size? */
1452 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1453 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1454 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1455 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1457 /* adjust the height ot match the width for the aspect ratios */
1458 if (self
->min_ratio
)
1459 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1460 if (self
->max_ratio
)
1461 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1464 /* keep to the increments */
1465 w
/= self
->size_inc
.width
;
1466 h
/= self
->size_inc
.height
;
1468 /* you cannot resize to nothing */
1472 /* store the logical size */
1473 SIZE_SET(self
->logical_size
, w
, h
);
1475 w
*= self
->size_inc
.width
;
1476 h
*= self
->size_inc
.height
;
1478 w
+= self
->base_size
.width
;
1479 h
+= self
->base_size
.height
;
1483 case Corner_TopLeft
:
1485 case Corner_TopRight
:
1486 x
-= w
- self
->area
.width
;
1488 case Corner_BottomLeft
:
1489 y
-= h
- self
->area
.height
;
1491 case Corner_BottomRight
:
1492 x
-= w
- self
->area
.width
;
1493 y
-= h
- self
->area
.height
;
1497 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1498 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1500 RECT_SET(self
->area
, x
, y
, w
, h
);
1503 XResizeWindow(ob_display
, self
->window
, w
, h
);
1505 /* move/resize the frame to match the request */
1507 if (moved
|| resized
)
1508 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1510 if (!user
|| final
) {
1512 event
.type
= ConfigureNotify
;
1513 event
.xconfigure
.display
= ob_display
;
1514 event
.xconfigure
.event
= self
->window
;
1515 event
.xconfigure
.window
= self
->window
;
1517 /* root window coords with border in mind */
1518 event
.xconfigure
.x
= x
- self
->border_width
+
1519 self
->frame
->size
.left
;
1520 event
.xconfigure
.y
= y
- self
->border_width
+
1521 self
->frame
->size
.top
;
1523 event
.xconfigure
.width
= self
->area
.width
;
1524 event
.xconfigure
.height
= self
->area
.height
;
1525 event
.xconfigure
.border_width
= self
->border_width
;
1526 event
.xconfigure
.above
= self
->frame
->plate
;
1527 event
.xconfigure
.override_redirect
= FALSE
;
1528 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1529 FALSE
, StructureNotifyMask
, &event
);
1534 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1538 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1539 self
->fullscreen
== fs
) return; /* already done */
1541 self
->fullscreen
= fs
;
1542 client_change_state(self
); /* change the state hints on the client */
1545 /* save the functions and remove them */
1546 self
->pre_fs_func
= self
->functions
;
1547 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1549 /* save the decorations and remove them */
1550 self
->pre_fs_decor
= self
->decorations
;
1551 self
->decorations
= 0;
1554 dimensions
[0] = self
->area
.x
;
1555 dimensions
[1] = self
->area
.y
;
1556 dimensions
[2] = self
->area
.width
;
1557 dimensions
[3] = self
->area
.height
;
1559 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1563 /* these are not actually used cuz client_configure will set them
1564 as appropriate when the window is fullscreened */
1569 self
->functions
= self
->pre_fs_func
;
1570 self
->decorations
= self
->pre_fs_decor
;
1572 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1580 /* pick some fallbacks... */
1581 x
= screen_area(self
->desktop
)->x
+
1582 screen_area(self
->desktop
)->width
/ 4;
1583 y
= screen_area(self
->desktop
)->y
+
1584 screen_area(self
->desktop
)->height
/ 4;
1585 w
= screen_area(self
->desktop
)->width
/ 2;
1586 h
= screen_area(self
->desktop
)->height
/ 2;
1590 client_change_allowed_actions(self
); /* based on the new _functions */
1592 /* when fullscreening, don't obey things like increments, fill the
1594 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1596 /* raise (back) into our stacking layer */
1597 stacking_raise(self
);
1599 /* try focus us when we go into fullscreen mode */
1603 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1605 if (self
->iconic
== iconic
) return; /* nothing to do */
1607 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1610 self
->iconic
= iconic
;
1613 self
->wmstate
= IconicState
;
1614 self
->ignore_unmaps
++;
1615 /* we unmap the client itself so that we can get MapRequest events,
1616 and because the ICCCM tells us to! */
1617 XUnmapWindow(ob_display
, self
->window
);
1620 client_set_desktop(self
, screen_desktop
, FALSE
);
1621 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1622 XMapWindow(ob_display
, self
->window
);
1624 client_change_state(self
);
1625 client_showhide(self
);
1626 screen_update_struts();
1628 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1631 /* iconify all transients */
1632 if (self
->transients
) {
1635 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1636 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1640 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1644 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1645 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1647 /* check if already done */
1649 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1650 if (dir
== 1 && self
->max_horz
) return;
1651 if (dir
== 2 && self
->max_vert
) return;
1653 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1654 if (dir
== 1 && !self
->max_horz
) return;
1655 if (dir
== 2 && !self
->max_vert
) return;
1658 /* work with the frame's coords */
1659 x
= self
->frame
->area
.x
;
1660 y
= self
->frame
->area
.y
;
1661 w
= self
->area
.width
;
1662 h
= self
->area
.height
;
1674 /* get the property off the window and use it for the dimensions
1675 we are already maxed on */
1676 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1678 if (self
->max_horz
) {
1679 dimensions
[0] = readdim
[0];
1680 dimensions
[2] = readdim
[2];
1682 if (self
->max_vert
) {
1683 dimensions
[1] = readdim
[1];
1684 dimensions
[3] = readdim
[3];
1689 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1695 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1697 if (dir
== 0 || dir
== 1) { /* horz */
1701 if (dir
== 0 || dir
== 2) { /* vert */
1707 /* pick some fallbacks... */
1708 if (dir
== 0 || dir
== 1) { /* horz */
1709 x
= screen_area(self
->desktop
)->x
+
1710 screen_area(self
->desktop
)->width
/ 4;
1711 w
= screen_area(self
->desktop
)->width
/ 2;
1713 if (dir
== 0 || dir
== 2) { /* vert */
1714 y
= screen_area(self
->desktop
)->y
+
1715 screen_area(self
->desktop
)->height
/ 4;
1716 h
= screen_area(self
->desktop
)->height
/ 2;
1721 if (dir
== 0 || dir
== 1) /* horz */
1722 self
->max_horz
= max
;
1723 if (dir
== 0 || dir
== 2) /* vert */
1724 self
->max_vert
= max
;
1726 if (!self
->max_horz
&& !self
->max_vert
)
1727 PROP_ERASE(self
->window
, openbox_premax
);
1729 client_change_state(self
); /* change the state hints on the client */
1731 /* figure out where the client should be going */
1732 frame_frame_gravity(self
->frame
, &x
, &y
);
1733 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1736 void client_shade(Client
*self
, gboolean shade
)
1738 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1739 self
->shaded
== shade
) return; /* already done */
1741 /* when we're iconic, don't change the wmstate */
1743 self
->wmstate
= shade
? IconicState
: NormalState
;
1744 self
->shaded
= shade
;
1745 client_change_state(self
);
1746 /* resize the frame to just the titlebar */
1747 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1750 void client_close(Client
*self
)
1754 if (!(self
->functions
& Func_Close
)) return;
1757 XXX: itd be cool to do timeouts and shit here for killing the client's
1759 like... if the window is around after 5 seconds, then the close button
1760 turns a nice red, and if this function is called again, the client is
1764 ce
.xclient
.type
= ClientMessage
;
1765 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1766 ce
.xclient
.display
= ob_display
;
1767 ce
.xclient
.window
= self
->window
;
1768 ce
.xclient
.format
= 32;
1769 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1770 ce
.xclient
.data
.l
[1] = event_lasttime
;
1771 ce
.xclient
.data
.l
[2] = 0l;
1772 ce
.xclient
.data
.l
[3] = 0l;
1773 ce
.xclient
.data
.l
[4] = 0l;
1774 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1777 void client_kill(Client
*self
)
1779 XKillClient(ob_display
, self
->window
);
1782 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1786 if (target
== self
->desktop
) return;
1788 g_message("Setting desktop %u", target
);
1790 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1792 old
= self
->desktop
;
1793 self
->desktop
= target
;
1794 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1795 /* the frame can display the current desktop state */
1796 engine_frame_adjust_state(self
->frame
);
1797 /* 'move' the window to the new desktop */
1799 client_showhide(self
);
1800 /* raise if it was not already on the desktop */
1801 if (old
!= DESKTOP_ALL
)
1802 stacking_raise(self
);
1803 screen_update_struts();
1805 /* update the focus lists */
1806 if (old
== DESKTOP_ALL
) {
1807 for (i
= 0; i
< screen_num_desktops
; ++i
)
1808 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1810 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1811 if (target
== DESKTOP_ALL
) {
1812 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1814 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1816 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1820 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1822 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1825 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1828 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1833 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1834 Client
*c
= it
->data
;
1835 if (c
== skip
) continue; /* circular? */
1836 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1837 if (c
->modal
) return c
;
1842 Client
*client_find_modal_child(Client
*self
)
1844 return search_modal_tree(self
, self
);
1847 gboolean
client_validate(Client
*self
)
1851 XSync(ob_display
, FALSE
); /* get all events on the server */
1853 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1854 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1855 XPutBackEvent(ob_display
, &e
);
1862 void client_set_wm_state(Client
*self
, long state
)
1864 if (state
== self
->wmstate
) return; /* no change */
1868 client_iconify(self
, TRUE
, TRUE
);
1871 client_iconify(self
, FALSE
, TRUE
);
1876 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1878 gboolean shaded
= self
->shaded
;
1879 gboolean fullscreen
= self
->fullscreen
;
1880 gboolean max_horz
= self
->max_horz
;
1881 gboolean max_vert
= self
->max_vert
;
1884 if (!(action
== prop_atoms
.net_wm_state_add
||
1885 action
== prop_atoms
.net_wm_state_remove
||
1886 action
== prop_atoms
.net_wm_state_toggle
))
1887 /* an invalid action was passed to the client message, ignore it */
1890 for (i
= 0; i
< 2; ++i
) {
1891 Atom state
= i
== 0 ? data1
: data2
;
1893 if (!state
) continue;
1895 /* if toggling, then pick whether we're adding or removing */
1896 if (action
== prop_atoms
.net_wm_state_toggle
) {
1897 if (state
== prop_atoms
.net_wm_state_modal
)
1898 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1899 prop_atoms
.net_wm_state_add
;
1900 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1901 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1902 prop_atoms
.net_wm_state_add
;
1903 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1904 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1905 prop_atoms
.net_wm_state_add
;
1906 else if (state
== prop_atoms
.net_wm_state_shaded
)
1907 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1908 prop_atoms
.net_wm_state_add
;
1909 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1910 action
= self
->skip_taskbar
?
1911 prop_atoms
.net_wm_state_remove
:
1912 prop_atoms
.net_wm_state_add
;
1913 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1914 action
= self
->skip_pager
?
1915 prop_atoms
.net_wm_state_remove
:
1916 prop_atoms
.net_wm_state_add
;
1917 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1918 action
= self
->fullscreen
?
1919 prop_atoms
.net_wm_state_remove
:
1920 prop_atoms
.net_wm_state_add
;
1921 else if (state
== prop_atoms
.net_wm_state_above
)
1922 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1923 prop_atoms
.net_wm_state_add
;
1924 else if (state
== prop_atoms
.net_wm_state_below
)
1925 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1926 prop_atoms
.net_wm_state_add
;
1929 if (action
== prop_atoms
.net_wm_state_add
) {
1930 if (state
== prop_atoms
.net_wm_state_modal
) {
1931 /* XXX raise here or something? */
1933 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1935 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1937 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1939 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1940 self
->skip_taskbar
= TRUE
;
1941 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1942 self
->skip_pager
= TRUE
;
1943 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1945 } else if (state
== prop_atoms
.net_wm_state_above
) {
1947 } else if (state
== prop_atoms
.net_wm_state_below
) {
1951 } else { /* action == prop_atoms.net_wm_state_remove */
1952 if (state
== prop_atoms
.net_wm_state_modal
) {
1953 self
->modal
= FALSE
;
1954 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1956 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1958 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1960 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1961 self
->skip_taskbar
= FALSE
;
1962 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1963 self
->skip_pager
= FALSE
;
1964 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1966 } else if (state
== prop_atoms
.net_wm_state_above
) {
1967 self
->above
= FALSE
;
1968 } else if (state
== prop_atoms
.net_wm_state_below
) {
1969 self
->below
= FALSE
;
1973 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1974 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1976 if (max_horz
== max_vert
) { /* both going the same way */
1977 client_maximize(self
, max_horz
, 0, TRUE
);
1979 client_maximize(self
, max_horz
, 1, TRUE
);
1980 client_maximize(self
, max_vert
, 2, TRUE
);
1984 if (max_horz
!= self
->max_horz
)
1985 client_maximize(self
, max_horz
, 1, TRUE
);
1987 client_maximize(self
, max_vert
, 2, TRUE
);
1990 /* change fullscreen state before shading, as it will affect if the window
1992 if (fullscreen
!= self
->fullscreen
)
1993 client_fullscreen(self
, fullscreen
, TRUE
);
1994 if (shaded
!= self
->shaded
)
1995 client_shade(self
, shaded
);
1996 client_calc_layer(self
);
1997 client_change_state(self
); /* change the hint to relect these changes */
2000 Client
*client_focus_target(Client
*self
)
2004 /* if we have a modal child, then focus it, not us */
2005 child
= client_find_modal_child(self
);
2006 if (child
) return child
;
2010 gboolean
client_focusable(Client
*self
)
2012 /* won't try focus if the client doesn't want it, or if the window isn't
2013 visible on the screen */
2014 return self
->frame
->visible
&&
2015 (self
->can_focus
|| self
->focus_notify
);
2018 gboolean
client_focus(Client
*self
)
2022 /* choose the correct target */
2023 self
= client_focus_target(self
);
2025 if (!client_focusable(self
))
2028 /* do a check to see if the window has already been unmapped or destroyed
2029 do this intelligently while watching out for unmaps we've generated
2030 (ignore_unmaps > 0) */
2031 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2032 DestroyNotify
, &ev
)) {
2033 XPutBackEvent(ob_display
, &ev
);
2036 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2037 UnmapNotify
, &ev
)) {
2038 if (self
->ignore_unmaps
) {
2039 self
->ignore_unmaps
--;
2041 XPutBackEvent(ob_display
, &ev
);
2046 if (self
->can_focus
)
2047 /* RevertToPointerRoot causes much more headache than TevertToNone, so
2048 I choose to use it always, hopefully to find errors quicker, if any
2049 are left. (I hate X. I hate focus events.) */
2050 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2053 if (self
->focus_notify
) {
2055 ce
.xclient
.type
= ClientMessage
;
2056 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2057 ce
.xclient
.display
= ob_display
;
2058 ce
.xclient
.window
= self
->window
;
2059 ce
.xclient
.format
= 32;
2060 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2061 ce
.xclient
.data
.l
[1] = event_lasttime
;
2062 ce
.xclient
.data
.l
[2] = 0l;
2063 ce
.xclient
.data
.l
[3] = 0l;
2064 ce
.xclient
.data
.l
[4] = 0l;
2065 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2069 g_message("focusing %lx", self
->window
);
2072 /* Cause the FocusIn to come back to us. Important for desktop switches,
2073 since otherwise we'll have no FocusIn on the queue and send it off to
2074 the focus_backup. */
2075 XSync(ob_display
, FALSE
);
2079 void client_unfocus(Client
*self
)
2081 g_assert(focus_client
== self
);
2082 g_message("client_unfocus");
2083 focus_fallback(Fallback_Unfocusing
);
2086 gboolean
client_focused(Client
*self
)
2088 return self
== focus_client
;
2091 Icon
*client_icon(Client
*self
, int w
, int h
)
2094 /* si is the smallest image >= req */
2095 /* li is the largest image < req */
2096 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2098 if (!self
->nicons
) return NULL
;
2100 for (i
= 0; i
< self
->nicons
; ++i
) {
2101 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2102 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2106 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2111 if (largest
== 0) /* didnt find one smaller than the requested size */
2112 return &self
->icons
[si
];
2113 return &self
->icons
[li
];