diff options
-rw-r--r-- | common/util.c | 9 | ||||
-rw-r--r-- | include/util.h | 5 | ||||
-rw-r--r-- | sway/commands/bar.c | 4 | ||||
-rw-r--r-- | sway/commands/move.c | 1 | ||||
-rw-r--r-- | sway/commands/scratchpad.c | 4 | ||||
-rw-r--r-- | sway/tree/root.c | 7 | ||||
-rw-r--r-- | swaybar/ipc.c | 11 |
7 files changed, 13 insertions, 28 deletions
diff --git a/common/util.c b/common/util.c index bd7bed2d..edbbf3f7 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -11,15 +11,6 @@ int wrap(int i, int max) { | |||
11 | return ((i % max) + max) % max; | 11 | return ((i % max) + max) % max; |
12 | } | 12 | } |
13 | 13 | ||
14 | int numlen(int n) { | ||
15 | int j = n <= 0 ? 1 : 0; | ||
16 | while (n) { | ||
17 | j++; | ||
18 | n /= 10; | ||
19 | } | ||
20 | return j; | ||
21 | } | ||
22 | |||
23 | uint32_t parse_color(const char *color) { | 14 | uint32_t parse_color(const char *color) { |
24 | if (color[0] == '#') { | 15 | if (color[0] == '#') { |
25 | ++color; | 16 | ++color; |
diff --git a/include/util.h b/include/util.h index e3269d6b..1fd772c0 100644 --- a/include/util.h +++ b/include/util.h | |||
@@ -10,11 +10,6 @@ | |||
10 | int wrap(int i, int max); | 10 | int wrap(int i, int max); |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * Count number of digits in int, including '-' sign if there is one | ||
14 | */ | ||
15 | int numlen(int n); | ||
16 | |||
17 | /** | ||
18 | * Given a string that represents an RGB(A) color, return a uint32_t | 13 | * Given a string that represents an RGB(A) color, return a uint32_t |
19 | * version of the color. | 14 | * version of the color. |
20 | */ | 15 | */ |
diff --git a/sway/commands/bar.c b/sway/commands/bar.c index e9360603..82441f9e 100644 --- a/sway/commands/bar.c +++ b/sway/commands/bar.c | |||
@@ -1,10 +1,10 @@ | |||
1 | #define _POSIX_C_SOURCE 200809 | 1 | #define _POSIX_C_SOURCE 200809 |
2 | #include <stdio.h> | ||
2 | #include <string.h> | 3 | #include <string.h> |
3 | #include <strings.h> | 4 | #include <strings.h> |
4 | #include "sway/commands.h" | 5 | #include "sway/commands.h" |
5 | #include "sway/config.h" | 6 | #include "sway/config.h" |
6 | #include "log.h" | 7 | #include "log.h" |
7 | #include "util.h" | ||
8 | 8 | ||
9 | // Must be in alphabetical order for bsearch | 9 | // Must be in alphabetical order for bsearch |
10 | static struct cmd_handler bar_handlers[] = { | 10 | static struct cmd_handler bar_handlers[] = { |
@@ -89,7 +89,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) { | |||
89 | } | 89 | } |
90 | 90 | ||
91 | // set bar id | 91 | // set bar id |
92 | const int len = 5 + numlen(config->bars->length - 1); // "bar-"+i+\0 | 92 | const int len = snprintf(NULL, 0, "bar-%d", config->bars->length - 1) + 1; |
93 | bar->id = malloc(len * sizeof(char)); | 93 | bar->id = malloc(len * sizeof(char)); |
94 | if (bar->id) { | 94 | if (bar->id) { |
95 | snprintf(bar->id, len, "bar-%d", config->bars->length - 1); | 95 | snprintf(bar->id, len, "bar-%d", config->bars->length - 1); |
diff --git a/sway/commands/move.c b/sway/commands/move.c index b22bb056..acb5f44f 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -515,6 +515,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) { | |||
515 | // move container | 515 | // move container |
516 | if (container->scratchpad) { | 516 | if (container->scratchpad) { |
517 | root_scratchpad_remove_container(container); | 517 | root_scratchpad_remove_container(container); |
518 | root_scratchpad_show(container); | ||
518 | } | 519 | } |
519 | switch (destination->type) { | 520 | switch (destination->type) { |
520 | case N_WORKSPACE: | 521 | case N_WORKSPACE: |
diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c index 805dbc0b..714efa2b 100644 --- a/sway/commands/scratchpad.c +++ b/sway/commands/scratchpad.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "sway/config.h" | 3 | #include "sway/config.h" |
4 | #include "sway/input/input-manager.h" | 4 | #include "sway/input/input-manager.h" |
5 | #include "sway/input/seat.h" | 5 | #include "sway/input/seat.h" |
6 | #include "sway/ipc-server.h" | ||
6 | #include "sway/tree/container.h" | 7 | #include "sway/tree/container.h" |
7 | #include "sway/tree/root.h" | 8 | #include "sway/tree/root.h" |
8 | #include "sway/tree/workspace.h" | 9 | #include "sway/tree/workspace.h" |
@@ -51,6 +52,7 @@ static void scratchpad_toggle_auto(void) { | |||
51 | "Moving a visible scratchpad window (%s) to this workspace", | 52 | "Moving a visible scratchpad window (%s) to this workspace", |
52 | con->title); | 53 | con->title); |
53 | root_scratchpad_show(con); | 54 | root_scratchpad_show(con); |
55 | ipc_event_window(con, "move"); | ||
54 | return; | 56 | return; |
55 | } | 57 | } |
56 | } | 58 | } |
@@ -62,6 +64,7 @@ static void scratchpad_toggle_auto(void) { | |||
62 | struct sway_container *con = root->scratchpad->items[0]; | 64 | struct sway_container *con = root->scratchpad->items[0]; |
63 | sway_log(SWAY_DEBUG, "Showing %s from list", con->title); | 65 | sway_log(SWAY_DEBUG, "Showing %s from list", con->title); |
64 | root_scratchpad_show(con); | 66 | root_scratchpad_show(con); |
67 | ipc_event_window(con, "move"); | ||
65 | } | 68 | } |
66 | 69 | ||
67 | static void scratchpad_toggle_container(struct sway_container *con) { | 70 | static void scratchpad_toggle_container(struct sway_container *con) { |
@@ -76,6 +79,7 @@ static void scratchpad_toggle_container(struct sway_container *con) { | |||
76 | } | 79 | } |
77 | 80 | ||
78 | root_scratchpad_show(con); | 81 | root_scratchpad_show(con); |
82 | ipc_event_window(con, "move"); | ||
79 | } | 83 | } |
80 | 84 | ||
81 | struct cmd_results *cmd_scratchpad(int argc, char **argv) { | 85 | struct cmd_results *cmd_scratchpad(int argc, char **argv) { |
diff --git a/sway/tree/root.c b/sway/tree/root.c index ec6bccf6..c4d1145d 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c | |||
@@ -85,9 +85,6 @@ void root_scratchpad_remove_container(struct sway_container *con) { | |||
85 | if (!sway_assert(con->scratchpad, "Container is not in scratchpad")) { | 85 | if (!sway_assert(con->scratchpad, "Container is not in scratchpad")) { |
86 | return; | 86 | return; |
87 | } | 87 | } |
88 | if (!con->workspace) { | ||
89 | root_scratchpad_show(con); | ||
90 | } | ||
91 | con->scratchpad = false; | 88 | con->scratchpad = false; |
92 | int index = list_find(root->scratchpad, con); | 89 | int index = list_find(root->scratchpad, con); |
93 | if (index != -1) { | 90 | if (index != -1) { |
@@ -133,10 +130,6 @@ void root_scratchpad_show(struct sway_container *con) { | |||
133 | 130 | ||
134 | arrange_workspace(new_ws); | 131 | arrange_workspace(new_ws); |
135 | seat_set_focus(seat, seat_get_focus_inactive(seat, &con->node)); | 132 | seat_set_focus(seat, seat_get_focus_inactive(seat, &con->node)); |
136 | |||
137 | if (new_ws != old_ws) { | ||
138 | ipc_event_window(con, "move"); | ||
139 | } | ||
140 | } | 133 | } |
141 | 134 | ||
142 | void root_scratchpad_hide(struct sway_container *con) { | 135 | void root_scratchpad_hide(struct sway_container *con) { |
diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 29b782bb..dbb593fb 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #define _POSIX_C_SOURCE 200809 | 1 | #define _POSIX_C_SOURCE 200809 |
2 | #include <limits.h> | 2 | #include <limits.h> |
3 | #include <stdio.h> | ||
3 | #include <string.h> | 4 | #include <string.h> |
4 | #include <strings.h> | 5 | #include <strings.h> |
5 | #include <json-c/json.h> | 6 | #include <json-c/json.h> |
@@ -9,6 +10,7 @@ | |||
9 | #include "ipc-client.h" | 10 | #include "ipc-client.h" |
10 | #include "list.h" | 11 | #include "list.h" |
11 | #include "log.h" | 12 | #include "log.h" |
13 | #include "util.h" | ||
12 | 14 | ||
13 | void ipc_send_workspace_command(struct swaybar *bar, const char *ws) { | 15 | void ipc_send_workspace_command(struct swaybar *bar, const char *ws) { |
14 | const char *fmt = "workspace \"%s\""; | 16 | const char *fmt = "workspace \"%s\""; |
@@ -372,15 +374,14 @@ bool ipc_get_workspaces(struct swaybar *bar) { | |||
372 | ws->label = strdup(ws->name); | 374 | ws->label = strdup(ws->name); |
373 | // ws->num will be -1 if workspace name doesn't begin with int. | 375 | // ws->num will be -1 if workspace name doesn't begin with int. |
374 | if (ws->num != -1) { | 376 | if (ws->num != -1) { |
375 | size_t len_offset = numlen(ws->num); | 377 | size_t len_offset = snprintf(NULL, 0, "%d", ws->num); |
376 | if (bar->config->strip_workspace_name) { | 378 | if (bar->config->strip_workspace_name) { |
377 | free(ws->label); | 379 | free(ws->label); |
378 | ws->label = malloc(len_offset + 1 * sizeof(char)); | 380 | ws->label = malloc(len_offset + 1); |
379 | ws->label[len_offset] = '\0'; | 381 | snprintf(ws->label, len_offset + 1, "%d", ws->num); |
380 | strncpy(ws->label, ws->name, len_offset); | ||
381 | } else if (bar->config->strip_workspace_numbers) { | 382 | } else if (bar->config->strip_workspace_numbers) { |
382 | len_offset += ws->label[len_offset] == ':'; | 383 | len_offset += ws->label[len_offset] == ':'; |
383 | if (strlen(ws->name) > len_offset) { | 384 | if (ws->name[len_offset] != '\0') { |
384 | free(ws->label); | 385 | free(ws->label); |
385 | // Strip number prefix [1-?:] using len_offset. | 386 | // Strip number prefix [1-?:] using len_offset. |
386 | ws->label = strdup(ws->name + len_offset); | 387 | ws->label = strdup(ws->name + len_offset); |