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

@ -1,6 +1,7 @@
#ifndef _SWAYBAR_BAR_H #ifndef _SWAYBAR_BAR_H
#define _SWAYBAR_BAR_H #define _SWAYBAR_BAR_H
#include <wayland-client.h> #include <wayland-client.h>
#include "config.h"
#include "input.h" #include "input.h"
#include "pool-buffer.h" #include "pool-buffer.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h"
@ -8,6 +9,9 @@
struct swaybar_config; struct swaybar_config;
struct swaybar_output; struct swaybar_output;
#if HAVE_TRAY
struct swaybar_tray;
#endif
struct swaybar_workspace; struct swaybar_workspace;
struct loop; struct loop;
@ -38,6 +42,10 @@ struct swaybar {
int ipc_socketfd; int ipc_socketfd;
struct wl_list outputs; // swaybar_output::link struct wl_list outputs; // swaybar_output::link
#if HAVE_TRAY
struct swaybar_tray *tray;
#endif
}; };
struct swaybar_output { struct swaybar_output {

View file

@ -0,0 +1,28 @@
#ifndef _SWAYBAR_TRAY_TRAY_H
#define _SWAYBAR_TRAY_TRAY_H
#include "config.h"
#ifdef HAVE_SYSTEMD
#include <systemd/sd-bus.h>
#elif HAVE_ELOGIND
#include <elogind/sd-bus.h>
#endif
#include <cairo.h>
#include <stdint.h>
struct swaybar;
struct swaybar_output;
struct swaybar_tray {
struct swaybar *bar;
int fd;
sd_bus *bus;
};
struct swaybar_tray *create_tray(struct swaybar *bar);
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);
#endif

View file

@ -66,6 +66,7 @@ endif
conf_data.set10('HAVE_GDK_PIXBUF', gdk_pixbuf.found()) conf_data.set10('HAVE_GDK_PIXBUF', gdk_pixbuf.found())
conf_data.set10('HAVE_SYSTEMD', systemd.found()) conf_data.set10('HAVE_SYSTEMD', systemd.found())
conf_data.set10('HAVE_ELOGIND', elogind.found()) conf_data.set10('HAVE_ELOGIND', elogind.found())
conf_data.set10('HAVE_TRAY', get_option('enable-tray') and (systemd.found() or elogind.found()))
if not systemd.found() and not elogind.found() if not systemd.found() and not elogind.found()
warning('The sway binary must be setuid when compiled without (e)logind') warning('The sway binary must be setuid when compiled without (e)logind')

View file

@ -6,3 +6,4 @@ option('zsh-completions', type: 'boolean', value: true, description: 'Install zs
option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.')
option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.')
option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications') option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications')
option('enable-tray', type: 'boolean', value: false, description: 'Enable support for swaybar tray')

View file

@ -18,6 +18,9 @@
#include "swaybar/ipc.h" #include "swaybar/ipc.h"
#include "swaybar/status_line.h" #include "swaybar/status_line.h"
#include "swaybar/render.h" #include "swaybar/render.h"
#if HAVE_TRAY
#include "swaybar/tray/tray.h"
#endif
#include "ipc-client.h" #include "ipc-client.h"
#include "list.h" #include "list.h"
#include "log.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); pointer->cursor_surface = wl_compositor_create_surface(bar->compositor);
assert(pointer->cursor_surface); assert(pointer->cursor_surface);
#if HAVE_TRAY
bar->tray = create_tray(bar);
#endif
if (bar->config->workspace_buttons) { if (bar->config->workspace_buttons) {
ipc_get_workspaces(bar); ipc_get_workspaces(bar);
} }
@ -403,6 +410,11 @@ void bar_run(struct swaybar *bar) {
loop_add_fd(bar->eventloop, bar->status->read_fd, POLLIN, loop_add_fd(bar->eventloop, bar->status->read_fd, POLLIN,
status_in, bar); 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) { while (1) {
errno = 0; errno = 0;
if (wl_display_flush(bar->display) == -1 && errno != EAGAIN) { 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) { void bar_teardown(struct swaybar *bar) {
#if HAVE_TRAY
destroy_tray(bar->tray);
#endif
free_outputs(&bar->outputs); free_outputs(&bar->outputs);
if (bar->config) { if (bar->config) {
free_config(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( executable(
'swaybar', [ 'swaybar', [
'bar.c', 'bar.c',
@ -8,21 +33,10 @@ executable(
'main.c', 'main.c',
'render.c', 'render.c',
'status_line.c', 'status_line.c',
tray_files
], ],
include_directories: [sway_inc], include_directories: [sway_inc],
dependencies: [ dependencies: swaybar_deps,
cairo,
client_protos,
gdk_pixbuf,
jsonc,
math,
pango,
pangocairo,
rt,
wayland_client,
wayland_cursor,
wlroots,
],
link_with: [lib_sway_common, lib_sway_client], link_with: [lib_sway_common, lib_sway_client],
install_rpath : rpathdir, install_rpath : rpathdir,
install: true install: true

View file

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