diff options
author | 2017-06-14 18:53:32 -0400 | |
---|---|---|
committer | 2017-06-14 18:53:32 -0400 | |
commit | eb6e38c86d2deb37cc6f378f8644c4a530fd7448 (patch) | |
tree | e3c567c4684faf0f9a7f77494f1bf638171d5349 /swaybar/bar.c | |
parent | Merge pull request #1236 from ykrivopalov/fix_complex_status_command (diff) | |
parent | Merge branch 'master' into tray (diff) | |
download | sway-eb6e38c86d2deb37cc6f378f8644c4a530fd7448.tar.gz sway-eb6e38c86d2deb37cc6f378f8644c4a530fd7448.tar.zst sway-eb6e38c86d2deb37cc6f378f8644c4a530fd7448.zip |
Implement Tray Icons
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r-- | swaybar/bar.c | 84 |
1 files changed, 50 insertions, 34 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index 5ed0d266..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" |
@@ -57,12 +64,15 @@ struct output *new_output(const char *name) { | |||
57 | output->window = NULL; | 64 | output->window = NULL; |
58 | output->registry = NULL; | 65 | output->registry = NULL; |
59 | output->workspaces = create_list(); | 66 | output->workspaces = create_list(); |
67 | #ifdef ENABLE_TRAY | ||
68 | output->items = create_list(); | ||
69 | #endif | ||
60 | return output; | 70 | return output; |
61 | } | 71 | } |
62 | 72 | ||
63 | 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, |
64 | uint32_t button, uint32_t state_w) { | 74 | uint32_t button, uint32_t state_w) { |
65 | 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); |
66 | if (!state_w) { | 76 | if (!state_w) { |
67 | return; | 77 | return; |
68 | } | 78 | } |
@@ -93,6 +103,10 @@ static void mouse_button_notify(struct window *window, int x, int y, | |||
93 | break; | 103 | break; |
94 | } | 104 | } |
95 | } | 105 | } |
106 | |||
107 | #ifdef ENABLE_TRAY | ||
108 | tray_mouse_event(clicked_output, x, y, button, state_w); | ||
109 | #endif | ||
96 | } | 110 | } |
97 | 111 | ||
98 | 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) { |
@@ -137,6 +151,9 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { | |||
137 | /* initialize bar with default values */ | 151 | /* initialize bar with default values */ |
138 | bar_init(bar); | 152 | bar_init(bar); |
139 | 153 | ||
154 | /* Initialize event loop lists */ | ||
155 | init_event_loop(); | ||
156 | |||
140 | /* connect to sway ipc */ | 157 | /* connect to sway ipc */ |
141 | bar->ipc_socketfd = ipc_open_socket(socket_path); | 158 | bar->ipc_socketfd = ipc_open_socket(socket_path); |
142 | bar->ipc_event_socketfd = ipc_open_socket(socket_path); | 159 | bar->ipc_event_socketfd = ipc_open_socket(socket_path); |
@@ -179,23 +196,41 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { | |||
179 | } | 196 | } |
180 | /* spawn status command */ | 197 | /* spawn status command */ |
181 | spawn_status_cmd_proc(bar); | 198 | spawn_status_cmd_proc(bar); |
199 | |||
200 | #ifdef ENABLE_TRAY | ||
201 | init_tray(bar); | ||
202 | #endif | ||
182 | } | 203 | } |
183 | 204 | ||
184 | void bar_run(struct bar *bar) { | 205 | bool dirty = true; |
185 | int pfds = bar->outputs->length + 2; | 206 | |
186 | struct pollfd *pfd = malloc(pfds * sizeof(struct pollfd)); | 207 | static void respond_ipc(int fd, short mask, void *_bar) { |
187 | 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 | } | ||
188 | 224 | ||
189 | pfd[0].fd = bar->ipc_event_socketfd; | 225 | void bar_run(struct bar *bar) { |
190 | pfd[0].events = POLLIN; | 226 | add_event(bar->ipc_event_socketfd, POLLIN, respond_ipc, bar); |
191 | pfd[1].fd = bar->status_read_fd; | 227 | add_event(bar->status_read_fd, POLLIN, respond_command, bar); |
192 | pfd[1].events = POLLIN; | ||
193 | 228 | ||
194 | int i; | 229 | int i; |
195 | for (i = 0; i < bar->outputs->length; ++i) { | 230 | for (i = 0; i < bar->outputs->length; ++i) { |
196 | struct output *output = bar->outputs->items[i]; | 231 | struct output *output = bar->outputs->items[i]; |
197 | pfd[i+2].fd = wl_display_get_fd(output->registry->display); | 232 | add_event(wl_display_get_fd(output->registry->display), |
198 | pfd[i+2].events = POLLIN; | 233 | POLLIN, respond_output, output); |
199 | } | 234 | } |
200 | 235 | ||
201 | while (1) { | 236 | while (1) { |
@@ -213,29 +248,10 @@ void bar_run(struct bar *bar) { | |||
213 | 248 | ||
214 | dirty = false; | 249 | dirty = false; |
215 | 250 | ||
216 | poll(pfd, pfds, -1); | 251 | event_loop_poll(); |
217 | 252 | #ifdef ENABLE_TRAY | |
218 | if (pfd[0].revents & POLLIN) { | 253 | dispatch_dbus(); |
219 | sway_log(L_DEBUG, "Got IPC event."); | 254 | #endif |
220 | dirty = handle_ipc_event(bar); | ||
221 | } | ||
222 | |||
223 | if (bar->config->status_command && pfd[1].revents & POLLIN) { | ||
224 | sway_log(L_DEBUG, "Got update from status command."); | ||
225 | dirty = handle_status_line(bar); | ||
226 | } | ||
227 | |||
228 | // dispatch wl_display events | ||
229 | for (i = 0; i < bar->outputs->length; ++i) { | ||
230 | struct output *output = bar->outputs->items[i]; | ||
231 | if (pfd[i+2].revents & POLLIN) { | ||
232 | if (wl_display_dispatch(output->registry->display) == -1) { | ||
233 | sway_log(L_ERROR, "failed to dispatch wl: %d", errno); | ||
234 | } | ||
235 | } else { | ||
236 | wl_display_dispatch_pending(output->registry->display); | ||
237 | } | ||
238 | } | ||
239 | } | 255 | } |
240 | } | 256 | } |
241 | 257 | ||