]> code.delx.au - spectrwm/commitdiff
Name and search workspaces.
authorLawrence Teo <lteo@devio.us>
Tue, 29 Nov 2011 04:25:46 +0000 (23:25 -0500)
committerLawrence Teo <lteo@devio.us>
Tue, 29 Nov 2011 04:49:52 +0000 (23:49 -0500)
Workspaces can be searched by either name or number.

ok marco

scrotwm.1
scrotwm.c
scrotwm_cz.conf
scrotwm_es.conf
scrotwm_fr.conf
scrotwm_us.conf

index d47304c4c9dccde68a551a370a9fe47d16c4ab45..09b4f88e58576f0db9f77a5a057cea24d7a1e8bb 100644 (file)
--- a/scrotwm.1
+++ b/scrotwm.1
@@ -447,11 +447,15 @@ move_right
 move_up
 .It Cm M-S-]
 move_down
+.It Cm M-S-/
+name_workspace
+.It Cm M-/
+search_workspace
 .El
 .Pp
 The action names and descriptions are listed below:
 .Pp
-.Bl -tag -width "M-j, M-<TAB>XXX" -offset indent -compact
+.Bl -tag -width "M-j, M-<TAB>XXXX" -offset indent -compact
 .It Cm term
 Spawn a new terminal
 (see
@@ -576,6 +580,10 @@ Move a floating window a step to the right.
 Move a floating window a step upwards.
 .It Cm move_down
 Move a floating window a step downwards.
+.It Cm name_workspace
+Name the current workspace.
+.It Cm search_workspace
+Search for a workspace.
 .El
 .Pp
 Custom bindings in the configuration file are specified as follows:
index ac9b894f82d8be414c9c8a0145b05bb1a361b49d..1575a43ad6d307f70f4d958ee3833972fdf870e1 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -210,7 +210,9 @@ int                 search_resp_action;
 /* search actions */
 enum {
        SWM_SEARCH_NONE,
-       SWM_SEARCH_UNICONIFY
+       SWM_SEARCH_UNICONIFY,
+       SWM_SEARCH_NAME_WORKSPACE,
+       SWM_SEARCH_SEARCH_WORKSPACE
 };
 
 /* dialog windows */
@@ -369,6 +371,7 @@ struct layout {
 /* define work spaces */
 struct workspace {
        int                     idx;            /* workspace index */
+       char                    *name;          /* workspace name */
        int                     always_raise;   /* raise windows on focus */
        struct layout           *cur_layout;    /* current layout handlers */
        struct ws_win           *focus;         /* may be NULL */
@@ -1359,6 +1362,7 @@ bar_update(void)
        struct swm_region       *r;
        int                     i, x;
        size_t                  len;
+       char                    ws[SWM_BAR_MAX];
        char                    s[SWM_BAR_MAX];
        char                    cn[SWM_BAR_MAX];
        char                    loc[SWM_BAR_MAX];
@@ -1394,16 +1398,20 @@ bar_update(void)
                x = 1;
                TAILQ_FOREACH(r, &screens[i].rl, entry) {
                        strlcpy(cn, "", sizeof cn);
+                       strlcpy(ws, "", sizeof ws);
                        if (r && r->ws) {
                                bar_urgent(cn, sizeof cn);
                                bar_class_name(cn, sizeof cn, r->ws->focus);
                                bar_window_name(cn, sizeof cn, r->ws->focus);
+                               if (r->ws->name)
+                                       snprintf(ws, sizeof ws, "<%s>", r->ws->name);
                        }
                        if (stack_enabled)
                                stack = r->ws->stacker;
 
-                       snprintf(loc, sizeof loc, "%d:%d %s   %s%s    %s    %s",
-                           x++, r->ws->idx + 1, stack, s, cn, bar_ext, bar_vertext);
+                       snprintf(loc, sizeof loc, "%d:%d %s %s   %s%s    %s    %s",
+                           x++, r->ws->idx + 1, stack, ws, s, cn, bar_ext,
+                           bar_vertext);
                        bar_print(r, loc);
                }
        }
@@ -3244,6 +3252,62 @@ uniconify(struct swm_region *r, union arg *args)
        fclose(lfile);
 }
 
+void
+name_workspace(struct swm_region *r, union arg *args)
+{
+       struct workspace        *ws;
+       FILE                    *lfile;
+
+       DNPRINTF(SWM_D_MISC, "name_workspace\n");
+
+       if (r && r->ws)
+               ws = r->ws;
+       else
+               return;
+
+       search_r = r;
+       search_resp_action = SWM_SEARCH_NAME_WORKSPACE;
+
+       spawn_select(r, args, "name_workspace", &searchpid);
+
+       if ((lfile = fdopen(select_list_pipe[1], "w")) == NULL)
+               return;
+
+       fprintf(lfile, "%s", "");
+       fclose(lfile);
+}
+
+void
+search_workspace(struct swm_region *r, union arg *args)
+{
+       int                     i;
+       struct workspace        *ws;
+       FILE                    *lfile;
+
+       DNPRINTF(SWM_D_MISC, "search_workspace\n");
+
+       if (r == NULL)
+               return;
+
+       search_r = r;
+       search_resp_action = SWM_SEARCH_SEARCH_WORKSPACE;
+
+       spawn_select(r, args, "search", &searchpid);
+
+       if ((lfile = fdopen(select_list_pipe[1], "w")) == NULL)
+               return;
+
+       for (i = 0; i < SWM_WS_MAX; i++) {
+               ws = &r->s->ws[i];
+               if (ws == NULL)
+                       continue;
+               fprintf(lfile, "%d%s%s\n", ws->idx + 1,
+                   (ws->name ? ":" : ""), (ws->name ? ws->name : ""));
+       }
+
+       fclose(lfile);
+}
+
 void
 search_resp_uniconify(char *resp, unsigned long len)
 {
@@ -3274,6 +3338,65 @@ search_resp_uniconify(char *resp, unsigned long len)
        }
 }
 
