swaybar: save id upon startup

This adds an id property to the bar, which will be used to filter
barconfig_update events
This commit is contained in:
Ian Fan 2018-09-30 15:09:09 +01:00
parent 1f90f92f45
commit d0b54e932b
5 changed files with 13 additions and 13 deletions

View File

@ -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);

View File

@ -3,7 +3,7 @@
#include <stdbool.h>
#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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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);