aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/util.c9
-rw-r--r--include/util.h5
-rw-r--r--sway/commands/bar.c4
-rw-r--r--sway/commands/move.c1
-rw-r--r--sway/commands/scratchpad.c4
-rw-r--r--sway/tree/root.c7
-rw-r--r--swaybar/ipc.c11
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) {
return ((i % max) + max) % max;
}
-int numlen(int n) {
- int j = n <= 0 ? 1 : 0;
- while (n) {
- j++;
- n /= 10;
- }
- return j;
-}
-
uint32_t parse_color(const char *color) {
if (color[0] == '#') {
++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 @@
int wrap(int i, int max);
/**
- * Count number of digits in int, including '-' sign if there is one
- */
-int numlen(int n);
-
-/**
* Given a string that represents an RGB(A) color, return a uint32_t
* version of the color.
*/
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 @@
#define _POSIX_C_SOURCE 200809
+#include <stdio.h>
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
#include "sway/config.h"
#include "log.h"
-#include "util.h"
// Must be in alphabetical order for bsearch
static struct cmd_handler bar_handlers[] = {
@@ -89,7 +89,7 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
}
// set bar id
- const int len = 5 + numlen(config->bars->length - 1); // "bar-"+i+\0
+ const int len = snprintf(NULL, 0, "bar-%d", config->bars->length - 1) + 1;
bar->id = malloc(len * sizeof(char));
if (bar->id) {
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) {
// move container
if (container->scratchpad) {
root_scratchpad_remove_container(container);
+ root_scratchpad_show(container);
}
switch (destination->type) {
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 @@
#include "sway/config.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
+#include "sway/ipc-server.h"
#include "sway/tree/container.h"
#include "sway/tree/root.h"
#include "sway/tree/workspace.h"
@@ -51,6 +52,7 @@ static void scratchpad_toggle_auto(void) {
"Moving a visible scratchpad window (%s) to this workspace",
con->title);
root_scratchpad_show(con);
+ ipc_event_window(con, "move");
return;
}
}
@@ -62,6 +64,7 @@ static void scratchpad_toggle_auto(void) {
struct sway_container *con = root->scratchpad->items[0];
sway_log(SWAY_DEBUG, "Showing %s from list", con->title);
root_scratchpad_show(con);
+ ipc_event_window(con, "move");
}
static void scratchpad_toggle_container(struct sway_container *con) {
@@ -76,6 +79,7 @@ static void scratchpad_toggle_container(struct sway_container *con) {
}
root_scratchpad_show(con);
+ ipc_event_window(con, "move");
}
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) {
if (!sway_assert(con->scratchpad, "Container is not in scratchpad")) {
return;
}
- if (!con->workspace) {
- root_scratchpad_show(con);
- }
con->scratchpad = false;
int index = list_find(root->scratchpad, con);
if (index != -1) {
@@ -133,10 +130,6 @@ void root_scratchpad_show(struct sway_container *con) {
arrange_workspace(new_ws);
seat_set_focus(seat, seat_get_focus_inactive(seat, &con->node));
-
- if (new_ws != old_ws) {
- ipc_event_window(con, "move");
- }
}
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 @@
#define _POSIX_C_SOURCE 200809
#include <limits.h>
+#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <json-c/json.h>
@@ -9,6 +10,7 @@
#include "ipc-client.h"
#include "list.h"
#include "log.h"
+#include "util.h"
void ipc_send_workspace_command(struct swaybar *bar, const char *ws) {
const char *fmt = "workspace \"%s\"";
@@ -372,15 +374,14 @@ bool ipc_get_workspaces(struct swaybar *bar) {
ws->label = strdup(ws->name);
// ws->num will be -1 if workspace name doesn't begin with int.
if (ws->num != -1) {
- size_t len_offset = numlen(ws->num);
+ size_t len_offset = snprintf(NULL, 0, "%d", ws->num);
if (bar->config->strip_workspace_name) {
free(ws->label);
- ws->label = malloc(len_offset + 1 * sizeof(char));
- ws->label[len_offset] = '\0';
- strncpy(ws->label, ws->name, len_offset);
+ ws->label = malloc(len_offset + 1);
+ snprintf(ws->label, len_offset + 1, "%d", ws->num);
} else if (bar->config->strip_workspace_numbers) {
len_offset += ws->label[len_offset] == ':';
- if (strlen(ws->name) > len_offset) {
+ if (ws->name[len_offset] != '\0') {
free(ws->label);
// Strip number prefix [1-?:] using len_offset.
ws->label = strdup(ws->name + len_offset);