From: Lawrence Teo Date: Tue, 29 Nov 2011 04:25:46 +0000 (-0500) Subject: Name and search workspaces. X-Git-Url: https://jasonwoof.com/gitweb/?a=commitdiff_plain;h=63eea690871eadbb0998dd035cf8d2759f495016;p=spectrwm.git Name and search workspaces. Workspaces can be searched by either name or number. ok marco --- diff --git a/scrotwm.1 b/scrotwm.1 index d47304c..09b4f88 100644 --- 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-XXX" -offset indent -compact +.Bl -tag -width "M-j, M-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: diff --git a/scrotwm.c b/scrotwm.c index ac9b894..1575a43 100644 --- 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); } } @@ -3245,6 +3253,62 @@ uniconify(struct swm_region *r, union arg *args) } 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) { unsigned char *name; @@ -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; diff --git a/scrotwm_cz.conf b/scrotwm_cz.conf index f332bc8..598bab4 100644 --- a/scrotwm_cz.conf +++ b/scrotwm_cz.conf @@ -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 diff --git a/scrotwm_es.conf b/scrotwm_es.conf index eb825da..5b2668e 100644 --- a/scrotwm_es.conf +++ b/scrotwm_es.conf @@ -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 diff --git a/scrotwm_fr.conf b/scrotwm_fr.conf index deabd00..e38db31 100644 --- a/scrotwm_fr.conf +++ b/scrotwm_fr.conf @@ -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 diff --git a/scrotwm_us.conf b/scrotwm_us.conf index a5b4aed..0781eed 100644 --- a/scrotwm_us.conf +++ b/scrotwm_us.conf @@ -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