summaryrefslogtreecommitdiffstats
path: root/include/swaybar
diff options
context:
space:
mode:
Diffstat (limited to 'include/swaybar')
-rw-r--r--include/swaybar/bar.h110
-rw-r--r--include/swaybar/config.h59
-rw-r--r--include/swaybar/event_loop.h4
-rw-r--r--include/swaybar/ipc.h26
-rw-r--r--include/swaybar/render.h22
-rw-r--r--include/swaybar/status_line.h78
6 files changed, 136 insertions, 163 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index 50d36e76..0037190b 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -1,36 +1,71 @@
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>
4#include "pool-buffer.h"
3 5
4#include "client/registry.h" 6struct swaybar_config;
5#include "client/window.h" 7struct swaybar_output;
6#include "list.h" 8struct swaybar_workspace;
7 9
8struct bar { 10struct swaybar_pointer {
9 struct config *config; 11 struct wl_pointer *pointer;
12 struct wl_cursor_theme *cursor_theme;
13 struct wl_cursor_image *cursor_image;
14 struct wl_surface *cursor_surface;
15 struct swaybar_output *current;
16 int x, y;
17};
18
19struct swaybar_hotspot {
20 struct wl_list link;
21 int x, y, width, height;
22 void (*callback)(struct swaybar_output *output,
23 int x, int y, uint32_t button, void *data);
24 void (*destroy)(void *data);
25 void *data;
26};
27
28struct swaybar {
29 struct wl_display *display;
30 struct wl_compositor *compositor;
31 struct zwlr_layer_shell_v1 *layer_shell;
32 struct wl_shm *shm;
33 struct wl_seat *seat;
34
35 struct swaybar_config *config;
36 struct swaybar_output *focused_output;
37 struct swaybar_pointer pointer;
10 struct status_line *status; 38 struct status_line *status;
11 list_t *outputs;
12 struct output *focused_output;
13 39
14 int ipc_event_socketfd; 40 int ipc_event_socketfd;
15 int ipc_socketfd; 41 int ipc_socketfd;
16 int status_read_fd; 42
17 int status_write_fd; 43 struct wl_list outputs;
18 pid_t status_command_pid;
19}; 44};
20 45
21struct output { 46struct swaybar_output {
22 struct window *window; 47 struct wl_list link;
23 struct registry *registry; 48 struct swaybar *bar;
24 list_t *workspaces; 49 struct wl_output *output;
25#ifdef ENABLE_TRAY 50 struct wl_surface *surface;
26 list_t *items; 51 struct zwlr_layer_surface_v1 *layer_surface;
27#endif 52 uint32_t wl_name;
53
54 struct wl_list workspaces;
55 struct wl_list hotspots;
56
28 char *name; 57 char *name;
29 int idx; 58 size_t index;
30 bool focused; 59 bool focused;
60
61 uint32_t width, height;
62 int32_t scale;
63 struct pool_buffer buffers[2];
64 struct pool_buffer *current_buffer;
31}; 65};
32 66
33struct workspace { 67struct swaybar_workspace {
68 struct wl_list link;
34 int num; 69 int num;
35 char *name; 70 char *name;
36 bool focused; 71 bool focused;
@@ -38,35 +73,10 @@ struct workspace {
38 bool urgent; 73 bool urgent;
39}; 74};
40 75
41/** Global bar state */ 76void bar_setup(struct swaybar *bar,
42extern struct bar swaybar; 77 const char *socket_path,
43 78 const char *bar_id);
44/** True if sway needs to render */ 79void bar_run(struct swaybar *bar);
45extern bool dirty; 80void bar_teardown(struct swaybar *bar);
46
47/**
48 * Setup bar.
49 */
50void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id);
51
52/**
53 * Create new output struct from name.
54 */
55struct output *new_output(const char *name);
56 81
57/** 82#endif
58 * Bar mainloop.
59 */
60void bar_run(struct bar *bar);
61
62/**
63 * free workspace list.
64 */
65void free_workspaces(list_t *workspaces);
66
67/**
68 * Teardown bar.
69 */
70void bar_teardown(struct bar *bar);
71
72#endif /* _SWAYBAR_BAR_H */
diff --git a/include/swaybar/config.h b/include/swaybar/config.h
index 651f0ee3..7f321df8 100644
--- a/include/swaybar/config.h
+++ b/include/swaybar/config.h
@@ -1,49 +1,36 @@
1#ifndef _SWAYBAR_CONFIG_H 1#ifndef _SWAYBAR_CONFIG_H
2#define _SWAYBAR_CONFIG_H 2#define _SWAYBAR_CONFIG_H
3
4#include <stdint.h>
5#include <stdbool.h> 3#include <stdbool.h>
6 4#include <stdint.h>
7#include "list.h" 5#include <wayland-client.h>
8#include "util.h" 6#include "util.h"
9 7
10/**
11 * Colors for a box with background, border and text colors.
12 */
13struct box_colors { 8struct box_colors {
14 uint32_t border; 9 uint32_t border;
15 uint32_t background; 10 uint32_t background;
16 uint32_t text; 11 uint32_t text;
17}; 12};
18 13
19/** 14struct config_output {
20 * Swaybar config. 15 struct wl_list link;
21 */ 16 char *name;
22struct config { 17 size_t index;
18};
19
20struct swaybar_config {
23 char *status_command; 21 char *status_command;
24 bool pango_markup; 22 bool pango_markup;
25 uint32_t position; 23 uint32_t position; // zwlr_layer_surface_v1_anchor
26 char *font; 24 char *font;
27 char *sep_symbol; 25 char *sep_symbol;
28 char *mode; 26 char *mode;
27 bool mode_pango_markup;
29 bool strip_workspace_numbers; 28 bool strip_workspace_numbers;
30 bool binding_mode_indicator; 29 bool binding_mode_indicator;
31 bool wrap_scroll; 30 bool wrap_scroll;
32 bool workspace_buttons; 31 bool workspace_buttons;
32 struct wl_list outputs;
33 bool all_outputs; 33 bool all_outputs;
34 list_t *outputs;
35
36#ifdef ENABLE_TRAY
37 // Tray
38 char *tray_output;
39 char *icon_theme;
40
41 uint32_t tray_padding;
42 uint32_t activate_button;
43 uint32_t context_button;
44 uint32_t secondary_button;
45#endif
46
47 int height; 34 int height;
48 35
49 struct { 36 struct {
@@ -63,24 +50,8 @@ struct config {
63 } colors; 50 } colors;
64}; 51};
65 52
66/** 53struct swaybar_config *init_config();
67 * Parse position top|bottom|left|right. 54void free_config(struct swaybar_config *config);
68 */
69uint32_t parse_position(const char *position); 55uint32_t parse_position(const char *position);
70 56
71/** 57#endif
72 * Parse font.
73 */
74char *parse_font(const char *font);
75
76/**
77 * Initialize default sway config.
78 */
79struct config *init_config();
80
81/**
82 * Free config struct.
83 */
84void free_config(struct config *config);
85
86#endif /* _SWAYBAR_CONFIG_H */
diff --git a/include/swaybar/event_loop.h b/include/swaybar/event_loop.h
index a0cde07f..99f6ed36 100644
--- a/include/swaybar/event_loop.h
+++ b/include/swaybar/event_loop.h
@@ -1,6 +1,5 @@
1#ifndef _SWAYBAR_EVENT_LOOP_H 1#ifndef _SWAYBAR_EVENT_LOOP_H
2#define _SWAYBAR_EVENT_LOOP_H 2#define _SWAYBAR_EVENT_LOOP_H
3
4#include <stdbool.h> 3#include <stdbool.h>
5#include <time.h> 4#include <time.h>
6 5
@@ -23,4 +22,5 @@ bool remove_timer(timer_t timer);
23void event_loop_poll(); 22void event_loop_poll();
24 23
25void init_event_loop(); 24void init_event_loop();
26#endif /*_SWAYBAR_EVENT_LOOP_H */ 25
26#endif
diff --git a/include/swaybar/ipc.h b/include/swaybar/ipc.h
index c11931d0..a1696bcf 100644
--- a/include/swaybar/ipc.h
+++ b/include/swaybar/ipc.h
@@ -1,23 +1,11 @@
1#ifndef _SWAYBAR_IPC_H 1#ifndef _SWAYBAR_IPC_H
2#define _SWAYBAR_IPC_H 2#define _SWAYBAR_IPC_H
3#include <stdbool.h>
4#include "swaybar/bar.h"
3 5
4#include "bar.h" 6void ipc_initialize(struct swaybar *bar, const char *bar_id);
5 7bool handle_ipc_readable(struct swaybar *bar);
6/** 8void ipc_get_workspaces(struct swaybar *bar);
7 * Initialize ipc connection to sway and get sway state, outputs, bar_config. 9void ipc_send_workspace_command(struct swaybar *bar, const char *ws);
8 */
9void ipc_bar_init(struct bar *bar, const char *bar_id);
10
11/**
12 * Handle ipc event from sway.
13 */
14bool handle_ipc_event(struct bar *bar);
15
16
17/**
18 * Send workspace command to sway
19 */
20void ipc_send_workspace_command(const char *workspace_name);
21
22#endif /* _SWAYBAR_IPC_H */
23 10
11#endif
diff --git a/include/swaybar/render.h b/include/swaybar/render.h
index 114f43f4..071e2298 100644
--- a/include/swaybar/render.h
+++ b/include/swaybar/render.h
@@ -1,22 +1,10 @@
1#ifndef _SWAYBAR_RENDER_H 1#ifndef _SWAYBAR_RENDER_H
2#define _SWAYBAR_RENDER_H 2#define _SWAYBAR_RENDER_H
3 3
4#include "config.h" 4struct swaybar;
5#include "bar.h" 5struct swaybar_output;
6struct swaybar_config;
6 7
7/** 8void render_frame(struct swaybar *bar, struct swaybar_output *output);
8 * Render swaybar.
9 */
10void render(struct output *output, struct config *config, struct status_line *line);
11 9
12/** 10#endif
13 * Set window height and modify internal spacing accordingly.
14 */
15void set_window_height(struct window *window, int height);
16
17/**
18 * Compute the size of a workspace name
19 */
20void workspace_button_size(struct window *window, const char *workspace_name, int *width, int *height);
21
22#endif /* _SWAYBAR_RENDER_H */
diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h
index 0664ddee..3538f49c 100644
--- a/include/swaybar/status_line.h
+++ b/include/swaybar/status_line.h
@@ -1,25 +1,44 @@
1#ifndef _SWAYBAR_STATUS_LINE_H 1#ifndef _SWAYBAR_STATUS_LINE_H
2#define _SWAYBAR_STATUS_LINE_H 2#define _SWAYBAR_STATUS_LINE_H
3
4#include <stdint.h> 3#include <stdint.h>
4#include <stdio.h>
5#include <stdbool.h> 5#include <stdbool.h>
6
7#include "list.h"
8#include "bar.h" 6#include "bar.h"
9 7
10typedef enum {UNDEF, TEXT, I3BAR} command_protocol; 8enum status_protocol {
9 PROTOCOL_UNDEF,
10 PROTOCOL_ERROR,
11 PROTOCOL_TEXT,
12 PROTOCOL_I3BAR,
13};
14
15struct text_protocol_state {
16 char *buffer;
17 size_t buffer_size;
18};
11 19
12struct status_line { 20enum json_node_type {
13 list_t *block_line; 21 JSON_NODE_UNKNOWN,
14 const char *text_line; 22 JSON_NODE_ARRAY,
15 command_protocol protocol; 23 JSON_NODE_STRING,
24};
25
26struct i3bar_protocol_state {
16 bool click_events; 27 bool click_events;
28 char *buffer;
29 size_t buffer_size;
30 size_t buffer_index;
31 const char *current_node;
32 bool escape;
33 size_t depth;
34 enum json_node_type nodes[16];
17}; 35};
18 36
19struct status_block { 37struct i3bar_block {
38 struct wl_list link;
20 char *full_text, *short_text, *align; 39 char *full_text, *short_text, *align;
21 bool urgent; 40 bool urgent;
22 uint32_t color; 41 uint32_t *color;
23 int min_width; 42 int min_width;
24 char *name, *instance; 43 char *name, *instance;
25 bool separator; 44 bool separator;
@@ -32,30 +51,27 @@ struct status_block {
32 int border_bottom; 51 int border_bottom;
33 int border_left; 52 int border_left;
34 int border_right; 53 int border_right;
35
36 // Set during rendering
37 int x;
38 int width;
39}; 54};
40 55
41/** 56struct status_line {
42 * Initialize status line struct. 57 pid_t pid;
43 */ 58 int read_fd, write_fd;
44struct status_line *init_status_line(); 59 FILE *read, *write;
45 60
46/** 61 enum status_protocol protocol;
47 * handle status line activity. 62 const char *text;
48 */ 63 struct wl_list blocks; // i3bar_block::link
49bool handle_status_line(struct bar *bar);
50 64
51/** 65 struct text_protocol_state text_state;
52 * Handle mouse clicks. 66 struct i3bar_protocol_state i3bar_state;
53 */ 67};
54bool status_line_mouse_event(struct bar *bar, int x, int y, uint32_t button);
55 68
56/** 69struct status_line *status_line_init(char *cmd);
57 * Free status line struct. 70void status_error(struct status_line *status, const char *text);
58 */ 71bool status_handle_readable(struct status_line *status);
59void free_status_line(struct status_line *line); 72void status_line_free(struct status_line *status);
73bool i3bar_handle_readable(struct status_line *status);
74void i3bar_block_send_click(struct status_line *status,
75 struct i3bar_block *block, int x, int y, uint32_t button);
60 76
61#endif /* _SWAYBAR_STATUS_LINE_H */ 77#endif