diff options
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 71 |
1 files changed, 63 insertions, 8 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 5e87eac9..f8dc3a1f 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <sys/wait.h> | 7 | #include <sys/wait.h> |
8 | #include <signal.h> | 8 | #include <signal.h> |
9 | #include <poll.h> | 9 | #include <poll.h> |
10 | #include <linux/input-event-codes.h> | ||
10 | #ifdef ENABLE_TRAY | 11 | #ifdef ENABLE_TRAY |
11 | #include <dbus/dbus.h> | 12 | #include <dbus/dbus.h> |
12 | #include "swaybar/tray/sni_watcher.h" | 13 | #include "swaybar/tray/sni_watcher.h" |
@@ -31,16 +32,30 @@ static void bar_init(struct bar *bar) { | |||
31 | 32 | ||
32 | static void spawn_status_cmd_proc(struct bar *bar) { | 33 | static void spawn_status_cmd_proc(struct bar *bar) { |
33 | if (bar->config->status_command) { | 34 | if (bar->config->status_command) { |
34 | int pipefd[2]; | 35 | int pipe_read_fd[2]; |
35 | if (pipe(pipefd) != 0) { | 36 | int pipe_write_fd[2]; |
36 | sway_log(L_ERROR, "Unable to create pipe for status_command fork"); | 37 | |
38 | if (pipe(pipe_read_fd) != 0) { | ||
39 | sway_log(L_ERROR, "Unable to create pipes for status_command fork"); | ||
40 | return; | ||
41 | } | ||
42 | if (pipe(pipe_write_fd) != 0) { | ||
43 | sway_log(L_ERROR, "Unable to create pipe for status_command fork (write)"); | ||
44 | close(pipe_read_fd[0]); | ||
45 | close(pipe_read_fd[1]); | ||
37 | return; | 46 | return; |
38 | } | 47 | } |
48 | |||
39 | bar->status_command_pid = fork(); | 49 | bar->status_command_pid = fork(); |
40 | if (bar->status_command_pid == 0) { | 50 | if (bar->status_command_pid == 0) { |
41 | close(pipefd[0]); | 51 | close(pipe_read_fd[0]); |
42 | dup2(pipefd[1], STDOUT_FILENO); | 52 | dup2(pipe_read_fd[1], STDOUT_FILENO); |
43 | close(pipefd[1]); | 53 | close(pipe_read_fd[1]); |
54 | |||
55 | dup2(pipe_write_fd[0], STDIN_FILENO); | ||
56 | close(pipe_write_fd[0]); | ||
57 | close(pipe_write_fd[1]); | ||
58 | |||
44 | char *const cmd[] = { | 59 | char *const cmd[] = { |
45 | "sh", | 60 | "sh", |
46 | "-c", | 61 | "-c", |
@@ -51,9 +66,13 @@ static void spawn_status_cmd_proc(struct bar *bar) { | |||
51 | return; | 66 | return; |
52 | } | 67 | } |
53 | 68 | ||
54 | close(pipefd[1]); | 69 | close(pipe_read_fd[1]); |
55 | bar->status_read_fd = pipefd[0]; | 70 | bar->status_read_fd = pipe_read_fd[0]; |
56 | fcntl(bar->status_read_fd, F_SETFL, O_NONBLOCK); | 71 | fcntl(bar->status_read_fd, F_SETFL, O_NONBLOCK); |
72 | |||
73 | close(pipe_write_fd[0]); | ||
74 | bar->status_write_fd = pipe_write_fd[1]; | ||
75 | fcntl(bar->status_write_fd, F_SETFL, O_NONBLOCK); | ||
57 | } | 76 | } |
58 | } | 77 | } |
59 | 78 | ||
@@ -103,14 +122,46 @@ static void mouse_button_notify(struct window *window, int x, int y, | |||
103 | } | 122 | } |
104 | } | 123 | } |
105 | 124 | ||
125 | switch (button) { | ||
126 | case BTN_LEFT: | ||
127 | status_line_mouse_event(&swaybar, x, y, 1); | ||
128 | break; | ||
129 | case BTN_MIDDLE: | ||
130 | status_line_mouse_event(&swaybar, x, y, 2); | ||
131 | break; | ||
132 | case BTN_RIGHT: | ||
133 | status_line_mouse_event(&swaybar, x, y, 3); | ||
134 | break; | ||
135 | } | ||
136 | |||
106 | #ifdef ENABLE_TRAY | 137 | #ifdef ENABLE_TRAY |
107 | tray_mouse_event(clicked_output, x, y, button, state_w); | 138 | tray_mouse_event(clicked_output, x, y, button, state_w); |
108 | #endif | 139 | #endif |
140 | |||
109 | } | 141 | } |
110 | 142 | ||
111 | static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) { | 143 | static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) { |
112 | sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down"); | 144 | sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down"); |
113 | 145 | ||
146 | // If there are status blocks and click_events are enabled | ||
147 | // check if the position is within the status area and if so | ||
148 | // tell the status line to output the event and skip workspace | ||
149 | // switching below. | ||
150 | int num_blocks = swaybar.status->block_line->length; | ||
151 | if (swaybar.status->click_events && num_blocks > 0) { | ||
152 | struct status_block *first_block = swaybar.status->block_line->items[0]; | ||
153 | int x = window->pointer_input.last_x; | ||
154 | int y = window->pointer_input.last_y; | ||
155 | if (x > first_block->x) { | ||
156 | if (direction == SCROLL_UP) { | ||
157 | status_line_mouse_event(&swaybar, x, y, 4); | ||
158 | } else { | ||
159 | status_line_mouse_event(&swaybar, x, y, 5); | ||
160 | } | ||
161 | return; | ||
162 | } | ||
163 | } | ||
164 | |||
114 | if (!swaybar.config->wrap_scroll) { | 165 | if (!swaybar.config->wrap_scroll) { |
115 | // Find output this window lives on | 166 | // Find output this window lives on |
116 | int i; | 167 | int i; |
@@ -318,6 +369,10 @@ void bar_teardown(struct bar *bar) { | |||
318 | close(bar->status_read_fd); | 369 | close(bar->status_read_fd); |
319 | } | 370 | } |
320 | 371 | ||
372 | if (bar->status_write_fd) { | ||
373 | close(bar->status_write_fd); | ||
374 | } | ||
375 | |||
321 | if (bar->ipc_socketfd) { | 376 | if (bar->ipc_socketfd) { |
322 | close(bar->ipc_socketfd); | 377 | close(bar->ipc_socketfd); |
323 | } | 378 | } |