mirror of
https://github.com/swaywm/sway.git
synced 2025-11-19 06:59:52 -05:00
Use has_prefix() instead of strncmp() throughout
This is safer than hardcoded string lengths.
This commit is contained in:
parent
c55dff95bc
commit
0c60d1581f
19 changed files with 44 additions and 49 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue