Skip to content

Commit 3d7c20f

Browse files
authored
Merge pull request #3249 from ianyfan/tray
Swaybar tray
2 parents 4a3ada3 + 9e31f5d commit 3d7c20f

34 files changed

+1965
-165
lines changed

include/sway/commands.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,9 @@ sway_cmd cmd_workspace;
182182
sway_cmd cmd_ws_auto_back_and_forth;
183183
sway_cmd cmd_workspace_layout;
184184

185-
sway_cmd bar_cmd_activate_button;
186185
sway_cmd bar_cmd_binding_mode_indicator;
187186
sway_cmd bar_cmd_bindsym;
188187
sway_cmd bar_cmd_colors;
189-
sway_cmd bar_cmd_context_button;
190188
sway_cmd bar_cmd_font;
191189
sway_cmd bar_cmd_gaps;
192190
sway_cmd bar_cmd_mode;
@@ -197,13 +195,13 @@ sway_cmd bar_cmd_hidden_state;
197195
sway_cmd bar_cmd_icon_theme;
198196
sway_cmd bar_cmd_id;
199197
sway_cmd bar_cmd_position;
200-
sway_cmd bar_cmd_secondary_button;
201198
sway_cmd bar_cmd_separator_symbol;
202199
sway_cmd bar_cmd_status_command;
203200
sway_cmd bar_cmd_pango_markup;
204201
sway_cmd bar_cmd_strip_workspace_numbers;
205202
sway_cmd bar_cmd_strip_workspace_name;
206203
sway_cmd bar_cmd_swaybar_command;
204+
sway_cmd bar_cmd_tray_bindsym;
207205
sway_cmd bar_cmd_tray_output;
208206
sway_cmd bar_cmd_tray_padding;
209207
sway_cmd bar_cmd_wrap_scroll;

include/sway/config.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <time.h>
77
#include <wlr/types/wlr_box.h>
88
#include <xkbcommon/xkbcommon.h>
9+
#include "../include/config.h"
910
#include "list.h"
1011
#include "swaynag.h"
1112
#include "tree/container.h"
@@ -253,6 +254,13 @@ struct bar_config {
253254
char *binding_mode_bg;
254255
char *binding_mode_text;
255256
} colors;
257+
258+
#if HAVE_TRAY
259+
char *icon_theme;
260+
const char *tray_bindings[10]; // mouse buttons 0-9
261+
list_t *tray_outputs; // char *
262+
int tray_padding;
263+
#endif
256264
};
257265

