summaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorLibravatar Calvin Lee <cyrus296@gmail.com>2017-06-07 21:32:48 -0700
committerLibravatar Calvin Lee <cyrus296@gmail.com>2017-06-07 21:32:48 -0700
commit1451ee8fd13dd35227d11e393c80871c70ad90f0 (patch)
tree74a34de797c46c2734751d77b4dc4ac5694af9a7 /swaybar/bar.c
parentFix cairo blending on tray icons (diff)
downloadsway-1451ee8fd13dd35227d11e393c80871c70ad90f0.tar.gz
sway-1451ee8fd13dd35227d11e393c80871c70ad90f0.tar.zst
sway-1451ee8fd13dd35227d11e393c80871c70ad90f0.zip
Reorganize Tray Code
Remove tray code from bar.c and render.c
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c60
1 files changed, 7 insertions, 53 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index cdaf6a37..5d480b63 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -27,6 +27,9 @@ static void bar_init(struct bar *bar) {
27 bar->config = init_config(); 27 bar->config = init_config();
28 bar->status = init_status_line(); 28 bar->status = init_status_line();
29 bar->outputs = create_list(); 29 bar->outputs = create_list();
30#ifdef ENABLE_TRAY
31 bar->xembed_pid = 0;
32#endif
30} 33}
31 34
32static void spawn_status_cmd_proc(struct bar *bar) { 35static void spawn_status_cmd_proc(struct bar *bar) {
@@ -57,24 +60,6 @@ static void spawn_status_cmd_proc(struct bar *bar) {
57 } 60 }
58} 61}
59 62
60#ifdef ENABLE_TRAY
61static void spawn_xembed_sni_proxy() {
62 pid_t pid = fork();
63 if (pid == 0) {
64 int wstatus;
65 do {
66 pid = fork();
67 if (pid == 0) {
68 execlp("xembedsniproxy", "xembedsniproxy", NULL);
69 _exit(EXIT_FAILURE);
70 }
71 waitpid(pid, &wstatus, 0);
72 } while (!WIFEXITED(wstatus));
73 _exit(EXIT_FAILURE);
74 }
75}
76#endif
77
78struct output *new_output(const char *name) { 63struct output *new_output(const char *name) {
79 struct output *output = malloc(sizeof(struct output)); 64 struct output *output = malloc(sizeof(struct output));
80 output->name = strdup(name); 65 output->name = strdup(name);
@@ -122,27 +107,7 @@ static void mouse_button_notify(struct window *window, int x, int y,
122 } 107 }
123 108
124#ifdef ENABLE_TRAY 109#ifdef ENABLE_TRAY
125 uint32_t tray_padding = swaybar.config->tray_padding; 110 tray_mouse_event(clicked_output, x, y, button, state_w);
126 int tray_width = window->width * window->scale;
127
128 for (int i = 0; i < clicked_output->items->length; ++i) {
129 struct sni_icon_ref *item =
130 clicked_output->items->items[i];
131 int icon_width = cairo_image_surface_get_width(item->icon);
132
133 tray_width -= tray_padding;
134 if (x <= tray_width && x >= tray_width - icon_width) {
135 if (button == swaybar.config->activate_button) {
136 sni_activate(item->ref, x, y);
137 } else if (button == swaybar.config->context_button) {
138 sni_context_menu(item->ref, x, y);
139 } else if (button == swaybar.config->secondary_button) {
140 sni_secondary(item->ref, x, y);
141 }
142 break;
143 }
144 tray_width -= icon_width;
145 }
146#endif 111#endif
147} 112}
148 113
@@ -235,20 +200,7 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
235 spawn_status_cmd_proc(bar); 200 spawn_status_cmd_proc(bar);
236 201
237#ifdef ENABLE_TRAY 202#ifdef ENABLE_TRAY
238 // We should have at least one output to serve the tray to 203 init_tray(bar);
239 if (!swaybar.config->tray_output || strcmp(swaybar.config->tray_output, "none") != 0) {
240 /* Connect to the D-Bus */
241 dbus_init();
242
243 /* Start the SNI watcher */
244 init_sni_watcher();
245
246 /* Start the SNI host */
247 init_tray();
248
249 /* Start xembedsniproxy */
250 spawn_xembed_sni_proxy();
251 }
252#endif 204#endif
253} 205}
254 206
@@ -300,6 +252,8 @@ void bar_run(struct bar *bar) {
300 252
301 event_loop_poll(); 253 event_loop_poll();
302#ifdef ENABLE_TRAY 254#ifdef ENABLE_TRAY
255 tray_upkeep(bar);
256
303 dispatch_dbus(); 257 dispatch_dbus();
304#endif 258#endif
305 } 259 }