]>
Dogcows Code - chaz/openbox/blob - openbox/focus.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 focus.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.
26 #include "focus_cycle.h"
36 #define FOCUS_INDICATOR_WIDTH 6
38 ObClient
*focus_client
= NULL
;
39 GList
*focus_order
= NULL
;
41 void focus_startup(gboolean reconfig
)
45 /* start with nothing focused */
49 void focus_shutdown(gboolean reconfig
)
53 /* reset focus to root */
54 XSetInputFocus(ob_display
, PointerRoot
, RevertToNone
, CurrentTime
);
57 static void push_to_top(ObClient
*client
)
59 focus_order
= g_list_remove(focus_order
, client
);
60 focus_order
= g_list_prepend(focus_order
, client
);
63 void focus_set_client(ObClient
*client
)
67 ob_debug_type(OB_DEBUG_FOCUS
,
68 "focus_set_client 0x%lx\n", client
? client
->window
: 0);
70 if (focus_client
== client
)
73 /* uninstall the old colormap, and install the new one */
74 screen_install_colormap(focus_client
, FALSE
);
75 screen_install_colormap(client
, TRUE
);
77 /* in the middle of cycling..? kill it. */
78 focus_cycle_stop(focus_client
);
79 focus_cycle_stop(client
);
81 focus_client
= client
;
84 /* move to the top of the list */
86 /* remove hiliting from the window when it gets focused */
87 client_hilite(client
, FALSE
);
90 /* set the NET_ACTIVE_WINDOW hint, but preserve it on shutdown */
91 if (ob_state() != OB_STATE_EXITING
) {
92 active
= client
? client
->window
: None
;
93 PROP_SET32(RootWindow(ob_display
, ob_screen
),
94 net_active_window
, window
, active
);
98 static ObClient
* focus_fallback_target(gboolean allow_refocus
, ObClient
*old
)
103 ob_debug_type(OB_DEBUG_FOCUS
, "trying pointer stuff\n");
104 if (config_focus_follow
&& !config_focus_last
)
105 if ((c
= client_under_pointer()) &&
106 (allow_refocus
|| c
!= old
) &&
110 ob_debug_type(OB_DEBUG_FOCUS
, "found in pointer stuff\n");
114 ob_debug_type(OB_DEBUG_FOCUS
, "trying the focus order\n");
115 for (it
= focus_order
; it
; it
= g_list_next(it
)) {
117 /* fallback focus to a window if:
118 1. it is on the current desktop. this ignores omnipresent
119 windows, which are problematic in their own rite.
120 2. it is a normal type window, don't fall back onto a dock or
121 a splashscreen or a desktop window (save the desktop as a
122 backup fallback though)
124 if (c
->desktop
== screen_desktop
&&
126 (allow_refocus
|| c
!= old
) &&
129 ob_debug_type(OB_DEBUG_FOCUS
, "found in focus order\n");
134 ob_debug_type(OB_DEBUG_FOCUS
, "trying a desktop window\n");
135 for (it
= focus_order
; it
; it
= g_list_next(it
)) {
137 /* fallback focus to a window if:
138 1. it is on the current desktop. this ignores omnipresent
139 windows, which are problematic in their own rite.
140 2. it is a normal type window, don't fall back onto a dock or
141 a splashscreen or a desktop window (save the desktop as a
142 backup fallback though)
144 if (c
->type
== OB_CLIENT_TYPE_DESKTOP
&&
145 (allow_refocus
|| c
!= old
) &&
148 ob_debug_type(OB_DEBUG_FOCUS
, "found a desktop window\n");
156 ObClient
* focus_fallback(gboolean allow_refocus
)
159 ObClient
*old
= focus_client
;
161 /* unfocus any focused clients.. they can be focused by Pointer events
162 and such, and then when we try focus them, we won't get a FocusIn
163 event at all for them. */
166 new = focus_fallback_target(allow_refocus
, old
);
173 /* Install our own colormap */
174 if (focus_client
!= NULL
) {
175 screen_install_colormap(focus_client
, FALSE
);
176 screen_install_colormap(NULL
, TRUE
);
179 /* nothing is focused, update the colormap and _the root property_ */
180 focus_set_client(NULL
);
182 /* if there is a grab going on, then we need to cancel it. if we move
183 focus during the grab, applications will get NotifyWhileGrabbed events
186 actions should not rely on being able to move focus during an
189 if (keyboard_interactively_grabbed())
190 keyboard_interactive_cancel();
192 /* when nothing will be focused, send focus to the backup target */
193 XSetInputFocus(ob_display
, screen_support_win
, RevertToPointerRoot
,
197 void focus_order_add_new(ObClient
*c
)
200 focus_order_to_top(c
);
202 g_assert(!g_list_find(focus_order
, c
));
203 /* if there are any iconic windows, put this above them in the order,
204 but if there are not, then put it under the currently focused one */
205 if (focus_order
&& ((ObClient
*)focus_order
->data
)->iconic
)
206 focus_order
= g_list_insert(focus_order
, c
, 0);
208 focus_order
= g_list_insert(focus_order
, c
, 1);
211 /* in the middle of cycling..? kill it. */
215 void focus_order_remove(ObClient
*c
)
217 focus_order
= g_list_remove(focus_order
, c
);
219 /* in the middle of cycling..? kill it. */
223 void focus_order_to_top(ObClient
*c
)
225 focus_order
= g_list_remove(focus_order
, c
);
227 focus_order
= g_list_prepend(focus_order
, c
);
231 /* insert before first iconic window */
232 for (it
= focus_order
;
233 it
&& !((ObClient
*)it
->data
)->iconic
; it
= g_list_next(it
));
234 focus_order
= g_list_insert_before(focus_order
, it
, c
);
238 void focus_order_to_bottom(ObClient
*c
)
240 focus_order
= g_list_remove(focus_order
, c
);
242 focus_order
= g_list_append(focus_order
, c
);
246 /* insert before first iconic window */
247 for (it
= focus_order
;
248 it
&& !((ObClient
*)it
->data
)->iconic
; it
= g_list_next(it
));
249 focus_order
= g_list_insert_before(focus_order
, it
, c
);
253 ObClient
*focus_order_find_first(guint desktop
)
256 for (it
= focus_order
; it
; it
= g_list_next(it
)) {
257 ObClient
*c
= it
->data
;
258 if (c
->desktop
== desktop
|| c
->desktop
== DESKTOP_ALL
)
This page took 0.042696 seconds and 4 git commands to generate.