1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
40 #include "menuframe.h"
43 #include "render/render.h"
50 #include <X11/Xutil.h>
52 /*! The event mask to grab on client windows */
53 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
56 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
61 ObClientCallback func
;
65 GList
*client_list
= NULL
;
67 static GSList
*client_destroy_notifies
= NULL
;
69 static void client_get_all(ObClient
*self
, gboolean real
);
70 static void client_get_startup_id(ObClient
*self
);
71 static void client_get_session_ids(ObClient
*self
);
72 static void client_get_area(ObClient
*self
);
73 static void client_get_desktop(ObClient
*self
);
74 static void client_get_state(ObClient
*self
);
75 static void client_get_shaped(ObClient
*self
);
76 static void client_get_mwm_hints(ObClient
*self
);
77 static void client_get_colormap(ObClient
*self
);
78 static void client_change_allowed_actions(ObClient
*self
);
79 static void client_change_state(ObClient
*self
);
80 static void client_change_wm_state(ObClient
*self
);
81 static void client_apply_startup_state(ObClient
*self
,
82 gint x
, gint y
, gint w
, gint h
);
83 static void client_restore_session_state(ObClient
*self
);
84 static gboolean
client_restore_session_stacking(ObClient
*self
);
85 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
86 static void client_update_transient_tree(ObClient
*self
,
87 ObGroup
*oldgroup
, ObGroup
*newgroup
,
90 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
);
91 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
93 ObStackingLayer layer
);
94 static void client_call_notifies(ObClient
*self
, GSList
*list
);
96 void client_startup(gboolean reconfig
)
103 void client_shutdown(gboolean reconfig
)
105 if (reconfig
) return;
108 static void client_call_notifies(ObClient
*self
, GSList
*list
)
112 for (it
= list
; it
; it
= g_slist_next(it
)) {
113 ClientCallback
*d
= it
->data
;
114 d
->func(self
, d
->data
);
118 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
120 ClientCallback
*d
= g_new(ClientCallback
, 1);
123 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
126 void client_remove_destroy_notify(ObClientCallback func
)
130 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
131 ClientCallback
*d
= it
->data
;
132 if (d
->func
== func
) {
134 client_destroy_notifies
=
135 g_slist_delete_link(client_destroy_notifies
, it
);
141 void client_set_list()
143 Window
*windows
, *win_it
;
145 guint size
= g_list_length(client_list
);
147 /* create an array of the window ids */
149 windows
= g_new(Window
, size
);
151 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
152 *win_it
= ((ObClient
*)it
->data
)->window
;
156 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
157 net_client_list
, window
, (gulong
*)windows
, size
);
166 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
170 for (it = self->transients; it; it = g_slist_next(it)) {
171 if (!func(it->data, data)) return;
172 client_foreach_transient(it->data, func, data);
176 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
178 if (self->transient_for) {
179 if (self->transient_for != OB_TRAN_GROUP) {
180 if (!func(self->transient_for, data)) return;
181 client_foreach_ancestor(self->transient_for, func, data);
185 for (it = self->group->members; it; it = g_slist_next(it))
186 if (it->data != self &&
187 !((ObClient*)it->data)->transient_for) {
188 if (!func(it->data, data)) return;
189 client_foreach_ancestor(it->data, func, data);
196 void client_manage_all()
201 XWindowAttributes attrib
;
203 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
204 &w
, &w
, &children
, &nchild
);
206 /* remove all icon windows from the list */
207 for (i
= 0; i
< nchild
; i
++) {
208 if (children
[i
] == None
) continue;
209 wmhints
= XGetWMHints(ob_display
, children
[i
]);
211 if ((wmhints
->flags
& IconWindowHint
) &&
212 (wmhints
->icon_window
!= children
[i
]))
213 for (j
= 0; j
< nchild
; j
++)
214 if (children
[j
] == wmhints
->icon_window
) {
222 for (i
= 0; i
< nchild
; ++i
) {
223 if (children
[i
] == None
)
225 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
226 if (attrib
.override_redirect
) continue;
228 if (attrib
.map_state
!= IsUnmapped
)
229 client_manage(children
[i
]);
235 void client_manage(Window window
)
239 XWindowAttributes attrib
;
240 XSetWindowAttributes attrib_set
;
242 gboolean activate
= FALSE
;
243 ObAppSettings
*settings
;
244 gint placex
, placey
, placew
, placeh
;
245 gboolean transient
= FALSE
;
249 /* check if it has already been unmapped by the time we started
250 mapping. the grab does a sync so we don't have to here */
251 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
252 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
254 XPutBackEvent(ob_display
, &e
);
256 ob_debug("Trying to manage unmapped window. Aborting that.\n");
258 return; /* don't manage it */
261 /* make sure it isn't an override-redirect window */
262 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
263 attrib
.override_redirect
)
266 return; /* don't manage it */
269 /* is the window a docking app */
270 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
271 if ((wmhint
->flags
& StateHint
) &&
272 wmhint
->initial_state
== WithdrawnState
)
274 dock_add(window
, wmhint
);
282 ob_debug("Managing window: 0x%lx\n", window
);
284 /* choose the events we want to receive on the CLIENT window */
285 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
286 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
287 XChangeWindowAttributes(ob_display
, window
,
288 CWEventMask
|CWDontPropagate
, &attrib_set
);
290 /* create the ObClient struct, and populate it from the hints on the
292 self
= g_new0(ObClient
, 1);
293 self
->obwin
.type
= Window_Client
;
294 self
->window
= window
;
296 /* non-zero defaults */
297 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
298 self
->gravity
= NorthWestGravity
;
299 self
->desktop
= screen_num_desktops
; /* always an invalid value */
300 self
->user_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
302 /* get all the stuff off the window */
303 client_get_all(self
, TRUE
);
305 /* specify that if we exit, the window should not be destroyed and
306 should be reparented back to root automatically */
307 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
309 /* create the decoration frame for the client window */
310 self
->frame
= frame_new(self
);
312 frame_grab_client(self
->frame
);
314 /* we've grabbed everything and set everything that we need to at mapping
318 /* per-app settings override stuff from client_get_all, and return the
319 settings for other uses too. the returned settings is a shallow copy,
320 that needs to be freed with g_free(). */
321 settings
= client_get_settings_state(self
);
322 /* the session should get the last say thought */
323 client_restore_session_state(self
);
325 /* now we have all of the window's information so we can set this up */
326 client_setup_decor_and_functions(self
, FALSE
);
329 Time t
= sn_app_started(self
->startup_id
, self
->class);
330 if (t
) self
->user_time
= t
;
333 /* do this after we have a frame.. it uses the frame to help determine the
334 WM_STATE to apply. */
335 client_change_state(self
);
337 /* add ourselves to the focus order */
338 focus_order_add_new(self
);
340 /* do this to add ourselves to the stacking list in a non-intrusive way */
341 client_calc_layer(self
);
343 /* focus the new window? */
344 if (ob_state() != OB_STATE_STARTING
&&
345 (!self
->session
|| self
->session
->focused
) &&
347 /* this means focus=true for window is same as config_focus_new=true */
348 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
349 client_search_focus_tree_full(self
)) &&
350 /* this checks for focus=false for the window */
351 (!settings
|| settings
->focus
!= 0) &&
352 /* note the check against Type_Normal/Dialog, not client_normal(self),
353 which would also include other types. in this case we want more
354 strict rules for focus */
355 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
356 self
->type
== OB_CLIENT_TYPE_DIALOG
))
361 /* adjust the frame to the client's size before showing or placing
363 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
365 /* where the frame was placed is where the window was originally */
366 placex
= self
->area
.x
;
367 placey
= self
->area
.y
;
368 placew
= self
->area
.width
;
369 placeh
= self
->area
.height
;
371 /* figure out placement for the window if the window is new */
372 if (ob_state() == OB_STATE_RUNNING
) {
373 ob_debug("Positioned: %s @ %d %d\n",
374 (!self
->positioned
? "no" :
375 (self
->positioned
== PPosition
? "program specified" :
376 (self
->positioned
== USPosition
? "user specified" :
377 (self
->positioned
== (PPosition
| USPosition
) ?
378 "program + user specified" :
379 "BADNESS !?")))), placex
, placey
);
381 ob_debug("Sized: %s @ %d %d\n",
382 (!self
->sized
? "no" :
383 (self
->sized
== PSize
? "program specified" :
384 (self
->sized
== USSize
? "user specified" :
385 (self
->sized
== (PSize
| USSize
) ?
386 "program + user specified" :
387 "BADNESS !?")))), placew
, placeh
);
389 transient
= place_client(self
, &placex
, &placey
, settings
);
391 /* make sure the window is visible. */
392 client_find_onscreen(self
, &placex
, &placey
, placew
, placeh
,
393 /* non-normal clients has less rules, and
394 windows that are being restored from a
395 session do also. we can assume you want
396 it back where you saved it. Clients saying
397 they placed themselves are subjected to
398 harder rules, ones that are placed by
399 place.c or by the user are allowed partially
400 off-screen and on xinerama divides (ie,
401 it is up to the placement routines to avoid
402 the xinerama divides) */
404 (!(self
->positioned
& USPosition
) &&
405 client_normal(self
) &&
409 /* if the window isn't user-sized, then make it fit inside
410 the visible screen area on its monitor. Use basically the same rules
411 for forcing the window on screen in the client_find_onscreen call.
413 do this after place_client, it chooses the monitor! */
415 (!(self
->sized
& USSize
) &&
416 client_normal(self
) &&
419 /* make a copy to modify */
420 Rect a
= *screen_area_monitor(self
->desktop
, client_monitor(self
));
422 /* shrink by the frame's area */
423 a
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
424 a
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
426 /* fit the window inside the area */
427 if (placew
> a
.width
|| self
->area
.height
> a
.height
) {
428 placew
= MAX(MIN(MIN(self
->area
.width
, a
.width
),
429 self
->max_size
.width
),
430 self
->min_size
.width
);
431 placeh
= MAX(MIN(MIN(self
->area
.height
, a
.height
),
432 self
->max_size
.height
),
433 self
->min_size
.height
);
435 ob_debug("setting window size to %dx%d\n",
436 self
->area
.width
, self
->area
.height
);
441 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
442 "some restrictions may apply\n",
443 self
->window
, placex
, placey
, placew
, placeh
);
445 ob_debug(" but session requested %d, %d %d x %d instead, "
447 self
->session
->x
, self
->session
->y
,
448 self
->session
->w
, self
->session
->h
);
450 /* do this after the window is placed, so the premax/prefullscreen numbers
453 this also places the window
455 client_apply_startup_state(self
, placex
, placey
, placew
, placeh
);
458 guint32 last_time
= focus_client
?
459 focus_client
->user_time
: CurrentTime
;
461 /* This is focus stealing prevention */
462 ob_debug_type(OB_DEBUG_FOCUS
,
463 "Want to focus new window 0x%x with time %u "
465 self
->window
, self
->user_time
, last_time
);
467 /* if it's on another desktop */
468 if (!(self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
469 && /* the timestamp is from before you changed desktops */
470 self
->user_time
&& screen_desktop_user_time
&&
471 !event_time_after(self
->user_time
, screen_desktop_user_time
))
474 ob_debug_type(OB_DEBUG_FOCUS
,
475 "Not focusing the window because its on another "
478 /* If something is focused, and it's not our relative... */
479 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
)
481 /* If time stamp is old, don't steal focus */
482 if (self
->user_time
&& last_time
&&
483 !event_time_after(self
->user_time
, last_time
))
486 ob_debug_type(OB_DEBUG_FOCUS
,
487 "Not focusing the window because the time is "
490 /* If its a transient (and parents aren't focused) and the time
491 is ambiguous (either the current focus target doesn't have
492 a timestamp, or they are the same (we probably inherited it
494 else if (client_has_parent(self
) &&
495 (!last_time
|| self
->user_time
== last_time
))
498 ob_debug_type(OB_DEBUG_FOCUS
,
499 "Not focusing the window because it is a "
500 "transient, and the time is very ambiguous\n");
502 /* Don't steal focus from globally active clients.
503 I stole this idea from KWin. It seems nice.
505 else if (!(focus_client
->can_focus
||
506 focus_client
->focus_notify
))
509 ob_debug_type(OB_DEBUG_FOCUS
,
510 "Not focusing the window because a globally "
511 "active client has focus\n");
513 /* Don't move focus if it's not going to go to this window
515 else if (client_focus_target(self
) != self
) {
517 ob_debug_type(OB_DEBUG_FOCUS
,
518 "Not focusing the window because another window "
519 "would get the focus anyway\n");
524 ob_debug_type(OB_DEBUG_FOCUS
,
525 "Focus stealing prevention activated for %s with "
526 "time %u (last time %u)\n",
527 self
->title
, self
->user_time
, last_time
);
528 /* if the client isn't focused, then hilite it so the user
530 client_hilite(self
, TRUE
);
534 /* This may look rather odd. Well it's because new windows are added
535 to the stacking order non-intrusively. If we're not going to focus
536 the new window or hilite it, then we raise it to the top. This will
537 take affect for things that don't get focused like splash screens.
538 Also if you don't have focus_new enabled, then it's going to get
539 raised to the top. Legacy begets legacy I guess?
541 if (!client_restore_session_stacking(self
))
542 stacking_raise(CLIENT_AS_WINDOW(self
));
545 mouse_grab_for_client(self
, TRUE
);
547 /* this has to happen before we try focus the window, but we want it to
548 happen after the client's stacking has been determined or it looks bad
553 gboolean stacked
= client_restore_session_stacking(self
);
554 client_present(self
, FALSE
, !stacked
);
557 /* add to client list/map */
558 client_list
= g_list_append(client_list
, self
);
559 g_hash_table_insert(window_map
, &self
->window
, self
);
561 /* this has to happen after we're in the client_list */
562 if (STRUT_EXISTS(self
->strut
))
563 screen_update_areas();
565 /* update the list hints */
568 /* free the ObAppSettings shallow copy */
571 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
572 window
, self
->frame
->window
, self
->class);
578 ObClient
*client_fake_manage(Window window
)
581 ObAppSettings
*settings
;
583 ob_debug("Pretend-managing window: %lx\n", window
);
585 /* do this minimal stuff to figure out the client's decorations */
587 self
= g_new0(ObClient
, 1);
588 self
->window
= window
;
590 client_get_all(self
, FALSE
);
591 /* per-app settings override stuff, and return the settings for other
592 uses too. this returns a shallow copy that needs to be freed */
593 settings
= client_get_settings_state(self
);
595 client_setup_decor_and_functions(self
, FALSE
);
597 /* create the decoration frame for the client window and adjust its size */
598 self
->frame
= frame_new(self
);
599 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
601 ob_debug("gave extents left %d right %d top %d bottom %d\n",
602 self
->frame
->size
.left
, self
->frame
->size
.right
,
603 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
605 /* free the ObAppSettings shallow copy */
611 void client_unmanage_all()
613 while (client_list
!= NULL
)
614 client_unmanage(client_list
->data
);
617 void client_unmanage(ObClient
*self
)
622 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
623 self
->window
, self
->frame
->window
,
624 self
->class, self
->title
? self
->title
: "");
626 g_assert(self
!= NULL
);
628 /* we dont want events no more. do this before hiding the frame so we
629 don't generate more events */
630 XSelectInput(ob_display
, self
->window
, NoEventMask
);
632 frame_hide(self
->frame
);
633 /* flush to send the hide to the server quickly */
636 /* ignore enter events from the unmap so it doesnt mess with the
638 event_ignore_all_queued_enters();
640 mouse_grab_for_client(self
, FALSE
);
642 /* remove the window from our save set */
643 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
645 /* kill the property windows */
646 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
648 /* update the focus lists */
649 focus_order_remove(self
);
650 if (client_focused(self
)) {
651 /* don't leave an invalid focus_client */
655 client_list
= g_list_remove(client_list
, self
);
656 stacking_remove(self
);
657 g_hash_table_remove(window_map
, &self
->window
);
659 /* once the client is out of the list, update the struts to remove its
661 if (STRUT_EXISTS(self
->strut
))
662 screen_update_areas();
664 client_call_notifies(self
, client_destroy_notifies
);
666 /* tell our parent(s) that we're gone */
667 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
668 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
669 if (it
->data
!= self
)
670 ((ObClient
*)it
->data
)->transients
=
671 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
672 } else if (self
->transient_for
) { /* transient of window */
673 self
->transient_for
->transients
=
674 g_slist_remove(self
->transient_for
->transients
, self
);
677 /* tell our transients that we're gone */
678 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
679 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
680 ((ObClient
*)it
->data
)->transient_for
= NULL
;
681 client_calc_layer(it
->data
);
685 /* remove from its group */
687 group_remove(self
->group
, self
);
691 /* restore the window's original geometry so it is not lost */
697 if (self
->fullscreen
)
698 a
= self
->pre_fullscreen_area
;
699 else if (self
->max_horz
|| self
->max_vert
) {
700 if (self
->max_horz
) {
701 a
.x
= self
->pre_max_area
.x
;
702 a
.width
= self
->pre_max_area
.width
;
704 if (self
->max_vert
) {
705 a
.y
= self
->pre_max_area
.y
;
706 a
.height
= self
->pre_max_area
.height
;
710 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
711 /* let it be moved and resized no matter what */
712 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
713 self
->decorations
= 0; /* unmanaged windows have no decor */
715 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
718 /* reparent the window out of the frame, and free the frame */
719 frame_release_client(self
->frame
);
720 frame_free(self
->frame
);
723 if (ob_state() != OB_STATE_EXITING
) {
724 /* these values should not be persisted across a window
726 PROP_ERASE(self
->window
, net_wm_desktop
);
727 PROP_ERASE(self
->window
, net_wm_state
);
728 PROP_ERASE(self
->window
, wm_state
);
730 /* if we're left in an unmapped state, the client wont be mapped.
731 this is bad, since we will no longer be managing the window on
733 XMapWindow(ob_display
, self
->window
);
736 /* update the list hints */
739 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
741 /* free all data allocated in the client struct */
742 g_slist_free(self
->transients
);
743 for (j
= 0; j
< self
->nicons
; ++j
)
744 g_free(self
->icons
[j
].data
);
745 if (self
->nicons
> 0)
747 g_free(self
->wm_command
);
749 g_free(self
->icon_title
);
753 g_free(self
->client_machine
);
754 g_free(self
->sm_client_id
);
758 void client_fake_unmanage(ObClient
*self
)
760 /* this is all that got allocated to get the decorations */
762 frame_free(self
->frame
);
766 /*! Returns a new structure containing the per-app settings for this client.
767 The returned structure needs to be freed with g_free. */
768 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
770 ObAppSettings
*settings
;
773 settings
= config_create_app_settings();
775 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
776 ObAppSettings
*app
= it
->data
;
777 gboolean match
= TRUE
;
779 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
781 /* we know that either name or class is not NULL so it will have to
782 match to use the rule */
784 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
786 else if (app
->class &&
787 !g_pattern_match(app
->class,
788 strlen(self
->class), self
->class, NULL
))
790 else if (app
->role
&&
791 !g_pattern_match(app
->role
,
792 strlen(self
->role
), self
->role
, NULL
))
796 ob_debug("Window matching: %s\n", app
->name
);
798 /* copy the settings to our struct, overriding the existing
799 settings if they are not defaults */
800 config_app_settings_copy_non_defaults(app
, settings
);
804 if (settings
->shade
!= -1)
805 self
->shaded
= !!settings
->shade
;
806 if (settings
->decor
!= -1)
807 self
->undecorated
= !settings
->decor
;
808 if (settings
->iconic
!= -1)
809 self
->iconic
= !!settings
->iconic
;
810 if (settings
->skip_pager
!= -1)
811 self
->skip_pager
= !!settings
->skip_pager
;
812 if (settings
->skip_taskbar
!= -1)
813 self
->skip_taskbar
= !!settings
->skip_taskbar
;
815 if (settings
->max_vert
!= -1)
816 self
->max_vert
= !!settings
->max_vert
;
817 if (settings
->max_horz
!= -1)
818 self
->max_horz
= !!settings
->max_horz
;
820 if (settings
->fullscreen
!= -1)
821 self
->fullscreen
= !!settings
->fullscreen
;
823 if (settings
->desktop
) {
824 if (settings
->desktop
== DESKTOP_ALL
)
825 self
->desktop
= settings
->desktop
;
826 else if (settings
->desktop
> 0 &&
827 settings
->desktop
<= screen_num_desktops
)
828 self
->desktop
= settings
->desktop
- 1;
831 if (settings
->layer
== -1) {
835 else if (settings
->layer
== 0) {
839 else if (settings
->layer
== 1) {
846 static void client_restore_session_state(ObClient
*self
)
850 ob_debug_type(OB_DEBUG_SM
,
851 "Restore session for client %s\n", self
->title
);
853 if (!(it
= session_state_find(self
))) {
854 ob_debug_type(OB_DEBUG_SM
,
855 "Session data not found for client %s\n", self
->title
);
859 self
->session
= it
->data
;
861 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
864 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
865 self
->positioned
= USPosition
;
866 self
->sized
= USSize
;
867 if (self
->session
->w
> 0)
868 self
->area
.width
= self
->session
->w
;
869 if (self
->session
->h
> 0)
870 self
->area
.height
= self
->session
->h
;
871 XResizeWindow(ob_display
, self
->window
,
872 self
->area
.width
, self
->area
.height
);
874 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
875 self
->session
->desktop
:
876 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
877 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
879 self
->shaded
= self
->session
->shaded
;
880 self
->iconic
= self
->session
->iconic
;
881 self
->skip_pager
= self
->session
->skip_pager
;
882 self
->skip_taskbar
= self
->session
->skip_taskbar
;
883 self
->fullscreen
= self
->session
->fullscreen
;
884 self
->above
= self
->session
->above
;
885 self
->below
= self
->session
->below
;
886 self
->max_horz
= self
->session
->max_horz
;
887 self
->max_vert
= self
->session
->max_vert
;
888 self
->undecorated
= self
->session
->undecorated
;
891 static gboolean
client_restore_session_stacking(ObClient
*self
)
895 if (!self
->session
) return FALSE
;
897 mypos
= g_list_find(session_saved_state
, self
->session
);
898 if (!mypos
) return FALSE
;
900 /* start above me and look for the first client */
901 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
904 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
905 ObClient
*c
= cit
->data
;
906 /* found a client that was in the session, so go below it */
907 if (c
->session
== it
->data
) {
908 stacking_below(CLIENT_AS_WINDOW(self
),
909 CLIENT_AS_WINDOW(cit
->data
));
917 void client_move_onscreen(ObClient
*self
, gboolean rude
)
919 gint x
= self
->area
.x
;
920 gint y
= self
->area
.y
;
921 if (client_find_onscreen(self
, &x
, &y
,
923 self
->area
.height
, rude
)) {
924 client_move(self
, x
, y
);
928 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
932 gint ox
= *x
, oy
= *y
;
933 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
937 RECT_SET(desired
, *x
, *y
, w
, h
);
938 all_a
= screen_area(self
->desktop
);
939 mon_a
= screen_area_monitor(self
->desktop
, screen_find_monitor(&desired
));
941 /* get where the frame would be */
942 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
944 /* get the requested size of the window with decorations */
945 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
946 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
948 /* This makes sure windows aren't entirely outside of the screen so you
949 can't see them at all.
950 It makes sure 10% of the window is on the screen at least. At don't let
951 it move itself off the top of the screen, which would hide the titlebar
952 on you. (The user can still do this if they want too, it's only limiting
955 XXX watch for xinerama dead areas...
957 if (client_normal(self
)) {
958 if (!self
->strut
.right
&& *x
+ fw
/10 >= all_a
->x
+ all_a
->width
- 1)
959 *x
= all_a
->x
+ all_a
->width
- fw
/10;
960 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= all_a
->y
+ all_a
->height
- 1)
961 *y
= all_a
->y
+ all_a
->height
- fh
/10;
962 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < all_a
->x
)
963 *x
= all_a
->x
- fw
*9/10;
964 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < all_a
->y
)
965 *y
= all_a
->y
- fw
*9/10;
968 /* If rudeness wasn't requested, then figure out of the client is currently
969 entirely on the screen. If it is, and the position isn't changing by
970 request, and it is enlarging, then be rude even though it wasn't
973 Point oldtl
, oldtr
, oldbl
, oldbr
;
974 Point newtl
, newtr
, newbl
, newbr
;
975 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
977 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
978 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
979 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
980 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
981 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
983 POINT_SET(newtl
, *x
, *y
);
984 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
985 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
986 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
988 /* is it moving or just resizing from some corner? */
989 stationary_l
= oldtl
.x
== newtl
.x
;
990 stationary_r
= oldtr
.x
== newtr
.x
;
991 stationary_t
= oldtl
.y
== newtl
.y
;
992 stationary_b
= oldbl
.y
== newbl
.y
;
994 /* if left edge is growing and didnt move right edge */
995 if (stationary_r
&& newtl
.x
< oldtl
.x
)
997 /* if right edge is growing and didnt move left edge */
998 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1000 /* if top edge is growing and didnt move bottom edge */
1001 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1003 /* if bottom edge is growing and didnt move top edge */
1004 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1008 /* This here doesn't let windows even a pixel outside the struts/screen.
1009 * When called from client_manage, programs placing themselves are
1010 * forced completely onscreen, while things like
1011 * xterm -geometry resolution-width/2 will work fine. Trying to
1012 * place it completely offscreen will be handled in the above code.
1013 * Sorry for this confused comment, i am tired. */
1014 if (rudel
&& !self
->strut
.left
&& *x
< mon_a
->x
) *x
= mon_a
->x
;
1015 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> mon_a
->x
+ mon_a
->width
)
1016 *x
= mon_a
->x
+ MAX(0, mon_a
->width
- fw
);
1018 if (rudet
&& !self
->strut
.top
&& *y
< mon_a
->y
) *y
= mon_a
->y
;
1019 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> mon_a
->y
+ mon_a
->height
)
1020 *y
= mon_a
->y
+ MAX(0, mon_a
->height
- fh
);
1022 /* get where the client should be */
1023 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
1025 return ox
!= *x
|| oy
!= *y
;
1028 static void client_get_all(ObClient
*self
, gboolean real
)
1030 /* this is needed for the frame to set itself up */
1031 client_get_area(self
);
1033 /* these things can change the decor and functions of the window */
1035 client_get_mwm_hints(self
);
1036 /* this can change the mwmhints for special cases */
1037 client_get_type_and_transientness(self
);
1038 client_get_state(self
);
1039 client_update_normal_hints(self
);
1041 /* get the session related properties, these can change decorations
1042 from per-app settings */
1043 client_get_session_ids(self
);
1045 /* now we got everything that can affect the decorations */
1049 /* get this early so we have it for debugging */
1050 client_update_title(self
);
1052 client_update_protocols(self
);
1054 client_update_wmhints(self
);
1055 /* this may have already been called from client_update_wmhints */
1056 if (self
->transient_for
== NULL
)
1057 client_update_transient_for(self
);
1059 client_get_startup_id(self
);
1060 client_get_desktop(self
);/* uses transient data/group/startup id if a
1061 desktop is not specified */
1062 client_get_shaped(self
);
1065 /* a couple type-based defaults for new windows */
1067 /* this makes sure that these windows appear on all desktops */
1068 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1069 self
->desktop
= DESKTOP_ALL
;
1073 client_update_sync_request_counter(self
);
1076 client_get_colormap(self
);
1077 client_update_strut(self
);
1078 client_update_icons(self
);
1079 client_update_user_time_window(self
);
1080 if (!self
->user_time_window
) /* check if this would have been called */
1081 client_update_user_time(self
);
1082 client_update_icon_geometry(self
);
1085 static void client_get_startup_id(ObClient
*self
)
1087 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1089 PROP_GETS(self
->group
->leader
,
1090 net_startup_id
, utf8
, &self
->startup_id
);
1093 static void client_get_area(ObClient
*self
)
1095 XWindowAttributes wattrib
;
1098 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1099 g_assert(ret
!= BadWindow
);
1101 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1102 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1103 self
->border_width
= wattrib
.border_width
;
1105 ob_debug("client area: %d %d %d %d bw %d\n", wattrib
.x
, wattrib
.y
,
1106 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1109 static void client_get_desktop(ObClient
*self
)
1111 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1113 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1114 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1115 self
->desktop
= screen_num_desktops
- 1;
1118 ob_debug("client requested desktop 0x%x\n", self
->desktop
);
1120 gboolean trdesk
= FALSE
;
1122 if (self
->transient_for
) {
1123 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1124 if (self
->transient_for
->desktop
!= DESKTOP_ALL
) {
1125 self
->desktop
= self
->transient_for
->desktop
;
1129 /* if all the group is on one desktop, then open it on the
1132 gboolean first
= TRUE
;
1133 guint all
= screen_num_desktops
; /* not a valid value */
1135 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1136 ObClient
*c
= it
->data
;
1142 else if (all
!= c
->desktop
)
1143 all
= screen_num_desktops
; /* make it invalid */
1146 if (all
!= screen_num_desktops
) {
1147 self
->desktop
= all
;
1153 /* try get from the startup-notification protocol */
1154 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1155 if (self
->desktop
>= screen_num_desktops
&&
1156 self
->desktop
!= DESKTOP_ALL
)
1157 self
->desktop
= screen_num_desktops
- 1;
1159 /* defaults to the current desktop */
1160 self
->desktop
= screen_desktop
;
1165 static void client_get_state(ObClient
*self
)
1170 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1172 for (i
= 0; i
< num
; ++i
) {
1173 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1175 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1176 self
->shaded
= TRUE
;
1177 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1178 self
->iconic
= TRUE
;
1179 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1180 self
->skip_taskbar
= TRUE
;
1181 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1182 self
->skip_pager
= TRUE
;
1183 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1184 self
->fullscreen
= TRUE
;
1185 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1186 self
->max_vert
= TRUE
;
1187 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1188 self
->max_horz
= TRUE
;
1189 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1191 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1193 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1194 self
->demands_attention
= TRUE
;
1195 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1196 self
->undecorated
= TRUE
;
1203 static void client_get_shaped(ObClient
*self
)
1205 self
->shaped
= FALSE
;
1207 if (extensions_shape
) {
1212 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1214 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1215 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1217 self
->shaped
= (s
!= 0);
1222 void client_update_transient_for(ObClient
*self
)
1225 ObClient
*target
= NULL
;
1227 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1228 if (t
!= self
->window
) { /* cant be transient to itself! */
1229 target
= g_hash_table_lookup(window_map
, &t
);
1230 /* if this happens then we need to check for it*/
1231 g_assert(target
!= self
);
1232 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1233 /* this can happen when a dialog is a child of
1234 a dockapp, for example */
1238 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1240 Setting the transient_for to Root is actually illegal, however
1241 applications from time have done this to specify transient for
1244 Now you can do that by being a TYPE_DIALOG and not setting
1245 the transient_for hint at all on your window. But people still
1246 use Root, and Kwin is very strange in this regard.
1248 KWin 3.0 will not consider windows with transient_for set to
1249 Root as transient for their group *UNLESS* they are also modal.
1250 In that case, it will make them transient for the group. This
1251 leads to all sorts of weird behavior from KDE apps which are
1252 only tested in KWin. I'd like to follow their behavior just to
1253 make this work right with KDE stuff, but that seems wrong.
1255 if (!target
&& self
->group
) {
1256 /* not transient to a client, see if it is transient for a
1258 if (t
== RootWindow(ob_display
, ob_screen
)) {
1259 /* window is a transient for its group! */
1260 target
= OB_TRAN_GROUP
;
1264 } else if (self
->transient
&& self
->group
)
1265 target
= OB_TRAN_GROUP
;
1267 client_update_transient_tree(self
, self
->group
, self
->group
,
1268 self
->transient_for
, target
);
1269 self
->transient_for
= target
;
1273 static void client_update_transient_tree(ObClient
*self
,
1274 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1275 ObClient
* oldparent
,
1276 ObClient
*newparent
)
1282 Group transient windows are not allowed to have other group
1283 transient windows as their children.
1287 /* No change has occured */
1288 if (oldgroup
== newgroup
&& oldparent
== newparent
) return;
1290 /** Remove the client from the transient tree wherever it has changed **/
1292 /* If the window is becoming a direct transient for a window in its group
1293 then any group transients which were our children and are now becoming
1294 our parents need to stop being our children.
1296 Group transients can't be children of group transients already, but
1297 we could have any number of direct parents above up, any of which could
1298 be transient for the group, and we need to remove it from our children.
1300 if (oldparent
!= newparent
&&
1301 newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1302 newgroup
!= NULL
&& newgroup
== oldgroup
)
1304 ObClient
*look
= newparent
;
1306 self
->transients
= g_slist_remove(self
->transients
, look
);
1307 look
= look
->transient_for
;
1308 } while (look
!= NULL
&& look
!= OB_TRAN_GROUP
);
1312 /* If the group changed, or if we are just becoming transient for the
1313 group, then we need to remove any old group transient windows
1314 from our children. But if we were already transient for the group, then
1315 other group transients are not our children. */
1316 if ((oldgroup
!= newgroup
||
1317 (newparent
== OB_TRAN_GROUP
&& oldparent
!= newparent
)) &&
1318 oldgroup
!= NULL
&& oldparent
!= OB_TRAN_GROUP
)
1320 for (it
= self
->transients
; it
; it
= next
) {
1321 next
= g_slist_next(it
);
1323 if (c
->group
== oldgroup
)
1324 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1328 /* If we used to be transient for a group and now we are not, or we're
1329 transient for a new group, then we need to remove ourselves from all
1331 if (oldparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1332 oldparent
!= newparent
))
1334 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1336 if (c
!= self
&& (!c
->transient_for
||
1337 c
->transient_for
!= OB_TRAN_GROUP
))
1338 c
->transients
= g_slist_remove(c
->transients
, self
);
1341 /* If we used to be transient for a single window and we are no longer
1342 transient for it, then we need to remove ourself from its children */
1343 else if (oldparent
!= NULL
&& oldparent
!= OB_TRAN_GROUP
&&
1344 oldparent
!= newparent
)
1345 oldparent
->transients
= g_slist_remove(oldparent
->transients
, self
);
1348 /** Re-add the client to the transient tree wherever it has changed **/
1350 /* If we're now transient for a group and we weren't transient for it
1351 before then we need to add ourselves to all our new parents */
1352 if (newparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1353 oldparent
!= newparent
))
1355 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1357 if (c
!= self
&& (!c
->transient_for
||
1358 c
->transient_for
!= OB_TRAN_GROUP
))
1359 c
->transients
= g_slist_prepend(c
->transients
, self
);
1362 /* If we are now transient for a single window which we weren't before,
1363 we need to add ourselves to its children
1365 WARNING: Cyclical transient ness is possible if two windows are
1366 transient for eachother.
1368 else if (newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1369 newparent
!= oldparent
&&
1370 /* don't make ourself its child if it is already our child */
1371 !client_is_direct_child(self
, newparent
))
1372 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1374 /* If the group changed then we need to add any new group transient
1375 windows to our children. But if we're transient for the group, then
1376 other group transients are not our children.
1378 WARNING: Cyclical transient-ness is possible. For e.g. if:
1379 A is transient for the group
1380 B is transient for A
1381 C is transient for B
1382 A can't be transient for C or we have a cycle
1384 if (oldgroup
!= newgroup
&& newgroup
!= NULL
&&
1385 newparent
!= OB_TRAN_GROUP
)
1387 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1389 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
&&
1390 /* Don't make it our child if it is already our parent */
1391 !client_is_direct_child(c
, self
))
1393 self
->transients
= g_slist_prepend(self
->transients
, c
);
1399 static void client_get_mwm_hints(ObClient
*self
)
1404 self
->mwmhints
.flags
= 0; /* default to none */
1406 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1408 if (num
>= OB_MWM_ELEMENTS
) {
1409 self
->mwmhints
.flags
= hints
[0];
1410 self
->mwmhints
.functions
= hints
[1];
1411 self
->mwmhints
.decorations
= hints
[2];
1417 void client_get_type_and_transientness(ObClient
*self
)
1424 self
->transient
= FALSE
;
1426 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1427 /* use the first value that we know about in the array */
1428 for (i
= 0; i
< num
; ++i
) {
1429 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1430 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1431 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1432 self
->type
= OB_CLIENT_TYPE_DOCK
;
1433 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1434 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1435 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1436 self
->type
= OB_CLIENT_TYPE_MENU
;
1437 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1438 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1439 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1440 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1441 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1442 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1443 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1444 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1445 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1446 /* prevent this window from getting any decor or
1448 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1449 OB_MWM_FLAG_DECORATIONS
);
1450 self
->mwmhints
.decorations
= 0;
1451 self
->mwmhints
.functions
= 0;
1453 if (self
->type
!= (ObClientType
) -1)
1454 break; /* grab the first legit type */
1459 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1460 self
->transient
= TRUE
;
1462 if (self
->type
== (ObClientType
) -1) {
1463 /*the window type hint was not set, which means we either classify
1464 ourself as a normal window or a dialog, depending on if we are a
1466 if (self
->transient
)
1467 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1469 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1472 /* then, based on our type, we can update our transientness.. */
1473 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1474 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1475 self
->type
== OB_CLIENT_TYPE_MENU
||
1476 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1478 self
->transient
= TRUE
;
1482 void client_update_protocols(ObClient
*self
)
1485 guint num_return
, i
;
1487 self
->focus_notify
= FALSE
;
1488 self
->delete_window
= FALSE
;
1490 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1491 for (i
= 0; i
< num_return
; ++i
) {
1492 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1493 /* this means we can request the window to close */
1494 self
->delete_window
= TRUE
;
1495 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1496 /* if this protocol is requested, then the window will be
1497 notified whenever we want it to receive focus */
1498 self
->focus_notify
= TRUE
;
1500 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1501 /* if this protocol is requested, then resizing the
1502 window will be synchronized between the frame and the
1504 self
->sync_request
= TRUE
;
1512 void client_update_sync_request_counter(ObClient
*self
)
1516 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1517 self
->sync_counter
= i
;
1519 self
->sync_counter
= None
;
1523 void client_get_colormap(ObClient
*self
)
1525 XWindowAttributes wa
;
1527 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1528 client_update_colormap(self
, wa
.colormap
);
1531 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1533 if (colormap
== self
->colormap
) return;
1535 ob_debug("Setting client %s colormap: 0x%x\n", self
->title
, colormap
);
1537 if (client_focused(self
)) {
1538 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1539 self
->colormap
= colormap
;
1540 screen_install_colormap(self
, FALSE
); /* install new one */
1542 self
->colormap
= colormap
;
1545 void client_update_normal_hints(ObClient
*self
)
1551 self
->min_ratio
= 0.0f
;
1552 self
->max_ratio
= 0.0f
;
1553 SIZE_SET(self
->size_inc
, 1, 1);
1554 SIZE_SET(self
->base_size
, 0, 0);
1555 SIZE_SET(self
->min_size
, 0, 0);
1556 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1558 /* get the hints from the window */
1559 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1560 /* normal windows can't request placement! har har
1561 if (!client_normal(self))
1563 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1564 self
->sized
= (size
.flags
& (PSize
|USSize
));
1566 if (size
.flags
& PWinGravity
)
1567 self
->gravity
= size
.win_gravity
;
1569 if (size
.flags
& PAspect
) {
1570 if (size
.min_aspect
.y
)
1572 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1573 if (size
.max_aspect
.y
)
1575 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1578 if (size
.flags
& PMinSize
)
1579 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1581 if (size
.flags
& PMaxSize
)
1582 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1584 if (size
.flags
& PBaseSize
)
1585 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1587 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1588 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1592 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1594 /* start with everything (cept fullscreen) */
1596 (OB_FRAME_DECOR_TITLEBAR
|
1597 OB_FRAME_DECOR_HANDLE
|
1598 OB_FRAME_DECOR_GRIPS
|
1599 OB_FRAME_DECOR_BORDER
|
1600 OB_FRAME_DECOR_ICON
|
1601 OB_FRAME_DECOR_ALLDESKTOPS
|
1602 OB_FRAME_DECOR_ICONIFY
|
1603 OB_FRAME_DECOR_MAXIMIZE
|
1604 OB_FRAME_DECOR_SHADE
|
1605 OB_FRAME_DECOR_CLOSE
);
1607 (OB_CLIENT_FUNC_RESIZE
|
1608 OB_CLIENT_FUNC_MOVE
|
1609 OB_CLIENT_FUNC_ICONIFY
|
1610 OB_CLIENT_FUNC_MAXIMIZE
|
1611 OB_CLIENT_FUNC_SHADE
|
1612 OB_CLIENT_FUNC_CLOSE
|
1613 OB_CLIENT_FUNC_BELOW
|
1614 OB_CLIENT_FUNC_ABOVE
|
1615 OB_CLIENT_FUNC_UNDECORATE
);
1617 if (!(self
->min_size
.width
< self
->max_size
.width
||
1618 self
->min_size
.height
< self
->max_size
.height
))
1619 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1621 switch (self
->type
) {
1622 case OB_CLIENT_TYPE_NORMAL
:
1623 /* normal windows retain all of the possible decorations and
1624 functionality, and are the only windows that you can fullscreen */
1625 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1628 case OB_CLIENT_TYPE_DIALOG
:
1629 case OB_CLIENT_TYPE_UTILITY
:
1630 /* these windows don't have anything added or removed by default */
1633 case OB_CLIENT_TYPE_MENU
:
1634 case OB_CLIENT_TYPE_TOOLBAR
:
1635 /* these windows can't iconify or maximize */
1636 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1637 OB_FRAME_DECOR_MAXIMIZE
);
1638 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1639 OB_CLIENT_FUNC_MAXIMIZE
);
1642 case OB_CLIENT_TYPE_SPLASH
:
1643 /* these don't get get any decorations, and the only thing you can
1644 do with them is move them */
1645 self
->decorations
= 0;
1646 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1649 case OB_CLIENT_TYPE_DESKTOP
:
1650 /* these windows are not manipulated by the window manager */
1651 self
->decorations
= 0;
1652 self
->functions
= 0;
1655 case OB_CLIENT_TYPE_DOCK
:
1656 /* these windows are not manipulated by the window manager, but they
1657 can set below layer which has a special meaning */
1658 self
->decorations
= 0;
1659 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1663 /* Mwm Hints are applied subtractively to what has already been chosen for
1664 decor and functionality */
1665 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1666 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1667 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1668 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1670 /* if the mwm hints request no handle or title, then all
1671 decorations are disabled, but keep the border if that's
1673 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1674 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1676 self
->decorations
= 0;
1681 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1682 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1683 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1684 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1685 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1686 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1687 /* dont let mwm hints kill any buttons
1688 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1689 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1690 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1691 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1693 /* dont let mwm hints kill the close button
1694 if (! (self->mwmhints.functions & MwmFunc_Close))
1695 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1699 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1700 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1701 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1702 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1703 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1704 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1706 /* can't maximize without moving/resizing */
1707 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1708 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1709 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1710 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1711 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1714 if (self
->max_horz
&& self
->max_vert
) {
1715 /* you can't resize fully maximized windows */
1716 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1717 /* kill the handle on fully maxed windows */
1718 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1721 /* If there are no decorations to remove, don't allow the user to try
1723 if (self
->decorations
== 0)
1724 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1726 /* finally, the user can have requested no decorations, which overrides
1727 everything (but doesnt give it a border if it doesnt have one) */
1728 if (self
->undecorated
) {
1729 if (config_theme_keepborder
)
1730 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1732 self
->decorations
= 0;
1735 /* if we don't have a titlebar, then we cannot shade! */
1736 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1737 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1739 /* now we need to check against rules for the client's current state */
1740 if (self
->fullscreen
) {
1741 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1742 OB_CLIENT_FUNC_FULLSCREEN
|
1743 OB_CLIENT_FUNC_ICONIFY
);
1744 self
->decorations
= 0;
1747 client_change_allowed_actions(self
);
1750 client_reconfigure(self
);
1753 static void client_change_allowed_actions(ObClient
*self
)
1758 /* desktop windows are kept on all desktops */
1759 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1760 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1762 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1763 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1764 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1765 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1766 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1767 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1768 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1769 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1770 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1771 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1772 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1773 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1774 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1775 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1776 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1778 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1779 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1780 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1781 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1782 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1783 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1785 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1787 /* make sure the window isn't breaking any rules now */
1789 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1790 if (self
->frame
) client_shade(self
, FALSE
);
1791 else self
->shaded
= FALSE
;
1793 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1794 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
, FALSE
);
1795 else self
->iconic
= FALSE
;
1797 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1798 if (self
->frame
) client_fullscreen(self
, FALSE
);
1799 else self
->fullscreen
= FALSE
;
1801 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1803 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1804 else self
->max_vert
= self
->max_horz
= FALSE
;
1808 void client_reconfigure(ObClient
*self
)
1810 client_configure(self
, self
->area
.x
, self
->area
.y
,
1811 self
->area
.width
, self
->area
.height
,
1812 self
->border_width
, FALSE
, TRUE
);
1815 void client_update_wmhints(ObClient
*self
)
1819 /* assume a window takes input if it doesnt specify */
1820 self
->can_focus
= TRUE
;
1822 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1825 if (hints
->flags
& InputHint
)
1826 self
->can_focus
= hints
->input
;
1828 /* only do this when first managing the window *AND* when we aren't
1830 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1831 if (hints
->flags
& StateHint
)
1832 self
->iconic
= hints
->initial_state
== IconicState
;
1835 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1836 if (self
->urgent
&& !ur
)
1837 client_hilite(self
, TRUE
);
1838 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1839 client_hilite(self
, FALSE
);
1841 if (!(hints
->flags
& WindowGroupHint
))
1842 hints
->window_group
= None
;
1844 /* did the group state change? */
1845 if (hints
->window_group
!=
1846 (self
->group
? self
->group
->leader
: None
))
1848 ObGroup
*oldgroup
= self
->group
;
1850 /* remove from the old group if there was one */
1851 if (self
->group
!= NULL
) {
1852 group_remove(self
->group
, self
);
1856 /* add ourself to the group if we have one */
1857 if (hints
->window_group
!= None
) {
1858 self
->group
= group_add(hints
->window_group
, self
);
1861 /* Put ourselves into the new group's transient tree, and remove
1862 ourselves from the old group's */
1863 client_update_transient_tree(self
, oldgroup
, self
->group
,
1864 self
->transient_for
,
1865 self
->transient_for
);
1867 /* Lastly, being in a group, or not, can change if the window is
1868 transient for anything.
1870 The logic for this is:
1871 self->transient = TRUE always if the window wants to be
1872 transient for something, even if transient_for was NULL because
1873 it wasn't in a group before.
1875 If transient_for was NULL and oldgroup was NULL we can assume
1876 that when we add the new group, it will become transient for
1879 If transient_for was OB_TRAN_GROUP, then it must have already
1880 had a group. If it is getting a new group, the above call to
1881 client_update_transient_tree has already taken care of
1882 everything ! If it is losing all group status then it will
1883 no longer be transient for anything and that needs to be
1886 if (self
->transient
&&
1887 ((self
->transient_for
== NULL
&& oldgroup
== NULL
) ||
1888 (self
->transient_for
== OB_TRAN_GROUP
&& !self
->group
)))
1889 client_update_transient_for(self
);
1892 /* the WM_HINTS can contain an icon */
1893 if (hints
->flags
& IconPixmapHint
)
1894 client_update_icons(self
);
1900 void client_update_title(ObClient
*self
)
1903 gchar
*visible
= NULL
;
1905 g_free(self
->title
);
1908 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1909 /* try old x stuff */
1910 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1911 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1912 if (self
->transient
) {
1914 GNOME alert windows are not given titles:
1915 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1917 data
= g_strdup("");
1919 data
= g_strdup("Unnamed Window");
1923 if (self
->client_machine
) {
1924 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1929 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1930 self
->title
= visible
;
1933 frame_adjust_title(self
->frame
);
1935 /* update the icon title */
1937 g_free(self
->icon_title
);
1940 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1941 /* try old x stuff */
1942 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1943 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1944 data
= g_strdup(self
->title
);
1946 if (self
->client_machine
) {
1947 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1952 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
1953 self
->icon_title
= visible
;
1956 void client_update_strut(ObClient
*self
)
1960 gboolean got
= FALSE
;
1963 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1967 STRUT_PARTIAL_SET(strut
,
1968 data
[0], data
[2], data
[1], data
[3],
1969 data
[4], data
[5], data
[8], data
[9],
1970 data
[6], data
[7], data
[10], data
[11]);
1976 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1982 /* use the screen's width/height */
1983 a
= screen_physical_area();
1985 STRUT_PARTIAL_SET(strut
,
1986 data
[0], data
[2], data
[1], data
[3],
1987 a
->y
, a
->y
+ a
->height
- 1,
1988 a
->x
, a
->x
+ a
->width
- 1,
1989 a
->y
, a
->y
+ a
->height
- 1,
1990 a
->x
, a
->x
+ a
->width
- 1);
1996 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1997 0, 0, 0, 0, 0, 0, 0, 0);
1999 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2000 self
->strut
= strut
;
2002 /* updating here is pointless while we're being mapped cuz we're not in
2003 the client list yet */
2005 screen_update_areas();
2009 void client_update_icons(ObClient
*self
)
2015 for (i
= 0; i
< self
->nicons
; ++i
)
2016 g_free(self
->icons
[i
].data
);
2017 if (self
->nicons
> 0)
2018 g_free(self
->icons
);
2021 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2022 /* figure out how many valid icons are in here */
2024 while (num
- i
> 2) {
2028 if (i
> num
|| w
*h
== 0) break;
2032 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2034 /* store the icons */
2036 for (j
= 0; j
< self
->nicons
; ++j
) {
2039 w
= self
->icons
[j
].width
= data
[i
++];
2040 h
= self
->icons
[j
].height
= data
[i
++];
2042 if (w
*h
== 0) continue;
2044 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2045 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2050 self
->icons
[j
].data
[t
] =
2051 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2052 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2053 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2054 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2063 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2064 if (hints
->flags
& IconPixmapHint
) {
2066 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2067 xerror_set_ignore(TRUE
);
2068 if (!RrPixmapToRGBA(ob_rr_inst
,
2070 (hints
->flags
& IconMaskHint
?
2071 hints
->icon_mask
: None
),
2072 &self
->icons
[self
->nicons
-1].width
,
2073 &self
->icons
[self
->nicons
-1].height
,
2074 &self
->icons
[self
->nicons
-1].data
)){
2075 g_free(&self
->icons
[self
->nicons
-1]);
2078 xerror_set_ignore(FALSE
);
2084 /* set the default icon onto the window
2085 in theory, this could be a race, but if a window doesn't set an icon
2086 or removes it entirely, it's not very likely it is going to set one
2087 right away afterwards */
2088 if (self
->nicons
== 0) {
2089 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2092 data
= g_new(gulong
, 48*48+2);
2093 data
[0] = data
[1] = 48;
2094 for (i
= 0; i
< 48*48; ++i
)
2095 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2096 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2097 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2098 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2099 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2101 } else if (self
->frame
)
2102 /* don't draw the icon empty if we're just setting one now anyways,
2103 we'll get the property change any second */
2104 frame_adjust_icon(self
->frame
);
2107 void client_update_user_time(ObClient
*self
)
2110 gboolean got
= FALSE
;
2112 if (self
->user_time_window
)
2113 got
= PROP_GET32(self
->user_time_window
,
2114 net_wm_user_time
, cardinal
, &time
);
2116 got
= PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
);
2119 /* we set this every time, not just when it grows, because in practice
2120 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
2121 backward we don't want all windows to stop focusing. we'll just
2122 assume noone is setting times older than the last one, cuz that
2123 would be pretty stupid anyways
2125 self
->user_time
= time
;
2127 /*ob_debug("window %s user time %u\n", self->title, time);*/
2131 void client_update_user_time_window(ObClient
*self
)
2135 if (!PROP_GET32(self
->window
, net_wm_user_time_window
, window
, &w
))
2138 if (w
!= self
->user_time_window
) {
2139 /* remove the old window */
2140 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
2141 self
->user_time_window
= None
;
2143 if (self
->group
&& self
->group
->leader
== w
) {
2144 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2145 "_NET_WM_USER_TYPE_WINDOW to its group leader\n");
2146 /* do it anyways..? */
2148 else if (w
== self
->window
) {
2149 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2150 "_NET_WM_USER_TIME_WINDOW to itself\n");
2151 w
= None
; /* don't do it */
2154 /* add the new window */
2155 propwin_add(w
, OB_PROPWIN_USER_TIME
, self
);
2156 self
->user_time_window
= w
;
2158 /* and update from it */
2159 client_update_user_time(self
);
2163 void client_update_icon_geometry(ObClient
*self
)
2168 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2170 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2173 /* don't let them set it with an area < 0 */
2174 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2175 MAX(data
[2],0), MAX(data
[3],0));
2179 static void client_get_session_ids(ObClient
*self
)
2186 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2189 /* get the SM_CLIENT_ID */
2192 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2194 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2196 /* get the WM_CLASS (name and class). make them "" if they are not
2200 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2202 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2206 self
->name
= g_strdup(ss
[0]);
2208 self
->class = g_strdup(ss
[1]);
2213 if (self
->name
== NULL
) self
->name
= g_strdup("");
2214 if (self
->class == NULL
) self
->class = g_strdup("");
2216 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2219 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2221 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2226 self
->role
= g_strdup("");
2228 /* get the WM_COMMAND */
2232 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2234 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2237 /* merge/mash them all together */
2238 gchar
*merge
= NULL
;
2241 for (i
= 0; ss
[i
]; ++i
) {
2244 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2246 merge
= g_strconcat(ss
[i
], NULL
);
2251 self
->wm_command
= merge
;
2254 /* get the WM_CLIENT_MACHINE */
2257 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2259 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2262 gchar localhost
[128];
2264 gethostname(localhost
, 127);
2265 localhost
[127] = '\0';
2266 if (strcmp(localhost
, s
) != 0)
2267 self
->client_machine
= s
;
2273 static void client_change_wm_state(ObClient
*self
)
2278 old
= self
->wmstate
;
2280 if (self
->shaded
|| self
->iconic
||
2281 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2283 self
->wmstate
= IconicState
;
2285 self
->wmstate
= NormalState
;
2287 if (old
!= self
->wmstate
) {
2288 PROP_MSG(self
->window
, kde_wm_change_state
,
2289 self
->wmstate
, 1, 0, 0);
2291 state
[0] = self
->wmstate
;
2293 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2297 static void client_change_state(ObClient
*self
)
2299 gulong netstate
[11];
2304 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2306 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2308 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2309 if (self
->skip_taskbar
)
2310 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2311 if (self
->skip_pager
)
2312 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2313 if (self
->fullscreen
)
2314 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2316 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2318 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2320 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2322 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2323 if (self
->demands_attention
)
2324 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2325 if (self
->undecorated
)
2326 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2327 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2330 frame_adjust_state(self
->frame
);
2333 ObClient
*client_search_focus_tree(ObClient
*self
)
2338 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2339 if (client_focused(it
->data
)) return it
->data
;
2340 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2345 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2347 if (self
->transient_for
) {
2348 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2349 return client_search_focus_tree_full(self
->transient_for
);
2353 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2354 if (it
->data
!= self
) {
2355 ObClient
*c
= it
->data
;
2357 if (client_focused(c
)) return c
;
2358 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2364 /* this function checks the whole tree, the client_search_focus_tree
2365 does not, so we need to check this window */
2366 if (client_focused(self
))
2368 return client_search_focus_tree(self
);
2371 gboolean
client_has_parent(ObClient
*self
)
2373 if (self
->transient_for
) {
2374 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2375 if (client_normal(self
->transient_for
))
2378 else if (self
->group
) {
2381 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2382 if (it
->data
!= self
&& client_normal(it
->data
))
2390 static ObStackingLayer
calc_layer(ObClient
*self
)
2394 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2395 l
= OB_STACKING_LAYER_DESKTOP
;
2396 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2397 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2398 else l
= OB_STACKING_LAYER_ABOVE
;
2400 else if ((self
->fullscreen
||
2401 /* No decorations and fills the monitor = oldskool fullscreen.
2402 But not for maximized windows.
2404 (self
->decorations
== 0 &&
2405 !(self
->max_horz
&& self
->max_vert
) &&
2406 RECT_EQUAL(self
->area
,
2407 *screen_physical_area_monitor
2408 (client_monitor(self
))))) &&
2409 (client_focused(self
) || client_search_focus_tree(self
)))
2410 l
= OB_STACKING_LAYER_FULLSCREEN
;
2411 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2412 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2413 else l
= OB_STACKING_LAYER_NORMAL
;
2418 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2419 ObStackingLayer min
)
2421 ObStackingLayer old
, own
;
2425 own
= calc_layer(self
);
2426 self
->layer
= MAX(own
, min
);
2428 if (self
->layer
!= old
) {
2429 stacking_remove(CLIENT_AS_WINDOW(self
));
2430 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2433 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2434 client_calc_layer_recursive(it
->data
, orig
,
2438 void client_calc_layer(ObClient
*self
)
2445 /* transients take on the layer of their parents */
2446 it
= client_search_all_top_parents(self
);
2448 for (; it
; it
= g_slist_next(it
))
2449 client_calc_layer_recursive(it
->data
, orig
, 0);
2452 gboolean
client_should_show(ObClient
*self
)
2456 if (client_normal(self
) && screen_showing_desktop
)
2458 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2464 gboolean
client_show(ObClient
*self
)
2466 gboolean show
= FALSE
;
2468 if (client_should_show(self
)) {
2469 frame_show(self
->frame
);
2472 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2473 it needs to be in IconicState. This includes when it is on another
2476 client_change_wm_state(self
);
2481 gboolean
client_hide(ObClient
*self
)
2483 gboolean hide
= FALSE
;
2485 if (!client_should_show(self
)) {
2486 if (self
== focus_client
) {
2487 /* if there is a grab going on, then we need to cancel it. if we
2488 move focus during the grab, applications will get
2489 NotifyWhileGrabbed events and ignore them !
2491 actions should not rely on being able to move focus during an
2494 event_cancel_all_key_grabs();
2497 frame_hide(self
->frame
);
2500 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2501 it needs to be in IconicState. This includes when it is on another
2504 client_change_wm_state(self
);
2509 void client_showhide(ObClient
*self
)
2511 if (!client_show(self
))
2515 gboolean
client_normal(ObClient
*self
) {
2516 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2517 self
->type
== OB_CLIENT_TYPE_DOCK
||
2518 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2521 gboolean
client_helper(ObClient
*self
)
2523 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2524 self
->type
== OB_CLIENT_TYPE_MENU
||
2525 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2528 gboolean
client_mouse_focusable(ObClient
*self
)
2530 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2531 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2532 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2533 self
->type
== OB_CLIENT_TYPE_DOCK
);
2536 gboolean
client_enter_focusable(ObClient
*self
)
2538 /* you can focus desktops but it shouldn't on enter */
2539 return (client_mouse_focusable(self
) &&
2540 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2544 static void client_apply_startup_state(ObClient
*self
,
2545 gint x
, gint y
, gint w
, gint h
)
2547 /* save the states that we are going to apply */
2548 gboolean iconic
= self
->iconic
;
2549 gboolean fullscreen
= self
->fullscreen
;
2550 gboolean undecorated
= self
->undecorated
;
2551 gboolean shaded
= self
->shaded
;
2552 gboolean demands_attention
= self
->demands_attention
;
2553 gboolean max_horz
= self
->max_horz
;
2554 gboolean max_vert
= self
->max_vert
;
2556 /* turn them all off in the client, so they won't affect the window
2558 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2559 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2561 /* move the client to its placed position, or it it's already there,
2562 generate a ConfigureNotify telling the client where it is.
2564 do this after adjusting the frame. otherwise it gets all weird and
2565 clients don't work right
2567 do this before applying the states so they have the correct
2568 pre-max/pre-fullscreen values
2570 client_configure(self
, x
, y
, w
, h
, self
->border_width
, FALSE
, TRUE
);
2571 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2572 self
->window
, self
->area
.x
, self
->area
.y
,
2573 self
->area
.width
, self
->area
.height
);
2575 /* apply the states. these are in a carefully crafted order.. */
2578 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2580 client_fullscreen(self
, TRUE
);
2582 client_set_undecorated(self
, TRUE
);
2584 client_shade(self
, TRUE
);
2585 if (demands_attention
)
2586 client_hilite(self
, TRUE
);
2588 if (max_vert
&& max_horz
)
2589 client_maximize(self
, TRUE
, 0);
2591 client_maximize(self
, TRUE
, 2);
2593 client_maximize(self
, TRUE
, 1);
2595 /* set the desktop hint, to make sure that it always exists */
2596 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2598 /* nothing to do for the other states:
2607 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2609 /* these should be the current values. this is for when you're not moving,
2611 g_assert(*x
== self
->area
.x
);
2612 g_assert(oldw
== self
->area
.width
);
2615 switch (self
->gravity
) {
2617 case NorthWestGravity
:
2619 case SouthWestGravity
:
2626 *x
-= (neww
- oldw
) / 2;
2628 case NorthEastGravity
:
2630 case SouthEastGravity
:
2636 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2638 /* these should be the current values. this is for when you're not moving,
2640 g_assert(*y
== self
->area
.y
);
2641 g_assert(oldh
== self
->area
.height
);
2644 switch (self
->gravity
) {
2646 case NorthWestGravity
:
2648 case NorthEastGravity
:
2655 *y
-= (newh
- oldh
) / 2;
2657 case SouthWestGravity
:
2659 case SouthEastGravity
:
2665 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2666 gint
*logicalw
, gint
*logicalh
,
2669 Rect desired_area
= {*x
, *y
, *w
, *h
};
2671 /* make the frame recalculate its dimentions n shit without changing
2672 anything visible for real, this way the constraints below can work with
2673 the updated frame dimensions. */
2674 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2676 /* work within the prefered sizes given by the window */
2677 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2678 gint basew
, baseh
, minw
, minh
;
2680 /* base size is substituted with min size if not specified */
2681 if (self
->base_size
.width
|| self
->base_size
.height
) {
2682 basew
= self
->base_size
.width
;
2683 baseh
= self
->base_size
.height
;
2685 basew
= self
->min_size
.width
;
2686 baseh
= self
->min_size
.height
;
2688 /* min size is substituted with base size if not specified */
2689 if (self
->min_size
.width
|| self
->min_size
.height
) {
2690 minw
= self
->min_size
.width
;
2691 minh
= self
->min_size
.height
;
2693 minw
= self
->base_size
.width
;
2694 minh
= self
->base_size
.height
;
2697 /* if this is a user-requested resize, then check against min/max
2700 /* smaller than min size or bigger than max size? */
2701 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2702 if (*w
< minw
) *w
= minw
;
2703 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2704 if (*h
< minh
) *h
= minh
;
2709 /* keep to the increments */
2710 *w
/= self
->size_inc
.width
;
2711 *h
/= self
->size_inc
.height
;
2713 /* you cannot resize to nothing */
2714 if (basew
+ *w
< 1) *w
= 1 - basew
;
2715 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2717 /* save the logical size */
2718 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2719 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2721 *w
*= self
->size_inc
.width
;
2722 *h
*= self
->size_inc
.height
;
2727 /* adjust the height to match the width for the aspect ratios.
2728 for this, min size is not substituted for base size ever. */
2729 *w
-= self
->base_size
.width
;
2730 *h
-= self
->base_size
.height
;
2732 if (!self
->fullscreen
) {
2733 if (self
->min_ratio
)
2734 if (*h
* self
->min_ratio
> *w
) {
2735 *h
= (gint
)(*w
/ self
->min_ratio
);
2737 /* you cannot resize to nothing */
2740 *w
= (gint
)(*h
* self
->min_ratio
);
2743 if (self
->max_ratio
)
2744 if (*h
* self
->max_ratio
< *w
) {
2745 *h
= (gint
)(*w
/ self
->max_ratio
);
2747 /* you cannot resize to nothing */
2750 *w
= (gint
)(*h
* self
->min_ratio
);
2755 *w
+= self
->base_size
.width
;
2756 *h
+= self
->base_size
.height
;
2759 /* gets the frame's position */
2760 frame_client_gravity(self
->frame
, x
, y
, *w
, *h
);
2762 /* these positions are frame positions, not client positions */
2764 /* set the size and position if fullscreen */
2765 if (self
->fullscreen
) {
2769 i
= screen_find_monitor(&desired_area
);
2770 a
= screen_physical_area_monitor(i
);
2777 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2779 } else if (self
->max_horz
|| self
->max_vert
) {
2783 i
= screen_find_monitor(&desired_area
);
2784 a
= screen_area_monitor(self
->desktop
, i
);
2786 /* set the size and position if maximized */
2787 if (self
->max_horz
) {
2789 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2791 if (self
->max_vert
) {
2793 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2796 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2800 /* gets the client's position */
2801 frame_frame_gravity(self
->frame
, x
, y
, *w
, *h
);
2803 /* these override the above states! if you cant move you can't move! */
2805 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2809 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2810 *w
= self
->area
.width
;
2811 *h
= self
->area
.height
;
2820 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
, gint b
,
2821 gboolean user
, gboolean final
)
2824 gboolean send_resize_client
;
2825 gboolean moved
= FALSE
, resized
= FALSE
;
2826 gboolean fmoved
, fresized
;
2827 guint fdecor
= self
->frame
->decorations
;
2828 gboolean fhorz
= self
->frame
->max_horz
;
2829 gboolean fvert
= self
->frame
->max_vert
;
2830 gint logicalw
, logicalh
;
2832 /* find the new x, y, width, and height (and logical size) */
2833 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2835 /* set the logical size if things changed */
2836 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2837 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2839 /* figure out if we moved or resized or what */
2840 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2841 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
||
2842 b
!= self
->border_width
;
2844 oldw
= self
->area
.width
;
2845 oldh
= self
->area
.height
;
2846 RECT_SET(self
->area
, x
, y
, w
, h
);
2847 self
->border_width
= b
;
2849 /* for app-requested resizes, always resize if 'resized' is true.
2850 for user-requested ones, only resize if final is true, or when
2851 resizing in redraw mode */
2852 send_resize_client
= ((!user
&& resized
) ||
2854 (resized
&& config_resize_redraw
))));
2856 /* if the client is enlarging, then resize the client before the frame */
2857 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2858 XWindowChanges changes
;
2859 changes
.x
= self
->frame
->size
.left
- self
->border_width
;
2860 changes
.y
= self
->frame
->size
.top
-self
->border_width
;
2861 changes
.width
= MAX(w
, oldw
);
2862 changes
.height
= MAX(h
, oldh
);
2863 changes
.border_width
= self
->border_width
;
2864 XConfigureWindow(ob_display
, self
->window
,
2865 CWX
|CWY
|CWWidth
|CWHeight
|CWBorderWidth
,
2869 /* find the frame's dimensions and move/resize it */
2873 /* if decorations changed, then readjust everything for the frame */
2874 if (self
->decorations
!= fdecor
||
2875 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2877 fmoved
= fresized
= TRUE
;
2880 /* adjust the frame */
2881 if (fmoved
|| fresized
)
2882 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2884 if ((!user
|| (user
&& final
)) && !resized
)
2888 /* we have reset the client to 0 border width, so don't include
2889 it in these coords */
2890 POINT_SET(self
->root_pos
,
2891 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2893 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2894 self
->border_width
);
2896 event
.type
= ConfigureNotify
;
2897 event
.xconfigure
.display
= ob_display
;
2898 event
.xconfigure
.event
= self
->window
;
2899 event
.xconfigure
.window
= self
->window
;
2901 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
2902 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
2904 /* root window real coords */
2905 event
.xconfigure
.x
= self
->root_pos
.x
;
2906 event
.xconfigure
.y
= self
->root_pos
.y
;
2907 event
.xconfigure
.width
= w
;
2908 event
.xconfigure
.height
= h
;
2909 event
.xconfigure
.border_width
= self
->border_width
;
2910 event
.xconfigure
.above
= None
;
2911 event
.xconfigure
.override_redirect
= FALSE
;
2912 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2913 FALSE
, StructureNotifyMask
, &event
);
2916 /* if the client is shrinking, then resize the frame before the client */
2917 if (send_resize_client
&& (w
<= oldw
&& h
<= oldh
)) {
2918 if (send_resize_client
) {
2919 XWindowChanges changes
;
2920 changes
.x
= self
->frame
->size
.left
- self
->border_width
;
2921 changes
.y
= self
->frame
->size
.top
-self
->border_width
;
2924 changes
.border_width
= self
->border_width
;
2925 XConfigureWindow(ob_display
, self
->window
,
2926 CWX
|CWY
|CWWidth
|CWHeight
|CWBorderWidth
,
2934 void client_fullscreen(ObClient
*self
, gboolean fs
)
2938 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2939 self
->fullscreen
== fs
) return; /* already done */
2941 self
->fullscreen
= fs
;
2942 client_change_state(self
); /* change the state hints on the client */
2945 self
->pre_fullscreen_area
= self
->area
;
2946 /* if the window is maximized, its area isn't all that meaningful.
2947 save it's premax area instead. */
2948 if (self
->max_horz
) {
2949 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2950 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2952 if (self
->max_vert
) {
2953 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2954 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2957 /* these will help configure_full figure out where to fullscreen
2961 w
= self
->area
.width
;
2962 h
= self
->area
.height
;
2964 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
2965 self
->pre_fullscreen_area
.height
> 0);
2967 x
= self
->pre_fullscreen_area
.x
;
2968 y
= self
->pre_fullscreen_area
.y
;
2969 w
= self
->pre_fullscreen_area
.width
;
2970 h
= self
->pre_fullscreen_area
.height
;
2971 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2974 client_setup_decor_and_functions(self
, FALSE
);
2975 client_move_resize(self
, x
, y
, w
, h
);
2977 /* and adjust our layer/stacking. do this after resizing the window,
2978 and applying decorations, because windows which fill the screen are
2979 considered "fullscreen" and it affects their layer */
2980 client_calc_layer(self
);
2983 /* try focus us when we go into fullscreen mode */
2988 static void client_iconify_recursive(ObClient
*self
,
2989 gboolean iconic
, gboolean curdesk
,
2990 gboolean hide_animation
)
2993 gboolean changed
= FALSE
;
2996 if (self
->iconic
!= iconic
) {
2997 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3001 /* don't let non-normal windows iconify along with their parents
3003 if (client_normal(self
)) {
3004 self
->iconic
= iconic
;
3006 /* update the focus lists.. iconic windows go to the bottom of
3008 focus_order_to_bottom(self
);
3013 self
->iconic
= iconic
;
3015 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3016 self
->desktop
!= DESKTOP_ALL
)
3017 client_set_desktop(self
, screen_desktop
, FALSE
);
3019 /* this puts it after the current focused window */
3020 focus_order_remove(self
);
3021 focus_order_add_new(self
);
3028 client_change_state(self
);
3029 if (config_animate_iconify
&& !hide_animation
)
3030 frame_begin_iconify_animation(self
->frame
, iconic
);
3031 /* do this after starting the animation so it doesn't flash */
3032 client_showhide(self
);
3035 /* iconify all direct transients, and deiconify all transients
3037 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3038 if (it
->data
!= self
)
3039 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3040 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3044 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3045 gboolean hide_animation
)
3047 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3048 /* move up the transient chain as far as possible first */
3049 self
= client_search_top_normal_parent(self
);
3050 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3054 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3058 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3059 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3061 /* check if already done */
3063 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3064 if (dir
== 1 && self
->max_horz
) return;
3065 if (dir
== 2 && self
->max_vert
) return;
3067 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3068 if (dir
== 1 && !self
->max_horz
) return;
3069 if (dir
== 2 && !self
->max_vert
) return;
3072 /* these will help configure_full figure out which screen to fill with
3076 w
= self
->area
.width
;
3077 h
= self
->area
.height
;
3080 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3081 RECT_SET(self
->pre_max_area
,
3082 self
->area
.x
, self
->pre_max_area
.y
,
3083 self
->area
.width
, self
->pre_max_area
.height
);
3085 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3086 RECT_SET(self
->pre_max_area
,
3087 self
->pre_max_area
.x
, self
->area
.y
,
3088 self
->pre_max_area
.width
, self
->area
.height
);
3091 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3092 g_assert(self
->pre_max_area
.width
> 0);
3094 x
= self
->pre_max_area
.x
;
3095 w
= self
->pre_max_area
.width
;
3097 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3098 0, self
->pre_max_area
.height
);
3100 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3101 g_assert(self
->pre_max_area
.height
> 0);
3103 y
= self
->pre_max_area
.y
;
3104 h
= self
->pre_max_area
.height
;
3106 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3107 self
->pre_max_area
.width
, 0);
3111 if (dir
== 0 || dir
== 1) /* horz */
3112 self
->max_horz
= max
;
3113 if (dir
== 0 || dir
== 2) /* vert */
3114 self
->max_vert
= max
;
3116 client_change_state(self
); /* change the state hints on the client */
3118 client_setup_decor_and_functions(self
, FALSE
);
3119 client_move_resize(self
, x
, y
, w
, h
);
3122 void client_shade(ObClient
*self
, gboolean shade
)
3124 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3125 shade
) || /* can't shade */
3126 self
->shaded
== shade
) return; /* already done */
3128 self
->shaded
= shade
;
3129 client_change_state(self
);
3130 client_change_wm_state(self
); /* the window is being hidden/shown */
3131 /* resize the frame to just the titlebar */
3132 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
3135 void client_close(ObClient
*self
)
3139 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3141 /* in the case that the client provides no means to requesting that it
3142 close, we just kill it */
3143 if (!self
->delete_window
)
3147 XXX: itd be cool to do timeouts and shit here for killing the client's
3149 like... if the window is around after 5 seconds, then the close button
3150 turns a nice red, and if this function is called again, the client is
3154 ce
.xclient
.type
= ClientMessage
;
3155 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3156 ce
.xclient
.display
= ob_display
;
3157 ce
.xclient
.window
= self
->window
;
3158 ce
.xclient
.format
= 32;
3159 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
3160 ce
.xclient
.data
.l
[1] = event_curtime
;
3161 ce
.xclient
.data
.l
[2] = 0l;
3162 ce
.xclient
.data
.l
[3] = 0l;
3163 ce
.xclient
.data
.l
[4] = 0l;
3164 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3167 void client_kill(ObClient
*self
)
3169 XKillClient(ob_display
, self
->window
);
3172 void client_hilite(ObClient
*self
, gboolean hilite
)
3174 if (self
->demands_attention
== hilite
)
3175 return; /* no change */
3177 /* don't allow focused windows to hilite */
3178 self
->demands_attention
= hilite
&& !client_focused(self
);
3179 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3180 if (self
->demands_attention
)
3181 frame_flash_start(self
->frame
);
3183 frame_flash_stop(self
->frame
);
3184 client_change_state(self
);
3188 void client_set_desktop_recursive(ObClient
*self
,
3195 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3197 ob_debug("Setting desktop %u\n", target
+1);
3199 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3201 old
= self
->desktop
;
3202 self
->desktop
= target
;
3203 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3204 /* the frame can display the current desktop state */
3205 frame_adjust_state(self
->frame
);
3206 /* 'move' the window to the new desktop */
3208 client_showhide(self
);
3209 /* raise if it was not already on the desktop */
3210 if (old
!= DESKTOP_ALL
)
3211 stacking_raise(CLIENT_AS_WINDOW(self
));
3212 if (STRUT_EXISTS(self
->strut
))
3213 screen_update_areas();
3216 /* move all transients */
3217 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3218 if (it
->data
!= self
)
3219 if (client_is_direct_child(self
, it
->data
))
3220 client_set_desktop_recursive(it
->data
, target
, donthide
);
3223 void client_set_desktop(ObClient
*self
, guint target
,
3226 self
= client_search_top_normal_parent(self
);
3227 client_set_desktop_recursive(self
, target
, donthide
);
3230 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3232 while (child
!= parent
&&
3233 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
3234 child
= child
->transient_for
;
3235 return child
== parent
;
3238 ObClient
*client_search_modal_child(ObClient
*self
)
3243 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3244 ObClient
*c
= it
->data
;
3245 if ((ret
= client_search_modal_child(c
))) return ret
;
3246 if (c
->modal
) return c
;
3251 gboolean
client_validate(ObClient
*self
)
3255 XSync(ob_display
, FALSE
); /* get all events on the server */
3257 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3258 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3259 XPutBackEvent(ob_display
, &e
);
3266 void client_set_wm_state(ObClient
*self
, glong state
)
3268 if (state
== self
->wmstate
) return; /* no change */
3272 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3275 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3280 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3282 gboolean shaded
= self
->shaded
;
3283 gboolean fullscreen
= self
->fullscreen
;
3284 gboolean undecorated
= self
->undecorated
;
3285 gboolean max_horz
= self
->max_horz
;
3286 gboolean max_vert
= self
->max_vert
;
3287 gboolean modal
= self
->modal
;
3288 gboolean iconic
= self
->iconic
;
3289 gboolean demands_attention
= self
->demands_attention
;
3290 gboolean above
= self
->above
;
3291 gboolean below
= self
->below
;
3294 if (!(action
== prop_atoms
.net_wm_state_add
||
3295 action
== prop_atoms
.net_wm_state_remove
||
3296 action
== prop_atoms
.net_wm_state_toggle
))
3297 /* an invalid action was passed to the client message, ignore it */
3300 for (i
= 0; i
< 2; ++i
) {
3301 Atom state
= i
== 0 ? data1
: data2
;
3303 if (!state
) continue;
3305 /* if toggling, then pick whether we're adding or removing */
3306 if (action
== prop_atoms
.net_wm_state_toggle
) {
3307 if (state
== prop_atoms
.net_wm_state_modal
)
3308 action
= modal
? prop_atoms
.net_wm_state_remove
:
3309 prop_atoms
.net_wm_state_add
;
3310 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3311 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3312 prop_atoms
.net_wm_state_add
;
3313 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3314 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3315 prop_atoms
.net_wm_state_add
;
3316 else if (state
== prop_atoms
.net_wm_state_shaded
)
3317 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3318 prop_atoms
.net_wm_state_add
;
3319 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3320 action
= self
->skip_taskbar
?
3321 prop_atoms
.net_wm_state_remove
:
3322 prop_atoms
.net_wm_state_add
;
3323 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3324 action
= self
->skip_pager
?
3325 prop_atoms
.net_wm_state_remove
:
3326 prop_atoms
.net_wm_state_add
;
3327 else if (state
== prop_atoms
.net_wm_state_hidden
)
3328 action
= self
->iconic
?
3329 prop_atoms
.net_wm_state_remove
:
3330 prop_atoms
.net_wm_state_add
;
3331 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3332 action
= fullscreen
?
3333 prop_atoms
.net_wm_state_remove
:
3334 prop_atoms
.net_wm_state_add
;
3335 else if (state
== prop_atoms
.net_wm_state_above
)
3336 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3337 prop_atoms
.net_wm_state_add
;
3338 else if (state
== prop_atoms
.net_wm_state_below
)
3339 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3340 prop_atoms
.net_wm_state_add
;
3341 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3342 action
= self
->demands_attention
?
3343 prop_atoms
.net_wm_state_remove
:
3344 prop_atoms
.net_wm_state_add
;
3345 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3346 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3347 prop_atoms
.net_wm_state_add
;
3350 if (action
== prop_atoms
.net_wm_state_add
) {
3351 if (state
== prop_atoms
.net_wm_state_modal
) {
3353 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3355 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3357 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3359 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3360 self
->skip_taskbar
= TRUE
;
3361 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3362 self
->skip_pager
= TRUE
;
3363 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3365 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3367 } else if (state
== prop_atoms
.net_wm_state_above
) {
3370 } else if (state
== prop_atoms
.net_wm_state_below
) {
3373 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3374 demands_attention
= TRUE
;
3375 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3379 } else { /* action == prop_atoms.net_wm_state_remove */
3380 if (state
== prop_atoms
.net_wm_state_modal
) {
3382 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3384 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3386 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3388 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3389 self
->skip_taskbar
= FALSE
;
3390 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3391 self
->skip_pager
= FALSE
;
3392 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3394 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3396 } else if (state
== prop_atoms
.net_wm_state_above
) {
3398 } else if (state
== prop_atoms
.net_wm_state_below
) {
3400 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3401 demands_attention
= FALSE
;
3402 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3403 undecorated
= FALSE
;
3408 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3409 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3411 if (max_horz
== max_vert
) { /* both going the same way */
3412 client_maximize(self
, max_horz
, 0);
3414 client_maximize(self
, max_horz
, 1);
3415 client_maximize(self
, max_vert
, 2);
3419 if (max_horz
!= self
->max_horz
)
3420 client_maximize(self
, max_horz
, 1);
3422 client_maximize(self
, max_vert
, 2);
3425 /* change fullscreen state before shading, as it will affect if the window
3427 if (fullscreen
!= self
->fullscreen
)
3428 client_fullscreen(self
, fullscreen
);
3429 if (shaded
!= self
->shaded
)
3430 client_shade(self
, shaded
);
3431 if (undecorated
!= self
->undecorated
)
3432 client_set_undecorated(self
, undecorated
);
3433 if (above
!= self
->above
|| below
!= self
->below
) {
3434 self
->above
= above
;
3435 self
->below
= below
;
3436 client_calc_layer(self
);
3439 if (modal
!= self
->modal
) {
3440 self
->modal
= modal
;
3441 /* when a window changes modality, then its stacking order with its
3442 transients needs to change */
3443 stacking_raise(CLIENT_AS_WINDOW(self
));
3445 /* it also may get focused. if something is focused that shouldn't
3446 be focused anymore, then move the focus */
3447 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3448 client_focus(focus_client
);
3451 if (iconic
!= self
->iconic
)
3452 client_iconify(self
, iconic
, FALSE
, FALSE
);
3454 if (demands_attention
!= self
->demands_attention
)
3455 client_hilite(self
, demands_attention
);
3457 client_change_state(self
); /* change the hint to reflect these changes */
3460 ObClient
*client_focus_target(ObClient
*self
)
3462 ObClient
*child
= NULL
;
3464 child
= client_search_modal_child(self
);
3465 if (child
) return child
;
3469 gboolean
client_can_focus(ObClient
*self
)
3471 /* choose the correct target */
3472 self
= client_focus_target(self
);
3474 if (!self
->frame
->visible
)
3477 if (!(self
->can_focus
|| self
->focus_notify
))
3483 gboolean
client_focus(ObClient
*self
)
3485 /* we might not focus this window, so if we have modal children which would
3486 be focused instead, bring them to this desktop */
3487 client_bring_modal_windows(self
);
3489 /* choose the correct target */
3490 self
= client_focus_target(self
);
3492 if (!client_can_focus(self
)) {
3493 if (!self
->frame
->visible
) {
3494 /* update the focus lists */
3495 focus_order_to_top(self
);
3497 ob_debug_type(OB_DEBUG_FOCUS
,
3498 "Client %s can't be focused\n", self
->title
);
3502 ob_debug_type(OB_DEBUG_FOCUS
,
3503 "Focusing client \"%s\" (0x%x) at time %u\n",
3504 self
->title
, self
->window
, event_curtime
);
3506 /* if there is a grab going on, then we need to cancel it. if we move
3507 focus during the grab, applications will get NotifyWhileGrabbed events
3510 actions should not rely on being able to move focus during an
3513 event_cancel_all_key_grabs();
3515 xerror_set_ignore(TRUE
);
3516 xerror_occured
= FALSE
;
3518 if (self
->can_focus
) {
3519 /* This can cause a BadMatch error with CurrentTime, or if an app
3520 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3521 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3525 if (self
->focus_notify
) {
3527 ce
.xclient
.type
= ClientMessage
;
3528 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3529 ce
.xclient
.display
= ob_display
;
3530 ce
.xclient
.window
= self
->window
;
3531 ce
.xclient
.format
= 32;
3532 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3533 ce
.xclient
.data
.l
[1] = event_curtime
;
3534 ce
.xclient
.data
.l
[2] = 0l;
3535 ce
.xclient
.data
.l
[3] = 0l;
3536 ce
.xclient
.data
.l
[4] = 0l;
3537 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3540 xerror_set_ignore(FALSE
);
3542 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d\n", xerror_occured
);
3543 return !xerror_occured
;
3546 /*! Present the client to the user.
3547 @param raise If the client should be raised or not. You should only set
3548 raise to false if you don't care if the window is completely
3551 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
)
3553 /* if using focus_delay, stop the timer now so that focus doesn't
3555 event_halt_focus_delay();
3557 if (client_normal(self
) && screen_showing_desktop
)
3558 screen_show_desktop(FALSE
, self
);
3560 client_iconify(self
, FALSE
, here
, FALSE
);
3561 if (self
->desktop
!= DESKTOP_ALL
&&
3562 self
->desktop
!= screen_desktop
)
3565 client_set_desktop(self
, screen_desktop
, FALSE
);
3567 screen_set_desktop(self
->desktop
, FALSE
);
3568 } else if (!self
->frame
->visible
)
3569 /* if its not visible for other reasons, then don't mess
3573 client_shade(self
, FALSE
);
3575 stacking_raise(CLIENT_AS_WINDOW(self
));
3580 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3582 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3583 gboolean allow
= FALSE
;
3585 /* if the request came from the user, or if nothing is focused, then grant
3587 if the currently focused app doesn't set a user_time, then it can't
3588 benefit from any focus stealing prevention.
3590 if (user
|| !focus_client
|| !last_time
)
3592 /* otherwise, if they didn't give a time stamp or if it is too old, they
3595 allow
= event_curtime
&& event_time_after(event_curtime
, last_time
);
3597 ob_debug_type(OB_DEBUG_FOCUS
,
3598 "Want to activate window 0x%x with time %u (last time %u), "
3599 "source=%s allowing? %d\n",
3600 self
->window
, event_curtime
, last_time
,
3601 (user
? "user" : "application"), allow
);
3604 client_present(self
, here
, TRUE
);
3606 /* don't focus it but tell the user it wants attention */
3607 client_hilite(self
, TRUE
);
3610 static void client_bring_windows_recursive(ObClient
*self
,
3617 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3618 client_bring_windows_recursive(it
->data
, desktop
, helpers
, modals
);
3620 if (((helpers
&& client_helper(self
)) ||
3621 (modals
&& self
->modal
))&&
3622 self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
)
3624 client_set_desktop(self
, desktop
, FALSE
);
3628 void client_bring_helper_windows(ObClient
*self
)
3630 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
);
3633 void client_bring_modal_windows(ObClient
*self
)
3635 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
);
3638 gboolean
client_focused(ObClient
*self
)
3640 return self
== focus_client
;
3643 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3646 gulong min_diff
, min_i
;
3648 if (!self
->nicons
) {
3649 ObClientIcon
*parent
= NULL
;
3651 if (self
->transient_for
) {
3652 if (self
->transient_for
!= OB_TRAN_GROUP
)
3653 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3656 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3657 ObClient
*c
= it
->data
;
3658 if (c
!= self
&& !c
->transient_for
) {
3659 if ((parent
= client_icon_recursive(c
, w
, h
)))
3669 /* some kind of crappy approximation to find the icon closest in size to
3670 what we requested, but icons are generally all the same ratio as
3671 eachother so it's good enough. */
3673 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3676 for (i
= 1; i
< self
->nicons
; ++i
) {
3679 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3680 if (diff
< min_diff
) {
3685 return &self
->icons
[min_i
];
3688 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3691 static ObClientIcon deficon
;
3693 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3694 deficon
.width
= deficon
.height
= 48;
3695 deficon
.data
= ob_rr_theme
->def_win_icon
;
3701 void client_set_layer(ObClient
*self
, gint layer
)
3705 self
->above
= FALSE
;
3706 } else if (layer
== 0) {
3707 self
->below
= self
->above
= FALSE
;
3709 self
->below
= FALSE
;
3712 client_calc_layer(self
);
3713 client_change_state(self
); /* reflect this in the state hints */
3716 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3718 if (self
->undecorated
!= undecorated
&&
3719 /* don't let it undecorate if the function is missing, but let
3721 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3723 self
->undecorated
= undecorated
;
3724 client_setup_decor_and_functions(self
, TRUE
);
3725 client_change_state(self
); /* reflect this in the state hints */
3729 guint
client_monitor(ObClient
*self
)
3731 return screen_find_monitor(&self
->frame
->area
);
3734 ObClient
*client_search_top_normal_parent(ObClient
*self
)
3736 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3737 client_normal(self
->transient_for
))
3738 self
= self
->transient_for
;
3742 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3744 ObStackingLayer layer
)
3748 /* move up the direct transient chain as far as possible */
3749 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3750 (!bylayer
|| self
->transient_for
->layer
== layer
) &&
3751 client_normal(self
->transient_for
))
3752 self
= self
->transient_for
;
3754 if (!self
->transient_for
)
3755 ret
= g_slist_prepend(ret
, self
);
3759 g_assert(self
->group
);
3761 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3762 ObClient
*c
= it
->data
;
3764 if (!c
->transient_for
&& client_normal(c
) &&
3765 (!bylayer
|| c
->layer
== layer
))
3767 ret
= g_slist_prepend(ret
, c
);
3771 if (ret
== NULL
) /* no group parents */
3772 ret
= g_slist_prepend(ret
, self
);
3778 GSList
*client_search_all_top_parents(ObClient
*self
)
3780 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3783 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3785 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3788 ObClient
*client_search_focus_parent(ObClient
*self
)
3790 if (self
->transient_for
) {
3791 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3792 if (client_focused(self
->transient_for
))
3793 return self
->transient_for
;
3797 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3798 ObClient
*c
= it
->data
;
3800 /* checking transient_for prevents infinate loops! */
3801 if (c
!= self
&& !c
->transient_for
)
3802 if (client_focused(c
))
3811 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3813 if (self
->transient_for
) {
3814 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3815 if (self
->transient_for
== search
)
3820 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3821 ObClient
*c
= it
->data
;
3823 /* checking transient_for prevents infinate loops! */
3824 if (c
!= self
&& !c
->transient_for
)
3834 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3838 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3839 if (sit
->data
== search
)
3841 if (client_search_transient(sit
->data
, search
))
3847 #define WANT_EDGE(cur, c) \
3850 if(!client_normal(cur)) \
3852 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3857 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3858 if ((his_edge_start >= my_edge_start && \
3859 his_edge_start <= my_edge_end) || \
3860 (my_edge_start >= his_edge_start && \
3861 my_edge_start <= his_edge_end)) \
3864 /* finds the nearest edge in the given direction from the current client
3865 * note to self: the edge is the -frame- edge (the actual one), not the
3868 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3870 gint dest
, monitor_dest
;
3871 gint my_edge_start
, my_edge_end
, my_offset
;
3878 a
= screen_area(c
->desktop
);
3879 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3882 case OB_DIRECTION_NORTH
:
3883 my_edge_start
= c
->frame
->area
.x
;
3884 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3885 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3887 /* default: top of screen */
3888 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3889 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3890 /* if the monitor edge comes before the screen edge, */
3891 /* use that as the destination instead. (For xinerama) */
3892 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3893 dest
= monitor_dest
;
3895 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3896 gint his_edge_start
, his_edge_end
, his_offset
;
3897 ObClient
*cur
= it
->data
;
3901 his_edge_start
= cur
->frame
->area
.x
;
3902 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3903 his_offset
= cur
->frame
->area
.y
+
3904 (hang
? 0 : cur
->frame
->area
.height
);
3906 if(his_offset
+ 1 > my_offset
)
3909 if(his_offset
< dest
)
3912 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3915 case OB_DIRECTION_SOUTH
:
3916 my_edge_start
= c
->frame
->area
.x
;
3917 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3918 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3920 /* default: bottom of screen */
3921 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3922 monitor_dest
= monitor
->y
+ monitor
->height
-
3923 (hang
? c
->frame
->area
.height
: 0);
3924 /* if the monitor edge comes before the screen edge, */
3925 /* use that as the destination instead. (For xinerama) */
3926 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3927 dest
= monitor_dest
;
3929 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3930 gint his_edge_start
, his_edge_end
, his_offset
;
3931 ObClient
*cur
= it
->data
;
3935 his_edge_start
= cur
->frame
->area
.x
;
3936 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3937 his_offset
= cur
->frame
->area
.y
+
3938 (hang
? cur
->frame
->area
.height
: 0);
3941 if(his_offset
- 1 < my_offset
)
3944 if(his_offset
> dest
)
3947 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3950 case OB_DIRECTION_WEST
:
3951 my_edge_start
= c
->frame
->area
.y
;
3952 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3953 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3955 /* default: leftmost egde of screen */
3956 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3957 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3958 /* if the monitor edge comes before the screen edge, */
3959 /* use that as the destination instead. (For xinerama) */
3960 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3961 dest
= monitor_dest
;
3963 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3964 gint his_edge_start
, his_edge_end
, his_offset
;
3965 ObClient
*cur
= it
->data
;
3969 his_edge_start
= cur
->frame
->area
.y
;
3970 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3971 his_offset
= cur
->frame
->area
.x
+
3972 (hang
? 0 : cur
->frame
->area
.width
);
3974 if(his_offset
+ 1 > my_offset
)
3977 if(his_offset
< dest
)
3980 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3983 case OB_DIRECTION_EAST
:
3984 my_edge_start
= c
->frame
->area
.y
;
3985 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3986 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3988 /* default: rightmost edge of screen */
3989 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3990 monitor_dest
= monitor
->x
+ monitor
->width
-
3991 (hang
? c
->frame
->area
.width
: 0);
3992 /* if the monitor edge comes before the screen edge, */
3993 /* use that as the destination instead. (For xinerama) */
3994 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3995 dest
= monitor_dest
;
3997 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3998 gint his_edge_start
, his_edge_end
, his_offset
;
3999 ObClient
*cur
= it
->data
;
4003 his_edge_start
= cur
->frame
->area
.y
;
4004 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
4005 his_offset
= cur
->frame
->area
.x
+
4006 (hang
? cur
->frame
->area
.width
: 0);
4008 if(his_offset
- 1 < my_offset
)
4011 if(his_offset
> dest
)
4014 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
4017 case OB_DIRECTION_NORTHEAST
:
4018 case OB_DIRECTION_SOUTHEAST
:
4019 case OB_DIRECTION_NORTHWEST
:
4020 case OB_DIRECTION_SOUTHWEST
:
4021 /* not implemented */
4023 g_assert_not_reached();
4024 dest
= 0; /* suppress warning */
4029 ObClient
* client_under_pointer()
4033 ObClient
*ret
= NULL
;
4035 if (screen_pointer_pos(&x
, &y
)) {
4036 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4037 if (WINDOW_IS_CLIENT(it
->data
)) {
4038 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4039 if (c
->frame
->visible
&&
4040 /* ignore all animating windows */
4041 !frame_iconify_animating(c
->frame
) &&
4042 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4053 gboolean
client_has_group_siblings(ObClient
*self
)
4055 return self
->group
&& self
->group
->members
->next
;