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 Window
*client_startup_stack_order
= NULL
;
27 static gulong client_startup_stack_size
= 0;
29 static void client_get_all(Client
*self
);
30 static void client_toggle_border(Client
*self
, gboolean show
);
31 static void client_get_area(Client
*self
);
32 static void client_get_desktop(Client
*self
);
33 static void client_get_state(Client
*self
);
34 static void client_get_shaped(Client
*self
);
35 static void client_get_mwm_hints(Client
*self
);
36 static void client_get_gravity(Client
*self
);
37 static void client_showhide(Client
*self
);
38 static void client_change_allowed_actions(Client
*self
);
39 static void client_change_state(Client
*self
);
40 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
41 static void client_apply_startup_state(Client
*self
);
42 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
44 static guint
map_hash(Window
*w
) { return *w
; }
45 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
49 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
50 (GEqualFunc
)map_key_comp
);
52 /* save the stacking order on startup! */
53 if (!PROP_GET32U(ob_root
, net_client_list_stacking
, window
,
54 client_startup_stack_order
, client_startup_stack_size
))
56 g_message("%ld", client_startup_stack_size
);
61 void client_shutdown()
63 g_hash_table_destroy(client_map
);
66 void client_set_list()
68 Window
*windows
, *win_it
;
70 guint size
= g_slist_length(client_list
);
72 /* create an array of the window ids */
74 windows
= g_new(Window
, size
);
76 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
77 *win_it
= ((Client
*)it
->data
)->window
;
81 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
89 void client_manage_all()
91 unsigned int i
, j
, nchild
;
94 XWindowAttributes attrib
;
96 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
98 /* remove all icon windows from the list */
99 for (i
= 0; i
< nchild
; i
++) {
100 if (children
[i
] == None
) continue;
101 wmhints
= XGetWMHints(ob_display
, children
[i
]);
103 if ((wmhints
->flags
& IconWindowHint
) &&
104 (wmhints
->icon_window
!= children
[i
]))
105 for (j
= 0; j
< nchild
; j
++)
106 if (children
[j
] == wmhints
->icon_window
) {
114 for (i
= 0; i
< nchild
; ++i
) {
115 if (children
[i
] == None
)
117 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
118 if (attrib
.override_redirect
) continue;
120 if (attrib
.map_state
!= IsUnmapped
)
121 client_manage(children
[i
]);
126 /* stack them as they were on startup! */
127 for (i
= client_startup_stack_size
; i
> 0; --i
) {
130 w
= client_startup_stack_order
[i
-1];
131 c
= g_hash_table_lookup(client_map
, &w
);
132 if (c
) stacking_lower(c
);
136 void client_manage(Window window
)
140 XWindowAttributes attrib
;
141 XSetWindowAttributes attrib_set
;
142 /* XWMHints *wmhint; */
147 /* check if it has already been unmapped by the time we started mapping
148 the grab does a sync so we don't have to here */
149 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
150 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
151 XPutBackEvent(ob_display
, &e
);
154 return; /* don't manage it */
157 /* make sure it isn't an override-redirect window */
158 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
159 attrib
.override_redirect
) {
161 return; /* don't manage it */
164 /* /\* is the window a docking app *\/
165 if ((wmhint = XGetWMHints(ob_display, window))) {
166 if ((wmhint->flags & StateHint) &&
167 wmhint->initial_state == WithdrawnState) {
168 /\* XXX: make dock apps work! *\/
177 /* choose the events we want to receive on the CLIENT window */
178 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
179 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
180 XChangeWindowAttributes(ob_display
, window
,
181 CWEventMask
|CWDontPropagate
, &attrib_set
);
184 /* create the Client struct, and populate it from the hints on the
186 client
= g_new(Client
, 1);
187 client
->window
= window
;
188 client_get_all(client
);
190 /* remove the client's border (and adjust re gravity) */
191 client_toggle_border(client
, FALSE
);
193 /* specify that if we exit, the window should not be destroyed and should
194 be reparented back to root automatically */
195 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
197 /* create the decoration frame for the client window */
198 client
->frame
= engine_frame_new();
200 engine_frame_grab_client(client
->frame
, client
);
202 client_apply_startup_state(client
);
206 client_list
= g_slist_append(client_list
, client
);
207 stacking_list
= g_list_append(stacking_list
, client
);
208 g_assert(!g_hash_table_lookup(client_map
, &client
->window
));
209 g_hash_table_insert(client_map
, &client
->window
, client
);
211 /* update the focus lists */
212 if (client
->desktop
== DESKTOP_ALL
) {
213 for (i
= 0; i
< screen_num_desktops
; ++i
)
214 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
217 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
220 stacking_raise(client
);
222 screen_update_struts();
224 dispatch_client(Event_Client_New
, client
, 0, 0);
226 client_showhide(client
);
228 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
230 /* update the list hints */
233 g_message("Managed window 0x%lx", window
);
236 void client_unmanage_all()
238 while (client_list
!= NULL
)
239 client_unmanage(client_list
->data
);
242 void client_unmanage(Client
*client
)
248 g_message("Unmanaging window: %lx", client
->window
);
250 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
251 g_assert(client
!= NULL
);
253 /* remove the window from our save set */
254 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
256 /* we dont want events no more */
257 XSelectInput(ob_display
, client
->window
, NoEventMask
);
259 engine_frame_hide(client
->frame
);
261 client_list
= g_slist_remove(client_list
, client
);
262 stacking_list
= g_list_remove(stacking_list
, client
);
263 g_hash_table_remove(client_map
, &client
->window
);
265 /* update the focus lists */
266 if (client
->desktop
== DESKTOP_ALL
) {
267 for (i
= 0; i
< screen_num_desktops
; ++i
)
268 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
271 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
274 /* once the client is out of the list, update the struts to remove it's
276 screen_update_struts();
278 /* tell our parent that we're gone */
279 if (client
->transient_for
!= NULL
)
280 client
->transient_for
->transients
=
281 g_slist_remove(client
->transient_for
->transients
, client
);
283 /* tell our transients that we're gone */
284 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
285 ((Client
*)it
->data
)->transient_for
= NULL
;
286 client_calc_layer(it
->data
);
289 /* dispatch the unmapped event */
290 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
291 g_assert(client
!= NULL
);
293 /* unfocus the client (dispatchs the focus event) (we're out of the
294 transient lists already, so being modal doesn't matter) */
295 if (client_focused(client
))
296 client_unfocus(client
);
298 /* give the client its border back */
299 client_toggle_border(client
, TRUE
);
301 /* reparent the window out of the frame, and free the frame */
302 engine_frame_release_client(client
->frame
, client
);
303 client
->frame
= NULL
;
305 if (ob_state
!= State_Exiting
) {
306 /* these values should not be persisted across a window
308 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
309 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
311 /* if we're left in an iconic state, the client wont be mapped. this is
312 bad, since we will no longer be managing the window on restart */
314 XMapWindow(ob_display
, client
->window
);
317 /* free all data allocated in the client struct */
318 g_slist_free(client
->transients
);
319 for (j
= 0; j
< client
->nicons
; ++j
)
320 g_free(client
->icons
[j
].data
);
321 if (client
->nicons
> 0)
322 g_free(client
->icons
);
323 g_free(client
->title
);
324 g_free(client
->icon_title
);
325 g_free(client
->name
);
326 g_free(client
->class);
327 g_free(client
->role
);
330 /* update the list hints */
334 static void client_toggle_border(Client
*self
, gboolean show
)
336 /* adjust our idea of where the client is, based on its border. When the
337 border is removed, the client should now be considered to be in a
339 when re-adding the border to the client, the same operation needs to be
341 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
342 int x
= oldx
, y
= oldy
;
343 switch(self
->gravity
) {
345 case NorthWestGravity
:
347 case SouthWestGravity
:
349 case NorthEastGravity
:
351 case SouthEastGravity
:
352 if (show
) x
-= self
->border_width
* 2;
353 else x
+= self
->border_width
* 2;
360 if (show
) x
-= self
->border_width
;
361 else x
+= self
->border_width
;
364 switch(self
->gravity
) {
366 case NorthWestGravity
:
368 case NorthEastGravity
:
370 case SouthWestGravity
:
372 case SouthEastGravity
:
373 if (show
) y
-= self
->border_width
* 2;
374 else y
+= self
->border_width
* 2;
381 if (show
) y
-= self
->border_width
;
382 else y
+= self
->border_width
;
389 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
391 /* move the client so it is back it the right spot _with_ its
393 if (x
!= oldx
|| y
!= oldy
)
394 XMoveWindow(ob_display
, self
->window
, x
, y
);
396 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
400 static void client_get_all(Client
*self
)
402 /* update EVERYTHING!! */
404 self
->ignore_unmaps
= 0;
408 self
->title
= self
->icon_title
= NULL
;
409 self
->name
= self
->class = self
->role
= NULL
;
410 self
->wmstate
= NormalState
;
411 self
->transient
= FALSE
;
412 self
->transients
= NULL
;
413 self
->transient_for
= NULL
;
415 self
->urgent
= FALSE
;
416 self
->positioned
= FALSE
;
417 self
->disabled_decorations
= 0;
421 client_get_area(self
);
422 client_get_desktop(self
);
423 client_get_state(self
);
424 client_get_shaped(self
);
426 client_update_transient_for(self
);
427 client_get_mwm_hints(self
);
428 client_get_type(self
);/* this can change the mwmhints for special cases */
430 client_update_protocols(self
);
432 client_get_gravity(self
); /* get the attribute gravity */
433 client_update_normal_hints(self
); /* this may override the attribute
436 /* got the type, the mwmhints, the protocols, and the normal hints
437 (min/max sizes), so we're ready to set up the decorations/functions */
438 client_setup_decor_and_functions(self
);
440 client_update_wmhints(self
);
441 client_update_title(self
);
442 client_update_icon_title(self
);
443 client_update_class(self
);
444 client_update_strut(self
);
445 client_update_icons(self
);
446 client_update_kwm_icon(self
);
448 /* this makes sure that these windows appear on all desktops */
449 if (self
->type
== Type_Desktop
)
450 self
->desktop
= DESKTOP_ALL
;
452 /* set the desktop hint, to make sure that it always exists, and to
453 reflect any changes we've made here */
454 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
456 client_change_state(self
);
459 static void client_get_area(Client
*self
)
461 XWindowAttributes wattrib
;
464 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
465 g_assert(ret
!= BadWindow
);
467 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
468 self
->border_width
= wattrib
.border_width
;
471 static void client_get_desktop(Client
*self
)
475 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
476 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
477 d
= screen_num_desktops
- 1;
480 /* defaults to the current desktop */
481 self
->desktop
= screen_desktop
;
485 static void client_get_state(Client
*self
)
490 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
491 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
492 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
494 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
496 for (i
= 0; i
< num
; ++i
) {
497 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
499 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
501 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
503 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
504 self
->skip_taskbar
= TRUE
;
505 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
506 self
->skip_pager
= TRUE
;
507 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
508 self
->fullscreen
= TRUE
;
509 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
510 self
->max_vert
= TRUE
;
511 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
512 self
->max_horz
= TRUE
;
513 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
515 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
523 static void client_get_shaped(Client
*self
)
525 self
->shaped
= FALSE
;
527 if (extensions_shape
) {
532 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
534 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
535 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
537 self
->shaped
= (s
!= 0);
542 void client_update_transient_for(Client
*self
)
547 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
548 t
!= self
->window
) { /* cant be transient to itself! */
549 self
->transient
= TRUE
;
550 c
= g_hash_table_lookup(client_map
, &t
);
551 g_assert(c
!= self
);/* if this happens then we need to check for it*/
553 if (!c
/*XXX: && _group*/) {
554 /* not transient to a client, see if it is transient for a
556 if (/*t == _group->leader() || */
559 /* window is a transient for its group! */
560 /* XXX: for now this is treated as non-transient.
561 this needs to be fixed! */
565 self
->transient
= FALSE
;
567 /* if anything has changed... */
568 if (c
!= self
->transient_for
) {
569 if (self
->transient_for
)
570 /* remove from old parent */
571 self
->transient_for
->transients
=
572 g_slist_remove(self
->transient_for
->transients
, self
);
573 self
->transient_for
= c
;
574 if (self
->transient_for
)
575 /* add to new parent */
576 self
->transient_for
->transients
=
577 g_slist_append(self
->transient_for
->transients
, self
);
581 static void client_get_mwm_hints(Client
*self
)
584 unsigned long *hints
;
586 self
->mwmhints
.flags
= 0; /* default to none */
588 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
589 if (num
>= MWM_ELEMENTS
) {
590 self
->mwmhints
.flags
= hints
[0];
591 self
->mwmhints
.functions
= hints
[1];
592 self
->mwmhints
.decorations
= hints
[2];
598 void client_get_type(Client
*self
)
604 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
605 /* use the first value that we know about in the array */
606 for (i
= 0; i
< num
; ++i
) {
607 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
608 self
->type
= Type_Desktop
;
609 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
610 self
->type
= Type_Dock
;
611 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
612 self
->type
= Type_Toolbar
;
613 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
614 self
->type
= Type_Menu
;
615 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
616 self
->type
= Type_Utility
;
617 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
618 self
->type
= Type_Splash
;
619 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
620 self
->type
= Type_Dialog
;
621 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
622 self
->type
= Type_Normal
;
623 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
624 /* prevent this window from getting any decor or
626 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
627 MwmFlag_Decorations
);
628 self
->mwmhints
.decorations
= 0;
629 self
->mwmhints
.functions
= 0;
631 if (self
->type
!= (WindowType
) -1)
632 break; /* grab the first legit type */
637 if (self
->type
== (WindowType
) -1) {
638 /*the window type hint was not set, which means we either classify
639 ourself as a normal window or a dialog, depending on if we are a
642 self
->type
= Type_Dialog
;
644 self
->type
= Type_Normal
;
648 void client_update_protocols(Client
*self
)
651 gulong num_return
, i
;
653 self
->focus_notify
= FALSE
;
654 self
->delete_window
= FALSE
;
656 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
657 for (i
= 0; i
< num_return
; ++i
) {
658 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
659 /* this means we can request the window to close */
660 self
->delete_window
= TRUE
;
661 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
662 /* if this protocol is requested, then the window will be
663 notified whenever we want it to receive focus */
664 self
->focus_notify
= TRUE
;
670 static void client_get_gravity(Client
*self
)
672 XWindowAttributes wattrib
;
675 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
676 g_assert(ret
!= BadWindow
);
677 self
->gravity
= wattrib
.win_gravity
;
680 void client_update_normal_hints(Client
*self
)
684 int oldgravity
= self
->gravity
;
687 self
->min_ratio
= 0.0f
;
688 self
->max_ratio
= 0.0f
;
689 SIZE_SET(self
->size_inc
, 1, 1);
690 SIZE_SET(self
->base_size
, 0, 0);
691 SIZE_SET(self
->min_size
, 0, 0);
692 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
694 /* get the hints from the window */
695 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
696 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
698 if (size
.flags
& PWinGravity
) {
699 self
->gravity
= size
.win_gravity
;
701 /* if the client has a frame, i.e. has already been mapped and
702 is changing its gravity */
703 if (self
->frame
&& self
->gravity
!= oldgravity
) {
704 /* move our idea of the client's position based on its new
706 self
->area
.x
= self
->frame
->area
.x
;
707 self
->area
.y
= self
->frame
->area
.y
;
708 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
712 if (size
.flags
& PAspect
) {
713 if (size
.min_aspect
.y
)
714 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
715 if (size
.max_aspect
.y
)
716 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
719 if (size
.flags
& PMinSize
)
720 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
722 if (size
.flags
& PMaxSize
)
723 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
725 if (size
.flags
& PBaseSize
)
726 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
728 if (size
.flags
& PResizeInc
)
729 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
733 void client_setup_decor_and_functions(Client
*self
)
735 /* start with everything (cept fullscreen) */
736 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
737 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
738 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
740 if (self
->delete_window
) {
741 self
->decorations
|= Decor_Close
;
742 self
->functions
|= Func_Close
;
745 if (!(self
->min_size
.width
< self
->max_size
.width
||
746 self
->min_size
.height
< self
->max_size
.height
)) {
747 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
748 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
751 switch (self
->type
) {
753 /* normal windows retain all of the possible decorations and
754 functionality, and are the only windows that you can fullscreen */
755 self
->functions
|= Func_Fullscreen
;
759 /* dialogs cannot be maximized */
760 self
->decorations
&= ~Decor_Maximize
;
761 self
->functions
&= ~Func_Maximize
;
767 /* these windows get less functionality */
768 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
769 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
775 /* none of these windows are manipulated by the window manager */
776 self
->decorations
= 0;
781 /* Mwm Hints are applied subtractively to what has already been chosen for
782 decor and functionality */
783 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
784 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
785 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
786 self
->decorations
&= ~Decor_Border
;
787 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
788 self
->decorations
&= ~Decor_Handle
;
789 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
790 self
->decorations
&= ~Decor_Titlebar
;
791 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
792 self
->decorations
&= ~Decor_Iconify
;
793 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
794 self
->decorations
&= ~Decor_Maximize
;
798 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
799 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
800 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
801 self
->functions
&= ~Func_Resize
;
802 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
803 self
->functions
&= ~Func_Move
;
804 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
805 self
->functions
&= ~Func_Iconify
;
806 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
807 self
->functions
&= ~Func_Maximize
;
808 /* dont let mwm hints kill the close button
809 if (! (self->mwmhints.functions & MwmFunc_Close))
810 self->functions &= ~Func_Close; */
814 /* can't maximize without moving/resizing */
815 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
816 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
818 /* finally, user specified disabled decorations are applied to subtract
820 if (self
->disabled_decorations
& Decor_Titlebar
)
821 self
->decorations
&= ~Decor_Titlebar
;
822 if (self
->disabled_decorations
& Decor_Handle
)
823 self
->decorations
&= ~Decor_Handle
;
824 if (self
->disabled_decorations
& Decor_Border
)
825 self
->decorations
&= ~Decor_Border
;
826 if (self
->disabled_decorations
& Decor_Iconify
)
827 self
->decorations
&= ~Decor_Iconify
;
828 if (self
->disabled_decorations
& Decor_Maximize
)
829 self
->decorations
&= ~Decor_Maximize
;
830 if (self
->disabled_decorations
& Decor_AllDesktops
)
831 self
->decorations
&= ~Decor_AllDesktops
;
832 if (self
->disabled_decorations
& Decor_Close
)
833 self
->decorations
&= ~Decor_Close
;
835 /* if we don't have a titlebar, then we cannot shade! */
836 if (!(self
->decorations
& Decor_Titlebar
))
837 self
->functions
&= ~Func_Shade
;
839 client_change_allowed_actions(self
);
842 /* change the decors on the frame, and with more/less decorations,
843 we may also need to be repositioned */
844 engine_frame_adjust_area(self
->frame
, TRUE
, TRUE
);
845 /* with new decor, the window's maximized size may change */
846 client_remaximize(self
);
850 static void client_change_allowed_actions(Client
*self
)
855 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
857 if (self
->functions
& Func_Shade
)
858 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
859 if (self
->functions
& Func_Close
)
860 actions
[num
++] = prop_atoms
.net_wm_action_close
;
861 if (self
->functions
& Func_Move
)
862 actions
[num
++] = prop_atoms
.net_wm_action_move
;
863 if (self
->functions
& Func_Iconify
)
864 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
865 if (self
->functions
& Func_Resize
)
866 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
867 if (self
->functions
& Func_Fullscreen
)
868 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
869 if (self
->functions
& Func_Maximize
) {
870 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
871 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
874 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
876 /* make sure the window isn't breaking any rules now */
878 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
879 if (self
->frame
) client_shade(self
, FALSE
);
880 else self
->shaded
= FALSE
;
882 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
883 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
884 else self
->iconic
= FALSE
;
886 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
887 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
888 else self
->fullscreen
= FALSE
;
890 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
892 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
893 else self
->max_vert
= self
->max_horz
= FALSE
;
897 void client_remaximize(Client
*self
)
900 if (self
->max_horz
&& self
->max_vert
)
902 else if (self
->max_horz
)
904 else if (self
->max_vert
)
907 return; /* not maximized */
908 self
->max_horz
= self
->max_vert
= FALSE
;
909 client_maximize(self
, TRUE
, dir
, FALSE
);
912 void client_update_wmhints(Client
*self
)
917 /* assume a window takes input if it doesnt specify */
918 self
->can_focus
= TRUE
;
920 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
921 if (hints
->flags
& InputHint
)
922 self
->can_focus
= hints
->input
;
924 /* only do this when starting! */
925 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
926 self
->iconic
= hints
->initial_state
== IconicState
;
928 if (hints
->flags
& XUrgencyHint
)
931 if (hints
->flags
& WindowGroupHint
) {
932 if (hints
->window_group
!= self
->group
) {
933 /* XXX: remove from the old group if there was one */
934 self
->group
= hints
->window_group
;
935 /* XXX: do stuff with the group */
937 } else /* no group! */
940 if (hints
->flags
& IconPixmapHint
) {
941 client_update_kwm_icon(self
);
942 /* try get the kwm icon first, this is a fallback only */
943 if (self
->pixmap_icon
== None
) {
944 self
->pixmap_icon
= hints
->icon_pixmap
;
945 if (hints
->flags
& IconMaskHint
)
946 self
->pixmap_icon_mask
= hints
->icon_mask
;
948 self
->pixmap_icon_mask
= None
;
951 engine_frame_adjust_icon(self
->frame
);
958 if (ur
!= self
->urgent
) {
960 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
962 /* fire the urgent callback if we're mapped, otherwise, wait until
963 after we're mapped */
965 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
969 void client_update_title(Client
*self
)
976 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
977 /* try old x stuff */
978 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
979 /* convert it to UTF-8 */
983 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
985 g_warning("Unable to convert string to UTF-8");
992 data
= g_strdup("Unnamed Window");
994 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1000 engine_frame_adjust_title(self
->frame
);
1003 void client_update_icon_title(Client
*self
)
1007 g_free(self
->icon_title
);
1010 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1011 /* try old x stuff */
1012 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1013 /* convert it to UTF-8 */
1017 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1019 g_warning("Unable to convert string to UTF-8");
1026 data
= g_strdup("Unnamed Window");
1028 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1031 self
->icon_title
= data
;
1034 void client_update_class(Client
*self
)
1040 if (self
->name
) g_free(self
->name
);
1041 if (self
->class) g_free(self
->class);
1042 if (self
->role
) g_free(self
->role
);
1044 self
->name
= self
->class = self
->role
= NULL
;
1046 data
= g_ptr_array_new();
1048 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1050 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1052 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1055 for (i
= 0; i
< data
->len
; ++i
)
1056 g_free(g_ptr_array_index(data
, i
));
1057 g_ptr_array_free(data
, TRUE
);
1059 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1060 self
->role
= g_strdup(s
);
1062 if (self
->name
== NULL
) self
->name
= g_strdup("");
1063 if (self
->class == NULL
) self
->class = g_strdup("");
1064 if (self
->role
== NULL
) self
->role
= g_strdup("");
1067 void client_update_strut(Client
*self
)
1071 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1072 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1075 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1077 /* updating here is pointless while we're being mapped cuz we're not in
1078 the client list yet */
1080 screen_update_struts();
1083 void client_update_icons(Client
*self
)
1086 unsigned long *data
;
1087 unsigned long w
, h
, i
;
1090 for (j
= 0; j
< self
->nicons
; ++j
)
1091 g_free(self
->icons
[j
].data
);
1092 if (self
->nicons
> 0)
1093 g_free(self
->icons
);
1096 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1097 /* figure out how many valid icons are in here */
1099 while (num
- i
> 2) {
1107 self
->icons
= g_new(Icon
, self
->nicons
);
1109 /* store the icons */
1111 for (j
= 0; j
< self
->nicons
; ++j
) {
1112 w
= self
->icons
[j
].w
= data
[i
++];
1113 h
= self
->icons
[j
].h
= data
[i
++];
1114 self
->icons
[j
].data
=
1115 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1123 if (self
->nicons
<= 0) {
1125 self
->icons
= g_new0(Icon
, 1);
1129 engine_frame_adjust_icon(self
->frame
);
1132 void client_update_kwm_icon(Client
*self
)
1136 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1137 self
->pixmap_icon
= data
[0];
1138 self
->pixmap_icon_mask
= data
[1];
1141 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1144 engine_frame_adjust_icon(self
->frame
);
1147 static void client_change_state(Client
*self
)
1149 unsigned long state
[2];
1153 state
[0] = self
->wmstate
;
1155 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1159 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1161 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1163 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1164 if (self
->skip_taskbar
)
1165 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1166 if (self
->skip_pager
)
1167 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1168 if (self
->fullscreen
)
1169 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1171 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1173 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1175 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1177 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1178 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1180 client_calc_layer(self
);
1183 engine_frame_adjust_state(self
->frame
);
1186 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1191 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1192 Client
*c
= it
->data
;
1193 if (c
== skip
) continue; /* circular? */
1194 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1195 if (client_focused(c
)) return c
;
1200 void client_calc_layer(Client
*self
)
1206 /* are we fullscreen, or do we have a fullscreen transient parent? */
1210 if (c
->fullscreen
) {
1214 c
= c
->transient_for
;
1216 if (!fs
&& self
->fullscreen
) {
1217 /* is one of our transients focused? */
1218 c
= search_focus_tree(self
, self
);
1219 if (c
!= NULL
) fs
= TRUE
;
1222 if (self
->iconic
) l
= Layer_Icon
;
1223 else if (fs
) l
= Layer_Fullscreen
;
1224 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1225 else if (self
->type
== Type_Dock
) {
1226 if (!self
->below
) l
= Layer_Top
;
1227 else l
= Layer_Normal
;
1229 else if (self
->above
) l
= Layer_Above
;
1230 else if (self
->below
) l
= Layer_Below
;
1231 else l
= Layer_Normal
;
1233 if (l
!= self
->layer
) {
1236 stacking_raise(self
);
1240 gboolean
client_should_show(Client
*self
)
1242 if (self
->iconic
) return FALSE
;
1243 else if (!(self
->desktop
== screen_desktop
||
1244 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1245 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1250 static void client_showhide(Client
*self
)
1253 if (client_should_show(self
))
1254 engine_frame_show(self
->frame
);
1256 engine_frame_hide(self
->frame
);
1259 gboolean
client_normal(Client
*self
) {
1260 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1261 self
->type
== Type_Splash
);
1264 static void client_apply_startup_state(Client
*self
)
1266 /* these are in a carefully crafted order.. */
1269 self
->iconic
= FALSE
;
1270 client_iconify(self
, TRUE
, FALSE
);
1272 if (self
->fullscreen
) {
1273 self
->fullscreen
= FALSE
;
1274 client_fullscreen(self
, TRUE
, FALSE
);
1277 self
->shaded
= FALSE
;
1278 client_shade(self
, TRUE
);
1281 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1283 if (self
->max_vert
&& self
->max_horz
) {
1284 self
->max_vert
= self
->max_horz
= FALSE
;
1285 client_maximize(self
, TRUE
, 0, FALSE
);
1286 } else if (self
->max_vert
) {
1287 self
->max_vert
= FALSE
;
1288 client_maximize(self
, TRUE
, 2, FALSE
);
1289 } else if (self
->max_horz
) {
1290 self
->max_horz
= FALSE
;
1291 client_maximize(self
, TRUE
, 1, FALSE
);
1294 /* nothing to do for the other states:
1303 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1304 gboolean user
, gboolean final
)
1306 gboolean moved
= FALSE
, resized
= FALSE
;
1308 /* set the size and position if fullscreen */
1309 if (self
->fullscreen
) {
1312 w
= screen_physical_size
.width
;
1313 h
= screen_physical_size
.height
;
1315 /* set the size and position if maximized */
1316 if (self
->max_horz
) {
1317 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1318 w
= screen_area(self
->desktop
)->x
+
1319 screen_area(self
->desktop
)->width
;
1321 if (self
->max_vert
) {
1322 y
= screen_area(self
->desktop
)->y
;
1323 h
= screen_area(self
->desktop
)->y
+
1324 screen_area(self
->desktop
)->height
-
1325 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1329 /* these override the above states! if you cant move you can't move! */
1331 if (!(self
->functions
& Func_Move
)) {
1335 if (!(self
->functions
& Func_Resize
)) {
1336 w
= self
->area
.width
;
1337 h
= self
->area
.height
;
1341 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1342 w
-= self
->base_size
.width
;
1343 h
-= self
->base_size
.height
;
1346 /* for interactive resizing. have to move half an increment in each
1349 /* how far we are towards the next size inc */
1350 int mw
= w
% self
->size_inc
.width
;
1351 int mh
= h
% self
->size_inc
.height
;
1353 int aw
= self
->size_inc
.width
/ 2;
1354 int ah
= self
->size_inc
.height
/ 2;
1355 /* don't let us move into a new size increment */
1356 if (mw
+ aw
>= self
->size_inc
.width
)
1357 aw
= self
->size_inc
.width
- mw
- 1;
1358 if (mh
+ ah
>= self
->size_inc
.height
)
1359 ah
= self
->size_inc
.height
- mh
- 1;
1363 /* if this is a user-requested resize, then check against min/max
1364 sizes and aspect ratios */
1366 /* smaller than min size or bigger than max size? */
1367 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1368 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1369 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1370 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1372 /* adjust the height ot match the width for the aspect ratios */
1373 if (self
->min_ratio
)
1374 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1375 if (self
->max_ratio
)
1376 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1379 /* keep to the increments */
1380 w
/= self
->size_inc
.width
;
1381 h
/= self
->size_inc
.height
;
1383 /* you cannot resize to nothing */
1387 /* store the logical size */
1388 SIZE_SET(self
->logical_size
, w
, h
);
1390 w
*= self
->size_inc
.width
;
1391 h
*= self
->size_inc
.height
;
1393 w
+= self
->base_size
.width
;
1394 h
+= self
->base_size
.height
;
1398 case Corner_TopLeft
:
1400 case Corner_TopRight
:
1401 x
-= w
- self
->area
.width
;
1403 case Corner_BottomLeft
:
1404 y
-= h
- self
->area
.height
;
1406 case Corner_BottomRight
:
1407 x
-= w
- self
->area
.width
;
1408 y
-= h
- self
->area
.height
;
1412 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1413 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1415 RECT_SET(self
->area
, x
, y
, w
, h
);
1418 XResizeWindow(ob_display
, self
->window
, w
, h
);
1420 /* move/resize the frame to match the request */
1422 if (moved
|| resized
)
1423 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1425 if (!user
|| final
) {
1427 event
.type
= ConfigureNotify
;
1428 event
.xconfigure
.display
= ob_display
;
1429 event
.xconfigure
.event
= self
->window
;
1430 event
.xconfigure
.window
= self
->window
;
1432 /* root window coords with border in mind */
1433 event
.xconfigure
.x
= x
- self
->border_width
+
1434 self
->frame
->size
.left
;
1435 event
.xconfigure
.y
= y
- self
->border_width
+
1436 self
->frame
->size
.top
;
1438 event
.xconfigure
.width
= self
->area
.width
;
1439 event
.xconfigure
.height
= self
->area
.height
;
1440 event
.xconfigure
.border_width
= self
->border_width
;
1441 event
.xconfigure
.above
= self
->frame
->plate
;
1442 event
.xconfigure
.override_redirect
= FALSE
;
1443 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1444 FALSE
, StructureNotifyMask
, &event
);
1449 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1453 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1454 self
->fullscreen
== fs
) return; /* already done */
1456 self
->fullscreen
= fs
;
1457 client_change_state(self
); /* change the state hints on the client */
1460 /* save the functions and remove them */
1461 self
->pre_fs_func
= self
->functions
;
1462 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1464 /* save the decorations and remove them */
1465 self
->pre_fs_decor
= self
->decorations
;
1466 self
->decorations
= 0;
1469 dimensions
[0] = self
->area
.x
;
1470 dimensions
[1] = self
->area
.y
;
1471 dimensions
[2] = self
->area
.width
;
1472 dimensions
[3] = self
->area
.height
;
1474 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1478 /* these are not actually used cuz client_configure will set them
1479 as appropriate when the window is fullscreened */
1484 self
->functions
= self
->pre_fs_func
;
1485 self
->decorations
= self
->pre_fs_decor
;
1487 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1495 /* pick some fallbacks... */
1496 x
= screen_area(self
->desktop
)->x
+
1497 screen_area(self
->desktop
)->width
/ 4;
1498 y
= screen_area(self
->desktop
)->y
+
1499 screen_area(self
->desktop
)->height
/ 4;
1500 w
= screen_area(self
->desktop
)->width
/ 2;
1501 h
= screen_area(self
->desktop
)->height
/ 2;
1505 client_change_allowed_actions(self
); /* based on the new _functions */
1507 /* when fullscreening, don't obey things like increments, fill the
1509 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1511 /* raise (back) into our stacking layer */
1512 stacking_raise(self
);
1514 /* try focus us when we go into fullscreen mode */
1518 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1520 if (self
->iconic
== iconic
) return; /* nothing to do */
1522 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1525 self
->iconic
= iconic
;
1528 self
->wmstate
= IconicState
;
1529 self
->ignore_unmaps
++;
1530 /* we unmap the client itself so that we can get MapRequest events,
1531 and because the ICCCM tells us to! */
1532 XUnmapWindow(ob_display
, self
->window
);
1535 client_set_desktop(self
, screen_desktop
);
1536 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1537 XMapWindow(ob_display
, self
->window
);
1539 client_change_state(self
);
1540 client_showhide(self
);
1541 screen_update_struts();
1543 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1547 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1551 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1552 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1554 /* check if already done */
1556 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1557 if (dir
== 1 && self
->max_horz
) return;
1558 if (dir
== 2 && self
->max_vert
) return;
1560 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1561 if (dir
== 1 && !self
->max_horz
) return;
1562 if (dir
== 2 && !self
->max_vert
) return;
1565 /* work with the frame's coords */
1566 x
= self
->frame
->area
.x
;
1567 y
= self
->frame
->area
.y
;
1568 w
= self
->area
.width
;
1569 h
= self
->area
.height
;
1581 /* get the property off the window and use it for the dimensions
1582 we are already maxed on */
1583 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1585 if (self
->max_horz
) {
1586 dimensions
[0] = readdim
[0];
1587 dimensions
[2] = readdim
[2];
1589 if (self
->max_vert
) {
1590 dimensions
[1] = readdim
[1];
1591 dimensions
[3] = readdim
[3];
1596 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1600 /* pass the client's current position info. the client_configure
1601 will move/size stuff as appropriate for a maximized window */
1604 w
= self
->area
.width
;
1605 h
= self
->area
.height
;
1609 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1611 if (dir
== 0 || dir
== 1) { /* horz */
1615 if (dir
== 0 || dir
== 2) { /* vert */
1621 /* pick some fallbacks... */
1622 if (dir
== 0 || dir
== 1) { /* horz */
1623 x
= screen_area(self
->desktop
)->x
+
1624 screen_area(self
->desktop
)->width
/ 4;
1625 w
= screen_area(self
->desktop
)->width
/ 2;
1627 if (dir
== 0 || dir
== 2) { /* vert */
1628 y
= screen_area(self
->desktop
)->y
+
1629 screen_area(self
->desktop
)->height
/ 4;
1630 h
= screen_area(self
->desktop
)->height
/ 2;
1635 if (dir
== 0 || dir
== 1) /* horz */
1636 self
->max_horz
= max
;
1637 if (dir
== 0 || dir
== 2) /* vert */
1638 self
->max_vert
= max
;
1640 if (!self
->max_horz
&& !self
->max_vert
)
1641 PROP_ERASE(self
->window
, openbox_premax
);
1643 client_change_state(self
); /* change the state hints on the client */
1645 /* figure out where the client should be going */
1646 frame_frame_gravity(self
->frame
, &x
, &y
);
1647 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1650 void client_shade(Client
*self
, gboolean shade
)
1652 if (!(self
->functions
& Func_Shade
) || /* can't */
1653 self
->shaded
== shade
) return; /* already done */
1655 /* when we're iconic, don't change the wmstate */
1657 self
->wmstate
= shade
? IconicState
: NormalState
;
1658 self
->shaded
= shade
;
1659 client_change_state(self
);
1660 /* resize the frame to just the titlebar */
1661 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1664 void client_close(Client
*self
)
1668 if (!(self
->functions
& Func_Close
)) return;
1671 XXX: itd be cool to do timeouts and shit here for killing the client's
1673 like... if the window is around after 5 seconds, then the close button
1674 turns a nice red, and if this function is called again, the client is
1678 ce
.xclient
.type
= ClientMessage
;
1679 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1680 ce
.xclient
.display
= ob_display
;
1681 ce
.xclient
.window
= self
->window
;
1682 ce
.xclient
.format
= 32;
1683 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1684 ce
.xclient
.data
.l
[1] = event_lasttime
;
1685 ce
.xclient
.data
.l
[2] = 0l;
1686 ce
.xclient
.data
.l
[3] = 0l;
1687 ce
.xclient
.data
.l
[4] = 0l;
1688 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1691 void client_kill(Client
*self
)
1693 XKillClient(ob_display
, self
->window
);
1696 void client_set_desktop(Client
*self
, guint target
)
1700 if (target
== self
->desktop
) return;
1702 g_message("Setting desktop %u\n", target
);
1704 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1706 old
= self
->desktop
;
1707 self
->desktop
= target
;
1708 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1709 /* the frame can display the current desktop state */
1710 engine_frame_adjust_state(self
->frame
);
1711 /* 'move' the window to the new desktop */
1712 client_showhide(self
);
1713 screen_update_struts();
1715 /* update the focus lists */
1716 if (old
== DESKTOP_ALL
) {
1717 for (i
= 0; i
< screen_num_desktops
; ++i
)
1718 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1719 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1721 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1722 if (target
== DESKTOP_ALL
)
1723 for (i
= 0; i
< screen_num_desktops
; ++i
)
1724 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1727 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1730 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1735 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1736 Client
*c
= it
->data
;
1737 if (c
== skip
) continue; /* circular? */
1738 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1739 if (c
->modal
) return c
;
1744 Client
*client_find_modal_child(Client
*self
)
1746 return search_modal_tree(self
, self
);
1749 gboolean
client_validate(Client
*self
)
1753 XSync(ob_display
, FALSE
); /* get all events on the server */
1755 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1756 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1757 XPutBackEvent(ob_display
, &e
);
1764 void client_set_wm_state(Client
*self
, long state
)
1766 if (state
== self
->wmstate
) return; /* no change */
1770 client_iconify(self
, TRUE
, TRUE
);
1773 client_iconify(self
, FALSE
, TRUE
);
1778 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1780 gboolean shaded
= self
->shaded
;
1781 gboolean fullscreen
= self
->fullscreen
;
1782 gboolean max_horz
= self
->max_horz
;
1783 gboolean max_vert
= self
->max_vert
;
1786 if (!(action
== prop_atoms
.net_wm_state_add
||
1787 action
== prop_atoms
.net_wm_state_remove
||
1788 action
== prop_atoms
.net_wm_state_toggle
))
1789 /* an invalid action was passed to the client message, ignore it */
1792 for (i
= 0; i
< 2; ++i
) {
1793 Atom state
= i
== 0 ? data1
: data2
;
1795 if (!state
) continue;
1797 /* if toggling, then pick whether we're adding or removing */
1798 if (action
== prop_atoms
.net_wm_state_toggle
) {
1799 if (state
== prop_atoms
.net_wm_state_modal
)
1800 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1801 prop_atoms
.net_wm_state_add
;
1802 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1803 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1804 prop_atoms
.net_wm_state_add
;
1805 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1806 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1807 prop_atoms
.net_wm_state_add
;
1808 else if (state
== prop_atoms
.net_wm_state_shaded
)
1809 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1810 prop_atoms
.net_wm_state_add
;
1811 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1812 action
= self
->skip_taskbar
?
1813 prop_atoms
.net_wm_state_remove
:
1814 prop_atoms
.net_wm_state_add
;
1815 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1816 action
= self
->skip_pager
?
1817 prop_atoms
.net_wm_state_remove
:
1818 prop_atoms
.net_wm_state_add
;
1819 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1820 action
= self
->fullscreen
?
1821 prop_atoms
.net_wm_state_remove
:
1822 prop_atoms
.net_wm_state_add
;
1823 else if (state
== prop_atoms
.net_wm_state_above
)
1824 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1825 prop_atoms
.net_wm_state_add
;
1826 else if (state
== prop_atoms
.net_wm_state_below
)
1827 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1828 prop_atoms
.net_wm_state_add
;
1831 if (action
== prop_atoms
.net_wm_state_add
) {
1832 if (state
== prop_atoms
.net_wm_state_modal
) {
1833 /* XXX raise here or something? */
1835 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1837 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1839 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1841 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1842 self
->skip_taskbar
= TRUE
;
1843 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1844 self
->skip_pager
= TRUE
;
1845 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1847 } else if (state
== prop_atoms
.net_wm_state_above
) {
1849 } else if (state
== prop_atoms
.net_wm_state_below
) {
1853 } else { /* action == prop_atoms.net_wm_state_remove */
1854 if (state
== prop_atoms
.net_wm_state_modal
) {
1855 self
->modal
= FALSE
;
1856 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1858 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1860 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1862 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1863 self
->skip_taskbar
= FALSE
;
1864 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1865 self
->skip_pager
= FALSE
;
1866 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1868 } else if (state
== prop_atoms
.net_wm_state_above
) {
1869 self
->above
= FALSE
;
1870 } else if (state
== prop_atoms
.net_wm_state_below
) {
1871 self
->below
= FALSE
;
1875 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1876 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1878 if (max_horz
== max_vert
) { /* both going the same way */
1879 client_maximize(self
, max_horz
, 0, TRUE
);
1881 client_maximize(self
, max_horz
, 1, TRUE
);
1882 client_maximize(self
, max_vert
, 2, TRUE
);
1886 if (max_horz
!= self
->max_horz
)
1887 client_maximize(self
, max_horz
, 1, TRUE
);
1889 client_maximize(self
, max_vert
, 2, TRUE
);
1892 /* change fullscreen state before shading, as it will affect if the window
1894 if (fullscreen
!= self
->fullscreen
)
1895 client_fullscreen(self
, fullscreen
, TRUE
);
1896 if (shaded
!= self
->shaded
)
1897 client_shade(self
, shaded
);
1898 client_calc_layer(self
);
1899 client_change_state(self
); /* change the hint to relect these changes */
1902 gboolean
client_focus(Client
*self
)
1907 /* if we have a modal child, then focus it, not us */
1908 child
= client_find_modal_child(self
);
1910 return client_focus(child
);
1912 /* won't try focus if the client doesn't want it, or if the window isn't
1913 visible on the screen */
1914 if (!(self
->frame
->visible
&&
1915 (self
->can_focus
|| self
->focus_notify
)))
1918 /* do a check to see if the window has already been unmapped or destroyed
1919 do this intelligently while watching out for unmaps we've generated
1920 (ignore_unmaps > 0) */
1921 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1922 DestroyNotify
, &ev
)) {
1923 XPutBackEvent(ob_display
, &ev
);
1926 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1927 UnmapNotify
, &ev
)) {
1928 if (self
->ignore_unmaps
) {
1929 self
->ignore_unmaps
--;
1931 XPutBackEvent(ob_display
, &ev
);
1936 if (self
->can_focus
)
1937 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
1940 if (self
->focus_notify
) {
1942 ce
.xclient
.type
= ClientMessage
;
1943 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1944 ce
.xclient
.display
= ob_display
;
1945 ce
.xclient
.window
= self
->window
;
1946 ce
.xclient
.format
= 32;
1947 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1948 ce
.xclient
.data
.l
[1] = CurrentTime
;
1949 ce
.xclient
.data
.l
[2] = 0l;
1950 ce
.xclient
.data
.l
[3] = 0l;
1951 ce
.xclient
.data
.l
[4] = 0l;
1952 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1955 /* XSync(ob_display, FALSE); XXX Why sync? */
1959 void client_unfocus(Client
*self
)
1961 g_assert(focus_client
== self
);
1962 client_set_focused(self
, FALSE
);
1965 gboolean
client_focused(Client
*self
)
1967 return self
== focus_client
;
1970 void client_set_focused(Client
*self
, gboolean focused
)
1973 if (focus_client
!= self
)
1974 focus_set_client(self
);
1976 if (focus_client
== self
)
1977 focus_set_client(NULL
);
1980 /* focus state can affect the stacking layer */
1981 client_calc_layer(self
);
1983 engine_frame_adjust_focus(self
->frame
);