From 2ac03f635fcaf119653eecb41feb6c0a8ccc8f79 Mon Sep 17 00:00:00 2001 From: Reginald Kennedy Date: Fri, 26 Oct 2012 14:24:19 +0800 Subject: [PATCH] Add new argument variables for programs: $region_index $workspace_index --- spectrwm.1 | 12 ++++-------- spectrwm.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/spectrwm.1 b/spectrwm.1 index e37a7ee..38c208e 100644 --- a/spectrwm.1 +++ b/spectrwm.1 @@ -427,14 +427,8 @@ is the desired program, and .Aq arg is zero or more arguments to the program. .Pp -The following variables represent settable values in -.Nm -(see the -.Sx CONFIGURATION FILES -section above), -and may be used in the -.Aq arg -fields and will be substituted for values at the time the program is spawned: +The following argument variables will be substituted for values at the time the program +is spawned: .Pp .Bl -tag -width "$bar_font_color" -offset indent -compact .It Cm $bar_border @@ -443,6 +437,8 @@ fields and will be substituted for values at the time the program is spawned: .It Cm $bar_font_color .It Cm $color_focus .It Cm $color_unfocus +.It Cm $region_index +.It Cm $workspace_index .El .Pp Example: diff --git a/spectrwm.c b/spectrwm.c index 40e2944..130c7af 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -924,6 +924,7 @@ char *get_notify_mode_label(uint8_t); #endif struct ws_win *get_pointer_win(xcb_window_t); struct ws_win *get_region_focus(struct swm_region *); +int get_region_index(struct swm_region *); xcb_screen_t *get_screen(int); #ifdef SWM_DEBUG char *get_stack_mode_name(uint8_t); @@ -1176,6 +1177,27 @@ get_screen(int screen) return (NULL); } +int +get_region_index(struct swm_region *r) +{ + struct swm_region *rr; + int ridx = 0; + + if (r == NULL) + return -1; + + TAILQ_FOREACH(rr, &r->s->rl, entry) { + if (rr == r) + break; + ++ridx; + } + + if (rr == NULL) + return -1; + + return ridx; +} + void focus_flush(void) { @@ -5813,6 +5835,13 @@ spawn_expand(struct swm_region *r, union arg *args, const char *spawn_name, strdup(r->s->c[SWM_S_COLOR_UNFOCUS].name)) == NULL) err(1, "spawn_custom color unfocus"); + } else if (!strcasecmp(ap, "$region_index")) { + if (asprintf(&real_args[i], "%d", + get_region_index(r) + 1) < 1) + err(1, "spawn_custom region index"); + } else if (!strcasecmp(ap, "$workspace_index")) { + if (asprintf(&real_args[i], "%d", r->ws->idx + 1) < 1) + err(1, "spawn_custom workspace index"); } else { /* no match --> copy as is */ if ((real_args[i] = strdup(ap)) == NULL) -- 1.7.10.4