4 #include "extensions.h"
14 #include <X11/Xutil.h>
16 /*! The event mask to grab on client windows */
17 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
20 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
23 GSList
*client_list
= NULL
;
24 GHashTable
*client_map
= NULL
;
26 static void client_get_all(Client
*self
);
27 static void client_toggle_border(Client
*self
, gboolean show
);
28 static void client_get_area(Client
*self
);
29 static void client_get_desktop(Client
*self
);
30 static void client_get_state(Client
*self
);
31 static void client_get_shaped(Client
*self
);
32 static void client_get_mwm_hints(Client
*self
);
33 static void client_get_gravity(Client
*self
);
34 static void client_showhide(Client
*self
);
35 static void client_change_allowed_actions(Client
*self
);
36 static void client_change_state(Client
*self
);
37 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
38 static void client_apply_startup_state(Client
*self
);
39 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
41 static guint
map_hash(Window w
) { return w
; }
42 static gboolean
map_key_comp(Window w1
, Window w2
) { return w1
== w2
; }
46 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
47 (GEqualFunc
)map_key_comp
);
51 void client_shutdown()
53 g_hash_table_destroy(client_map
);
56 void client_set_list()
58 Window
*windows
, *win_it
;
60 guint size
= g_slist_length(client_list
);
62 /* create an array of the window ids */
64 windows
= g_new(Window
, size
);
66 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
67 *win_it
= ((Client
*)it
->data
)->window
;
71 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
79 void client_manage_all()
81 unsigned int i
, j
, nchild
;
84 XWindowAttributes attrib
;
86 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
88 /* remove all icon windows from the list */
89 for (i
= 0; i
< nchild
; i
++) {
90 if (children
[i
] == None
) continue;
91 wmhints
= XGetWMHints(ob_display
, children
[i
]);
93 if ((wmhints
->flags
& IconWindowHint
) &&
94 (wmhints
->icon_window
!= children
[i
]))
95 for (j
= 0; j
< nchild
; j
++)
96 if (children
[j
] == wmhints
->icon_window
) {
104 for (i
= 0; i
< nchild
; ++i
) {
105 if (children
[i
] == None
)
107 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
108 if (attrib
.override_redirect
) continue;
110 if (attrib
.map_state
!= IsUnmapped
)
111 client_manage(children
[i
]);
117 void client_manage(Window window
)
121 XWindowAttributes attrib
;
122 XSetWindowAttributes attrib_set
;
123 /* XWMHints *wmhint; */
128 /* check if it has already been unmapped by the time we started mapping
129 the grab does a sync so we don't have to here */
130 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
131 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
132 XPutBackEvent(ob_display
, &e
);
135 return; /* don't manage it */
138 /* make sure it isn't an override-redirect window */
139 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
140 attrib
.override_redirect
) {
142 return; /* don't manage it */
145 /* /\* is the window a docking app *\/
146 if ((wmhint = XGetWMHints(ob_display, window))) {
147 if ((wmhint->flags & StateHint) &&
148 wmhint->initial_state == WithdrawnState) {
149 /\* XXX: make dock apps work! *\/
158 /* choose the events we want to receive on the CLIENT window */
159 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
160 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
161 XChangeWindowAttributes(ob_display
, window
,
162 CWEventMask
|CWDontPropagate
, &attrib_set
);
165 /* create the Client struct, and populate it from the hints on the
167 client
= g_new(Client
, 1);
168 client
->window
= window
;
169 client_get_all(client
);
171 /* remove the client's border (and adjust re gravity) */
172 client_toggle_border(client
, FALSE
);
174 /* specify that if we exit, the window should not be destroyed and should
175 be reparented back to root automatically */
176 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
178 /* create the decoration frame for the client window */
179 client
->frame
= engine_frame_new();
181 engine_frame_grab_client(client
->frame
, client
);
183 client_apply_startup_state(client
);
187 client_list
= g_slist_append(client_list
, client
);
188 stacking_list
= g_list_append(stacking_list
, client
);
189 g_hash_table_insert(client_map
, (gpointer
)window
, client
);
191 /* update the focus lists */
192 if (client
->desktop
== DESKTOP_ALL
) {
193 for (i
= 0; i
< screen_num_desktops
; ++i
)
194 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
197 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
200 stacking_raise(client
);
202 screen_update_struts();
204 dispatch_client(Event_Client_New
, client
, 0, 0);
206 client_showhide(client
);
208 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
210 /* grab all mouse bindings */
211 /*pointer_grab_all(client, TRUE);XXX*/
213 /* update the list hints */
216 g_message("Managed window 0x%lx", window
);
219 void client_unmanage_all()
221 while (client_list
!= NULL
)
222 client_unmanage(client_list
->data
);
225 void client_unmanage(Client
*client
)
231 g_message("Unmanaging window: %lx", client
->window
);
233 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
235 /* remove the window from our save set */
236 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
238 /* we dont want events no more */
239 XSelectInput(ob_display
, client
->window
, NoEventMask
);
241 /* ungrab any mouse bindings */
242 /*pointer_grab_all(client, FALSE);XXX*/
244 engine_frame_hide(client
->frame
);
246 /* give the client its border back */
247 client_toggle_border(client
, TRUE
);
249 /* reparent the window out of the frame, and free the frame */
250 engine_frame_release_client(client
->frame
, client
);
252 client_list
= g_slist_remove(client_list
, client
);
253 stacking_list
= g_list_remove(stacking_list
, client
);
254 g_hash_table_remove(client_map
, (gpointer
)client
->window
);
256 /* update the focus lists */
257 if (client
->desktop
== DESKTOP_ALL
) {
258 for (i
= 0; i
< screen_num_desktops
; ++i
)
259 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
262 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
265 /* once the client is out of the list, update the struts to remove it's
267 screen_update_struts();
269 /* tell our parent that we're gone */
270 if (client
->transient_for
!= NULL
)
271 client
->transient_for
->transients
=
272 g_slist_remove(client
->transient_for
->transients
, client
);
274 /* tell our transients that we're gone */
275 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
276 ((Client
*)it
->data
)->transient_for
= NULL
;
277 client_calc_layer(it
->data
);
280 /* unfocus the client (dispatchs the focus event) (we're out of the
281 transient lists already, so being modal doesn't matter) */
283 client_unfocus(client
);
285 if (ob_state
!= State_Exiting
) {
286 /* these values should not be persisted across a window
288 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
289 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
291 /* if we're left in an iconic state, the client wont be mapped. this is
292 bad, since we will no longer be managing the window on restart */
294 XMapWindow(ob_display
, client
->window
);
297 /* free all data allocated in the client struct */
298 g_slist_free(client
->transients
);
299 for (j
= 0; j
< client
->nicons
; ++j
)
300 g_free(client
->icons
[j
].data
);
301 if (client
->nicons
> 0)
302 g_free(client
->icons
);
303 g_free(client
->title
);
304 g_free(client
->icon_title
);
305 g_free(client
->res_name
);
306 g_free(client
->res_class
);
307 g_free(client
->role
);
310 /* update the list hints */
314 static void client_toggle_border(Client
*self
, gboolean show
)
316 /* adjust our idea of where the client is, based on its border. When the
317 border is removed, the client should now be considered to be in a
319 when re-adding the border to the client, the same operation needs to be
321 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
322 int x
= oldx
, y
= oldy
;
323 switch(self
->gravity
) {
325 case NorthWestGravity
:
327 case SouthWestGravity
:
329 case NorthEastGravity
:
331 case SouthEastGravity
:
332 if (show
) x
-= self
->border_width
* 2;
333 else x
+= self
->border_width
* 2;
340 if (show
) x
-= self
->border_width
;
341 else x
+= self
->border_width
;
344 switch(self
->gravity
) {
346 case NorthWestGravity
:
348 case NorthEastGravity
:
350 case SouthWestGravity
:
352 case SouthEastGravity
:
353 if (show
) y
-= self
->border_width
* 2;
354 else y
+= self
->border_width
* 2;
361 if (show
) y
-= self
->border_width
;
362 else y
+= self
->border_width
;
369 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
371 /* move the client so it is back it the right spot _with_ its
373 if (x
!= oldx
|| y
!= oldy
)
374 XMoveWindow(ob_display
, self
->window
, x
, y
);
376 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
380 static void client_get_all(Client
*self
)
382 /* update EVERYTHING!! */
384 self
->ignore_unmaps
= 0;
388 self
->title
= self
->icon_title
= NULL
;
389 self
->res_name
= self
->res_class
= self
->role
= NULL
;
390 self
->wmstate
= NormalState
;
391 self
->focused
= FALSE
;
392 self
->transient
= FALSE
;
393 self
->transients
= NULL
;
394 self
->transient_for
= NULL
;
396 self
->urgent
= FALSE
;
397 self
->positioned
= FALSE
;
398 self
->disabled_decorations
= 0;
402 client_get_area(self
);
403 client_get_desktop(self
);
404 client_get_state(self
);
405 client_get_shaped(self
);
407 client_update_transient_for(self
);
408 client_get_mwm_hints(self
);
409 client_get_type(self
);/* this can change the mwmhints for special cases */
411 client_update_protocols(self
);
413 client_get_gravity(self
); /* get the attribute gravity */
414 client_update_normal_hints(self
); /* this may override the attribute
417 /* got the type, the mwmhints, the protocols, and the normal hints
418 (min/max sizes), so we're ready to set up the decorations/functions */
419 client_setup_decor_and_functions(self
);
421 client_update_wmhints(self
);
422 client_update_title(self
);
423 client_update_icon_title(self
);
424 client_update_class(self
);
425 client_update_strut(self
);
426 client_update_icons(self
);
427 client_update_kwm_icon(self
);
429 /* this makes sure that these windows appear on all desktops */
430 if (self
->type
== Type_Desktop
)
431 self
->desktop
= DESKTOP_ALL
;
433 /* set the desktop hint, to make sure that it always exists, and to
434 reflect any changes we've made here */
435 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
437 client_change_state(self
);
440 static void client_get_area(Client
*self
)
442 XWindowAttributes wattrib
;
445 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
446 g_assert(ret
!= BadWindow
);
448 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
449 self
->border_width
= wattrib
.border_width
;
452 static void client_get_desktop(Client
*self
)
456 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
457 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
458 d
= screen_num_desktops
- 1;
461 /* defaults to the current desktop */
462 self
->desktop
= screen_desktop
;
466 static void client_get_state(Client
*self
)
471 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
472 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
473 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
475 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
477 for (i
= 0; i
< num
; ++i
) {
478 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
480 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
482 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
484 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
485 self
->skip_taskbar
= TRUE
;
486 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
487 self
->skip_pager
= TRUE
;
488 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
489 self
->fullscreen
= TRUE
;
490 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
491 self
->max_vert
= TRUE
;
492 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
493 self
->max_horz
= TRUE
;
494 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
496 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
504 static void client_get_shaped(Client
*self
)
506 self
->shaped
= FALSE
;
508 if (extensions_shape
) {
513 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
515 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
516 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
518 self
->shaped
= (s
!= 0);
523 void client_update_transient_for(Client
*self
)
528 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
529 t
!= self
->window
) { /* cant be transient to itself! */
530 self
->transient
= TRUE
;
531 c
= g_hash_table_lookup(client_map
, (gpointer
)t
);
532 g_assert(c
!= self
);/* if this happens then we need to check for it*/
534 if (!c
/*XXX: && _group*/) {
535 /* not transient to a client, see if it is transient for a
537 if (/*t == _group->leader() || */
540 /* window is a transient for its group! */
541 /* XXX: for now this is treated as non-transient.
542 this needs to be fixed! */
546 self
->transient
= FALSE
;
548 /* if anything has changed... */
549 if (c
!= self
->transient_for
) {
550 if (self
->transient_for
)
551 /* remove from old parent */
552 g_slist_remove(self
->transient_for
->transients
, self
);
553 self
->transient_for
= c
;
554 if (self
->transient_for
)
555 /* add to new parent */
556 g_slist_append(self
->transient_for
->transients
, self
);
560 static void client_get_mwm_hints(Client
*self
)
563 unsigned long *hints
;
565 self
->mwmhints
.flags
= 0; /* default to none */
567 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
568 if (num
>= MWM_ELEMENTS
) {
569 self
->mwmhints
.flags
= hints
[0];
570 self
->mwmhints
.functions
= hints
[1];
571 self
->mwmhints
.decorations
= hints
[2];
577 void client_get_type(Client
*self
)
583 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
584 /* use the first value that we know about in the array */
585 for (i
= 0; i
< num
; ++i
) {
586 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
587 self
->type
= Type_Desktop
;
588 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
589 self
->type
= Type_Dock
;
590 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
591 self
->type
= Type_Toolbar
;
592 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
593 self
->type
= Type_Menu
;
594 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
595 self
->type
= Type_Utility
;
596 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
597 self
->type
= Type_Splash
;
598 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
599 self
->type
= Type_Dialog
;
600 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
601 self
->type
= Type_Normal
;
602 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
603 /* prevent this window from getting any decor or
605 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
606 MwmFlag_Decorations
);
607 self
->mwmhints
.decorations
= 0;
608 self
->mwmhints
.functions
= 0;
610 if (self
->type
!= (WindowType
) -1)
611 break; /* grab the first legit type */
616 if (self
->type
== (WindowType
) -1) {
617 /*the window type hint was not set, which means we either classify
618 ourself as a normal window or a dialog, depending on if we are a
621 self
->type
= Type_Dialog
;
623 self
->type
= Type_Normal
;
627 void client_update_protocols(Client
*self
)
630 gulong num_return
, i
;
632 self
->focus_notify
= FALSE
;
633 self
->delete_window
= FALSE
;
635 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
636 for (i
= 0; i
< num_return
; ++i
) {
637 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
638 /* this means we can request the window to close */
639 self
->delete_window
= TRUE
;
640 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
641 /* if this protocol is requested, then the window will be
642 notified whenever we want it to receive focus */
643 self
->focus_notify
= TRUE
;
649 static void client_get_gravity(Client
*self
)
651 XWindowAttributes wattrib
;
654 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
655 g_assert(ret
!= BadWindow
);
656 self
->gravity
= wattrib
.win_gravity
;
659 void client_update_normal_hints(Client
*self
)
663 int oldgravity
= self
->gravity
;
666 self
->min_ratio
= 0.0f
;
667 self
->max_ratio
= 0.0f
;
668 SIZE_SET(self
->size_inc
, 1, 1);
669 SIZE_SET(self
->base_size
, 0, 0);
670 SIZE_SET(self
->min_size
, 0, 0);
671 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
673 /* get the hints from the window */
674 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
675 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
677 if (size
.flags
& PWinGravity
) {
678 self
->gravity
= size
.win_gravity
;
680 /* if the client has a frame, i.e. has already been mapped and
681 is changing its gravity */
682 if (self
->frame
&& self
->gravity
!= oldgravity
) {
683 /* move our idea of the client's position based on its new
685 self
->area
.x
= self
->frame
->area
.x
;
686 self
->area
.y
= self
->frame
->area
.y
;
687 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
691 if (size
.flags
& PAspect
) {
692 if (size
.min_aspect
.y
)
693 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
694 if (size
.max_aspect
.y
)
695 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
698 if (size
.flags
& PMinSize
)
699 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
701 if (size
.flags
& PMaxSize
)
702 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
704 if (size
.flags
& PBaseSize
)
705 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
707 if (size
.flags
& PResizeInc
)
708 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
712 void client_setup_decor_and_functions(Client
*self
)
714 /* start with everything (cept fullscreen) */
715 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
716 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
717 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
719 if (self
->delete_window
) {
720 self
->decorations
|= Decor_Close
;
721 self
->functions
|= Func_Close
;
724 if (!(self
->min_size
.width
< self
->max_size
.width
||
725 self
->min_size
.height
< self
->max_size
.height
)) {
726 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
727 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
730 switch (self
->type
) {
732 /* normal windows retain all of the possible decorations and
733 functionality, and are the only windows that you can fullscreen */
734 self
->functions
|= Func_Fullscreen
;
738 /* dialogs cannot be maximized */
739 self
->decorations
&= ~Decor_Maximize
;
740 self
->functions
&= ~Func_Maximize
;
746 /* these windows get less functionality */
747 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
748 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
754 /* none of these windows are manipulated by the window manager */
755 self
->decorations
= 0;
760 /* Mwm Hints are applied subtractively to what has already been chosen for
761 decor and functionality */
762 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
763 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
764 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
765 self
->decorations
&= ~Decor_Border
;
766 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
767 self
->decorations
&= ~Decor_Handle
;
768 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
769 self
->decorations
&= ~Decor_Titlebar
;
770 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
771 self
->decorations
&= ~Decor_Iconify
;
772 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
773 self
->decorations
&= ~Decor_Maximize
;
777 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
778 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
779 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
780 self
->functions
&= ~Func_Resize
;
781 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
782 self
->functions
&= ~Func_Move
;
783 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
784 self
->functions
&= ~Func_Iconify
;
785 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
786 self
->functions
&= ~Func_Maximize
;
787 /* dont let mwm hints kill the close button
788 if (! (self->mwmhints.functions & MwmFunc_Close))
789 self->functions &= ~Func_Close; */
793 /* can't maximize without moving/resizing */
794 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
795 self
->functions
&= ~Func_Maximize
;
797 /* finally, user specified disabled decorations are applied to subtract
799 if (self
->disabled_decorations
& Decor_Titlebar
)
800 self
->decorations
&= ~Decor_Titlebar
;
801 if (self
->disabled_decorations
& Decor_Handle
)
802 self
->decorations
&= ~Decor_Handle
;
803 if (self
->disabled_decorations
& Decor_Border
)
804 self
->decorations
&= ~Decor_Border
;
805 if (self
->disabled_decorations
& Decor_Iconify
)
806 self
->decorations
&= ~Decor_Iconify
;
807 if (self
->disabled_decorations
& Decor_Maximize
)
808 self
->decorations
&= ~Decor_Maximize
;
809 if (self
->disabled_decorations
& Decor_AllDesktops
)
810 self
->decorations
&= ~Decor_AllDesktops
;
811 if (self
->disabled_decorations
& Decor_Close
)
812 self
->decorations
&= ~Decor_Close
;
814 /* if we don't have a titlebar, then we cannot shade! */
815 if (!(self
->decorations
& Decor_Titlebar
))
816 self
->functions
&= ~Func_Shade
;
818 client_change_allowed_actions(self
);
821 /* change the decors on the frame */
822 engine_frame_adjust_size(self
->frame
);
823 /* with more/less decorations, we may need to be repositioned */
824 engine_frame_adjust_position(self
->frame
);
825 /* with new decor, the window's maximized size may change */
826 client_remaximize(self
);
830 static void client_change_allowed_actions(Client
*self
)
835 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
837 if (self
->functions
& Func_Shade
)
838 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
839 if (self
->functions
& Func_Close
)
840 actions
[num
++] = prop_atoms
.net_wm_action_close
;
841 if (self
->functions
& Func_Move
)
842 actions
[num
++] = prop_atoms
.net_wm_action_move
;
843 if (self
->functions
& Func_Iconify
)
844 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
845 if (self
->functions
& Func_Resize
)
846 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
847 if (self
->functions
& Func_Fullscreen
)
848 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
849 if (self
->functions
& Func_Maximize
) {
850 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
851 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
854 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
856 /* make sure the window isn't breaking any rules now */
858 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
859 if (self
->frame
) client_shade(self
, FALSE
);
860 else self
->shaded
= FALSE
;
862 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
863 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
864 else self
->iconic
= FALSE
;
866 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
867 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
868 else self
->fullscreen
= FALSE
;
870 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
872 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
873 else self
->max_vert
= self
->max_horz
= FALSE
;
877 void client_remaximize(Client
*self
)
880 if (self
->max_horz
&& self
->max_vert
)
882 else if (self
->max_horz
)
884 else if (self
->max_vert
)
887 return; /* not maximized */
888 self
->max_horz
= self
->max_vert
= FALSE
;
889 client_maximize(self
, TRUE
, dir
, FALSE
);
892 void client_update_wmhints(Client
*self
)
897 /* assume a window takes input if it doesnt specify */
898 self
->can_focus
= TRUE
;
900 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
901 if (hints
->flags
& InputHint
)
902 self
->can_focus
= hints
->input
;
904 /* only do this when starting! */
905 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
906 self
->iconic
= hints
->initial_state
== IconicState
;
908 if (hints
->flags
& XUrgencyHint
)
911 if (hints
->flags
& WindowGroupHint
) {
912 if (hints
->window_group
!= self
->group
) {
913 /* XXX: remove from the old group if there was one */
914 self
->group
= hints
->window_group
;
915 /* XXX: do stuff with the group */
917 } else /* no group! */
920 if (hints
->flags
& IconPixmapHint
) {
921 client_update_kwm_icon(self
);
922 /* try get the kwm icon first, this is a fallback only */
923 if (self
->pixmap_icon
== None
) {
924 self
->pixmap_icon
= hints
->icon_pixmap
;
925 if (hints
->flags
& IconMaskHint
)
926 self
->pixmap_icon_mask
= hints
->icon_mask
;
928 self
->pixmap_icon_mask
= None
;
931 engine_frame_adjust_icon(self
->frame
);
938 if (ur
!= self
->urgent
) {
940 g_message("Urgent Hint for 0x%lx: %s\n", self
->window
,
942 /* fire the urgent callback if we're mapped, otherwise, wait until
943 after we're mapped */
945 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
949 void client_update_title(Client
*self
)
953 if (self
->title
!= NULL
)
957 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
958 /* try old x stuff */
959 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
960 /* convert it to UTF-8 */
964 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
966 g_warning("Unable to convert string to UTF-8");
973 data
= g_strdup("Unnamed Window");
975 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
981 engine_frame_adjust_title(self
->frame
);
984 void client_update_icon_title(Client
*self
)
988 if (self
->icon_title
!= NULL
)
989 g_free(self
->icon_title
);
992 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
993 /* try old x stuff */
994 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
995 /* convert it to UTF-8 */
999 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1001 g_warning("Unable to convert string to UTF-8");
1008 data
= g_strdup("Unnamed Window");
1010 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1013 self
->icon_title
= data
;
1016 void client_update_class(Client
*self
)
1022 if (self
->res_name
) g_free(self
->res_name
);
1023 if (self
->res_class
) g_free(self
->res_class
);
1024 if (self
->role
) g_free(self
->role
);
1026 self
->res_name
= self
->res_class
= self
->role
= NULL
;
1028 data
= g_ptr_array_new();
1030 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1032 self
->res_name
= g_strdup(g_ptr_array_index(data
, 0));
1034 self
->res_class
= g_strdup(g_ptr_array_index(data
, 1));
1037 for (i
= 0; i
< data
->len
; ++i
)
1038 g_free(g_ptr_array_index(data
, i
));
1039 g_ptr_array_free(data
, TRUE
);
1041 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1042 self
->role
= g_strdup(s
);
1044 if (self
->res_name
== NULL
) self
->res_name
= g_strdup("");
1045 if (self
->res_class
== NULL
) self
->res_class
= g_strdup("");
1046 if (self
->role
== NULL
) self
->role
= g_strdup("");
1049 void client_update_strut(Client
*self
)
1053 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1054 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1057 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1059 /* updating here is pointless while we're being mapped cuz we're not in
1060 the client list yet */
1062 screen_update_struts();
1065 void client_update_icons(Client
*self
)
1068 unsigned long *data
;
1069 unsigned long w
, h
, i
;
1072 for (j
= 0; j
< self
->nicons
; ++j
)
1073 g_free(self
->icons
[j
].data
);
1074 if (self
->nicons
> 0)
1075 g_free(self
->icons
);
1078 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1079 /* figure out how many valid icons are in here */
1081 while (num
- i
> 2) {
1089 self
->icons
= g_new(Icon
, self
->nicons
);
1091 /* store the icons */
1093 for (j
= 0; j
< self
->nicons
; ++j
) {
1094 w
= self
->icons
[j
].w
= data
[i
++];
1095 h
= self
->icons
[j
].h
= data
[i
++];
1096 self
->icons
[j
].data
=
1097 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1105 if (self
->nicons
<= 0) {
1107 self
->icons
= g_new0(Icon
, 1);
1111 engine_frame_adjust_icon(self
->frame
);
1114 void client_update_kwm_icon(Client
*self
)
1118 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1119 self
->pixmap_icon
= data
[0];
1120 self
->pixmap_icon_mask
= data
[1];
1123 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1126 engine_frame_adjust_icon(self
->frame
);
1129 static void client_change_state(Client
*self
)
1131 unsigned long state
[2];
1135 state
[0] = self
->wmstate
;
1137 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1141 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1143 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1145 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1146 if (self
->skip_taskbar
)
1147 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1148 if (self
->skip_pager
)
1149 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1150 if (self
->fullscreen
)
1151 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1153 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1155 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1157 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1159 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1160 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1162 client_calc_layer(self
);
1165 engine_frame_adjust_state(self
->frame
);
1168 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1173 for (it
= node
->transients
; it
!= NULL
; it
= g_slist_next(it
)) {
1174 Client
*c
= it
->data
;
1175 if (c
== skip
) continue; /* circular? */
1176 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1177 if (c
->focused
) return c
;
1182 void client_calc_layer(Client
*self
)
1188 /* are we fullscreen, or do we have a fullscreen transient parent? */
1192 if (c
->fullscreen
) {
1196 c
= c
->transient_for
;
1198 if (!fs
&& self
->fullscreen
) {
1199 /* is one of our transients focused? */
1200 c
= search_focus_tree(self
, self
);
1201 if (c
!= NULL
) fs
= TRUE
;
1204 if (self
->iconic
) l
= Layer_Icon
;
1205 else if (fs
) l
= Layer_Fullscreen
;
1206 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1207 else if (self
->type
== Type_Dock
) {
1208 if (!self
->below
) l
= Layer_Top
;
1209 else l
= Layer_Normal
;
1211 else if (self
->above
) l
= Layer_Above
;
1212 else if (self
->below
) l
= Layer_Below
;
1213 else l
= Layer_Normal
;
1215 if (l
!= self
->layer
) {
1218 stacking_raise(self
);
1222 gboolean
client_should_show(Client
*self
)
1224 if (self
->iconic
) return FALSE
;
1225 else if (!(self
->desktop
== screen_desktop
||
1226 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1227 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1232 static void client_showhide(Client
*self
)
1235 if (client_should_show(self
))
1236 engine_frame_show(self
->frame
);
1238 engine_frame_hide(self
->frame
);
1241 gboolean
client_normal(Client
*self
) {
1242 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1243 self
->type
== Type_Splash
);
1246 static void client_apply_startup_state(Client
*self
)
1248 /* these are in a carefully crafted order.. */
1251 self
->iconic
= FALSE
;
1252 client_iconify(self
, TRUE
, FALSE
);
1254 if (self
->fullscreen
) {
1255 self
->fullscreen
= FALSE
;
1256 client_fullscreen(self
, TRUE
, FALSE
);
1259 self
->shaded
= FALSE
;
1260 client_shade(self
, TRUE
);
1263 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1265 if (self
->max_vert
&& self
->max_horz
) {
1266 self
->max_vert
= self
->max_horz
= FALSE
;
1267 client_maximize(self
, TRUE
, 0, FALSE
);
1268 } else if (self
->max_vert
) {
1269 self
->max_vert
= FALSE
;
1270 client_maximize(self
, TRUE
, 2, FALSE
);
1271 } else if (self
->max_horz
) {
1272 self
->max_horz
= FALSE
;
1273 client_maximize(self
, TRUE
, 1, FALSE
);
1276 /* nothing to do for the other states:
1285 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1286 gboolean user
, gboolean final
)
1288 gboolean moved
= FALSE
, resized
= FALSE
;
1290 w
-= self
->base_size
.width
;
1291 h
-= self
->base_size
.height
;
1294 /* for interactive resizing. have to move half an increment in each
1297 /* how far we are towards the next size inc */
1298 int mw
= w
% self
->size_inc
.width
;
1299 int mh
= h
% self
->size_inc
.height
;
1301 int aw
= self
->size_inc
.width
/ 2;
1302 int ah
= self
->size_inc
.height
/ 2;
1303 /* don't let us move into a new size increment */
1304 if (mw
+ aw
>= self
->size_inc
.width
)
1305 aw
= self
->size_inc
.width
- mw
- 1;
1306 if (mh
+ ah
>= self
->size_inc
.height
)
1307 ah
= self
->size_inc
.height
- mh
- 1;
1311 /* if this is a user-requested resize, then check against min/max
1312 sizes and aspect ratios */
1314 /* smaller than min size or bigger than max size? */
1315 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1316 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1317 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1318 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1320 /* adjust the height ot match the width for the aspect ratios */
1321 if (self
->min_ratio
)
1322 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1323 if (self
->max_ratio
)
1324 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1327 /* keep to the increments */
1328 w
/= self
->size_inc
.width
;
1329 h
/= self
->size_inc
.height
;
1331 /* you cannot resize to nothing */
1335 /* store the logical size */
1336 SIZE_SET(self
->logical_size
, w
, h
);
1338 w
*= self
->size_inc
.width
;
1339 h
*= self
->size_inc
.height
;
1341 w
+= self
->base_size
.width
;
1342 h
+= self
->base_size
.height
;
1345 case Corner_TopLeft
:
1347 case Corner_TopRight
:
1348 x
-= w
- self
->area
.width
;
1350 case Corner_BottomLeft
:
1351 y
-= h
- self
->area
.height
;
1353 case Corner_BottomRight
:
1354 x
-= w
- self
->area
.width
;
1355 y
-= h
- self
->area
.height
;
1359 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1360 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1362 RECT_SET(self
->area
, x
, y
, w
, h
);
1365 XResizeWindow(ob_display
, self
->window
, w
, h
);
1367 /* move/resize the frame to match the request */
1369 /* Adjust the size and then the position, as required by the EWMH */
1371 engine_frame_adjust_size(self
->frame
);
1373 engine_frame_adjust_position(self
->frame
);
1375 if (!user
|| final
) {
1377 event
.type
= ConfigureNotify
;
1378 event
.xconfigure
.display
= ob_display
;
1379 event
.xconfigure
.event
= self
->window
;
1380 event
.xconfigure
.window
= self
->window
;
1382 /* root window coords with border in mind */
1383 event
.xconfigure
.x
= x
- self
->border_width
+
1384 self
->frame
->size
.left
;
1385 event
.xconfigure
.y
= y
- self
->border_width
+
1386 self
->frame
->size
.top
;
1388 event
.xconfigure
.width
= self
->area
.width
;
1389 event
.xconfigure
.height
= self
->area
.height
;
1390 event
.xconfigure
.border_width
= self
->border_width
;
1391 event
.xconfigure
.above
= self
->frame
->plate
;
1392 event
.xconfigure
.override_redirect
= FALSE
;
1393 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1394 FALSE
, StructureNotifyMask
, &event
);
1400 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1402 static int saved_func
, saved_decor
;
1405 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1406 self
->fullscreen
== fs
) return; /* already done */
1408 self
->fullscreen
= fs
;
1409 client_change_state(self
); /* change the state hints on the client */
1412 /* save the functions and remove them */
1413 saved_func
= self
->functions
;
1414 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1416 /* save the decorations and remove them */
1417 saved_decor
= self
->decorations
;
1418 self
->decorations
= 0;
1421 dimensions
[0] = self
->area
.x
;
1422 dimensions
[1] = self
->area
.y
;
1423 dimensions
[2] = self
->area
.width
;
1424 dimensions
[3] = self
->area
.height
;
1426 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1431 w
= screen_physical_size
.width
;
1432 h
= screen_physical_size
.height
;
1436 self
->functions
= saved_func
;
1437 self
->decorations
= saved_decor
;
1439 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1447 /* pick some fallbacks... */
1448 x
= screen_area(self
->desktop
)->x
+
1449 screen_area(self
->desktop
)->width
/ 4;
1450 y
= screen_area(self
->desktop
)->y
+
1451 screen_area(self
->desktop
)->height
/ 4;
1452 w
= screen_area(self
->desktop
)->width
/ 2;
1453 h
= screen_area(self
->desktop
)->height
/ 2;
1457 client_change_allowed_actions(self
); /* based on the new _functions */
1459 /* when fullscreening, don't obey things like increments, fill the
1461 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1463 /* raise (back) into our stacking layer */
1464 stacking_raise(self
);
1466 /* try focus us when we go into fullscreen mode */
1470 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1472 if (self
->iconic
== iconic
) return; /* nothing to do */
1474 g_message("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1477 self
->iconic
= iconic
;
1480 self
->wmstate
= IconicState
;
1481 self
->ignore_unmaps
++;
1482 /* we unmap the client itself so that we can get MapRequest events,
1483 and because the ICCCM tells us to! */
1484 XUnmapWindow(ob_display
, self
->window
);
1487 client_set_desktop(self
, screen_desktop
);
1488 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1489 XMapWindow(ob_display
, self
->window
);
1491 client_change_state(self
);
1492 client_showhide(self
);
1493 screen_update_struts();
1496 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1500 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1501 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1503 /* check if already done */
1505 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1506 if (dir
== 1 && self
->max_horz
) return;
1507 if (dir
== 2 && self
->max_vert
) return;
1509 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1510 if (dir
== 1 && !self
->max_horz
) return;
1511 if (dir
== 2 && !self
->max_vert
) return;
1514 /* work with the frame's coords */
1515 x
= self
->frame
->area
.x
;
1516 y
= self
->frame
->area
.y
;
1517 w
= self
->area
.width
;
1518 h
= self
->area
.height
;
1530 /* get the property off the window and use it for the dimensions
1531 we are already maxed on */
1532 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1534 if (self
->max_horz
) {
1535 dimensions
[0] = readdim
[0];
1536 dimensions
[2] = readdim
[2];
1538 if (self
->max_vert
) {
1539 dimensions
[1] = readdim
[1];
1540 dimensions
[3] = readdim
[3];
1545 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1548 if (dir
== 0 || dir
== 1) { /* horz */
1549 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1550 w
= screen_area(self
->desktop
)->x
+
1551 screen_area(self
->desktop
)->width
;
1553 if (dir
== 0 || dir
== 2) { /* vert */
1554 y
= screen_area(self
->desktop
)->y
;
1555 h
= screen_area(self
->desktop
)->y
+
1556 screen_area(self
->desktop
)->height
-
1557 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1562 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1564 if (dir
== 0 || dir
== 1) { /* horz */
1568 if (dir
== 0 || dir
== 2) { /* vert */
1574 /* pick some fallbacks... */
1575 if (dir
== 0 || dir
== 1) { /* horz */
1576 x
= screen_area(self
->desktop
)->x
+
1577 screen_area(self
->desktop
)->width
/ 4;
1578 w
= screen_area(self
->desktop
)->width
/ 2;
1580 if (dir
== 0 || dir
== 2) { /* vert */
1581 y
= screen_area(self
->desktop
)->y
+
1582 screen_area(self
->desktop
)->height
/ 4;
1583 h
= screen_area(self
->desktop
)->height
/ 2;
1588 if (dir
== 0 || dir
== 1) /* horz */
1589 self
->max_horz
= max
;
1590 if (dir
== 0 || dir
== 2) /* vert */
1591 self
->max_vert
= max
;
1593 if (!self
->max_horz
&& !self
->max_vert
)
1594 PROP_ERASE(self
->window
, openbox_premax
);
1596 client_change_state(self
); /* change the state hints on the client */
1598 /* figure out where the client should be going */
1599 frame_frame_gravity(self
->frame
, &x
, &y
);
1600 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1603 void client_shade(Client
*self
, gboolean shade
)
1605 if (!(self
->functions
& Func_Shade
) || /* can't */
1606 self
->shaded
== shade
) return; /* already done */
1608 /* when we're iconic, don't change the wmstate */
1610 self
->wmstate
= shade
? IconicState
: NormalState
;
1611 self
->shaded
= shade
;
1612 client_change_state(self
);
1613 engine_frame_adjust_size(self
->frame
);
1616 void client_close(Client
*self
)
1620 if (!(self
->functions
& Func_Close
)) return;
1623 XXX: itd be cool to do timeouts and shit here for killing the client's
1625 like... if the window is around after 5 seconds, then the close button
1626 turns a nice red, and if this function is called again, the client is
1630 ce
.xclient
.type
= ClientMessage
;
1631 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1632 ce
.xclient
.display
= ob_display
;
1633 ce
.xclient
.window
= self
->window
;
1634 ce
.xclient
.format
= 32;
1635 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1636 ce
.xclient
.data
.l
[1] = CurrentTime
;
1637 ce
.xclient
.data
.l
[2] = 0l;
1638 ce
.xclient
.data
.l
[3] = 0l;
1639 ce
.xclient
.data
.l
[4] = 0l;
1640 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1643 void client_set_desktop(Client
*self
, guint target
)
1647 if (target
== self
->desktop
) return;
1649 g_message("Setting desktop %u\n", target
);
1651 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1653 old
= self
->desktop
;
1654 self
->desktop
= target
;
1655 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1656 /* the frame can display the current desktop state */
1657 engine_frame_adjust_state(self
->frame
);
1658 /* 'move' the window to the new desktop */
1659 client_showhide(self
);
1660 screen_update_struts();
1662 /* update the focus lists */
1663 if (old
== DESKTOP_ALL
) {
1664 for (i
= 0; i
< screen_num_desktops
; ++i
)
1665 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1667 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1669 if (target
== DESKTOP_ALL
) {
1670 for (i
= 0; i
< screen_num_desktops
; ++i
)
1671 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1673 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1676 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1679 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1684 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1685 Client
*c
= it
->data
;
1686 if (c
== skip
) continue; /* circular? */
1687 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1688 if (c
->modal
) return c
;
1693 Client
*client_find_modal_child(Client
*self
)
1695 return search_modal_tree(self
, self
);
1698 gboolean
client_validate(Client
*self
)
1702 XSync(ob_display
, FALSE
); /* get all events on the server */
1704 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1705 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1706 XPutBackEvent(ob_display
, &e
);
1713 void client_set_wm_state(Client
*self
, long state
)
1715 if (state
== self
->wmstate
) return; /* no change */
1719 client_iconify(self
, TRUE
, TRUE
);
1722 client_iconify(self
, FALSE
, TRUE
);
1727 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1729 gboolean shaded
= self
->shaded
;
1730 gboolean fullscreen
= self
->fullscreen
;
1731 gboolean max_horz
= self
->max_horz
;
1732 gboolean max_vert
= self
->max_vert
;
1735 if (!(action
== prop_atoms
.net_wm_state_add
||
1736 action
== prop_atoms
.net_wm_state_remove
||
1737 action
== prop_atoms
.net_wm_state_toggle
))
1738 /* an invalid action was passed to the client message, ignore it */
1741 for (i
= 0; i
< 2; ++i
) {
1742 Atom state
= i
== 0 ? data1
: data2
;
1744 if (!state
) continue;
1746 /* if toggling, then pick whether we're adding or removing */
1747 if (action
== prop_atoms
.net_wm_state_toggle
) {
1748 if (state
== prop_atoms
.net_wm_state_modal
)
1749 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1750 prop_atoms
.net_wm_state_add
;
1751 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1752 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1753 prop_atoms
.net_wm_state_add
;
1754 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1755 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1756 prop_atoms
.net_wm_state_add
;
1757 else if (state
== prop_atoms
.net_wm_state_shaded
)
1758 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1759 prop_atoms
.net_wm_state_add
;
1760 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1761 action
= self
->skip_taskbar
?
1762 prop_atoms
.net_wm_state_remove
:
1763 prop_atoms
.net_wm_state_add
;
1764 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1765 action
= self
->skip_pager
?
1766 prop_atoms
.net_wm_state_remove
:
1767 prop_atoms
.net_wm_state_add
;
1768 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1769 action
= self
->fullscreen
?
1770 prop_atoms
.net_wm_state_remove
:
1771 prop_atoms
.net_wm_state_add
;
1772 else if (state
== prop_atoms
.net_wm_state_above
)
1773 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1774 prop_atoms
.net_wm_state_add
;
1775 else if (state
== prop_atoms
.net_wm_state_below
)
1776 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1777 prop_atoms
.net_wm_state_add
;
1780 if (action
== prop_atoms
.net_wm_state_add
) {
1781 if (state
== prop_atoms
.net_wm_state_modal
) {
1782 /* XXX raise here or something? */
1784 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1786 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1788 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1790 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1791 self
->skip_taskbar
= TRUE
;
1792 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1793 self
->skip_pager
= TRUE
;
1794 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1796 } else if (state
== prop_atoms
.net_wm_state_above
) {
1798 } else if (state
== prop_atoms
.net_wm_state_below
) {
1802 } else { /* action == prop_atoms.net_wm_state_remove */
1803 if (state
== prop_atoms
.net_wm_state_modal
) {
1804 self
->modal
= FALSE
;
1805 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1807 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1809 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1811 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1812 self
->skip_taskbar
= FALSE
;
1813 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1814 self
->skip_pager
= FALSE
;
1815 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1817 } else if (state
== prop_atoms
.net_wm_state_above
) {
1818 self
->above
= FALSE
;
1819 } else if (state
== prop_atoms
.net_wm_state_below
) {
1820 self
->below
= FALSE
;
1824 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1825 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1827 if (max_horz
== max_vert
) { /* both going the same way */
1828 client_maximize(self
, max_horz
, 0, TRUE
);
1830 client_maximize(self
, max_horz
, 1, TRUE
);
1831 client_maximize(self
, max_vert
, 2, TRUE
);
1835 if (max_horz
!= self
->max_horz
)
1836 client_maximize(self
, max_horz
, 1, TRUE
);
1838 client_maximize(self
, max_vert
, 2, TRUE
);
1841 /* change fullscreen state before shading, as it will affect if the window
1843 if (fullscreen
!= self
->fullscreen
)
1844 client_fullscreen(self
, fullscreen
, TRUE
);
1845 if (shaded
!= self
->shaded
)
1846 client_shade(self
, shaded
);
1847 client_calc_layer(self
);
1848 client_change_state(self
); /* change the hint to relect these changes */
1851 gboolean
client_focus(Client
*self
)
1856 /* if we have a modal child, then focus it, not us */
1857 child
= client_find_modal_child(self
);
1859 return client_focus(child
);
1861 /* won't try focus if the client doesn't want it, or if the window isn't
1862 visible on the screen */
1863 if (!(self
->frame
->visible
&&
1864 (self
->can_focus
|| self
->focus_notify
)))
1867 /* do a check to see if the window has already been unmapped or destroyed
1868 do this intelligently while watching out for unmaps we've generated
1869 (ignore_unmaps > 0) */
1870 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1871 DestroyNotify
, &ev
)) {
1872 XPutBackEvent(ob_display
, &ev
);
1875 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1876 UnmapNotify
, &ev
)) {
1877 if (self
->ignore_unmaps
) {
1878 self
->ignore_unmaps
--;
1880 XPutBackEvent(ob_display
, &ev
);
1885 if (self
->can_focus
)
1886 XSetInputFocus(ob_display
, self
->window
, RevertToNone
, CurrentTime
);
1888 if (self
->focus_notify
) {
1890 ce
.xclient
.type
= ClientMessage
;
1891 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1892 ce
.xclient
.display
= ob_display
;
1893 ce
.xclient
.window
= self
->window
;
1894 ce
.xclient
.format
= 32;
1895 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1896 ce
.xclient
.data
.l
[1] = event_lasttime
;
1897 ce
.xclient
.data
.l
[2] = 0l;
1898 ce
.xclient
.data
.l
[3] = 0l;
1899 ce
.xclient
.data
.l
[4] = 0l;
1900 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1903 /*XSync(ob_display, FALSE); XXX Why sync? */
1907 void client_unfocus(Client
*self
)
1909 g_assert(focus_client
== self
);
1910 focus_set_client(NULL
);