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(FALSE
);
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! *\/
186 /* choose the events we want to receive on the CLIENT window */
187 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
188 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
189 XChangeWindowAttributes(ob_display
, window
,
190 CWEventMask
|CWDontPropagate
, &attrib_set
);
193 /* create the Client struct, and populate it from the hints on the
195 self
= g_new(Client
, 1);
196 self
->window
= window
;
197 client_get_all(self
);
199 /* remove the client's border (and adjust re gravity) */
200 client_toggle_border(self
, FALSE
);
202 /* specify that if we exit, the window should not be destroyed and should
203 be reparented back to root automatically */
204 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
206 /* create the decoration frame for the client window */
207 self
->frame
= engine_frame_new();
209 engine_frame_grab_client(self
->frame
, self
);
211 client_apply_startup_state(self
);
215 client_list
= g_list_append(client_list
, self
);
216 stacking_list
= g_list_append(stacking_list
, self
);
217 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
218 g_hash_table_insert(client_map
, &self
->window
, self
);
220 /* update the focus lists */
221 if (self
->desktop
== DESKTOP_ALL
) {
222 for (i
= 0; i
< screen_num_desktops
; ++i
)
223 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
226 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
229 stacking_raise(self
);
231 screen_update_struts();
233 dispatch_client(Event_Client_New
, self
, 0, 0);
235 client_showhide(self
);
237 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
239 if (ob_state
!= State_Starting
&& focus_new
)
242 /* update the list hints */
245 /* make sure the window is visible */
246 client_move_onscreen(self
);
248 /* g_message("Managed window 0x%lx", window);*/
251 void client_unmanage_all()
253 while (client_list
!= NULL
)
254 client_unmanage(client_list
->data
);
257 void client_unmanage(Client
*self
)
263 /* g_message("Unmanaging window: %lx", self->window);*/
265 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
266 g_assert(self
!= NULL
);
268 /* remove the window from our save set */
269 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
271 /* we dont want events no more */
272 XSelectInput(ob_display
, self
->window
, NoEventMask
);
274 engine_frame_hide(self
->frame
);
276 client_list
= g_list_remove(client_list
, self
);
277 stacking_list
= g_list_remove(stacking_list
, self
);
278 g_hash_table_remove(client_map
, &self
->window
);
280 /* update the focus lists */
281 if (self
->desktop
== DESKTOP_ALL
) {
282 for (i
= 0; i
< screen_num_desktops
; ++i
)
283 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
286 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
289 /* once the client is out of the list, update the struts to remove it's
291 screen_update_struts();
293 /* tell our parent(s) that we're gone */
294 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
297 for (it
= self
->group
->members
; it
; it
= it
->next
)
298 if (it
->data
!= self
)
299 ((Client
*)it
->data
)->transients
=
300 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
301 } else if (self
->transient_for
) { /* transient of window */
302 self
->transient_for
->transients
=
303 g_slist_remove(self
->transient_for
->transients
, self
);
306 /* tell our transients that we're gone */
307 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
308 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
309 ((Client
*)it
->data
)->transient_for
= NULL
;
310 client_calc_layer(it
->data
);
314 /* remove from its group */
316 group_remove(self
->group
, self
);
320 /* dispatch the unmapped event */
321 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
322 g_assert(self
!= NULL
);
324 /* give the client its border back */
325 client_toggle_border(self
, TRUE
);
327 /* reparent the window out of the frame, and free the frame */
328 engine_frame_release_client(self
->frame
, self
);
331 if (ob_state
!= State_Exiting
) {
332 /* these values should not be persisted across a window
334 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
335 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
337 /* if we're left in an iconic state, the client wont be mapped. this is
338 bad, since we will no longer be managing the window on restart */
340 XMapWindow(ob_display
, self
->window
);
343 /* free all data allocated in the client struct */
344 g_slist_free(self
->transients
);
345 for (j
= 0; j
< self
->nicons
; ++j
)
346 g_free(self
->icons
[j
].data
);
347 if (self
->nicons
> 0)
350 g_free(self
->icon_title
);
356 /* update the list hints */
360 static void client_move_onscreen(Client
*self
)
363 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
365 a
= screen_area(self
->desktop
);
366 if (x
>= a
->x
+ a
->width
- 1)
367 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
368 if (y
>= a
->y
+ a
->height
- 1)
369 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
370 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
372 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
375 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
377 client_configure(self
, Corner_TopLeft
, x
, y
,
378 self
->area
.width
, self
->area
.height
,
382 static void client_toggle_border(Client
*self
, gboolean show
)
384 /* adjust our idea of where the client is, based on its border. When the
385 border is removed, the client should now be considered to be in a
387 when re-adding the border to the client, the same operation needs to be
389 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
390 int x
= oldx
, y
= oldy
;
391 switch(self
->gravity
) {
393 case NorthWestGravity
:
395 case SouthWestGravity
:
397 case NorthEastGravity
:
399 case SouthEastGravity
:
400 if (show
) x
-= self
->border_width
* 2;
401 else x
+= self
->border_width
* 2;
408 if (show
) x
-= self
->border_width
;
409 else x
+= self
->border_width
;
412 switch(self
->gravity
) {
414 case NorthWestGravity
:
416 case NorthEastGravity
:
418 case SouthWestGravity
:
420 case SouthEastGravity
:
421 if (show
) y
-= self
->border_width
* 2;
422 else y
+= self
->border_width
* 2;
429 if (show
) y
-= self
->border_width
;
430 else y
+= self
->border_width
;
437 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
439 /* move the client so it is back it the right spot _with_ its
441 if (x
!= oldx
|| y
!= oldy
)
442 XMoveWindow(ob_display
, self
->window
, x
, y
);
444 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
448 static void client_get_all(Client
*self
)
450 /* update EVERYTHING!! */
452 self
->ignore_unmaps
= 0;
456 self
->title
= self
->icon_title
= NULL
;
457 self
->name
= self
->class = self
->role
= NULL
;
458 self
->wmstate
= NormalState
;
459 self
->transient
= FALSE
;
460 self
->transients
= NULL
;
461 self
->transient_for
= NULL
;
463 self
->urgent
= FALSE
;
464 self
->positioned
= FALSE
;
465 self
->disabled_decorations
= 0;
469 client_get_area(self
);
470 client_get_desktop(self
);
471 client_get_state(self
);
472 client_get_shaped(self
);
474 client_update_transient_for(self
);
475 client_get_mwm_hints(self
);
476 client_get_type(self
);/* this can change the mwmhints for special cases */
478 client_update_protocols(self
);
480 client_get_gravity(self
); /* get the attribute gravity */
481 client_update_normal_hints(self
); /* this may override the attribute
484 /* got the type, the mwmhints, the protocols, and the normal hints
485 (min/max sizes), so we're ready to set up the decorations/functions */
486 client_setup_decor_and_functions(self
);
488 client_update_wmhints(self
);
489 client_update_title(self
);
490 client_update_icon_title(self
);
491 client_update_class(self
);
492 client_update_strut(self
);
493 client_update_icons(self
);
494 client_update_kwm_icon(self
);
496 /* this makes sure that these windows appear on all desktops */
497 if (self
->type
== Type_Desktop
)
498 self
->desktop
= DESKTOP_ALL
;
500 /* set the desktop hint, to make sure that it always exists, and to
501 reflect any changes we've made here */
502 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
504 client_change_state(self
);
507 static void client_get_area(Client
*self
)
509 XWindowAttributes wattrib
;
512 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
513 g_assert(ret
!= BadWindow
);
515 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
516 self
->border_width
= wattrib
.border_width
;
519 static void client_get_desktop(Client
*self
)
523 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
524 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
525 d
= screen_num_desktops
- 1;
528 /* defaults to the current desktop */
529 self
->desktop
= screen_desktop
;
533 static void client_get_state(Client
*self
)
538 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
539 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
540 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
542 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
544 for (i
= 0; i
< num
; ++i
) {
545 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
547 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
549 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
551 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
552 self
->skip_taskbar
= TRUE
;
553 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
554 self
->skip_pager
= TRUE
;
555 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
556 self
->fullscreen
= TRUE
;
557 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
558 self
->max_vert
= TRUE
;
559 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
560 self
->max_horz
= TRUE
;
561 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
563 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
571 static void client_get_shaped(Client
*self
)
573 self
->shaped
= FALSE
;
575 if (extensions_shape
) {
580 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
582 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
583 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
585 self
->shaped
= (s
!= 0);
590 void client_update_transient_for(Client
*self
)
595 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
596 t
!= self
->window
) { /* cant be transient to itself! */
597 self
->transient
= TRUE
;
598 c
= g_hash_table_lookup(client_map
, &t
);
599 g_assert(c
!= self
);/* if this happens then we need to check for it*/
601 if (!c
&& self
->group
) {
602 /* not transient to a client, see if it is transient for a
604 if (t
== self
->group
->leader
||
607 /* window is a transient for its group! */
612 self
->transient
= FALSE
;
614 /* if anything has changed... */
615 if (c
!= self
->transient_for
) {
616 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
619 /* remove from old parents */
620 for (it
= self
->group
->members
; it
; it
= it
->next
)
621 if (it
->data
!= self
)
622 ((Client
*)it
->data
)->transients
=
623 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
624 } else if (self
->transient_for
!= NULL
) { /* transient of window */
625 /* remove from old parent */
626 self
->transient_for
->transients
=
627 g_slist_remove(self
->transient_for
->transients
, self
);
629 self
->transient_for
= c
;
630 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
633 /* add to new parents */
634 for (it
= self
->group
->members
; it
; it
= it
->next
)
635 if (it
->data
!= self
)
636 ((Client
*)it
->data
)->transients
=
637 g_slist_append(((Client
*)it
->data
)->transients
, self
);
638 } else if (self
->transient_for
!= NULL
) { /* transient of window */
639 /* add to new parent */
640 self
->transient_for
->transients
=
641 g_slist_append(self
->transient_for
->transients
, self
);
646 static void client_get_mwm_hints(Client
*self
)
649 unsigned long *hints
;
651 self
->mwmhints
.flags
= 0; /* default to none */
653 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
654 if (num
>= MWM_ELEMENTS
) {
655 self
->mwmhints
.flags
= hints
[0];
656 self
->mwmhints
.functions
= hints
[1];
657 self
->mwmhints
.decorations
= hints
[2];
663 void client_get_type(Client
*self
)
669 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
670 /* use the first value that we know about in the array */
671 for (i
= 0; i
< num
; ++i
) {
672 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
673 self
->type
= Type_Desktop
;
674 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
675 self
->type
= Type_Dock
;
676 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
677 self
->type
= Type_Toolbar
;
678 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
679 self
->type
= Type_Menu
;
680 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
681 self
->type
= Type_Utility
;
682 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
683 self
->type
= Type_Splash
;
684 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
685 self
->type
= Type_Dialog
;
686 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
687 self
->type
= Type_Normal
;
688 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
689 /* prevent this window from getting any decor or
691 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
692 MwmFlag_Decorations
);
693 self
->mwmhints
.decorations
= 0;
694 self
->mwmhints
.functions
= 0;
696 if (self
->type
!= (WindowType
) -1)
697 break; /* grab the first legit type */
702 if (self
->type
== (WindowType
) -1) {
703 /*the window type hint was not set, which means we either classify
704 ourself as a normal window or a dialog, depending on if we are a
707 self
->type
= Type_Dialog
;
709 self
->type
= Type_Normal
;
713 void client_update_protocols(Client
*self
)
716 gulong num_return
, i
;
718 self
->focus_notify
= FALSE
;
719 self
->delete_window
= FALSE
;
721 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
722 for (i
= 0; i
< num_return
; ++i
) {
723 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
724 /* this means we can request the window to close */
725 self
->delete_window
= TRUE
;
726 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
727 /* if this protocol is requested, then the window will be
728 notified whenever we want it to receive focus */
729 self
->focus_notify
= TRUE
;
735 static void client_get_gravity(Client
*self
)
737 XWindowAttributes wattrib
;
740 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
741 g_assert(ret
!= BadWindow
);
742 self
->gravity
= wattrib
.win_gravity
;
745 void client_update_normal_hints(Client
*self
)
749 int oldgravity
= self
->gravity
;
752 self
->min_ratio
= 0.0f
;
753 self
->max_ratio
= 0.0f
;
754 SIZE_SET(self
->size_inc
, 1, 1);
755 SIZE_SET(self
->base_size
, 0, 0);
756 SIZE_SET(self
->min_size
, 0, 0);
757 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
759 /* get the hints from the window */
760 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
761 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
763 if (size
.flags
& PWinGravity
) {
764 self
->gravity
= size
.win_gravity
;
766 /* if the client has a frame, i.e. has already been mapped and
767 is changing its gravity */
768 if (self
->frame
&& self
->gravity
!= oldgravity
) {
769 /* move our idea of the client's position based on its new
771 self
->area
.x
= self
->frame
->area
.x
;
772 self
->area
.y
= self
->frame
->area
.y
;
773 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
777 if (size
.flags
& PAspect
) {
778 if (size
.min_aspect
.y
)
779 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
780 if (size
.max_aspect
.y
)
781 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
784 if (size
.flags
& PMinSize
)
785 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
787 if (size
.flags
& PMaxSize
)
788 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
790 if (size
.flags
& PBaseSize
)
791 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
793 if (size
.flags
& PResizeInc
)
794 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
798 void client_setup_decor_and_functions(Client
*self
)
800 /* start with everything (cept fullscreen) */
801 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
802 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
804 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
806 if (self
->delete_window
) {
807 self
->decorations
|= Decor_Close
;
808 self
->functions
|= Func_Close
;
811 if (!(self
->min_size
.width
< self
->max_size
.width
||
812 self
->min_size
.height
< self
->max_size
.height
)) {
813 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
814 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
817 switch (self
->type
) {
819 /* normal windows retain all of the possible decorations and
820 functionality, and are the only windows that you can fullscreen */
821 self
->functions
|= Func_Fullscreen
;
825 /* dialogs cannot be maximized */
826 self
->decorations
&= ~Decor_Maximize
;
827 self
->functions
&= ~Func_Maximize
;
833 /* these windows get less functionality */
834 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
835 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
841 /* none of these windows are manipulated by the window manager */
842 self
->decorations
= 0;
847 /* Mwm Hints are applied subtractively to what has already been chosen for
848 decor and functionality */
849 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
850 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
851 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
852 self
->decorations
&= ~Decor_Border
;
853 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
854 self
->decorations
&= ~Decor_Handle
;
855 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
856 self
->decorations
&= ~Decor_Titlebar
;
857 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
858 self
->decorations
&= ~Decor_Iconify
;
859 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
860 self
->decorations
&= ~Decor_Maximize
;
864 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
865 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
866 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
867 self
->functions
&= ~Func_Resize
;
868 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
869 self
->functions
&= ~Func_Move
;
870 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
871 self
->functions
&= ~Func_Iconify
;
872 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
873 self
->functions
&= ~Func_Maximize
;
874 /* dont let mwm hints kill the close button
875 if (! (self->mwmhints.functions & MwmFunc_Close))
876 self->functions &= ~Func_Close; */
880 /* can't maximize without moving/resizing */
881 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
882 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
884 /* finally, user specified disabled decorations are applied to subtract
886 if (self
->disabled_decorations
& Decor_Titlebar
)
887 self
->decorations
&= ~Decor_Titlebar
;
888 if (self
->disabled_decorations
& Decor_Handle
)
889 self
->decorations
&= ~Decor_Handle
;
890 if (self
->disabled_decorations
& Decor_Border
)
891 self
->decorations
&= ~Decor_Border
;
892 if (self
->disabled_decorations
& Decor_Iconify
)
893 self
->decorations
&= ~Decor_Iconify
;
894 if (self
->disabled_decorations
& Decor_Maximize
)
895 self
->decorations
&= ~Decor_Maximize
;
896 if (self
->disabled_decorations
& Decor_AllDesktops
)
897 self
->decorations
&= ~Decor_AllDesktops
;
898 if (self
->disabled_decorations
& Decor_Shade
)
899 self
->decorations
&= ~Decor_Shade
;
900 if (self
->disabled_decorations
& Decor_Close
)
901 self
->decorations
&= ~Decor_Close
;
903 /* if we don't have a titlebar, then we cannot shade! */
904 if (!(self
->decorations
& Decor_Titlebar
))
905 self
->functions
&= ~Func_Shade
;
907 client_change_allowed_actions(self
);
910 /* change the decors on the frame, and with more/less decorations,
911 we may also need to be repositioned */
912 engine_frame_adjust_area(self
->frame
, TRUE
, TRUE
);
913 /* with new decor, the window's maximized size may change */
914 client_remaximize(self
);
918 static void client_change_allowed_actions(Client
*self
)
923 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
925 if (self
->functions
& Func_Shade
)
926 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
927 if (self
->functions
& Func_Close
)
928 actions
[num
++] = prop_atoms
.net_wm_action_close
;
929 if (self
->functions
& Func_Move
)
930 actions
[num
++] = prop_atoms
.net_wm_action_move
;
931 if (self
->functions
& Func_Iconify
)
932 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
933 if (self
->functions
& Func_Resize
)
934 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
935 if (self
->functions
& Func_Fullscreen
)
936 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
937 if (self
->functions
& Func_Maximize
) {
938 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
939 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
942 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
944 /* make sure the window isn't breaking any rules now */
946 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
947 if (self
->frame
) client_shade(self
, FALSE
);
948 else self
->shaded
= FALSE
;
950 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
951 g_message("UNSETTING ICONIC");
952 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
953 else self
->iconic
= FALSE
;
955 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
956 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
957 else self
->fullscreen
= FALSE
;
959 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
961 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
962 else self
->max_vert
= self
->max_horz
= FALSE
;
966 void client_remaximize(Client
*self
)
969 if (self
->max_horz
&& self
->max_vert
)
971 else if (self
->max_horz
)
973 else if (self
->max_vert
)
976 return; /* not maximized */
977 self
->max_horz
= self
->max_vert
= FALSE
;
978 client_maximize(self
, TRUE
, dir
, FALSE
);
981 void client_update_wmhints(Client
*self
)
986 /* assume a window takes input if it doesnt specify */
987 self
->can_focus
= TRUE
;
989 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
990 if (hints
->flags
& InputHint
)
991 self
->can_focus
= hints
->input
;
993 /* only do this when first managing the window *AND* when we aren't
995 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
996 if (hints
->flags
& StateHint
)
997 self
->iconic
= hints
->initial_state
== IconicState
;
999 if (hints
->flags
& XUrgencyHint
)
1002 if (!(hints
->flags
& WindowGroupHint
))
1003 hints
->window_group
= None
; /* no group */
1004 /* did the group state change? */
1005 if (hints
->window_group
!= (self
->group
? self
->group
->leader
: None
)){
1006 /* remove from the old group if there was one */
1007 if (self
->group
!= NULL
)
1008 group_remove(self
->group
, self
);
1009 if (hints
->window_group
!= None
)
1010 self
->group
= group_add(hints
->window_group
, self
);
1012 /* because the self->transient flag wont change from this call,
1013 we don't need to update the window's type and such, only its
1014 transient_for, and the transients lists of other windows in the
1015 group may be affected */
1016 client_update_transient_for(self
);
1019 if (hints
->flags
& IconPixmapHint
) {
1020 client_update_kwm_icon(self
);
1021 /* try get the kwm icon first, this is a fallback only */
1022 if (self
->pixmap_icon
== None
) {
1023 self
->pixmap_icon
= hints
->icon_pixmap
;
1024 if (hints
->flags
& IconMaskHint
)
1025 self
->pixmap_icon_mask
= hints
->icon_mask
;
1027 self
->pixmap_icon_mask
= None
;
1030 engine_frame_adjust_icon(self
->frame
);
1037 if (ur
!= self
->urgent
) {
1039 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1041 /* fire the urgent callback if we're mapped, otherwise, wait until
1042 after we're mapped */
1044 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1048 void client_update_title(Client
*self
)
1052 g_free(self
->title
);
1055 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
1056 /* try old x stuff */
1057 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
1058 /* convert it to UTF-8 */
1062 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1064 g_warning("Unable to convert string to UTF-8");
1071 data
= g_strdup("Unnamed Window");
1073 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1079 engine_frame_adjust_title(self
->frame
);
1082 void client_update_icon_title(Client
*self
)
1086 g_free(self
->icon_title
);
1089 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1090 /* try old x stuff */
1091 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1092 /* convert it to UTF-8 */
1096 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1098 g_warning("Unable to convert string to UTF-8");
1105 data
= g_strdup("Unnamed Window");
1107 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1110 self
->icon_title
= data
;
1113 void client_update_class(Client
*self
)
1119 if (self
->name
) g_free(self
->name
);
1120 if (self
->class) g_free(self
->class);
1121 if (self
->role
) g_free(self
->role
);
1123 self
->name
= self
->class = self
->role
= NULL
;
1125 data
= g_ptr_array_new();
1127 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1129 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1131 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1134 for (i
= 0; i
< data
->len
; ++i
)
1135 g_free(g_ptr_array_index(data
, i
));
1136 g_ptr_array_free(data
, TRUE
);
1138 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1139 self
->role
= g_strdup(s
);
1141 if (self
->name
== NULL
) self
->name
= g_strdup("");
1142 if (self
->class == NULL
) self
->class = g_strdup("");
1143 if (self
->role
== NULL
) self
->role
= g_strdup("");
1146 void client_update_strut(Client
*self
)
1150 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1151 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1154 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1156 /* updating here is pointless while we're being mapped cuz we're not in
1157 the client list yet */
1159 screen_update_struts();
1162 void client_update_icons(Client
*self
)
1165 unsigned long *data
;
1166 unsigned long w
, h
, i
;
1169 for (j
= 0; j
< self
->nicons
; ++j
)
1170 g_free(self
->icons
[j
].data
);
1171 if (self
->nicons
> 0)
1172 g_free(self
->icons
);
1175 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1176 /* figure out how many valid icons are in here */
1178 while (num
- i
> 2) {
1186 self
->icons
= g_new(Icon
, self
->nicons
);
1188 /* store the icons */
1190 for (j
= 0; j
< self
->nicons
; ++j
) {
1191 w
= self
->icons
[j
].width
= data
[i
++];
1192 h
= self
->icons
[j
].height
= data
[i
++];
1193 self
->icons
[j
].data
=
1194 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1203 engine_frame_adjust_icon(self
->frame
);
1206 void client_update_kwm_icon(Client
*self
)
1210 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1211 self
->pixmap_icon
= data
[0];
1212 self
->pixmap_icon_mask
= data
[1];
1215 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1218 engine_frame_adjust_icon(self
->frame
);
1221 static void client_change_state(Client
*self
)
1223 unsigned long state
[2];
1227 state
[0] = self
->wmstate
;
1229 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1233 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1235 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1237 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1238 if (self
->skip_taskbar
)
1239 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1240 if (self
->skip_pager
)
1241 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1242 if (self
->fullscreen
)
1243 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1245 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1247 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1249 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1251 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1252 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1254 client_calc_layer(self
);
1257 engine_frame_adjust_state(self
->frame
);
1260 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1265 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1266 Client
*c
= it
->data
;
1267 if (c
== skip
) continue; /* circular? */
1268 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1269 if (client_focused(c
)) return c
;
1274 void client_calc_layer(Client
*self
)
1280 /* are we fullscreen, or do we have a fullscreen transient parent? */
1283 while (c
&& c
!= TRAN_GROUP
) { /* XXX do smthng with the TRAN_GROUP case?*/
1284 if (c
->fullscreen
) {
1288 c
= c
->transient_for
;
1290 if (!fs
&& self
->fullscreen
) {
1291 /* is one of our transients focused? */
1292 c
= search_focus_tree(self
, self
);
1293 if (c
!= NULL
) fs
= TRUE
;
1296 if (self
->iconic
) l
= Layer_Icon
;
1297 else if (fs
) l
= Layer_Fullscreen
;
1298 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1299 else if (self
->type
== Type_Dock
) {
1300 if (!self
->below
) l
= Layer_Top
;
1301 else l
= Layer_Normal
;
1303 else if (self
->above
) l
= Layer_Above
;
1304 else if (self
->below
) l
= Layer_Below
;
1305 else l
= Layer_Normal
;
1307 if (l
!= self
->layer
) {
1310 stacking_raise(self
);
1314 gboolean
client_should_show(Client
*self
)
1316 if (self
->iconic
) return FALSE
;
1317 else if (!(self
->desktop
== screen_desktop
||
1318 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1319 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1324 static void client_showhide(Client
*self
)
1327 if (client_should_show(self
))
1328 engine_frame_show(self
->frame
);
1330 engine_frame_hide(self
->frame
);
1333 gboolean
client_normal(Client
*self
) {
1334 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1335 self
->type
== Type_Splash
);
1338 static void client_apply_startup_state(Client
*self
)
1340 /* these are in a carefully crafted order.. */
1343 self
->iconic
= FALSE
;
1344 client_iconify(self
, TRUE
, FALSE
);
1346 if (self
->fullscreen
) {
1347 self
->fullscreen
= FALSE
;
1348 client_fullscreen(self
, TRUE
, FALSE
);
1351 self
->shaded
= FALSE
;
1352 client_shade(self
, TRUE
);
1355 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1357 if (self
->max_vert
&& self
->max_horz
) {
1358 self
->max_vert
= self
->max_horz
= FALSE
;
1359 client_maximize(self
, TRUE
, 0, FALSE
);
1360 } else if (self
->max_vert
) {
1361 self
->max_vert
= FALSE
;
1362 client_maximize(self
, TRUE
, 2, FALSE
);
1363 } else if (self
->max_horz
) {
1364 self
->max_horz
= FALSE
;
1365 client_maximize(self
, TRUE
, 1, FALSE
);
1368 /* nothing to do for the other states:
1377 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1378 gboolean user
, gboolean final
)
1380 gboolean moved
= FALSE
, resized
= FALSE
;
1382 /* gets the frame's position */
1383 frame_client_gravity(self
->frame
, &x
, &y
);
1385 /* these positions are frame positions, not client positions */
1387 /* set the size and position if fullscreen */
1388 if (self
->fullscreen
) {
1391 w
= screen_physical_size
.width
;
1392 h
= screen_physical_size
.height
;
1394 /* set the size and position if maximized */
1395 if (self
->max_horz
) {
1396 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1397 w
= screen_area(self
->desktop
)->width
;
1399 if (self
->max_vert
) {
1400 y
= screen_area(self
->desktop
)->y
;
1401 h
= screen_area(self
->desktop
)->height
-
1402 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1406 /* gets the client's position */
1407 frame_frame_gravity(self
->frame
, &x
, &y
);
1409 /* these override the above states! if you cant move you can't move! */
1411 if (!(self
->functions
& Func_Move
)) {
1415 if (!(self
->functions
& Func_Resize
)) {
1416 w
= self
->area
.width
;
1417 h
= self
->area
.height
;
1421 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1422 w
-= self
->base_size
.width
;
1423 h
-= self
->base_size
.height
;
1426 /* for interactive resizing. have to move half an increment in each
1429 /* how far we are towards the next size inc */
1430 int mw
= w
% self
->size_inc
.width
;
1431 int mh
= h
% self
->size_inc
.height
;
1433 int aw
= self
->size_inc
.width
/ 2;
1434 int ah
= self
->size_inc
.height
/ 2;
1435 /* don't let us move into a new size increment */
1436 if (mw
+ aw
>= self
->size_inc
.width
)
1437 aw
= self
->size_inc
.width
- mw
- 1;
1438 if (mh
+ ah
>= self
->size_inc
.height
)
1439 ah
= self
->size_inc
.height
- mh
- 1;
1443 /* if this is a user-requested resize, then check against min/max
1444 sizes and aspect ratios */
1446 /* smaller than min size or bigger than max size? */
1447 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1448 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1449 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1450 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1452 /* adjust the height ot match the width for the aspect ratios */
1453 if (self
->min_ratio
)
1454 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1455 if (self
->max_ratio
)
1456 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1459 /* keep to the increments */
1460 w
/= self
->size_inc
.width
;
1461 h
/= self
->size_inc
.height
;
1463 /* you cannot resize to nothing */
1467 /* store the logical size */
1468 SIZE_SET(self
->logical_size
, w
, h
);
1470 w
*= self
->size_inc
.width
;
1471 h
*= self
->size_inc
.height
;
1473 w
+= self
->base_size
.width
;
1474 h
+= self
->base_size
.height
;
1478 case Corner_TopLeft
:
1480 case Corner_TopRight
:
1481 x
-= w
- self
->area
.width
;
1483 case Corner_BottomLeft
:
1484 y
-= h
- self
->area
.height
;
1486 case Corner_BottomRight
:
1487 x
-= w
- self
->area
.width
;
1488 y
-= h
- self
->area
.height
;
1492 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1493 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1495 RECT_SET(self
->area
, x
, y
, w
, h
);
1498 XResizeWindow(ob_display
, self
->window
, w
, h
);
1500 /* move/resize the frame to match the request */
1502 if (moved
|| resized
)
1503 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1505 if (!user
|| final
) {
1507 event
.type
= ConfigureNotify
;
1508 event
.xconfigure
.display
= ob_display
;
1509 event
.xconfigure
.event
= self
->window
;
1510 event
.xconfigure
.window
= self
->window
;
1512 /* root window coords with border in mind */
1513 event
.xconfigure
.x
= x
- self
->border_width
+
1514 self
->frame
->size
.left
;
1515 event
.xconfigure
.y
= y
- self
->border_width
+
1516 self
->frame
->size
.top
;
1518 event
.xconfigure
.width
= self
->area
.width
;
1519 event
.xconfigure
.height
= self
->area
.height
;
1520 event
.xconfigure
.border_width
= self
->border_width
;
1521 event
.xconfigure
.above
= self
->frame
->plate
;
1522 event
.xconfigure
.override_redirect
= FALSE
;
1523 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1524 FALSE
, StructureNotifyMask
, &event
);
1529 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1533 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1534 self
->fullscreen
== fs
) return; /* already done */
1536 self
->fullscreen
= fs
;
1537 client_change_state(self
); /* change the state hints on the client */
1540 /* save the functions and remove them */
1541 self
->pre_fs_func
= self
->functions
;
1542 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1544 /* save the decorations and remove them */
1545 self
->pre_fs_decor
= self
->decorations
;
1546 self
->decorations
= 0;
1549 dimensions
[0] = self
->area
.x
;
1550 dimensions
[1] = self
->area
.y
;
1551 dimensions
[2] = self
->area
.width
;
1552 dimensions
[3] = self
->area
.height
;
1554 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1558 /* these are not actually used cuz client_configure will set them
1559 as appropriate when the window is fullscreened */
1564 self
->functions
= self
->pre_fs_func
;
1565 self
->decorations
= self
->pre_fs_decor
;
1567 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1575 /* pick some fallbacks... */
1576 x
= screen_area(self
->desktop
)->x
+
1577 screen_area(self
->desktop
)->width
/ 4;
1578 y
= screen_area(self
->desktop
)->y
+
1579 screen_area(self
->desktop
)->height
/ 4;
1580 w
= screen_area(self
->desktop
)->width
/ 2;
1581 h
= screen_area(self
->desktop
)->height
/ 2;
1585 client_change_allowed_actions(self
); /* based on the new _functions */
1587 /* when fullscreening, don't obey things like increments, fill the
1589 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1591 /* raise (back) into our stacking layer */
1592 stacking_raise(self
);
1594 /* try focus us when we go into fullscreen mode */
1598 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1600 if (self
->iconic
== iconic
) return; /* nothing to do */
1602 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1605 self
->iconic
= iconic
;
1608 self
->wmstate
= IconicState
;
1609 self
->ignore_unmaps
++;
1610 /* we unmap the client itself so that we can get MapRequest events,
1611 and because the ICCCM tells us to! */
1612 XUnmapWindow(ob_display
, self
->window
);
1615 client_set_desktop(self
, screen_desktop
, FALSE
);
1616 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1617 XMapWindow(ob_display
, self
->window
);
1619 client_change_state(self
);
1620 client_showhide(self
);
1621 screen_update_struts();
1623 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1626 /* iconify all transients */
1627 if (self
->transients
) {
1630 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1631 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1635 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1639 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1640 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1642 /* check if already done */
1644 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1645 if (dir
== 1 && self
->max_horz
) return;
1646 if (dir
== 2 && self
->max_vert
) return;
1648 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1649 if (dir
== 1 && !self
->max_horz
) return;
1650 if (dir
== 2 && !self
->max_vert
) return;
1653 /* work with the frame's coords */
1654 x
= self
->frame
->area
.x
;
1655 y
= self
->frame
->area
.y
;
1656 w
= self
->area
.width
;
1657 h
= self
->area
.height
;
1669 /* get the property off the window and use it for the dimensions
1670 we are already maxed on */
1671 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1673 if (self
->max_horz
) {
1674 dimensions
[0] = readdim
[0];
1675 dimensions
[2] = readdim
[2];
1677 if (self
->max_vert
) {
1678 dimensions
[1] = readdim
[1];
1679 dimensions
[3] = readdim
[3];
1684 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1690 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1692 if (dir
== 0 || dir
== 1) { /* horz */
1696 if (dir
== 0 || dir
== 2) { /* vert */
1702 /* pick some fallbacks... */
1703 if (dir
== 0 || dir
== 1) { /* horz */
1704 x
= screen_area(self
->desktop
)->x
+
1705 screen_area(self
->desktop
)->width
/ 4;
1706 w
= screen_area(self
->desktop
)->width
/ 2;
1708 if (dir
== 0 || dir
== 2) { /* vert */
1709 y
= screen_area(self
->desktop
)->y
+
1710 screen_area(self
->desktop
)->height
/ 4;
1711 h
= screen_area(self
->desktop
)->height
/ 2;
1716 if (dir
== 0 || dir
== 1) /* horz */
1717 self
->max_horz
= max
;
1718 if (dir
== 0 || dir
== 2) /* vert */
1719 self
->max_vert
= max
;
1721 if (!self
->max_horz
&& !self
->max_vert
)
1722 PROP_ERASE(self
->window
, openbox_premax
);
1724 client_change_state(self
); /* change the state hints on the client */
1726 /* figure out where the client should be going */
1727 frame_frame_gravity(self
->frame
, &x
, &y
);
1728 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1731 void client_shade(Client
*self
, gboolean shade
)
1733 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1734 self
->shaded
== shade
) return; /* already done */
1736 /* when we're iconic, don't change the wmstate */
1738 self
->wmstate
= shade
? IconicState
: NormalState
;
1739 self
->shaded
= shade
;
1740 client_change_state(self
);
1741 /* resize the frame to just the titlebar */
1742 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1745 void client_close(Client
*self
)
1749 if (!(self
->functions
& Func_Close
)) return;
1752 XXX: itd be cool to do timeouts and shit here for killing the client's
1754 like... if the window is around after 5 seconds, then the close button
1755 turns a nice red, and if this function is called again, the client is
1759 ce
.xclient
.type
= ClientMessage
;
1760 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1761 ce
.xclient
.display
= ob_display
;
1762 ce
.xclient
.window
= self
->window
;
1763 ce
.xclient
.format
= 32;
1764 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1765 ce
.xclient
.data
.l
[1] = event_lasttime
;
1766 ce
.xclient
.data
.l
[2] = 0l;
1767 ce
.xclient
.data
.l
[3] = 0l;
1768 ce
.xclient
.data
.l
[4] = 0l;
1769 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1772 void client_kill(Client
*self
)
1774 XKillClient(ob_display
, self
->window
);
1777 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1781 if (target
== self
->desktop
) return;
1783 g_message("Setting desktop %u", target
);
1785 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1787 old
= self
->desktop
;
1788 self
->desktop
= target
;
1789 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1790 /* the frame can display the current desktop state */
1791 engine_frame_adjust_state(self
->frame
);
1792 /* 'move' the window to the new desktop */
1794 client_showhide(self
);
1795 /* raise if it was not already on the desktop */
1796 if (old
!= DESKTOP_ALL
)
1797 stacking_raise(self
);
1798 screen_update_struts();
1800 /* update the focus lists */
1801 if (old
== DESKTOP_ALL
) {
1802 for (i
= 0; i
< screen_num_desktops
; ++i
)
1803 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1805 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1806 if (target
== DESKTOP_ALL
) {
1807 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1809 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1811 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1815 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1817 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1820 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1823 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1828 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1829 Client
*c
= it
->data
;
1830 if (c
== skip
) continue; /* circular? */
1831 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1832 if (c
->modal
) return c
;
1837 Client
*client_find_modal_child(Client
*self
)
1839 return search_modal_tree(self
, self
);
1842 gboolean
client_validate(Client
*self
)
1846 XSync(ob_display
, FALSE
); /* get all events on the server */
1848 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1849 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1850 XPutBackEvent(ob_display
, &e
);
1857 void client_set_wm_state(Client
*self
, long state
)
1859 if (state
== self
->wmstate
) return; /* no change */
1863 client_iconify(self
, TRUE
, TRUE
);
1866 client_iconify(self
, FALSE
, TRUE
);
1871 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1873 gboolean shaded
= self
->shaded
;
1874 gboolean fullscreen
= self
->fullscreen
;
1875 gboolean max_horz
= self
->max_horz
;
1876 gboolean max_vert
= self
->max_vert
;
1879 if (!(action
== prop_atoms
.net_wm_state_add
||
1880 action
== prop_atoms
.net_wm_state_remove
||
1881 action
== prop_atoms
.net_wm_state_toggle
))
1882 /* an invalid action was passed to the client message, ignore it */
1885 for (i
= 0; i
< 2; ++i
) {
1886 Atom state
= i
== 0 ? data1
: data2
;
1888 if (!state
) continue;
1890 /* if toggling, then pick whether we're adding or removing */
1891 if (action
== prop_atoms
.net_wm_state_toggle
) {
1892 if (state
== prop_atoms
.net_wm_state_modal
)
1893 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1894 prop_atoms
.net_wm_state_add
;
1895 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1896 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1897 prop_atoms
.net_wm_state_add
;
1898 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1899 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1900 prop_atoms
.net_wm_state_add
;
1901 else if (state
== prop_atoms
.net_wm_state_shaded
)
1902 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1903 prop_atoms
.net_wm_state_add
;
1904 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1905 action
= self
->skip_taskbar
?
1906 prop_atoms
.net_wm_state_remove
:
1907 prop_atoms
.net_wm_state_add
;
1908 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1909 action
= self
->skip_pager
?
1910 prop_atoms
.net_wm_state_remove
:
1911 prop_atoms
.net_wm_state_add
;
1912 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1913 action
= self
->fullscreen
?
1914 prop_atoms
.net_wm_state_remove
:
1915 prop_atoms
.net_wm_state_add
;
1916 else if (state
== prop_atoms
.net_wm_state_above
)
1917 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1918 prop_atoms
.net_wm_state_add
;
1919 else if (state
== prop_atoms
.net_wm_state_below
)
1920 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1921 prop_atoms
.net_wm_state_add
;
1924 if (action
== prop_atoms
.net_wm_state_add
) {
1925 if (state
== prop_atoms
.net_wm_state_modal
) {
1926 /* XXX raise here or something? */
1928 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1930 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1932 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1934 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1935 self
->skip_taskbar
= TRUE
;
1936 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1937 self
->skip_pager
= TRUE
;
1938 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1940 } else if (state
== prop_atoms
.net_wm_state_above
) {
1942 } else if (state
== prop_atoms
.net_wm_state_below
) {
1946 } else { /* action == prop_atoms.net_wm_state_remove */
1947 if (state
== prop_atoms
.net_wm_state_modal
) {
1948 self
->modal
= FALSE
;
1949 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1951 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1953 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1955 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1956 self
->skip_taskbar
= FALSE
;
1957 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1958 self
->skip_pager
= FALSE
;
1959 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1961 } else if (state
== prop_atoms
.net_wm_state_above
) {
1962 self
->above
= FALSE
;
1963 } else if (state
== prop_atoms
.net_wm_state_below
) {
1964 self
->below
= FALSE
;
1968 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1969 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1971 if (max_horz
== max_vert
) { /* both going the same way */
1972 client_maximize(self
, max_horz
, 0, TRUE
);
1974 client_maximize(self
, max_horz
, 1, TRUE
);
1975 client_maximize(self
, max_vert
, 2, TRUE
);
1979 if (max_horz
!= self
->max_horz
)
1980 client_maximize(self
, max_horz
, 1, TRUE
);
1982 client_maximize(self
, max_vert
, 2, TRUE
);
1985 /* change fullscreen state before shading, as it will affect if the window
1987 if (fullscreen
!= self
->fullscreen
)
1988 client_fullscreen(self
, fullscreen
, TRUE
);
1989 if (shaded
!= self
->shaded
)
1990 client_shade(self
, shaded
);
1991 client_calc_layer(self
);
1992 client_change_state(self
); /* change the hint to relect these changes */
1995 Client
*client_focus_target(Client
*self
)
1999 /* if we have a modal child, then focus it, not us */
2000 child
= client_find_modal_child(self
);
2001 if (child
) return child
;
2005 gboolean
client_focusable(Client
*self
)
2007 /* won't try focus if the client doesn't want it, or if the window isn't
2008 visible on the screen */
2009 return self
->frame
->visible
&&
2010 (self
->can_focus
|| self
->focus_notify
);
2013 gboolean
client_focus(Client
*self
)
2017 /* choose the correct target */
2018 self
= client_focus_target(self
);
2020 if (!client_focusable(self
))
2023 /* do a check to see if the window has already been unmapped or destroyed
2024 do this intelligently while watching out for unmaps we've generated
2025 (ignore_unmaps > 0) */
2026 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2027 DestroyNotify
, &ev
)) {
2028 XPutBackEvent(ob_display
, &ev
);
2031 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2032 UnmapNotify
, &ev
)) {
2033 if (self
->ignore_unmaps
) {
2034 self
->ignore_unmaps
--;
2036 XPutBackEvent(ob_display
, &ev
);
2041 if (self
->can_focus
)
2042 /* RevertToPointerRoot causes much more headache than TevertToNone, so
2043 I choose to use it always, hopefully to find errors quicker, if any
2044 are left. (I hate X. I hate focus events.) */
2045 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2048 if (self
->focus_notify
) {
2050 ce
.xclient
.type
= ClientMessage
;
2051 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2052 ce
.xclient
.display
= ob_display
;
2053 ce
.xclient
.window
= self
->window
;
2054 ce
.xclient
.format
= 32;
2055 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2056 ce
.xclient
.data
.l
[1] = event_lasttime
;
2057 ce
.xclient
.data
.l
[2] = 0l;
2058 ce
.xclient
.data
.l
[3] = 0l;
2059 ce
.xclient
.data
.l
[4] = 0l;
2060 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2064 g_message("focusing %lx", self
->window
);
2067 /* Cause the FocusIn to come back to us. Important for desktop switches,
2068 since otherwise we'll have no FocusIn on the queue and send it off to
2069 the focus_backup. */
2070 XSync(ob_display
, FALSE
);
2074 void client_unfocus(Client
*self
)
2076 g_assert(focus_client
== self
);
2077 g_message("client_unfocus");
2078 focus_fallback(FALSE
);
2081 gboolean
client_focused(Client
*self
)
2083 return self
== focus_client
;
2086 Icon
*client_icon(Client
*self
, int w
, int h
)
2089 /* si is the smallest image >= req */
2090 /* li is the largest image < req */
2091 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2093 if (!self
->nicons
) return NULL
;
2095 for (i
= 0; i
< self
->nicons
; ++i
) {
2096 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2097 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2101 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2106 if (largest
== 0) /* didnt find one smaller than the requested size */
2107 return &self
->icons
[si
];
2108 return &self
->icons
[li
];