diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-10-28 10:25:47 +0000 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-12-31 20:40:18 +0000 |
commit | 5f65f339896fadf0011b75d78c869594876d35d9 (patch) | |
tree | bbb234ad123657f1a8ed1f311cf9183b67e7e961 | |
parent | swaybar: remove old tray implementation (diff) | |
download | sway-5f65f339896fadf0011b75d78c869594876d35d9.tar.gz sway-5f65f339896fadf0011b75d78c869594876d35d9.tar.zst sway-5f65f339896fadf0011b75d78c869594876d35d9.zip |
swaybar: add tray interface
-rw-r--r-- | include/swaybar/bar.h | 8 | ||||
-rw-r--r-- | include/swaybar/tray/tray.h | 28 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | meson_options.txt | 1 | ||||
-rw-r--r-- | swaybar/bar.c | 15 | ||||
-rw-r--r-- | swaybar/meson.build | 40 | ||||
-rw-r--r-- | swaybar/render.c | 9 | ||||
-rw-r--r-- | swaybar/tray/tray.c | 21 |
8 files changed, 110 insertions, 13 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 57c5114e..ef27012d 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _SWAYBAR_BAR_H | 1 | #ifndef _SWAYBAR_BAR_H |
2 | #define _SWAYBAR_BAR_H | 2 | #define _SWAYBAR_BAR_H |
3 | #include <wayland-client.h> | 3 | #include <wayland-client.h> |
4 | #include "config.h" | ||
4 | #include "input.h" | 5 | #include "input.h" |
5 | #include "pool-buffer.h" | 6 | #include "pool-buffer.h" |
6 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 7 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
@@ -8,6 +9,9 @@ | |||
8 | 9 | ||
9 | struct swaybar_config; | 10 | struct swaybar_config; |
10 | struct swaybar_output; | 11 | struct swaybar_output; |
12 | #if HAVE_TRAY | ||
13 | struct swaybar_tray; | ||
14 | #endif | ||
11 | struct swaybar_workspace; | 15 | struct swaybar_workspace; |
12 | struct loop; | 16 | struct loop; |
13 | 17 | ||
@@ -38,6 +42,10 @@ struct swaybar { | |||
38 | int ipc_socketfd; | 42 | int ipc_socketfd; |
39 | 43 | ||
40 | struct wl_list outputs; // swaybar_output::link | 44 | struct wl_list outputs; // swaybar_output::link |
45 | |||
46 | #if HAVE_TRAY | ||
47 | struct swaybar_tray *tray; | ||
48 | #endif | ||
41 | }; | 49 | }; |
42 | 50 | ||
43 | struct swaybar_output { | 51 | struct swaybar_output { |
diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h new file mode 100644 index 00000000..217e2d45 --- /dev/null +++ b/include/swaybar/tray/tray.h | |||
@@ -0,0 +1,28 @@ | |||
1 | #ifndef _SWAYBAR_TRAY_TRAY_H | ||
2 | #define _SWAYBAR_TRAY_TRAY_H | ||
3 | |||
4 | #include "config.h" | ||
5 | #ifdef HAVE_SYSTEMD | ||
6 | #include <systemd/sd-bus.h> | ||
7 | #elif HAVE_ELOGIND | ||
8 | #include <elogind/sd-bus.h> | ||
9 | #endif | ||
10 | #include <cairo.h> | ||
11 | #include <stdint.h> | ||
12 | |||
13 | struct swaybar; | ||
14 | struct swaybar_output; | ||
15 | |||
16 | struct swaybar_tray { | ||
17 | struct swaybar *bar; | ||
18 | |||
19 | int fd; | ||
20 | sd_bus *bus; | ||
21 | }; | ||
22 | |||
23 | struct swaybar_tray *create_tray(struct swaybar *bar); | ||
24 | void destroy_tray(struct swaybar_tray *tray); | ||
25 | void tray_in(int fd, short mask, void *data); | ||
26 | uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x); | ||
27 | |||
28 | #endif | ||
diff --git a/meson.build b/meson.build index e1e0fc2d..981f74ac 100644 --- a/meson.build +++ b/meson.build | |||
@@ -66,6 +66,7 @@ endif | |||
66 | conf_data.set10('HAVE_GDK_PIXBUF', gdk_pixbuf.found()) | 66 | conf_data.set10('HAVE_GDK_PIXBUF', gdk_pixbuf.found()) |
67 | conf_data.set10('HAVE_SYSTEMD', systemd.found()) | 67 | conf_data.set10('HAVE_SYSTEMD', systemd.found()) |
68 | conf_data.set10('HAVE_ELOGIND', elogind.found()) | 68 | conf_data.set10('HAVE_ELOGIND', elogind.found()) |
69 | conf_data.set10('HAVE_TRAY', get_option('enable-tray') and (systemd.found() or elogind.found())) | ||
69 | 70 | ||
70 | if not systemd.found() and not elogind.found() | 71 | if not systemd.found() and not elogind.found() |
71 | warning('The sway binary must be setuid when compiled without (e)logind') | 72 | warning('The sway binary must be setuid when compiled without (e)logind') |
diff --git a/meson_options.txt b/meson_options.txt index 2db852fc..4640618e 100644 --- a/meson_options.txt +++ b/meson_options.txt | |||
@@ -6,3 +6,4 @@ option('zsh-completions', type: 'boolean', value: true, description: 'Install zs | |||
6 | option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') | 6 | option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') |
7 | option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') | 7 | option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') |
8 | option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications') | 8 | option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications') |
9 | option('enable-tray', type: 'boolean', value: false, description: 'Enable support for swaybar tray') | ||
diff --git a/swaybar/bar.c b/swaybar/bar.c index 53e798bc..c26e76ce 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -18,6 +18,9 @@ | |||
18 | #include "swaybar/ipc.h" | 18 | #include "swaybar/ipc.h" |
19 | #include "swaybar/status_line.h" | 19 | #include "swaybar/status_line.h" |
20 | #include "swaybar/render.h" | 20 | #include "swaybar/render.h" |
21 | #if HAVE_TRAY | ||
22 | #include "swaybar/tray/tray.h" | ||
23 | #endif | ||
21 | #include "ipc-client.h" | 24 | #include "ipc-client.h" |
22 | #include "list.h" | 25 | #include "list.h" |
23 | #include "log.h" | 26 | #include "log.h" |
@@ -362,6 +365,10 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) { | |||
362 | pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); | 365 | pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); |
363 | assert(pointer->cursor_surface); | 366 | assert(pointer->cursor_surface); |
364 | 367 | ||
368 | #if HAVE_TRAY | ||
369 | bar->tray = create_tray(bar); | ||
370 | #endif | ||
371 | |||
365 | if (bar->config->workspace_buttons) { | 372 | if (bar->config->workspace_buttons) { |
366 | ipc_get_workspaces(bar); | 373 | ipc_get_workspaces(bar); |
367 | } | 374 | } |
@@ -403,6 +410,11 @@ void bar_run(struct swaybar *bar) { | |||
403 | loop_add_fd(bar->eventloop, bar->status->read_fd, POLLIN, | 410 | loop_add_fd(bar->eventloop, bar->status->read_fd, POLLIN, |
404 | status_in, bar); | 411 | status_in, bar); |
405 | } | 412 | } |
413 | #if HAVE_TRAY | ||
414 | if (bar->tray) { | ||
415 | loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar->tray->bus); | ||
416 | } | ||
417 | #endif | ||
406 | while (1) { | 418 | while (1) { |
407 | errno = 0; | 419 | errno = 0; |
408 | if (wl_display_flush(bar->display) == -1 && errno != EAGAIN) { | 420 | if (wl_display_flush(bar->display) == -1 && errno != EAGAIN) { |
@@ -420,6 +432,9 @@ static void free_outputs(struct wl_list *list) { | |||
420 | } | 432 | } |
421 | 433 | ||
422 | void bar_teardown(struct swaybar *bar) { | 434 | void bar_teardown(struct swaybar *bar) { |
435 | #if HAVE_TRAY | ||
436 | destroy_tray(bar->tray); | ||
437 | #endif | ||
423 | free_outputs(&bar->outputs); | 438 | free_outputs(&bar->outputs); |
424 | if (bar->config) { | 439 | if (bar->config) { |
425 | free_config(bar->config); | 440 | free_config(bar->config); |
diff --git a/swaybar/meson.build b/swaybar/meson.build index c27cf2c2..b83f47e5 100644 --- a/swaybar/meson.build +++ b/swaybar/meson.build | |||
@@ -1,3 +1,28 @@ | |||
1 | tray_files = get_option('enable-tray') ? [ | ||
2 | 'tray/tray.c', | ||
3 | ] : [] | ||
4 | |||
5 | swaybar_deps = [ | ||
6 | cairo, | ||
7 | client_protos, | ||
8 | gdk_pixbuf, | ||
9 | jsonc, | ||
10 | math, | ||
11 | pango, | ||
12 | pangocairo, | ||
13 | rt, | ||
14 | wayland_client, | ||
15 | wayland_cursor, | ||
16 | wlroots, | ||
17 | ] | ||
18 | if get_option('enable-tray') | ||
19 | if systemd.found() | ||
20 | swaybar_deps += systemd | ||
21 | elif elogind.found() | ||
22 | swaybar_deps += elogind | ||
23 | endif | ||
24 | endif | ||
25 | |||
1 | executable( | 26 | executable( |
2 | 'swaybar', [ | 27 | 'swaybar', [ |
3 | 'bar.c', | 28 | 'bar.c', |
@@ -8,21 +33,10 @@ executable( | |||
8 | 'main.c', | 33 | 'main.c', |
9 | 'render.c', | 34 | 'render.c', |
10 | 'status_line.c', | 35 | 'status_line.c', |
36 | tray_files | ||
11 | ], | 37 | ], |
12 | include_directories: [sway_inc], | 38 | include_directories: [sway_inc], |
13 | dependencies: [ | 39 | dependencies: swaybar_deps, |
14 | cairo, | ||
15 | client_protos, | ||
16 | gdk_pixbuf, | ||
17 | jsonc, | ||
18 | math, | ||
19 | pango, | ||
20 | pangocairo, | ||
21 | rt, | ||
22 | wayland_client, | ||
23 | wayland_cursor, | ||
24 | wlroots, | ||
25 | ], | ||
26 | link_with: [lib_sway_common, lib_sway_client], | 40 | link_with: [lib_sway_common, lib_sway_client], |
27 | install_rpath : rpathdir, | 41 | install_rpath : rpathdir, |
28 | install: true | 42 | install: true |
diff --git a/swaybar/render.c b/swaybar/render.c index 96118c42..9fe4ee9c 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -14,6 +14,9 @@ | |||
14 | #include "swaybar/ipc.h" | 14 | #include "swaybar/ipc.h" |
15 | #include "swaybar/render.h" | 15 | #include "swaybar/render.h" |
16 | #include "swaybar/status_line.h" | 16 | #include "swaybar/status_line.h" |
17 | #if HAVE_TRAY | ||
18 | #include "swaybar/tray/tray.h" | ||
19 | #endif | ||
17 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | 20 | #include "wlr-layer-shell-unstable-v1-client-protocol.h" |
18 | 21 | ||
19 | static const int WS_HORIZONTAL_PADDING = 5; | 22 | static const int WS_HORIZONTAL_PADDING = 5; |
@@ -453,6 +456,12 @@ static uint32_t render_to_cairo(cairo_t *cairo, struct swaybar_output *output) { | |||
453 | * utilize the available space. | 456 | * utilize the available space. |
454 | */ | 457 | */ |
455 | double x = output->width * output->scale; | 458 | double x = output->width * output->scale; |
459 | #if HAVE_TRAY | ||
460 | if (bar->tray) { | ||
461 | uint32_t h = render_tray(cairo, output, &x); | ||
462 | max_height = h > max_height ? h : max_height; | ||
463 | } | ||
464 | #endif | ||
456 | if (bar->status) { | 465 | if (bar->status) { |
457 | uint32_t h = render_status_line(cairo, output, &x); | 466 | uint32_t h = render_status_line(cairo, output, &x); |
458 | max_height = h > max_height ? h : max_height; | 467 | max_height = h > max_height ? h : max_height; |
diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c new file mode 100644 index 00000000..d5fb3ea9 --- /dev/null +++ b/swaybar/tray/tray.c | |||
@@ -0,0 +1,21 @@ | |||
1 | #include <cairo.h> | ||
2 | #include <stdint.h> | ||
3 | #include <stdlib.h> | ||
4 | #include "swaybar/bar.h" | ||
5 | #include "swaybar/tray/tray.h" | ||
6 | #include "log.h" | ||
7 | |||
8 | struct swaybar_tray *create_tray(struct swaybar *bar) { | ||
9 | wlr_log(WLR_DEBUG, "Initializing tray"); | ||
10 | return NULL; | ||
11 | } | ||
12 | |||
13 | void destroy_tray(struct swaybar_tray *tray) { | ||
14 | } | ||
15 | |||
16 | void tray_in(int fd, short mask, void *data) { | ||
17 | } | ||
18 | |||
19 | uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) { | ||
20 | return 0; // placeholder | ||
21 | } | ||