258266
struct bar_binding {

include/swaybar/bar.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#ifndef _SWAYBAR_BAR_H
22
#define _SWAYBAR_BAR_H
33
#include <wayland-client.h>
4+
#include "config.h"
45
#include "input.h"
56
#include "pool-buffer.h"
67
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
78
#include "xdg-output-unstable-v1-client-protocol.h"
89

910
struct swaybar_config;
1011
struct swaybar_output;
12+
#if HAVE_TRAY
13+
struct swaybar_tray;
14+
#endif
1115
struct swaybar_workspace;
1216
struct loop;
1317

@@ -38,6 +42,10 @@ struct swaybar {
3842
int ipc_socketfd;
3943

4044
struct wl_list outputs; // swaybar_output::link
45+
46+
#if HAVE_TRAY
47+
struct swaybar_tray *tray;
48+
#endif
4149
};
4250

4351
struct swaybar_output {
@@ -62,6 +70,8 @@ struct swaybar_output {
6270
struct pool_buffer *current_buffer;
6371
bool dirty;
6472
bool frame_scheduled;
73+
74+
uint32_t output_height, output_width, output_x, output_y;
6575
};
6676

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

91+
void set_bar_dirty(struct swaybar *bar);
92+
8193
/*
8294
* Determines whether the bar should be visible and changes it to be so.
8395
* If the current visibility of the bar is the different to what it should be,

include/swaybar/config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <stdbool.h>
44
#include <stdint.h>
55
#include <wayland-client.h>
6+
#include "../include/config.h"
67
#include "list.h"
78
#include "util.h"
89

@@ -64,6 +65,14 @@ struct swaybar_config {
6465
struct box_colors urgent_workspace;
6566
struct box_colors binding_mode;
6667
} colors;
68+
69+
#if HAVE_TRAY
70+
char *icon_theme;
71+
char *tray_bindings[10]; // mouse buttons 0-9
72+
bool tray_hidden;
73+
list_t *tray_outputs; // char *
74+
int tray_padding;
75+
#endif
6776
};
6877

6978
struct swaybar_config *init_config(void);

include/swaybar/tray/host.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef _SWAYBAR_TRAY_HOST_H
2+
#define _SWAYBAR_TRAY_HOST_H
3+
4+
#include <stdbool.h>
5+
6+
struct swaybar_tray;
7+
8+
struct swaybar_host {
9+
struct swaybar_tray *tray;
10+
char *service;
11+
char *watcher_interface;
12+
};
13+
14+
bool init_host(struct swaybar_host *host, char *protocol, struct swaybar_tray *tray);
15+
void finish_host(struct swaybar_host *host);
16+
17+
#endif

include/swaybar/tray/icon.h

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
1-
#ifndef _SWAYBAR_ICON_H
2-
#define _SWAYBAR_ICON_H
1+
#ifndef _SWAYBAR_TRAY_ICON_H
2+
#define _SWAYBAR_TRAY_ICON_H
33

4-
#include <stdint.h>
5-
#include <stdbool.h>
6-
#include <client/cairo.h>
4+
#include "list.h"
75

8-
/**
9-
* Returns the image found by `name` that is closest to `size`
10-
*/
11-
cairo_surface_t *find_icon(const char *name, int size);
6+
enum subdir_type {
7+
THRESHOLD,
8+
SCALABLE,
9+
FIXED
10+
};
11+
12+
struct icon_theme_subdir {
13+
char *name;
14+
int size;
15+
enum subdir_type type;
16+
int max_size;
17+
int min_size;
18+
int threshold;
19+
};
20+
21+
struct icon_theme {
22+
char *name;
23+
char *comment;
24+
char *inherits;
25+
list_t *directories; // char *
1226

13-
/* Struct used internally only */
14-
struct subdir;
27+
char *dir;
28+
list_t *subdirs; // struct icon_theme_subdir *
29+
};
30+
31+
void init_themes(list_t **themes, list_t **basedirs);
32+
void finish_themes(list_t *themes, list_t *basedirs);
33+
34+
/*
35+
* Finds an icon of a specified size given a list of themes and base directories.
36+
* If the icon is found, the pointers min_size & max_size are set to minimum &
37+
* maximum size that the icon can be scaled to, respectively.
38+
* Returns: path of icon (which should be freed), or NULL if the icon is not found.
39+
*/
40+
char *find_icon(list_t *themes, list_t *basedirs, char *name, int size,
41+
char *theme, int *min_size, int *max_size);
42+
char *find_icon_in_dir(char *name, char *dir, int *min_size, int *max_size);
1543

16-
#endif /* _SWAYBAR_ICON_H */
44+
#endif

include/swaybar/tray/item.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef _SWAYBAR_TRAY_ITEM_H
2+
#define _SWAYBAR_TRAY_ITEM_H
3+
4+
#include <cairo.h>
5+
#include <stdbool.h>
6+
#include <stdint.h>
7+
#include "swaybar/tray/tray.h"
8+
#include "list.h"
9+
10+
struct swaybar_output;
11+
12+
struct swaybar_pixmap {
13+
int size;
14+
unsigned char pixels[];
15+
};
16+
17+
struct swaybar_sni {
18+
// icon properties
19+
struct swaybar_tray *tray;
20+
cairo_surface_t *icon;
21+
int min_size;
22+
int max_size;
23+
24+
// dbus properties
25+
char *watcher_id;
26+
char *service;
27+
char *path;
28+
char *interface;
29+
30+
char *status;
31+
char *icon_name;
32+
list_t *icon_pixmap; // struct swaybar_pixmap *
33+
char *attention_icon_name;
34+
list_t *attention_icon_pixmap; // struct swaybar_pixmap *
35+
bool item_is_menu;
36+
char *menu;
37+
char *icon_theme_path; // non-standard KDE property
38+
};
39+
40+
struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray);
41+
void destroy_sni(struct swaybar_sni *sni);
42+
uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
43+
struct swaybar_sni *sni);
44+
45+
#endif

include/swaybar/tray/sni.h

Lines changed: 0 additions & 82 deletions
This file was deleted.

include/swaybar/tray/tray.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
#include "swaybar/tray/host.h"
13+
#include "list.h"
14+
15+
struct swaybar;
16+
struct swaybar_output;
17+
struct swaybar_watcher;
18+
19+
struct swaybar_tray {
20+
struct swaybar *bar;
21+
22+
int fd;
23+
sd_bus *bus;
24+
25+
struct swaybar_host host_xdg;
26+
struct swaybar_host host_kde;
27+
list_t *items; // struct swaybar_sni *
28+
struct swaybar_watcher *watcher_xdg;
29+
struct swaybar_watcher *watcher_kde;
30+
31+
list_t *basedirs; // char *
32+
list_t *themes; // struct swaybar_theme *
33+
};
34+
35+
struct swaybar_tray *create_tray(struct swaybar *bar);
36+
void destroy_tray(struct swaybar_tray *tray);
37+
void tray_in(int fd, short mask, void *data);
38+
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x);
39+
40+
#endif

include/swaybar/tray/watcher.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef _SWAYBAR_TRAY_WATCHER_H
2+
#define _SWAYBAR_TRAY_WATCHER_H
3+
4+
#include "swaybar/tray/tray.h"
5+
#include "list.h"
6+
7+
struct swaybar_watcher {
8+
char *interface;
9+
sd_bus *bus;
10+
list_t *hosts;
11+
list_t *items;
12+
int version;
13+
};
14+
15+
struct swaybar_watcher *create_watcher(char *protocol, sd_bus *bus);
16+
void destroy_watcher(struct swaybar_watcher *watcher);
17+
18+
#endif

0 commit comments

Comments
 (0)