+
+gboolean focus_cycle_popup_is_showing(ObClient *c)
+{
+ if (popup.mapped) {
+ GList *it;
+
+ for (it = popup.targets; it; it = g_list_next(it)) {
+ ObFocusCyclePopupTarget *t = it->data;
+ if (t->client == c)
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+static ObClient* popup_revert(ObClient *target)
+{
+ GList *it, *itt;
+
+ for (it = popup.targets; it; it = g_list_next(it)) {
+ ObFocusCyclePopupTarget *t = it->data;
+ if (t->client == target) {
+ /* move to a previous window if possible */
+ for (itt = it->prev; itt; itt = g_list_previous(itt)) {
+ ObFocusCyclePopupTarget *t2 = itt->data;
+ if (focus_cycle_valid(t2->client))
+ return t2->client;
+ }
+
+ /* otherwise move to a following window if possible */
+ for (itt = it->next; itt; itt = g_list_next(itt)) {
+ ObFocusCyclePopupTarget *t2 = itt->data;
+ if (focus_cycle_valid(t2->client))
+ return t2->client;
+ }
+
+ /* otherwise, we can't go anywhere there is nowhere valid to go */
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
+ObClient* focus_cycle_popup_refresh(ObClient *target,
+ gboolean redraw)
+{
+ if (!popup.mapped) return NULL;
+
+ if (!focus_cycle_valid(target))
+ target = popup_revert(target);
+
+ redraw = popup_setup(&popup, TRUE, TRUE) && redraw;
+
+ if (!target && popup.targets)
+ target = ((ObFocusCyclePopupTarget*)popup.targets->data)->client;
+
+ if (target && redraw) {
+ popup.mapped = FALSE;
+ popup_render(&popup, target);
+ XFlush(obt_display);
+ popup.mapped = TRUE;
+ }
+
+ return target;
+}