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
);
92 g_message("REORDERING");
95 void focus_set_client(Client
*client
)
100 /* uninstall the old colormap, and install the new one */
101 screen_install_colormap(focus_client
, FALSE
);
102 screen_install_colormap(client
, TRUE
);
104 if (client
== NULL
) {
105 /* when nothing will be focused, send focus to the backup target */
106 XSetInputFocus(ob_display
, focus_backup
, RevertToPointerRoot
,
108 XSync(ob_display
, FALSE
);
112 focus_client
= client
;
114 /* move to the top of the list */
117 else if (client
!= NULL
)
120 /* set the NET_ACTIVE_WINDOW hint */
121 active
= client
? client
->window
: None
;
122 PROP_SET32(ob_root
, net_active_window
, window
, active
);
124 if (focus_client
!= NULL
)
125 dispatch_client(Event_Client_Focus
, focus_client
, 0, 0);
127 dispatch_client(Event_Client_Unfocus
, old
, 0, 0);
130 static gboolean
focus_under_pointer()
137 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
)) {
138 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
139 Client
*c
= it
->data
;
140 if (c
->desktop
== screen_desktop
&&
141 RECT_CONTAINS(c
->frame
->area
, x
, y
))
145 return client_normal(it
->data
) && client_focus(it
->data
);
150 void focus_fallback(gboolean switching_desks
)
153 gboolean under
= FALSE
;
158 /* unfocus any focused clients.. they can be focused by Pointer events
159 and such, and then when I try focus them, I won't get a FocusIn event
162 focus_set_client(NULL
);
164 if (switching_desks
) {
165 /* don't skip any windows when switching desktops */
169 under
= focus_under_pointer();
173 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
174 if (it
->data
!= old
&& client_normal(it
->data
))
175 if (client_focus(it
->data
))
177 if (it
== NULL
) /* nothing to focus */
178 focus_set_client(NULL
);
182 void focus_cycle(gboolean forward
, gboolean linear
, gboolean done
,
185 static Client
*first
= NULL
;
186 static Client
*t
= NULL
;
187 static GList
*order
= NULL
;
188 GList
*it
, *start
, *list
;
192 if (first
) client_focus(first
);
196 push_to_top(focus_client
); /* move to top of focus_order */
197 stacking_raise(focus_client
);
201 if (!first
) first
= focus_client
;
203 if (linear
) list
= client_list
;
204 else list
= focus_order
[screen_desktop
];
206 start
= it
= g_list_find(list
, focus_client
);
207 if (!start
) goto done_cycle
; /* switched desktops or something? */
212 if (it
== NULL
) it
= list
;
215 if (it
== NULL
) it
= g_list_last(list
);
217 ft
= client_focus_target(it
->data
);
218 if (ft
== it
->data
&& focus_client
!= ft
&& client_focusable(ft
)) {
219 if (client_focus(ft
)) {
220 noreorder
++; /* avoid reordering the focus_order */
224 } while (it
!= start
);