Skip to content

Commit

Permalink
Merge pull request #3249 from ianyfan/tray
Browse files Browse the repository at this point in the history
Swaybar tray
  • Loading branch information
ddevault authored Dec 31, 2018
2 parents 4a3ada3 + 9e31f5d commit 3d7c20f
Show file tree
Hide file tree
Showing 34 changed files with 1,965 additions and 165 deletions.
4 changes: 1 addition & 3 deletions include/sway/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,9 @@ sway_cmd cmd_workspace;
sway_cmd cmd_ws_auto_back_and_forth;
sway_cmd cmd_workspace_layout;

sway_cmd bar_cmd_activate_button;
sway_cmd bar_cmd_binding_mode_indicator;
sway_cmd bar_cmd_bindsym;
sway_cmd bar_cmd_colors;
sway_cmd bar_cmd_context_button;
sway_cmd bar_cmd_font;
sway_cmd bar_cmd_gaps;
sway_cmd bar_cmd_mode;
Expand All @@ -197,13 +195,13 @@ sway_cmd bar_cmd_hidden_state;
sway_cmd bar_cmd_icon_theme;
sway_cmd bar_cmd_id;
sway_cmd bar_cmd_position;
sway_cmd bar_cmd_secondary_button;
sway_cmd bar_cmd_separator_symbol;
sway_cmd bar_cmd_status_command;
sway_cmd bar_cmd_pango_markup;
sway_cmd bar_cmd_strip_workspace_numbers;
sway_cmd bar_cmd_strip_workspace_name;
sway_cmd bar_cmd_swaybar_command;
sway_cmd bar_cmd_tray_bindsym;
sway_cmd bar_cmd_tray_output;
sway_cmd bar_cmd_tray_padding;
sway_cmd bar_cmd_wrap_scroll;
Expand Down
8 changes: 8 additions & 0 deletions include/sway/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <time.h>
#include <wlr/types/wlr_box.h>
#include <xkbcommon/xkbcommon.h>
#include "../include/config.h"
#include "list.h"
#include "swaynag.h"
#include "tree/container.h"
Expand Down Expand Up @@ -253,6 +254,13 @@ struct bar_config {
char *binding_mode_bg;
char *binding_mode_text;
} colors;

#if HAVE_TRAY
char *icon_theme;
const char *tray_bindings[10]; // mouse buttons 0-9
list_t *tray_outputs; // char *
int tray_padding;
#endif
};

