From d0b54e932b59baa71b54d842b249400db74ce79b Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Sun, 30 Sep 2018 15:09:09 +0100 Subject: [PATCH] swaybar: save id upon startup This adds an id property to the bar, which will be used to filter barconfig_update events --- include/swaybar/bar.h | 4 +++- include/swaybar/ipc.h | 2 +- swaybar/bar.c | 6 +++--- swaybar/ipc.c | 6 +++--- swaybar/main.c | 8 +++----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index de2341118..d29db31e5 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -46,6 +46,8 @@ struct swaybar_hotspot { }; struct swaybar { + char *id; + struct wl_display *display; struct wl_compositor *compositor; struct zwlr_layer_shell_v1 *layer_shell; @@ -96,7 +98,7 @@ struct swaybar_workspace { bool urgent; }; -bool bar_setup(struct swaybar *bar, const char *socket_path, const char *bar_id); +bool bar_setup(struct swaybar *bar, const char *socket_path); void bar_run(struct swaybar *bar); void bar_teardown(struct swaybar *bar); diff --git a/include/swaybar/ipc.h b/include/swaybar/ipc.h index 8731dac2a..51db85b55 100644 --- a/include/swaybar/ipc.h +++ b/include/swaybar/ipc.h @@ -3,7 +3,7 @@ #include #include "swaybar/bar.h" -bool ipc_initialize(struct swaybar *bar, const char *bar_id); +bool ipc_initialize(struct swaybar *bar); bool handle_ipc_readable(struct swaybar *bar); void ipc_get_workspaces(struct swaybar *bar); void ipc_send_workspace_command(struct swaybar *bar, const char *ws); diff --git a/swaybar/bar.c b/swaybar/bar.c index 5b7fea717..f2dab7383 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -517,14 +517,13 @@ static void set_bar_dirty(struct swaybar *bar) { } } -bool bar_setup(struct swaybar *bar, - const char *socket_path, const char *bar_id) { +bool bar_setup(struct swaybar *bar, const char *socket_path) { bar_init(bar); init_event_loop(); bar->ipc_socketfd = ipc_open_socket(socket_path); bar->ipc_event_socketfd = ipc_open_socket(socket_path); - if (!ipc_initialize(bar, bar_id)) { + if (!ipc_initialize(bar)) { return false; } if (bar->config->status_command) { @@ -625,4 +624,5 @@ void bar_teardown(struct swaybar *bar) { if (bar->status) { status_line_free(bar->status); } + free(bar->id); } diff --git a/swaybar/ipc.c b/swaybar/ipc.c index a67814c11..84046ab57 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -345,10 +345,10 @@ void ipc_execute_binding(struct swaybar *bar, struct swaybar_binding *bind) { IPC_COMMAND, bind->command, &len)); } -bool ipc_initialize(struct swaybar *bar, const char *bar_id) { - uint32_t len = strlen(bar_id); +bool ipc_initialize(struct swaybar *bar) { + uint32_t len = strlen(bar->id); char *res = ipc_single_command(bar->ipc_socketfd, - IPC_GET_BAR_CONFIG, bar_id, &len); + IPC_GET_BAR_CONFIG, bar->id, &len); if (!ipc_parse_config(bar->config, res)) { free(res); return false; diff --git a/swaybar/main.c b/swaybar/main.c index db204f4a8..2672abefc 100644 --- a/swaybar/main.c +++ b/swaybar/main.c @@ -22,7 +22,6 @@ void sway_terminate(int code) { int main(int argc, char **argv) { char *socket_path = NULL; - char *bar_id = NULL; bool debug = false; static struct option long_options[] = { @@ -59,7 +58,7 @@ int main(int argc, char **argv) { socket_path = strdup(optarg); break; case 'b': // Type - bar_id = strdup(optarg); + swaybar.id = strdup(optarg); break; case 'v': fprintf(stdout, "swaybar version " SWAY_VERSION "\n"); @@ -80,7 +79,7 @@ int main(int argc, char **argv) { wlr_log_init(WLR_ERROR, NULL); } - if (!bar_id) { + if (!swaybar.id) { wlr_log(WLR_ERROR, "No bar_id passed. " "Provide --bar_id or let sway start swaybar"); return 1; @@ -96,13 +95,12 @@ int main(int argc, char **argv) { signal(SIGTERM, sig_handler); - if (!bar_setup(&swaybar, socket_path, bar_id)) { + if (!bar_setup(&swaybar, socket_path)) { free(socket_path); return 1; } free(socket_path); - free(bar_id); bar_run(&swaybar); bar_teardown(&swaybar);