4 #include "extensions.h"
15 #include <X11/Xutil.h>
17 /*! The event mask to grab on client windows */
18 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
21 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
24 GSList
*client_list
= NULL
;
25 GHashTable
*client_map
= NULL
;
27 static Window
*client_startup_stack_order
= NULL
;
28 static gulong client_startup_stack_size
= 0;
30 static void client_get_all(Client
*self
);
31 static void client_toggle_border(Client
*self
, gboolean show
);
32 static void client_get_area(Client
*self
);
33 static void client_get_desktop(Client
*self
);
34 static void client_get_state(Client
*self
);
35 static void client_get_shaped(Client
*self
);
36 static void client_get_mwm_hints(Client
*self
);
37 static void client_get_gravity(Client
*self
);
38 static void client_showhide(Client
*self
);
39 static void client_change_allowed_actions(Client
*self
);
40 static void client_change_state(Client
*self
);
41 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
42 static void client_apply_startup_state(Client
*self
);
43 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
45 static guint
map_hash(Window
*w
) { return *w
; }
46 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
50 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
51 (GEqualFunc
)map_key_comp
);
53 /* save the stacking order on startup! */
54 PROP_GET32U(ob_root
, net_client_list_stacking
, window
,
55 client_startup_stack_order
, client_startup_stack_size
);
60 void client_shutdown()
62 g_hash_table_destroy(client_map
);
65 void client_set_list()
67 Window
*windows
, *win_it
;
69 guint size
= g_slist_length(client_list
);
71 /* create an array of the window ids */
73 windows
= g_new(Window
, size
);
75 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
76 *win_it
= ((Client
*)it
->data
)->window
;
80 PROP_SET32A(ob_root
, net_client_list
, window
, windows
, size
);
88 void client_manage_all()
90 ConfigValue focus_new
;
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;
141 if (!config_get("focusNew", Config_Bool
, &focus_new
))
142 g_assert_not_reached();
144 focus_fallback(FALSE
);
147 void client_manage(Window window
)
151 XWindowAttributes attrib
;
152 XSetWindowAttributes attrib_set
;
153 /* XWMHints *wmhint; */
155 ConfigValue focus_new
;
159 /* check if it has already been unmapped by the time we started mapping
160 the grab does a sync so we don't have to here */
161 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
162 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
163 XPutBackEvent(ob_display
, &e
);
166 return; /* don't manage it */
169 /* make sure it isn't an override-redirect window */
170 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
171 attrib
.override_redirect
) {
173 return; /* don't manage it */
176 /* /\* is the window a docking app *\/
177 if ((wmhint = XGetWMHints(ob_display, window))) {
178 if ((wmhint->flags & StateHint) &&
179 wmhint->initial_state == WithdrawnState) {
180 /\* XXX: make dock apps work! *\/
189 /* choose the events we want to receive on the CLIENT window */
190 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
191 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
192 XChangeWindowAttributes(ob_display
, window
,
193 CWEventMask
|CWDontPropagate
, &attrib_set
);
196 /* create the Client struct, and populate it from the hints on the
198 client
= g_new(Client
, 1);
199 client
->window
= window
;
200 client_get_all(client
);
202 /* remove the client's border (and adjust re gravity) */
203 client_toggle_border(client
, FALSE
);
205 /* specify that if we exit, the window should not be destroyed and should
206 be reparented back to root automatically */
207 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
209 /* create the decoration frame for the client window */
210 client
->frame
= engine_frame_new();
212 engine_frame_grab_client(client
->frame
, client
);
214 client_apply_startup_state(client
);
218 client_list
= g_slist_append(client_list
, client
);
219 stacking_list
= g_list_append(stacking_list
, client
);
220 g_assert(!g_hash_table_lookup(client_map
, &client
->window
));
221 g_hash_table_insert(client_map
, &client
->window
, client
);
223 /* update the focus lists */
224 if (client
->desktop
== DESKTOP_ALL
) {
225 for (i
= 0; i
< screen_num_desktops
; ++i
)
226 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
229 focus_order
[i
] = g_list_append(focus_order
[i
], client
);
232 stacking_raise(client
);
234 screen_update_struts();
236 dispatch_client(Event_Client_New
, client
, 0, 0);
238 client_showhide(client
);
240 dispatch_client(Event_Client_Mapped
, client
, 0, 0);
242 if (!config_get("focusNew", Config_Bool
, &focus_new
))
243 g_assert_not_reached();
244 if (ob_state
!= State_Starting
&& focus_new
.bool)
245 client_focus(client
);
247 /* update the list hints */
250 /* g_message("Managed window 0x%lx", window);*/
253 void client_unmanage_all()
255 while (client_list
!= NULL
)
256 client_unmanage(client_list
->data
);
259 void client_unmanage(Client
*client
)
265 /* g_message("Unmanaging window: %lx", client->window);*/
267 dispatch_client(Event_Client_Destroy
, client
, 0, 0);
268 g_assert(client
!= NULL
);
270 /* remove the window from our save set */
271 XChangeSaveSet(ob_display
, client
->window
, SetModeDelete
);
273 /* we dont want events no more */
274 XSelectInput(ob_display
, client
->window
, NoEventMask
);
276 engine_frame_hide(client
->frame
);
278 client_list
= g_slist_remove(client_list
, client
);
279 stacking_list
= g_list_remove(stacking_list
, client
);
280 g_hash_table_remove(client_map
, &client
->window
);
282 /* update the focus lists */
283 if (client
->desktop
== DESKTOP_ALL
) {
284 for (i
= 0; i
< screen_num_desktops
; ++i
)
285 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
288 focus_order
[i
] = g_list_remove(focus_order
[i
], client
);
291 /* once the client is out of the list, update the struts to remove it's
293 screen_update_struts();
295 /* tell our parent that we're gone */
296 if (client
->transient_for
!= NULL
)
297 client
->transient_for
->transients
=
298 g_slist_remove(client
->transient_for
->transients
, client
);
300 /* tell our transients that we're gone */
301 for (it
= client
->transients
; it
!= NULL
; it
= it
->next
) {
302 ((Client
*)it
->data
)->transient_for
= NULL
;
303 client_calc_layer(it
->data
);
306 /* dispatch the unmapped event */
307 dispatch_client(Event_Client_Unmapped
, client
, 0, 0);
308 g_assert(client
!= NULL
);
310 /* give the client its border back */
311 client_toggle_border(client
, TRUE
);
313 /* reparent the window out of the frame, and free the frame */
314 engine_frame_release_client(client
->frame
, client
);
315 client
->frame
= NULL
;
317 if (ob_state
!= State_Exiting
) {
318 /* these values should not be persisted across a window
320 prop_erase(client
->window
, prop_atoms
.net_wm_desktop
);
321 prop_erase(client
->window
, prop_atoms
.net_wm_state
);
323 /* if we're left in an iconic state, the client wont be mapped. this is
324 bad, since we will no longer be managing the window on restart */
326 XMapWindow(ob_display
, client
->window
);
329 /* free all data allocated in the client struct */
330 g_slist_free(client
->transients
);
331 for (j
= 0; j
< client
->nicons
; ++j
)
332 g_free(client
->icons
[j
].data
);
333 if (client
->nicons
> 0)
334 g_free(client
->icons
);
335 g_free(client
->title
);
336 g_free(client
->icon_title
);
337 g_free(client
->name
);
338 g_free(client
->class);
339 g_free(client
->role
);
342 /* update the list hints */
346 static void client_toggle_border(Client
*self
, gboolean show
)
348 /* adjust our idea of where the client is, based on its border. When the
349 border is removed, the client should now be considered to be in a
351 when re-adding the border to the client, the same operation needs to be
353 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
354 int x
= oldx
, y
= oldy
;
355 switch(self
->gravity
) {
357 case NorthWestGravity
:
359 case SouthWestGravity
:
361 case NorthEastGravity
:
363 case SouthEastGravity
:
364 if (show
) x
-= self
->border_width
* 2;
365 else x
+= self
->border_width
* 2;
372 if (show
) x
-= self
->border_width
;
373 else x
+= self
->border_width
;
376 switch(self
->gravity
) {
378 case NorthWestGravity
:
380 case NorthEastGravity
:
382 case SouthWestGravity
:
384 case SouthEastGravity
:
385 if (show
) y
-= self
->border_width
* 2;
386 else y
+= self
->border_width
* 2;
393 if (show
) y
-= self
->border_width
;
394 else y
+= self
->border_width
;
401 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
403 /* move the client so it is back it the right spot _with_ its
405 if (x
!= oldx
|| y
!= oldy
)
406 XMoveWindow(ob_display
, self
->window
, x
, y
);
408 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
412 static void client_get_all(Client
*self
)
414 /* update EVERYTHING!! */
416 self
->ignore_unmaps
= 0;
420 self
->title
= self
->icon_title
= NULL
;
421 self
->name
= self
->class = self
->role
= NULL
;
422 self
->wmstate
= NormalState
;
423 self
->transient
= FALSE
;
424 self
->transients
= NULL
;
425 self
->transient_for
= NULL
;
427 self
->urgent
= FALSE
;
428 self
->positioned
= FALSE
;
429 self
->disabled_decorations
= 0;
433 client_get_area(self
);
434 client_get_desktop(self
);
435 client_get_state(self
);
436 client_get_shaped(self
);
438 client_update_transient_for(self
);
439 client_get_mwm_hints(self
);
440 client_get_type(self
);/* this can change the mwmhints for special cases */
442 client_update_protocols(self
);
444 client_get_gravity(self
); /* get the attribute gravity */
445 client_update_normal_hints(self
); /* this may override the attribute
448 /* got the type, the mwmhints, the protocols, and the normal hints
449 (min/max sizes), so we're ready to set up the decorations/functions */
450 client_setup_decor_and_functions(self
);
452 client_update_wmhints(self
);
453 client_update_title(self
);
454 client_update_icon_title(self
);
455 client_update_class(self
);
456 client_update_strut(self
);
457 client_update_icons(self
);
458 client_update_kwm_icon(self
);
460 /* this makes sure that these windows appear on all desktops */
461 if (self
->type
== Type_Desktop
)
462 self
->desktop
= DESKTOP_ALL
;
464 /* set the desktop hint, to make sure that it always exists, and to
465 reflect any changes we've made here */
466 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
468 client_change_state(self
);
471 static void client_get_area(Client
*self
)
473 XWindowAttributes wattrib
;
476 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
477 g_assert(ret
!= BadWindow
);
479 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
480 self
->border_width
= wattrib
.border_width
;
483 static void client_get_desktop(Client
*self
)
487 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, d
)) {
488 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
489 d
= screen_num_desktops
- 1;
492 /* defaults to the current desktop */
493 self
->desktop
= screen_desktop
;
497 static void client_get_state(Client
*self
)
502 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
503 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
504 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
506 if (PROP_GET32U(self
->window
, net_wm_state
, atom
, state
, num
)) {
508 for (i
= 0; i
< num
; ++i
) {
509 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
511 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
513 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
515 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
516 self
->skip_taskbar
= TRUE
;
517 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
518 self
->skip_pager
= TRUE
;
519 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
520 self
->fullscreen
= TRUE
;
521 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
522 self
->max_vert
= TRUE
;
523 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
524 self
->max_horz
= TRUE
;
525 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
527 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
535 static void client_get_shaped(Client
*self
)
537 self
->shaped
= FALSE
;
539 if (extensions_shape
) {
544 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
546 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
547 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
549 self
->shaped
= (s
!= 0);
554 void client_update_transient_for(Client
*self
)
559 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
560 t
!= self
->window
) { /* cant be transient to itself! */
561 self
->transient
= TRUE
;
562 c
= g_hash_table_lookup(client_map
, &t
);
563 g_assert(c
!= self
);/* if this happens then we need to check for it*/
565 if (!c
/*XXX: && _group*/) {
566 /* not transient to a client, see if it is transient for a
568 if (/*t == _group->leader() || */
571 /* window is a transient for its group! */
572 /* XXX: for now this is treated as non-transient.
573 this needs to be fixed! */
577 self
->transient
= FALSE
;
579 /* if anything has changed... */
580 if (c
!= self
->transient_for
) {
581 if (self
->transient_for
)
582 /* remove from old parent */
583 self
->transient_for
->transients
=
584 g_slist_remove(self
->transient_for
->transients
, self
);
585 self
->transient_for
= c
;
586 if (self
->transient_for
)
587 /* add to new parent */
588 self
->transient_for
->transients
=
589 g_slist_append(self
->transient_for
->transients
, self
);
593 static void client_get_mwm_hints(Client
*self
)
596 unsigned long *hints
;
598 self
->mwmhints
.flags
= 0; /* default to none */
600 if (PROP_GET32U(self
->window
, motif_wm_hints
, motif_wm_hints
, hints
, num
)) {
601 if (num
>= MWM_ELEMENTS
) {
602 self
->mwmhints
.flags
= hints
[0];
603 self
->mwmhints
.functions
= hints
[1];
604 self
->mwmhints
.decorations
= hints
[2];
610 void client_get_type(Client
*self
)
616 if (PROP_GET32U(self
->window
, net_wm_window_type
, atom
, val
, num
)) {
617 /* use the first value that we know about in the array */
618 for (i
= 0; i
< num
; ++i
) {
619 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
620 self
->type
= Type_Desktop
;
621 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
622 self
->type
= Type_Dock
;
623 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
624 self
->type
= Type_Toolbar
;
625 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
626 self
->type
= Type_Menu
;
627 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
628 self
->type
= Type_Utility
;
629 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
630 self
->type
= Type_Splash
;
631 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
632 self
->type
= Type_Dialog
;
633 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
634 self
->type
= Type_Normal
;
635 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
636 /* prevent this window from getting any decor or
638 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
639 MwmFlag_Decorations
);
640 self
->mwmhints
.decorations
= 0;
641 self
->mwmhints
.functions
= 0;
643 if (self
->type
!= (WindowType
) -1)
644 break; /* grab the first legit type */
649 if (self
->type
== (WindowType
) -1) {
650 /*the window type hint was not set, which means we either classify
651 ourself as a normal window or a dialog, depending on if we are a
654 self
->type
= Type_Dialog
;
656 self
->type
= Type_Normal
;
660 void client_update_protocols(Client
*self
)
663 gulong num_return
, i
;
665 self
->focus_notify
= FALSE
;
666 self
->delete_window
= FALSE
;
668 if (PROP_GET32U(self
->window
, wm_protocols
, atom
, proto
, num_return
)) {
669 for (i
= 0; i
< num_return
; ++i
) {
670 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
671 /* this means we can request the window to close */
672 self
->delete_window
= TRUE
;
673 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
674 /* if this protocol is requested, then the window will be
675 notified whenever we want it to receive focus */
676 self
->focus_notify
= TRUE
;
682 static void client_get_gravity(Client
*self
)
684 XWindowAttributes wattrib
;
687 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
688 g_assert(ret
!= BadWindow
);
689 self
->gravity
= wattrib
.win_gravity
;
692 void client_update_normal_hints(Client
*self
)
696 int oldgravity
= self
->gravity
;
699 self
->min_ratio
= 0.0f
;
700 self
->max_ratio
= 0.0f
;
701 SIZE_SET(self
->size_inc
, 1, 1);
702 SIZE_SET(self
->base_size
, 0, 0);
703 SIZE_SET(self
->min_size
, 0, 0);
704 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
706 /* get the hints from the window */
707 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
708 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
710 if (size
.flags
& PWinGravity
) {
711 self
->gravity
= size
.win_gravity
;
713 /* if the client has a frame, i.e. has already been mapped and
714 is changing its gravity */
715 if (self
->frame
&& self
->gravity
!= oldgravity
) {
716 /* move our idea of the client's position based on its new
718 self
->area
.x
= self
->frame
->area
.x
;
719 self
->area
.y
= self
->frame
->area
.y
;
720 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
724 if (size
.flags
& PAspect
) {
725 if (size
.min_aspect
.y
)
726 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
727 if (size
.max_aspect
.y
)
728 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
731 if (size
.flags
& PMinSize
)
732 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
734 if (size
.flags
& PMaxSize
)
735 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
737 if (size
.flags
& PBaseSize
)
738 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
740 if (size
.flags
& PResizeInc
)
741 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
745 void client_setup_decor_and_functions(Client
*self
)
747 /* start with everything (cept fullscreen) */
748 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
749 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
751 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
753 if (self
->delete_window
) {
754 self
->decorations
|= Decor_Close
;
755 self
->functions
|= Func_Close
;
758 if (!(self
->min_size
.width
< self
->max_size
.width
||
759 self
->min_size
.height
< self
->max_size
.height
)) {
760 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
761 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
764 switch (self
->type
) {
766 /* normal windows retain all of the possible decorations and
767 functionality, and are the only windows that you can fullscreen */
768 self
->functions
|= Func_Fullscreen
;
772 /* dialogs cannot be maximized */
773 self
->decorations
&= ~Decor_Maximize
;
774 self
->functions
&= ~Func_Maximize
;
780 /* these windows get less functionality */
781 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
782 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
788 /* none of these windows are manipulated by the window manager */
789 self
->decorations
= 0;
794 /* Mwm Hints are applied subtractively to what has already been chosen for
795 decor and functionality */
796 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
797 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
798 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
799 self
->decorations
&= ~Decor_Border
;
800 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
801 self
->decorations
&= ~Decor_Handle
;
802 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
803 self
->decorations
&= ~Decor_Titlebar
;
804 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
805 self
->decorations
&= ~Decor_Iconify
;
806 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
807 self
->decorations
&= ~Decor_Maximize
;
811 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
812 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
813 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
814 self
->functions
&= ~Func_Resize
;
815 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
816 self
->functions
&= ~Func_Move
;
817 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
818 self
->functions
&= ~Func_Iconify
;
819 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
820 self
->functions
&= ~Func_Maximize
;
821 /* dont let mwm hints kill the close button
822 if (! (self->mwmhints.functions & MwmFunc_Close))
823 self->functions &= ~Func_Close; */
827 /* can't maximize without moving/resizing */
828 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
829 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
831 /* finally, user specified disabled decorations are applied to subtract
833 if (self
->disabled_decorations
& Decor_Titlebar
)
834 self
->decorations
&= ~Decor_Titlebar
;
835 if (self
->disabled_decorations
& Decor_Handle
)
836 self
->decorations
&= ~Decor_Handle
;
837 if (self
->disabled_decorations
& Decor_Border
)
838 self
->decorations
&= ~Decor_Border
;
839 if (self
->disabled_decorations
& Decor_Iconify
)
840 self
->decorations
&= ~Decor_Iconify
;
841 if (self
->disabled_decorations
& Decor_Maximize
)
842 self
->decorations
&= ~Decor_Maximize
;
843 if (self
->disabled_decorations
& Decor_AllDesktops
)
844 self
->decorations
&= ~Decor_AllDesktops
;
845 if (self
->disabled_decorations
& Decor_Shade
)
846 self
->decorations
&= ~Decor_Shade
;
847 if (self
->disabled_decorations
& Decor_Close
)
848 self
->decorations
&= ~Decor_Close
;
850 /* if we don't have a titlebar, then we cannot shade! */
851 if (!(self
->decorations
& Decor_Titlebar
))
852 self
->functions
&= ~Func_Shade
;
854 client_change_allowed_actions(self
);
857 /* change the decors on the frame, and with more/less decorations,
858 we may also need to be repositioned */
859 engine_frame_adjust_area(self
->frame
, TRUE
, TRUE
);
860 /* with new decor, the window's maximized size may change */
861 client_remaximize(self
);
865 static void client_change_allowed_actions(Client
*self
)
870 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
872 if (self
->functions
& Func_Shade
)
873 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
874 if (self
->functions
& Func_Close
)
875 actions
[num
++] = prop_atoms
.net_wm_action_close
;
876 if (self
->functions
& Func_Move
)
877 actions
[num
++] = prop_atoms
.net_wm_action_move
;
878 if (self
->functions
& Func_Iconify
)
879 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
880 if (self
->functions
& Func_Resize
)
881 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
882 if (self
->functions
& Func_Fullscreen
)
883 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
884 if (self
->functions
& Func_Maximize
) {
885 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
886 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
889 PROP_SET32A(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
891 /* make sure the window isn't breaking any rules now */
893 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
894 if (self
->frame
) client_shade(self
, FALSE
);
895 else self
->shaded
= FALSE
;
897 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
898 g_message("UNSETTING ICONIC");
899 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
900 else self
->iconic
= FALSE
;
902 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
903 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
904 else self
->fullscreen
= FALSE
;
906 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
908 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
909 else self
->max_vert
= self
->max_horz
= FALSE
;
913 void client_remaximize(Client
*self
)
916 if (self
->max_horz
&& self
->max_vert
)
918 else if (self
->max_horz
)
920 else if (self
->max_vert
)
923 return; /* not maximized */
924 self
->max_horz
= self
->max_vert
= FALSE
;
925 client_maximize(self
, TRUE
, dir
, FALSE
);
928 void client_update_wmhints(Client
*self
)
933 /* assume a window takes input if it doesnt specify */
934 self
->can_focus
= TRUE
;
936 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
937 if (hints
->flags
& InputHint
)
938 self
->can_focus
= hints
->input
;
940 /* only do this when first managing the window *AND* when we aren't
942 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
943 if (hints
->flags
& StateHint
)
944 self
->iconic
= hints
->initial_state
== IconicState
;
946 if (hints
->flags
& XUrgencyHint
)
949 if (hints
->flags
& WindowGroupHint
) {
950 if (hints
->window_group
!= self
->group
) {
951 /* XXX: remove from the old group if there was one */
952 self
->group
= hints
->window_group
;
953 /* XXX: do stuff with the group */
955 } else /* no group! */
958 if (hints
->flags
& IconPixmapHint
) {
959 client_update_kwm_icon(self
);
960 /* try get the kwm icon first, this is a fallback only */
961 if (self
->pixmap_icon
== None
) {
962 self
->pixmap_icon
= hints
->icon_pixmap
;
963 if (hints
->flags
& IconMaskHint
)
964 self
->pixmap_icon_mask
= hints
->icon_mask
;
966 self
->pixmap_icon_mask
= None
;
969 engine_frame_adjust_icon(self
->frame
);
976 if (ur
!= self
->urgent
) {
978 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
980 /* fire the urgent callback if we're mapped, otherwise, wait until
981 after we're mapped */
983 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
987 void client_update_title(Client
*self
)
994 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, data
)) {
995 /* try old x stuff */
996 if (PROP_GETS(self
->window
, wm_name
, string
, data
)) {
997 /* convert it to UTF-8 */
1001 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1003 g_warning("Unable to convert string to UTF-8");
1010 data
= g_strdup("Unnamed Window");
1012 PROP_SETS(self
->window
, net_wm_visible_name
, utf8
, data
);
1018 engine_frame_adjust_title(self
->frame
);
1021 void client_update_icon_title(Client
*self
)
1025 g_free(self
->icon_title
);
1028 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, data
)) {
1029 /* try old x stuff */
1030 if (PROP_GETS(self
->window
, wm_icon_name
, string
, data
)) {
1031 /* convert it to UTF-8 */
1035 u
= g_locale_to_utf8(data
, -1, &r
, &w
, NULL
);
1037 g_warning("Unable to convert string to UTF-8");
1044 data
= g_strdup("Unnamed Window");
1046 PROP_SETS(self
->window
, net_wm_visible_icon_name
, utf8
, data
);
1049 self
->icon_title
= data
;
1052 void client_update_class(Client
*self
)
1058 if (self
->name
) g_free(self
->name
);
1059 if (self
->class) g_free(self
->class);
1060 if (self
->role
) g_free(self
->role
);
1062 self
->name
= self
->class = self
->role
= NULL
;
1064 data
= g_ptr_array_new();
1066 if (PROP_GETSA(self
->window
, wm_class
, string
, data
)) {
1068 self
->name
= g_strdup(g_ptr_array_index(data
, 0));
1070 self
->class = g_strdup(g_ptr_array_index(data
, 1));
1073 for (i
= 0; i
< data
->len
; ++i
)
1074 g_free(g_ptr_array_index(data
, i
));
1075 g_ptr_array_free(data
, TRUE
);
1077 if (PROP_GETS(self
->window
, wm_window_role
, string
, s
))
1078 self
->role
= g_strdup(s
);
1080 if (self
->name
== NULL
) self
->name
= g_strdup("");
1081 if (self
->class == NULL
) self
->class = g_strdup("");
1082 if (self
->role
== NULL
) self
->role
= g_strdup("");
1085 void client_update_strut(Client
*self
)
1089 if (PROP_GET32A(self
->window
, net_wm_strut
, cardinal
, data
, 4)) {
1090 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1093 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1095 /* updating here is pointless while we're being mapped cuz we're not in
1096 the client list yet */
1098 screen_update_struts();
1101 void client_update_icons(Client
*self
)
1104 unsigned long *data
;
1105 unsigned long w
, h
, i
;
1108 for (j
= 0; j
< self
->nicons
; ++j
)
1109 g_free(self
->icons
[j
].data
);
1110 if (self
->nicons
> 0)
1111 g_free(self
->icons
);
1114 if (PROP_GET32U(self
->window
, net_wm_icon
, cardinal
, data
, num
)) {
1115 /* figure out how many valid icons are in here */
1117 while (num
- i
> 2) {
1125 self
->icons
= g_new(Icon
, self
->nicons
);
1127 /* store the icons */
1129 for (j
= 0; j
< self
->nicons
; ++j
) {
1130 w
= self
->icons
[j
].width
= data
[i
++];
1131 h
= self
->icons
[j
].height
= data
[i
++];
1132 self
->icons
[j
].data
=
1133 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1142 engine_frame_adjust_icon(self
->frame
);
1145 void client_update_kwm_icon(Client
*self
)
1149 if (PROP_GET32A(self
->window
, kwm_win_icon
, kwm_win_icon
, data
, 2)) {
1150 self
->pixmap_icon
= data
[0];
1151 self
->pixmap_icon_mask
= data
[1];
1154 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1157 engine_frame_adjust_icon(self
->frame
);
1160 static void client_change_state(Client
*self
)
1162 unsigned long state
[2];
1166 state
[0] = self
->wmstate
;
1168 PROP_SET32A(self
->window
, wm_state
, wm_state
, state
, 2);
1172 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1174 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1176 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1177 if (self
->skip_taskbar
)
1178 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1179 if (self
->skip_pager
)
1180 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1181 if (self
->fullscreen
)
1182 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1184 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1186 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1188 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1190 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1191 PROP_SET32A(self
->window
, net_wm_state
, atom
, netstate
, num
);
1193 client_calc_layer(self
);
1196 engine_frame_adjust_state(self
->frame
);
1199 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1204 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1205 Client
*c
= it
->data
;
1206 if (c
== skip
) continue; /* circular? */
1207 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1208 if (client_focused(c
)) return c
;
1213 void client_calc_layer(Client
*self
)
1219 /* are we fullscreen, or do we have a fullscreen transient parent? */
1223 if (c
->fullscreen
) {
1227 c
= c
->transient_for
;
1229 if (!fs
&& self
->fullscreen
) {
1230 /* is one of our transients focused? */
1231 c
= search_focus_tree(self
, self
);
1232 if (c
!= NULL
) fs
= TRUE
;
1235 if (self
->iconic
) l
= Layer_Icon
;
1236 else if (fs
) l
= Layer_Fullscreen
;
1237 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1238 else if (self
->type
== Type_Dock
) {
1239 if (!self
->below
) l
= Layer_Top
;
1240 else l
= Layer_Normal
;
1242 else if (self
->above
) l
= Layer_Above
;
1243 else if (self
->below
) l
= Layer_Below
;
1244 else l
= Layer_Normal
;
1246 if (l
!= self
->layer
) {
1249 stacking_raise(self
);
1253 gboolean
client_should_show(Client
*self
)
1255 if (self
->iconic
) return FALSE
;
1256 else if (!(self
->desktop
== screen_desktop
||
1257 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1258 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1263 static void client_showhide(Client
*self
)
1266 if (client_should_show(self
))
1267 engine_frame_show(self
->frame
);
1269 engine_frame_hide(self
->frame
);
1272 gboolean
client_normal(Client
*self
) {
1273 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1274 self
->type
== Type_Splash
);
1277 static void client_apply_startup_state(Client
*self
)
1279 /* these are in a carefully crafted order.. */
1282 self
->iconic
= FALSE
;
1283 client_iconify(self
, TRUE
, FALSE
);
1285 if (self
->fullscreen
) {
1286 self
->fullscreen
= FALSE
;
1287 client_fullscreen(self
, TRUE
, FALSE
);
1290 self
->shaded
= FALSE
;
1291 client_shade(self
, TRUE
);
1294 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1296 if (self
->max_vert
&& self
->max_horz
) {
1297 self
->max_vert
= self
->max_horz
= FALSE
;
1298 client_maximize(self
, TRUE
, 0, FALSE
);
1299 } else if (self
->max_vert
) {
1300 self
->max_vert
= FALSE
;
1301 client_maximize(self
, TRUE
, 2, FALSE
);
1302 } else if (self
->max_horz
) {
1303 self
->max_horz
= FALSE
;
1304 client_maximize(self
, TRUE
, 1, FALSE
);
1307 /* nothing to do for the other states:
1316 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1317 gboolean user
, gboolean final
)
1319 gboolean moved
= FALSE
, resized
= FALSE
;
1321 /* gets the frame's position */
1322 frame_client_gravity(self
->frame
, &x
, &y
);
1324 /* these positions are frame positions, not client positions */
1326 /* set the size and position if fullscreen */
1327 if (self
->fullscreen
) {
1330 w
= screen_physical_size
.width
;
1331 h
= screen_physical_size
.height
;
1333 /* set the size and position if maximized */
1334 if (self
->max_horz
) {
1335 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1336 w
= screen_area(self
->desktop
)->width
;
1338 if (self
->max_vert
) {
1339 y
= screen_area(self
->desktop
)->y
;
1340 h
= screen_area(self
->desktop
)->height
-
1341 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1345 /* gets the client's position */
1346 frame_frame_gravity(self
->frame
, &x
, &y
);
1348 /* these override the above states! if you cant move you can't move! */
1350 if (!(self
->functions
& Func_Move
)) {
1354 if (!(self
->functions
& Func_Resize
)) {
1355 w
= self
->area
.width
;
1356 h
= self
->area
.height
;
1360 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1361 w
-= self
->base_size
.width
;
1362 h
-= self
->base_size
.height
;
1365 /* for interactive resizing. have to move half an increment in each
1368 /* how far we are towards the next size inc */
1369 int mw
= w
% self
->size_inc
.width
;
1370 int mh
= h
% self
->size_inc
.height
;
1372 int aw
= self
->size_inc
.width
/ 2;
1373 int ah
= self
->size_inc
.height
/ 2;
1374 /* don't let us move into a new size increment */
1375 if (mw
+ aw
>= self
->size_inc
.width
)
1376 aw
= self
->size_inc
.width
- mw
- 1;
1377 if (mh
+ ah
>= self
->size_inc
.height
)
1378 ah
= self
->size_inc
.height
- mh
- 1;
1382 /* if this is a user-requested resize, then check against min/max
1383 sizes and aspect ratios */
1385 /* smaller than min size or bigger than max size? */
1386 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1387 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1388 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1389 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1391 /* adjust the height ot match the width for the aspect ratios */
1392 if (self
->min_ratio
)
1393 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1394 if (self
->max_ratio
)
1395 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1398 /* keep to the increments */
1399 w
/= self
->size_inc
.width
;
1400 h
/= self
->size_inc
.height
;
1402 /* you cannot resize to nothing */
1406 /* store the logical size */
1407 SIZE_SET(self
->logical_size
, w
, h
);
1409 w
*= self
->size_inc
.width
;
1410 h
*= self
->size_inc
.height
;
1412 w
+= self
->base_size
.width
;
1413 h
+= self
->base_size
.height
;
1417 case Corner_TopLeft
:
1419 case Corner_TopRight
:
1420 x
-= w
- self
->area
.width
;
1422 case Corner_BottomLeft
:
1423 y
-= h
- self
->area
.height
;
1425 case Corner_BottomRight
:
1426 x
-= w
- self
->area
.width
;
1427 y
-= h
- self
->area
.height
;
1431 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1432 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1434 RECT_SET(self
->area
, x
, y
, w
, h
);
1437 XResizeWindow(ob_display
, self
->window
, w
, h
);
1439 /* move/resize the frame to match the request */
1441 if (moved
|| resized
)
1442 engine_frame_adjust_area(self
->frame
, moved
, resized
);
1444 if (!user
|| final
) {
1446 event
.type
= ConfigureNotify
;
1447 event
.xconfigure
.display
= ob_display
;
1448 event
.xconfigure
.event
= self
->window
;
1449 event
.xconfigure
.window
= self
->window
;
1451 /* root window coords with border in mind */
1452 event
.xconfigure
.x
= x
- self
->border_width
+
1453 self
->frame
->size
.left
;
1454 event
.xconfigure
.y
= y
- self
->border_width
+
1455 self
->frame
->size
.top
;
1457 event
.xconfigure
.width
= self
->area
.width
;
1458 event
.xconfigure
.height
= self
->area
.height
;
1459 event
.xconfigure
.border_width
= self
->border_width
;
1460 event
.xconfigure
.above
= self
->frame
->plate
;
1461 event
.xconfigure
.override_redirect
= FALSE
;
1462 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1463 FALSE
, StructureNotifyMask
, &event
);
1468 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1472 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1473 self
->fullscreen
== fs
) return; /* already done */
1475 self
->fullscreen
= fs
;
1476 client_change_state(self
); /* change the state hints on the client */
1479 /* save the functions and remove them */
1480 self
->pre_fs_func
= self
->functions
;
1481 self
->functions
&= (Func_Close
| Func_Fullscreen
|
1483 /* save the decorations and remove them */
1484 self
->pre_fs_decor
= self
->decorations
;
1485 self
->decorations
= 0;
1488 dimensions
[0] = self
->area
.x
;
1489 dimensions
[1] = self
->area
.y
;
1490 dimensions
[2] = self
->area
.width
;
1491 dimensions
[3] = self
->area
.height
;
1493 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1497 /* these are not actually used cuz client_configure will set them
1498 as appropriate when the window is fullscreened */
1503 self
->functions
= self
->pre_fs_func
;
1504 self
->decorations
= self
->pre_fs_decor
;
1506 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1514 /* pick some fallbacks... */
1515 x
= screen_area(self
->desktop
)->x
+
1516 screen_area(self
->desktop
)->width
/ 4;
1517 y
= screen_area(self
->desktop
)->y
+
1518 screen_area(self
->desktop
)->height
/ 4;
1519 w
= screen_area(self
->desktop
)->width
/ 2;
1520 h
= screen_area(self
->desktop
)->height
/ 2;
1524 client_change_allowed_actions(self
); /* based on the new _functions */
1526 /* when fullscreening, don't obey things like increments, fill the
1528 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, !fs
, TRUE
);
1530 /* raise (back) into our stacking layer */
1531 stacking_raise(self
);
1533 /* try focus us when we go into fullscreen mode */
1537 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1539 if (self
->iconic
== iconic
) return; /* nothing to do */
1541 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1544 self
->iconic
= iconic
;
1547 self
->wmstate
= IconicState
;
1548 self
->ignore_unmaps
++;
1549 /* we unmap the client itself so that we can get MapRequest events,
1550 and because the ICCCM tells us to! */
1551 XUnmapWindow(ob_display
, self
->window
);
1554 client_set_desktop(self
, screen_desktop
, FALSE
);
1555 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1556 XMapWindow(ob_display
, self
->window
);
1558 client_change_state(self
);
1559 client_showhide(self
);
1560 screen_update_struts();
1562 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1566 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1570 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1571 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1573 /* check if already done */
1575 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1576 if (dir
== 1 && self
->max_horz
) return;
1577 if (dir
== 2 && self
->max_vert
) return;
1579 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1580 if (dir
== 1 && !self
->max_horz
) return;
1581 if (dir
== 2 && !self
->max_vert
) return;
1584 /* work with the frame's coords */
1585 x
= self
->frame
->area
.x
;
1586 y
= self
->frame
->area
.y
;
1587 w
= self
->area
.width
;
1588 h
= self
->area
.height
;
1600 /* get the property off the window and use it for the dimensions
1601 we are already maxed on */
1602 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1604 if (self
->max_horz
) {
1605 dimensions
[0] = readdim
[0];
1606 dimensions
[2] = readdim
[2];
1608 if (self
->max_vert
) {
1609 dimensions
[1] = readdim
[1];
1610 dimensions
[3] = readdim
[3];
1615 PROP_SET32A(self
->window
, openbox_premax
, cardinal
,
1621 if (PROP_GET32A(self
->window
, openbox_premax
, cardinal
,
1623 if (dir
== 0 || dir
== 1) { /* horz */
1627 if (dir
== 0 || dir
== 2) { /* vert */
1633 /* pick some fallbacks... */
1634 if (dir
== 0 || dir
== 1) { /* horz */
1635 x
= screen_area(self
->desktop
)->x
+
1636 screen_area(self
->desktop
)->width
/ 4;
1637 w
= screen_area(self
->desktop
)->width
/ 2;
1639 if (dir
== 0 || dir
== 2) { /* vert */
1640 y
= screen_area(self
->desktop
)->y
+
1641 screen_area(self
->desktop
)->height
/ 4;
1642 h
= screen_area(self
->desktop
)->height
/ 2;
1647 if (dir
== 0 || dir
== 1) /* horz */
1648 self
->max_horz
= max
;
1649 if (dir
== 0 || dir
== 2) /* vert */
1650 self
->max_vert
= max
;
1652 if (!self
->max_horz
&& !self
->max_vert
)
1653 PROP_ERASE(self
->window
, openbox_premax
);
1655 client_change_state(self
); /* change the state hints on the client */
1657 /* figure out where the client should be going */
1658 frame_frame_gravity(self
->frame
, &x
, &y
);
1659 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1662 void client_shade(Client
*self
, gboolean shade
)
1664 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1665 self
->shaded
== shade
) return; /* already done */
1667 /* when we're iconic, don't change the wmstate */
1669 self
->wmstate
= shade
? IconicState
: NormalState
;
1670 self
->shaded
= shade
;
1671 client_change_state(self
);
1672 /* resize the frame to just the titlebar */
1673 engine_frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1676 void client_close(Client
*self
)
1680 if (!(self
->functions
& Func_Close
)) return;
1683 XXX: itd be cool to do timeouts and shit here for killing the client's
1685 like... if the window is around after 5 seconds, then the close button
1686 turns a nice red, and if this function is called again, the client is
1690 ce
.xclient
.type
= ClientMessage
;
1691 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1692 ce
.xclient
.display
= ob_display
;
1693 ce
.xclient
.window
= self
->window
;
1694 ce
.xclient
.format
= 32;
1695 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1696 ce
.xclient
.data
.l
[1] = event_lasttime
;
1697 ce
.xclient
.data
.l
[2] = 0l;
1698 ce
.xclient
.data
.l
[3] = 0l;
1699 ce
.xclient
.data
.l
[4] = 0l;
1700 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1703 void client_kill(Client
*self
)
1705 XKillClient(ob_display
, self
->window
);
1708 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1711 ConfigValue focus_new
;
1713 if (target
== self
->desktop
) return;
1715 g_message("Setting desktop %u", target
);
1717 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1719 old
= self
->desktop
;
1720 self
->desktop
= target
;
1721 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1722 /* the frame can display the current desktop state */
1723 engine_frame_adjust_state(self
->frame
);
1724 /* 'move' the window to the new desktop */
1726 client_showhide(self
);
1727 /* raise if it was not already on the desktop */
1728 if (old
!= DESKTOP_ALL
)
1729 stacking_raise(self
);
1730 screen_update_struts();
1732 /* update the focus lists */
1733 if (!config_get("focusNew", Config_Bool
, &focus_new
))
1734 g_assert_not_reached();
1735 if (old
== DESKTOP_ALL
) {
1736 for (i
= 0; i
< screen_num_desktops
; ++i
)
1737 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1739 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1740 if (target
== DESKTOP_ALL
) {
1741 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1743 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1745 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1749 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1751 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1754 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1757 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1762 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1763 Client
*c
= it
->data
;
1764 if (c
== skip
) continue; /* circular? */
1765 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1766 if (c
->modal
) return c
;
1771 Client
*client_find_modal_child(Client
*self
)
1773 return search_modal_tree(self
, self
);
1776 gboolean
client_validate(Client
*self
)
1780 XSync(ob_display
, FALSE
); /* get all events on the server */
1782 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1783 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1784 XPutBackEvent(ob_display
, &e
);
1791 void client_set_wm_state(Client
*self
, long state
)
1793 if (state
== self
->wmstate
) return; /* no change */
1797 client_iconify(self
, TRUE
, TRUE
);
1800 client_iconify(self
, FALSE
, TRUE
);
1805 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1807 gboolean shaded
= self
->shaded
;
1808 gboolean fullscreen
= self
->fullscreen
;
1809 gboolean max_horz
= self
->max_horz
;
1810 gboolean max_vert
= self
->max_vert
;
1813 if (!(action
== prop_atoms
.net_wm_state_add
||
1814 action
== prop_atoms
.net_wm_state_remove
||
1815 action
== prop_atoms
.net_wm_state_toggle
))
1816 /* an invalid action was passed to the client message, ignore it */
1819 for (i
= 0; i
< 2; ++i
) {
1820 Atom state
= i
== 0 ? data1
: data2
;
1822 if (!state
) continue;
1824 /* if toggling, then pick whether we're adding or removing */
1825 if (action
== prop_atoms
.net_wm_state_toggle
) {
1826 if (state
== prop_atoms
.net_wm_state_modal
)
1827 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
1828 prop_atoms
.net_wm_state_add
;
1829 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
1830 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
1831 prop_atoms
.net_wm_state_add
;
1832 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
1833 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
1834 prop_atoms
.net_wm_state_add
;
1835 else if (state
== prop_atoms
.net_wm_state_shaded
)
1836 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
1837 prop_atoms
.net_wm_state_add
;
1838 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
1839 action
= self
->skip_taskbar
?
1840 prop_atoms
.net_wm_state_remove
:
1841 prop_atoms
.net_wm_state_add
;
1842 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
1843 action
= self
->skip_pager
?
1844 prop_atoms
.net_wm_state_remove
:
1845 prop_atoms
.net_wm_state_add
;
1846 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
1847 action
= self
->fullscreen
?
1848 prop_atoms
.net_wm_state_remove
:
1849 prop_atoms
.net_wm_state_add
;
1850 else if (state
== prop_atoms
.net_wm_state_above
)
1851 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
1852 prop_atoms
.net_wm_state_add
;
1853 else if (state
== prop_atoms
.net_wm_state_below
)
1854 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
1855 prop_atoms
.net_wm_state_add
;
1858 if (action
== prop_atoms
.net_wm_state_add
) {
1859 if (state
== prop_atoms
.net_wm_state_modal
) {
1860 /* XXX raise here or something? */
1862 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1864 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1866 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1868 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1869 self
->skip_taskbar
= TRUE
;
1870 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1871 self
->skip_pager
= TRUE
;
1872 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1874 } else if (state
== prop_atoms
.net_wm_state_above
) {
1876 } else if (state
== prop_atoms
.net_wm_state_below
) {
1880 } else { /* action == prop_atoms.net_wm_state_remove */
1881 if (state
== prop_atoms
.net_wm_state_modal
) {
1882 self
->modal
= FALSE
;
1883 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
1885 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
1887 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
1889 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
1890 self
->skip_taskbar
= FALSE
;
1891 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
1892 self
->skip_pager
= FALSE
;
1893 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
1895 } else if (state
== prop_atoms
.net_wm_state_above
) {
1896 self
->above
= FALSE
;
1897 } else if (state
== prop_atoms
.net_wm_state_below
) {
1898 self
->below
= FALSE
;
1902 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
1903 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
1905 if (max_horz
== max_vert
) { /* both going the same way */
1906 client_maximize(self
, max_horz
, 0, TRUE
);
1908 client_maximize(self
, max_horz
, 1, TRUE
);
1909 client_maximize(self
, max_vert
, 2, TRUE
);
1913 if (max_horz
!= self
->max_horz
)
1914 client_maximize(self
, max_horz
, 1, TRUE
);
1916 client_maximize(self
, max_vert
, 2, TRUE
);
1919 /* change fullscreen state before shading, as it will affect if the window
1921 if (fullscreen
!= self
->fullscreen
)
1922 client_fullscreen(self
, fullscreen
, TRUE
);
1923 if (shaded
!= self
->shaded
)
1924 client_shade(self
, shaded
);
1925 client_calc_layer(self
);
1926 client_change_state(self
); /* change the hint to relect these changes */
1929 gboolean
client_focus(Client
*self
)
1934 /* if we have a modal child, then focus it, not us */
1935 child
= client_find_modal_child(self
);
1937 return client_focus(child
);
1939 /* won't try focus if the client doesn't want it, or if the window isn't
1940 visible on the screen */
1941 if (!(self
->frame
->visible
&&
1942 (self
->can_focus
|| self
->focus_notify
)))
1945 /* do a check to see if the window has already been unmapped or destroyed
1946 do this intelligently while watching out for unmaps we've generated
1947 (ignore_unmaps > 0) */
1948 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
1949 DestroyNotify
, &ev
)) {
1950 XPutBackEvent(ob_display
, &ev
);
1953 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
1954 UnmapNotify
, &ev
)) {
1955 if (self
->ignore_unmaps
) {
1956 self
->ignore_unmaps
--;
1958 XPutBackEvent(ob_display
, &ev
);
1963 if (self
->can_focus
)
1964 /* RevertToPointerRoot causes much more headache than TevertToNone, so
1965 I choose to use it always, hopefully to find errors quicker, if any
1966 are left. (I hate X. I hate focus events.) */
1967 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
1970 if (self
->focus_notify
) {
1972 ce
.xclient
.type
= ClientMessage
;
1973 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1974 ce
.xclient
.display
= ob_display
;
1975 ce
.xclient
.window
= self
->window
;
1976 ce
.xclient
.format
= 32;
1977 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
1978 ce
.xclient
.data
.l
[1] = event_lasttime
;
1979 ce
.xclient
.data
.l
[2] = 0l;
1980 ce
.xclient
.data
.l
[3] = 0l;
1981 ce
.xclient
.data
.l
[4] = 0l;
1982 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1985 g_message("focusing %lx", self
->window
);
1987 /* Cause the FocusIn to come back to us. Important for desktop switches,
1988 since otherwise we'll have no FocusIn on the queue and send it off to
1989 the focus_backup. */
1990 XSync(ob_display
, FALSE
);
1994 void client_unfocus(Client
*self
)
1996 g_assert(focus_client
== self
);
1997 focus_fallback(FALSE
);
2000 gboolean
client_focused(Client
*self
)
2002 return self
== focus_client
;
2005 Icon
*client_icon(Client
*self
, int w
, int h
)
2008 /* si is the smallest image >= req */
2009 /* li is the largest image < req */
2010 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2012 if (!self
->nicons
) return NULL
;
2014 for (i
= 0; i
< self
->nicons
; ++i
) {
2015 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2016 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2020 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2025 if (largest
== 0) /* didnt find one smaller than the requested size */
2026 return &self
->icons
[si
];
2027 return &self
->icons
[li
];