replaced strcmp for command strings with a pointer cmd to where the command should be in sockbuf, and repeated ADVANCE_IF_LAST_RET() to set wordbeg to the xdg_output_name

This commit is contained in:
samjjacko 2025-07-24 18:06:18 +08:00
parent 48dbe00bdb
commit 5221e192f3

22
dwlb.c
View File

@ -1463,6 +1463,10 @@ read_socket(void)
ADVANCE_IF_LAST_RET();
char *cmd = wordbeg;
ADVANCE_IF_LAST_RET();
Bar *bar = NULL, *it;
bool all = false;
@ -1489,7 +1493,7 @@ read_socket(void)
ADVANCE();
if (!strcmp(wordbeg, "status")) {
if (!strcmp(cmd, "status")) {
if (!*wordend)
return;
if (all) {
@ -1507,7 +1511,7 @@ read_socket(void)
parse_into_customtext(&bar->status, wordend);
bar->redraw = true;
}
} else if (!strcmp(wordbeg, "title")) {
} else if (!strcmp(cmd, "title")) {
if (!custom_title || !*wordend)
return;
if (all) {
@ -1525,7 +1529,7 @@ read_socket(void)
parse_into_customtext(&bar->title, wordend);
bar->redraw = true;
}
} else if (!strcmp(wordbeg, "show")) {
} else if (!strcmp(cmd, "show")) {
if (all) {
wl_list_for_each(bar, &bar_list, link)
if (bar->hidden)
@ -1534,7 +1538,7 @@ read_socket(void)
if (bar->hidden)
show_bar(bar);
}
} else if (!strcmp(wordbeg, "hide")) {
} else if (!strcmp(cmd, "hide")) {
if (all) {
wl_list_for_each(bar, &bar_list, link)
if (!bar->hidden)
@ -1543,7 +1547,7 @@ read_socket(void)
if (!bar->hidden)
hide_bar(bar);
}
} else if (!strcmp(wordbeg, "toggle-visibility")) {
} else if (!strcmp(cmd, "toggle-visibility")) {
if (all) {
wl_list_for_each(bar, &bar_list, link)
if (bar->hidden)
@ -1556,27 +1560,25 @@ read_socket(void)
else
hide_bar(bar);
}
} else if (!strcmp(wordbeg, "set-top")) {
} else if (!strcmp(cmd, "set-top")) {
if (all) {
wl_list_for_each(bar, &bar_list, link)
if (bar->bottom)
set_top(bar);
} else {
if (bar->bottom)
set_top(bar);
}
} else if (!strcmp(wordbeg, "set-bottom")) {
} else if (!strcmp(cmd, "set-bottom")) {
if (all) {
wl_list_for_each(bar, &bar_list, link)
if (!bar->bottom)
set_bottom(bar);
} else {
if (!bar->bottom)
set_bottom(bar);
}
} else if (!strcmp(wordbeg, "toggle-location")) {
} else if (!strcmp(cmd, "toggle-location")) {
if (all) {
wl_list_for_each(bar, &bar_list, link)
if (bar->bottom)