4 #include "extensions.h"
8 #include "clientwrap.h"
12 #include <X11/Xutil.h>
14 /*! The event mask to grab on client windows */
15 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
18 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
21 GSList
*client_list
= NULL
;
22 GHashTable
*client_map
= NULL
;
24 static void client_get_all(Client
*self
);
25 static void client_toggle_border(Client
*self
, gboolean show
);
26 static void client_get_area(Client
*self
);
27 static void client_get_desktop(Client
*self
);
28 static void client_get_state(Client
*self
);
29 static void client_get_shaped(Client
*self
);
30 static void client_get_mwm_hints(Client
*self
);
31 static void client_get_gravity(Client
*self
);
32 static void client_change_allowed_actions(Client
*self
);
33 static void client_change_state(Client
*self
);
34 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
35 static void client_apply_startup_state(Client
*self
);
36 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
38 static guint
map_hash(Window w
) { return w
; }
39 static gboolean
map_key_comp(Window w1
, Window w2
) { return w1
== w2
; }
43 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
44 (GEqualFunc
)map_key_comp
);
48 void client_shutdown()
50 g_hash_table_destroy(client_map
);
53 void client_set_list()
55 Window
*windows
, *win_it
;
57 guint size
= g_slist_length(client_list
);
59 /* create an array of the window ids */
61 windows
= g_new(Window
, size
);
63 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
64 *win_it
= ((Client
*)it
->data
)->window
;
68 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
76 void client_manage_all()
78 unsigned int i
, j
, nchild
;
81 XWindowAttributes attrib
;
83 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
85 /* remove all icon windows from the list */
86 for (i
= 0; i
< nchild
; i
++) {
87 if (children
[i
] == None
) continue;
88 wmhints
= XGetWMHints(ob_display
, children
[i
]);
90 if ((wmhints
->flags
& IconWindowHint
) &&
91 (wmhints
->icon_window
!= children
[i
]))
92 for (j
= 0; j
< nchild
; j
++)
93 if (children
[j
] == wmhints
->icon_window
) {
101 for (i
= 0; i
< nchild
; ++i
) {
102 if (children
[i
] == None
)
104 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
105 if (attrib
.override_redirect
) continue;
107 if (attrib
.map_state
!= IsUnmapped
)
108 client_manage(children
[i
]);
114 void client_manage(Window window
)
118 XWindowAttributes attrib
;
119 XSetWindowAttributes attrib_set
;
122 XGrabServer(ob_display
);
123 XSync(ob_display
, FALSE
);
125 /* check if it has already been unmapped by the time we started mapping
126 the grab does a sync so we don't have to here */
127 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
128 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
129 XPutBackEvent(ob_display
, &e
);
131 XUngrabServer(ob_display
);
133 return; /* don't manage it */
136 /* make sure it isn't an override-redirect window */
137 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
138 attrib
.override_redirect
) {
139 XUngrabServer(ob_display
);
141 return; /* don't manage it */
144 /* is the window a docking app */
145 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
146 if ((wmhint
->flags
& StateHint
) &&
147 wmhint
->initial_state
== WithdrawnState
) {
148 /* XXX: make dock apps work! */
149 XUngrabServer(ob_display
);
157 /* choose the events we want to receive on the CLIENT window */
158 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
159 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
160 XChangeWindowAttributes(ob_display
, window
,
161 CWEventMask
|CWDontPropagate
, &attrib_set
);
164 /* create the Client struct, and populate it from the hints on the
166 client
= g_new(Client
, 1);
167 client
->window
= window
;
168 client_get_all(client
);
170 /* remove the client's border (and adjust re gravity) */
171 client_toggle_border(client
, FALSE
);
173 /* specify that if we exit, the window should not be destroyed and should
174 be reparented back to root automatically */
175 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
177 /* create the decoration frame for the client window */
178 client
->frame
= frame_new(client
);
180 frame_grab_client(client
->frame
);
182 client_apply_startup_state(client
);
184 XUngrabServer(ob_display
);
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 stacking_raise(client
);
193 screen_update_struts();
195 LOGICALHOOK(NewWindow
, g_quark_try_string("client"), client
);
197 client_showhide(client
);
199 /* grab all mouse bindings */
200 mbind_grab_all(client
, TRUE
);
202 /* update the list hints */
205 g_message("Managed window 0x%lx frame 0x%lx", window
,
206 client
->frame
->window
);
209 void client_unmanage_all()
211 while (client_list
!= NULL
) {
212 client_unmanage(client_list
->data
);
216 void client_unmanage(Client
*client
)
221 g_message("Unmanaging window: %lx", client
->window
);
223 LOGICALHOOK(CloseWindow
, g_quark_try_string("client"), client
);
225 /* remove the window from our save set */
226 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
228 /* we dont want events no more */
229 XSelectInput(ob_display
, client
->window
, NoEventMask
);
231 /* ungrab any mouse bindings */
232 mbind_grab_all(client
, FALSE
);
234 frame_hide(client
->frame
);
236 /* give the client its border back */
237 client_toggle_border(client
, TRUE
);
239 /* reparent the window out of the frame */
240 frame_release_client(client
->frame
);
242 client_list
= g_slist_remove(client_list
, client
);
243 stacking_list
= g_list_remove(stacking_list
, client
);
244 g_hash_table_remove(client_map
, (gpointer
)client
->window
);
246 /* once the client is out of the list, update the struts to remove it's
248 screen_update_struts();
250 frame_free(client
->frame
);
252 /* notify the wrapper that its useless now */
253 if (client
->wrap
!= NULL
)
254 client
->wrap
->client
= NULL
;
256 /* tell our parent that we're gone */
257 if (client
->transient_for
!= NULL
)
258 client
->transient_for
->transients
=
259 g_slist_remove(client
->transient_for
->transients
, client
);
261 /* tell our transients that we're gone */
262 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
263 Client
*t
= ((Client
*)it
->data
)->transient_for
;
264 ((Client
*)it
->data
)->transient_for
= NULL
;
266 client_calc_layer(it
->data
);
269 /* unfocus the client (calls the focus callbacks) (we're out of the
270 transient lists already, so being modal doesn't matter) */
272 client_unfocus(client
);
274 if (ob_state
!= State_Exiting
) {
275 /* these values should not be persisted across a window
277 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
278 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
280 /* if we're left in an iconic state, the client wont be mapped. this is
281 bad, since we will no longer be managing the window on restart */
283 XMapWindow(ob_display
, client
->window
);
286 /* free all data allocated in the client struct */
287 g_slist_free(client
->transients
);
288 for (j
= 0; j
< client
->nicons
; ++j
)
289 g_free(client
->icons
[j
].data
);
290 if (client
->nicons
> 0)
291 g_free(client
->icons
);
292 g_free(client
->title
);
293 g_free(client
->icon_title
);
294 g_free(client
->res_name
);
295 g_free(client
->res_class
);
296 g_free(client
->role
);
299 /* update the list hints */
303 static void client_toggle_border(Client
*self
, gboolean show
)
305 /* adjust our idea of where the client is, based on its border. When the
306 border is removed, the client should now be considered to be in a
308 when re-adding the border to the client, the same operation needs to be
310 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
311 int x
= oldx
, y
= oldy
;
312 switch(self
->gravity
) {
314 case NorthWestGravity
:
316 case SouthWestGravity
:
318 case NorthEastGravity
:
320 case SouthEastGravity
:
321 if (show
) x
-= self
->border_width
* 2;
322 else x
+= self
->border_width
* 2;
329 if (show
) x
-= self
->border_width
;
330 else x
+= self
->border_width
;
333 switch(self
->gravity
) {
335 case NorthWestGravity
:
337 case NorthEastGravity
:
339 case SouthWestGravity
:
341 case SouthEastGravity
:
342 if (show
) y
-= self
->border_width
* 2;
343 else y
+= self
->border_width
* 2;
350 if (show
) y
-= self
->border_width
;
351 else y
+= self
->border_width
;
358 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
360 /* move the client so it is back it the right spot _with_ its
362 if (x
!= oldx
|| y
!= oldy
)
363 XMoveWindow(ob_display
, self
->window
, x
, y
);
365 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
369 static void client_get_all(Client
*self
)
371 /* update EVERYTHING!! */
373 self
->ignore_unmaps
= 0;
377 self
->title
= self
->icon_title
= NULL
;
378 self
->res_name
= self
->res_class
= self
->role
= NULL
;
379 self
->wmstate
= NormalState
;
380 self
->focused
= FALSE
;
381 self
->transient
= FALSE
;
382 self
->transients
= NULL
;
383 self
->transient_for
= NULL
;
385 self
->urgent
= FALSE
;
386 self
->positioned
= FALSE
;
387 self
->disabled_decorations
= 0;
392 client_get_area(self
);
393 client_get_desktop(self
);
394 client_get_state(self
);
395 client_get_shaped(self
);
397 client_update_transient_for(self
);
398 client_get_mwm_hints(self
);
399 client_get_type(self
);/* this can change the mwmhints for special cases */
401 client_update_protocols(self
);
403 client_get_gravity(self
); /* get the attribute gravity */
404 client_update_normal_hints(self
); /* this may override the attribute
407 /* got the type, the mwmhints, the protocols, and the normal hints
408 (min/max sizes), so we're ready to set up the decorations/functions */
409 client_setup_decor_and_functions(self
);
411 client_update_wmhints(self
);
412 client_update_title(self
);
413 client_update_icon_title(self
);
414 client_update_class(self
);
415 client_update_strut(self
);
416 client_update_icons(self
);
417 client_update_kwm_icon(self
);
419 /* this makes sure that these windows appear on all desktops */
420 if (self
->type
== Type_Desktop
)
421 self
->desktop
= DESKTOP_ALL
;
423 /* set the desktop hint, to make sure that it always exists, and to
424 reflect any changes we've made here */
425 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
427 client_change_state(self
);
430 static void client_get_area(Client
*self
)
432 XWindowAttributes wattrib
;
435 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
436 g_assert(ret
!= BadWindow
);
438 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
439 self
->border_width
= wattrib
.border_width
;
442 static void client_get_desktop(Client
*self
)
446 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
447 if (d
>= screen_desktop
&& d
!= DESKTOP_ALL
)
448 d
= screen_desktop
- 1;
451 /* defaults to the current desktop */
452 self
->desktop
= screen_desktop
;
456 static void client_get_state(Client
*self
)
461 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
462 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
463 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
465 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
467 for (i
= 0; i
< num
; ++i
) {
468 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
470 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
472 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
474 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
475 self
->skip_taskbar
= TRUE
;
476 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
477 self
->skip_pager
= TRUE
;
478 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
479 self
->fullscreen
= TRUE
;
480 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
481 self
->max_vert
= TRUE
;
482 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
483 self
->max_horz
= TRUE
;
484 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
486 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
494 static void client_get_shaped(Client
*self
)
496 self
->shaped
= FALSE
;
498 if (extensions_shape
) {
503 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
505 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
506 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
508 self
->shaped
= (s
!= 0);
513 void client_update_transient_for(Client
*self
)
518 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
519 t
!= self
->window
) { /* cant be transient to itself! */
520 self
->transient
= TRUE
;
521 c
= g_hash_table_lookup(client_map
, (gpointer
)t
);
522 g_assert(c
!= self
);/* if this happens then we need to check for it*/
524 if (!c
/*XXX: && _group*/) {
525 /* not transient to a client, see if it is transient for a
527 if (/*t == _group->leader() || */
530 /* window is a transient for its group! */
531 /* XXX: for now this is treated as non-transient.
532 this needs to be fixed! */
536 self
->transient
= FALSE
;
538 /* if anything has changed... */
539 if (c
!= self
->transient_for
) {
540 if (self
->transient_for
)
541 /* remove from old parent */
542 g_slist_remove(self
->transient_for
->transients
, self
);
543 self
->transient_for
= c
;
544 if (self
->transient_for
)
545 /* add to new parent */
546 g_slist_append(self
->transient_for
->transients
, self
);
550 static void client_get_mwm_hints(Client
*self
)
553 unsigned long *hints
;
555 self
->mwmhints
.flags
= 0; /* default to none */
557 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
558 if (num
>= MWM_ELEMENTS
) {
559 self
->mwmhints
.flags
= hints
[0];
560 self
->mwmhints
.functions
= hints
[1];
561 self
->mwmhints
.decorations
= hints
[2];
567 void client_get_type(Client
*self
)
573 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
574 /* use the first value that we know about in the array */
575 for (i
= 0; i
< num
; ++i
) {
576 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
577 self
->type
= Type_Desktop
;
578 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
579 self
->type
= Type_Dock
;
580 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
581 self
->type
= Type_Toolbar
;
582 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
583 self
->type
= Type_Menu
;
584 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
585 self
->type
= Type_Utility
;
586 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
587 self
->type
= Type_Splash
;
588 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
589 self
->type
= Type_Dialog
;
590 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
591 self
->type
= Type_Normal
;
592 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
593 /* prevent this window from getting any decor or
595 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
596 MwmFlag_Decorations
);
597 self
->mwmhints
.decorations
= 0;
598 self
->mwmhints
.functions
= 0;
600 if (self
->type
!= (WindowType
) -1)
601 break; /* grab the first legit type */
606 if (self
->type
== (WindowType
) -1) {
607 /*the window type hint was not set, which means we either classify
608 ourself as a normal window or a dialog, depending on if we are a
611 self
->type
= Type_Dialog
;
613 self
->type
= Type_Normal
;
617 void client_update_protocols(Client
*self
)
620 int num_return
= 0, i
;
622 self
->focus_notify
= FALSE
;
623 self
->delete_window
= FALSE
;
625 if (XGetWMProtocols(ob_display
, self
->window
, &proto
, &num_return
)) {
626 for (i
= 0; i
< num_return
; ++i
) {
627 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
628 /* this means we can request the window to close */
629 self
->delete_window
= TRUE
;
630 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
631 /* if this protocol is requested, then the window will be
632 notified whenever we want it to receive focus */
633 self
->focus_notify
= TRUE
;
639 static void client_get_gravity(Client
*self
)
641 XWindowAttributes wattrib
;
644 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
645 g_assert(ret
!= BadWindow
);
646 self
->gravity
= wattrib
.win_gravity
;
649 void client_update_normal_hints(Client
*self
)
653 int oldgravity
= self
->gravity
;
656 self
->min_ratio
= 0.0f
;
657 self
->max_ratio
= 0.0f
;
658 SIZE_SET(self
->size_inc
, 1, 1);
659 SIZE_SET(self
->base_size
, 0, 0);
660 SIZE_SET(self
->min_size
, 0, 0);
661 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
663 /* get the hints from the window */
664 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
665 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
667 if (size
.flags
& PWinGravity
) {
668 self
->gravity
= size
.win_gravity
;
670 /* if the client has a frame, i.e. has already been mapped and
671 is changing its gravity */
672 if (self
->frame
&& self
->gravity
!= oldgravity
) {
673 /* move our idea of the client's position based on its new
675 self
->area
.x
= self
->frame
->area
.x
;
676 self
->area
.y
= self
->frame
->area
.y
;
677 frame_frame_gravity(self
->frame
,
678 &self
->area
.x
, &self
->area
.y
);
682 if (size
.flags
& PAspect
) {
683 if (size
.min_aspect
.y
)
684 self
->min_ratio
= size
.min_aspect
.x
/ size
.min_aspect
.y
;
685 if (size
.max_aspect
.y
)
686 self
->max_ratio
= size
.max_aspect
.x
/ size
.max_aspect
.y
;
689 if (size
.flags
& PMinSize
)
690 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
692 if (size
.flags
& PMaxSize
)
693 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
695 if (size
.flags
& PBaseSize
)
696 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
698 if (size
.flags
& PResizeInc
)
699 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
703 void client_setup_decor_and_functions(Client
*self
)
705 /* start with everything (cept fullscreen) */
706 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
707 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
708 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
710 if (self
->delete_window
) {
711 self
->decorations
|= Decor_Close
;
712 self
->functions
|= Func_Close
;
715 if (!(self
->min_size
.width
< self
->max_size
.width
||
716 self
->min_size
.height
< self
->max_size
.height
)) {
717 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
718 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
721 switch (self
->type
) {
723 /* normal windows retain all of the possible decorations and
724 functionality, and are the only windows that you can fullscreen */
725 self
->functions
|= Func_Fullscreen
;
729 /* dialogs cannot be maximized */
730 self
->decorations
&= ~Decor_Maximize
;
731 self
->functions
&= ~Func_Maximize
;
737 /* these windows get less functionality */
738 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
739 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
745 /* none of these windows are manipulated by the window manager */
746 self
->decorations
= 0;
751 /* Mwm Hints are applied subtractively to what has already been chosen for
752 decor and functionality */
753 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
754 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
755 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
756 self
->decorations
&= ~Decor_Border
;
757 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
758 self
->decorations
&= ~Decor_Handle
;
759 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
760 self
->decorations
&= ~Decor_Titlebar
;
761 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
762 self
->decorations
&= ~Decor_Iconify
;
763 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
764 self
->decorations
&= ~Decor_Maximize
;
768 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
769 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
770 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
771 self
->functions
&= ~Func_Resize
;
772 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
773 self
->functions
&= ~Func_Move
;
774 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
775 self
->functions
&= ~Func_Iconify
;
776 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
777 self
->functions
&= ~Func_Maximize
;
778 /* dont let mwm hints kill the close button
779 if (! (self->mwmhints.functions & MwmFunc_Close))
780 self->functions &= ~Func_Close; */
784 /* can't maximize without moving/resizing */
785 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
786 self
->functions
&= ~Func_Maximize
;
788 /* finally, user specified disabled decorations are applied to subtract
790 if (self
->disabled_decorations
& Decor_Titlebar
)
791 self
->decorations
&= ~Decor_Titlebar
;
792 if (self
->disabled_decorations
& Decor_Handle
)
793 self
->decorations
&= ~Decor_Handle
;
794 if (self
->disabled_decorations
& Decor_Border
)
795 self
->decorations
&= ~Decor_Border
;
796 if (self
->disabled_decorations
& Decor_Iconify
)
797 self
->decorations
&= ~Decor_Iconify
;
798 if (self
->disabled_decorations
& Decor_Maximize
)
799 self
->decorations
&= ~Decor_Maximize
;
800 if (self
->disabled_decorations
& Decor_AllDesktops
)
801 self
->decorations
&= ~Decor_AllDesktops
;
802 if (self
->disabled_decorations
& Decor_Close
)
803 self
->decorations
&= ~Decor_Close
;
805 /* if we don't have a titlebar, then we cannot shade! */
806 if (!(self
->decorations
& Decor_Titlebar
))
807 self
->functions
&= ~Func_Shade
;
809 client_change_allowed_actions(self
);
812 /* change the decors on the frame */
813 frame_adjust_size(self
->frame
);
814 /* with more/less decorations, we may need to be repositioned */
815 frame_adjust_position(self
->frame
);
816 /* with new decor, the window's maximized size may change */
817 client_remaximize(self
);
821 static void client_change_allowed_actions(Client
*self
)
826 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
828 if (self
->functions
& Func_Shade
)
829 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
830 if (self
->functions
& Func_Close
)
831 actions
[num
++] = prop_atoms
.net_wm_action_close
;
832 if (self
->functions
& Func_Move
)
833 actions
[num
++] = prop_atoms
.net_wm_action_move
;
834 if (self
->functions
& Func_Iconify
)
835 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
836 if (self
->functions
& Func_Resize
)
837 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
838 if (self
->functions
& Func_Fullscreen
)
839 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
840 if (self
->functions
& Func_Maximize
) {
841 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
842 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
845 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
847 /* make sure the window isn't breaking any rules now */
849 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
850 if (self
->frame
) client_shade(self
, FALSE
);
851 else self
->shaded
= FALSE
;
853 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
854 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
855 else self
->iconic
= FALSE
;
857 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
858 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
859 else self
->fullscreen
= FALSE
;
861 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
863 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
864 else self
->max_vert
= self
->max_horz
= FALSE
;
868 void client_remaximize(Client
*self
)
871 if (self
->max_horz
&& self
->max_vert
)
873 else if (self
->max_horz
)
875 else if (self
->max_vert
)
878 return; /* not maximized */
879 self
->max_horz
= self
->max_vert
= FALSE
;
880 client_maximize(self
, TRUE
, dir
, FALSE
);
883 void client_update_wmhints(Client
*self
)
888 /* assume a window takes input if it doesnt specify */
889 self
->can_focus
= TRUE
;
891 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
892 if (hints
->flags
& InputHint
)
893 self
->can_focus
= hints
->input
;
895 /* only do this when starting! */
896 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
897 self
->iconic
= hints
->initial_state
== IconicState
;
899 if (hints
->flags
& XUrgencyHint
)
902 if (hints
->flags
& WindowGroupHint
) {
903 if (hints
->window_group
!= self
->group
) {
904 /* XXX: remove from the old group if there was one */
905 self
->group
= hints
->window_group
;
906 /* XXX: do stuff with the group */
908 } else /* no group! */
911 if (hints
->flags
& IconPixmapHint
) {
912 client_update_kwm_icon(self
);
913 /* try get the kwm icon first, this is a fallback only */
914 if (self
->pixmap_icon
== None
) {
915 self
->pixmap_icon
= hints
->icon_pixmap
;
916 if (hints
->flags
& IconMaskHint
)
917 self
->pixmap_icon_mask
= hints
->icon_mask
;
919 self
->pixmap_icon_mask
= None
;
922 frame_adjust_icon(self
->frame
);
929 if (ur
!= self
->urgent
) {
931 g_message("Urgent Hint for 0x%lx: %s\n", self
->window
,
933 /* fire the urgent callback if we're mapped, otherwise, wait until
934 after we're mapped */
936 LOGICALHOOK(UrgentWindow
, g_quark_try_string("client"), self
);
940 void client_update_title(Client
*self
)
944 if (self
->title
!= NULL
)
948 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
949 /* try old x stuff */
950 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
951 /* convert it to UTF-8 */
955 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
957 g_warning("Unable to convert string to UTF-8");
966 data
= g_strdup("Unnamed Window");
971 frame_adjust_title(self
->frame
);
974 void client_update_icon_title(Client
*self
)
978 if (self
->icon_title
!= NULL
)
979 g_free(self
->icon_title
);
982 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
983 /* try old x stuff */
984 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
985 /* convert it to UTF-8 */
989 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
991 g_warning("Unable to convert string to UTF-8");
1000 data
= g_strdup(self
->title
);
1002 self
->icon_title
= data
;
1005 void client_update_class(Client
*self
)
1011 if (self
->res_name
) g_free(self
->res_name
);
1012 if (self
->res_class
) g_free(self
->res_class
);
1013 if (self
->role
) g_free(self
->role
);
1015 self
->res_name
= self
->res_class
= self
->role
= NULL
;
1017 data
= g_ptr_array_new();
1019 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1021 self
->res_name
= g_strdup(g_ptr_array_index(data
, 0));
1023 self
->res_class
= g_strdup(g_ptr_array_index(data
, 1));
1026 for (i
= 0; i
< data
->len
; ++i
)
1027 g_free(g_ptr_array_index(data
, i
));
1028 g_ptr_array_free(data
, TRUE
);
1030 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1031 self
->role
= g_strdup(s
);
1033 if (self
->res_name
== NULL
) self
->res_name
= g_strdup("");
1034 if (self
->res_class
== NULL
) self
->res_class
= g_strdup("");
1035 if (self
->role
== NULL
) self
->role
= g_strdup("");
1038 void client_update_strut(Client
*self
)
1043 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, num
)) {
1044 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1047 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1049 /* updating here is pointless while we're being mapped cuz we're not in
1050 the client list yet */
1052 screen_update_struts();
1055 void client_update_icons(Client
*self
)
1058 unsigned long *data
;
1059 unsigned long w
, h
, i
;
1062 for (j
= 0; j
< self
->nicons
; ++j
)
1063 g_free(self
->icons
[j
].data
);
1064 if (self
->nicons
> 0)
1065 g_free(self
->icons
);
1068 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1069 /* figure out how many valid icons are in here */
1071 while (num
- i
> 2) {
1079 self
->icons
= g_new(Icon
, self
->nicons
);
1081 /* store the icons */
1083 for (j
= 0; j
< self
->nicons
; ++j
) {
1084 w
= self
->icons
[j
].w
= data
[i
++];
1085 h
= self
->icons
[j
].h
= data
[i
++];
1086 self
->icons
[j
].data
=
1087 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1095 if (self
->nicons
<= 0) {
1097 self
->icons
= g_new0(Icon
, 1);
1101 frame_adjust_icon(self
->frame
);
1104 void client_update_kwm_icon(Client
*self
)
1108 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1109 self
->pixmap_icon
= data
[0];
1110 self
->pixmap_icon_mask
= data
[1];
1113 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1116 frame_adjust_icon(self
->frame
);
1119 static void client_change_state(Client
*self
)
1121 unsigned long state
[2];
1125 state
[0] = self
->wmstate
;
1127 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1131 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1133 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1135 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1136 if (self
->skip_taskbar
)
1137 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1138 if (self
->skip_pager
)
1139 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1140 if (self
->fullscreen
)
1141 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1143 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1145 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1147 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1149 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1150 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1152 client_calc_layer(self
);
1155 frame_adjust_state(self
->frame
);
1158 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1163 for (it
= node
->transients
; it
!= NULL
; it
= g_slist_next(it
)) {
1164 Client
*c
= it
->data
;
1165 if (c
== skip
) continue; /* circular? */
1166 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1167 if (c
->focused
) return c
;
1172 void client_calc_layer(Client
*self
)
1178 /* are we fullscreen, or do we have a fullscreen transient parent? */
1182 if (c
->fullscreen
) {
1186 c
= c
->transient_for
;
1188 if (!fs
&& self
->fullscreen
) {
1189 /* is one of our transients focused? */
1190 c
= search_focus_tree(self
, self
);
1191 if (c
!= NULL
) fs
= TRUE
;
1194 if (self
->iconic
) l
= Layer_Icon
;
1195 else if (fs
) l
= Layer_Fullscreen
;
1196 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1197 else if (self
->type
== Type_Dock
) {
1198 if (!self
->below
) l
= Layer_Top
;
1199 else l
= Layer_Normal
;
1201 else if (self
->above
) l
= Layer_Above
;
1202 else if (self
->below
) l
= Layer_Below
;
1203 else l
= Layer_Normal
;
1205 if (l
!= self
->layer
) {
1208 stacking_raise(self
);
1212 void client_showhide(Client
*self
)
1216 if (self
->iconic
) show
= FALSE
;
1217 else if (!(self
->desktop
== screen_desktop
||
1218 self
->desktop
== DESKTOP_ALL
)) show
= FALSE
;
1219 else if (client_normal(self
) && screen_showing_desktop
) show
= FALSE
;
1222 if (show
) frame_show(self
->frame
);
1223 else frame_hide(self
->frame
);
1226 gboolean
client_normal(Client
*self
) {
1227 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1228 self
->type
== Type_Splash
);
1231 static void client_apply_startup_state(Client
*self
)
1233 /* these are in a carefully crafted order.. */
1236 self
->iconic
= FALSE
;
1237 client_iconify(self
, TRUE
, FALSE
);
1239 if (self
->fullscreen
) {
1240 self
->fullscreen
= FALSE
;
1241 client_fullscreen(self
, TRUE
, FALSE
);
1244 self
->shaded
= FALSE
;
1245 client_shade(self
, TRUE
);
1248 LOGICALHOOK(UrgentWindow
, g_quark_try_string("client"), self
);
1250 if (self
->max_vert
&& self
->max_horz
) {
1251 self
->max_vert
= self
->max_horz
= FALSE
;
1252 client_maximize(self
, TRUE
, 0, FALSE
);
1253 } else if (self
->max_vert
) {
1254 self
->max_vert
= FALSE
;
1255 client_maximize(self
, TRUE
, 2, FALSE
);
1256 } else if (self
->max_horz
) {
1257 self
->max_horz
= FALSE
;
1258 client_maximize(self
, TRUE
, 1, FALSE
);
1261 /* nothing to do for the other states:
1270 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1271 gboolean user
, gboolean final
)
1273 w
-= self
->base_size
.width
;
1274 h
-= self
->base_size
.height
;
1277 /* for interactive resizing. have to move half an increment in each
1280 /* how far we are towards the next size inc */
1281 int mw
= w
% self
->size_inc
.width
;
1282 int mh
= h
% self
->size_inc
.height
;
1284 int aw
= self
->size_inc
.width
/ 2;
1285 int ah
= self
->size_inc
.height
/ 2;
1286 /* don't let us move into a new size increment */
1287 if (mw
+ aw
>= self
->size_inc
.width
)
1288 aw
= self
->size_inc
.width
- mw
- 1;
1289 if (mh
+ ah
>= self
->size_inc
.height
)
1290 ah
= self
->size_inc
.height
- mh
- 1;
1294 /* if this is a user-requested resize, then check against min/max
1295 sizes and aspect ratios */
1297 /* smaller than min size or bigger than max size? */
1298 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1299 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1300 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1301 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1303 /* adjust the height ot match the width for the aspect ratios */
1304 if (self
->min_ratio
)
1305 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1306 if (self
->max_ratio
)
1307 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1310 /* keep to the increments */
1311 w
/= self
->size_inc
.width
;
1312 h
/= self
->size_inc
.height
;
1314 /* you cannot resize to nothing */
1318 /* store the logical size */
1319 SIZE_SET(self
->logical_size
, w
, h
);
1321 w
*= self
->size_inc
.width
;
1322 h
*= self
->size_inc
.height
;
1324 w
+= self
->base_size
.width
;
1325 h
+= self
->base_size
.height
;
1328 case Corner_TopLeft
:
1330 case Corner_TopRight
:
1331 x
-= w
- self
->area
.width
;
1333 case Corner_BottomLeft
:
1334 y
-= h
- self
->area
.height
;
1336 case Corner_BottomRight
:
1337 x
-= w
- self
->area
.width
;
1338 y
-= h
- self
->area
.height
;
1342 RECT_SET(self
->area
, x
, y
, w
, h
);
1344 XResizeWindow(ob_display
, self
->window
, w
, h
);
1346 /* move/resize the frame to match the request */
1348 /* Adjust the size and then the position, as required by the EWMH */
1349 frame_adjust_size(self
->frame
);
1350 frame_adjust_position(self
->frame
);
1352 if (!user
|| final
) {
1354 event
.type
= ConfigureNotify
;
1355 event
.xconfigure
.display
= ob_display
;
1356 event
.xconfigure
.event
= self
->window
;
1357 event
.xconfigure
.window
= self
->window
;
1359 /* root window coords with border in mind */
1360 event
.xconfigure
.x
= x
- self
->border_width
+
1361 self
->frame
->size
.left
;
1362 event
.xconfigure
.y
= y
- self
->border_width
+
1363 self
->frame
->size
.top
;
1365 event
.xconfigure
.width
= self
->area
.width
;
1366 event
.xconfigure
.height
= self
->area
.height
;
1367 event
.xconfigure
.border_width
= self
->border_width
;
1368 event
.xconfigure
.above
= self
->frame
->plate
;
1369 event
.xconfigure
.override_redirect
= FALSE
;
1370 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1371 FALSE
, StructureNotifyMask
, &event
);
1376 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1378 static int saved_func
, saved_decor
;
1381 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1382 self
->fullscreen
== fs
) return; /* already done */
1384 self
->fullscreen
= fs
;
1385 client_change_state(self
); /* change the state hints on the client */
1388 /* save the functions and remove them */
1389 saved_func
= self
->functions
;
1390 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1392 /* save the decorations and remove them */
1393 saved_decor
= self
->decorations
;
1394 self
->decorations
= 0;
1397 dimensions
[0] = self
->area
.x
;
1398 dimensions
[1] = self
->area
.y
;
1399 dimensions
[2] = self
->area
.width
;
1400 dimensions
[3] = self
->area
.height
;
1402 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1407 w
= screen_physical_size
.width
;
1408 h
= screen_physical_size
.height
;
1412 self
->functions
= saved_func
;
1413 self
->decorations
= saved_decor
;
1415 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1423 /* pick some fallbacks... */
1424 x
= screen_area(self
->desktop
)->x
+
1425 screen_area(self
->desktop
)->width
/ 4;
1426 y
= screen_area(self
->desktop
)->y
+
1427 screen_area(self
->desktop
)->height
/ 4;
1428 w
= screen_area(self
->desktop
)->width
/ 2;
1429 h
= screen_area(self
->desktop
)->height
/ 2;
1433 client_change_allowed_actions(self
); /* based on the new _functions */
1435 /* when fullscreening, don't obey things like increments, fill the
1437 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1439 /* raise (back) into our stacking layer */
1440 stacking_raise(self
);
1442 /* try focus us when we go into fullscreen mode */
1446 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1448 if (self
->iconic
== iconic
) return; /* nothing to do */
1450 g_message("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1453 self
->iconic
= iconic
;
1456 self
->wmstate
= IconicState
;
1457 self
->ignore_unmaps
++;
1458 /* we unmap the client itself so that we can get MapRequest events,
1459 and because the ICCCM tells us to! */
1460 XUnmapWindow(ob_display
, self
->window
);
1463 client_set_desktop(self
, screen_desktop
);
1464 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1465 XMapWindow(ob_display
, self
->window
);
1467 client_change_state(self
);
1468 client_showhide(self
);
1469 screen_update_struts();
1472 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1476 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1477 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1479 /* check if already done */
1481 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1482 if (dir
== 1 && self
->max_horz
) return;
1483 if (dir
== 2 && self
->max_vert
) return;
1485 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1486 if (dir
== 1 && !self
->max_horz
) return;
1487 if (dir
== 2 && !self
->max_vert
) return;
1490 x
= self
->frame
->area
.x
;
1491 y
= self
->frame
->area
.y
;
1492 w
= self
->frame
->area
.width
;
1493 h
= self
->frame
->area
.height
;
1505 /* get the property off the window and use it for the dimensions
1506 we are already maxed on */
1507 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1509 if (self
->max_horz
) {
1510 dimensions
[0] = readdim
[0];
1511 dimensions
[2] = readdim
[2];
1513 if (self
->max_vert
) {
1514 dimensions
[1] = readdim
[1];
1515 dimensions
[3] = readdim
[3];
1520 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1523 if (dir
== 0 || dir
== 1) { /* horz */
1524 x
= screen_area(self
->desktop
)->x
;
1525 w
= screen_area(self
->desktop
)->x
+
1526 screen_area(self
->desktop
)->width
;
1528 if (dir
== 0 || dir
== 2) { /* vert */
1529 y
= screen_area(self
->desktop
)->y
;
1530 h
= screen_area(self
->desktop
)->y
+
1531 screen_area(self
->desktop
)->height
-
1532 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1537 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1539 if (dir
== 0 || dir
== 1) { /* horz */
1543 if (dir
== 0 || dir
== 2) { /* vert */
1549 /* pick some fallbacks... */
1550 if (dir
== 0 || dir
== 1) { /* horz */
1551 x
= screen_area(self
->desktop
)->x
+
1552 screen_area(self
->desktop
)->width
/ 4;
1553 w
= screen_area(self
->desktop
)->width
/ 2;
1555 if (dir
== 0 || dir
== 2) { /* vert */
1556 y
= screen_area(self
->desktop
)->y
+
1557 screen_area(self
->desktop
)->height
/ 4;
1558 h
= screen_area(self
->desktop
)->height
/ 2;
1563 if (dir
== 0 || dir
== 1) /* horz */
1564 self
->max_horz
= max
;
1565 if (dir
== 0 || dir
== 2) /* vert */
1566 self
->max_vert
= max
;
1568 if (!self
->max_horz
&& !self
->max_vert
)
1569 PROP_ERASE(self
->window
, openbox_premax
);
1571 client_change_state(self
); /* change the state hints on the client */
1573 /* figure out where the client should be going */
1574 frame_frame_gravity(self
->frame
, &x
, &y
);
1575 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1578 void client_shade(Client
*self
, gboolean shade
)
1580 if (!(self
->functions
& Func_Shade
) || /* can't */
1581 self
->shaded
== shade
) return; /* already done */
1583 /* when we're iconic, don't change the wmstate */
1585 self
->wmstate
= shade
? IconicState
: NormalState
;
1586 self
->shaded
= shade
;
1587 client_change_state(self
);
1588 frame_adjust_size(self
->frame
);
1591 void client_close(Client
*self
)
1595 if (!(self
->functions
& Func_Close
)) return;
1598 XXX: itd be cool to do timeouts and shit here for killing the client's
1600 like... if the window is around after 5 seconds, then the close button
1601 turns a nice red, and if this function is called again, the client is
1605 ce
.xclient
.type
= ClientMessage
;
1606 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1607 ce
.xclient
.display
= ob_display
;
1608 ce
.xclient
.window
= self
->window
;
1609 ce
.xclient
.format
= 32;
1610 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1611 ce
.xclient
.data
.l
[1] = CurrentTime
;
1612 ce
.xclient
.data
.l
[2] = 0l;
1613 ce
.xclient
.data
.l
[3] = 0l;
1614 ce
.xclient
.data
.l
[4] = 0l;
1615 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1618 void client_set_desktop(Client
*self
, unsigned int target
)
1620 if (target
== self
->desktop
) return;
1622 g_message("Setting desktop %u\n", target
);
1624 if (!(target
< screen_num_desktops
||
1625 target
== DESKTOP_ALL
))
1628 self
->desktop
= target
;
1629 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1630 /* the frame can display the current desktop state */
1631 frame_adjust_state(self
->frame
);
1632 /* 'move' the window to the new desktop */
1633 client_showhide(self
);
1634 screen_update_struts();
1637 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1642 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1643 Client
*c
= it
->data
;
1644 if (c
== skip
) continue; /* circular? */
1645 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1646 if (c
->modal
) return c
;
1651 Client
*client_find_modal_child(Client
*self
)
1653 return search_modal_tree(self
, self
);
1656 gboolean
client_validate(Client
*self
)
1660 XSync(ob_display
, FALSE
); /* get all events on the server */
1662 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1663 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1664 XPutBackEvent(ob_display
, &e
);
1671 void client_set_wm_state(Client
*self
, long state
)
1673 if (state
== self
->wmstate
) return; /* no change */
1677 client_iconify(self
, TRUE
, TRUE
);
1680 client_iconify(self
, FALSE
, TRUE
);
1685 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1687 gboolean shaded
= self
->shaded
;
1688 gboolean fullscreen
= self
->fullscreen
;
1689 gboolean max_horz
= self
->max_horz
;
1690 gboolean max_vert
= self
->max_vert
;
1693 if (!(action
== prop_atoms
.net_wm_state_add
||
1694 action
== prop_atoms
.net_wm_state_remove
||
1695 action
== prop_atoms
.net_wm_state_toggle
))
1696 /* an invalid action was passed to the client message, ignore it */
1699 for (i
= 0; i
< 2; ++i
) {
1700 Atom state
= i
== 0 ? data1
: data2
;
1702 if (!state
) continue;
1704 /* if toggling, then pick whether we're adding or removing */
1705 if (action
== prop_atoms
.net_wm_state_toggle
) {
1706 if (state
== prop_atoms
.net_wm_state_modal
)
1707 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1708 prop_atoms
.net_wm_state_add
;
1709 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1710 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1711 prop_atoms
.net_wm_state_add
;
1712 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1713 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1714 prop_atoms
.net_wm_state_add
;
1715 else if (state
== prop_atoms
.net_wm_state_shaded
)
1716 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1717 prop_atoms
.net_wm_state_add
;
1718 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1719 action
= self
->skip_taskbar
?
1720 prop_atoms
.net_wm_state_remove
:
1721 prop_atoms
.net_wm_state_add
;
1722 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1723 action
= self
->skip_pager
?
1724 prop_atoms
.net_wm_state_remove
:
1725 prop_atoms
.net_wm_state_add
;
1726 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1727 action
= self
->fullscreen
?
1728 prop_atoms
.net_wm_state_remove
:
1729 prop_atoms
.net_wm_state_add
;
1730 else if (state
== prop_atoms
.net_wm_state_above
)
1731 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1732 prop_atoms
.net_wm_state_add
;
1733 else if (state
== prop_atoms
.net_wm_state_below
)
1734 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1735 prop_atoms
.net_wm_state_add
;
1738 if (action
== prop_atoms
.net_wm_state_add
) {
1739 if (state
== prop_atoms
.net_wm_state_modal
) {
1740 /* XXX raise here or something? */
1742 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1744 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1746 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1748 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1749 self
->skip_taskbar
= TRUE
;
1750 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1751 self
->skip_pager
= TRUE
;
1752 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1754 } else if (state
== prop_atoms
.net_wm_state_above
) {
1756 } else if (state
== prop_atoms
.net_wm_state_below
) {
1760 } else { /* action == prop_atoms.net_wm_state_remove */
1761 if (state
== prop_atoms
.net_wm_state_modal
) {
1762 self
->modal
= FALSE
;
1763 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1765 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1767 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1769 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1770 self
->skip_taskbar
= FALSE
;
1771 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1772 self
->skip_pager
= FALSE
;
1773 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1775 } else if (state
== prop_atoms
.net_wm_state_above
) {
1776 self
->above
= FALSE
;
1777 } else if (state
== prop_atoms
.net_wm_state_below
) {
1778 self
->below
= FALSE
;
1782 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1783 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1785 if (max_horz
== max_vert
) { /* both going the same way */
1786 client_maximize(self
, max_horz
, 0, TRUE
);
1788 client_maximize(self
, max_horz
, 1, TRUE
);
1789 client_maximize(self
, max_vert
, 2, TRUE
);
1793 if (max_horz
!= self
->max_horz
)
1794 client_maximize(self
, max_horz
, 1, TRUE
);
1796 client_maximize(self
, max_vert
, 2, TRUE
);
1799 /* change fullscreen state before shading, as it will affect if the window
1801 if (fullscreen
!= self
->fullscreen
)
1802 client_fullscreen(self
, fullscreen
, TRUE
);
1803 if (shaded
!= self
->shaded
)
1804 client_shade(self
, shaded
);
1805 client_calc_layer(self
);
1806 client_change_state(self
); /* change the hint to relect these changes */
1809 gboolean
client_focus(Client
*self
)
1814 /* if we have a modal child, then focus it, not us */
1815 child
= client_find_modal_child(self
);
1817 return client_focus(child
);
1819 /* won't try focus if the client doesn't want it, or if the window isn't
1820 visible on the screen */
1821 if (!(self
->frame
->visible
&&
1822 (self
->can_focus
|| self
->focus_notify
)))
1825 /* do a check to see if the window has already been unmapped or destroyed
1826 do this intelligently while watching out for unmaps we've generated
1827 (ignore_unmaps > 0) */
1828 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1829 DestroyNotify
, &ev
)) {
1830 XPutBackEvent(ob_display
, &ev
);
1833 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1834 UnmapNotify
, &ev
)) {
1835 if (self
->ignore_unmaps
) {
1836 self
->ignore_unmaps
--;
1838 XPutBackEvent(ob_display
, &ev
);
1843 if (self
->can_focus
)
1844 XSetInputFocus(ob_display
, self
->window
, RevertToNone
, CurrentTime
);
1846 if (self
->focus_notify
) {
1848 ce
.xclient
.type
= ClientMessage
;
1849 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1850 ce
.xclient
.display
= ob_display
;
1851 ce
.xclient
.window
= self
->window
;
1852 ce
.xclient
.format
= 32;
1853 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1854 ce
.xclient
.data
.l
[1] = event_lasttime
;
1855 ce
.xclient
.data
.l
[2] = 0l;
1856 ce
.xclient
.data
.l
[3] = 0l;
1857 ce
.xclient
.data
.l
[4] = 0l;
1858 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1861 /*XSync(ob_display, FALSE); XXX Why sync? */
1865 void client_unfocus(Client
*self
)
1867 g_assert(focus_client
== self
);
1868 focus_set_client(NULL
);