diff options
Diffstat (limited to 'include/swaybar')
-rw-r--r-- | include/swaybar/bar.h | 110 | ||||
-rw-r--r-- | include/swaybar/config.h | 59 | ||||
-rw-r--r-- | include/swaybar/event_loop.h | 4 | ||||
-rw-r--r-- | include/swaybar/ipc.h | 26 | ||||
-rw-r--r-- | include/swaybar/render.h | 22 | ||||
-rw-r--r-- | include/swaybar/status_line.h | 78 |
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 @@ #ifndef _SWAYBAR_BAR_H #define _SWAYBAR_BAR_H +#include <wayland-client.h> +#include "pool-buffer.h" -#include "client/registry.h" -#include "client/window.h" -#include "list.h" +struct swaybar_config; +struct swaybar_output; +struct swaybar_workspace; -struct bar { - struct config *config; +struct swaybar_pointer { + struct wl_pointer *pointer; + struct wl_cursor_theme *cursor_theme; + struct wl_cursor_image *cursor_image; + struct wl_surface *cursor_surface; + struct swaybar_output *current; + int x, y; +}; + +struct swaybar_hotspot { + struct wl_list link; + int x, y, width, height; + void (*callback)(struct swaybar_output *output, + int x, int y, uint32_t button, void *data); + void (*destroy)(void *data); + void *data; +}; + +struct swaybar { + struct wl_display *display; + struct wl_compositor *compositor; + struct zwlr_layer_shell_v1 *layer_shell; + struct wl_shm *shm; + struct wl_seat *seat; + + struct swaybar_config *config; + struct swaybar_output *focused_output; + struct swaybar_pointer pointer; struct status_line *status; - list_t *outputs; - struct output *focused_output; int ipc_event_socketfd; int ipc_socketfd; - int status_read_fd; - int status_write_fd; - pid_t status_command_pid; + + struct wl_list outputs; }; -struct output { - struct window *window; - struct registry *registry; - list_t *workspaces; -#ifdef ENABLE_TRAY - list_t *items; -#endif +struct swaybar_output { + struct wl_list link; + struct swaybar *bar; + struct wl_output *output; + struct wl_surface *surface; + struct zwlr_layer_surface_v1 *layer_surface; + uint32_t wl_name; + + struct wl_list workspaces; + struct wl_list hotspots; + char *name; - int idx; + size_t index; bool focused; + + uint32_t width, height; + int32_t scale; + struct pool_buffer buffers[2]; + struct pool_buffer *current_buffer; }; -struct workspace { +struct swaybar_workspace { + struct wl_list link; int num; char *name; bool focused; @@ -38,35 +73,10 @@ struct workspace { bool urgent; }; -/** Global bar state */ -extern struct bar swaybar; - -/** True if sway needs to render */ -extern bool dirty; - -/** - * Setup bar. - */ -void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id); - -/** - * Create new output struct from name. - */ -struct output *new_output(const char *name); +void bar_setup(struct swaybar *bar, + const char *socket_path, + const char *bar_id); +void bar_run(struct swaybar *bar); +void bar_teardown(struct swaybar *bar); -/** - * Bar mainloop. - */ -void bar_run(struct bar *bar); - -/** - * free workspace list. - */ -void free_workspaces(list_t *workspaces); - -/** - * Teardown bar. - */ -void bar_teardown(struct bar *bar); - -#endif /* _SWAYBAR_BAR_H */ +#endif 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 @@ #ifndef _SWAYBAR_CONFIG_H #define _SWAYBAR_CONFIG_H - -#include <stdint.h> #include <stdbool.h> - -#include "list.h" +#include <stdint.h> +#include <wayland-client.h> #include "util.h" -/** - * Colors for a box with background, border and text colors. - */ struct box_colors { uint32_t border; uint32_t background; uint32_t text; }; -/** - * Swaybar config. - */ -struct config { +struct config_output { + struct wl_list link; + char *name; + size_t index; +}; + +struct swaybar_config { char *status_command; bool pango_markup; - uint32_t position; + uint32_t position; // zwlr_layer_surface_v1_anchor char *font; char *sep_symbol; char *mode; + bool mode_pango_markup; bool strip_workspace_numbers; bool binding_mode_indicator; bool wrap_scroll; bool workspace_buttons; + struct wl_list outputs; bool all_outputs; - list_t *outputs; - -#ifdef ENABLE_TRAY - // Tray - char *tray_output; - char *icon_theme; - - uint32_t tray_padding; - uint32_t activate_button; - uint32_t context_button; - uint32_t secondary_button; -#endif - int height; struct { @@ -63,24 +50,8 @@ struct config { } colors; }; -/** - * Parse position top|bottom|left|right. - */ +struct swaybar_config *init_config(); +void free_config(struct swaybar_config *config); uint32_t parse_position(const char *position); -/** - * Parse font. - */ -char *parse_font(const char *font); - -/** - * Initialize default sway config. - */ -struct config *init_config(); - -/** - * Free config struct. - */ -void free_config(struct config *config); - -#endif /* _SWAYBAR_CONFIG_H */ +#endif 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 @@ #ifndef _SWAYBAR_EVENT_LOOP_H #define _SWAYBAR_EVENT_LOOP_H - #include <stdbool.h> #include <time.h> @@ -23,4 +22,5 @@ bool remove_timer(timer_t timer); void event_loop_poll(); void init_event_loop(); -#endif /*_SWAYBAR_EVENT_LOOP_H */ + +#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 @@ #ifndef _SWAYBAR_IPC_H #define _SWAYBAR_IPC_H +#include <stdbool.h> +#include "swaybar/bar.h" -#include "bar.h" - -/** - * Initialize ipc connection to sway and get sway state, outputs, bar_config. - */ -void ipc_bar_init(struct bar *bar, const char *bar_id); - -/** - * Handle ipc event from sway. - */ -bool handle_ipc_event(struct bar *bar); - - -/** - * Send workspace command to sway - */ -void ipc_send_workspace_command(const char *workspace_name); - -#endif /* _SWAYBAR_IPC_H */ +void ipc_initialize(struct swaybar *bar, const char *bar_id); +bool handle_ipc_readable(struct swaybar *bar); +void ipc_get_workspaces(struct swaybar *bar); +void ipc_send_workspace_command(struct swaybar *bar, const char *ws); +#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 @@ #ifndef _SWAYBAR_RENDER_H #define _SWAYBAR_RENDER_H -#include "config.h" -#include "bar.h" +struct swaybar; +struct swaybar_output; +struct swaybar_config; -/** - * Render swaybar. - */ -void render(struct output *output, struct config *config, struct status_line *line); +void render_frame(struct swaybar *bar, struct swaybar_output *output); -/** - * Set window height and modify internal spacing accordingly. - */ -void set_window_height(struct window *window, int height); - -/** - * Compute the size of a workspace name - */ -void workspace_button_size(struct window *window, const char *workspace_name, int *width, int *height); - -#endif /* _SWAYBAR_RENDER_H */ +#endif 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 @@ #ifndef _SWAYBAR_STATUS_LINE_H #define _SWAYBAR_STATUS_LINE_H - #include <stdint.h> +#include <stdio.h> #include <stdbool.h> - -#include "list.h" #include "bar.h" -typedef enum {UNDEF, TEXT, I3BAR} command_protocol; +enum status_protocol { + PROTOCOL_UNDEF, + PROTOCOL_ERROR, + PROTOCOL_TEXT, + PROTOCOL_I3BAR, +}; + +struct text_protocol_state { + char *buffer; + size_t buffer_size; +}; -struct status_line { - list_t *block_line; - const char *text_line; - command_protocol protocol; +enum json_node_type { + JSON_NODE_UNKNOWN, + JSON_NODE_ARRAY, + JSON_NODE_STRING, +}; + +struct i3bar_protocol_state { bool click_events; + char *buffer; + size_t buffer_size; + size_t buffer_index; + const char *current_node; + bool escape; + size_t depth; + enum json_node_type nodes[16]; }; -struct status_block { +struct i3bar_block { + struct wl_list link; char *full_text, *short_text, *align; bool urgent; - uint32_t color; + uint32_t *color; int min_width; char *name, *instance; bool separator; @@ -32,30 +51,27 @@ struct status_block { int border_bottom; int border_left; int border_right; - - // Set during rendering - int x; - int width; }; -/** - * Initialize status line struct. - */ -struct status_line *init_status_line(); +struct status_line { + pid_t pid; + int read_fd, write_fd; + FILE *read, *write; -/** - * handle status line activity. - */ -bool handle_status_line(struct bar *bar); + enum status_protocol protocol; + const char *text; + struct wl_list blocks; // i3bar_block::link -/** - * Handle mouse clicks. - */ -bool status_line_mouse_event(struct bar *bar, int x, int y, uint32_t button); + struct text_protocol_state text_state; + struct i3bar_protocol_state i3bar_state; +}; -/** - * Free status line struct. - */ -void free_status_line(struct status_line *line); +struct status_line *status_line_init(char *cmd); +void status_error(struct status_line *status, const char *text); +bool status_handle_readable(struct status_line *status); +void status_line_free(struct status_line *status); +bool i3bar_handle_readable(struct status_line *status); +void i3bar_block_send_click(struct status_line *status, + struct i3bar_block *block, int x, int y, uint32_t button); -#endif /* _SWAYBAR_STATUS_LINE_H */ +#endif |