+void
+search_resp_name_workspace(char *resp, unsigned long len)
+{
+       struct workspace        *ws;
+
+       DNPRINTF(SWM_D_MISC, "search_resp_name_workspace: resp %s\n", resp);
+
+       if (search_r->ws == NULL)
+               return;
+       ws = search_r->ws;
+
+       if (ws->name) {
+               free(search_r->ws->name);
+               search_r->ws->name = NULL;
+       }
+
+       if (len > 1) {
+               ws->name = strdup(resp);
+               if (ws->name == NULL) {
+                       DNPRINTF(SWM_D_MISC, "search_resp_name_workspace: strdup: %s",
+                           strerror(errno));
+                       return;
+               }
+               ws->name[len - 1] = '\0';
+       }
+}
+
+void
+search_resp_search_workspace(char *resp, unsigned long len)
+{
+       char                    *p, *q;
+       int                     ws_idx;
+       const char              *errstr;
+       union arg               a;
+
+       DNPRINTF(SWM_D_MISC, "search_resp_search_workspace: resp %s\n", resp);
+
+       q = strdup(resp);
+       if (!q) {
+               DNPRINTF(SWM_D_MISC, "search_resp_search_workspace: strdup: %s",
+                   strerror(errno));
+               return;
+       }
+       q[len - 1] = '\0';
+       p = strchr(q, ':');
+       if (p != NULL)
+               *p = '\0';
+       ws_idx = strtonum(q, 1, SWM_WS_MAX, &errstr);
+       if (errstr) {
+               DNPRINTF(SWM_D_MISC, "workspace idx is %s: %s",
+                   errstr, q);
+               free(q);
+               return;
+       }
+       free(q);
+       a.id = ws_idx - 1;
+       switchws(search_r, &a);
+}
+
 #define MAX_RESP_LEN   1024
 
 void
@@ -3305,6 +3428,12 @@ search_do_resp(void)
        case SWM_SEARCH_UNICONIFY:
                search_resp_uniconify(resp, len);
                break;
+       case SWM_SEARCH_NAME_WORKSPACE:
+               search_resp_name_workspace(resp, len);
+               break;
+       case SWM_SEARCH_SEARCH_WORKSPACE:
+               search_resp_search_workspace(resp, len);
+               break;
        }
 
 done:
@@ -3762,6 +3891,8 @@ enum keyfuncid {
        kf_move_right,
        kf_move_up,
        kf_move_down,
+       kf_name_workspace,
+       kf_search_workspace,
        kf_dumpwins, /* MUST BE LAST */
        kf_invalid
 };
