-ObClient *focus_cycle(gboolean forward, gboolean linear, gboolean done,
- gboolean cancel)
-{
- static ObClient *first = NULL;
- static ObClient *t = NULL;
- static GList *order = NULL;
- GList *it, *start, *list;
- ObClient *ft;
-
- if (cancel) {
- if (focus_cycle_target)
- frame_adjust_focus(focus_cycle_target->frame, FALSE);
- if (focus_client)
- frame_adjust_focus(focus_client->frame, TRUE);
- goto done_cycle;
- } else if (done) {
- if (focus_cycle_target)
- client_activate(focus_cycle_target);
- goto done_cycle;
- }
- if (!first)
- grab_pointer(TRUE, None);
-
- if (!first) first = focus_client;
- if (!focus_cycle_target) focus_cycle_target = focus_client;
-
- if (linear) list = client_list;
- else list = focus_order[screen_desktop];
-
- start = it = g_list_find(list, focus_cycle_target);
- if (!start) /* switched desktops or something? */
- start = it = forward ? g_list_last(list) : g_list_first(list);
- if (!start) goto done_cycle;
-
- do {
- if (forward) {
- it = it->next;
- if (it == NULL) it = g_list_first(list);
- } else {
- it = it->prev;
- if (it == NULL) it = g_list_last(list);
- }
- /*ft = client_focus_target(it->data);*/
- ft = it->data;
- /* we don't use client_can_focus here, because that doesn't let you
- focus an iconic window, but we want to be able to, so we just check
- if the focus flags on the window allow it, and its on the current
- desktop */
- if (ft->transients == NULL && client_normal(ft) &&
- ((ft->can_focus || ft->focus_notify) &&
- (ft->desktop == screen_desktop || ft->desktop == DESKTOP_ALL))) {
- if (ft != focus_cycle_target) { /* prevents flicker */
- if (focus_cycle_target)
- frame_adjust_focus(focus_cycle_target->frame, FALSE);
- focus_cycle_target = ft;
- frame_adjust_focus(focus_cycle_target->frame, TRUE);
- }
- popup_cycle(ft, config_focus_popup);
- return ft;
- }
- } while (it != start);