From 65022e1cbf0ccf8764dcef7e2a738feb3331deeb Mon Sep 17 00:00:00 2001 From: "akokshar@redhat.com" Date: Tue, 29 Aug 2017 11:19:43 +0200 Subject: click_events as documented at https://i3wm.org/docs/i3bar-protocol.html --- swaybar/bar.c | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'swaybar/bar.c') diff --git a/swaybar/bar.c b/swaybar/bar.c index 5e87eac9..89f7c8c1 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -7,6 +7,7 @@ #include #include #include +#include #ifdef ENABLE_TRAY #include #include "swaybar/tray/sni_watcher.h" @@ -31,16 +32,30 @@ static void bar_init(struct bar *bar) { static void spawn_status_cmd_proc(struct bar *bar) { if (bar->config->status_command) { - int pipefd[2]; - if (pipe(pipefd) != 0) { - sway_log(L_ERROR, "Unable to create pipe for status_command fork"); + int pipe_read_fd[2]; + int pipe_write_fd[2]; + + if (pipe(pipe_read_fd) != 0) { + sway_log(L_ERROR, "Unable to create pipes for status_command fork"); + return; + } + if (pipe(pipe_write_fd) != 0) { + sway_log(L_ERROR, "Unable to create pipe for status_command fork (write)"); + close(pipe_read_fd[0]); + close(pipe_read_fd[1]); return; } + bar->status_command_pid = fork(); if (bar->status_command_pid == 0) { - close(pipefd[0]); - dup2(pipefd[1], STDOUT_FILENO); - close(pipefd[1]); + close(pipe_read_fd[0]); + dup2(pipe_read_fd[1], STDOUT_FILENO); + close(pipe_read_fd[1]); + + dup2(pipe_write_fd[0], STDIN_FILENO); + close(pipe_write_fd[0]); + close(pipe_write_fd[1]); + char *const cmd[] = { "sh", "-c", @@ -51,9 +66,13 @@ static void spawn_status_cmd_proc(struct bar *bar) { return; } - close(pipefd[1]); - bar->status_read_fd = pipefd[0]; + close(pipe_read_fd[1]); + bar->status_read_fd = pipe_read_fd[0]; fcntl(bar->status_read_fd, F_SETFL, O_NONBLOCK); + + close(pipe_write_fd[0]); + bar->status_write_fd = pipe_write_fd[1]; + fcntl(bar->status_write_fd, F_SETFL, O_NONBLOCK); } } @@ -103,9 +122,22 @@ static void mouse_button_notify(struct window *window, int x, int y, } } + switch (button) { + case BTN_LEFT: + status_line_mouse_event(&swaybar, x, y, 1); + break; + case BTN_MIDDLE: + status_line_mouse_event(&swaybar, x, y, 2); + break; + case BTN_RIGHT: + status_line_mouse_event(&swaybar, x, y, 3); + break; + } + #ifdef ENABLE_TRAY tray_mouse_event(clicked_output, x, y, button, state_w); #endif + } static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) { @@ -318,6 +350,10 @@ void bar_teardown(struct bar *bar) { close(bar->status_read_fd); } + if (bar->status_write_fd) { + close(bar->status_write_fd); + } + if (bar->ipc_socketfd) { close(bar->ipc_socketfd); } -- cgit v1.2.3-70-g09d2 From 39df3aed821d32644780df2875390a259941e353 Mon Sep 17 00:00:00 2001 From: "akokshar@redhat.com" Date: Tue, 29 Aug 2017 17:33:06 +0200 Subject: styling fixes --- swaybar/bar.c | 18 +++++++++--------- swaybar/render.c | 4 ++-- swaybar/status_line.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'swaybar/bar.c') diff --git a/swaybar/bar.c b/swaybar/bar.c index 89f7c8c1..85cb5270 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -123,15 +123,15 @@ static void mouse_button_notify(struct window *window, int x, int y, } switch (button) { - case BTN_LEFT: - status_line_mouse_event(&swaybar, x, y, 1); - break; - case BTN_MIDDLE: - status_line_mouse_event(&swaybar, x, y, 2); - break; - case BTN_RIGHT: - status_line_mouse_event(&swaybar, x, y, 3); - break; + case BTN_LEFT: + status_line_mouse_event(&swaybar, x, y, 1); + break; + case BTN_MIDDLE: + status_line_mouse_event(&swaybar, x, y, 2); + break; + case BTN_RIGHT: + status_line_mouse_event(&swaybar, x, y, 3); + break; } #ifdef ENABLE_TRAY diff --git a/swaybar/render.c b/swaybar/render.c index 232d254b..6fc09078 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -94,8 +94,8 @@ static void render_block(struct window *window, struct config *config, struct st double pos = *x; - block->x = (int) pos; - block->width = (int) block_width; + block->x = (int)pos; + block->width = (int)block_width; // render background if (block->background != 0x0) { diff --git a/swaybar/status_line.c b/swaybar/status_line.c index f3bb3013..7da311ac 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c @@ -492,7 +492,7 @@ bool handle_status_line(struct bar *bar) { json_object *click_events; if (json_object_object_get_ex(proto, "click_events", &click_events) - && json_object_get_boolean(click_events) + && json_object_get_boolean(click_events) == true ) { sway_log(L_DEBUG, "Enabling click events."); bar->status->click_events = true; -- cgit v1.2.3-70-g09d2