struct bar_binding {
Expand Down
12 changes: 12 additions & 0 deletions include/swaybar/bar.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#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"
#include "xdg-output-unstable-v1-client-protocol.h"

struct swaybar_config;
struct swaybar_output;
#if HAVE_TRAY
struct swaybar_tray;
#endif
struct swaybar_workspace;
struct loop;

Expand Down Expand Up @@ -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 {
Expand All @@ -62,6 +70,8 @@ struct swaybar_output {
struct pool_buffer *current_buffer;
bool dirty;
bool frame_scheduled;

uint32_t output_height, output_width, output_x, output_y;
};

struct swaybar_workspace {
Expand All @@ -78,6 +88,8 @@ bool bar_setup(struct swaybar *bar, const char *socket_path);
void bar_run(struct swaybar *bar);
void bar_teardown(struct swaybar *bar);

void set_bar_dirty(struct swaybar *bar);

/*
* Determines whether the bar should be visible and changes it to be so.
* If the current visibility of the bar is the different to what it should be,
Expand Down
9 changes: 9 additions & 0 deletions include/swaybar/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <wayland-client.h>
#include "../include/config.h"
#include "list.h"
#include "util.h"

Expand Down Expand Up @@ -64,6 +65,14 @@ struct swaybar_config {
struct box_colors urgent_workspace;
struct box_colors binding_mode;
} colors;

#if HAVE_TRAY
char *icon_theme;
char *tray_bindings[10]; // mouse buttons 0-9
bool tray_hidden;
list_t *tray_outputs; // char *
int tray_padding;
#endif
};

struct swaybar_config *init_config(void);
Expand Down
17 changes: 17 additions & 0 deletions include/swaybar/tray/host.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef _SWAYBAR_TRAY_HOST_H
#define _SWAYBAR_TRAY_HOST_H

#include <stdbool.h>

struct swaybar_tray;

struct swaybar_host {
struct swaybar_tray *tray;
char *service;
char *watcher_interface;
};

bool init_host(struct swaybar_host *host, char *protocol, struct swaybar_tray *tray);
void finish_host(struct swaybar_host *host);

#endif
52 changes: 40 additions & 12 deletions include/swaybar/tray/icon.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
#ifndef _SWAYBAR_ICON_H
#define _SWAYBAR_ICON_H
#ifndef _SWAYBAR_TRAY_ICON_H
#define _SWAYBAR_TRAY_ICON_H

#include <stdint.h>
#include <stdbool.h>
#include <client/cairo.h>
#include "list.h"

/**
* Returns the image found by `name` that is closest to `size`
*/
cairo_surface_t *find_icon(const char *name, int size);
enum subdir_type {
THRESHOLD,
SCALABLE,
FIXED
};

struct icon_theme_subdir {
char *name;
int size;
enum subdir_type type;
int max_size;
int min_size;
int threshold;
};

struct icon_theme {
char *name;
char *comment;
char *inherits;
list_t *directories; // char *

/* Struct used internally only */
struct subdir;
char *dir;
list_t *subdirs; // struct icon_theme_subdir *
};

void init_themes(list_t **themes, list_t **basedirs);
void finish_themes(list_t *themes, list_t *basedirs);

/*
* Finds an icon of a specified size given a list of themes and base directories.
* If the icon is found, the pointers min_size & max_size are set to minimum &
* maximum size that the icon can be scaled to, respectively.
* Returns: path of icon (which should be freed), or NULL if the icon is not found.
*/
char *find_icon(list_t *themes, list_t *basedirs, char *name, int size,
char *theme, int *min_size, int *max_size);
char *find_icon_in_dir(char *name, char *dir, int *min_size, int *max_size);

#endif /* _SWAYBAR_ICON_H */
#endif
45 changes: 45 additions & 0 deletions include/swaybar/tray/item.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef _SWAYBAR_TRAY_ITEM_H
#define _SWAYBAR_TRAY_ITEM_H

#include <cairo.h>
#include <stdbool.h>
#include <stdint.h>
#include "swaybar/tray/tray.h"
#include "list.h"

struct swaybar_output;

struct swaybar_pixmap {
int size;
unsigned char pixels[];
};

struct swaybar_sni {
// icon properties
struct swaybar_tray *tray;
cairo_surface_t *icon;
int min_size;
int max_size;

// dbus properties
char *watcher_id;
char *service;
char *path;
char *interface;

char *status;
char *icon_name;
list_t *icon_pixmap; // struct swaybar_pixmap *
char *attention_icon_name;
list_t *attention_icon_pixmap; // struct swaybar_pixmap *
bool item_is_menu;
char *menu;
char *icon_theme_path; // non-standard KDE property
};

struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray);
void destroy_sni(struct swaybar_sni *sni);
uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
struct swaybar_sni *sni);

#endif
82 changes: 0 additions & 82 deletions include/swaybar/tray/sni.h

This file was deleted.

40 changes: 40 additions & 0 deletions include/swaybar/tray/tray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#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>
#include "swaybar/tray/host.h"
#include "list.h"

struct swaybar;
struct swaybar_output;
struct swaybar_watcher;

struct swaybar_tray {
struct swaybar *bar;

int fd;
sd_bus *bus;

struct swaybar_host host_xdg;
struct swaybar_host host_kde;
list_t *items; // struct swaybar_sni *
struct swaybar_watcher *watcher_xdg;
struct swaybar_watcher *watcher_kde;

list_t *basedirs; // char *
list_t *themes; // struct swaybar_theme *
};

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
18 changes: 18 additions & 0 deletions include/swaybar/tray/watcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _SWAYBAR_TRAY_WATCHER_H
#define _SWAYBAR_TRAY_WATCHER_H

#include "swaybar/tray/tray.h"
#include "list.h"

struct swaybar_watcher {
char *interface;
sd_bus *bus;
list_t *hosts;
list_t *items;
int version;
};

struct swaybar_watcher *create_watcher(char *protocol, sd_bus *bus);
void destroy_watcher(struct swaybar_watcher *watcher);

#endif
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Loading

0 comments on commit 3d7c20f

Please sign in to comment.