4 #include "extensions.h"
12 #include "openboxwrap.h"
13 #include "clientwrap.h"
15 #include <X11/Xutil.h>
17 /*! The event mask to grab on client windows */
18 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
21 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
24 GSList
*client_list
= NULL
;
25 GHashTable
*client_map
= NULL
;
27 static void client_get_all(Client
*self
);
28 static void client_toggle_border(Client
*self
, gboolean show
);
29 static void client_get_area(Client
*self
);
30 static void client_get_desktop(Client
*self
);
31 static void client_get_state(Client
*self
);
32 static void client_get_shaped(Client
*self
);
33 static void client_get_mwm_hints(Client
*self
);
34 static void client_get_gravity(Client
*self
);
35 static void client_showhide(Client
*self
);
36 static void client_change_allowed_actions(Client
*self
);
37 static void client_change_state(Client
*self
);
38 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
39 static void client_apply_startup_state(Client
*self
);
40 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
42 static guint
map_hash(Window w
) { return w
; }
43 static gboolean
map_key_comp(Window w1
, Window w2
) { return w1
== w2
; }
47 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
48 (GEqualFunc
)map_key_comp
);
52 void client_shutdown()
54 g_hash_table_destroy(client_map
);
57 void client_set_list()
59 Window
*windows
, *win_it
;
61 guint size
= g_slist_length(client_list
);
63 /* create an array of the window ids */
65 windows
= g_new(Window
, size
);
67 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
68 *win_it
= ((Client
*)it
->data
)->window
;
72 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
80 void client_manage_all()
82 unsigned int i
, j
, nchild
;
85 XWindowAttributes attrib
;
87 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
89 /* remove all icon windows from the list */
90 for (i
= 0; i
< nchild
; i
++) {
91 if (children
[i
] == None
) continue;
92 wmhints
= XGetWMHints(ob_display
, children
[i
]);
94 if ((wmhints
->flags
& IconWindowHint
) &&
95 (wmhints
->icon_window
!= children
[i
]))
96 for (j
= 0; j
< nchild
; j
++)
97 if (children
[j
] == wmhints
->icon_window
) {
105 for (i
= 0; i
< nchild
; ++i
) {
106 if (children
[i
] == None
)
108 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
109 if (attrib
.override_redirect
) continue;
111 if (attrib
.map_state
!= IsUnmapped
)
112 client_manage(children
[i
]);
118 void client_manage(Window window
)
122 XWindowAttributes attrib
;
123 XSetWindowAttributes attrib_set
;
124 /* XWMHints *wmhint; */
127 XGrabServer(ob_display
);
128 XSync(ob_display
, FALSE
);
130 /* check if it has already been unmapped by the time we started mapping
131 the grab does a sync so we don't have to here */
132 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
133 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
134 XPutBackEvent(ob_display
, &e
);
136 XUngrabServer(ob_display
);
138 return; /* don't manage it */
141 /* make sure it isn't an override-redirect window */
142 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
143 attrib
.override_redirect
) {
144 XUngrabServer(ob_display
);
146 return; /* don't manage it */
149 /* /\* is the window a docking app *\/
150 if ((wmhint = XGetWMHints(ob_display, window))) {
151 if ((wmhint->flags & StateHint) &&
152 wmhint->initial_state == WithdrawnState) {
153 /\* XXX: make dock apps work! *\/
154 XUngrabServer(ob_display);
163 /* choose the events we want to receive on the CLIENT window */
164 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
165 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
166 XChangeWindowAttributes(ob_display
, window
,
167 CWEventMask
|CWDontPropagate
, &attrib_set
);
170 /* create the Client struct, and populate it from the hints on the
172 client
= g_new(Client
, 1);
173 client
->window
= window
;
174 client_get_all(client
);
176 /* remove the client's border (and adjust re gravity) */
177 client_toggle_border(client
, FALSE
);
179 /* specify that if we exit, the window should not be destroyed and should
180 be reparented back to root automatically */
181 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
183 /* create the decoration frame for the client window */
184 client
->frame
= engine_frame_new();
186 engine_frame_grab_client(client
->frame
, client
);
188 client_apply_startup_state(client
);
190 XUngrabServer(ob_display
);
193 client_list
= g_slist_append(client_list
, client
);
194 stacking_list
= g_list_append(stacking_list
, client
);
195 g_hash_table_insert(client_map
, (gpointer
)window
, client
);
197 stacking_raise(client
);
199 screen_update_struts();
201 /* add to the python list */
202 cw
= clientwrap_new(client
);
203 PyList_Append(openboxwrap_obj
->client_list
, cw
);
206 HOOKFIRECLIENT(managed
, client
);
208 client_showhide(client
);
210 /* grab all mouse bindings */
211 pointer_grab_all(client
, TRUE
);
213 /* update the list hints */
216 g_message("Managed window 0x%lx", window
);
219 void client_unmanage_all()
221 while (client_list
!= NULL
)
222 client_unmanage(client_list
->data
);
225 void client_unmanage(Client
*client
)
231 g_message("Unmanaging window: %lx", client
->window
);
233 HOOKFIRECLIENT(closed
, client
);
235 /* remove the window from our save set */
236 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
238 /* we dont want events no more */
239 XSelectInput(ob_display
, client
->window
, NoEventMask
);
241 /* ungrab any mouse bindings */
242 pointer_grab_all(client
, FALSE
);
244 engine_frame_hide(client
->frame
);
246 /* give the client its border back */
247 client_toggle_border(client
, TRUE
);
249 /* reparent the window out of the frame, and free the frame */
250 engine_frame_release_client(client
->frame
, client
);
252 client_list
= g_slist_remove(client_list
, client
);
253 stacking_list
= g_list_remove(stacking_list
, client
);
254 g_hash_table_remove(client_map
, (gpointer
)client
->window
);
256 /* once the client is out of the list, update the struts to remove it's
258 screen_update_struts();
260 /* remove from the python list */
261 cw
= clientwrap_new(client
);
262 seq
= PySequence_Index(openboxwrap_obj
->client_list
, cw
);
266 PySequence_DelItem(openboxwrap_obj
->client_list
, seq
);
269 /* notify the wrapper that its useless now */
270 if (client
->wrap
!= NULL
)
271 client
->wrap
->client
= NULL
;
273 /* tell our parent that we're gone */
274 if (client
->transient_for
!= NULL
)
275 client
->transient_for
->transients
=
276 g_slist_remove(client
->transient_for
->transients
, client
);
278 /* tell our transients that we're gone */
279 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
280 ((Client
*)it
->data
)->transient_for
= NULL
;
281 client_calc_layer(it
->data
);
284 /* unfocus the client (calls the focus callbacks) (we're out of the
285 transient lists already, so being modal doesn't matter) */
287 client_unfocus(client
);
289 if (ob_state
!= State_Exiting
) {
290 /* these values should not be persisted across a window
292 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
293 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
295 /* if we're left in an iconic state, the client wont be mapped. this is
296 bad, since we will no longer be managing the window on restart */
298 XMapWindow(ob_display
, client
->window
);
301 /* free all data allocated in the client struct */
302 g_slist_free(client
->transients
);
303 for (j
= 0; j
< client
->nicons
; ++j
)
304 g_free(client
->icons
[j
].data
);
305 if (client
->nicons
> 0)
306 g_free(client
->icons
);
307 g_free(client
->title
);
308 g_free(client
->icon_title
);
309 g_free(client
->res_name
);
310 g_free(client
->res_class
);
311 g_free(client
->role
);
314 /* update the list hints */
318 static void client_toggle_border(Client
*self
, gboolean show
)
320 /* adjust our idea of where the client is, based on its border. When the
321 border is removed, the client should now be considered to be in a
323 when re-adding the border to the client, the same operation needs to be
325 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
326 int x
= oldx
, y
= oldy
;
327 switch(self
->gravity
) {
329 case NorthWestGravity
:
331 case SouthWestGravity
:
333 case NorthEastGravity
:
335 case SouthEastGravity
:
336 if (show
) x
-= self
->border_width
* 2;
337 else x
+= self
->border_width
* 2;
344 if (show
) x
-= self
->border_width
;
345 else x
+= self
->border_width
;
348 switch(self
->gravity
) {
350 case NorthWestGravity
:
352 case NorthEastGravity
:
354 case SouthWestGravity
:
356 case SouthEastGravity
:
357 if (show
) y
-= self
->border_width
* 2;
358 else y
+= self
->border_width
* 2;
365 if (show
) y
-= self
->border_width
;
366 else y
+= self
->border_width
;
373 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
375 /* move the client so it is back it the right spot _with_ its
377 if (x
!= oldx
|| y
!= oldy
)
378 XMoveWindow(ob_display
, self
->window
, x
, y
);
380 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
384 static void client_get_all(Client
*self
)
386 /* update EVERYTHING!! */
388 self
->ignore_unmaps
= 0;
392 self
->title
= self
->icon_title
= NULL
;
393 self
->res_name
= self
->res_class
= self
->role
= NULL
;
394 self
->wmstate
= NormalState
;
395 self
->focused
= FALSE
;
396 self
->transient
= FALSE
;
397 self
->transients
= NULL
;
398 self
->transient_for
= NULL
;
400 self
->urgent
= FALSE
;
401 self
->positioned
= FALSE
;
402 self
->disabled_decorations
= 0;
407 client_get_area(self
);
408 client_get_desktop(self
);
409 client_get_state(self
);
410 client_get_shaped(self
);
412 client_update_transient_for(self
);
413 client_get_mwm_hints(self
);
414 client_get_type(self
);/* this can change the mwmhints for special cases */
416 client_update_protocols(self
);
418 client_get_gravity(self
); /* get the attribute gravity */
419 client_update_normal_hints(self
); /* this may override the attribute
422 /* got the type, the mwmhints, the protocols, and the normal hints
423 (min/max sizes), so we're ready to set up the decorations/functions */
424 client_setup_decor_and_functions(self
);
426 client_update_wmhints(self
);
427 client_update_title(self
);
428 client_update_icon_title(self
);
429 client_update_class(self
);
430 client_update_strut(self
);
431 client_update_icons(self
);
432 client_update_kwm_icon(self
);
434 /* this makes sure that these windows appear on all desktops */
435 if (self
->type
== Type_Desktop
)
436 self
->desktop
= DESKTOP_ALL
;
438 /* set the desktop hint, to make sure that it always exists, and to
439 reflect any changes we've made here */
440 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
442 client_change_state(self
);
445 static void client_get_area(Client
*self
)
447 XWindowAttributes wattrib
;
450 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
451 g_assert(ret
!= BadWindow
);
453 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
454 self
->border_width
= wattrib
.border_width
;
457 static void client_get_desktop(Client
*self
)
461 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
462 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
463 d
= screen_num_desktops
- 1;
466 /* defaults to the current desktop */
467 self
->desktop
= screen_desktop
;
471 static void client_get_state(Client
*self
)
476 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
477 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
478 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
480 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
482 for (i
= 0; i
< num
; ++i
) {
483 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
485 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
487 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
489 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
490 self
->skip_taskbar
= TRUE
;
491 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
492 self
->skip_pager
= TRUE
;
493 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
494 self
->fullscreen
= TRUE
;
495 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
496 self
->max_vert
= TRUE
;
497 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
498 self
->max_horz
= TRUE
;
499 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
501 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
509 static void client_get_shaped(Client
*self
)
511 self
->shaped
= FALSE
;
513 if (extensions_shape
) {
518 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
520 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
521 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
523 self
->shaped
= (s
!= 0);
528 void client_update_transient_for(Client
*self
)
533 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
534 t
!= self
->window
) { /* cant be transient to itself! */
535 self
->transient
= TRUE
;
536 c
= g_hash_table_lookup(client_map
, (gpointer
)t
);
537 g_assert(c
!= self
);/* if this happens then we need to check for it*/
539 if (!c
/*XXX: && _group*/) {
540 /* not transient to a client, see if it is transient for a
542 if (/*t == _group->leader() || */
545 /* window is a transient for its group! */
546 /* XXX: for now this is treated as non-transient.
547 this needs to be fixed! */
551 self
->transient
= FALSE
;
553 /* if anything has changed... */
554 if (c
!= self
->transient_for
) {
555 if (self
->transient_for
)
556 /* remove from old parent */
557 g_slist_remove(self
->transient_for
->transients
, self
);
558 self
->transient_for
= c
;
559 if (self
->transient_for
)
560 /* add to new parent */
561 g_slist_append(self
->transient_for
->transients
, self
);
565 static void client_get_mwm_hints(Client
*self
)
568 unsigned long *hints
;
570 self
->mwmhints
.flags
= 0; /* default to none */
572 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
573 if (num
>= MWM_ELEMENTS
) {
574 self
->mwmhints
.flags
= hints
[0];
575 self
->mwmhints
.functions
= hints
[1];
576 self
->mwmhints
.decorations
= hints
[2];
582 void client_get_type(Client
*self
)
588 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
589 /* use the first value that we know about in the array */
590 for (i
= 0; i
< num
; ++i
) {
591 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
592 self
->type
= Type_Desktop
;
593 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
594 self
->type
= Type_Dock
;
595 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
596 self
->type
= Type_Toolbar
;
597 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
598 self
->type
= Type_Menu
;
599 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
600 self
->type
= Type_Utility
;
601 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
602 self
->type
= Type_Splash
;
603 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
604 self
->type
= Type_Dialog
;
605 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
606 self
->type
= Type_Normal
;
607 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
608 /* prevent this window from getting any decor or
610 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
611 MwmFlag_Decorations
);
612 self
->mwmhints
.decorations
= 0;
613 self
->mwmhints
.functions
= 0;
615 if (self
->type
!= (WindowType
) -1)
616 break; /* grab the first legit type */
621 if (self
->type
== (WindowType
) -1) {
622 /*the window type hint was not set, which means we either classify
623 ourself as a normal window or a dialog, depending on if we are a
626 self
->type
= Type_Dialog
;
628 self
->type
= Type_Normal
;
632 void client_update_protocols(Client
*self
)
635 gulong num_return
, i
;
637 self
->focus_notify
= FALSE
;
638 self
->delete_window
= FALSE
;
640 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
641 for (i
= 0; i
< num_return
; ++i
) {
642 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
643 /* this means we can request the window to close */
644 self
->delete_window
= TRUE
;
645 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
646 /* if this protocol is requested, then the window will be
647 notified whenever we want it to receive focus */
648 self
->focus_notify
= TRUE
;
654 static void client_get_gravity(Client
*self
)
656 XWindowAttributes wattrib
;
659 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
660 g_assert(ret
!= BadWindow
);
661 self
->gravity
= wattrib
.win_gravity
;
664 void client_update_normal_hints(Client
*self
)
668 int oldgravity
= self
->gravity
;
671 self
->min_ratio
= 0.0f
;
672 self
->max_ratio
= 0.0f
;
673 SIZE_SET(self
->size_inc
, 1, 1);
674 SIZE_SET(self
->base_size
, 0, 0);
675 SIZE_SET(self
->min_size
, 0, 0);
676 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
678 /* get the hints from the window */
679 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
680 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
682 if (size
.flags
& PWinGravity
) {
683 self
->gravity
= size
.win_gravity
;
685 /* if the client has a frame, i.e. has already been mapped and
686 is changing its gravity */
687 if (self
->frame
&& self
->gravity
!= oldgravity
) {
688 /* move our idea of the client's position based on its new
690 self
->area
.x
= self
->frame
->area
.x
;
691 self
->area
.y
= self
->frame
->area
.y
;
692 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
696 if (size
.flags
& PAspect
) {
697 if (size
.min_aspect
.y
)
698 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
699 if (size
.max_aspect
.y
)
700 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
703 if (size
.flags
& PMinSize
)
704 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
706 if (size
.flags
& PMaxSize
)
707 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
709 if (size
.flags
& PBaseSize
)
710 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
712 if (size
.flags
& PResizeInc
)
713 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
717 void client_setup_decor_and_functions(Client
*self
)
719 /* start with everything (cept fullscreen) */
720 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
721 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
722 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
724 if (self
->delete_window
) {
725 self
->decorations
|= Decor_Close
;
726 self
->functions
|= Func_Close
;
729 if (!(self
->min_size
.width
< self
->max_size
.width
||
730 self
->min_size
.height
< self
->max_size
.height
)) {
731 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
732 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
735 switch (self
->type
) {
737 /* normal windows retain all of the possible decorations and
738 functionality, and are the only windows that you can fullscreen */
739 self
->functions
|= Func_Fullscreen
;
743 /* dialogs cannot be maximized */
744 self
->decorations
&= ~Decor_Maximize
;
745 self
->functions
&= ~Func_Maximize
;
751 /* these windows get less functionality */
752 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
753 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
759 /* none of these windows are manipulated by the window manager */
760 self
->decorations
= 0;
765 /* Mwm Hints are applied subtractively to what has already been chosen for
766 decor and functionality */
767 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
768 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
769 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
770 self
->decorations
&= ~Decor_Border
;
771 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
772 self
->decorations
&= ~Decor_Handle
;
773 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
774 self
->decorations
&= ~Decor_Titlebar
;
775 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
776 self
->decorations
&= ~Decor_Iconify
;
777 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
778 self
->decorations
&= ~Decor_Maximize
;
782 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
783 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
784 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
785 self
->functions
&= ~Func_Resize
;
786 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
787 self
->functions
&= ~Func_Move
;
788 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
789 self
->functions
&= ~Func_Iconify
;
790 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
791 self
->functions
&= ~Func_Maximize
;
792 /* dont let mwm hints kill the close button
793 if (! (self->mwmhints.functions & MwmFunc_Close))
794 self->functions &= ~Func_Close; */
798 /* can't maximize without moving/resizing */
799 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
800 self
->functions
&= ~Func_Maximize
;
802 /* finally, user specified disabled decorations are applied to subtract
804 if (self
->disabled_decorations
& Decor_Titlebar
)
805 self
->decorations
&= ~Decor_Titlebar
;
806 if (self
->disabled_decorations
& Decor_Handle
)
807 self
->decorations
&= ~Decor_Handle
;
808 if (self
->disabled_decorations
& Decor_Border
)
809 self
->decorations
&= ~Decor_Border
;
810 if (self
->disabled_decorations
& Decor_Iconify
)
811 self
->decorations
&= ~Decor_Iconify
;
812 if (self
->disabled_decorations
& Decor_Maximize
)
813 self
->decorations
&= ~Decor_Maximize
;
814 if (self
->disabled_decorations
& Decor_AllDesktops
)
815 self
->decorations
&= ~Decor_AllDesktops
;
816 if (self
->disabled_decorations
& Decor_Close
)
817 self
->decorations
&= ~Decor_Close
;
819 /* if we don't have a titlebar, then we cannot shade! */
820 if (!(self
->decorations
& Decor_Titlebar
))
821 self
->functions
&= ~Func_Shade
;
823 client_change_allowed_actions(self
);
826 /* change the decors on the frame */
827 engine_frame_adjust_size(self
->frame
);
828 /* with more/less decorations, we may need to be repositioned */
829 engine_frame_adjust_position(self
->frame
);
830 /* with new decor, the window's maximized size may change */
831 client_remaximize(self
);
835 static void client_change_allowed_actions(Client
*self
)
840 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
842 if (self
->functions
& Func_Shade
)
843 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
844 if (self
->functions
& Func_Close
)
845 actions
[num
++] = prop_atoms
.net_wm_action_close
;
846 if (self
->functions
& Func_Move
)
847 actions
[num
++] = prop_atoms
.net_wm_action_move
;
848 if (self
->functions
& Func_Iconify
)
849 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
850 if (self
->functions
& Func_Resize
)
851 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
852 if (self
->functions
& Func_Fullscreen
)
853 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
854 if (self
->functions
& Func_Maximize
) {
855 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
856 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
859 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
861 /* make sure the window isn't breaking any rules now */
863 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
864 if (self
->frame
) client_shade(self
, FALSE
);
865 else self
->shaded
= FALSE
;
867 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
868 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
869 else self
->iconic
= FALSE
;
871 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
872 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
873 else self
->fullscreen
= FALSE
;
875 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
877 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
878 else self
->max_vert
= self
->max_horz
= FALSE
;
882 void client_remaximize(Client
*self
)
885 if (self
->max_horz
&& self
->max_vert
)
887 else if (self
->max_horz
)
889 else if (self
->max_vert
)
892 return; /* not maximized */
893 self
->max_horz
= self
->max_vert
= FALSE
;
894 client_maximize(self
, TRUE
, dir
, FALSE
);
897 void client_update_wmhints(Client
*self
)
902 /* assume a window takes input if it doesnt specify */
903 self
->can_focus
= TRUE
;
905 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
906 if (hints
->flags
& InputHint
)
907 self
->can_focus
= hints
->input
;
909 /* only do this when starting! */
910 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
911 self
->iconic
= hints
->initial_state
== IconicState
;
913 if (hints
->flags
& XUrgencyHint
)
916 if (hints
->flags
& WindowGroupHint
) {
917 if (hints
->window_group
!= self
->group
) {
918 /* XXX: remove from the old group if there was one */
919 self
->group
= hints
->window_group
;
920 /* XXX: do stuff with the group */
922 } else /* no group! */
925 if (hints
->flags
& IconPixmapHint
) {
926 client_update_kwm_icon(self
);
927 /* try get the kwm icon first, this is a fallback only */
928 if (self
->pixmap_icon
== None
) {
929 self
->pixmap_icon
= hints
->icon_pixmap
;
930 if (hints
->flags
& IconMaskHint
)
931 self
->pixmap_icon_mask
= hints
->icon_mask
;
933 self
->pixmap_icon_mask
= None
;
936 engine_frame_adjust_icon(self
->frame
);
943 if (ur
!= self
->urgent
) {
945 g_message("Urgent Hint for 0x%lx: %s\n", self
->window
,
947 /* fire the urgent callback if we're mapped, otherwise, wait until
948 after we're mapped */
950 HOOKFIRECLIENT(urgent
, self
);
954 void client_update_title(Client
*self
)
958 if (self
->title
!= NULL
)
962 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
963 /* try old x stuff */
964 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
965 /* convert it to UTF-8 */
969 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
971 g_warning("Unable to convert string to UTF-8");
978 data
= g_strdup("Unnamed Window");
980 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
986 engine_frame_adjust_title(self
->frame
);
989 void client_update_icon_title(Client
*self
)
993 if (self
->icon_title
!= NULL
)
994 g_free(self
->icon_title
);
997 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
998 /* try old x stuff */
999 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1000 /* convert it to UTF-8 */
1004 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1006 g_warning("Unable to convert string to UTF-8");
1013 data
= g_strdup("Unnamed Window");
1015 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1018 self
->icon_title
= data
;
1021 void client_update_class(Client
*self
)
1027 if (self
->res_name
) g_free(self
->res_name
);
1028 if (self
->res_class
) g_free(self
->res_class
);
1029 if (self
->role
) g_free(self
->role
);
1031 self
->res_name
= self
->res_class
= self
->role
= NULL
;
1033 data
= g_ptr_array_new();
1035 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1037 self
->res_name
= g_strdup(g_ptr_array_index(data
, 0));
1039 self
->res_class
= g_strdup(g_ptr_array_index(data
, 1));
1042 for (i
= 0; i
< data
->len
; ++i
)
1043 g_free(g_ptr_array_index(data
, i
));
1044 g_ptr_array_free(data
, TRUE
);
1046 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1047 self
->role
= g_strdup(s
);
1049 if (self
->res_name
== NULL
) self
->res_name
= g_strdup("");
1050 if (self
->res_class
== NULL
) self
->res_class
= g_strdup("");
1051 if (self
->role
== NULL
) self
->role
= g_strdup("");
1054 void client_update_strut(Client
*self
)
1058 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1059 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1062 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1064 /* updating here is pointless while we're being mapped cuz we're not in
1065 the client list yet */
1067 screen_update_struts();
1070 void client_update_icons(Client
*self
)
1073 unsigned long *data
;
1074 unsigned long w
, h
, i
;
1077 for (j
= 0; j
< self
->nicons
; ++j
)
1078 g_free(self
->icons
[j
].data
);
1079 if (self
->nicons
> 0)
1080 g_free(self
->icons
);
1083 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1084 /* figure out how many valid icons are in here */
1086 while (num
- i
> 2) {
1094 self
->icons
= g_new(Icon
, self
->nicons
);
1096 /* store the icons */
1098 for (j
= 0; j
< self
->nicons
; ++j
) {
1099 w
= self
->icons
[j
].w
= data
[i
++];
1100 h
= self
->icons
[j
].h
= data
[i
++];
1101 self
->icons
[j
].data
=
1102 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1110 if (self
->nicons
<= 0) {
1112 self
->icons
= g_new0(Icon
, 1);
1116 engine_frame_adjust_icon(self
->frame
);
1119 void client_update_kwm_icon(Client
*self
)
1123 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1124 self
->pixmap_icon
= data
[0];
1125 self
->pixmap_icon_mask
= data
[1];
1128 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1131 engine_frame_adjust_icon(self
->frame
);
1134 static void client_change_state(Client
*self
)
1136 unsigned long state
[2];
1140 state
[0] = self
->wmstate
;
1142 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1146 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1148 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1150 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1151 if (self
->skip_taskbar
)
1152 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1153 if (self
->skip_pager
)
1154 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1155 if (self
->fullscreen
)
1156 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1158 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1160 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1162 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1164 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1165 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1167 client_calc_layer(self
);
1170 engine_frame_adjust_state(self
->frame
);
1173 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1178 for (it
= node
->transients
; it
!= NULL
; it
= g_slist_next(it
)) {
1179 Client
*c
= it
->data
;
1180 if (c
== skip
) continue; /* circular? */
1181 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1182 if (c
->focused
) return c
;
1187 void client_calc_layer(Client
*self
)
1193 /* are we fullscreen, or do we have a fullscreen transient parent? */
1197 if (c
->fullscreen
) {
1201 c
= c
->transient_for
;
1203 if (!fs
&& self
->fullscreen
) {
1204 /* is one of our transients focused? */
1205 c
= search_focus_tree(self
, self
);
1206 if (c
!= NULL
) fs
= TRUE
;
1209 if (self
->iconic
) l
= Layer_Icon
;
1210 else if (fs
) l
= Layer_Fullscreen
;
1211 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1212 else if (self
->type
== Type_Dock
) {
1213 if (!self
->below
) l
= Layer_Top
;
1214 else l
= Layer_Normal
;
1216 else if (self
->above
) l
= Layer_Above
;
1217 else if (self
->below
) l
= Layer_Below
;
1218 else l
= Layer_Normal
;
1220 if (l
!= self
->layer
) {
1223 stacking_raise(self
);
1227 gboolean
client_should_show(Client
*self
)
1229 if (self
->iconic
) return FALSE
;
1230 else if (!(self
->desktop
== screen_desktop
||
1231 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1232 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1237 static void client_showhide(Client
*self
)
1240 if (client_should_show(self
))
1241 engine_frame_show(self
->frame
);
1243 engine_frame_hide(self
->frame
);
1245 HOOKFIRECLIENT(visible
, self
);
1248 gboolean
client_normal(Client
*self
) {
1249 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1250 self
->type
== Type_Splash
);
1253 static void client_apply_startup_state(Client
*self
)
1255 /* these are in a carefully crafted order.. */
1258 self
->iconic
= FALSE
;
1259 client_iconify(self
, TRUE
, FALSE
);
1261 if (self
->fullscreen
) {
1262 self
->fullscreen
= FALSE
;
1263 client_fullscreen(self
, TRUE
, FALSE
);
1266 self
->shaded
= FALSE
;
1267 client_shade(self
, TRUE
);
1270 HOOKFIRECLIENT(urgent
, self
);
1272 if (self
->max_vert
&& self
->max_horz
) {
1273 self
->max_vert
= self
->max_horz
= FALSE
;
1274 client_maximize(self
, TRUE
, 0, FALSE
);
1275 } else if (self
->max_vert
) {
1276 self
->max_vert
= FALSE
;
1277 client_maximize(self
, TRUE
, 2, FALSE
);
1278 } else if (self
->max_horz
) {
1279 self
->max_horz
= FALSE
;
1280 client_maximize(self
, TRUE
, 1, FALSE
);
1283 /* nothing to do for the other states:
1292 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1293 gboolean user
, gboolean final
)
1295 gboolean moved
= FALSE
, resized
= FALSE
;
1297 w
-= self
->base_size
.width
;
1298 h
-= self
->base_size
.height
;
1301 /* for interactive resizing. have to move half an increment in each
1304 /* how far we are towards the next size inc */
1305 int mw
= w
% self
->size_inc
.width
;
1306 int mh
= h
% self
->size_inc
.height
;
1308 int aw
= self
->size_inc
.width
/ 2;
1309 int ah
= self
->size_inc
.height
/ 2;
1310 /* don't let us move into a new size increment */
1311 if (mw
+ aw
>= self
->size_inc
.width
)
1312 aw
= self
->size_inc
.width
- mw
- 1;
1313 if (mh
+ ah
>= self
->size_inc
.height
)
1314 ah
= self
->size_inc
.height
- mh
- 1;
1318 /* if this is a user-requested resize, then check against min/max
1319 sizes and aspect ratios */
1321 /* smaller than min size or bigger than max size? */
1322 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1323 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1324 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1325 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1327 /* adjust the height ot match the width for the aspect ratios */
1328 if (self
->min_ratio
)
1329 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1330 if (self
->max_ratio
)
1331 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1334 /* keep to the increments */
1335 w
/= self
->size_inc
.width
;
1336 h
/= self
->size_inc
.height
;
1338 /* you cannot resize to nothing */
1342 /* store the logical size */
1343 SIZE_SET(self
->logical_size
, w
, h
);
1345 w
*= self
->size_inc
.width
;
1346 h
*= self
->size_inc
.height
;
1348 w
+= self
->base_size
.width
;
1349 h
+= self
->base_size
.height
;
1352 case Corner_TopLeft
:
1354 case Corner_TopRight
:
1355 x
-= w
- self
->area
.width
;
1357 case Corner_BottomLeft
:
1358 y
-= h
- self
->area
.height
;
1360 case Corner_BottomRight
:
1361 x
-= w
- self
->area
.width
;
1362 y
-= h
- self
->area
.height
;
1366 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1367 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1369 RECT_SET(self
->area
, x
, y
, w
, h
);
1372 XResizeWindow(ob_display
, self
->window
, w
, h
);
1374 /* move/resize the frame to match the request */
1376 /* Adjust the size and then the position, as required by the EWMH */
1378 engine_frame_adjust_size(self
->frame
);
1380 engine_frame_adjust_position(self
->frame
);
1382 if (!user
|| final
) {
1384 event
.type
= ConfigureNotify
;
1385 event
.xconfigure
.display
= ob_display
;
1386 event
.xconfigure
.event
= self
->window
;
1387 event
.xconfigure
.window
= self
->window
;
1389 /* root window coords with border in mind */
1390 event
.xconfigure
.x
= x
- self
->border_width
+
1391 self
->frame
->size
.left
;
1392 event
.xconfigure
.y
= y
- self
->border_width
+
1393 self
->frame
->size
.top
;
1395 event
.xconfigure
.width
= self
->area
.width
;
1396 event
.xconfigure
.height
= self
->area
.height
;
1397 event
.xconfigure
.border_width
= self
->border_width
;
1398 event
.xconfigure
.above
= self
->frame
->plate
;
1399 event
.xconfigure
.override_redirect
= FALSE
;
1400 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1401 FALSE
, StructureNotifyMask
, &event
);
1407 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1409 static int saved_func
, saved_decor
;
1412 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1413 self
->fullscreen
== fs
) return; /* already done */
1415 self
->fullscreen
= fs
;
1416 client_change_state(self
); /* change the state hints on the client */
1419 /* save the functions and remove them */
1420 saved_func
= self
->functions
;
1421 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1423 /* save the decorations and remove them */
1424 saved_decor
= self
->decorations
;
1425 self
->decorations
= 0;
1428 dimensions
[0] = self
->area
.x
;
1429 dimensions
[1] = self
->area
.y
;
1430 dimensions
[2] = self
->area
.width
;
1431 dimensions
[3] = self
->area
.height
;
1433 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1438 w
= screen_physical_size
.width
;
1439 h
= screen_physical_size
.height
;
1443 self
->functions
= saved_func
;
1444 self
->decorations
= saved_decor
;
1446 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1454 /* pick some fallbacks... */
1455 x
= screen_area(self
->desktop
)->x
+
1456 screen_area(self
->desktop
)->width
/ 4;
1457 y
= screen_area(self
->desktop
)->y
+
1458 screen_area(self
->desktop
)->height
/ 4;
1459 w
= screen_area(self
->desktop
)->width
/ 2;
1460 h
= screen_area(self
->desktop
)->height
/ 2;
1464 client_change_allowed_actions(self
); /* based on the new _functions */
1466 /* when fullscreening, don't obey things like increments, fill the
1468 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1470 /* raise (back) into our stacking layer */
1471 stacking_raise(self
);
1473 /* try focus us when we go into fullscreen mode */
1477 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1479 if (self
->iconic
== iconic
) return; /* nothing to do */
1481 g_message("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
1484 self
->iconic
= iconic
;
1487 self
->wmstate
= IconicState
;
1488 self
->ignore_unmaps
++;
1489 /* we unmap the client itself so that we can get MapRequest events,
1490 and because the ICCCM tells us to! */
1491 XUnmapWindow(ob_display
, self
->window
);
1494 client_set_desktop(self
, screen_desktop
);
1495 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1496 XMapWindow(ob_display
, self
->window
);
1498 client_change_state(self
);
1499 client_showhide(self
);
1500 screen_update_struts();
1503 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1507 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1508 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1510 /* check if already done */
1512 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1513 if (dir
== 1 && self
->max_horz
) return;
1514 if (dir
== 2 && self
->max_vert
) return;
1516 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1517 if (dir
== 1 && !self
->max_horz
) return;
1518 if (dir
== 2 && !self
->max_vert
) return;
1521 /* work with the frame's coords */
1522 x
= self
->frame
->area
.x
;
1523 y
= self
->frame
->area
.y
;
1524 w
= self
->area
.width
;
1525 h
= self
->area
.height
;
1537 /* get the property off the window and use it for the dimensions
1538 we are already maxed on */
1539 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1541 if (self
->max_horz
) {
1542 dimensions
[0] = readdim
[0];
1543 dimensions
[2] = readdim
[2];
1545 if (self
->max_vert
) {
1546 dimensions
[1] = readdim
[1];
1547 dimensions
[3] = readdim
[3];
1552 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1555 if (dir
== 0 || dir
== 1) { /* horz */
1556 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1557 w
= screen_area(self
->desktop
)->x
+
1558 screen_area(self
->desktop
)->width
;
1560 if (dir
== 0 || dir
== 2) { /* vert */
1561 y
= screen_area(self
->desktop
)->y
;
1562 h
= screen_area(self
->desktop
)->y
+
1563 screen_area(self
->desktop
)->height
-
1564 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1569 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1571 if (dir
== 0 || dir
== 1) { /* horz */
1575 if (dir
== 0 || dir
== 2) { /* vert */
1581 /* pick some fallbacks... */
1582 if (dir
== 0 || dir
== 1) { /* horz */
1583 x
= screen_area(self
->desktop
)->x
+
1584 screen_area(self
->desktop
)->width
/ 4;
1585 w
= screen_area(self
->desktop
)->width
/ 2;
1587 if (dir
== 0 || dir
== 2) { /* vert */
1588 y
= screen_area(self
->desktop
)->y
+
1589 screen_area(self
->desktop
)->height
/ 4;
1590 h
= screen_area(self
->desktop
)->height
/ 2;
1595 if (dir
== 0 || dir
== 1) /* horz */
1596 self
->max_horz
= max
;
1597 if (dir
== 0 || dir
== 2) /* vert */
1598 self
->max_vert
= max
;
1600 if (!self
->max_horz
&& !self
->max_vert
)
1601 PROP_ERASE(self
->window
, openbox_premax
);
1603 client_change_state(self
); /* change the state hints on the client */
1605 /* figure out where the client should be going */
1606 frame_frame_gravity(self
->frame
, &x
, &y
);
1607 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1610 void client_shade(Client
*self
, gboolean shade
)
1612 if (!(self
->functions
& Func_Shade
) || /* can't */
1613 self
->shaded
== shade
) return; /* already done */
1615 /* when we're iconic, don't change the wmstate */
1617 self
->wmstate
= shade
? IconicState
: NormalState
;
1618 self
->shaded
= shade
;
1619 client_change_state(self
);
1620 engine_frame_adjust_size(self
->frame
);
1623 void client_close(Client
*self
)
1627 if (!(self
->functions
& Func_Close
)) return;
1630 XXX: itd be cool to do timeouts and shit here for killing the client's
1632 like... if the window is around after 5 seconds, then the close button
1633 turns a nice red, and if this function is called again, the client is
1637 ce
.xclient
.type
= ClientMessage
;
1638 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1639 ce
.xclient
.display
= ob_display
;
1640 ce
.xclient
.window
= self
->window
;
1641 ce
.xclient
.format
= 32;
1642 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1643 ce
.xclient
.data
.l
[1] = CurrentTime
;
1644 ce
.xclient
.data
.l
[2] = 0l;
1645 ce
.xclient
.data
.l
[3] = 0l;
1646 ce
.xclient
.data
.l
[4] = 0l;
1647 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1650 void client_set_desktop(Client
*self
, unsigned int target
)
1652 if (target
== self
->desktop
) return;
1654 g_message("Setting desktop %u\n", target
);
1656 if (!(target
< screen_num_desktops
||
1657 target
== DESKTOP_ALL
))
1660 self
->desktop
= target
;
1661 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1662 /* the frame can display the current desktop state */
1663 engine_frame_adjust_state(self
->frame
);
1664 /* 'move' the window to the new desktop */
1665 client_showhide(self
);
1666 screen_update_struts();
1669 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1674 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1675 Client
*c
= it
->data
;
1676 if (c
== skip
) continue; /* circular? */
1677 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1678 if (c
->modal
) return c
;
1683 Client
*client_find_modal_child(Client
*self
)
1685 return search_modal_tree(self
, self
);
1688 gboolean
client_validate(Client
*self
)
1692 XSync(ob_display
, FALSE
); /* get all events on the server */
1694 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1695 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1696 XPutBackEvent(ob_display
, &e
);
1703 void client_set_wm_state(Client
*self
, long state
)
1705 if (state
== self
->wmstate
) return; /* no change */
1709 client_iconify(self
, TRUE
, TRUE
);
1712 client_iconify(self
, FALSE
, TRUE
);
1717 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1719 gboolean shaded
= self
->shaded
;
1720 gboolean fullscreen
= self
->fullscreen
;
1721 gboolean max_horz
= self
->max_horz
;
1722 gboolean max_vert
= self
->max_vert
;
1725 if (!(action
== prop_atoms
.net_wm_state_add
||
1726 action
== prop_atoms
.net_wm_state_remove
||
1727 action
== prop_atoms
.net_wm_state_toggle
))
1728 /* an invalid action was passed to the client message, ignore it */
1731 for (i
= 0; i
< 2; ++i
) {
1732 Atom state
= i
== 0 ? data1
: data2
;
1734 if (!state
) continue;
1736 /* if toggling, then pick whether we're adding or removing */
1737 if (action
== prop_atoms
.net_wm_state_toggle
) {
1738 if (state
== prop_atoms
.net_wm_state_modal
)
1739 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1740 prop_atoms
.net_wm_state_add
;
1741 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1742 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1743 prop_atoms
.net_wm_state_add
;
1744 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1745 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1746 prop_atoms
.net_wm_state_add
;
1747 else if (state
== prop_atoms
.net_wm_state_shaded
)
1748 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1749 prop_atoms
.net_wm_state_add
;
1750 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1751 action
= self
->skip_taskbar
?
1752 prop_atoms
.net_wm_state_remove
:
1753 prop_atoms
.net_wm_state_add
;
1754 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1755 action
= self
->skip_pager
?
1756 prop_atoms
.net_wm_state_remove
:
1757 prop_atoms
.net_wm_state_add
;
1758 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1759 action
= self
->fullscreen
?
1760 prop_atoms
.net_wm_state_remove
:
1761 prop_atoms
.net_wm_state_add
;
1762 else if (state
== prop_atoms
.net_wm_state_above
)
1763 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1764 prop_atoms
.net_wm_state_add
;
1765 else if (state
== prop_atoms
.net_wm_state_below
)
1766 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1767 prop_atoms
.net_wm_state_add
;
1770 if (action
== prop_atoms
.net_wm_state_add
) {
1771 if (state
== prop_atoms
.net_wm_state_modal
) {
1772 /* XXX raise here or something? */
1774 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1776 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1778 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1780 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1781 self
->skip_taskbar
= TRUE
;
1782 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1783 self
->skip_pager
= TRUE
;
1784 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1786 } else if (state
== prop_atoms
.net_wm_state_above
) {
1788 } else if (state
== prop_atoms
.net_wm_state_below
) {
1792 } else { /* action == prop_atoms.net_wm_state_remove */
1793 if (state
== prop_atoms
.net_wm_state_modal
) {
1794 self
->modal
= FALSE
;
1795 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1797 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1799 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1801 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1802 self
->skip_taskbar
= FALSE
;
1803 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1804 self
->skip_pager
= FALSE
;
1805 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1807 } else if (state
== prop_atoms
.net_wm_state_above
) {
1808 self
->above
= FALSE
;
1809 } else if (state
== prop_atoms
.net_wm_state_below
) {
1810 self
->below
= FALSE
;
1814 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1815 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1817 if (max_horz
== max_vert
) { /* both going the same way */
1818 client_maximize(self
, max_horz
, 0, TRUE
);
1820 client_maximize(self
, max_horz
, 1, TRUE
);
1821 client_maximize(self
, max_vert
, 2, TRUE
);
1825 if (max_horz
!= self
->max_horz
)
1826 client_maximize(self
, max_horz
, 1, TRUE
);
1828 client_maximize(self
, max_vert
, 2, TRUE
);
1831 /* change fullscreen state before shading, as it will affect if the window
1833 if (fullscreen
!= self
->fullscreen
)
1834 client_fullscreen(self
, fullscreen
, TRUE
);
1835 if (shaded
!= self
->shaded
)
1836 client_shade(self
, shaded
);
1837 client_calc_layer(self
);
1838 client_change_state(self
); /* change the hint to relect these changes */
1841 gboolean
client_focus(Client
*self
)
1846 /* if we have a modal child, then focus it, not us */
1847 child
= client_find_modal_child(self
);
1849 return client_focus(child
);
1851 /* won't try focus if the client doesn't want it, or if the window isn't
1852 visible on the screen */
1853 if (!(self
->frame
->visible
&&
1854 (self
->can_focus
|| self
->focus_notify
)))
1857 /* do a check to see if the window has already been unmapped or destroyed
1858 do this intelligently while watching out for unmaps we've generated
1859 (ignore_unmaps > 0) */
1860 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1861 DestroyNotify
, &ev
)) {
1862 XPutBackEvent(ob_display
, &ev
);
1865 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1866 UnmapNotify
, &ev
)) {
1867 if (self
->ignore_unmaps
) {
1868 self
->ignore_unmaps
--;
1870 XPutBackEvent(ob_display
, &ev
);
1875 if (self
->can_focus
)
1876 XSetInputFocus(ob_display
, self
->window
, RevertToNone
, CurrentTime
);
1878 if (self
->focus_notify
) {
1880 ce
.xclient
.type
= ClientMessage
;
1881 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1882 ce
.xclient
.display
= ob_display
;
1883 ce
.xclient
.window
= self
->window
;
1884 ce
.xclient
.format
= 32;
1885 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1886 ce
.xclient
.data
.l
[1] = event_lasttime
;
1887 ce
.xclient
.data
.l
[2] = 0l;
1888 ce
.xclient
.data
.l
[3] = 0l;
1889 ce
.xclient
.data
.l
[4] = 0l;
1890 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1893 /*XSync(ob_display, FALSE); XXX Why sync? */
1897 void client_unfocus(Client
*self
)
1899 g_assert(focus_client
== self
);
1900 focus_set_client(NULL
);