1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
39 #include "menuframe.h"
42 #include "render/render.h"
49 #include <X11/Xutil.h>
51 /*! The event mask to grab on client windows */
52 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
55 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
60 ObClientCallback func
;
64 GList
*client_list
= NULL
;
66 static GSList
*client_destroy_notifies
= NULL
;
68 static void client_get_all(ObClient
*self
, gboolean real
);
69 static void client_get_startup_id(ObClient
*self
);
70 static void client_get_session_ids(ObClient
*self
);
71 static void client_get_area(ObClient
*self
);
72 static void client_get_desktop(ObClient
*self
);
73 static void client_get_state(ObClient
*self
);
74 static void client_get_shaped(ObClient
*self
);
75 static void client_get_mwm_hints(ObClient
*self
);
76 static void client_get_colormap(ObClient
*self
);
77 static void client_change_allowed_actions(ObClient
*self
);
78 static void client_change_state(ObClient
*self
);
79 static void client_change_wm_state(ObClient
*self
);
80 static void client_apply_startup_state(ObClient
*self
,
81 gint x
, gint y
, gint w
, gint h
);
82 static void client_restore_session_state(ObClient
*self
);
83 static gboolean
client_restore_session_stacking(ObClient
*self
);
84 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
85 static void client_update_transient_tree(ObClient
*self
,
86 ObGroup
*oldgroup
, ObGroup
*newgroup
,
87 gboolean oldgtran
, gboolean newgtran
,
90 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
92 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
94 ObStackingLayer layer
);
95 static void client_call_notifies(ObClient
*self
, GSList
*list
);
98 void client_startup(gboolean reconfig
)
100 if (reconfig
) return;
105 void client_shutdown(gboolean reconfig
)
107 if (reconfig
) return;
110 static void client_call_notifies(ObClient
*self
, GSList
*list
)
114 for (it
= list
; it
; it
= g_slist_next(it
)) {
115 ClientCallback
*d
= it
->data
;
116 d
->func(self
, d
->data
);
120 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
122 ClientCallback
*d
= g_new(ClientCallback
, 1);
125 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
128 void client_remove_destroy_notify(ObClientCallback func
)
132 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
133 ClientCallback
*d
= it
->data
;
134 if (d
->func
== func
) {
136 client_destroy_notifies
=
137 g_slist_delete_link(client_destroy_notifies
, it
);
143 void client_set_list(void)
145 Window
*windows
, *win_it
;
147 guint size
= g_list_length(client_list
);
149 /* create an array of the window ids */
151 windows
= g_new(Window
, size
);
153 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
154 *win_it
= ((ObClient
*)it
->data
)->window
;
158 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
159 net_client_list
, window
, (gulong
*)windows
, size
);
167 void client_manage_all(void)
172 XWindowAttributes attrib
;
174 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
175 &w
, &w
, &children
, &nchild
);
177 /* remove all icon windows from the list */
178 for (i
= 0; i
< nchild
; i
++) {
179 if (children
[i
] == None
) continue;
180 wmhints
= XGetWMHints(ob_display
, children
[i
]);
182 if ((wmhints
->flags
& IconWindowHint
) &&
183 (wmhints
->icon_window
!= children
[i
]))
184 for (j
= 0; j
< nchild
; j
++)
185 if (children
[j
] == wmhints
->icon_window
) {
193 for (i
= 0; i
< nchild
; ++i
) {
194 if (children
[i
] == None
)
196 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
197 if (attrib
.override_redirect
) continue;
199 if (attrib
.map_state
!= IsUnmapped
)
200 client_manage(children
[i
]);
206 void client_manage(Window window
)
210 XWindowAttributes attrib
;
211 XSetWindowAttributes attrib_set
;
213 gboolean activate
= FALSE
;
214 ObAppSettings
*settings
;
215 gboolean transient
= FALSE
;
216 Rect place
, *monitor
;
217 Time launch_time
, map_time
;
221 /* check if it has already been unmapped by the time we started
222 mapping. the grab does a sync so we don't have to here */
223 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
224 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
226 XPutBackEvent(ob_display
, &e
);
228 ob_debug("Trying to manage unmapped window. Aborting that.\n");
230 return; /* don't manage it */
233 /* make sure it isn't an override-redirect window */
234 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
235 attrib
.override_redirect
)
238 return; /* don't manage it */
241 /* is the window a docking app */
242 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
243 if ((wmhint
->flags
& StateHint
) &&
244 wmhint
->initial_state
== WithdrawnState
)
246 dock_add(window
, wmhint
);
254 ob_debug("Managing window: 0x%lx\n", window
);
256 map_time
= event_get_server_time();
258 /* choose the events we want to receive on the CLIENT window */
259 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
260 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
261 XChangeWindowAttributes(ob_display
, window
,
262 CWEventMask
|CWDontPropagate
, &attrib_set
);
264 /* create the ObClient struct, and populate it from the hints on the
266 self
= g_new0(ObClient
, 1);
267 self
->obwin
.type
= Window_Client
;
268 self
->window
= window
;
270 /* non-zero defaults */
271 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
272 self
->gravity
= NorthWestGravity
;
273 self
->desktop
= screen_num_desktops
; /* always an invalid value */
275 /* get all the stuff off the window */
276 client_get_all(self
, TRUE
);
278 ob_debug("Window type: %d\n", self
->type
);
279 ob_debug("Window group: 0x%x\n", self
->group
?self
->group
->leader
:0);
281 /* specify that if we exit, the window should not be destroyed and
282 should be reparented back to root automatically */
283 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
285 /* create the decoration frame for the client window */
286 self
->frame
= frame_new(self
);
288 frame_grab_client(self
->frame
);
290 /* we've grabbed everything and set everything that we need to at mapping
294 /* per-app settings override stuff from client_get_all, and return the
295 settings for other uses too. the returned settings is a shallow copy,
296 that needs to be freed with g_free(). */
297 settings
= client_get_settings_state(self
);
298 /* the session should get the last say though */
299 client_restore_session_state(self
);
301 /* now we have all of the window's information so we can set this up */
302 client_setup_decor_and_functions(self
, FALSE
);
304 /* tell startup notification that this app started */
305 launch_time
= sn_app_started(self
->startup_id
, self
->class);
307 /* do this after we have a frame.. it uses the frame to help determine the
308 WM_STATE to apply. */
309 client_change_state(self
);
311 /* add ourselves to the focus order */
312 focus_order_add_new(self
);
314 /* do this to add ourselves to the stacking list in a non-intrusive way */
315 client_calc_layer(self
);
317 /* focus the new window? */
318 if (ob_state() != OB_STATE_STARTING
&&
319 (!self
->session
|| self
->session
->focused
) &&
320 /* this means focus=true for window is same as config_focus_new=true */
321 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
322 client_search_focus_tree_full(self
)) &&
323 /* this checks for focus=false for the window */
324 (!settings
|| settings
->focus
!= 0) &&
325 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
330 /* remove the client's border */
331 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
333 /* adjust the frame to the client's size before showing or placing
335 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
336 frame_adjust_client_area(self
->frame
);
338 /* where the frame was placed is where the window was originally */
340 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
342 /* figure out placement for the window if the window is new */
343 if (ob_state() == OB_STATE_RUNNING
) {
344 ob_debug("Positioned: %s @ %d %d\n",
345 (!self
->positioned
? "no" :
346 (self
->positioned
== PPosition
? "program specified" :
347 (self
->positioned
== USPosition
? "user specified" :
348 (self
->positioned
== (PPosition
| USPosition
) ?
349 "program + user specified" :
350 "BADNESS !?")))), place
.x
, place
.y
);
352 ob_debug("Sized: %s @ %d %d\n",
353 (!self
->sized
? "no" :
354 (self
->sized
== PSize
? "program specified" :
355 (self
->sized
== USSize
? "user specified" :
356 (self
->sized
== (PSize
| USSize
) ?
357 "program + user specified" :
358 "BADNESS !?")))), place
.width
, place
.height
);
360 /* splash screens are also returned as TRUE for transient,
361 and so will be forced on screen below */
362 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
364 /* make sure the window is visible. */
365 client_find_onscreen(self
, &place
.x
, &place
.y
,
366 place
.width
, place
.height
,
367 /* non-normal clients has less rules, and
368 windows that are being restored from a
369 session do also. we can assume you want
370 it back where you saved it. Clients saying
371 they placed themselves are subjected to
372 harder rules, ones that are placed by
373 place.c or by the user are allowed partially
374 off-screen and on xinerama divides (ie,
375 it is up to the placement routines to avoid
376 the xinerama divides)
378 splash screens get "transient" set to TRUE by
379 the place_client call
381 ob_state() == OB_STATE_RUNNING
&&
383 (!((self
->positioned
& USPosition
) ||
384 (settings
&& settings
->pos_given
)) &&
385 client_normal(self
) &&
387 /* don't move oldschool fullscreen windows to
388 fit inside the struts (fixes Acroread, which
389 makes its fullscreen window fit the screen
390 but it is not USSize'd or USPosition'd) */
391 !(self
->decorations
== 0 &&
392 RECT_EQUAL(place
, *monitor
)))));
395 /* if the window isn't user-sized, then make it fit inside
396 the visible screen area on its monitor. Use basically the same rules
397 for forcing the window on screen in the client_find_onscreen call.
399 do this after place_client, it chooses the monitor!
401 splash screens get "transient" set to TRUE by
402 the place_client call
404 if (ob_state() == OB_STATE_RUNNING
&&
406 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
407 client_normal(self
) &&
409 /* don't shrink oldschool fullscreen windows to fit inside the
410 struts (fixes Acroread, which makes its fullscreen window
411 fit the screen but it is not USSize'd or USPosition'd) */
412 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
414 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
416 /* get the size of the frame */
417 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
418 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
420 /* fit the window inside the area */
421 place
.width
= MIN(place
.width
, a
->width
);
422 place
.height
= MIN(place
.height
, a
->height
);
424 ob_debug("setting window size to %dx%d\n", place
.width
, place
.height
);
426 /* get the size of the client back */
427 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
428 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
433 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
434 "some restrictions may apply\n",
435 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
437 ob_debug(" but session requested %d, %d %d x %d instead, "
439 self
->session
->x
, self
->session
->y
,
440 self
->session
->w
, self
->session
->h
);
442 /* do this after the window is placed, so the premax/prefullscreen numbers
445 this also places the window
447 client_apply_startup_state(self
, place
.x
, place
.y
,
448 place
.width
, place
.height
);
453 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s\n",
454 activate
? "yes" : "no");
456 gboolean raise
= FALSE
;
458 /* This is focus stealing prevention */
459 ob_debug_type(OB_DEBUG_FOCUS
,
460 "Want to focus new window 0x%x at time %u "
461 "launched at %u (last user interaction time %u)\n",
462 self
->window
, map_time
, launch_time
,
463 event_last_user_time
);
465 if (menu_frame_visible
|| moveresize_in_progress
) {
468 ob_debug_type(OB_DEBUG_FOCUS
,
469 "Not focusing the window because the user is inside "
470 "an Openbox menu or is move/resizing a window and "
471 "we don't want to interrupt them\n");
474 /* if it's on another desktop */
475 else if (!(self
->desktop
== screen_desktop
||
476 self
->desktop
== DESKTOP_ALL
) &&
477 /* the timestamp is from before you changed desktops */
478 launch_time
&& screen_desktop_user_time
&&
479 !event_time_after(launch_time
, screen_desktop_user_time
))
483 ob_debug_type(OB_DEBUG_FOCUS
,
484 "Not focusing the window because its on another "
487 /* If something is focused, and it's not our relative... */
488 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
489 client_search_focus_group_full(self
) == NULL
)
491 /* If the user is working in another window right now, then don't
493 if (event_last_user_time
&& launch_time
&&
494 event_time_after(event_last_user_time
, launch_time
) &&
495 event_last_user_time
!= launch_time
&&
496 event_time_after(event_last_user_time
,
497 map_time
- OB_EVENT_USER_TIME_DELAY
))
500 ob_debug_type(OB_DEBUG_FOCUS
,
501 "Not focusing the window because the user is "
502 "working in another window\n");
504 /* If its a transient (and its parents aren't focused) */
505 else if (client_has_parent(self
)) {
507 ob_debug_type(OB_DEBUG_FOCUS
,
508 "Not focusing the window because it is a "
509 "transient, and its relatives aren't focused\n");
511 /* Don't steal focus from globally active clients.
512 I stole this idea from KWin. It seems nice.
514 else if (!(focus_client
->can_focus
||
515 focus_client
->focus_notify
))
518 ob_debug_type(OB_DEBUG_FOCUS
,
519 "Not focusing the window because a globally "
520 "active client has focus\n");
522 /* Don't move focus if it's not going to go to this window
524 else if (client_focus_target(self
) != self
) {
527 ob_debug_type(OB_DEBUG_FOCUS
,
528 "Not focusing the window because another window "
529 "would get the focus anyway\n");
531 else if (!(self
->desktop
== screen_desktop
||
532 self
->desktop
== DESKTOP_ALL
))
536 ob_debug_type(OB_DEBUG_FOCUS
,
537 "Not focusing the window because it is on "
538 "another desktop and no relatives are focused ");
543 ob_debug_type(OB_DEBUG_FOCUS
,
544 "Focus stealing prevention activated for %s at "
545 "time %u (last user interactioon time %u)\n",
546 self
->title
, map_time
, event_last_user_time
);
547 /* if the client isn't focused, then hilite it so the user
549 client_hilite(self
, TRUE
);
550 /* we may want to raise it even tho we're not activating it */
551 if (raise
&& !client_restore_session_stacking(self
))
552 stacking_raise(CLIENT_AS_WINDOW(self
));
556 /* This may look rather odd. Well it's because new windows are added
557 to the stacking order non-intrusively. If we're not going to focus
558 the new window or hilite it, then we raise it to the top. This will
559 take affect for things that don't get focused like splash screens.
560 Also if you don't have focus_new enabled, then it's going to get
561 raised to the top. Legacy begets legacy I guess?
563 if (!client_restore_session_stacking(self
))
564 stacking_raise(CLIENT_AS_WINDOW(self
));
567 mouse_grab_for_client(self
, TRUE
);
569 /* this has to happen before we try focus the window, but we want it to
570 happen after the client's stacking has been determined or it looks bad
574 if (!config_focus_under_mouse
)
575 ignore_start
= event_start_ignore_all_enters();
579 if (!config_focus_under_mouse
)
580 event_end_ignore_all_enters(ignore_start
);
584 gboolean stacked
= client_restore_session_stacking(self
);
585 client_present(self
, FALSE
, !stacked
, TRUE
);
588 /* add to client list/map */
589 client_list
= g_list_append(client_list
, self
);
590 g_hash_table_insert(window_map
, &self
->window
, self
);
592 /* this has to happen after we're in the client_list */
593 if (STRUT_EXISTS(self
->strut
))
594 screen_update_areas();
596 /* update the list hints */
599 /* free the ObAppSettings shallow copy */
602 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
603 window
, self
->frame
->window
, self
->class);
609 ObClient
*client_fake_manage(Window window
)
612 ObAppSettings
*settings
;
614 ob_debug("Pretend-managing window: %lx\n", window
);
616 /* do this minimal stuff to figure out the client's decorations */
618 self
= g_new0(ObClient
, 1);
619 self
->window
= window
;
621 client_get_all(self
, FALSE
);
622 /* per-app settings override stuff, and return the settings for other
623 uses too. this returns a shallow copy that needs to be freed */
624 settings
= client_get_settings_state(self
);
626 client_setup_decor_and_functions(self
, FALSE
);
628 /* create the decoration frame for the client window and adjust its size */
629 self
->frame
= frame_new(self
);
630 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
632 ob_debug("gave extents left %d right %d top %d bottom %d\n",
633 self
->frame
->size
.left
, self
->frame
->size
.right
,
634 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
636 /* free the ObAppSettings shallow copy */
642 void client_unmanage_all(void)
644 while (client_list
!= NULL
)
645 client_unmanage(client_list
->data
);
648 void client_unmanage(ObClient
*self
)
654 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
655 self
->window
, self
->frame
->window
,
656 self
->class, self
->title
? self
->title
: "");
658 g_assert(self
!= NULL
);
660 /* we dont want events no more. do this before hiding the frame so we
661 don't generate more events */
662 XSelectInput(ob_display
, self
->window
, NoEventMask
);
664 /* ignore enter events from the unmap so it doesnt mess with the focus */
665 if (!config_focus_under_mouse
)
666 ignore_start
= event_start_ignore_all_enters();
668 frame_hide(self
->frame
);
669 /* flush to send the hide to the server quickly */
672 if (!config_focus_under_mouse
)
673 event_end_ignore_all_enters(ignore_start
);
675 mouse_grab_for_client(self
, FALSE
);
677 /* remove the window from our save set */
678 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
680 /* update the focus lists */
681 focus_order_remove(self
);
682 if (client_focused(self
)) {
683 /* don't leave an invalid focus_client */
687 client_list
= g_list_remove(client_list
, self
);
688 stacking_remove(self
);
689 g_hash_table_remove(window_map
, &self
->window
);
691 /* once the client is out of the list, update the struts to remove its
693 if (STRUT_EXISTS(self
->strut
))
694 screen_update_areas();
696 client_call_notifies(self
, client_destroy_notifies
);
698 /* tell our parent(s) that we're gone */
699 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
700 ((ObClient
*)it
->data
)->transients
=
701 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
703 /* tell our transients that we're gone */
704 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
705 ((ObClient
*)it
->data
)->parents
=
706 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
707 /* we could be keeping our children in a higher layer */
708 client_calc_layer(it
->data
);
711 /* remove from its group */
713 group_remove(self
->group
, self
);
717 /* restore the window's original geometry so it is not lost */
723 if (self
->fullscreen
)
724 a
= self
->pre_fullscreen_area
;
725 else if (self
->max_horz
|| self
->max_vert
) {
726 if (self
->max_horz
) {
727 a
.x
= self
->pre_max_area
.x
;
728 a
.width
= self
->pre_max_area
.width
;
730 if (self
->max_vert
) {
731 a
.y
= self
->pre_max_area
.y
;
732 a
.height
= self
->pre_max_area
.height
;
736 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
737 /* let it be moved and resized no matter what */
738 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
739 self
->decorations
= 0; /* unmanaged windows have no decor */
741 /* give the client its border back */
742 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
744 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
747 /* reparent the window out of the frame, and free the frame */
748 frame_release_client(self
->frame
);
749 frame_free(self
->frame
);
752 if (ob_state() != OB_STATE_EXITING
) {
753 /* these values should not be persisted across a window
755 PROP_ERASE(self
->window
, net_wm_desktop
);
756 PROP_ERASE(self
->window
, net_wm_state
);
757 PROP_ERASE(self
->window
, wm_state
);
759 /* if we're left in an unmapped state, the client wont be mapped.
760 this is bad, since we will no longer be managing the window on
762 XMapWindow(ob_display
, self
->window
);
765 /* these should not be left on the window ever. other window managers
766 don't necessarily use them and it will mess them up (like compiz) */
767 PROP_ERASE(self
->window
, net_wm_visible_name
);
768 PROP_ERASE(self
->window
, net_wm_visible_icon_name
);
770 /* update the list hints */
773 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
775 /* free all data allocated in the client struct */
776 g_slist_free(self
->transients
);
777 for (j
= 0; j
< self
->nicons
; ++j
)
778 g_free(self
->icons
[j
].data
);
779 if (self
->nicons
> 0)
781 g_free(self
->wm_command
);
783 g_free(self
->icon_title
);
787 g_free(self
->client_machine
);
788 g_free(self
->sm_client_id
);
792 void client_fake_unmanage(ObClient
*self
)
794 /* this is all that got allocated to get the decorations */
796 frame_free(self
->frame
);
800 /*! Returns a new structure containing the per-app settings for this client.
801 The returned structure needs to be freed with g_free. */
802 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
804 ObAppSettings
*settings
;
807 settings
= config_create_app_settings();
809 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
810 ObAppSettings
*app
= it
->data
;
811 gboolean match
= TRUE
;
813 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
815 /* we know that either name or class is not NULL so it will have to
816 match to use the rule */
818 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
820 else if (app
->class &&
821 !g_pattern_match(app
->class,
822 strlen(self
->class), self
->class, NULL
))
824 else if (app
->role
&&
825 !g_pattern_match(app
->role
,
826 strlen(self
->role
), self
->role
, NULL
))
830 ob_debug("Window matching: %s\n", app
->name
);
832 /* copy the settings to our struct, overriding the existing
833 settings if they are not defaults */
834 config_app_settings_copy_non_defaults(app
, settings
);
838 if (settings
->shade
!= -1)
839 self
->shaded
= !!settings
->shade
;
840 if (settings
->decor
!= -1)
841 self
->undecorated
= !settings
->decor
;
842 if (settings
->iconic
!= -1)
843 self
->iconic
= !!settings
->iconic
;
844 if (settings
->skip_pager
!= -1)
845 self
->skip_pager
= !!settings
->skip_pager
;
846 if (settings
->skip_taskbar
!= -1)
847 self
->skip_taskbar
= !!settings
->skip_taskbar
;
849 if (settings
->max_vert
!= -1)
850 self
->max_vert
= !!settings
->max_vert
;
851 if (settings
->max_horz
!= -1)
852 self
->max_horz
= !!settings
->max_horz
;
854 if (settings
->fullscreen
!= -1)
855 self
->fullscreen
= !!settings
->fullscreen
;
857 if (settings
->desktop
) {
858 if (settings
->desktop
== DESKTOP_ALL
)
859 self
->desktop
= settings
->desktop
;
860 else if (settings
->desktop
> 0 &&
861 settings
->desktop
<= screen_num_desktops
)
862 self
->desktop
= settings
->desktop
- 1;
865 if (settings
->layer
== -1) {
869 else if (settings
->layer
== 0) {
873 else if (settings
->layer
== 1) {
880 static void client_restore_session_state(ObClient
*self
)
884 ob_debug_type(OB_DEBUG_SM
,
885 "Restore session for client %s\n", self
->title
);
887 if (!(it
= session_state_find(self
))) {
888 ob_debug_type(OB_DEBUG_SM
,
889 "Session data not found for client %s\n", self
->title
);
893 self
->session
= it
->data
;
895 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
898 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
899 self
->positioned
= USPosition
;
900 self
->sized
= USSize
;
901 if (self
->session
->w
> 0)
902 self
->area
.width
= self
->session
->w
;
903 if (self
->session
->h
> 0)
904 self
->area
.height
= self
->session
->h
;
905 XResizeWindow(ob_display
, self
->window
,
906 self
->area
.width
, self
->area
.height
);
908 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
909 self
->session
->desktop
:
910 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
911 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
913 self
->shaded
= self
->session
->shaded
;
914 self
->iconic
= self
->session
->iconic
;
915 self
->skip_pager
= self
->session
->skip_pager
;
916 self
->skip_taskbar
= self
->session
->skip_taskbar
;
917 self
->fullscreen
= self
->session
->fullscreen
;
918 self
->above
= self
->session
->above
;
919 self
->below
= self
->session
->below
;
920 self
->max_horz
= self
->session
->max_horz
;
921 self
->max_vert
= self
->session
->max_vert
;
922 self
->undecorated
= self
->session
->undecorated
;
925 static gboolean
client_restore_session_stacking(ObClient
*self
)
929 if (!self
->session
) return FALSE
;
931 mypos
= g_list_find(session_saved_state
, self
->session
);
932 if (!mypos
) return FALSE
;
934 /* start above me and look for the first client */
935 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
938 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
939 ObClient
*c
= cit
->data
;
940 /* found a client that was in the session, so go below it */
941 if (c
->session
== it
->data
) {
942 stacking_below(CLIENT_AS_WINDOW(self
),
943 CLIENT_AS_WINDOW(cit
->data
));
951 void client_move_onscreen(ObClient
*self
, gboolean rude
)
953 gint x
= self
->area
.x
;
954 gint y
= self
->area
.y
;
955 if (client_find_onscreen(self
, &x
, &y
,
957 self
->area
.height
, rude
)) {
958 client_move(self
, x
, y
);
962 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
965 gint ox
= *x
, oy
= *y
;
966 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
971 RECT_SET(desired
, *x
, *y
, w
, h
);
972 frame_rect_to_frame(self
->frame
, &desired
);
974 /* get where the frame would be */
975 frame_client_gravity(self
->frame
, x
, y
);
977 /* get the requested size of the window with decorations */
978 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
979 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
981 /* If rudeness wasn't requested, then still be rude in a given direction
982 if the client is not moving, only resizing in that direction */
984 Point oldtl
, oldtr
, oldbl
, oldbr
;
985 Point newtl
, newtr
, newbl
, newbr
;
986 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
988 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
989 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
990 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
991 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
992 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
994 POINT_SET(newtl
, *x
, *y
);
995 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
996 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
997 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
999 /* is it moving or just resizing from some corner? */
1000 stationary_l
= oldtl
.x
== newtl
.x
;
1001 stationary_r
= oldtr
.x
== newtr
.x
;
1002 stationary_t
= oldtl
.y
== newtl
.y
;
1003 stationary_b
= oldbl
.y
== newbl
.y
;
1005 /* if left edge is growing and didnt move right edge */
1006 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1008 /* if right edge is growing and didnt move left edge */
1009 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1011 /* if top edge is growing and didnt move bottom edge */
1012 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1014 /* if bottom edge is growing and didnt move top edge */
1015 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1019 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1022 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1023 if (i
< screen_num_monitors
- 1)
1026 /* the window is not inside any monitor! so just use the first
1028 a
= screen_area(self
->desktop
, 0, NULL
);
1030 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1032 /* This makes sure windows aren't entirely outside of the screen so you
1033 can't see them at all.
1034 It makes sure 10% of the window is on the screen at least. At don't
1035 let it move itself off the top of the screen, which would hide the
1036 titlebar on you. (The user can still do this if they want too, it's
1037 only limiting the application.
1039 if (client_normal(self
)) {
1040 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1041 *x
= a
->x
+ a
->width
- fw
/10;
1042 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1043 *y
= a
->y
+ a
->height
- fh
/10;
1044 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1045 *x
= a
->x
- fw
*9/10;
1046 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1047 *y
= a
->y
- fh
*9/10;
1050 /* This here doesn't let windows even a pixel outside the
1051 struts/screen. When called from client_manage, programs placing
1052 themselves are forced completely onscreen, while things like
1053 xterm -geometry resolution-width/2 will work fine. Trying to
1054 place it completely offscreen will be handled in the above code.
1055 Sorry for this confused comment, i am tired. */
1056 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1057 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1058 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1060 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1061 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1062 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1067 /* get where the client should be */
1068 frame_frame_gravity(self
->frame
, x
, y
);
1070 return ox
!= *x
|| oy
!= *y
;
1073 static void client_get_all(ObClient
*self
, gboolean real
)
1075 /* this is needed for the frame to set itself up */
1076 client_get_area(self
);
1078 /* these things can change the decor and functions of the window */
1080 client_get_mwm_hints(self
);
1081 /* this can change the mwmhints for special cases */
1082 client_get_type_and_transientness(self
);
1083 client_get_state(self
);
1084 client_update_normal_hints(self
);
1086 /* get the session related properties, these can change decorations
1087 from per-app settings */
1088 client_get_session_ids(self
);
1090 /* now we got everything that can affect the decorations */
1094 /* get this early so we have it for debugging */
1095 client_update_title(self
);
1097 client_update_protocols(self
);
1099 client_update_wmhints(self
);
1100 /* this may have already been called from client_update_wmhints */
1101 if (!self
->parents
&& !self
->transient_for_group
)
1102 client_update_transient_for(self
);
1104 client_get_startup_id(self
);
1105 client_get_desktop(self
);/* uses transient data/group/startup id if a
1106 desktop is not specified */
1107 client_get_shaped(self
);
1110 /* a couple type-based defaults for new windows */
1112 /* this makes sure that these windows appear on all desktops */
1113 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1114 self
->desktop
= DESKTOP_ALL
;
1118 client_update_sync_request_counter(self
);
1121 client_get_colormap(self
);
1122 client_update_strut(self
);
1123 client_update_icons(self
);
1124 client_update_icon_geometry(self
);
1127 static void client_get_startup_id(ObClient
*self
)
1129 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1131 PROP_GETS(self
->group
->leader
,
1132 net_startup_id
, utf8
, &self
->startup_id
);
1135 static void client_get_area(ObClient
*self
)
1137 XWindowAttributes wattrib
;
1140 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1141 g_assert(ret
!= BadWindow
);
1143 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1144 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1145 self
->border_width
= wattrib
.border_width
;
1147 ob_debug("client area: %d %d %d %d bw %d\n", wattrib
.x
, wattrib
.y
,
1148 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1151 static void client_get_desktop(ObClient
*self
)
1153 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1155 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1156 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1157 self
->desktop
= screen_num_desktops
- 1;
1160 ob_debug("client requested desktop 0x%x\n", self
->desktop
);
1163 gboolean first
= TRUE
;
1164 guint all
= screen_num_desktops
; /* not a valid value */
1166 /* if they are all on one desktop, then open it on the
1168 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1169 ObClient
*c
= it
->data
;
1171 if (c
->desktop
== DESKTOP_ALL
) continue;
1177 else if (all
!= c
->desktop
)
1178 all
= screen_num_desktops
; /* make it invalid */
1180 if (all
!= screen_num_desktops
) {
1181 self
->desktop
= all
;
1183 ob_debug("client desktop set from parents: 0x%x\n",
1186 /* try get from the startup-notification protocol */
1187 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1188 if (self
->desktop
>= screen_num_desktops
&&
1189 self
->desktop
!= DESKTOP_ALL
)
1190 self
->desktop
= screen_num_desktops
- 1;
1191 ob_debug("client desktop set from startup-notification: 0x%x\n",
1194 /* defaults to the current desktop */
1196 self
->desktop
= screen_desktop
;
1197 ob_debug("client desktop set to the current desktop: %d\n",
1203 static void client_get_state(ObClient
*self
)
1208 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1210 for (i
= 0; i
< num
; ++i
) {
1211 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1213 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1214 self
->shaded
= TRUE
;
1215 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1216 self
->iconic
= TRUE
;
1217 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1218 self
->skip_taskbar
= TRUE
;
1219 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1220 self
->skip_pager
= TRUE
;
1221 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1222 self
->fullscreen
= TRUE
;
1223 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1224 self
->max_vert
= TRUE
;
1225 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1226 self
->max_horz
= TRUE
;
1227 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1229 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1231 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1232 self
->demands_attention
= TRUE
;
1233 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1234 self
->undecorated
= TRUE
;
1241 static void client_get_shaped(ObClient
*self
)
1243 self
->shaped
= FALSE
;
1245 if (extensions_shape
) {
1250 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1252 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1253 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1255 self
->shaped
= (s
!= 0);
1260 void client_update_transient_for(ObClient
*self
)
1263 ObClient
*target
= NULL
;
1264 gboolean trangroup
= FALSE
;
1266 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1267 if (t
!= self
->window
) { /* cant be transient to itself! */
1268 target
= g_hash_table_lookup(window_map
, &t
);
1269 /* if this happens then we need to check for it*/
1270 g_assert(target
!= self
);
1271 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1272 /* this can happen when a dialog is a child of
1273 a dockapp, for example */
1278 /* Setting the transient_for to Root is actually illegal, however
1279 applications from time have done this to specify transient for
1281 if (!target
&& self
->group
&& t
== RootWindow(ob_display
, ob_screen
))
1283 } else if (self
->group
&& self
->transient
)
1286 client_update_transient_tree(self
, self
->group
, self
->group
,
1287 self
->transient_for_group
, trangroup
,
1288 client_direct_parent(self
), target
);
1289 self
->transient_for_group
= trangroup
;
1293 static void client_update_transient_tree(ObClient
*self
,
1294 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1295 gboolean oldgtran
, gboolean newgtran
,
1296 ObClient
* oldparent
,
1297 ObClient
*newparent
)
1302 g_assert(!oldgtran
|| oldgroup
);
1303 g_assert(!newgtran
|| newgroup
);
1304 g_assert((!oldgtran
&& !oldparent
) ||
1305 (oldgtran
&& !oldparent
) ||
1306 (!oldgtran
&& oldparent
));
1307 g_assert((!newgtran
&& !newparent
) ||
1308 (newgtran
&& !newparent
) ||
1309 (!newgtran
&& newparent
));
1312 Group transient windows are not allowed to have other group
1313 transient windows as their children.
1317 /* No change has occured */
1318 if (oldgroup
== newgroup
&&
1319 oldgtran
== newgtran
&&
1320 oldparent
== newparent
) return;
1322 /** Remove the client from the transient tree **/
1324 for (it
= self
->transients
; it
; it
= next
) {
1325 next
= g_slist_next(it
);
1327 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1328 c
->parents
= g_slist_remove(c
->parents
, self
);
1330 for (it
= self
->parents
; it
; it
= next
) {
1331 next
= g_slist_next(it
);
1333 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1334 c
->transients
= g_slist_remove(c
->transients
, self
);
1337 /** Re-add the client to the transient tree **/
1339 /* If we're transient for a group then we need to add ourselves to all our
1342 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1345 !client_search_top_direct_parent(c
)->transient_for_group
&&
1348 c
->transients
= g_slist_prepend(c
->transients
, self
);
1349 self
->parents
= g_slist_prepend(self
->parents
, c
);
1354 /* If we are now transient for a single window we need to add ourselves to
1357 WARNING: Cyclical transient ness is possible if two windows are
1358 transient for eachother.
1360 else if (newparent
&&
1361 /* don't make ourself its child if it is already our child */
1362 !client_is_direct_child(self
, newparent
) &&
1363 client_normal(newparent
))
1365 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1366 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1369 /* Add any group transient windows to our children. But if we're transient
1370 for the group, then other group transients are not our children.
1372 WARNING: Cyclical transient-ness is possible. For e.g. if:
1373 A is transient for the group
1374 B is transient for A
1375 C is transient for B
1376 A can't be transient for C or we have a cycle
1378 if (!newgtran
&& newgroup
&&
1380 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1381 client_normal(self
))
1383 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1385 if (c
!= self
&& c
->transient_for_group
&&
1386 /* Don't make it our child if it is already our parent */
1387 !client_is_direct_child(c
, self
))
1389 self
->transients
= g_slist_prepend(self
->transients
, c
);
1390 c
->parents
= g_slist_prepend(c
->parents
, self
);
1395 /** If we change our group transient-ness, our children change their
1396 effect group transient-ness, which affects how they relate to other
1399 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1401 if (!c
->transient_for_group
)
1402 client_update_transient_tree(c
, c
->group
, c
->group
,
1403 c
->transient_for_group
,
1404 c
->transient_for_group
,
1405 client_direct_parent(c
),
1406 client_direct_parent(c
));
1410 static void client_get_mwm_hints(ObClient
*self
)
1415 self
->mwmhints
.flags
= 0; /* default to none */
1417 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1419 if (num
>= OB_MWM_ELEMENTS
) {
1420 self
->mwmhints
.flags
= hints
[0];
1421 self
->mwmhints
.functions
= hints
[1];
1422 self
->mwmhints
.decorations
= hints
[2];
1428 void client_get_type_and_transientness(ObClient
*self
)
1435 self
->transient
= FALSE
;
1437 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1438 /* use the first value that we know about in the array */
1439 for (i
= 0; i
< num
; ++i
) {
1440 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1441 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1442 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1443 self
->type
= OB_CLIENT_TYPE_DOCK
;
1444 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1445 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1446 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1447 self
->type
= OB_CLIENT_TYPE_MENU
;
1448 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1449 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1450 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1451 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1452 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1453 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1454 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1455 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1456 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1457 /* prevent this window from getting any decor or
1459 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1460 OB_MWM_FLAG_DECORATIONS
);
1461 self
->mwmhints
.decorations
= 0;
1462 self
->mwmhints
.functions
= 0;
1464 if (self
->type
!= (ObClientType
) -1)
1465 break; /* grab the first legit type */
1470 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1471 self
->transient
= TRUE
;
1473 if (self
->type
== (ObClientType
) -1) {
1474 /*the window type hint was not set, which means we either classify
1475 ourself as a normal window or a dialog, depending on if we are a
1477 if (self
->transient
)
1478 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1480 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1483 /* then, based on our type, we can update our transientness.. */
1484 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1485 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1486 self
->type
== OB_CLIENT_TYPE_MENU
||
1487 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1489 self
->transient
= TRUE
;
1493 void client_update_protocols(ObClient
*self
)
1496 guint num_return
, i
;
1498 self
->focus_notify
= FALSE
;
1499 self
->delete_window
= FALSE
;
1501 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1502 for (i
= 0; i
< num_return
; ++i
) {
1503 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1504 /* this means we can request the window to close */
1505 self
->delete_window
= TRUE
;
1506 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1507 /* if this protocol is requested, then the window will be
1508 notified whenever we want it to receive focus */
1509 self
->focus_notify
= TRUE
;
1511 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1512 /* if this protocol is requested, then resizing the
1513 window will be synchronized between the frame and the
1515 self
->sync_request
= TRUE
;
1523 void client_update_sync_request_counter(ObClient
*self
)
1527 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1528 self
->sync_counter
= i
;
1530 self
->sync_counter
= None
;
1534 void client_get_colormap(ObClient
*self
)
1536 XWindowAttributes wa
;
1538 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1539 client_update_colormap(self
, wa
.colormap
);
1542 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1544 if (colormap
== self
->colormap
) return;
1546 ob_debug("Setting client %s colormap: 0x%x\n", self
->title
, colormap
);
1548 if (client_focused(self
)) {
1549 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1550 self
->colormap
= colormap
;
1551 screen_install_colormap(self
, FALSE
); /* install new one */
1553 self
->colormap
= colormap
;
1556 void client_update_normal_hints(ObClient
*self
)
1562 self
->min_ratio
= 0.0f
;
1563 self
->max_ratio
= 0.0f
;
1564 SIZE_SET(self
->size_inc
, 1, 1);
1565 SIZE_SET(self
->base_size
, 0, 0);
1566 SIZE_SET(self
->min_size
, 0, 0);
1567 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1569 /* get the hints from the window */
1570 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1571 /* normal windows can't request placement! har har
1572 if (!client_normal(self))
1574 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1575 self
->sized
= (size
.flags
& (PSize
|USSize
));
1577 if (size
.flags
& PWinGravity
)
1578 self
->gravity
= size
.win_gravity
;
1580 if (size
.flags
& PAspect
) {
1581 if (size
.min_aspect
.y
)
1583 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1584 if (size
.max_aspect
.y
)
1586 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1589 if (size
.flags
& PMinSize
)
1590 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1592 if (size
.flags
& PMaxSize
)
1593 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1595 if (size
.flags
& PBaseSize
)
1596 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1598 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1599 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1601 ob_debug("Normal hints: min size (%d %d) max size (%d %d)\n "
1602 "size inc (%d %d) base size (%d %d)\n",
1603 self
->min_size
.width
, self
->min_size
.height
,
1604 self
->max_size
.width
, self
->max_size
.height
,
1605 self
->size_inc
.width
, self
->size_inc
.height
,
1606 self
->base_size
.width
, self
->base_size
.height
);
1609 ob_debug("Normal hints: not set\n");
1612 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1614 /* start with everything (cept fullscreen) */
1616 (OB_FRAME_DECOR_TITLEBAR
|
1617 OB_FRAME_DECOR_HANDLE
|
1618 OB_FRAME_DECOR_GRIPS
|
1619 OB_FRAME_DECOR_BORDER
|
1620 OB_FRAME_DECOR_ICON
|
1621 OB_FRAME_DECOR_ALLDESKTOPS
|
1622 OB_FRAME_DECOR_ICONIFY
|
1623 OB_FRAME_DECOR_MAXIMIZE
|
1624 OB_FRAME_DECOR_SHADE
|
1625 OB_FRAME_DECOR_CLOSE
);
1627 (OB_CLIENT_FUNC_RESIZE
|
1628 OB_CLIENT_FUNC_MOVE
|
1629 OB_CLIENT_FUNC_ICONIFY
|
1630 OB_CLIENT_FUNC_MAXIMIZE
|
1631 OB_CLIENT_FUNC_SHADE
|
1632 OB_CLIENT_FUNC_CLOSE
|
1633 OB_CLIENT_FUNC_BELOW
|
1634 OB_CLIENT_FUNC_ABOVE
|
1635 OB_CLIENT_FUNC_UNDECORATE
);
1637 if (!(self
->min_size
.width
< self
->max_size
.width
||
1638 self
->min_size
.height
< self
->max_size
.height
))
1639 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1641 switch (self
->type
) {
1642 case OB_CLIENT_TYPE_NORMAL
:
1643 /* normal windows retain all of the possible decorations and
1644 functionality, and can be fullscreen */
1645 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1648 case OB_CLIENT_TYPE_DIALOG
:
1649 /* sometimes apps make dialog windows fullscreen for some reason (for
1650 e.g. kpdf does this..) */
1651 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1654 case OB_CLIENT_TYPE_UTILITY
:
1655 /* these windows don't have anything added or removed by default */
1658 case OB_CLIENT_TYPE_MENU
:
1659 case OB_CLIENT_TYPE_TOOLBAR
:
1660 /* these windows can't iconify or maximize */
1661 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1662 OB_FRAME_DECOR_MAXIMIZE
);
1663 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1664 OB_CLIENT_FUNC_MAXIMIZE
);
1667 case OB_CLIENT_TYPE_SPLASH
:
1668 /* these don't get get any decorations, and the only thing you can
1669 do with them is move them */
1670 self
->decorations
= 0;
1671 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1674 case OB_CLIENT_TYPE_DESKTOP
:
1675 /* these windows are not manipulated by the window manager */
1676 self
->decorations
= 0;
1677 self
->functions
= 0;
1680 case OB_CLIENT_TYPE_DOCK
:
1681 /* these windows are not manipulated by the window manager, but they
1682 can set below layer which has a special meaning */
1683 self
->decorations
= 0;
1684 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1688 /* Mwm Hints are applied subtractively to what has already been chosen for
1689 decor and functionality */
1690 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1691 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1692 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1693 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1695 /* if the mwm hints request no handle or title, then all
1696 decorations are disabled, but keep the border if that's
1698 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1699 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1701 self
->decorations
= 0;
1706 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1707 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1708 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1709 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1710 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1711 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1712 /* dont let mwm hints kill any buttons
1713 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1714 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1715 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1716 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1718 /* dont let mwm hints kill the close button
1719 if (! (self->mwmhints.functions & MwmFunc_Close))
1720 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1724 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1725 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1726 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1727 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1728 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1729 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1731 /* can't maximize without moving/resizing */
1732 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1733 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1734 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1735 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1736 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1739 if (self
->max_horz
&& self
->max_vert
) {
1740 /* you can't resize fully maximized windows */
1741 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1742 /* kill the handle on fully maxed windows */
1743 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1746 /* If there are no decorations to remove, don't allow the user to try
1748 if (self
->decorations
== 0)
1749 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1751 /* finally, the user can have requested no decorations, which overrides
1752 everything (but doesnt give it a border if it doesnt have one) */
1753 if (self
->undecorated
)
1754 self
->decorations
= 0;
1756 /* if we don't have a titlebar, then we cannot shade! */
1757 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1758 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1760 /* now we need to check against rules for the client's current state */
1761 if (self
->fullscreen
) {
1762 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1763 OB_CLIENT_FUNC_FULLSCREEN
|
1764 OB_CLIENT_FUNC_ICONIFY
);
1765 self
->decorations
= 0;
1768 client_change_allowed_actions(self
);
1771 /* force reconfigure to make sure decorations are updated */
1772 client_reconfigure(self
, TRUE
);
1775 static void client_change_allowed_actions(ObClient
*self
)
1780 /* desktop windows are kept on all desktops */
1781 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1782 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1784 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1785 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1786 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1787 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1788 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1789 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1790 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1791 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1792 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1793 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1794 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1795 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1796 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1797 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1798 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1800 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1801 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1802 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1803 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1804 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1805 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1807 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1809 /* make sure the window isn't breaking any rules now */
1811 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1812 if (self
->frame
) client_shade(self
, FALSE
);
1813 else self
->shaded
= FALSE
;
1815 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1816 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
, FALSE
);
1817 else self
->iconic
= FALSE
;
1819 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1820 if (self
->frame
) client_fullscreen(self
, FALSE
);
1821 else self
->fullscreen
= FALSE
;
1823 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1825 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1826 else self
->max_vert
= self
->max_horz
= FALSE
;
1830 void client_update_wmhints(ObClient
*self
)
1834 /* assume a window takes input if it doesnt specify */
1835 self
->can_focus
= TRUE
;
1837 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1840 if (hints
->flags
& InputHint
)
1841 self
->can_focus
= hints
->input
;
1843 /* only do this when first managing the window *AND* when we aren't
1845 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1846 if (hints
->flags
& StateHint
)
1847 self
->iconic
= hints
->initial_state
== IconicState
;
1850 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1851 if (self
->urgent
&& !ur
)
1852 client_hilite(self
, TRUE
);
1853 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1854 client_hilite(self
, FALSE
);
1856 if (!(hints
->flags
& WindowGroupHint
))
1857 hints
->window_group
= None
;
1859 /* did the group state change? */
1860 if (hints
->window_group
!=
1861 (self
->group
? self
->group
->leader
: None
))
1863 ObGroup
*oldgroup
= self
->group
;
1865 /* remove from the old group if there was one */
1866 if (self
->group
!= NULL
) {
1867 group_remove(self
->group
, self
);
1871 /* add ourself to the group if we have one */
1872 if (hints
->window_group
!= None
) {
1873 self
->group
= group_add(hints
->window_group
, self
);
1876 /* Put ourselves into the new group's transient tree, and remove
1877 ourselves from the old group's */
1878 client_update_transient_tree(self
, oldgroup
, self
->group
,
1879 self
->transient_for_group
,
1880 self
->transient_for_group
,
1881 client_direct_parent(self
),
1882 client_direct_parent(self
));
1884 /* Lastly, being in a group, or not, can change if the window is
1885 transient for anything.
1887 The logic for this is:
1888 self->transient = TRUE always if the window wants to be
1889 transient for something, even if transient_for was NULL because
1890 it wasn't in a group before.
1892 If parents was NULL and oldgroup was NULL we can assume
1893 that when we add the new group, it will become transient for
1896 If transient_for_group is TRUE, then it must have already
1897 had a group. If it is getting a new group, the above call to
1898 client_update_transient_tree has already taken care of
1899 everything ! If it is losing all group status then it will
1900 no longer be transient for anything and that needs to be
1903 if (self
->transient
&&
1904 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1905 (self
->transient_for_group
&& !self
->group
)))
1906 client_update_transient_for(self
);
1909 /* the WM_HINTS can contain an icon */
1910 if (hints
->flags
& IconPixmapHint
)
1911 client_update_icons(self
);
1917 void client_update_title(ObClient
*self
)
1920 gchar
*visible
= NULL
;
1922 g_free(self
->title
);
1925 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1926 /* try old x stuff */
1927 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1928 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1929 if (self
->transient
) {
1931 GNOME alert windows are not given titles:
1932 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1934 data
= g_strdup("");
1936 data
= g_strdup("Unnamed Window");
1940 if (self
->client_machine
) {
1941 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1946 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1947 self
->title
= visible
;
1950 frame_adjust_title(self
->frame
);
1952 /* update the icon title */
1954 g_free(self
->icon_title
);
1957 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1958 /* try old x stuff */
1959 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1960 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1961 data
= g_strdup(self
->title
);
1963 if (self
->client_machine
) {
1964 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1969 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
1970 self
->icon_title
= visible
;
1973 void client_update_strut(ObClient
*self
)
1977 gboolean got
= FALSE
;
1980 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1984 STRUT_PARTIAL_SET(strut
,
1985 data
[0], data
[2], data
[1], data
[3],
1986 data
[4], data
[5], data
[8], data
[9],
1987 data
[6], data
[7], data
[10], data
[11]);
1993 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1999 /* use the screen's width/height */
2000 a
= screen_physical_area_all_monitors();
2002 STRUT_PARTIAL_SET(strut
,
2003 data
[0], data
[2], data
[1], data
[3],
2004 a
->y
, a
->y
+ a
->height
- 1,
2005 a
->x
, a
->x
+ a
->width
- 1,
2006 a
->y
, a
->y
+ a
->height
- 1,
2007 a
->x
, a
->x
+ a
->width
- 1);
2014 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2015 0, 0, 0, 0, 0, 0, 0, 0);
2017 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2018 self
->strut
= strut
;
2020 /* updating here is pointless while we're being mapped cuz we're not in
2021 the client list yet */
2023 screen_update_areas();
2027 void client_update_icons(ObClient
*self
)
2033 for (i
= 0; i
< self
->nicons
; ++i
)
2034 g_free(self
->icons
[i
].data
);
2035 if (self
->nicons
> 0)
2036 g_free(self
->icons
);
2039 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2040 /* figure out how many valid icons are in here */
2042 while (num
- i
> 2) {
2046 if (i
> num
|| w
*h
== 0) break;
2050 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2052 /* store the icons */
2054 for (j
= 0; j
< self
->nicons
; ++j
) {
2057 w
= self
->icons
[j
].width
= data
[i
++];
2058 h
= self
->icons
[j
].height
= data
[i
++];
2060 if (w
*h
== 0) continue;
2062 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2063 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2068 self
->icons
[j
].data
[t
] =
2069 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2070 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2071 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2072 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2081 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2082 if (hints
->flags
& IconPixmapHint
) {
2084 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2085 xerror_set_ignore(TRUE
);
2086 if (!RrPixmapToRGBA(ob_rr_inst
,
2088 (hints
->flags
& IconMaskHint
?
2089 hints
->icon_mask
: None
),
2090 &self
->icons
[0].width
,
2091 &self
->icons
[0].height
,
2092 &self
->icons
[0].data
))
2094 g_free(self
->icons
);
2097 xerror_set_ignore(FALSE
);
2103 /* set the default icon onto the window
2104 in theory, this could be a race, but if a window doesn't set an icon
2105 or removes it entirely, it's not very likely it is going to set one
2106 right away afterwards
2108 if it has parents, then one of them will have an icon already
2110 if (self
->nicons
== 0 && !self
->parents
) {
2111 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2114 data
= g_new(gulong
, 48*48+2);
2115 data
[0] = data
[1] = 48;
2116 for (i
= 0; i
< 48*48; ++i
)
2117 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2118 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2119 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2120 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2121 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2123 } else if (self
->frame
)
2124 /* don't draw the icon empty if we're just setting one now anyways,
2125 we'll get the property change any second */
2126 frame_adjust_icon(self
->frame
);
2129 void client_update_icon_geometry(ObClient
*self
)
2134 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2136 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2139 /* don't let them set it with an area < 0 */
2140 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2141 MAX(data
[2],0), MAX(data
[3],0));
2145 static void client_get_session_ids(ObClient
*self
)
2152 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2155 /* get the SM_CLIENT_ID */
2158 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2160 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2162 /* get the WM_CLASS (name and class). make them "" if they are not
2166 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2168 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2172 self
->name
= g_strdup(ss
[0]);
2174 self
->class = g_strdup(ss
[1]);
2179 if (self
->name
== NULL
) self
->name
= g_strdup("");
2180 if (self
->class == NULL
) self
->class = g_strdup("");
2182 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2185 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2187 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2192 self
->role
= g_strdup("");
2194 /* get the WM_COMMAND */
2198 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2200 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2203 /* merge/mash them all together */
2204 gchar
*merge
= NULL
;
2207 for (i
= 0; ss
[i
]; ++i
) {
2210 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2212 merge
= g_strconcat(ss
[i
], NULL
);
2217 self
->wm_command
= merge
;
2220 /* get the WM_CLIENT_MACHINE */
2223 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2225 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2228 gchar localhost
[128];
2230 gethostname(localhost
, 127);
2231 localhost
[127] = '\0';
2232 if (strcmp(localhost
, s
) != 0)
2233 self
->client_machine
= s
;
2239 static void client_change_wm_state(ObClient
*self
)
2244 old
= self
->wmstate
;
2246 if (self
->shaded
|| self
->iconic
||
2247 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2249 self
->wmstate
= IconicState
;
2251 self
->wmstate
= NormalState
;
2253 if (old
!= self
->wmstate
) {
2254 PROP_MSG(self
->window
, kde_wm_change_state
,
2255 self
->wmstate
, 1, 0, 0);
2257 state
[0] = self
->wmstate
;
2259 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2263 static void client_change_state(ObClient
*self
)
2265 gulong netstate
[12];
2270 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2272 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2274 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2275 if (self
->skip_taskbar
)
2276 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2277 if (self
->skip_pager
)
2278 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2279 if (self
->fullscreen
)
2280 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2282 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2284 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2286 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2288 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2289 if (self
->demands_attention
)
2290 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2291 if (self
->undecorated
)
2292 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2293 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2296 frame_adjust_state(self
->frame
);
2299 ObClient
*client_search_focus_tree(ObClient
*self
)
2304 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2305 if (client_focused(it
->data
)) return it
->data
;
2306 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2311 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2313 if (self
->parents
) {
2316 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2317 ObClient
*c
= it
->data
;
2318 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2324 /* this function checks the whole tree, the client_search_focus_tree
2325 does not, so we need to check this window */
2326 if (client_focused(self
))
2328 return client_search_focus_tree(self
);
2332 ObClient
*client_search_focus_group_full(ObClient
*self
)
2337 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2338 ObClient
*c
= it
->data
;
2340 if (client_focused(c
)) return c
;
2341 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2344 if (client_focused(self
)) return self
;
2348 gboolean
client_has_parent(ObClient
*self
)
2350 return self
->parents
!= NULL
;
2353 static ObStackingLayer
calc_layer(ObClient
*self
)
2358 monitor
= screen_physical_area_monitor(client_monitor(self
));
2360 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2361 l
= OB_STACKING_LAYER_DESKTOP
;
2362 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2363 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2364 else l
= OB_STACKING_LAYER_ABOVE
;
2366 else if ((self
->fullscreen
||
2367 /* No decorations and fills the monitor = oldskool fullscreen.
2368 But not for maximized windows.
2370 (self
->decorations
== 0 &&
2371 !(self
->max_horz
&& self
->max_vert
) &&
2372 RECT_EQUAL(self
->area
, *monitor
))) &&
2373 (client_focused(self
) || client_search_focus_tree(self
)))
2374 l
= OB_STACKING_LAYER_FULLSCREEN
;
2375 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2376 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2377 else l
= OB_STACKING_LAYER_NORMAL
;
2384 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2385 ObStackingLayer min
)
2387 ObStackingLayer old
, own
;
2391 own
= calc_layer(self
);
2392 self
->layer
= MAX(own
, min
);
2394 if (self
->layer
!= old
) {
2395 stacking_remove(CLIENT_AS_WINDOW(self
));
2396 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2399 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2400 client_calc_layer_recursive(it
->data
, orig
,
2404 void client_calc_layer(ObClient
*self
)
2411 /* transients take on the layer of their parents */
2412 it
= client_search_all_top_parents(self
);
2414 for (; it
; it
= g_slist_next(it
))
2415 client_calc_layer_recursive(it
->data
, orig
, 0);
2418 gboolean
client_should_show(ObClient
*self
)
2422 if (client_normal(self
) && screen_showing_desktop
)
2424 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2430 gboolean
client_show(ObClient
*self
)
2432 gboolean show
= FALSE
;
2434 if (client_should_show(self
)) {
2435 frame_show(self
->frame
);
2438 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2439 it needs to be in IconicState. This includes when it is on another
2442 client_change_wm_state(self
);
2447 gboolean
client_hide(ObClient
*self
)
2449 gboolean hide
= FALSE
;
2451 if (!client_should_show(self
)) {
2452 if (self
== focus_client
) {
2453 /* if there is a grab going on, then we need to cancel it. if we
2454 move focus during the grab, applications will get
2455 NotifyWhileGrabbed events and ignore them !
2457 actions should not rely on being able to move focus during an
2460 event_cancel_all_key_grabs();
2463 /* We don't need to ignore enter events here.
2464 The window can hide/iconify in 3 different ways:
2465 1 - through an x message. in this case we ignore all enter events
2466 caused by responding to the x message (unless underMouse)
2467 2 - by a keyboard action. in this case we ignore all enter events
2468 caused by the action
2469 3 - by a mouse action. in this case they are doing stuff with the
2470 mouse and focus _should_ move.
2472 Also in action_end, we simulate an enter event that can't be ignored
2473 so trying to ignore them is futile in case 3 anyways
2476 frame_hide(self
->frame
);
2479 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2480 it needs to be in IconicState. This includes when it is on another
2483 client_change_wm_state(self
);
2488 void client_showhide(ObClient
*self
)
2490 if (!client_show(self
))
2494 gboolean
client_normal(ObClient
*self
) {
2495 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2496 self
->type
== OB_CLIENT_TYPE_DOCK
||
2497 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2500 gboolean
client_helper(ObClient
*self
)
2502 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2503 self
->type
== OB_CLIENT_TYPE_MENU
||
2504 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2507 gboolean
client_mouse_focusable(ObClient
*self
)
2509 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2510 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2511 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2512 self
->type
== OB_CLIENT_TYPE_DOCK
);
2515 gboolean
client_enter_focusable(ObClient
*self
)
2517 /* you can focus desktops but it shouldn't on enter */
2518 return (client_mouse_focusable(self
) &&
2519 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2523 static void client_apply_startup_state(ObClient
*self
,
2524 gint x
, gint y
, gint w
, gint h
)
2526 /* save the states that we are going to apply */
2527 gboolean iconic
= self
->iconic
;
2528 gboolean fullscreen
= self
->fullscreen
;
2529 gboolean undecorated
= self
->undecorated
;
2530 gboolean shaded
= self
->shaded
;
2531 gboolean demands_attention
= self
->demands_attention
;
2532 gboolean max_horz
= self
->max_horz
;
2533 gboolean max_vert
= self
->max_vert
;
2537 /* turn them all off in the client, so they won't affect the window
2539 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2540 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2542 /* move the client to its placed position, or it it's already there,
2543 generate a ConfigureNotify telling the client where it is.
2545 do this after adjusting the frame. otherwise it gets all weird and
2546 clients don't work right
2548 do this before applying the states so they have the correct
2549 pre-max/pre-fullscreen values
2551 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2552 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2553 self
->window
, x
, y
, w
, h
);
2554 /* save the area, and make it where it should be for the premax stuff */
2555 oldarea
= self
->area
;
2556 RECT_SET(self
->area
, x
, y
, w
, h
);
2558 /* apply the states. these are in a carefully crafted order.. */
2561 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2563 client_fullscreen(self
, TRUE
);
2565 client_set_undecorated(self
, TRUE
);
2567 client_shade(self
, TRUE
);
2568 if (demands_attention
)
2569 client_hilite(self
, TRUE
);
2571 if (max_vert
&& max_horz
)
2572 client_maximize(self
, TRUE
, 0);
2574 client_maximize(self
, TRUE
, 2);
2576 client_maximize(self
, TRUE
, 1);
2578 /* if the window hasn't been configured yet, then do so now, in fact the
2579 x,y,w,h may _not_ be the same as the area rect, which can end up
2580 meaning that the client isn't properly moved/resized by the fullscreen
2582 pho can cause this because it maps at size of the screen but not 0,0
2583 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2584 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2585 cuz thats where the pre-fullscreen will be. however the actual area is
2586 not, so this needs to be called even if we have fullscreened/maxed
2588 self
->area
= oldarea
;
2589 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2591 /* set the desktop hint, to make sure that it always exists */
2592 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2594 /* nothing to do for the other states:
2603 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2605 /* these should be the current values. this is for when you're not moving,
2607 g_assert(*x
== self
->area
.x
);
2608 g_assert(oldw
== self
->area
.width
);
2611 switch (self
->gravity
) {
2613 case NorthWestGravity
:
2615 case SouthWestGravity
:
2622 *x
-= (neww
- oldw
) / 2;
2624 case NorthEastGravity
:
2626 case SouthEastGravity
:
2632 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2634 /* these should be the current values. this is for when you're not moving,
2636 g_assert(*y
== self
->area
.y
);
2637 g_assert(oldh
== self
->area
.height
);
2640 switch (self
->gravity
) {
2642 case NorthWestGravity
:
2644 case NorthEastGravity
:
2651 *y
-= (newh
- oldh
) / 2;
2653 case SouthWestGravity
:
2655 case SouthEastGravity
:
2661 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2662 gint
*logicalw
, gint
*logicalh
,
2665 Rect desired
= {*x
, *y
, *w
, *h
};
2666 frame_rect_to_frame(self
->frame
, &desired
);
2668 /* make the frame recalculate its dimentions n shit without changing
2669 anything visible for real, this way the constraints below can work with
2670 the updated frame dimensions. */
2671 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2673 /* gets the frame's position */
2674 frame_client_gravity(self
->frame
, x
, y
);
2676 /* these positions are frame positions, not client positions */
2678 /* set the size and position if fullscreen */
2679 if (self
->fullscreen
) {
2683 i
= screen_find_monitor(&desired
);
2684 a
= screen_physical_area_monitor(i
);
2691 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2695 } else if (self
->max_horz
|| self
->max_vert
) {
2699 /* use all possible struts when maximizing to the full screen */
2700 i
= screen_find_monitor(&desired
);
2701 a
= screen_area(self
->desktop
, i
,
2702 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2704 /* set the size and position if maximized */
2705 if (self
->max_horz
) {
2707 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2709 if (self
->max_vert
) {
2711 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2714 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2720 /* gets the client's position */
2721 frame_frame_gravity(self
->frame
, x
, y
);
2723 /* work within the prefered sizes given by the window */
2724 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2725 gint basew
, baseh
, minw
, minh
;
2727 gfloat minratio
, maxratio
;
2729 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2730 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2731 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2732 0 : self
->min_ratio
;
2733 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2734 0 : self
->max_ratio
;
2736 /* base size is substituted with min size if not specified */
2737 if (self
->base_size
.width
|| self
->base_size
.height
) {
2738 basew
= self
->base_size
.width
;
2739 baseh
= self
->base_size
.height
;
2741 basew
= self
->min_size
.width
;
2742 baseh
= self
->min_size
.height
;
2744 /* min size is substituted with base size if not specified */
2745 if (self
->min_size
.width
|| self
->min_size
.height
) {
2746 minw
= self
->min_size
.width
;
2747 minh
= self
->min_size
.height
;
2749 minw
= self
->base_size
.width
;
2750 minh
= self
->base_size
.height
;
2753 /* if this is a user-requested resize, then check against min/max
2756 /* smaller than min size or bigger than max size? */
2757 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2758 if (*w
< minw
) *w
= minw
;
2759 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2760 if (*h
< minh
) *h
= minh
;
2765 /* keep to the increments */
2769 /* you cannot resize to nothing */
2770 if (basew
+ *w
< 1) *w
= 1 - basew
;
2771 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2773 /* save the logical size */
2774 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2775 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2783 /* adjust the height to match the width for the aspect ratios.
2784 for this, min size is not substituted for base size ever. */
2785 *w
-= self
->base_size
.width
;
2786 *h
-= self
->base_size
.height
;
2789 if (*h
* minratio
> *w
) {
2790 *h
= (gint
)(*w
/ minratio
);
2792 /* you cannot resize to nothing */
2795 *w
= (gint
)(*h
* minratio
);
2799 if (*h
* maxratio
< *w
) {
2800 *h
= (gint
)(*w
/ maxratio
);
2802 /* you cannot resize to nothing */
2805 *w
= (gint
)(*h
* minratio
);
2809 *w
+= self
->base_size
.width
;
2810 *h
+= self
->base_size
.height
;
2813 /* these override the above states! if you cant move you can't move! */
2815 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2819 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2820 *w
= self
->area
.width
;
2821 *h
= self
->area
.height
;
2830 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2831 gboolean user
, gboolean final
, gboolean force_reply
)
2834 gboolean send_resize_client
;
2835 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2836 gboolean fmoved
, fresized
;
2837 guint fdecor
= self
->frame
->decorations
;
2838 gboolean fhorz
= self
->frame
->max_horz
;
2839 gboolean fvert
= self
->frame
->max_vert
;
2840 gint logicalw
, logicalh
;
2842 /* find the new x, y, width, and height (and logical size) */
2843 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2845 /* set the logical size if things changed */
2846 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2847 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2849 /* figure out if we moved or resized or what */
2850 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2851 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2853 oldw
= self
->area
.width
;
2854 oldh
= self
->area
.height
;
2855 RECT_SET(self
->area
, x
, y
, w
, h
);
2857 /* for app-requested resizes, always resize if 'resized' is true.
2858 for user-requested ones, only resize if final is true, or when
2859 resizing in redraw mode */
2860 send_resize_client
= ((!user
&& resized
) ||
2862 (resized
&& config_resize_redraw
))));
2864 /* if the client is enlarging, then resize the client before the frame */
2865 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2866 XMoveResizeWindow(ob_display
, self
->window
,
2867 self
->frame
->size
.left
, self
->frame
->size
.top
,
2868 MAX(w
, oldw
), MAX(h
, oldh
));
2869 frame_adjust_client_area(self
->frame
);
2872 /* find the frame's dimensions and move/resize it */
2876 /* if decorations changed, then readjust everything for the frame */
2877 if (self
->decorations
!= fdecor
||
2878 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2880 fmoved
= fresized
= TRUE
;
2883 /* adjust the frame */
2884 if (fmoved
|| fresized
) {
2885 gulong ignore_start
;
2887 ignore_start
= event_start_ignore_all_enters();
2889 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2892 event_end_ignore_all_enters(ignore_start
);
2895 if (!user
|| final
) {
2896 gint oldrx
= self
->root_pos
.x
;
2897 gint oldry
= self
->root_pos
.y
;
2898 /* we have reset the client to 0 border width, so don't include
2899 it in these coords */
2900 POINT_SET(self
->root_pos
,
2901 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2903 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2904 self
->border_width
);
2905 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
2909 /* This is kinda tricky and should not be changed.. let me explain!
2911 When user = FALSE, then the request is coming from the application
2912 itself, and we are more strict about when to send a synthetic
2913 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
2914 in this case (if force_reply is true)
2916 When user = TRUE, then the request is coming from "us", like when we
2917 maximize a window or something. In this case we are more lenient. We
2918 used to follow the same rules as above, but _Java_ Swing can't handle
2919 this. So just to appease Swing, when user = TRUE, we always send
2920 a synthetic ConfigureNotify to give the window its root coordinates.
2922 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
2923 (user
&& final
&& rootmoved
))
2927 event
.type
= ConfigureNotify
;
2928 event
.xconfigure
.display
= ob_display
;
2929 event
.xconfigure
.event
= self
->window
;
2930 event
.xconfigure
.window
= self
->window
;
2932 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
2933 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
2935 /* root window real coords */
2936 event
.xconfigure
.x
= self
->root_pos
.x
;
2937 event
.xconfigure
.y
= self
->root_pos
.y
;
2938 event
.xconfigure
.width
= w
;
2939 event
.xconfigure
.height
= h
;
2940 event
.xconfigure
.border_width
= self
->border_width
;
2941 event
.xconfigure
.above
= None
;
2942 event
.xconfigure
.override_redirect
= FALSE
;
2943 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2944 FALSE
, StructureNotifyMask
, &event
);
2947 /* if the client is shrinking, then resize the frame before the client.
2949 both of these resize sections may run, because the top one only resizes
2950 in the direction that is growing
2952 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
2953 frame_adjust_client_area(self
->frame
);
2954 XMoveResizeWindow(ob_display
, self
->window
,
2955 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
2961 void client_fullscreen(ObClient
*self
, gboolean fs
)
2965 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2966 self
->fullscreen
== fs
) return; /* already done */
2968 self
->fullscreen
= fs
;
2969 client_change_state(self
); /* change the state hints on the client */
2972 self
->pre_fullscreen_area
= self
->area
;
2973 /* if the window is maximized, its area isn't all that meaningful.
2974 save it's premax area instead. */
2975 if (self
->max_horz
) {
2976 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2977 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2979 if (self
->max_vert
) {
2980 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2981 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2984 /* these will help configure_full figure out where to fullscreen
2988 w
= self
->area
.width
;
2989 h
= self
->area
.height
;
2991 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
2992 self
->pre_fullscreen_area
.height
> 0);
2994 x
= self
->pre_fullscreen_area
.x
;
2995 y
= self
->pre_fullscreen_area
.y
;
2996 w
= self
->pre_fullscreen_area
.width
;
2997 h
= self
->pre_fullscreen_area
.height
;
2998 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3001 ob_debug("Window %s going fullscreen (%d)\n",
3002 self
->title
, self
->fullscreen
);
3004 client_setup_decor_and_functions(self
, FALSE
);
3005 client_move_resize(self
, x
, y
, w
, h
);
3007 /* and adjust our layer/stacking. do this after resizing the window,
3008 and applying decorations, because windows which fill the screen are
3009 considered "fullscreen" and it affects their layer */
3010 client_calc_layer(self
);
3013 /* try focus us when we go into fullscreen mode */
3018 static void client_iconify_recursive(ObClient
*self
,
3019 gboolean iconic
, gboolean curdesk
,
3020 gboolean hide_animation
)
3023 gboolean changed
= FALSE
;
3026 if (self
->iconic
!= iconic
) {
3027 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3031 /* don't let non-normal windows iconify along with their parents
3033 if (client_normal(self
)) {
3034 self
->iconic
= iconic
;
3036 /* update the focus lists.. iconic windows go to the bottom of
3038 focus_order_to_bottom(self
);
3043 self
->iconic
= iconic
;
3045 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3046 self
->desktop
!= DESKTOP_ALL
)
3047 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3049 /* this puts it after the current focused window */
3050 focus_order_remove(self
);
3051 focus_order_add_new(self
);
3058 client_change_state(self
);
3059 if (config_animate_iconify
&& !hide_animation
)
3060 frame_begin_iconify_animation(self
->frame
, iconic
);
3061 /* do this after starting the animation so it doesn't flash */
3062 client_showhide(self
);
3065 /* iconify all direct transients, and deiconify all transients
3067 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3068 if (it
->data
!= self
)
3069 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3070 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3074 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3075 gboolean hide_animation
)
3077 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3078 /* move up the transient chain as far as possible first */
3079 self
= client_search_top_direct_parent(self
);
3080 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3084 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3088 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3089 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3091 /* check if already done */
3093 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3094 if (dir
== 1 && self
->max_horz
) return;
3095 if (dir
== 2 && self
->max_vert
) return;
3097 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3098 if (dir
== 1 && !self
->max_horz
) return;
3099 if (dir
== 2 && !self
->max_vert
) return;
3102 /* these will help configure_full figure out which screen to fill with
3106 w
= self
->area
.width
;
3107 h
= self
->area
.height
;
3110 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3111 RECT_SET(self
->pre_max_area
,
3112 self
->area
.x
, self
->pre_max_area
.y
,
3113 self
->area
.width
, self
->pre_max_area
.height
);
3115 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3116 RECT_SET(self
->pre_max_area
,
3117 self
->pre_max_area
.x
, self
->area
.y
,
3118 self
->pre_max_area
.width
, self
->area
.height
);
3121 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3122 g_assert(self
->pre_max_area
.width
> 0);
3124 x
= self
->pre_max_area
.x
;
3125 w
= self
->pre_max_area
.width
;
3127 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3128 0, self
->pre_max_area
.height
);
3130 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3131 g_assert(self
->pre_max_area
.height
> 0);
3133 y
= self
->pre_max_area
.y
;
3134 h
= self
->pre_max_area
.height
;
3136 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3137 self
->pre_max_area
.width
, 0);
3141 if (dir
== 0 || dir
== 1) /* horz */
3142 self
->max_horz
= max
;
3143 if (dir
== 0 || dir
== 2) /* vert */
3144 self
->max_vert
= max
;
3146 client_change_state(self
); /* change the state hints on the client */
3148 client_setup_decor_and_functions(self
, FALSE
);
3149 client_move_resize(self
, x
, y
, w
, h
);
3152 void client_shade(ObClient
*self
, gboolean shade
)
3154 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3155 shade
) || /* can't shade */
3156 self
->shaded
== shade
) return; /* already done */
3158 self
->shaded
= shade
;
3159 client_change_state(self
);
3160 client_change_wm_state(self
); /* the window is being hidden/shown */
3161 /* resize the frame to just the titlebar */
3162 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3165 void client_close(ObClient
*self
)
3169 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3171 /* in the case that the client provides no means to requesting that it
3172 close, we just kill it */
3173 if (!self
->delete_window
)
3177 XXX: itd be cool to do timeouts and shit here for killing the client's
3179 like... if the window is around after 5 seconds, then the close button
3180 turns a nice red, and if this function is called again, the client is
3184 ce
.xclient
.type
= ClientMessage
;
3185 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3186 ce
.xclient
.display
= ob_display
;
3187 ce
.xclient
.window
= self
->window
;
3188 ce
.xclient
.format
= 32;
3189 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
3190 ce
.xclient
.data
.l
[1] = event_curtime
;
3191 ce
.xclient
.data
.l
[2] = 0l;
3192 ce
.xclient
.data
.l
[3] = 0l;
3193 ce
.xclient
.data
.l
[4] = 0l;
3194 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3197 void client_kill(ObClient
*self
)
3199 XKillClient(ob_display
, self
->window
);
3202 void client_hilite(ObClient
*self
, gboolean hilite
)
3204 if (self
->demands_attention
== hilite
)
3205 return; /* no change */
3207 /* don't allow focused windows to hilite */
3208 self
->demands_attention
= hilite
&& !client_focused(self
);
3209 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3210 if (self
->demands_attention
)
3211 frame_flash_start(self
->frame
);
3213 frame_flash_stop(self
->frame
);
3214 client_change_state(self
);
3218 void client_set_desktop_recursive(ObClient
*self
,
3226 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3228 ob_debug("Setting desktop %u\n", target
+1);
3230 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3232 old
= self
->desktop
;
3233 self
->desktop
= target
;
3234 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3235 /* the frame can display the current desktop state */
3236 frame_adjust_state(self
->frame
);
3237 /* 'move' the window to the new desktop */
3241 /* raise if it was not already on the desktop */
3242 if (old
!= DESKTOP_ALL
&& !dontraise
)
3243 stacking_raise(CLIENT_AS_WINDOW(self
));
3244 if (STRUT_EXISTS(self
->strut
))
3245 screen_update_areas();
3247 /* the new desktop's geometry may be different, so we may need to
3248 resize, for example if we are maximized */
3249 client_reconfigure(self
, FALSE
);
3252 /* move all transients */
3253 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3254 if (it
->data
!= self
)
3255 if (client_is_direct_child(self
, it
->data
))
3256 client_set_desktop_recursive(it
->data
, target
,
3257 donthide
, dontraise
);
3260 void client_set_desktop(ObClient
*self
, guint target
,
3261 gboolean donthide
, gboolean dontraise
)
3263 self
= client_search_top_direct_parent(self
);
3264 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3267 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3269 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3270 return child
== parent
;
3273 ObClient
*client_search_modal_child(ObClient
*self
)
3278 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3279 ObClient
*c
= it
->data
;
3280 if ((ret
= client_search_modal_child(c
))) return ret
;
3281 if (c
->modal
) return c
;
3286 gboolean
client_validate(ObClient
*self
)
3290 XSync(ob_display
, FALSE
); /* get all events on the server */
3292 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3293 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3294 XPutBackEvent(ob_display
, &e
);
3301 void client_set_wm_state(ObClient
*self
, glong state
)
3303 if (state
== self
->wmstate
) return; /* no change */
3307 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3310 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3315 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3317 gboolean shaded
= self
->shaded
;
3318 gboolean fullscreen
= self
->fullscreen
;
3319 gboolean undecorated
= self
->undecorated
;
3320 gboolean max_horz
= self
->max_horz
;
3321 gboolean max_vert
= self
->max_vert
;
3322 gboolean modal
= self
->modal
;
3323 gboolean iconic
= self
->iconic
;
3324 gboolean demands_attention
= self
->demands_attention
;
3325 gboolean above
= self
->above
;
3326 gboolean below
= self
->below
;
3329 if (!(action
== prop_atoms
.net_wm_state_add
||
3330 action
== prop_atoms
.net_wm_state_remove
||
3331 action
== prop_atoms
.net_wm_state_toggle
))
3332 /* an invalid action was passed to the client message, ignore it */
3335 for (i
= 0; i
< 2; ++i
) {
3336 Atom state
= i
== 0 ? data1
: data2
;
3338 if (!state
) continue;
3340 /* if toggling, then pick whether we're adding or removing */
3341 if (action
== prop_atoms
.net_wm_state_toggle
) {
3342 if (state
== prop_atoms
.net_wm_state_modal
)
3343 action
= modal
? prop_atoms
.net_wm_state_remove
:
3344 prop_atoms
.net_wm_state_add
;
3345 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3346 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3347 prop_atoms
.net_wm_state_add
;
3348 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3349 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3350 prop_atoms
.net_wm_state_add
;
3351 else if (state
== prop_atoms
.net_wm_state_shaded
)
3352 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3353 prop_atoms
.net_wm_state_add
;
3354 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3355 action
= self
->skip_taskbar
?
3356 prop_atoms
.net_wm_state_remove
:
3357 prop_atoms
.net_wm_state_add
;
3358 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3359 action
= self
->skip_pager
?
3360 prop_atoms
.net_wm_state_remove
:
3361 prop_atoms
.net_wm_state_add
;
3362 else if (state
== prop_atoms
.net_wm_state_hidden
)
3363 action
= self
->iconic
?
3364 prop_atoms
.net_wm_state_remove
:
3365 prop_atoms
.net_wm_state_add
;
3366 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3367 action
= fullscreen
?
3368 prop_atoms
.net_wm_state_remove
:
3369 prop_atoms
.net_wm_state_add
;
3370 else if (state
== prop_atoms
.net_wm_state_above
)
3371 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3372 prop_atoms
.net_wm_state_add
;
3373 else if (state
== prop_atoms
.net_wm_state_below
)
3374 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3375 prop_atoms
.net_wm_state_add
;
3376 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3377 action
= self
->demands_attention
?
3378 prop_atoms
.net_wm_state_remove
:
3379 prop_atoms
.net_wm_state_add
;
3380 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3381 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3382 prop_atoms
.net_wm_state_add
;
3385 if (action
== prop_atoms
.net_wm_state_add
) {
3386 if (state
== prop_atoms
.net_wm_state_modal
) {
3388 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3390 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3392 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3394 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3395 self
->skip_taskbar
= TRUE
;
3396 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3397 self
->skip_pager
= TRUE
;
3398 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3400 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3402 } else if (state
== prop_atoms
.net_wm_state_above
) {
3405 } else if (state
== prop_atoms
.net_wm_state_below
) {
3408 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3409 demands_attention
= TRUE
;
3410 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3414 } else { /* action == prop_atoms.net_wm_state_remove */
3415 if (state
== prop_atoms
.net_wm_state_modal
) {
3417 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3419 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3421 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3423 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3424 self
->skip_taskbar
= FALSE
;
3425 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3426 self
->skip_pager
= FALSE
;
3427 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3429 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3431 } else if (state
== prop_atoms
.net_wm_state_above
) {
3433 } else if (state
== prop_atoms
.net_wm_state_below
) {
3435 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3436 demands_attention
= FALSE
;
3437 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3438 undecorated
= FALSE
;
3443 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3444 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3446 if (max_horz
== max_vert
) { /* both going the same way */
3447 client_maximize(self
, max_horz
, 0);
3449 client_maximize(self
, max_horz
, 1);
3450 client_maximize(self
, max_vert
, 2);
3454 if (max_horz
!= self
->max_horz
)
3455 client_maximize(self
, max_horz
, 1);
3457 client_maximize(self
, max_vert
, 2);
3460 /* change fullscreen state before shading, as it will affect if the window
3462 if (fullscreen
!= self
->fullscreen
)
3463 client_fullscreen(self
, fullscreen
);
3464 if (shaded
!= self
->shaded
)
3465 client_shade(self
, shaded
);
3466 if (undecorated
!= self
->undecorated
)
3467 client_set_undecorated(self
, undecorated
);
3468 if (above
!= self
->above
|| below
!= self
->below
) {
3469 self
->above
= above
;
3470 self
->below
= below
;
3471 client_calc_layer(self
);
3474 if (modal
!= self
->modal
) {
3475 self
->modal
= modal
;
3476 /* when a window changes modality, then its stacking order with its
3477 transients needs to change */
3478 stacking_raise(CLIENT_AS_WINDOW(self
));
3480 /* it also may get focused. if something is focused that shouldn't
3481 be focused anymore, then move the focus */
3482 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3483 client_focus(focus_client
);
3486 if (iconic
!= self
->iconic
)
3487 client_iconify(self
, iconic
, FALSE
, FALSE
);
3489 if (demands_attention
!= self
->demands_attention
)
3490 client_hilite(self
, demands_attention
);
3492 client_change_state(self
); /* change the hint to reflect these changes */
3495 ObClient
*client_focus_target(ObClient
*self
)
3497 ObClient
*child
= NULL
;
3499 child
= client_search_modal_child(self
);
3500 if (child
) return child
;
3504 gboolean
client_can_focus(ObClient
*self
)
3506 /* choose the correct target */
3507 self
= client_focus_target(self
);
3509 if (!self
->frame
->visible
)
3512 if (!(self
->can_focus
|| self
->focus_notify
))
3518 gboolean
client_focus(ObClient
*self
)
3520 /* we might not focus this window, so if we have modal children which would
3521 be focused instead, bring them to this desktop */
3522 client_bring_modal_windows(self
);
3524 /* choose the correct target */
3525 self
= client_focus_target(self
);
3527 if (!client_can_focus(self
)) {
3528 ob_debug_type(OB_DEBUG_FOCUS
,
3529 "Client %s can't be focused\n", self
->title
);
3533 ob_debug_type(OB_DEBUG_FOCUS
,
3534 "Focusing client \"%s\" (0x%x) at time %u\n",
3535 self
->title
, self
->window
, event_curtime
);
3537 /* if using focus_delay, stop the timer now so that focus doesn't
3539 event_halt_focus_delay();
3541 /* if there is a grab going on, then we need to cancel it. if we move
3542 focus during the grab, applications will get NotifyWhileGrabbed events
3545 actions should not rely on being able to move focus during an
3548 event_cancel_all_key_grabs();
3550 xerror_set_ignore(TRUE
);
3551 xerror_occured
= FALSE
;
3553 if (self
->can_focus
) {
3554 /* This can cause a BadMatch error with CurrentTime, or if an app
3555 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3556 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3560 if (self
->focus_notify
) {
3562 ce
.xclient
.type
= ClientMessage
;
3563 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3564 ce
.xclient
.display
= ob_display
;
3565 ce
.xclient
.window
= self
->window
;
3566 ce
.xclient
.format
= 32;
3567 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3568 ce
.xclient
.data
.l
[1] = event_curtime
;
3569 ce
.xclient
.data
.l
[2] = 0l;
3570 ce
.xclient
.data
.l
[3] = 0l;
3571 ce
.xclient
.data
.l
[4] = 0l;
3572 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3575 xerror_set_ignore(FALSE
);
3577 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d\n", xerror_occured
);
3578 return !xerror_occured
;
3581 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3584 if (client_normal(self
) && screen_showing_desktop
)
3585 screen_show_desktop(FALSE
, self
);
3587 client_iconify(self
, FALSE
, here
, FALSE
);
3588 if (self
->desktop
!= DESKTOP_ALL
&&
3589 self
->desktop
!= screen_desktop
)
3592 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3594 screen_set_desktop(self
->desktop
, FALSE
);
3595 } else if (!self
->frame
->visible
)
3596 /* if its not visible for other reasons, then don't mess
3599 if (self
->shaded
&& unshade
)
3600 client_shade(self
, FALSE
);
3602 stacking_raise(CLIENT_AS_WINDOW(self
));
3607 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3608 gboolean unshade
, gboolean user
)
3610 client_present(self
, here
, raise
, unshade
);
3613 static void client_bring_windows_recursive(ObClient
*self
,
3621 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3622 client_bring_windows_recursive(it
->data
, desktop
,
3623 helpers
, modals
, iconic
);
3625 if (((helpers
&& client_helper(self
)) ||
3626 (modals
&& self
->modal
)) &&
3627 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3628 (iconic
&& self
->iconic
)))
3630 if (iconic
&& self
->iconic
)
3631 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3633 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3637 void client_bring_helper_windows(ObClient
*self
)
3639 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3642 void client_bring_modal_windows(ObClient
*self
)
3644 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3647 gboolean
client_focused(ObClient
*self
)
3649 return self
== focus_client
;
3652 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3655 gulong min_diff
, min_i
;
3657 if (!self
->nicons
) {
3658 ObClientIcon
*parent
= NULL
;
3661 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
3662 ObClient
*c
= it
->data
;
3663 if ((parent
= client_icon_recursive(c
, w
, h
)))
3670 /* some kind of crappy approximation to find the icon closest in size to
3671 what we requested, but icons are generally all the same ratio as
3672 eachother so it's good enough. */
3674 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3677 for (i
= 1; i
< self
->nicons
; ++i
) {
3680 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3681 if (diff
< min_diff
) {
3686 return &self
->icons
[min_i
];
3689 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3692 static ObClientIcon deficon
;
3694 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3695 deficon
.width
= deficon
.height
= 48;
3696 deficon
.data
= ob_rr_theme
->def_win_icon
;
3702 void client_set_layer(ObClient
*self
, gint layer
)
3706 self
->above
= FALSE
;
3707 } else if (layer
== 0) {
3708 self
->below
= self
->above
= FALSE
;
3710 self
->below
= FALSE
;
3713 client_calc_layer(self
);
3714 client_change_state(self
); /* reflect this in the state hints */
3717 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3719 if (self
->undecorated
!= undecorated
&&
3720 /* don't let it undecorate if the function is missing, but let
3722 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3724 self
->undecorated
= undecorated
;
3725 client_setup_decor_and_functions(self
, TRUE
);
3726 client_change_state(self
); /* reflect this in the state hints */
3730 guint
client_monitor(ObClient
*self
)
3732 return screen_find_monitor(&self
->frame
->area
);
3735 ObClient
*client_direct_parent(ObClient
*self
)
3737 if (!self
->parents
) return NULL
;
3738 if (self
->transient_for_group
) return NULL
;
3739 return self
->parents
->data
;
3742 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3745 while ((p
= client_direct_parent(self
))) self
= p
;
3749 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3751 ObStackingLayer layer
)
3756 /* move up the direct transient chain as far as possible */
3757 while ((p
= client_direct_parent(self
)) &&
3758 (!bylayer
|| p
->layer
== layer
))
3762 ret
= g_slist_prepend(NULL
, self
);
3764 ret
= g_slist_copy(self
->parents
);
3769 GSList
*client_search_all_top_parents(ObClient
*self
)
3771 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3774 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3776 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3779 ObClient
*client_search_focus_parent(ObClient
*self
)
3783 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3784 if (client_focused(it
->data
)) return it
->data
;
3789 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3793 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3794 if (it
->data
== search
) return search
;
3799 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3803 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3804 if (sit
->data
== search
)
3806 if (client_search_transient(sit
->data
, search
))
3812 static void detect_edge(Rect area
, ObDirection dir
,
3813 gint my_head
, gint my_size
,
3814 gint my_edge_start
, gint my_edge_size
,
3815 gint
*dest
, gboolean
*near_edge
)
3817 gint edge_start
, edge_size
, head
, tail
;
3818 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
3821 case OB_DIRECTION_NORTH
:
3822 case OB_DIRECTION_SOUTH
:
3823 edge_start
= area
.x
;
3824 edge_size
= area
.width
;
3826 case OB_DIRECTION_EAST
:
3827 case OB_DIRECTION_WEST
:
3828 edge_start
= area
.y
;
3829 edge_size
= area
.height
;
3832 g_assert_not_reached();
3835 /* do we collide with this window? */
3836 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
3837 edge_start
, edge_size
))
3841 case OB_DIRECTION_NORTH
:
3842 head
= RECT_BOTTOM(area
);
3843 tail
= RECT_TOP(area
);
3845 case OB_DIRECTION_SOUTH
:
3846 head
= RECT_TOP(area
);
3847 tail
= RECT_BOTTOM(area
);
3849 case OB_DIRECTION_WEST
:
3850 head
= RECT_RIGHT(area
);
3851 tail
= RECT_LEFT(area
);
3853 case OB_DIRECTION_EAST
:
3854 head
= RECT_LEFT(area
);
3855 tail
= RECT_RIGHT(area
);
3858 g_assert_not_reached();
3861 case OB_DIRECTION_NORTH
:
3862 case OB_DIRECTION_WEST
:
3863 /* check if our window is past the head of this window */
3864 if (my_head
<= head
+ 1)
3866 /* check if our window's tail is past the tail of this window */
3867 if (my_head
+ my_size
- 1 <= tail
)
3869 /* check if the head of this window is closer than the previously
3870 chosen edge (take into account that the previously chosen
3871 edge might have been a tail, not a head) */
3872 if (head
+ (*near_edge
? 0 : my_size
) < *dest
)
3874 /* check if the tail of this window is closer than the previously
3875 chosen edge (take into account that the previously chosen
3876 edge might have been a head, not a tail) */
3877 if (tail
- (!*near_edge
? 0 : my_size
) < *dest
)
3880 case OB_DIRECTION_SOUTH
:
3881 case OB_DIRECTION_EAST
:
3882 /* check if our window is past the head of this window */
3883 if (my_head
>= head
- 1)
3885 /* check if our window's tail is past the tail of this window */
3886 if (my_head
- my_size
+ 1 >= tail
)
3888 /* check if the head of this window is closer than the previously
3889 chosen edge (take into account that the previously chosen
3890 edge might have been a tail, not a head) */
3891 if (head
- (*near_edge
? 0 : my_size
) > *dest
)
3893 /* check if the tail of this window is closer than the previously
3894 chosen edge (take into account that the previously chosen
3895 edge might have been a head, not a tail) */
3896 if (tail
+ (!*near_edge
? 0 : my_size
) > *dest
)
3900 g_assert_not_reached();
3903 ob_debug("my head %d size %d\n", my_head
, my_size
);
3904 ob_debug("head %d tail %d deest %d\n", head
, tail
, *dest
);
3906 ob_debug("using near edge %d\n", head
);
3910 else if (!skip_tail
) {
3911 ob_debug("using far edge %d\n", tail
);
3917 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
3918 gint my_head
, gint my_size
,
3919 gint my_edge_start
, gint my_edge_size
,
3920 gint
*dest
, gboolean
*near_edge
)
3927 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
3928 &self
->frame
->area
);
3929 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
3930 &self
->frame
->area
);
3933 case OB_DIRECTION_NORTH
:
3934 if (my_head
>= RECT_TOP(*mon
) + 1)
3935 edge
= RECT_TOP(*mon
) - 1;
3937 edge
= RECT_TOP(*a
) - 1;
3939 case OB_DIRECTION_SOUTH
:
3940 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
3941 edge
= RECT_BOTTOM(*mon
) + 1;
3943 edge
= RECT_BOTTOM(*a
) + 1;
3945 case OB_DIRECTION_EAST
:
3946 if (my_head
<= RECT_RIGHT(*mon
) - 1)
3947 edge
= RECT_RIGHT(*mon
) + 1;
3949 edge
= RECT_RIGHT(*a
) + 1;
3951 case OB_DIRECTION_WEST
:
3952 if (my_head
>= RECT_LEFT(*mon
) + 1)
3953 edge
= RECT_LEFT(*mon
) - 1;
3955 edge
= RECT_LEFT(*a
) - 1;
3958 g_assert_not_reached();
3960 /* default to the far edge, then narrow it down */
3964 for (it
= client_list
; it
; it
= g_list_next(it
)) {
3965 ObClient
*cur
= it
->data
;
3967 /* skip windows to not bump into */
3972 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
3973 cur
->desktop
!= screen_desktop
)
3976 ob_debug("trying window %s\n", cur
->title
);
3978 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
3979 my_edge_size
, dest
, near_edge
);
3981 dock_get_area(&dock_area
);
3982 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
3983 my_edge_size
, dest
, near_edge
);
3988 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
3992 gint e
, e_start
, e_size
;
3996 case OB_DIRECTION_EAST
:
3997 head
= RECT_RIGHT(self
->frame
->area
);
3998 size
= self
->frame
->area
.width
;
3999 e_start
= RECT_TOP(self
->frame
->area
);
4000 e_size
= self
->frame
->area
.height
;
4002 case OB_DIRECTION_WEST
:
4003 head
= RECT_LEFT(self
->frame
->area
);
4004 size
= self
->frame
->area
.width
;
4005 e_start
= RECT_TOP(self
->frame
->area
);
4006 e_size
= self
->frame
->area
.height
;
4008 case OB_DIRECTION_NORTH
:
4009 head
= RECT_TOP(self
->frame
->area
);
4010 size
= self
->frame
->area
.height
;
4011 e_start
= RECT_LEFT(self
->frame
->area
);
4012 e_size
= self
->frame
->area
.width
;
4014 case OB_DIRECTION_SOUTH
:
4015 head
= RECT_BOTTOM(self
->frame
->area
);
4016 size
= self
->frame
->area
.height
;
4017 e_start
= RECT_LEFT(self
->frame
->area
);
4018 e_size
= self
->frame
->area
.width
;
4021 g_assert_not_reached();
4024 client_find_edge_directional(self
, dir
, head
, size
,
4025 e_start
, e_size
, &e
, &near
);
4026 *x
= self
->frame
->area
.x
;
4027 *y
= self
->frame
->area
.y
;
4029 case OB_DIRECTION_EAST
:
4030 if (near
) e
-= self
->frame
->area
.width
;
4034 case OB_DIRECTION_WEST
:
4036 else e
-= self
->frame
->area
.width
;
4039 case OB_DIRECTION_NORTH
:
4041 else e
-= self
->frame
->area
.height
;
4044 case OB_DIRECTION_SOUTH
:
4045 if (near
) e
-= self
->frame
->area
.height
;
4050 g_assert_not_reached();
4052 frame_frame_gravity(self
->frame
, x
, y
);
4055 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4057 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4060 gint e
, e_start
, e_size
, delta
;
4065 case OB_DIRECTION_EAST
:
4066 head
= RECT_RIGHT(self
->frame
->area
) +
4067 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4068 e_start
= RECT_TOP(self
->frame
->area
);
4069 e_size
= self
->frame
->area
.height
;
4070 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4072 case OB_DIRECTION_WEST
:
4073 head
= RECT_LEFT(self
->frame
->area
) -
4074 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4075 e_start
= RECT_TOP(self
->frame
->area
);
4076 e_size
= self
->frame
->area
.height
;
4077 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4079 case OB_DIRECTION_NORTH
:
4080 head
= RECT_TOP(self
->frame
->area
) -
4081 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4082 e_start
= RECT_LEFT(self
->frame
->area
);
4083 e_size
= self
->frame
->area
.width
;
4084 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4086 case OB_DIRECTION_SOUTH
:
4087 head
= RECT_BOTTOM(self
->frame
->area
) +
4088 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4089 e_start
= RECT_LEFT(self
->frame
->area
);
4090 e_size
= self
->frame
->area
.width
;
4091 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4094 g_assert_not_reached();
4097 ob_debug("head %d dir %d\n", head
, dir
);
4098 client_find_edge_directional(self
, dir
, head
, 1,
4099 e_start
, e_size
, &e
, &near
);
4100 ob_debug("edge %d\n", e
);
4101 *x
= self
->frame
->area
.x
;
4102 *y
= self
->frame
->area
.y
;
4103 *w
= self
->frame
->area
.width
;
4104 *h
= self
->frame
->area
.height
;
4106 case OB_DIRECTION_EAST
:
4107 if (grow
== near
) --e
;
4108 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4111 case OB_DIRECTION_WEST
:
4112 if (grow
== near
) ++e
;
4113 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4117 case OB_DIRECTION_NORTH
:
4118 if (grow
== near
) ++e
;
4119 delta
= RECT_TOP(self
->frame
->area
) - e
;
4123 case OB_DIRECTION_SOUTH
:
4124 if (grow
== near
) --e
;
4125 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4129 g_assert_not_reached();
4131 frame_frame_gravity(self
->frame
, x
, y
);
4132 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4133 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4136 ObClient
* client_under_pointer(void)
4140 ObClient
*ret
= NULL
;
4142 if (screen_pointer_pos(&x
, &y
)) {
4143 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4144 if (WINDOW_IS_CLIENT(it
->data
)) {
4145 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4146 if (c
->frame
->visible
&&
4147 /* check the desktop, this is done during desktop
4148 switching and windows are shown/hidden status is not
4150 (c
->desktop
== screen_desktop
||
4151 c
->desktop
== DESKTOP_ALL
) &&
4152 /* ignore all animating windows */
4153 !frame_iconify_animating(c
->frame
) &&
4154 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4165 gboolean
client_has_group_siblings(ObClient
*self
)
4167 return self
->group
&& self
->group
->members
->next
;