@@ -3850,6 +3981,8 @@ struct keyfunc {
        { "move_right",         move_step,      {.id = SWM_ARG_ID_MOVERIGHT} },
        { "move_up",            move_step,      {.id = SWM_ARG_ID_MOVEUP} },
        { "move_down",          move_step,      {.id = SWM_ARG_ID_MOVEDOWN} },
+       { "name_workspace",     name_workspace, {0} },
+       { "search_workspace",   search_workspace,       {0} },
        { "dumpwins",           dumpwins,       {0} }, /* MUST BE LAST */
        { "invalid key func",   NULL,           {0} },
 };
@@ -4189,6 +4322,13 @@ setup_spawn(void)
                                        " -nf $bar_font_color"
                                        " -sb $bar_border"
                                        " -sf $bar_color",      0);
+       setconfspawn("name_workspace",  "dmenu"
+                                       " -p Workspace"
+                                       " -fn $bar_font"
+                                       " -nb $bar_color"
+                                       " -nf $bar_font_color"
+                                       " -sb $bar_border"
+                                       " -sf $bar_color",      0);
 }
 
 /* key bindings */
@@ -4453,6 +4593,8 @@ setup_keys(void)
        setkeybinding(MODKEY,           XK_bracketright,kf_move_right,  NULL);
        setkeybinding(MODKEY|ShiftMask, XK_bracketleft, kf_move_up,     NULL);
        setkeybinding(MODKEY|ShiftMask, XK_bracketright,kf_move_down,   NULL);
+       setkeybinding(MODKEY|ShiftMask, XK_slash,       kf_name_workspace,NULL);
+       setkeybinding(MODKEY,           XK_slash,       kf_search_workspace,NULL);
 #ifdef SWM_DEBUG
        setkeybinding(MODKEY|ShiftMask, XK_d,           kf_dumpwins,    NULL);
 #endif
@@ -6322,6 +6464,7 @@ setup_screens(void)
                for (j = 0; j < SWM_WS_MAX; j++) {
                        ws = &screens[i].ws[j];
                        ws->idx = j;
+                       ws->name = NULL;
                        ws->focus = NULL;
                        ws->r = NULL;
                        ws->old_r = NULL;
index f332bc8ba4d335ac4233524980f6278f070b560f..598bab459f50a5d265f73934501eec781e9ed059 100644 (file)
@@ -67,3 +67,5 @@ bind[move_left]               = MOD+uacute
 bind[move_right]       = MOD+parenright
 bind[move_up]          = MOD+Shift+uacute
 bind[move_down]                = MOD+Shift+parenright
+bind[name_workspace]   = MOD+Shift+slash
+bind[search_workspace] = MOD+slash
index eb825da2d9ae10f8acf544fa1c17662121a74c5d..5b2668e6833d3ffffffa0a73d9bb64bea94dcd4c 100644 (file)
@@ -67,3 +67,5 @@ bind[move_left]               = MOD+dead_grave
 bind[move_right]       = MOD+plus
 bind[move_up]          = MOD+Shift+dead_grave
 bind[move_down]                = MOD+Shift+plus
+bind[name_workspace]   = MOD+Shift+slash
+bind[search_workspace] = MOD+slash
index deabd005dd967db66103f0ffe83a009abf683c81..e38db319338b6c2ac6695bb4d3dc3261945a6b6c 100644 (file)
@@ -67,3 +67,5 @@ bind[move_left]               = MOD+ugrave
 bind[move_right]       = MOD+asterisk
 bind[move_up]          = MOD+Shift+ugrave
 bind[move_down]                = MOD+Shift+asterisk
+bind[name_workspace]   = MOD+Shift+slash
+bind[search_workspace] = MOD+slash
index a5b4aed579274f1f59bd7a2ea8d1c5e885e7ced9..0781eedbdba91154875fd69300ffbe5417e058cf 100644 (file)
@@ -67,3 +67,5 @@ bind[move_left]               = MOD+bracketleft
 bind[move_right]       = MOD+bracketright
 bind[move_up]          = MOD+Shift+bracketleft
 bind[move_down]                = MOD+Shift+bracketright
+bind[name_workspace]   = MOD+Shift+slash
+bind[search_workspace] = MOD+slash