summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-10-28 10:25:47 +0000
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-12-31 20:40:18 +0000
commit5f65f339896fadf0011b75d78c869594876d35d9 (patch)
treebbb234ad123657f1a8ed1f311cf9183b67e7e961
parentswaybar: remove old tray implementation (diff)
downloadsway-5f65f339896fadf0011b75d78c869594876d35d9.tar.gz
sway-5f65f339896fadf0011b75d78c869594876d35d9.tar.zst
sway-5f65f339896fadf0011b75d78c869594876d35d9.zip
swaybar: add tray interface
-rw-r--r--include/swaybar/bar.h8
-rw-r--r--include/swaybar/tray/tray.h28
-rw-r--r--meson.build1
-rw-r--r--meson_options.txt1
-rw-r--r--swaybar/bar.c15
-rw-r--r--swaybar/meson.build40
-rw-r--r--swaybar/render.c9
-rw-r--r--swaybar/tray/tray.c21
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
9struct swaybar_config; 10struct swaybar_config;
10struct swaybar_output; 11struct swaybar_output;
12#if HAVE_TRAY
13struct swaybar_tray;
14#endif
11struct swaybar_workspace; 15struct swaybar_workspace;
12struct loop; 16struct 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
43struct swaybar_output { 51struct 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
13struct swaybar;
14struct swaybar_output;
15
16struct swaybar_tray {
17 struct swaybar *bar;
18
19 int fd;
20 sd_bus *bus;
21};
22
23struct swaybar_tray *create_tray(struct swaybar *bar);
24void destroy_tray(struct swaybar_tray *tray);
25void tray_in(int fd, short mask, void *data);
26uint32_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
66conf_data.set10('HAVE_GDK_PIXBUF', gdk_pixbuf.found()) 66conf_data.set10('HAVE_GDK_PIXBUF', gdk_pixbuf.found())
67conf_data.set10('HAVE_SYSTEMD', systemd.found()) 67conf_data.set10('HAVE_SYSTEMD', systemd.found())
68conf_data.set10('HAVE_ELOGIND', elogind.found()) 68conf_data.set10('HAVE_ELOGIND', elogind.found())
69conf_data.set10('HAVE_TRAY', get_option('enable-tray') and (systemd.found() or elogind.found()))
69 70
70if not systemd.found() and not elogind.found() 71if 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
6option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') 6option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.')
7option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') 7option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.')
8option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications') 8option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications')
9option('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
422void bar_teardown(struct swaybar *bar) { 434void 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 @@
1tray_files = get_option('enable-tray') ? [
2 'tray/tray.c',
3] : []
4
5swaybar_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]
18if get_option('enable-tray')
19 if systemd.found()
20 swaybar_deps += systemd
21 elif elogind.found()
22 swaybar_deps += elogind
23 endif
24endif
25
1executable( 26executable(
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
19static const int WS_HORIZONTAL_PADDING = 5; 22static 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
8struct swaybar_tray *create_tray(struct swaybar *bar) {
9 wlr_log(WLR_DEBUG, "Initializing tray");
10 return NULL;
11}
12
13void destroy_tray(struct swaybar_tray *tray) {
14}
15
16void tray_in(int fd, short mask, void *data) {
17}
18
19uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
20 return 0; // placeholder
21}