+ if (data->client) {
+ gchar *c, *before, *expand;
+
+ /* replace occurances of $pid and $window */
+
+ expand = NULL;
+ before = cmd;
+
+ while ((c = strchr(before, '$'))) {
+ if ((c[1] == 'p' || c[1] == 'P') &&
+ (c[2] == 'i' || c[2] == 'I') &&
+ (c[3] == 'd' || c[3] == 'D') &&
+ !g_ascii_isalnum(c[4]))
+ {
+ /* found $pid */
+ gchar *tmp;
+
+ *c = '\0';
+ tmp = expand;
+ expand = g_strdup_printf("%s%s%u",
+ (expand ? expand : ""),
+ before,
+ data->client->pid);
+ g_free(tmp);
+
+ before = c + 4; /* 4 = strlen("$pid") */
+ }
+
+ if ((c[1] == 'w' || c[1] == 'W') &&
+ (c[2] == 'i' || c[2] == 'I') &&
+ (c[3] == 'd' || c[3] == 'D') &&
+ !g_ascii_isalnum(c[7]))
+ {
+ /* found $window */
+ gchar *tmp;
+
+ *c = '\0';
+ tmp = expand;
+ expand = g_strdup_printf("%s%s%lu",
+ (expand ? expand : ""),
+ before,
+ data->client->window);
+ g_free(tmp);
+
+ before = c + 7; /* 4 = strlen("$window") */
+ }
+ }
+
+ if (expand) {
+ gchar *tmp;
+
+ /* add on the end of the string after the last replacement */
+ tmp = expand;
+ expand = g_strconcat(expand, before, NULL);
+ g_free(tmp);
+
+ /* replace the command with the expanded one */
+ g_free(cmd);
+ cmd = expand;
+ }
+ }
+