diff options
author | 2017-08-30 17:45:43 -0500 | |
---|---|---|
committer | 2017-08-30 17:45:43 -0500 | |
commit | 82d6afc91d270f3761588b54a46b7f8fbbacaa3f (patch) | |
tree | df50d6f095cbeeb5256527245c5e1adeb51b6860 /swaybar/bar.c | |
parent | Merge pull request #1247 from clarcharr/master (diff) | |
parent | styling fixes (diff) | |
download | sway-82d6afc91d270f3761588b54a46b7f8fbbacaa3f.tar.gz sway-82d6afc91d270f3761588b54a46b7f8fbbacaa3f.tar.zst sway-82d6afc91d270f3761588b54a46b7f8fbbacaa3f.zip |
Merge pull request #1336 from akokshar/master
click_events
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 5e87eac9..85cb5270 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,9 +122,22 @@ 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) { |
@@ -318,6 +350,10 @@ void bar_teardown(struct bar *bar) { | |||
318 | close(bar->status_read_fd); | 350 | close(bar->status_read_fd); |
319 | } | 351 | } |
320 | 352 | ||
353 | if (bar->status_write_fd) { | ||
354 | close(bar->status_write_fd); | ||
355 | } | ||
356 | |||
321 | if (bar->ipc_socketfd) { | 357 | if (bar->ipc_socketfd) { |
322 | close(bar->ipc_socketfd); | 358 | close(bar->ipc_socketfd); |
323 | } | 359 | } |