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 client_list
= g_slist_remove(client_list
, client
);
243 stacking_list
= g_list_remove(stacking_list
, client
);
244 g_hash_table_remove(client_map
, (gpointer
)client
->window
);
246 /* update the focus lists */
247 if (client
->desktop
== DESKTOP_ALL
) {
248 for (i
= 0; i
< screen_num_desktops
; ++i
)
249 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
252 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
255 /* once the client is out of the list, update the struts to remove it's
257 screen_update_struts();
259 /* tell our parent that we're gone */
260 if (client
->transient_for
!= NULL
)
261 client
->transient_for
->transients
=
262 g_slist_remove(client
->transient_for
->transients
, client
);
264 /* tell our transients that we're gone */
265 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
266 ((Client
*)it
->data
)->transient_for
= NULL
;
267 client_calc_layer(it
->data
);
270 /* dispatch the unmapped event */
271 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
272 g_assert(client
!= NULL
);
274 /* unfocus the client (dispatchs the focus event) (we're out of the
275 transient lists already, so being modal doesn't matter) */
276 if (client_focused(client
))
277 client_unfocus(client
);
279 /* give the client its border back */
280 client_toggle_border(client
, TRUE
);
282 /* reparent the window out of the frame, and free the frame */
283 engine_frame_release_client(client
->frame
, client
);
284 client
->frame
= NULL
;
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
| Func_Fullscreen
);
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
, TRUE
, TRUE
);
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", 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 /* these override the above states! if you cant move you can't move! */
1312 if (!(self
->functions
& Func_Move
)) {
1316 if (!(self
->functions
& Func_Resize
)) {
1317 w
= self
->area
.width
;
1318 h
= self
->area
.height
;
1322 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1323 w
-= self
->base_size
.width
;
1324 h
-= self
->base_size
.height
;
1327 /* for interactive resizing. have to move half an increment in each
1330 /* how far we are towards the next size inc */
1331 int mw
= w
% self
->size_inc
.width
;
1332 int mh
= h
% self
->size_inc
.height
;
1334 int aw
= self
->size_inc
.width
/ 2;
1335 int ah
= self
->size_inc
.height
/ 2;
1336 /* don't let us move into a new size increment */
1337 if (mw
+ aw
>= self
->size_inc
.width
)
1338 aw
= self
->size_inc
.width
- mw
- 1;
1339 if (mh
+ ah
>= self
->size_inc
.height
)
1340 ah
= self
->size_inc
.height
- mh
- 1;
1344 /* if this is a user-requested resize, then check against min/max
1345 sizes and aspect ratios */
1347 /* smaller than min size or bigger than max size? */
1348 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1349 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1350 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1351 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1353 /* adjust the height ot match the width for the aspect ratios */
1354 if (self
->min_ratio
)
1355 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1356 if (self
->max_ratio
)
1357 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1360 /* keep to the increments */
1361 w
/= self
->size_inc
.width
;
1362 h
/= self
->size_inc
.height
;
1364 /* you cannot resize to nothing */
1368 /* store the logical size */
1369 SIZE_SET(self
->logical_size
, w
, h
);
1371 w
*= self
->size_inc
.width
;
1372 h
*= self
->size_inc
.height
;
1374 w
+= self
->base_size
.width
;
1375 h
+= self
->base_size
.height
;
1379 case Corner_TopLeft
:
1381 case Corner_TopRight
:
1382 x
-= w
- self
->area
.width
;
1384 case Corner_BottomLeft
:
1385 y
-= h
- self
->area
.height
;
1387 case Corner_BottomRight
:
1388 x
-= w
- self
->area
.width
;
1389 y
-= h
- self
->area
.height
;
1393 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1394 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1396 RECT_SET(self
->area
, x
, y
, w
, h
);
1399 XResizeWindow(ob_display
, self
->window
, w
, h
);
1401 /* move/resize the frame to match the request */
1403 if (moved
|| resized
)
1404 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1406 if (!user
|| final
) {
1408 event
.type
= ConfigureNotify
;
1409 event
.xconfigure
.display
= ob_display
;
1410 event
.xconfigure
.event
= self
->window
;
1411 event
.xconfigure
.window
= self
->window
;
1413 /* root window coords with border in mind */
1414 event
.xconfigure
.x
= x
- self
->border_width
+
1415 self
->frame
->size
.left
;
1416 event
.xconfigure
.y
= y
- self
->border_width
+
1417 self
->frame
->size
.top
;
1419 event
.xconfigure
.width
= self
->area
.width
;
1420 event
.xconfigure
.height
= self
->area
.height
;
1421 event
.xconfigure
.border_width
= self
->border_width
;
1422 event
.xconfigure
.above
= self
->frame
->plate
;
1423 event
.xconfigure
.override_redirect
= FALSE
;
1424 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1425 FALSE
, StructureNotifyMask
, &event
);
1430 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1434 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1435 self
->fullscreen
== fs
) return; /* already done */
1437 self
->fullscreen
= fs
;
1438 client_change_state(self
); /* change the state hints on the client */
1441 /* save the functions and remove them */
1442 self
->pre_fs_func
= self
->functions
;
1443 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1445 /* save the decorations and remove them */
1446 self
->pre_fs_decor
= self
->decorations
;
1447 self
->decorations
= 0;
1450 dimensions
[0] = self
->area
.x
;
1451 dimensions
[1] = self
->area
.y
;
1452 dimensions
[2] = self
->area
.width
;
1453 dimensions
[3] = self
->area
.height
;
1455 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1459 /* these are not actually used cuz client_configure will set them
1460 as appropriate when the window is fullscreened */
1465 self
->functions
= self
->pre_fs_func
;
1466 self
->decorations
= self
->pre_fs_decor
;
1468 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1476 /* pick some fallbacks... */
1477 x
= screen_area(self
->desktop
)->x
+
1478 screen_area(self
->desktop
)->width
/ 4;
1479 y
= screen_area(self
->desktop
)->y
+
1480 screen_area(self
->desktop
)->height
/ 4;
1481 w
= screen_area(self
->desktop
)->width
/ 2;
1482 h
= screen_area(self
->desktop
)->height
/ 2;
1486 client_change_allowed_actions(self
); /* based on the new _functions */
1488 /* when fullscreening, don't obey things like increments, fill the
1490 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1492 /* raise (back) into our stacking layer */
1493 stacking_raise(self
);
1495 /* try focus us when we go into fullscreen mode */
1499 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1501 if (self
->iconic
== iconic
) return; /* nothing to do */
1503 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1506 self
->iconic
= iconic
;
1509 self
->wmstate
= IconicState
;
1510 self
->ignore_unmaps
++;
1511 /* we unmap the client itself so that we can get MapRequest events,
1512 and because the ICCCM tells us to! */
1513 XUnmapWindow(ob_display
, self
->window
);
1516 client_set_desktop(self
, screen_desktop
);
1517 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1518 XMapWindow(ob_display
, self
->window
);
1520 client_change_state(self
);
1521 client_showhide(self
);
1522 screen_update_struts();
1524 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1528 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1532 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1533 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1535 /* check if already done */
1537 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1538 if (dir
== 1 && self
->max_horz
) return;
1539 if (dir
== 2 && self
->max_vert
) return;
1541 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1542 if (dir
== 1 && !self
->max_horz
) return;
1543 if (dir
== 2 && !self
->max_vert
) return;
1546 /* work with the frame's coords */
1547 x
= self
->frame
->area
.x
;
1548 y
= self
->frame
->area
.y
;
1549 w
= self
->area
.width
;
1550 h
= self
->area
.height
;
1562 /* get the property off the window and use it for the dimensions
1563 we are already maxed on */
1564 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1566 if (self
->max_horz
) {
1567 dimensions
[0] = readdim
[0];
1568 dimensions
[2] = readdim
[2];
1570 if (self
->max_vert
) {
1571 dimensions
[1] = readdim
[1];
1572 dimensions
[3] = readdim
[3];
1577 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1581 /* pass the client's current position info. the client_configure
1582 will move/size stuff as appropriate for a maximized window */
1585 w
= self
->area
.width
;
1586 h
= self
->area
.height
;
1590 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1592 if (dir
== 0 || dir
== 1) { /* horz */
1596 if (dir
== 0 || dir
== 2) { /* vert */
1602 /* pick some fallbacks... */
1603 if (dir
== 0 || dir
== 1) { /* horz */
1604 x
= screen_area(self
->desktop
)->x
+
1605 screen_area(self
->desktop
)->width
/ 4;
1606 w
= screen_area(self
->desktop
)->width
/ 2;
1608 if (dir
== 0 || dir
== 2) { /* vert */
1609 y
= screen_area(self
->desktop
)->y
+
1610 screen_area(self
->desktop
)->height
/ 4;
1611 h
= screen_area(self
->desktop
)->height
/ 2;
1616 if (dir
== 0 || dir
== 1) /* horz */
1617 self
->max_horz
= max
;
1618 if (dir
== 0 || dir
== 2) /* vert */
1619 self
->max_vert
= max
;
1621 if (!self
->max_horz
&& !self
->max_vert
)
1622 PROP_ERASE(self
->window
, openbox_premax
);
1624 client_change_state(self
); /* change the state hints on the client */
1626 /* figure out where the client should be going */
1627 frame_frame_gravity(self
->frame
, &x
, &y
);
1628 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1631 void client_shade(Client
*self
, gboolean shade
)
1633 if (!(self
->functions
& Func_Shade
) || /* can't */
1634 self
->shaded
== shade
) return; /* already done */
1636 /* when we're iconic, don't change the wmstate */
1638 self
->wmstate
= shade
? IconicState
: NormalState
;
1639 self
->shaded
= shade
;
1640 client_change_state(self
);
1641 /* resize the frame to just the titlebar */
1642 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1645 void client_close(Client
*self
)
1649 if (!(self
->functions
& Func_Close
)) return;
1652 XXX: itd be cool to do timeouts and shit here for killing the client's
1654 like... if the window is around after 5 seconds, then the close button
1655 turns a nice red, and if this function is called again, the client is
1659 ce
.xclient
.type
= ClientMessage
;
1660 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1661 ce
.xclient
.display
= ob_display
;
1662 ce
.xclient
.window
= self
->window
;
1663 ce
.xclient
.format
= 32;
1664 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1665 ce
.xclient
.data
.l
[1] = event_lasttime
;
1666 ce
.xclient
.data
.l
[2] = 0l;
1667 ce
.xclient
.data
.l
[3] = 0l;
1668 ce
.xclient
.data
.l
[4] = 0l;
1669 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1672 void client_kill(Client
*self
)
1674 XKillClient(ob_display
, self
->window
);
1677 void client_set_desktop(Client
*self
, guint target
)
1681 if (target
== self
->desktop
) return;
1683 g_message("Setting desktop %u\n", target
);
1685 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1687 old
= self
->desktop
;
1688 self
->desktop
= target
;
1689 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1690 /* the frame can display the current desktop state */
1691 engine_frame_adjust_state(self
->frame
);
1692 /* 'move' the window to the new desktop */
1693 client_showhide(self
);
1694 screen_update_struts();
1696 /* update the focus lists */
1697 if (old
== DESKTOP_ALL
) {
1698 for (i
= 0; i
< screen_num_desktops
; ++i
)
1699 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1700 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1702 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1703 if (target
== DESKTOP_ALL
)
1704 for (i
= 0; i
< screen_num_desktops
; ++i
)
1705 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1708 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1711 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1716 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1717 Client
*c
= it
->data
;
1718 if (c
== skip
) continue; /* circular? */
1719 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1720 if (c
->modal
) return c
;
1725 Client
*client_find_modal_child(Client
*self
)
1727 return search_modal_tree(self
, self
);
1730 gboolean
client_validate(Client
*self
)
1734 XSync(ob_display
, FALSE
); /* get all events on the server */
1736 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1737 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1738 XPutBackEvent(ob_display
, &e
);
1745 void client_set_wm_state(Client
*self
, long state
)
1747 if (state
== self
->wmstate
) return; /* no change */
1751 client_iconify(self
, TRUE
, TRUE
);
1754 client_iconify(self
, FALSE
, TRUE
);
1759 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1761 gboolean shaded
= self
->shaded
;
1762 gboolean fullscreen
= self
->fullscreen
;
1763 gboolean max_horz
= self
->max_horz
;
1764 gboolean max_vert
= self
->max_vert
;
1767 if (!(action
== prop_atoms
.net_wm_state_add
||
1768 action
== prop_atoms
.net_wm_state_remove
||
1769 action
== prop_atoms
.net_wm_state_toggle
))
1770 /* an invalid action was passed to the client message, ignore it */
1773 for (i
= 0; i
< 2; ++i
) {
1774 Atom state
= i
== 0 ? data1
: data2
;
1776 if (!state
) continue;
1778 /* if toggling, then pick whether we're adding or removing */
1779 if (action
== prop_atoms
.net_wm_state_toggle
) {
1780 if (state
== prop_atoms
.net_wm_state_modal
)
1781 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1782 prop_atoms
.net_wm_state_add
;
1783 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1784 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1785 prop_atoms
.net_wm_state_add
;
1786 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1787 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1788 prop_atoms
.net_wm_state_add
;
1789 else if (state
== prop_atoms
.net_wm_state_shaded
)
1790 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1791 prop_atoms
.net_wm_state_add
;
1792 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1793 action
= self
->skip_taskbar
?
1794 prop_atoms
.net_wm_state_remove
:
1795 prop_atoms
.net_wm_state_add
;
1796 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1797 action
= self
->skip_pager
?
1798 prop_atoms
.net_wm_state_remove
:
1799 prop_atoms
.net_wm_state_add
;
1800 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1801 action
= self
->fullscreen
?
1802 prop_atoms
.net_wm_state_remove
:
1803 prop_atoms
.net_wm_state_add
;
1804 else if (state
== prop_atoms
.net_wm_state_above
)
1805 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1806 prop_atoms
.net_wm_state_add
;
1807 else if (state
== prop_atoms
.net_wm_state_below
)
1808 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1809 prop_atoms
.net_wm_state_add
;
1812 if (action
== prop_atoms
.net_wm_state_add
) {
1813 if (state
== prop_atoms
.net_wm_state_modal
) {
1814 /* XXX raise here or something? */
1816 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1818 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1820 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1822 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1823 self
->skip_taskbar
= TRUE
;
1824 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1825 self
->skip_pager
= TRUE
;
1826 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1828 } else if (state
== prop_atoms
.net_wm_state_above
) {
1830 } else if (state
== prop_atoms
.net_wm_state_below
) {
1834 } else { /* action == prop_atoms.net_wm_state_remove */
1835 if (state
== prop_atoms
.net_wm_state_modal
) {
1836 self
->modal
= FALSE
;
1837 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1839 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1841 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1843 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1844 self
->skip_taskbar
= FALSE
;
1845 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1846 self
->skip_pager
= FALSE
;
1847 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1849 } else if (state
== prop_atoms
.net_wm_state_above
) {
1850 self
->above
= FALSE
;
1851 } else if (state
== prop_atoms
.net_wm_state_below
) {
1852 self
->below
= FALSE
;
1856 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1857 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1859 if (max_horz
== max_vert
) { /* both going the same way */
1860 client_maximize(self
, max_horz
, 0, TRUE
);
1862 client_maximize(self
, max_horz
, 1, TRUE
);
1863 client_maximize(self
, max_vert
, 2, TRUE
);
1867 if (max_horz
!= self
->max_horz
)
1868 client_maximize(self
, max_horz
, 1, TRUE
);
1870 client_maximize(self
, max_vert
, 2, TRUE
);
1873 /* change fullscreen state before shading, as it will affect if the window
1875 if (fullscreen
!= self
->fullscreen
)
1876 client_fullscreen(self
, fullscreen
, TRUE
);
1877 if (shaded
!= self
->shaded
)
1878 client_shade(self
, shaded
);
1879 client_calc_layer(self
);
1880 client_change_state(self
); /* change the hint to relect these changes */
1883 gboolean
client_focus(Client
*self
)
1888 /* if we have a modal child, then focus it, not us */
1889 child
= client_find_modal_child(self
);
1891 return client_focus(child
);
1893 /* won't try focus if the client doesn't want it, or if the window isn't
1894 visible on the screen */
1895 if (!(self
->frame
->visible
&&
1896 (self
->can_focus
|| self
->focus_notify
)))
1899 /* do a check to see if the window has already been unmapped or destroyed
1900 do this intelligently while watching out for unmaps we've generated
1901 (ignore_unmaps > 0) */
1902 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1903 DestroyNotify
, &ev
)) {
1904 XPutBackEvent(ob_display
, &ev
);
1907 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1908 UnmapNotify
, &ev
)) {
1909 if (self
->ignore_unmaps
) {
1910 self
->ignore_unmaps
--;
1912 XPutBackEvent(ob_display
, &ev
);
1917 if (self
->can_focus
)
1918 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
1921 if (self
->focus_notify
) {
1923 ce
.xclient
.type
= ClientMessage
;
1924 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1925 ce
.xclient
.display
= ob_display
;
1926 ce
.xclient
.window
= self
->window
;
1927 ce
.xclient
.format
= 32;
1928 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1929 ce
.xclient
.data
.l
[1] = CurrentTime
;
1930 ce
.xclient
.data
.l
[2] = 0l;
1931 ce
.xclient
.data
.l
[3] = 0l;
1932 ce
.xclient
.data
.l
[4] = 0l;
1933 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1936 /* XSync(ob_display, FALSE); XXX Why sync? */
1940 void client_unfocus(Client
*self
)
1942 g_assert(focus_client
== self
);
1943 client_set_focused(self
, FALSE
);
1946 gboolean
client_focused(Client
*self
)
1948 return self
== focus_client
;
1951 void client_set_focused(Client
*self
, gboolean focused
)
1954 if (focus_client
!= self
)
1955 focus_set_client(self
);
1957 if (focus_client
== self
)
1958 focus_set_client(NULL
);
1961 /* focus state can affect the stacking layer */
1962 client_calc_layer(self
);
1964 engine_frame_adjust_focus(self
->frame
);