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"
30 #include "extensions.h"
41 #include "menuframe.h"
44 #include "render/render.h"
52 # include <signal.h> /* for kill() */
56 #include <X11/Xutil.h>
58 /*! The event mask to grab on client windows */
59 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
62 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
67 ObClientCallback func
;
71 GList
*client_list
= NULL
;
73 static GSList
*client_destroy_notifies
= NULL
;
75 static void client_get_all(ObClient
*self
, gboolean real
);
76 static void client_get_startup_id(ObClient
*self
);
77 static void client_get_session_ids(ObClient
*self
);
78 static void client_get_area(ObClient
*self
);
79 static void client_get_desktop(ObClient
*self
);
80 static void client_get_state(ObClient
*self
);
81 static void client_get_shaped(ObClient
*self
);
82 static void client_get_mwm_hints(ObClient
*self
);
83 static void client_get_colormap(ObClient
*self
);
84 static void client_set_desktop_recursive(ObClient
*self
,
88 static void client_change_allowed_actions(ObClient
*self
);
89 static void client_change_state(ObClient
*self
);
90 static void client_change_wm_state(ObClient
*self
);
91 static void client_apply_startup_state(ObClient
*self
,
92 gint x
, gint y
, gint w
, gint h
);
93 static void client_restore_session_state(ObClient
*self
);
94 static gboolean
client_restore_session_stacking(ObClient
*self
);
95 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
96 static void client_update_transient_tree(ObClient
*self
,
97 ObGroup
*oldgroup
, ObGroup
*newgroup
,
98 gboolean oldgtran
, gboolean newgtran
,
100 ObClient
*newparent
);
101 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
103 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
105 ObStackingLayer layer
);
106 static void client_call_notifies(ObClient
*self
, GSList
*list
);
107 static void client_ping_event(ObClient
*self
, gboolean dead
);
110 void client_startup(gboolean reconfig
)
112 if (reconfig
) return;
117 void client_shutdown(gboolean reconfig
)
119 if (reconfig
) return;
122 static void client_call_notifies(ObClient
*self
, GSList
*list
)
126 for (it
= list
; it
; it
= g_slist_next(it
)) {
127 ClientCallback
*d
= it
->data
;
128 d
->func(self
, d
->data
);
132 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
134 ClientCallback
*d
= g_new(ClientCallback
, 1);
137 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
140 void client_remove_destroy_notify(ObClientCallback func
)
144 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
145 ClientCallback
*d
= it
->data
;
146 if (d
->func
== func
) {
148 client_destroy_notifies
=
149 g_slist_delete_link(client_destroy_notifies
, it
);
155 void client_set_list(void)
157 Window
*windows
, *win_it
;
159 guint size
= g_list_length(client_list
);
161 /* create an array of the window ids */
163 windows
= g_new(Window
, size
);
165 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
166 *win_it
= ((ObClient
*)it
->data
)->window
;
170 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
171 net_client_list
, window
, (gulong
*)windows
, size
);
179 void client_manage_all(void)
184 XWindowAttributes attrib
;
186 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
187 &w
, &w
, &children
, &nchild
);
189 /* remove all icon windows from the list */
190 for (i
= 0; i
< nchild
; i
++) {
191 if (children
[i
] == None
) continue;
192 wmhints
= XGetWMHints(ob_display
, children
[i
]);
194 if ((wmhints
->flags
& IconWindowHint
) &&
195 (wmhints
->icon_window
!= children
[i
]))
196 for (j
= 0; j
< nchild
; j
++)
197 if (children
[j
] == wmhints
->icon_window
) {
205 /* manage windows in reverse order from how they were originally mapped.
206 this is an attempt to manage children windows before their parents, so
207 that when the parent is mapped, it can find the child */
208 for (i
= 0; i
< nchild
; ++i
) {
209 if (children
[i
] == None
)
211 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
212 if (attrib
.override_redirect
) continue;
214 if (attrib
.map_state
!= IsUnmapped
)
215 client_manage(children
[i
], NULL
);
221 void client_manage(Window window
, ObPrompt
*prompt
)
225 XWindowAttributes attrib
;
226 XSetWindowAttributes attrib_set
;
228 gboolean activate
= FALSE
;
229 ObAppSettings
*settings
;
230 gboolean transient
= FALSE
;
231 Rect place
, *monitor
;
232 Time launch_time
, map_time
;
236 /* check if it has already been unmapped by the time we started
237 mapping. the grab does a sync so we don't have to here */
238 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
239 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
241 XPutBackEvent(ob_display
, &e
);
243 ob_debug("Trying to manage unmapped window. Aborting that.\n");
245 return; /* don't manage it */
248 /* make sure it isn't an override-redirect window */
249 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
250 attrib
.override_redirect
)
253 return; /* don't manage it */
256 /* is the window a docking app */
257 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
258 if ((wmhint
->flags
& StateHint
) &&
259 wmhint
->initial_state
== WithdrawnState
)
261 dock_add(window
, wmhint
);
269 ob_debug("Managing window: 0x%lx\n", window
);
271 map_time
= event_get_server_time();
273 /* choose the events we want to receive on the CLIENT window
274 (ObPrompt windows can request events too) */
275 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
276 (prompt
? prompt
->event_mask
: 0);
277 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
278 XChangeWindowAttributes(ob_display
, window
,
279 CWEventMask
|CWDontPropagate
, &attrib_set
);
281 /* create the ObClient struct, and populate it from the hints on the
283 self
= g_new0(ObClient
, 1);
284 self
->obwin
.type
= Window_Client
;
285 self
->window
= window
;
286 self
->prompt
= prompt
;
288 /* non-zero defaults */
289 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
290 self
->gravity
= NorthWestGravity
;
291 self
->desktop
= screen_num_desktops
; /* always an invalid value */
293 /* get all the stuff off the window */
294 client_get_all(self
, TRUE
);
296 ob_debug("Window type: %d\n", self
->type
);
297 ob_debug("Window group: 0x%x\n", self
->group
?self
->group
->leader
:0);
299 /* now we have all of the window's information so we can set this up.
300 do this before creating the frame, so it can tell that we are still
301 mapping and doesn't go applying things right away */
302 client_setup_decor_and_functions(self
, FALSE
);
304 /* specify that if we exit, the window should not be destroyed and
305 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 though */
323 client_restore_session_state(self
);
325 /* tell startup notification that this app started */
326 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
328 /* do this after we have a frame.. it uses the frame to help determine the
329 WM_STATE to apply. */
330 client_change_state(self
);
332 /* add ourselves to the focus order */
333 focus_order_add_new(self
);
335 /* do this to add ourselves to the stacking list in a non-intrusive way */
336 client_calc_layer(self
);
338 /* focus the new window? */
339 if (ob_state() != OB_STATE_STARTING
&&
340 (!self
->session
|| self
->session
->focused
) &&
341 /* this means focus=true for window is same as config_focus_new=true */
342 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
343 client_search_focus_tree_full(self
)) &&
344 /* this checks for focus=false for the window */
345 (!settings
|| settings
->focus
!= 0) &&
346 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
351 /* remove the client's border */
352 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
354 /* adjust the frame to the client's size before showing or placing
356 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
357 frame_adjust_client_area(self
->frame
);
359 /* where the frame was placed is where the window was originally */
361 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
363 /* figure out placement for the window if the window is new */
364 if (ob_state() == OB_STATE_RUNNING
) {
365 ob_debug("Positioned: %s @ %d %d\n",
366 (!self
->positioned
? "no" :
367 (self
->positioned
== PPosition
? "program specified" :
368 (self
->positioned
== USPosition
? "user specified" :
369 (self
->positioned
== (PPosition
| USPosition
) ?
370 "program + user specified" :
371 "BADNESS !?")))), place
.x
, place
.y
);
373 ob_debug("Sized: %s @ %d %d\n",
374 (!self
->sized
? "no" :
375 (self
->sized
== PSize
? "program specified" :
376 (self
->sized
== USSize
? "user specified" :
377 (self
->sized
== (PSize
| USSize
) ?
378 "program + user specified" :
379 "BADNESS !?")))), place
.width
, place
.height
);
381 /* splash screens are also returned as TRUE for transient,
382 and so will be forced on screen below */
383 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
385 /* make sure the window is visible. */
386 client_find_onscreen(self
, &place
.x
, &place
.y
,
387 place
.width
, place
.height
,
388 /* non-normal clients has less rules, and
389 windows that are being restored from a
390 session do also. we can assume you want
391 it back where you saved it. Clients saying
392 they placed themselves are subjected to
393 harder rules, ones that are placed by
394 place.c or by the user are allowed partially
395 off-screen and on xinerama divides (ie,
396 it is up to the placement routines to avoid
397 the xinerama divides)
399 splash screens get "transient" set to TRUE by
400 the place_client call
402 ob_state() == OB_STATE_RUNNING
&&
404 (!((self
->positioned
& USPosition
) ||
405 (settings
&& settings
->pos_given
)) &&
406 client_normal(self
) &&
408 /* don't move oldschool fullscreen windows to
409 fit inside the struts (fixes Acroread, which
410 makes its fullscreen window fit the screen
411 but it is not USSize'd or USPosition'd) */
412 !(self
->decorations
== 0 &&
413 RECT_EQUAL(place
, *monitor
)))));
416 /* if the window isn't user-sized, then make it fit inside
417 the visible screen area on its monitor. Use basically the same rules
418 for forcing the window on screen in the client_find_onscreen call.
420 do this after place_client, it chooses the monitor!
422 splash screens get "transient" set to TRUE by
423 the place_client call
425 if (ob_state() == OB_STATE_RUNNING
&&
427 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
428 client_normal(self
) &&
430 /* don't shrink oldschool fullscreen windows to fit inside the
431 struts (fixes Acroread, which makes its fullscreen window
432 fit the screen but it is not USSize'd or USPosition'd) */
433 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
435 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
437 /* get the size of the frame */
438 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
439 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
441 /* fit the window inside the area */
442 place
.width
= MIN(place
.width
, a
->width
);
443 place
.height
= MIN(place
.height
, a
->height
);
445 ob_debug("setting window size to %dx%d\n", place
.width
, place
.height
);
447 /* get the size of the client back */
448 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
449 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
454 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
455 "some restrictions may apply\n",
456 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
458 ob_debug(" but session requested %d, %d %d x %d instead, "
460 self
->session
->x
, self
->session
->y
,
461 self
->session
->w
, self
->session
->h
);
463 /* do this after the window is placed, so the premax/prefullscreen numbers
466 this also places the window
468 client_apply_startup_state(self
, place
.x
, place
.y
,
469 place
.width
, place
.height
);
474 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s\n",
475 activate
? "yes" : "no");
477 gboolean raise
= FALSE
;
479 /* This is focus stealing prevention */
480 ob_debug_type(OB_DEBUG_FOCUS
,
481 "Want to focus new window 0x%x at time %u "
482 "launched at %u (last user interaction time %u)\n",
483 self
->window
, map_time
, launch_time
,
484 event_last_user_time
);
486 if (menu_frame_visible
|| moveresize_in_progress
) {
489 ob_debug_type(OB_DEBUG_FOCUS
,
490 "Not focusing the window because the user is inside "
491 "an Openbox menu or is move/resizing a window and "
492 "we don't want to interrupt them\n");
495 /* if it's on another desktop */
496 else if (!(self
->desktop
== screen_desktop
||
497 self
->desktop
== DESKTOP_ALL
) &&
498 /* the timestamp is from before you changed desktops */
499 launch_time
&& screen_desktop_user_time
&&
500 !event_time_after(launch_time
, screen_desktop_user_time
))
504 ob_debug_type(OB_DEBUG_FOCUS
,
505 "Not focusing the window because its on another "
508 /* If something is focused, and it's not our relative... */
509 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
510 client_search_focus_group_full(self
) == NULL
)
512 /* If the user is working in another window right now, then don't
514 if (event_last_user_time
&& launch_time
&&
515 event_time_after(event_last_user_time
, launch_time
) &&
516 event_last_user_time
!= launch_time
&&
517 event_time_after(event_last_user_time
,
518 map_time
- OB_EVENT_USER_TIME_DELAY
))
521 ob_debug_type(OB_DEBUG_FOCUS
,
522 "Not focusing the window because the user is "
523 "working in another window\n");
525 /* If its a transient (and its parents aren't focused) */
526 else if (client_has_parent(self
)) {
528 ob_debug_type(OB_DEBUG_FOCUS
,
529 "Not focusing the window because it is a "
530 "transient, and its relatives aren't focused\n");
532 /* Don't steal focus from globally active clients.
533 I stole this idea from KWin. It seems nice.
535 else if (!(focus_client
->can_focus
||
536 focus_client
->focus_notify
))
539 ob_debug_type(OB_DEBUG_FOCUS
,
540 "Not focusing the window because a globally "
541 "active client has focus\n");
543 /* Don't move focus if it's not going to go to this window
545 else if (client_focus_target(self
) != self
) {
548 ob_debug_type(OB_DEBUG_FOCUS
,
549 "Not focusing the window because another window "
550 "would get the focus anyway\n");
552 else if (!(self
->desktop
== screen_desktop
||
553 self
->desktop
== DESKTOP_ALL
))
557 ob_debug_type(OB_DEBUG_FOCUS
,
558 "Not focusing the window because it is on "
559 "another desktop and no relatives are focused ");
564 ob_debug_type(OB_DEBUG_FOCUS
,
565 "Focus stealing prevention activated for %s at "
566 "time %u (last user interactioon time %u)\n",
567 self
->title
, map_time
, event_last_user_time
);
568 /* if the client isn't focused, then hilite it so the user
570 client_hilite(self
, TRUE
);
571 /* we may want to raise it even tho we're not activating it */
572 if (raise
&& !client_restore_session_stacking(self
))
573 stacking_raise(CLIENT_AS_WINDOW(self
));
577 /* This may look rather odd. Well it's because new windows are added
578 to the stacking order non-intrusively. If we're not going to focus
579 the new window or hilite it, then we raise it to the top. This will
580 take affect for things that don't get focused like splash screens.
581 Also if you don't have focus_new enabled, then it's going to get
582 raised to the top. Legacy begets legacy I guess?
584 if (!client_restore_session_stacking(self
))
585 stacking_raise(CLIENT_AS_WINDOW(self
));
588 mouse_grab_for_client(self
, TRUE
);
590 /* this has to happen before we try focus the window, but we want it to
591 happen after the client's stacking has been determined or it looks bad
595 if (!config_focus_under_mouse
)
596 ignore_start
= event_start_ignore_all_enters();
600 if (!config_focus_under_mouse
)
601 event_end_ignore_all_enters(ignore_start
);
605 gboolean stacked
= client_restore_session_stacking(self
);
606 client_present(self
, FALSE
, !stacked
, TRUE
);
609 /* add to client list/map */
610 client_list
= g_list_append(client_list
, self
);
611 g_hash_table_insert(window_map
, &self
->window
, self
);
613 /* this has to happen after we're in the client_list */
614 if (STRUT_EXISTS(self
->strut
))
615 screen_update_areas();
617 /* update the list hints */
620 /* watch for when the application stops responding. only do this for
621 normal windows, i.e. windows which have titlebars and close buttons
622 and things like that.
623 we don't need to stop pinging on unmanage, because it will be handled
624 automatically by the destroy callback!
626 if (self
->ping
&& client_normal(self
))
627 ping_start(self
, client_ping_event
);
629 /* free the ObAppSettings shallow copy */
632 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
633 window
, self
->frame
->window
, self
->class);
639 ObClient
*client_fake_manage(Window window
)
642 ObAppSettings
*settings
;
644 ob_debug("Pretend-managing window: %lx\n", window
);
646 /* do this minimal stuff to figure out the client's decorations */
648 self
= g_new0(ObClient
, 1);
649 self
->window
= window
;
651 client_get_all(self
, FALSE
);
652 /* per-app settings override stuff, and return the settings for other
653 uses too. this returns a shallow copy that needs to be freed */
654 settings
= client_get_settings_state(self
);
656 client_setup_decor_and_functions(self
, FALSE
);
658 /* create the decoration frame for the client window and adjust its size */
659 self
->frame
= frame_new(self
);
660 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
662 ob_debug("gave extents left %d right %d top %d bottom %d\n",
663 self
->frame
->size
.left
, self
->frame
->size
.right
,
664 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
666 /* free the ObAppSettings shallow copy */
672 void client_unmanage_all(void)
674 while (client_list
!= NULL
)
675 client_unmanage(client_list
->data
);
678 void client_unmanage(ObClient
*self
)
684 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
685 self
->window
, self
->frame
->window
,
686 self
->class, self
->title
? self
->title
: "");
688 g_assert(self
!= NULL
);
690 /* we dont want events no more. do this before hiding the frame so we
691 don't generate more events */
692 XSelectInput(ob_display
, self
->window
, NoEventMask
);
694 /* ignore enter events from the unmap so it doesnt mess with the focus */
695 if (!config_focus_under_mouse
)
696 ignore_start
= event_start_ignore_all_enters();
698 frame_hide(self
->frame
);
699 /* flush to send the hide to the server quickly */
702 if (!config_focus_under_mouse
)
703 event_end_ignore_all_enters(ignore_start
);
705 mouse_grab_for_client(self
, FALSE
);
707 /* remove the window from our save set */
709 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
711 /* update the focus lists */
712 focus_order_remove(self
);
713 if (client_focused(self
)) {
714 /* don't leave an invalid focus_client */
718 client_list
= g_list_remove(client_list
, self
);
719 stacking_remove(self
);
720 g_hash_table_remove(window_map
, &self
->window
);
722 /* once the client is out of the list, update the struts to remove its
724 if (STRUT_EXISTS(self
->strut
))
725 screen_update_areas();
727 client_call_notifies(self
, client_destroy_notifies
);
729 /* tell our parent(s) that we're gone */
730 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
731 ((ObClient
*)it
->data
)->transients
=
732 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
734 /* tell our transients that we're gone */
735 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
736 ((ObClient
*)it
->data
)->parents
=
737 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
738 /* we could be keeping our children in a higher layer */
739 client_calc_layer(it
->data
);
742 /* remove from its group */
744 group_remove(self
->group
, self
);
748 /* restore the window's original geometry so it is not lost */
754 if (self
->fullscreen
)
755 a
= self
->pre_fullscreen_area
;
756 else if (self
->max_horz
|| self
->max_vert
) {
757 if (self
->max_horz
) {
758 a
.x
= self
->pre_max_area
.x
;
759 a
.width
= self
->pre_max_area
.width
;
761 if (self
->max_vert
) {
762 a
.y
= self
->pre_max_area
.y
;
763 a
.height
= self
->pre_max_area
.height
;
767 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
768 /* let it be moved and resized no matter what */
769 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
770 self
->decorations
= 0; /* unmanaged windows have no decor */
772 /* give the client its border back */
773 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
775 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
778 /* reparent the window out of the frame, and free the frame */
779 frame_release_client(self
->frame
);
780 frame_free(self
->frame
);
783 if (ob_state() != OB_STATE_EXITING
) {
784 /* these values should not be persisted across a window
786 PROP_ERASE(self
->window
, net_wm_desktop
);
787 PROP_ERASE(self
->window
, net_wm_state
);
788 PROP_ERASE(self
->window
, wm_state
);
790 /* if we're left in an unmapped state, the client wont be mapped.
791 this is bad, since we will no longer be managing the window on
793 XMapWindow(ob_display
, self
->window
);
796 /* these should not be left on the window ever. other window managers
797 don't necessarily use them and it will mess them up (like compiz) */
798 PROP_ERASE(self
->window
, net_wm_visible_name
);
799 PROP_ERASE(self
->window
, net_wm_visible_icon_name
);
801 /* update the list hints */
804 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
806 /* free all data allocated in the client struct */
807 g_slist_free(self
->transients
);
808 for (j
= 0; j
< self
->nicons
; ++j
)
809 g_free(self
->icons
[j
].data
);
810 if (self
->nicons
> 0)
812 g_free(self
->startup_id
);
813 g_free(self
->wm_command
);
815 g_free(self
->icon_title
);
819 g_free(self
->client_machine
);
820 g_free(self
->sm_client_id
);
824 void client_fake_unmanage(ObClient
*self
)
826 /* this is all that got allocated to get the decorations */
828 frame_free(self
->frame
);
832 /*! Returns a new structure containing the per-app settings for this client.
833 The returned structure needs to be freed with g_free. */
834 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
836 ObAppSettings
*settings
;
839 settings
= config_create_app_settings();
841 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
842 ObAppSettings
*app
= it
->data
;
843 gboolean match
= TRUE
;
845 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
847 /* we know that either name or class is not NULL so it will have to
848 match to use the rule */
850 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
852 else if (app
->class &&
853 !g_pattern_match(app
->class,
854 strlen(self
->class), self
->class, NULL
))
856 else if (app
->role
&&
857 !g_pattern_match(app
->role
,
858 strlen(self
->role
), self
->role
, NULL
))
860 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
)
864 ob_debug("Window matching: %s\n", app
->name
);
866 /* copy the settings to our struct, overriding the existing
867 settings if they are not defaults */
868 config_app_settings_copy_non_defaults(app
, settings
);
872 if (settings
->shade
!= -1)
873 self
->shaded
= !!settings
->shade
;
874 if (settings
->decor
!= -1)
875 self
->undecorated
= !settings
->decor
;
876 if (settings
->iconic
!= -1)
877 self
->iconic
= !!settings
->iconic
;
878 if (settings
->skip_pager
!= -1)
879 self
->skip_pager
= !!settings
->skip_pager
;
880 if (settings
->skip_taskbar
!= -1)
881 self
->skip_taskbar
= !!settings
->skip_taskbar
;
883 if (settings
->max_vert
!= -1)
884 self
->max_vert
= !!settings
->max_vert
;
885 if (settings
->max_horz
!= -1)
886 self
->max_horz
= !!settings
->max_horz
;
888 if (settings
->fullscreen
!= -1)
889 self
->fullscreen
= !!settings
->fullscreen
;
891 if (settings
->desktop
) {
892 if (settings
->desktop
== DESKTOP_ALL
)
893 self
->desktop
= settings
->desktop
;
894 else if (settings
->desktop
> 0 &&
895 settings
->desktop
<= screen_num_desktops
)
896 self
->desktop
= settings
->desktop
- 1;
899 if (settings
->layer
== -1) {
903 else if (settings
->layer
== 0) {
907 else if (settings
->layer
== 1) {
914 static void client_restore_session_state(ObClient
*self
)
918 ob_debug_type(OB_DEBUG_SM
,
919 "Restore session for client %s\n", self
->title
);
921 if (!(it
= session_state_find(self
))) {
922 ob_debug_type(OB_DEBUG_SM
,
923 "Session data not found for client %s\n", self
->title
);
927 self
->session
= it
->data
;
929 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
932 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
933 self
->positioned
= USPosition
;
934 self
->sized
= USSize
;
935 if (self
->session
->w
> 0)
936 self
->area
.width
= self
->session
->w
;
937 if (self
->session
->h
> 0)
938 self
->area
.height
= self
->session
->h
;
939 XResizeWindow(ob_display
, self
->window
,
940 self
->area
.width
, self
->area
.height
);
942 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
943 self
->session
->desktop
:
944 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
945 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
947 self
->shaded
= self
->session
->shaded
;
948 self
->iconic
= self
->session
->iconic
;
949 self
->skip_pager
= self
->session
->skip_pager
;
950 self
->skip_taskbar
= self
->session
->skip_taskbar
;
951 self
->fullscreen
= self
->session
->fullscreen
;
952 self
->above
= self
->session
->above
;
953 self
->below
= self
->session
->below
;
954 self
->max_horz
= self
->session
->max_horz
;
955 self
->max_vert
= self
->session
->max_vert
;
956 self
->undecorated
= self
->session
->undecorated
;
959 static gboolean
client_restore_session_stacking(ObClient
*self
)
963 if (!self
->session
) return FALSE
;
965 mypos
= g_list_find(session_saved_state
, self
->session
);
966 if (!mypos
) return FALSE
;
968 /* start above me and look for the first client */
969 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
972 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
973 ObClient
*c
= cit
->data
;
974 /* found a client that was in the session, so go below it */
975 if (c
->session
== it
->data
) {
976 stacking_below(CLIENT_AS_WINDOW(self
),
977 CLIENT_AS_WINDOW(cit
->data
));
985 void client_move_onscreen(ObClient
*self
, gboolean rude
)
987 gint x
= self
->area
.x
;
988 gint y
= self
->area
.y
;
989 if (client_find_onscreen(self
, &x
, &y
,
991 self
->area
.height
, rude
)) {
992 client_move(self
, x
, y
);
996 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
999 gint ox
= *x
, oy
= *y
;
1000 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
1006 RECT_SET(desired
, *x
, *y
, w
, h
);
1007 frame_rect_to_frame(self
->frame
, &desired
);
1009 /* get where the frame would be */
1010 frame_client_gravity(self
->frame
, x
, y
);
1012 /* get the requested size of the window with decorations */
1013 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
1014 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
1016 /* If rudeness wasn't requested, then still be rude in a given direction
1017 if the client is not moving, only resizing in that direction */
1019 Point oldtl
, oldtr
, oldbl
, oldbr
;
1020 Point newtl
, newtr
, newbl
, newbr
;
1021 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
1023 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
1024 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1025 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1026 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1027 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1029 POINT_SET(newtl
, *x
, *y
);
1030 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1031 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1032 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1034 /* is it moving or just resizing from some corner? */
1035 stationary_l
= oldtl
.x
== newtl
.x
;
1036 stationary_r
= oldtr
.x
== newtr
.x
;
1037 stationary_t
= oldtl
.y
== newtl
.y
;
1038 stationary_b
= oldbl
.y
== newbl
.y
;
1040 /* if left edge is growing and didnt move right edge */
1041 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1043 /* if right edge is growing and didnt move left edge */
1044 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1046 /* if top edge is growing and didnt move bottom edge */
1047 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1049 /* if bottom edge is growing and didnt move top edge */
1050 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1054 /* we iterate through every monitor that the window is at least partially
1055 on, to make sure it is obeying the rules on them all
1057 if the window does not appear on any monitors, then use the first one
1060 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1063 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1064 if (i
< screen_num_monitors
- 1 || found_mon
)
1067 /* the window is not inside any monitor! so just use the first
1069 a
= screen_area(self
->desktop
, 0, NULL
);
1072 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1075 /* This makes sure windows aren't entirely outside of the screen so you
1076 can't see them at all.
1077 It makes sure 10% of the window is on the screen at least. At don't
1078 let it move itself off the top of the screen, which would hide the
1079 titlebar on you. (The user can still do this if they want too, it's
1080 only limiting the application.
1082 if (client_normal(self
)) {
1083 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1084 *x
= a
->x
+ a
->width
- fw
/10;
1085 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1086 *y
= a
->y
+ a
->height
- fh
/10;
1087 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1088 *x
= a
->x
- fw
*9/10;
1089 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1090 *y
= a
->y
- fh
*9/10;
1093 /* This here doesn't let windows even a pixel outside the
1094 struts/screen. When called from client_manage, programs placing
1095 themselves are forced completely onscreen, while things like
1096 xterm -geometry resolution-width/2 will work fine. Trying to
1097 place it completely offscreen will be handled in the above code.
1098 Sorry for this confused comment, i am tired. */
1099 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1100 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1101 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1103 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1104 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1105 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1110 /* get where the client should be */
1111 frame_frame_gravity(self
->frame
, x
, y
);
1113 return ox
!= *x
|| oy
!= *y
;
1116 static void client_get_all(ObClient
*self
, gboolean real
)
1118 /* this is needed for the frame to set itself up */
1119 client_get_area(self
);
1121 /* these things can change the decor and functions of the window */
1123 client_get_mwm_hints(self
);
1124 /* this can change the mwmhints for special cases */
1125 client_get_type_and_transientness(self
);
1126 client_get_state(self
);
1127 client_update_normal_hints(self
);
1129 /* get the session related properties, these can change decorations
1130 from per-app settings */
1131 client_get_session_ids(self
);
1133 /* now we got everything that can affect the decorations */
1137 /* get this early so we have it for debugging */
1138 client_update_title(self
);
1140 client_update_protocols(self
);
1142 client_update_wmhints(self
);
1143 /* this may have already been called from client_update_wmhints */
1144 if (!self
->parents
&& !self
->transient_for_group
)
1145 client_update_transient_for(self
);
1147 client_get_startup_id(self
);
1148 client_get_desktop(self
);/* uses transient data/group/startup id if a
1149 desktop is not specified */
1150 client_get_shaped(self
);
1153 /* a couple type-based defaults for new windows */
1155 /* this makes sure that these windows appear on all desktops */
1156 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1157 self
->desktop
= DESKTOP_ALL
;
1161 client_update_sync_request_counter(self
);
1164 client_get_colormap(self
);
1165 client_update_strut(self
);
1166 client_update_icons(self
);
1167 client_update_icon_geometry(self
);
1170 static void client_get_startup_id(ObClient
*self
)
1172 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1174 PROP_GETS(self
->group
->leader
,
1175 net_startup_id
, utf8
, &self
->startup_id
);
1178 static void client_get_area(ObClient
*self
)
1180 XWindowAttributes wattrib
;
1183 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1184 g_assert(ret
!= BadWindow
);
1186 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1187 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1188 self
->border_width
= wattrib
.border_width
;
1190 ob_debug("client area: %d %d %d %d bw %d\n", wattrib
.x
, wattrib
.y
,
1191 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1194 static void client_get_desktop(ObClient
*self
)
1196 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1198 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1199 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1200 self
->desktop
= screen_num_desktops
- 1;
1203 ob_debug("client requested desktop 0x%x\n", self
->desktop
);
1206 gboolean first
= TRUE
;
1207 guint all
= screen_num_desktops
; /* not a valid value */
1209 /* if they are all on one desktop, then open it on the
1211 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1212 ObClient
*c
= it
->data
;
1214 if (c
->desktop
== DESKTOP_ALL
) continue;
1220 else if (all
!= c
->desktop
)
1221 all
= screen_num_desktops
; /* make it invalid */
1223 if (all
!= screen_num_desktops
) {
1224 self
->desktop
= all
;
1226 ob_debug("client desktop set from parents: 0x%x\n",
1229 /* try get from the startup-notification protocol */
1230 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1231 if (self
->desktop
>= screen_num_desktops
&&
1232 self
->desktop
!= DESKTOP_ALL
)
1233 self
->desktop
= screen_num_desktops
- 1;
1234 ob_debug("client desktop set from startup-notification: 0x%x\n",
1237 /* defaults to the current desktop */
1239 self
->desktop
= screen_desktop
;
1240 ob_debug("client desktop set to the current desktop: %d\n",
1246 static void client_get_state(ObClient
*self
)
1251 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1253 for (i
= 0; i
< num
; ++i
) {
1254 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1256 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1257 self
->shaded
= TRUE
;
1258 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1259 self
->iconic
= TRUE
;
1260 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1261 self
->skip_taskbar
= TRUE
;
1262 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1263 self
->skip_pager
= TRUE
;
1264 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1265 self
->fullscreen
= TRUE
;
1266 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1267 self
->max_vert
= TRUE
;
1268 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1269 self
->max_horz
= TRUE
;
1270 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1272 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1274 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1275 self
->demands_attention
= TRUE
;
1276 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1277 self
->undecorated
= TRUE
;
1284 static void client_get_shaped(ObClient
*self
)
1286 self
->shaped
= FALSE
;
1288 if (extensions_shape
) {
1293 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1295 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1296 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1298 self
->shaped
= (s
!= 0);
1303 void client_update_transient_for(ObClient
*self
)
1306 ObClient
*target
= NULL
;
1307 gboolean trangroup
= FALSE
;
1309 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1310 if (t
!= self
->window
) { /* cant be transient to itself! */
1311 target
= g_hash_table_lookup(window_map
, &t
);
1312 /* if this happens then we need to check for it*/
1313 g_assert(target
!= self
);
1314 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1315 /* this can happen when a dialog is a child of
1316 a dockapp, for example */
1321 /* Setting the transient_for to Root is actually illegal, however
1322 applications from time have done this to specify transient for
1324 if (!target
&& self
->group
&& t
== RootWindow(ob_display
, ob_screen
))
1326 } else if (self
->group
&& self
->transient
)
1329 client_update_transient_tree(self
, self
->group
, self
->group
,
1330 self
->transient_for_group
, trangroup
,
1331 client_direct_parent(self
), target
);
1332 self
->transient_for_group
= trangroup
;
1336 static void client_update_transient_tree(ObClient
*self
,
1337 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1338 gboolean oldgtran
, gboolean newgtran
,
1339 ObClient
* oldparent
,
1340 ObClient
*newparent
)
1345 g_assert(!oldgtran
|| oldgroup
);
1346 g_assert(!newgtran
|| newgroup
);
1347 g_assert((!oldgtran
&& !oldparent
) ||
1348 (oldgtran
&& !oldparent
) ||
1349 (!oldgtran
&& oldparent
));
1350 g_assert((!newgtran
&& !newparent
) ||
1351 (newgtran
&& !newparent
) ||
1352 (!newgtran
&& newparent
));
1355 Group transient windows are not allowed to have other group
1356 transient windows as their children.
1360 /* No change has occured */
1361 if (oldgroup
== newgroup
&&
1362 oldgtran
== newgtran
&&
1363 oldparent
== newparent
) return;
1365 /** Remove the client from the transient tree **/
1367 for (it
= self
->transients
; it
; it
= next
) {
1368 next
= g_slist_next(it
);
1370 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1371 c
->parents
= g_slist_remove(c
->parents
, self
);
1373 for (it
= self
->parents
; it
; it
= next
) {
1374 next
= g_slist_next(it
);
1376 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1377 c
->transients
= g_slist_remove(c
->transients
, self
);
1380 /** Re-add the client to the transient tree **/
1382 /* If we're transient for a group then we need to add ourselves to all our
1385 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1388 !client_search_top_direct_parent(c
)->transient_for_group
&&
1391 c
->transients
= g_slist_prepend(c
->transients
, self
);
1392 self
->parents
= g_slist_prepend(self
->parents
, c
);
1397 /* If we are now transient for a single window we need to add ourselves to
1400 WARNING: Cyclical transient ness is possible if two windows are
1401 transient for eachother.
1403 else if (newparent
&&
1404 /* don't make ourself its child if it is already our child */
1405 !client_is_direct_child(self
, newparent
) &&
1406 client_normal(newparent
))
1408 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1409 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1412 /* Add any group transient windows to our children. But if we're transient
1413 for the group, then other group transients are not our children.
1415 WARNING: Cyclical transient-ness is possible. For e.g. if:
1416 A is transient for the group
1417 B is transient for A
1418 C is transient for B
1419 A can't be transient for C or we have a cycle
1421 if (!newgtran
&& newgroup
&&
1423 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1424 client_normal(self
))
1426 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1428 if (c
!= self
&& c
->transient_for_group
&&
1429 /* Don't make it our child if it is already our parent */
1430 !client_is_direct_child(c
, self
))
1432 self
->transients
= g_slist_prepend(self
->transients
, c
);
1433 c
->parents
= g_slist_prepend(c
->parents
, self
);
1438 /** If we change our group transient-ness, our children change their
1439 effect group transient-ness, which affects how they relate to other
1442 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1444 if (!c
->transient_for_group
)
1445 client_update_transient_tree(c
, c
->group
, c
->group
,
1446 c
->transient_for_group
,
1447 c
->transient_for_group
,
1448 client_direct_parent(c
),
1449 client_direct_parent(c
));
1453 static void client_get_mwm_hints(ObClient
*self
)
1458 self
->mwmhints
.flags
= 0; /* default to none */
1460 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1462 if (num
>= OB_MWM_ELEMENTS
) {
1463 self
->mwmhints
.flags
= hints
[0];
1464 self
->mwmhints
.functions
= hints
[1];
1465 self
->mwmhints
.decorations
= hints
[2];
1471 void client_get_type_and_transientness(ObClient
*self
)
1478 self
->transient
= FALSE
;
1480 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1481 /* use the first value that we know about in the array */
1482 for (i
= 0; i
< num
; ++i
) {
1483 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1484 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1485 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1486 self
->type
= OB_CLIENT_TYPE_DOCK
;
1487 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1488 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1489 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1490 self
->type
= OB_CLIENT_TYPE_MENU
;
1491 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1492 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1493 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1494 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1495 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1496 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1497 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1498 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1499 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1500 /* prevent this window from getting any decor or
1502 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1503 OB_MWM_FLAG_DECORATIONS
);
1504 self
->mwmhints
.decorations
= 0;
1505 self
->mwmhints
.functions
= 0;
1507 if (self
->type
!= (ObClientType
) -1)
1508 break; /* grab the first legit type */
1513 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1514 self
->transient
= TRUE
;
1516 if (self
->type
== (ObClientType
) -1) {
1517 /*the window type hint was not set, which means we either classify
1518 ourself as a normal window or a dialog, depending on if we are a
1520 if (self
->transient
)
1521 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1523 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1526 /* then, based on our type, we can update our transientness.. */
1527 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1528 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1529 self
->type
== OB_CLIENT_TYPE_MENU
||
1530 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1532 self
->transient
= TRUE
;
1536 void client_update_protocols(ObClient
*self
)
1539 guint num_return
, i
;
1541 self
->focus_notify
= FALSE
;
1542 self
->delete_window
= FALSE
;
1544 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1545 for (i
= 0; i
< num_return
; ++i
) {
1546 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1547 /* this means we can request the window to close */
1548 self
->delete_window
= TRUE
;
1549 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1550 /* if this protocol is requested, then the window will be
1551 notified whenever we want it to receive focus */
1552 self
->focus_notify
= TRUE
;
1553 else if (proto
[i
] == prop_atoms
.net_wm_ping
)
1554 /* if this protocol is requested, then the window will allow
1555 pings to determine if it is still alive */
1558 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1559 /* if this protocol is requested, then resizing the
1560 window will be synchronized between the frame and the
1562 self
->sync_request
= TRUE
;
1570 void client_update_sync_request_counter(ObClient
*self
)
1574 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1575 self
->sync_counter
= i
;
1577 self
->sync_counter
= None
;
1581 static void client_get_colormap(ObClient
*self
)
1583 XWindowAttributes wa
;
1585 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1586 client_update_colormap(self
, wa
.colormap
);
1589 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1591 if (colormap
== self
->colormap
) return;
1593 ob_debug("Setting client %s colormap: 0x%x\n", self
->title
, colormap
);
1595 if (client_focused(self
)) {
1596 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1597 self
->colormap
= colormap
;
1598 screen_install_colormap(self
, FALSE
); /* install new one */
1600 self
->colormap
= colormap
;
1603 void client_update_normal_hints(ObClient
*self
)
1609 self
->min_ratio
= 0.0f
;
1610 self
->max_ratio
= 0.0f
;
1611 SIZE_SET(self
->size_inc
, 1, 1);
1612 SIZE_SET(self
->base_size
, 0, 0);
1613 SIZE_SET(self
->min_size
, 0, 0);
1614 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1616 /* get the hints from the window */
1617 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1618 /* normal windows can't request placement! har har
1619 if (!client_normal(self))
1621 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1622 self
->sized
= (size
.flags
& (PSize
|USSize
));
1624 if (size
.flags
& PWinGravity
)
1625 self
->gravity
= size
.win_gravity
;
1627 if (size
.flags
& PAspect
) {
1628 if (size
.min_aspect
.y
)
1630 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1631 if (size
.max_aspect
.y
)
1633 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1636 if (size
.flags
& PMinSize
)
1637 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1639 if (size
.flags
& PMaxSize
)
1640 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1642 if (size
.flags
& PBaseSize
)
1643 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1645 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1646 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1648 ob_debug("Normal hints: min size (%d %d) max size (%d %d)\n "
1649 "size inc (%d %d) base size (%d %d)\n",
1650 self
->min_size
.width
, self
->min_size
.height
,
1651 self
->max_size
.width
, self
->max_size
.height
,
1652 self
->size_inc
.width
, self
->size_inc
.height
,
1653 self
->base_size
.width
, self
->base_size
.height
);
1656 ob_debug("Normal hints: not set\n");
1659 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1661 /* start with everything (cept fullscreen) */
1663 (OB_FRAME_DECOR_TITLEBAR
|
1664 OB_FRAME_DECOR_HANDLE
|
1665 OB_FRAME_DECOR_GRIPS
|
1666 OB_FRAME_DECOR_BORDER
|
1667 OB_FRAME_DECOR_ICON
|
1668 OB_FRAME_DECOR_ALLDESKTOPS
|
1669 OB_FRAME_DECOR_ICONIFY
|
1670 OB_FRAME_DECOR_MAXIMIZE
|
1671 OB_FRAME_DECOR_SHADE
|
1672 OB_FRAME_DECOR_CLOSE
);
1674 (OB_CLIENT_FUNC_RESIZE
|
1675 OB_CLIENT_FUNC_MOVE
|
1676 OB_CLIENT_FUNC_ICONIFY
|
1677 OB_CLIENT_FUNC_MAXIMIZE
|
1678 OB_CLIENT_FUNC_SHADE
|
1679 OB_CLIENT_FUNC_CLOSE
|
1680 OB_CLIENT_FUNC_BELOW
|
1681 OB_CLIENT_FUNC_ABOVE
|
1682 OB_CLIENT_FUNC_UNDECORATE
);
1684 if (!(self
->min_size
.width
< self
->max_size
.width
||
1685 self
->min_size
.height
< self
->max_size
.height
))
1686 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1688 switch (self
->type
) {
1689 case OB_CLIENT_TYPE_NORMAL
:
1690 /* normal windows retain all of the possible decorations and
1691 functionality, and can be fullscreen */
1692 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1695 case OB_CLIENT_TYPE_DIALOG
:
1696 /* sometimes apps make dialog windows fullscreen for some reason (for
1697 e.g. kpdf does this..) */
1698 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1701 case OB_CLIENT_TYPE_UTILITY
:
1702 /* these windows don't have anything added or removed by default */
1705 case OB_CLIENT_TYPE_MENU
:
1706 case OB_CLIENT_TYPE_TOOLBAR
:
1707 /* these windows can't iconify or maximize */
1708 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1709 OB_FRAME_DECOR_MAXIMIZE
);
1710 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1711 OB_CLIENT_FUNC_MAXIMIZE
);
1714 case OB_CLIENT_TYPE_SPLASH
:
1715 /* these don't get get any decorations, and the only thing you can
1716 do with them is move them */
1717 self
->decorations
= 0;
1718 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1721 case OB_CLIENT_TYPE_DESKTOP
:
1722 /* these windows are not manipulated by the window manager */
1723 self
->decorations
= 0;
1724 self
->functions
= 0;
1727 case OB_CLIENT_TYPE_DOCK
:
1728 /* these windows are not manipulated by the window manager, but they
1729 can set below layer which has a special meaning */
1730 self
->decorations
= 0;
1731 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1735 /* Mwm Hints are applied subtractively to what has already been chosen for
1736 decor and functionality */
1737 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1738 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1739 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1740 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1742 /* if the mwm hints request no handle or title, then all
1743 decorations are disabled, but keep the border if that's
1745 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1746 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1748 self
->decorations
= 0;
1753 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1754 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1755 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1756 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1757 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1758 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1759 /* dont let mwm hints kill any buttons
1760 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1761 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1762 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1763 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1765 /* dont let mwm hints kill the close button
1766 if (! (self->mwmhints.functions & MwmFunc_Close))
1767 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1771 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1772 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1773 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1774 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1775 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1776 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1778 /* can't maximize without moving/resizing */
1779 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1780 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1781 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1782 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1783 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1786 if (self
->max_horz
&& self
->max_vert
) {
1787 /* you can't resize fully maximized windows */
1788 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1789 /* kill the handle on fully maxed windows */
1790 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1793 /* If there are no decorations to remove, don't allow the user to try
1795 if (self
->decorations
== 0)
1796 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1798 /* finally, the user can have requested no decorations, which overrides
1799 everything (but doesnt give it a border if it doesnt have one) */
1800 if (self
->undecorated
)
1801 self
->decorations
= 0;
1803 /* if we don't have a titlebar, then we cannot shade! */
1804 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1805 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1807 /* now we need to check against rules for the client's current state */
1808 if (self
->fullscreen
) {
1809 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1810 OB_CLIENT_FUNC_FULLSCREEN
|
1811 OB_CLIENT_FUNC_ICONIFY
);
1812 self
->decorations
= 0;
1815 client_change_allowed_actions(self
);
1818 /* force reconfigure to make sure decorations are updated */
1819 client_reconfigure(self
, TRUE
);
1822 static void client_change_allowed_actions(ObClient
*self
)
1827 /* desktop windows are kept on all desktops */
1828 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1829 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1831 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1832 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1833 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1834 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1835 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1836 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1837 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1838 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1839 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1840 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1841 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1842 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1843 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1844 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1845 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1847 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1848 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1849 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1850 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1851 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1852 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1854 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1856 /* make sure the window isn't breaking any rules now
1858 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1859 it can't be iconified with its parent
1862 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1863 if (self
->frame
) client_shade(self
, FALSE
);
1864 else self
->shaded
= FALSE
;
1866 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1867 if (self
->frame
) client_fullscreen(self
, FALSE
);
1868 else self
->fullscreen
= FALSE
;
1870 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1872 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1873 else self
->max_vert
= self
->max_horz
= FALSE
;
1877 void client_update_wmhints(ObClient
*self
)
1881 /* assume a window takes input if it doesnt specify */
1882 self
->can_focus
= TRUE
;
1884 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1887 if (hints
->flags
& InputHint
)
1888 self
->can_focus
= hints
->input
;
1890 /* only do this when first managing the window *AND* when we aren't
1892 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1893 if (hints
->flags
& StateHint
)
1894 self
->iconic
= hints
->initial_state
== IconicState
;
1897 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1898 if (self
->urgent
&& !ur
)
1899 client_hilite(self
, TRUE
);
1900 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1901 client_hilite(self
, FALSE
);
1903 if (!(hints
->flags
& WindowGroupHint
))
1904 hints
->window_group
= None
;
1906 /* did the group state change? */
1907 if (hints
->window_group
!=
1908 (self
->group
? self
->group
->leader
: None
))
1910 ObGroup
*oldgroup
= self
->group
;
1912 /* remove from the old group if there was one */
1913 if (self
->group
!= NULL
) {
1914 group_remove(self
->group
, self
);
1918 /* add ourself to the group if we have one */
1919 if (hints
->window_group
!= None
) {
1920 self
->group
= group_add(hints
->window_group
, self
);
1923 /* Put ourselves into the new group's transient tree, and remove
1924 ourselves from the old group's */
1925 client_update_transient_tree(self
, oldgroup
, self
->group
,
1926 self
->transient_for_group
,
1927 self
->transient_for_group
,
1928 client_direct_parent(self
),
1929 client_direct_parent(self
));
1931 /* Lastly, being in a group, or not, can change if the window is
1932 transient for anything.
1934 The logic for this is:
1935 self->transient = TRUE always if the window wants to be
1936 transient for something, even if transient_for was NULL because
1937 it wasn't in a group before.
1939 If parents was NULL and oldgroup was NULL we can assume
1940 that when we add the new group, it will become transient for
1943 If transient_for_group is TRUE, then it must have already
1944 had a group. If it is getting a new group, the above call to
1945 client_update_transient_tree has already taken care of
1946 everything ! If it is losing all group status then it will
1947 no longer be transient for anything and that needs to be
1950 if (self
->transient
&&
1951 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1952 (self
->transient_for_group
&& !self
->group
)))
1953 client_update_transient_for(self
);
1956 /* the WM_HINTS can contain an icon */
1957 if (hints
->flags
& IconPixmapHint
)
1958 client_update_icons(self
);
1964 void client_update_title(ObClient
*self
)
1967 gchar
*visible
= NULL
;
1969 g_free(self
->title
);
1972 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1973 /* try old x stuff */
1974 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1975 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1976 if (self
->transient
) {
1978 GNOME alert windows are not given titles:
1979 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1981 data
= g_strdup("");
1983 data
= g_strdup("Unnamed Window");
1987 if (self
->client_machine
) {
1988 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1993 if (self
->not_responding
) {
1995 if (self
->close_tried_term
)
1996 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1998 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2002 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
2003 self
->title
= visible
;
2006 frame_adjust_title(self
->frame
);
2008 /* update the icon title */
2010 g_free(self
->icon_title
);
2013 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
2014 /* try old x stuff */
2015 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
2016 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
2017 data
= g_strdup(self
->title
);
2019 if (self
->client_machine
) {
2020 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2025 if (self
->not_responding
) {
2027 if (self
->close_tried_term
)
2028 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2030 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2034 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
2035 self
->icon_title
= visible
;
2038 void client_update_strut(ObClient
*self
)
2042 gboolean got
= FALSE
;
2045 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
2049 STRUT_PARTIAL_SET(strut
,
2050 data
[0], data
[2], data
[1], data
[3],
2051 data
[4], data
[5], data
[8], data
[9],
2052 data
[6], data
[7], data
[10], data
[11]);
2058 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
2064 /* use the screen's width/height */
2065 a
= screen_physical_area_all_monitors();
2067 STRUT_PARTIAL_SET(strut
,
2068 data
[0], data
[2], data
[1], data
[3],
2069 a
->y
, a
->y
+ a
->height
- 1,
2070 a
->x
, a
->x
+ a
->width
- 1,
2071 a
->y
, a
->y
+ a
->height
- 1,
2072 a
->x
, a
->x
+ a
->width
- 1);
2079 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2080 0, 0, 0, 0, 0, 0, 0, 0);
2082 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2083 self
->strut
= strut
;
2085 /* updating here is pointless while we're being mapped cuz we're not in
2086 the client list yet */
2088 screen_update_areas();
2092 /* Avoid storing icons above this size if possible */
2093 #define AVOID_ABOVE 64
2095 void client_update_icons(ObClient
*self
)
2100 guint num_seen
; /* number of icons present */
2101 guint num_small_seen
; /* number of icons small enough present */
2102 guint smallest
, smallest_area
;
2104 for (i
= 0; i
< self
->nicons
; ++i
)
2105 g_free(self
->icons
[i
].data
);
2106 if (self
->nicons
> 0)
2107 g_free(self
->icons
);
2110 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2111 /* figure out how many valid icons are in here */
2113 num_seen
= num_small_seen
= 0;
2114 smallest
= smallest_area
= 0;
2120 /* watch for it being too small for the specified size, or for
2121 zero sized icons. */
2122 if (i
> num
|| w
== 0 || h
== 0) break;
2124 if (!smallest_area
|| w
*h
< smallest_area
) {
2125 smallest
= num_seen
;
2126 smallest_area
= w
*h
;
2129 if (w
<= AVOID_ABOVE
&& h
<= AVOID_ABOVE
)
2132 if (num_small_seen
> 0)
2133 self
->nicons
= num_small_seen
;
2137 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2139 /* store the icons */
2141 for (j
= 0; j
< self
->nicons
;) {
2144 w
= self
->icons
[j
].width
= data
[i
++];
2145 h
= self
->icons
[j
].height
= data
[i
++];
2147 /* if there are some icons smaller than the threshold, we're
2148 skipping all the ones above */
2149 if (num_small_seen
> 0) {
2150 if (w
> AVOID_ABOVE
|| h
> AVOID_ABOVE
) {
2155 /* if there were no icons smaller than the threshold, then we are
2156 only taking the smallest available one we saw */
2157 else if (j
!= smallest
) {
2162 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2163 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2168 self
->icons
[j
].data
[t
] =
2169 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2170 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2171 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2172 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2183 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2184 if (hints
->flags
& IconPixmapHint
) {
2186 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2187 xerror_set_ignore(TRUE
);
2188 if (!RrPixmapToRGBA(ob_rr_inst
,
2190 (hints
->flags
& IconMaskHint
?
2191 hints
->icon_mask
: None
),
2192 &self
->icons
[0].width
,
2193 &self
->icons
[0].height
,
2194 &self
->icons
[0].data
))
2196 g_free(self
->icons
);
2199 xerror_set_ignore(FALSE
);
2205 /* set the default icon onto the window
2206 in theory, this could be a race, but if a window doesn't set an icon
2207 or removes it entirely, it's not very likely it is going to set one
2208 right away afterwards
2210 if it has parents, then one of them will have an icon already
2212 if (self
->nicons
== 0 && !self
->parents
) {
2213 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2216 data
= g_new(gulong
, 48*48+2);
2217 data
[0] = data
[1] = 48;
2218 for (i
= 0; i
< 48*48; ++i
)
2219 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2220 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2221 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2222 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2223 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2225 } else if (self
->frame
)
2226 /* don't draw the icon empty if we're just setting one now anyways,
2227 we'll get the property change any second */
2228 frame_adjust_icon(self
->frame
);
2231 void client_update_icon_geometry(ObClient
*self
)
2236 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2238 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
))
2241 /* don't let them set it with an area < 0 */
2242 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2243 MAX(data
[2],0), MAX(data
[3],0));
2248 static void client_get_session_ids(ObClient
*self
)
2255 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2258 /* get the SM_CLIENT_ID */
2261 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2263 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2265 /* get the WM_CLASS (name and class). make them "" if they are not
2269 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2271 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2275 self
->name
= g_strdup(ss
[0]);
2277 self
->class = g_strdup(ss
[1]);
2282 if (self
->name
== NULL
) self
->name
= g_strdup("");
2283 if (self
->class == NULL
) self
->class = g_strdup("");
2285 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2288 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2290 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2295 self
->role
= g_strdup("");
2297 /* get the WM_COMMAND */
2301 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2303 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2306 /* merge/mash them all together */
2307 gchar
*merge
= NULL
;
2310 for (i
= 0; ss
[i
]; ++i
) {
2313 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2315 merge
= g_strconcat(ss
[i
], NULL
);
2320 self
->wm_command
= merge
;
2323 /* get the WM_CLIENT_MACHINE */
2326 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2328 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2331 gchar localhost
[128];
2334 gethostname(localhost
, 127);
2335 localhost
[127] = '\0';
2336 if (strcmp(localhost
, s
) != 0)
2337 self
->client_machine
= s
;
2341 /* see if it has the PID set too (the PID requires that the
2342 WM_CLIENT_MACHINE be set) */
2343 if (PROP_GET32(self
->window
, net_wm_pid
, cardinal
, &pid
))
2348 static void client_change_wm_state(ObClient
*self
)
2353 old
= self
->wmstate
;
2355 if (self
->shaded
|| self
->iconic
||
2356 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2358 self
->wmstate
= IconicState
;
2360 self
->wmstate
= NormalState
;
2362 if (old
!= self
->wmstate
) {
2363 PROP_MSG(self
->window
, kde_wm_change_state
,
2364 self
->wmstate
, 1, 0, 0);
2366 state
[0] = self
->wmstate
;
2368 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2372 static void client_change_state(ObClient
*self
)
2374 gulong netstate
[12];
2379 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2381 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2383 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2384 if (self
->skip_taskbar
)
2385 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2386 if (self
->skip_pager
)
2387 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2388 if (self
->fullscreen
)
2389 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2391 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2393 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2395 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2397 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2398 if (self
->demands_attention
)
2399 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2400 if (self
->undecorated
)
2401 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2402 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2405 frame_adjust_state(self
->frame
);
2408 ObClient
*client_search_focus_tree(ObClient
*self
)
2413 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2414 if (client_focused(it
->data
)) return it
->data
;
2415 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2420 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2422 if (self
->parents
) {
2425 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2426 ObClient
*c
= it
->data
;
2427 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2433 /* this function checks the whole tree, the client_search_focus_tree
2434 does not, so we need to check this window */
2435 if (client_focused(self
))
2437 return client_search_focus_tree(self
);
2441 ObClient
*client_search_focus_group_full(ObClient
*self
)
2446 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2447 ObClient
*c
= it
->data
;
2449 if (client_focused(c
)) return c
;
2450 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2453 if (client_focused(self
)) return self
;
2457 gboolean
client_has_parent(ObClient
*self
)
2459 return self
->parents
!= NULL
;
2462 static ObStackingLayer
calc_layer(ObClient
*self
)
2467 monitor
= screen_physical_area_monitor(client_monitor(self
));
2469 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2470 l
= OB_STACKING_LAYER_DESKTOP
;
2471 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2472 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2473 else l
= OB_STACKING_LAYER_ABOVE
;
2475 else if ((self
->fullscreen
||
2476 /* No decorations and fills the monitor = oldskool fullscreen.
2477 But not for maximized windows.
2479 (self
->decorations
== 0 &&
2480 !(self
->max_horz
&& self
->max_vert
) &&
2481 RECT_EQUAL(self
->area
, *monitor
))) &&
2482 /* you are fullscreen while you or your children are focused.. */
2483 (client_focused(self
) || client_search_focus_tree(self
) ||
2484 /* you can be fullscreen if you're on another desktop */
2485 (self
->desktop
!= screen_desktop
&&
2486 self
->desktop
!= DESKTOP_ALL
) ||
2487 /* and you can also be fullscreen if the focused client is on
2488 another monitor, or nothing else is focused */
2490 client_monitor(focus_client
) != client_monitor(self
))))
2491 l
= OB_STACKING_LAYER_FULLSCREEN
;
2492 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2493 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2494 else l
= OB_STACKING_LAYER_NORMAL
;
2501 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2502 ObStackingLayer min
)
2504 ObStackingLayer old
, own
;
2508 own
= calc_layer(self
);
2509 self
->layer
= MAX(own
, min
);
2511 if (self
->layer
!= old
) {
2512 stacking_remove(CLIENT_AS_WINDOW(self
));
2513 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2516 /* we've been restacked */
2517 self
->visited
= TRUE
;
2519 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2520 client_calc_layer_recursive(it
->data
, orig
,
2524 static void client_calc_layer_internal(ObClient
*self
)
2528 /* transients take on the layer of their parents */
2529 sit
= client_search_all_top_parents(self
);
2531 for (; sit
; sit
= g_slist_next(sit
))
2532 client_calc_layer_recursive(sit
->data
, self
, 0);
2535 void client_calc_layer(ObClient
*self
)
2539 /* skip over stuff above fullscreen layer */
2540 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2541 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2543 /* find the windows in the fullscreen layer, and mark them not-visited */
2544 for (; it
; it
= g_list_next(it
)) {
2545 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2546 else if (WINDOW_IS_CLIENT(it
->data
))
2547 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2550 client_calc_layer_internal(self
);
2552 /* skip over stuff above fullscreen layer */
2553 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2554 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2556 /* now recalc any windows in the fullscreen layer which have not
2557 had their layer recalced already */
2558 for (; it
; it
= g_list_next(it
)) {
2559 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2560 else if (WINDOW_IS_CLIENT(it
->data
) &&
2561 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2562 client_calc_layer_internal(it
->data
);
2566 gboolean
client_should_show(ObClient
*self
)
2570 if (client_normal(self
) && screen_showing_desktop
)
2572 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2578 gboolean
client_show(ObClient
*self
)
2580 gboolean show
= FALSE
;
2582 if (client_should_show(self
)) {
2583 /* replay pending pointer event before showing the window, in case it
2584 should be going to something under the window */
2585 mouse_replay_pointer();
2587 frame_show(self
->frame
);
2590 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2591 it needs to be in IconicState. This includes when it is on another
2594 client_change_wm_state(self
);
2599 gboolean
client_hide(ObClient
*self
)
2601 gboolean hide
= FALSE
;
2603 if (!client_should_show(self
)) {
2604 if (self
== focus_client
) {
2605 /* if there is a grab going on, then we need to cancel it. if we
2606 move focus during the grab, applications will get
2607 NotifyWhileGrabbed events and ignore them !
2609 actions should not rely on being able to move focus during an
2612 event_cancel_all_key_grabs();
2615 /* We don't need to ignore enter events here.
2616 The window can hide/iconify in 3 different ways:
2617 1 - through an x message. in this case we ignore all enter events
2618 caused by responding to the x message (unless underMouse)
2619 2 - by a keyboard action. in this case we ignore all enter events
2620 caused by the action
2621 3 - by a mouse action. in this case they are doing stuff with the
2622 mouse and focus _should_ move.
2624 Also in action_end, we simulate an enter event that can't be ignored
2625 so trying to ignore them is futile in case 3 anyways
2628 /* replay pending pointer event before hiding the window, in case it
2629 should be going to the window */
2630 mouse_replay_pointer();
2632 frame_hide(self
->frame
);
2635 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2636 it needs to be in IconicState. This includes when it is on another
2639 client_change_wm_state(self
);
2644 void client_showhide(ObClient
*self
)
2646 if (!client_show(self
))
2650 gboolean
client_normal(ObClient
*self
) {
2651 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2652 self
->type
== OB_CLIENT_TYPE_DOCK
||
2653 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2656 gboolean
client_helper(ObClient
*self
)
2658 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2659 self
->type
== OB_CLIENT_TYPE_MENU
||
2660 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2663 gboolean
client_mouse_focusable(ObClient
*self
)
2665 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2666 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2667 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2668 self
->type
== OB_CLIENT_TYPE_DOCK
);
2671 gboolean
client_enter_focusable(ObClient
*self
)
2673 /* you can focus desktops but it shouldn't on enter */
2674 return (client_mouse_focusable(self
) &&
2675 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2679 static void client_apply_startup_state(ObClient
*self
,
2680 gint x
, gint y
, gint w
, gint h
)
2682 /* save the states that we are going to apply */
2683 gboolean iconic
= self
->iconic
;
2684 gboolean fullscreen
= self
->fullscreen
;
2685 gboolean undecorated
= self
->undecorated
;
2686 gboolean shaded
= self
->shaded
;
2687 gboolean demands_attention
= self
->demands_attention
;
2688 gboolean max_horz
= self
->max_horz
;
2689 gboolean max_vert
= self
->max_vert
;
2693 /* turn them all off in the client, so they won't affect the window
2695 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2696 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2698 /* move the client to its placed position, or it it's already there,
2699 generate a ConfigureNotify telling the client where it is.
2701 do this after adjusting the frame. otherwise it gets all weird and
2702 clients don't work right
2704 do this before applying the states so they have the correct
2705 pre-max/pre-fullscreen values
2707 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2708 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2709 self
->window
, x
, y
, w
, h
);
2710 /* save the area, and make it where it should be for the premax stuff */
2711 oldarea
= self
->area
;
2712 RECT_SET(self
->area
, x
, y
, w
, h
);
2714 /* apply the states. these are in a carefully crafted order.. */
2717 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2719 client_fullscreen(self
, TRUE
);
2721 client_set_undecorated(self
, TRUE
);
2723 client_shade(self
, TRUE
);
2724 if (demands_attention
)
2725 client_hilite(self
, TRUE
);
2727 if (max_vert
&& max_horz
)
2728 client_maximize(self
, TRUE
, 0);
2730 client_maximize(self
, TRUE
, 2);
2732 client_maximize(self
, TRUE
, 1);
2734 /* if the window hasn't been configured yet, then do so now, in fact the
2735 x,y,w,h may _not_ be the same as the area rect, which can end up
2736 meaning that the client isn't properly moved/resized by the fullscreen
2738 pho can cause this because it maps at size of the screen but not 0,0
2739 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2740 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2741 cuz thats where the pre-fullscreen will be. however the actual area is
2742 not, so this needs to be called even if we have fullscreened/maxed
2744 self
->area
= oldarea
;
2745 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2747 /* set the desktop hint, to make sure that it always exists */
2748 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2750 /* nothing to do for the other states:
2759 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2761 /* these should be the current values. this is for when you're not moving,
2763 g_assert(*x
== self
->area
.x
);
2764 g_assert(oldw
== self
->area
.width
);
2767 switch (self
->gravity
) {
2769 case NorthWestGravity
:
2771 case SouthWestGravity
:
2778 *x
-= (neww
- oldw
) / 2;
2780 case NorthEastGravity
:
2782 case SouthEastGravity
:
2788 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2790 /* these should be the current values. this is for when you're not moving,
2792 g_assert(*y
== self
->area
.y
);
2793 g_assert(oldh
== self
->area
.height
);
2796 switch (self
->gravity
) {
2798 case NorthWestGravity
:
2800 case NorthEastGravity
:
2807 *y
-= (newh
- oldh
) / 2;
2809 case SouthWestGravity
:
2811 case SouthEastGravity
:
2817 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2818 gint
*logicalw
, gint
*logicalh
,
2821 Rect desired
= {*x
, *y
, *w
, *h
};
2822 frame_rect_to_frame(self
->frame
, &desired
);
2824 /* make the frame recalculate its dimentions n shit without changing
2825 anything visible for real, this way the constraints below can work with
2826 the updated frame dimensions. */
2827 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2829 /* gets the frame's position */
2830 frame_client_gravity(self
->frame
, x
, y
);
2832 /* these positions are frame positions, not client positions */
2834 /* set the size and position if fullscreen */
2835 if (self
->fullscreen
) {
2839 i
= screen_find_monitor(&desired
);
2840 a
= screen_physical_area_monitor(i
);
2847 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2851 } else if (self
->max_horz
|| self
->max_vert
) {
2855 /* use all possible struts when maximizing to the full screen */
2856 i
= screen_find_monitor(&desired
);
2857 a
= screen_area(self
->desktop
, i
,
2858 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2860 /* set the size and position if maximized */
2861 if (self
->max_horz
) {
2863 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2865 if (self
->max_vert
) {
2867 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2870 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2876 /* gets the client's position */
2877 frame_frame_gravity(self
->frame
, x
, y
);
2879 /* work within the prefered sizes given by the window */
2880 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2881 gint basew
, baseh
, minw
, minh
;
2883 gfloat minratio
, maxratio
;
2885 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2886 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2887 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2888 0 : self
->min_ratio
;
2889 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2890 0 : self
->max_ratio
;
2892 /* base size is substituted with min size if not specified */
2893 if (self
->base_size
.width
|| self
->base_size
.height
) {
2894 basew
= self
->base_size
.width
;
2895 baseh
= self
->base_size
.height
;
2897 basew
= self
->min_size
.width
;
2898 baseh
= self
->min_size
.height
;
2900 /* min size is substituted with base size if not specified */
2901 if (self
->min_size
.width
|| self
->min_size
.height
) {
2902 minw
= self
->min_size
.width
;
2903 minh
= self
->min_size
.height
;
2905 minw
= self
->base_size
.width
;
2906 minh
= self
->base_size
.height
;
2909 /* if this is a user-requested resize, then check against min/max
2912 /* smaller than min size or bigger than max size? */
2913 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2914 if (*w
< minw
) *w
= minw
;
2915 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2916 if (*h
< minh
) *h
= minh
;
2921 /* keep to the increments */
2925 /* you cannot resize to nothing */
2926 if (basew
+ *w
< 1) *w
= 1 - basew
;
2927 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2929 /* save the logical size */
2930 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2931 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2939 /* adjust the height to match the width for the aspect ratios.
2940 for this, min size is not substituted for base size ever. */
2941 *w
-= self
->base_size
.width
;
2942 *h
-= self
->base_size
.height
;
2945 if (*h
* minratio
> *w
) {
2946 *h
= (gint
)(*w
/ minratio
);
2948 /* you cannot resize to nothing */
2951 *w
= (gint
)(*h
* minratio
);
2955 if (*h
* maxratio
< *w
) {
2956 *h
= (gint
)(*w
/ maxratio
);
2958 /* you cannot resize to nothing */
2961 *w
= (gint
)(*h
* minratio
);
2965 *w
+= self
->base_size
.width
;
2966 *h
+= self
->base_size
.height
;
2969 /* these override the above states! if you cant move you can't move! */
2971 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2975 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2976 *w
= self
->area
.width
;
2977 *h
= self
->area
.height
;
2986 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2987 gboolean user
, gboolean final
, gboolean force_reply
)
2991 gboolean send_resize_client
;
2992 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2993 gboolean fmoved
, fresized
;
2994 guint fdecor
= self
->frame
->decorations
;
2995 gboolean fhorz
= self
->frame
->max_horz
;
2996 gboolean fvert
= self
->frame
->max_vert
;
2997 gint logicalw
, logicalh
;
2999 /* find the new x, y, width, and height (and logical size) */
3000 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
3002 /* set the logical size if things changed */
3003 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
3004 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
3006 /* figure out if we moved or resized or what */
3007 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
3008 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
3010 oldw
= self
->area
.width
;
3011 oldh
= self
->area
.height
;
3012 oldframe
= self
->frame
->area
;
3013 RECT_SET(self
->area
, x
, y
, w
, h
);
3015 /* for app-requested resizes, always resize if 'resized' is true.
3016 for user-requested ones, only resize if final is true, or when
3017 resizing in redraw mode */
3018 send_resize_client
= ((!user
&& resized
) ||
3020 (resized
&& config_resize_redraw
))));
3022 /* if the client is enlarging, then resize the client before the frame */
3023 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
3024 XMoveResizeWindow(ob_display
, self
->window
,
3025 self
->frame
->size
.left
, self
->frame
->size
.top
,
3026 MAX(w
, oldw
), MAX(h
, oldh
));
3027 frame_adjust_client_area(self
->frame
);
3030 /* find the frame's dimensions and move/resize it */
3034 /* if decorations changed, then readjust everything for the frame */
3035 if (self
->decorations
!= fdecor
||
3036 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
3038 fmoved
= fresized
= TRUE
;
3041 /* adjust the frame */
3042 if (fmoved
|| fresized
) {
3043 gulong ignore_start
;
3045 ignore_start
= event_start_ignore_all_enters();
3047 /* replay pending pointer event before move the window, in case it
3048 would change what window gets the event */
3049 mouse_replay_pointer();
3051 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
3054 event_end_ignore_all_enters(ignore_start
);
3057 if (!user
|| final
) {
3058 gint oldrx
= self
->root_pos
.x
;
3059 gint oldry
= self
->root_pos
.y
;
3060 /* we have reset the client to 0 border width, so don't include
3061 it in these coords */
3062 POINT_SET(self
->root_pos
,
3063 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3065 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3066 self
->border_width
);
3067 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3071 /* This is kinda tricky and should not be changed.. let me explain!
3073 When user = FALSE, then the request is coming from the application
3074 itself, and we are more strict about when to send a synthetic
3075 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3076 in this case (if force_reply is true)
3078 When user = TRUE, then the request is coming from "us", like when we
3079 maximize a window or something. In this case we are more lenient. We
3080 used to follow the same rules as above, but _Java_ Swing can't handle
3081 this. So just to appease Swing, when user = TRUE, we always send
3082 a synthetic ConfigureNotify to give the window its root coordinates.
3084 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3085 (user
&& final
&& rootmoved
))
3089 event
.type
= ConfigureNotify
;
3090 event
.xconfigure
.display
= ob_display
;
3091 event
.xconfigure
.event
= self
->window
;
3092 event
.xconfigure
.window
= self
->window
;
3094 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
3095 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3097 /* root window real coords */
3098 event
.xconfigure
.x
= self
->root_pos
.x
;
3099 event
.xconfigure
.y
= self
->root_pos
.y
;
3100 event
.xconfigure
.width
= w
;
3101 event
.xconfigure
.height
= h
;
3102 event
.xconfigure
.border_width
= self
->border_width
;
3103 event
.xconfigure
.above
= None
;
3104 event
.xconfigure
.override_redirect
= FALSE
;
3105 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3106 FALSE
, StructureNotifyMask
, &event
);
3109 /* if the client is shrinking, then resize the frame before the client.
3111 both of these resize sections may run, because the top one only resizes
3112 in the direction that is growing
3114 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3115 frame_adjust_client_area(self
->frame
);
3116 XMoveResizeWindow(ob_display
, self
->window
,
3117 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3122 /* if it moved between monitors, then this can affect the stacking
3123 layer of this window or others - for fullscreen windows */
3124 if (screen_find_monitor(&self
->frame
->area
) !=
3125 screen_find_monitor(&oldframe
))
3127 client_calc_layer(self
);
3131 void client_fullscreen(ObClient
*self
, gboolean fs
)
3135 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3136 self
->fullscreen
== fs
) return; /* already done */
3138 self
->fullscreen
= fs
;
3139 client_change_state(self
); /* change the state hints on the client */
3142 self
->pre_fullscreen_area
= self
->area
;
3143 /* if the window is maximized, its area isn't all that meaningful.
3144 save it's premax area instead. */
3145 if (self
->max_horz
) {
3146 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3147 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3149 if (self
->max_vert
) {
3150 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3151 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3154 /* these will help configure_full figure out where to fullscreen
3158 w
= self
->area
.width
;
3159 h
= self
->area
.height
;
3161 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3162 self
->pre_fullscreen_area
.height
> 0);
3164 x
= self
->pre_fullscreen_area
.x
;
3165 y
= self
->pre_fullscreen_area
.y
;
3166 w
= self
->pre_fullscreen_area
.width
;
3167 h
= self
->pre_fullscreen_area
.height
;
3168 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3171 ob_debug("Window %s going fullscreen (%d)\n",
3172 self
->title
, self
->fullscreen
);
3174 client_setup_decor_and_functions(self
, FALSE
);
3175 client_move_resize(self
, x
, y
, w
, h
);
3177 /* and adjust our layer/stacking. do this after resizing the window,
3178 and applying decorations, because windows which fill the screen are
3179 considered "fullscreen" and it affects their layer */
3180 client_calc_layer(self
);
3183 /* try focus us when we go into fullscreen mode */
3188 static void client_iconify_recursive(ObClient
*self
,
3189 gboolean iconic
, gboolean curdesk
,
3190 gboolean hide_animation
)
3193 gboolean changed
= FALSE
;
3196 if (self
->iconic
!= iconic
) {
3197 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3201 /* don't let non-normal windows iconify along with their parents
3203 if (client_normal(self
)) {
3204 self
->iconic
= iconic
;
3206 /* update the focus lists.. iconic windows go to the bottom of
3208 focus_order_to_bottom(self
);
3213 self
->iconic
= iconic
;
3215 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3216 self
->desktop
!= DESKTOP_ALL
)
3217 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3219 /* this puts it after the current focused window */
3220 focus_order_remove(self
);
3221 focus_order_add_new(self
);
3228 client_change_state(self
);
3229 if (config_animate_iconify
&& !hide_animation
)
3230 frame_begin_iconify_animation(self
->frame
, iconic
);
3231 /* do this after starting the animation so it doesn't flash */
3232 client_showhide(self
);
3235 /* iconify all direct transients, and deiconify all transients
3237 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3238 if (it
->data
!= self
)
3239 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3240 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3244 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3245 gboolean hide_animation
)
3247 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3248 /* move up the transient chain as far as possible first */
3249 self
= client_search_top_direct_parent(self
);
3250 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3254 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3258 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3259 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3261 /* check if already done */
3263 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3264 if (dir
== 1 && self
->max_horz
) return;
3265 if (dir
== 2 && self
->max_vert
) return;
3267 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3268 if (dir
== 1 && !self
->max_horz
) return;
3269 if (dir
== 2 && !self
->max_vert
) return;
3272 /* these will help configure_full figure out which screen to fill with
3276 w
= self
->area
.width
;
3277 h
= self
->area
.height
;
3280 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3281 RECT_SET(self
->pre_max_area
,
3282 self
->area
.x
, self
->pre_max_area
.y
,
3283 self
->area
.width
, self
->pre_max_area
.height
);
3285 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3286 RECT_SET(self
->pre_max_area
,
3287 self
->pre_max_area
.x
, self
->area
.y
,
3288 self
->pre_max_area
.width
, self
->area
.height
);
3291 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3292 g_assert(self
->pre_max_area
.width
> 0);
3294 x
= self
->pre_max_area
.x
;
3295 w
= self
->pre_max_area
.width
;
3297 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3298 0, self
->pre_max_area
.height
);
3300 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3301 g_assert(self
->pre_max_area
.height
> 0);
3303 y
= self
->pre_max_area
.y
;
3304 h
= self
->pre_max_area
.height
;
3306 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3307 self
->pre_max_area
.width
, 0);
3311 if (dir
== 0 || dir
== 1) /* horz */
3312 self
->max_horz
= max
;
3313 if (dir
== 0 || dir
== 2) /* vert */
3314 self
->max_vert
= max
;
3316 client_change_state(self
); /* change the state hints on the client */
3318 client_setup_decor_and_functions(self
, FALSE
);
3319 client_move_resize(self
, x
, y
, w
, h
);
3322 void client_shade(ObClient
*self
, gboolean shade
)
3324 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3325 shade
) || /* can't shade */
3326 self
->shaded
== shade
) return; /* already done */
3328 self
->shaded
= shade
;
3329 client_change_state(self
);
3330 client_change_wm_state(self
); /* the window is being hidden/shown */
3331 /* resize the frame to just the titlebar */
3332 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3335 static void client_ping_event(ObClient
*self
, gboolean dead
)
3337 self
->not_responding
= dead
;
3338 client_update_title(self
);
3341 /* try kill it nicely the first time again, if it started responding
3343 self
->close_tried_term
= FALSE
;
3347 void client_close(ObClient
*self
)
3349 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3352 prompt_cancel(self
->prompt
);
3356 /* in the case that the client provides no means to requesting that it
3357 close, we just kill it */
3358 if (!self
->delete_window
)
3359 /* don't use client_kill(), we should only kill based on PID in
3360 response to a lack of PING replies */
3361 XKillClient(ob_display
, self
->window
);
3362 else if (self
->not_responding
)
3365 /* request the client to close with WM_DELETE_WINDOW */
3366 PROP_MSG_TO(self
->window
, self
->window
, wm_protocols
,
3367 prop_atoms
.wm_delete_window
, event_curtime
, 0, 0, 0,
3371 void client_kill(ObClient
*self
)
3373 if (!self
->client_machine
&& self
->pid
) {
3374 /* running on the local host */
3375 if (!self
->close_tried_term
) {
3376 ob_debug("killing window 0x%x with pid %lu, with SIGTERM\n",
3377 self
->window
, self
->pid
);
3378 kill(self
->pid
, SIGTERM
);
3379 self
->close_tried_term
= TRUE
;
3381 /* show that we're trying to kill it */
3382 client_update_title(self
);
3385 ob_debug("killing window 0x%x with pid %lu, with SIGKILL\n",
3386 self
->window
, self
->pid
);
3387 kill(self
->pid
, SIGKILL
); /* kill -9 */
3391 XKillClient(ob_display
, self
->window
);
3394 void client_hilite(ObClient
*self
, gboolean hilite
)
3396 if (self
->demands_attention
== hilite
)
3397 return; /* no change */
3399 /* don't allow focused windows to hilite */
3400 self
->demands_attention
= hilite
&& !client_focused(self
);
3401 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3402 if (self
->demands_attention
)
3403 frame_flash_start(self
->frame
);
3405 frame_flash_stop(self
->frame
);
3406 client_change_state(self
);
3410 static void client_set_desktop_recursive(ObClient
*self
,
3418 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3420 ob_debug("Setting desktop %u\n", target
+1);
3422 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3424 old
= self
->desktop
;
3425 self
->desktop
= target
;
3426 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3427 /* the frame can display the current desktop state */
3428 frame_adjust_state(self
->frame
);
3429 /* 'move' the window to the new desktop */
3433 /* raise if it was not already on the desktop */
3434 if (old
!= DESKTOP_ALL
&& !dontraise
)
3435 stacking_raise(CLIENT_AS_WINDOW(self
));
3436 if (STRUT_EXISTS(self
->strut
))
3437 screen_update_areas();
3439 /* the new desktop's geometry may be different, so we may need to
3440 resize, for example if we are maximized */
3441 client_reconfigure(self
, FALSE
);
3444 /* move all transients */
3445 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3446 if (it
->data
!= self
)
3447 if (client_is_direct_child(self
, it
->data
))
3448 client_set_desktop_recursive(it
->data
, target
,
3449 donthide
, dontraise
);
3452 void client_set_desktop(ObClient
*self
, guint target
,
3453 gboolean donthide
, gboolean dontraise
)
3455 self
= client_search_top_direct_parent(self
);
3456 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3459 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3461 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3462 return child
== parent
;
3465 ObClient
*client_search_modal_child(ObClient
*self
)
3470 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3471 ObClient
*c
= it
->data
;
3472 if ((ret
= client_search_modal_child(c
))) return ret
;
3473 if (c
->modal
) return c
;
3478 gboolean
client_validate(ObClient
*self
)
3482 XSync(ob_display
, FALSE
); /* get all events on the server */
3484 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3485 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3486 XPutBackEvent(ob_display
, &e
);
3493 void client_set_wm_state(ObClient
*self
, glong state
)
3495 if (state
== self
->wmstate
) return; /* no change */
3499 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3502 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3507 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3509 gboolean shaded
= self
->shaded
;
3510 gboolean fullscreen
= self
->fullscreen
;
3511 gboolean undecorated
= self
->undecorated
;
3512 gboolean max_horz
= self
->max_horz
;
3513 gboolean max_vert
= self
->max_vert
;
3514 gboolean modal
= self
->modal
;
3515 gboolean iconic
= self
->iconic
;
3516 gboolean demands_attention
= self
->demands_attention
;
3517 gboolean above
= self
->above
;
3518 gboolean below
= self
->below
;
3521 if (!(action
== prop_atoms
.net_wm_state_add
||
3522 action
== prop_atoms
.net_wm_state_remove
||
3523 action
== prop_atoms
.net_wm_state_toggle
))
3524 /* an invalid action was passed to the client message, ignore it */
3527 for (i
= 0; i
< 2; ++i
) {
3528 Atom state
= i
== 0 ? data1
: data2
;
3530 if (!state
) continue;
3532 /* if toggling, then pick whether we're adding or removing */
3533 if (action
== prop_atoms
.net_wm_state_toggle
) {
3534 if (state
== prop_atoms
.net_wm_state_modal
)
3535 action
= modal
? prop_atoms
.net_wm_state_remove
:
3536 prop_atoms
.net_wm_state_add
;
3537 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3538 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3539 prop_atoms
.net_wm_state_add
;
3540 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3541 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3542 prop_atoms
.net_wm_state_add
;
3543 else if (state
== prop_atoms
.net_wm_state_shaded
)
3544 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3545 prop_atoms
.net_wm_state_add
;
3546 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3547 action
= self
->skip_taskbar
?
3548 prop_atoms
.net_wm_state_remove
:
3549 prop_atoms
.net_wm_state_add
;
3550 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3551 action
= self
->skip_pager
?
3552 prop_atoms
.net_wm_state_remove
:
3553 prop_atoms
.net_wm_state_add
;
3554 else if (state
== prop_atoms
.net_wm_state_hidden
)
3555 action
= self
->iconic
?
3556 prop_atoms
.net_wm_state_remove
:
3557 prop_atoms
.net_wm_state_add
;
3558 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3559 action
= fullscreen
?
3560 prop_atoms
.net_wm_state_remove
:
3561 prop_atoms
.net_wm_state_add
;
3562 else if (state
== prop_atoms
.net_wm_state_above
)
3563 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3564 prop_atoms
.net_wm_state_add
;
3565 else if (state
== prop_atoms
.net_wm_state_below
)
3566 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3567 prop_atoms
.net_wm_state_add
;
3568 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3569 action
= self
->demands_attention
?
3570 prop_atoms
.net_wm_state_remove
:
3571 prop_atoms
.net_wm_state_add
;
3572 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3573 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3574 prop_atoms
.net_wm_state_add
;
3577 if (action
== prop_atoms
.net_wm_state_add
) {
3578 if (state
== prop_atoms
.net_wm_state_modal
) {
3580 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3582 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3584 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3586 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3587 self
->skip_taskbar
= TRUE
;
3588 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3589 self
->skip_pager
= TRUE
;
3590 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3592 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3594 } else if (state
== prop_atoms
.net_wm_state_above
) {
3597 } else if (state
== prop_atoms
.net_wm_state_below
) {
3600 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3601 demands_attention
= TRUE
;
3602 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3606 } else { /* action == prop_atoms.net_wm_state_remove */
3607 if (state
== prop_atoms
.net_wm_state_modal
) {
3609 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3611 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3613 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3615 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3616 self
->skip_taskbar
= FALSE
;
3617 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3618 self
->skip_pager
= FALSE
;
3619 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3621 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3623 } else if (state
== prop_atoms
.net_wm_state_above
) {
3625 } else if (state
== prop_atoms
.net_wm_state_below
) {
3627 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3628 demands_attention
= FALSE
;
3629 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3630 undecorated
= FALSE
;
3635 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3636 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3638 if (max_horz
== max_vert
) { /* both going the same way */
3639 client_maximize(self
, max_horz
, 0);
3641 client_maximize(self
, max_horz
, 1);
3642 client_maximize(self
, max_vert
, 2);
3646 if (max_horz
!= self
->max_horz
)
3647 client_maximize(self
, max_horz
, 1);
3649 client_maximize(self
, max_vert
, 2);
3652 /* change fullscreen state before shading, as it will affect if the window
3654 if (fullscreen
!= self
->fullscreen
)
3655 client_fullscreen(self
, fullscreen
);
3656 if (shaded
!= self
->shaded
)
3657 client_shade(self
, shaded
);
3658 if (undecorated
!= self
->undecorated
)
3659 client_set_undecorated(self
, undecorated
);
3660 if (above
!= self
->above
|| below
!= self
->below
) {
3661 self
->above
= above
;
3662 self
->below
= below
;
3663 client_calc_layer(self
);
3666 if (modal
!= self
->modal
) {
3667 self
->modal
= modal
;
3668 /* when a window changes modality, then its stacking order with its
3669 transients needs to change */
3670 stacking_raise(CLIENT_AS_WINDOW(self
));
3672 /* it also may get focused. if something is focused that shouldn't
3673 be focused anymore, then move the focus */
3674 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3675 client_focus(focus_client
);
3678 if (iconic
!= self
->iconic
)
3679 client_iconify(self
, iconic
, FALSE
, FALSE
);
3681 if (demands_attention
!= self
->demands_attention
)
3682 client_hilite(self
, demands_attention
);
3684 client_change_state(self
); /* change the hint to reflect these changes */
3687 ObClient
*client_focus_target(ObClient
*self
)
3689 ObClient
*child
= NULL
;
3691 child
= client_search_modal_child(self
);
3692 if (child
) return child
;
3696 gboolean
client_can_focus(ObClient
*self
)
3698 /* choose the correct target */
3699 self
= client_focus_target(self
);
3701 if (!self
->frame
->visible
)
3704 if (!(self
->can_focus
|| self
->focus_notify
))
3710 gboolean
client_focus(ObClient
*self
)
3712 /* we might not focus this window, so if we have modal children which would
3713 be focused instead, bring them to this desktop */
3714 client_bring_modal_windows(self
);
3716 /* choose the correct target */
3717 self
= client_focus_target(self
);
3719 if (!client_can_focus(self
)) {
3720 ob_debug_type(OB_DEBUG_FOCUS
,
3721 "Client %s can't be focused\n", self
->title
);
3725 ob_debug_type(OB_DEBUG_FOCUS
,
3726 "Focusing client \"%s\" (0x%x) at time %u\n",
3727 self
->title
, self
->window
, event_curtime
);
3729 /* if using focus_delay, stop the timer now so that focus doesn't
3731 event_halt_focus_delay();
3733 /* if there is a grab going on, then we need to cancel it. if we move
3734 focus during the grab, applications will get NotifyWhileGrabbed events
3737 actions should not rely on being able to move focus during an
3740 event_cancel_all_key_grabs();
3742 xerror_set_ignore(TRUE
);
3743 xerror_occured
= FALSE
;
3745 if (self
->can_focus
) {
3746 /* This can cause a BadMatch error with CurrentTime, or if an app
3747 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3748 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3752 if (self
->focus_notify
) {
3754 ce
.xclient
.type
= ClientMessage
;
3755 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3756 ce
.xclient
.display
= ob_display
;
3757 ce
.xclient
.window
= self
->window
;
3758 ce
.xclient
.format
= 32;
3759 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3760 ce
.xclient
.data
.l
[1] = event_curtime
;
3761 ce
.xclient
.data
.l
[2] = 0l;
3762 ce
.xclient
.data
.l
[3] = 0l;
3763 ce
.xclient
.data
.l
[4] = 0l;
3764 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3767 xerror_set_ignore(FALSE
);
3769 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d\n", xerror_occured
);
3770 return !xerror_occured
;
3773 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3776 if (client_normal(self
) && screen_showing_desktop
)
3777 screen_show_desktop(FALSE
, self
);
3779 client_iconify(self
, FALSE
, here
, FALSE
);
3780 if (self
->desktop
!= DESKTOP_ALL
&&
3781 self
->desktop
!= screen_desktop
)
3784 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3786 screen_set_desktop(self
->desktop
, FALSE
);
3787 } else if (!self
->frame
->visible
)
3788 /* if its not visible for other reasons, then don't mess
3791 if (self
->shaded
&& unshade
)
3792 client_shade(self
, FALSE
);
3794 stacking_raise(CLIENT_AS_WINDOW(self
));
3799 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3800 gboolean unshade
, gboolean user
)
3802 client_present(self
, here
, raise
, unshade
);
3805 static void client_bring_windows_recursive(ObClient
*self
,
3813 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3814 client_bring_windows_recursive(it
->data
, desktop
,
3815 helpers
, modals
, iconic
);
3817 if (((helpers
&& client_helper(self
)) ||
3818 (modals
&& self
->modal
)) &&
3819 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3820 (iconic
&& self
->iconic
)))
3822 if (iconic
&& self
->iconic
)
3823 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3825 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3829 void client_bring_helper_windows(ObClient
*self
)
3831 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3834 void client_bring_modal_windows(ObClient
*self
)
3836 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3839 gboolean
client_focused(ObClient
*self
)
3841 return self
== focus_client
;
3844 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3847 gulong min_diff
, min_i
;
3849 if (!self
->nicons
) {
3850 ObClientIcon
*parent
= NULL
;
3853 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
3854 ObClient
*c
= it
->data
;
3855 if ((parent
= client_icon_recursive(c
, w
, h
)))
3862 /* some kind of crappy approximation to find the icon closest in size to
3863 what we requested, but icons are generally all the same ratio as
3864 eachother so it's good enough. */
3866 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3869 for (i
= 1; i
< self
->nicons
; ++i
) {
3872 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3873 if (diff
< min_diff
) {
3878 return &self
->icons
[min_i
];
3881 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3884 static ObClientIcon deficon
;
3886 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3887 deficon
.width
= deficon
.height
= 48;
3888 deficon
.data
= ob_rr_theme
->def_win_icon
;
3894 void client_set_layer(ObClient
*self
, gint layer
)
3898 self
->above
= FALSE
;
3899 } else if (layer
== 0) {
3900 self
->below
= self
->above
= FALSE
;
3902 self
->below
= FALSE
;
3905 client_calc_layer(self
);
3906 client_change_state(self
); /* reflect this in the state hints */
3909 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3911 if (self
->undecorated
!= undecorated
&&
3912 /* don't let it undecorate if the function is missing, but let
3914 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3916 self
->undecorated
= undecorated
;
3917 client_setup_decor_and_functions(self
, TRUE
);
3918 client_change_state(self
); /* reflect this in the state hints */
3922 guint
client_monitor(ObClient
*self
)
3924 return screen_find_monitor(&self
->frame
->area
);
3927 ObClient
*client_direct_parent(ObClient
*self
)
3929 if (!self
->parents
) return NULL
;
3930 if (self
->transient_for_group
) return NULL
;
3931 return self
->parents
->data
;
3934 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3937 while ((p
= client_direct_parent(self
))) self
= p
;
3941 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3943 ObStackingLayer layer
)
3948 /* move up the direct transient chain as far as possible */
3949 while ((p
= client_direct_parent(self
)) &&
3950 (!bylayer
|| p
->layer
== layer
))
3954 ret
= g_slist_prepend(NULL
, self
);
3956 ret
= g_slist_copy(self
->parents
);
3961 GSList
*client_search_all_top_parents(ObClient
*self
)
3963 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3966 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3968 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3971 ObClient
*client_search_focus_parent(ObClient
*self
)
3975 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3976 if (client_focused(it
->data
)) return it
->data
;
3981 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3985 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3986 if (it
->data
== search
) return search
;
3991 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3995 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3996 if (sit
->data
== search
)
3998 if (client_search_transient(sit
->data
, search
))
4004 static void detect_edge(Rect area
, ObDirection dir
,
4005 gint my_head
, gint my_size
,
4006 gint my_edge_start
, gint my_edge_size
,
4007 gint
*dest
, gboolean
*near_edge
)
4009 gint edge_start
, edge_size
, head
, tail
;
4010 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
4013 case OB_DIRECTION_NORTH
:
4014 case OB_DIRECTION_SOUTH
:
4015 edge_start
= area
.x
;
4016 edge_size
= area
.width
;
4018 case OB_DIRECTION_EAST
:
4019 case OB_DIRECTION_WEST
:
4020 edge_start
= area
.y
;
4021 edge_size
= area
.height
;
4024 g_assert_not_reached();
4027 /* do we collide with this window? */
4028 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4029 edge_start
, edge_size
))
4033 case OB_DIRECTION_NORTH
:
4034 head
= RECT_BOTTOM(area
);
4035 tail
= RECT_TOP(area
);
4037 case OB_DIRECTION_SOUTH
:
4038 head
= RECT_TOP(area
);
4039 tail
= RECT_BOTTOM(area
);
4041 case OB_DIRECTION_WEST
:
4042 head
= RECT_RIGHT(area
);
4043 tail
= RECT_LEFT(area
);
4045 case OB_DIRECTION_EAST
:
4046 head
= RECT_LEFT(area
);
4047 tail
= RECT_RIGHT(area
);
4050 g_assert_not_reached();
4053 case OB_DIRECTION_NORTH
:
4054 case OB_DIRECTION_WEST
:
4055 /* check if our window is past the head of this window */
4056 if (my_head
<= head
+ 1)
4058 /* check if our window's tail is past the tail of this window */
4059 if (my_head
+ my_size
- 1 <= tail
)
4061 /* check if the head of this window is closer than the previously
4062 chosen edge (take into account that the previously chosen
4063 edge might have been a tail, not a head) */
4064 if (head
+ (*near_edge
? 0 : my_size
) < *dest
)
4066 /* check if the tail of this window is closer than the previously
4067 chosen edge (take into account that the previously chosen
4068 edge might have been a head, not a tail) */
4069 if (tail
- (!*near_edge
? 0 : my_size
) < *dest
)
4072 case OB_DIRECTION_SOUTH
:
4073 case OB_DIRECTION_EAST
:
4074 /* check if our window is past the head of this window */
4075 if (my_head
>= head
- 1)
4077 /* check if our window's tail is past the tail of this window */
4078 if (my_head
- my_size
+ 1 >= tail
)
4080 /* check if the head of this window is closer than the previously
4081 chosen edge (take into account that the previously chosen
4082 edge might have been a tail, not a head) */
4083 if (head
- (*near_edge
? 0 : my_size
) > *dest
)
4085 /* check if the tail of this window is closer than the previously
4086 chosen edge (take into account that the previously chosen
4087 edge might have been a head, not a tail) */
4088 if (tail
+ (!*near_edge
? 0 : my_size
) > *dest
)
4092 g_assert_not_reached();
4095 ob_debug("my head %d size %d\n", my_head
, my_size
);
4096 ob_debug("head %d tail %d deest %d\n", head
, tail
, *dest
);
4098 ob_debug("using near edge %d\n", head
);
4102 else if (!skip_tail
) {
4103 ob_debug("using far edge %d\n", tail
);
4109 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4110 gint my_head
, gint my_size
,
4111 gint my_edge_start
, gint my_edge_size
,
4112 gint
*dest
, gboolean
*near_edge
)
4119 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4120 &self
->frame
->area
);
4121 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
4122 &self
->frame
->area
);
4125 case OB_DIRECTION_NORTH
:
4126 if (my_head
>= RECT_TOP(*mon
) + 1)
4127 edge
= RECT_TOP(*mon
) - 1;
4129 edge
= RECT_TOP(*a
) - 1;
4131 case OB_DIRECTION_SOUTH
:
4132 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
4133 edge
= RECT_BOTTOM(*mon
) + 1;
4135 edge
= RECT_BOTTOM(*a
) + 1;
4137 case OB_DIRECTION_EAST
:
4138 if (my_head
<= RECT_RIGHT(*mon
) - 1)
4139 edge
= RECT_RIGHT(*mon
) + 1;
4141 edge
= RECT_RIGHT(*a
) + 1;
4143 case OB_DIRECTION_WEST
:
4144 if (my_head
>= RECT_LEFT(*mon
) + 1)
4145 edge
= RECT_LEFT(*mon
) - 1;
4147 edge
= RECT_LEFT(*a
) - 1;
4150 g_assert_not_reached();
4152 /* default to the far edge, then narrow it down */
4156 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4157 ObClient
*cur
= it
->data
;
4159 /* skip windows to not bump into */
4164 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4165 cur
->desktop
!= screen_desktop
)
4168 ob_debug("trying window %s\n", cur
->title
);
4170 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4171 my_edge_size
, dest
, near_edge
);
4173 dock_get_area(&dock_area
);
4174 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4175 my_edge_size
, dest
, near_edge
);
4180 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4184 gint e
, e_start
, e_size
;
4188 case OB_DIRECTION_EAST
:
4189 head
= RECT_RIGHT(self
->frame
->area
);
4190 size
= self
->frame
->area
.width
;
4191 e_start
= RECT_TOP(self
->frame
->area
);
4192 e_size
= self
->frame
->area
.height
;
4194 case OB_DIRECTION_WEST
:
4195 head
= RECT_LEFT(self
->frame
->area
);
4196 size
= self
->frame
->area
.width
;
4197 e_start
= RECT_TOP(self
->frame
->area
);
4198 e_size
= self
->frame
->area
.height
;
4200 case OB_DIRECTION_NORTH
:
4201 head
= RECT_TOP(self
->frame
->area
);
4202 size
= self
->frame
->area
.height
;
4203 e_start
= RECT_LEFT(self
->frame
->area
);
4204 e_size
= self
->frame
->area
.width
;
4206 case OB_DIRECTION_SOUTH
:
4207 head
= RECT_BOTTOM(self
->frame
->area
);
4208 size
= self
->frame
->area
.height
;
4209 e_start
= RECT_LEFT(self
->frame
->area
);
4210 e_size
= self
->frame
->area
.width
;
4213 g_assert_not_reached();
4216 client_find_edge_directional(self
, dir
, head
, size
,
4217 e_start
, e_size
, &e
, &near
);
4218 *x
= self
->frame
->area
.x
;
4219 *y
= self
->frame
->area
.y
;
4221 case OB_DIRECTION_EAST
:
4222 if (near
) e
-= self
->frame
->area
.width
;
4226 case OB_DIRECTION_WEST
:
4228 else e
-= self
->frame
->area
.width
;
4231 case OB_DIRECTION_NORTH
:
4233 else e
-= self
->frame
->area
.height
;
4236 case OB_DIRECTION_SOUTH
:
4237 if (near
) e
-= self
->frame
->area
.height
;
4242 g_assert_not_reached();
4244 frame_frame_gravity(self
->frame
, x
, y
);
4247 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4249 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4252 gint e
, e_start
, e_size
, delta
;
4257 case OB_DIRECTION_EAST
:
4258 head
= RECT_RIGHT(self
->frame
->area
) +
4259 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4260 e_start
= RECT_TOP(self
->frame
->area
);
4261 e_size
= self
->frame
->area
.height
;
4262 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4264 case OB_DIRECTION_WEST
:
4265 head
= RECT_LEFT(self
->frame
->area
) -
4266 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4267 e_start
= RECT_TOP(self
->frame
->area
);
4268 e_size
= self
->frame
->area
.height
;
4269 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4271 case OB_DIRECTION_NORTH
:
4272 head
= RECT_TOP(self
->frame
->area
) -
4273 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4274 e_start
= RECT_LEFT(self
->frame
->area
);
4275 e_size
= self
->frame
->area
.width
;
4276 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4278 case OB_DIRECTION_SOUTH
:
4279 head
= RECT_BOTTOM(self
->frame
->area
) +
4280 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4281 e_start
= RECT_LEFT(self
->frame
->area
);
4282 e_size
= self
->frame
->area
.width
;
4283 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4286 g_assert_not_reached();
4289 ob_debug("head %d dir %d\n", head
, dir
);
4290 client_find_edge_directional(self
, dir
, head
, 1,
4291 e_start
, e_size
, &e
, &near
);
4292 ob_debug("edge %d\n", e
);
4293 *x
= self
->frame
->area
.x
;
4294 *y
= self
->frame
->area
.y
;
4295 *w
= self
->frame
->area
.width
;
4296 *h
= self
->frame
->area
.height
;
4298 case OB_DIRECTION_EAST
:
4299 if (grow
== near
) --e
;
4300 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4303 case OB_DIRECTION_WEST
:
4304 if (grow
== near
) ++e
;
4305 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4309 case OB_DIRECTION_NORTH
:
4310 if (grow
== near
) ++e
;
4311 delta
= RECT_TOP(self
->frame
->area
) - e
;
4315 case OB_DIRECTION_SOUTH
:
4316 if (grow
== near
) --e
;
4317 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4321 g_assert_not_reached();
4323 frame_frame_gravity(self
->frame
, x
, y
);
4324 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4325 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4328 ObClient
* client_under_pointer(void)
4332 ObClient
*ret
= NULL
;
4334 if (screen_pointer_pos(&x
, &y
)) {
4335 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4336 if (WINDOW_IS_CLIENT(it
->data
)) {
4337 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4338 if (c
->frame
->visible
&&
4339 /* check the desktop, this is done during desktop
4340 switching and windows are shown/hidden status is not
4342 (c
->desktop
== screen_desktop
||
4343 c
->desktop
== DESKTOP_ALL
) &&
4344 /* ignore all animating windows */
4345 !frame_iconify_animating(c
->frame
) &&
4346 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4357 gboolean
client_has_group_siblings(ObClient
*self
)
4359 return self
->group
&& self
->group
->members
->next
;