7 #include "moveresize.h"
10 #include "extensions.h"
20 #include "menuframe.h"
23 #include "render/render.h"
26 #include <X11/Xutil.h>
28 /*! The event mask to grab on client windows */
29 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
32 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
35 GList
*client_list
= NULL
;
36 GSList
*client_destructors
= NULL
;
38 static void client_get_all(ObClient
*self
);
39 static void client_toggle_border(ObClient
*self
, gboolean show
);
40 static void client_get_area(ObClient
*self
);
41 static void client_get_desktop(ObClient
*self
);
42 static void client_get_state(ObClient
*self
);
43 static void client_get_shaped(ObClient
*self
);
44 static void client_get_mwm_hints(ObClient
*self
);
45 static void client_get_gravity(ObClient
*self
);
46 static void client_showhide(ObClient
*self
);
47 static void client_change_allowed_actions(ObClient
*self
);
48 static void client_change_state(ObClient
*self
);
49 static void client_apply_startup_state(ObClient
*self
);
50 static void client_restore_session_state(ObClient
*self
);
51 static void client_restore_session_stacking(ObClient
*self
);
52 static void client_urgent_notify(ObClient
*self
);
54 void client_startup(gboolean reconfig
)
61 void client_shutdown(gboolean reconfig
)
65 void client_add_destructor(GDestroyNotify func
)
67 client_destructors
= g_slist_prepend(client_destructors
, (gpointer
)func
);
70 void client_remove_destructor(GDestroyNotify func
)
72 client_destructors
= g_slist_remove(client_destructors
, (gpointer
)func
);
75 void client_set_list()
77 Window
*windows
, *win_it
;
79 guint size
= g_list_length(client_list
);
81 /* create an array of the window ids */
83 windows
= g_new(Window
, size
);
85 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
86 *win_it
= ((ObClient
*)it
->data
)->window
;
90 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
91 net_client_list
, window
, (guint32
*)windows
, size
);
100 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
104 for (it = self->transients; it; it = it->next) {
105 if (!func(it->data, data)) return;
106 client_foreach_transient(it->data, func, data);
110 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
112 if (self->transient_for) {
113 if (self->transient_for != OB_TRAN_GROUP) {
114 if (!func(self->transient_for, data)) return;
115 client_foreach_ancestor(self->transient_for, func, data);
119 for (it = self->group->members; it; it = it->next)
120 if (it->data != self &&
121 !((ObClient*)it->data)->transient_for) {
122 if (!func(it->data, data)) return;
123 client_foreach_ancestor(it->data, func, data);
130 void client_manage_all()
132 unsigned int i
, j
, nchild
;
135 XWindowAttributes attrib
;
137 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
138 &w
, &w
, &children
, &nchild
);
140 /* remove all icon windows from the list */
141 for (i
= 0; i
< nchild
; i
++) {
142 if (children
[i
] == None
) continue;
143 wmhints
= XGetWMHints(ob_display
, children
[i
]);
145 if ((wmhints
->flags
& IconWindowHint
) &&
146 (wmhints
->icon_window
!= children
[i
]))
147 for (j
= 0; j
< nchild
; j
++)
148 if (children
[j
] == wmhints
->icon_window
) {
156 for (i
= 0; i
< nchild
; ++i
) {
157 if (children
[i
] == None
)
159 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
160 if (attrib
.override_redirect
) continue;
162 if (attrib
.map_state
!= IsUnmapped
)
163 client_manage(children
[i
]);
168 /* stack them as they were on startup!
169 why with stacking_lower? Why, because then windows who aren't in the
170 stacking list are on the top where you can see them instead of buried
172 for (i
= startup_stack_size
; i
> 0; --i
) {
175 w
= startup_stack_order
[i
-1];
176 obw
= g_hash_table_lookup(window_map
, &w
);
178 g_assert(WINDOW_IS_CLIENT(obw
));
179 stacking_lower(CLIENT_AS_WINDOW(obw
));
182 g_free(startup_stack_order
);
183 startup_stack_order
= NULL
;
184 startup_stack_size
= 0;
186 if (config_focus_new
) {
189 active
= g_hash_table_lookup(window_map
, &startup_active
);
191 g_assert(WINDOW_IS_CLIENT(active
));
192 if (!client_focus(WINDOW_AS_CLIENT(active
)))
193 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
195 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
199 void client_manage(Window window
)
203 XWindowAttributes attrib
;
204 XSetWindowAttributes attrib_set
;
206 gboolean activate
= FALSE
;
210 /* check if it has already been unmapped by the time we started mapping
211 the grab does a sync so we don't have to here */
212 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
213 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
214 XPutBackEvent(ob_display
, &e
);
217 return; /* don't manage it */
220 /* make sure it isn't an override-redirect window */
221 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
222 attrib
.override_redirect
) {
224 return; /* don't manage it */
227 /* is the window a docking app */
228 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
229 if ((wmhint
->flags
& StateHint
) &&
230 wmhint
->initial_state
== WithdrawnState
) {
231 dock_add(window
, wmhint
);
239 ob_debug("Managing window: %lx\n", window
);
241 /* choose the events we want to receive on the CLIENT window */
242 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
243 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
244 XChangeWindowAttributes(ob_display
, window
,
245 CWEventMask
|CWDontPropagate
, &attrib_set
);
248 /* create the ObClient struct, and populate it from the hints on the
250 self
= g_new0(ObClient
, 1);
251 self
->obwin
.type
= Window_Client
;
252 self
->window
= window
;
254 client_get_all(self
);
255 client_restore_session_state(self
);
257 client_change_state(self
);
259 /* remove the client's border (and adjust re gravity) */
260 client_toggle_border(self
, FALSE
);
262 /* specify that if we exit, the window should not be destroyed and should
263 be reparented back to root automatically */
264 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
266 /* create the decoration frame for the client window */
267 self
->frame
= frame_new();
269 frame_grab_client(self
->frame
, self
);
273 client_apply_startup_state(self
);
275 /* update the focus lists */
276 focus_order_add_new(self
);
278 stacking_add(CLIENT_AS_WINDOW(self
));
279 client_restore_session_stacking(self
);
281 /* focus the new window? */
282 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
283 /* note the check against Type_Normal/Dialog, not client_normal(self),
284 which would also include other types. in this case we want more
285 strict rules for focus */
286 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
287 self
->type
== OB_CLIENT_TYPE_DIALOG
))
291 if (self
->desktop
!= screen_desktop
) {
292 /* activate the window */
295 gboolean group_foc
= FALSE
;
300 for (it
= self
->group
->members
; it
; it
= it
->next
)
302 if (client_focused(it
->data
))
310 (!self
->transient_for
&& (!self
->group
||
311 !self
->group
->members
->next
))) ||
312 client_search_focus_tree_full(self
) ||
314 !client_normal(focus_client
))
316 /* activate the window */
323 if (ob_state() == OB_STATE_RUNNING
) {
324 int x
= self
->area
.x
, ox
= x
;
325 int y
= self
->area
.y
, oy
= y
;
327 place_client(self
, &x
, &y
);
329 /* make sure the window is visible */
330 client_find_onscreen(self
, &x
, &y
,
331 self
->frame
->area
.width
,
332 self
->frame
->area
.height
,
333 client_normal(self
));
335 if (x
!= ox
|| y
!= oy
)
336 client_move(self
, x
, y
);
339 client_showhide(self
);
341 /* use client_focus instead of client_activate cuz client_activate does
342 stuff like switch desktops etc and I'm not interested in all that when
343 a window maps since its not based on an action from the user like
344 clicking a window to activate is. so keep the new window out of the way
346 if (activate
) client_focus(self
);
348 /* client_activate does this but we aret using it so we have to do it
350 if (screen_showing_desktop
)
351 screen_show_desktop(FALSE
);
353 /* add to client list/map */
354 client_list
= g_list_append(client_list
, self
);
355 g_hash_table_insert(window_map
, &self
->window
, self
);
357 /* this has to happen after we're in the client_list */
358 screen_update_areas();
360 /* update the list hints */
363 keyboard_grab_for_client(self
, TRUE
);
364 mouse_grab_for_client(self
, TRUE
);
366 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
369 void client_unmanage_all()
371 while (client_list
!= NULL
)
372 client_unmanage(client_list
->data
);
375 void client_unmanage(ObClient
*self
)
380 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
382 g_assert(self
!= NULL
);
384 keyboard_grab_for_client(self
, FALSE
);
385 mouse_grab_for_client(self
, FALSE
);
387 /* remove the window from our save set */
388 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
390 /* we dont want events no more */
391 XSelectInput(ob_display
, self
->window
, NoEventMask
);
393 frame_hide(self
->frame
);
395 client_list
= g_list_remove(client_list
, self
);
396 stacking_remove(self
);
397 g_hash_table_remove(window_map
, &self
->window
);
399 /* update the focus lists */
400 focus_order_remove(self
);
402 /* once the client is out of the list, update the struts to remove it's
404 screen_update_areas();
406 /* tell our parent(s) that we're gone */
407 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
410 for (it
= self
->group
->members
; it
; it
= it
->next
)
411 if (it
->data
!= self
)
412 ((ObClient
*)it
->data
)->transients
=
413 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
414 } else if (self
->transient_for
) { /* transient of window */
415 self
->transient_for
->transients
=
416 g_slist_remove(self
->transient_for
->transients
, self
);
419 /* tell our transients that we're gone */
420 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
421 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
422 ((ObClient
*)it
->data
)->transient_for
= NULL
;
423 client_calc_layer(it
->data
);
427 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
428 GDestroyNotify func
= (GDestroyNotify
) it
->data
;
432 if (focus_client
== self
) {
435 /* focus the last focused window on the desktop, and ignore enter
436 events from the unmap so it doesnt mess with the focus */
437 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
438 client_unfocus(self
);
441 /* remove from its group */
443 group_remove(self
->group
, self
);
447 /* give the client its border back */
448 client_toggle_border(self
, TRUE
);
450 /* reparent the window out of the frame, and free the frame */
451 frame_release_client(self
->frame
, self
);
454 if (ob_state() != OB_STATE_EXITING
) {
455 /* these values should not be persisted across a window
457 PROP_ERASE(self
->window
, net_wm_desktop
);
458 PROP_ERASE(self
->window
, net_wm_state
);
459 PROP_ERASE(self
->window
, wm_state
);
461 /* if we're left in an iconic state, the client wont be mapped. this is
462 bad, since we will no longer be managing the window on restart */
464 XMapWindow(ob_display
, self
->window
);
468 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
470 /* free all data allocated in the client struct */
471 g_slist_free(self
->transients
);
472 for (j
= 0; j
< self
->nicons
; ++j
)
473 g_free(self
->icons
[j
].data
);
474 if (self
->nicons
> 0)
477 g_free(self
->icon_title
);
483 /* update the list hints */
487 static void client_urgent_notify(ObClient
*self
)
490 frame_flash_start(self
->frame
);
492 frame_flash_stop(self
->frame
);
495 static void client_restore_session_state(ObClient
*self
)
499 if (!(it
= session_state_find(self
)))
502 self
->session
= it
->data
;
504 RECT_SET(self
->area
, self
->session
->x
, self
->session
->y
,
505 self
->session
->w
, self
->session
->h
);
506 self
->positioned
= TRUE
;
507 XResizeWindow(ob_display
, self
->window
,
508 self
->session
->w
, self
->session
->h
);
510 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
511 self
->session
->desktop
:
512 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
513 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
515 self
->shaded
= self
->session
->shaded
;
516 self
->iconic
= self
->session
->iconic
;
517 self
->skip_pager
= self
->session
->skip_pager
;
518 self
->skip_taskbar
= self
->session
->skip_taskbar
;
519 self
->fullscreen
= self
->session
->fullscreen
;
520 self
->above
= self
->session
->above
;
521 self
->below
= self
->session
->below
;
522 self
->max_horz
= self
->session
->max_horz
;
523 self
->max_vert
= self
->session
->max_vert
;
526 static void client_restore_session_stacking(ObClient
*self
)
530 if (!self
->session
) return;
532 it
= g_list_find(session_saved_state
, self
->session
);
533 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
536 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
537 if (session_state_cmp(it
->data
, cit
->data
))
540 client_calc_layer(self
);
541 stacking_below(CLIENT_AS_WINDOW(self
),
542 CLIENT_AS_WINDOW(cit
->data
));
548 void client_move_onscreen(ObClient
*self
, gboolean rude
)
550 int x
= self
->area
.x
;
551 int y
= self
->area
.y
;
552 if (client_find_onscreen(self
, &x
, &y
,
553 self
->frame
->area
.width
,
554 self
->frame
->area
.height
, rude
)) {
555 client_move(self
, x
, y
);
559 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
563 int ox
= *x
, oy
= *y
;
565 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
568 /* XXX watch for xinerama dead areas */
570 a
= screen_area(self
->desktop
);
571 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
572 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
573 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
574 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
575 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
577 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
581 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
582 Java can suck it too. */
584 /* dont let windows map/move into the strut unless they
585 are bigger than the available area */
587 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
588 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
589 *x
= a
->x
+ a
->width
- w
;
591 if (h
<= a
->height
) {
592 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
593 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
594 *y
= a
->y
+ a
->height
- h
;
598 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
601 return ox
!= *x
|| oy
!= *y
;
604 static void client_toggle_border(ObClient
*self
, gboolean show
)
606 /* adjust our idea of where the client is, based on its border. When the
607 border is removed, the client should now be considered to be in a
609 when re-adding the border to the client, the same operation needs to be
611 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
612 int x
= oldx
, y
= oldy
;
613 switch(self
->gravity
) {
615 case NorthWestGravity
:
617 case SouthWestGravity
:
619 case NorthEastGravity
:
621 case SouthEastGravity
:
622 if (show
) x
-= self
->border_width
* 2;
623 else x
+= self
->border_width
* 2;
630 if (show
) x
-= self
->border_width
;
631 else x
+= self
->border_width
;
634 switch(self
->gravity
) {
636 case NorthWestGravity
:
638 case NorthEastGravity
:
640 case SouthWestGravity
:
642 case SouthEastGravity
:
643 if (show
) y
-= self
->border_width
* 2;
644 else y
+= self
->border_width
* 2;
651 if (show
) y
-= self
->border_width
;
652 else y
+= self
->border_width
;
659 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
661 /* move the client so it is back it the right spot _with_ its
663 if (x
!= oldx
|| y
!= oldy
)
664 XMoveWindow(ob_display
, self
->window
, x
, y
);
666 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
670 static void client_get_all(ObClient
*self
)
672 /* non-zero defaults */
673 self
->title_count
= 1;
674 self
->wmstate
= NormalState
;
676 self
->decorate
= TRUE
;
678 client_get_area(self
);
679 client_update_transient_for(self
);
680 client_update_wmhints(self
);
681 client_get_desktop(self
);
682 client_get_state(self
);
683 client_get_shaped(self
);
685 client_get_mwm_hints(self
);
686 client_get_type(self
);/* this can change the mwmhints for special cases */
688 client_update_protocols(self
);
690 client_get_gravity(self
); /* get the attribute gravity */
691 client_update_normal_hints(self
); /* this may override the attribute
694 /* got the type, the mwmhints, the protocols, and the normal hints
695 (min/max sizes), so we're ready to set up the decorations/functions */
696 client_setup_decor_and_functions(self
);
698 client_update_title(self
);
699 client_update_class(self
);
700 client_update_strut(self
);
701 client_update_icons(self
);
704 static void client_get_area(ObClient
*self
)
706 XWindowAttributes wattrib
;
709 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
710 g_assert(ret
!= BadWindow
);
712 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
713 self
->border_width
= wattrib
.border_width
;
716 static void client_get_desktop(ObClient
*self
)
718 guint32 d
= screen_num_desktops
; /* an always-invalid value */
720 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
721 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
722 self
->desktop
= screen_num_desktops
- 1;
726 gboolean trdesk
= FALSE
;
728 if (self
->transient_for
) {
729 if (self
->transient_for
!= OB_TRAN_GROUP
) {
730 self
->desktop
= self
->transient_for
->desktop
;
735 for (it
= self
->group
->members
; it
; it
= it
->next
)
736 if (it
->data
!= self
&&
737 !((ObClient
*)it
->data
)->transient_for
) {
738 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
745 /* defaults to the current desktop */
746 self
->desktop
= screen_desktop
;
748 if (self
->desktop
!= d
) {
749 /* set the desktop hint, to make sure that it always exists */
750 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
754 static void client_get_state(ObClient
*self
)
759 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
760 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
761 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
763 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
765 for (i
= 0; i
< num
; ++i
) {
766 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
768 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
770 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
772 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
773 self
->skip_taskbar
= TRUE
;
774 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
775 self
->skip_pager
= TRUE
;
776 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
777 self
->fullscreen
= TRUE
;
778 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
779 self
->max_vert
= TRUE
;
780 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
781 self
->max_horz
= TRUE
;
782 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
784 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
792 static void client_get_shaped(ObClient
*self
)
794 self
->shaped
= FALSE
;
796 if (extensions_shape
) {
801 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
803 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
804 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
806 self
->shaped
= (s
!= 0);
811 void client_update_transient_for(ObClient
*self
)
814 ObClient
*target
= NULL
;
816 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
817 self
->transient
= TRUE
;
818 if (t
!= self
->window
) { /* cant be transient to itself! */
819 target
= g_hash_table_lookup(window_map
, &t
);
820 /* if this happens then we need to check for it*/
821 g_assert(target
!= self
);
822 g_assert(!target
|| WINDOW_IS_CLIENT(target
));
824 if (!target
&& self
->group
) {
825 /* not transient to a client, see if it is transient for a
827 if (t
== self
->group
->leader
||
829 t
== RootWindow(ob_display
, ob_screen
)) {
830 /* window is a transient for its group! */
831 target
= OB_TRAN_GROUP
;
836 self
->transient
= FALSE
;
838 /* if anything has changed... */
839 if (target
!= self
->transient_for
) {
840 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
843 /* remove from old parents */
844 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
845 ObClient
*c
= it
->data
;
846 if (c
!= self
&& !c
->transient_for
)
847 c
->transients
= g_slist_remove(c
->transients
, self
);
849 } else if (self
->transient_for
!= NULL
) { /* transient of window */
850 /* remove from old parent */
851 self
->transient_for
->transients
=
852 g_slist_remove(self
->transient_for
->transients
, self
);
854 self
->transient_for
= target
;
855 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
858 /* add to new parents */
859 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
860 ObClient
*c
= it
->data
;
861 if (c
!= self
&& !c
->transient_for
)
862 c
->transients
= g_slist_append(c
->transients
, self
);
865 /* remove all transients which are in the group, that causes
866 circlular pointer hell of doom */
867 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
869 for (sit
= self
->transients
; sit
; sit
= next
) {
870 next
= g_slist_next(sit
);
871 if (sit
->data
== it
->data
)
873 g_slist_delete_link(self
->transients
, sit
);
876 } else if (self
->transient_for
!= NULL
) { /* transient of window */
877 /* add to new parent */
878 self
->transient_for
->transients
=
879 g_slist_append(self
->transient_for
->transients
, self
);
884 static void client_get_mwm_hints(ObClient
*self
)
889 self
->mwmhints
.flags
= 0; /* default to none */
891 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
893 if (num
>= OB_MWM_ELEMENTS
) {
894 self
->mwmhints
.flags
= hints
[0];
895 self
->mwmhints
.functions
= hints
[1];
896 self
->mwmhints
.decorations
= hints
[2];
902 void client_get_type(ObClient
*self
)
909 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
910 /* use the first value that we know about in the array */
911 for (i
= 0; i
< num
; ++i
) {
912 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
913 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
914 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
915 self
->type
= OB_CLIENT_TYPE_DOCK
;
916 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
917 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
918 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
919 self
->type
= OB_CLIENT_TYPE_MENU
;
920 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
921 self
->type
= OB_CLIENT_TYPE_UTILITY
;
922 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
923 self
->type
= OB_CLIENT_TYPE_SPLASH
;
924 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
925 self
->type
= OB_CLIENT_TYPE_DIALOG
;
926 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
927 self
->type
= OB_CLIENT_TYPE_NORMAL
;
928 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
929 /* prevent this window from getting any decor or
931 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
932 OB_MWM_FLAG_DECORATIONS
);
933 self
->mwmhints
.decorations
= 0;
934 self
->mwmhints
.functions
= 0;
936 if (self
->type
!= (ObClientType
) -1)
937 break; /* grab the first legit type */
942 if (self
->type
== (ObClientType
) -1) {
943 /*the window type hint was not set, which means we either classify
944 ourself as a normal window or a dialog, depending on if we are a
947 self
->type
= OB_CLIENT_TYPE_DIALOG
;
949 self
->type
= OB_CLIENT_TYPE_NORMAL
;
953 void client_update_protocols(ObClient
*self
)
958 self
->focus_notify
= FALSE
;
959 self
->delete_window
= FALSE
;
961 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
962 for (i
= 0; i
< num_return
; ++i
) {
963 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
964 /* this means we can request the window to close */
965 self
->delete_window
= TRUE
;
966 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
967 /* if this protocol is requested, then the window will be
968 notified whenever we want it to receive focus */
969 self
->focus_notify
= TRUE
;
975 static void client_get_gravity(ObClient
*self
)
977 XWindowAttributes wattrib
;
980 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
981 g_assert(ret
!= BadWindow
);
982 self
->gravity
= wattrib
.win_gravity
;
985 void client_update_normal_hints(ObClient
*self
)
989 int oldgravity
= self
->gravity
;
992 self
->min_ratio
= 0.0f
;
993 self
->max_ratio
= 0.0f
;
994 SIZE_SET(self
->size_inc
, 1, 1);
995 SIZE_SET(self
->base_size
, 0, 0);
996 SIZE_SET(self
->min_size
, 0, 0);
997 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
999 /* get the hints from the window */
1000 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1001 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1003 if (size
.flags
& PWinGravity
) {
1004 self
->gravity
= size
.win_gravity
;
1006 /* if the client has a frame, i.e. has already been mapped and
1007 is changing its gravity */
1008 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1009 /* move our idea of the client's position based on its new
1011 self
->area
.x
= self
->frame
->area
.x
;
1012 self
->area
.y
= self
->frame
->area
.y
;
1013 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1017 if (size
.flags
& PAspect
) {
1018 if (size
.min_aspect
.y
)
1019 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1020 if (size
.max_aspect
.y
)
1021 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1024 if (size
.flags
& PMinSize
)
1025 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1027 if (size
.flags
& PMaxSize
)
1028 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1030 if (size
.flags
& PBaseSize
)
1031 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1033 if (size
.flags
& PResizeInc
)
1034 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1038 void client_setup_decor_and_functions(ObClient
*self
)
1040 /* start with everything (cept fullscreen) */
1042 (OB_FRAME_DECOR_TITLEBAR
|
1043 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1044 OB_FRAME_DECOR_GRIPS
|
1045 OB_FRAME_DECOR_BORDER
|
1046 OB_FRAME_DECOR_ICON
|
1047 OB_FRAME_DECOR_ALLDESKTOPS
|
1048 OB_FRAME_DECOR_ICONIFY
|
1049 OB_FRAME_DECOR_MAXIMIZE
|
1050 OB_FRAME_DECOR_SHADE
);
1052 (OB_CLIENT_FUNC_RESIZE
|
1053 OB_CLIENT_FUNC_MOVE
|
1054 OB_CLIENT_FUNC_ICONIFY
|
1055 OB_CLIENT_FUNC_MAXIMIZE
|
1056 OB_CLIENT_FUNC_SHADE
);
1057 if (self
->delete_window
) {
1058 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1059 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1062 if (!(self
->min_size
.width
< self
->max_size
.width
||
1063 self
->min_size
.height
< self
->max_size
.height
))
1064 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1066 switch (self
->type
) {
1067 case OB_CLIENT_TYPE_NORMAL
:
1068 /* normal windows retain all of the possible decorations and
1069 functionality, and are the only windows that you can fullscreen */
1070 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1073 case OB_CLIENT_TYPE_DIALOG
:
1074 case OB_CLIENT_TYPE_UTILITY
:
1075 /* these windows cannot be maximized */
1076 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1079 case OB_CLIENT_TYPE_MENU
:
1080 case OB_CLIENT_TYPE_TOOLBAR
:
1081 /* these windows get less functionality */
1082 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1085 case OB_CLIENT_TYPE_DESKTOP
:
1086 case OB_CLIENT_TYPE_DOCK
:
1087 case OB_CLIENT_TYPE_SPLASH
:
1088 /* none of these windows are manipulated by the window manager */
1089 self
->decorations
= 0;
1090 self
->functions
= 0;
1094 /* Mwm Hints are applied subtractively to what has already been chosen for
1095 decor and functionality */
1096 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1097 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1098 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1099 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1100 /* if the mwm hints request no handle or title, then all
1101 decorations are disabled */
1102 self
->decorations
= 0;
1106 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1107 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1108 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1109 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1110 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1111 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1112 /* dont let mwm hints kill any buttons
1113 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1114 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1115 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1116 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1118 /* dont let mwm hints kill the close button
1119 if (! (self->mwmhints.functions & MwmFunc_Close))
1120 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1124 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1125 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1126 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1127 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1128 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1129 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1131 /* can't maximize without moving/resizing */
1132 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1133 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1134 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1135 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1136 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1139 /* kill the handle on fully maxed windows */
1140 if (self
->max_vert
&& self
->max_horz
)
1141 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1143 /* finally, the user can have requested no decorations, which overrides
1145 if (!self
->decorate
)
1146 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1148 /* if we don't have a titlebar, then we cannot shade! */
1149 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1150 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1152 /* now we need to check against rules for the client's current state */
1153 if (self
->fullscreen
) {
1154 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1155 OB_CLIENT_FUNC_FULLSCREEN
|
1156 OB_CLIENT_FUNC_ICONIFY
);
1157 self
->decorations
= 0;
1160 client_change_allowed_actions(self
);
1163 /* adjust the client's decorations, etc. */
1164 client_reconfigure(self
);
1166 /* this makes sure that these windows appear on all desktops */
1167 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1168 self
->desktop
!= DESKTOP_ALL
)
1170 self
->desktop
= DESKTOP_ALL
;
1175 static void client_change_allowed_actions(ObClient
*self
)
1180 /* desktop windows are kept on all desktops */
1181 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1182 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1184 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1185 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1186 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1187 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1188 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1189 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1190 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1191 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1192 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1193 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1194 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1195 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1196 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1197 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1198 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1201 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1203 /* make sure the window isn't breaking any rules now */
1205 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1206 if (self
->frame
) client_shade(self
, FALSE
);
1207 else self
->shaded
= FALSE
;
1209 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1210 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1211 else self
->iconic
= FALSE
;
1213 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1214 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1215 else self
->fullscreen
= FALSE
;
1217 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1219 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1220 else self
->max_vert
= self
->max_horz
= FALSE
;
1224 void client_reconfigure(ObClient
*self
)
1226 /* by making this pass FALSE for user, we avoid the emacs event storm where
1227 every configurenotify causes an update in its normal hints, i think this
1228 is generally what we want anyways... */
1229 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1230 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1233 void client_update_wmhints(ObClient
*self
)
1236 gboolean ur
= FALSE
;
1239 /* assume a window takes input if it doesnt specify */
1240 self
->can_focus
= TRUE
;
1242 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1243 if (hints
->flags
& InputHint
)
1244 self
->can_focus
= hints
->input
;
1246 /* only do this when first managing the window *AND* when we aren't
1248 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1249 if (hints
->flags
& StateHint
)
1250 self
->iconic
= hints
->initial_state
== IconicState
;
1252 if (hints
->flags
& XUrgencyHint
)
1255 if (!(hints
->flags
& WindowGroupHint
))
1256 hints
->window_group
= None
;
1258 /* did the group state change? */
1259 if (hints
->window_group
!=
1260 (self
->group
? self
->group
->leader
: None
)) {
1261 /* remove from the old group if there was one */
1262 if (self
->group
!= NULL
) {
1263 /* remove transients of the group */
1264 for (it
= self
->group
->members
; it
; it
= it
->next
)
1265 self
->transients
= g_slist_remove(self
->transients
,
1267 group_remove(self
->group
, self
);
1270 if (hints
->window_group
!= None
) {
1271 self
->group
= group_add(hints
->window_group
, self
);
1273 /* i can only have transients from the group if i am not
1275 if (!self
->transient_for
) {
1276 /* add other transients of the group that are already
1278 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1279 ObClient
*c
= it
->data
;
1280 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1282 g_slist_append(self
->transients
, c
);
1287 /* because the self->transient flag wont change from this call,
1288 we don't need to update the window's type and such, only its
1289 transient_for, and the transients lists of other windows in
1290 the group may be affected */
1291 client_update_transient_for(self
);
1294 /* the WM_HINTS can contain an icon */
1295 client_update_icons(self
);
1300 if (ur
!= self
->urgent
) {
1302 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1304 /* fire the urgent callback if we're mapped, otherwise, wait until
1305 after we're mapped */
1307 client_urgent_notify(self
);
1311 void client_update_title(ObClient
*self
)
1317 gboolean read_title
;
1319 g_free(self
->title
);
1322 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1323 /* try old x stuff */
1324 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1325 data
= g_strdup("Unnamed Window");
1327 /* look for duplicates and append a number */
1329 for (it
= client_list
; it
; it
= it
->next
)
1330 if (it
->data
!= self
) {
1331 ObClient
*c
= it
->data
;
1332 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1333 nums
|= 1 << c
->title_count
;
1335 /* find first free number */
1336 for (i
= 1; i
<= 32; ++i
)
1337 if (!(nums
& (1 << i
))) {
1338 if (self
->title_count
== 1 || i
== 1)
1339 self
->title_count
= i
;
1342 /* dont display the number for the first window */
1343 if (self
->title_count
> 1) {
1344 char *vdata
, *ndata
;
1345 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1346 vdata
= g_strconcat(data
, ndata
, NULL
);
1352 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1357 frame_adjust_title(self
->frame
);
1359 /* update the icon title */
1361 g_free(self
->icon_title
);
1365 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1366 /* try old x stuff */
1367 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1368 data
= g_strdup(self
->title
);
1372 /* append the title count, dont display the number for the first window */
1373 if (read_title
&& self
->title_count
> 1) {
1374 char *vdata
, *ndata
;
1375 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1376 vdata
= g_strconcat(data
, ndata
, NULL
);
1382 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1384 self
->icon_title
= data
;
1387 void client_update_class(ObClient
*self
)
1392 if (self
->name
) g_free(self
->name
);
1393 if (self
->class) g_free(self
->class);
1394 if (self
->role
) g_free(self
->role
);
1396 self
->name
= self
->class = self
->role
= NULL
;
1398 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1400 self
->name
= g_strdup(data
[0]);
1402 self
->class = g_strdup(data
[1]);
1407 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1408 self
->role
= g_strdup(s
);
1410 if (self
->name
== NULL
) self
->name
= g_strdup("");
1411 if (self
->class == NULL
) self
->class = g_strdup("");
1412 if (self
->role
== NULL
) self
->role
= g_strdup("");
1415 void client_update_strut(ObClient
*self
)
1419 gboolean got
= FALSE
;
1422 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1426 STRUT_PARTIAL_SET(strut
,
1427 data
[0], data
[2], data
[1], data
[3],
1428 data
[4], data
[5], data
[8], data
[9],
1429 data
[6], data
[7], data
[10], data
[11]);
1435 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1438 STRUT_PARTIAL_SET(strut
,
1439 data
[0], data
[2], data
[1], data
[3],
1440 0, 0, 0, 0, 0, 0, 0, 0);
1446 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1447 0, 0, 0, 0, 0, 0, 0, 0);
1449 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1450 self
->strut
= strut
;
1452 /* updating here is pointless while we're being mapped cuz we're not in
1453 the client list yet */
1455 screen_update_areas();
1459 void client_update_icons(ObClient
*self
)
1465 for (i
= 0; i
< self
->nicons
; ++i
)
1466 g_free(self
->icons
[i
].data
);
1467 if (self
->nicons
> 0)
1468 g_free(self
->icons
);
1471 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1472 /* figure out how many valid icons are in here */
1474 while (num
- i
> 2) {
1478 if (i
> num
|| w
*h
== 0) break;
1482 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1484 /* store the icons */
1486 for (j
= 0; j
< self
->nicons
; ++j
) {
1489 w
= self
->icons
[j
].width
= data
[i
++];
1490 h
= self
->icons
[j
].height
= data
[i
++];
1492 if (w
*h
== 0) continue;
1494 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1495 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1500 self
->icons
[j
].data
[t
] =
1501 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1502 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1503 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1504 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1510 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1511 kwm_win_icon
, &data
, &num
)) {
1514 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1515 xerror_set_ignore(TRUE
);
1516 if (!RrPixmapToRGBA(ob_rr_inst
,
1518 &self
->icons
[self
->nicons
-1].width
,
1519 &self
->icons
[self
->nicons
-1].height
,
1520 &self
->icons
[self
->nicons
-1].data
)) {
1521 g_free(&self
->icons
[self
->nicons
-1]);
1524 xerror_set_ignore(FALSE
);
1530 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1531 if (hints
->flags
& IconPixmapHint
) {
1533 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1534 xerror_set_ignore(TRUE
);
1535 if (!RrPixmapToRGBA(ob_rr_inst
,
1537 (hints
->flags
& IconMaskHint
?
1538 hints
->icon_mask
: None
),
1539 &self
->icons
[self
->nicons
-1].width
,
1540 &self
->icons
[self
->nicons
-1].height
,
1541 &self
->icons
[self
->nicons
-1].data
)){
1542 g_free(&self
->icons
[self
->nicons
-1]);
1545 xerror_set_ignore(FALSE
);
1552 frame_adjust_icon(self
->frame
);
1555 static void client_change_state(ObClient
*self
)
1558 guint32 netstate
[10];
1561 state
[0] = self
->wmstate
;
1563 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1567 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1569 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1571 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1572 if (self
->skip_taskbar
)
1573 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1574 if (self
->skip_pager
)
1575 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1576 if (self
->fullscreen
)
1577 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1579 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1581 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1583 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1585 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1586 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1588 client_calc_layer(self
);
1591 frame_adjust_state(self
->frame
);
1594 ObClient
*client_search_focus_tree(ObClient
*self
)
1599 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1600 if (client_focused(it
->data
)) return it
->data
;
1601 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1606 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1608 if (self
->transient_for
) {
1609 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1610 return client_search_focus_tree_full(self
->transient_for
);
1613 gboolean recursed
= FALSE
;
1615 for (it
= self
->group
->members
; it
; it
= it
->next
)
1616 if (!((ObClient
*)it
->data
)->transient_for
) {
1618 if ((c
= client_search_focus_tree_full(it
->data
)))
1627 /* this function checks the whole tree, the client_search_focus_tree~
1628 does not, so we need to check this window */
1629 if (client_focused(self
))
1631 return client_search_focus_tree(self
);
1634 static ObStackingLayer
calc_layer(ObClient
*self
)
1638 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1639 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1640 l
= OB_STACKING_LAYER_DESKTOP
;
1641 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1642 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1643 else l
= OB_STACKING_LAYER_NORMAL
;
1645 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1646 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1647 else l
= OB_STACKING_LAYER_NORMAL
;
1652 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1653 ObStackingLayer l
, gboolean raised
)
1655 ObStackingLayer old
, own
;
1659 own
= calc_layer(self
);
1660 self
->layer
= l
> own
? l
: own
;
1662 for (it
= self
->transients
; it
; it
= it
->next
)
1663 client_calc_layer_recursive(it
->data
, orig
,
1664 l
, raised
? raised
: l
!= old
);
1666 if (!raised
&& l
!= old
)
1667 if (orig
->frame
) { /* only restack if the original window is managed */
1668 /* XXX add_non_intrusive ever? */
1669 stacking_remove(CLIENT_AS_WINDOW(self
));
1670 stacking_add(CLIENT_AS_WINDOW(self
));
1674 void client_calc_layer(ObClient
*self
)
1681 /* transients take on the layer of their parents */
1682 self
= client_search_top_transient(self
);
1684 l
= calc_layer(self
);
1686 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1689 gboolean
client_should_show(ObClient
*self
)
1691 if (self
->iconic
) return FALSE
;
1692 else if (!(self
->desktop
== screen_desktop
||
1693 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1694 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1699 static void client_showhide(ObClient
*self
)
1702 if (client_should_show(self
))
1703 frame_show(self
->frame
);
1705 frame_hide(self
->frame
);
1708 gboolean
client_normal(ObClient
*self
) {
1709 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1710 self
->type
== OB_CLIENT_TYPE_DOCK
||
1711 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1714 static void client_apply_startup_state(ObClient
*self
)
1716 /* these are in a carefully crafted order.. */
1719 self
->iconic
= FALSE
;
1720 client_iconify(self
, TRUE
, FALSE
);
1722 if (self
->fullscreen
) {
1723 self
->fullscreen
= FALSE
;
1724 client_fullscreen(self
, TRUE
, FALSE
);
1727 self
->shaded
= FALSE
;
1728 client_shade(self
, TRUE
);
1731 client_urgent_notify(self
);
1733 if (self
->max_vert
&& self
->max_horz
) {
1734 self
->max_vert
= self
->max_horz
= FALSE
;
1735 client_maximize(self
, TRUE
, 0, FALSE
);
1736 } else if (self
->max_vert
) {
1737 self
->max_vert
= FALSE
;
1738 client_maximize(self
, TRUE
, 2, FALSE
);
1739 } else if (self
->max_horz
) {
1740 self
->max_horz
= FALSE
;
1741 client_maximize(self
, TRUE
, 1, FALSE
);
1744 /* nothing to do for the other states:
1753 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1754 int x
, int y
, int w
, int h
,
1755 gboolean user
, gboolean final
,
1756 gboolean force_reply
)
1758 gboolean moved
= FALSE
, resized
= FALSE
;
1759 guint fdecor
= self
->frame
->decorations
;
1760 gboolean fhorz
= self
->frame
->max_horz
;
1762 /* make the frame recalculate its dimentions n shit without changing
1763 anything visible for real, this way the constraints below can work with
1764 the updated frame dimensions. */
1765 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1767 /* gets the frame's position */
1768 frame_client_gravity(self
->frame
, &x
, &y
);
1770 /* these positions are frame positions, not client positions */
1772 /* set the size and position if fullscreen */
1773 if (self
->fullscreen
) {
1776 XF86VidModeModeLine mode
;
1781 i
= client_monitor(self
);
1782 a
= screen_physical_area_monitor(i
);
1785 if (i
== 0 && /* primary head */
1786 extensions_vidmode
&&
1787 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1788 /* get the mode last so the mode.privsize isnt freed incorrectly */
1789 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1794 if (mode
.privsize
) XFree(mode
.private);
1804 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1808 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1810 /* set the size and position if maximized */
1811 if (self
->max_horz
) {
1813 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1815 if (self
->max_vert
) {
1817 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1821 /* gets the client's position */
1822 frame_frame_gravity(self
->frame
, &x
, &y
);
1824 /* these override the above states! if you cant move you can't move! */
1826 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1830 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1831 w
= self
->area
.width
;
1832 h
= self
->area
.height
;
1836 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1837 int basew
, baseh
, minw
, minh
;
1839 /* base size is substituted with min size if not specified */
1840 if (self
->base_size
.width
|| self
->base_size
.height
) {
1841 basew
= self
->base_size
.width
;
1842 baseh
= self
->base_size
.height
;
1844 basew
= self
->min_size
.width
;
1845 baseh
= self
->min_size
.height
;
1847 /* min size is substituted with base size if not specified */
1848 if (self
->min_size
.width
|| self
->min_size
.height
) {
1849 minw
= self
->min_size
.width
;
1850 minh
= self
->min_size
.height
;
1852 minw
= self
->base_size
.width
;
1853 minh
= self
->base_size
.height
;
1856 /* if this is a user-requested resize, then check against min/max
1859 /* smaller than min size or bigger than max size? */
1860 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1861 if (w
< minw
) w
= minw
;
1862 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1863 if (h
< minh
) h
= minh
;
1868 /* keep to the increments */
1869 w
/= self
->size_inc
.width
;
1870 h
/= self
->size_inc
.height
;
1872 /* you cannot resize to nothing */
1873 if (basew
+ w
< 1) w
= 1 - basew
;
1874 if (baseh
+ h
< 1) h
= 1 - baseh
;
1876 /* store the logical size */
1877 SIZE_SET(self
->logical_size
,
1878 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1879 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1881 w
*= self
->size_inc
.width
;
1882 h
*= self
->size_inc
.height
;
1887 /* adjust the height to match the width for the aspect ratios.
1888 for this, min size is not substituted for base size ever. */
1889 w
-= self
->base_size
.width
;
1890 h
-= self
->base_size
.height
;
1892 if (self
->min_ratio
)
1893 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1894 if (self
->max_ratio
)
1895 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1897 w
+= self
->base_size
.width
;
1898 h
+= self
->base_size
.height
;
1902 case OB_CORNER_TOPLEFT
:
1904 case OB_CORNER_TOPRIGHT
:
1905 x
-= w
- self
->area
.width
;
1907 case OB_CORNER_BOTTOMLEFT
:
1908 y
-= h
- self
->area
.height
;
1910 case OB_CORNER_BOTTOMRIGHT
:
1911 x
-= w
- self
->area
.width
;
1912 y
-= h
- self
->area
.height
;
1916 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1917 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1919 RECT_SET(self
->area
, x
, y
, w
, h
);
1921 /* for app-requested resizes, always resize if 'resized' is true.
1922 for user-requested ones, only resize if final is true, or when
1923 resizing in redraw mode */
1924 if ((!user
&& resized
) ||
1925 (user
&& (final
|| (resized
&& config_redraw_resize
))))
1926 XResizeWindow(ob_display
, self
->window
, w
, h
);
1928 /* move/resize the frame to match the request */
1930 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
1931 moved
= resized
= TRUE
;
1933 if (moved
|| resized
)
1934 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
1936 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1939 event
.type
= ConfigureNotify
;
1940 event
.xconfigure
.display
= ob_display
;
1941 event
.xconfigure
.event
= self
->window
;
1942 event
.xconfigure
.window
= self
->window
;
1944 /* root window real coords */
1945 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1947 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1949 event
.xconfigure
.width
= w
;
1950 event
.xconfigure
.height
= h
;
1951 event
.xconfigure
.border_width
= 0;
1952 event
.xconfigure
.above
= self
->frame
->plate
;
1953 event
.xconfigure
.override_redirect
= FALSE
;
1954 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1955 FALSE
, StructureNotifyMask
, &event
);
1960 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1964 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1965 self
->fullscreen
== fs
) return; /* already done */
1967 self
->fullscreen
= fs
;
1968 client_change_state(self
); /* change the state hints on the client,
1969 and adjust out layer/stacking */
1973 guint32 dimensions
[4];
1974 dimensions
[0] = self
->area
.x
;
1975 dimensions
[1] = self
->area
.y
;
1976 dimensions
[2] = self
->area
.width
;
1977 dimensions
[3] = self
->area
.height
;
1979 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1983 /* these are not actually used cuz client_configure will set them
1984 as appropriate when the window is fullscreened */
1991 /* pick some fallbacks... */
1992 a
= screen_area_monitor(self
->desktop
, 0);
1993 x
= a
->x
+ a
->width
/ 4;
1994 y
= a
->y
+ a
->height
/ 4;
1998 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1999 (guint32
**)&dimensions
, &num
)) {
2010 client_setup_decor_and_functions(self
);
2012 client_move_resize(self
, x
, y
, w
, h
);
2014 /* try focus us when we go into fullscreen mode */
2018 static void client_iconify_recursive(ObClient
*self
,
2019 gboolean iconic
, gboolean curdesk
)
2022 gboolean changed
= FALSE
;
2025 if (self
->iconic
!= iconic
) {
2026 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2029 self
->iconic
= iconic
;
2032 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2033 self
->wmstate
= IconicState
;
2034 self
->ignore_unmaps
++;
2035 /* we unmap the client itself so that we can get MapRequest
2036 events, and because the ICCCM tells us to! */
2037 XUnmapWindow(ob_display
, self
->window
);
2039 /* update the focus lists.. iconic windows go to the bottom of
2040 the list, put the new iconic window at the 'top of the
2042 focus_order_to_top(self
);
2048 client_set_desktop(self
, screen_desktop
, FALSE
);
2049 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2050 XMapWindow(ob_display
, self
->window
);
2052 /* this puts it after the current focused window */
2053 focus_order_remove(self
);
2054 focus_order_add_new(self
);
2056 /* this is here cuz with the VIDMODE extension, the viewport can
2057 change while a fullscreen window is iconic, and when it
2058 uniconifies, it would be nice if it did so to the new position
2060 client_reconfigure(self
);
2067 client_change_state(self
);
2068 client_showhide(self
);
2069 screen_update_areas();
2072 /* iconify all transients */
2073 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2074 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2078 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2080 /* move up the transient chain as far as possible first */
2081 self
= client_search_top_transient(self
);
2083 client_iconify_recursive(client_search_top_transient(self
),
2087 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2091 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2092 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2094 /* check if already done */
2096 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2097 if (dir
== 1 && self
->max_horz
) return;
2098 if (dir
== 2 && self
->max_vert
) return;
2100 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2101 if (dir
== 1 && !self
->max_horz
) return;
2102 if (dir
== 2 && !self
->max_vert
) return;
2105 /* work with the frame's coords */
2106 x
= self
->frame
->area
.x
;
2107 y
= self
->frame
->area
.y
;
2108 w
= self
->area
.width
;
2109 h
= self
->area
.height
;
2113 gint32 dimensions
[4];
2122 /* get the property off the window and use it for the dimensions
2123 we are already maxed on */
2124 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2125 (guint32
**)&readdim
, &num
)) {
2127 if (self
->max_horz
) {
2128 dimensions
[0] = readdim
[0];
2129 dimensions
[2] = readdim
[2];
2131 if (self
->max_vert
) {
2132 dimensions
[1] = readdim
[1];
2133 dimensions
[3] = readdim
[3];
2139 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2140 (guint32
*)dimensions
, 4);
2147 /* pick some fallbacks... */
2148 a
= screen_area_monitor(self
->desktop
, 0);
2149 if (dir
== 0 || dir
== 1) { /* horz */
2150 x
= a
->x
+ a
->width
/ 4;
2153 if (dir
== 0 || dir
== 2) { /* vert */
2154 y
= a
->y
+ a
->height
/ 4;
2158 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2159 (guint32
**)&dimensions
, &num
)) {
2161 if (dir
== 0 || dir
== 1) { /* horz */
2165 if (dir
== 0 || dir
== 2) { /* vert */
2174 if (dir
== 0 || dir
== 1) /* horz */
2175 self
->max_horz
= max
;
2176 if (dir
== 0 || dir
== 2) /* vert */
2177 self
->max_vert
= max
;
2179 if (!self
->max_horz
&& !self
->max_vert
)
2180 PROP_ERASE(self
->window
, openbox_premax
);
2182 client_change_state(self
); /* change the state hints on the client */
2184 client_setup_decor_and_functions(self
);
2186 /* figure out where the client should be going */
2187 frame_frame_gravity(self
->frame
, &x
, &y
);
2188 client_move_resize(self
, x
, y
, w
, h
);
2191 void client_shade(ObClient
*self
, gboolean shade
)
2193 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2194 shade
) || /* can't shade */
2195 self
->shaded
== shade
) return; /* already done */
2197 /* when we're iconic, don't change the wmstate */
2199 self
->wmstate
= shade
? IconicState
: NormalState
;
2200 self
->shaded
= shade
;
2201 client_change_state(self
);
2202 /* resize the frame to just the titlebar */
2203 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2206 void client_close(ObClient
*self
)
2210 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2213 XXX: itd be cool to do timeouts and shit here for killing the client's
2215 like... if the window is around after 5 seconds, then the close button
2216 turns a nice red, and if this function is called again, the client is
2220 ce
.xclient
.type
= ClientMessage
;
2221 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2222 ce
.xclient
.display
= ob_display
;
2223 ce
.xclient
.window
= self
->window
;
2224 ce
.xclient
.format
= 32;
2225 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2226 ce
.xclient
.data
.l
[1] = event_lasttime
;
2227 ce
.xclient
.data
.l
[2] = 0l;
2228 ce
.xclient
.data
.l
[3] = 0l;
2229 ce
.xclient
.data
.l
[4] = 0l;
2230 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2233 void client_kill(ObClient
*self
)
2235 XKillClient(ob_display
, self
->window
);
2238 void client_set_desktop_recursive(ObClient
*self
,
2239 guint target
, gboolean donthide
)
2244 if (target
!= self
->desktop
) {
2246 ob_debug("Setting desktop %u\n", target
+1);
2248 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2250 /* remove from the old desktop(s) */
2251 focus_order_remove(self
);
2253 old
= self
->desktop
;
2254 self
->desktop
= target
;
2255 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2256 /* the frame can display the current desktop state */
2257 frame_adjust_state(self
->frame
);
2258 /* 'move' the window to the new desktop */
2260 client_showhide(self
);
2261 /* raise if it was not already on the desktop */
2262 if (old
!= DESKTOP_ALL
)
2263 stacking_raise(CLIENT_AS_WINDOW(self
));
2264 screen_update_areas();
2266 /* add to the new desktop(s) */
2267 if (config_focus_new
)
2268 focus_order_to_top(self
);
2270 focus_order_to_bottom(self
);
2273 /* move all transients */
2274 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2275 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2279 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2281 client_set_desktop_recursive(client_search_top_transient(self
),
2285 ObClient
*client_search_modal_child(ObClient
*self
)
2290 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2291 ObClient
*c
= it
->data
;
2292 if ((ret
= client_search_modal_child(c
))) return ret
;
2293 if (c
->modal
) return c
;
2298 gboolean
client_validate(ObClient
*self
)
2302 XSync(ob_display
, FALSE
); /* get all events on the server */
2304 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2305 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2306 XPutBackEvent(ob_display
, &e
);
2313 void client_set_wm_state(ObClient
*self
, long state
)
2315 if (state
== self
->wmstate
) return; /* no change */
2319 client_iconify(self
, TRUE
, TRUE
);
2322 client_iconify(self
, FALSE
, TRUE
);
2327 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2329 gboolean shaded
= self
->shaded
;
2330 gboolean fullscreen
= self
->fullscreen
;
2331 gboolean max_horz
= self
->max_horz
;
2332 gboolean max_vert
= self
->max_vert
;
2335 if (!(action
== prop_atoms
.net_wm_state_add
||
2336 action
== prop_atoms
.net_wm_state_remove
||
2337 action
== prop_atoms
.net_wm_state_toggle
))
2338 /* an invalid action was passed to the client message, ignore it */
2341 for (i
= 0; i
< 2; ++i
) {
2342 Atom state
= i
== 0 ? data1
: data2
;
2344 if (!state
) continue;
2346 /* if toggling, then pick whether we're adding or removing */
2347 if (action
== prop_atoms
.net_wm_state_toggle
) {
2348 if (state
== prop_atoms
.net_wm_state_modal
)
2349 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2350 prop_atoms
.net_wm_state_add
;
2351 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2352 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2353 prop_atoms
.net_wm_state_add
;
2354 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2355 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2356 prop_atoms
.net_wm_state_add
;
2357 else if (state
== prop_atoms
.net_wm_state_shaded
)
2358 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2359 prop_atoms
.net_wm_state_add
;
2360 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2361 action
= self
->skip_taskbar
?
2362 prop_atoms
.net_wm_state_remove
:
2363 prop_atoms
.net_wm_state_add
;
2364 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2365 action
= self
->skip_pager
?
2366 prop_atoms
.net_wm_state_remove
:
2367 prop_atoms
.net_wm_state_add
;
2368 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2369 action
= self
->fullscreen
?
2370 prop_atoms
.net_wm_state_remove
:
2371 prop_atoms
.net_wm_state_add
;
2372 else if (state
== prop_atoms
.net_wm_state_above
)
2373 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2374 prop_atoms
.net_wm_state_add
;
2375 else if (state
== prop_atoms
.net_wm_state_below
)
2376 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2377 prop_atoms
.net_wm_state_add
;
2380 if (action
== prop_atoms
.net_wm_state_add
) {
2381 if (state
== prop_atoms
.net_wm_state_modal
) {
2382 /* XXX raise here or something? */
2384 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2386 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2388 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2390 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2391 self
->skip_taskbar
= TRUE
;
2392 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2393 self
->skip_pager
= TRUE
;
2394 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2396 } else if (state
== prop_atoms
.net_wm_state_above
) {
2398 } else if (state
== prop_atoms
.net_wm_state_below
) {
2402 } else { /* action == prop_atoms.net_wm_state_remove */
2403 if (state
== prop_atoms
.net_wm_state_modal
) {
2404 self
->modal
= FALSE
;
2405 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2407 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2409 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2411 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2412 self
->skip_taskbar
= FALSE
;
2413 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2414 self
->skip_pager
= FALSE
;
2415 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2417 } else if (state
== prop_atoms
.net_wm_state_above
) {
2418 self
->above
= FALSE
;
2419 } else if (state
== prop_atoms
.net_wm_state_below
) {
2420 self
->below
= FALSE
;
2424 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2425 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2427 if (max_horz
== max_vert
) { /* both going the same way */
2428 client_maximize(self
, max_horz
, 0, TRUE
);
2430 client_maximize(self
, max_horz
, 1, TRUE
);
2431 client_maximize(self
, max_vert
, 2, TRUE
);
2435 if (max_horz
!= self
->max_horz
)
2436 client_maximize(self
, max_horz
, 1, TRUE
);
2438 client_maximize(self
, max_vert
, 2, TRUE
);
2441 /* change fullscreen state before shading, as it will affect if the window
2443 if (fullscreen
!= self
->fullscreen
)
2444 client_fullscreen(self
, fullscreen
, TRUE
);
2445 if (shaded
!= self
->shaded
)
2446 client_shade(self
, shaded
);
2447 client_calc_layer(self
);
2448 client_change_state(self
); /* change the hint to reflect these changes */
2451 ObClient
*client_focus_target(ObClient
*self
)
2455 /* if we have a modal child, then focus it, not us */
2456 child
= client_search_modal_child(self
);
2457 if (child
) return child
;
2461 gboolean
client_can_focus(ObClient
*self
)
2465 /* choose the correct target */
2466 self
= client_focus_target(self
);
2468 if (!self
->frame
->visible
)
2471 if (!((self
->can_focus
|| self
->focus_notify
) &&
2472 (self
->desktop
== screen_desktop
||
2473 self
->desktop
== DESKTOP_ALL
) &&
2477 /* do a check to see if the window has already been unmapped or destroyed
2478 do this intelligently while watching out for unmaps we've generated
2479 (ignore_unmaps > 0) */
2480 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2481 DestroyNotify
, &ev
)) {
2482 XPutBackEvent(ob_display
, &ev
);
2485 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2486 UnmapNotify
, &ev
)) {
2487 if (self
->ignore_unmaps
) {
2488 self
->ignore_unmaps
--;
2490 XPutBackEvent(ob_display
, &ev
);
2498 gboolean
client_focus(ObClient
*self
)
2500 /* choose the correct target */
2501 self
= client_focus_target(self
);
2503 if (!client_can_focus(self
)) {
2504 if (!self
->frame
->visible
) {
2505 /* update the focus lists */
2506 focus_order_to_top(self
);
2511 if (self
->can_focus
)
2512 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2513 I choose to use it always, hopefully to find errors quicker, if any
2514 are left. (I hate X. I hate focus events.) */
2515 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2518 if (self
->focus_notify
) {
2520 ce
.xclient
.type
= ClientMessage
;
2521 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2522 ce
.xclient
.display
= ob_display
;
2523 ce
.xclient
.window
= self
->window
;
2524 ce
.xclient
.format
= 32;
2525 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2526 ce
.xclient
.data
.l
[1] = event_lasttime
;
2527 ce
.xclient
.data
.l
[2] = 0l;
2528 ce
.xclient
.data
.l
[3] = 0l;
2529 ce
.xclient
.data
.l
[4] = 0l;
2530 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2534 ob_debug("%sively focusing %lx at %d\n",
2535 (self
->can_focus
? "act" : "pass"),
2536 self
->window
, (int) event_lasttime
);
2539 /* Cause the FocusIn to come back to us. Important for desktop switches,
2540 since otherwise we'll have no FocusIn on the queue and send it off to
2541 the focus_backup. */
2542 XSync(ob_display
, FALSE
);
2546 void client_unfocus(ObClient
*self
)
2548 g_assert(focus_client
== self
);
2550 ob_debug("client_unfocus for %lx\n", self
->window
);
2552 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2555 void client_activate(ObClient
*self
, gboolean here
)
2557 if (client_normal(self
) && screen_showing_desktop
)
2558 screen_show_desktop(FALSE
);
2560 client_iconify(self
, FALSE
, FALSE
);
2561 if (self
->desktop
!= DESKTOP_ALL
&&
2562 self
->desktop
!= screen_desktop
) {
2564 client_set_desktop(self
, screen_desktop
, FALSE
);
2566 screen_set_desktop(self
->desktop
);
2567 } else if (!self
->frame
->visible
)
2568 /* if its not visible for other reasons, then don't mess
2572 client_shade(self
, FALSE
);
2574 stacking_raise(CLIENT_AS_WINDOW(self
));
2577 gboolean
client_focused(ObClient
*self
)
2579 return self
== focus_client
;
2582 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2585 /* si is the smallest image >= req */
2586 /* li is the largest image < req */
2587 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2589 if (!self
->nicons
) return NULL
;
2591 for (i
= 0; i
< self
->nicons
; ++i
) {
2592 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2593 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2597 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2602 if (largest
== 0) /* didnt find one smaller than the requested size */
2603 return &self
->icons
[si
];
2604 return &self
->icons
[li
];
2607 /* this be mostly ripped from fvwm */
2608 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2610 int my_cx
, my_cy
, his_cx
, his_cy
;
2613 int score
, best_score
;
2614 ObClient
*best_client
, *cur
;
2620 /* first, find the centre coords of the currently focused window */
2621 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2622 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2627 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2630 /* the currently selected window isn't interesting */
2633 if (!client_normal(cur
))
2635 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2639 if(client_focus_target(cur
) == cur
&&
2640 !(cur
->can_focus
|| cur
->focus_notify
))
2643 /* find the centre coords of this window, from the
2644 * currently focused window's point of view */
2645 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2646 + cur
->frame
->area
.width
/ 2;
2647 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2648 + cur
->frame
->area
.height
/ 2;
2650 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2651 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2653 /* Rotate the diagonals 45 degrees counterclockwise.
2654 * To do this, multiply the matrix /+h +h\ with the
2655 * vector (x y). \-h +h/
2656 * h = sqrt(0.5). We can set h := 1 since absolute
2657 * distance doesn't matter here. */
2658 tx
= his_cx
+ his_cy
;
2659 his_cy
= -his_cx
+ his_cy
;
2664 case OB_DIRECTION_NORTH
:
2665 case OB_DIRECTION_SOUTH
:
2666 case OB_DIRECTION_NORTHEAST
:
2667 case OB_DIRECTION_SOUTHWEST
:
2668 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2669 distance
= ((dir
== OB_DIRECTION_NORTH
||
2670 dir
== OB_DIRECTION_NORTHEAST
) ?
2673 case OB_DIRECTION_EAST
:
2674 case OB_DIRECTION_WEST
:
2675 case OB_DIRECTION_SOUTHEAST
:
2676 case OB_DIRECTION_NORTHWEST
:
2677 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2678 distance
= ((dir
== OB_DIRECTION_WEST
||
2679 dir
== OB_DIRECTION_NORTHWEST
) ?
2684 /* the target must be in the requested direction */
2688 /* Calculate score for this window. The smaller the better. */
2689 score
= distance
+ offset
;
2691 /* windows more than 45 degrees off the direction are
2692 * heavily penalized and will only be chosen if nothing
2693 * else within a million pixels */
2694 if(offset
> distance
)
2697 if(best_score
== -1 || score
< best_score
)
2705 void client_set_layer(ObClient
*self
, int layer
)
2709 self
->above
= FALSE
;
2710 } else if (layer
== 0) {
2711 self
->below
= self
->above
= FALSE
;
2713 self
->below
= FALSE
;
2716 client_calc_layer(self
);
2717 client_change_state(self
); /* reflect this in the state hints */
2720 guint
client_monitor(ObClient
*self
)
2724 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2725 Rect
*area
= screen_physical_area_monitor(i
);
2726 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2729 if (i
== screen_num_monitors
) i
= 0;
2730 g_assert(i
< screen_num_monitors
);
2734 ObClient
*client_search_top_transient(ObClient
*self
)
2736 /* move up the transient chain as far as possible */
2737 if (self
->transient_for
) {
2738 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2739 return client_search_top_transient(self
->transient_for
);
2743 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2744 ObClient
*c
= it
->data
;
2746 /* checking transient_for prevents infinate loops! */
2747 if (c
!= self
&& !c
->transient_for
)
2758 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2762 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2763 if (sit
->data
== search
)
2765 if (client_search_transient(sit
->data
, search
))
2771 gchar
* client_get_sm_client_id(ObClient
*self
)
2775 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &id
) && self
->group
)
2776 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
, &id
);
2780 /* finds the nearest edge in the given direction from the current client
2781 * note to self: the edge is the -frame- edge (the actual one), not the
2784 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
2787 int my_edge_start
, my_edge_end
, my_offset
;
2794 a
= screen_area(c
->desktop
);
2797 case OB_DIRECTION_NORTH
:
2798 my_edge_start
= c
->frame
->area
.x
;
2799 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2800 my_offset
= c
->frame
->area
.y
;
2802 dest
= a
->y
; /* default: top of screen */
2804 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2805 int his_edge_start
, his_edge_end
, his_offset
;
2806 ObClient
*cur
= it
->data
;
2810 if(!client_normal(cur
))
2812 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2817 his_edge_start
= cur
->frame
->area
.x
;
2818 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2819 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2821 if(his_offset
+ 1 > my_offset
)
2824 if(his_offset
< dest
)
2827 if(his_edge_start
>= my_edge_start
&&
2828 his_edge_start
<= my_edge_end
)
2831 if(my_edge_start
>= his_edge_start
&&
2832 my_edge_start
<= his_edge_end
)
2837 case OB_DIRECTION_SOUTH
:
2838 my_edge_start
= c
->frame
->area
.x
;
2839 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2840 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2842 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
2844 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2845 int his_edge_start
, his_edge_end
, his_offset
;
2846 ObClient
*cur
= it
->data
;
2850 if(!client_normal(cur
))
2852 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2857 his_edge_start
= cur
->frame
->area
.x
;
2858 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2859 his_offset
= cur
->frame
->area
.y
;
2862 if(his_offset
- 1 < my_offset
)
2865 if(his_offset
> dest
)
2868 if(his_edge_start
>= my_edge_start
&&
2869 his_edge_start
<= my_edge_end
)
2872 if(my_edge_start
>= his_edge_start
&&
2873 my_edge_start
<= his_edge_end
)
2878 case OB_DIRECTION_WEST
:
2879 my_edge_start
= c
->frame
->area
.y
;
2880 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2881 my_offset
= c
->frame
->area
.x
;
2883 dest
= a
->x
; /* default: leftmost egde of screen */
2885 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2886 int his_edge_start
, his_edge_end
, his_offset
;
2887 ObClient
*cur
= it
->data
;
2891 if(!client_normal(cur
))
2893 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2898 his_edge_start
= cur
->frame
->area
.y
;
2899 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2900 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2902 if(his_offset
+ 1 > my_offset
)
2905 if(his_offset
< dest
)
2908 if(his_edge_start
>= my_edge_start
&&
2909 his_edge_start
<= my_edge_end
)
2912 if(my_edge_start
>= his_edge_start
&&
2913 my_edge_start
<= his_edge_end
)
2919 case OB_DIRECTION_EAST
:
2920 my_edge_start
= c
->frame
->area
.y
;
2921 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2922 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2924 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
2926 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2927 int his_edge_start
, his_edge_end
, his_offset
;
2928 ObClient
*cur
= it
->data
;
2932 if(!client_normal(cur
))
2934 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2939 his_edge_start
= cur
->frame
->area
.y
;
2940 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2941 his_offset
= cur
->frame
->area
.x
;
2943 if(his_offset
- 1 < my_offset
)
2946 if(his_offset
> dest
)
2949 if(his_edge_start
>= my_edge_start
&&
2950 his_edge_start
<= my_edge_end
)
2953 if(my_edge_start
>= his_edge_start
&&
2954 my_edge_start
<= his_edge_end
)
2959 case OB_DIRECTION_NORTHEAST
:
2960 case OB_DIRECTION_SOUTHEAST
:
2961 case OB_DIRECTION_NORTHWEST
:
2962 case OB_DIRECTION_SOUTHWEST
:
2963 /* not implemented */
2966 g_assert_not_reached();