summaryrefslogtreecommitdiffstats
path: root/include/swaybar
diff options
context:
space:
mode:
Diffstat (limited to 'include/swaybar')
-rw-r--r--include/swaybar/bar.h14
-rw-r--r--include/swaybar/config.h18
-rw-r--r--include/swaybar/i3bar.h3
-rw-r--r--include/swaybar/input.h12
-rw-r--r--include/swaybar/tray/host.h17
-rw-r--r--include/swaybar/tray/icon.h52
-rw-r--r--include/swaybar/tray/item.h49
-rw-r--r--include/swaybar/tray/sni.h82
-rw-r--r--include/swaybar/tray/tray.h40
-rw-r--r--include/swaybar/tray/watcher.h18
10 files changed, 209 insertions, 96 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index 95b20510..2d9ba0d9 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -1,6 +1,7 @@
1#ifndef _SWAYBAR_BAR_H 1#ifndef _SWAYBAR_BAR_H
2#define _SWAYBAR_BAR_H 2#define _SWAYBAR_BAR_H
3#include <wayland-client.h> 3#include <wayland-client.h>
4#include "config.h"
4#include "input.h" 5#include "input.h"
5#include "pool-buffer.h" 6#include "pool-buffer.h"
6#include "wlr-layer-shell-unstable-v1-client-protocol.h" 7#include "wlr-layer-shell-unstable-v1-client-protocol.h"
@@ -8,6 +9,9 @@
8 9
9struct swaybar_config; 10struct swaybar_config;
10struct swaybar_output; 11struct swaybar_output;
12#if HAVE_TRAY
13struct swaybar_tray;
14#endif
11struct swaybar_workspace; 15struct swaybar_workspace;
12struct loop; 16struct loop;
13 17
@@ -38,6 +42,10 @@ struct swaybar {
38 int ipc_socketfd; 42 int ipc_socketfd;
39 43
40 struct wl_list outputs; // swaybar_output::link 44 struct wl_list outputs; // swaybar_output::link
45
46#if HAVE_TRAY
47 struct swaybar_tray *tray;
48#endif
41}; 49};
42 50
43struct swaybar_output { 51struct swaybar_output {
@@ -53,6 +61,7 @@ struct swaybar_output {
53 struct wl_list hotspots; // swaybar_hotspot::link 61 struct wl_list hotspots; // swaybar_hotspot::link
54 62
55 char *name; 63 char *name;
64 char *identifier;
56 bool focused; 65 bool focused;
57 66
58 uint32_t width, height; 67 uint32_t width, height;
@@ -62,12 +71,15 @@ struct swaybar_output {
62 struct pool_buffer *current_buffer; 71 struct pool_buffer *current_buffer;
63 bool dirty; 72 bool dirty;
64 bool frame_scheduled; 73 bool frame_scheduled;
74
75 uint32_t output_height, output_width, output_x, output_y;
65}; 76};
66 77
67struct swaybar_workspace { 78struct swaybar_workspace {
68 struct wl_list link; // swaybar_output::workspaces 79 struct wl_list link; // swaybar_output::workspaces
69 int num; 80 int num;
70 char *name; 81 char *name;
82 char *label;
71 bool focused; 83 bool focused;
72 bool visible; 84 bool visible;
73 bool urgent; 85 bool urgent;
@@ -77,6 +89,8 @@ bool bar_setup(struct swaybar *bar, const char *socket_path);
77void bar_run(struct swaybar *bar); 89void bar_run(struct swaybar *bar);
78void bar_teardown(struct swaybar *bar); 90void bar_teardown(struct swaybar *bar);
79 91
92void set_bar_dirty(struct swaybar *bar);
93
80/* 94/*
81 * Determines whether the bar should be visible and changes it to be so. 95 * Determines whether the bar should be visible and changes it to be so.
82 * If the current visibility of the bar is the different to what it should be, 96 * If the current visibility of the bar is the different to what it should be,
diff --git a/include/swaybar/config.h b/include/swaybar/config.h
index 5d40790a..add0a1cf 100644
--- a/include/swaybar/config.h
+++ b/include/swaybar/config.h
@@ -3,6 +3,7 @@
3#include <stdbool.h> 3#include <stdbool.h>
4#include <stdint.h> 4#include <stdint.h>
5#include <wayland-client.h> 5#include <wayland-client.h>
6#include "../include/config.h"
6#include "list.h" 7#include "list.h"
7#include "util.h" 8#include "util.h"
8 9
@@ -34,6 +35,7 @@ struct swaybar_config {
34 char *hidden_state; 35 char *hidden_state;
35 char *modifier; 36 char *modifier;
36 bool strip_workspace_numbers; 37 bool strip_workspace_numbers;
38 bool strip_workspace_name;
37 bool binding_mode_indicator; 39 bool binding_mode_indicator;
38 bool wrap_scroll; 40 bool wrap_scroll;
39 bool workspace_buttons; 41 bool workspace_buttons;
@@ -41,6 +43,14 @@ struct swaybar_config {
41 struct wl_list outputs; // config_output::link 43 struct wl_list outputs; // config_output::link
42 bool all_outputs; 44 bool all_outputs;
43 int height; 45 int height;
46 int status_padding;
47 int status_edge_padding;
48 struct {
49 int top;
50 int right;
51 int bottom;
52 int left;
53 } gaps;
44 54
45 struct { 55 struct {
46 uint32_t background; 56 uint32_t background;
@@ -57,6 +67,14 @@ struct swaybar_config {
57 struct box_colors urgent_workspace; 67 struct box_colors urgent_workspace;
58 struct box_colors binding_mode; 68 struct box_colors binding_mode;
59 } colors; 69 } colors;
70
71#if HAVE_TRAY
72 char *icon_theme;
73 char *tray_bindings[10]; // mouse buttons 0-9
74 bool tray_hidden;
75 list_t *tray_outputs; // char *
76 int tray_padding;
77#endif
60}; 78};
61 79
62struct swaybar_config *init_config(void); 80struct swaybar_config *init_config(void);
diff --git a/include/swaybar/i3bar.h b/include/swaybar/i3bar.h
index 3f1ecc25..aa4415ff 100644
--- a/include/swaybar/i3bar.h
+++ b/include/swaybar/i3bar.h
@@ -27,6 +27,7 @@ struct i3bar_block {
27void i3bar_block_unref(struct i3bar_block *block); 27void i3bar_block_unref(struct i3bar_block *block);
28bool i3bar_handle_readable(struct status_line *status); 28bool i3bar_handle_readable(struct status_line *status);
29enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, 29enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
30 struct i3bar_block *block, int x, int y, enum x11_button button); 30 struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h,
31 uint32_t button);
31 32
32#endif 33#endif
diff --git a/include/swaybar/input.h b/include/swaybar/input.h
index a552e7ac..4b46b0de 100644
--- a/include/swaybar/input.h
+++ b/include/swaybar/input.h
@@ -4,6 +4,12 @@
4#include <wayland-client.h> 4#include <wayland-client.h>
5#include "list.h" 5#include "list.h"
6 6
7#define SWAY_SCROLL_UP KEY_MAX + 1
8#define SWAY_SCROLL_DOWN KEY_MAX + 2
9#define SWAY_SCROLL_LEFT KEY_MAX + 3
10#define SWAY_SCROLL_RIGHT KEY_MAX + 4
11
12struct swaybar;
7struct swaybar_output; 13struct swaybar_output;
8 14
9struct swaybar_pointer { 15struct swaybar_pointer {
@@ -13,6 +19,7 @@ struct swaybar_pointer {
13 struct wl_surface *cursor_surface; 19 struct wl_surface *cursor_surface;
14 struct swaybar_output *current; 20 struct swaybar_output *current;
15 int x, y; 21 int x, y;
22 uint32_t serial;
16}; 23};
17 24
18enum x11_button { 25enum x11_button {
@@ -37,13 +44,16 @@ struct swaybar_hotspot {
37 struct wl_list link; // swaybar_output::hotspots 44 struct wl_list link; // swaybar_output::hotspots
38 int x, y, width, height; 45 int x, y, width, height;
39 enum hotspot_event_handling (*callback)(struct swaybar_output *output, 46 enum hotspot_event_handling (*callback)(struct swaybar_output *output,
40 int x, int y, enum x11_button button, void *data); 47 struct swaybar_hotspot *hotspot, int x, int y, uint32_t button,
48 void *data);
41 void (*destroy)(void *data); 49 void (*destroy)(void *data);
42 void *data; 50 void *data;
43}; 51};
44 52
45extern const struct wl_seat_listener seat_listener; 53extern const struct wl_seat_listener seat_listener;
46 54
55void update_cursor(struct swaybar *bar);
56
47void free_hotspots(struct wl_list *list); 57void free_hotspots(struct wl_list *list);
48 58
49#endif 59#endif
diff --git a/include/swaybar/tray/host.h b/include/swaybar/tray/host.h
new file mode 100644
index 00000000..2d4cf82b
--- /dev/null
+++ b/include/swaybar/tray/host.h
@@ -0,0 +1,17 @@
1#ifndef _SWAYBAR_TRAY_HOST_H
2#define _SWAYBAR_TRAY_HOST_H
3
4#include <stdbool.h>
5
6struct swaybar_tray;
7
8struct swaybar_host {
9 struct swaybar_tray *tray;
10 char *service;
11 char *watcher_interface;
12};
13
14bool init_host(struct swaybar_host *host, char *protocol, struct swaybar_tray *tray);
15void finish_host(struct swaybar_host *host);
16
17#endif
diff --git a/include/swaybar/tray/icon.h b/include/swaybar/tray/icon.h
index 1cc6ff9c..7a6c400c 100644
--- a/include/swaybar/tray/icon.h
+++ b/include/swaybar/tray/icon.h
@@ -1,16 +1,44 @@
1#ifndef _SWAYBAR_ICON_H 1#ifndef _SWAYBAR_TRAY_ICON_H
2#define _SWAYBAR_ICON_H 2#define _SWAYBAR_TRAY_ICON_H
3 3
4#include <stdint.h> 4#include "list.h"
5#include <stdbool.h>
6#include <client/cairo.h>
7 5
8/** 6enum subdir_type {
9 * Returns the image found by `name` that is closest to `size` 7 THRESHOLD,
10 */ 8 SCALABLE,
11cairo_surface_t *find_icon(const char *name, int size); 9 FIXED
10};
11
12struct 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
21struct icon_theme {
22 char *name;
23 char *comment;
24 char *inherits;
25 list_t *directories; // char *
12 26
13/* Struct used internally only */ 27 char *dir;
14struct subdir; 28 list_t *subdirs; // struct icon_theme_subdir *
29};
30
31void init_themes(list_t **themes, list_t **basedirs);
32void 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 */
40char *find_icon(list_t *themes, list_t *basedirs, char *name, int size,
41 char *theme, int *min_size, int *max_size);
42char *find_icon_in_dir(char *name, char *dir, int *min_size, int *max_size);
15 43
16#endif /* _SWAYBAR_ICON_H */ 44#endif
diff --git a/include/swaybar/tray/item.h b/include/swaybar/tray/item.h
new file mode 100644
index 00000000..4238bdb8
--- /dev/null
+++ b/include/swaybar/tray/item.h
@@ -0,0 +1,49 @@
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
10struct swaybar_output;
11
12struct swaybar_pixmap {
13 int size;
14 unsigned char pixels[];
15};
16
17struct 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 sd_bus_slot *new_icon_slot;
40 sd_bus_slot *new_attention_icon_slot;
41 sd_bus_slot *new_status_slot;
42};
43
44struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray);
45void destroy_sni(struct swaybar_sni *sni);
46uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
47 struct swaybar_sni *sni);
48
49#endif
diff --git a/include/swaybar/tray/sni.h b/include/swaybar/tray/sni.h
deleted file mode 100644
index c2544e2a..00000000
--- a/include/swaybar/tray/sni.h
+++ /dev/null
@@ -1,82 +0,0 @@
1#ifndef _SWAYBAR_SNI_H
2#define _SWAYBAR_SNI_H
3
4#include <stdbool.h>
5#include <client/cairo.h>
6
7struct StatusNotifierItem {
8 /* Name registered to sni watcher */
9 char *name;
10 /* Unique bus name, needed for determining signal origins */
11 char *unique_name;
12 bool kde_special_snowflake;
13
14 cairo_surface_t *image;
15 bool dirty;
16};
17
18/* Each output holds an sni_icon_ref of each item to render */
19struct sni_icon_ref {
20 cairo_surface_t *icon;
21 struct StatusNotifierItem *ref;
22};
23
24struct sni_icon_ref *sni_icon_ref_create(struct StatusNotifierItem *item,
25 int height);
26
27void sni_icon_ref_free(struct sni_icon_ref *sni_ref);
28
29/**
30 * Will return a new item and get its icon. (see warning below)
31 * May return `NULL` if `name` is not valid.
32 */
33struct StatusNotifierItem *sni_create(const char *name);
34
35/**
36 * `item` must be a struct StatusNotifierItem *
37 * `str` must be a NUL terminated char *
38 *
39 * Returns 0 if `item` has a name of `str`
40 */
41int sni_str_cmp(const void *item, const void *str);
42
43/**
44 * Returns 0 if `item` has a unique name of `str` or if
45 * `item->unique_name == NULL`
46 */
47int sni_uniq_cmp(const void *item, const void *str);
48
49/**
50 * Gets an icon for the given item if found.
51 *
52 * XXX
53 * This function keeps a reference to the item until it gets responses, make
54 * sure that the reference and item are valid during this time.
55 */
56void get_icon(struct StatusNotifierItem *item);
57
58/**
59 * Calls the "activate" method on the given StatusNotifierItem
60 *
61 * x and y should be where the item was clicked
62 */
63void sni_activate(struct StatusNotifierItem *item, uint32_t x, uint32_t y);
64
65/**
66 * Asks the item to draw a context menu at the given x and y coords
67 */
68void sni_context_menu(struct StatusNotifierItem *item, uint32_t x, uint32_t y);
69
70/**
71 * Calls the "secondary activate" method on the given StatusNotifierItem
72 *
73 * x and y should be where the item was clicked
74 */
75void sni_secondary(struct StatusNotifierItem *item, uint32_t x, uint32_t y);
76
77/**
78 * Deconstructs `item`
79 */
80void sni_free(struct StatusNotifierItem *item);
81
82#endif /* _SWAYBAR_SNI_H */
diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h
new file mode 100644
index 00000000..8958b69a
--- /dev/null
+++ b/include/swaybar/tray/tray.h
@@ -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
15struct swaybar;
16struct swaybar_output;
17struct swaybar_watcher;
18
19struct 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
35struct swaybar_tray *create_tray(struct swaybar *bar);
36void destroy_tray(struct swaybar_tray *tray);
37void tray_in(int fd, short mask, void *data);
38uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x);
39
40#endif
diff --git a/include/swaybar/tray/watcher.h b/include/swaybar/tray/watcher.h
new file mode 100644
index 00000000..8f276da8
--- /dev/null
+++ b/include/swaybar/tray/watcher.h
@@ -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
7struct swaybar_watcher {
8 char *interface;
9 sd_bus *bus;
10 list_t *hosts;
11 list_t *items;
12 int version;
13};
14
15struct swaybar_watcher *create_watcher(char *protocol, sd_bus *bus);
16void destroy_watcher(struct swaybar_watcher *watcher);
17
18#endif