JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Extend the uniconify code to support upcoming search-based features.
[spectrwm.git] / scrotwm.c
index 06b4a97..ac9b894 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -205,6 +205,13 @@ int                        select_list_pipe[2];
 int                    select_resp_pipe[2];
 pid_t                  searchpid;
 volatile sig_atomic_t  search_resp;
+int                    search_resp_action;
+
+/* search actions */
+enum {
+       SWM_SEARCH_NONE,
+       SWM_SEARCH_UNICONIFY
+};
 
 /* dialog windows */
 double                 dialog_ratio = .6;
@@ -425,6 +432,8 @@ union arg {
 #define SWM_ARG_ID_CYCLEWS_DOWN        (41)
 #define SWM_ARG_ID_CYCLESC_UP  (42)
 #define SWM_ARG_ID_CYCLESC_DOWN        (43)
+#define SWM_ARG_ID_CYCLEWS_UP_ALL      (44)
+#define SWM_ARG_ID_CYCLEWS_DOWN_ALL    (45)
 #define SWM_ARG_ID_STACKINC    (50)
 #define SWM_ARG_ID_STACKDEC    (51)
 #define SWM_ARG_ID_SS_ALL      (60)
@@ -2145,6 +2154,7 @@ cyclews(struct swm_region *r, union arg *args)
 {
        union                   arg a;
        struct swm_screen       *s = r->s;
+       int                     cycle_all = 0;
 
        DNPRINTF(SWM_D_WS, "cyclews id %d "
            "in screen[%d]:%dx%d+%d+%d ws %d\n", args->id,
@@ -2153,12 +2163,18 @@ cyclews(struct swm_region *r, union arg *args)
        a.id = r->ws->idx;
        do {
                switch (args->id) {
+               case SWM_ARG_ID_CYCLEWS_UP_ALL:
+                       cycle_all = 1;
+                       /* FALLTHROUGH */
                case SWM_ARG_ID_CYCLEWS_UP:
                        if (a.id < SWM_WS_MAX - 1)
                                a.id++;
                        else
                                a.id = 0;
                        break;
+               case SWM_ARG_ID_CYCLEWS_DOWN_ALL:
+                       cycle_all = 1;
+                       /* FALLTHROUGH */
                case SWM_ARG_ID_CYCLEWS_DOWN:
                        if (a.id > 0)
                                a.id--;
@@ -2169,7 +2185,8 @@ cyclews(struct swm_region *r, union arg *args)
                        return;
                };
 
-               if (cycle_empty == 0 && TAILQ_EMPTY(&s->ws[a.id].winlist))
+               if (!cycle_all &&
+                   (cycle_empty == 0 && TAILQ_EMPTY(&s->ws[a.id].winlist)))
                        continue;
                if (cycle_visible == 0 && s->ws[a.id].r != NULL)
                        continue;
@@ -3203,8 +3220,9 @@ uniconify(struct swm_region *r, union arg *args)
                return;
 
        search_r = r;
+       search_resp_action = SWM_SEARCH_UNICONIFY;
 
-       spawn_select(r, args, "uniconify", &searchpid);
+       spawn_select(r, args, "search", &searchpid);
 
        if ((lfile = fdopen(select_list_pipe[1], "w")) == NULL)
                return;
@@ -3226,15 +3244,43 @@ uniconify(struct swm_region *r, union arg *args)
        fclose(lfile);
 }
 
+void
+search_resp_uniconify(char *resp, unsigned long len)
+{
+       unsigned char           *name;
+       struct ws_win           *win;
+       char                    *s;
+
+       DNPRINTF(SWM_D_MISC, "search_resp_uniconify: resp %s\n", resp);
+
+       TAILQ_FOREACH(win, &search_r->ws->winlist, entry) {
+               if (win->iconic == 0)
+                       continue;
+               name = get_win_name(display, win->id, a_wmname, a_string, &len);
+               if (name == NULL)
+                       continue;
+               if (asprintf(&s, "%s.%lu", name, win->id) == -1) {
+                       XFree(name);
+                       continue;
+               }
+               XFree(name);
+               if (strncmp(s, resp, len) == 0) {
+                       /* XXX this should be a callback to generalize */
+                       update_iconic(win, 0);
+                       free(s);
+                       break;
+               }
+               free(s);
+       }
+}
+
 #define MAX_RESP_LEN   1024
 
 void
 search_do_resp(void)
 {
        ssize_t                 rbytes;
-       struct ws_win           *win;
-       unsigned char           *name;
-       char                    *resp, *s;
+       char                    *resp;
        unsigned long           len;
 
        DNPRINTF(SWM_D_MISC, "search_do_resp:\n");
@@ -3255,27 +3301,14 @@ search_do_resp(void)
        resp[rbytes] = '\0';
        len = strlen(resp);
 
-       DNPRINTF(SWM_D_MISC, "search_do_resp: resp %s\n", resp);
-       TAILQ_FOREACH(win, &search_r->ws->winlist, entry) {
-               if (win->iconic == 0)
-                       continue;
-               name = get_win_name(display, win->id, a_wmname, a_string, &len);
-               if (name == NULL)
-                       continue;
-               if (asprintf(&s, "%s.%lu", name, win->id) == -1) {
-                       XFree(name);
-                       continue;
-               }
-               XFree(name);
-               if (strncmp(s, resp, len) == 0) {
-                       /* XXX this should be a callback to generalize */
-                       update_iconic(win, 0);
-                       free(s);
-                       break;
-               }
-               free(s);
+       switch (search_resp_action) {
+       case SWM_SEARCH_UNICONIFY:
+               search_resp_uniconify(resp, len);
+               break;
        }
+
 done:
+       search_resp_action = SWM_SEARCH_NONE;
        close(select_resp_pipe[0]);
        free(resp);
 }
@@ -3692,6 +3725,8 @@ enum keyfuncid {
        kf_ws_10,
        kf_ws_next,
        kf_ws_prev,
+       kf_ws_next_all,
+       kf_ws_prev_all,
        kf_ws_prior,
        kf_screen_next,
        kf_screen_prev,
@@ -3778,6 +3813,8 @@ struct keyfunc {
        { "ws_10",              switchws,       {.id = 9} },
        { "ws_next",            cyclews,        {.id = SWM_ARG_ID_CYCLEWS_UP} },
        { "ws_prev",            cyclews,        {.id = SWM_ARG_ID_CYCLEWS_DOWN} },
+       { "ws_next_all",        cyclews,        {.id = SWM_ARG_ID_CYCLEWS_UP_ALL} },
+       { "ws_prev_all",        cyclews,        {.id = SWM_ARG_ID_CYCLEWS_DOWN_ALL} },
        { "ws_prior",           priorws,        {0} },
        { "screen_next",        cyclescr,       {.id = SWM_ARG_ID_CYCLESC_UP} },
        { "screen_prev",        cyclescr,       {.id = SWM_ARG_ID_CYCLESC_DOWN} },
@@ -4145,7 +4182,7 @@ setup_spawn(void)
                                        " -nf $bar_font_color"
                                        " -sb $bar_border"
                                        " -sf $bar_color",      0);
-       setconfspawn("uniconify",       "dmenu"
+       setconfspawn("search",          "dmenu"
                                        " -i"
                                        " -fn $bar_font"
                                        " -nb $bar_color"
@@ -4378,6 +4415,8 @@ setup_keys(void)
        setkeybinding(MODKEY,           XK_0,           kf_ws_10,       NULL);
        setkeybinding(MODKEY,           XK_Right,       kf_ws_next,     NULL);
        setkeybinding(MODKEY,           XK_Left,        kf_ws_prev,     NULL);
+       setkeybinding(MODKEY,           XK_Up,          kf_ws_next_all, NULL);
+       setkeybinding(MODKEY,           XK_Down,        kf_ws_prev_all, NULL);
        setkeybinding(MODKEY,           XK_a,           kf_ws_prior,    NULL);
        setkeybinding(MODKEY|ShiftMask, XK_Right,       kf_screen_next, NULL);
        setkeybinding(MODKEY|ShiftMask, XK_Left,        kf_screen_prev, NULL);