1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
25 #include "moveresize.h"
34 #include "focus_cycle.h"
39 #include "menuframe.h"
42 #include "obrender/render.h"
44 #include "obt/display.h"
52 # include <signal.h> /* for kill() */
56 #include <X11/Xutil.h>
58 /*! The event mask to grab on client windows */
59 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
62 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
67 ObClientCallback func
;
71 GList
*client_list
= NULL
;
73 static GSList
*client_destroy_notifies
= NULL
;
74 static RrImage
*client_default_icon
= NULL
;
76 static void client_get_all(ObClient
*self
, gboolean real
);
77 static void client_get_startup_id(ObClient
*self
);
78 static void client_get_session_ids(ObClient
*self
);
79 static void client_save_app_rule_values(ObClient
*self
);
80 static void client_get_area(ObClient
*self
);
81 static void client_get_desktop(ObClient
*self
);
82 static void client_get_state(ObClient
*self
);
83 static void client_get_shaped(ObClient
*self
);
84 static void client_get_colormap(ObClient
*self
);
85 static void client_set_desktop_recursive(ObClient
*self
,
89 static void client_change_allowed_actions(ObClient
*self
);
90 static void client_change_state(ObClient
*self
);
91 static void client_change_wm_state(ObClient
*self
);
92 static void client_apply_startup_state(ObClient
*self
,
93 gint x
, gint y
, gint w
, gint h
);
94 static void client_restore_session_state(ObClient
*self
);
95 static gboolean
client_restore_session_stacking(ObClient
*self
);
96 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
97 static void client_update_transient_tree(ObClient
*self
,
98 ObGroup
*oldgroup
, ObGroup
*newgroup
,
99 gboolean oldgtran
, gboolean newgtran
,
101 ObClient
*newparent
);
102 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
104 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
106 ObStackingLayer layer
);
107 static void client_call_notifies(ObClient
*self
, GSList
*list
);
108 static void client_ping_event(ObClient
*self
, gboolean dead
);
109 static void client_prompt_kill(ObClient
*self
);
110 static gboolean
client_can_steal_focus(ObClient
*self
, Time steal_time
,
113 void client_startup(gboolean reconfig
)
115 if ((client_default_icon
= RrImageCacheFind(ob_rr_icons
,
116 ob_rr_theme
->def_win_icon
,
117 ob_rr_theme
->def_win_icon_w
,
118 ob_rr_theme
->def_win_icon_h
)))
119 RrImageRef(client_default_icon
);
121 client_default_icon
= RrImageNew(ob_rr_icons
);
122 RrImageAddPicture(client_default_icon
,
123 ob_rr_theme
->def_win_icon
,
124 ob_rr_theme
->def_win_icon_w
,
125 ob_rr_theme
->def_win_icon_h
);
128 if (reconfig
) return;
133 void client_shutdown(gboolean reconfig
)
135 RrImageUnref(client_default_icon
);
136 client_default_icon
= NULL
;
138 if (reconfig
) return;
141 static void client_call_notifies(ObClient
*self
, GSList
*list
)
145 for (it
= list
; it
; it
= g_slist_next(it
)) {
146 ClientCallback
*d
= it
->data
;
147 d
->func(self
, d
->data
);
151 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
153 ClientCallback
*d
= g_slice_new(ClientCallback
);
156 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
159 void client_remove_destroy_notify(ObClientCallback func
)
163 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
164 ClientCallback
*d
= it
->data
;
165 if (d
->func
== func
) {
166 g_slice_free(ClientCallback
, d
);
167 client_destroy_notifies
=
168 g_slist_delete_link(client_destroy_notifies
, it
);
174 void client_set_list(void)
176 Window
*windows
, *win_it
;
178 guint size
= g_list_length(client_list
);
180 /* create an array of the window ids */
182 windows
= g_new(Window
, size
);
184 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
185 *win_it
= ((ObClient
*)it
->data
)->window
;
189 OBT_PROP_SETA32(obt_root(ob_screen
), NET_CLIENT_LIST
, WINDOW
,
190 (gulong
*)windows
, size
);
198 void client_manage(Window window
, ObPrompt
*prompt
)
201 XSetWindowAttributes attrib_set
;
202 gboolean activate
= FALSE
;
203 ObAppSettings
*settings
;
204 gboolean transient
= FALSE
;
210 ob_debug("Managing window: 0x%lx", window
);
212 /* choose the events we want to receive on the CLIENT window
213 (ObPrompt windows can request events too) */
214 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
215 (prompt
? prompt
->event_mask
: 0);
216 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
217 XChangeWindowAttributes(obt_display
, window
,
218 CWEventMask
|CWDontPropagate
, &attrib_set
);
220 /* create the ObClient struct, and populate it from the hints on the
222 self
= g_slice_new0(ObClient
);
223 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
224 self
->window
= window
;
225 self
->prompt
= prompt
;
226 self
->managed
= TRUE
;
228 /* non-zero defaults */
229 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
230 self
->gravity
= NorthWestGravity
;
231 self
->desktop
= screen_num_desktops
; /* always an invalid value */
233 /* get all the stuff off the window */
234 client_get_all(self
, TRUE
);
236 ob_debug("Window type: %d", self
->type
);
237 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
238 ob_debug("Window name: %s class: %s role: %s title: %s",
239 self
->name
, self
->class, self
->role
, self
->title
);
241 /* per-app settings override stuff from client_get_all, and return the
242 settings for other uses too. the returned settings is a shallow copy,
243 that needs to be freed with g_free(). */
244 settings
= client_get_settings_state(self
);
246 /* now we have all of the window's information so we can set this up.
247 do this before creating the frame, so it can tell that we are still
248 mapping and doesn't go applying things right away */
249 client_setup_decor_and_functions(self
, FALSE
);
251 /* specify that if we exit, the window should not be destroyed and
252 should be reparented back to root automatically, unless we are managing
253 an internal ObPrompt window */
255 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
257 /* create the decoration frame for the client window */
258 self
->frame
= frame_new(self
);
260 frame_grab_client(self
->frame
);
262 /* we've grabbed everything and set everything that we need to at mapping
266 /* the session should get the last say though */
267 client_restore_session_state(self
);
269 /* tell startup notification that this app started */
270 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
272 if (!OBT_PROP_GET32(self
->window
, NET_WM_USER_TIME
, CARDINAL
, &user_time
))
273 user_time
= event_time();
275 /* do this after we have a frame.. it uses the frame to help determine the
276 WM_STATE to apply. */
277 client_change_state(self
);
279 /* add ourselves to the focus order */
280 focus_order_add_new(self
);
282 /* do this to add ourselves to the stacking list in a non-intrusive way */
283 client_calc_layer(self
);
285 /* focus the new window? */
286 if (ob_state() != OB_STATE_STARTING
&&
287 (!self
->session
|| self
->session
->focused
) &&
288 /* this means focus=true for window is same as config_focus_new=true */
289 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
290 client_search_focus_tree_full(self
)) &&
291 /* NET_WM_USER_TIME 0 when mapping means don't focus */
293 /* this checks for focus=false for the window */
294 (!settings
|| settings
->focus
!= 0) &&
295 focus_valid_target(self
, self
->desktop
,
296 FALSE
, FALSE
, TRUE
, TRUE
, FALSE
, FALSE
,
297 settings
->focus
== 1))
302 /* remove the client's border */
303 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
305 /* adjust the frame to the client's size before showing or placing
307 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
308 frame_adjust_client_area(self
->frame
);
310 /* where the frame was placed is where the window was originally */
313 /* figure out placement for the window if the window is new */
314 if (ob_state() == OB_STATE_RUNNING
) {
315 ob_debug("Positioned: %s @ %d %d",
316 (!self
->positioned
? "no" :
317 (self
->positioned
== PPosition
? "program specified" :
318 (self
->positioned
== USPosition
? "user specified" :
319 (self
->positioned
== (PPosition
| USPosition
) ?
320 "program + user specified" :
321 "BADNESS !?")))), place
.x
, place
.y
);
323 ob_debug("Sized: %s @ %d %d",
324 (!self
->sized
? "no" :
325 (self
->sized
== PSize
? "program specified" :
326 (self
->sized
== USSize
? "user specified" :
327 (self
->sized
== (PSize
| USSize
) ?
328 "program + user specified" :
329 "BADNESS !?")))), place
.width
, place
.height
);
331 obplaced
= place_client(self
, &place
.x
, &place
.y
, settings
);
333 /* watch for buggy apps that ask to be placed at (0,0) when there is
335 if (!obplaced
&& place
.x
== 0 && place
.y
== 0 &&
336 /* non-normal windows are allowed */
337 client_normal(self
) &&
338 /* oldschool fullscreen windows are allowed */
339 !client_is_oldfullscreen(self
, &place
))
343 r
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
, NULL
);
347 ob_debug("Moving buggy app from (0,0) to (%d,%d)", r
->x
, r
->y
);
349 g_slice_free(Rect
, r
);
352 /* make sure the window is visible. */
353 client_find_onscreen(self
, &place
.x
, &place
.y
,
354 place
.width
, place
.height
,
355 /* non-normal clients has less rules, and
356 windows that are being restored from a
357 session do also. we can assume you want
358 it back where you saved it. Clients saying
359 they placed themselves are subjected to
360 harder rules, ones that are placed by
361 place.c or by the user are allowed partially
362 off-screen and on xinerama divides (ie,
363 it is up to the placement routines to avoid
364 the xinerama divides)
366 children and splash screens are forced on
367 screen, but i don't remember why i decided to
370 ob_state() == OB_STATE_RUNNING
&&
371 (self
->type
== OB_CLIENT_TYPE_DIALOG
||
372 self
->type
== OB_CLIENT_TYPE_SPLASH
||
373 (!((self
->positioned
& USPosition
) ||
374 (settings
&& settings
->pos_given
)) &&
375 client_normal(self
) &&
377 /* don't move oldschool fullscreen windows to
378 fit inside the struts (fixes Acroread, which
379 makes its fullscreen window fit the screen
380 but it is not USSize'd or USPosition'd) */
381 !client_is_oldfullscreen(self
, &place
))));
384 /* if the window isn't user-sized, then make it fit inside
385 the visible screen area on its monitor. Use basically the same rules
386 for forcing the window on screen in the client_find_onscreen call.
388 do this after place_client, it chooses the monitor!
390 splash screens get "transient" set to TRUE by
391 the place_client call
393 if (ob_state() == OB_STATE_RUNNING
&&
395 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
396 client_normal(self
) &&
398 /* don't shrink oldschool fullscreen windows to fit inside the
399 struts (fixes Acroread, which makes its fullscreen window
400 fit the screen but it is not USSize'd or USPosition'd) */
401 !client_is_oldfullscreen(self
, &place
))))
403 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
405 /* get the size of the frame */
406 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
407 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
409 /* fit the window inside the area */
410 place
.width
= MIN(place
.width
, a
->width
);
411 place
.height
= MIN(place
.height
, a
->height
);
413 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
415 /* get the size of the client back */
416 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
417 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
419 g_slice_free(Rect
, a
);
422 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
423 "some restrictions may apply",
424 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
426 ob_debug(" but session requested %d, %d %d x %d instead, "
428 self
->session
->x
, self
->session
->y
,
429 self
->session
->w
, self
->session
->h
);
431 /* do this after the window is placed, so the premax/prefullscreen numbers
434 this also places the window
436 client_apply_startup_state(self
, place
.x
, place
.y
,
437 place
.width
, place
.height
);
439 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s",
440 activate
? "yes" : "no");
442 activate
= client_can_steal_focus(self
, event_time(), launch_time
);
445 /* if the client isn't stealing focus, then hilite it so the user
446 knows it is there, but don't do this if we're restoring from a
448 if (!client_restore_session_stacking(self
))
449 client_hilite(self
, TRUE
);
453 /* This may look rather odd. Well it's because new windows are added
454 to the stacking order non-intrusively. If we're not going to focus
455 the new window or hilite it, then we raise it to the top. This will
456 take affect for things that don't get focused like splash screens.
457 Also if you don't have focus_new enabled, then it's going to get
458 raised to the top. Legacy begets legacy I guess?
460 if (!client_restore_session_stacking(self
))
461 stacking_raise(CLIENT_AS_WINDOW(self
));
464 mouse_grab_for_client(self
, TRUE
);
466 /* this has to happen before we try focus the window, but we want it to
467 happen after the client's stacking has been determined or it looks bad
471 if (!config_focus_under_mouse
)
472 ignore_start
= event_start_ignore_all_enters();
476 if (!config_focus_under_mouse
)
477 event_end_ignore_all_enters(ignore_start
);
481 gboolean stacked
= client_restore_session_stacking(self
);
482 client_present(self
, FALSE
, !stacked
, TRUE
);
485 /* add to client list/map */
486 client_list
= g_list_append(client_list
, self
);
487 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
489 /* this has to happen after we're in the client_list */
490 if (STRUT_EXISTS(self
->strut
))
491 screen_update_areas();
493 /* update the list hints */
496 /* free the ObAppSettings shallow copy */
497 g_slice_free(ObAppSettings
, settings
);
499 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
500 window
, self
->frame
->window
, self
->class);
503 ObClient
*client_fake_manage(Window window
)
506 ObAppSettings
*settings
;
508 ob_debug("Pretend-managing window: %lx", window
);
510 /* do this minimal stuff to figure out the client's decorations */
512 self
= g_slice_new0(ObClient
);
513 self
->window
= window
;
515 client_get_all(self
, FALSE
);
516 /* per-app settings override stuff, and return the settings for other
517 uses too. this returns a shallow copy that needs to be freed */
518 settings
= client_get_settings_state(self
);
520 client_setup_decor_and_functions(self
, FALSE
);
522 /* create the decoration frame for the client window and adjust its size */
523 self
->frame
= frame_new(self
);
524 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
526 ob_debug("gave extents left %d right %d top %d bottom %d",
527 self
->frame
->size
.left
, self
->frame
->size
.right
,
528 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
530 /* free the ObAppSettings shallow copy */
531 g_slice_free(ObAppSettings
, settings
);
536 void client_unmanage_all(void)
539 client_unmanage(client_list
->data
);
542 void client_unmanage(ObClient
*self
)
547 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
548 self
->window
, self
->frame
->window
,
549 self
->class, self
->title
? self
->title
: "");
551 g_assert(self
!= NULL
);
553 /* we dont want events no more. do this before hiding the frame so we
554 don't generate more events */
555 XSelectInput(obt_display
, self
->window
, NoEventMask
);
557 /* ignore enter events from the unmap so it doesnt mess with the focus */
558 if (!config_focus_under_mouse
)
559 ignore_start
= event_start_ignore_all_enters();
561 frame_hide(self
->frame
);
562 /* flush to send the hide to the server quickly */
565 if (!config_focus_under_mouse
)
566 event_end_ignore_all_enters(ignore_start
);
568 mouse_grab_for_client(self
, FALSE
);
570 self
->managed
= FALSE
;
572 /* remove the window from our save set, unless we are managing an internal
575 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
577 /* update the focus lists */
578 focus_order_remove(self
);
579 if (client_focused(self
)) {
580 /* don't leave an invalid focus_client */
584 /* if we're prompting to kill the client, close that */
585 prompt_unref(self
->kill_prompt
);
586 self
->kill_prompt
= NULL
;
588 client_list
= g_list_remove(client_list
, self
);
589 stacking_remove(self
);
590 window_remove(self
->window
);
592 /* once the client is out of the list, update the struts to remove its
594 if (STRUT_EXISTS(self
->strut
))
595 screen_update_areas();
597 client_call_notifies(self
, client_destroy_notifies
);
599 /* tell our parent(s) that we're gone */
600 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
601 ((ObClient
*)it
->data
)->transients
=
602 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
604 /* tell our transients that we're gone */
605 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
606 ((ObClient
*)it
->data
)->parents
=
607 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
608 /* we could be keeping our children in a higher layer */
609 client_calc_layer(it
->data
);
612 /* remove from its group */
614 group_remove(self
->group
, self
);
618 /* restore the window's original geometry so it is not lost */
624 if (self
->fullscreen
)
625 a
= self
->pre_fullscreen_area
;
626 else if (self
->max_horz
|| self
->max_vert
) {
627 if (self
->max_horz
) {
628 a
.x
= self
->pre_max_area
.x
;
629 a
.width
= self
->pre_max_area
.width
;
631 if (self
->max_vert
) {
632 a
.y
= self
->pre_max_area
.y
;
633 a
.height
= self
->pre_max_area
.height
;
637 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
638 /* let it be moved and resized no matter what */
639 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
640 self
->decorations
= 0; /* unmanaged windows have no decor */
642 /* give the client its border back */
643 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
645 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
648 /* reparent the window out of the frame, and free the frame */
649 frame_release_client(self
->frame
);
650 frame_free(self
->frame
);
653 if (ob_state() != OB_STATE_EXITING
) {
654 /* these values should not be persisted across a window
656 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
657 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
658 OBT_PROP_ERASE(self
->window
, WM_STATE
);
660 /* if we're left in an unmapped state, the client wont be mapped.
661 this is bad, since we will no longer be managing the window on
663 XMapWindow(obt_display
, self
->window
);
666 /* these should not be left on the window ever. other window managers
667 don't necessarily use them and it will mess them up (like compiz) */
668 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
669 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
671 /* update the list hints */
674 ob_debug("Unmanaged window 0x%lx", self
->window
);
676 /* free all data allocated in the client struct */
677 RrImageUnref(self
->icon_set
);
678 g_slist_free(self
->transients
);
679 g_free(self
->startup_id
);
680 g_free(self
->wm_command
);
682 g_free(self
->icon_title
);
683 g_free(self
->original_title
);
687 g_free(self
->client_machine
);
688 g_free(self
->sm_client_id
);
689 g_slice_free(ObClient
, self
);
692 void client_fake_unmanage(ObClient
*self
)
694 /* this is all that got allocated to get the decorations */
696 frame_free(self
->frame
);
697 g_slice_free(ObClient
, self
);
700 static gboolean
client_can_steal_focus(ObClient
*self
, Time steal_time
,
704 gboolean relative_focused
;
705 gboolean parent_focused
;
709 parent_focused
= (focus_client
!= NULL
&&
710 client_search_focus_parent(self
));
711 relative_focused
= (focus_client
!= NULL
&&
712 (client_search_focus_tree_full(self
) != NULL
||
713 client_search_focus_group_full(self
) != NULL
));
715 /* This is focus stealing prevention */
716 ob_debug_type(OB_DEBUG_FOCUS
,
717 "Want to focus window 0x%x at time %u "
718 "launched at %u (last user interaction time %u)",
719 self
->window
, steal_time
, launch_time
,
720 event_last_user_time
);
722 /* if it's on another desktop */
723 if (!(self
->desktop
== screen_desktop
||
724 self
->desktop
== DESKTOP_ALL
) &&
725 /* the timestamp is from before you changed desktops */
727 (screen_desktop_user_time
&&
728 !event_time_after(launch_time
, screen_desktop_user_time
))))
731 ob_debug_type(OB_DEBUG_FOCUS
,
732 "Not focusing the window because its on another "
735 /* If something is focused... */
736 else if (focus_client
) {
737 /* If the user is working in another window right now, then don't
739 if (!parent_focused
&&
740 event_last_user_time
&& launch_time
&&
741 event_time_after(event_last_user_time
, launch_time
) &&
742 event_last_user_time
!= launch_time
&&
743 event_time_after(event_last_user_time
,
744 steal_time
- OB_EVENT_USER_TIME_DELAY
))
747 ob_debug_type(OB_DEBUG_FOCUS
,
748 "Not focusing the window because the user is "
749 "working in another window that is not "
752 /* If the new window is a transient (and its relatives aren't
754 else if (client_has_parent(self
) && !relative_focused
) {
756 ob_debug_type(OB_DEBUG_FOCUS
,
757 "Not focusing the window because it is a "
758 "transient, and its relatives aren't focused");
760 /* Don't steal focus from globally active clients.
761 I stole this idea from KWin. It seems nice.
763 else if (!(focus_client
->can_focus
||
764 focus_client
->focus_notify
))
767 ob_debug_type(OB_DEBUG_FOCUS
,
768 "Not focusing the window because a globally "
769 "active client has focus");
771 /* Don't move focus if it's not going to go to this window
773 else if (client_focus_target(self
) != self
) {
775 ob_debug_type(OB_DEBUG_FOCUS
,
776 "Not focusing the window because another window "
777 "would get the focus anyway");
779 /* Don't move focus if the window is not visible on the current
780 desktop and none of its relatives are focused */
781 else if (!(self
->desktop
== screen_desktop
||
782 self
->desktop
== DESKTOP_ALL
) &&
786 ob_debug_type(OB_DEBUG_FOCUS
,
787 "Not focusing the window because it is on "
788 "another desktop and no relatives are focused ");
793 ob_debug_type(OB_DEBUG_FOCUS
,
794 "Focus stealing prevention activated for %s at "
795 "time %u (last user interaction time %u)",
796 self
->title
, steal_time
, event_last_user_time
);
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
||
814 app
->role
!= NULL
|| app
->title
!= NULL
||
815 (signed)app
->type
>= 0);
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
))
828 else if (app
->title
&&
829 !g_pattern_match(app
->title
,
830 strlen(self
->title
), self
->title
, NULL
))
832 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
) {
837 ob_debug("Window matching: %s", app
->name
);
839 /* copy the settings to our struct, overriding the existing
840 settings if they are not defaults */
841 config_app_settings_copy_non_defaults(app
, settings
);
845 if (settings
->shade
!= -1)
846 self
->shaded
= !!settings
->shade
;
847 if (settings
->decor
!= -1)
848 self
->undecorated
= !settings
->decor
;
849 if (settings
->iconic
!= -1)
850 self
->iconic
= !!settings
->iconic
;
851 if (settings
->skip_pager
!= -1)
852 self
->skip_pager
= !!settings
->skip_pager
;
853 if (settings
->skip_taskbar
!= -1)
854 self
->skip_taskbar
= !!settings
->skip_taskbar
;
856 if (settings
->max_vert
!= -1)
857 self
->max_vert
= !!settings
->max_vert
;
858 if (settings
->max_horz
!= -1)
859 self
->max_horz
= !!settings
->max_horz
;
861 if (settings
->fullscreen
!= -1)
862 self
->fullscreen
= !!settings
->fullscreen
;
864 if (settings
->desktop
) {
865 if (settings
->desktop
== DESKTOP_ALL
)
866 self
->desktop
= settings
->desktop
;
867 else if (settings
->desktop
> 0 &&
868 settings
->desktop
<= screen_num_desktops
)
869 self
->desktop
= settings
->desktop
- 1;
872 if (settings
->layer
== -1) {
876 else if (settings
->layer
== 0) {
880 else if (settings
->layer
== 1) {
887 static void client_restore_session_state(ObClient
*self
)
891 ob_debug_type(OB_DEBUG_SM
,
892 "Restore session for client %s", self
->title
);
894 if (!(it
= session_state_find(self
))) {
895 ob_debug_type(OB_DEBUG_SM
,
896 "Session data not found for client %s", self
->title
);
900 self
->session
= it
->data
;
902 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
905 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
906 self
->positioned
= USPosition
;
907 self
->sized
= USSize
;
908 if (self
->session
->w
> 0)
909 self
->area
.width
= self
->session
->w
;
910 if (self
->session
->h
> 0)
911 self
->area
.height
= self
->session
->h
;
912 XResizeWindow(obt_display
, self
->window
,
913 self
->area
.width
, self
->area
.height
);
915 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
916 self
->session
->desktop
:
917 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
918 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
920 self
->shaded
= self
->session
->shaded
;
921 self
->iconic
= self
->session
->iconic
;
922 self
->skip_pager
= self
->session
->skip_pager
;
923 self
->skip_taskbar
= self
->session
->skip_taskbar
;
924 self
->fullscreen
= self
->session
->fullscreen
;
925 self
->above
= self
->session
->above
;
926 self
->below
= self
->session
->below
;
927 self
->max_horz
= self
->session
->max_horz
;
928 self
->max_vert
= self
->session
->max_vert
;
929 self
->undecorated
= self
->session
->undecorated
;
932 static gboolean
client_restore_session_stacking(ObClient
*self
)
936 if (!self
->session
) return FALSE
;
938 mypos
= g_list_find(session_saved_state
, self
->session
);
939 if (!mypos
) return FALSE
;
941 /* start above me and look for the first client */
942 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
945 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
946 ObClient
*c
= cit
->data
;
947 /* found a client that was in the session, so go below it */
948 if (c
->session
== it
->data
) {
949 stacking_below(CLIENT_AS_WINDOW(self
),
950 CLIENT_AS_WINDOW(cit
->data
));
958 void client_move_onscreen(ObClient
*self
, gboolean rude
)
960 gint x
= self
->area
.x
;
961 gint y
= self
->area
.y
;
962 if (client_find_onscreen(self
, &x
, &y
,
964 self
->area
.height
, rude
)) {
965 client_move(self
, x
, y
);
969 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
972 gint ox
= *x
, oy
= *y
;
973 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
979 RECT_SET(desired
, *x
, *y
, w
, h
);
980 frame_rect_to_frame(self
->frame
, &desired
);
982 /* get where the frame would be */
983 frame_client_gravity(self
->frame
, x
, y
);
985 /* get the requested size of the window with decorations */
986 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
987 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
989 /* If rudeness wasn't requested, then still be rude in a given direction
990 if the client is not moving, only resizing in that direction */
992 Point oldtl
, oldtr
, oldbl
, oldbr
;
993 Point newtl
, newtr
, newbl
, newbr
;
994 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
996 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
997 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
998 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
999 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1000 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1002 POINT_SET(newtl
, *x
, *y
);
1003 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1004 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1005 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1007 /* is it moving or just resizing from some corner? */
1008 stationary_l
= oldtl
.x
== newtl
.x
;
1009 stationary_r
= oldtr
.x
== newtr
.x
;
1010 stationary_t
= oldtl
.y
== newtl
.y
;
1011 stationary_b
= oldbl
.y
== newbl
.y
;
1013 /* if left edge is growing and didnt move right edge */
1014 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1016 /* if right edge is growing and didnt move left edge */
1017 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1019 /* if top edge is growing and didnt move bottom edge */
1020 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1022 /* if bottom edge is growing and didnt move top edge */
1023 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1027 /* we iterate through every monitor that the window is at least partially
1028 on, to make sure it is obeying the rules on them all
1030 if the window does not appear on any monitors, then use the first one
1033 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1036 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1037 if (i
< screen_num_monitors
- 1 || found_mon
)
1040 /* the window is not inside any monitor! so just use the first
1042 a
= screen_area(self
->desktop
, 0, NULL
);
1045 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1048 /* This makes sure windows aren't entirely outside of the screen so you
1049 can't see them at all.
1050 It makes sure 10% of the window is on the screen at least. And don't
1051 let it move itself off the top of the screen, which would hide the
1052 titlebar on you. (The user can still do this if they want too, it's
1053 only limiting the application.
1055 if (client_normal(self
)) {
1056 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1057 *x
= a
->x
+ a
->width
- fw
/10;
1058 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1059 *y
= a
->y
+ a
->height
- fh
/10;
1060 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1061 *x
= a
->x
- fw
*9/10;
1062 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1063 *y
= a
->y
- fh
*9/10;
1066 /* This here doesn't let windows even a pixel outside the
1067 struts/screen. When called from client_manage, programs placing
1068 themselves are forced completely onscreen, while things like
1069 xterm -geometry resolution-width/2 will work fine. Trying to
1070 place it completely offscreen will be handled in the above code.
1071 Sorry for this confused comment, i am tired. */
1072 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1073 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1074 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1076 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1077 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1078 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1080 g_slice_free(Rect
, a
);
1083 /* get where the client should be */
1084 frame_frame_gravity(self
->frame
, x
, y
);
1086 return ox
!= *x
|| oy
!= *y
;
1089 static void client_get_all(ObClient
*self
, gboolean real
)
1091 /* this is needed for the frame to set itself up */
1092 client_get_area(self
);
1094 /* these things can change the decor and functions of the window */
1096 client_get_mwm_hints(self
);
1097 /* this can change the mwmhints for special cases */
1098 client_get_type_and_transientness(self
);
1099 client_get_state(self
);
1100 client_update_normal_hints(self
);
1102 /* get the session related properties, these can change decorations
1103 from per-app settings */
1104 client_get_session_ids(self
);
1106 /* now we got everything that can affect the decorations */
1110 /* get this early so we have it for debugging */
1111 client_update_title(self
);
1113 /* save the values of the variables used for app rule matching */
1114 client_save_app_rule_values(self
);
1116 client_update_protocols(self
);
1118 client_update_wmhints(self
);
1119 /* this may have already been called from client_update_wmhints */
1120 if (!self
->parents
&& !self
->transient_for_group
)
1121 client_update_transient_for(self
);
1123 client_get_startup_id(self
);
1124 client_get_desktop(self
);/* uses transient data/group/startup id if a
1125 desktop is not specified */
1126 client_get_shaped(self
);
1129 /* a couple type-based defaults for new windows */
1131 /* this makes sure that these windows appear on all desktops */
1132 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1133 self
->desktop
= DESKTOP_ALL
;
1137 client_update_sync_request_counter(self
);
1140 client_get_colormap(self
);
1141 client_update_strut(self
);
1142 client_update_icons(self
);
1143 client_update_icon_geometry(self
);
1146 static void client_get_startup_id(ObClient
*self
)
1148 if (!(OBT_PROP_GETS(self
->window
, NET_STARTUP_ID
, utf8
,
1149 &self
->startup_id
)))
1151 OBT_PROP_GETS(self
->group
->leader
,
1152 NET_STARTUP_ID
, utf8
, &self
->startup_id
);
1155 static void client_get_area(ObClient
*self
)
1157 XWindowAttributes wattrib
;
1160 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1161 g_assert(ret
!= BadWindow
);
1163 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1164 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1165 self
->border_width
= wattrib
.border_width
;
1167 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1168 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1171 static void client_get_desktop(ObClient
*self
)
1173 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1175 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1176 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1177 self
->desktop
= screen_num_desktops
- 1;
1180 ob_debug("client requested desktop 0x%x", self
->desktop
);
1183 gboolean first
= TRUE
;
1184 guint all
= screen_num_desktops
; /* not a valid value */
1186 /* if they are all on one desktop, then open it on the
1188 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1189 ObClient
*c
= it
->data
;
1191 if (c
->desktop
== DESKTOP_ALL
) continue;
1197 else if (all
!= c
->desktop
)
1198 all
= screen_num_desktops
; /* make it invalid */
1200 if (all
!= screen_num_desktops
) {
1201 self
->desktop
= all
;
1203 ob_debug("client desktop set from parents: 0x%x",
1206 /* try get from the startup-notification protocol */
1207 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1208 if (self
->desktop
>= screen_num_desktops
&&
1209 self
->desktop
!= DESKTOP_ALL
)
1210 self
->desktop
= screen_num_desktops
- 1;
1211 ob_debug("client desktop set from startup-notification: 0x%x",
1214 /* defaults to the current desktop */
1216 self
->desktop
= screen_desktop
;
1217 ob_debug("client desktop set to the current desktop: %d",
1223 static void client_get_state(ObClient
*self
)
1228 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1230 for (i
= 0; i
< num
; ++i
) {
1231 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1233 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1234 self
->shaded
= TRUE
;
1235 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1236 self
->iconic
= TRUE
;
1237 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1238 self
->skip_taskbar
= TRUE
;
1239 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1240 self
->skip_pager
= TRUE
;
1241 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1242 self
->fullscreen
= TRUE
;
1243 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1244 self
->max_vert
= TRUE
;
1245 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1246 self
->max_horz
= TRUE
;
1247 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1249 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1251 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1252 self
->demands_attention
= TRUE
;
1253 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1254 self
->undecorated
= TRUE
;
1261 static void client_get_shaped(ObClient
*self
)
1263 self
->shaped
= FALSE
;
1265 if (obt_display_extension_shape
) {
1270 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1272 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1273 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1280 void client_update_transient_for(ObClient
*self
)
1283 ObClient
*target
= NULL
;
1284 gboolean trangroup
= FALSE
;
1286 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1287 if (t
!= self
->window
) { /* can't be transient to itself! */
1288 ObWindow
*tw
= window_find(t
);
1289 /* if this happens then we need to check for it */
1290 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1291 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1292 /* watch out for windows with a parent that is something
1293 different, like a dockapp for example */
1294 target
= WINDOW_AS_CLIENT(tw
);
1298 /* Setting the transient_for to Root is actually illegal, however
1299 applications from time have done this to specify transient for
1301 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1303 } else if (self
->group
&& self
->transient
)
1306 client_update_transient_tree(self
, self
->group
, self
->group
,
1307 self
->transient_for_group
, trangroup
,
1308 client_direct_parent(self
), target
);
1309 self
->transient_for_group
= trangroup
;
1313 static void client_update_transient_tree(ObClient
*self
,
1314 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1315 gboolean oldgtran
, gboolean newgtran
,
1316 ObClient
* oldparent
,
1317 ObClient
*newparent
)
1322 g_assert(!oldgtran
|| oldgroup
);
1323 g_assert(!newgtran
|| newgroup
);
1324 g_assert((!oldgtran
&& !oldparent
) ||
1325 (oldgtran
&& !oldparent
) ||
1326 (!oldgtran
&& oldparent
));
1327 g_assert((!newgtran
&& !newparent
) ||
1328 (newgtran
&& !newparent
) ||
1329 (!newgtran
&& newparent
));
1332 Group transient windows are not allowed to have other group
1333 transient windows as their children.
1336 /* No change has occured */
1337 if (oldgroup
== newgroup
&&
1338 oldgtran
== newgtran
&&
1339 oldparent
== newparent
) return;
1341 /** Remove the client from the transient tree **/
1343 for (it
= self
->transients
; it
; it
= next
) {
1344 next
= g_slist_next(it
);
1346 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1347 c
->parents
= g_slist_remove(c
->parents
, self
);
1349 for (it
= self
->parents
; it
; it
= next
) {
1350 next
= g_slist_next(it
);
1352 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1353 c
->transients
= g_slist_remove(c
->transients
, self
);
1356 /** Re-add the client to the transient tree **/
1358 /* If we're transient for a group then we need to add ourselves to all our
1361 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1364 !client_search_top_direct_parent(c
)->transient_for_group
&&
1367 c
->transients
= g_slist_prepend(c
->transients
, self
);
1368 self
->parents
= g_slist_prepend(self
->parents
, c
);
1373 /* If we are now transient for a single window we need to add ourselves to
1376 WARNING: Cyclical transient-ness is possible if two windows are
1377 transient for eachother.
1379 else if (newparent
&&
1380 /* don't make ourself its child if it is already our child */
1381 !client_is_direct_child(self
, newparent
) &&
1382 client_normal(newparent
))
1384 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1385 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1388 /* Add any group transient windows to our children. But if we're transient
1389 for the group, then other group transients are not our children.
1391 WARNING: Cyclical transient-ness is possible. For e.g. if:
1392 A is transient for the group
1393 B is transient for A
1394 C is transient for B
1395 A can't be transient for C or we have a cycle
1397 if (!newgtran
&& newgroup
&&
1399 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1400 client_normal(self
))
1402 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1404 if (c
!= self
&& c
->transient_for_group
&&
1405 /* Don't make it our child if it is already our parent */
1406 !client_is_direct_child(c
, self
))
1408 self
->transients
= g_slist_prepend(self
->transients
, c
);
1409 c
->parents
= g_slist_prepend(c
->parents
, self
);
1414 /** If we change our group transient-ness, our children change their
1415 effective group transient-ness, which affects how they relate to other
1418 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1420 if (!c
->transient_for_group
)
1421 client_update_transient_tree(c
, c
->group
, c
->group
,
1422 c
->transient_for_group
,
1423 c
->transient_for_group
,
1424 client_direct_parent(c
),
1425 client_direct_parent(c
));
1429 void client_get_mwm_hints(ObClient
*self
)
1434 self
->mwmhints
.flags
= 0; /* default to none */
1436 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1438 if (num
>= OB_MWM_ELEMENTS
) {
1439 self
->mwmhints
.flags
= hints
[0];
1440 self
->mwmhints
.functions
= hints
[1];
1441 self
->mwmhints
.decorations
= hints
[2];
1447 void client_get_type_and_transientness(ObClient
*self
)
1454 self
->transient
= FALSE
;
1456 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1457 /* use the first value that we know about in the array */
1458 for (i
= 0; i
< num
; ++i
) {
1459 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1460 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1461 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1462 self
->type
= OB_CLIENT_TYPE_DOCK
;
1463 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1464 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1465 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1466 self
->type
= OB_CLIENT_TYPE_MENU
;
1467 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1468 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1469 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1470 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1471 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1472 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1473 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1474 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1475 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1477 /* prevent this window from getting any decor or
1479 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1480 OB_MWM_FLAG_DECORATIONS
);
1481 self
->mwmhints
.decorations
= 0;
1482 self
->mwmhints
.functions
= 0;
1484 if (self
->type
!= (ObClientType
) -1)
1485 break; /* grab the first legit type */
1490 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1491 self
->transient
= TRUE
;
1493 if (self
->type
== (ObClientType
) -1) {
1494 /*the window type hint was not set, which means we either classify
1495 ourself as a normal window or a dialog, depending on if we are a
1497 if (self
->transient
)
1498 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1500 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1503 /* then, based on our type, we can update our transientness.. */
1504 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1505 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1506 self
->type
== OB_CLIENT_TYPE_MENU
||
1507 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1509 self
->transient
= TRUE
;
1513 void client_update_protocols(ObClient
*self
)
1518 self
->focus_notify
= FALSE
;
1519 self
->delete_window
= FALSE
;
1521 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1522 for (i
= 0; i
< num_ret
; ++i
) {
1523 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1524 /* this means we can request the window to close */
1525 self
->delete_window
= TRUE
;
1526 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1527 /* if this protocol is requested, then the window will be
1528 notified whenever we want it to receive focus */
1529 self
->focus_notify
= TRUE
;
1530 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1531 /* if this protocol is requested, then the window will allow
1532 pings to determine if it is still alive */
1535 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1536 /* if this protocol is requested, then resizing the
1537 window will be synchronized between the frame and the
1539 self
->sync_request
= TRUE
;
1547 void client_update_sync_request_counter(ObClient
*self
)
1551 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1553 self
->sync_counter
= i
;
1555 self
->sync_counter
= None
;
1559 static void client_get_colormap(ObClient
*self
)
1561 XWindowAttributes wa
;
1563 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1564 client_update_colormap(self
, wa
.colormap
);
1567 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1569 if (colormap
== self
->colormap
) return;
1571 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1573 if (client_focused(self
)) {
1574 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1575 self
->colormap
= colormap
;
1576 screen_install_colormap(self
, TRUE
); /* install new one */
1578 self
->colormap
= colormap
;
1581 void client_update_normal_hints(ObClient
*self
)
1587 self
->min_ratio
= 0.0f
;
1588 self
->max_ratio
= 0.0f
;
1589 SIZE_SET(self
->size_inc
, 1, 1);
1590 SIZE_SET(self
->base_size
, -1, -1);
1591 SIZE_SET(self
->min_size
, 0, 0);
1592 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1594 /* get the hints from the window */
1595 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1596 /* normal windows can't request placement! har har
1597 if (!client_normal(self))
1599 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1600 self
->sized
= (size
.flags
& (PSize
|USSize
));
1602 if (size
.flags
& PWinGravity
)
1603 self
->gravity
= size
.win_gravity
;
1605 if (size
.flags
& PAspect
) {
1606 if (size
.min_aspect
.y
)
1608 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1609 if (size
.max_aspect
.y
)
1611 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1614 if (size
.flags
& PMinSize
)
1615 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1617 if (size
.flags
& PMaxSize
)
1618 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1620 if (size
.flags
& PBaseSize
)
1621 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1623 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1624 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1626 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1627 self
->min_size
.width
, self
->min_size
.height
,
1628 self
->max_size
.width
, self
->max_size
.height
);
1629 ob_debug("size inc (%d %d) base size (%d %d)",
1630 self
->size_inc
.width
, self
->size_inc
.height
,
1631 self
->base_size
.width
, self
->base_size
.height
);
1634 ob_debug("Normal hints: not set");
1637 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1639 /* start with everything (cept fullscreen) */
1641 (OB_FRAME_DECOR_TITLEBAR
|
1642 OB_FRAME_DECOR_HANDLE
|
1643 OB_FRAME_DECOR_GRIPS
|
1644 OB_FRAME_DECOR_BORDER
|
1645 OB_FRAME_DECOR_ICON
|
1646 OB_FRAME_DECOR_ALLDESKTOPS
|
1647 OB_FRAME_DECOR_ICONIFY
|
1648 OB_FRAME_DECOR_MAXIMIZE
|
1649 OB_FRAME_DECOR_SHADE
|
1650 OB_FRAME_DECOR_CLOSE
);
1652 (OB_CLIENT_FUNC_RESIZE
|
1653 OB_CLIENT_FUNC_MOVE
|
1654 OB_CLIENT_FUNC_ICONIFY
|
1655 OB_CLIENT_FUNC_MAXIMIZE
|
1656 OB_CLIENT_FUNC_SHADE
|
1657 OB_CLIENT_FUNC_CLOSE
|
1658 OB_CLIENT_FUNC_BELOW
|
1659 OB_CLIENT_FUNC_ABOVE
|
1660 OB_CLIENT_FUNC_UNDECORATE
);
1662 if (!(self
->min_size
.width
< self
->max_size
.width
||
1663 self
->min_size
.height
< self
->max_size
.height
))
1664 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1666 switch (self
->type
) {
1667 case OB_CLIENT_TYPE_NORMAL
:
1668 /* normal windows retain all of the possible decorations and
1669 functionality, and can be fullscreen */
1670 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1673 case OB_CLIENT_TYPE_DIALOG
:
1674 /* sometimes apps make dialog windows fullscreen for some reason (for
1675 e.g. kpdf does this..) */
1676 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1679 case OB_CLIENT_TYPE_UTILITY
:
1680 /* these windows don't have anything added or removed by default */
1683 case OB_CLIENT_TYPE_MENU
:
1684 case OB_CLIENT_TYPE_TOOLBAR
:
1685 /* these windows can't iconify or maximize */
1686 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1687 OB_FRAME_DECOR_MAXIMIZE
);
1688 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1689 OB_CLIENT_FUNC_MAXIMIZE
);
1692 case OB_CLIENT_TYPE_SPLASH
:
1693 /* these don't get get any decorations, and the only thing you can
1694 do with them is move them */
1695 self
->decorations
= 0;
1696 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1699 case OB_CLIENT_TYPE_DESKTOP
:
1700 /* these windows are not manipulated by the window manager */
1701 self
->decorations
= 0;
1702 self
->functions
= 0;
1705 case OB_CLIENT_TYPE_DOCK
:
1706 /* these windows are not manipulated by the window manager, but they
1707 can set below layer which has a special meaning */
1708 self
->decorations
= 0;
1709 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1713 /* Mwm Hints are applied subtractively to what has already been chosen for
1714 decor and functionality */
1715 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1716 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1717 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1718 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1720 /* if the mwm hints request no handle or title, then all
1721 decorations are disabled, but keep the border if that's
1723 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1724 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1726 self
->decorations
= 0;
1731 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1732 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1733 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1734 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1735 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1736 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1737 /* dont let mwm hints kill any buttons
1738 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1739 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1740 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1741 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1743 /* dont let mwm hints kill the close button
1744 if (! (self->mwmhints.functions & MwmFunc_Close))
1745 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1749 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1750 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1751 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1752 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1753 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1754 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1756 /* can't maximize without moving/resizing */
1757 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1758 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1759 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1760 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1761 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1764 if (self
->max_horz
&& self
->max_vert
) {
1765 /* you can't resize fully maximized windows */
1766 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1767 /* kill the handle on fully maxed windows */
1768 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1771 /* If there are no decorations to remove, don't allow the user to try
1773 if (self
->decorations
== 0)
1774 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1776 /* finally, the user can have requested no decorations, which overrides
1777 everything (but doesnt give it a border if it doesnt have one) */
1778 if (self
->undecorated
)
1779 self
->decorations
&= (config_theme_keepborder
?
1780 OB_FRAME_DECOR_BORDER
: 0);
1782 /* if we don't have a titlebar, then we cannot shade! */
1783 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1784 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1786 /* now we need to check against rules for the client's current state */
1787 if (self
->fullscreen
) {
1788 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1789 OB_CLIENT_FUNC_FULLSCREEN
|
1790 OB_CLIENT_FUNC_ICONIFY
);
1791 self
->decorations
= 0;
1794 client_change_allowed_actions(self
);
1797 /* force reconfigure to make sure decorations are updated */
1798 client_reconfigure(self
, TRUE
);
1801 static void client_change_allowed_actions(ObClient
*self
)
1806 /* desktop windows are kept on all desktops */
1807 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1808 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1810 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1811 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1812 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1813 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1814 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1815 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1816 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1817 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1818 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1819 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1820 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1821 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1822 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1823 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1824 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1826 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1827 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1828 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1829 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1830 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1831 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1833 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1835 /* make sure the window isn't breaking any rules now
1837 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1838 it can't be iconified with its parent
1841 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1842 if (self
->frame
) client_shade(self
, FALSE
);
1843 else self
->shaded
= FALSE
;
1845 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1846 if (self
->frame
) client_fullscreen(self
, FALSE
);
1847 else self
->fullscreen
= FALSE
;
1849 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1851 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1852 else self
->max_vert
= self
->max_horz
= FALSE
;
1856 void client_update_wmhints(ObClient
*self
)
1860 /* assume a window takes input if it doesn't specify */
1861 self
->can_focus
= TRUE
;
1863 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1866 if (hints
->flags
& InputHint
)
1867 self
->can_focus
= hints
->input
;
1869 /* only do this when first managing the window *AND* when we aren't
1871 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1872 if (hints
->flags
& StateHint
)
1873 self
->iconic
= hints
->initial_state
== IconicState
;
1876 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1877 if (self
->urgent
&& !ur
)
1878 client_hilite(self
, TRUE
);
1879 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1880 client_hilite(self
, FALSE
);
1882 if (!(hints
->flags
& WindowGroupHint
))
1883 hints
->window_group
= None
;
1885 /* did the group state change? */
1886 if (hints
->window_group
!=
1887 (self
->group
? self
->group
->leader
: None
))
1889 ObGroup
*oldgroup
= self
->group
;
1891 /* remove from the old group if there was one */
1893 group_remove(self
->group
, self
);
1897 /* add ourself to the group if we have one */
1898 if (hints
->window_group
!= None
) {
1899 self
->group
= group_add(hints
->window_group
, self
);
1902 /* Put ourselves into the new group's transient tree, and remove
1903 ourselves from the old group's */
1904 client_update_transient_tree(self
, oldgroup
, self
->group
,
1905 self
->transient_for_group
,
1906 self
->transient_for_group
,
1907 client_direct_parent(self
),
1908 client_direct_parent(self
));
1910 /* Lastly, being in a group, or not, can change if the window is
1911 transient for anything.
1913 The logic for this is:
1914 self->transient = TRUE always if the window wants to be
1915 transient for something, even if transient_for was NULL because
1916 it wasn't in a group before.
1918 If parents was NULL and oldgroup was NULL we can assume
1919 that when we add the new group, it will become transient for
1922 If transient_for_group is TRUE, then it must have already
1923 had a group. If it is getting a new group, the above call to
1924 client_update_transient_tree has already taken care of
1925 everything ! If it is losing all group status then it will
1926 no longer be transient for anything and that needs to be
1929 if (self
->transient
&&
1930 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1931 (self
->transient_for_group
&& !self
->group
)))
1932 client_update_transient_for(self
);
1935 /* the WM_HINTS can contain an icon */
1936 if (hints
->flags
& IconPixmapHint
)
1937 client_update_icons(self
);
1942 focus_cycle_addremove(self
, TRUE
);
1945 void client_update_title(ObClient
*self
)
1948 gchar
*visible
= NULL
;
1950 g_free(self
->title
);
1951 g_free(self
->original_title
);
1954 if (!OBT_PROP_GETS(self
->window
, NET_WM_NAME
, utf8
, &data
)) {
1955 /* try old x stuff */
1956 if (!(OBT_PROP_GETS(self
->window
, WM_NAME
, locale
, &data
)
1957 || OBT_PROP_GETS(self
->window
, WM_NAME
, utf8
, &data
))) {
1958 if (self
->transient
) {
1960 GNOME alert windows are not given titles:
1961 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1963 data
= g_strdup("");
1965 data
= g_strdup(_("Unnamed Window"));
1968 self
->original_title
= g_strdup(data
);
1970 if (self
->client_machine
) {
1971 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1976 if (self
->not_responding
) {
1978 if (self
->kill_level
> 0)
1979 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1981 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1985 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, utf8
, visible
);
1986 self
->title
= visible
;
1989 frame_adjust_title(self
->frame
);
1991 /* update the icon title */
1993 g_free(self
->icon_title
);
1996 if (!OBT_PROP_GETS(self
->window
, NET_WM_ICON_NAME
, utf8
, &data
))
1997 /* try old x stuff */
1998 if (!(OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, locale
, &data
) ||
1999 OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, utf8
, &data
)))
2000 data
= g_strdup(self
->title
);
2002 if (self
->client_machine
) {
2003 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2008 if (self
->not_responding
) {
2010 if (self
->kill_level
> 0)
2011 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2013 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2017 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, utf8
, visible
);
2018 self
->icon_title
= visible
;
2021 void client_update_strut(ObClient
*self
)
2025 gboolean got
= FALSE
;
2028 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
2033 STRUT_PARTIAL_SET(strut
,
2034 data
[0], data
[2], data
[1], data
[3],
2035 data
[4], data
[5], data
[8], data
[9],
2036 data
[6], data
[7], data
[10], data
[11]);
2042 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
2048 /* use the screen's width/height */
2049 a
= screen_physical_area_all_monitors();
2051 STRUT_PARTIAL_SET(strut
,
2052 data
[0], data
[2], data
[1], data
[3],
2053 a
->y
, a
->y
+ a
->height
- 1,
2054 a
->x
, a
->x
+ a
->width
- 1,
2055 a
->y
, a
->y
+ a
->height
- 1,
2056 a
->x
, a
->x
+ a
->width
- 1);
2062 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2063 0, 0, 0, 0, 0, 0, 0, 0);
2065 if (!PARTIAL_STRUT_EQUAL(strut
, self
->strut
)) {
2066 self
->strut
= strut
;
2068 /* updating here is pointless while we're being mapped cuz we're not in
2069 the client list yet */
2071 screen_update_areas();
2075 void client_update_icons(ObClient
*self
)
2080 guint num_seen
; /* number of icons present */
2085 /* grab the server, because we might be setting the window's icon and
2086 we don't want them to set it in between and we overwrite their own
2090 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2091 /* figure out how many valid icons are in here */
2094 while (i
+ 2 < num
) { /* +2 is to make sure there is a w and h */
2097 /* watch for the data being too small for the specified size,
2098 or for zero sized icons. */
2099 if (i
+ w
*h
> num
|| w
== 0 || h
== 0) break;
2101 /* convert it to the right bit order for ObRender */
2102 for (j
= 0; j
< w
*h
; ++j
)
2104 (((data
[i
+j
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2105 (((data
[i
+j
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2106 (((data
[i
+j
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2107 (((data
[i
+j
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2109 /* is it in the cache? */
2110 img
= RrImageCacheFind(ob_rr_icons
, &data
[i
], w
, h
);
2111 if (img
) RrImageRef(img
); /* own it */
2116 /* don't bother looping anymore if we already found it in the cache
2117 since we'll just use that! */
2121 /* if it's not in the cache yet, then add it to the cache now.
2122 we have already converted it to the correct bit order above */
2123 if (!img
&& num_seen
> 0) {
2124 img
= RrImageNew(ob_rr_icons
);
2126 for (j
= 0; j
< num_seen
; ++j
) {
2129 RrImageAddPicture(img
, &data
[i
], w
, h
);
2137 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2142 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2143 if (hints
->flags
& IconPixmapHint
) {
2145 obt_display_ignore_errors(TRUE
);
2146 xicon
= RrPixmapToRGBA(ob_rr_inst
,
2148 (hints
->flags
& IconMaskHint
?
2149 hints
->icon_mask
: None
),
2150 (gint
*)&w
, (gint
*)&h
, &data
);
2151 obt_display_ignore_errors(FALSE
);
2154 if (w
> 0 && h
> 0) {
2155 /* is this icon in the cache yet? */
2156 img
= RrImageCacheFind(ob_rr_icons
, data
, w
, h
);
2157 if (img
) RrImageRef(img
); /* own it */
2159 /* if not, then add it */
2161 img
= RrImageNew(ob_rr_icons
);
2162 RrImageAddPicture(img
, data
, w
, h
);
2173 /* set the client's icons to be whatever we found */
2174 RrImageUnref(self
->icon_set
);
2175 self
->icon_set
= img
;
2177 /* if the client has no icon at all, then we set a default icon onto it.
2178 but, if it has parents, then one of them will have an icon already
2180 if (!self
->icon_set
&& !self
->parents
) {
2181 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2182 gulong
*ldata
; /* use a long here to satisfy OBT_PROP_SETA32 */
2184 w
= ob_rr_theme
->def_win_icon_w
;
2185 h
= ob_rr_theme
->def_win_icon_h
;
2186 ldata
= g_new(gulong
, w
*h
+2);
2189 for (i
= 0; i
< w
*h
; ++i
)
2190 ldata
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2191 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2192 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2193 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2194 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, ldata
, w
*h
+2);
2196 } else if (self
->frame
)
2197 /* don't draw the icon empty if we're just setting one now anyways,
2198 we'll get the property change any second */
2199 frame_adjust_icon(self
->frame
);
2204 void client_update_icon_geometry(ObClient
*self
)
2209 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2211 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2215 /* don't let them set it with an area < 0 */
2216 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2217 MAX(data
[2],0), MAX(data
[3],0));
2222 static void client_get_session_ids(ObClient
*self
)
2229 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2232 /* get the SM_CLIENT_ID */
2235 got
= OBT_PROP_GETS(leader
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2237 OBT_PROP_GETS(self
->window
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2239 /* get the WM_CLASS (name and class). make them "" if they are not
2243 got
= OBT_PROP_GETSS(leader
, WM_CLASS
, locale
, &ss
);
2245 got
= OBT_PROP_GETSS(self
->window
, WM_CLASS
, locale
, &ss
);
2249 self
->name
= g_strdup(ss
[0]);
2251 self
->class = g_strdup(ss
[1]);
2256 if (self
->name
== NULL
) self
->name
= g_strdup("");
2257 if (self
->class == NULL
) self
->class = g_strdup("");
2259 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2262 got
= OBT_PROP_GETS(leader
, WM_WINDOW_ROLE
, locale
, &s
);
2264 got
= OBT_PROP_GETS(self
->window
, WM_WINDOW_ROLE
, locale
, &s
);
2269 self
->role
= g_strdup("");
2271 /* get the WM_COMMAND */
2275 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, locale
, &ss
);
2277 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, locale
, &ss
);
2280 /* merge/mash them all together */
2281 gchar
*merge
= NULL
;
2284 for (i
= 0; ss
[i
]; ++i
) {
2287 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2289 merge
= g_strconcat(ss
[i
], NULL
);
2294 self
->wm_command
= merge
;
2297 /* get the WM_CLIENT_MACHINE */
2300 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, locale
, &s
);
2302 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, locale
, &s
);
2305 gchar localhost
[128];
2308 gethostname(localhost
, 127);
2309 localhost
[127] = '\0';
2310 if (strcmp(localhost
, s
) != 0)
2311 self
->client_machine
= s
;
2315 /* see if it has the PID set too (the PID requires that the
2316 WM_CLIENT_MACHINE be set) */
2317 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2322 /*! Save the properties used for app matching rules, as seen by Openbox when
2323 the window mapped, so that users can still access them later if the app
2325 static void client_save_app_rule_values(ObClient
*self
)
2329 OBT_PROP_SETS(self
->window
, OB_APP_ROLE
, utf8
, self
->role
);
2330 OBT_PROP_SETS(self
->window
, OB_APP_NAME
, utf8
, self
->name
);
2331 OBT_PROP_SETS(self
->window
, OB_APP_CLASS
, utf8
, self
->class);
2332 OBT_PROP_SETS(self
->window
, OB_APP_TITLE
, utf8
, self
->original_title
);
2334 switch (self
->type
) {
2335 case OB_CLIENT_TYPE_NORMAL
:
2336 type
= "normal"; break;
2337 case OB_CLIENT_TYPE_DIALOG
:
2338 type
= "dialog"; break;
2339 case OB_CLIENT_TYPE_UTILITY
:
2340 type
= "utility"; break;
2341 case OB_CLIENT_TYPE_MENU
:
2342 type
= "menu"; break;
2343 case OB_CLIENT_TYPE_TOOLBAR
:
2344 type
= "toolbar"; break;
2345 case OB_CLIENT_TYPE_SPLASH
:
2346 type
= "splash"; break;
2347 case OB_CLIENT_TYPE_DESKTOP
:
2348 type
= "desktop"; break;
2349 case OB_CLIENT_TYPE_DOCK
:
2350 type
= "dock"; break;
2352 OBT_PROP_SETS(self
->window
, OB_APP_TYPE
, utf8
, type
);
2355 static void client_change_wm_state(ObClient
*self
)
2360 old
= self
->wmstate
;
2362 if (self
->shaded
|| self
->iconic
||
2363 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2365 self
->wmstate
= IconicState
;
2367 self
->wmstate
= NormalState
;
2369 if (old
!= self
->wmstate
) {
2370 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2371 self
->wmstate
, 1, 0, 0, 0);
2373 state
[0] = self
->wmstate
;
2375 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2379 static void client_change_state(ObClient
*self
)
2381 gulong netstate
[12];
2386 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2388 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2390 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2391 if (self
->skip_taskbar
)
2392 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2393 if (self
->skip_pager
)
2394 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2395 if (self
->fullscreen
)
2396 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2398 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2400 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2402 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2404 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2405 if (self
->demands_attention
)
2406 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2407 if (self
->undecorated
)
2408 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2409 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2412 frame_adjust_state(self
->frame
);
2415 ObClient
*client_search_focus_tree(ObClient
*self
)
2420 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2421 if (client_focused(it
->data
)) return it
->data
;
2422 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2427 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2429 if (self
->parents
) {
2432 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2433 ObClient
*c
= it
->data
;
2434 if ((c
= client_search_focus_tree_full(c
))) return c
;
2440 /* this function checks the whole tree, the client_search_focus_tree
2441 does not, so we need to check this window */
2442 if (client_focused(self
))
2444 return client_search_focus_tree(self
);
2448 ObClient
*client_search_focus_group_full(ObClient
*self
)
2453 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2454 ObClient
*c
= it
->data
;
2456 if (client_focused(c
)) return c
;
2457 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2460 if (client_focused(self
)) return self
;
2464 gboolean
client_has_parent(ObClient
*self
)
2466 return self
->parents
!= NULL
;
2469 gboolean
client_is_oldfullscreen(const ObClient
*self
,
2472 const Rect
*monitor
, *allmonitors
;
2474 /* No decorations and fills the monitor = oldskool fullscreen.
2475 But not for maximized windows.
2478 if (self
->decorations
|| self
->max_horz
|| self
->max_vert
) return FALSE
;
2480 monitor
= screen_physical_area_monitor(screen_find_monitor(area
));
2481 allmonitors
= screen_physical_area_all_monitors();
2483 return (RECT_EQUAL(*area
, *monitor
) ||
2484 RECT_EQUAL(*area
, *allmonitors
));
2487 static ObStackingLayer
calc_layer(ObClient
*self
)
2490 const Rect
*monitor
, *allmonitors
;
2492 monitor
= screen_physical_area_monitor(client_monitor(self
));
2493 allmonitors
= screen_physical_area_all_monitors();
2495 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2496 l
= OB_STACKING_LAYER_DESKTOP
;
2497 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2498 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2499 else l
= OB_STACKING_LAYER_ABOVE
;
2501 else if ((self
->fullscreen
||
2502 client_is_oldfullscreen(self
, &self
->area
)) &&
2503 /* you are fullscreen while you or your children are focused.. */
2504 (client_focused(self
) || client_search_focus_tree(self
) ||
2505 /* you can be fullscreen if you're on another desktop */
2506 (self
->desktop
!= screen_desktop
&&
2507 self
->desktop
!= DESKTOP_ALL
) ||
2508 /* and you can also be fullscreen if the focused client is on
2509 another monitor, or nothing else is focused */
2511 client_monitor(focus_client
) != client_monitor(self
))))
2512 l
= OB_STACKING_LAYER_FULLSCREEN
;
2513 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2514 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2515 else l
= OB_STACKING_LAYER_NORMAL
;
2520 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2521 ObStackingLayer min
)
2523 ObStackingLayer old
, own
;
2527 own
= calc_layer(self
);
2528 self
->layer
= MAX(own
, min
);
2530 if (self
->layer
!= old
) {
2531 stacking_remove(CLIENT_AS_WINDOW(self
));
2532 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2535 /* we've been restacked */
2536 self
->visited
= TRUE
;
2538 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2539 client_calc_layer_recursive(it
->data
, orig
,
2543 static void client_calc_layer_internal(ObClient
*self
)
2547 /* transients take on the layer of their parents */
2548 sit
= client_search_all_top_parents(self
);
2550 for (; sit
; sit
= g_slist_next(sit
))
2551 client_calc_layer_recursive(sit
->data
, self
, 0);
2554 void client_calc_layer(ObClient
*self
)
2558 /* skip over stuff above fullscreen layer */
2559 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2560 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2562 /* find the windows in the fullscreen layer, and mark them not-visited */
2563 for (; it
; it
= g_list_next(it
)) {
2564 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2565 else if (WINDOW_IS_CLIENT(it
->data
))
2566 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2569 client_calc_layer_internal(self
);
2571 /* skip over stuff above fullscreen layer */
2572 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2573 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2575 /* now recalc any windows in the fullscreen layer which have not
2576 had their layer recalced already */
2577 for (; it
; it
= g_list_next(it
)) {
2578 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2579 else if (WINDOW_IS_CLIENT(it
->data
) &&
2580 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2581 client_calc_layer_internal(it
->data
);
2585 gboolean
client_should_show(ObClient
*self
)
2589 if (client_normal(self
) && screen_showing_desktop
)
2591 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2597 gboolean
client_show(ObClient
*self
)
2599 gboolean show
= FALSE
;
2601 if (client_should_show(self
)) {
2602 /* replay pending pointer event before showing the window, in case it
2603 should be going to something under the window */
2604 mouse_replay_pointer();
2606 frame_show(self
->frame
);
2609 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2610 it needs to be in IconicState. This includes when it is on another
2613 client_change_wm_state(self
);
2618 gboolean
client_hide(ObClient
*self
)
2620 gboolean hide
= FALSE
;
2622 if (!client_should_show(self
)) {
2623 /* We don't need to ignore enter events here.
2624 The window can hide/iconify in 3 different ways:
2625 1 - through an x message. in this case we ignore all enter events
2626 caused by responding to the x message (unless underMouse)
2627 2 - by a keyboard action. in this case we ignore all enter events
2628 caused by the action
2629 3 - by a mouse action. in this case they are doing stuff with the
2630 mouse and focus _should_ move.
2632 Also in action_end, we simulate an enter event that can't be ignored
2633 so trying to ignore them is futile in case 3 anyways
2636 /* replay pending pointer event before hiding the window, in case it
2637 should be going to the window */
2638 mouse_replay_pointer();
2640 frame_hide(self
->frame
);
2643 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2644 it needs to be in IconicState. This includes when it is on another
2647 client_change_wm_state(self
);
2652 void client_showhide(ObClient
*self
)
2654 if (!client_show(self
))
2658 gboolean
client_normal(ObClient
*self
) {
2659 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2660 self
->type
== OB_CLIENT_TYPE_DOCK
||
2661 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2664 gboolean
client_helper(ObClient
*self
)
2666 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2667 self
->type
== OB_CLIENT_TYPE_MENU
||
2668 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2671 gboolean
client_mouse_focusable(ObClient
*self
)
2673 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2674 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2675 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2676 self
->type
== OB_CLIENT_TYPE_DOCK
);
2679 gboolean
client_enter_focusable(ObClient
*self
)
2681 /* you can focus desktops but it shouldn't on enter */
2682 return (client_mouse_focusable(self
) &&
2683 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2686 static void client_apply_startup_state(ObClient
*self
,
2687 gint x
, gint y
, gint w
, gint h
)
2689 /* save the states that we are going to apply */
2690 gboolean iconic
= self
->iconic
;
2691 gboolean fullscreen
= self
->fullscreen
;
2692 gboolean undecorated
= self
->undecorated
;
2693 gboolean shaded
= self
->shaded
;
2694 gboolean demands_attention
= self
->demands_attention
;
2695 gboolean max_horz
= self
->max_horz
;
2696 gboolean max_vert
= self
->max_vert
;
2700 /* turn them all off in the client, so they won't affect the window
2702 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2703 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2705 /* move the client to its placed position, or it it's already there,
2706 generate a ConfigureNotify telling the client where it is.
2708 do this after adjusting the frame. otherwise it gets all weird and
2709 clients don't work right
2711 do this before applying the states so they have the correct
2712 pre-max/pre-fullscreen values
2714 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2715 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2716 self
->window
, x
, y
, w
, h
);
2717 /* save the area, and make it where it should be for the premax stuff */
2718 oldarea
= self
->area
;
2719 RECT_SET(self
->area
, x
, y
, w
, h
);
2721 /* apply the states. these are in a carefully crafted order.. */
2724 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2726 client_fullscreen(self
, TRUE
);
2728 client_set_undecorated(self
, TRUE
);
2730 client_shade(self
, TRUE
);
2731 if (demands_attention
)
2732 client_hilite(self
, TRUE
);
2734 if (max_vert
&& max_horz
)
2735 client_maximize(self
, TRUE
, 0);
2737 client_maximize(self
, TRUE
, 2);
2739 client_maximize(self
, TRUE
, 1);
2741 /* if the window hasn't been configured yet, then do so now, in fact the
2742 x,y,w,h may _not_ be the same as the area rect, which can end up
2743 meaning that the client isn't properly moved/resized by the fullscreen
2745 pho can cause this because it maps at size of the screen but not 0,0
2746 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2747 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2748 cuz thats where the pre-fullscreen will be. however the actual area is
2749 not, so this needs to be called even if we have fullscreened/maxed
2751 self
->area
= oldarea
;
2752 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2754 /* set the desktop hint, to make sure that it always exists */
2755 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
2757 /* nothing to do for the other states:
2766 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2768 /* these should be the current values. this is for when you're not moving,
2770 g_assert(*x
== self
->area
.x
);
2771 g_assert(oldw
== self
->area
.width
);
2774 switch (self
->gravity
) {
2776 case NorthWestGravity
:
2778 case SouthWestGravity
:
2785 *x
-= (neww
- oldw
) / 2;
2787 case NorthEastGravity
:
2789 case SouthEastGravity
:
2795 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2797 /* these should be the current values. this is for when you're not moving,
2799 g_assert(*y
== self
->area
.y
);
2800 g_assert(oldh
== self
->area
.height
);
2803 switch (self
->gravity
) {
2805 case NorthWestGravity
:
2807 case NorthEastGravity
:
2814 *y
-= (newh
- oldh
) / 2;
2816 case SouthWestGravity
:
2818 case SouthEastGravity
:
2824 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2825 gint
*logicalw
, gint
*logicalh
,
2828 Rect desired
= {*x
, *y
, *w
, *h
};
2829 frame_rect_to_frame(self
->frame
, &desired
);
2831 /* make the frame recalculate its dimensions n shit without changing
2832 anything visible for real, this way the constraints below can work with
2833 the updated frame dimensions. */
2834 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2836 /* gets the frame's position */
2837 frame_client_gravity(self
->frame
, x
, y
);
2839 /* these positions are frame positions, not client positions */
2841 /* set the size and position if fullscreen */
2842 if (self
->fullscreen
) {
2846 i
= screen_find_monitor(&desired
);
2847 a
= screen_physical_area_monitor(i
);
2854 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2856 } else if (self
->max_horz
|| self
->max_vert
) {
2860 /* use all possible struts when maximizing to the full screen */
2861 i
= screen_find_monitor(&desired
);
2862 a
= screen_area(self
->desktop
, i
,
2863 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2865 /* set the size and position if maximized */
2866 if (self
->max_horz
) {
2868 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2870 if (self
->max_vert
) {
2872 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2875 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2878 g_slice_free(Rect
, a
);
2881 /* gets the client's position */
2882 frame_frame_gravity(self
->frame
, x
, y
);
2884 /* work within the preferred sizes given by the window, these may have
2885 changed rather than it's requested width and height, so always run
2886 through this code */
2888 gint basew
, baseh
, minw
, minh
;
2890 gfloat minratio
, maxratio
;
2892 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2893 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2894 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2895 0 : self
->min_ratio
;
2896 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2897 0 : self
->max_ratio
;
2899 /* base size is substituted with min size if not specified */
2900 if (self
->base_size
.width
>= 0 || self
->base_size
.height
>= 0) {
2901 basew
= self
->base_size
.width
;
2902 baseh
= self
->base_size
.height
;
2904 basew
= self
->min_size
.width
;
2905 baseh
= self
->min_size
.height
;
2907 /* min size is substituted with base size if not specified */
2908 if (self
->min_size
.width
|| self
->min_size
.height
) {
2909 minw
= self
->min_size
.width
;
2910 minh
= self
->min_size
.height
;
2912 minw
= self
->base_size
.width
;
2913 minh
= self
->base_size
.height
;
2916 /* This comment is no longer true */
2917 /* if this is a user-requested resize, then check against min/max
2920 /* smaller than min size or bigger than max size? */
2921 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2922 if (*w
< minw
) *w
= minw
;
2923 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2924 if (*h
< minh
) *h
= minh
;
2929 /* keep to the increments */
2933 /* you cannot resize to nothing */
2934 if (basew
+ *w
< 1) *w
= 1 - basew
;
2935 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2937 /* save the logical size */
2938 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2939 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2947 /* adjust the height to match the width for the aspect ratios.
2948 for this, min size is not substituted for base size ever. */
2949 *w
-= self
->base_size
.width
;
2950 *h
-= self
->base_size
.height
;
2953 if (*h
* minratio
> *w
) {
2954 *h
= (gint
)(*w
/ minratio
);
2956 /* you cannot resize to nothing */
2959 *w
= (gint
)(*h
* minratio
);
2963 if (*h
* maxratio
< *w
) {
2964 *h
= (gint
)(*w
/ maxratio
);
2966 /* you cannot resize to nothing */
2969 *w
= (gint
)(*h
* minratio
);
2973 *w
+= self
->base_size
.width
;
2974 *h
+= self
->base_size
.height
;
2977 /* these override the above states! if you cant move you can't move! */
2979 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2983 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2984 *w
= self
->area
.width
;
2985 *h
= self
->area
.height
;
2993 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2994 gboolean user
, gboolean final
, gboolean force_reply
)
2996 Rect oldframe
, oldclient
;
2997 gboolean send_resize_client
;
2998 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2999 gboolean fmoved
, fresized
;
3000 guint fdecor
= self
->frame
->decorations
;
3001 gboolean fhorz
= self
->frame
->max_horz
;
3002 gboolean fvert
= self
->frame
->max_vert
;
3003 gint logicalw
, logicalh
;
3005 /* find the new x, y, width, and height (and logical size) */
3006 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
3008 /* set the logical size if things changed */
3009 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
3010 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
3012 /* figure out if we moved or resized or what */
3013 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
3014 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
3016 oldframe
= self
->frame
->area
;
3017 oldclient
= self
->area
;
3018 RECT_SET(self
->area
, x
, y
, w
, h
);
3020 /* for app-requested resizes, always resize if 'resized' is true.
3021 for user-requested ones, only resize if final is true, or when
3022 resizing in redraw mode */
3023 send_resize_client
= ((!user
&& resized
) ||
3025 (resized
&& config_resize_redraw
))));
3027 /* if the client is enlarging, then resize the client before the frame */
3028 if (send_resize_client
&& (w
> oldclient
.width
|| h
> oldclient
.height
)) {
3029 XMoveResizeWindow(obt_display
, self
->window
,
3030 self
->frame
->size
.left
, self
->frame
->size
.top
,
3031 MAX(w
, oldclient
.width
), MAX(h
, oldclient
.height
));
3032 frame_adjust_client_area(self
->frame
);
3035 /* find the frame's dimensions and move/resize it */
3039 /* if decorations changed, then readjust everything for the frame */
3040 if (self
->decorations
!= fdecor
||
3041 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
3043 fmoved
= fresized
= TRUE
;
3046 /* adjust the frame */
3047 if (fmoved
|| fresized
) {
3048 gulong ignore_start
;
3050 ignore_start
= event_start_ignore_all_enters();
3052 /* replay pending pointer event before move the window, in case it
3053 would change what window gets the event */
3054 mouse_replay_pointer();
3056 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
3059 event_end_ignore_all_enters(ignore_start
);
3062 if (!user
|| final
) {
3063 gint oldrx
= self
->root_pos
.x
;
3064 gint oldry
= self
->root_pos
.y
;
3065 /* we have reset the client to 0 border width, so don't include
3066 it in these coords */
3067 POINT_SET(self
->root_pos
,
3068 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3070 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3071 self
->border_width
);
3072 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3076 /* This is kinda tricky and should not be changed.. let me explain!
3078 When user = FALSE, then the request is coming from the application
3079 itself, and we are more strict about when to send a synthetic
3080 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3081 in this case (if force_reply is true)
3083 When user = TRUE, then the request is coming from "us", like when we
3084 maximize a window or something. In this case we are more lenient. We
3085 used to follow the same rules as above, but _Java_ Swing can't handle
3086 this. So just to appease Swing, when user = TRUE, we always send
3087 a synthetic ConfigureNotify to give the window its root coordinates.
3089 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3090 (user
&& final
&& rootmoved
))
3094 event
.type
= ConfigureNotify
;
3095 event
.xconfigure
.display
= obt_display
;
3096 event
.xconfigure
.event
= self
->window
;
3097 event
.xconfigure
.window
= self
->window
;
3099 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3100 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3102 /* root window real coords */
3103 event
.xconfigure
.x
= self
->root_pos
.x
;
3104 event
.xconfigure
.y
= self
->root_pos
.y
;
3105 event
.xconfigure
.width
= w
;
3106 event
.xconfigure
.height
= h
;
3107 event
.xconfigure
.border_width
= self
->border_width
;
3108 event
.xconfigure
.above
= None
;
3109 event
.xconfigure
.override_redirect
= FALSE
;
3110 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3111 FALSE
, StructureNotifyMask
, &event
);
3114 /* if the client is shrinking, then resize the frame before the client.
3116 both of these resize sections may run, because the top one only resizes
3117 in the direction that is growing
3119 if (send_resize_client
&& (w
<= oldclient
.width
|| h
<= oldclient
.height
))
3121 frame_adjust_client_area(self
->frame
);
3122 XMoveResizeWindow(obt_display
, self
->window
,
3123 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3126 XFlush(obt_display
);
3128 /* if it moved between monitors, then this can affect the stacking
3129 layer of this window or others - for fullscreen windows.
3130 also if it changed to/from oldschool fullscreen then its layer may
3132 if (screen_find_monitor(&self
->frame
->area
) !=
3133 screen_find_monitor(&oldframe
) ||
3134 (final
&& (client_is_oldfullscreen(self
, &oldclient
) !=
3135 client_is_oldfullscreen(self
, &self
->area
))))
3137 client_calc_layer(self
);
3141 void client_fullscreen(ObClient
*self
, gboolean fs
)
3145 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3146 self
->fullscreen
== fs
) return; /* already done */
3148 self
->fullscreen
= fs
;
3149 client_change_state(self
); /* change the state hints on the client */
3152 self
->pre_fullscreen_area
= self
->area
;
3153 self
->pre_fullscreen_max_horz
= self
->max_horz
;
3154 self
->pre_fullscreen_max_vert
= self
->max_vert
;
3156 /* if the window is maximized, its area isn't all that meaningful.
3157 save its premax area instead. */
3158 if (self
->max_horz
) {
3159 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3160 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3162 if (self
->max_vert
) {
3163 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3164 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3167 /* these will help configure_full figure out where to fullscreen
3171 w
= self
->area
.width
;
3172 h
= self
->area
.height
;
3174 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3175 self
->pre_fullscreen_area
.height
> 0);
3177 self
->max_horz
= self
->pre_fullscreen_max_horz
;
3178 self
->max_vert
= self
->pre_fullscreen_max_vert
;
3179 if (self
->max_horz
) {
3180 self
->pre_max_area
.x
= self
->pre_fullscreen_area
.x
;
3181 self
->pre_max_area
.width
= self
->pre_fullscreen_area
.width
;
3183 if (self
->max_vert
) {
3184 self
->pre_max_area
.y
= self
->pre_fullscreen_area
.y
;
3185 self
->pre_max_area
.height
= self
->pre_fullscreen_area
.height
;
3188 x
= self
->pre_fullscreen_area
.x
;
3189 y
= self
->pre_fullscreen_area
.y
;
3190 w
= self
->pre_fullscreen_area
.width
;
3191 h
= self
->pre_fullscreen_area
.height
;
3192 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3195 ob_debug("Window %s going fullscreen (%d)",
3196 self
->title
, self
->fullscreen
);
3198 client_setup_decor_and_functions(self
, FALSE
);
3199 client_move_resize(self
, x
, y
, w
, h
);
3201 /* and adjust our layer/stacking. do this after resizing the window,
3202 and applying decorations, because windows which fill the screen are
3203 considered "fullscreen" and it affects their layer */
3204 client_calc_layer(self
);
3207 /* try focus us when we go into fullscreen mode */
3212 static void client_iconify_recursive(ObClient
*self
,
3213 gboolean iconic
, gboolean curdesk
,
3214 gboolean hide_animation
)
3217 gboolean changed
= FALSE
;
3219 if (self
->iconic
!= iconic
) {
3220 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3224 /* don't let non-normal windows iconify along with their parents
3226 if (client_normal(self
)) {
3227 self
->iconic
= iconic
;
3229 /* update the focus lists.. iconic windows go to the bottom of
3230 the list. this will also call focus_cycle_addremove(). */
3231 focus_order_to_bottom(self
);
3236 self
->iconic
= iconic
;
3238 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3239 self
->desktop
!= DESKTOP_ALL
)
3240 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3242 /* this puts it after the current focused window, this will
3243 also cause focus_cycle_addremove() to be called for the
3245 focus_order_like_new(self
);
3252 client_change_state(self
);
3253 if (config_animate_iconify
&& !hide_animation
)
3254 frame_begin_iconify_animation(self
->frame
, iconic
);
3255 /* do this after starting the animation so it doesn't flash */
3256 client_showhide(self
);
3259 /* iconify all direct transients, and deiconify all transients
3261 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3262 if (it
->data
!= self
)
3263 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3264 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3268 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3269 gboolean hide_animation
)
3271 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3272 /* move up the transient chain as far as possible first */
3273 self
= client_search_top_direct_parent(self
);
3274 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3278 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3282 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3283 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && max
) return;/* can't */
3285 /* check if already done */
3287 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3288 if (dir
== 1 && self
->max_horz
) return;
3289 if (dir
== 2 && self
->max_vert
) return;
3291 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3292 if (dir
== 1 && !self
->max_horz
) return;
3293 if (dir
== 2 && !self
->max_vert
) return;
3296 /* these will help configure_full figure out which screen to fill with
3300 w
= self
->area
.width
;
3301 h
= self
->area
.height
;
3304 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3305 RECT_SET(self
->pre_max_area
,
3306 self
->area
.x
, self
->pre_max_area
.y
,
3307 self
->area
.width
, self
->pre_max_area
.height
);
3309 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3310 RECT_SET(self
->pre_max_area
,
3311 self
->pre_max_area
.x
, self
->area
.y
,
3312 self
->pre_max_area
.width
, self
->area
.height
);
3315 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3316 g_assert(self
->pre_max_area
.width
> 0);
3318 x
= self
->pre_max_area
.x
;
3319 w
= self
->pre_max_area
.width
;
3321 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3322 0, self
->pre_max_area
.height
);
3324 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3325 g_assert(self
->pre_max_area
.height
> 0);
3327 y
= self
->pre_max_area
.y
;
3328 h
= self
->pre_max_area
.height
;
3330 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3331 self
->pre_max_area
.width
, 0);
3335 if (dir
== 0 || dir
== 1) /* horz */
3336 self
->max_horz
= max
;
3337 if (dir
== 0 || dir
== 2) /* vert */
3338 self
->max_vert
= max
;
3340 client_change_state(self
); /* change the state hints on the client */
3342 client_setup_decor_and_functions(self
, FALSE
);
3343 client_move_resize(self
, x
, y
, w
, h
);
3346 void client_shade(ObClient
*self
, gboolean shade
)
3348 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3349 shade
) || /* can't shade */
3350 self
->shaded
== shade
) return; /* already done */
3352 self
->shaded
= shade
;
3353 client_change_state(self
);
3354 client_change_wm_state(self
); /* the window is being hidden/shown */
3355 /* resize the frame to just the titlebar */
3356 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3359 static void client_ping_event(ObClient
*self
, gboolean dead
)
3361 if (self
->not_responding
!= dead
) {
3362 self
->not_responding
= dead
;
3363 client_update_title(self
);
3366 /* the client isn't responding, so ask to kill it */
3367 client_prompt_kill(self
);
3369 /* it came back to life ! */
3371 if (self
->kill_prompt
) {
3372 prompt_unref(self
->kill_prompt
);
3373 self
->kill_prompt
= NULL
;
3376 self
->kill_level
= 0;
3381 void client_close(ObClient
*self
)
3383 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3385 /* if closing an internal obprompt, that is just cancelling it */
3387 prompt_cancel(self
->prompt
);
3391 /* in the case that the client provides no means to requesting that it
3392 close, we just kill it */
3393 if (!self
->delete_window
)
3394 /* don't use client_kill(), we should only kill based on PID in
3395 response to a lack of PING replies */
3396 XKillClient(obt_display
, self
->window
);
3398 /* request the client to close with WM_DELETE_WINDOW */
3399 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3400 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_time(),
3401 0, 0, 0, NoEventMask
);
3403 /* we're trying to close the window, so see if it is responding. if it
3404 is not, then we will let them kill the window */
3406 ping_start(self
, client_ping_event
);
3408 /* if we already know the window isn't responding (maybe they clicked
3409 no in the kill dialog but it hasn't come back to life), then show
3411 if (self
->not_responding
)
3412 client_prompt_kill(self
);
3416 #define OB_KILL_RESULT_NO 0
3417 #define OB_KILL_RESULT_YES 1
3419 static gboolean
client_kill_requested(ObPrompt
*p
, gint result
, gpointer data
)
3421 ObClient
*self
= data
;
3423 if (result
== OB_KILL_RESULT_YES
)
3425 return TRUE
; /* call the cleanup func */
3428 static void client_kill_cleanup(ObPrompt
*p
, gpointer data
)
3430 ObClient
*self
= data
;
3432 g_assert(p
== self
->kill_prompt
);
3434 prompt_unref(self
->kill_prompt
);
3435 self
->kill_prompt
= NULL
;
3438 static void client_prompt_kill(ObClient
*self
)
3440 /* check if we're already prompting */
3441 if (!self
->kill_prompt
) {
3442 ObPromptAnswer answers
[] = {
3443 { 0, OB_KILL_RESULT_NO
},
3444 { 0, OB_KILL_RESULT_YES
}
3447 const gchar
*y
, *title
;
3449 title
= self
->original_title
;
3450 if (title
[0] == '\0') {
3451 /* empty string, so use its parent */
3452 ObClient
*p
= client_search_top_direct_parent(self
);
3453 if (p
) title
= p
->original_title
;
3456 if (client_on_localhost(self
)) {
3459 if (self
->kill_level
== 0)
3465 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3467 y
= _("End Process");
3471 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3473 y
= _("Disconnect");
3475 /* set the dialog buttons' text */
3476 answers
[0].text
= _("Cancel"); /* "no" */
3477 answers
[1].text
= y
; /* "yes" */
3479 self
->kill_prompt
= prompt_new(m
, NULL
, answers
,
3480 sizeof(answers
)/sizeof(answers
[0]),
3481 OB_KILL_RESULT_NO
, /* default = no */
3482 OB_KILL_RESULT_NO
, /* cancel = no */
3483 client_kill_requested
,
3484 client_kill_cleanup
,
3489 prompt_show(self
->kill_prompt
, self
, TRUE
);
3492 void client_kill(ObClient
*self
)
3494 /* don't kill our own windows */
3495 if (self
->prompt
) return;
3497 if (client_on_localhost(self
) && self
->pid
) {
3498 /* running on the local host */
3499 if (self
->kill_level
== 0) {
3500 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3501 self
->window
, self
->pid
);
3502 kill(self
->pid
, SIGTERM
);
3505 /* show that we're trying to kill it */
3506 client_update_title(self
);
3509 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3510 self
->window
, self
->pid
);
3511 kill(self
->pid
, SIGKILL
); /* kill -9 */
3515 /* running on a remote host */
3516 XKillClient(obt_display
, self
->window
);
3520 void client_hilite(ObClient
*self
, gboolean hilite
)
3522 if (self
->demands_attention
== hilite
)
3523 return; /* no change */
3525 /* don't allow focused windows to hilite */
3526 self
->demands_attention
= hilite
&& !client_focused(self
);
3527 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3528 if (self
->demands_attention
) {
3529 frame_flash_start(self
->frame
);
3531 /* if the window is on another desktop then raise it and make it
3532 the most recently used window */
3533 if (self
->desktop
!= screen_desktop
&&
3534 self
->desktop
!= DESKTOP_ALL
)
3536 stacking_raise(CLIENT_AS_WINDOW(self
));
3537 focus_order_to_top(self
);
3541 frame_flash_stop(self
->frame
);
3542 client_change_state(self
);
3546 static void client_set_desktop_recursive(ObClient
*self
,
3554 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3556 ob_debug("Setting desktop %u", target
+1);
3558 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3560 old
= self
->desktop
;
3561 self
->desktop
= target
;
3562 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3563 /* the frame can display the current desktop state */
3564 frame_adjust_state(self
->frame
);
3565 /* 'move' the window to the new desktop */
3569 /* raise if it was not already on the desktop */
3570 if (old
!= DESKTOP_ALL
&& !dontraise
)
3571 stacking_raise(CLIENT_AS_WINDOW(self
));
3572 if (STRUT_EXISTS(self
->strut
))
3573 screen_update_areas();
3575 /* the new desktop's geometry may be different, so we may need to
3576 resize, for example if we are maximized */
3577 client_reconfigure(self
, FALSE
);
3579 focus_cycle_addremove(self
, FALSE
);
3582 /* move all transients */
3583 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3584 if (it
->data
!= self
)
3585 if (client_is_direct_child(self
, it
->data
))
3586 client_set_desktop_recursive(it
->data
, target
,
3587 donthide
, dontraise
);
3590 void client_set_desktop(ObClient
*self
, guint target
,
3591 gboolean donthide
, gboolean dontraise
)
3593 self
= client_search_top_direct_parent(self
);
3594 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3596 focus_cycle_addremove(NULL
, TRUE
);
3599 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3601 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3602 return child
== parent
;
3605 ObClient
*client_search_modal_child(ObClient
*self
)
3610 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3611 ObClient
*c
= it
->data
;
3612 if ((ret
= client_search_modal_child(c
))) return ret
;
3613 if (c
->modal
) return c
;
3618 static gboolean
client_validate_unmap(ObClient
*self
, int n
)
3621 gboolean ret
= TRUE
;
3623 if (XCheckTypedWindowEvent(obt_display
, self
->window
, UnmapNotify
, &e
)) {
3624 if (n
< self
->ignore_unmaps
) // ignore this one, but look for more
3625 ret
= client_validate_unmap(self
, n
+1);
3627 ret
= FALSE
; // the window is going to become unmanaged
3629 /* put them back on the event stack so they end up in the same order */
3630 XPutBackEvent(obt_display
, &e
);
3636 gboolean
client_validate(ObClient
*self
)
3640 XSync(obt_display
, FALSE
); /* get all events on the server */
3642 if (XCheckTypedWindowEvent(obt_display
, self
->window
, DestroyNotify
, &e
)) {
3643 XPutBackEvent(obt_display
, &e
);
3647 if (!client_validate_unmap(self
, 0))
3653 void client_set_wm_state(ObClient
*self
, glong state
)
3655 if (state
== self
->wmstate
) return; /* no change */
3659 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3662 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3667 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3669 gboolean shaded
= self
->shaded
;
3670 gboolean fullscreen
= self
->fullscreen
;
3671 gboolean undecorated
= self
->undecorated
;
3672 gboolean max_horz
= self
->max_horz
;
3673 gboolean max_vert
= self
->max_vert
;
3674 gboolean modal
= self
->modal
;
3675 gboolean iconic
= self
->iconic
;
3676 gboolean demands_attention
= self
->demands_attention
;
3677 gboolean above
= self
->above
;
3678 gboolean below
= self
->below
;
3682 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3683 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3684 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3685 /* an invalid action was passed to the client message, ignore it */
3688 for (i
= 0; i
< 2; ++i
) {
3689 Atom state
= i
== 0 ? data1
: data2
;
3691 if (!state
) continue;
3693 /* if toggling, then pick whether we're adding or removing */
3694 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3695 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3697 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3698 value
= self
->max_vert
;
3699 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3700 value
= self
->max_horz
;
3701 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3703 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3704 value
= self
->skip_taskbar
;
3705 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3706 value
= self
->skip_pager
;
3707 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3708 value
= self
->iconic
;
3709 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3711 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3712 value
= self
->above
;
3713 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3714 value
= self
->below
;
3715 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3716 value
= self
->demands_attention
;
3717 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3718 value
= undecorated
;
3720 g_assert_not_reached();
3721 action
= value
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3722 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3725 value
= action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3726 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3728 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3730 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3732 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3734 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3735 self
->skip_taskbar
= value
;
3736 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3737 self
->skip_pager
= value
;
3738 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3740 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3742 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3744 /* only unset below when setting above, otherwise you can't get to
3748 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3749 /* and vice versa */
3753 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3754 demands_attention
= value
;
3755 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3756 undecorated
= value
;
3760 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3761 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3763 if (max_horz
== max_vert
) { /* both going the same way */
3764 client_maximize(self
, max_horz
, 0);
3766 client_maximize(self
, max_horz
, 1);
3767 client_maximize(self
, max_vert
, 2);
3771 if (max_horz
!= self
->max_horz
)
3772 client_maximize(self
, max_horz
, 1);
3774 client_maximize(self
, max_vert
, 2);
3777 /* change fullscreen state before shading, as it will affect if the window
3779 if (fullscreen
!= self
->fullscreen
)
3780 client_fullscreen(self
, fullscreen
);
3781 if (shaded
!= self
->shaded
)
3782 client_shade(self
, shaded
);
3783 if (undecorated
!= self
->undecorated
)
3784 client_set_undecorated(self
, undecorated
);
3785 if (above
!= self
->above
|| below
!= self
->below
) {
3786 self
->above
= above
;
3787 self
->below
= below
;
3788 client_calc_layer(self
);
3791 if (modal
!= self
->modal
) {
3792 self
->modal
= modal
;
3793 /* when a window changes modality, then its stacking order with its
3794 transients needs to change */
3795 stacking_raise(CLIENT_AS_WINDOW(self
));
3797 /* it also may get focused. if something is focused that shouldn't
3798 be focused anymore, then move the focus */
3799 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3800 client_focus(focus_client
);
3803 if (iconic
!= self
->iconic
)
3804 client_iconify(self
, iconic
, FALSE
, FALSE
);
3806 if (demands_attention
!= self
->demands_attention
)
3807 client_hilite(self
, demands_attention
);
3809 client_change_state(self
); /* change the hint to reflect these changes */
3811 focus_cycle_addremove(self
, TRUE
);
3814 ObClient
*client_focus_target(ObClient
*self
)
3816 ObClient
*child
= NULL
;
3818 child
= client_search_modal_child(self
);
3819 if (child
) return child
;
3823 gboolean
client_can_focus(ObClient
*self
)
3825 /* choose the correct target */
3826 self
= client_focus_target(self
);
3828 if (!self
->frame
->visible
)
3831 if (!(self
->can_focus
|| self
->focus_notify
))
3837 gboolean
client_focus(ObClient
*self
)
3839 /* we might not focus this window, so if we have modal children which would
3840 be focused instead, bring them to this desktop */
3841 client_bring_modal_windows(self
);
3843 /* choose the correct target */
3844 self
= client_focus_target(self
);
3846 if (!client_can_focus(self
)) {
3847 ob_debug_type(OB_DEBUG_FOCUS
,
3848 "Client %s can't be focused", self
->title
);
3852 ob_debug_type(OB_DEBUG_FOCUS
,
3853 "Focusing client \"%s\" (0x%x) at time %u",
3854 self
->title
, self
->window
, event_time());
3856 /* if using focus_delay, stop the timer now so that focus doesn't
3858 event_halt_focus_delay();
3860 obt_display_ignore_errors(TRUE
);
3862 if (self
->can_focus
) {
3863 /* This can cause a BadMatch error with CurrentTime, or if an app
3864 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3865 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3869 if (self
->focus_notify
) {
3871 ce
.xclient
.type
= ClientMessage
;
3872 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3873 ce
.xclient
.display
= obt_display
;
3874 ce
.xclient
.window
= self
->window
;
3875 ce
.xclient
.format
= 32;
3876 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
3877 ce
.xclient
.data
.l
[1] = event_time();
3878 ce
.xclient
.data
.l
[2] = 0l;
3879 ce
.xclient
.data
.l
[3] = 0l;
3880 ce
.xclient
.data
.l
[4] = 0l;
3881 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3884 obt_display_ignore_errors(FALSE
);
3886 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
3887 obt_display_error_occured
);
3888 return !obt_display_error_occured
;
3891 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3894 if (client_normal(self
) && screen_showing_desktop
)
3895 screen_show_desktop(FALSE
, self
);
3897 client_iconify(self
, FALSE
, here
, FALSE
);
3898 if (self
->desktop
!= DESKTOP_ALL
&&
3899 self
->desktop
!= screen_desktop
)
3902 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3904 screen_set_desktop(self
->desktop
, FALSE
);
3905 } else if (!self
->frame
->visible
)
3906 /* if its not visible for other reasons, then don't mess
3909 if (self
->shaded
&& unshade
)
3910 client_shade(self
, FALSE
);
3912 stacking_raise(CLIENT_AS_WINDOW(self
));
3917 /* this function exists to map to the net_active_window message in the ewmh */
3918 void client_activate(ObClient
*self
, gboolean desktop
,
3919 gboolean here
, gboolean raise
,
3920 gboolean unshade
, gboolean user
)
3922 if ((user
&& (desktop
||
3923 self
->desktop
== DESKTOP_ALL
||
3924 self
->desktop
== screen_desktop
)) ||
3925 client_can_steal_focus(self
, event_time(), CurrentTime
))
3927 client_present(self
, here
, raise
, unshade
);
3930 client_hilite(self
, TRUE
);
3933 static void client_bring_windows_recursive(ObClient
*self
,
3941 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3942 client_bring_windows_recursive(it
->data
, desktop
,
3943 helpers
, modals
, iconic
);
3945 if (((helpers
&& client_helper(self
)) ||
3946 (modals
&& self
->modal
)) &&
3947 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3948 (iconic
&& self
->iconic
)))
3950 if (iconic
&& self
->iconic
)
3951 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3953 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3957 void client_bring_helper_windows(ObClient
*self
)
3959 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3962 void client_bring_modal_windows(ObClient
*self
)
3964 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3967 gboolean
client_focused(ObClient
*self
)
3969 return self
== focus_client
;
3972 RrImage
* client_icon(ObClient
*self
)
3974 RrImage
*ret
= NULL
;
3977 ret
= self
->icon_set
;
3978 else if (self
->parents
) {
3980 for (it
= self
->parents
; it
&& !ret
; it
= g_slist_next(it
))
3981 ret
= client_icon(it
->data
);
3984 ret
= client_default_icon
;
3988 void client_set_layer(ObClient
*self
, gint layer
)
3992 self
->above
= FALSE
;
3993 } else if (layer
== 0) {
3994 self
->below
= self
->above
= FALSE
;
3996 self
->below
= FALSE
;
3999 client_calc_layer(self
);
4000 client_change_state(self
); /* reflect this in the state hints */
4003 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
4005 if (self
->undecorated
!= undecorated
&&
4006 /* don't let it undecorate if the function is missing, but let
4008 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
4010 self
->undecorated
= undecorated
;
4011 client_setup_decor_and_functions(self
, TRUE
);
4012 client_change_state(self
); /* reflect this in the state hints */
4016 guint
client_monitor(ObClient
*self
)
4018 return screen_find_monitor(&self
->frame
->area
);
4021 ObClient
*client_direct_parent(ObClient
*self
)
4023 if (!self
->parents
) return NULL
;
4024 if (self
->transient_for_group
) return NULL
;
4025 return self
->parents
->data
;
4028 ObClient
*client_search_top_direct_parent(ObClient
*self
)
4031 while ((p
= client_direct_parent(self
))) self
= p
;
4035 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
4037 ObStackingLayer layer
)
4042 /* move up the direct transient chain as far as possible */
4043 while ((p
= client_direct_parent(self
)) &&
4044 (!bylayer
|| p
->layer
== layer
))
4048 ret
= g_slist_prepend(NULL
, self
);
4050 ret
= g_slist_copy(self
->parents
);
4055 GSList
*client_search_all_top_parents(ObClient
*self
)
4057 return client_search_all_top_parents_internal(self
, FALSE
, 0);
4060 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
4062 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
4065 ObClient
*client_search_focus_parent(ObClient
*self
)
4069 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4070 if (client_focused(it
->data
)) return it
->data
;
4075 ObClient
*client_search_focus_parent_full(ObClient
*self
)
4078 ObClient
*ret
= NULL
;
4080 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
4081 if (client_focused(it
->data
))
4084 ret
= client_search_focus_parent_full(it
->data
);
4090 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
4094 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4095 if (it
->data
== search
) return search
;
4100 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
4104 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
4105 if (sit
->data
== search
)
4107 if (client_search_transient(sit
->data
, search
))
4113 static void detect_edge(Rect area
, ObDirection dir
,
4114 gint my_head
, gint my_size
,
4115 gint my_edge_start
, gint my_edge_size
,
4116 gint
*dest
, gboolean
*near_edge
)
4118 gint edge_start
, edge_size
, head
, tail
;
4119 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
4122 case OB_DIRECTION_NORTH
:
4123 case OB_DIRECTION_SOUTH
:
4124 edge_start
= area
.x
;
4125 edge_size
= area
.width
;
4127 case OB_DIRECTION_EAST
:
4128 case OB_DIRECTION_WEST
:
4129 edge_start
= area
.y
;
4130 edge_size
= area
.height
;
4133 g_assert_not_reached();
4136 /* do we collide with this window? */
4137 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4138 edge_start
, edge_size
))
4142 case OB_DIRECTION_NORTH
:
4143 head
= RECT_BOTTOM(area
);
4144 tail
= RECT_TOP(area
);
4146 case OB_DIRECTION_SOUTH
:
4147 head
= RECT_TOP(area
);
4148 tail
= RECT_BOTTOM(area
);
4150 case OB_DIRECTION_WEST
:
4151 head
= RECT_RIGHT(area
);
4152 tail
= RECT_LEFT(area
);
4154 case OB_DIRECTION_EAST
:
4155 head
= RECT_LEFT(area
);
4156 tail
= RECT_RIGHT(area
);
4159 g_assert_not_reached();
4162 case OB_DIRECTION_NORTH
:
4163 case OB_DIRECTION_WEST
:
4164 /* check if our window is past the head of this window */
4165 if (my_head
<= head
+ 1)
4167 /* check if our window's tail is past the tail of this window */
4168 if (my_head
+ my_size
- 1 <= tail
)
4170 /* check if the head of this window is closer than the previously
4171 chosen edge (take into account that the previously chosen
4172 edge might have been a tail, not a head) */
4173 if (head
+ (*near_edge
? 0 : my_size
) <= *dest
)
4175 /* check if the tail of this window is closer than the previously
4176 chosen edge (take into account that the previously chosen
4177 edge might have been a head, not a tail) */
4178 if (tail
- (!*near_edge
? 0 : my_size
) <= *dest
)
4181 case OB_DIRECTION_SOUTH
:
4182 case OB_DIRECTION_EAST
:
4183 /* check if our window is past the head of this window */
4184 if (my_head
>= head
- 1)
4186 /* check if our window's tail is past the tail of this window */
4187 if (my_head
- my_size
+ 1 >= tail
)
4189 /* check if the head of this window is closer than the previously
4190 chosen edge (take into account that the previously chosen
4191 edge might have been a tail, not a head) */
4192 if (head
- (*near_edge
? 0 : my_size
) >= *dest
)
4194 /* check if the tail of this window is closer than the previously
4195 chosen edge (take into account that the previously chosen
4196 edge might have been a head, not a tail) */
4197 if (tail
+ (!*near_edge
? 0 : my_size
) >= *dest
)
4201 g_assert_not_reached();
4204 ob_debug("my head %d size %d", my_head
, my_size
);
4205 ob_debug("head %d tail %d dest %d", head
, tail
, *dest
);
4207 ob_debug("using near edge %d", head
);
4211 else if (!skip_tail
) {
4212 ob_debug("using far edge %d", tail
);
4218 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4219 gint my_head
, gint my_size
,
4220 gint my_edge_start
, gint my_edge_size
,
4221 gint
*dest
, gboolean
*near_edge
)
4229 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4230 &self
->frame
->area
);
4233 case OB_DIRECTION_NORTH
:
4234 edge
= RECT_TOP(*a
) - 1;
4236 case OB_DIRECTION_SOUTH
:
4237 edge
= RECT_BOTTOM(*a
) + 1;
4239 case OB_DIRECTION_EAST
:
4240 edge
= RECT_RIGHT(*a
) + 1;
4242 case OB_DIRECTION_WEST
:
4243 edge
= RECT_LEFT(*a
) - 1;
4246 g_assert_not_reached();
4248 /* default to the far edge, then narrow it down */
4252 /* search for edges of monitors */
4253 for (i
= 0; i
< screen_num_monitors
; ++i
) {
4254 Rect
*area
= screen_area(self
->desktop
, i
, NULL
);
4255 detect_edge(*area
, dir
, my_head
, my_size
, my_edge_start
,
4256 my_edge_size
, dest
, near_edge
);
4257 g_slice_free(Rect
, area
);
4260 /* search for edges of clients */
4261 if (((dir
== OB_DIRECTION_NORTH
|| dir
== OB_DIRECTION_SOUTH
) &&
4263 ((dir
== OB_DIRECTION_EAST
|| dir
== OB_DIRECTION_WEST
) &&
4266 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4267 ObClient
*cur
= it
->data
;
4269 /* skip windows to not bump into */
4274 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4275 cur
->desktop
!= screen_desktop
)
4278 ob_debug("trying window %s", cur
->title
);
4280 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4281 my_edge_size
, dest
, near_edge
);
4283 dock_get_area(&dock_area
);
4284 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4285 my_edge_size
, dest
, near_edge
);
4288 g_slice_free(Rect
, a
);
4291 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4295 gint e
, e_start
, e_size
;
4299 case OB_DIRECTION_EAST
:
4300 head
= RECT_RIGHT(self
->frame
->area
);
4301 size
= self
->frame
->area
.width
;
4302 e_start
= RECT_TOP(self
->frame
->area
);
4303 e_size
= self
->frame
->area
.height
;
4305 case OB_DIRECTION_WEST
:
4306 head
= RECT_LEFT(self
->frame
->area
);
4307 size
= self
->frame
->area
.width
;
4308 e_start
= RECT_TOP(self
->frame
->area
);
4309 e_size
= self
->frame
->area
.height
;
4311 case OB_DIRECTION_NORTH
:
4312 head
= RECT_TOP(self
->frame
->area
);
4313 size
= self
->frame
->area
.height
;
4314 e_start
= RECT_LEFT(self
->frame
->area
);
4315 e_size
= self
->frame
->area
.width
;
4317 case OB_DIRECTION_SOUTH
:
4318 head
= RECT_BOTTOM(self
->frame
->area
);
4319 size
= self
->frame
->area
.height
;
4320 e_start
= RECT_LEFT(self
->frame
->area
);
4321 e_size
= self
->frame
->area
.width
;
4324 g_assert_not_reached();
4327 client_find_edge_directional(self
, dir
, head
, size
,
4328 e_start
, e_size
, &e
, &near
);
4329 *x
= self
->frame
->area
.x
;
4330 *y
= self
->frame
->area
.y
;
4332 case OB_DIRECTION_EAST
:
4333 if (near
) e
-= self
->frame
->area
.width
;
4337 case OB_DIRECTION_WEST
:
4339 else e
-= self
->frame
->area
.width
;
4342 case OB_DIRECTION_NORTH
:
4344 else e
-= self
->frame
->area
.height
;
4347 case OB_DIRECTION_SOUTH
:
4348 if (near
) e
-= self
->frame
->area
.height
;
4353 g_assert_not_reached();
4355 frame_frame_gravity(self
->frame
, x
, y
);
4358 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4360 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4363 gint e
, e_start
, e_size
, delta
;
4368 case OB_DIRECTION_EAST
:
4369 head
= RECT_RIGHT(self
->frame
->area
) +
4370 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4371 e_start
= RECT_TOP(self
->frame
->area
);
4372 e_size
= self
->frame
->area
.height
;
4373 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4375 case OB_DIRECTION_WEST
:
4376 head
= RECT_LEFT(self
->frame
->area
) -
4377 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4378 e_start
= RECT_TOP(self
->frame
->area
);
4379 e_size
= self
->frame
->area
.height
;
4380 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4382 case OB_DIRECTION_NORTH
:
4383 head
= RECT_TOP(self
->frame
->area
) -
4384 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4385 e_start
= RECT_LEFT(self
->frame
->area
);
4386 e_size
= self
->frame
->area
.width
;
4387 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4389 case OB_DIRECTION_SOUTH
:
4390 head
= RECT_BOTTOM(self
->frame
->area
) +
4391 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4392 e_start
= RECT_LEFT(self
->frame
->area
);
4393 e_size
= self
->frame
->area
.width
;
4394 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4397 g_assert_not_reached();
4400 ob_debug("head %d dir %d", head
, dir
);
4401 client_find_edge_directional(self
, dir
, head
, 1,
4402 e_start
, e_size
, &e
, &near
);
4403 ob_debug("edge %d", e
);
4404 *x
= self
->frame
->area
.x
;
4405 *y
= self
->frame
->area
.y
;
4406 *w
= self
->frame
->area
.width
;
4407 *h
= self
->frame
->area
.height
;
4409 case OB_DIRECTION_EAST
:
4410 if (grow
== near
) --e
;
4411 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4414 case OB_DIRECTION_WEST
:
4415 if (grow
== near
) ++e
;
4416 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4420 case OB_DIRECTION_NORTH
:
4421 if (grow
== near
) ++e
;
4422 delta
= RECT_TOP(self
->frame
->area
) - e
;
4426 case OB_DIRECTION_SOUTH
:
4427 if (grow
== near
) --e
;
4428 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4432 g_assert_not_reached();
4434 frame_frame_gravity(self
->frame
, x
, y
);
4435 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4436 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4439 ObClient
* client_under_pointer(void)
4443 ObClient
*ret
= NULL
;
4445 if (screen_pointer_pos(&x
, &y
)) {
4446 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4447 if (WINDOW_IS_CLIENT(it
->data
)) {
4448 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4449 if (c
->frame
->visible
&&
4450 /* check the desktop, this is done during desktop
4451 switching and windows are shown/hidden status is not
4453 (c
->desktop
== screen_desktop
||
4454 c
->desktop
== DESKTOP_ALL
) &&
4455 /* ignore all animating windows */
4456 !frame_iconify_animating(c
->frame
) &&
4457 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4468 gboolean
client_has_group_siblings(ObClient
*self
)
4470 return self
->group
&& self
->group
->members
->next
;
4473 /*! Returns TRUE if the client is running on the same machine as Openbox */
4474 gboolean
client_on_localhost(ObClient
*self
)
4476 return self
->client_machine
== NULL
;