+ if (data->client) {
+ gchar *c, *before, *expand;
+
+ /* replace occurrences of $pid and $wid */
+
+ 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") */
+ }
+ else if ((c[1] == 'w' || c[1] == 'W') &&
+ (c[2] == 'i' || c[2] == 'I') &&
+ (c[3] == 'd' || c[3] == 'D') &&
+ !g_ascii_isalnum(c[4]))
+ {
+ /* found $wid */
+ gchar *tmp;
+
+ *c = '\0';
+ tmp = expand;
+ expand = g_strdup_printf("%s%s%lu",
+ (expand ? expand : ""),
+ before,
+ data->client->window);
+ g_free(tmp);
+
+ before = c + 4; /* 4 = strlen("$wid") */
+ }
+ else
+ before = c + 1; /* no infinite loops plz */
+ }
+
+ 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;
+ }
+ }
+