diff options
author | 2018-03-30 00:11:00 -0400 | |
---|---|---|
committer | 2018-03-30 00:11:00 -0400 | |
commit | 9d7f47746cdcb0eed3cf41875d06a8ef238eef1c (patch) | |
tree | 997658454de40db3f8b76b68d658efaf2b686188 /include/swaybar | |
parent | Merge pull request #1654 from acrisci/refactor-2-electric-boogaloo (diff) | |
parent | Merge remote-tracking branch 'origin/wlroots' into swaybar-layers (diff) | |
download | sway-9d7f47746cdcb0eed3cf41875d06a8ef238eef1c.tar.gz sway-9d7f47746cdcb0eed3cf41875d06a8ef238eef1c.tar.zst sway-9d7f47746cdcb0eed3cf41875d06a8ef238eef1c.zip |
Merge pull request #1648 from swaywm/swaybar-layers
Port swaybar to layer shell
Diffstat (limited to 'include/swaybar')
-rw-r--r-- | include/swaybar/bar.h | 89 | ||||
-rw-r--r-- | include/swaybar/config.h | 60 | ||||
-rw-r--r-- | include/swaybar/event_loop.h | 4 | ||||
-rw-r--r-- | include/swaybar/ipc.h | 25 | ||||
-rw-r--r-- | include/swaybar/render.h | 22 | ||||
-rw-r--r-- | include/swaybar/status_line.h | 65 |
6 files changed, 84 insertions, 181 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 50d36e76..1bf2ea2d 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h | |||
@@ -1,36 +1,49 @@ | |||
1 | #ifndef _SWAYBAR_BAR_H | 1 | #ifndef _SWAYBAR_BAR_H |
2 | #define _SWAYBAR_BAR_H | 2 | #define _SWAYBAR_BAR_H |
3 | 3 | #include <wayland-client.h> | |
4 | #include "client/registry.h" | 4 | #include "pool-buffer.h" |
5 | #include "client/window.h" | ||
6 | #include "list.h" | 5 | #include "list.h" |
7 | 6 | ||
8 | struct bar { | 7 | struct swaybar_config; |
9 | struct config *config; | 8 | struct swaybar_output; |
9 | struct swaybar_workspace; | ||
10 | |||
11 | struct swaybar { | ||
12 | struct wl_display *display; | ||
13 | struct wl_compositor *compositor; | ||
14 | struct zwlr_layer_shell_v1 *layer_shell; | ||
15 | struct wl_shm *shm; | ||
16 | |||
17 | struct swaybar_config *config; | ||
18 | struct swaybar_output *focused_output; | ||
10 | struct status_line *status; | 19 | struct status_line *status; |
11 | list_t *outputs; | ||
12 | struct output *focused_output; | ||
13 | 20 | ||
14 | int ipc_event_socketfd; | 21 | int ipc_event_socketfd; |
15 | int ipc_socketfd; | 22 | int ipc_socketfd; |
16 | int status_read_fd; | 23 | |
17 | int status_write_fd; | 24 | struct wl_list outputs; |
18 | pid_t status_command_pid; | ||
19 | }; | 25 | }; |
20 | 26 | ||
21 | struct output { | 27 | struct swaybar_output { |
22 | struct window *window; | 28 | struct wl_list link; |
23 | struct registry *registry; | 29 | struct swaybar *bar; |
24 | list_t *workspaces; | 30 | struct wl_output *output; |
25 | #ifdef ENABLE_TRAY | 31 | struct wl_surface *surface; |
26 | list_t *items; | 32 | struct zwlr_layer_surface_v1 *layer_surface; |
27 | #endif | 33 | |
34 | struct wl_list workspaces; | ||
35 | |||
28 | char *name; | 36 | char *name; |
29 | int idx; | 37 | size_t index; |
30 | bool focused; | 38 | bool focused; |
39 | |||
40 | uint32_t width, height; | ||
41 | struct pool_buffer buffers[2]; | ||
42 | struct pool_buffer *current_buffer; | ||
31 | }; | 43 | }; |
32 | 44 | ||
33 | struct workspace { | 45 | struct swaybar_workspace { |
46 | struct wl_list link; | ||
34 | int num; | 47 | int num; |
35 | char *name; | 48 | char *name; |
36 | bool focused; | 49 | bool focused; |
@@ -38,35 +51,11 @@ struct workspace { | |||
38 | bool urgent; | 51 | bool urgent; |
39 | }; | 52 | }; |
40 | 53 | ||
41 | /** Global bar state */ | 54 | // TODO: Rename stuff to match wlroots conventions (init/create/etc) |
42 | extern struct bar swaybar; | 55 | void bar_setup(struct swaybar *bar, |
56 | const char *socket_path, | ||
57 | const char *bar_id); | ||
58 | void bar_run(struct swaybar *bar); | ||
59 | void bar_teardown(struct swaybar *bar); | ||
43 | 60 | ||
44 | /** True if sway needs to render */ | 61 | #endif |
45 | extern bool dirty; | ||
46 | |||
47 | /** | ||
48 | * Setup bar. | ||
49 | */ | ||
50 | void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id); | ||
51 | |||
52 | /** | ||
53 | * Create new output struct from name. | ||
54 | */ | ||
55 | struct output *new_output(const char *name); | ||
56 | |||
57 | /** | ||
58 | * Bar mainloop. | ||
59 | */ | ||
60 | void bar_run(struct bar *bar); | ||
61 | |||
62 | /** | ||
63 | * free workspace list. | ||
64 | */ | ||
65 | void free_workspaces(list_t *workspaces); | ||
66 | |||
67 | /** | ||
68 | * Teardown bar. | ||
69 | */ | ||
70 | void 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..7634cb16 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h | |||
@@ -1,49 +1,35 @@ | |||
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 | */ | ||
13 | struct box_colors { | 8 | struct 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 | /** | 14 | struct config_output { |
20 | * Swaybar config. | 15 | struct wl_list link; |
21 | */ | 16 | char *name; |
22 | struct config { | 17 | size_t index; |
18 | }; | ||
19 | |||
20 | struct 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; |
33 | bool all_outputs; | 32 | struct wl_list 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; | 33 | int height; |
48 | 34 | ||
49 | struct { | 35 | struct { |
@@ -63,24 +49,8 @@ struct config { | |||
63 | } colors; | 49 | } colors; |
64 | }; | 50 | }; |
65 | 51 | ||
66 | /** | 52 | struct swaybar_config *init_config(); |
67 | * Parse position top|bottom|left|right. | 53 | void free_config(struct swaybar_config *config); |
68 | */ | ||
69 | uint32_t parse_position(const char *position); | 54 | uint32_t parse_position(const char *position); |
70 | 55 | ||
71 | /** | 56 | #endif |
72 | * Parse font. | ||
73 | */ | ||
74 | char *parse_font(const char *font); | ||
75 | |||
76 | /** | ||
77 | * Initialize default sway config. | ||
78 | */ | ||
79 | struct config *init_config(); | ||
80 | |||
81 | /** | ||
82 | * Free config struct. | ||
83 | */ | ||
84 | void 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); | |||
23 | void event_loop_poll(); | 22 | void event_loop_poll(); |
24 | 23 | ||
25 | void init_event_loop(); | 24 | void 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..278baef0 100644 --- a/include/swaybar/ipc.h +++ b/include/swaybar/ipc.h | |||
@@ -1,23 +1,10 @@ | |||
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" | 6 | void ipc_initialize(struct swaybar *bar, const char *bar_id); |
5 | 7 | bool handle_ipc_event(struct swaybar *bar); | |
6 | /** | 8 | void ipc_get_workspaces(struct swaybar *bar); |
7 | * Initialize ipc connection to sway and get sway state, outputs, bar_config. | ||
8 | */ | ||
9 | void ipc_bar_init(struct bar *bar, const char *bar_id); | ||
10 | |||
11 | /** | ||
12 | * Handle ipc event from sway. | ||
13 | */ | ||
14 | bool handle_ipc_event(struct bar *bar); | ||
15 | |||
16 | |||
17 | /** | ||
18 | * Send workspace command to sway | ||
19 | */ | ||
20 | void ipc_send_workspace_command(const char *workspace_name); | ||
21 | |||
22 | #endif /* _SWAYBAR_IPC_H */ | ||
23 | 9 | ||
10 | #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" | 4 | struct swaybar; |
5 | #include "bar.h" | 5 | struct swaybar_output; |
6 | struct swaybar_config; | ||
6 | 7 | ||
7 | /** | 8 | void render_frame(struct swaybar *bar, struct swaybar_output *output); |
8 | * Render swaybar. | ||
9 | */ | ||
10 | void 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 | */ | ||
15 | void set_window_height(struct window *window, int height); | ||
16 | |||
17 | /** | ||
18 | * Compute the size of a workspace name | ||
19 | */ | ||
20 | void 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..6c595df0 100644 --- a/include/swaybar/status_line.h +++ b/include/swaybar/status_line.h | |||
@@ -1,61 +1,30 @@ | |||
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 | ||
10 | typedef enum {UNDEF, TEXT, I3BAR} command_protocol; | 8 | enum status_protocol { |
9 | PROTOCOL_UNDEF, | ||
10 | PROTOCOL_TEXT, | ||
11 | PROTOCOL_I3BAR, | ||
12 | }; | ||
11 | 13 | ||
12 | struct status_line { | 14 | struct status_line { |
13 | list_t *block_line; | 15 | pid_t pid; |
14 | const char *text_line; | 16 | int read_fd, write_fd; |
15 | command_protocol protocol; | 17 | FILE *read, *write; |
16 | bool click_events; | ||
17 | }; | ||
18 | 18 | ||
19 | struct status_block { | 19 | enum status_protocol protocol; |
20 | char *full_text, *short_text, *align; | 20 | const char *text; |
21 | bool urgent; | ||
22 | uint32_t color; | ||
23 | int min_width; | ||
24 | char *name, *instance; | ||
25 | bool separator; | ||
26 | int separator_block_width; | ||
27 | bool markup; | ||
28 | // Airblader features | ||
29 | uint32_t background; | ||
30 | uint32_t border; | ||
31 | int border_top; | ||
32 | int border_bottom; | ||
33 | int border_left; | ||
34 | int border_right; | ||
35 | 21 | ||
36 | // Set during rendering | 22 | char *buffer; |
37 | int x; | 23 | size_t buffer_size; |
38 | int width; | ||
39 | }; | 24 | }; |
40 | 25 | ||
41 | /** | 26 | struct status_line *status_line_init(char *cmd); |
42 | * Initialize status line struct. | 27 | void status_line_free(struct status_line *status); |
43 | */ | 28 | bool handle_status_readable(struct status_line *status); |
44 | struct status_line *init_status_line(); | ||
45 | |||
46 | /** | ||
47 | * handle status line activity. | ||
48 | */ | ||
49 | bool handle_status_line(struct bar *bar); | ||
50 | |||
51 | /** | ||
52 | * Handle mouse clicks. | ||
53 | */ | ||
54 | bool status_line_mouse_event(struct bar *bar, int x, int y, uint32_t button); | ||
55 | |||
56 | /** | ||
57 | * Free status line struct. | ||
58 | */ | ||
59 | void free_status_line(struct status_line *line); | ||
60 | 29 | ||
61 | #endif /* _SWAYBAR_STATUS_LINE_H */ | 30 | #endif |