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