]> code.delx.au - spectrwm/commitdiff
Add new argument variables for programs:
authorReginald Kennedy <rk@rejii.com>
Fri, 26 Oct 2012 06:24:19 +0000 (14:24 +0800)
committerReginald Kennedy <rk@rejii.com>
Fri, 26 Oct 2012 06:25:30 +0000 (14:25 +0800)
$region_index
$workspace_index

spectrwm.1
spectrwm.c

index e37a7eef7b04bc3a78ab49d4fc31e34c42e5129f..38c208ecbd87402931ea466e2b60c37197784714 100644 (file)
@@ -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:
index 40e2944e1bd91ddcc1e646b63ec99997512ffbf1..130c7afcbf54ffe9ef4c0375b0e4aa9f90cbd24f 100644 (file)
@@ -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)