4 #include "extensions.h"
14 #include <X11/Xutil.h>
16 /*! The event mask to grab on client windows */
17 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
20 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
23 GSList
*client_list
= NULL
;
24 GHashTable
*client_map
= NULL
;
26 static void client_get_all(Client
*self
);
27 static void client_toggle_border(Client
*self
, gboolean show
);
28 static void client_get_area(Client
*self
);
29 static void client_get_desktop(Client
*self
);
30 static void client_get_state(Client
*self
);
31 static void client_get_shaped(Client
*self
);
32 static void client_get_mwm_hints(Client
*self
);
33 static void client_get_gravity(Client
*self
);
34 static void client_showhide(Client
*self
);
35 static void client_change_allowed_actions(Client
*self
);
36 static void client_change_state(Client
*self
);
37 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
38 static void client_apply_startup_state(Client
*self
);
39 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
41 static guint
map_hash(Window w
) { return w
; }
42 static gboolean
map_key_comp(Window w1
, Window w2
) { return w1
== w2
; }
46 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
47 (GEqualFunc
)map_key_comp
);
51 void client_shutdown()
53 g_hash_table_destroy(client_map
);
56 void client_set_list()
58 Window
*windows
, *win_it
;
60 guint size
= g_slist_length(client_list
);
62 /* create an array of the window ids */
64 windows
= g_new(Window
, size
);
66 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
67 *win_it
= ((Client
*)it
->data
)->window
;
71 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
79 void client_manage_all()
81 unsigned int i
, j
, nchild
;
84 XWindowAttributes attrib
;
86 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
88 /* remove all icon windows from the list */
89 for (i
= 0; i
< nchild
; i
++) {
90 if (children
[i
] == None
) continue;
91 wmhints
= XGetWMHints(ob_display
, children
[i
]);
93 if ((wmhints
->flags
& IconWindowHint
) &&
94 (wmhints
->icon_window
!= children
[i
]))
95 for (j
= 0; j
< nchild
; j
++)
96 if (children
[j
] == wmhints
->icon_window
) {
104 for (i
= 0; i
< nchild
; ++i
) {
105 if (children
[i
] == None
)
107 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
108 if (attrib
.override_redirect
) continue;
110 if (attrib
.map_state
!= IsUnmapped
)
111 client_manage(children
[i
]);
117 void client_manage(Window window
)
121 XWindowAttributes attrib
;
122 XSetWindowAttributes attrib_set
;
123 /* XWMHints *wmhint; */
128 /* check if it has already been unmapped by the time we started mapping
129 the grab does a sync so we don't have to here */
130 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
131 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
132 XPutBackEvent(ob_display
, &e
);
135 return; /* don't manage it */
138 /* make sure it isn't an override-redirect window */
139 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
140 attrib
.override_redirect
) {
142 return; /* don't manage it */
145 /* /\* is the window a docking app *\/
146 if ((wmhint = XGetWMHints(ob_display, window))) {
147 if ((wmhint->flags & StateHint) &&
148 wmhint->initial_state == WithdrawnState) {
149 /\* XXX: make dock apps work! *\/
158 /* choose the events we want to receive on the CLIENT window */
159 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
160 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
161 XChangeWindowAttributes(ob_display
, window
,
162 CWEventMask
|CWDontPropagate
, &attrib_set
);
165 /* create the Client struct, and populate it from the hints on the
167 client
= g_new(Client
, 1);
168 client
->window
= window
;
169 client_get_all(client
);
171 /* remove the client's border (and adjust re gravity) */
172 client_toggle_border(client
, FALSE
);
174 /* specify that if we exit, the window should not be destroyed and should
175 be reparented back to root automatically */
176 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
178 /* create the decoration frame for the client window */
179 client
->frame
= engine_frame_new();
181 engine_frame_grab_client(client
->frame
, client
);
183 client_apply_startup_state(client
);
187 client_list
= g_slist_append(client_list
, client
);
188 stacking_list
= g_list_append(stacking_list
, client
);
189 g_hash_table_insert(client_map
, (gpointer
)window
, client
);
191 /* update the focus lists */
192 if (client
->desktop
== DESKTOP_ALL
) {
193 for (i
= 0; i
< screen_num_desktops
; ++i
)
194 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
197 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
200 stacking_raise(client
);
202 screen_update_struts();
204 dispatch_client(Event_Client_New
, client
, 0, 0);
206 client_showhide(client
);
208 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
210 /* update the list hints */
213 g_message("Managed window 0x%lx", window
);
216 void client_unmanage_all()
218 while (client_list
!= NULL
)
219 client_unmanage(client_list
->data
);
222 void client_unmanage(Client
*client
)
228 g_message("Unmanaging window: %lx", client
->window
);
230 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
231 g_assert(client
!= NULL
);
233 /* remove the window from our save set */
234 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
236 /* we dont want events no more */
237 XSelectInput(ob_display
, client
->window
, NoEventMask
);
239 engine_frame_hide(client
->frame
);
241 /* dispatch the unmapped event */
242 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
243 g_assert(client
!= NULL
);
245 /* give the client its border back */
246 client_toggle_border(client
, TRUE
);
248 /* reparent the window out of the frame, and free the frame */
249 engine_frame_release_client(client
->frame
, client
);
250 client
->frame
= NULL
;
252 client_list
= g_slist_remove(client_list
, client
);
253 stacking_list
= g_list_remove(stacking_list
, client
);
254 g_hash_table_remove(client_map
, (gpointer
)client
->window
);
256 /* update the focus lists */
257 if (client
->desktop
== DESKTOP_ALL
) {
258 for (i
= 0; i
< screen_num_desktops
; ++i
)
259 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
262 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
265 /* once the client is out of the list, update the struts to remove it's
267 screen_update_struts();
269 /* tell our parent that we're gone */
270 if (client
->transient_for
!= NULL
)
271 client
->transient_for
->transients
=
272 g_slist_remove(client
->transient_for
->transients
, client
);
274 /* tell our transients that we're gone */
275 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
276 ((Client
*)it
->data
)->transient_for
= NULL
;
277 client_calc_layer(it
->data
);
280 /* unfocus the client (dispatchs the focus event) (we're out of the
281 transient lists already, so being modal doesn't matter) */
282 if (client_focused(client
))
283 client_unfocus(client
);
285 if (ob_state
!= State_Exiting
) {
286 /* these values should not be persisted across a window
288 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
289 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
291 /* if we're left in an iconic state, the client wont be mapped. this is
292 bad, since we will no longer be managing the window on restart */
294 XMapWindow(ob_display
, client
->window
);
297 /* free all data allocated in the client struct */
298 g_slist_free(client
->transients
);
299 for (j
= 0; j
< client
->nicons
; ++j
)
300 g_free(client
->icons
[j
].data
);
301 if (client
->nicons
> 0)
302 g_free(client
->icons
);
303 g_free(client
->title
);
304 g_free(client
->icon_title
);
305 g_free(client
->name
);
306 g_free(client
->class);
307 g_free(client
->role
);
310 /* update the list hints */
314 static void client_toggle_border(Client
*self
, gboolean show
)
316 /* adjust our idea of where the client is, based on its border. When the
317 border is removed, the client should now be considered to be in a
319 when re-adding the border to the client, the same operation needs to be
321 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
322 int x
= oldx
, y
= oldy
;
323 switch(self
->gravity
) {
325 case NorthWestGravity
:
327 case SouthWestGravity
:
329 case NorthEastGravity
:
331 case SouthEastGravity
:
332 if (show
) x
-= self
->border_width
* 2;
333 else x
+= self
->border_width
* 2;
340 if (show
) x
-= self
->border_width
;
341 else x
+= self
->border_width
;
344 switch(self
->gravity
) {
346 case NorthWestGravity
:
348 case NorthEastGravity
:
350 case SouthWestGravity
:
352 case SouthEastGravity
:
353 if (show
) y
-= self
->border_width
* 2;
354 else y
+= self
->border_width
* 2;
361 if (show
) y
-= self
->border_width
;
362 else y
+= self
->border_width
;
369 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
371 /* move the client so it is back it the right spot _with_ its
373 if (x
!= oldx
|| y
!= oldy
)
374 XMoveWindow(ob_display
, self
->window
, x
, y
);
376 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
380 static void client_get_all(Client
*self
)
382 /* update EVERYTHING!! */
384 self
->ignore_unmaps
= 0;
388 self
->title
= self
->icon_title
= NULL
;
389 self
->name
= self
->class = self
->role
= NULL
;
390 self
->wmstate
= NormalState
;
391 self
->transient
= FALSE
;
392 self
->transients
= NULL
;
393 self
->transient_for
= NULL
;
395 self
->urgent
= FALSE
;
396 self
->positioned
= FALSE
;
397 self
->disabled_decorations
= 0;
401 client_get_area(self
);
402 client_get_desktop(self
);
403 client_get_state(self
);
404 client_get_shaped(self
);
406 client_update_transient_for(self
);
407 client_get_mwm_hints(self
);
408 client_get_type(self
);/* this can change the mwmhints for special cases */
410 client_update_protocols(self
);
412 client_get_gravity(self
); /* get the attribute gravity */
413 client_update_normal_hints(self
); /* this may override the attribute
416 /* got the type, the mwmhints, the protocols, and the normal hints
417 (min/max sizes), so we're ready to set up the decorations/functions */
418 client_setup_decor_and_functions(self
);
420 client_update_wmhints(self
);
421 client_update_title(self
);
422 client_update_icon_title(self
);
423 client_update_class(self
);
424 client_update_strut(self
);
425 client_update_icons(self
);
426 client_update_kwm_icon(self
);
428 /* this makes sure that these windows appear on all desktops */
429 if (self
->type
== Type_Desktop
)
430 self
->desktop
= DESKTOP_ALL
;
432 /* set the desktop hint, to make sure that it always exists, and to
433 reflect any changes we've made here */
434 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
436 client_change_state(self
);
439 static void client_get_area(Client
*self
)
441 XWindowAttributes wattrib
;
444 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
445 g_assert(ret
!= BadWindow
);
447 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
448 self
->border_width
= wattrib
.border_width
;
451 static void client_get_desktop(Client
*self
)
455 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
456 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
457 d
= screen_num_desktops
- 1;
460 /* defaults to the current desktop */
461 self
->desktop
= screen_desktop
;
465 static void client_get_state(Client
*self
)
470 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
471 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
472 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
474 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
476 for (i
= 0; i
< num
; ++i
) {
477 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
479 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
481 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
483 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
484 self
->skip_taskbar
= TRUE
;
485 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
486 self
->skip_pager
= TRUE
;
487 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
488 self
->fullscreen
= TRUE
;
489 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
490 self
->max_vert
= TRUE
;
491 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
492 self
->max_horz
= TRUE
;
493 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
495 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
503 static void client_get_shaped(Client
*self
)
505 self
->shaped
= FALSE
;
507 if (extensions_shape
) {
512 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
514 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
515 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
517 self
->shaped
= (s
!= 0);
522 void client_update_transient_for(Client
*self
)
527 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
528 t
!= self
->window
) { /* cant be transient to itself! */
529 self
->transient
= TRUE
;
530 c
= g_hash_table_lookup(client_map
, (gpointer
)t
);
531 g_assert(c
!= self
);/* if this happens then we need to check for it*/
533 if (!c
/*XXX: && _group*/) {
534 /* not transient to a client, see if it is transient for a
536 if (/*t == _group->leader() || */
539 /* window is a transient for its group! */
540 /* XXX: for now this is treated as non-transient.
541 this needs to be fixed! */
545 self
->transient
= FALSE
;
547 /* if anything has changed... */
548 if (c
!= self
->transient_for
) {
549 if (self
->transient_for
)
550 /* remove from old parent */
551 g_slist_remove(self
->transient_for
->transients
, self
);
552 self
->transient_for
= c
;
553 if (self
->transient_for
)
554 /* add to new parent */
555 g_slist_append(self
->transient_for
->transients
, self
);
559 static void client_get_mwm_hints(Client
*self
)
562 unsigned long *hints
;
564 self
->mwmhints
.flags
= 0; /* default to none */
566 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
567 if (num
>= MWM_ELEMENTS
) {
568 self
->mwmhints
.flags
= hints
[0];
569 self
->mwmhints
.functions
= hints
[1];
570 self
->mwmhints
.decorations
= hints
[2];
576 void client_get_type(Client
*self
)
582 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
583 /* use the first value that we know about in the array */
584 for (i
= 0; i
< num
; ++i
) {
585 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
586 self
->type
= Type_Desktop
;
587 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
588 self
->type
= Type_Dock
;
589 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
590 self
->type
= Type_Toolbar
;
591 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
592 self
->type
= Type_Menu
;
593 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
594 self
->type
= Type_Utility
;
595 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
596 self
->type
= Type_Splash
;
597 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
598 self
->type
= Type_Dialog
;
599 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
600 self
->type
= Type_Normal
;
601 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
602 /* prevent this window from getting any decor or
604 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
605 MwmFlag_Decorations
);
606 self
->mwmhints
.decorations
= 0;
607 self
->mwmhints
.functions
= 0;
609 if (self
->type
!= (WindowType
) -1)
610 break; /* grab the first legit type */
615 if (self
->type
== (WindowType
) -1) {
616 /*the window type hint was not set, which means we either classify
617 ourself as a normal window or a dialog, depending on if we are a
620 self
->type
= Type_Dialog
;
622 self
->type
= Type_Normal
;
626 void client_update_protocols(Client
*self
)
629 gulong num_return
, i
;
631 self
->focus_notify
= FALSE
;
632 self
->delete_window
= FALSE
;
634 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
635 for (i
= 0; i
< num_return
; ++i
) {
636 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
637 /* this means we can request the window to close */
638 self
->delete_window
= TRUE
;
639 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
640 /* if this protocol is requested, then the window will be
641 notified whenever we want it to receive focus */
642 self
->focus_notify
= TRUE
;
648 static void client_get_gravity(Client
*self
)
650 XWindowAttributes wattrib
;
653 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
654 g_assert(ret
!= BadWindow
);
655 self
->gravity
= wattrib
.win_gravity
;
658 void client_update_normal_hints(Client
*self
)
662 int oldgravity
= self
->gravity
;
665 self
->min_ratio
= 0.0f
;
666 self
->max_ratio
= 0.0f
;
667 SIZE_SET(self
->size_inc
, 1, 1);
668 SIZE_SET(self
->base_size
, 0, 0);
669 SIZE_SET(self
->min_size
, 0, 0);
670 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
672 /* get the hints from the window */
673 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
674 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
676 if (size
.flags
& PWinGravity
) {
677 self
->gravity
= size
.win_gravity
;
679 /* if the client has a frame, i.e. has already been mapped and
680 is changing its gravity */
681 if (self
->frame
&& self
->gravity
!= oldgravity
) {
682 /* move our idea of the client's position based on its new
684 self
->area
.x
= self
->frame
->area
.x
;
685 self
->area
.y
= self
->frame
->area
.y
;
686 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
690 if (size
.flags
& PAspect
) {
691 if (size
.min_aspect
.y
)
692 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
693 if (size
.max_aspect
.y
)
694 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
697 if (size
.flags
& PMinSize
)
698 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
700 if (size
.flags
& PMaxSize
)
701 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
703 if (size
.flags
& PBaseSize
)
704 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
706 if (size
.flags
& PResizeInc
)
707 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
711 void client_setup_decor_and_functions(Client
*self
)
713 /* start with everything (cept fullscreen) */
714 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
715 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
716 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
718 if (self
->delete_window
) {
719 self
->decorations
|= Decor_Close
;
720 self
->functions
|= Func_Close
;
723 if (!(self
->min_size
.width
< self
->max_size
.width
||
724 self
->min_size
.height
< self
->max_size
.height
)) {
725 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
726 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
729 switch (self
->type
) {
731 /* normal windows retain all of the possible decorations and
732 functionality, and are the only windows that you can fullscreen */
733 self
->functions
|= Func_Fullscreen
;
737 /* dialogs cannot be maximized */
738 self
->decorations
&= ~Decor_Maximize
;
739 self
->functions
&= ~Func_Maximize
;
745 /* these windows get less functionality */
746 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
747 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
753 /* none of these windows are manipulated by the window manager */
754 self
->decorations
= 0;
759 /* Mwm Hints are applied subtractively to what has already been chosen for
760 decor and functionality */
761 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
762 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
763 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
764 self
->decorations
&= ~Decor_Border
;
765 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
766 self
->decorations
&= ~Decor_Handle
;
767 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
768 self
->decorations
&= ~Decor_Titlebar
;
769 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
770 self
->decorations
&= ~Decor_Iconify
;
771 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
772 self
->decorations
&= ~Decor_Maximize
;
776 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
777 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
778 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
779 self
->functions
&= ~Func_Resize
;
780 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
781 self
->functions
&= ~Func_Move
;
782 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
783 self
->functions
&= ~Func_Iconify
;
784 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
785 self
->functions
&= ~Func_Maximize
;
786 /* dont let mwm hints kill the close button
787 if (! (self->mwmhints.functions & MwmFunc_Close))
788 self->functions &= ~Func_Close; */
792 /* can't maximize without moving/resizing */
793 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
794 self
->functions
&= ~Func_Maximize
;
796 /* finally, user specified disabled decorations are applied to subtract
798 if (self
->disabled_decorations
& Decor_Titlebar
)
799 self
->decorations
&= ~Decor_Titlebar
;
800 if (self
->disabled_decorations
& Decor_Handle
)
801 self
->decorations
&= ~Decor_Handle
;
802 if (self
->disabled_decorations
& Decor_Border
)
803 self
->decorations
&= ~Decor_Border
;
804 if (self
->disabled_decorations
& Decor_Iconify
)
805 self
->decorations
&= ~Decor_Iconify
;
806 if (self
->disabled_decorations
& Decor_Maximize
)
807 self
->decorations
&= ~Decor_Maximize
;
808 if (self
->disabled_decorations
& Decor_AllDesktops
)
809 self
->decorations
&= ~Decor_AllDesktops
;
810 if (self
->disabled_decorations
& Decor_Close
)
811 self
->decorations
&= ~Decor_Close
;
813 /* if we don't have a titlebar, then we cannot shade! */
814 if (!(self
->decorations
& Decor_Titlebar
))
815 self
->functions
&= ~Func_Shade
;
817 client_change_allowed_actions(self
);
820 /* change the decors on the frame, and with more/less decorations,
821 we may also need to be repositioned */
822 engine_frame_adjust_area(self
->frame
);
823 /* with new decor, the window's maximized size may change */
824 client_remaximize(self
);
828 static void client_change_allowed_actions(Client
*self
)
833 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
835 if (self
->functions
& Func_Shade
)
836 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
837 if (self
->functions
& Func_Close
)
838 actions
[num
++] = prop_atoms
.net_wm_action_close
;
839 if (self
->functions
& Func_Move
)
840 actions
[num
++] = prop_atoms
.net_wm_action_move
;
841 if (self
->functions
& Func_Iconify
)
842 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
843 if (self
->functions
& Func_Resize
)
844 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
845 if (self
->functions
& Func_Fullscreen
)
846 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
847 if (self
->functions
& Func_Maximize
) {
848 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
849 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
852 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
854 /* make sure the window isn't breaking any rules now */
856 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
857 if (self
->frame
) client_shade(self
, FALSE
);
858 else self
->shaded
= FALSE
;
860 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
861 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
862 else self
->iconic
= FALSE
;
864 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
865 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
866 else self
->fullscreen
= FALSE
;
868 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
870 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
871 else self
->max_vert
= self
->max_horz
= FALSE
;
875 void client_remaximize(Client
*self
)
878 if (self
->max_horz
&& self
->max_vert
)
880 else if (self
->max_horz
)
882 else if (self
->max_vert
)
885 return; /* not maximized */
886 self
->max_horz
= self
->max_vert
= FALSE
;
887 client_maximize(self
, TRUE
, dir
, FALSE
);
890 void client_update_wmhints(Client
*self
)
895 /* assume a window takes input if it doesnt specify */
896 self
->can_focus
= TRUE
;
898 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
899 if (hints
->flags
& InputHint
)
900 self
->can_focus
= hints
->input
;
902 /* only do this when starting! */
903 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
904 self
->iconic
= hints
->initial_state
== IconicState
;
906 if (hints
->flags
& XUrgencyHint
)
909 if (hints
->flags
& WindowGroupHint
) {
910 if (hints
->window_group
!= self
->group
) {
911 /* XXX: remove from the old group if there was one */
912 self
->group
= hints
->window_group
;
913 /* XXX: do stuff with the group */
915 } else /* no group! */
918 if (hints
->flags
& IconPixmapHint
) {
919 client_update_kwm_icon(self
);
920 /* try get the kwm icon first, this is a fallback only */
921 if (self
->pixmap_icon
== None
) {
922 self
->pixmap_icon
= hints
->icon_pixmap
;
923 if (hints
->flags
& IconMaskHint
)
924 self
->pixmap_icon_mask
= hints
->icon_mask
;
926 self
->pixmap_icon_mask
= None
;
929 engine_frame_adjust_icon(self
->frame
);
936 if (ur
!= self
->urgent
) {
938 g_message("Urgent Hint for 0x%lx: %s\n", self
->window
,
940 /* fire the urgent callback if we're mapped, otherwise, wait until
941 after we're mapped */
943 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
947 void client_update_title(Client
*self
)
954 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
955 /* try old x stuff */
956 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
957 /* convert it to UTF-8 */
961 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
963 g_warning("Unable to convert string to UTF-8");
970 data
= g_strdup("Unnamed Window");
972 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
978 engine_frame_adjust_title(self
->frame
);
981 void client_update_icon_title(Client
*self
)
985 g_free(self
->icon_title
);
988 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
989 /* try old x stuff */
990 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
991 /* convert it to UTF-8 */
995 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
997 g_warning("Unable to convert string to UTF-8");
1004 data
= g_strdup("Unnamed Window");
1006 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1009 self
->icon_title
= data
;
1012 void client_update_class(Client
*self
)
1018 if (self
->name
) g_free(self
->name
);
1019 if (self
->class) g_free(self
->class);
1020 if (self
->role
) g_free(self
->role
);
1022 self
->name
= self
->class = self
->role
= NULL
;
1024 data
= g_ptr_array_new();
1026 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1028 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1030 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1033 for (i
= 0; i
< data
->len
; ++i
)
1034 g_free(g_ptr_array_index(data
, i
));
1035 g_ptr_array_free(data
, TRUE
);
1037 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1038 self
->role
= g_strdup(s
);
1040 if (self
->name
== NULL
) self
->name
= g_strdup("");
1041 if (self
->class == NULL
) self
->class = g_strdup("");
1042 if (self
->role
== NULL
) self
->role
= g_strdup("");
1045 void client_update_strut(Client
*self
)
1049 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1050 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1053 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1055 /* updating here is pointless while we're being mapped cuz we're not in
1056 the client list yet */
1058 screen_update_struts();
1061 void client_update_icons(Client
*self
)
1064 unsigned long *data
;
1065 unsigned long w
, h
, i
;
1068 for (j
= 0; j
< self
->nicons
; ++j
)
1069 g_free(self
->icons
[j
].data
);
1070 if (self
->nicons
> 0)
1071 g_free(self
->icons
);
1074 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1075 /* figure out how many valid icons are in here */
1077 while (num
- i
> 2) {
1085 self
->icons
= g_new(Icon
, self
->nicons
);
1087 /* store the icons */
1089 for (j
= 0; j
< self
->nicons
; ++j
) {
1090 w
= self
->icons
[j
].w
= data
[i
++];
1091 h
= self
->icons
[j
].h
= data
[i
++];
1092 self
->icons
[j
].data
=
1093 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1101 if (self
->nicons
<= 0) {
1103 self
->icons
= g_new0(Icon
, 1);
1107 engine_frame_adjust_icon(self
->frame
);
1110 void client_update_kwm_icon(Client
*self
)
1114 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1115 self
->pixmap_icon
= data
[0];
1116 self
->pixmap_icon_mask
= data
[1];
1119 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1122 engine_frame_adjust_icon(self
->frame
);
1125 static void client_change_state(Client
*self
)
1127 unsigned long state
[2];
1131 state
[0] = self
->wmstate
;
1133 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1137 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1139 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1141 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1142 if (self
->skip_taskbar
)
1143 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1144 if (self
->skip_pager
)
1145 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1146 if (self
->fullscreen
)
1147 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1149 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1151 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1153 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1155 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1156 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1158 client_calc_layer(self
);
1161 engine_frame_adjust_state(self
->frame
);
1164 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1169 for (it
= node
->transients
; it
!= NULL
; it
= g_slist_next(it
)) {
1170 Client
*c
= it
->data
;
1171 if (c
== skip
) continue; /* circular? */
1172 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1173 if (client_focused(c
)) return c
;
1178 void client_calc_layer(Client
*self
)
1184 /* are we fullscreen, or do we have a fullscreen transient parent? */
1188 if (c
->fullscreen
) {
1192 c
= c
->transient_for
;
1194 if (!fs
&& self
->fullscreen
) {
1195 /* is one of our transients focused? */
1196 c
= search_focus_tree(self
, self
);
1197 if (c
!= NULL
) fs
= TRUE
;
1200 if (self
->iconic
) l
= Layer_Icon
;
1201 else if (fs
) l
= Layer_Fullscreen
;
1202 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1203 else if (self
->type
== Type_Dock
) {
1204 if (!self
->below
) l
= Layer_Top
;
1205 else l
= Layer_Normal
;
1207 else if (self
->above
) l
= Layer_Above
;
1208 else if (self
->below
) l
= Layer_Below
;
1209 else l
= Layer_Normal
;
1211 if (l
!= self
->layer
) {
1214 stacking_raise(self
);
1218 gboolean
client_should_show(Client
*self
)
1220 if (self
->iconic
) return FALSE
;
1221 else if (!(self
->desktop
== screen_desktop
||
1222 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1223 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1228 static void client_showhide(Client
*self
)
1231 if (client_should_show(self
))
1232 engine_frame_show(self
->frame
);
1234 engine_frame_hide(self
->frame
);
1237 gboolean
client_normal(Client
*self
) {
1238 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1239 self
->type
== Type_Splash
);
1242 static void client_apply_startup_state(Client
*self
)
1244 /* these are in a carefully crafted order.. */
1247 self
->iconic
= FALSE
;
1248 client_iconify(self
, TRUE
, FALSE
);
1250 if (self
->fullscreen
) {
1251 self
->fullscreen
= FALSE
;
1252 client_fullscreen(self
, TRUE
, FALSE
);
1255 self
->shaded
= FALSE
;
1256 client_shade(self
, TRUE
);
1259 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1261 if (self
->max_vert
&& self
->max_horz
) {
1262 self
->max_vert
= self
->max_horz
= FALSE
;
1263 client_maximize(self
, TRUE
, 0, FALSE
);
1264 } else if (self
->max_vert
) {
1265 self
->max_vert
= FALSE
;
1266 client_maximize(self
, TRUE
, 2, FALSE
);
1267 } else if (self
->max_horz
) {
1268 self
->max_horz
= FALSE
;
1269 client_maximize(self
, TRUE
, 1, FALSE
);
1272 /* nothing to do for the other states:
1281 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1282 gboolean user
, gboolean final
)
1284 gboolean moved
= FALSE
, resized
= FALSE
;
1286 /* set the size and position if fullscreen */
1287 if (self
->fullscreen
) {
1290 w
= screen_physical_size
.width
;
1291 h
= screen_physical_size
.height
;
1293 /* set the size and position if maximized */
1294 if (self
->max_horz
) {
1295 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1296 w
= screen_area(self
->desktop
)->x
+
1297 screen_area(self
->desktop
)->width
;
1299 if (self
->max_vert
) {
1300 y
= screen_area(self
->desktop
)->y
;
1301 h
= screen_area(self
->desktop
)->y
+
1302 screen_area(self
->desktop
)->height
-
1303 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1307 if (x
== self
->area
.x
&& y
== self
->area
.y
&& w
== self
->area
.width
&&
1308 h
== self
->area
.height
)
1309 return; /* no change */
1311 w
-= self
->base_size
.width
;
1312 h
-= self
->base_size
.height
;
1315 /* for interactive resizing. have to move half an increment in each
1318 /* how far we are towards the next size inc */
1319 int mw
= w
% self
->size_inc
.width
;
1320 int mh
= h
% self
->size_inc
.height
;
1322 int aw
= self
->size_inc
.width
/ 2;
1323 int ah
= self
->size_inc
.height
/ 2;
1324 /* don't let us move into a new size increment */
1325 if (mw
+ aw
>= self
->size_inc
.width
)
1326 aw
= self
->size_inc
.width
- mw
- 1;
1327 if (mh
+ ah
>= self
->size_inc
.height
)
1328 ah
= self
->size_inc
.height
- mh
- 1;
1332 /* if this is a user-requested resize, then check against min/max
1333 sizes and aspect ratios */
1335 /* smaller than min size or bigger than max size? */
1336 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1337 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1338 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1339 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1341 /* adjust the height ot match the width for the aspect ratios */
1342 if (self
->min_ratio
)
1343 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1344 if (self
->max_ratio
)
1345 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1348 /* keep to the increments */
1349 w
/= self
->size_inc
.width
;
1350 h
/= self
->size_inc
.height
;
1352 /* you cannot resize to nothing */
1356 /* store the logical size */
1357 SIZE_SET(self
->logical_size
, w
, h
);
1359 w
*= self
->size_inc
.width
;
1360 h
*= self
->size_inc
.height
;
1362 w
+= self
->base_size
.width
;
1363 h
+= self
->base_size
.height
;
1366 case Corner_TopLeft
:
1368 case Corner_TopRight
:
1369 x
-= w
- self
->area
.width
;
1371 case Corner_BottomLeft
:
1372 y
-= h
- self
->area
.height
;
1374 case Corner_BottomRight
:
1375 x
-= w
- self
->area
.width
;
1376 y
-= h
- self
->area
.height
;
1380 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1381 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1383 RECT_SET(self
->area
, x
, y
, w
, h
);
1386 XResizeWindow(ob_display
, self
->window
, w
, h
);
1388 /* move/resize the frame to match the request */
1390 engine_frame_adjust_area(self
->frame
);
1393 if (!user
|| final
) {
1395 event
.type
= ConfigureNotify
;
1396 event
.xconfigure
.display
= ob_display
;
1397 event
.xconfigure
.event
= self
->window
;
1398 event
.xconfigure
.window
= self
->window
;
1400 /* root window coords with border in mind */
1401 event
.xconfigure
.x
= x
- self
->border_width
+
1402 self
->frame
->size
.left
;
1403 event
.xconfigure
.y
= y
- self
->border_width
+
1404 self
->frame
->size
.top
;
1406 event
.xconfigure
.width
= self
->area
.width
;
1407 event
.xconfigure
.height
= self
->area
.height
;
1408 event
.xconfigure
.border_width
= self
->border_width
;
1409 event
.xconfigure
.above
= self
->frame
->plate
;
1410 event
.xconfigure
.override_redirect
= FALSE
;
1411 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1412 FALSE
, StructureNotifyMask
, &event
);
1418 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1422 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1423 self
->fullscreen
== fs
) return; /* already done */
1425 self
->fullscreen
= fs
;
1426 client_change_state(self
); /* change the state hints on the client */
1429 /* save the functions and remove them */
1430 self
->pre_fs_func
= self
->functions
;
1431 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1433 /* save the decorations and remove them */
1434 self
->pre_fs_decor
= self
->decorations
;
1435 self
->decorations
= 0;
1438 dimensions
[0] = self
->area
.x
;
1439 dimensions
[1] = self
->area
.y
;
1440 dimensions
[2] = self
->area
.width
;
1441 dimensions
[3] = self
->area
.height
;
1443 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1447 /* these are not actually used cuz client_configure will set them
1448 as appropriate when the window is fullscreened */
1453 self
->functions
= self
->pre_fs_func
;
1454 self
->decorations
= self
->pre_fs_decor
;
1456 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1464 /* pick some fallbacks... */
1465 x
= screen_area(self
->desktop
)->x
+
1466 screen_area(self
->desktop
)->width
/ 4;
1467 y
= screen_area(self
->desktop
)->y
+
1468 screen_area(self
->desktop
)->height
/ 4;
1469 w
= screen_area(self
->desktop
)->width
/ 2;
1470 h
= screen_area(self
->desktop
)->height
/ 2;
1474 client_change_allowed_actions(self
); /* based on the new _functions */
1476 /* when fullscreening, don't obey things like increments, fill the
1478 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1480 /* raise (back) into our stacking layer */
1481 stacking_raise(self
);
1483 /* try focus us when we go into fullscreen mode */
1487 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1489 if (self
->iconic
== iconic
) return; /* nothing to do */
1491 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1494 self
->iconic
= iconic
;
1497 self
->wmstate
= IconicState
;
1498 self
->ignore_unmaps
++;
1499 /* we unmap the client itself so that we can get MapRequest events,
1500 and because the ICCCM tells us to! */
1501 XUnmapWindow(ob_display
, self
->window
);
1504 client_set_desktop(self
, screen_desktop
);
1505 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1506 XMapWindow(ob_display
, self
->window
);
1508 client_change_state(self
);
1509 client_showhide(self
);
1510 screen_update_struts();
1513 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1517 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1518 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1520 /* check if already done */
1522 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1523 if (dir
== 1 && self
->max_horz
) return;
1524 if (dir
== 2 && self
->max_vert
) return;
1526 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1527 if (dir
== 1 && !self
->max_horz
) return;
1528 if (dir
== 2 && !self
->max_vert
) return;
1531 /* work with the frame's coords */
1532 x
= self
->frame
->area
.x
;
1533 y
= self
->frame
->area
.y
;
1534 w
= self
->area
.width
;
1535 h
= self
->area
.height
;
1547 /* get the property off the window and use it for the dimensions
1548 we are already maxed on */
1549 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1551 if (self
->max_horz
) {
1552 dimensions
[0] = readdim
[0];
1553 dimensions
[2] = readdim
[2];
1555 if (self
->max_vert
) {
1556 dimensions
[1] = readdim
[1];
1557 dimensions
[3] = readdim
[3];
1562 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1566 /* pass the client's current position info. the client_configure
1567 will move/size stuff as appropriate for a maximized window */
1570 w
= self
->area
.width
;
1571 h
= self
->area
.height
;
1575 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1577 if (dir
== 0 || dir
== 1) { /* horz */
1581 if (dir
== 0 || dir
== 2) { /* vert */
1587 /* pick some fallbacks... */
1588 if (dir
== 0 || dir
== 1) { /* horz */
1589 x
= screen_area(self
->desktop
)->x
+
1590 screen_area(self
->desktop
)->width
/ 4;
1591 w
= screen_area(self
->desktop
)->width
/ 2;
1593 if (dir
== 0 || dir
== 2) { /* vert */
1594 y
= screen_area(self
->desktop
)->y
+
1595 screen_area(self
->desktop
)->height
/ 4;
1596 h
= screen_area(self
->desktop
)->height
/ 2;
1601 if (dir
== 0 || dir
== 1) /* horz */
1602 self
->max_horz
= max
;
1603 if (dir
== 0 || dir
== 2) /* vert */
1604 self
->max_vert
= max
;
1606 if (!self
->max_horz
&& !self
->max_vert
)
1607 PROP_ERASE(self
->window
, openbox_premax
);
1609 client_change_state(self
); /* change the state hints on the client */
1611 /* figure out where the client should be going */
1612 frame_frame_gravity(self
->frame
, &x
, &y
);
1613 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1616 void client_shade(Client
*self
, gboolean shade
)
1618 if (!(self
->functions
& Func_Shade
) || /* can't */
1619 self
->shaded
== shade
) return; /* already done */
1621 /* when we're iconic, don't change the wmstate */
1623 self
->wmstate
= shade
? IconicState
: NormalState
;
1624 self
->shaded
= shade
;
1625 client_change_state(self
);
1626 /* resize the frame to just the titlebar */
1627 engine_frame_adjust_area(self
->frame
);
1630 void client_close(Client
*self
)
1634 if (!(self
->functions
& Func_Close
)) return;
1637 XXX: itd be cool to do timeouts and shit here for killing the client's
1639 like... if the window is around after 5 seconds, then the close button
1640 turns a nice red, and if this function is called again, the client is
1644 ce
.xclient
.type
= ClientMessage
;
1645 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1646 ce
.xclient
.display
= ob_display
;
1647 ce
.xclient
.window
= self
->window
;
1648 ce
.xclient
.format
= 32;
1649 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1650 ce
.xclient
.data
.l
[1] = CurrentTime
;
1651 ce
.xclient
.data
.l
[2] = 0l;
1652 ce
.xclient
.data
.l
[3] = 0l;
1653 ce
.xclient
.data
.l
[4] = 0l;
1654 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1657 void client_kill(Client
*self
)
1659 XKillClient(ob_display
, self
->window
);
1662 void client_set_desktop(Client
*self
, guint target
)
1666 if (target
== self
->desktop
) return;
1668 g_message("Setting desktop %u\n", target
);
1670 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1672 old
= self
->desktop
;
1673 self
->desktop
= target
;
1674 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1675 /* the frame can display the current desktop state */
1676 engine_frame_adjust_state(self
->frame
);
1677 /* 'move' the window to the new desktop */
1678 client_showhide(self
);
1679 screen_update_struts();
1681 /* update the focus lists */
1682 if (old
== DESKTOP_ALL
) {
1683 for (i
= 0; i
< screen_num_desktops
; ++i
)
1684 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1686 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1688 if (target
== DESKTOP_ALL
) {
1689 for (i
= 0; i
< screen_num_desktops
; ++i
)
1690 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1692 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1695 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1698 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1703 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1704 Client
*c
= it
->data
;
1705 if (c
== skip
) continue; /* circular? */
1706 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1707 if (c
->modal
) return c
;
1712 Client
*client_find_modal_child(Client
*self
)
1714 return search_modal_tree(self
, self
);
1717 gboolean
client_validate(Client
*self
)
1721 XSync(ob_display
, FALSE
); /* get all events on the server */
1723 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1724 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1725 XPutBackEvent(ob_display
, &e
);
1732 void client_set_wm_state(Client
*self
, long state
)
1734 if (state
== self
->wmstate
) return; /* no change */
1738 client_iconify(self
, TRUE
, TRUE
);
1741 client_iconify(self
, FALSE
, TRUE
);
1746 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1748 gboolean shaded
= self
->shaded
;
1749 gboolean fullscreen
= self
->fullscreen
;
1750 gboolean max_horz
= self
->max_horz
;
1751 gboolean max_vert
= self
->max_vert
;
1754 if (!(action
== prop_atoms
.net_wm_state_add
||
1755 action
== prop_atoms
.net_wm_state_remove
||
1756 action
== prop_atoms
.net_wm_state_toggle
))
1757 /* an invalid action was passed to the client message, ignore it */
1760 for (i
= 0; i
< 2; ++i
) {
1761 Atom state
= i
== 0 ? data1
: data2
;
1763 if (!state
) continue;
1765 /* if toggling, then pick whether we're adding or removing */
1766 if (action
== prop_atoms
.net_wm_state_toggle
) {
1767 if (state
== prop_atoms
.net_wm_state_modal
)
1768 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1769 prop_atoms
.net_wm_state_add
;
1770 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1771 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1772 prop_atoms
.net_wm_state_add
;
1773 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1774 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1775 prop_atoms
.net_wm_state_add
;
1776 else if (state
== prop_atoms
.net_wm_state_shaded
)
1777 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1778 prop_atoms
.net_wm_state_add
;
1779 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1780 action
= self
->skip_taskbar
?
1781 prop_atoms
.net_wm_state_remove
:
1782 prop_atoms
.net_wm_state_add
;
1783 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1784 action
= self
->skip_pager
?
1785 prop_atoms
.net_wm_state_remove
:
1786 prop_atoms
.net_wm_state_add
;
1787 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1788 action
= self
->fullscreen
?
1789 prop_atoms
.net_wm_state_remove
:
1790 prop_atoms
.net_wm_state_add
;
1791 else if (state
== prop_atoms
.net_wm_state_above
)
1792 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1793 prop_atoms
.net_wm_state_add
;
1794 else if (state
== prop_atoms
.net_wm_state_below
)
1795 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1796 prop_atoms
.net_wm_state_add
;
1799 if (action
== prop_atoms
.net_wm_state_add
) {
1800 if (state
== prop_atoms
.net_wm_state_modal
) {
1801 /* XXX raise here or something? */
1803 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1805 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1807 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1809 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1810 self
->skip_taskbar
= TRUE
;
1811 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1812 self
->skip_pager
= TRUE
;
1813 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1815 } else if (state
== prop_atoms
.net_wm_state_above
) {
1817 } else if (state
== prop_atoms
.net_wm_state_below
) {
1821 } else { /* action == prop_atoms.net_wm_state_remove */
1822 if (state
== prop_atoms
.net_wm_state_modal
) {
1823 self
->modal
= FALSE
;
1824 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1826 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1828 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1830 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1831 self
->skip_taskbar
= FALSE
;
1832 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1833 self
->skip_pager
= FALSE
;
1834 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1836 } else if (state
== prop_atoms
.net_wm_state_above
) {
1837 self
->above
= FALSE
;
1838 } else if (state
== prop_atoms
.net_wm_state_below
) {
1839 self
->below
= FALSE
;
1843 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1844 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1846 if (max_horz
== max_vert
) { /* both going the same way */
1847 client_maximize(self
, max_horz
, 0, TRUE
);
1849 client_maximize(self
, max_horz
, 1, TRUE
);
1850 client_maximize(self
, max_vert
, 2, TRUE
);
1854 if (max_horz
!= self
->max_horz
)
1855 client_maximize(self
, max_horz
, 1, TRUE
);
1857 client_maximize(self
, max_vert
, 2, TRUE
);
1860 /* change fullscreen state before shading, as it will affect if the window
1862 if (fullscreen
!= self
->fullscreen
)
1863 client_fullscreen(self
, fullscreen
, TRUE
);
1864 if (shaded
!= self
->shaded
)
1865 client_shade(self
, shaded
);
1866 client_calc_layer(self
);
1867 client_change_state(self
); /* change the hint to relect these changes */
1870 gboolean
client_focus(Client
*self
)
1875 /* if we have a modal child, then focus it, not us */
1876 child
= client_find_modal_child(self
);
1878 return client_focus(child
);
1880 /* won't try focus if the client doesn't want it, or if the window isn't
1881 visible on the screen */
1882 if (!(self
->frame
->visible
&&
1883 (self
->can_focus
|| self
->focus_notify
)))
1886 /* do a check to see if the window has already been unmapped or destroyed
1887 do this intelligently while watching out for unmaps we've generated
1888 (ignore_unmaps > 0) */
1889 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1890 DestroyNotify
, &ev
)) {
1891 XPutBackEvent(ob_display
, &ev
);
1894 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1895 UnmapNotify
, &ev
)) {
1896 if (self
->ignore_unmaps
) {
1897 self
->ignore_unmaps
--;
1899 XPutBackEvent(ob_display
, &ev
);
1904 if (client_focused(self
))
1907 if (self
->can_focus
)
1908 XSetInputFocus(ob_display
, self
->window
, RevertToNone
, CurrentTime
);
1910 if (self
->focus_notify
) {
1912 ce
.xclient
.type
= ClientMessage
;
1913 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1914 ce
.xclient
.display
= ob_display
;
1915 ce
.xclient
.window
= self
->window
;
1916 ce
.xclient
.format
= 32;
1917 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1918 ce
.xclient
.data
.l
[1] = event_lasttime
;
1919 ce
.xclient
.data
.l
[2] = 0l;
1920 ce
.xclient
.data
.l
[3] = 0l;
1921 ce
.xclient
.data
.l
[4] = 0l;
1922 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1925 client_set_focused(self
, TRUE
);
1927 /* XSync(ob_display, FALSE); XXX Why sync? */
1931 void client_unfocus(Client
*self
)
1933 g_assert(focus_client
== self
);
1934 client_set_focused(self
, FALSE
);
1937 void client_set_focused(Client
*self
, gboolean focused
)
1940 if (focus_client
!= self
) {
1941 focus_set_client(self
);
1943 /* focus state can affect the stacking layer */
1944 client_calc_layer(self
);
1946 engine_frame_adjust_focus(self
->frame
);
1949 if (focus_client
== self
)
1950 focus_set_client(NULL
);
1952 /* focus state can affect the stacking layer */
1953 client_calc_layer(self
);
1955 if (self
->frame
!= NULL
) /* unfocus can happen while being unmanaged */
1956 engine_frame_adjust_focus(self
->frame
);
1960 gboolean
client_focused(Client
*self
)
1962 return self
== focus_client
;