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_assert(!g_hash_table_lookup(client_map
, (gpointer
)client
->window
));
190 g_hash_table_insert(client_map
, (gpointer
)window
, client
);
192 /* update the focus lists */
193 if (client
->desktop
== DESKTOP_ALL
) {
194 for (i
= 0; i
< screen_num_desktops
; ++i
)
195 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
198 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
201 stacking_raise(client
);
203 screen_update_struts();
205 dispatch_client(Event_Client_New
, client
, 0, 0);
207 client_showhide(client
);
209 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
211 /* update the list hints */
214 g_message("Managed window 0x%lx", window
);
217 void client_unmanage_all()
219 while (client_list
!= NULL
)
220 client_unmanage(client_list
->data
);
223 void client_unmanage(Client
*client
)
229 g_message("Unmanaging window: %lx", client
->window
);
231 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
232 g_assert(client
!= NULL
);
234 /* remove the window from our save set */
235 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
237 /* we dont want events no more */
238 XSelectInput(ob_display
, client
->window
, NoEventMask
);
240 engine_frame_hide(client
->frame
);
242 /* dispatch the unmapped event */
243 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
244 g_assert(client
!= NULL
);
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
);
251 client
->frame
= NULL
;
253 client_list
= g_slist_remove(client_list
, client
);
254 stacking_list
= g_list_remove(stacking_list
, client
);
255 g_hash_table_remove(client_map
, (gpointer
)client
->window
);
257 /* update the focus lists */
258 if (client
->desktop
== DESKTOP_ALL
) {
259 for (i
= 0; i
< screen_num_desktops
; ++i
)
260 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
263 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
266 /* once the client is out of the list, update the struts to remove it's
268 screen_update_struts();
270 /* tell our parent that we're gone */
271 if (client
->transient_for
!= NULL
)
272 client
->transient_for
->transients
=
273 g_slist_remove(client
->transient_for
->transients
, client
);
275 /* tell our transients that we're gone */
276 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
277 ((Client
*)it
->data
)->transient_for
= NULL
;
278 client_calc_layer(it
->data
);
281 /* unfocus the client (dispatchs the focus event) (we're out of the
282 transient lists already, so being modal doesn't matter) */
283 if (client_focused(client
))
284 client_unfocus(client
);
286 if (ob_state
!= State_Exiting
) {
287 /* these values should not be persisted across a window
289 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
290 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
292 /* if we're left in an iconic state, the client wont be mapped. this is
293 bad, since we will no longer be managing the window on restart */
295 XMapWindow(ob_display
, client
->window
);
298 /* free all data allocated in the client struct */
299 g_slist_free(client
->transients
);
300 for (j
= 0; j
< client
->nicons
; ++j
)
301 g_free(client
->icons
[j
].data
);
302 if (client
->nicons
> 0)
303 g_free(client
->icons
);
304 g_free(client
->title
);
305 g_free(client
->icon_title
);
306 g_free(client
->name
);
307 g_free(client
->class);
308 g_free(client
->role
);
311 /* update the list hints */
315 static void client_toggle_border(Client
*self
, gboolean show
)
317 /* adjust our idea of where the client is, based on its border. When the
318 border is removed, the client should now be considered to be in a
320 when re-adding the border to the client, the same operation needs to be
322 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
323 int x
= oldx
, y
= oldy
;
324 switch(self
->gravity
) {
326 case NorthWestGravity
:
328 case SouthWestGravity
:
330 case NorthEastGravity
:
332 case SouthEastGravity
:
333 if (show
) x
-= self
->border_width
* 2;
334 else x
+= self
->border_width
* 2;
341 if (show
) x
-= self
->border_width
;
342 else x
+= self
->border_width
;
345 switch(self
->gravity
) {
347 case NorthWestGravity
:
349 case NorthEastGravity
:
351 case SouthWestGravity
:
353 case SouthEastGravity
:
354 if (show
) y
-= self
->border_width
* 2;
355 else y
+= self
->border_width
* 2;
362 if (show
) y
-= self
->border_width
;
363 else y
+= self
->border_width
;
370 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
372 /* move the client so it is back it the right spot _with_ its
374 if (x
!= oldx
|| y
!= oldy
)
375 XMoveWindow(ob_display
, self
->window
, x
, y
);
377 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
381 static void client_get_all(Client
*self
)
383 /* update EVERYTHING!! */
385 self
->ignore_unmaps
= 0;
389 self
->title
= self
->icon_title
= NULL
;
390 self
->name
= self
->class = self
->role
= NULL
;
391 self
->wmstate
= NormalState
;
392 self
->transient
= FALSE
;
393 self
->transients
= NULL
;
394 self
->transient_for
= NULL
;
396 self
->urgent
= FALSE
;
397 self
->positioned
= FALSE
;
398 self
->disabled_decorations
= 0;
402 client_get_area(self
);
403 client_get_desktop(self
);
404 client_get_state(self
);
405 client_get_shaped(self
);
407 client_update_transient_for(self
);
408 client_get_mwm_hints(self
);
409 client_get_type(self
);/* this can change the mwmhints for special cases */
411 client_update_protocols(self
);
413 client_get_gravity(self
); /* get the attribute gravity */
414 client_update_normal_hints(self
); /* this may override the attribute
417 /* got the type, the mwmhints, the protocols, and the normal hints
418 (min/max sizes), so we're ready to set up the decorations/functions */
419 client_setup_decor_and_functions(self
);
421 client_update_wmhints(self
);
422 client_update_title(self
);
423 client_update_icon_title(self
);
424 client_update_class(self
);
425 client_update_strut(self
);
426 client_update_icons(self
);
427 client_update_kwm_icon(self
);
429 /* this makes sure that these windows appear on all desktops */
430 if (self
->type
== Type_Desktop
)
431 self
->desktop
= DESKTOP_ALL
;
433 /* set the desktop hint, to make sure that it always exists, and to
434 reflect any changes we've made here */
435 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
437 client_change_state(self
);
440 static void client_get_area(Client
*self
)
442 XWindowAttributes wattrib
;
445 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
446 g_assert(ret
!= BadWindow
);
448 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
449 self
->border_width
= wattrib
.border_width
;
452 static void client_get_desktop(Client
*self
)
456 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
457 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
458 d
= screen_num_desktops
- 1;
461 /* defaults to the current desktop */
462 self
->desktop
= screen_desktop
;
466 static void client_get_state(Client
*self
)
471 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
472 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
473 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
475 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
477 for (i
= 0; i
< num
; ++i
) {
478 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
480 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
482 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
484 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
485 self
->skip_taskbar
= TRUE
;
486 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
487 self
->skip_pager
= TRUE
;
488 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
489 self
->fullscreen
= TRUE
;
490 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
491 self
->max_vert
= TRUE
;
492 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
493 self
->max_horz
= TRUE
;
494 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
496 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
504 static void client_get_shaped(Client
*self
)
506 self
->shaped
= FALSE
;
508 if (extensions_shape
) {
513 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
515 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
516 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
518 self
->shaped
= (s
!= 0);
523 void client_update_transient_for(Client
*self
)
528 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
529 t
!= self
->window
) { /* cant be transient to itself! */
530 self
->transient
= TRUE
;
531 c
= g_hash_table_lookup(client_map
, (gpointer
)t
);
532 g_assert(c
!= self
);/* if this happens then we need to check for it*/
534 if (!c
/*XXX: && _group*/) {
535 /* not transient to a client, see if it is transient for a
537 if (/*t == _group->leader() || */
540 /* window is a transient for its group! */
541 /* XXX: for now this is treated as non-transient.
542 this needs to be fixed! */
546 self
->transient
= FALSE
;
548 /* if anything has changed... */
549 if (c
!= self
->transient_for
) {
550 if (self
->transient_for
)
551 /* remove from old parent */
552 self
->transient_for
->transients
=
553 g_slist_remove(self
->transient_for
->transients
, self
);
554 self
->transient_for
= c
;
555 if (self
->transient_for
)
556 /* add to new parent */
557 self
->transient_for
->transients
=
558 g_slist_append(self
->transient_for
->transients
, self
);
562 static void client_get_mwm_hints(Client
*self
)
565 unsigned long *hints
;
567 self
->mwmhints
.flags
= 0; /* default to none */
569 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
570 if (num
>= MWM_ELEMENTS
) {
571 self
->mwmhints
.flags
= hints
[0];
572 self
->mwmhints
.functions
= hints
[1];
573 self
->mwmhints
.decorations
= hints
[2];
579 void client_get_type(Client
*self
)
585 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
586 /* use the first value that we know about in the array */
587 for (i
= 0; i
< num
; ++i
) {
588 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
589 self
->type
= Type_Desktop
;
590 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
591 self
->type
= Type_Dock
;
592 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
593 self
->type
= Type_Toolbar
;
594 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
595 self
->type
= Type_Menu
;
596 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
597 self
->type
= Type_Utility
;
598 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
599 self
->type
= Type_Splash
;
600 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
601 self
->type
= Type_Dialog
;
602 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
603 self
->type
= Type_Normal
;
604 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
605 /* prevent this window from getting any decor or
607 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
608 MwmFlag_Decorations
);
609 self
->mwmhints
.decorations
= 0;
610 self
->mwmhints
.functions
= 0;
612 if (self
->type
!= (WindowType
) -1)
613 break; /* grab the first legit type */
618 if (self
->type
== (WindowType
) -1) {
619 /*the window type hint was not set, which means we either classify
620 ourself as a normal window or a dialog, depending on if we are a
623 self
->type
= Type_Dialog
;
625 self
->type
= Type_Normal
;
629 void client_update_protocols(Client
*self
)
632 gulong num_return
, i
;
634 self
->focus_notify
= FALSE
;
635 self
->delete_window
= FALSE
;
637 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
638 for (i
= 0; i
< num_return
; ++i
) {
639 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
640 /* this means we can request the window to close */
641 self
->delete_window
= TRUE
;
642 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
643 /* if this protocol is requested, then the window will be
644 notified whenever we want it to receive focus */
645 self
->focus_notify
= TRUE
;
651 static void client_get_gravity(Client
*self
)
653 XWindowAttributes wattrib
;
656 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
657 g_assert(ret
!= BadWindow
);
658 self
->gravity
= wattrib
.win_gravity
;
661 void client_update_normal_hints(Client
*self
)
665 int oldgravity
= self
->gravity
;
668 self
->min_ratio
= 0.0f
;
669 self
->max_ratio
= 0.0f
;
670 SIZE_SET(self
->size_inc
, 1, 1);
671 SIZE_SET(self
->base_size
, 0, 0);
672 SIZE_SET(self
->min_size
, 0, 0);
673 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
675 /* get the hints from the window */
676 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
677 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
679 if (size
.flags
& PWinGravity
) {
680 self
->gravity
= size
.win_gravity
;
682 /* if the client has a frame, i.e. has already been mapped and
683 is changing its gravity */
684 if (self
->frame
&& self
->gravity
!= oldgravity
) {
685 /* move our idea of the client's position based on its new
687 self
->area
.x
= self
->frame
->area
.x
;
688 self
->area
.y
= self
->frame
->area
.y
;
689 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
693 if (size
.flags
& PAspect
) {
694 if (size
.min_aspect
.y
)
695 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
696 if (size
.max_aspect
.y
)
697 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
700 if (size
.flags
& PMinSize
)
701 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
703 if (size
.flags
& PMaxSize
)
704 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
706 if (size
.flags
& PBaseSize
)
707 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
709 if (size
.flags
& PResizeInc
)
710 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
714 void client_setup_decor_and_functions(Client
*self
)
716 /* start with everything (cept fullscreen) */
717 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
718 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
719 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
721 if (self
->delete_window
) {
722 self
->decorations
|= Decor_Close
;
723 self
->functions
|= Func_Close
;
726 if (!(self
->min_size
.width
< self
->max_size
.width
||
727 self
->min_size
.height
< self
->max_size
.height
)) {
728 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
729 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
732 switch (self
->type
) {
734 /* normal windows retain all of the possible decorations and
735 functionality, and are the only windows that you can fullscreen */
736 self
->functions
|= Func_Fullscreen
;
740 /* dialogs cannot be maximized */
741 self
->decorations
&= ~Decor_Maximize
;
742 self
->functions
&= ~Func_Maximize
;
748 /* these windows get less functionality */
749 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
750 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
756 /* none of these windows are manipulated by the window manager */
757 self
->decorations
= 0;
762 /* Mwm Hints are applied subtractively to what has already been chosen for
763 decor and functionality */
764 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
765 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
766 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
767 self
->decorations
&= ~Decor_Border
;
768 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
769 self
->decorations
&= ~Decor_Handle
;
770 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
771 self
->decorations
&= ~Decor_Titlebar
;
772 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
773 self
->decorations
&= ~Decor_Iconify
;
774 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
775 self
->decorations
&= ~Decor_Maximize
;
779 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
780 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
781 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
782 self
->functions
&= ~Func_Resize
;
783 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
784 self
->functions
&= ~Func_Move
;
785 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
786 self
->functions
&= ~Func_Iconify
;
787 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
788 self
->functions
&= ~Func_Maximize
;
789 /* dont let mwm hints kill the close button
790 if (! (self->mwmhints.functions & MwmFunc_Close))
791 self->functions &= ~Func_Close; */
795 /* can't maximize without moving/resizing */
796 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
797 self
->functions
&= ~Func_Maximize
;
799 /* finally, user specified disabled decorations are applied to subtract
801 if (self
->disabled_decorations
& Decor_Titlebar
)
802 self
->decorations
&= ~Decor_Titlebar
;
803 if (self
->disabled_decorations
& Decor_Handle
)
804 self
->decorations
&= ~Decor_Handle
;
805 if (self
->disabled_decorations
& Decor_Border
)
806 self
->decorations
&= ~Decor_Border
;
807 if (self
->disabled_decorations
& Decor_Iconify
)
808 self
->decorations
&= ~Decor_Iconify
;
809 if (self
->disabled_decorations
& Decor_Maximize
)
810 self
->decorations
&= ~Decor_Maximize
;
811 if (self
->disabled_decorations
& Decor_AllDesktops
)
812 self
->decorations
&= ~Decor_AllDesktops
;
813 if (self
->disabled_decorations
& Decor_Close
)
814 self
->decorations
&= ~Decor_Close
;
816 /* if we don't have a titlebar, then we cannot shade! */
817 if (!(self
->decorations
& Decor_Titlebar
))
818 self
->functions
&= ~Func_Shade
;
820 client_change_allowed_actions(self
);
823 /* change the decors on the frame, and with more/less decorations,
824 we may also need to be repositioned */
825 engine_frame_adjust_area(self
->frame
);
826 /* with new decor, the window's maximized size may change */
827 client_remaximize(self
);
831 static void client_change_allowed_actions(Client
*self
)
836 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
838 if (self
->functions
& Func_Shade
)
839 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
840 if (self
->functions
& Func_Close
)
841 actions
[num
++] = prop_atoms
.net_wm_action_close
;
842 if (self
->functions
& Func_Move
)
843 actions
[num
++] = prop_atoms
.net_wm_action_move
;
844 if (self
->functions
& Func_Iconify
)
845 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
846 if (self
->functions
& Func_Resize
)
847 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
848 if (self
->functions
& Func_Fullscreen
)
849 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
850 if (self
->functions
& Func_Maximize
) {
851 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
852 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
855 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
857 /* make sure the window isn't breaking any rules now */
859 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
860 if (self
->frame
) client_shade(self
, FALSE
);
861 else self
->shaded
= FALSE
;
863 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
864 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
865 else self
->iconic
= FALSE
;
867 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
868 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
869 else self
->fullscreen
= FALSE
;
871 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
873 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
874 else self
->max_vert
= self
->max_horz
= FALSE
;
878 void client_remaximize(Client
*self
)
881 if (self
->max_horz
&& self
->max_vert
)
883 else if (self
->max_horz
)
885 else if (self
->max_vert
)
888 return; /* not maximized */
889 self
->max_horz
= self
->max_vert
= FALSE
;
890 client_maximize(self
, TRUE
, dir
, FALSE
);
893 void client_update_wmhints(Client
*self
)
898 /* assume a window takes input if it doesnt specify */
899 self
->can_focus
= TRUE
;
901 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
902 if (hints
->flags
& InputHint
)
903 self
->can_focus
= hints
->input
;
905 /* only do this when starting! */
906 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
907 self
->iconic
= hints
->initial_state
== IconicState
;
909 if (hints
->flags
& XUrgencyHint
)
912 if (hints
->flags
& WindowGroupHint
) {
913 if (hints
->window_group
!= self
->group
) {
914 /* XXX: remove from the old group if there was one */
915 self
->group
= hints
->window_group
;
916 /* XXX: do stuff with the group */
918 } else /* no group! */
921 if (hints
->flags
& IconPixmapHint
) {
922 client_update_kwm_icon(self
);
923 /* try get the kwm icon first, this is a fallback only */
924 if (self
->pixmap_icon
== None
) {
925 self
->pixmap_icon
= hints
->icon_pixmap
;
926 if (hints
->flags
& IconMaskHint
)
927 self
->pixmap_icon_mask
= hints
->icon_mask
;
929 self
->pixmap_icon_mask
= None
;
932 engine_frame_adjust_icon(self
->frame
);
939 if (ur
!= self
->urgent
) {
941 g_message("Urgent Hint for 0x%lx: %s\n", self
->window
,
943 /* fire the urgent callback if we're mapped, otherwise, wait until
944 after we're mapped */
946 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
950 void client_update_title(Client
*self
)
957 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
958 /* try old x stuff */
959 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
960 /* convert it to UTF-8 */
964 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
966 g_warning("Unable to convert string to UTF-8");
973 data
= g_strdup("Unnamed Window");
975 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
981 engine_frame_adjust_title(self
->frame
);
984 void client_update_icon_title(Client
*self
)
988 g_free(self
->icon_title
);
991 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
992 /* try old x stuff */
993 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
994 /* convert it to UTF-8 */
998 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1000 g_warning("Unable to convert string to UTF-8");
1007 data
= g_strdup("Unnamed Window");
1009 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1012 self
->icon_title
= data
;
1015 void client_update_class(Client
*self
)
1021 if (self
->name
) g_free(self
->name
);
1022 if (self
->class) g_free(self
->class);
1023 if (self
->role
) g_free(self
->role
);
1025 self
->name
= self
->class = self
->role
= NULL
;
1027 data
= g_ptr_array_new();
1029 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1031 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1033 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1036 for (i
= 0; i
< data
->len
; ++i
)
1037 g_free(g_ptr_array_index(data
, i
));
1038 g_ptr_array_free(data
, TRUE
);
1040 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1041 self
->role
= g_strdup(s
);
1043 if (self
->name
== NULL
) self
->name
= g_strdup("");
1044 if (self
->class == NULL
) self
->class = g_strdup("");
1045 if (self
->role
== NULL
) self
->role
= g_strdup("");
1048 void client_update_strut(Client
*self
)
1052 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1053 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1056 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1058 /* updating here is pointless while we're being mapped cuz we're not in
1059 the client list yet */
1061 screen_update_struts();
1064 void client_update_icons(Client
*self
)
1067 unsigned long *data
;
1068 unsigned long w
, h
, i
;
1071 for (j
= 0; j
< self
->nicons
; ++j
)
1072 g_free(self
->icons
[j
].data
);
1073 if (self
->nicons
> 0)
1074 g_free(self
->icons
);
1077 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1078 /* figure out how many valid icons are in here */
1080 while (num
- i
> 2) {
1088 self
->icons
= g_new(Icon
, self
->nicons
);
1090 /* store the icons */
1092 for (j
= 0; j
< self
->nicons
; ++j
) {
1093 w
= self
->icons
[j
].w
= data
[i
++];
1094 h
= self
->icons
[j
].h
= data
[i
++];
1095 self
->icons
[j
].data
=
1096 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1104 if (self
->nicons
<= 0) {
1106 self
->icons
= g_new0(Icon
, 1);
1110 engine_frame_adjust_icon(self
->frame
);
1113 void client_update_kwm_icon(Client
*self
)
1117 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1118 self
->pixmap_icon
= data
[0];
1119 self
->pixmap_icon_mask
= data
[1];
1122 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1125 engine_frame_adjust_icon(self
->frame
);
1128 static void client_change_state(Client
*self
)
1130 unsigned long state
[2];
1134 state
[0] = self
->wmstate
;
1136 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1140 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1142 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1144 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1145 if (self
->skip_taskbar
)
1146 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1147 if (self
->skip_pager
)
1148 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1149 if (self
->fullscreen
)
1150 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1152 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1154 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1156 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1158 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1159 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1161 client_calc_layer(self
);
1164 engine_frame_adjust_state(self
->frame
);
1167 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1172 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1173 Client
*c
= it
->data
;
1174 if (c
== skip
) continue; /* circular? */
1175 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1176 if (client_focused(c
)) return c
;
1181 void client_calc_layer(Client
*self
)
1187 /* are we fullscreen, or do we have a fullscreen transient parent? */
1191 if (c
->fullscreen
) {
1195 c
= c
->transient_for
;
1197 if (!fs
&& self
->fullscreen
) {
1198 /* is one of our transients focused? */
1199 c
= search_focus_tree(self
, self
);
1200 if (c
!= NULL
) fs
= TRUE
;
1203 if (self
->iconic
) l
= Layer_Icon
;
1204 else if (fs
) l
= Layer_Fullscreen
;
1205 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1206 else if (self
->type
== Type_Dock
) {
1207 if (!self
->below
) l
= Layer_Top
;
1208 else l
= Layer_Normal
;
1210 else if (self
->above
) l
= Layer_Above
;
1211 else if (self
->below
) l
= Layer_Below
;
1212 else l
= Layer_Normal
;
1214 if (l
!= self
->layer
) {
1217 stacking_raise(self
);
1221 gboolean
client_should_show(Client
*self
)
1223 if (self
->iconic
) return FALSE
;
1224 else if (!(self
->desktop
== screen_desktop
||
1225 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1226 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1231 static void client_showhide(Client
*self
)
1234 if (client_should_show(self
))
1235 engine_frame_show(self
->frame
);
1237 engine_frame_hide(self
->frame
);
1240 gboolean
client_normal(Client
*self
) {
1241 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1242 self
->type
== Type_Splash
);
1245 static void client_apply_startup_state(Client
*self
)
1247 /* these are in a carefully crafted order.. */
1250 self
->iconic
= FALSE
;
1251 client_iconify(self
, TRUE
, FALSE
);
1253 if (self
->fullscreen
) {
1254 self
->fullscreen
= FALSE
;
1255 client_fullscreen(self
, TRUE
, FALSE
);
1258 self
->shaded
= FALSE
;
1259 client_shade(self
, TRUE
);
1262 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1264 if (self
->max_vert
&& self
->max_horz
) {
1265 self
->max_vert
= self
->max_horz
= FALSE
;
1266 client_maximize(self
, TRUE
, 0, FALSE
);
1267 } else if (self
->max_vert
) {
1268 self
->max_vert
= FALSE
;
1269 client_maximize(self
, TRUE
, 2, FALSE
);
1270 } else if (self
->max_horz
) {
1271 self
->max_horz
= FALSE
;
1272 client_maximize(self
, TRUE
, 1, FALSE
);
1275 /* nothing to do for the other states:
1284 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1285 gboolean user
, gboolean final
)
1287 gboolean moved
= FALSE
, resized
= FALSE
;
1289 /* set the size and position if fullscreen */
1290 if (self
->fullscreen
) {
1293 w
= screen_physical_size
.width
;
1294 h
= screen_physical_size
.height
;
1296 /* set the size and position if maximized */
1297 if (self
->max_horz
) {
1298 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1299 w
= screen_area(self
->desktop
)->x
+
1300 screen_area(self
->desktop
)->width
;
1302 if (self
->max_vert
) {
1303 y
= screen_area(self
->desktop
)->y
;
1304 h
= screen_area(self
->desktop
)->y
+
1305 screen_area(self
->desktop
)->height
-
1306 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1310 if (x
== self
->area
.x
&& y
== self
->area
.y
&& w
== self
->area
.width
&&
1311 h
== self
->area
.height
)
1312 return; /* no change */
1314 w
-= self
->base_size
.width
;
1315 h
-= self
->base_size
.height
;
1318 /* for interactive resizing. have to move half an increment in each
1321 /* how far we are towards the next size inc */
1322 int mw
= w
% self
->size_inc
.width
;
1323 int mh
= h
% self
->size_inc
.height
;
1325 int aw
= self
->size_inc
.width
/ 2;
1326 int ah
= self
->size_inc
.height
/ 2;
1327 /* don't let us move into a new size increment */
1328 if (mw
+ aw
>= self
->size_inc
.width
)
1329 aw
= self
->size_inc
.width
- mw
- 1;
1330 if (mh
+ ah
>= self
->size_inc
.height
)
1331 ah
= self
->size_inc
.height
- mh
- 1;
1335 /* if this is a user-requested resize, then check against min/max
1336 sizes and aspect ratios */
1338 /* smaller than min size or bigger than max size? */
1339 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1340 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1341 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1342 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1344 /* adjust the height ot match the width for the aspect ratios */
1345 if (self
->min_ratio
)
1346 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1347 if (self
->max_ratio
)
1348 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1351 /* keep to the increments */
1352 w
/= self
->size_inc
.width
;
1353 h
/= self
->size_inc
.height
;
1355 /* you cannot resize to nothing */
1359 /* store the logical size */
1360 SIZE_SET(self
->logical_size
, w
, h
);
1362 w
*= self
->size_inc
.width
;
1363 h
*= self
->size_inc
.height
;
1365 w
+= self
->base_size
.width
;
1366 h
+= self
->base_size
.height
;
1369 case Corner_TopLeft
:
1371 case Corner_TopRight
:
1372 x
-= w
- self
->area
.width
;
1374 case Corner_BottomLeft
:
1375 y
-= h
- self
->area
.height
;
1377 case Corner_BottomRight
:
1378 x
-= w
- self
->area
.width
;
1379 y
-= h
- self
->area
.height
;
1383 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1384 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1386 RECT_SET(self
->area
, x
, y
, w
, h
);
1389 XResizeWindow(ob_display
, self
->window
, w
, h
);
1391 /* move/resize the frame to match the request */
1393 engine_frame_adjust_area(self
->frame
);
1396 if (!user
|| final
) {
1398 event
.type
= ConfigureNotify
;
1399 event
.xconfigure
.display
= ob_display
;
1400 event
.xconfigure
.event
= self
->window
;
1401 event
.xconfigure
.window
= self
->window
;
1403 /* root window coords with border in mind */
1404 event
.xconfigure
.x
= x
- self
->border_width
+
1405 self
->frame
->size
.left
;
1406 event
.xconfigure
.y
= y
- self
->border_width
+
1407 self
->frame
->size
.top
;
1409 event
.xconfigure
.width
= self
->area
.width
;
1410 event
.xconfigure
.height
= self
->area
.height
;
1411 event
.xconfigure
.border_width
= self
->border_width
;
1412 event
.xconfigure
.above
= self
->frame
->plate
;
1413 event
.xconfigure
.override_redirect
= FALSE
;
1414 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1415 FALSE
, StructureNotifyMask
, &event
);
1421 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1425 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1426 self
->fullscreen
== fs
) return; /* already done */
1428 self
->fullscreen
= fs
;
1429 client_change_state(self
); /* change the state hints on the client */
1432 /* save the functions and remove them */
1433 self
->pre_fs_func
= self
->functions
;
1434 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1436 /* save the decorations and remove them */
1437 self
->pre_fs_decor
= self
->decorations
;
1438 self
->decorations
= 0;
1441 dimensions
[0] = self
->area
.x
;
1442 dimensions
[1] = self
->area
.y
;
1443 dimensions
[2] = self
->area
.width
;
1444 dimensions
[3] = self
->area
.height
;
1446 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1450 /* these are not actually used cuz client_configure will set them
1451 as appropriate when the window is fullscreened */
1456 self
->functions
= self
->pre_fs_func
;
1457 self
->decorations
= self
->pre_fs_decor
;
1459 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1467 /* pick some fallbacks... */
1468 x
= screen_area(self
->desktop
)->x
+
1469 screen_area(self
->desktop
)->width
/ 4;
1470 y
= screen_area(self
->desktop
)->y
+
1471 screen_area(self
->desktop
)->height
/ 4;
1472 w
= screen_area(self
->desktop
)->width
/ 2;
1473 h
= screen_area(self
->desktop
)->height
/ 2;
1477 client_change_allowed_actions(self
); /* based on the new _functions */
1479 /* when fullscreening, don't obey things like increments, fill the
1481 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1483 /* raise (back) into our stacking layer */
1484 stacking_raise(self
);
1486 /* try focus us when we go into fullscreen mode */
1490 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1492 if (self
->iconic
== iconic
) return; /* nothing to do */
1494 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1497 self
->iconic
= iconic
;
1500 self
->wmstate
= IconicState
;
1501 self
->ignore_unmaps
++;
1502 /* we unmap the client itself so that we can get MapRequest events,
1503 and because the ICCCM tells us to! */
1504 XUnmapWindow(ob_display
, self
->window
);
1507 client_set_desktop(self
, screen_desktop
);
1508 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1509 XMapWindow(ob_display
, self
->window
);
1511 client_change_state(self
);
1512 client_showhide(self
);
1513 screen_update_struts();
1516 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1520 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1521 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1523 /* check if already done */
1525 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1526 if (dir
== 1 && self
->max_horz
) return;
1527 if (dir
== 2 && self
->max_vert
) return;
1529 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1530 if (dir
== 1 && !self
->max_horz
) return;
1531 if (dir
== 2 && !self
->max_vert
) return;
1534 /* work with the frame's coords */
1535 x
= self
->frame
->area
.x
;
1536 y
= self
->frame
->area
.y
;
1537 w
= self
->area
.width
;
1538 h
= self
->area
.height
;
1550 /* get the property off the window and use it for the dimensions
1551 we are already maxed on */
1552 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1554 if (self
->max_horz
) {
1555 dimensions
[0] = readdim
[0];
1556 dimensions
[2] = readdim
[2];
1558 if (self
->max_vert
) {
1559 dimensions
[1] = readdim
[1];
1560 dimensions
[3] = readdim
[3];
1565 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1569 /* pass the client's current position info. the client_configure
1570 will move/size stuff as appropriate for a maximized window */
1573 w
= self
->area
.width
;
1574 h
= self
->area
.height
;
1578 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1580 if (dir
== 0 || dir
== 1) { /* horz */
1584 if (dir
== 0 || dir
== 2) { /* vert */
1590 /* pick some fallbacks... */
1591 if (dir
== 0 || dir
== 1) { /* horz */
1592 x
= screen_area(self
->desktop
)->x
+
1593 screen_area(self
->desktop
)->width
/ 4;
1594 w
= screen_area(self
->desktop
)->width
/ 2;
1596 if (dir
== 0 || dir
== 2) { /* vert */
1597 y
= screen_area(self
->desktop
)->y
+
1598 screen_area(self
->desktop
)->height
/ 4;
1599 h
= screen_area(self
->desktop
)->height
/ 2;
1604 if (dir
== 0 || dir
== 1) /* horz */
1605 self
->max_horz
= max
;
1606 if (dir
== 0 || dir
== 2) /* vert */
1607 self
->max_vert
= max
;
1609 if (!self
->max_horz
&& !self
->max_vert
)
1610 PROP_ERASE(self
->window
, openbox_premax
);
1612 client_change_state(self
); /* change the state hints on the client */
1614 /* figure out where the client should be going */
1615 frame_frame_gravity(self
->frame
, &x
, &y
);
1616 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1619 void client_shade(Client
*self
, gboolean shade
)
1621 if (!(self
->functions
& Func_Shade
) || /* can't */
1622 self
->shaded
== shade
) return; /* already done */
1624 /* when we're iconic, don't change the wmstate */
1626 self
->wmstate
= shade
? IconicState
: NormalState
;
1627 self
->shaded
= shade
;
1628 client_change_state(self
);
1629 /* resize the frame to just the titlebar */
1630 engine_frame_adjust_area(self
->frame
);
1633 void client_close(Client
*self
)
1637 if (!(self
->functions
& Func_Close
)) return;
1640 XXX: itd be cool to do timeouts and shit here for killing the client's
1642 like... if the window is around after 5 seconds, then the close button
1643 turns a nice red, and if this function is called again, the client is
1647 ce
.xclient
.type
= ClientMessage
;
1648 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1649 ce
.xclient
.display
= ob_display
;
1650 ce
.xclient
.window
= self
->window
;
1651 ce
.xclient
.format
= 32;
1652 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1653 ce
.xclient
.data
.l
[1] = CurrentTime
;
1654 ce
.xclient
.data
.l
[2] = 0l;
1655 ce
.xclient
.data
.l
[3] = 0l;
1656 ce
.xclient
.data
.l
[4] = 0l;
1657 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1660 void client_kill(Client
*self
)
1662 XKillClient(ob_display
, self
->window
);
1665 void client_set_desktop(Client
*self
, guint target
)
1669 if (target
== self
->desktop
) return;
1671 g_message("Setting desktop %u\n", target
);
1673 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1675 old
= self
->desktop
;
1676 self
->desktop
= target
;
1677 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1678 /* the frame can display the current desktop state */
1679 engine_frame_adjust_state(self
->frame
);
1680 /* 'move' the window to the new desktop */
1681 client_showhide(self
);
1682 screen_update_struts();
1684 /* update the focus lists */
1685 if (old
== DESKTOP_ALL
) {
1686 for (i
= 0; i
< screen_num_desktops
; ++i
)
1687 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1688 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1690 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1691 if (target
== DESKTOP_ALL
)
1692 for (i
= 0; i
< screen_num_desktops
; ++i
)
1693 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1696 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1699 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1704 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1705 Client
*c
= it
->data
;
1706 if (c
== skip
) continue; /* circular? */
1707 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1708 if (c
->modal
) return c
;
1713 Client
*client_find_modal_child(Client
*self
)
1715 return search_modal_tree(self
, self
);
1718 gboolean
client_validate(Client
*self
)
1722 XSync(ob_display
, FALSE
); /* get all events on the server */
1724 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1725 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1726 XPutBackEvent(ob_display
, &e
);
1733 void client_set_wm_state(Client
*self
, long state
)
1735 if (state
== self
->wmstate
) return; /* no change */
1739 client_iconify(self
, TRUE
, TRUE
);
1742 client_iconify(self
, FALSE
, TRUE
);
1747 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1749 gboolean shaded
= self
->shaded
;
1750 gboolean fullscreen
= self
->fullscreen
;
1751 gboolean max_horz
= self
->max_horz
;
1752 gboolean max_vert
= self
->max_vert
;
1755 if (!(action
== prop_atoms
.net_wm_state_add
||
1756 action
== prop_atoms
.net_wm_state_remove
||
1757 action
== prop_atoms
.net_wm_state_toggle
))
1758 /* an invalid action was passed to the client message, ignore it */
1761 for (i
= 0; i
< 2; ++i
) {
1762 Atom state
= i
== 0 ? data1
: data2
;
1764 if (!state
) continue;
1766 /* if toggling, then pick whether we're adding or removing */
1767 if (action
== prop_atoms
.net_wm_state_toggle
) {
1768 if (state
== prop_atoms
.net_wm_state_modal
)
1769 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1770 prop_atoms
.net_wm_state_add
;
1771 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1772 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1773 prop_atoms
.net_wm_state_add
;
1774 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1775 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1776 prop_atoms
.net_wm_state_add
;
1777 else if (state
== prop_atoms
.net_wm_state_shaded
)
1778 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1779 prop_atoms
.net_wm_state_add
;
1780 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1781 action
= self
->skip_taskbar
?
1782 prop_atoms
.net_wm_state_remove
:
1783 prop_atoms
.net_wm_state_add
;
1784 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1785 action
= self
->skip_pager
?
1786 prop_atoms
.net_wm_state_remove
:
1787 prop_atoms
.net_wm_state_add
;
1788 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1789 action
= self
->fullscreen
?
1790 prop_atoms
.net_wm_state_remove
:
1791 prop_atoms
.net_wm_state_add
;
1792 else if (state
== prop_atoms
.net_wm_state_above
)
1793 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1794 prop_atoms
.net_wm_state_add
;
1795 else if (state
== prop_atoms
.net_wm_state_below
)
1796 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1797 prop_atoms
.net_wm_state_add
;
1800 if (action
== prop_atoms
.net_wm_state_add
) {
1801 if (state
== prop_atoms
.net_wm_state_modal
) {
1802 /* XXX raise here or something? */
1804 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1806 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1808 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1810 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1811 self
->skip_taskbar
= TRUE
;
1812 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1813 self
->skip_pager
= TRUE
;
1814 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1816 } else if (state
== prop_atoms
.net_wm_state_above
) {
1818 } else if (state
== prop_atoms
.net_wm_state_below
) {
1822 } else { /* action == prop_atoms.net_wm_state_remove */
1823 if (state
== prop_atoms
.net_wm_state_modal
) {
1824 self
->modal
= FALSE
;
1825 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1827 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1829 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1831 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1832 self
->skip_taskbar
= FALSE
;
1833 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1834 self
->skip_pager
= FALSE
;
1835 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1837 } else if (state
== prop_atoms
.net_wm_state_above
) {
1838 self
->above
= FALSE
;
1839 } else if (state
== prop_atoms
.net_wm_state_below
) {
1840 self
->below
= FALSE
;
1844 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1845 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1847 if (max_horz
== max_vert
) { /* both going the same way */
1848 client_maximize(self
, max_horz
, 0, TRUE
);
1850 client_maximize(self
, max_horz
, 1, TRUE
);
1851 client_maximize(self
, max_vert
, 2, TRUE
);
1855 if (max_horz
!= self
->max_horz
)
1856 client_maximize(self
, max_horz
, 1, TRUE
);
1858 client_maximize(self
, max_vert
, 2, TRUE
);
1861 /* change fullscreen state before shading, as it will affect if the window
1863 if (fullscreen
!= self
->fullscreen
)
1864 client_fullscreen(self
, fullscreen
, TRUE
);
1865 if (shaded
!= self
->shaded
)
1866 client_shade(self
, shaded
);
1867 client_calc_layer(self
);
1868 client_change_state(self
); /* change the hint to relect these changes */
1871 gboolean
client_focus(Client
*self
)
1876 /* if we have a modal child, then focus it, not us */
1877 child
= client_find_modal_child(self
);
1879 return client_focus(child
);
1881 /* won't try focus if the client doesn't want it, or if the window isn't
1882 visible on the screen */
1883 if (!(self
->frame
->visible
&&
1884 (self
->can_focus
|| self
->focus_notify
)))
1887 /* do a check to see if the window has already been unmapped or destroyed
1888 do this intelligently while watching out for unmaps we've generated
1889 (ignore_unmaps > 0) */
1890 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1891 DestroyNotify
, &ev
)) {
1892 XPutBackEvent(ob_display
, &ev
);
1895 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1896 UnmapNotify
, &ev
)) {
1897 if (self
->ignore_unmaps
) {
1898 self
->ignore_unmaps
--;
1900 XPutBackEvent(ob_display
, &ev
);
1905 if (client_focused(self
))
1908 if (self
->can_focus
)
1909 XSetInputFocus(ob_display
, self
->window
, RevertToNone
, CurrentTime
);
1911 if (self
->focus_notify
) {
1913 ce
.xclient
.type
= ClientMessage
;
1914 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1915 ce
.xclient
.display
= ob_display
;
1916 ce
.xclient
.window
= self
->window
;
1917 ce
.xclient
.format
= 32;
1918 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1919 ce
.xclient
.data
.l
[1] = event_lasttime
;
1920 ce
.xclient
.data
.l
[2] = 0l;
1921 ce
.xclient
.data
.l
[3] = 0l;
1922 ce
.xclient
.data
.l
[4] = 0l;
1923 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1926 client_set_focused(self
, TRUE
);
1928 /* XSync(ob_display, FALSE); XXX Why sync? */
1932 void client_unfocus(Client
*self
)
1934 g_assert(focus_client
== self
);
1935 client_set_focused(self
, FALSE
);
1938 void client_set_focused(Client
*self
, gboolean focused
)
1941 if (focus_client
!= self
) {
1942 focus_set_client(self
);
1944 /* focus state can affect the stacking layer */
1945 client_calc_layer(self
);
1947 engine_frame_adjust_focus(self
->frame
);
1950 if (focus_client
== self
)
1951 focus_set_client(NULL
);
1953 /* focus state can affect the stacking layer */
1954 client_calc_layer(self
);
1956 if (self
->frame
!= NULL
) /* unfocus can happen while being unmanaged */
1957 engine_frame_adjust_focus(self
->frame
);
1961 gboolean
client_focused(Client
*self
)
1963 return self
== focus_client
;