- 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 = list;
- } else {
- it = it->prev;
- if (it == NULL) it = g_list_last(list);
- }
- ft = client_focus_target(it->data);
- if (ft == it->data && client_normal(ft) && client_focusable(ft)) {
- if (focus_cycle_target)
- frame_adjust_focus(focus_cycle_target->frame, FALSE);
- else if (focus_client)
- frame_adjust_focus(focus_client->frame, FALSE);
- focus_cycle_target = ft;
- frame_adjust_focus(focus_cycle_target->frame, TRUE);
- return ft;
- }
- } while (it != start);
- return NULL;