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"
25 #include "moveresize.h"
37 #include "menuframe.h"
40 #include "render/render.h"
42 #include "obt/display.h"
50 # include <signal.h> /* for kill() */
54 #include <X11/Xutil.h>
56 /*! The event mask to grab on client windows */
57 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
60 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
65 ObClientCallback func
;
69 GList
*client_list
= NULL
;
71 static GSList
*client_destroy_notifies
= NULL
;
73 static void client_get_all(ObClient
*self
, gboolean real
);
74 static void client_get_startup_id(ObClient
*self
);
75 static void client_get_session_ids(ObClient
*self
);
76 static void client_get_area(ObClient
*self
);
77 static void client_get_desktop(ObClient
*self
);
78 static void client_get_state(ObClient
*self
);
79 static void client_get_shaped(ObClient
*self
);
80 static void client_get_mwm_hints(ObClient
*self
);
81 static void client_get_colormap(ObClient
*self
);
82 static void client_set_desktop_recursive(ObClient
*self
,
86 static void client_change_allowed_actions(ObClient
*self
);
87 static void client_change_state(ObClient
*self
);
88 static void client_change_wm_state(ObClient
*self
);
89 static void client_apply_startup_state(ObClient
*self
,
90 gint x
, gint y
, gint w
, gint h
);
91 static void client_restore_session_state(ObClient
*self
);
92 static gboolean
client_restore_session_stacking(ObClient
*self
);
93 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
94 static void client_update_transient_tree(ObClient
*self
,
95 ObGroup
*oldgroup
, ObGroup
*newgroup
,
96 gboolean oldgtran
, gboolean newgtran
,
99 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
101 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
103 ObStackingLayer layer
);
104 static void client_call_notifies(ObClient
*self
, GSList
*list
);
105 static void client_ping_event(ObClient
*self
, gboolean dead
);
108 void client_startup(gboolean reconfig
)
110 if (reconfig
) return;
115 void client_shutdown(gboolean reconfig
)
117 if (reconfig
) return;
120 static void client_call_notifies(ObClient
*self
, GSList
*list
)
124 for (it
= list
; it
; it
= g_slist_next(it
)) {
125 ClientCallback
*d
= it
->data
;
126 d
->func(self
, d
->data
);
130 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
132 ClientCallback
*d
= g_new(ClientCallback
, 1);
135 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
138 void client_remove_destroy_notify(ObClientCallback func
)
142 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
143 ClientCallback
*d
= it
->data
;
144 if (d
->func
== func
) {
146 client_destroy_notifies
=
147 g_slist_delete_link(client_destroy_notifies
, it
);
153 void client_set_list(void)
155 Window
*windows
, *win_it
;
157 guint size
= g_list_length(client_list
);
159 /* create an array of the window ids */
161 windows
= g_new(Window
, size
);
163 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
164 *win_it
= ((ObClient
*)it
->data
)->window
;
168 OBT_PROP_SETA32(obt_root(ob_screen
), NET_CLIENT_LIST
, WINDOW
,
169 (gulong
*)windows
, size
);
177 void client_manage(Window window
)
180 XSetWindowAttributes attrib_set
;
181 gboolean activate
= FALSE
;
182 ObAppSettings
*settings
;
183 gboolean transient
= FALSE
;
184 Rect place
, *monitor
;
185 Time launch_time
, map_time
;
187 ob_debug("Managing window: 0x%lx", window
);
189 map_time
= event_get_server_time();
191 /* choose the events we want to receive on the CLIENT window */
192 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
193 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
194 XChangeWindowAttributes(obt_display
, window
,
195 CWEventMask
|CWDontPropagate
, &attrib_set
);
197 /* create the ObClient struct, and populate it from the hints on the
199 self
= g_new0(ObClient
, 1);
200 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
201 self
->window
= window
;
203 /* non-zero defaults */
204 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
205 self
->gravity
= NorthWestGravity
;
206 self
->desktop
= screen_num_desktops
; /* always an invalid value */
208 /* get all the stuff off the window */
209 client_get_all(self
, TRUE
);
211 ob_debug("Window type: %d", self
->type
);
212 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
214 /* now we have all of the window's information so we can set this up.
215 do this before creating the frame, so it can tell that we are still
216 mapping and doesn't go applying things right away */
217 client_setup_decor_and_functions(self
, FALSE
);
219 /* specify that if we exit, the window should not be destroyed and
220 should be reparented back to root automatically */
221 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
223 /* create the decoration frame for the client window */
224 self
->frame
= frame_new(self
);
226 frame_grab_client(self
->frame
);
228 /* we've grabbed everything and set everything that we need to at mapping
232 /* per-app settings override stuff from client_get_all, and return the
233 settings for other uses too. the returned settings is a shallow copy,
234 that needs to be freed with g_free(). */
235 settings
= client_get_settings_state(self
);
236 /* the session should get the last say though */
237 client_restore_session_state(self
);
239 /* tell startup notification that this app started */
240 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
242 /* do this after we have a frame.. it uses the frame to help determine the
243 WM_STATE to apply. */
244 client_change_state(self
);
246 /* add ourselves to the focus order */
247 focus_order_add_new(self
);
249 /* do this to add ourselves to the stacking list in a non-intrusive way */
250 client_calc_layer(self
);
252 /* focus the new window? */
253 if (ob_state() != OB_STATE_STARTING
&&
254 (!self
->session
|| self
->session
->focused
) &&
255 /* this means focus=true for window is same as config_focus_new=true */
256 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
257 client_search_focus_tree_full(self
)) &&
258 /* this checks for focus=false for the window */
259 (!settings
|| settings
->focus
!= 0) &&
260 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
265 /* remove the client's border */
266 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
268 /* adjust the frame to the client's size before showing or placing
270 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
271 frame_adjust_client_area(self
->frame
);
273 /* where the frame was placed is where the window was originally */
275 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
277 /* figure out placement for the window if the window is new */
278 if (ob_state() == OB_STATE_RUNNING
) {
279 ob_debug("Positioned: %s @ %d %d",
280 (!self
->positioned
? "no" :
281 (self
->positioned
== PPosition
? "program specified" :
282 (self
->positioned
== USPosition
? "user specified" :
283 (self
->positioned
== (PPosition
| USPosition
) ?
284 "program + user specified" :
285 "BADNESS !?")))), place
.x
, place
.y
);
287 ob_debug("Sized: %s @ %d %d",
288 (!self
->sized
? "no" :
289 (self
->sized
== PSize
? "program specified" :
290 (self
->sized
== USSize
? "user specified" :
291 (self
->sized
== (PSize
| USSize
) ?
292 "program + user specified" :
293 "BADNESS !?")))), place
.width
, place
.height
);
295 /* splash screens are also returned as TRUE for transient,
296 and so will be forced on screen below */
297 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
299 /* make sure the window is visible. */
300 client_find_onscreen(self
, &place
.x
, &place
.y
,
301 place
.width
, place
.height
,
302 /* non-normal clients has less rules, and
303 windows that are being restored from a
304 session do also. we can assume you want
305 it back where you saved it. Clients saying
306 they placed themselves are subjected to
307 harder rules, ones that are placed by
308 place.c or by the user are allowed partially
309 off-screen and on xinerama divides (ie,
310 it is up to the placement routines to avoid
311 the xinerama divides)
313 splash screens get "transient" set to TRUE by
314 the place_client call
316 ob_state() == OB_STATE_RUNNING
&&
318 (!((self
->positioned
& USPosition
) ||
319 (settings
&& settings
->pos_given
)) &&
320 client_normal(self
) &&
322 /* don't move oldschool fullscreen windows to
323 fit inside the struts (fixes Acroread, which
324 makes its fullscreen window fit the screen
325 but it is not USSize'd or USPosition'd) */
326 !(self
->decorations
== 0 &&
327 RECT_EQUAL(place
, *monitor
)))));
330 /* if the window isn't user-sized, then make it fit inside
331 the visible screen area on its monitor. Use basically the same rules
332 for forcing the window on screen in the client_find_onscreen call.
334 do this after place_client, it chooses the monitor!
336 splash screens get "transient" set to TRUE by
337 the place_client call
339 if (ob_state() == OB_STATE_RUNNING
&&
341 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
342 client_normal(self
) &&
344 /* don't shrink oldschool fullscreen windows to fit inside the
345 struts (fixes Acroread, which makes its fullscreen window
346 fit the screen but it is not USSize'd or USPosition'd) */
347 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
349 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
351 /* get the size of the frame */
352 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
353 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
355 /* fit the window inside the area */
356 place
.width
= MIN(place
.width
, a
->width
);
357 place
.height
= MIN(place
.height
, a
->height
);
359 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
361 /* get the size of the client back */
362 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
363 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
368 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
369 "some restrictions may apply",
370 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
372 ob_debug(" but session requested %d, %d %d x %d instead, "
374 self
->session
->x
, self
->session
->y
,
375 self
->session
->w
, self
->session
->h
);
377 /* do this after the window is placed, so the premax/prefullscreen numbers
380 this also places the window
382 client_apply_startup_state(self
, place
.x
, place
.y
,
383 place
.width
, place
.height
);
388 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s",
389 activate
? "yes" : "no");
391 gboolean raise
= FALSE
;
393 /* This is focus stealing prevention */
394 ob_debug_type(OB_DEBUG_FOCUS
,
395 "Want to focus new window 0x%x at time %u "
396 "launched at %u (last user interaction time %u)",
397 self
->window
, map_time
, launch_time
,
398 event_last_user_time
);
400 if (menu_frame_visible
|| moveresize_in_progress
) {
403 ob_debug_type(OB_DEBUG_FOCUS
,
404 "Not focusing the window because the user is inside "
405 "an Openbox menu or is move/resizing a window and "
406 "we don't want to interrupt them");
409 /* if it's on another desktop */
410 else if (!(self
->desktop
== screen_desktop
||
411 self
->desktop
== DESKTOP_ALL
) &&
412 /* the timestamp is from before you changed desktops */
413 launch_time
&& screen_desktop_user_time
&&
414 !event_time_after(launch_time
, screen_desktop_user_time
))
418 ob_debug_type(OB_DEBUG_FOCUS
,
419 "Not focusing the window because its on another "
422 /* If something is focused, and it's not our relative... */
423 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
424 client_search_focus_group_full(self
) == NULL
)
426 /* If the user is working in another window right now, then don't
428 if (event_last_user_time
&& launch_time
&&
429 event_time_after(event_last_user_time
, launch_time
) &&
430 event_last_user_time
!= launch_time
&&
431 event_time_after(event_last_user_time
,
432 map_time
- OB_EVENT_USER_TIME_DELAY
))
435 ob_debug_type(OB_DEBUG_FOCUS
,
436 "Not focusing the window because the user is "
437 "working in another window");
439 /* If its a transient (and its parents aren't focused) */
440 else if (client_has_parent(self
)) {
442 ob_debug_type(OB_DEBUG_FOCUS
,
443 "Not focusing the window because it is a "
444 "transient, and its relatives aren't focused");
446 /* Don't steal focus from globally active clients.
447 I stole this idea from KWin. It seems nice.
449 else if (!(focus_client
->can_focus
||
450 focus_client
->focus_notify
))
453 ob_debug_type(OB_DEBUG_FOCUS
,
454 "Not focusing the window because a globally "
455 "active client has focus");
457 /* Don't move focus if it's not going to go to this window
459 else if (client_focus_target(self
) != self
) {
462 ob_debug_type(OB_DEBUG_FOCUS
,
463 "Not focusing the window because another window "
464 "would get the focus anyway");
466 else if (!(self
->desktop
== screen_desktop
||
467 self
->desktop
== DESKTOP_ALL
))
471 ob_debug_type(OB_DEBUG_FOCUS
,
472 "Not focusing the window because it is on "
473 "another desktop and no relatives are focused ");
478 ob_debug_type(OB_DEBUG_FOCUS
,
479 "Focus stealing prevention activated for %s at "
480 "time %u (last user interactioon time %u)",
481 self
->title
, map_time
, event_last_user_time
);
482 /* if the client isn't focused, then hilite it so the user
484 client_hilite(self
, TRUE
);
485 /* we may want to raise it even tho we're not activating it */
486 if (raise
&& !client_restore_session_stacking(self
))
487 stacking_raise(CLIENT_AS_WINDOW(self
));
491 /* This may look rather odd. Well it's because new windows are added
492 to the stacking order non-intrusively. If we're not going to focus
493 the new window or hilite it, then we raise it to the top. This will
494 take affect for things that don't get focused like splash screens.
495 Also if you don't have focus_new enabled, then it's going to get
496 raised to the top. Legacy begets legacy I guess?
498 if (!client_restore_session_stacking(self
))
499 stacking_raise(CLIENT_AS_WINDOW(self
));
502 mouse_grab_for_client(self
, TRUE
);
504 /* this has to happen before we try focus the window, but we want it to
505 happen after the client's stacking has been determined or it looks bad
509 if (!config_focus_under_mouse
)
510 ignore_start
= event_start_ignore_all_enters();
514 if (!config_focus_under_mouse
)
515 event_end_ignore_all_enters(ignore_start
);
519 gboolean stacked
= client_restore_session_stacking(self
);
520 client_present(self
, FALSE
, !stacked
, TRUE
);
523 /* add to client list/map */
524 client_list
= g_list_append(client_list
, self
);
525 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
527 /* this has to happen after we're in the client_list */
528 if (STRUT_EXISTS(self
->strut
))
529 screen_update_areas();
531 /* update the list hints */
534 /* watch for when the application stops responding. only do this for
535 normal windows, i.e. windows which have titlebars and close buttons
536 and things like that.
537 we don't need to stop pinging on unmanage, because it will be handled
538 automatically by the destroy callback!
540 if (self
->ping
&& client_normal(self
))
541 ping_start(self
, client_ping_event
);
543 /* free the ObAppSettings shallow copy */
546 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
547 window
, self
->frame
->window
, self
->class);
551 ObClient
*client_fake_manage(Window window
)
554 ObAppSettings
*settings
;
556 ob_debug("Pretend-managing window: %lx", window
);
558 /* do this minimal stuff to figure out the client's decorations */
560 self
= g_new0(ObClient
, 1);
561 self
->window
= window
;
563 client_get_all(self
, FALSE
);
564 /* per-app settings override stuff, and return the settings for other
565 uses too. this returns a shallow copy that needs to be freed */
566 settings
= client_get_settings_state(self
);
568 client_setup_decor_and_functions(self
, FALSE
);
570 /* create the decoration frame for the client window and adjust its size */
571 self
->frame
= frame_new(self
);
572 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
574 ob_debug("gave extents left %d right %d top %d bottom %d",
575 self
->frame
->size
.left
, self
->frame
->size
.right
,
576 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
578 /* free the ObAppSettings shallow copy */
584 void client_unmanage_all(void)
586 while (client_list
!= NULL
)
587 client_unmanage(client_list
->data
);
590 void client_unmanage(ObClient
*self
)
596 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
597 self
->window
, self
->frame
->window
,
598 self
->class, self
->title
? self
->title
: "");
600 g_assert(self
!= NULL
);
602 /* we dont want events no more. do this before hiding the frame so we
603 don't generate more events */
604 XSelectInput(obt_display
, self
->window
, NoEventMask
);
606 /* ignore enter events from the unmap so it doesnt mess with the focus */
607 if (!config_focus_under_mouse
)
608 ignore_start
= event_start_ignore_all_enters();
610 frame_hide(self
->frame
);
611 /* flush to send the hide to the server quickly */
614 if (!config_focus_under_mouse
)
615 event_end_ignore_all_enters(ignore_start
);
617 mouse_grab_for_client(self
, FALSE
);
619 /* remove the window from our save set */
620 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
622 /* update the focus lists */
623 focus_order_remove(self
);
624 if (client_focused(self
)) {
625 /* don't leave an invalid focus_client */
629 client_list
= g_list_remove(client_list
, self
);
630 stacking_remove(self
);
631 window_remove(self
->window
);
633 /* once the client is out of the list, update the struts to remove its
635 if (STRUT_EXISTS(self
->strut
))
636 screen_update_areas();
638 client_call_notifies(self
, client_destroy_notifies
);
640 /* tell our parent(s) that we're gone */
641 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
642 ((ObClient
*)it
->data
)->transients
=
643 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
645 /* tell our transients that we're gone */
646 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
647 ((ObClient
*)it
->data
)->parents
=
648 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
649 /* we could be keeping our children in a higher layer */
650 client_calc_layer(it
->data
);
653 /* remove from its group */
655 group_remove(self
->group
, self
);
659 /* restore the window's original geometry so it is not lost */
665 if (self
->fullscreen
)
666 a
= self
->pre_fullscreen_area
;
667 else if (self
->max_horz
|| self
->max_vert
) {
668 if (self
->max_horz
) {
669 a
.x
= self
->pre_max_area
.x
;
670 a
.width
= self
->pre_max_area
.width
;
672 if (self
->max_vert
) {
673 a
.y
= self
->pre_max_area
.y
;
674 a
.height
= self
->pre_max_area
.height
;
678 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
679 /* let it be moved and resized no matter what */
680 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
681 self
->decorations
= 0; /* unmanaged windows have no decor */
683 /* give the client its border back */
684 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
686 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
689 /* reparent the window out of the frame, and free the frame */
690 frame_release_client(self
->frame
);
691 frame_free(self
->frame
);
694 if (ob_state() != OB_STATE_EXITING
) {
695 /* these values should not be persisted across a window
697 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
698 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
699 OBT_PROP_ERASE(self
->window
, WM_STATE
);
701 /* if we're left in an unmapped state, the client wont be mapped.
702 this is bad, since we will no longer be managing the window on
704 XMapWindow(obt_display
, self
->window
);
707 /* these should not be left on the window ever. other window managers
708 don't necessarily use them and it will mess them up (like compiz) */
709 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
710 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
712 /* update the list hints */
715 ob_debug("Unmanaged window 0x%lx", self
->window
);
717 /* free all data allocated in the client struct */
718 g_slist_free(self
->transients
);
719 for (j
= 0; j
< self
->nicons
; ++j
)
720 g_free(self
->icons
[j
].data
);
721 if (self
->nicons
> 0)
723 g_free(self
->startup_id
);
724 g_free(self
->wm_command
);
726 g_free(self
->icon_title
);
730 g_free(self
->client_machine
);
731 g_free(self
->sm_client_id
);
735 void client_fake_unmanage(ObClient
*self
)
737 /* this is all that got allocated to get the decorations */
739 frame_free(self
->frame
);
743 /*! Returns a new structure containing the per-app settings for this client.
744 The returned structure needs to be freed with g_free. */
745 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
747 ObAppSettings
*settings
;
750 settings
= config_create_app_settings();
752 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
753 ObAppSettings
*app
= it
->data
;
754 gboolean match
= TRUE
;
756 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
758 /* we know that either name or class is not NULL so it will have to
759 match to use the rule */
761 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
763 else if (app
->class &&
764 !g_pattern_match(app
->class,
765 strlen(self
->class), self
->class, NULL
))
767 else if (app
->role
&&
768 !g_pattern_match(app
->role
,
769 strlen(self
->role
), self
->role
, NULL
))
773 ob_debug("Window matching: %s", app
->name
);
775 /* copy the settings to our struct, overriding the existing
776 settings if they are not defaults */
777 config_app_settings_copy_non_defaults(app
, settings
);
781 if (settings
->shade
!= -1)
782 self
->shaded
= !!settings
->shade
;
783 if (settings
->decor
!= -1)
784 self
->undecorated
= !settings
->decor
;
785 if (settings
->iconic
!= -1)
786 self
->iconic
= !!settings
->iconic
;
787 if (settings
->skip_pager
!= -1)
788 self
->skip_pager
= !!settings
->skip_pager
;
789 if (settings
->skip_taskbar
!= -1)
790 self
->skip_taskbar
= !!settings
->skip_taskbar
;
792 if (settings
->max_vert
!= -1)
793 self
->max_vert
= !!settings
->max_vert
;
794 if (settings
->max_horz
!= -1)
795 self
->max_horz
= !!settings
->max_horz
;
797 if (settings
->fullscreen
!= -1)
798 self
->fullscreen
= !!settings
->fullscreen
;
800 if (settings
->desktop
) {
801 if (settings
->desktop
== DESKTOP_ALL
)
802 self
->desktop
= settings
->desktop
;
803 else if (settings
->desktop
> 0 &&
804 settings
->desktop
<= screen_num_desktops
)
805 self
->desktop
= settings
->desktop
- 1;
808 if (settings
->layer
== -1) {
812 else if (settings
->layer
== 0) {
816 else if (settings
->layer
== 1) {
823 static void client_restore_session_state(ObClient
*self
)
827 ob_debug_type(OB_DEBUG_SM
,
828 "Restore session for client %s", self
->title
);
830 if (!(it
= session_state_find(self
))) {
831 ob_debug_type(OB_DEBUG_SM
,
832 "Session data not found for client %s", self
->title
);
836 self
->session
= it
->data
;
838 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
841 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
842 self
->positioned
= USPosition
;
843 self
->sized
= USSize
;
844 if (self
->session
->w
> 0)
845 self
->area
.width
= self
->session
->w
;
846 if (self
->session
->h
> 0)
847 self
->area
.height
= self
->session
->h
;
848 XResizeWindow(obt_display
, self
->window
,
849 self
->area
.width
, self
->area
.height
);
851 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
852 self
->session
->desktop
:
853 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
854 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
856 self
->shaded
= self
->session
->shaded
;
857 self
->iconic
= self
->session
->iconic
;
858 self
->skip_pager
= self
->session
->skip_pager
;
859 self
->skip_taskbar
= self
->session
->skip_taskbar
;
860 self
->fullscreen
= self
->session
->fullscreen
;
861 self
->above
= self
->session
->above
;
862 self
->below
= self
->session
->below
;
863 self
->max_horz
= self
->session
->max_horz
;
864 self
->max_vert
= self
->session
->max_vert
;
865 self
->undecorated
= self
->session
->undecorated
;
868 static gboolean
client_restore_session_stacking(ObClient
*self
)
872 if (!self
->session
) return FALSE
;
874 mypos
= g_list_find(session_saved_state
, self
->session
);
875 if (!mypos
) return FALSE
;
877 /* start above me and look for the first client */
878 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
881 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
882 ObClient
*c
= cit
->data
;
883 /* found a client that was in the session, so go below it */
884 if (c
->session
== it
->data
) {
885 stacking_below(CLIENT_AS_WINDOW(self
),
886 CLIENT_AS_WINDOW(cit
->data
));
894 void client_move_onscreen(ObClient
*self
, gboolean rude
)
896 gint x
= self
->area
.x
;
897 gint y
= self
->area
.y
;
898 if (client_find_onscreen(self
, &x
, &y
,
900 self
->area
.height
, rude
)) {
901 client_move(self
, x
, y
);
905 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
908 gint ox
= *x
, oy
= *y
;
909 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
915 RECT_SET(desired
, *x
, *y
, w
, h
);
916 frame_rect_to_frame(self
->frame
, &desired
);
918 /* get where the frame would be */
919 frame_client_gravity(self
->frame
, x
, y
);
921 /* get the requested size of the window with decorations */
922 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
923 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
925 /* If rudeness wasn't requested, then still be rude in a given direction
926 if the client is not moving, only resizing in that direction */
928 Point oldtl
, oldtr
, oldbl
, oldbr
;
929 Point newtl
, newtr
, newbl
, newbr
;
930 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
932 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
933 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
934 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
935 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
936 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
938 POINT_SET(newtl
, *x
, *y
);
939 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
940 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
941 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
943 /* is it moving or just resizing from some corner? */
944 stationary_l
= oldtl
.x
== newtl
.x
;
945 stationary_r
= oldtr
.x
== newtr
.x
;
946 stationary_t
= oldtl
.y
== newtl
.y
;
947 stationary_b
= oldbl
.y
== newbl
.y
;
949 /* if left edge is growing and didnt move right edge */
950 if (stationary_r
&& newtl
.x
< oldtl
.x
)
952 /* if right edge is growing and didnt move left edge */
953 if (stationary_l
&& newtr
.x
> oldtr
.x
)
955 /* if top edge is growing and didnt move bottom edge */
956 if (stationary_b
&& newtl
.y
< oldtl
.y
)
958 /* if bottom edge is growing and didnt move top edge */
959 if (stationary_t
&& newbl
.y
> oldbl
.y
)
963 /* we iterate through every monitor that the window is at least partially
964 on, to make sure it is obeying the rules on them all
966 if the window does not appear on any monitors, then use the first one
969 for (i
= 0; i
< screen_num_monitors
; ++i
) {
972 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
973 if (i
< screen_num_monitors
- 1 || found_mon
)
976 /* the window is not inside any monitor! so just use the first
978 a
= screen_area(self
->desktop
, 0, NULL
);
981 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
984 /* This makes sure windows aren't entirely outside of the screen so you
985 can't see them at all.
986 It makes sure 10% of the window is on the screen at least. At don't
987 let it move itself off the top of the screen, which would hide the
988 titlebar on you. (The user can still do this if they want too, it's
989 only limiting the application.
991 if (client_normal(self
)) {
992 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
993 *x
= a
->x
+ a
->width
- fw
/10;
994 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
995 *y
= a
->y
+ a
->height
- fh
/10;
996 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
998 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1002 /* This here doesn't let windows even a pixel outside the
1003 struts/screen. When called from client_manage, programs placing
1004 themselves are forced completely onscreen, while things like
1005 xterm -geometry resolution-width/2 will work fine. Trying to
1006 place it completely offscreen will be handled in the above code.
1007 Sorry for this confused comment, i am tired. */
1008 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1009 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1010 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1012 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1013 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1014 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1019 /* get where the client should be */
1020 frame_frame_gravity(self
->frame
, x
, y
);
1022 return ox
!= *x
|| oy
!= *y
;
1025 static void client_get_all(ObClient
*self
, gboolean real
)
1027 /* this is needed for the frame to set itself up */
1028 client_get_area(self
);
1030 /* these things can change the decor and functions of the window */
1032 client_get_mwm_hints(self
);
1033 /* this can change the mwmhints for special cases */
1034 client_get_type_and_transientness(self
);
1035 client_get_state(self
);
1036 client_update_normal_hints(self
);
1038 /* get the session related properties, these can change decorations
1039 from per-app settings */
1040 client_get_session_ids(self
);
1042 /* now we got everything that can affect the decorations */
1046 /* get this early so we have it for debugging */
1047 client_update_title(self
);
1049 client_update_protocols(self
);
1051 client_update_wmhints(self
);
1052 /* this may have already been called from client_update_wmhints */
1053 if (!self
->parents
&& !self
->transient_for_group
)
1054 client_update_transient_for(self
);
1056 client_get_startup_id(self
);
1057 client_get_desktop(self
);/* uses transient data/group/startup id if a
1058 desktop is not specified */
1059 client_get_shaped(self
);
1062 /* a couple type-based defaults for new windows */
1064 /* this makes sure that these windows appear on all desktops */
1065 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1066 self
->desktop
= DESKTOP_ALL
;
1070 client_update_sync_request_counter(self
);
1073 client_get_colormap(self
);
1074 client_update_strut(self
);
1075 client_update_icons(self
);
1076 client_update_icon_geometry(self
);
1079 static void client_get_startup_id(ObClient
*self
)
1081 if (!(OBT_PROP_GETS(self
->window
, NET_STARTUP_ID
, utf8
,
1082 &self
->startup_id
)))
1084 OBT_PROP_GETS(self
->group
->leader
,
1085 NET_STARTUP_ID
, utf8
, &self
->startup_id
);
1088 static void client_get_area(ObClient
*self
)
1090 XWindowAttributes wattrib
;
1093 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1094 g_assert(ret
!= BadWindow
);
1096 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1097 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1098 self
->border_width
= wattrib
.border_width
;
1100 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1101 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1104 static void client_get_desktop(ObClient
*self
)
1106 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1108 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1109 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1110 self
->desktop
= screen_num_desktops
- 1;
1113 ob_debug("client requested desktop 0x%x", self
->desktop
);
1116 gboolean first
= TRUE
;
1117 guint all
= screen_num_desktops
; /* not a valid value */
1119 /* if they are all on one desktop, then open it on the
1121 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1122 ObClient
*c
= it
->data
;
1124 if (c
->desktop
== DESKTOP_ALL
) continue;
1130 else if (all
!= c
->desktop
)
1131 all
= screen_num_desktops
; /* make it invalid */
1133 if (all
!= screen_num_desktops
) {
1134 self
->desktop
= all
;
1136 ob_debug("client desktop set from parents: 0x%x",
1139 /* try get from the startup-notification protocol */
1140 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1141 if (self
->desktop
>= screen_num_desktops
&&
1142 self
->desktop
!= DESKTOP_ALL
)
1143 self
->desktop
= screen_num_desktops
- 1;
1144 ob_debug("client desktop set from startup-notification: 0x%x",
1147 /* defaults to the current desktop */
1149 self
->desktop
= screen_desktop
;
1150 ob_debug("client desktop set to the current desktop: %d",
1156 static void client_get_state(ObClient
*self
)
1161 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1163 for (i
= 0; i
< num
; ++i
) {
1164 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1166 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1167 self
->shaded
= TRUE
;
1168 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1169 self
->iconic
= TRUE
;
1170 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1171 self
->skip_taskbar
= TRUE
;
1172 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1173 self
->skip_pager
= TRUE
;
1174 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1175 self
->fullscreen
= TRUE
;
1176 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1177 self
->max_vert
= TRUE
;
1178 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1179 self
->max_horz
= TRUE
;
1180 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1182 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1184 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1185 self
->demands_attention
= TRUE
;
1186 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1187 self
->undecorated
= TRUE
;
1194 static void client_get_shaped(ObClient
*self
)
1196 self
->shaped
= FALSE
;
1198 if (obt_display_extension_shape
) {
1203 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1205 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1206 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1208 self
->shaped
= (s
!= 0);
1213 void client_update_transient_for(ObClient
*self
)
1216 ObClient
*target
= NULL
;
1217 gboolean trangroup
= FALSE
;
1219 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1220 if (t
!= self
->window
) { /* cant be transient to itself! */
1221 ObWindow
*tw
= window_find(t
);
1222 /* if this happens then we need to check for it*/
1223 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1224 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1225 /* watch out for windows with a parent that is something
1226 different, like a dockapp for example */
1227 target
= WINDOW_AS_CLIENT(tw
);
1231 /* Setting the transient_for to Root is actually illegal, however
1232 applications from time have done this to specify transient for
1234 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1236 } else if (self
->group
&& self
->transient
)
1239 client_update_transient_tree(self
, self
->group
, self
->group
,
1240 self
->transient_for_group
, trangroup
,
1241 client_direct_parent(self
), target
);
1242 self
->transient_for_group
= trangroup
;
1246 static void client_update_transient_tree(ObClient
*self
,
1247 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1248 gboolean oldgtran
, gboolean newgtran
,
1249 ObClient
* oldparent
,
1250 ObClient
*newparent
)
1255 g_assert(!oldgtran
|| oldgroup
);
1256 g_assert(!newgtran
|| newgroup
);
1257 g_assert((!oldgtran
&& !oldparent
) ||
1258 (oldgtran
&& !oldparent
) ||
1259 (!oldgtran
&& oldparent
));
1260 g_assert((!newgtran
&& !newparent
) ||
1261 (newgtran
&& !newparent
) ||
1262 (!newgtran
&& newparent
));
1265 Group transient windows are not allowed to have other group
1266 transient windows as their children.
1270 /* No change has occured */
1271 if (oldgroup
== newgroup
&&
1272 oldgtran
== newgtran
&&
1273 oldparent
== newparent
) return;
1275 /** Remove the client from the transient tree **/
1277 for (it
= self
->transients
; it
; it
= next
) {
1278 next
= g_slist_next(it
);
1280 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1281 c
->parents
= g_slist_remove(c
->parents
, self
);
1283 for (it
= self
->parents
; it
; it
= next
) {
1284 next
= g_slist_next(it
);
1286 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1287 c
->transients
= g_slist_remove(c
->transients
, self
);
1290 /** Re-add the client to the transient tree **/
1292 /* If we're transient for a group then we need to add ourselves to all our
1295 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1298 !client_search_top_direct_parent(c
)->transient_for_group
&&
1301 c
->transients
= g_slist_prepend(c
->transients
, self
);
1302 self
->parents
= g_slist_prepend(self
->parents
, c
);
1307 /* If we are now transient for a single window we need to add ourselves to
1310 WARNING: Cyclical transient ness is possible if two windows are
1311 transient for eachother.
1313 else if (newparent
&&
1314 /* don't make ourself its child if it is already our child */
1315 !client_is_direct_child(self
, newparent
) &&
1316 client_normal(newparent
))
1318 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1319 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1322 /* Add any group transient windows to our children. But if we're transient
1323 for the group, then other group transients are not our children.
1325 WARNING: Cyclical transient-ness is possible. For e.g. if:
1326 A is transient for the group
1327 B is transient for A
1328 C is transient for B
1329 A can't be transient for C or we have a cycle
1331 if (!newgtran
&& newgroup
&&
1333 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1334 client_normal(self
))
1336 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1338 if (c
!= self
&& c
->transient_for_group
&&
1339 /* Don't make it our child if it is already our parent */
1340 !client_is_direct_child(c
, self
))
1342 self
->transients
= g_slist_prepend(self
->transients
, c
);
1343 c
->parents
= g_slist_prepend(c
->parents
, self
);
1348 /** If we change our group transient-ness, our children change their
1349 effect group transient-ness, which affects how they relate to other
1352 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1354 if (!c
->transient_for_group
)
1355 client_update_transient_tree(c
, c
->group
, c
->group
,
1356 c
->transient_for_group
,
1357 c
->transient_for_group
,
1358 client_direct_parent(c
),
1359 client_direct_parent(c
));
1363 static void client_get_mwm_hints(ObClient
*self
)
1368 self
->mwmhints
.flags
= 0; /* default to none */
1370 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1372 if (num
>= OB_MWM_ELEMENTS
) {
1373 self
->mwmhints
.flags
= hints
[0];
1374 self
->mwmhints
.functions
= hints
[1];
1375 self
->mwmhints
.decorations
= hints
[2];
1381 void client_get_type_and_transientness(ObClient
*self
)
1388 self
->transient
= FALSE
;
1390 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1391 /* use the first value that we know about in the array */
1392 for (i
= 0; i
< num
; ++i
) {
1393 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1394 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1395 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1396 self
->type
= OB_CLIENT_TYPE_DOCK
;
1397 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1398 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1399 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1400 self
->type
= OB_CLIENT_TYPE_MENU
;
1401 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1402 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1403 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1404 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1405 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1406 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1407 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1408 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1409 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1411 /* prevent this window from getting any decor or
1413 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1414 OB_MWM_FLAG_DECORATIONS
);
1415 self
->mwmhints
.decorations
= 0;
1416 self
->mwmhints
.functions
= 0;
1418 if (self
->type
!= (ObClientType
) -1)
1419 break; /* grab the first legit type */
1424 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1425 self
->transient
= TRUE
;
1427 if (self
->type
== (ObClientType
) -1) {
1428 /*the window type hint was not set, which means we either classify
1429 ourself as a normal window or a dialog, depending on if we are a
1431 if (self
->transient
)
1432 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1434 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1437 /* then, based on our type, we can update our transientness.. */
1438 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1439 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1440 self
->type
== OB_CLIENT_TYPE_MENU
||
1441 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1443 self
->transient
= TRUE
;
1447 void client_update_protocols(ObClient
*self
)
1452 self
->focus_notify
= FALSE
;
1453 self
->delete_window
= FALSE
;
1455 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1456 for (i
= 0; i
< num_ret
; ++i
) {
1457 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1458 /* this means we can request the window to close */
1459 self
->delete_window
= TRUE
;
1460 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1461 /* if this protocol is requested, then the window will be
1462 notified whenever we want it to receive focus */
1463 self
->focus_notify
= TRUE
;
1464 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1465 /* if this protocol is requested, then the window will allow
1466 pings to determine if it is still alive */
1469 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1470 /* if this protocol is requested, then resizing the
1471 window will be synchronized between the frame and the
1473 self
->sync_request
= TRUE
;
1481 void client_update_sync_request_counter(ObClient
*self
)
1485 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1487 self
->sync_counter
= i
;
1489 self
->sync_counter
= None
;
1493 static void client_get_colormap(ObClient
*self
)
1495 XWindowAttributes wa
;
1497 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1498 client_update_colormap(self
, wa
.colormap
);
1501 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1503 if (colormap
== self
->colormap
) return;
1505 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1507 if (client_focused(self
)) {
1508 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1509 self
->colormap
= colormap
;
1510 screen_install_colormap(self
, FALSE
); /* install new one */
1512 self
->colormap
= colormap
;
1515 void client_update_normal_hints(ObClient
*self
)
1521 self
->min_ratio
= 0.0f
;
1522 self
->max_ratio
= 0.0f
;
1523 SIZE_SET(self
->size_inc
, 1, 1);
1524 SIZE_SET(self
->base_size
, 0, 0);
1525 SIZE_SET(self
->min_size
, 0, 0);
1526 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1528 /* get the hints from the window */
1529 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1530 /* normal windows can't request placement! har har
1531 if (!client_normal(self))
1533 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1534 self
->sized
= (size
.flags
& (PSize
|USSize
));
1536 if (size
.flags
& PWinGravity
)
1537 self
->gravity
= size
.win_gravity
;
1539 if (size
.flags
& PAspect
) {
1540 if (size
.min_aspect
.y
)
1542 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1543 if (size
.max_aspect
.y
)
1545 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1548 if (size
.flags
& PMinSize
)
1549 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1551 if (size
.flags
& PMaxSize
)
1552 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1554 if (size
.flags
& PBaseSize
)
1555 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1557 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1558 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1560 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1561 self
->min_size
.width
, self
->min_size
.height
,
1562 self
->max_size
.width
, self
->max_size
.height
);
1563 ob_debug("size inc (%d %d) base size (%d %d)",
1564 self
->size_inc
.width
, self
->size_inc
.height
,
1565 self
->base_size
.width
, self
->base_size
.height
);
1568 ob_debug("Normal hints: not set");
1571 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1573 /* start with everything (cept fullscreen) */
1575 (OB_FRAME_DECOR_TITLEBAR
|
1576 OB_FRAME_DECOR_HANDLE
|
1577 OB_FRAME_DECOR_GRIPS
|
1578 OB_FRAME_DECOR_BORDER
|
1579 OB_FRAME_DECOR_ICON
|
1580 OB_FRAME_DECOR_ALLDESKTOPS
|
1581 OB_FRAME_DECOR_ICONIFY
|
1582 OB_FRAME_DECOR_MAXIMIZE
|
1583 OB_FRAME_DECOR_SHADE
|
1584 OB_FRAME_DECOR_CLOSE
);
1586 (OB_CLIENT_FUNC_RESIZE
|
1587 OB_CLIENT_FUNC_MOVE
|
1588 OB_CLIENT_FUNC_ICONIFY
|
1589 OB_CLIENT_FUNC_MAXIMIZE
|
1590 OB_CLIENT_FUNC_SHADE
|
1591 OB_CLIENT_FUNC_CLOSE
|
1592 OB_CLIENT_FUNC_BELOW
|
1593 OB_CLIENT_FUNC_ABOVE
|
1594 OB_CLIENT_FUNC_UNDECORATE
);
1596 if (!(self
->min_size
.width
< self
->max_size
.width
||
1597 self
->min_size
.height
< self
->max_size
.height
))
1598 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1600 switch (self
->type
) {
1601 case OB_CLIENT_TYPE_NORMAL
:
1602 /* normal windows retain all of the possible decorations and
1603 functionality, and can be fullscreen */
1604 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1607 case OB_CLIENT_TYPE_DIALOG
:
1608 /* sometimes apps make dialog windows fullscreen for some reason (for
1609 e.g. kpdf does this..) */
1610 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1613 case OB_CLIENT_TYPE_UTILITY
:
1614 /* these windows don't have anything added or removed by default */
1617 case OB_CLIENT_TYPE_MENU
:
1618 case OB_CLIENT_TYPE_TOOLBAR
:
1619 /* these windows can't iconify or maximize */
1620 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1621 OB_FRAME_DECOR_MAXIMIZE
);
1622 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1623 OB_CLIENT_FUNC_MAXIMIZE
);
1626 case OB_CLIENT_TYPE_SPLASH
:
1627 /* these don't get get any decorations, and the only thing you can
1628 do with them is move them */
1629 self
->decorations
= 0;
1630 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1633 case OB_CLIENT_TYPE_DESKTOP
:
1634 /* these windows are not manipulated by the window manager */
1635 self
->decorations
= 0;
1636 self
->functions
= 0;
1639 case OB_CLIENT_TYPE_DOCK
:
1640 /* these windows are not manipulated by the window manager, but they
1641 can set below layer which has a special meaning */
1642 self
->decorations
= 0;
1643 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1647 /* Mwm Hints are applied subtractively to what has already been chosen for
1648 decor and functionality */
1649 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1650 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1651 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1652 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1654 /* if the mwm hints request no handle or title, then all
1655 decorations are disabled, but keep the border if that's
1657 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1658 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1660 self
->decorations
= 0;
1665 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1666 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1667 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1668 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1669 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1670 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1671 /* dont let mwm hints kill any buttons
1672 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1673 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1674 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1675 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1677 /* dont let mwm hints kill the close button
1678 if (! (self->mwmhints.functions & MwmFunc_Close))
1679 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1683 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1684 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1685 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1686 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1687 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1688 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1690 /* can't maximize without moving/resizing */
1691 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1692 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1693 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1694 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1695 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1698 if (self
->max_horz
&& self
->max_vert
) {
1699 /* you can't resize fully maximized windows */
1700 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1701 /* kill the handle on fully maxed windows */
1702 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1705 /* If there are no decorations to remove, don't allow the user to try
1707 if (self
->decorations
== 0)
1708 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1710 /* finally, the user can have requested no decorations, which overrides
1711 everything (but doesnt give it a border if it doesnt have one) */
1712 if (self
->undecorated
)
1713 self
->decorations
= 0;
1715 /* if we don't have a titlebar, then we cannot shade! */
1716 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1717 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1719 /* now we need to check against rules for the client's current state */
1720 if (self
->fullscreen
) {
1721 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1722 OB_CLIENT_FUNC_FULLSCREEN
|
1723 OB_CLIENT_FUNC_ICONIFY
);
1724 self
->decorations
= 0;
1727 client_change_allowed_actions(self
);
1730 /* force reconfigure to make sure decorations are updated */
1731 client_reconfigure(self
, TRUE
);
1734 static void client_change_allowed_actions(ObClient
*self
)
1739 /* desktop windows are kept on all desktops */
1740 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1741 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1743 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1744 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1745 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1746 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1747 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1748 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1749 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1750 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1751 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1752 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1753 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1754 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1755 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1756 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1757 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1759 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1760 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1761 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1762 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1763 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1764 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1766 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1768 /* make sure the window isn't breaking any rules now
1770 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1771 it can't be iconified with its parent
1774 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1775 if (self
->frame
) client_shade(self
, FALSE
);
1776 else self
->shaded
= FALSE
;
1778 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1779 if (self
->frame
) client_fullscreen(self
, FALSE
);
1780 else self
->fullscreen
= FALSE
;
1782 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1784 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1785 else self
->max_vert
= self
->max_horz
= FALSE
;
1789 void client_update_wmhints(ObClient
*self
)
1793 /* assume a window takes input if it doesnt specify */
1794 self
->can_focus
= TRUE
;
1796 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1799 if (hints
->flags
& InputHint
)
1800 self
->can_focus
= hints
->input
;
1802 /* only do this when first managing the window *AND* when we aren't
1804 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1805 if (hints
->flags
& StateHint
)
1806 self
->iconic
= hints
->initial_state
== IconicState
;
1809 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1810 if (self
->urgent
&& !ur
)
1811 client_hilite(self
, TRUE
);
1812 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1813 client_hilite(self
, FALSE
);
1815 if (!(hints
->flags
& WindowGroupHint
))
1816 hints
->window_group
= None
;
1818 /* did the group state change? */
1819 if (hints
->window_group
!=
1820 (self
->group
? self
->group
->leader
: None
))
1822 ObGroup
*oldgroup
= self
->group
;
1824 /* remove from the old group if there was one */
1825 if (self
->group
!= NULL
) {
1826 group_remove(self
->group
, self
);
1830 /* add ourself to the group if we have one */
1831 if (hints
->window_group
!= None
) {
1832 self
->group
= group_add(hints
->window_group
, self
);
1835 /* Put ourselves into the new group's transient tree, and remove
1836 ourselves from the old group's */
1837 client_update_transient_tree(self
, oldgroup
, self
->group
,
1838 self
->transient_for_group
,
1839 self
->transient_for_group
,
1840 client_direct_parent(self
),
1841 client_direct_parent(self
));
1843 /* Lastly, being in a group, or not, can change if the window is
1844 transient for anything.
1846 The logic for this is:
1847 self->transient = TRUE always if the window wants to be
1848 transient for something, even if transient_for was NULL because
1849 it wasn't in a group before.
1851 If parents was NULL and oldgroup was NULL we can assume
1852 that when we add the new group, it will become transient for
1855 If transient_for_group is TRUE, then it must have already
1856 had a group. If it is getting a new group, the above call to
1857 client_update_transient_tree has already taken care of
1858 everything ! If it is losing all group status then it will
1859 no longer be transient for anything and that needs to be
1862 if (self
->transient
&&
1863 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1864 (self
->transient_for_group
&& !self
->group
)))
1865 client_update_transient_for(self
);
1868 /* the WM_HINTS can contain an icon */
1869 if (hints
->flags
& IconPixmapHint
)
1870 client_update_icons(self
);
1876 void client_update_title(ObClient
*self
)
1879 gchar
*visible
= NULL
;
1881 g_free(self
->title
);
1884 if (!OBT_PROP_GETS(self
->window
, NET_WM_NAME
, utf8
, &data
)) {
1885 /* try old x stuff */
1886 if (!(OBT_PROP_GETS(self
->window
, WM_NAME
, locale
, &data
)
1887 || OBT_PROP_GETS(self
->window
, WM_NAME
, utf8
, &data
))) {
1888 if (self
->transient
) {
1890 GNOME alert windows are not given titles:
1891 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1893 data
= g_strdup("");
1895 data
= g_strdup("Unnamed Window");
1899 if (self
->client_machine
) {
1900 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1905 if (self
->not_responding
) {
1907 if (self
->close_tried_term
)
1908 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1910 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1914 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, utf8
, visible
);
1915 self
->title
= visible
;
1918 frame_adjust_title(self
->frame
);
1920 /* update the icon title */
1922 g_free(self
->icon_title
);
1925 if (!OBT_PROP_GETS(self
->window
, NET_WM_ICON_NAME
, utf8
, &data
))
1926 /* try old x stuff */
1927 if (!(OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, locale
, &data
) ||
1928 OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, utf8
, &data
)))
1929 data
= g_strdup(self
->title
);
1931 if (self
->client_machine
) {
1932 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1937 if (self
->not_responding
) {
1939 if (self
->close_tried_term
)
1940 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1942 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1946 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, utf8
, visible
);
1947 self
->icon_title
= visible
;
1950 void client_update_strut(ObClient
*self
)
1954 gboolean got
= FALSE
;
1957 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
1962 STRUT_PARTIAL_SET(strut
,
1963 data
[0], data
[2], data
[1], data
[3],
1964 data
[4], data
[5], data
[8], data
[9],
1965 data
[6], data
[7], data
[10], data
[11]);
1971 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
1977 /* use the screen's width/height */
1978 a
= screen_physical_area_all_monitors();
1980 STRUT_PARTIAL_SET(strut
,
1981 data
[0], data
[2], data
[1], data
[3],
1982 a
->y
, a
->y
+ a
->height
- 1,
1983 a
->x
, a
->x
+ a
->width
- 1,
1984 a
->y
, a
->y
+ a
->height
- 1,
1985 a
->x
, a
->x
+ a
->width
- 1);
1992 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1993 0, 0, 0, 0, 0, 0, 0, 0);
1995 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1996 self
->strut
= strut
;
1998 /* updating here is pointless while we're being mapped cuz we're not in
1999 the client list yet */
2001 screen_update_areas();
2005 /* Avoid storing icons above this size if possible */
2006 #define AVOID_ABOVE 64
2008 void client_update_icons(ObClient
*self
)
2013 guint num_seen
; /* number of icons present */
2014 guint num_small_seen
; /* number of icons small enough present */
2015 guint smallest
, smallest_area
;
2017 for (i
= 0; i
< self
->nicons
; ++i
)
2018 g_free(self
->icons
[i
].data
);
2019 if (self
->nicons
> 0)
2020 g_free(self
->icons
);
2023 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2024 /* figure out how many valid icons are in here */
2026 num_seen
= num_small_seen
= 0;
2027 smallest
= smallest_area
= 0;
2033 /* watch for it being too small for the specified size, or for
2034 zero sized icons. */
2035 if (i
> num
|| w
== 0 || h
== 0) break;
2037 if (!smallest_area
|| w
*h
< smallest_area
) {
2038 smallest
= num_seen
;
2039 smallest_area
= w
*h
;
2042 if (w
<= AVOID_ABOVE
&& h
<= AVOID_ABOVE
)
2045 if (num_small_seen
> 0)
2046 self
->nicons
= num_small_seen
;
2050 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2052 /* store the icons */
2054 for (j
= 0; j
< self
->nicons
;) {
2057 w
= self
->icons
[j
].width
= data
[i
++];
2058 h
= self
->icons
[j
].height
= data
[i
++];
2060 /* if there are some icons smaller than the threshold, we're
2061 skipping all the ones above */
2062 if (num_small_seen
> 0) {
2063 if (w
> AVOID_ABOVE
|| h
> AVOID_ABOVE
) {
2068 /* if there were no icons smaller than the threshold, then we are
2069 only taking the smallest available one we saw */
2070 else if (j
!= smallest
) {
2075 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2076 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2081 self
->icons
[j
].data
[t
] =
2082 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2083 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2084 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2085 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2096 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2097 if (hints
->flags
& IconPixmapHint
) {
2099 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2100 obt_display_ignore_errors(TRUE
);
2101 if (!RrPixmapToRGBA(ob_rr_inst
,
2103 (hints
->flags
& IconMaskHint
?
2104 hints
->icon_mask
: None
),
2105 &self
->icons
[0].width
,
2106 &self
->icons
[0].height
,
2107 &self
->icons
[0].data
))
2109 g_free(self
->icons
);
2112 obt_display_ignore_errors(FALSE
);
2118 /* set the default icon onto the window
2119 in theory, this could be a race, but if a window doesn't set an icon
2120 or removes it entirely, it's not very likely it is going to set one
2121 right away afterwards
2123 if it has parents, then one of them will have an icon already
2125 if (self
->nicons
== 0 && !self
->parents
) {
2126 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2129 data
= g_new(gulong
, 48*48+2);
2130 data
[0] = data
[1] = 48;
2131 for (i
= 0; i
< 48*48; ++i
)
2132 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2133 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2134 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2135 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2136 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, data
, 48*48+2);
2138 } else if (self
->frame
)
2139 /* don't draw the icon empty if we're just setting one now anyways,
2140 we'll get the property change any second */
2141 frame_adjust_icon(self
->frame
);
2144 void client_update_icon_geometry(ObClient
*self
)
2149 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2151 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2155 /* don't let them set it with an area < 0 */
2156 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2157 MAX(data
[2],0), MAX(data
[3],0));
2162 static void client_get_session_ids(ObClient
*self
)
2169 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2172 /* get the SM_CLIENT_ID */
2175 got
= OBT_PROP_GETS(leader
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2177 OBT_PROP_GETS(self
->window
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2179 /* get the WM_CLASS (name and class). make them "" if they are not
2183 got
= OBT_PROP_GETSS(leader
, WM_CLASS
, locale
, &ss
);
2185 got
= OBT_PROP_GETSS(self
->window
, WM_CLASS
, locale
, &ss
);
2189 self
->name
= g_strdup(ss
[0]);
2191 self
->class = g_strdup(ss
[1]);
2196 if (self
->name
== NULL
) self
->name
= g_strdup("");
2197 if (self
->class == NULL
) self
->class = g_strdup("");
2199 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2202 got
= OBT_PROP_GETS(leader
, WM_WINDOW_ROLE
, locale
, &s
);
2204 got
= OBT_PROP_GETS(self
->window
, WM_WINDOW_ROLE
, locale
, &s
);
2209 self
->role
= g_strdup("");
2211 /* get the WM_COMMAND */
2215 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, locale
, &ss
);
2217 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, locale
, &ss
);
2220 /* merge/mash them all together */
2221 gchar
*merge
= NULL
;
2224 for (i
= 0; ss
[i
]; ++i
) {
2227 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2229 merge
= g_strconcat(ss
[i
], NULL
);
2234 self
->wm_command
= merge
;
2237 /* get the WM_CLIENT_MACHINE */
2240 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, locale
, &s
);
2242 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, locale
, &s
);
2245 gchar localhost
[128];
2248 gethostname(localhost
, 127);
2249 localhost
[127] = '\0';
2250 if (strcmp(localhost
, s
) != 0)
2251 self
->client_machine
= s
;
2255 /* see if it has the PID set too (the PID requires that the
2256 WM_CLIENT_MACHINE be set) */
2257 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2262 static void client_change_wm_state(ObClient
*self
)
2267 old
= self
->wmstate
;
2269 if (self
->shaded
|| self
->iconic
||
2270 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2272 self
->wmstate
= IconicState
;
2274 self
->wmstate
= NormalState
;
2276 if (old
!= self
->wmstate
) {
2277 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2278 self
->wmstate
, 1, 0, 0, 0);
2280 state
[0] = self
->wmstate
;
2282 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2286 static void client_change_state(ObClient
*self
)
2288 gulong netstate
[12];
2293 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2295 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2297 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2298 if (self
->skip_taskbar
)
2299 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2300 if (self
->skip_pager
)
2301 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2302 if (self
->fullscreen
)
2303 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2305 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2307 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2309 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2311 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2312 if (self
->demands_attention
)
2313 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2314 if (self
->undecorated
)
2315 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2316 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2319 frame_adjust_state(self
->frame
);
2322 ObClient
*client_search_focus_tree(ObClient
*self
)
2327 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2328 if (client_focused(it
->data
)) return it
->data
;
2329 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2334 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2336 if (self
->parents
) {
2339 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2340 ObClient
*c
= it
->data
;
2341 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2347 /* this function checks the whole tree, the client_search_focus_tree
2348 does not, so we need to check this window */
2349 if (client_focused(self
))
2351 return client_search_focus_tree(self
);
2355 ObClient
*client_search_focus_group_full(ObClient
*self
)
2360 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2361 ObClient
*c
= it
->data
;
2363 if (client_focused(c
)) return c
;
2364 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2367 if (client_focused(self
)) return self
;
2371 gboolean
client_has_parent(ObClient
*self
)
2373 return self
->parents
!= NULL
;
2376 static ObStackingLayer
calc_layer(ObClient
*self
)
2381 monitor
= screen_physical_area_monitor(client_monitor(self
));
2383 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2384 l
= OB_STACKING_LAYER_DESKTOP
;
2385 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2386 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2387 else l
= OB_STACKING_LAYER_ABOVE
;
2389 else if ((self
->fullscreen
||
2390 /* No decorations and fills the monitor = oldskool fullscreen.
2391 But not for maximized windows.
2393 (self
->decorations
== 0 &&
2394 !(self
->max_horz
&& self
->max_vert
) &&
2395 RECT_EQUAL(self
->area
, *monitor
))) &&
2396 /* you are fullscreen while you or your children are focused.. */
2397 (client_focused(self
) || client_search_focus_tree(self
) ||
2398 /* you can be fullscreen if you're on another desktop */
2399 (self
->desktop
!= screen_desktop
&&
2400 self
->desktop
!= DESKTOP_ALL
) ||
2401 /* and you can also be fullscreen if the focused client is on
2402 another monitor, or nothing else is focused */
2404 client_monitor(focus_client
) != client_monitor(self
))))
2405 l
= OB_STACKING_LAYER_FULLSCREEN
;
2406 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2407 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2408 else l
= OB_STACKING_LAYER_NORMAL
;
2415 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2416 ObStackingLayer min
)
2418 ObStackingLayer old
, own
;
2422 own
= calc_layer(self
);
2423 self
->layer
= MAX(own
, min
);
2425 if (self
->layer
!= old
) {
2426 stacking_remove(CLIENT_AS_WINDOW(self
));
2427 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2430 /* we've been restacked */
2431 self
->visited
= TRUE
;
2433 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2434 client_calc_layer_recursive(it
->data
, orig
,
2438 static void client_calc_layer_internal(ObClient
*self
)
2442 /* transients take on the layer of their parents */
2443 sit
= client_search_all_top_parents(self
);
2445 for (; sit
; sit
= g_slist_next(sit
))
2446 client_calc_layer_recursive(sit
->data
, self
, 0);
2449 void client_calc_layer(ObClient
*self
)
2453 /* skip over stuff above fullscreen layer */
2454 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2455 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2457 /* find the windows in the fullscreen layer, and mark them not-visited */
2458 for (; it
; it
= g_list_next(it
)) {
2459 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2460 else if (WINDOW_IS_CLIENT(it
->data
))
2461 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2464 client_calc_layer_internal(self
);
2466 /* skip over stuff above fullscreen layer */
2467 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2468 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2470 /* now recalc any windows in the fullscreen layer which have not
2471 had their layer recalced already */
2472 for (; it
; it
= g_list_next(it
)) {
2473 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2474 else if (WINDOW_IS_CLIENT(it
->data
) &&
2475 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2476 client_calc_layer_internal(it
->data
);
2480 gboolean
client_should_show(ObClient
*self
)
2484 if (client_normal(self
) && screen_showing_desktop
)
2486 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2492 gboolean
client_show(ObClient
*self
)
2494 gboolean show
= FALSE
;
2496 if (client_should_show(self
)) {
2497 frame_show(self
->frame
);
2500 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2501 it needs to be in IconicState. This includes when it is on another
2504 client_change_wm_state(self
);
2509 gboolean
client_hide(ObClient
*self
)
2511 gboolean hide
= FALSE
;
2513 if (!client_should_show(self
)) {
2514 if (self
== focus_client
) {
2515 /* if there is a grab going on, then we need to cancel it. if we
2516 move focus during the grab, applications will get
2517 NotifyWhileGrabbed events and ignore them !
2519 actions should not rely on being able to move focus during an
2522 event_cancel_all_key_grabs();
2525 /* We don't need to ignore enter events here.
2526 The window can hide/iconify in 3 different ways:
2527 1 - through an x message. in this case we ignore all enter events
2528 caused by responding to the x message (unless underMouse)
2529 2 - by a keyboard action. in this case we ignore all enter events
2530 caused by the action
2531 3 - by a mouse action. in this case they are doing stuff with the
2532 mouse and focus _should_ move.
2534 Also in action_end, we simulate an enter event that can't be ignored
2535 so trying to ignore them is futile in case 3 anyways
2538 frame_hide(self
->frame
);
2541 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2542 it needs to be in IconicState. This includes when it is on another
2545 client_change_wm_state(self
);
2550 void client_showhide(ObClient
*self
)
2552 if (!client_show(self
))
2556 gboolean
client_normal(ObClient
*self
) {
2557 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2558 self
->type
== OB_CLIENT_TYPE_DOCK
||
2559 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2562 gboolean
client_helper(ObClient
*self
)
2564 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2565 self
->type
== OB_CLIENT_TYPE_MENU
||
2566 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2569 gboolean
client_mouse_focusable(ObClient
*self
)
2571 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2572 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2573 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2574 self
->type
== OB_CLIENT_TYPE_DOCK
);
2577 gboolean
client_enter_focusable(ObClient
*self
)
2579 /* you can focus desktops but it shouldn't on enter */
2580 return (client_mouse_focusable(self
) &&
2581 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2585 static void client_apply_startup_state(ObClient
*self
,
2586 gint x
, gint y
, gint w
, gint h
)
2588 /* save the states that we are going to apply */
2589 gboolean iconic
= self
->iconic
;
2590 gboolean fullscreen
= self
->fullscreen
;
2591 gboolean undecorated
= self
->undecorated
;
2592 gboolean shaded
= self
->shaded
;
2593 gboolean demands_attention
= self
->demands_attention
;
2594 gboolean max_horz
= self
->max_horz
;
2595 gboolean max_vert
= self
->max_vert
;
2599 /* turn them all off in the client, so they won't affect the window
2601 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2602 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2604 /* move the client to its placed position, or it it's already there,
2605 generate a ConfigureNotify telling the client where it is.
2607 do this after adjusting the frame. otherwise it gets all weird and
2608 clients don't work right
2610 do this before applying the states so they have the correct
2611 pre-max/pre-fullscreen values
2613 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2614 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2615 self
->window
, x
, y
, w
, h
);
2616 /* save the area, and make it where it should be for the premax stuff */
2617 oldarea
= self
->area
;
2618 RECT_SET(self
->area
, x
, y
, w
, h
);
2620 /* apply the states. these are in a carefully crafted order.. */
2623 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2625 client_fullscreen(self
, TRUE
);
2627 client_set_undecorated(self
, TRUE
);
2629 client_shade(self
, TRUE
);
2630 if (demands_attention
)
2631 client_hilite(self
, TRUE
);
2633 if (max_vert
&& max_horz
)
2634 client_maximize(self
, TRUE
, 0);
2636 client_maximize(self
, TRUE
, 2);
2638 client_maximize(self
, TRUE
, 1);
2640 /* if the window hasn't been configured yet, then do so now, in fact the
2641 x,y,w,h may _not_ be the same as the area rect, which can end up
2642 meaning that the client isn't properly moved/resized by the fullscreen
2644 pho can cause this because it maps at size of the screen but not 0,0
2645 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2646 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2647 cuz thats where the pre-fullscreen will be. however the actual area is
2648 not, so this needs to be called even if we have fullscreened/maxed
2650 self
->area
= oldarea
;
2651 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2653 /* set the desktop hint, to make sure that it always exists */
2654 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
2656 /* nothing to do for the other states:
2665 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2667 /* these should be the current values. this is for when you're not moving,
2669 g_assert(*x
== self
->area
.x
);
2670 g_assert(oldw
== self
->area
.width
);
2673 switch (self
->gravity
) {
2675 case NorthWestGravity
:
2677 case SouthWestGravity
:
2684 *x
-= (neww
- oldw
) / 2;
2686 case NorthEastGravity
:
2688 case SouthEastGravity
:
2694 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2696 /* these should be the current values. this is for when you're not moving,
2698 g_assert(*y
== self
->area
.y
);
2699 g_assert(oldh
== self
->area
.height
);
2702 switch (self
->gravity
) {
2704 case NorthWestGravity
:
2706 case NorthEastGravity
:
2713 *y
-= (newh
- oldh
) / 2;
2715 case SouthWestGravity
:
2717 case SouthEastGravity
:
2723 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2724 gint
*logicalw
, gint
*logicalh
,
2727 Rect desired
= {*x
, *y
, *w
, *h
};
2728 frame_rect_to_frame(self
->frame
, &desired
);
2730 /* make the frame recalculate its dimentions n shit without changing
2731 anything visible for real, this way the constraints below can work with
2732 the updated frame dimensions. */
2733 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2735 /* gets the frame's position */
2736 frame_client_gravity(self
->frame
, x
, y
);
2738 /* these positions are frame positions, not client positions */
2740 /* set the size and position if fullscreen */
2741 if (self
->fullscreen
) {
2745 i
= screen_find_monitor(&desired
);
2746 a
= screen_physical_area_monitor(i
);
2753 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2757 } else if (self
->max_horz
|| self
->max_vert
) {
2761 /* use all possible struts when maximizing to the full screen */
2762 i
= screen_find_monitor(&desired
);
2763 a
= screen_area(self
->desktop
, i
,
2764 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2766 /* set the size and position if maximized */
2767 if (self
->max_horz
) {
2769 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2771 if (self
->max_vert
) {
2773 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2776 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2782 /* gets the client's position */
2783 frame_frame_gravity(self
->frame
, x
, y
);
2785 /* work within the prefered sizes given by the window */
2786 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2787 gint basew
, baseh
, minw
, minh
;
2789 gfloat minratio
, maxratio
;
2791 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2792 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2793 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2794 0 : self
->min_ratio
;
2795 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2796 0 : self
->max_ratio
;
2798 /* base size is substituted with min size if not specified */
2799 if (self
->base_size
.width
|| self
->base_size
.height
) {
2800 basew
= self
->base_size
.width
;
2801 baseh
= self
->base_size
.height
;
2803 basew
= self
->min_size
.width
;
2804 baseh
= self
->min_size
.height
;
2806 /* min size is substituted with base size if not specified */
2807 if (self
->min_size
.width
|| self
->min_size
.height
) {
2808 minw
= self
->min_size
.width
;
2809 minh
= self
->min_size
.height
;
2811 minw
= self
->base_size
.width
;
2812 minh
= self
->base_size
.height
;
2815 /* if this is a user-requested resize, then check against min/max
2818 /* smaller than min size or bigger than max size? */
2819 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2820 if (*w
< minw
) *w
= minw
;
2821 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2822 if (*h
< minh
) *h
= minh
;
2827 /* keep to the increments */
2831 /* you cannot resize to nothing */
2832 if (basew
+ *w
< 1) *w
= 1 - basew
;
2833 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2835 /* save the logical size */
2836 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2837 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2845 /* adjust the height to match the width for the aspect ratios.
2846 for this, min size is not substituted for base size ever. */
2847 *w
-= self
->base_size
.width
;
2848 *h
-= self
->base_size
.height
;
2851 if (*h
* minratio
> *w
) {
2852 *h
= (gint
)(*w
/ minratio
);
2854 /* you cannot resize to nothing */
2857 *w
= (gint
)(*h
* minratio
);
2861 if (*h
* maxratio
< *w
) {
2862 *h
= (gint
)(*w
/ maxratio
);
2864 /* you cannot resize to nothing */
2867 *w
= (gint
)(*h
* minratio
);
2871 *w
+= self
->base_size
.width
;
2872 *h
+= self
->base_size
.height
;
2875 /* these override the above states! if you cant move you can't move! */
2877 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2881 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2882 *w
= self
->area
.width
;
2883 *h
= self
->area
.height
;
2892 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2893 gboolean user
, gboolean final
, gboolean force_reply
)
2897 gboolean send_resize_client
;
2898 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2899 gboolean fmoved
, fresized
;
2900 guint fdecor
= self
->frame
->decorations
;
2901 gboolean fhorz
= self
->frame
->max_horz
;
2902 gboolean fvert
= self
->frame
->max_vert
;
2903 gint logicalw
, logicalh
;
2905 /* find the new x, y, width, and height (and logical size) */
2906 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2908 /* set the logical size if things changed */
2909 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2910 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2912 /* figure out if we moved or resized or what */
2913 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2914 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2916 oldw
= self
->area
.width
;
2917 oldh
= self
->area
.height
;
2918 oldframe
= self
->frame
->area
;
2919 RECT_SET(self
->area
, x
, y
, w
, h
);
2921 /* for app-requested resizes, always resize if 'resized' is true.
2922 for user-requested ones, only resize if final is true, or when
2923 resizing in redraw mode */
2924 send_resize_client
= ((!user
&& resized
) ||
2926 (resized
&& config_resize_redraw
))));
2928 /* if the client is enlarging, then resize the client before the frame */
2929 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2930 XMoveResizeWindow(obt_display
, self
->window
,
2931 self
->frame
->size
.left
, self
->frame
->size
.top
,
2932 MAX(w
, oldw
), MAX(h
, oldh
));
2933 frame_adjust_client_area(self
->frame
);
2936 /* find the frame's dimensions and move/resize it */
2940 /* if decorations changed, then readjust everything for the frame */
2941 if (self
->decorations
!= fdecor
||
2942 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2944 fmoved
= fresized
= TRUE
;
2947 /* adjust the frame */
2948 if (fmoved
|| fresized
) {
2949 gulong ignore_start
;
2951 ignore_start
= event_start_ignore_all_enters();
2953 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2956 event_end_ignore_all_enters(ignore_start
);
2959 if (!user
|| final
) {
2960 gint oldrx
= self
->root_pos
.x
;
2961 gint oldry
= self
->root_pos
.y
;
2962 /* we have reset the client to 0 border width, so don't include
2963 it in these coords */
2964 POINT_SET(self
->root_pos
,
2965 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2967 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2968 self
->border_width
);
2969 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
2973 /* This is kinda tricky and should not be changed.. let me explain!
2975 When user = FALSE, then the request is coming from the application
2976 itself, and we are more strict about when to send a synthetic
2977 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
2978 in this case (if force_reply is true)
2980 When user = TRUE, then the request is coming from "us", like when we
2981 maximize a window or something. In this case we are more lenient. We
2982 used to follow the same rules as above, but _Java_ Swing can't handle
2983 this. So just to appease Swing, when user = TRUE, we always send
2984 a synthetic ConfigureNotify to give the window its root coordinates.
2986 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
2987 (user
&& final
&& rootmoved
))
2991 event
.type
= ConfigureNotify
;
2992 event
.xconfigure
.display
= obt_display
;
2993 event
.xconfigure
.event
= self
->window
;
2994 event
.xconfigure
.window
= self
->window
;
2996 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
2997 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
2999 /* root window real coords */
3000 event
.xconfigure
.x
= self
->root_pos
.x
;
3001 event
.xconfigure
.y
= self
->root_pos
.y
;
3002 event
.xconfigure
.width
= w
;
3003 event
.xconfigure
.height
= h
;
3004 event
.xconfigure
.border_width
= self
->border_width
;
3005 event
.xconfigure
.above
= None
;
3006 event
.xconfigure
.override_redirect
= FALSE
;
3007 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3008 FALSE
, StructureNotifyMask
, &event
);
3011 /* if the client is shrinking, then resize the frame before the client.
3013 both of these resize sections may run, because the top one only resizes
3014 in the direction that is growing
3016 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3017 frame_adjust_client_area(self
->frame
);
3018 XMoveResizeWindow(obt_display
, self
->window
,
3019 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3022 XFlush(obt_display
);
3024 /* if it moved between monitors, then this can affect the stacking
3025 layer of this window or others - for fullscreen windows */
3026 if (screen_find_monitor(&self
->frame
->area
) !=
3027 screen_find_monitor(&oldframe
))
3029 client_calc_layer(self
);
3033 void client_fullscreen(ObClient
*self
, gboolean fs
)
3037 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3038 self
->fullscreen
== fs
) return; /* already done */
3040 self
->fullscreen
= fs
;
3041 client_change_state(self
); /* change the state hints on the client */
3044 self
->pre_fullscreen_area
= self
->area
;
3045 /* if the window is maximized, its area isn't all that meaningful.
3046 save it's premax area instead. */
3047 if (self
->max_horz
) {
3048 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3049 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3051 if (self
->max_vert
) {
3052 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3053 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3056 /* these will help configure_full figure out where to fullscreen
3060 w
= self
->area
.width
;
3061 h
= self
->area
.height
;
3063 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3064 self
->pre_fullscreen_area
.height
> 0);
3066 x
= self
->pre_fullscreen_area
.x
;
3067 y
= self
->pre_fullscreen_area
.y
;
3068 w
= self
->pre_fullscreen_area
.width
;
3069 h
= self
->pre_fullscreen_area
.height
;
3070 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3073 ob_debug("Window %s going fullscreen (%d)",
3074 self
->title
, self
->fullscreen
);
3076 client_setup_decor_and_functions(self
, FALSE
);
3077 client_move_resize(self
, x
, y
, w
, h
);
3079 /* and adjust our layer/stacking. do this after resizing the window,
3080 and applying decorations, because windows which fill the screen are
3081 considered "fullscreen" and it affects their layer */
3082 client_calc_layer(self
);
3085 /* try focus us when we go into fullscreen mode */
3090 static void client_iconify_recursive(ObClient
*self
,
3091 gboolean iconic
, gboolean curdesk
,
3092 gboolean hide_animation
)
3095 gboolean changed
= FALSE
;
3098 if (self
->iconic
!= iconic
) {
3099 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3103 /* don't let non-normal windows iconify along with their parents
3105 if (client_normal(self
)) {
3106 self
->iconic
= iconic
;
3108 /* update the focus lists.. iconic windows go to the bottom of
3110 focus_order_to_bottom(self
);
3115 self
->iconic
= iconic
;
3117 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3118 self
->desktop
!= DESKTOP_ALL
)
3119 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3121 /* this puts it after the current focused window */
3122 focus_order_remove(self
);
3123 focus_order_add_new(self
);
3130 client_change_state(self
);
3131 if (config_animate_iconify
&& !hide_animation
)
3132 frame_begin_iconify_animation(self
->frame
, iconic
);
3133 /* do this after starting the animation so it doesn't flash */
3134 client_showhide(self
);
3137 /* iconify all direct transients, and deiconify all transients
3139 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3140 if (it
->data
!= self
)
3141 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3142 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3146 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3147 gboolean hide_animation
)
3149 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3150 /* move up the transient chain as far as possible first */
3151 self
= client_search_top_direct_parent(self
);
3152 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3156 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3160 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3161 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3163 /* check if already done */
3165 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3166 if (dir
== 1 && self
->max_horz
) return;
3167 if (dir
== 2 && self
->max_vert
) return;
3169 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3170 if (dir
== 1 && !self
->max_horz
) return;
3171 if (dir
== 2 && !self
->max_vert
) return;
3174 /* these will help configure_full figure out which screen to fill with
3178 w
= self
->area
.width
;
3179 h
= self
->area
.height
;
3182 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3183 RECT_SET(self
->pre_max_area
,
3184 self
->area
.x
, self
->pre_max_area
.y
,
3185 self
->area
.width
, self
->pre_max_area
.height
);
3187 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3188 RECT_SET(self
->pre_max_area
,
3189 self
->pre_max_area
.x
, self
->area
.y
,
3190 self
->pre_max_area
.width
, self
->area
.height
);
3193 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3194 g_assert(self
->pre_max_area
.width
> 0);
3196 x
= self
->pre_max_area
.x
;
3197 w
= self
->pre_max_area
.width
;
3199 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3200 0, self
->pre_max_area
.height
);
3202 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3203 g_assert(self
->pre_max_area
.height
> 0);
3205 y
= self
->pre_max_area
.y
;
3206 h
= self
->pre_max_area
.height
;
3208 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3209 self
->pre_max_area
.width
, 0);
3213 if (dir
== 0 || dir
== 1) /* horz */
3214 self
->max_horz
= max
;
3215 if (dir
== 0 || dir
== 2) /* vert */
3216 self
->max_vert
= max
;
3218 client_change_state(self
); /* change the state hints on the client */
3220 client_setup_decor_and_functions(self
, FALSE
);
3221 client_move_resize(self
, x
, y
, w
, h
);
3224 void client_shade(ObClient
*self
, gboolean shade
)
3226 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3227 shade
) || /* can't shade */
3228 self
->shaded
== shade
) return; /* already done */
3230 self
->shaded
= shade
;
3231 client_change_state(self
);
3232 client_change_wm_state(self
); /* the window is being hidden/shown */
3233 /* resize the frame to just the titlebar */
3234 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3237 static void client_ping_event(ObClient
*self
, gboolean dead
)
3239 self
->not_responding
= dead
;
3240 client_update_title(self
);
3243 /* try kill it nicely the first time again, if it started responding
3245 self
->close_tried_term
= FALSE
;
3249 void client_close(ObClient
*self
)
3251 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3253 /* in the case that the client provides no means to requesting that it
3254 close, we just kill it */
3255 if (!self
->delete_window
)
3256 /* don't use client_kill(), we should only kill based on PID in
3257 response to a lack of PING replies */
3258 XKillClient(obt_display
, self
->window
);
3259 else if (self
->not_responding
)
3262 /* request the client to close with WM_DELETE_WINDOW */
3263 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3264 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_curtime
,
3265 0, 0, 0, NoEventMask
);
3268 void client_kill(ObClient
*self
)
3270 if (!self
->client_machine
&& self
->pid
) {
3271 /* running on the local host */
3272 if (!self
->close_tried_term
) {
3273 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3274 self
->window
, self
->pid
);
3275 kill(self
->pid
, SIGTERM
);
3276 self
->close_tried_term
= TRUE
;
3278 /* show that we're trying to kill it */
3279 client_update_title(self
);
3282 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3283 self
->window
, self
->pid
);
3284 kill(self
->pid
, SIGKILL
); /* kill -9 */
3288 XKillClient(obt_display
, self
->window
);
3291 void client_hilite(ObClient
*self
, gboolean hilite
)
3293 if (self
->demands_attention
== hilite
)
3294 return; /* no change */
3296 /* don't allow focused windows to hilite */
3297 self
->demands_attention
= hilite
&& !client_focused(self
);
3298 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3299 if (self
->demands_attention
)
3300 frame_flash_start(self
->frame
);
3302 frame_flash_stop(self
->frame
);
3303 client_change_state(self
);
3307 static void client_set_desktop_recursive(ObClient
*self
,
3315 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3317 ob_debug("Setting desktop %u", target
+1);
3319 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3321 old
= self
->desktop
;
3322 self
->desktop
= target
;
3323 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3324 /* the frame can display the current desktop state */
3325 frame_adjust_state(self
->frame
);
3326 /* 'move' the window to the new desktop */
3330 /* raise if it was not already on the desktop */
3331 if (old
!= DESKTOP_ALL
&& !dontraise
)
3332 stacking_raise(CLIENT_AS_WINDOW(self
));
3333 if (STRUT_EXISTS(self
->strut
))
3334 screen_update_areas();
3336 /* the new desktop's geometry may be different, so we may need to
3337 resize, for example if we are maximized */
3338 client_reconfigure(self
, FALSE
);
3341 /* move all transients */
3342 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3343 if (it
->data
!= self
)
3344 if (client_is_direct_child(self
, it
->data
))
3345 client_set_desktop_recursive(it
->data
, target
,
3346 donthide
, dontraise
);
3349 void client_set_desktop(ObClient
*self
, guint target
,
3350 gboolean donthide
, gboolean dontraise
)
3352 self
= client_search_top_direct_parent(self
);
3353 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3356 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3358 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3359 return child
== parent
;
3362 ObClient
*client_search_modal_child(ObClient
*self
)
3367 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3368 ObClient
*c
= it
->data
;
3369 if ((ret
= client_search_modal_child(c
))) return ret
;
3370 if (c
->modal
) return c
;
3375 gboolean
client_validate(ObClient
*self
)
3379 XSync(obt_display
, FALSE
); /* get all events on the server */
3381 if (XCheckTypedWindowEvent(obt_display
, self
->window
, DestroyNotify
, &e
) ||
3382 XCheckTypedWindowEvent(obt_display
, self
->window
, UnmapNotify
, &e
))
3384 XPutBackEvent(obt_display
, &e
);
3391 void client_set_wm_state(ObClient
*self
, glong state
)
3393 if (state
== self
->wmstate
) return; /* no change */
3397 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3400 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3405 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3407 gboolean shaded
= self
->shaded
;
3408 gboolean fullscreen
= self
->fullscreen
;
3409 gboolean undecorated
= self
->undecorated
;
3410 gboolean max_horz
= self
->max_horz
;
3411 gboolean max_vert
= self
->max_vert
;
3412 gboolean modal
= self
->modal
;
3413 gboolean iconic
= self
->iconic
;
3414 gboolean demands_attention
= self
->demands_attention
;
3415 gboolean above
= self
->above
;
3416 gboolean below
= self
->below
;
3419 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3420 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3421 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3422 /* an invalid action was passed to the client message, ignore it */
3425 for (i
= 0; i
< 2; ++i
) {
3426 Atom state
= i
== 0 ? data1
: data2
;
3428 if (!state
) continue;
3430 /* if toggling, then pick whether we're adding or removing */
3431 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3432 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3433 action
= modal
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3434 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3435 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3436 action
= self
->max_vert
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3437 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3438 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3439 action
= self
->max_horz
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3440 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3441 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3442 action
= shaded
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3443 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3444 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3445 action
= self
->skip_taskbar
?
3446 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3447 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3448 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3449 action
= self
->skip_pager
?
3450 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3451 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3452 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3453 action
= self
->iconic
?
3454 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3455 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3456 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3457 action
= fullscreen
?
3458 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3459 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3460 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3461 action
= self
->above
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3462 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3463 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3464 action
= self
->below
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3465 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3466 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3467 action
= self
->demands_attention
?
3468 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3469 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3470 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3471 action
= undecorated
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3472 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3475 if (action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
)) {
3476 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3478 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3480 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3482 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3484 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3485 self
->skip_taskbar
= TRUE
;
3486 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3487 self
->skip_pager
= TRUE
;
3488 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3490 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3492 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3495 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3498 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3499 demands_attention
= TRUE
;
3500 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3504 } else { /* action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) */
3505 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3507 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3509 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3511 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3513 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3514 self
->skip_taskbar
= FALSE
;
3515 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3516 self
->skip_pager
= FALSE
;
3517 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3519 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3521 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3523 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3525 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3526 demands_attention
= FALSE
;
3527 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3528 undecorated
= FALSE
;
3533 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3534 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3536 if (max_horz
== max_vert
) { /* both going the same way */
3537 client_maximize(self
, max_horz
, 0);
3539 client_maximize(self
, max_horz
, 1);
3540 client_maximize(self
, max_vert
, 2);
3544 if (max_horz
!= self
->max_horz
)
3545 client_maximize(self
, max_horz
, 1);
3547 client_maximize(self
, max_vert
, 2);
3550 /* change fullscreen state before shading, as it will affect if the window
3552 if (fullscreen
!= self
->fullscreen
)
3553 client_fullscreen(self
, fullscreen
);
3554 if (shaded
!= self
->shaded
)
3555 client_shade(self
, shaded
);
3556 if (undecorated
!= self
->undecorated
)
3557 client_set_undecorated(self
, undecorated
);
3558 if (above
!= self
->above
|| below
!= self
->below
) {
3559 self
->above
= above
;
3560 self
->below
= below
;
3561 client_calc_layer(self
);
3564 if (modal
!= self
->modal
) {
3565 self
->modal
= modal
;
3566 /* when a window changes modality, then its stacking order with its
3567 transients needs to change */
3568 stacking_raise(CLIENT_AS_WINDOW(self
));
3570 /* it also may get focused. if something is focused that shouldn't
3571 be focused anymore, then move the focus */
3572 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3573 client_focus(focus_client
);
3576 if (iconic
!= self
->iconic
)
3577 client_iconify(self
, iconic
, FALSE
, FALSE
);
3579 if (demands_attention
!= self
->demands_attention
)
3580 client_hilite(self
, demands_attention
);
3582 client_change_state(self
); /* change the hint to reflect these changes */
3585 ObClient
*client_focus_target(ObClient
*self
)
3587 ObClient
*child
= NULL
;
3589 child
= client_search_modal_child(self
);
3590 if (child
) return child
;
3594 gboolean
client_can_focus(ObClient
*self
)
3596 /* choose the correct target */
3597 self
= client_focus_target(self
);
3599 if (!self
->frame
->visible
)
3602 if (!(self
->can_focus
|| self
->focus_notify
))
3608 gboolean
client_focus(ObClient
*self
)
3610 /* we might not focus this window, so if we have modal children which would
3611 be focused instead, bring them to this desktop */
3612 client_bring_modal_windows(self
);
3614 /* choose the correct target */
3615 self
= client_focus_target(self
);
3617 if (!client_can_focus(self
)) {
3618 ob_debug_type(OB_DEBUG_FOCUS
,
3619 "Client %s can't be focused", self
->title
);
3623 ob_debug_type(OB_DEBUG_FOCUS
,
3624 "Focusing client \"%s\" (0x%x) at time %u",
3625 self
->title
, self
->window
, event_curtime
);
3627 /* if using focus_delay, stop the timer now so that focus doesn't
3629 event_halt_focus_delay();
3631 /* if there is a grab going on, then we need to cancel it. if we move
3632 focus during the grab, applications will get NotifyWhileGrabbed events
3635 actions should not rely on being able to move focus during an
3638 event_cancel_all_key_grabs();
3640 obt_display_ignore_errors(TRUE
);
3642 if (self
->can_focus
) {
3643 /* This can cause a BadMatch error with CurrentTime, or if an app
3644 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3645 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3649 if (self
->focus_notify
) {
3651 ce
.xclient
.type
= ClientMessage
;
3652 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3653 ce
.xclient
.display
= obt_display
;
3654 ce
.xclient
.window
= self
->window
;
3655 ce
.xclient
.format
= 32;
3656 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
3657 ce
.xclient
.data
.l
[1] = event_curtime
;
3658 ce
.xclient
.data
.l
[2] = 0l;
3659 ce
.xclient
.data
.l
[3] = 0l;
3660 ce
.xclient
.data
.l
[4] = 0l;
3661 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3664 obt_display_ignore_errors(FALSE
);
3666 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
3667 obt_display_error_occured
);
3668 return !obt_display_error_occured
;
3671 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3674 if (client_normal(self
) && screen_showing_desktop
)
3675 screen_show_desktop(FALSE
, self
);
3677 client_iconify(self
, FALSE
, here
, FALSE
);
3678 if (self
->desktop
!= DESKTOP_ALL
&&
3679 self
->desktop
!= screen_desktop
)
3682 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3684 screen_set_desktop(self
->desktop
, FALSE
);
3685 } else if (!self
->frame
->visible
)
3686 /* if its not visible for other reasons, then don't mess
3689 if (self
->shaded
&& unshade
)
3690 client_shade(self
, FALSE
);
3692 stacking_raise(CLIENT_AS_WINDOW(self
));
3697 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3698 gboolean unshade
, gboolean user
)
3700 client_present(self
, here
, raise
, unshade
);
3703 static void client_bring_windows_recursive(ObClient
*self
,
3711 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3712 client_bring_windows_recursive(it
->data
, desktop
,
3713 helpers
, modals
, iconic
);
3715 if (((helpers
&& client_helper(self
)) ||
3716 (modals
&& self
->modal
)) &&
3717 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3718 (iconic
&& self
->iconic
)))
3720 if (iconic
&& self
->iconic
)
3721 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3723 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3727 void client_bring_helper_windows(ObClient
*self
)
3729 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3732 void client_bring_modal_windows(ObClient
*self
)
3734 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3737 gboolean
client_focused(ObClient
*self
)
3739 return self
== focus_client
;
3742 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3745 gulong min_diff
, min_i
;
3747 if (!self
->nicons
) {
3748 ObClientIcon
*parent
= NULL
;
3751 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
3752 ObClient
*c
= it
->data
;
3753 if ((parent
= client_icon_recursive(c
, w
, h
)))
3760 /* some kind of crappy approximation to find the icon closest in size to
3761 what we requested, but icons are generally all the same ratio as
3762 eachother so it's good enough. */
3764 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3767 for (i
= 1; i
< self
->nicons
; ++i
) {
3770 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3771 if (diff
< min_diff
) {
3776 return &self
->icons
[min_i
];
3779 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3782 static ObClientIcon deficon
;
3784 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3785 deficon
.width
= deficon
.height
= 48;
3786 deficon
.data
= ob_rr_theme
->def_win_icon
;
3792 void client_set_layer(ObClient
*self
, gint layer
)
3796 self
->above
= FALSE
;
3797 } else if (layer
== 0) {
3798 self
->below
= self
->above
= FALSE
;
3800 self
->below
= FALSE
;
3803 client_calc_layer(self
);
3804 client_change_state(self
); /* reflect this in the state hints */
3807 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3809 if (self
->undecorated
!= undecorated
&&
3810 /* don't let it undecorate if the function is missing, but let
3812 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3814 self
->undecorated
= undecorated
;
3815 client_setup_decor_and_functions(self
, TRUE
);
3816 client_change_state(self
); /* reflect this in the state hints */
3820 guint
client_monitor(ObClient
*self
)
3822 return screen_find_monitor(&self
->frame
->area
);
3825 ObClient
*client_direct_parent(ObClient
*self
)
3827 if (!self
->parents
) return NULL
;
3828 if (self
->transient_for_group
) return NULL
;
3829 return self
->parents
->data
;
3832 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3835 while ((p
= client_direct_parent(self
))) self
= p
;
3839 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3841 ObStackingLayer layer
)
3846 /* move up the direct transient chain as far as possible */
3847 while ((p
= client_direct_parent(self
)) &&
3848 (!bylayer
|| p
->layer
== layer
))
3852 ret
= g_slist_prepend(NULL
, self
);
3854 ret
= g_slist_copy(self
->parents
);
3859 GSList
*client_search_all_top_parents(ObClient
*self
)
3861 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3864 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3866 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3869 ObClient
*client_search_focus_parent(ObClient
*self
)
3873 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3874 if (client_focused(it
->data
)) return it
->data
;
3879 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3883 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3884 if (it
->data
== search
) return search
;
3889 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3893 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3894 if (sit
->data
== search
)
3896 if (client_search_transient(sit
->data
, search
))
3902 static void detect_edge(Rect area
, ObDirection dir
,
3903 gint my_head
, gint my_size
,
3904 gint my_edge_start
, gint my_edge_size
,
3905 gint
*dest
, gboolean
*near_edge
)
3907 gint edge_start
, edge_size
, head
, tail
;
3908 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
3911 case OB_DIRECTION_NORTH
:
3912 case OB_DIRECTION_SOUTH
:
3913 edge_start
= area
.x
;
3914 edge_size
= area
.width
;
3916 case OB_DIRECTION_EAST
:
3917 case OB_DIRECTION_WEST
:
3918 edge_start
= area
.y
;
3919 edge_size
= area
.height
;
3922 g_assert_not_reached();
3925 /* do we collide with this window? */
3926 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
3927 edge_start
, edge_size
))
3931 case OB_DIRECTION_NORTH
:
3932 head
= RECT_BOTTOM(area
);
3933 tail
= RECT_TOP(area
);
3935 case OB_DIRECTION_SOUTH
:
3936 head
= RECT_TOP(area
);
3937 tail
= RECT_BOTTOM(area
);
3939 case OB_DIRECTION_WEST
:
3940 head
= RECT_RIGHT(area
);
3941 tail
= RECT_LEFT(area
);
3943 case OB_DIRECTION_EAST
:
3944 head
= RECT_LEFT(area
);
3945 tail
= RECT_RIGHT(area
);
3948 g_assert_not_reached();
3951 case OB_DIRECTION_NORTH
:
3952 case OB_DIRECTION_WEST
:
3953 /* check if our window is past the head of this window */
3954 if (my_head
<= head
+ 1)
3956 /* check if our window's tail is past the tail of this window */
3957 if (my_head
+ my_size
- 1 <= tail
)
3959 /* check if the head of this window is closer than the previously
3960 chosen edge (take into account that the previously chosen
3961 edge might have been a tail, not a head) */
3962 if (head
+ (*near_edge
? 0 : my_size
) < *dest
)
3964 /* check if the tail of this window is closer than the previously
3965 chosen edge (take into account that the previously chosen
3966 edge might have been a head, not a tail) */
3967 if (tail
- (!*near_edge
? 0 : my_size
) < *dest
)
3970 case OB_DIRECTION_SOUTH
:
3971 case OB_DIRECTION_EAST
:
3972 /* check if our window is past the head of this window */
3973 if (my_head
>= head
- 1)
3975 /* check if our window's tail is past the tail of this window */
3976 if (my_head
- my_size
+ 1 >= tail
)
3978 /* check if the head of this window is closer than the previously
3979 chosen edge (take into account that the previously chosen
3980 edge might have been a tail, not a head) */
3981 if (head
- (*near_edge
? 0 : my_size
) > *dest
)
3983 /* check if the tail of this window is closer than the previously
3984 chosen edge (take into account that the previously chosen
3985 edge might have been a head, not a tail) */
3986 if (tail
+ (!*near_edge
? 0 : my_size
) > *dest
)
3990 g_assert_not_reached();
3993 ob_debug("my head %d size %d", my_head
, my_size
);
3994 ob_debug("head %d tail %d deest %d", head
, tail
, *dest
);
3996 ob_debug("using near edge %d", head
);
4000 else if (!skip_tail
) {
4001 ob_debug("using far edge %d", tail
);
4007 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4008 gint my_head
, gint my_size
,
4009 gint my_edge_start
, gint my_edge_size
,
4010 gint
*dest
, gboolean
*near_edge
)
4017 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4018 &self
->frame
->area
);
4019 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
4020 &self
->frame
->area
);
4023 case OB_DIRECTION_NORTH
:
4024 if (my_head
>= RECT_TOP(*mon
) + 1)
4025 edge
= RECT_TOP(*mon
) - 1;
4027 edge
= RECT_TOP(*a
) - 1;
4029 case OB_DIRECTION_SOUTH
:
4030 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
4031 edge
= RECT_BOTTOM(*mon
) + 1;
4033 edge
= RECT_BOTTOM(*a
) + 1;
4035 case OB_DIRECTION_EAST
:
4036 if (my_head
<= RECT_RIGHT(*mon
) - 1)
4037 edge
= RECT_RIGHT(*mon
) + 1;
4039 edge
= RECT_RIGHT(*a
) + 1;
4041 case OB_DIRECTION_WEST
:
4042 if (my_head
>= RECT_LEFT(*mon
) + 1)
4043 edge
= RECT_LEFT(*mon
) - 1;
4045 edge
= RECT_LEFT(*a
) - 1;
4048 g_assert_not_reached();
4050 /* default to the far edge, then narrow it down */
4054 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4055 ObClient
*cur
= it
->data
;
4057 /* skip windows to not bump into */
4062 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4063 cur
->desktop
!= screen_desktop
)
4066 ob_debug("trying window %s", cur
->title
);
4068 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4069 my_edge_size
, dest
, near_edge
);
4071 dock_get_area(&dock_area
);
4072 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4073 my_edge_size
, dest
, near_edge
);
4078 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4082 gint e
, e_start
, e_size
;
4086 case OB_DIRECTION_EAST
:
4087 head
= RECT_RIGHT(self
->frame
->area
);
4088 size
= self
->frame
->area
.width
;
4089 e_start
= RECT_TOP(self
->frame
->area
);
4090 e_size
= self
->frame
->area
.height
;
4092 case OB_DIRECTION_WEST
:
4093 head
= RECT_LEFT(self
->frame
->area
);
4094 size
= self
->frame
->area
.width
;
4095 e_start
= RECT_TOP(self
->frame
->area
);
4096 e_size
= self
->frame
->area
.height
;
4098 case OB_DIRECTION_NORTH
:
4099 head
= RECT_TOP(self
->frame
->area
);
4100 size
= self
->frame
->area
.height
;
4101 e_start
= RECT_LEFT(self
->frame
->area
);
4102 e_size
= self
->frame
->area
.width
;
4104 case OB_DIRECTION_SOUTH
:
4105 head
= RECT_BOTTOM(self
->frame
->area
);
4106 size
= self
->frame
->area
.height
;
4107 e_start
= RECT_LEFT(self
->frame
->area
);
4108 e_size
= self
->frame
->area
.width
;
4111 g_assert_not_reached();
4114 client_find_edge_directional(self
, dir
, head
, size
,
4115 e_start
, e_size
, &e
, &near
);
4116 *x
= self
->frame
->area
.x
;
4117 *y
= self
->frame
->area
.y
;
4119 case OB_DIRECTION_EAST
:
4120 if (near
) e
-= self
->frame
->area
.width
;
4124 case OB_DIRECTION_WEST
:
4126 else e
-= self
->frame
->area
.width
;
4129 case OB_DIRECTION_NORTH
:
4131 else e
-= self
->frame
->area
.height
;
4134 case OB_DIRECTION_SOUTH
:
4135 if (near
) e
-= self
->frame
->area
.height
;
4140 g_assert_not_reached();
4142 frame_frame_gravity(self
->frame
, x
, y
);
4145 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4147 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4150 gint e
, e_start
, e_size
, delta
;
4155 case OB_DIRECTION_EAST
:
4156 head
= RECT_RIGHT(self
->frame
->area
) +
4157 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4158 e_start
= RECT_TOP(self
->frame
->area
);
4159 e_size
= self
->frame
->area
.height
;
4160 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4162 case OB_DIRECTION_WEST
:
4163 head
= RECT_LEFT(self
->frame
->area
) -
4164 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4165 e_start
= RECT_TOP(self
->frame
->area
);
4166 e_size
= self
->frame
->area
.height
;
4167 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4169 case OB_DIRECTION_NORTH
:
4170 head
= RECT_TOP(self
->frame
->area
) -
4171 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4172 e_start
= RECT_LEFT(self
->frame
->area
);
4173 e_size
= self
->frame
->area
.width
;
4174 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4176 case OB_DIRECTION_SOUTH
:
4177 head
= RECT_BOTTOM(self
->frame
->area
) +
4178 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4179 e_start
= RECT_LEFT(self
->frame
->area
);
4180 e_size
= self
->frame
->area
.width
;
4181 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4184 g_assert_not_reached();
4187 ob_debug("head %d dir %d", head
, dir
);
4188 client_find_edge_directional(self
, dir
, head
, 1,
4189 e_start
, e_size
, &e
, &near
);
4190 ob_debug("edge %d", e
);
4191 *x
= self
->frame
->area
.x
;
4192 *y
= self
->frame
->area
.y
;
4193 *w
= self
->frame
->area
.width
;
4194 *h
= self
->frame
->area
.height
;
4196 case OB_DIRECTION_EAST
:
4197 if (grow
== near
) --e
;
4198 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4201 case OB_DIRECTION_WEST
:
4202 if (grow
== near
) ++e
;
4203 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4207 case OB_DIRECTION_NORTH
:
4208 if (grow
== near
) ++e
;
4209 delta
= RECT_TOP(self
->frame
->area
) - e
;
4213 case OB_DIRECTION_SOUTH
:
4214 if (grow
== near
) --e
;
4215 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4219 g_assert_not_reached();
4221 frame_frame_gravity(self
->frame
, x
, y
);
4222 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4223 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4226 ObClient
* client_under_pointer(void)
4230 ObClient
*ret
= NULL
;
4232 if (screen_pointer_pos(&x
, &y
)) {
4233 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4234 if (WINDOW_IS_CLIENT(it
->data
)) {
4235 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4236 if (c
->frame
->visible
&&
4237 /* check the desktop, this is done during desktop
4238 switching and windows are shown/hidden status is not
4240 (c
->desktop
== screen_desktop
||
4241 c
->desktop
== DESKTOP_ALL
) &&
4242 /* ignore all animating windows */
4243 !frame_iconify_animating(c
->frame
) &&
4244 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4255 gboolean
client_has_group_siblings(ObClient
*self
)
4257 return self
->group
&& self
->group
->members
->next
;