15 Client
*focus_client
= NULL
;
16 GList
**focus_order
= NULL
; /* these lists are created when screen_startup
17 sets the number of desktops */
19 Window focus_backup
= None
;
20 gboolean focus_new
= TRUE
;
21 gboolean focus_follow
= TRUE
;
23 static gboolean noreorder
= 0;
25 static void parse_assign(char *name
, ParseToken
*value
)
27 if (!g_ascii_strcasecmp(name
, "focusnew")) {
28 if (value
->type
!= TOKEN_BOOL
)
29 yyerror("invalid value");
31 focus_new
= value
->data
.bool;
33 } else if (!g_ascii_strcasecmp(name
, "followmouse")) {
34 if (value
->type
!= TOKEN_BOOL
)
35 yyerror("invalid value");
37 focus_follow
= value
->data
.bool;
40 yyerror("invalid option");
41 parse_free_token(value
);
46 /* create the window which gets focus when no clients get it. Have to
47 make it override-redirect so we don't try manage it, since it is
49 XSetWindowAttributes attrib
;
55 attrib
.override_redirect
= TRUE
;
56 focus_backup
= XCreateWindow(ob_display
, ob_root
,
58 CopyFromParent
, InputOutput
, CopyFromParent
,
59 CWOverrideRedirect
, &attrib
);
60 XMapRaised(ob_display
, focus_backup
);
62 /* start with nothing focused */
63 focus_set_client(NULL
);
65 parse_reg_section("focus", NULL
, parse_assign
);
72 for (i
= 0; i
< screen_num_desktops
; ++i
)
73 g_list_free(focus_order
[i
]);
77 XDestroyWindow(ob_display
, focus_backup
);
79 /* reset focus to root */
80 XSetInputFocus(ob_display
, PointerRoot
, RevertToPointerRoot
,
84 static void push_to_top(Client
*client
)
88 desktop
= client
->desktop
;
89 if (desktop
== DESKTOP_ALL
) desktop
= screen_desktop
;
90 focus_order
[desktop
] = g_list_remove(focus_order
[desktop
], client
);
91 focus_order
[desktop
] = g_list_prepend(focus_order
[desktop
], client
);
94 void focus_set_client(Client
*client
)
99 /* uninstall the old colormap, and install the new one */
100 screen_install_colormap(focus_client
, FALSE
);
101 screen_install_colormap(client
, TRUE
);
103 if (client
== NULL
) {
104 /* when nothing will be focused, send focus to the backup target */
105 XSetInputFocus(ob_display
, focus_backup
, RevertToPointerRoot
,
107 XSync(ob_display
, FALSE
);
111 focus_client
= client
;
113 /* move to the top of the list */
116 else if (client
!= NULL
)
119 /* set the NET_ACTIVE_WINDOW hint */
120 active
= client
? client
->window
: None
;
121 PROP_SET32(ob_root
, net_active_window
, window
, active
);
123 if (focus_client
!= NULL
)
124 dispatch_client(Event_Client_Focus
, focus_client
, 0, 0);
126 dispatch_client(Event_Client_Unfocus
, old
, 0, 0);
129 static gboolean
focus_under_pointer()
136 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
)) {
137 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
138 Client
*c
= it
->data
;
139 if (c
->desktop
== screen_desktop
&&
140 RECT_CONTAINS(c
->frame
->area
, x
, y
))
144 return client_normal(it
->data
) && client_focus(it
->data
);
149 void focus_fallback(gboolean switching_desks
)
152 gboolean under
= FALSE
;
157 /* unfocus any focused clients.. they can be focused by Pointer events
158 and such, and then when I try focus them, I won't get a FocusIn event
161 focus_set_client(NULL
);
163 if (switching_desks
) {
164 /* don't skip any windows when switching desktops */
168 under
= focus_under_pointer();
172 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
173 if (it
->data
!= old
&& client_normal(it
->data
))
174 if (client_focus(it
->data
))
176 if (it
== NULL
) /* nothing to focus */
177 focus_set_client(NULL
);
181 void focus_cycle(gboolean forward
, gboolean linear
, gboolean done
,
184 static Client
*first
= NULL
;
185 static Client
*t
= NULL
;
186 static GList
*order
= NULL
;
187 GList
*it
, *start
, *list
;
191 if (first
) client_focus(first
);
195 push_to_top(focus_client
); /* move to top of focus_order */
196 stacking_raise(focus_client
);
200 if (!first
) first
= focus_client
;
202 if (linear
) list
= client_list
;
203 else list
= focus_order
[screen_desktop
];
205 start
= it
= g_list_find(list
, focus_client
);
206 if (!start
) goto done_cycle
; /* switched desktops or something? */
211 if (it
== NULL
) it
= list
;
214 if (it
== NULL
) it
= g_list_last(list
);
216 ft
= client_focus_target(it
->data
);
217 if (ft
== it
->data
&& focus_client
!= ft
&& client_focusable(ft
)) {
218 if (client_focus(ft
)) {
219 noreorder
++; /* avoid reordering the focus_order */
223 } while (it
!= start
);