]> code.delx.au - spectrwm/blobdiff - spectrwm.c
Add new argument variables for programs:
[spectrwm] / spectrwm.c
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)