16 Client
*focus_client
= NULL
;
17 GList
**focus_order
= NULL
; /* these lists are created when screen_startup
18 sets the number of desktops */
20 Window focus_backup
= None
;
21 gboolean focus_new
= TRUE
;
22 gboolean focus_follow
= FALSE
;
23 static gboolean focus_last
= TRUE
;
24 static gboolean focus_last_on_desktop
= TRUE
;
26 static gboolean noreorder
= 0;
28 static void parse_assign(char *name
, ParseToken
*value
)
30 if (!g_ascii_strcasecmp(name
, "focusnew")) {
31 if (value
->type
!= TOKEN_BOOL
)
32 yyerror("invalid value");
34 focus_new
= value
->data
.bool;
36 } else if (!g_ascii_strcasecmp(name
, "followmouse")) {
37 if (value
->type
!= TOKEN_BOOL
)
38 yyerror("invalid value");
40 focus_follow
= value
->data
.bool;
42 } else if (!g_ascii_strcasecmp(name
, "focuslast")) {
43 if (value
->type
!= TOKEN_BOOL
)
44 yyerror("invalid value");
46 focus_last
= value
->data
.bool;
48 } else if (!g_ascii_strcasecmp(name
, "focuslastondesktop")) {
49 if (value
->type
!= TOKEN_BOOL
)
50 yyerror("invalid value");
52 focus_last_on_desktop
= value
->data
.bool;
55 yyerror("invalid option");
56 parse_free_token(value
);
61 /* create the window which gets focus when no clients get it. Have to
62 make it override-redirect so we don't try manage it, since it is
64 XSetWindowAttributes attrib
;
70 focus_last_on_desktop
= TRUE
;
72 attrib
.override_redirect
= TRUE
;
73 focus_backup
= XCreateWindow(ob_display
, ob_root
,
75 CopyFromParent
, InputOutput
, CopyFromParent
,
76 CWOverrideRedirect
, &attrib
);
77 XMapRaised(ob_display
, focus_backup
);
79 /* start with nothing focused */
80 focus_set_client(NULL
);
82 parse_reg_section("focus", NULL
, parse_assign
);
89 for (i
= 0; i
< screen_num_desktops
; ++i
)
90 g_list_free(focus_order
[i
]);
94 XDestroyWindow(ob_display
, focus_backup
);
96 /* reset focus to root */
97 XSetInputFocus(ob_display
, PointerRoot
, RevertToPointerRoot
,
101 static void push_to_top(Client
*client
)
105 desktop
= client
->desktop
;
106 if (desktop
== DESKTOP_ALL
) desktop
= screen_desktop
;
107 focus_order
[desktop
] = g_list_remove(focus_order
[desktop
], client
);
108 focus_order
[desktop
] = g_list_prepend(focus_order
[desktop
], client
);
111 void focus_set_client(Client
*client
)
116 /* uninstall the old colormap, and install the new one */
117 screen_install_colormap(focus_client
, FALSE
);
118 screen_install_colormap(client
, TRUE
);
120 if (client
== NULL
) {
121 /* when nothing will be focused, send focus to the backup target */
122 XSetInputFocus(ob_display
, focus_backup
, RevertToPointerRoot
,
124 XSync(ob_display
, FALSE
);
128 focus_client
= client
;
130 /* move to the top of the list */
133 else if (client
!= NULL
)
136 /* set the NET_ACTIVE_WINDOW hint */
137 active
= client
? client
->window
: None
;
138 PROP_SET32(ob_root
, net_active_window
, window
, active
);
140 if (focus_client
!= NULL
)
141 dispatch_client(Event_Client_Focus
, focus_client
, 0, 0);
143 dispatch_client(Event_Client_Unfocus
, old
, 0, 0);
146 static gboolean
focus_under_pointer()
153 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
)) {
154 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
155 Client
*c
= it
->data
;
156 if (c
->desktop
== screen_desktop
&&
157 RECT_CONTAINS(c
->frame
->area
, x
, y
))
161 return client_normal(it
->data
) && client_focus(it
->data
);
166 void focus_fallback(gboolean switching_desks
)
173 /* unfocus any focused clients.. they can be focused by Pointer events
174 and such, and then when I try focus them, I won't get a FocusIn event
177 focus_set_client(NULL
);
179 if (switching_desks
) {
180 /* don't skip any windows when switching desktops */
184 if (!(switching_desks
? focus_last_on_desktop
: focus_last
)) {
185 if (focus_follow
) focus_under_pointer();
189 if (old
&& old
->transient_for
) {
190 if (old
->transient_for
== TRAN_GROUP
) {
191 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
) {
194 for (sit
= old
->group
->members
; sit
; sit
= sit
->next
)
195 if (sit
->data
== it
->data
&& client_focus(sit
->data
))
199 if (client_focus(old
->transient_for
))
204 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
205 if (it
->data
!= old
&& client_normal(it
->data
))
206 if (client_focus(it
->data
))
209 /* nothing to focus */
210 focus_set_client(NULL
);
213 Client
*focus_cycle(gboolean forward
, gboolean linear
, gboolean done
,
216 static Client
*first
= NULL
;
217 static Client
*t
= NULL
;
218 static GList
*order
= NULL
;
219 GList
*it
, *start
, *list
;
223 if (first
) client_focus(first
);
227 push_to_top(focus_client
); /* move to top of focus_order */
228 stacking_raise(focus_client
);
232 if (!first
) first
= focus_client
;
234 if (linear
) list
= client_list
;
235 else list
= focus_order
[screen_desktop
];
237 start
= it
= g_list_find(list
, focus_client
);
238 if (!start
) /* switched desktops or something? */
239 start
= it
= forward
? g_list_last(list
) : g_list_first(list
);
240 if (!start
) goto done_cycle
;
245 if (it
== NULL
) it
= list
;
248 if (it
== NULL
) it
= g_list_last(list
);
250 ft
= client_focus_target(it
->data
);
251 if (ft
== it
->data
&& focus_client
!= ft
&& client_normal(ft
) &&
252 client_focusable(ft
)) {
253 if (client_focus(ft
)) {
254 noreorder
++; /* avoid reordering the focus_order */
258 } while (it
!= start
);