swaybar: add tray interface

This commit is contained in:
Ian Fan 2018-10-28 10:25:47 +00:00
parent 598e950296
commit 5f65f33989
8 changed files with 110 additions and 13 deletions

View file

@ -18,6 +18,9 @@
#include "swaybar/ipc.h"
#include "swaybar/status_line.h"
#include "swaybar/render.h"
#if HAVE_TRAY
#include "swaybar/tray/tray.h"
#endif
#include "ipc-client.h"
#include "list.h"
#include "log.h"
@ -362,6 +365,10 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
pointer->cursor_surface = wl_compositor_create_surface(bar->compositor);
assert(pointer->cursor_surface);
#if HAVE_TRAY
bar->tray = create_tray(bar);
#endif
if (bar->config->workspace_buttons) {
ipc_get_workspaces(bar);
}
@ -403,6 +410,11 @@ void bar_run(struct swaybar *bar) {
loop_add_fd(bar->eventloop, bar->status->read_fd, POLLIN,
status_in, bar);
}
#if HAVE_TRAY
if (bar->tray) {
loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar->tray->bus);
}
#endif
while (1) {
errno = 0;
if (wl_display_flush(bar->display) == -1 && errno != EAGAIN) {
@ -420,6 +432,9 @@ static void free_outputs(struct wl_list *list) {
}
void bar_teardown(struct swaybar *bar) {
#if HAVE_TRAY
destroy_tray(bar->tray);
#endif
free_outputs(&bar->outputs);
if (bar->config) {
free_config(bar->config);

View file

@ -1,3 +1,28 @@
tray_files = get_option('enable-tray') ? [
'tray/tray.c',
] : []
swaybar_deps = [
cairo,
client_protos,
gdk_pixbuf,
jsonc,
math,
pango,
pangocairo,
rt,
wayland_client,
wayland_cursor,
wlroots,
]
if get_option('enable-tray')
if systemd.found()
swaybar_deps += systemd
elif elogind.found()
swaybar_deps += elogind
endif
endif
executable(
'swaybar', [
'bar.c',
@ -8,21 +33,10 @@ executable(
'main.c',
'render.c',
'status_line.c',
tray_files
],
include_directories: [sway_inc],
dependencies: [
cairo,
client_protos,
gdk_pixbuf,
jsonc,
math,
pango,
pangocairo,
rt,
wayland_client,
wayland_cursor,
wlroots,
],
dependencies: swaybar_deps,
link_with: [lib_sway_common, lib_sway_client],
install_rpath : rpathdir,
install: true

View file

@ -14,6 +14,9 @@
#include "swaybar/ipc.h"
#include "swaybar/render.h"
#include "swaybar/status_line.h"
#if HAVE_TRAY
#include "swaybar/tray/tray.h"
#endif
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
static const int WS_HORIZONTAL_PADDING = 5;
@ -453,6 +456,12 @@ static uint32_t render_to_cairo(cairo_t *cairo, struct swaybar_output *output) {
* utilize the available space.
*/
double x = output->width * output->scale;
#if HAVE_TRAY
if (bar->tray) {
uint32_t h = render_tray(cairo, output, &x);
max_height = h > max_height ? h : max_height;
}
#endif
if (bar->status) {
uint32_t h = render_status_line(cairo, output, &x);
max_height = h > max_height ? h : max_height;

21
swaybar/tray/tray.c Normal file
View file

@ -0,0 +1,21 @@
#include <cairo.h>
#include <stdint.h>
#include <stdlib.h>
#include "swaybar/bar.h"
#include "swaybar/tray/tray.h"
#include "log.h"
struct swaybar_tray *create_tray(struct swaybar *bar) {
wlr_log(WLR_DEBUG, "Initializing tray");
return NULL;
}
void destroy_tray(struct swaybar_tray *tray) {
}
void tray_in(int fd, short mask, void *data) {
}
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
return 0; // placeholder
}