aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2019-01-22 11:43:37 +0000
committerLibravatar emersion <contact@emersion.fr>2019-01-22 18:48:33 +0100
commitd8f3e6e19a12514ed6f8c8f470b89fde0f39dc59 (patch)
tree89a75ecad4a25b16a6734593b094429f139cbc0e /swaybar
parentMerge pull request #3496 from mstoeckl/fix-san (diff)
downloadsway-d8f3e6e19a12514ed6f8c8f470b89fde0f39dc59.tar.gz
sway-d8f3e6e19a12514ed6f8c8f470b89fde0f39dc59.tar.zst
sway-d8f3e6e19a12514ed6f8c8f470b89fde0f39dc59.zip
swaybar: fix workspace command
Escape quotes and backslashes, allowing switching to workspace names like "1" (including quotes) and \
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/ipc.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index dbb593fb..46565202 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -13,10 +13,27 @@
13#include "util.h" 13#include "util.h"
14 14
15void ipc_send_workspace_command(struct swaybar *bar, const char *ws) { 15void ipc_send_workspace_command(struct swaybar *bar, const char *ws) {
16 const char *fmt = "workspace \"%s\""; 16 uint32_t size = strlen("workspace \"\"") + strlen(ws);
17 uint32_t size = snprintf(NULL, 0, fmt, ws); 17 for (size_t i = 0; i < strlen(ws); ++i) {
18 char *command = malloc(sizeof(char) * (size + 1)); 18 if (ws[i] == '"' || ws[i] == '\\') {
19 snprintf(command, size, fmt, ws); 19 ++size;
20 }
21 }
22
23 char *command = malloc(size) + 1;
24 if (!command) {
25 return;
26 }
27
28 strcpy(command, "workspace \"");
29 strcpy(&command[size - 1], "\"");
30 for (size_t i = 0, d = strlen("workspace \""); i < strlen(ws); ++i) {
31 if (ws[i] == '"' || ws[i] == '\\') {
32 command[d++] = '\\';
33 }
34 command[d++] = ws[i];
35 }
36
20 ipc_single_command(bar->ipc_socketfd, IPC_COMMAND, command, &size); 37 ipc_single_command(bar->ipc_socketfd, IPC_COMMAND, command, &size);
21 free(command); 38 free(command);
22} 39}