diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-06-14 18:53:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-14 18:53:40 -0400 |
commit | 298f56353ef155f6a2ccc977c96b2ff5d971e65e (patch) | |
tree | dcb3b74f1dde93bce8657b7509662ffd7db667d0 /swaybar/bar.c | |
parent | Implement KDE's server-side decoration protocol (diff) | |
parent | Merge pull request #1234 from 4e554c4c/tray (diff) | |
download | sway-298f56353ef155f6a2ccc977c96b2ff5d971e65e.tar.gz sway-298f56353ef155f6a2ccc977c96b2ff5d971e65e.tar.zst sway-298f56353ef155f6a2ccc977c96b2ff5d971e65e.zip |
Merge branch 'master' into server-decoration
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 87 |
1 files changed, 52 insertions, 35 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index abde1cc9..3412ff29 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -7,10 +7,17 @@ | |||
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 | #ifdef ENABLE_TRAY | ||
11 | #include <dbus/dbus.h> | ||
12 | #include "swaybar/tray/sni_watcher.h" | ||
13 | #include "swaybar/tray/tray.h" | ||
14 | #include "swaybar/tray/sni.h" | ||
15 | #endif | ||
10 | #include "swaybar/ipc.h" | 16 | #include "swaybar/ipc.h" |
11 | #include "swaybar/render.h" | 17 | #include "swaybar/render.h" |
12 | #include "swaybar/config.h" | 18 | #include "swaybar/config.h" |
13 | #include "swaybar/status_line.h" | 19 | #include "swaybar/status_line.h" |
20 | #include "swaybar/event_loop.h" | ||
14 | #include "swaybar/bar.h" | 21 | #include "swaybar/bar.h" |
15 | #include "ipc-client.h" | 22 | #include "ipc-client.h" |
16 | #include "list.h" | 23 | #include "list.h" |
@@ -34,6 +41,7 @@ static void spawn_status_cmd_proc(struct bar *bar) { | |||
34 | close(pipefd[0]); | 41 | close(pipefd[0]); |
35 | dup2(pipefd[1], STDOUT_FILENO); | 42 | dup2(pipefd[1], STDOUT_FILENO); |
36 | close(pipefd[1]); | 43 | close(pipefd[1]); |
44 | setpgid(bar->status_command_pid, 0); | ||
37 | char *const cmd[] = { | 45 | char *const cmd[] = { |
38 | "sh", | 46 | "sh", |
39 | "-c", | 47 | "-c", |
@@ -56,12 +64,15 @@ struct output *new_output(const char *name) { | |||
56 | output->window = NULL; | 64 | output->window = NULL; |
57 | output->registry = NULL; | 65 | output->registry = NULL; |
58 | output->workspaces = create_list(); | 66 | output->workspaces = create_list(); |
67 | #ifdef ENABLE_TRAY | ||
68 | output->items = create_list(); | ||
69 | #endif | ||
59 | return output; | 70 | return output; |
60 | } | 71 | } |
61 | 72 | ||
62 | static void mouse_button_notify(struct window *window, int x, int y, | 73 | static void mouse_button_notify(struct window *window, int x, int y, |
63 | uint32_t button, uint32_t state_w) { | 74 | uint32_t button, uint32_t state_w) { |
64 | sway_log(L_DEBUG, "Mouse button %d clicked at %d %d %d\n", button, x, y, state_w); | 75 | sway_log(L_DEBUG, "Mouse button %d clicked at %d %d %d", button, x, y, state_w); |
65 | if (!state_w) { | 76 | if (!state_w) { |
66 | return; | 77 | return; |
67 | } | 78 | } |
@@ -92,6 +103,10 @@ static void mouse_button_notify(struct window *window, int x, int y, | |||
92 | break; | 103 | break; |
93 | } | 104 | } |
94 | } | 105 | } |
106 | |||
107 | #ifdef ENABLE_TRAY | ||
108 | tray_mouse_event(clicked_output, x, y, button, state_w); | ||
109 | #endif | ||
95 | } | 110 | } |
96 | 111 | ||
97 | static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) { | 112 | static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) { |
@@ -136,6 +151,9 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { | |||
136 | /* initialize bar with default values */ | 151 | /* initialize bar with default values */ |
137 | bar_init(bar); | 152 | bar_init(bar); |
138 | 153 | ||
154 | /* Initialize event loop lists */ | ||
155 | init_event_loop(); | ||
156 | |||
139 | /* connect to sway ipc */ | 157 | /* connect to sway ipc */ |
140 | bar->ipc_socketfd = ipc_open_socket(socket_path); | 158 | bar->ipc_socketfd = ipc_open_socket(socket_path); |
141 | bar->ipc_event_socketfd = ipc_open_socket(socket_path); | 159 | bar->ipc_event_socketfd = ipc_open_socket(socket_path); |
@@ -178,23 +196,41 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { | |||
178 | } | 196 | } |
179 | /* spawn status command */ | 197 | /* spawn status command */ |
180 | spawn_status_cmd_proc(bar); | 198 | spawn_status_cmd_proc(bar); |
199 | |||
200 | #ifdef ENABLE_TRAY | ||
201 | init_tray(bar); | ||
202 | #endif | ||
181 | } | 203 | } |
182 | 204 | ||
183 | void bar_run(struct bar *bar) { | 205 | bool dirty = true; |
184 | int pfds = bar->outputs->length + 2; | 206 | |
185 | struct pollfd *pfd = malloc(pfds * sizeof(struct pollfd)); | 207 | static void respond_ipc(int fd, short mask, void *_bar) { |
186 | bool dirty = true; | 208 | struct bar *bar = (struct bar *)_bar; |
209 | sway_log(L_DEBUG, "Got IPC event."); | ||
210 | dirty = handle_ipc_event(bar); | ||
211 | } | ||
212 | |||
213 | static void respond_command(int fd, short mask, void *_bar) { | ||
214 | struct bar *bar = (struct bar *)_bar; | ||
215 | dirty = handle_status_line(bar); | ||
216 | } | ||
217 | |||
218 | static void respond_output(int fd, short mask, void *_output) { | ||
219 | struct output *output = (struct output *)_output; | ||
220 | if (wl_display_dispatch(output->registry->display) == -1) { | ||
221 | sway_log(L_ERROR, "failed to dispatch wl: %d", errno); | ||
222 | } | ||
223 | } | ||
187 | 224 | ||
188 | pfd[0].fd = bar->ipc_event_socketfd; | 225 | void bar_run(struct bar *bar) { |
189 | pfd[0].events = POLLIN; | 226 | add_event(bar->ipc_event_socketfd, POLLIN, respond_ipc, bar); |
190 | pfd[1].fd = bar->status_read_fd; | 227 | add_event(bar->status_read_fd, POLLIN, respond_command, bar); |
191 | pfd[1].events = POLLIN; | ||
192 | 228 | ||
193 | int i; | 229 | int i; |
194 | for (i = 0; i < bar->outputs->length; ++i) { | 230 | for (i = 0; i < bar->outputs->length; ++i) { |
195 | struct output *output = bar->outputs->items[i]; | 231 | struct output *output = bar->outputs->items[i]; |
196 | pfd[i+2].fd = wl_display_get_fd(output->registry->display); | 232 | add_event(wl_display_get_fd(output->registry->display), |
197 | pfd[i+2].events = POLLIN; | 233 | POLLIN, respond_output, output); |
198 | } | 234 | } |
199 | 235 | ||
200 | while (1) { | 236 | while (1) { |
@@ -212,29 +248,10 @@ void bar_run(struct bar *bar) { | |||
212 | 248 | ||
213 | dirty = false; | 249 | dirty = false; |
214 | 250 | ||
215 | poll(pfd, pfds, -1); | 251 | event_loop_poll(); |
216 | 252 | #ifdef ENABLE_TRAY | |
217 | if (pfd[0].revents & POLLIN) { | 253 | dispatch_dbus(); |
218 | sway_log(L_DEBUG, "Got IPC event."); | 254 | #endif |
219 | dirty = handle_ipc_event(bar); | ||
220 | } | ||
221 | |||
222 | if (bar->config->status_command && pfd[1].revents & POLLIN) { | ||
223 | sway_log(L_DEBUG, "Got update from status command."); | ||
224 | dirty = handle_status_line(bar); | ||
225 | } | ||
226 | |||
227 | // dispatch wl_display events | ||
228 | for (i = 0; i < bar->outputs->length; ++i) { | ||
229 | struct output *output = bar->outputs->items[i]; | ||
230 | if (pfd[i+2].revents & POLLIN) { | ||
231 | if (wl_display_dispatch(output->registry->display) == -1) { | ||
232 | sway_log(L_ERROR, "failed to dispatch wl: %d", errno); | ||
233 | } | ||
234 | } else { | ||
235 | wl_display_dispatch_pending(output->registry->display); | ||
236 | } | ||
237 | } | ||
238 | } | 255 | } |
239 | } | 256 | } |
240 | 257 | ||
@@ -274,7 +291,7 @@ static void free_outputs(list_t *outputs) { | |||
274 | static void terminate_status_command(pid_t pid) { | 291 | static void terminate_status_command(pid_t pid) { |
275 | if (pid) { | 292 | if (pid) { |
276 | // terminate status_command process | 293 | // terminate status_command process |
277 | int ret = kill(pid, SIGTERM); | 294 | int ret = killpg(pid, SIGTERM); |
278 | if (ret != 0) { | 295 | if (ret != 0) { |
279 | sway_log(L_ERROR, "Unable to terminate status_command [pid: %d]", pid); | 296 | sway_log(L_ERROR, "Unable to terminate status_command [pid: %d]", pid); |
280 | } else { | 297 | } else { |