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
#define _SWAYBAR_BAR_H
#include <wayland-client.h>
#include "config.h"
#include "input.h"
#include "pool-buffer.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
@ -8,6 +9,9 @@
struct swaybar_config;
struct swaybar_output;
#if HAVE_TRAY
struct swaybar_tray;
#endif
struct swaybar_workspace;
struct loop;
@ -38,6 +42,10 @@ struct swaybar {
int ipc_socketfd;
struct wl_list outputs; // swaybar_output::link
#if HAVE_TRAY
struct swaybar_tray *tray;
#endif
};
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_SYSTEMD', systemd.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()
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('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-tray', type: 'boolean', value: false, description: 'Enable support for swaybar tray')

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,16 +1,8 @@
executable(
'swaybar', [
'bar.c',
'config.c',
'i3bar.c',
'input.c',
'ipc.c',
'main.c',
'render.c',
'status_line.c',
],
include_directories: [sway_inc],
dependencies: [
tray_files = get_option('enable-tray') ? [
'tray/tray.c',
] : []
swaybar_deps = [
cairo,
client_protos,
gdk_pixbuf,
@ -22,7 +14,29 @@ executable(
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',
'config.c',
'i3bar.c',
'input.c',
'ipc.c',
'main.c',
'render.c',
'status_line.c',
tray_files
],
include_directories: [sway_inc],
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
}