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; */
127 /* check if it has already been unmapped by the time we started mapping
128 the grab does a sync so we don't have to here */
129 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
130 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
131 XPutBackEvent(ob_display
, &e
);
134 return; /* don't manage it */
137 /* make sure it isn't an override-redirect window */
138 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
139 attrib
.override_redirect
) {
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! *\/
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
= engine_frame_new();
180 engine_frame_grab_client(client
->frame
, client
);
182 client_apply_startup_state(client
);
186 client_list
= g_slist_append(client_list
, client
);
187 stacking_list
= g_list_append(stacking_list
, client
);
188 g_hash_table_insert(client_map
, (gpointer
)window
, client
);
190 stacking_raise(client
);
192 screen_update_struts();
194 dispatch_client(Event_Client_New
, client
, 0, 0);
196 client_showhide(client
);
198 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
200 /* grab all mouse bindings */
201 /*pointer_grab_all(client, TRUE);XXX*/
203 /* update the list hints */
206 g_message("Managed window 0x%lx", window
);
209 void client_unmanage_all()
211 while (client_list
!= NULL
)
212 client_unmanage(client_list
->data
);
215 void client_unmanage(Client
*client
)
220 g_message("Unmanaging window: %lx", client
->window
);
222 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
224 /* remove the window from our save set */
225 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
227 /* we dont want events no more */
228 XSelectInput(ob_display
, client
->window
, NoEventMask
);
230 /* ungrab any mouse bindings */
231 /*pointer_grab_all(client, FALSE);XXX*/
233 engine_frame_hide(client
->frame
);
235 /* give the client its border back */
236 client_toggle_border(client
, TRUE
);
238 /* reparent the window out of the frame, and free the frame */
239 engine_frame_release_client(client
->frame
, client
);
241 client_list
= g_slist_remove(client_list
, client
);
242 stacking_list
= g_list_remove(stacking_list
, client
);
243 g_hash_table_remove(client_map
, (gpointer
)client
->window
);
245 /* once the client is out of the list, update the struts to remove it's
247 screen_update_struts();
249 /* tell our parent that we're gone */
250 if (client
->transient_for
!= NULL
)
251 client
->transient_for
->transients
=
252 g_slist_remove(client
->transient_for
->transients
, client
);
254 /* tell our transients that we're gone */
255 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
256 ((Client
*)it
->data
)->transient_for
= NULL
;
257 client_calc_layer(it
->data
);
260 /* unfocus the client (calls the focus callbacks) (we're out of the
261 transient lists already, so being modal doesn't matter) */
263 client_unfocus(client
);
265 if (ob_state
!= State_Exiting
) {
266 /* these values should not be persisted across a window
268 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
269 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
271 /* if we're left in an iconic state, the client wont be mapped. this is
272 bad, since we will no longer be managing the window on restart */
274 XMapWindow(ob_display
, client
->window
);
277 /* free all data allocated in the client struct */
278 g_slist_free(client
->transients
);
279 for (j
= 0; j
< client
->nicons
; ++j
)
280 g_free(client
->icons
[j
].data
);
281 if (client
->nicons
> 0)
282 g_free(client
->icons
);
283 g_free(client
->title
);
284 g_free(client
->icon_title
);
285 g_free(client
->res_name
);
286 g_free(client
->res_class
);
287 g_free(client
->role
);
290 /* update the list hints */
294 static void client_toggle_border(Client
*self
, gboolean show
)
296 /* adjust our idea of where the client is, based on its border. When the
297 border is removed, the client should now be considered to be in a
299 when re-adding the border to the client, the same operation needs to be
301 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
302 int x
= oldx
, y
= oldy
;
303 switch(self
->gravity
) {
305 case NorthWestGravity
:
307 case SouthWestGravity
:
309 case NorthEastGravity
:
311 case SouthEastGravity
:
312 if (show
) x
-= self
->border_width
* 2;
313 else x
+= self
->border_width
* 2;
320 if (show
) x
-= self
->border_width
;
321 else x
+= self
->border_width
;
324 switch(self
->gravity
) {
326 case NorthWestGravity
:
328 case NorthEastGravity
:
330 case SouthWestGravity
:
332 case SouthEastGravity
:
333 if (show
) y
-= self
->border_width
* 2;
334 else y
+= self
->border_width
* 2;
341 if (show
) y
-= self
->border_width
;
342 else y
+= self
->border_width
;
349 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
351 /* move the client so it is back it the right spot _with_ its
353 if (x
!= oldx
|| y
!= oldy
)
354 XMoveWindow(ob_display
, self
->window
, x
, y
);
356 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
360 static void client_get_all(Client
*self
)
362 /* update EVERYTHING!! */
364 self
->ignore_unmaps
= 0;
368 self
->title
= self
->icon_title
= NULL
;
369 self
->res_name
= self
->res_class
= self
->role
= NULL
;
370 self
->wmstate
= NormalState
;
371 self
->focused
= FALSE
;
372 self
->transient
= FALSE
;
373 self
->transients
= NULL
;
374 self
->transient_for
= NULL
;
376 self
->urgent
= FALSE
;
377 self
->positioned
= FALSE
;
378 self
->disabled_decorations
= 0;
382 client_get_area(self
);
383 client_get_desktop(self
);
384 client_get_state(self
);
385 client_get_shaped(self
);
387 client_update_transient_for(self
);
388 client_get_mwm_hints(self
);
389 client_get_type(self
);/* this can change the mwmhints for special cases */
391 client_update_protocols(self
);
393 client_get_gravity(self
); /* get the attribute gravity */
394 client_update_normal_hints(self
); /* this may override the attribute
397 /* got the type, the mwmhints, the protocols, and the normal hints
398 (min/max sizes), so we're ready to set up the decorations/functions */
399 client_setup_decor_and_functions(self
);
401 client_update_wmhints(self
);
402 client_update_title(self
);
403 client_update_icon_title(self
);
404 client_update_class(self
);
405 client_update_strut(self
);
406 client_update_icons(self
);
407 client_update_kwm_icon(self
);
409 /* this makes sure that these windows appear on all desktops */
410 if (self
->type
== Type_Desktop
)
411 self
->desktop
= DESKTOP_ALL
;
413 /* set the desktop hint, to make sure that it always exists, and to
414 reflect any changes we've made here */
415 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
417 client_change_state(self
);
420 static void client_get_area(Client
*self
)
422 XWindowAttributes wattrib
;
425 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
426 g_assert(ret
!= BadWindow
);
428 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
429 self
->border_width
= wattrib
.border_width
;
432 static void client_get_desktop(Client
*self
)
436 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
437 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
438 d
= screen_num_desktops
- 1;
441 /* defaults to the current desktop */
442 self
->desktop
= screen_desktop
;
446 static void client_get_state(Client
*self
)
451 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
452 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
453 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
455 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
457 for (i
= 0; i
< num
; ++i
) {
458 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
460 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
462 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
464 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
465 self
->skip_taskbar
= TRUE
;
466 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
467 self
->skip_pager
= TRUE
;
468 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
469 self
->fullscreen
= TRUE
;
470 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
471 self
->max_vert
= TRUE
;
472 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
473 self
->max_horz
= TRUE
;
474 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
476 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
484 static void client_get_shaped(Client
*self
)
486 self
->shaped
= FALSE
;
488 if (extensions_shape
) {
493 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
495 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
496 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
498 self
->shaped
= (s
!= 0);
503 void client_update_transient_for(Client
*self
)
508 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
509 t
!= self
->window
) { /* cant be transient to itself! */
510 self
->transient
= TRUE
;
511 c
= g_hash_table_lookup(client_map
, (gpointer
)t
);
512 g_assert(c
!= self
);/* if this happens then we need to check for it*/
514 if (!c
/*XXX: && _group*/) {
515 /* not transient to a client, see if it is transient for a
517 if (/*t == _group->leader() || */
520 /* window is a transient for its group! */
521 /* XXX: for now this is treated as non-transient.
522 this needs to be fixed! */
526 self
->transient
= FALSE
;
528 /* if anything has changed... */
529 if (c
!= self
->transient_for
) {
530 if (self
->transient_for
)
531 /* remove from old parent */
532 g_slist_remove(self
->transient_for
->transients
, self
);
533 self
->transient_for
= c
;
534 if (self
->transient_for
)
535 /* add to new parent */
536 g_slist_append(self
->transient_for
->transients
, self
);
540 static void client_get_mwm_hints(Client
*self
)
543 unsigned long *hints
;
545 self
->mwmhints
.flags
= 0; /* default to none */
547 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
548 if (num
>= MWM_ELEMENTS
) {
549 self
->mwmhints
.flags
= hints
[0];
550 self
->mwmhints
.functions
= hints
[1];
551 self
->mwmhints
.decorations
= hints
[2];
557 void client_get_type(Client
*self
)
563 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
564 /* use the first value that we know about in the array */
565 for (i
= 0; i
< num
; ++i
) {
566 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
567 self
->type
= Type_Desktop
;
568 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
569 self
->type
= Type_Dock
;
570 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
571 self
->type
= Type_Toolbar
;
572 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
573 self
->type
= Type_Menu
;
574 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
575 self
->type
= Type_Utility
;
576 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
577 self
->type
= Type_Splash
;
578 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
579 self
->type
= Type_Dialog
;
580 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
581 self
->type
= Type_Normal
;
582 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
583 /* prevent this window from getting any decor or
585 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
586 MwmFlag_Decorations
);
587 self
->mwmhints
.decorations
= 0;
588 self
->mwmhints
.functions
= 0;
590 if (self
->type
!= (WindowType
) -1)
591 break; /* grab the first legit type */
596 if (self
->type
== (WindowType
) -1) {
597 /*the window type hint was not set, which means we either classify
598 ourself as a normal window or a dialog, depending on if we are a
601 self
->type
= Type_Dialog
;
603 self
->type
= Type_Normal
;
607 void client_update_protocols(Client
*self
)
610 gulong num_return
, i
;
612 self
->focus_notify
= FALSE
;
613 self
->delete_window
= FALSE
;
615 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
616 for (i
= 0; i
< num_return
; ++i
) {
617 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
618 /* this means we can request the window to close */
619 self
->delete_window
= TRUE
;
620 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
621 /* if this protocol is requested, then the window will be
622 notified whenever we want it to receive focus */
623 self
->focus_notify
= TRUE
;
629 static void client_get_gravity(Client
*self
)
631 XWindowAttributes wattrib
;
634 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
635 g_assert(ret
!= BadWindow
);
636 self
->gravity
= wattrib
.win_gravity
;
639 void client_update_normal_hints(Client
*self
)
643 int oldgravity
= self
->gravity
;
646 self
->min_ratio
= 0.0f
;
647 self
->max_ratio
= 0.0f
;
648 SIZE_SET(self
->size_inc
, 1, 1);
649 SIZE_SET(self
->base_size
, 0, 0);
650 SIZE_SET(self
->min_size
, 0, 0);
651 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
653 /* get the hints from the window */
654 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
655 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
657 if (size
.flags
& PWinGravity
) {
658 self
->gravity
= size
.win_gravity
;
660 /* if the client has a frame, i.e. has already been mapped and
661 is changing its gravity */
662 if (self
->frame
&& self
->gravity
!= oldgravity
) {
663 /* move our idea of the client's position based on its new
665 self
->area
.x
= self
->frame
->area
.x
;
666 self
->area
.y
= self
->frame
->area
.y
;
667 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
671 if (size
.flags
& PAspect
) {
672 if (size
.min_aspect
.y
)
673 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
674 if (size
.max_aspect
.y
)
675 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
678 if (size
.flags
& PMinSize
)
679 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
681 if (size
.flags
& PMaxSize
)
682 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
684 if (size
.flags
& PBaseSize
)
685 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
687 if (size
.flags
& PResizeInc
)
688 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
692 void client_setup_decor_and_functions(Client
*self
)
694 /* start with everything (cept fullscreen) */
695 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
696 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
697 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
699 if (self
->delete_window
) {
700 self
->decorations
|= Decor_Close
;
701 self
->functions
|= Func_Close
;
704 if (!(self
->min_size
.width
< self
->max_size
.width
||
705 self
->min_size
.height
< self
->max_size
.height
)) {
706 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
707 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
710 switch (self
->type
) {
712 /* normal windows retain all of the possible decorations and
713 functionality, and are the only windows that you can fullscreen */
714 self
->functions
|= Func_Fullscreen
;
718 /* dialogs cannot be maximized */
719 self
->decorations
&= ~Decor_Maximize
;
720 self
->functions
&= ~Func_Maximize
;
726 /* these windows get less functionality */
727 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
728 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
734 /* none of these windows are manipulated by the window manager */
735 self
->decorations
= 0;
740 /* Mwm Hints are applied subtractively to what has already been chosen for
741 decor and functionality */
742 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
743 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
744 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
745 self
->decorations
&= ~Decor_Border
;
746 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
747 self
->decorations
&= ~Decor_Handle
;
748 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
749 self
->decorations
&= ~Decor_Titlebar
;
750 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
751 self
->decorations
&= ~Decor_Iconify
;
752 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
753 self
->decorations
&= ~Decor_Maximize
;
757 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
758 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
759 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
760 self
->functions
&= ~Func_Resize
;
761 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
762 self
->functions
&= ~Func_Move
;
763 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
764 self
->functions
&= ~Func_Iconify
;
765 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
766 self
->functions
&= ~Func_Maximize
;
767 /* dont let mwm hints kill the close button
768 if (! (self->mwmhints.functions & MwmFunc_Close))
769 self->functions &= ~Func_Close; */
773 /* can't maximize without moving/resizing */
774 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
775 self
->functions
&= ~Func_Maximize
;
777 /* finally, user specified disabled decorations are applied to subtract
779 if (self
->disabled_decorations
& Decor_Titlebar
)
780 self
->decorations
&= ~Decor_Titlebar
;
781 if (self
->disabled_decorations
& Decor_Handle
)
782 self
->decorations
&= ~Decor_Handle
;
783 if (self
->disabled_decorations
& Decor_Border
)
784 self
->decorations
&= ~Decor_Border
;
785 if (self
->disabled_decorations
& Decor_Iconify
)
786 self
->decorations
&= ~Decor_Iconify
;
787 if (self
->disabled_decorations
& Decor_Maximize
)
788 self
->decorations
&= ~Decor_Maximize
;
789 if (self
->disabled_decorations
& Decor_AllDesktops
)
790 self
->decorations
&= ~Decor_AllDesktops
;
791 if (self
->disabled_decorations
& Decor_Close
)
792 self
->decorations
&= ~Decor_Close
;
794 /* if we don't have a titlebar, then we cannot shade! */
795 if (!(self
->decorations
& Decor_Titlebar
))
796 self
->functions
&= ~Func_Shade
;
798 client_change_allowed_actions(self
);
801 /* change the decors on the frame */
802 engine_frame_adjust_size(self
->frame
);
803 /* with more/less decorations, we may need to be repositioned */
804 engine_frame_adjust_position(self
->frame
);
805 /* with new decor, the window's maximized size may change */
806 client_remaximize(self
);
810 static void client_change_allowed_actions(Client
*self
)
815 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
817 if (self
->functions
& Func_Shade
)
818 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
819 if (self
->functions
& Func_Close
)
820 actions
[num
++] = prop_atoms
.net_wm_action_close
;
821 if (self
->functions
& Func_Move
)
822 actions
[num
++] = prop_atoms
.net_wm_action_move
;
823 if (self
->functions
& Func_Iconify
)
824 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
825 if (self
->functions
& Func_Resize
)
826 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
827 if (self
->functions
& Func_Fullscreen
)
828 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
829 if (self
->functions
& Func_Maximize
) {
830 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
831 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
834 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
836 /* make sure the window isn't breaking any rules now */
838 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
839 if (self
->frame
) client_shade(self
, FALSE
);
840 else self
->shaded
= FALSE
;
842 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
843 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
844 else self
->iconic
= FALSE
;
846 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
847 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
848 else self
->fullscreen
= FALSE
;
850 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
852 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
853 else self
->max_vert
= self
->max_horz
= FALSE
;
857 void client_remaximize(Client
*self
)
860 if (self
->max_horz
&& self
->max_vert
)
862 else if (self
->max_horz
)
864 else if (self
->max_vert
)
867 return; /* not maximized */
868 self
->max_horz
= self
->max_vert
= FALSE
;
869 client_maximize(self
, TRUE
, dir
, FALSE
);
872 void client_update_wmhints(Client
*self
)
877 /* assume a window takes input if it doesnt specify */
878 self
->can_focus
= TRUE
;
880 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
881 if (hints
->flags
& InputHint
)
882 self
->can_focus
= hints
->input
;
884 /* only do this when starting! */
885 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
886 self
->iconic
= hints
->initial_state
== IconicState
;
888 if (hints
->flags
& XUrgencyHint
)
891 if (hints
->flags
& WindowGroupHint
) {
892 if (hints
->window_group
!= self
->group
) {
893 /* XXX: remove from the old group if there was one */
894 self
->group
= hints
->window_group
;
895 /* XXX: do stuff with the group */
897 } else /* no group! */
900 if (hints
->flags
& IconPixmapHint
) {
901 client_update_kwm_icon(self
);
902 /* try get the kwm icon first, this is a fallback only */
903 if (self
->pixmap_icon
== None
) {
904 self
->pixmap_icon
= hints
->icon_pixmap
;
905 if (hints
->flags
& IconMaskHint
)
906 self
->pixmap_icon_mask
= hints
->icon_mask
;
908 self
->pixmap_icon_mask
= None
;
911 engine_frame_adjust_icon(self
->frame
);
918 if (ur
!= self
->urgent
) {
920 g_message("Urgent Hint for 0x%lx: %s\n", self
->window
,
922 /* fire the urgent callback if we're mapped, otherwise, wait until
923 after we're mapped */
925 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
929 void client_update_title(Client
*self
)
933 if (self
->title
!= NULL
)
937 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
938 /* try old x stuff */
939 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
940 /* convert it to UTF-8 */
944 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
946 g_warning("Unable to convert string to UTF-8");
953 data
= g_strdup("Unnamed Window");
955 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
961 engine_frame_adjust_title(self
->frame
);
964 void client_update_icon_title(Client
*self
)
968 if (self
->icon_title
!= NULL
)
969 g_free(self
->icon_title
);
972 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
973 /* try old x stuff */
974 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
975 /* convert it to UTF-8 */
979 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
981 g_warning("Unable to convert string to UTF-8");
988 data
= g_strdup("Unnamed Window");
990 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
993 self
->icon_title
= data
;
996 void client_update_class(Client
*self
)
1002 if (self
->res_name
) g_free(self
->res_name
);
1003 if (self
->res_class
) g_free(self
->res_class
);
1004 if (self
->role
) g_free(self
->role
);
1006 self
->res_name
= self
->res_class
= self
->role
= NULL
;
1008 data
= g_ptr_array_new();
1010 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1012 self
->res_name
= g_strdup(g_ptr_array_index(data
, 0));
1014 self
->res_class
= g_strdup(g_ptr_array_index(data
, 1));
1017 for (i
= 0; i
< data
->len
; ++i
)
1018 g_free(g_ptr_array_index(data
, i
));
1019 g_ptr_array_free(data
, TRUE
);
1021 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1022 self
->role
= g_strdup(s
);
1024 if (self
->res_name
== NULL
) self
->res_name
= g_strdup("");
1025 if (self
->res_class
== NULL
) self
->res_class
= g_strdup("");
1026 if (self
->role
== NULL
) self
->role
= g_strdup("");
1029 void client_update_strut(Client
*self
)
1033 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1034 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1037 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1039 /* updating here is pointless while we're being mapped cuz we're not in
1040 the client list yet */
1042 screen_update_struts();
1045 void client_update_icons(Client
*self
)
1048 unsigned long *data
;
1049 unsigned long w
, h
, i
;
1052 for (j
= 0; j
< self
->nicons
; ++j
)
1053 g_free(self
->icons
[j
].data
);
1054 if (self
->nicons
> 0)
1055 g_free(self
->icons
);
1058 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1059 /* figure out how many valid icons are in here */
1061 while (num
- i
> 2) {
1069 self
->icons
= g_new(Icon
, self
->nicons
);
1071 /* store the icons */
1073 for (j
= 0; j
< self
->nicons
; ++j
) {
1074 w
= self
->icons
[j
].w
= data
[i
++];
1075 h
= self
->icons
[j
].h
= data
[i
++];
1076 self
->icons
[j
].data
=
1077 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1085 if (self
->nicons
<= 0) {
1087 self
->icons
= g_new0(Icon
, 1);
1091 engine_frame_adjust_icon(self
->frame
);
1094 void client_update_kwm_icon(Client
*self
)
1098 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1099 self
->pixmap_icon
= data
[0];
1100 self
->pixmap_icon_mask
= data
[1];
1103 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1106 engine_frame_adjust_icon(self
->frame
);
1109 static void client_change_state(Client
*self
)
1111 unsigned long state
[2];
1115 state
[0] = self
->wmstate
;
1117 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1121 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1123 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1125 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1126 if (self
->skip_taskbar
)
1127 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1128 if (self
->skip_pager
)
1129 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1130 if (self
->fullscreen
)
1131 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1133 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1135 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1137 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1139 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1140 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1142 client_calc_layer(self
);
1145 engine_frame_adjust_state(self
->frame
);
1148 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1153 for (it
= node
->transients
; it
!= NULL
; it
= g_slist_next(it
)) {
1154 Client
*c
= it
->data
;
1155 if (c
== skip
) continue; /* circular? */
1156 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1157 if (c
->focused
) return c
;
1162 void client_calc_layer(Client
*self
)
1168 /* are we fullscreen, or do we have a fullscreen transient parent? */
1172 if (c
->fullscreen
) {
1176 c
= c
->transient_for
;
1178 if (!fs
&& self
->fullscreen
) {
1179 /* is one of our transients focused? */
1180 c
= search_focus_tree(self
, self
);
1181 if (c
!= NULL
) fs
= TRUE
;
1184 if (self
->iconic
) l
= Layer_Icon
;
1185 else if (fs
) l
= Layer_Fullscreen
;
1186 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1187 else if (self
->type
== Type_Dock
) {
1188 if (!self
->below
) l
= Layer_Top
;
1189 else l
= Layer_Normal
;
1191 else if (self
->above
) l
= Layer_Above
;
1192 else if (self
->below
) l
= Layer_Below
;
1193 else l
= Layer_Normal
;
1195 if (l
!= self
->layer
) {
1198 stacking_raise(self
);
1202 gboolean
client_should_show(Client
*self
)
1204 if (self
->iconic
) return FALSE
;
1205 else if (!(self
->desktop
== screen_desktop
||
1206 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1207 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1212 static void client_showhide(Client
*self
)
1215 if (client_should_show(self
))
1216 engine_frame_show(self
->frame
);
1218 engine_frame_hide(self
->frame
);
1221 gboolean
client_normal(Client
*self
) {
1222 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1223 self
->type
== Type_Splash
);
1226 static void client_apply_startup_state(Client
*self
)
1228 /* these are in a carefully crafted order.. */
1231 self
->iconic
= FALSE
;
1232 client_iconify(self
, TRUE
, FALSE
);
1234 if (self
->fullscreen
) {
1235 self
->fullscreen
= FALSE
;
1236 client_fullscreen(self
, TRUE
, FALSE
);
1239 self
->shaded
= FALSE
;
1240 client_shade(self
, TRUE
);
1243 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1245 if (self
->max_vert
&& self
->max_horz
) {
1246 self
->max_vert
= self
->max_horz
= FALSE
;
1247 client_maximize(self
, TRUE
, 0, FALSE
);
1248 } else if (self
->max_vert
) {
1249 self
->max_vert
= FALSE
;
1250 client_maximize(self
, TRUE
, 2, FALSE
);
1251 } else if (self
->max_horz
) {
1252 self
->max_horz
= FALSE
;
1253 client_maximize(self
, TRUE
, 1, FALSE
);
1256 /* nothing to do for the other states:
1265 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1266 gboolean user
, gboolean final
)
1268 gboolean moved
= FALSE
, resized
= FALSE
;
1270 w
-= self
->base_size
.width
;
1271 h
-= self
->base_size
.height
;
1274 /* for interactive resizing. have to move half an increment in each
1277 /* how far we are towards the next size inc */
1278 int mw
= w
% self
->size_inc
.width
;
1279 int mh
= h
% self
->size_inc
.height
;
1281 int aw
= self
->size_inc
.width
/ 2;
1282 int ah
= self
->size_inc
.height
/ 2;
1283 /* don't let us move into a new size increment */
1284 if (mw
+ aw
>= self
->size_inc
.width
)
1285 aw
= self
->size_inc
.width
- mw
- 1;
1286 if (mh
+ ah
>= self
->size_inc
.height
)
1287 ah
= self
->size_inc
.height
- mh
- 1;
1291 /* if this is a user-requested resize, then check against min/max
1292 sizes and aspect ratios */
1294 /* smaller than min size or bigger than max size? */
1295 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1296 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1297 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1298 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1300 /* adjust the height ot match the width for the aspect ratios */
1301 if (self
->min_ratio
)
1302 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1303 if (self
->max_ratio
)
1304 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1307 /* keep to the increments */
1308 w
/= self
->size_inc
.width
;
1309 h
/= self
->size_inc
.height
;
1311 /* you cannot resize to nothing */
1315 /* store the logical size */
1316 SIZE_SET(self
->logical_size
, w
, h
);
1318 w
*= self
->size_inc
.width
;
1319 h
*= self
->size_inc
.height
;
1321 w
+= self
->base_size
.width
;
1322 h
+= self
->base_size
.height
;
1325 case Corner_TopLeft
:
1327 case Corner_TopRight
:
1328 x
-= w
- self
->area
.width
;
1330 case Corner_BottomLeft
:
1331 y
-= h
- self
->area
.height
;
1333 case Corner_BottomRight
:
1334 x
-= w
- self
->area
.width
;
1335 y
-= h
- self
->area
.height
;
1339 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1340 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1342 RECT_SET(self
->area
, x
, y
, w
, h
);
1345 XResizeWindow(ob_display
, self
->window
, w
, h
);
1347 /* move/resize the frame to match the request */
1349 /* Adjust the size and then the position, as required by the EWMH */
1351 engine_frame_adjust_size(self
->frame
);
1353 engine_frame_adjust_position(self
->frame
);
1355 if (!user
|| final
) {
1357 event
.type
= ConfigureNotify
;
1358 event
.xconfigure
.display
= ob_display
;
1359 event
.xconfigure
.event
= self
->window
;
1360 event
.xconfigure
.window
= self
->window
;
1362 /* root window coords with border in mind */
1363 event
.xconfigure
.x
= x
- self
->border_width
+
1364 self
->frame
->size
.left
;
1365 event
.xconfigure
.y
= y
- self
->border_width
+
1366 self
->frame
->size
.top
;
1368 event
.xconfigure
.width
= self
->area
.width
;
1369 event
.xconfigure
.height
= self
->area
.height
;
1370 event
.xconfigure
.border_width
= self
->border_width
;
1371 event
.xconfigure
.above
= self
->frame
->plate
;
1372 event
.xconfigure
.override_redirect
= FALSE
;
1373 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1374 FALSE
, StructureNotifyMask
, &event
);
1380 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1382 static int saved_func
, saved_decor
;
1385 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1386 self
->fullscreen
== fs
) return; /* already done */
1388 self
->fullscreen
= fs
;
1389 client_change_state(self
); /* change the state hints on the client */
1392 /* save the functions and remove them */
1393 saved_func
= self
->functions
;
1394 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1396 /* save the decorations and remove them */
1397 saved_decor
= self
->decorations
;
1398 self
->decorations
= 0;
1401 dimensions
[0] = self
->area
.x
;
1402 dimensions
[1] = self
->area
.y
;
1403 dimensions
[2] = self
->area
.width
;
1404 dimensions
[3] = self
->area
.height
;
1406 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1411 w
= screen_physical_size
.width
;
1412 h
= screen_physical_size
.height
;
1416 self
->functions
= saved_func
;
1417 self
->decorations
= saved_decor
;
1419 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1427 /* pick some fallbacks... */
1428 x
= screen_area(self
->desktop
)->x
+
1429 screen_area(self
->desktop
)->width
/ 4;
1430 y
= screen_area(self
->desktop
)->y
+
1431 screen_area(self
->desktop
)->height
/ 4;
1432 w
= screen_area(self
->desktop
)->width
/ 2;
1433 h
= screen_area(self
->desktop
)->height
/ 2;
1437 client_change_allowed_actions(self
); /* based on the new _functions */
1439 /* when fullscreening, don't obey things like increments, fill the
1441 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1443 /* raise (back) into our stacking layer */
1444 stacking_raise(self
);
1446 /* try focus us when we go into fullscreen mode */
1450 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1452 if (self
->iconic
== iconic
) return; /* nothing to do */
1454 g_message("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1457 self
->iconic
= iconic
;
1460 self
->wmstate
= IconicState
;
1461 self
->ignore_unmaps
++;
1462 /* we unmap the client itself so that we can get MapRequest events,
1463 and because the ICCCM tells us to! */
1464 XUnmapWindow(ob_display
, self
->window
);
1467 client_set_desktop(self
, screen_desktop
);
1468 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1469 XMapWindow(ob_display
, self
->window
);
1471 client_change_state(self
);
1472 client_showhide(self
);
1473 screen_update_struts();
1476 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1480 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1481 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1483 /* check if already done */
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;
1489 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1490 if (dir
== 1 && !self
->max_horz
) return;
1491 if (dir
== 2 && !self
->max_vert
) return;
1494 /* work with the frame's coords */
1495 x
= self
->frame
->area
.x
;
1496 y
= self
->frame
->area
.y
;
1497 w
= self
->area
.width
;
1498 h
= self
->area
.height
;
1510 /* get the property off the window and use it for the dimensions
1511 we are already maxed on */
1512 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1514 if (self
->max_horz
) {
1515 dimensions
[0] = readdim
[0];
1516 dimensions
[2] = readdim
[2];
1518 if (self
->max_vert
) {
1519 dimensions
[1] = readdim
[1];
1520 dimensions
[3] = readdim
[3];
1525 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1528 if (dir
== 0 || dir
== 1) { /* horz */
1529 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1530 w
= screen_area(self
->desktop
)->x
+
1531 screen_area(self
->desktop
)->width
;
1533 if (dir
== 0 || dir
== 2) { /* vert */
1534 y
= screen_area(self
->desktop
)->y
;
1535 h
= screen_area(self
->desktop
)->y
+
1536 screen_area(self
->desktop
)->height
-
1537 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1542 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1544 if (dir
== 0 || dir
== 1) { /* horz */
1548 if (dir
== 0 || dir
== 2) { /* vert */
1554 /* pick some fallbacks... */
1555 if (dir
== 0 || dir
== 1) { /* horz */
1556 x
= screen_area(self
->desktop
)->x
+
1557 screen_area(self
->desktop
)->width
/ 4;
1558 w
= screen_area(self
->desktop
)->width
/ 2;
1560 if (dir
== 0 || dir
== 2) { /* vert */
1561 y
= screen_area(self
->desktop
)->y
+
1562 screen_area(self
->desktop
)->height
/ 4;
1563 h
= screen_area(self
->desktop
)->height
/ 2;
1568 if (dir
== 0 || dir
== 1) /* horz */
1569 self
->max_horz
= max
;
1570 if (dir
== 0 || dir
== 2) /* vert */
1571 self
->max_vert
= max
;
1573 if (!self
->max_horz
&& !self
->max_vert
)
1574 PROP_ERASE(self
->window
, openbox_premax
);
1576 client_change_state(self
); /* change the state hints on the client */
1578 /* figure out where the client should be going */
1579 frame_frame_gravity(self
->frame
, &x
, &y
);
1580 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1583 void client_shade(Client
*self
, gboolean shade
)
1585 if (!(self
->functions
& Func_Shade
) || /* can't */
1586 self
->shaded
== shade
) return; /* already done */
1588 /* when we're iconic, don't change the wmstate */
1590 self
->wmstate
= shade
? IconicState
: NormalState
;
1591 self
->shaded
= shade
;
1592 client_change_state(self
);
1593 engine_frame_adjust_size(self
->frame
);
1596 void client_close(Client
*self
)
1600 if (!(self
->functions
& Func_Close
)) return;
1603 XXX: itd be cool to do timeouts and shit here for killing the client's
1605 like... if the window is around after 5 seconds, then the close button
1606 turns a nice red, and if this function is called again, the client is
1610 ce
.xclient
.type
= ClientMessage
;
1611 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1612 ce
.xclient
.display
= ob_display
;
1613 ce
.xclient
.window
= self
->window
;
1614 ce
.xclient
.format
= 32;
1615 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1616 ce
.xclient
.data
.l
[1] = CurrentTime
;
1617 ce
.xclient
.data
.l
[2] = 0l;
1618 ce
.xclient
.data
.l
[3] = 0l;
1619 ce
.xclient
.data
.l
[4] = 0l;
1620 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1623 void client_set_desktop(Client
*self
, guint target
)
1627 if (target
== self
->desktop
) return;
1629 g_message("Setting desktop %u\n", target
);
1631 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1633 old
= self
->desktop
;
1634 self
->desktop
= target
;
1635 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1636 /* the frame can display the current desktop state */
1637 engine_frame_adjust_state(self
->frame
);
1638 /* 'move' the window to the new desktop */
1639 client_showhide(self
);
1640 screen_update_struts();
1642 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1645 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1650 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1651 Client
*c
= it
->data
;
1652 if (c
== skip
) continue; /* circular? */
1653 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1654 if (c
->modal
) return c
;
1659 Client
*client_find_modal_child(Client
*self
)
1661 return search_modal_tree(self
, self
);
1664 gboolean
client_validate(Client
*self
)
1668 XSync(ob_display
, FALSE
); /* get all events on the server */
1670 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1671 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1672 XPutBackEvent(ob_display
, &e
);
1679 void client_set_wm_state(Client
*self
, long state
)
1681 if (state
== self
->wmstate
) return; /* no change */
1685 client_iconify(self
, TRUE
, TRUE
);
1688 client_iconify(self
, FALSE
, TRUE
);
1693 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1695 gboolean shaded
= self
->shaded
;
1696 gboolean fullscreen
= self
->fullscreen
;
1697 gboolean max_horz
= self
->max_horz
;
1698 gboolean max_vert
= self
->max_vert
;
1701 if (!(action
== prop_atoms
.net_wm_state_add
||
1702 action
== prop_atoms
.net_wm_state_remove
||
1703 action
== prop_atoms
.net_wm_state_toggle
))
1704 /* an invalid action was passed to the client message, ignore it */
1707 for (i
= 0; i
< 2; ++i
) {
1708 Atom state
= i
== 0 ? data1
: data2
;
1710 if (!state
) continue;
1712 /* if toggling, then pick whether we're adding or removing */
1713 if (action
== prop_atoms
.net_wm_state_toggle
) {
1714 if (state
== prop_atoms
.net_wm_state_modal
)
1715 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1716 prop_atoms
.net_wm_state_add
;
1717 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1718 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1719 prop_atoms
.net_wm_state_add
;
1720 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1721 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1722 prop_atoms
.net_wm_state_add
;
1723 else if (state
== prop_atoms
.net_wm_state_shaded
)
1724 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1725 prop_atoms
.net_wm_state_add
;
1726 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1727 action
= self
->skip_taskbar
?
1728 prop_atoms
.net_wm_state_remove
:
1729 prop_atoms
.net_wm_state_add
;
1730 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1731 action
= self
->skip_pager
?
1732 prop_atoms
.net_wm_state_remove
:
1733 prop_atoms
.net_wm_state_add
;
1734 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1735 action
= self
->fullscreen
?
1736 prop_atoms
.net_wm_state_remove
:
1737 prop_atoms
.net_wm_state_add
;
1738 else if (state
== prop_atoms
.net_wm_state_above
)
1739 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1740 prop_atoms
.net_wm_state_add
;
1741 else if (state
== prop_atoms
.net_wm_state_below
)
1742 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1743 prop_atoms
.net_wm_state_add
;
1746 if (action
== prop_atoms
.net_wm_state_add
) {
1747 if (state
== prop_atoms
.net_wm_state_modal
) {
1748 /* XXX raise here or something? */
1750 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1752 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1754 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1756 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1757 self
->skip_taskbar
= TRUE
;
1758 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1759 self
->skip_pager
= TRUE
;
1760 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1762 } else if (state
== prop_atoms
.net_wm_state_above
) {
1764 } else if (state
== prop_atoms
.net_wm_state_below
) {
1768 } else { /* action == prop_atoms.net_wm_state_remove */
1769 if (state
== prop_atoms
.net_wm_state_modal
) {
1770 self
->modal
= FALSE
;
1771 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1773 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1775 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1777 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1778 self
->skip_taskbar
= FALSE
;
1779 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1780 self
->skip_pager
= FALSE
;
1781 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1783 } else if (state
== prop_atoms
.net_wm_state_above
) {
1784 self
->above
= FALSE
;
1785 } else if (state
== prop_atoms
.net_wm_state_below
) {
1786 self
->below
= FALSE
;
1790 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1791 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1793 if (max_horz
== max_vert
) { /* both going the same way */
1794 client_maximize(self
, max_horz
, 0, TRUE
);
1796 client_maximize(self
, max_horz
, 1, TRUE
);
1797 client_maximize(self
, max_vert
, 2, TRUE
);
1801 if (max_horz
!= self
->max_horz
)
1802 client_maximize(self
, max_horz
, 1, TRUE
);
1804 client_maximize(self
, max_vert
, 2, TRUE
);
1807 /* change fullscreen state before shading, as it will affect if the window
1809 if (fullscreen
!= self
->fullscreen
)
1810 client_fullscreen(self
, fullscreen
, TRUE
);
1811 if (shaded
!= self
->shaded
)
1812 client_shade(self
, shaded
);
1813 client_calc_layer(self
);
1814 client_change_state(self
); /* change the hint to relect these changes */
1817 gboolean
client_focus(Client
*self
)
1822 /* if we have a modal child, then focus it, not us */
1823 child
= client_find_modal_child(self
);
1825 return client_focus(child
);
1827 /* won't try focus if the client doesn't want it, or if the window isn't
1828 visible on the screen */
1829 if (!(self
->frame
->visible
&&
1830 (self
->can_focus
|| self
->focus_notify
)))
1833 /* do a check to see if the window has already been unmapped or destroyed
1834 do this intelligently while watching out for unmaps we've generated
1835 (ignore_unmaps > 0) */
1836 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1837 DestroyNotify
, &ev
)) {
1838 XPutBackEvent(ob_display
, &ev
);
1841 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1842 UnmapNotify
, &ev
)) {
1843 if (self
->ignore_unmaps
) {
1844 self
->ignore_unmaps
--;
1846 XPutBackEvent(ob_display
, &ev
);
1851 if (self
->can_focus
)
1852 XSetInputFocus(ob_display
, self
->window
, RevertToNone
, CurrentTime
);
1854 if (self
->focus_notify
) {
1856 ce
.xclient
.type
= ClientMessage
;
1857 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1858 ce
.xclient
.display
= ob_display
;
1859 ce
.xclient
.window
= self
->window
;
1860 ce
.xclient
.format
= 32;
1861 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1862 ce
.xclient
.data
.l
[1] = event_lasttime
;
1863 ce
.xclient
.data
.l
[2] = 0l;
1864 ce
.xclient
.data
.l
[3] = 0l;
1865 ce
.xclient
.data
.l
[4] = 0l;
1866 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1869 /*XSync(ob_display, FALSE); XXX Why sync? */
1873 void client_unfocus(Client
*self
)
1875 g_assert(focus_client
== self
);
1876 focus_set_client(NULL
);