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 why with stacking_lower? Why, because then windows who aren't in the
128 stacking list are on the top where you can see them instead of buried
130 for (i
= client_startup_stack_size
; i
> 0; --i
) {
133 w
= client_startup_stack_order
[i
-1];
134 c
= g_hash_table_lookup(client_map
, &w
);
135 if (c
) stacking_lower(c
);
137 g_free(client_startup_stack_order
);
138 client_startup_stack_order
= NULL
;
139 client_startup_stack_size
= 0;
142 void client_manage(Window window
)
146 XWindowAttributes attrib
;
147 XSetWindowAttributes attrib_set
;
148 /* XWMHints *wmhint; */
153 /* check if it has already been unmapped by the time we started mapping
154 the grab does a sync so we don't have to here */
155 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
156 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
157 XPutBackEvent(ob_display
, &e
);
160 return; /* don't manage it */
163 /* make sure it isn't an override-redirect window */
164 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
165 attrib
.override_redirect
) {
167 return; /* don't manage it */
170 /* /\* is the window a docking app *\/
171 if ((wmhint = XGetWMHints(ob_display, window))) {
172 if ((wmhint->flags & StateHint) &&
173 wmhint->initial_state == WithdrawnState) {
174 /\* XXX: make dock apps work! *\/
183 /* choose the events we want to receive on the CLIENT window */
184 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
185 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
186 XChangeWindowAttributes(ob_display
, window
,
187 CWEventMask
|CWDontPropagate
, &attrib_set
);
190 /* create the Client struct, and populate it from the hints on the
192 client
= g_new(Client
, 1);
193 client
->window
= window
;
194 client_get_all(client
);
196 /* remove the client's border (and adjust re gravity) */
197 client_toggle_border(client
, FALSE
);
199 /* specify that if we exit, the window should not be destroyed and should
200 be reparented back to root automatically */
201 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
203 /* create the decoration frame for the client window */
204 client
->frame
= engine_frame_new();
206 engine_frame_grab_client(client
->frame
, client
);
208 client_apply_startup_state(client
);
212 client_list
= g_slist_append(client_list
, client
);
213 stacking_list
= g_list_append(stacking_list
, client
);
214 g_assert(!g_hash_table_lookup(client_map
, &client
->window
));
215 g_hash_table_insert(client_map
, &client
->window
, client
);
217 /* update the focus lists */
218 if (client
->desktop
== DESKTOP_ALL
) {
219 for (i
= 0; i
< screen_num_desktops
; ++i
)
220 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
223 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
226 stacking_raise(client
);
228 screen_update_struts();
230 dispatch_client(Event_Client_New
, client
, 0, 0);
232 client_showhide(client
);
234 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
236 /* update the list hints */
239 g_message("Managed window 0x%lx", window
);
242 void client_unmanage_all()
244 while (client_list
!= NULL
)
245 client_unmanage(client_list
->data
);
248 void client_unmanage(Client
*client
)
254 g_message("Unmanaging window: %lx", client
->window
);
256 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
257 g_assert(client
!= NULL
);
259 /* remove the window from our save set */
260 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
262 /* we dont want events no more */
263 XSelectInput(ob_display
, client
->window
, NoEventMask
);
265 engine_frame_hide(client
->frame
);
267 client_list
= g_slist_remove(client_list
, client
);
268 stacking_list
= g_list_remove(stacking_list
, client
);
269 g_hash_table_remove(client_map
, &client
->window
);
271 /* update the focus lists */
272 if (client
->desktop
== DESKTOP_ALL
) {
273 for (i
= 0; i
< screen_num_desktops
; ++i
)
274 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
277 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
280 /* once the client is out of the list, update the struts to remove it's
282 screen_update_struts();
284 /* tell our parent that we're gone */
285 if (client
->transient_for
!= NULL
)
286 client
->transient_for
->transients
=
287 g_slist_remove(client
->transient_for
->transients
, client
);
289 /* tell our transients that we're gone */
290 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
291 ((Client
*)it
->data
)->transient_for
= NULL
;
292 client_calc_layer(it
->data
);
295 /* dispatch the unmapped event */
296 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
297 g_assert(client
!= NULL
);
299 /* unfocus the client (dispatchs the focus event) (we're out of the
300 transient lists already, so being modal doesn't matter) */
301 if (client_focused(client
))
302 client_unfocus(client
);
304 /* give the client its border back */
305 client_toggle_border(client
, TRUE
);
307 /* reparent the window out of the frame, and free the frame */
308 engine_frame_release_client(client
->frame
, client
);
309 client
->frame
= NULL
;
311 if (ob_state
!= State_Exiting
) {
312 /* these values should not be persisted across a window
314 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
315 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
317 /* if we're left in an iconic state, the client wont be mapped. this is
318 bad, since we will no longer be managing the window on restart */
320 XMapWindow(ob_display
, client
->window
);
323 /* free all data allocated in the client struct */
324 g_slist_free(client
->transients
);
325 for (j
= 0; j
< client
->nicons
; ++j
)
326 g_free(client
->icons
[j
].data
);
327 if (client
->nicons
> 0)
328 g_free(client
->icons
);
329 g_free(client
->title
);
330 g_free(client
->icon_title
);
331 g_free(client
->name
);
332 g_free(client
->class);
333 g_free(client
->role
);
336 /* update the list hints */
340 static void client_toggle_border(Client
*self
, gboolean show
)
342 /* adjust our idea of where the client is, based on its border. When the
343 border is removed, the client should now be considered to be in a
345 when re-adding the border to the client, the same operation needs to be
347 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
348 int x
= oldx
, y
= oldy
;
349 switch(self
->gravity
) {
351 case NorthWestGravity
:
353 case SouthWestGravity
:
355 case NorthEastGravity
:
357 case SouthEastGravity
:
358 if (show
) x
-= self
->border_width
* 2;
359 else x
+= self
->border_width
* 2;
366 if (show
) x
-= self
->border_width
;
367 else x
+= self
->border_width
;
370 switch(self
->gravity
) {
372 case NorthWestGravity
:
374 case NorthEastGravity
:
376 case SouthWestGravity
:
378 case SouthEastGravity
:
379 if (show
) y
-= self
->border_width
* 2;
380 else y
+= self
->border_width
* 2;
387 if (show
) y
-= self
->border_width
;
388 else y
+= self
->border_width
;
395 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
397 /* move the client so it is back it the right spot _with_ its
399 if (x
!= oldx
|| y
!= oldy
)
400 XMoveWindow(ob_display
, self
->window
, x
, y
);
402 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
406 static void client_get_all(Client
*self
)
408 /* update EVERYTHING!! */
410 self
->ignore_unmaps
= 0;
414 self
->title
= self
->icon_title
= NULL
;
415 self
->name
= self
->class = self
->role
= NULL
;
416 self
->wmstate
= NormalState
;
417 self
->transient
= FALSE
;
418 self
->transients
= NULL
;
419 self
->transient_for
= NULL
;
421 self
->urgent
= FALSE
;
422 self
->positioned
= FALSE
;
423 self
->disabled_decorations
= 0;
427 client_get_area(self
);
428 client_get_desktop(self
);
429 client_get_state(self
);
430 client_get_shaped(self
);
432 client_update_transient_for(self
);
433 client_get_mwm_hints(self
);
434 client_get_type(self
);/* this can change the mwmhints for special cases */
436 client_update_protocols(self
);
438 client_get_gravity(self
); /* get the attribute gravity */
439 client_update_normal_hints(self
); /* this may override the attribute
442 /* got the type, the mwmhints, the protocols, and the normal hints
443 (min/max sizes), so we're ready to set up the decorations/functions */
444 client_setup_decor_and_functions(self
);
446 client_update_wmhints(self
);
447 client_update_title(self
);
448 client_update_icon_title(self
);
449 client_update_class(self
);
450 client_update_strut(self
);
451 client_update_icons(self
);
452 client_update_kwm_icon(self
);
454 /* this makes sure that these windows appear on all desktops */
455 if (self
->type
== Type_Desktop
)
456 self
->desktop
= DESKTOP_ALL
;
458 /* set the desktop hint, to make sure that it always exists, and to
459 reflect any changes we've made here */
460 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
462 client_change_state(self
);
465 static void client_get_area(Client
*self
)
467 XWindowAttributes wattrib
;
470 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
471 g_assert(ret
!= BadWindow
);
473 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
474 self
->border_width
= wattrib
.border_width
;
477 static void client_get_desktop(Client
*self
)
481 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
482 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
483 d
= screen_num_desktops
- 1;
486 /* defaults to the current desktop */
487 self
->desktop
= screen_desktop
;
491 static void client_get_state(Client
*self
)
496 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
497 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
498 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
500 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
502 for (i
= 0; i
< num
; ++i
) {
503 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
505 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
507 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
509 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
510 self
->skip_taskbar
= TRUE
;
511 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
512 self
->skip_pager
= TRUE
;
513 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
514 self
->fullscreen
= TRUE
;
515 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
516 self
->max_vert
= TRUE
;
517 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
518 self
->max_horz
= TRUE
;
519 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
521 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
529 static void client_get_shaped(Client
*self
)
531 self
->shaped
= FALSE
;
533 if (extensions_shape
) {
538 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
540 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
541 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
543 self
->shaped
= (s
!= 0);
548 void client_update_transient_for(Client
*self
)
553 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
554 t
!= self
->window
) { /* cant be transient to itself! */
555 self
->transient
= TRUE
;
556 c
= g_hash_table_lookup(client_map
, &t
);
557 g_assert(c
!= self
);/* if this happens then we need to check for it*/
559 if (!c
/*XXX: && _group*/) {
560 /* not transient to a client, see if it is transient for a
562 if (/*t == _group->leader() || */
565 /* window is a transient for its group! */
566 /* XXX: for now this is treated as non-transient.
567 this needs to be fixed! */
571 self
->transient
= FALSE
;
573 /* if anything has changed... */
574 if (c
!= self
->transient_for
) {
575 if (self
->transient_for
)
576 /* remove from old parent */
577 self
->transient_for
->transients
=
578 g_slist_remove(self
->transient_for
->transients
, self
);
579 self
->transient_for
= c
;
580 if (self
->transient_for
)
581 /* add to new parent */
582 self
->transient_for
->transients
=
583 g_slist_append(self
->transient_for
->transients
, self
);
587 static void client_get_mwm_hints(Client
*self
)
590 unsigned long *hints
;
592 self
->mwmhints
.flags
= 0; /* default to none */
594 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
595 if (num
>= MWM_ELEMENTS
) {
596 self
->mwmhints
.flags
= hints
[0];
597 self
->mwmhints
.functions
= hints
[1];
598 self
->mwmhints
.decorations
= hints
[2];
604 void client_get_type(Client
*self
)
610 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
611 /* use the first value that we know about in the array */
612 for (i
= 0; i
< num
; ++i
) {
613 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
614 self
->type
= Type_Desktop
;
615 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
616 self
->type
= Type_Dock
;
617 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
618 self
->type
= Type_Toolbar
;
619 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
620 self
->type
= Type_Menu
;
621 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
622 self
->type
= Type_Utility
;
623 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
624 self
->type
= Type_Splash
;
625 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
626 self
->type
= Type_Dialog
;
627 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
628 self
->type
= Type_Normal
;
629 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
630 /* prevent this window from getting any decor or
632 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
633 MwmFlag_Decorations
);
634 self
->mwmhints
.decorations
= 0;
635 self
->mwmhints
.functions
= 0;
637 if (self
->type
!= (WindowType
) -1)
638 break; /* grab the first legit type */
643 if (self
->type
== (WindowType
) -1) {
644 /*the window type hint was not set, which means we either classify
645 ourself as a normal window or a dialog, depending on if we are a
648 self
->type
= Type_Dialog
;
650 self
->type
= Type_Normal
;
654 void client_update_protocols(Client
*self
)
657 gulong num_return
, i
;
659 self
->focus_notify
= FALSE
;
660 self
->delete_window
= FALSE
;
662 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
663 for (i
= 0; i
< num_return
; ++i
) {
664 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
665 /* this means we can request the window to close */
666 self
->delete_window
= TRUE
;
667 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
668 /* if this protocol is requested, then the window will be
669 notified whenever we want it to receive focus */
670 self
->focus_notify
= TRUE
;
676 static void client_get_gravity(Client
*self
)
678 XWindowAttributes wattrib
;
681 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
682 g_assert(ret
!= BadWindow
);
683 self
->gravity
= wattrib
.win_gravity
;
686 void client_update_normal_hints(Client
*self
)
690 int oldgravity
= self
->gravity
;
693 self
->min_ratio
= 0.0f
;
694 self
->max_ratio
= 0.0f
;
695 SIZE_SET(self
->size_inc
, 1, 1);
696 SIZE_SET(self
->base_size
, 0, 0);
697 SIZE_SET(self
->min_size
, 0, 0);
698 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
700 /* get the hints from the window */
701 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
702 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
704 if (size
.flags
& PWinGravity
) {
705 self
->gravity
= size
.win_gravity
;
707 /* if the client has a frame, i.e. has already been mapped and
708 is changing its gravity */
709 if (self
->frame
&& self
->gravity
!= oldgravity
) {
710 /* move our idea of the client's position based on its new
712 self
->area
.x
= self
->frame
->area
.x
;
713 self
->area
.y
= self
->frame
->area
.y
;
714 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
718 if (size
.flags
& PAspect
) {
719 if (size
.min_aspect
.y
)
720 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
721 if (size
.max_aspect
.y
)
722 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
725 if (size
.flags
& PMinSize
)
726 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
728 if (size
.flags
& PMaxSize
)
729 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
731 if (size
.flags
& PBaseSize
)
732 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
734 if (size
.flags
& PResizeInc
)
735 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
739 void client_setup_decor_and_functions(Client
*self
)
741 /* start with everything (cept fullscreen) */
742 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
743 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
;
744 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
746 if (self
->delete_window
) {
747 self
->decorations
|= Decor_Close
;
748 self
->functions
|= Func_Close
;
751 if (!(self
->min_size
.width
< self
->max_size
.width
||
752 self
->min_size
.height
< self
->max_size
.height
)) {
753 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
754 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
757 switch (self
->type
) {
759 /* normal windows retain all of the possible decorations and
760 functionality, and are the only windows that you can fullscreen */
761 self
->functions
|= Func_Fullscreen
;
765 /* dialogs cannot be maximized */
766 self
->decorations
&= ~Decor_Maximize
;
767 self
->functions
&= ~Func_Maximize
;
773 /* these windows get less functionality */
774 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
775 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
781 /* none of these windows are manipulated by the window manager */
782 self
->decorations
= 0;
787 /* Mwm Hints are applied subtractively to what has already been chosen for
788 decor and functionality */
789 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
790 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
791 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
792 self
->decorations
&= ~Decor_Border
;
793 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
794 self
->decorations
&= ~Decor_Handle
;
795 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
796 self
->decorations
&= ~Decor_Titlebar
;
797 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
798 self
->decorations
&= ~Decor_Iconify
;
799 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
800 self
->decorations
&= ~Decor_Maximize
;
804 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
805 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
806 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
807 self
->functions
&= ~Func_Resize
;
808 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
809 self
->functions
&= ~Func_Move
;
810 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
811 self
->functions
&= ~Func_Iconify
;
812 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
813 self
->functions
&= ~Func_Maximize
;
814 /* dont let mwm hints kill the close button
815 if (! (self->mwmhints.functions & MwmFunc_Close))
816 self->functions &= ~Func_Close; */
820 /* can't maximize without moving/resizing */
821 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
822 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
824 /* finally, user specified disabled decorations are applied to subtract
826 if (self
->disabled_decorations
& Decor_Titlebar
)
827 self
->decorations
&= ~Decor_Titlebar
;
828 if (self
->disabled_decorations
& Decor_Handle
)
829 self
->decorations
&= ~Decor_Handle
;
830 if (self
->disabled_decorations
& Decor_Border
)
831 self
->decorations
&= ~Decor_Border
;
832 if (self
->disabled_decorations
& Decor_Iconify
)
833 self
->decorations
&= ~Decor_Iconify
;
834 if (self
->disabled_decorations
& Decor_Maximize
)
835 self
->decorations
&= ~Decor_Maximize
;
836 if (self
->disabled_decorations
& Decor_AllDesktops
)
837 self
->decorations
&= ~Decor_AllDesktops
;
838 if (self
->disabled_decorations
& Decor_Close
)
839 self
->decorations
&= ~Decor_Close
;
841 /* if we don't have a titlebar, then we cannot shade! */
842 if (!(self
->decorations
& Decor_Titlebar
))
843 self
->functions
&= ~Func_Shade
;
845 client_change_allowed_actions(self
);
848 /* change the decors on the frame, and with more/less decorations,
849 we may also need to be repositioned */
850 engine_frame_adjust_area(self
->frame
, TRUE
, TRUE
);
851 /* with new decor, the window's maximized size may change */
852 client_remaximize(self
);
856 static void client_change_allowed_actions(Client
*self
)
861 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
863 if (self
->functions
& Func_Shade
)
864 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
865 if (self
->functions
& Func_Close
)
866 actions
[num
++] = prop_atoms
.net_wm_action_close
;
867 if (self
->functions
& Func_Move
)
868 actions
[num
++] = prop_atoms
.net_wm_action_move
;
869 if (self
->functions
& Func_Iconify
)
870 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
871 if (self
->functions
& Func_Resize
)
872 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
873 if (self
->functions
& Func_Fullscreen
)
874 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
875 if (self
->functions
& Func_Maximize
) {
876 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
877 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
880 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
882 /* make sure the window isn't breaking any rules now */
884 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
885 if (self
->frame
) client_shade(self
, FALSE
);
886 else self
->shaded
= FALSE
;
888 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
889 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
890 else self
->iconic
= FALSE
;
892 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
893 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
894 else self
->fullscreen
= FALSE
;
896 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
898 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
899 else self
->max_vert
= self
->max_horz
= FALSE
;
903 void client_remaximize(Client
*self
)
906 if (self
->max_horz
&& self
->max_vert
)
908 else if (self
->max_horz
)
910 else if (self
->max_vert
)
913 return; /* not maximized */
914 self
->max_horz
= self
->max_vert
= FALSE
;
915 client_maximize(self
, TRUE
, dir
, FALSE
);
918 void client_update_wmhints(Client
*self
)
923 /* assume a window takes input if it doesnt specify */
924 self
->can_focus
= TRUE
;
926 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
927 if (hints
->flags
& InputHint
)
928 self
->can_focus
= hints
->input
;
930 /* only do this when starting! */
931 if (ob_state
== State_Starting
&& (hints
->flags
& StateHint
))
932 self
->iconic
= hints
->initial_state
== IconicState
;
934 if (hints
->flags
& XUrgencyHint
)
937 if (hints
->flags
& WindowGroupHint
) {
938 if (hints
->window_group
!= self
->group
) {
939 /* XXX: remove from the old group if there was one */
940 self
->group
= hints
->window_group
;
941 /* XXX: do stuff with the group */
943 } else /* no group! */
946 if (hints
->flags
& IconPixmapHint
) {
947 client_update_kwm_icon(self
);
948 /* try get the kwm icon first, this is a fallback only */
949 if (self
->pixmap_icon
== None
) {
950 self
->pixmap_icon
= hints
->icon_pixmap
;
951 if (hints
->flags
& IconMaskHint
)
952 self
->pixmap_icon_mask
= hints
->icon_mask
;
954 self
->pixmap_icon_mask
= None
;
957 engine_frame_adjust_icon(self
->frame
);
964 if (ur
!= self
->urgent
) {
966 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
968 /* fire the urgent callback if we're mapped, otherwise, wait until
969 after we're mapped */
971 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
975 void client_update_title(Client
*self
)
982 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
983 /* try old x stuff */
984 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
985 /* convert it to UTF-8 */
989 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
991 g_warning("Unable to convert string to UTF-8");
998 data
= g_strdup("Unnamed Window");
1000 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1006 engine_frame_adjust_title(self
->frame
);
1009 void client_update_icon_title(Client
*self
)
1013 g_free(self
->icon_title
);
1016 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1017 /* try old x stuff */
1018 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1019 /* convert it to UTF-8 */
1023 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1025 g_warning("Unable to convert string to UTF-8");
1032 data
= g_strdup("Unnamed Window");
1034 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1037 self
->icon_title
= data
;
1040 void client_update_class(Client
*self
)
1046 if (self
->name
) g_free(self
->name
);
1047 if (self
->class) g_free(self
->class);
1048 if (self
->role
) g_free(self
->role
);
1050 self
->name
= self
->class = self
->role
= NULL
;
1052 data
= g_ptr_array_new();
1054 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1056 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1058 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1061 for (i
= 0; i
< data
->len
; ++i
)
1062 g_free(g_ptr_array_index(data
, i
));
1063 g_ptr_array_free(data
, TRUE
);
1065 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1066 self
->role
= g_strdup(s
);
1068 if (self
->name
== NULL
) self
->name
= g_strdup("");
1069 if (self
->class == NULL
) self
->class = g_strdup("");
1070 if (self
->role
== NULL
) self
->role
= g_strdup("");
1073 void client_update_strut(Client
*self
)
1077 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1078 STRUT_SET(self
->strut
, data
[0], data
[1], data
[2], data
[3]);
1081 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1083 /* updating here is pointless while we're being mapped cuz we're not in
1084 the client list yet */
1086 screen_update_struts();
1089 void client_update_icons(Client
*self
)
1092 unsigned long *data
;
1093 unsigned long w
, h
, i
;
1096 for (j
= 0; j
< self
->nicons
; ++j
)
1097 g_free(self
->icons
[j
].data
);
1098 if (self
->nicons
> 0)
1099 g_free(self
->icons
);
1102 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1103 /* figure out how many valid icons are in here */
1105 while (num
- i
> 2) {
1113 self
->icons
= g_new(Icon
, self
->nicons
);
1115 /* store the icons */
1117 for (j
= 0; j
< self
->nicons
; ++j
) {
1118 w
= self
->icons
[j
].width
= data
[i
++];
1119 h
= self
->icons
[j
].height
= data
[i
++];
1120 self
->icons
[j
].data
=
1121 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1130 engine_frame_adjust_icon(self
->frame
);
1133 void client_update_kwm_icon(Client
*self
)
1137 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1138 self
->pixmap_icon
= data
[0];
1139 self
->pixmap_icon_mask
= data
[1];
1142 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1145 engine_frame_adjust_icon(self
->frame
);
1148 static void client_change_state(Client
*self
)
1150 unsigned long state
[2];
1154 state
[0] = self
->wmstate
;
1156 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1160 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1162 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1164 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1165 if (self
->skip_taskbar
)
1166 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1167 if (self
->skip_pager
)
1168 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1169 if (self
->fullscreen
)
1170 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1172 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1174 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1176 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1178 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1179 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1181 client_calc_layer(self
);
1184 engine_frame_adjust_state(self
->frame
);
1187 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1192 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1193 Client
*c
= it
->data
;
1194 if (c
== skip
) continue; /* circular? */
1195 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1196 if (client_focused(c
)) return c
;
1201 void client_calc_layer(Client
*self
)
1207 /* are we fullscreen, or do we have a fullscreen transient parent? */
1211 if (c
->fullscreen
) {
1215 c
= c
->transient_for
;
1217 if (!fs
&& self
->fullscreen
) {
1218 /* is one of our transients focused? */
1219 c
= search_focus_tree(self
, self
);
1220 if (c
!= NULL
) fs
= TRUE
;
1223 if (self
->iconic
) l
= Layer_Icon
;
1224 else if (fs
) l
= Layer_Fullscreen
;
1225 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1226 else if (self
->type
== Type_Dock
) {
1227 if (!self
->below
) l
= Layer_Top
;
1228 else l
= Layer_Normal
;
1230 else if (self
->above
) l
= Layer_Above
;
1231 else if (self
->below
) l
= Layer_Below
;
1232 else l
= Layer_Normal
;
1234 if (l
!= self
->layer
) {
1237 stacking_raise(self
);
1241 gboolean
client_should_show(Client
*self
)
1243 if (self
->iconic
) return FALSE
;
1244 else if (!(self
->desktop
== screen_desktop
||
1245 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1246 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1251 static void client_showhide(Client
*self
)
1254 if (client_should_show(self
))
1255 engine_frame_show(self
->frame
);
1257 engine_frame_hide(self
->frame
);
1260 gboolean
client_normal(Client
*self
) {
1261 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1262 self
->type
== Type_Splash
);
1265 static void client_apply_startup_state(Client
*self
)
1267 /* these are in a carefully crafted order.. */
1270 self
->iconic
= FALSE
;
1271 client_iconify(self
, TRUE
, FALSE
);
1273 if (self
->fullscreen
) {
1274 self
->fullscreen
= FALSE
;
1275 client_fullscreen(self
, TRUE
, FALSE
);
1278 self
->shaded
= FALSE
;
1279 client_shade(self
, TRUE
);
1282 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1284 if (self
->max_vert
&& self
->max_horz
) {
1285 self
->max_vert
= self
->max_horz
= FALSE
;
1286 client_maximize(self
, TRUE
, 0, FALSE
);
1287 } else if (self
->max_vert
) {
1288 self
->max_vert
= FALSE
;
1289 client_maximize(self
, TRUE
, 2, FALSE
);
1290 } else if (self
->max_horz
) {
1291 self
->max_horz
= FALSE
;
1292 client_maximize(self
, TRUE
, 1, FALSE
);
1295 /* nothing to do for the other states:
1304 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1305 gboolean user
, gboolean final
)
1307 gboolean moved
= FALSE
, resized
= FALSE
;
1309 /* set the size and position if fullscreen */
1310 if (self
->fullscreen
) {
1313 w
= screen_physical_size
.width
;
1314 h
= screen_physical_size
.height
;
1316 /* set the size and position if maximized */
1317 if (self
->max_horz
) {
1318 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1319 w
= screen_area(self
->desktop
)->x
+
1320 screen_area(self
->desktop
)->width
;
1322 if (self
->max_vert
) {
1323 y
= screen_area(self
->desktop
)->y
;
1324 h
= screen_area(self
->desktop
)->y
+
1325 screen_area(self
->desktop
)->height
-
1326 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1330 /* these override the above states! if you cant move you can't move! */
1332 if (!(self
->functions
& Func_Move
)) {
1336 if (!(self
->functions
& Func_Resize
)) {
1337 w
= self
->area
.width
;
1338 h
= self
->area
.height
;
1342 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1343 w
-= self
->base_size
.width
;
1344 h
-= self
->base_size
.height
;
1347 /* for interactive resizing. have to move half an increment in each
1350 /* how far we are towards the next size inc */
1351 int mw
= w
% self
->size_inc
.width
;
1352 int mh
= h
% self
->size_inc
.height
;
1354 int aw
= self
->size_inc
.width
/ 2;
1355 int ah
= self
->size_inc
.height
/ 2;
1356 /* don't let us move into a new size increment */
1357 if (mw
+ aw
>= self
->size_inc
.width
)
1358 aw
= self
->size_inc
.width
- mw
- 1;
1359 if (mh
+ ah
>= self
->size_inc
.height
)
1360 ah
= self
->size_inc
.height
- mh
- 1;
1364 /* if this is a user-requested resize, then check against min/max
1365 sizes and aspect ratios */
1367 /* smaller than min size or bigger than max size? */
1368 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1369 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1370 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1371 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1373 /* adjust the height ot match the width for the aspect ratios */
1374 if (self
->min_ratio
)
1375 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1376 if (self
->max_ratio
)
1377 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1380 /* keep to the increments */
1381 w
/= self
->size_inc
.width
;
1382 h
/= self
->size_inc
.height
;
1384 /* you cannot resize to nothing */
1388 /* store the logical size */
1389 SIZE_SET(self
->logical_size
, w
, h
);
1391 w
*= self
->size_inc
.width
;
1392 h
*= self
->size_inc
.height
;
1394 w
+= self
->base_size
.width
;
1395 h
+= self
->base_size
.height
;
1399 case Corner_TopLeft
:
1401 case Corner_TopRight
:
1402 x
-= w
- self
->area
.width
;
1404 case Corner_BottomLeft
:
1405 y
-= h
- self
->area
.height
;
1407 case Corner_BottomRight
:
1408 x
-= w
- self
->area
.width
;
1409 y
-= h
- self
->area
.height
;
1413 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1414 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1416 RECT_SET(self
->area
, x
, y
, w
, h
);
1419 XResizeWindow(ob_display
, self
->window
, w
, h
);
1421 /* move/resize the frame to match the request */
1423 if (moved
|| resized
)
1424 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1426 if (!user
|| final
) {
1428 event
.type
= ConfigureNotify
;
1429 event
.xconfigure
.display
= ob_display
;
1430 event
.xconfigure
.event
= self
->window
;
1431 event
.xconfigure
.window
= self
->window
;
1433 /* root window coords with border in mind */
1434 event
.xconfigure
.x
= x
- self
->border_width
+
1435 self
->frame
->size
.left
;
1436 event
.xconfigure
.y
= y
- self
->border_width
+
1437 self
->frame
->size
.top
;
1439 event
.xconfigure
.width
= self
->area
.width
;
1440 event
.xconfigure
.height
= self
->area
.height
;
1441 event
.xconfigure
.border_width
= self
->border_width
;
1442 event
.xconfigure
.above
= self
->frame
->plate
;
1443 event
.xconfigure
.override_redirect
= FALSE
;
1444 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1445 FALSE
, StructureNotifyMask
, &event
);
1450 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1454 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1455 self
->fullscreen
== fs
) return; /* already done */
1457 self
->fullscreen
= fs
;
1458 client_change_state(self
); /* change the state hints on the client */
1461 /* save the functions and remove them */
1462 self
->pre_fs_func
= self
->functions
;
1463 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1465 /* save the decorations and remove them */
1466 self
->pre_fs_decor
= self
->decorations
;
1467 self
->decorations
= 0;
1470 dimensions
[0] = self
->area
.x
;
1471 dimensions
[1] = self
->area
.y
;
1472 dimensions
[2] = self
->area
.width
;
1473 dimensions
[3] = self
->area
.height
;
1475 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1479 /* these are not actually used cuz client_configure will set them
1480 as appropriate when the window is fullscreened */
1485 self
->functions
= self
->pre_fs_func
;
1486 self
->decorations
= self
->pre_fs_decor
;
1488 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1496 /* pick some fallbacks... */
1497 x
= screen_area(self
->desktop
)->x
+
1498 screen_area(self
->desktop
)->width
/ 4;
1499 y
= screen_area(self
->desktop
)->y
+
1500 screen_area(self
->desktop
)->height
/ 4;
1501 w
= screen_area(self
->desktop
)->width
/ 2;
1502 h
= screen_area(self
->desktop
)->height
/ 2;
1506 client_change_allowed_actions(self
); /* based on the new _functions */
1508 /* when fullscreening, don't obey things like increments, fill the
1510 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1512 /* raise (back) into our stacking layer */
1513 stacking_raise(self
);
1515 /* try focus us when we go into fullscreen mode */
1519 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1521 if (self
->iconic
== iconic
) return; /* nothing to do */
1523 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1526 self
->iconic
= iconic
;
1529 self
->wmstate
= IconicState
;
1530 self
->ignore_unmaps
++;
1531 /* we unmap the client itself so that we can get MapRequest events,
1532 and because the ICCCM tells us to! */
1533 XUnmapWindow(ob_display
, self
->window
);
1536 client_set_desktop(self
, screen_desktop
);
1537 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1538 XMapWindow(ob_display
, self
->window
);
1540 client_change_state(self
);
1541 client_showhide(self
);
1542 screen_update_struts();
1544 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1548 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1552 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1553 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1555 /* check if already done */
1557 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1558 if (dir
== 1 && self
->max_horz
) return;
1559 if (dir
== 2 && self
->max_vert
) return;
1561 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1562 if (dir
== 1 && !self
->max_horz
) return;
1563 if (dir
== 2 && !self
->max_vert
) return;
1566 /* work with the frame's coords */
1567 x
= self
->frame
->area
.x
;
1568 y
= self
->frame
->area
.y
;
1569 w
= self
->area
.width
;
1570 h
= self
->area
.height
;
1582 /* get the property off the window and use it for the dimensions
1583 we are already maxed on */
1584 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1586 if (self
->max_horz
) {
1587 dimensions
[0] = readdim
[0];
1588 dimensions
[2] = readdim
[2];
1590 if (self
->max_vert
) {
1591 dimensions
[1] = readdim
[1];
1592 dimensions
[3] = readdim
[3];
1597 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1601 /* pass the client's current position info. the client_configure
1602 will move/size stuff as appropriate for a maximized window */
1605 w
= self
->area
.width
;
1606 h
= self
->area
.height
;
1610 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1612 if (dir
== 0 || dir
== 1) { /* horz */
1616 if (dir
== 0 || dir
== 2) { /* vert */
1622 /* pick some fallbacks... */
1623 if (dir
== 0 || dir
== 1) { /* horz */
1624 x
= screen_area(self
->desktop
)->x
+
1625 screen_area(self
->desktop
)->width
/ 4;
1626 w
= screen_area(self
->desktop
)->width
/ 2;
1628 if (dir
== 0 || dir
== 2) { /* vert */
1629 y
= screen_area(self
->desktop
)->y
+
1630 screen_area(self
->desktop
)->height
/ 4;
1631 h
= screen_area(self
->desktop
)->height
/ 2;
1636 if (dir
== 0 || dir
== 1) /* horz */
1637 self
->max_horz
= max
;
1638 if (dir
== 0 || dir
== 2) /* vert */
1639 self
->max_vert
= max
;
1641 if (!self
->max_horz
&& !self
->max_vert
)
1642 PROP_ERASE(self
->window
, openbox_premax
);
1644 client_change_state(self
); /* change the state hints on the client */
1646 /* figure out where the client should be going */
1647 frame_frame_gravity(self
->frame
, &x
, &y
);
1648 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1651 void client_shade(Client
*self
, gboolean shade
)
1653 if (!(self
->functions
& Func_Shade
) || /* can't */
1654 self
->shaded
== shade
) return; /* already done */
1656 /* when we're iconic, don't change the wmstate */
1658 self
->wmstate
= shade
? IconicState
: NormalState
;
1659 self
->shaded
= shade
;
1660 client_change_state(self
);
1661 /* resize the frame to just the titlebar */
1662 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1665 void client_close(Client
*self
)
1669 if (!(self
->functions
& Func_Close
)) return;
1672 XXX: itd be cool to do timeouts and shit here for killing the client's
1674 like... if the window is around after 5 seconds, then the close button
1675 turns a nice red, and if this function is called again, the client is
1679 ce
.xclient
.type
= ClientMessage
;
1680 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1681 ce
.xclient
.display
= ob_display
;
1682 ce
.xclient
.window
= self
->window
;
1683 ce
.xclient
.format
= 32;
1684 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1685 ce
.xclient
.data
.l
[1] = event_lasttime
;
1686 ce
.xclient
.data
.l
[2] = 0l;
1687 ce
.xclient
.data
.l
[3] = 0l;
1688 ce
.xclient
.data
.l
[4] = 0l;
1689 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1692 void client_kill(Client
*self
)
1694 XKillClient(ob_display
, self
->window
);
1697 void client_set_desktop(Client
*self
, guint target
)
1701 if (target
== self
->desktop
) return;
1703 g_message("Setting desktop %u\n", target
);
1705 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1707 old
= self
->desktop
;
1708 self
->desktop
= target
;
1709 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1710 /* the frame can display the current desktop state */
1711 engine_frame_adjust_state(self
->frame
);
1712 /* 'move' the window to the new desktop */
1713 client_showhide(self
);
1714 screen_update_struts();
1716 /* update the focus lists */
1717 if (old
== DESKTOP_ALL
) {
1718 for (i
= 0; i
< screen_num_desktops
; ++i
)
1719 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1720 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1722 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1723 if (target
== DESKTOP_ALL
)
1724 for (i
= 0; i
< screen_num_desktops
; ++i
)
1725 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1728 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1731 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1736 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1737 Client
*c
= it
->data
;
1738 if (c
== skip
) continue; /* circular? */
1739 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1740 if (c
->modal
) return c
;
1745 Client
*client_find_modal_child(Client
*self
)
1747 return search_modal_tree(self
, self
);
1750 gboolean
client_validate(Client
*self
)
1754 XSync(ob_display
, FALSE
); /* get all events on the server */
1756 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1757 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1758 XPutBackEvent(ob_display
, &e
);
1765 void client_set_wm_state(Client
*self
, long state
)
1767 if (state
== self
->wmstate
) return; /* no change */
1771 client_iconify(self
, TRUE
, TRUE
);
1774 client_iconify(self
, FALSE
, TRUE
);
1779 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1781 gboolean shaded
= self
->shaded
;
1782 gboolean fullscreen
= self
->fullscreen
;
1783 gboolean max_horz
= self
->max_horz
;
1784 gboolean max_vert
= self
->max_vert
;
1787 if (!(action
== prop_atoms
.net_wm_state_add
||
1788 action
== prop_atoms
.net_wm_state_remove
||
1789 action
== prop_atoms
.net_wm_state_toggle
))
1790 /* an invalid action was passed to the client message, ignore it */
1793 for (i
= 0; i
< 2; ++i
) {
1794 Atom state
= i
== 0 ? data1
: data2
;
1796 if (!state
) continue;
1798 /* if toggling, then pick whether we're adding or removing */
1799 if (action
== prop_atoms
.net_wm_state_toggle
) {
1800 if (state
== prop_atoms
.net_wm_state_modal
)
1801 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1802 prop_atoms
.net_wm_state_add
;
1803 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1804 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1805 prop_atoms
.net_wm_state_add
;
1806 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1807 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1808 prop_atoms
.net_wm_state_add
;
1809 else if (state
== prop_atoms
.net_wm_state_shaded
)
1810 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1811 prop_atoms
.net_wm_state_add
;
1812 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1813 action
= self
->skip_taskbar
?
1814 prop_atoms
.net_wm_state_remove
:
1815 prop_atoms
.net_wm_state_add
;
1816 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1817 action
= self
->skip_pager
?
1818 prop_atoms
.net_wm_state_remove
:
1819 prop_atoms
.net_wm_state_add
;
1820 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1821 action
= self
->fullscreen
?
1822 prop_atoms
.net_wm_state_remove
:
1823 prop_atoms
.net_wm_state_add
;
1824 else if (state
== prop_atoms
.net_wm_state_above
)
1825 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1826 prop_atoms
.net_wm_state_add
;
1827 else if (state
== prop_atoms
.net_wm_state_below
)
1828 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1829 prop_atoms
.net_wm_state_add
;
1832 if (action
== prop_atoms
.net_wm_state_add
) {
1833 if (state
== prop_atoms
.net_wm_state_modal
) {
1834 /* XXX raise here or something? */
1836 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1838 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1840 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1842 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1843 self
->skip_taskbar
= TRUE
;
1844 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1845 self
->skip_pager
= TRUE
;
1846 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1848 } else if (state
== prop_atoms
.net_wm_state_above
) {
1850 } else if (state
== prop_atoms
.net_wm_state_below
) {
1854 } else { /* action == prop_atoms.net_wm_state_remove */
1855 if (state
== prop_atoms
.net_wm_state_modal
) {
1856 self
->modal
= FALSE
;
1857 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1859 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1861 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1863 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1864 self
->skip_taskbar
= FALSE
;
1865 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1866 self
->skip_pager
= FALSE
;
1867 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1869 } else if (state
== prop_atoms
.net_wm_state_above
) {
1870 self
->above
= FALSE
;
1871 } else if (state
== prop_atoms
.net_wm_state_below
) {
1872 self
->below
= FALSE
;
1876 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1877 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1879 if (max_horz
== max_vert
) { /* both going the same way */
1880 client_maximize(self
, max_horz
, 0, TRUE
);
1882 client_maximize(self
, max_horz
, 1, TRUE
);
1883 client_maximize(self
, max_vert
, 2, TRUE
);
1887 if (max_horz
!= self
->max_horz
)
1888 client_maximize(self
, max_horz
, 1, TRUE
);
1890 client_maximize(self
, max_vert
, 2, TRUE
);
1893 /* change fullscreen state before shading, as it will affect if the window
1895 if (fullscreen
!= self
->fullscreen
)
1896 client_fullscreen(self
, fullscreen
, TRUE
);
1897 if (shaded
!= self
->shaded
)
1898 client_shade(self
, shaded
);
1899 client_calc_layer(self
);
1900 client_change_state(self
); /* change the hint to relect these changes */
1903 gboolean
client_focus(Client
*self
)
1908 /* if we have a modal child, then focus it, not us */
1909 child
= client_find_modal_child(self
);
1911 return client_focus(child
);
1913 /* won't try focus if the client doesn't want it, or if the window isn't
1914 visible on the screen */
1915 if (!(self
->frame
->visible
&&
1916 (self
->can_focus
|| self
->focus_notify
)))
1919 /* do a check to see if the window has already been unmapped or destroyed
1920 do this intelligently while watching out for unmaps we've generated
1921 (ignore_unmaps > 0) */
1922 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1923 DestroyNotify
, &ev
)) {
1924 XPutBackEvent(ob_display
, &ev
);
1927 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1928 UnmapNotify
, &ev
)) {
1929 if (self
->ignore_unmaps
) {
1930 self
->ignore_unmaps
--;
1932 XPutBackEvent(ob_display
, &ev
);
1937 if (self
->can_focus
)
1938 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
1941 if (self
->focus_notify
) {
1943 ce
.xclient
.type
= ClientMessage
;
1944 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1945 ce
.xclient
.display
= ob_display
;
1946 ce
.xclient
.window
= self
->window
;
1947 ce
.xclient
.format
= 32;
1948 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1949 ce
.xclient
.data
.l
[1] = CurrentTime
;
1950 ce
.xclient
.data
.l
[2] = 0l;
1951 ce
.xclient
.data
.l
[3] = 0l;
1952 ce
.xclient
.data
.l
[4] = 0l;
1953 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1956 /* XSync(ob_display, FALSE); XXX Why sync? */
1960 void client_unfocus(Client
*self
)
1962 g_assert(focus_client
== self
);
1963 client_set_focused(self
, FALSE
);
1966 gboolean
client_focused(Client
*self
)
1968 return self
== focus_client
;
1971 void client_set_focused(Client
*self
, gboolean focused
)
1974 if (focus_client
!= self
)
1975 focus_set_client(self
);
1977 if (focus_client
== self
)
1978 focus_set_client(NULL
);
1981 /* focus state can affect the stacking layer */
1982 client_calc_layer(self
);
1984 engine_frame_adjust_focus(self
->frame
);
1987 Icon
*client_icon(Client
*self
, int w
, int h
)
1990 /* si is the smallest image >= req */
1991 /* li is the largest image < req */
1992 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
1994 if (!self
->nicons
) return NULL
;
1996 for (i
= 0; i
< self
->nicons
; ++i
) {
1997 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
1998 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2002 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2007 if (largest
== 0) /* didnt find one smaller than the requested size */
2008 return &self
->icons
[si
];
2009 return &self
->icons
[li
];