aboutsummaryrefslogtreecommitdiff
path: root/swaybar
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/ipc.c5
-rw-r--r--swaybar/render.c6
-rw-r--r--swaybar/tray/item.c5
-rw-r--r--swaybar/tray/watcher.c6
4 files changed, 12 insertions, 10 deletions
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 71c9a4c5..f651f035 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -15,6 +15,7 @@
#include "list.h"
#include "log.h"
#include "loop.h"
+#include "stringop.h"
#include "util.h"
void ipc_send_workspace_command(struct swaybar *bar, const char *ws) {
@@ -45,8 +46,8 @@ void ipc_send_workspace_command(struct swaybar *bar, const char *ws) {
char *parse_font(const char *font) {
char *new_font = NULL;
- if (strncmp("pango:", font, 6) == 0) {
- font += 6;
+ if (has_prefix("pango:", font)) {
+ font += strlen("pango:");
}
new_font = strdup(font);
return new_font;
diff --git a/swaybar/render.c b/swaybar/render.c
index 13cfdc97..45faefa9 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -293,11 +293,11 @@ static uint32_t render_status_block(struct render_context *ctx,
}
double offset = 0;
- if (strncmp(block->align, "left", 4) == 0) {
+ if (has_prefix(block->align, "left")) {
offset = x_pos;
- } else if (strncmp(block->align, "right", 5) == 0) {
+ } else if (has_prefix(block->align, "right")) {
offset = x_pos + width - text_width;
- } else if (strncmp(block->align, "center", 6) == 0) {
+ } else if (has_prefix(block->align, "center")) {
offset = x_pos + (width - text_width) / 2;
}
double text_y = height / 2.0 - text_height / 2.0;
diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c
index ca6c03ad..12929743 100644
--- a/swaybar/tray/item.c
+++ b/swaybar/tray/item.c
@@ -15,6 +15,7 @@
#include "cairo_util.h"
#include "list.h"
#include "log.h"
+#include "stringop.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
// TODO menu
@@ -161,7 +162,7 @@ static int get_property_callback(sd_bus_message *msg, void *data,
}
if (strcmp(prop, "Status") == 0 || (sni->status && (sni->status[0] == 'N' ?
- prop[0] == 'A' : strncmp(prop, "Icon", 4) == 0))) {
+ prop[0] == 'A' : has_prefix(prop, "Icon")))) {
set_sni_dirty(sni);
}
cleanup:
@@ -364,7 +365,7 @@ static void handle_click(struct swaybar_sni *sni, int x, int y,
method = "ContextMenu";
}
- if (strncmp(method, "Scroll", strlen("Scroll")) == 0) {
+ if (has_prefix(method, "Scroll")) {
char dir = method[strlen("Scroll")];
char *orientation = (dir == 'U' || dir == 'D') ? "vertical" : "horizontal";
int sign = (dir == 'U' || dir == 'L') ? -1 : 1;
diff --git a/swaybar/tray/watcher.c b/swaybar/tray/watcher.c
index 54f000bd..28496403 100644
--- a/swaybar/tray/watcher.c
+++ b/swaybar/tray/watcher.c
@@ -31,9 +31,9 @@ static int handle_lost_service(sd_bus_message *msg,
struct swaybar_watcher *watcher = data;
for (int idx = 0; idx < watcher->items->length; ++idx) {
char *id = watcher->items->items[idx];
- int cmp_res = using_standard_protocol(watcher) ?
- cmp_id(id, service) : strncmp(id, service, strlen(service));
- if (cmp_res == 0) {
+ bool cmp_res = using_standard_protocol(watcher) ?
+ cmp_id(id, service) == 0 : has_prefix(id, service);
+ if (cmp_res) {
sway_log(SWAY_DEBUG, "Unregistering Status Notifier Item '%s'", id);
list_del(watcher->items, idx--);
sd_bus_emit_signal(watcher->bus, obj_path, watcher->interface,