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_all(void)
182 XWindowAttributes attrib
;
184 XQueryTree(obt_display
, RootWindow(obt_display
, ob_screen
),
185 &w
, &w
, &children
, &nchild
);
187 /* remove all icon windows from the list */
188 for (i
= 0; i
< nchild
; i
++) {
189 if (children
[i
] == None
) continue;
190 wmhints
= XGetWMHints(obt_display
, children
[i
]);
192 if ((wmhints
->flags
& IconWindowHint
) &&
193 (wmhints
->icon_window
!= children
[i
]))
194 for (j
= 0; j
< nchild
; j
++)
195 if (children
[j
] == wmhints
->icon_window
) {
203 /* manage windows in reverse order from how they were originally mapped.
204 this is an attempt to manage children windows before their parents, so
205 that when the parent is mapped, it can find the child */
206 for (i
= 0; i
< nchild
; ++i
) {
207 if (children
[i
] == None
)
209 if (XGetWindowAttributes(obt_display
, children
[i
], &attrib
)) {
210 if (attrib
.override_redirect
) continue;
212 if (attrib
.map_state
!= IsUnmapped
)
213 client_manage(children
[i
]);
219 void client_manage(Window window
)
223 XWindowAttributes attrib
;
224 XSetWindowAttributes attrib_set
;
226 gboolean activate
= FALSE
;
227 ObAppSettings
*settings
;
228 gboolean transient
= FALSE
;
229 Rect place
, *monitor
;
230 Time launch_time
, map_time
;
234 /* check if it has already been unmapped by the time we started
235 mapping. the grab does a sync so we don't have to here */
236 if (XCheckTypedWindowEvent(obt_display
, window
, DestroyNotify
, &e
) ||
237 XCheckTypedWindowEvent(obt_display
, window
, UnmapNotify
, &e
))
239 XPutBackEvent(obt_display
, &e
);
241 ob_debug("Trying to manage unmapped window. Aborting that.\n");
243 return; /* don't manage it */
246 /* make sure it isn't an override-redirect window */
247 if (!XGetWindowAttributes(obt_display
, window
, &attrib
) ||
248 attrib
.override_redirect
)
251 return; /* don't manage it */
254 /* is the window a docking app */
255 if ((wmhint
= XGetWMHints(obt_display
, window
))) {
256 if ((wmhint
->flags
& StateHint
) &&
257 wmhint
->initial_state
== WithdrawnState
)
259 dock_add(window
, wmhint
);
267 ob_debug("Managing window: 0x%lx", window
);
269 map_time
= event_get_server_time();
271 /* choose the events we want to receive on the CLIENT window */
272 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
273 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
274 XChangeWindowAttributes(obt_display
, window
,
275 CWEventMask
|CWDontPropagate
, &attrib_set
);
277 /* create the ObClient struct, and populate it from the hints on the
279 self
= g_new0(ObClient
, 1);
280 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
281 self
->window
= window
;
283 /* non-zero defaults */
284 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
285 self
->gravity
= NorthWestGravity
;
286 self
->desktop
= screen_num_desktops
; /* always an invalid value */
288 /* get all the stuff off the window */
289 client_get_all(self
, TRUE
);
291 ob_debug("Window type: %d", self
->type
);
292 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
294 /* now we have all of the window's information so we can set this up.
295 do this before creating the frame, so it can tell that we are still
296 mapping and doesn't go applying things right away */
297 client_setup_decor_and_functions(self
, FALSE
);
299 /* specify that if we exit, the window should not be destroyed and
300 should be reparented back to root automatically */
301 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
303 /* create the decoration frame for the client window */
304 self
->frame
= frame_new(self
);
306 frame_grab_client(self
->frame
);
308 /* we've grabbed everything and set everything that we need to at mapping
312 /* per-app settings override stuff from client_get_all, and return the
313 settings for other uses too. the returned settings is a shallow copy,
314 that needs to be freed with g_free(). */
315 settings
= client_get_settings_state(self
);
316 /* the session should get the last say though */
317 client_restore_session_state(self
);
319 /* tell startup notification that this app started */
320 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
322 /* do this after we have a frame.. it uses the frame to help determine the
323 WM_STATE to apply. */
324 client_change_state(self
);
326 /* add ourselves to the focus order */
327 focus_order_add_new(self
);
329 /* do this to add ourselves to the stacking list in a non-intrusive way */
330 client_calc_layer(self
);
332 /* focus the new window? */
333 if (ob_state() != OB_STATE_STARTING
&&
334 (!self
->session
|| self
->session
->focused
) &&
335 /* this means focus=true for window is same as config_focus_new=true */
336 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
337 client_search_focus_tree_full(self
)) &&
338 /* this checks for focus=false for the window */
339 (!settings
|| settings
->focus
!= 0) &&
340 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
345 /* remove the client's border */
346 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
348 /* adjust the frame to the client's size before showing or placing
350 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
351 frame_adjust_client_area(self
->frame
);
353 /* where the frame was placed is where the window was originally */
355 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
357 /* figure out placement for the window if the window is new */
358 if (ob_state() == OB_STATE_RUNNING
) {
359 ob_debug("Positioned: %s @ %d %d",
360 (!self
->positioned
? "no" :
361 (self
->positioned
== PPosition
? "program specified" :
362 (self
->positioned
== USPosition
? "user specified" :
363 (self
->positioned
== (PPosition
| USPosition
) ?
364 "program + user specified" :
365 "BADNESS !?")))), place
.x
, place
.y
);
367 ob_debug("Sized: %s @ %d %d",
368 (!self
->sized
? "no" :
369 (self
->sized
== PSize
? "program specified" :
370 (self
->sized
== USSize
? "user specified" :
371 (self
->sized
== (PSize
| USSize
) ?
372 "program + user specified" :
373 "BADNESS !?")))), place
.width
, place
.height
);
375 /* splash screens are also returned as TRUE for transient,
376 and so will be forced on screen below */
377 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
379 /* make sure the window is visible. */
380 client_find_onscreen(self
, &place
.x
, &place
.y
,
381 place
.width
, place
.height
,
382 /* non-normal clients has less rules, and
383 windows that are being restored from a
384 session do also. we can assume you want
385 it back where you saved it. Clients saying
386 they placed themselves are subjected to
387 harder rules, ones that are placed by
388 place.c or by the user are allowed partially
389 off-screen and on xinerama divides (ie,
390 it is up to the placement routines to avoid
391 the xinerama divides)
393 splash screens get "transient" set to TRUE by
394 the place_client call
396 ob_state() == OB_STATE_RUNNING
&&
398 (!((self
->positioned
& USPosition
) ||
399 (settings
&& settings
->pos_given
)) &&
400 client_normal(self
) &&
402 /* don't move oldschool fullscreen windows to
403 fit inside the struts (fixes Acroread, which
404 makes its fullscreen window fit the screen
405 but it is not USSize'd or USPosition'd) */
406 !(self
->decorations
== 0 &&
407 RECT_EQUAL(place
, *monitor
)))));
410 /* if the window isn't user-sized, then make it fit inside
411 the visible screen area on its monitor. Use basically the same rules
412 for forcing the window on screen in the client_find_onscreen call.
414 do this after place_client, it chooses the monitor!
416 splash screens get "transient" set to TRUE by
417 the place_client call
419 if (ob_state() == OB_STATE_RUNNING
&&
421 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
422 client_normal(self
) &&
424 /* don't shrink oldschool fullscreen windows to fit inside the
425 struts (fixes Acroread, which makes its fullscreen window
426 fit the screen but it is not USSize'd or USPosition'd) */
427 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
429 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
431 /* get the size of the frame */
432 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
433 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
435 /* fit the window inside the area */
436 place
.width
= MIN(place
.width
, a
->width
);
437 place
.height
= MIN(place
.height
, a
->height
);
439 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
441 /* get the size of the client back */
442 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
443 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
448 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
449 "some restrictions may apply",
450 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
452 ob_debug(" but session requested %d, %d %d x %d instead, "
454 self
->session
->x
, self
->session
->y
,
455 self
->session
->w
, self
->session
->h
);
457 /* do this after the window is placed, so the premax/prefullscreen numbers
460 this also places the window
462 client_apply_startup_state(self
, place
.x
, place
.y
,
463 place
.width
, place
.height
);
468 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s",
469 activate
? "yes" : "no");
471 gboolean raise
= FALSE
;
473 /* This is focus stealing prevention */
474 ob_debug_type(OB_DEBUG_FOCUS
,
475 "Want to focus new window 0x%x at time %u "
476 "launched at %u (last user interaction time %u)",
477 self
->window
, map_time
, launch_time
,
478 event_last_user_time
);
480 if (menu_frame_visible
|| moveresize_in_progress
) {
483 ob_debug_type(OB_DEBUG_FOCUS
,
484 "Not focusing the window because the user is inside "
485 "an Openbox menu or is move/resizing a window and "
486 "we don't want to interrupt them");
489 /* if it's on another desktop */
490 else if (!(self
->desktop
== screen_desktop
||
491 self
->desktop
== DESKTOP_ALL
) &&
492 /* the timestamp is from before you changed desktops */
493 launch_time
&& screen_desktop_user_time
&&
494 !event_time_after(launch_time
, screen_desktop_user_time
))
498 ob_debug_type(OB_DEBUG_FOCUS
,
499 "Not focusing the window because its on another "
502 /* If something is focused, and it's not our relative... */
503 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
504 client_search_focus_group_full(self
) == NULL
)
506 /* If the user is working in another window right now, then don't
508 if (event_last_user_time
&& launch_time
&&
509 event_time_after(event_last_user_time
, launch_time
) &&
510 event_last_user_time
!= launch_time
&&
511 event_time_after(event_last_user_time
,
512 map_time
- OB_EVENT_USER_TIME_DELAY
))
515 ob_debug_type(OB_DEBUG_FOCUS
,
516 "Not focusing the window because the user is "
517 "working in another window");
519 /* If its a transient (and its parents aren't focused) */
520 else if (client_has_parent(self
)) {
522 ob_debug_type(OB_DEBUG_FOCUS
,
523 "Not focusing the window because it is a "
524 "transient, and its relatives aren't focused");
526 /* Don't steal focus from globally active clients.
527 I stole this idea from KWin. It seems nice.
529 else if (!(focus_client
->can_focus
||
530 focus_client
->focus_notify
))
533 ob_debug_type(OB_DEBUG_FOCUS
,
534 "Not focusing the window because a globally "
535 "active client has focus");
537 /* Don't move focus if it's not going to go to this window
539 else if (client_focus_target(self
) != self
) {
542 ob_debug_type(OB_DEBUG_FOCUS
,
543 "Not focusing the window because another window "
544 "would get the focus anyway");
546 else if (!(self
->desktop
== screen_desktop
||
547 self
->desktop
== DESKTOP_ALL
))
551 ob_debug_type(OB_DEBUG_FOCUS
,
552 "Not focusing the window because it is on "
553 "another desktop and no relatives are focused ");
558 ob_debug_type(OB_DEBUG_FOCUS
,
559 "Focus stealing prevention activated for %s at "
560 "time %u (last user interactioon time %u)",
561 self
->title
, map_time
, event_last_user_time
);
562 /* if the client isn't focused, then hilite it so the user
564 client_hilite(self
, TRUE
);
565 /* we may want to raise it even tho we're not activating it */
566 if (raise
&& !client_restore_session_stacking(self
))
567 stacking_raise(CLIENT_AS_WINDOW(self
));
571 /* This may look rather odd. Well it's because new windows are added
572 to the stacking order non-intrusively. If we're not going to focus
573 the new window or hilite it, then we raise it to the top. This will
574 take affect for things that don't get focused like splash screens.
575 Also if you don't have focus_new enabled, then it's going to get
576 raised to the top. Legacy begets legacy I guess?
578 if (!client_restore_session_stacking(self
))
579 stacking_raise(CLIENT_AS_WINDOW(self
));
582 mouse_grab_for_client(self
, TRUE
);
584 /* this has to happen before we try focus the window, but we want it to
585 happen after the client's stacking has been determined or it looks bad
589 if (!config_focus_under_mouse
)
590 ignore_start
= event_start_ignore_all_enters();
594 if (!config_focus_under_mouse
)
595 event_end_ignore_all_enters(ignore_start
);
599 gboolean stacked
= client_restore_session_stacking(self
);
600 client_present(self
, FALSE
, !stacked
, TRUE
);
603 /* add to client list/map */
604 client_list
= g_list_append(client_list
, self
);
605 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
607 /* this has to happen after we're in the client_list */
608 if (STRUT_EXISTS(self
->strut
))
609 screen_update_areas();
611 /* update the list hints */
614 /* watch for when the application stops responding. only do this for
615 normal windows, i.e. windows which have titlebars and close buttons
616 and things like that.
617 we don't need to stop pinging on unmanage, because it will be handled
618 automatically by the destroy callback!
620 if (self
->ping
&& client_normal(self
))
621 ping_start(self
, client_ping_event
);
623 /* free the ObAppSettings shallow copy */
626 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
627 window
, self
->frame
->window
, self
->class);
633 ObClient
*client_fake_manage(Window window
)
636 ObAppSettings
*settings
;
638 ob_debug("Pretend-managing window: %lx", window
);
640 /* do this minimal stuff to figure out the client's decorations */
642 self
= g_new0(ObClient
, 1);
643 self
->window
= window
;
645 client_get_all(self
, FALSE
);
646 /* per-app settings override stuff, and return the settings for other
647 uses too. this returns a shallow copy that needs to be freed */
648 settings
= client_get_settings_state(self
);
650 client_setup_decor_and_functions(self
, FALSE
);
652 /* create the decoration frame for the client window and adjust its size */
653 self
->frame
= frame_new(self
);
654 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
656 ob_debug("gave extents left %d right %d top %d bottom %d",
657 self
->frame
->size
.left
, self
->frame
->size
.right
,
658 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
660 /* free the ObAppSettings shallow copy */
666 void client_unmanage_all(void)
668 while (client_list
!= NULL
)
669 client_unmanage(client_list
->data
);
672 void client_unmanage(ObClient
*self
)
678 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
679 self
->window
, self
->frame
->window
,
680 self
->class, self
->title
? self
->title
: "");
682 g_assert(self
!= NULL
);
684 /* we dont want events no more. do this before hiding the frame so we
685 don't generate more events */
686 XSelectInput(obt_display
, self
->window
, NoEventMask
);
688 /* ignore enter events from the unmap so it doesnt mess with the focus */
689 if (!config_focus_under_mouse
)
690 ignore_start
= event_start_ignore_all_enters();
692 frame_hide(self
->frame
);
693 /* flush to send the hide to the server quickly */
696 if (!config_focus_under_mouse
)
697 event_end_ignore_all_enters(ignore_start
);
699 mouse_grab_for_client(self
, FALSE
);
701 /* remove the window from our save set */
702 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
704 /* update the focus lists */
705 focus_order_remove(self
);
706 if (client_focused(self
)) {
707 /* don't leave an invalid focus_client */
711 client_list
= g_list_remove(client_list
, self
);
712 stacking_remove(self
);
713 window_remove(self
->window
);
715 /* once the client is out of the list, update the struts to remove its
717 if (STRUT_EXISTS(self
->strut
))
718 screen_update_areas();
720 client_call_notifies(self
, client_destroy_notifies
);
722 /* tell our parent(s) that we're gone */
723 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
724 ((ObClient
*)it
->data
)->transients
=
725 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
727 /* tell our transients that we're gone */
728 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
729 ((ObClient
*)it
->data
)->parents
=
730 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
731 /* we could be keeping our children in a higher layer */
732 client_calc_layer(it
->data
);
735 /* remove from its group */
737 group_remove(self
->group
, self
);
741 /* restore the window's original geometry so it is not lost */
747 if (self
->fullscreen
)
748 a
= self
->pre_fullscreen_area
;
749 else if (self
->max_horz
|| self
->max_vert
) {
750 if (self
->max_horz
) {
751 a
.x
= self
->pre_max_area
.x
;
752 a
.width
= self
->pre_max_area
.width
;
754 if (self
->max_vert
) {
755 a
.y
= self
->pre_max_area
.y
;
756 a
.height
= self
->pre_max_area
.height
;
760 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
761 /* let it be moved and resized no matter what */
762 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
763 self
->decorations
= 0; /* unmanaged windows have no decor */
765 /* give the client its border back */
766 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
768 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
771 /* reparent the window out of the frame, and free the frame */
772 frame_release_client(self
->frame
);
773 frame_free(self
->frame
);
776 if (ob_state() != OB_STATE_EXITING
) {
777 /* these values should not be persisted across a window
779 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
780 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
781 OBT_PROP_ERASE(self
->window
, WM_STATE
);
783 /* if we're left in an unmapped state, the client wont be mapped.
784 this is bad, since we will no longer be managing the window on
786 XMapWindow(obt_display
, self
->window
);
789 /* these should not be left on the window ever. other window managers
790 don't necessarily use them and it will mess them up (like compiz) */
791 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
792 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
794 /* update the list hints */
797 ob_debug("Unmanaged window 0x%lx", self
->window
);
799 /* free all data allocated in the client struct */
800 g_slist_free(self
->transients
);
801 for (j
= 0; j
< self
->nicons
; ++j
)
802 g_free(self
->icons
[j
].data
);
803 if (self
->nicons
> 0)
805 g_free(self
->startup_id
);
806 g_free(self
->wm_command
);
808 g_free(self
->icon_title
);
812 g_free(self
->client_machine
);
813 g_free(self
->sm_client_id
);
817 void client_fake_unmanage(ObClient
*self
)
819 /* this is all that got allocated to get the decorations */
821 frame_free(self
->frame
);
825 /*! Returns a new structure containing the per-app settings for this client.
826 The returned structure needs to be freed with g_free. */
827 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
829 ObAppSettings
*settings
;
832 settings
= config_create_app_settings();
834 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
835 ObAppSettings
*app
= it
->data
;
836 gboolean match
= TRUE
;
838 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
840 /* we know that either name or class is not NULL so it will have to
841 match to use the rule */
843 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
845 else if (app
->class &&
846 !g_pattern_match(app
->class,
847 strlen(self
->class), self
->class, NULL
))
849 else if (app
->role
&&
850 !g_pattern_match(app
->role
,
851 strlen(self
->role
), self
->role
, NULL
))
855 ob_debug("Window matching: %s", app
->name
);
857 /* copy the settings to our struct, overriding the existing
858 settings if they are not defaults */
859 config_app_settings_copy_non_defaults(app
, settings
);
863 if (settings
->shade
!= -1)
864 self
->shaded
= !!settings
->shade
;
865 if (settings
->decor
!= -1)
866 self
->undecorated
= !settings
->decor
;
867 if (settings
->iconic
!= -1)
868 self
->iconic
= !!settings
->iconic
;
869 if (settings
->skip_pager
!= -1)
870 self
->skip_pager
= !!settings
->skip_pager
;
871 if (settings
->skip_taskbar
!= -1)
872 self
->skip_taskbar
= !!settings
->skip_taskbar
;
874 if (settings
->max_vert
!= -1)
875 self
->max_vert
= !!settings
->max_vert
;
876 if (settings
->max_horz
!= -1)
877 self
->max_horz
= !!settings
->max_horz
;
879 if (settings
->fullscreen
!= -1)
880 self
->fullscreen
= !!settings
->fullscreen
;
882 if (settings
->desktop
) {
883 if (settings
->desktop
== DESKTOP_ALL
)
884 self
->desktop
= settings
->desktop
;
885 else if (settings
->desktop
> 0 &&
886 settings
->desktop
<= screen_num_desktops
)
887 self
->desktop
= settings
->desktop
- 1;
890 if (settings
->layer
== -1) {
894 else if (settings
->layer
== 0) {
898 else if (settings
->layer
== 1) {
905 static void client_restore_session_state(ObClient
*self
)
909 ob_debug_type(OB_DEBUG_SM
,
910 "Restore session for client %s", self
->title
);
912 if (!(it
= session_state_find(self
))) {
913 ob_debug_type(OB_DEBUG_SM
,
914 "Session data not found for client %s", self
->title
);
918 self
->session
= it
->data
;
920 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
923 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
924 self
->positioned
= USPosition
;
925 self
->sized
= USSize
;
926 if (self
->session
->w
> 0)
927 self
->area
.width
= self
->session
->w
;
928 if (self
->session
->h
> 0)
929 self
->area
.height
= self
->session
->h
;
930 XResizeWindow(obt_display
, self
->window
,
931 self
->area
.width
, self
->area
.height
);
933 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
934 self
->session
->desktop
:
935 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
936 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
938 self
->shaded
= self
->session
->shaded
;
939 self
->iconic
= self
->session
->iconic
;
940 self
->skip_pager
= self
->session
->skip_pager
;
941 self
->skip_taskbar
= self
->session
->skip_taskbar
;
942 self
->fullscreen
= self
->session
->fullscreen
;
943 self
->above
= self
->session
->above
;
944 self
->below
= self
->session
->below
;
945 self
->max_horz
= self
->session
->max_horz
;
946 self
->max_vert
= self
->session
->max_vert
;
947 self
->undecorated
= self
->session
->undecorated
;
950 static gboolean
client_restore_session_stacking(ObClient
*self
)
954 if (!self
->session
) return FALSE
;
956 mypos
= g_list_find(session_saved_state
, self
->session
);
957 if (!mypos
) return FALSE
;
959 /* start above me and look for the first client */
960 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
963 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
964 ObClient
*c
= cit
->data
;
965 /* found a client that was in the session, so go below it */
966 if (c
->session
== it
->data
) {
967 stacking_below(CLIENT_AS_WINDOW(self
),
968 CLIENT_AS_WINDOW(cit
->data
));
976 void client_move_onscreen(ObClient
*self
, gboolean rude
)
978 gint x
= self
->area
.x
;
979 gint y
= self
->area
.y
;
980 if (client_find_onscreen(self
, &x
, &y
,
982 self
->area
.height
, rude
)) {
983 client_move(self
, x
, y
);
987 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
990 gint ox
= *x
, oy
= *y
;
991 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
996 RECT_SET(desired
, *x
, *y
, w
, h
);
997 frame_rect_to_frame(self
->frame
, &desired
);
999 /* get where the frame would be */
1000 frame_client_gravity(self
->frame
, x
, y
);
1002 /* get the requested size of the window with decorations */
1003 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
1004 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
1006 /* If rudeness wasn't requested, then still be rude in a given direction
1007 if the client is not moving, only resizing in that direction */
1009 Point oldtl
, oldtr
, oldbl
, oldbr
;
1010 Point newtl
, newtr
, newbl
, newbr
;
1011 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
1013 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
1014 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1015 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1016 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1017 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1019 POINT_SET(newtl
, *x
, *y
);
1020 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1021 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1022 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1024 /* is it moving or just resizing from some corner? */
1025 stationary_l
= oldtl
.x
== newtl
.x
;
1026 stationary_r
= oldtr
.x
== newtr
.x
;
1027 stationary_t
= oldtl
.y
== newtl
.y
;
1028 stationary_b
= oldbl
.y
== newbl
.y
;
1030 /* if left edge is growing and didnt move right edge */
1031 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1033 /* if right edge is growing and didnt move left edge */
1034 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1036 /* if top edge is growing and didnt move bottom edge */
1037 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1039 /* if bottom edge is growing and didnt move top edge */
1040 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1044 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1047 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1048 if (i
< screen_num_monitors
- 1)
1051 /* the window is not inside any monitor! so just use the first
1053 a
= screen_area(self
->desktop
, 0, NULL
);
1055 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1057 /* This makes sure windows aren't entirely outside of the screen so you
1058 can't see them at all.
1059 It makes sure 10% of the window is on the screen at least. At don't
1060 let it move itself off the top of the screen, which would hide the
1061 titlebar on you. (The user can still do this if they want too, it's
1062 only limiting the application.
1064 if (client_normal(self
)) {
1065 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1066 *x
= a
->x
+ a
->width
- fw
/10;
1067 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1068 *y
= a
->y
+ a
->height
- fh
/10;
1069 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1070 *x
= a
->x
- fw
*9/10;
1071 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1072 *y
= a
->y
- fh
*9/10;
1075 /* This here doesn't let windows even a pixel outside the
1076 struts/screen. When called from client_manage, programs placing
1077 themselves are forced completely onscreen, while things like
1078 xterm -geometry resolution-width/2 will work fine. Trying to
1079 place it completely offscreen will be handled in the above code.
1080 Sorry for this confused comment, i am tired. */
1081 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1082 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1083 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1085 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1086 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1087 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1092 /* get where the client should be */
1093 frame_frame_gravity(self
->frame
, x
, y
);
1095 return ox
!= *x
|| oy
!= *y
;
1098 static void client_get_all(ObClient
*self
, gboolean real
)
1100 /* this is needed for the frame to set itself up */
1101 client_get_area(self
);
1103 /* these things can change the decor and functions of the window */
1105 client_get_mwm_hints(self
);
1106 /* this can change the mwmhints for special cases */
1107 client_get_type_and_transientness(self
);
1108 client_get_state(self
);
1109 client_update_normal_hints(self
);
1111 /* get the session related properties, these can change decorations
1112 from per-app settings */
1113 client_get_session_ids(self
);
1115 /* now we got everything that can affect the decorations */
1119 /* get this early so we have it for debugging */
1120 client_update_title(self
);
1122 client_update_protocols(self
);
1124 client_update_wmhints(self
);
1125 /* this may have already been called from client_update_wmhints */
1126 if (!self
->parents
&& !self
->transient_for_group
)
1127 client_update_transient_for(self
);
1129 client_get_startup_id(self
);
1130 client_get_desktop(self
);/* uses transient data/group/startup id if a
1131 desktop is not specified */
1132 client_get_shaped(self
);
1135 /* a couple type-based defaults for new windows */
1137 /* this makes sure that these windows appear on all desktops */
1138 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1139 self
->desktop
= DESKTOP_ALL
;
1143 client_update_sync_request_counter(self
);
1146 client_get_colormap(self
);
1147 client_update_strut(self
);
1148 client_update_icons(self
);
1149 client_update_icon_geometry(self
);
1152 static void client_get_startup_id(ObClient
*self
)
1154 if (!(OBT_PROP_GETS(self
->window
, NET_STARTUP_ID
, utf8
,
1155 &self
->startup_id
)))
1157 OBT_PROP_GETS(self
->group
->leader
,
1158 NET_STARTUP_ID
, utf8
, &self
->startup_id
);
1161 static void client_get_area(ObClient
*self
)
1163 XWindowAttributes wattrib
;
1166 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1167 g_assert(ret
!= BadWindow
);
1169 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1170 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1171 self
->border_width
= wattrib
.border_width
;
1173 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1174 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1177 static void client_get_desktop(ObClient
*self
)
1179 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1181 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1182 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1183 self
->desktop
= screen_num_desktops
- 1;
1186 ob_debug("client requested desktop 0x%x", self
->desktop
);
1189 gboolean first
= TRUE
;
1190 guint all
= screen_num_desktops
; /* not a valid value */
1192 /* if they are all on one desktop, then open it on the
1194 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1195 ObClient
*c
= it
->data
;
1197 if (c
->desktop
== DESKTOP_ALL
) continue;
1203 else if (all
!= c
->desktop
)
1204 all
= screen_num_desktops
; /* make it invalid */
1206 if (all
!= screen_num_desktops
) {
1207 self
->desktop
= all
;
1209 ob_debug("client desktop set from parents: 0x%x",
1212 /* try get from the startup-notification protocol */
1213 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1214 if (self
->desktop
>= screen_num_desktops
&&
1215 self
->desktop
!= DESKTOP_ALL
)
1216 self
->desktop
= screen_num_desktops
- 1;
1217 ob_debug("client desktop set from startup-notification: 0x%x",
1220 /* defaults to the current desktop */
1222 self
->desktop
= screen_desktop
;
1223 ob_debug("client desktop set to the current desktop: %d",
1229 static void client_get_state(ObClient
*self
)
1234 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1236 for (i
= 0; i
< num
; ++i
) {
1237 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1239 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1240 self
->shaded
= TRUE
;
1241 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1242 self
->iconic
= TRUE
;
1243 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1244 self
->skip_taskbar
= TRUE
;
1245 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1246 self
->skip_pager
= TRUE
;
1247 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1248 self
->fullscreen
= TRUE
;
1249 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1250 self
->max_vert
= TRUE
;
1251 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1252 self
->max_horz
= TRUE
;
1253 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1255 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1257 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1258 self
->demands_attention
= TRUE
;
1259 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1260 self
->undecorated
= TRUE
;
1267 static void client_get_shaped(ObClient
*self
)
1269 self
->shaped
= FALSE
;
1271 if (obt_display_extension_shape
) {
1276 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1278 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1279 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1281 self
->shaped
= (s
!= 0);
1286 void client_update_transient_for(ObClient
*self
)
1289 ObClient
*target
= NULL
;
1290 gboolean trangroup
= FALSE
;
1292 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1293 if (t
!= self
->window
) { /* cant be transient to itself! */
1294 ObWindow
*tw
= window_find(t
);
1295 /* if this happens then we need to check for it*/
1296 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1297 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1298 /* watch out for windows with a parent that is something
1299 different, like a dockapp for example */
1300 target
= WINDOW_AS_CLIENT(tw
);
1304 /* Setting the transient_for to Root is actually illegal, however
1305 applications from time have done this to specify transient for
1307 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1309 } else if (self
->group
&& self
->transient
)
1312 client_update_transient_tree(self
, self
->group
, self
->group
,
1313 self
->transient_for_group
, trangroup
,
1314 client_direct_parent(self
), target
);
1315 self
->transient_for_group
= trangroup
;
1319 static void client_update_transient_tree(ObClient
*self
,
1320 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1321 gboolean oldgtran
, gboolean newgtran
,
1322 ObClient
* oldparent
,
1323 ObClient
*newparent
)
1328 g_assert(!oldgtran
|| oldgroup
);
1329 g_assert(!newgtran
|| newgroup
);
1330 g_assert((!oldgtran
&& !oldparent
) ||
1331 (oldgtran
&& !oldparent
) ||
1332 (!oldgtran
&& oldparent
));
1333 g_assert((!newgtran
&& !newparent
) ||
1334 (newgtran
&& !newparent
) ||
1335 (!newgtran
&& newparent
));
1338 Group transient windows are not allowed to have other group
1339 transient windows as their children.
1343 /* No change has occured */
1344 if (oldgroup
== newgroup
&&
1345 oldgtran
== newgtran
&&
1346 oldparent
== newparent
) return;
1348 /** Remove the client from the transient tree **/
1350 for (it
= self
->transients
; it
; it
= next
) {
1351 next
= g_slist_next(it
);
1353 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1354 c
->parents
= g_slist_remove(c
->parents
, self
);
1356 for (it
= self
->parents
; it
; it
= next
) {
1357 next
= g_slist_next(it
);
1359 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1360 c
->transients
= g_slist_remove(c
->transients
, self
);
1363 /** Re-add the client to the transient tree **/
1365 /* If we're transient for a group then we need to add ourselves to all our
1368 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1371 !client_search_top_direct_parent(c
)->transient_for_group
&&
1374 c
->transients
= g_slist_prepend(c
->transients
, self
);
1375 self
->parents
= g_slist_prepend(self
->parents
, c
);
1380 /* If we are now transient for a single window we need to add ourselves to
1383 WARNING: Cyclical transient ness is possible if two windows are
1384 transient for eachother.
1386 else if (newparent
&&
1387 /* don't make ourself its child if it is already our child */
1388 !client_is_direct_child(self
, newparent
) &&
1389 client_normal(newparent
))
1391 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1392 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1395 /* Add any group transient windows to our children. But if we're transient
1396 for the group, then other group transients are not our children.
1398 WARNING: Cyclical transient-ness is possible. For e.g. if:
1399 A is transient for the group
1400 B is transient for A
1401 C is transient for B
1402 A can't be transient for C or we have a cycle
1404 if (!newgtran
&& newgroup
&&
1406 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1407 client_normal(self
))
1409 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1411 if (c
!= self
&& c
->transient_for_group
&&
1412 /* Don't make it our child if it is already our parent */
1413 !client_is_direct_child(c
, self
))
1415 self
->transients
= g_slist_prepend(self
->transients
, c
);
1416 c
->parents
= g_slist_prepend(c
->parents
, self
);
1421 /** If we change our group transient-ness, our children change their
1422 effect group transient-ness, which affects how they relate to other
1425 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1427 if (!c
->transient_for_group
)
1428 client_update_transient_tree(c
, c
->group
, c
->group
,
1429 c
->transient_for_group
,
1430 c
->transient_for_group
,
1431 client_direct_parent(c
),
1432 client_direct_parent(c
));
1436 static void client_get_mwm_hints(ObClient
*self
)
1441 self
->mwmhints
.flags
= 0; /* default to none */
1443 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1445 if (num
>= OB_MWM_ELEMENTS
) {
1446 self
->mwmhints
.flags
= hints
[0];
1447 self
->mwmhints
.functions
= hints
[1];
1448 self
->mwmhints
.decorations
= hints
[2];
1454 void client_get_type_and_transientness(ObClient
*self
)
1461 self
->transient
= FALSE
;
1463 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1464 /* use the first value that we know about in the array */
1465 for (i
= 0; i
< num
; ++i
) {
1466 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1467 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1468 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1469 self
->type
= OB_CLIENT_TYPE_DOCK
;
1470 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1471 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1472 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1473 self
->type
= OB_CLIENT_TYPE_MENU
;
1474 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1475 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1476 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1477 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1478 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1479 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1480 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1481 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1482 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1484 /* prevent this window from getting any decor or
1486 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1487 OB_MWM_FLAG_DECORATIONS
);
1488 self
->mwmhints
.decorations
= 0;
1489 self
->mwmhints
.functions
= 0;
1491 if (self
->type
!= (ObClientType
) -1)
1492 break; /* grab the first legit type */
1497 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1498 self
->transient
= TRUE
;
1500 if (self
->type
== (ObClientType
) -1) {
1501 /*the window type hint was not set, which means we either classify
1502 ourself as a normal window or a dialog, depending on if we are a
1504 if (self
->transient
)
1505 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1507 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1510 /* then, based on our type, we can update our transientness.. */
1511 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1512 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1513 self
->type
== OB_CLIENT_TYPE_MENU
||
1514 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1516 self
->transient
= TRUE
;
1520 void client_update_protocols(ObClient
*self
)
1525 self
->focus_notify
= FALSE
;
1526 self
->delete_window
= FALSE
;
1528 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1529 for (i
= 0; i
< num_ret
; ++i
) {
1530 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1531 /* this means we can request the window to close */
1532 self
->delete_window
= TRUE
;
1533 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1534 /* if this protocol is requested, then the window will be
1535 notified whenever we want it to receive focus */
1536 self
->focus_notify
= TRUE
;
1537 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1538 /* if this protocol is requested, then the window will allow
1539 pings to determine if it is still alive */
1542 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1543 /* if this protocol is requested, then resizing the
1544 window will be synchronized between the frame and the
1546 self
->sync_request
= TRUE
;
1554 void client_update_sync_request_counter(ObClient
*self
)
1558 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1560 self
->sync_counter
= i
;
1562 self
->sync_counter
= None
;
1566 static void client_get_colormap(ObClient
*self
)
1568 XWindowAttributes wa
;
1570 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1571 client_update_colormap(self
, wa
.colormap
);
1574 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1576 if (colormap
== self
->colormap
) return;
1578 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1580 if (client_focused(self
)) {
1581 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1582 self
->colormap
= colormap
;
1583 screen_install_colormap(self
, FALSE
); /* install new one */
1585 self
->colormap
= colormap
;
1588 void client_update_normal_hints(ObClient
*self
)
1594 self
->min_ratio
= 0.0f
;
1595 self
->max_ratio
= 0.0f
;
1596 SIZE_SET(self
->size_inc
, 1, 1);
1597 SIZE_SET(self
->base_size
, 0, 0);
1598 SIZE_SET(self
->min_size
, 0, 0);
1599 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1601 /* get the hints from the window */
1602 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1603 /* normal windows can't request placement! har har
1604 if (!client_normal(self))
1606 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1607 self
->sized
= (size
.flags
& (PSize
|USSize
));
1609 if (size
.flags
& PWinGravity
)
1610 self
->gravity
= size
.win_gravity
;
1612 if (size
.flags
& PAspect
) {
1613 if (size
.min_aspect
.y
)
1615 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1616 if (size
.max_aspect
.y
)
1618 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1621 if (size
.flags
& PMinSize
)
1622 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1624 if (size
.flags
& PMaxSize
)
1625 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1627 if (size
.flags
& PBaseSize
)
1628 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1630 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1631 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1633 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1634 self
->min_size
.width
, self
->min_size
.height
,
1635 self
->max_size
.width
, self
->max_size
.height
);
1636 ob_debug("size inc (%d %d) base size (%d %d)",
1637 self
->size_inc
.width
, self
->size_inc
.height
,
1638 self
->base_size
.width
, self
->base_size
.height
);
1641 ob_debug("Normal hints: not set");
1644 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1646 /* start with everything (cept fullscreen) */
1648 (OB_FRAME_DECOR_TITLEBAR
|
1649 OB_FRAME_DECOR_HANDLE
|
1650 OB_FRAME_DECOR_GRIPS
|
1651 OB_FRAME_DECOR_BORDER
|
1652 OB_FRAME_DECOR_ICON
|
1653 OB_FRAME_DECOR_ALLDESKTOPS
|
1654 OB_FRAME_DECOR_ICONIFY
|
1655 OB_FRAME_DECOR_MAXIMIZE
|
1656 OB_FRAME_DECOR_SHADE
|
1657 OB_FRAME_DECOR_CLOSE
);
1659 (OB_CLIENT_FUNC_RESIZE
|
1660 OB_CLIENT_FUNC_MOVE
|
1661 OB_CLIENT_FUNC_ICONIFY
|
1662 OB_CLIENT_FUNC_MAXIMIZE
|
1663 OB_CLIENT_FUNC_SHADE
|
1664 OB_CLIENT_FUNC_CLOSE
|
1665 OB_CLIENT_FUNC_BELOW
|
1666 OB_CLIENT_FUNC_ABOVE
|
1667 OB_CLIENT_FUNC_UNDECORATE
);
1669 if (!(self
->min_size
.width
< self
->max_size
.width
||
1670 self
->min_size
.height
< self
->max_size
.height
))
1671 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1673 switch (self
->type
) {
1674 case OB_CLIENT_TYPE_NORMAL
:
1675 /* normal windows retain all of the possible decorations and
1676 functionality, and can be fullscreen */
1677 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1680 case OB_CLIENT_TYPE_DIALOG
:
1681 /* sometimes apps make dialog windows fullscreen for some reason (for
1682 e.g. kpdf does this..) */
1683 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1686 case OB_CLIENT_TYPE_UTILITY
:
1687 /* these windows don't have anything added or removed by default */
1690 case OB_CLIENT_TYPE_MENU
:
1691 case OB_CLIENT_TYPE_TOOLBAR
:
1692 /* these windows can't iconify or maximize */
1693 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1694 OB_FRAME_DECOR_MAXIMIZE
);
1695 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1696 OB_CLIENT_FUNC_MAXIMIZE
);
1699 case OB_CLIENT_TYPE_SPLASH
:
1700 /* these don't get get any decorations, and the only thing you can
1701 do with them is move them */
1702 self
->decorations
= 0;
1703 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1706 case OB_CLIENT_TYPE_DESKTOP
:
1707 /* these windows are not manipulated by the window manager */
1708 self
->decorations
= 0;
1709 self
->functions
= 0;
1712 case OB_CLIENT_TYPE_DOCK
:
1713 /* these windows are not manipulated by the window manager, but they
1714 can set below layer which has a special meaning */
1715 self
->decorations
= 0;
1716 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1720 /* Mwm Hints are applied subtractively to what has already been chosen for
1721 decor and functionality */
1722 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1723 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1724 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1725 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1727 /* if the mwm hints request no handle or title, then all
1728 decorations are disabled, but keep the border if that's
1730 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1731 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1733 self
->decorations
= 0;
1738 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1739 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1740 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1741 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1742 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1743 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1744 /* dont let mwm hints kill any buttons
1745 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1746 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1747 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1748 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1750 /* dont let mwm hints kill the close button
1751 if (! (self->mwmhints.functions & MwmFunc_Close))
1752 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1756 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1757 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1758 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1759 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1760 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1761 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1763 /* can't maximize without moving/resizing */
1764 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1765 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1766 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1767 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1768 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1771 if (self
->max_horz
&& self
->max_vert
) {
1772 /* you can't resize fully maximized windows */
1773 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1774 /* kill the handle on fully maxed windows */
1775 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1778 /* If there are no decorations to remove, don't allow the user to try
1780 if (self
->decorations
== 0)
1781 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1783 /* finally, the user can have requested no decorations, which overrides
1784 everything (but doesnt give it a border if it doesnt have one) */
1785 if (self
->undecorated
)
1786 self
->decorations
= 0;
1788 /* if we don't have a titlebar, then we cannot shade! */
1789 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1790 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1792 /* now we need to check against rules for the client's current state */
1793 if (self
->fullscreen
) {
1794 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1795 OB_CLIENT_FUNC_FULLSCREEN
|
1796 OB_CLIENT_FUNC_ICONIFY
);
1797 self
->decorations
= 0;
1800 client_change_allowed_actions(self
);
1803 /* force reconfigure to make sure decorations are updated */
1804 client_reconfigure(self
, TRUE
);
1807 static void client_change_allowed_actions(ObClient
*self
)
1812 /* desktop windows are kept on all desktops */
1813 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1814 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1816 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1817 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1818 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1819 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1820 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1821 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1822 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1823 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1824 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1825 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1826 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1827 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1828 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1829 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1830 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1832 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1833 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1834 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1835 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1836 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1837 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1839 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1841 /* make sure the window isn't breaking any rules now
1843 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1844 it can't be iconified with its parent
1847 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1848 if (self
->frame
) client_shade(self
, FALSE
);
1849 else self
->shaded
= FALSE
;
1851 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1852 if (self
->frame
) client_fullscreen(self
, FALSE
);
1853 else self
->fullscreen
= FALSE
;
1855 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1857 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1858 else self
->max_vert
= self
->max_horz
= FALSE
;
1862 void client_update_wmhints(ObClient
*self
)
1866 /* assume a window takes input if it doesnt specify */
1867 self
->can_focus
= TRUE
;
1869 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1872 if (hints
->flags
& InputHint
)
1873 self
->can_focus
= hints
->input
;
1875 /* only do this when first managing the window *AND* when we aren't
1877 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1878 if (hints
->flags
& StateHint
)
1879 self
->iconic
= hints
->initial_state
== IconicState
;
1882 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1883 if (self
->urgent
&& !ur
)
1884 client_hilite(self
, TRUE
);
1885 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1886 client_hilite(self
, FALSE
);
1888 if (!(hints
->flags
& WindowGroupHint
))
1889 hints
->window_group
= None
;
1891 /* did the group state change? */
1892 if (hints
->window_group
!=
1893 (self
->group
? self
->group
->leader
: None
))
1895 ObGroup
*oldgroup
= self
->group
;
1897 /* remove from the old group if there was one */
1898 if (self
->group
!= NULL
) {
1899 group_remove(self
->group
, self
);
1903 /* add ourself to the group if we have one */
1904 if (hints
->window_group
!= None
) {
1905 self
->group
= group_add(hints
->window_group
, self
);
1908 /* Put ourselves into the new group's transient tree, and remove
1909 ourselves from the old group's */
1910 client_update_transient_tree(self
, oldgroup
, self
->group
,
1911 self
->transient_for_group
,
1912 self
->transient_for_group
,
1913 client_direct_parent(self
),
1914 client_direct_parent(self
));
1916 /* Lastly, being in a group, or not, can change if the window is
1917 transient for anything.
1919 The logic for this is:
1920 self->transient = TRUE always if the window wants to be
1921 transient for something, even if transient_for was NULL because
1922 it wasn't in a group before.
1924 If parents was NULL and oldgroup was NULL we can assume
1925 that when we add the new group, it will become transient for
1928 If transient_for_group is TRUE, then it must have already
1929 had a group. If it is getting a new group, the above call to
1930 client_update_transient_tree has already taken care of
1931 everything ! If it is losing all group status then it will
1932 no longer be transient for anything and that needs to be
1935 if (self
->transient
&&
1936 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1937 (self
->transient_for_group
&& !self
->group
)))
1938 client_update_transient_for(self
);
1941 /* the WM_HINTS can contain an icon */
1942 if (hints
->flags
& IconPixmapHint
)
1943 client_update_icons(self
);
1949 void client_update_title(ObClient
*self
)
1952 gchar
*visible
= NULL
;
1954 g_free(self
->title
);
1957 if (!OBT_PROP_GETS(self
->window
, NET_WM_NAME
, utf8
, &data
)) {
1958 /* try old x stuff */
1959 if (!(OBT_PROP_GETS(self
->window
, WM_NAME
, locale
, &data
)
1960 || OBT_PROP_GETS(self
->window
, WM_NAME
, utf8
, &data
))) {
1961 if (self
->transient
) {
1963 GNOME alert windows are not given titles:
1964 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1966 data
= g_strdup("");
1968 data
= g_strdup("Unnamed Window");
1972 if (self
->client_machine
) {
1973 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1978 if (self
->not_responding
) {
1980 if (self
->close_tried_term
)
1981 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1983 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1987 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, utf8
, visible
);
1988 self
->title
= visible
;
1991 frame_adjust_title(self
->frame
);
1993 /* update the icon title */
1995 g_free(self
->icon_title
);
1998 if (!OBT_PROP_GETS(self
->window
, NET_WM_ICON_NAME
, utf8
, &data
))
1999 /* try old x stuff */
2000 if (!(OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, locale
, &data
) ||
2001 OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, utf8
, &data
)))
2002 data
= g_strdup(self
->title
);
2004 if (self
->client_machine
) {
2005 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2010 if (self
->not_responding
) {
2012 if (self
->close_tried_term
)
2013 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2015 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2019 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, utf8
, visible
);
2020 self
->icon_title
= visible
;
2023 void client_update_strut(ObClient
*self
)
2027 gboolean got
= FALSE
;
2030 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
2035 STRUT_PARTIAL_SET(strut
,
2036 data
[0], data
[2], data
[1], data
[3],
2037 data
[4], data
[5], data
[8], data
[9],
2038 data
[6], data
[7], data
[10], data
[11]);
2044 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
2050 /* use the screen's width/height */
2051 a
= screen_physical_area_all_monitors();
2053 STRUT_PARTIAL_SET(strut
,
2054 data
[0], data
[2], data
[1], data
[3],
2055 a
->y
, a
->y
+ a
->height
- 1,
2056 a
->x
, a
->x
+ a
->width
- 1,
2057 a
->y
, a
->y
+ a
->height
- 1,
2058 a
->x
, a
->x
+ a
->width
- 1);
2065 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2066 0, 0, 0, 0, 0, 0, 0, 0);
2068 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2069 self
->strut
= strut
;
2071 /* updating here is pointless while we're being mapped cuz we're not in
2072 the client list yet */
2074 screen_update_areas();
2078 /* Avoid storing icons above this size if possible */
2079 #define AVOID_ABOVE 64
2081 void client_update_icons(ObClient
*self
)
2086 guint num_seen
; /* number of icons present */
2087 guint num_small_seen
; /* number of icons small enough present */
2088 guint smallest
, smallest_area
;
2090 for (i
= 0; i
< self
->nicons
; ++i
)
2091 g_free(self
->icons
[i
].data
);
2092 if (self
->nicons
> 0)
2093 g_free(self
->icons
);
2096 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2097 /* figure out how many valid icons are in here */
2099 num_seen
= num_small_seen
= 0;
2100 smallest
= smallest_area
= 0;
2106 /* watch for it being too small for the specified size, or for
2107 zero sized icons. */
2108 if (i
> num
|| w
== 0 || h
== 0) break;
2110 if (!smallest_area
|| w
*h
< smallest_area
) {
2111 smallest
= num_seen
;
2112 smallest_area
= w
*h
;
2115 if (w
<= AVOID_ABOVE
&& h
<= AVOID_ABOVE
)
2118 if (num_small_seen
> 0)
2119 self
->nicons
= num_small_seen
;
2123 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2125 /* store the icons */
2127 for (j
= 0; j
< self
->nicons
;) {
2130 w
= self
->icons
[j
].width
= data
[i
++];
2131 h
= self
->icons
[j
].height
= data
[i
++];
2133 /* if there are some icons smaller than the threshold, we're
2134 skipping all the ones above */
2135 if (num_small_seen
> 0) {
2136 if (w
> AVOID_ABOVE
|| h
> AVOID_ABOVE
) {
2141 /* if there were no icons smaller than the threshold, then we are
2142 only taking the smallest available one we saw */
2143 else if (j
!= smallest
) {
2148 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2149 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2154 self
->icons
[j
].data
[t
] =
2155 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2156 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2157 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2158 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2169 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2170 if (hints
->flags
& IconPixmapHint
) {
2172 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2173 obt_display_ignore_errors(TRUE
);
2174 if (!RrPixmapToRGBA(ob_rr_inst
,
2176 (hints
->flags
& IconMaskHint
?
2177 hints
->icon_mask
: None
),
2178 &self
->icons
[0].width
,
2179 &self
->icons
[0].height
,
2180 &self
->icons
[0].data
))
2182 g_free(self
->icons
);
2185 obt_display_ignore_errors(FALSE
);
2191 /* set the default icon onto the window
2192 in theory, this could be a race, but if a window doesn't set an icon
2193 or removes it entirely, it's not very likely it is going to set one
2194 right away afterwards
2196 if it has parents, then one of them will have an icon already
2198 if (self
->nicons
== 0 && !self
->parents
) {
2199 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2202 data
= g_new(gulong
, 48*48+2);
2203 data
[0] = data
[1] = 48;
2204 for (i
= 0; i
< 48*48; ++i
)
2205 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2206 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2207 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2208 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2209 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, data
, 48*48+2);
2211 } else if (self
->frame
)
2212 /* don't draw the icon empty if we're just setting one now anyways,
2213 we'll get the property change any second */
2214 frame_adjust_icon(self
->frame
);
2217 void client_update_icon_geometry(ObClient
*self
)
2222 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2224 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2228 /* don't let them set it with an area < 0 */
2229 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2230 MAX(data
[2],0), MAX(data
[3],0));
2235 static void client_get_session_ids(ObClient
*self
)
2242 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2245 /* get the SM_CLIENT_ID */
2248 got
= OBT_PROP_GETS(leader
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2250 OBT_PROP_GETS(self
->window
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2252 /* get the WM_CLASS (name and class). make them "" if they are not
2256 got
= OBT_PROP_GETSS(leader
, WM_CLASS
, locale
, &ss
);
2258 got
= OBT_PROP_GETSS(self
->window
, WM_CLASS
, locale
, &ss
);
2262 self
->name
= g_strdup(ss
[0]);
2264 self
->class = g_strdup(ss
[1]);
2269 if (self
->name
== NULL
) self
->name
= g_strdup("");
2270 if (self
->class == NULL
) self
->class = g_strdup("");
2272 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2275 got
= OBT_PROP_GETS(leader
, WM_WINDOW_ROLE
, locale
, &s
);
2277 got
= OBT_PROP_GETS(self
->window
, WM_WINDOW_ROLE
, locale
, &s
);
2282 self
->role
= g_strdup("");
2284 /* get the WM_COMMAND */
2288 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, locale
, &ss
);
2290 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, locale
, &ss
);
2293 /* merge/mash them all together */
2294 gchar
*merge
= NULL
;
2297 for (i
= 0; ss
[i
]; ++i
) {
2300 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2302 merge
= g_strconcat(ss
[i
], NULL
);
2307 self
->wm_command
= merge
;
2310 /* get the WM_CLIENT_MACHINE */
2313 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, locale
, &s
);
2315 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, locale
, &s
);
2318 gchar localhost
[128];
2321 gethostname(localhost
, 127);
2322 localhost
[127] = '\0';
2323 if (strcmp(localhost
, s
) != 0)
2324 self
->client_machine
= s
;
2328 /* see if it has the PID set too (the PID requires that the
2329 WM_CLIENT_MACHINE be set) */
2330 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2335 static void client_change_wm_state(ObClient
*self
)
2340 old
= self
->wmstate
;
2342 if (self
->shaded
|| self
->iconic
||
2343 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2345 self
->wmstate
= IconicState
;
2347 self
->wmstate
= NormalState
;
2349 if (old
!= self
->wmstate
) {
2350 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2351 self
->wmstate
, 1, 0, 0, 0);
2353 state
[0] = self
->wmstate
;
2355 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2359 static void client_change_state(ObClient
*self
)
2361 gulong netstate
[12];
2366 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2368 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2370 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2371 if (self
->skip_taskbar
)
2372 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2373 if (self
->skip_pager
)
2374 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2375 if (self
->fullscreen
)
2376 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2378 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2380 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2382 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2384 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2385 if (self
->demands_attention
)
2386 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2387 if (self
->undecorated
)
2388 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2389 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2392 frame_adjust_state(self
->frame
);
2395 ObClient
*client_search_focus_tree(ObClient
*self
)
2400 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2401 if (client_focused(it
->data
)) return it
->data
;
2402 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2407 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2409 if (self
->parents
) {
2412 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2413 ObClient
*c
= it
->data
;
2414 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2420 /* this function checks the whole tree, the client_search_focus_tree
2421 does not, so we need to check this window */
2422 if (client_focused(self
))
2424 return client_search_focus_tree(self
);
2428 ObClient
*client_search_focus_group_full(ObClient
*self
)
2433 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2434 ObClient
*c
= it
->data
;
2436 if (client_focused(c
)) return c
;
2437 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2440 if (client_focused(self
)) return self
;
2444 gboolean
client_has_parent(ObClient
*self
)
2446 return self
->parents
!= NULL
;
2449 static ObStackingLayer
calc_layer(ObClient
*self
)
2454 monitor
= screen_physical_area_monitor(client_monitor(self
));
2456 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2457 l
= OB_STACKING_LAYER_DESKTOP
;
2458 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2459 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2460 else l
= OB_STACKING_LAYER_ABOVE
;
2462 else if ((self
->fullscreen
||
2463 /* No decorations and fills the monitor = oldskool fullscreen.
2464 But not for maximized windows.
2466 (self
->decorations
== 0 &&
2467 !(self
->max_horz
&& self
->max_vert
) &&
2468 RECT_EQUAL(self
->area
, *monitor
))) &&
2469 (client_focused(self
) || client_search_focus_tree(self
)))
2470 l
= OB_STACKING_LAYER_FULLSCREEN
;
2471 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2472 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2473 else l
= OB_STACKING_LAYER_NORMAL
;
2480 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2481 ObStackingLayer min
)
2483 ObStackingLayer old
, own
;
2487 own
= calc_layer(self
);
2488 self
->layer
= MAX(own
, min
);
2490 if (self
->layer
!= old
) {
2491 stacking_remove(CLIENT_AS_WINDOW(self
));
2492 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2495 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2496 client_calc_layer_recursive(it
->data
, orig
,
2500 void client_calc_layer(ObClient
*self
)
2507 /* transients take on the layer of their parents */
2508 it
= client_search_all_top_parents(self
);
2510 for (; it
; it
= g_slist_next(it
))
2511 client_calc_layer_recursive(it
->data
, orig
, 0);
2514 gboolean
client_should_show(ObClient
*self
)
2518 if (client_normal(self
) && screen_showing_desktop
)
2520 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2526 gboolean
client_show(ObClient
*self
)
2528 gboolean show
= FALSE
;
2530 if (client_should_show(self
)) {
2531 frame_show(self
->frame
);
2534 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2535 it needs to be in IconicState. This includes when it is on another
2538 client_change_wm_state(self
);
2543 gboolean
client_hide(ObClient
*self
)
2545 gboolean hide
= FALSE
;
2547 if (!client_should_show(self
)) {
2548 if (self
== focus_client
) {
2549 /* if there is a grab going on, then we need to cancel it. if we
2550 move focus during the grab, applications will get
2551 NotifyWhileGrabbed events and ignore them !
2553 actions should not rely on being able to move focus during an
2556 event_cancel_all_key_grabs();
2559 /* We don't need to ignore enter events here.
2560 The window can hide/iconify in 3 different ways:
2561 1 - through an x message. in this case we ignore all enter events
2562 caused by responding to the x message (unless underMouse)
2563 2 - by a keyboard action. in this case we ignore all enter events
2564 caused by the action
2565 3 - by a mouse action. in this case they are doing stuff with the
2566 mouse and focus _should_ move.
2568 Also in action_end, we simulate an enter event that can't be ignored
2569 so trying to ignore them is futile in case 3 anyways
2572 frame_hide(self
->frame
);
2575 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2576 it needs to be in IconicState. This includes when it is on another
2579 client_change_wm_state(self
);
2584 void client_showhide(ObClient
*self
)
2586 if (!client_show(self
))
2590 gboolean
client_normal(ObClient
*self
) {
2591 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2592 self
->type
== OB_CLIENT_TYPE_DOCK
||
2593 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2596 gboolean
client_helper(ObClient
*self
)
2598 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2599 self
->type
== OB_CLIENT_TYPE_MENU
||
2600 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2603 gboolean
client_mouse_focusable(ObClient
*self
)
2605 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2606 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2607 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2608 self
->type
== OB_CLIENT_TYPE_DOCK
);
2611 gboolean
client_enter_focusable(ObClient
*self
)
2613 /* you can focus desktops but it shouldn't on enter */
2614 return (client_mouse_focusable(self
) &&
2615 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2619 static void client_apply_startup_state(ObClient
*self
,
2620 gint x
, gint y
, gint w
, gint h
)
2622 /* save the states that we are going to apply */
2623 gboolean iconic
= self
->iconic
;
2624 gboolean fullscreen
= self
->fullscreen
;
2625 gboolean undecorated
= self
->undecorated
;
2626 gboolean shaded
= self
->shaded
;
2627 gboolean demands_attention
= self
->demands_attention
;
2628 gboolean max_horz
= self
->max_horz
;
2629 gboolean max_vert
= self
->max_vert
;
2633 /* turn them all off in the client, so they won't affect the window
2635 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2636 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2638 /* move the client to its placed position, or it it's already there,
2639 generate a ConfigureNotify telling the client where it is.
2641 do this after adjusting the frame. otherwise it gets all weird and
2642 clients don't work right
2644 do this before applying the states so they have the correct
2645 pre-max/pre-fullscreen values
2647 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2648 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2649 self
->window
, x
, y
, w
, h
);
2650 /* save the area, and make it where it should be for the premax stuff */
2651 oldarea
= self
->area
;
2652 RECT_SET(self
->area
, x
, y
, w
, h
);
2654 /* apply the states. these are in a carefully crafted order.. */
2657 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2659 client_fullscreen(self
, TRUE
);
2661 client_set_undecorated(self
, TRUE
);
2663 client_shade(self
, TRUE
);
2664 if (demands_attention
)
2665 client_hilite(self
, TRUE
);
2667 if (max_vert
&& max_horz
)
2668 client_maximize(self
, TRUE
, 0);
2670 client_maximize(self
, TRUE
, 2);
2672 client_maximize(self
, TRUE
, 1);
2674 /* if the window hasn't been configured yet, then do so now, in fact the
2675 x,y,w,h may _not_ be the same as the area rect, which can end up
2676 meaning that the client isn't properly moved/resized by the fullscreen
2678 pho can cause this because it maps at size of the screen but not 0,0
2679 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2680 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2681 cuz thats where the pre-fullscreen will be. however the actual area is
2682 not, so this needs to be called even if we have fullscreened/maxed
2684 self
->area
= oldarea
;
2685 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2687 /* set the desktop hint, to make sure that it always exists */
2688 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
2690 /* nothing to do for the other states:
2699 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2701 /* these should be the current values. this is for when you're not moving,
2703 g_assert(*x
== self
->area
.x
);
2704 g_assert(oldw
== self
->area
.width
);
2707 switch (self
->gravity
) {
2709 case NorthWestGravity
:
2711 case SouthWestGravity
:
2718 *x
-= (neww
- oldw
) / 2;
2720 case NorthEastGravity
:
2722 case SouthEastGravity
:
2728 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2730 /* these should be the current values. this is for when you're not moving,
2732 g_assert(*y
== self
->area
.y
);
2733 g_assert(oldh
== self
->area
.height
);
2736 switch (self
->gravity
) {
2738 case NorthWestGravity
:
2740 case NorthEastGravity
:
2747 *y
-= (newh
- oldh
) / 2;
2749 case SouthWestGravity
:
2751 case SouthEastGravity
:
2757 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2758 gint
*logicalw
, gint
*logicalh
,
2761 Rect desired
= {*x
, *y
, *w
, *h
};
2762 frame_rect_to_frame(self
->frame
, &desired
);
2764 /* make the frame recalculate its dimentions n shit without changing
2765 anything visible for real, this way the constraints below can work with
2766 the updated frame dimensions. */
2767 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2769 /* gets the frame's position */
2770 frame_client_gravity(self
->frame
, x
, y
);
2772 /* these positions are frame positions, not client positions */
2774 /* set the size and position if fullscreen */
2775 if (self
->fullscreen
) {
2779 i
= screen_find_monitor(&desired
);
2780 a
= screen_physical_area_monitor(i
);
2787 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2791 } else if (self
->max_horz
|| self
->max_vert
) {
2795 /* use all possible struts when maximizing to the full screen */
2796 i
= screen_find_monitor(&desired
);
2797 a
= screen_area(self
->desktop
, i
,
2798 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2800 /* set the size and position if maximized */
2801 if (self
->max_horz
) {
2803 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2805 if (self
->max_vert
) {
2807 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2810 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2816 /* gets the client's position */
2817 frame_frame_gravity(self
->frame
, x
, y
);
2819 /* work within the prefered sizes given by the window */
2820 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2821 gint basew
, baseh
, minw
, minh
;
2823 gfloat minratio
, maxratio
;
2825 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2826 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2827 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2828 0 : self
->min_ratio
;
2829 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2830 0 : self
->max_ratio
;
2832 /* base size is substituted with min size if not specified */
2833 if (self
->base_size
.width
|| self
->base_size
.height
) {
2834 basew
= self
->base_size
.width
;
2835 baseh
= self
->base_size
.height
;
2837 basew
= self
->min_size
.width
;
2838 baseh
= self
->min_size
.height
;
2840 /* min size is substituted with base size if not specified */
2841 if (self
->min_size
.width
|| self
->min_size
.height
) {
2842 minw
= self
->min_size
.width
;
2843 minh
= self
->min_size
.height
;
2845 minw
= self
->base_size
.width
;
2846 minh
= self
->base_size
.height
;
2849 /* if this is a user-requested resize, then check against min/max
2852 /* smaller than min size or bigger than max size? */
2853 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2854 if (*w
< minw
) *w
= minw
;
2855 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2856 if (*h
< minh
) *h
= minh
;
2861 /* keep to the increments */
2865 /* you cannot resize to nothing */
2866 if (basew
+ *w
< 1) *w
= 1 - basew
;
2867 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2869 /* save the logical size */
2870 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2871 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2879 /* adjust the height to match the width for the aspect ratios.
2880 for this, min size is not substituted for base size ever. */
2881 *w
-= self
->base_size
.width
;
2882 *h
-= self
->base_size
.height
;
2885 if (*h
* minratio
> *w
) {
2886 *h
= (gint
)(*w
/ minratio
);
2888 /* you cannot resize to nothing */
2891 *w
= (gint
)(*h
* minratio
);
2895 if (*h
* maxratio
< *w
) {
2896 *h
= (gint
)(*w
/ maxratio
);
2898 /* you cannot resize to nothing */
2901 *w
= (gint
)(*h
* minratio
);
2905 *w
+= self
->base_size
.width
;
2906 *h
+= self
->base_size
.height
;
2909 /* these override the above states! if you cant move you can't move! */
2911 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2915 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2916 *w
= self
->area
.width
;
2917 *h
= self
->area
.height
;
2926 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2927 gboolean user
, gboolean final
, gboolean force_reply
)
2930 gboolean send_resize_client
;
2931 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2932 gboolean fmoved
, fresized
;
2933 guint fdecor
= self
->frame
->decorations
;
2934 gboolean fhorz
= self
->frame
->max_horz
;
2935 gboolean fvert
= self
->frame
->max_vert
;
2936 gint logicalw
, logicalh
;
2938 /* find the new x, y, width, and height (and logical size) */
2939 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2941 /* set the logical size if things changed */
2942 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2943 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2945 /* figure out if we moved or resized or what */
2946 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2947 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2949 oldw
= self
->area
.width
;
2950 oldh
= self
->area
.height
;
2951 RECT_SET(self
->area
, x
, y
, w
, h
);
2953 /* for app-requested resizes, always resize if 'resized' is true.
2954 for user-requested ones, only resize if final is true, or when
2955 resizing in redraw mode */
2956 send_resize_client
= ((!user
&& resized
) ||
2958 (resized
&& config_resize_redraw
))));
2960 /* if the client is enlarging, then resize the client before the frame */
2961 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2962 XMoveResizeWindow(obt_display
, self
->window
,
2963 self
->frame
->size
.left
, self
->frame
->size
.top
,
2964 MAX(w
, oldw
), MAX(h
, oldh
));
2965 frame_adjust_client_area(self
->frame
);
2968 /* find the frame's dimensions and move/resize it */
2972 /* if decorations changed, then readjust everything for the frame */
2973 if (self
->decorations
!= fdecor
||
2974 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2976 fmoved
= fresized
= TRUE
;
2979 /* adjust the frame */
2980 if (fmoved
|| fresized
) {
2981 gulong ignore_start
;
2983 ignore_start
= event_start_ignore_all_enters();
2985 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2988 event_end_ignore_all_enters(ignore_start
);
2991 if (!user
|| final
) {
2992 gint oldrx
= self
->root_pos
.x
;
2993 gint oldry
= self
->root_pos
.y
;
2994 /* we have reset the client to 0 border width, so don't include
2995 it in these coords */
2996 POINT_SET(self
->root_pos
,
2997 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2999 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3000 self
->border_width
);
3001 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3005 /* This is kinda tricky and should not be changed.. let me explain!
3007 When user = FALSE, then the request is coming from the application
3008 itself, and we are more strict about when to send a synthetic
3009 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3010 in this case (if force_reply is true)
3012 When user = TRUE, then the request is coming from "us", like when we
3013 maximize a window or something. In this case we are more lenient. We
3014 used to follow the same rules as above, but _Java_ Swing can't handle
3015 this. So just to appease Swing, when user = TRUE, we always send
3016 a synthetic ConfigureNotify to give the window its root coordinates.
3018 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3019 (user
&& final
&& rootmoved
))
3023 event
.type
= ConfigureNotify
;
3024 event
.xconfigure
.display
= obt_display
;
3025 event
.xconfigure
.event
= self
->window
;
3026 event
.xconfigure
.window
= self
->window
;
3028 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3029 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3031 /* root window real coords */
3032 event
.xconfigure
.x
= self
->root_pos
.x
;
3033 event
.xconfigure
.y
= self
->root_pos
.y
;
3034 event
.xconfigure
.width
= w
;
3035 event
.xconfigure
.height
= h
;
3036 event
.xconfigure
.border_width
= self
->border_width
;
3037 event
.xconfigure
.above
= None
;
3038 event
.xconfigure
.override_redirect
= FALSE
;
3039 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3040 FALSE
, StructureNotifyMask
, &event
);
3043 /* if the client is shrinking, then resize the frame before the client.
3045 both of these resize sections may run, because the top one only resizes
3046 in the direction that is growing
3048 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3049 frame_adjust_client_area(self
->frame
);
3050 XMoveResizeWindow(obt_display
, self
->window
,
3051 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3054 XFlush(obt_display
);
3057 void client_fullscreen(ObClient
*self
, gboolean fs
)
3061 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3062 self
->fullscreen
== fs
) return; /* already done */
3064 self
->fullscreen
= fs
;
3065 client_change_state(self
); /* change the state hints on the client */
3068 self
->pre_fullscreen_area
= self
->area
;
3069 /* if the window is maximized, its area isn't all that meaningful.
3070 save it's premax area instead. */
3071 if (self
->max_horz
) {
3072 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3073 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3075 if (self
->max_vert
) {
3076 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3077 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3080 /* these will help configure_full figure out where to fullscreen
3084 w
= self
->area
.width
;
3085 h
= self
->area
.height
;
3087 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3088 self
->pre_fullscreen_area
.height
> 0);
3090 x
= self
->pre_fullscreen_area
.x
;
3091 y
= self
->pre_fullscreen_area
.y
;
3092 w
= self
->pre_fullscreen_area
.width
;
3093 h
= self
->pre_fullscreen_area
.height
;
3094 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3097 ob_debug("Window %s going fullscreen (%d)",
3098 self
->title
, self
->fullscreen
);
3100 client_setup_decor_and_functions(self
, FALSE
);
3101 client_move_resize(self
, x
, y
, w
, h
);
3103 /* and adjust our layer/stacking. do this after resizing the window,
3104 and applying decorations, because windows which fill the screen are
3105 considered "fullscreen" and it affects their layer */
3106 client_calc_layer(self
);
3109 /* try focus us when we go into fullscreen mode */
3114 static void client_iconify_recursive(ObClient
*self
,
3115 gboolean iconic
, gboolean curdesk
,
3116 gboolean hide_animation
)
3119 gboolean changed
= FALSE
;
3122 if (self
->iconic
!= iconic
) {
3123 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3127 /* don't let non-normal windows iconify along with their parents
3129 if (client_normal(self
)) {
3130 self
->iconic
= iconic
;
3132 /* update the focus lists.. iconic windows go to the bottom of
3134 focus_order_to_bottom(self
);
3139 self
->iconic
= iconic
;
3141 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3142 self
->desktop
!= DESKTOP_ALL
)
3143 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3145 /* this puts it after the current focused window */
3146 focus_order_remove(self
);
3147 focus_order_add_new(self
);
3154 client_change_state(self
);
3155 if (config_animate_iconify
&& !hide_animation
)
3156 frame_begin_iconify_animation(self
->frame
, iconic
);
3157 /* do this after starting the animation so it doesn't flash */
3158 client_showhide(self
);
3161 /* iconify all direct transients, and deiconify all transients
3163 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3164 if (it
->data
!= self
)
3165 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3166 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3170 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3171 gboolean hide_animation
)
3173 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3174 /* move up the transient chain as far as possible first */
3175 self
= client_search_top_direct_parent(self
);
3176 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3180 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3184 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3185 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3187 /* check if already done */
3189 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3190 if (dir
== 1 && self
->max_horz
) return;
3191 if (dir
== 2 && self
->max_vert
) return;
3193 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3194 if (dir
== 1 && !self
->max_horz
) return;
3195 if (dir
== 2 && !self
->max_vert
) return;
3198 /* these will help configure_full figure out which screen to fill with
3202 w
= self
->area
.width
;
3203 h
= self
->area
.height
;
3206 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3207 RECT_SET(self
->pre_max_area
,
3208 self
->area
.x
, self
->pre_max_area
.y
,
3209 self
->area
.width
, self
->pre_max_area
.height
);
3211 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3212 RECT_SET(self
->pre_max_area
,
3213 self
->pre_max_area
.x
, self
->area
.y
,
3214 self
->pre_max_area
.width
, self
->area
.height
);
3217 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3218 g_assert(self
->pre_max_area
.width
> 0);
3220 x
= self
->pre_max_area
.x
;
3221 w
= self
->pre_max_area
.width
;
3223 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3224 0, self
->pre_max_area
.height
);
3226 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3227 g_assert(self
->pre_max_area
.height
> 0);
3229 y
= self
->pre_max_area
.y
;
3230 h
= self
->pre_max_area
.height
;
3232 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3233 self
->pre_max_area
.width
, 0);
3237 if (dir
== 0 || dir
== 1) /* horz */
3238 self
->max_horz
= max
;
3239 if (dir
== 0 || dir
== 2) /* vert */
3240 self
->max_vert
= max
;
3242 client_change_state(self
); /* change the state hints on the client */
3244 client_setup_decor_and_functions(self
, FALSE
);
3245 client_move_resize(self
, x
, y
, w
, h
);
3248 void client_shade(ObClient
*self
, gboolean shade
)
3250 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3251 shade
) || /* can't shade */
3252 self
->shaded
== shade
) return; /* already done */
3254 self
->shaded
= shade
;
3255 client_change_state(self
);
3256 client_change_wm_state(self
); /* the window is being hidden/shown */
3257 /* resize the frame to just the titlebar */
3258 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3261 static void client_ping_event(ObClient
*self
, gboolean dead
)
3263 self
->not_responding
= dead
;
3264 client_update_title(self
);
3267 /* try kill it nicely the first time again, if it started responding
3269 self
->close_tried_term
= FALSE
;
3273 void client_close(ObClient
*self
)
3275 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3277 /* in the case that the client provides no means to requesting that it
3278 close, we just kill it */
3279 if (!self
->delete_window
)
3280 /* don't use client_kill(), we should only kill based on PID in
3281 response to a lack of PING replies */
3282 XKillClient(obt_display
, self
->window
);
3283 else if (self
->not_responding
)
3286 /* request the client to close with WM_DELETE_WINDOW */
3287 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3288 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_curtime
,
3289 0, 0, 0, NoEventMask
);
3292 void client_kill(ObClient
*self
)
3294 if (!self
->client_machine
&& self
->pid
) {
3295 /* running on the local host */
3296 if (!self
->close_tried_term
) {
3297 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3298 self
->window
, self
->pid
);
3299 kill(self
->pid
, SIGTERM
);
3300 self
->close_tried_term
= TRUE
;
3302 /* show that we're trying to kill it */
3303 client_update_title(self
);
3306 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3307 self
->window
, self
->pid
);
3308 kill(self
->pid
, SIGKILL
); /* kill -9 */
3312 XKillClient(obt_display
, self
->window
);
3315 void client_hilite(ObClient
*self
, gboolean hilite
)
3317 if (self
->demands_attention
== hilite
)
3318 return; /* no change */
3320 /* don't allow focused windows to hilite */
3321 self
->demands_attention
= hilite
&& !client_focused(self
);
3322 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3323 if (self
->demands_attention
)
3324 frame_flash_start(self
->frame
);
3326 frame_flash_stop(self
->frame
);
3327 client_change_state(self
);
3331 static void client_set_desktop_recursive(ObClient
*self
,
3339 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3341 ob_debug("Setting desktop %u", target
+1);
3343 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3345 old
= self
->desktop
;
3346 self
->desktop
= target
;
3347 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3348 /* the frame can display the current desktop state */
3349 frame_adjust_state(self
->frame
);
3350 /* 'move' the window to the new desktop */
3354 /* raise if it was not already on the desktop */
3355 if (old
!= DESKTOP_ALL
&& !dontraise
)
3356 stacking_raise(CLIENT_AS_WINDOW(self
));
3357 if (STRUT_EXISTS(self
->strut
))
3358 screen_update_areas();
3360 /* the new desktop's geometry may be different, so we may need to
3361 resize, for example if we are maximized */
3362 client_reconfigure(self
, FALSE
);
3365 /* move all transients */
3366 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3367 if (it
->data
!= self
)
3368 if (client_is_direct_child(self
, it
->data
))
3369 client_set_desktop_recursive(it
->data
, target
,
3370 donthide
, dontraise
);
3373 void client_set_desktop(ObClient
*self
, guint target
,
3374 gboolean donthide
, gboolean dontraise
)
3376 self
= client_search_top_direct_parent(self
);
3377 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3380 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3382 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3383 return child
== parent
;
3386 ObClient
*client_search_modal_child(ObClient
*self
)
3391 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3392 ObClient
*c
= it
->data
;
3393 if ((ret
= client_search_modal_child(c
))) return ret
;
3394 if (c
->modal
) return c
;
3399 gboolean
client_validate(ObClient
*self
)
3403 XSync(obt_display
, FALSE
); /* get all events on the server */
3405 if (XCheckTypedWindowEvent(obt_display
, self
->window
, DestroyNotify
, &e
) ||
3406 XCheckTypedWindowEvent(obt_display
, self
->window
, UnmapNotify
, &e
))
3408 XPutBackEvent(obt_display
, &e
);
3415 void client_set_wm_state(ObClient
*self
, glong state
)
3417 if (state
== self
->wmstate
) return; /* no change */
3421 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3424 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3429 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3431 gboolean shaded
= self
->shaded
;
3432 gboolean fullscreen
= self
->fullscreen
;
3433 gboolean undecorated
= self
->undecorated
;
3434 gboolean max_horz
= self
->max_horz
;
3435 gboolean max_vert
= self
->max_vert
;
3436 gboolean modal
= self
->modal
;
3437 gboolean iconic
= self
->iconic
;
3438 gboolean demands_attention
= self
->demands_attention
;
3439 gboolean above
= self
->above
;
3440 gboolean below
= self
->below
;
3443 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3444 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3445 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3446 /* an invalid action was passed to the client message, ignore it */
3449 for (i
= 0; i
< 2; ++i
) {
3450 Atom state
= i
== 0 ? data1
: data2
;
3452 if (!state
) continue;
3454 /* if toggling, then pick whether we're adding or removing */
3455 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3456 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3457 action
= modal
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3458 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3459 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3460 action
= self
->max_vert
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3461 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3462 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3463 action
= self
->max_horz
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3464 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3465 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3466 action
= shaded
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3467 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3468 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3469 action
= self
->skip_taskbar
?
3470 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3471 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3472 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3473 action
= self
->skip_pager
?
3474 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3475 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3476 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3477 action
= self
->iconic
?
3478 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3479 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3480 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3481 action
= fullscreen
?
3482 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3483 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3484 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3485 action
= self
->above
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3486 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3487 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3488 action
= self
->below
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3489 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3490 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3491 action
= self
->demands_attention
?
3492 OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3493 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3494 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3495 action
= undecorated
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3496 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3499 if (action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
)) {
3500 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3502 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3504 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3506 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3508 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3509 self
->skip_taskbar
= TRUE
;
3510 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3511 self
->skip_pager
= TRUE
;
3512 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3514 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3516 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3519 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3522 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3523 demands_attention
= TRUE
;
3524 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3528 } else { /* action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) */
3529 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3531 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3533 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3535 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3537 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3538 self
->skip_taskbar
= FALSE
;
3539 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3540 self
->skip_pager
= FALSE
;
3541 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3543 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3545 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3547 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3549 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3550 demands_attention
= FALSE
;
3551 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3552 undecorated
= FALSE
;
3557 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3558 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3560 if (max_horz
== max_vert
) { /* both going the same way */
3561 client_maximize(self
, max_horz
, 0);
3563 client_maximize(self
, max_horz
, 1);
3564 client_maximize(self
, max_vert
, 2);
3568 if (max_horz
!= self
->max_horz
)
3569 client_maximize(self
, max_horz
, 1);
3571 client_maximize(self
, max_vert
, 2);
3574 /* change fullscreen state before shading, as it will affect if the window
3576 if (fullscreen
!= self
->fullscreen
)
3577 client_fullscreen(self
, fullscreen
);
3578 if (shaded
!= self
->shaded
)
3579 client_shade(self
, shaded
);
3580 if (undecorated
!= self
->undecorated
)
3581 client_set_undecorated(self
, undecorated
);
3582 if (above
!= self
->above
|| below
!= self
->below
) {
3583 self
->above
= above
;
3584 self
->below
= below
;
3585 client_calc_layer(self
);
3588 if (modal
!= self
->modal
) {
3589 self
->modal
= modal
;
3590 /* when a window changes modality, then its stacking order with its
3591 transients needs to change */
3592 stacking_raise(CLIENT_AS_WINDOW(self
));
3594 /* it also may get focused. if something is focused that shouldn't
3595 be focused anymore, then move the focus */
3596 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3597 client_focus(focus_client
);
3600 if (iconic
!= self
->iconic
)
3601 client_iconify(self
, iconic
, FALSE
, FALSE
);
3603 if (demands_attention
!= self
->demands_attention
)
3604 client_hilite(self
, demands_attention
);
3606 client_change_state(self
); /* change the hint to reflect these changes */
3609 ObClient
*client_focus_target(ObClient
*self
)
3611 ObClient
*child
= NULL
;
3613 child
= client_search_modal_child(self
);
3614 if (child
) return child
;
3618 gboolean
client_can_focus(ObClient
*self
)
3620 /* choose the correct target */
3621 self
= client_focus_target(self
);
3623 if (!self
->frame
->visible
)
3626 if (!(self
->can_focus
|| self
->focus_notify
))
3632 gboolean
client_focus(ObClient
*self
)
3634 /* we might not focus this window, so if we have modal children which would
3635 be focused instead, bring them to this desktop */
3636 client_bring_modal_windows(self
);
3638 /* choose the correct target */
3639 self
= client_focus_target(self
);
3641 if (!client_can_focus(self
)) {
3642 ob_debug_type(OB_DEBUG_FOCUS
,
3643 "Client %s can't be focused", self
->title
);
3647 ob_debug_type(OB_DEBUG_FOCUS
,
3648 "Focusing client \"%s\" (0x%x) at time %u",
3649 self
->title
, self
->window
, event_curtime
);
3651 /* if using focus_delay, stop the timer now so that focus doesn't
3653 event_halt_focus_delay();
3655 /* if there is a grab going on, then we need to cancel it. if we move
3656 focus during the grab, applications will get NotifyWhileGrabbed events
3659 actions should not rely on being able to move focus during an
3662 event_cancel_all_key_grabs();
3664 obt_display_ignore_errors(TRUE
);
3666 if (self
->can_focus
) {
3667 /* This can cause a BadMatch error with CurrentTime, or if an app
3668 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3669 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3673 if (self
->focus_notify
) {
3675 ce
.xclient
.type
= ClientMessage
;
3676 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3677 ce
.xclient
.display
= obt_display
;
3678 ce
.xclient
.window
= self
->window
;
3679 ce
.xclient
.format
= 32;
3680 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
3681 ce
.xclient
.data
.l
[1] = event_curtime
;
3682 ce
.xclient
.data
.l
[2] = 0l;
3683 ce
.xclient
.data
.l
[3] = 0l;
3684 ce
.xclient
.data
.l
[4] = 0l;
3685 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3688 obt_display_ignore_errors(FALSE
);
3690 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
3691 obt_display_error_occured
);
3692 return !obt_display_error_occured
;
3695 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3698 if (client_normal(self
) && screen_showing_desktop
)
3699 screen_show_desktop(FALSE
, self
);
3701 client_iconify(self
, FALSE
, here
, FALSE
);
3702 if (self
->desktop
!= DESKTOP_ALL
&&
3703 self
->desktop
!= screen_desktop
)
3706 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3708 screen_set_desktop(self
->desktop
, FALSE
);
3709 } else if (!self
->frame
->visible
)
3710 /* if its not visible for other reasons, then don't mess
3713 if (self
->shaded
&& unshade
)
3714 client_shade(self
, FALSE
);
3716 stacking_raise(CLIENT_AS_WINDOW(self
));
3721 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3722 gboolean unshade
, gboolean user
)
3724 client_present(self
, here
, raise
, unshade
);
3727 static void client_bring_windows_recursive(ObClient
*self
,
3735 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3736 client_bring_windows_recursive(it
->data
, desktop
,
3737 helpers
, modals
, iconic
);
3739 if (((helpers
&& client_helper(self
)) ||
3740 (modals
&& self
->modal
)) &&
3741 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3742 (iconic
&& self
->iconic
)))
3744 if (iconic
&& self
->iconic
)
3745 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3747 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3751 void client_bring_helper_windows(ObClient
*self
)
3753 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3756 void client_bring_modal_windows(ObClient
*self
)
3758 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3761 gboolean
client_focused(ObClient
*self
)
3763 return self
== focus_client
;
3766 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3769 gulong min_diff
, min_i
;
3771 if (!self
->nicons
) {
3772 ObClientIcon
*parent
= NULL
;
3775 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
3776 ObClient
*c
= it
->data
;
3777 if ((parent
= client_icon_recursive(c
, w
, h
)))
3784 /* some kind of crappy approximation to find the icon closest in size to
3785 what we requested, but icons are generally all the same ratio as
3786 eachother so it's good enough. */
3788 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3791 for (i
= 1; i
< self
->nicons
; ++i
) {
3794 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3795 if (diff
< min_diff
) {
3800 return &self
->icons
[min_i
];
3803 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3806 static ObClientIcon deficon
;
3808 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3809 deficon
.width
= deficon
.height
= 48;
3810 deficon
.data
= ob_rr_theme
->def_win_icon
;
3816 void client_set_layer(ObClient
*self
, gint layer
)
3820 self
->above
= FALSE
;
3821 } else if (layer
== 0) {
3822 self
->below
= self
->above
= FALSE
;
3824 self
->below
= FALSE
;
3827 client_calc_layer(self
);
3828 client_change_state(self
); /* reflect this in the state hints */
3831 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3833 if (self
->undecorated
!= undecorated
&&
3834 /* don't let it undecorate if the function is missing, but let
3836 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3838 self
->undecorated
= undecorated
;
3839 client_setup_decor_and_functions(self
, TRUE
);
3840 client_change_state(self
); /* reflect this in the state hints */
3844 guint
client_monitor(ObClient
*self
)
3846 return screen_find_monitor(&self
->frame
->area
);
3849 ObClient
*client_direct_parent(ObClient
*self
)
3851 if (!self
->parents
) return NULL
;
3852 if (self
->transient_for_group
) return NULL
;
3853 return self
->parents
->data
;
3856 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3859 while ((p
= client_direct_parent(self
))) self
= p
;
3863 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3865 ObStackingLayer layer
)
3870 /* move up the direct transient chain as far as possible */
3871 while ((p
= client_direct_parent(self
)) &&
3872 (!bylayer
|| p
->layer
== layer
))
3876 ret
= g_slist_prepend(NULL
, self
);
3878 ret
= g_slist_copy(self
->parents
);
3883 GSList
*client_search_all_top_parents(ObClient
*self
)
3885 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3888 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3890 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3893 ObClient
*client_search_focus_parent(ObClient
*self
)
3897 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3898 if (client_focused(it
->data
)) return it
->data
;
3903 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3907 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3908 if (it
->data
== search
) return search
;
3913 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3917 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3918 if (sit
->data
== search
)
3920 if (client_search_transient(sit
->data
, search
))
3926 static void detect_edge(Rect area
, ObDirection dir
,
3927 gint my_head
, gint my_size
,
3928 gint my_edge_start
, gint my_edge_size
,
3929 gint
*dest
, gboolean
*near_edge
)
3931 gint edge_start
, edge_size
, head
, tail
;
3932 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
3935 case OB_DIRECTION_NORTH
:
3936 case OB_DIRECTION_SOUTH
:
3937 edge_start
= area
.x
;
3938 edge_size
= area
.width
;
3940 case OB_DIRECTION_EAST
:
3941 case OB_DIRECTION_WEST
:
3942 edge_start
= area
.y
;
3943 edge_size
= area
.height
;
3946 g_assert_not_reached();
3949 /* do we collide with this window? */
3950 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
3951 edge_start
, edge_size
))
3955 case OB_DIRECTION_NORTH
:
3956 head
= RECT_BOTTOM(area
);
3957 tail
= RECT_TOP(area
);
3959 case OB_DIRECTION_SOUTH
:
3960 head
= RECT_TOP(area
);
3961 tail
= RECT_BOTTOM(area
);
3963 case OB_DIRECTION_WEST
:
3964 head
= RECT_RIGHT(area
);
3965 tail
= RECT_LEFT(area
);
3967 case OB_DIRECTION_EAST
:
3968 head
= RECT_LEFT(area
);
3969 tail
= RECT_RIGHT(area
);
3972 g_assert_not_reached();
3975 case OB_DIRECTION_NORTH
:
3976 case OB_DIRECTION_WEST
:
3977 /* check if our window is past the head of this window */
3978 if (my_head
<= head
+ 1)
3980 /* check if our window's tail is past the tail of this window */
3981 if (my_head
+ my_size
- 1 <= tail
)
3983 /* check if the head of this window is closer than the previously
3984 chosen edge (take into account that the previously chosen
3985 edge might have been a tail, not a head) */
3986 if (head
+ (*near_edge
? 0 : my_size
) < *dest
)
3988 /* check if the tail of this window is closer than the previously
3989 chosen edge (take into account that the previously chosen
3990 edge might have been a head, not a tail) */
3991 if (tail
- (!*near_edge
? 0 : my_size
) < *dest
)
3994 case OB_DIRECTION_SOUTH
:
3995 case OB_DIRECTION_EAST
:
3996 /* check if our window is past the head of this window */
3997 if (my_head
>= head
- 1)
3999 /* check if our window's tail is past the tail of this window */
4000 if (my_head
- my_size
+ 1 >= tail
)
4002 /* check if the head of this window is closer than the previously
4003 chosen edge (take into account that the previously chosen
4004 edge might have been a tail, not a head) */
4005 if (head
- (*near_edge
? 0 : my_size
) > *dest
)
4007 /* check if the tail of this window is closer than the previously
4008 chosen edge (take into account that the previously chosen
4009 edge might have been a head, not a tail) */
4010 if (tail
+ (!*near_edge
? 0 : my_size
) > *dest
)
4014 g_assert_not_reached();
4017 ob_debug("my head %d size %d", my_head
, my_size
);
4018 ob_debug("head %d tail %d deest %d", head
, tail
, *dest
);
4020 ob_debug("using near edge %d", head
);
4024 else if (!skip_tail
) {
4025 ob_debug("using far edge %d", tail
);
4031 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4032 gint my_head
, gint my_size
,
4033 gint my_edge_start
, gint my_edge_size
,
4034 gint
*dest
, gboolean
*near_edge
)
4041 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4042 &self
->frame
->area
);
4043 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
4044 &self
->frame
->area
);
4047 case OB_DIRECTION_NORTH
:
4048 if (my_head
>= RECT_TOP(*mon
) + 1)
4049 edge
= RECT_TOP(*mon
) - 1;
4051 edge
= RECT_TOP(*a
) - 1;
4053 case OB_DIRECTION_SOUTH
:
4054 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
4055 edge
= RECT_BOTTOM(*mon
) + 1;
4057 edge
= RECT_BOTTOM(*a
) + 1;
4059 case OB_DIRECTION_EAST
:
4060 if (my_head
<= RECT_RIGHT(*mon
) - 1)
4061 edge
= RECT_RIGHT(*mon
) + 1;
4063 edge
= RECT_RIGHT(*a
) + 1;
4065 case OB_DIRECTION_WEST
:
4066 if (my_head
>= RECT_LEFT(*mon
) + 1)
4067 edge
= RECT_LEFT(*mon
) - 1;
4069 edge
= RECT_LEFT(*a
) - 1;
4072 g_assert_not_reached();
4074 /* default to the far edge, then narrow it down */
4078 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4079 ObClient
*cur
= it
->data
;
4081 /* skip windows to not bump into */
4086 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4087 cur
->desktop
!= screen_desktop
)
4090 ob_debug("trying window %s", cur
->title
);
4092 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4093 my_edge_size
, dest
, near_edge
);
4095 dock_get_area(&dock_area
);
4096 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4097 my_edge_size
, dest
, near_edge
);
4102 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4106 gint e
, e_start
, e_size
;
4110 case OB_DIRECTION_EAST
:
4111 head
= RECT_RIGHT(self
->frame
->area
);
4112 size
= self
->frame
->area
.width
;
4113 e_start
= RECT_TOP(self
->frame
->area
);
4114 e_size
= self
->frame
->area
.height
;
4116 case OB_DIRECTION_WEST
:
4117 head
= RECT_LEFT(self
->frame
->area
);
4118 size
= self
->frame
->area
.width
;
4119 e_start
= RECT_TOP(self
->frame
->area
);
4120 e_size
= self
->frame
->area
.height
;
4122 case OB_DIRECTION_NORTH
:
4123 head
= RECT_TOP(self
->frame
->area
);
4124 size
= self
->frame
->area
.height
;
4125 e_start
= RECT_LEFT(self
->frame
->area
);
4126 e_size
= self
->frame
->area
.width
;
4128 case OB_DIRECTION_SOUTH
:
4129 head
= RECT_BOTTOM(self
->frame
->area
);
4130 size
= self
->frame
->area
.height
;
4131 e_start
= RECT_LEFT(self
->frame
->area
);
4132 e_size
= self
->frame
->area
.width
;
4135 g_assert_not_reached();
4138 client_find_edge_directional(self
, dir
, head
, size
,
4139 e_start
, e_size
, &e
, &near
);
4140 *x
= self
->frame
->area
.x
;
4141 *y
= self
->frame
->area
.y
;
4143 case OB_DIRECTION_EAST
:
4144 if (near
) e
-= self
->frame
->area
.width
;
4148 case OB_DIRECTION_WEST
:
4150 else e
-= self
->frame
->area
.width
;
4153 case OB_DIRECTION_NORTH
:
4155 else e
-= self
->frame
->area
.height
;
4158 case OB_DIRECTION_SOUTH
:
4159 if (near
) e
-= self
->frame
->area
.height
;
4164 g_assert_not_reached();
4166 frame_frame_gravity(self
->frame
, x
, y
);
4169 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4171 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4174 gint e
, e_start
, e_size
, delta
;
4179 case OB_DIRECTION_EAST
:
4180 head
= RECT_RIGHT(self
->frame
->area
) +
4181 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4182 e_start
= RECT_TOP(self
->frame
->area
);
4183 e_size
= self
->frame
->area
.height
;
4184 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4186 case OB_DIRECTION_WEST
:
4187 head
= RECT_LEFT(self
->frame
->area
) -
4188 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4189 e_start
= RECT_TOP(self
->frame
->area
);
4190 e_size
= self
->frame
->area
.height
;
4191 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4193 case OB_DIRECTION_NORTH
:
4194 head
= RECT_TOP(self
->frame
->area
) -
4195 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4196 e_start
= RECT_LEFT(self
->frame
->area
);
4197 e_size
= self
->frame
->area
.width
;
4198 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4200 case OB_DIRECTION_SOUTH
:
4201 head
= RECT_BOTTOM(self
->frame
->area
) +
4202 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4203 e_start
= RECT_LEFT(self
->frame
->area
);
4204 e_size
= self
->frame
->area
.width
;
4205 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4208 g_assert_not_reached();
4211 ob_debug("head %d dir %d", head
, dir
);
4212 client_find_edge_directional(self
, dir
, head
, 1,
4213 e_start
, e_size
, &e
, &near
);
4214 ob_debug("edge %d", e
);
4215 *x
= self
->frame
->area
.x
;
4216 *y
= self
->frame
->area
.y
;
4217 *w
= self
->frame
->area
.width
;
4218 *h
= self
->frame
->area
.height
;
4220 case OB_DIRECTION_EAST
:
4221 if (grow
== near
) --e
;
4222 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4225 case OB_DIRECTION_WEST
:
4226 if (grow
== near
) ++e
;
4227 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4231 case OB_DIRECTION_NORTH
:
4232 if (grow
== near
) ++e
;
4233 delta
= RECT_TOP(self
->frame
->area
) - e
;
4237 case OB_DIRECTION_SOUTH
:
4238 if (grow
== near
) --e
;
4239 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4243 g_assert_not_reached();
4245 frame_frame_gravity(self
->frame
, x
, y
);
4246 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4247 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4250 ObClient
* client_under_pointer(void)
4254 ObClient
*ret
= NULL
;
4256 if (screen_pointer_pos(&x
, &y
)) {
4257 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4258 if (WINDOW_IS_CLIENT(it
->data
)) {
4259 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4260 if (c
->frame
->visible
&&
4261 /* check the desktop, this is done during desktop
4262 switching and windows are shown/hidden status is not
4264 (c
->desktop
== screen_desktop
||
4265 c
->desktop
== DESKTOP_ALL
) &&
4266 /* ignore all animating windows */
4267 !frame_iconify_animating(c
->frame
) &&
4268 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4279 gboolean
client_has_group_siblings(ObClient
*self
)
4281 return self
->group
&& self
->group
->members
->next
;