diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-03-30 00:11:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-30 00:11:00 -0400 |
commit | 9d7f47746cdcb0eed3cf41875d06a8ef238eef1c (patch) | |
tree | 997658454de40db3f8b76b68d658efaf2b686188 /include | |
parent | 7162b9bea4d66d61376ad3605e23e2d83bb95201 (diff) | |
parent | f26ecd9f58bb672fe107660ce9b37f4bf0777a8c (diff) |
Merge pull request #1648 from swaywm/swaybar-layers
Port swaybar to layer shell
Diffstat (limited to 'include')
-rw-r--r-- | include/pango.h | 16 | ||||
-rw-r--r-- | include/sway/commands.h | 4 | ||||
-rw-r--r-- | include/sway/config.h | 46 | ||||
-rw-r--r-- | include/sway/ipc-json.h | 1 | ||||
-rw-r--r-- | include/sway/ipc-server.h | 4 | ||||
-rw-r--r-- | include/sway/layers.h | 2 | ||||
-rw-r--r-- | include/sway/output.h | 1 | ||||
-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 |
13 files changed, 121 insertions, 218 deletions
diff --git a/include/pango.h b/include/pango.h new file mode 100644 index 00000000..f6325f28 --- /dev/null +++ b/include/pango.h @@ -0,0 +1,16 @@ +#ifndef _SWAY_PANGO_H +#define _SWAY_PANGO_H +#include <stdarg.h> +#include <stdbool.h> +#include <stdint.h> +#include <cairo/cairo.h> +#include <pango/pangocairo.h> + +PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, + const char *text, int32_t scale, bool markup); +void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, + int32_t scale, bool markup, const char *fmt, ...); +void pango_printf(cairo_t *cairo, const char *font, + int32_t scale, bool markup, const char *fmt, ...); + +#endif diff --git a/include/sway/commands.h b/include/sway/commands.h index 9ff18823..1291d5fb 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -74,6 +74,9 @@ void free_cmd_results(struct cmd_results *results); */ const char *cmd_results_to_json(struct cmd_results *results); +struct cmd_results *add_color(const char *name, + char *buffer, const char *color); + typedef struct cmd_results *sway_cmd(int argc, char **argv); sway_cmd cmd_assign; @@ -138,6 +141,7 @@ sway_cmd cmd_splith; sway_cmd cmd_splitt; sway_cmd cmd_splitv; sway_cmd cmd_sticky; +sway_cmd cmd_swaybg_command; sway_cmd cmd_unmark; sway_cmd cmd_workspace; sway_cmd cmd_ws_auto_back_and_forth; diff --git a/include/sway/config.h b/include/sway/config.h index 7fdd0be0..ac1105b4 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -1,17 +1,18 @@ #ifndef _SWAY_CONFIG_H #define _SWAY_CONFIG_H - #define PID_WORKSPACE_TIMEOUT 60 - #include <libinput.h> #include <stdint.h> #include <string.h> +#include <time.h> #include <wlr/types/wlr_box.h> #include <xkbcommon/xkbcommon.h> -#include <time.h> #include "list.h" #include "tree/layout.h" #include "tree/container.h" +#include "wlr-layer-shell-unstable-v1-protocol.h" + +// TODO: Refactor this shit /** * Describes a variable created via the `set` command. @@ -152,24 +153,13 @@ struct bar_config { char *id; uint32_t modifier; list_t *outputs; - //enum desktop_shell_panel_position position; // TODO + char *position; list_t *bindings; char *status_command; bool pango_markup; char *swaybar_command; char *font; int height; // -1 not defined - -#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 - bool workspace_buttons; bool wrap_scroll; char *separator_symbol; @@ -292,6 +282,7 @@ struct sway_config { list_t *active_bar_modifiers; struct sway_mode *current_mode; struct bar_config *current_bar; + char *swaybg_command; uint32_t floating_mod; uint32_t dragging_key; uint32_t resizing_key; @@ -420,11 +411,6 @@ void apply_output_config(struct output_config *oc, struct sway_container *output); void free_output_config(struct output_config *oc); -/** - * Updates the list of active bar modifiers - */ -void update_active_bar_modifiers(void); - int workspace_output_cmp_workspace(const void *a, const void *b); int sway_binding_cmp(const void *a, const void *b); @@ -433,27 +419,17 @@ int sway_binding_cmp_keys(const void *a, const void *b); void free_sway_binding(struct sway_binding *sb); struct sway_binding *sway_binding_dup(struct sway_binding *sb); -int sway_mouse_binding_cmp(const void *a, const void *b); -int sway_mouse_binding_cmp_qsort(const void *a, const void *b); -int sway_mouse_binding_cmp_buttons(const void *a, const void *b); -void free_sway_mouse_binding(struct sway_mouse_binding *smb); - +/* Bar stuff */ void load_swaybars(); +void invoke_swaybar(struct bar_config *bar); void terminate_swaybg(pid_t pid); - -/** - * Allocate and initialize default bar configuration. - */ struct bar_config *default_bar_config(void); +void free_bar_config(struct bar_config *bar); -/** - * Global config singleton. - */ +/* Global config singleton. */ extern struct sway_config *config; -/** - * Config file currently being read. - */ +/* Config file currently being read */ extern const char *current_config_path; #endif diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h index 3d2fdc4f..7d87d377 100644 --- a/include/sway/ipc-json.h +++ b/include/sway/ipc-json.h @@ -9,5 +9,6 @@ json_object *ipc_json_get_version(); json_object *ipc_json_describe_container(struct sway_container *c); json_object *ipc_json_describe_container_recursive(struct sway_container *c); json_object *ipc_json_describe_input(struct sway_input_device *device); +json_object *ipc_json_describe_bar_config(struct bar_config *bar); #endif diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index d73006dc..c3389fe8 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h @@ -12,6 +12,10 @@ void ipc_terminate(void); struct sockaddr_un *ipc_user_sockaddr(void); +void ipc_event_workspace(struct sway_container *old, + struct sway_container *new, const char *change); void ipc_event_window(struct sway_container *window, const char *change); +void ipc_event_barconfig_update(struct bar_config *bar); +void ipc_event_mode(const char *mode); #endif diff --git a/include/sway/layers.h b/include/sway/layers.h index 22054be1..ee47c5ad 100644 --- a/include/sway/layers.h +++ b/include/sway/layers.h @@ -14,8 +14,6 @@ struct sway_layer_surface { struct wl_listener unmap; struct wl_listener surface_commit; struct wl_listener output_destroy; - struct wl_listener output_mode; - struct wl_listener output_transform; bool configured; struct wlr_box geo; diff --git a/include/sway/output.h b/include/sway/output.h index f899230f..6fb79987 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -21,6 +21,7 @@ struct sway_output { struct wl_listener frame; struct wl_listener destroy; struct wl_listener mode; + struct wl_listener transform; pid_t bg_pid; }; 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 @@ #ifndef _SWAYBAR_BAR_H #define _SWAYBAR_BAR_H - -#include "client/registry.h" -#include "client/window.h" +#include <wayland-client.h> +#include "pool-buffer.h" #include "list.h" -struct bar { - struct config *config; +struct swaybar_config; +struct swaybar_output; +struct swaybar_workspace; + +struct swaybar { + struct wl_display *display; + struct wl_compositor *compositor; + struct zwlr_layer_shell_v1 *layer_shell; + struct wl_shm *shm; + + struct swaybar_config *config; + struct swaybar_output *focused_output; 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; + + struct wl_list workspaces; + char *name; - int idx; + size_t index; bool focused; + + uint32_t width, height; + 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 +51,11 @@ struct workspace { bool urgent; }; -/** Global bar state */ -extern struct bar swaybar; +// TODO: Rename stuff to match wlroots conventions (init/create/etc) +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); -/** 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); - -/** - * 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..7634cb16 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h @@ -1,49 +1,35 @@ #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; - 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 - + struct wl_list outputs; int height; struct { @@ -63,24 +49,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..278baef0 100644 --- a/include/swaybar/ipc.h +++ b/include/swaybar/ipc.h @@ -1,23 +1,10 @@ #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_event(struct swaybar *bar); +void ipc_get_workspaces(struct swaybar *bar); +#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..6c595df0 100644 --- a/include/swaybar/status_line.h +++ b/include/swaybar/status_line.h @@ -1,61 +1,30 @@ #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_TEXT, + PROTOCOL_I3BAR, +}; struct status_line { - list_t *block_line; - const char *text_line; - command_protocol protocol; - bool click_events; -}; + pid_t pid; + int read_fd, write_fd; + FILE *read, *write; -struct status_block { - char *full_text, *short_text, *align; - bool urgent; - uint32_t color; - int min_width; - char *name, *instance; - bool separator; - int separator_block_width; - bool markup; - // Airblader features - uint32_t background; - uint32_t border; - int border_top; - int border_bottom; - int border_left; - int border_right; + enum status_protocol protocol; + const char *text; - // Set during rendering - int x; - int width; + char *buffer; + size_t buffer_size; }; -/** - * Initialize status line struct. - */ -struct status_line *init_status_line(); - -/** - * handle status line activity. - */ -bool handle_status_line(struct bar *bar); - -/** - * Handle mouse clicks. - */ -bool status_line_mouse_event(struct bar *bar, int x, int y, uint32_t button); - -/** - * Free status line struct. - */ -void free_status_line(struct status_line *line); +struct status_line *status_line_init(char *cmd); +void status_line_free(struct status_line *status); +bool handle_status_readable(struct status_line *status); -#endif /* _SWAYBAR_STATUS_LINE_H */ +#endif |