From a9c09932188be010967dd9c78f1a0c5381f3ba63 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Wed, 31 Aug 2016 21:07:20 -0500 Subject: document `orientation` command --- sway/sway.5.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 7de02a82..84e5e7c5 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt @@ -39,6 +39,9 @@ The following commands may only be used in the configuration file. **set** :: Sets variable $name to _value_. You can use the new variable in the arguments of future commands. + +**orientation** :: + Sets the default container layout for tiled containers. The following commands cannot be used directly in the configuration file. They are expected to be used with **bindsym** or at runtime through **swaymsg**(1). -- cgit v1.2.3-54-g00ecf From 8c5e84c79d817f67a8fd72f28d576e44f518073a Mon Sep 17 00:00:00 2001 From: Fabio Alessandro Locati Date: Thu, 1 Sep 2016 08:40:26 +0200 Subject: Add Fedora official packages mention :) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4ea135e7..fc086bb1 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Sway is not supported by many distributions yet. Here's a list of packages available for you to install: * [Arch Linux](https://github.com/SirCmpwn/sway/wiki/Install-from-packages#arch) +* [Fedora](https://github.com/SirCmpwn/sway/wiki/Install-from-packages#fedora) * [Gentoo](https://github.com/SirCmpwn/sway/wiki/Install-from-packages#gentoo) * [NixOS](https://github.com/SirCmpwn/sway/wiki/Install-from-packages#nixos) * [openSUSE Tumbleweed](https://github.com/SirCmpwn/sway/wiki/Install-from-packages#opensuse) -- cgit v1.2.3-54-g00ecf From 416417a54c5875abcdc257b6ad10ff086c35eefc Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 1 Sep 2016 08:18:37 -0400 Subject: Reorganize includes --- common/ipc-client.c | 11 +- common/log.c | 16 +-- common/util.c | 7 +- include/bar/bar.h | 63 --------- include/bar/config.h | 71 ---------- include/bar/ipc.h | 23 --- include/bar/render.h | 22 --- include/bar/status_line.h | 51 ------- include/border.h | 28 ---- include/commands.h | 64 --------- include/config.h | 320 ------------------------------------------ include/container.h | 312 ---------------------------------------- include/criteria.h | 36 ----- include/extensions.h | 49 ------- include/focus.h | 43 ------ include/handlers.h | 11 -- include/input.h | 23 --- include/input_state.h | 102 -------------- include/ipc-json.h | 14 -- include/ipc-server.h | 41 ------ include/layout.h | 78 ---------- include/lock/lock.h | 37 ----- include/output.h | 24 ---- include/resize.h | 14 -- include/sway/border.h | 28 ++++ include/sway/commands.h | 64 +++++++++ include/sway/config.h | 320 ++++++++++++++++++++++++++++++++++++++++++ include/sway/container.h | 312 ++++++++++++++++++++++++++++++++++++++++ include/sway/criteria.h | 36 +++++ include/sway/extensions.h | 49 +++++++ include/sway/focus.h | 43 ++++++ include/sway/handlers.h | 11 ++ include/sway/input.h | 23 +++ include/sway/input_state.h | 102 ++++++++++++++ include/sway/ipc-json.h | 14 ++ include/sway/ipc-server.h | 41 ++++++ include/sway/layout.h | 78 ++++++++++ include/sway/output.h | 24 ++++ include/sway/resize.h | 14 ++ include/sway/workspace.h | 22 +++ include/swaybar/bar.h | 63 +++++++++ include/swaybar/config.h | 71 ++++++++++ include/swaybar/ipc.h | 23 +++ include/swaybar/render.h | 22 +++ include/swaybar/status_line.h | 51 +++++++ include/swaylock/swaylock.h | 37 +++++ include/workspace.h | 22 --- sway/border.c | 6 +- sway/commands.c | 30 ++-- sway/config.c | 14 +- sway/container.c | 20 +-- sway/criteria.c | 6 +- sway/debug_log.c | 2 +- sway/extensions.c | 8 +- sway/focus.c | 15 +- sway/handlers.c | 35 +++-- sway/input.c | 4 +- sway/input_state.c | 5 +- sway/ipc-json.c | 4 +- sway/ipc-server.c | 12 +- sway/layout.c | 20 +-- sway/main.c | 18 +-- sway/output.c | 2 +- sway/resize.c | 10 +- sway/workspace.c | 20 +-- swaybar/bar.c | 11 +- swaybar/config.c | 2 +- swaybar/ipc.c | 5 +- swaybar/main.c | 2 +- swaybar/render.c | 6 +- swaybar/status_line.c | 4 +- swaylock/main.c | 3 +- 72 files changed, 1593 insertions(+), 1601 deletions(-) delete mode 100644 include/bar/bar.h delete mode 100644 include/bar/config.h delete mode 100644 include/bar/ipc.h delete mode 100644 include/bar/render.h delete mode 100644 include/bar/status_line.h delete mode 100644 include/border.h delete mode 100644 include/commands.h delete mode 100644 include/config.h delete mode 100644 include/container.h delete mode 100644 include/criteria.h delete mode 100644 include/extensions.h delete mode 100644 include/focus.h delete mode 100644 include/handlers.h delete mode 100644 include/input.h delete mode 100644 include/input_state.h delete mode 100644 include/ipc-json.h delete mode 100644 include/ipc-server.h delete mode 100644 include/layout.h delete mode 100644 include/lock/lock.h delete mode 100644 include/output.h delete mode 100644 include/resize.h create mode 100644 include/sway/border.h create mode 100644 include/sway/commands.h create mode 100644 include/sway/config.h create mode 100644 include/sway/container.h create mode 100644 include/sway/criteria.h create mode 100644 include/sway/extensions.h create mode 100644 include/sway/focus.h create mode 100644 include/sway/handlers.h create mode 100644 include/sway/input.h create mode 100644 include/sway/input_state.h create mode 100644 include/sway/ipc-json.h create mode 100644 include/sway/ipc-server.h create mode 100644 include/sway/layout.h create mode 100644 include/sway/output.h create mode 100644 include/sway/resize.h create mode 100644 include/sway/workspace.h create mode 100644 include/swaybar/bar.h create mode 100644 include/swaybar/config.h create mode 100644 include/swaybar/ipc.h create mode 100644 include/swaybar/render.h create mode 100644 include/swaybar/status_line.h create mode 100644 include/swaylock/swaylock.h delete mode 100644 include/workspace.h diff --git a/common/ipc-client.c b/common/ipc-client.c index e155c168..106f9d86 100644 --- a/common/ipc-client.c +++ b/common/ipc-client.c @@ -1,16 +1,13 @@ +#include #include #include #include -#include -#include -#include #include +#include #include -#include "log.h" -#include "stringop.h" -#include "ipc.h" -#include "readline.h" #include "ipc-client.h" +#include "readline.h" +#include "log.h" static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'}; static const size_t ipc_header_size = sizeof(ipc_magic)+8; diff --git a/common/log.c b/common/log.c index 1da2ba2f..4f0baa3f 100644 --- a/common/log.c +++ b/common/log.c @@ -1,17 +1,15 @@ -#include "log.h" -#include "sway.h" -#include "readline.h" +#include +#include +#include #include #include #include -#include -#include #include -#include -#include -#include #include -#include +#include +#include "log.h" +#include "sway.h" +#include "readline.h" static int colored = 1; static log_importance_t loglevel_default = L_ERROR; diff --git a/common/util.c b/common/util.c index f0b0fdf0..f2302676 100644 --- a/common/util.c +++ b/common/util.c @@ -1,10 +1,13 @@ #include +#include #include -#include #include +#include +#include +#include +#include "log.h" #include "readline.h" #include "util.h" -#include "log.h" int wrap(int i, int max) { return ((i % max) + max) % max; diff --git a/include/bar/bar.h b/include/bar/bar.h deleted file mode 100644 index a3c511d9..00000000 --- a/include/bar/bar.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _SWAYBAR_BAR_H -#define _SWAYBAR_BAR_H - -#include "client/registry.h" -#include "client/window.h" -#include "list.h" - -struct bar { - struct config *config; - struct status_line *status; - list_t *outputs; - - int ipc_event_socketfd; - int ipc_socketfd; - int status_read_fd; - pid_t status_command_pid; -}; - -struct output { - struct window *window; - struct registry *registry; - list_t *workspaces; - char *name; - int idx; -}; - -struct workspace { - int num; - char *name; - bool focused; - bool visible; - bool urgent; -}; - -/** Global bar state */ -extern struct bar swaybar; - -/** - * 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 */ diff --git a/include/bar/config.h b/include/bar/config.h deleted file mode 100644 index 934116ca..00000000 --- a/include/bar/config.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef _SWAYBAR_CONFIG_H -#define _SWAYBAR_CONFIG_H - -#include -#include - -#include "list.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 { - char *status_command; - bool pango_markup; - uint32_t position; - char *font; - char *sep_symbol; - char *mode; - bool strip_workspace_numbers; - bool binding_mode_indicator; - bool wrap_scroll; - bool workspace_buttons; - bool all_outputs; - list_t *outputs; - - int height; - - struct { - uint32_t background; - uint32_t statusline; - uint32_t separator; - - struct box_colors focused_workspace; - struct box_colors active_workspace; - struct box_colors inactive_workspace; - struct box_colors urgent_workspace; - struct box_colors binding_mode; - } colors; -}; - -/** - * Parse position top|bottom|left|right. - */ -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 */ diff --git a/include/bar/ipc.h b/include/bar/ipc.h deleted file mode 100644 index c11931d0..00000000 --- a/include/bar/ipc.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _SWAYBAR_IPC_H -#define _SWAYBAR_IPC_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 */ - diff --git a/include/bar/render.h b/include/bar/render.h deleted file mode 100644 index 114f43f4..00000000 --- a/include/bar/render.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _SWAYBAR_RENDER_H -#define _SWAYBAR_RENDER_H - -#include "config.h" -#include "bar.h" - -/** - * Render swaybar. - */ -void render(struct output *output, struct config *config, struct status_line *line); - -/** - * 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 */ diff --git a/include/bar/status_line.h b/include/bar/status_line.h deleted file mode 100644 index 9b77e8a7..00000000 --- a/include/bar/status_line.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef _SWAYBAR_STATUS_LINE_H -#define _SWAYBAR_STATUS_LINE_H - -#include -#include - -#include "list.h" -#include "bar.h" - -typedef enum {UNDEF, TEXT, I3BAR} command_protocol; - -struct status_line { - list_t *block_line; - const char *text_line; - command_protocol protocol; -}; - -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; -}; - -/** - * Initialize status line struct. - */ -struct status_line *init_status_line(); - -/** - * handle status line activity. - */ -bool handle_status_line(struct bar *bar); - -/** - * Free status line struct. - */ -void free_status_line(struct status_line *line); - -#endif /* _SWAYBAR_STATUS_LINE_H */ diff --git a/include/border.h b/include/border.h deleted file mode 100644 index c30c9da3..00000000 --- a/include/border.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _SWAY_BORDER_H -#define _SWAY_BORDER_H -#include -#include "container.h" - -/** - * Border pixel buffer and corresponding geometry. - */ -struct border { - unsigned char *buffer; - struct wlc_geometry geometry; -}; - -/** - * Clear border buffer. - */ -void border_clear(struct border *border); - -/** - * Recursively update all of the borders within a container. - */ -void update_container_border(swayc_t *container); - -void render_view_borders(wlc_handle view); -int get_font_text_height(const char *font); -bool should_hide_top_border(swayc_t *con, double y); - -#endif diff --git a/include/commands.h b/include/commands.h deleted file mode 100644 index cd0610f4..00000000 --- a/include/commands.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _SWAY_COMMANDS_H -#define _SWAY_COMMANDS_H -#include -#include -#include -#include "config.h" - -/** - * Indicates the result of a command's execution. - */ -enum cmd_status { - CMD_SUCCESS, /**< The command was successful */ - CMD_FAILURE, /**< The command resulted in an error */ - CMD_INVALID, /**< Unknown command or parser error */ - CMD_DEFER, /**< Command execution deferred */ - // Config Blocks - CMD_BLOCK_END, - CMD_BLOCK_MODE, - CMD_BLOCK_BAR, - CMD_BLOCK_BAR_COLORS, - CMD_BLOCK_INPUT -}; - -/** - * Stores the result of executing a command. - */ -struct cmd_results { - enum cmd_status status; - char *input; - /** - * Human friendly error message, or NULL on success - */ - char *error; -}; - -/** - * Parse and handles a command. - */ -struct cmd_results *handle_command(char *command); -/** - * Parse and handles a command during config file loading. - * - * Do not use this under normal conditions. - */ -struct cmd_results *config_command(char *command, enum cmd_status block); - -/** - * Allocates a cmd_results object. - */ -struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *error, ...); -/** - * Frees a cmd_results object. - */ -void free_cmd_results(struct cmd_results *results); -/** - * Serializes cmd_results to a JSON string. - * - * Free the JSON string later on. - */ -const char *cmd_results_to_json(struct cmd_results *results); - -void remove_view_from_scratchpad(swayc_t *); - -#endif diff --git a/include/config.h b/include/config.h deleted file mode 100644 index 56deaf01..00000000 --- a/include/config.h +++ /dev/null @@ -1,320 +0,0 @@ -#ifndef _SWAY_CONFIG_H -#define _SWAY_CONFIG_H - -#define PID_WORKSPACE_TIMEOUT 60 - -#include -#include -#include -#include -#include -#include -#include "wayland-desktop-shell-server-protocol.h" -#include "list.h" -#include "layout.h" -#include "container.h" - -/** - * Describes a variable created via the `set` command. - */ -struct sway_variable { - char *name; - char *value; -}; - -/** - * A key binding and an associated command. - */ -struct sway_binding { - int order; - bool release; - bool bindcode; - list_t *keys; - uint32_t modifiers; - char *command; -}; - -/** - * A mouse binding and an associated command. - */ -struct sway_mouse_binding { - uint32_t button; - char *command; -}; - -/** - * A "mode" of keybindings created via the `mode` command. - */ -struct sway_mode { - char *name; - list_t *bindings; -}; - -/** - * libinput options for input devices - */ -struct input_config { - char *identifier; - - int accel_profile; - int click_method; - int drag_lock; - int dwt; - int middle_emulation; - int natural_scroll; - float pointer_accel; - int scroll_method; - int send_events; - int tap; - - bool capturable; - struct wlc_geometry region; -}; - -/** - * Size and position configuration for a particular output. - * - * This is set via the `output` command. - */ -struct output_config { - char *name; - int enabled; - int width, height; - int x, y; - int scale; - char *background; - char *background_option; -}; - -/** - * Maps a workspace name to an output name. - * - * Set via `workspace output ` - */ -struct workspace_output { - char *output; - char *workspace; -}; - -struct pid_workspace { - pid_t *pid; - char *workspace; - time_t *time_added; -}; - -void pid_workspace_add(struct pid_workspace *pw); -void free_pid_workspace(struct pid_workspace *pw); - -struct bar_config { - /** - * One of "dock", "hide", "invisible" - * - * Always visible in dock mode. Visible only when modifier key is held in hide mode. - * Never visible in invisible mode. - */ - char *mode; - /** - * One of "show" or "hide". - * - * In "show" mode, it will always be shown on top of the active workspace. - */ - char *hidden_state; - /** - * Id name used to identify the bar through IPC. - * - * Defaults to bar-x, where x corresponds to the position of the - * embedding bar block in the config file (bar-0, bar-1, ...). - */ - char *id; - uint32_t modifier; - list_t *outputs; - enum desktop_shell_panel_position position; - list_t *bindings; - char *status_command; - bool pango_markup; - char *swaybar_command; - char *font; - int height; // -1 not defined - int tray_padding; - bool workspace_buttons; - bool wrap_scroll; - char *separator_symbol; - bool strip_workspace_numbers; - bool binding_mode_indicator; - bool verbose; - pid_t pid; - struct { - char background[10]; - char statusline[10]; - char separator[10]; - char focused_workspace_border[10]; - char focused_workspace_bg[10]; - char focused_workspace_text[10]; - char active_workspace_border[10]; - char active_workspace_bg[10]; - char active_workspace_text[10]; - char inactive_workspace_border[10]; - char inactive_workspace_bg[10]; - char inactive_workspace_text[10]; - char urgent_workspace_border[10]; - char urgent_workspace_bg[10]; - char urgent_workspace_text[10]; - char binding_mode_border[10]; - char binding_mode_bg[10]; - char binding_mode_text[10]; - } colors; -}; - -struct border_colors { - uint32_t border; - uint32_t background; - uint32_t text; - uint32_t indicator; - uint32_t child_border; -}; - -enum edge_border_types { - E_NONE, /**< Don't hide edge borders */ - E_VERTICAL, /**< hide vertical edge borders */ - E_HORIZONTAL, /**< hide horizontal edge borders */ - E_BOTH /**< hide vertical and horizontal edge borders */ -}; - -/** - * The configuration struct. The result of loading a config file. - */ -struct sway_config { - list_t *symbols; - list_t *modes; - list_t *bars; - list_t *cmd_queue; - list_t *workspace_outputs; - list_t *pid_workspaces; - list_t *output_configs; - list_t *input_configs; - list_t *criteria; - list_t *active_bar_modifiers; - struct sway_mode *current_mode; - struct bar_config *current_bar; - uint32_t floating_mod; - uint32_t dragging_key; - uint32_t resizing_key; - char *floating_scroll_up_cmd; - char *floating_scroll_down_cmd; - char *floating_scroll_left_cmd; - char *floating_scroll_right_cmd; - enum swayc_layouts default_orientation; - enum swayc_layouts default_layout; - char *font; - int font_height; - - // Flags - bool focus_follows_mouse; - bool mouse_warping; - bool active; - bool failed; - bool reloading; - bool reading; - bool auto_back_and_forth; - bool seamless_mouse; - - bool edge_gaps; - bool smart_gaps; - int gaps_inner; - int gaps_outer; - - list_t *config_chain; - const char *current_config; - - enum swayc_border_types border; - enum swayc_border_types floating_border; - int border_thickness; - int floating_border_thickness; - enum edge_border_types hide_edge_borders; - - // border colors - struct { - struct border_colors focused; - struct border_colors focused_inactive; - struct border_colors unfocused; - struct border_colors urgent; - struct border_colors placeholder; - uint32_t background; - } border_colors; - - // floating view - int32_t floating_maximum_width; - int32_t floating_maximum_height; - int32_t floating_minimum_width; - int32_t floating_minimum_height; -}; - -/** - * Loads the main config from the given path. is_active should be true when - * reloading the config. - */ -bool load_main_config(const char *path, bool is_active); - -/** - * Loads an included config. Can only be used after load_main_config. - */ -bool load_include_configs(const char *path, struct sway_config *config); - -/** - * Reads the config from the given FILE. - */ -bool read_config(FILE *file, struct sway_config *config); - -/** - * Free config struct - */ -void free_config(struct sway_config *config); -/** - * Does variable replacement for a string based on the config's currently loaded variables. - */ -char *do_var_replacement(char *str); - -int input_identifier_cmp(const void *item, const void *data); -void merge_input_config(struct input_config *dst, struct input_config *src); -void apply_input_config(struct input_config *ic, struct libinput_device *dev); -void free_input_config(struct input_config *ic); - -int output_name_cmp(const void *item, const void *data); -void merge_output_config(struct output_config *dst, struct output_config *src); -/** Sets up a WLC output handle based on a given output_config. - */ -void apply_output_config(struct output_config *oc, swayc_t *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); -int sway_binding_cmp_qsort(const void *a, const void *b); -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); - -void load_swaybars(); -void terminate_swaybg(pid_t pid); - -/** - * Allocate and initialize default bar configuration. - */ -struct bar_config *default_bar_config(void); - -/** - * Global config singleton. - */ -extern struct sway_config *config; - -#endif diff --git a/include/container.h b/include/container.h deleted file mode 100644 index 4dd7f3a0..00000000 --- a/include/container.h +++ /dev/null @@ -1,312 +0,0 @@ -#ifndef _SWAY_CONTAINER_H -#define _SWAY_CONTAINER_H -#include -#include - -#include "list.h" - -typedef struct sway_container swayc_t; - -extern swayc_t root_container; - -/** - * Different kinds of containers. - * - * This enum is in order. A container will never be inside of a container below - * it on this list. - */ -enum swayc_types { - C_ROOT, /**< The root container. Only one of these ever exists. */ - C_OUTPUT, /**< An output (aka monitor, head, etc). */ - C_WORKSPACE, /**< A workspace. */ - C_CONTAINER, /**< A manually created container. */ - C_VIEW, /**< A view (aka window). */ - // Keep last - C_TYPES, -}; - -/** - * Different ways to arrange a container. - */ -enum swayc_layouts { - L_NONE, /**< Used for containers that have no layout (views, root) */ - L_HORIZ, - L_VERT, - L_STACKED, - L_TABBED, - L_FLOATING, /**< A psuedo-container, removed from the tree, to hold floating windows */ - // Keep last - L_LAYOUTS, -}; - -enum swayc_border_types { - B_NONE, /**< No border */ - B_PIXEL, /**< 1px border */ - B_NORMAL /**< Normal border with title bar */ -}; - -/** - * Stores information about a container. - * - * The tree is made of these. Views are containers that cannot have children. - */ -struct sway_container { - /** - * If this container maps to a WLC object, this is set to that object's - * handle. Otherwise, NULL. - */ - wlc_handle handle; - - enum swayc_types type; - enum swayc_layouts layout; - enum swayc_layouts prev_layout; - - /** - * Width and height of this container, without borders or gaps. - */ - double width, height; - - /** - * Views may request geometry, which is stored in this and ignored until - * the views are floated. - */ - int desired_width, desired_height; - - /** - * The coordinates that this view appear at, relative to the output they - * are located on (output containers have absolute coordinates). - */ - double x, y; - - /** - * Cached geometry used to store view/container geometry when switching - * between tabbed/stacked and horizontal/vertical layouts. - */ - struct wlc_geometry cached_geometry; - - /** - * False if this view is invisible. It could be in the scratchpad or on a - * workspace that is not shown. - */ - bool visible; - bool is_floating; - bool is_focused; - bool sticky; // floating view always visible on its output - - // Attributes that mostly views have. - char *name; - char *class; - char *app_id; - - // Used by output containers to keep track of swaybg child processes. - pid_t bg_pid; - - int gaps; - - list_t *children; - /** - * Children of this container that are floated. - */ - list_t *floating; - /** - * Unmanaged view handles in this container. - */ - list_t *unmanaged; - - /** - * The parent of this container. NULL for the root container. - */ - struct sway_container *parent; - /** - * Which of this container's children has focus. - */ - struct sway_container *focused; - /** - * If this container's children include a fullscreen view, this is that view. - */ - struct sway_container *fullscreen; - /** - * If this container is a view, this may be set to the window's decoration - * buffer (or NULL). - */ - struct border *border; - enum swayc_border_types border_type; - struct wlc_geometry border_geometry; - struct wlc_geometry title_bar_geometry; - struct wlc_geometry actual_geometry; - int border_thickness; -}; - -enum visibility_mask { - VISIBLE = true -} visible; - -/** - * Allocates a new output container. - */ -swayc_t *new_output(wlc_handle handle); -/** - * Allocates a new workspace container. - */ -swayc_t *new_workspace(swayc_t *output, const char *name); -/** - * Allocates a new container and places a child into it. - * - * This is used from the split command, which creates a new container with the - * requested layout and replaces the focused container in the tree with the new - * one. Then the removed container is added as a child of the new container. - */ -swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); -/** - * Allocates a new view container. - * - * Pass in a sibling view, or a workspace to become this container's parent. - */ -swayc_t *new_view(swayc_t *sibling, wlc_handle handle); -/** - * Allocates a new floating view in the active workspace. - */ -swayc_t *new_floating_view(wlc_handle handle); - -void floating_view_sane_size(swayc_t *view); - -/** - * Frees an output's container. - */ -swayc_t *destroy_output(swayc_t *output); -/** - * Destroys a workspace container and returns the parent pointer, or NULL. - */ -swayc_t *destroy_workspace(swayc_t *workspace); -/** - * Destroys a container and all empty parents. Returns the topmost non-empty - * parent container, or NULL. - */ -swayc_t *destroy_container(swayc_t *container); -/** - * Destroys a view container and all empty parents. Returns the topmost - * non-empty parent container, or NULL. - */ -swayc_t *destroy_view(swayc_t *view); - -/** - * Finds a container based on test criteria. Returns the first container that - * passes the test. - */ -swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); -/** - * Finds a parent container with the given swayc_type. - */ -swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types); -/** - * Finds a parent with the given swayc_layout. - */ -swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts); -/** - * Finds the bottom-most focused container of a type. - */ -swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types); -/** - * Finds the bottom-most focused container of a layout. - */ -swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts); - -/** - * Gets the swayc_t associated with a wlc_handle. - */ -swayc_t *swayc_by_handle(wlc_handle handle); -/** - * Gets the named swayc_t. - */ -swayc_t *swayc_by_name(const char *name); -/** - * Gets the active output's container. - */ -swayc_t *swayc_active_output(void); -/** - * Gets the active workspace's container. - */ -swayc_t *swayc_active_workspace(void); -/** - * Gets the workspace for the given view container. - */ -swayc_t *swayc_active_workspace_for(swayc_t *view); -/** - * Finds the container currently underneath the pointer. - */ -swayc_t *container_under_pointer(void); - -/** - * Returns true if a container is fullscreen. - */ -bool swayc_is_fullscreen(swayc_t *view); -/** - * Returns true if this view is focused. - */ -bool swayc_is_active(swayc_t *view); -/** - * Returns true if the parent is an ancestor of the child. - */ -bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); -/** - * Returns true if the child is a desecendant of the parent. - */ -bool swayc_is_child_of(swayc_t *child, swayc_t *parent); - -/** - * Returns true if this container is an empty workspace. - */ -bool swayc_is_empty_workspace(swayc_t *container); - -/** - * Returns the top most tabbed or stacked parent container. Returns NULL if - * view is not in a tabbed/stacked layout. - */ -swayc_t *swayc_tabbed_stacked_ancestor(swayc_t *view); - -/** - * Returns the immediate tabbed or stacked parent container. Returns NULL if - * view is not directly in a tabbed/stacked layout. - */ -swayc_t *swayc_tabbed_stacked_parent(swayc_t *view); - -/** - * Returns the gap (padding) of the container. - * - * This returns the inner gaps for a view, the outer gaps for a workspace, and - * 0 otherwise. - */ -int swayc_gap(swayc_t *container); - -/** - * Maps a container's children over a function. - */ -void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); - -/** - * Set a view as visible or invisible. - * - * This will perform the required wlc calls as well; it is not sufficient to - * simply toggle the boolean in swayc_t. - */ -void set_view_visibility(swayc_t *view, void *data); -/** - * Set the gaps value for a view. - */ -void set_gaps(swayc_t *view, void *amount); -/** - * Add to the gaps value for a view. - */ -void add_gaps(swayc_t *view, void *amount); - -/** - * Issue wlc calls to make the visibility of a container consistent. - */ -void update_visibility(swayc_t *container); - -/** - * Close all child views of container - */ -void close_views(swayc_t *container); - -#endif diff --git a/include/criteria.h b/include/criteria.h deleted file mode 100644 index 5c71d172..00000000 --- a/include/criteria.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _SWAY_CRITERIA_H -#define _SWAY_CRITERIA_H - -#include "container.h" -#include "list.h" - -/** - * Maps criteria (as a list of criteria tokens) to a command list. - * - * A list of tokens together represent a single criteria string (e.g. - * '[class="abc" title="xyz"]' becomes two criteria tokens). - * - * for_window: Views matching all criteria will have the bound command list - * executed on them. - * - * Set via `for_window `. - */ -struct criteria { - list_t *tokens; // struct crit_token, contains compiled regex. - char *crit_raw; // entire criteria string (for logging) - - char *cmdlist; -}; - -int criteria_cmp(const void *item, const void *data); -void free_criteria(struct criteria *crit); - -// Pouplate list with crit_tokens extracted from criteria string, returns error -// string or NULL if successful. -char *extract_crit_tokens(list_t *tokens, const char *criteria); - -// Returns list of criteria that match given container. These criteria have -// been set with `for_window` commands and have an associated cmdlist. -list_t *criteria_for(swayc_t *cont); - -#endif diff --git a/include/extensions.h b/include/extensions.h deleted file mode 100644 index f6b0c00e..00000000 --- a/include/extensions.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef _SWAY_EXTENSIONS_H -#define _SWAY_EXTENSIONS_H - -#include -#include -#include "wayland-desktop-shell-server-protocol.h" -#include "list.h" - -struct background_config { - wlc_handle output; - wlc_resource surface; - // we need the wl_resource of the surface in the destructor - struct wl_resource *wl_surface_res; - struct wl_client *client; - wlc_handle handle; -}; - -struct panel_config { - // wayland resource used in callbacks, is used to track this panel - struct wl_resource *wl_resource; - wlc_handle output; - wlc_resource surface; - // we need the wl_resource of the surface in the destructor - struct wl_resource *wl_surface_res; - enum desktop_shell_panel_position panel_position; - // used to determine if client is a panel - struct wl_client *client; - // wlc handle for this panel's surface, not set until panel is created - wlc_handle handle; -}; - -struct desktop_shell_state { - list_t *backgrounds; - list_t *panels; - list_t *lock_surfaces; - bool is_locked; -}; - -struct swaylock_state { - bool active; - wlc_handle output; - wlc_resource surface; -}; - -extern struct desktop_shell_state desktop_shell; - -void register_extensions(void); - -#endif diff --git a/include/focus.h b/include/focus.h deleted file mode 100644 index b532edc2..00000000 --- a/include/focus.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _SWAY_FOCUS_H -#define _SWAY_FOCUS_H -enum movement_direction { - MOVE_LEFT, - MOVE_RIGHT, - MOVE_UP, - MOVE_DOWN, - MOVE_PARENT, - MOVE_CHILD -}; - -#include "container.h" - -// focused_container - the container found by following the `focused` pointer -// from a given container to a container with `is_focused` boolean set -// --- -// focused_view - the container found by following the `focused` pointer from a -// given container to a view. -// --- - -swayc_t *get_focused_container(swayc_t *parent); -swayc_t *get_focused_view(swayc_t *parent); -swayc_t *get_focused_float(swayc_t *ws); - -// a special-case function to get the focused view, regardless -// of whether it's tiled or floating -swayc_t *get_focused_view_include_floating(swayc_t *parent); - -bool set_focused_container(swayc_t *container); -bool set_focused_container_for(swayc_t *ancestor, swayc_t *container); - -// lock focused container/view. locked by windows with OVERRIDE attribute -// and unlocked when they are destroyed - -extern bool locked_container_focus; - -// Prevents wss from being destroyed on focus switch -extern bool suspend_workspace_cleanup; - -bool move_focus(enum movement_direction direction); - -#endif - diff --git a/include/handlers.h b/include/handlers.h deleted file mode 100644 index 956b98f4..00000000 --- a/include/handlers.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _SWAY_HANDLERS_H -#define _SWAY_HANDLERS_H -#include "container.h" -#include -#include - -void register_wlc_handlers(); - -extern uint32_t keys_pressed[32]; - -#endif diff --git a/include/input.h b/include/input.h deleted file mode 100644 index 4ed9bffe..00000000 --- a/include/input.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _SWAY_INPUT_H -#define _SWAY_INPUT_H - -#include -#include "config.h" -#include "list.h" - -struct input_config *new_input_config(const char* identifier); - -char* libinput_dev_unique_id(struct libinput_device *dev); - -/** - * Global input device list. - */ -extern list_t *input_devices; - -/** - * Pointer used when reading input blocked. - * Shared so that it can be cleared from commands.c when closing the block - */ -extern struct input_config *current_input_config; - -#endif diff --git a/include/input_state.h b/include/input_state.h deleted file mode 100644 index 903301fb..00000000 --- a/include/input_state.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef _SWAY_KEY_STATE_H -#define _SWAY_KEY_STATE_H -#include -#include -#include "container.h" - -/* Keyboard state */ - -// returns true if key has been pressed, otherwise false -bool check_key(uint32_t key_sym, uint32_t key_code); - -// returns true if key_sym matches latest released key. -bool check_released_key(uint32_t key_sym); - -// sets a key as pressed -void press_key(uint32_t key_sym, uint32_t key_code); - -// unsets a key as pressed -void release_key(uint32_t key_sym, uint32_t key_code); - - -/* Pointer state */ - -enum pointer_values { - M_LEFT_CLICK = 272, - M_RIGHT_CLICK = 273, - M_SCROLL_CLICK = 274, - M_SCROLL_UP = 275, - M_SCROLL_DOWN = 276, -}; - -enum pointer_mode { - // Target - M_FLOATING = 1, - M_TILING = 2, - // Action - M_DRAGGING = 4, - M_RESIZING = 8, -}; - -struct pointer_button_state { - bool held; - // state at the point it was pressed - int x, y; - swayc_t *view; -}; - -extern struct pointer_state { - // mouse clicks - struct pointer_button_state left; - struct pointer_button_state right; - struct pointer_button_state scroll; - - // change in pointer position - struct { - int x, y; - } delta; - - // view pointer is currently over - swayc_t *view; - - // Pointer mode - int mode; -} pointer_state; - -enum modifier_state { - MOD_STATE_UNCHANGED = 0, - MOD_STATE_PRESSED = 1, - MOD_STATE_RELEASED = 2 -}; - -void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); -void center_pointer_on(swayc_t *view); - -// on button release unset mode depending on the button. -// on button press set mode conditionally depending on the button -void pointer_mode_set(uint32_t button, bool condition); - -// Update mode in mouse motion -void pointer_mode_update(void); - -// Reset mode on any keypress; -void pointer_mode_reset(void); - -void input_init(void); - -/** - * Check if state of mod changed from current state to new_state. - * - * Returns MOD_STATE_UNCHANGED if the state didn't change, MOD_STATE_PRESSED if - * the state changed to pressed and MOD_STATE_RELEASED if the state changed to - * released. - */ -uint32_t modifier_state_changed(uint32_t new_state, uint32_t mod); - -/** - * Update the current modifiers state to new_state. - */ -void modifiers_state_update(uint32_t new_state); - -#endif - diff --git a/include/ipc-json.h b/include/ipc-json.h deleted file mode 100644 index 02b07a23..00000000 --- a/include/ipc-json.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _SWAY_IPC_JSON_H -#define _SWAY_IPC_JSON_H - -#include -#include "config.h" -#include "container.h" - -json_object *ipc_json_get_version(); -json_object *ipc_json_describe_bar_config(struct bar_config *bar); -json_object *ipc_json_describe_container(swayc_t *c); -json_object *ipc_json_describe_container_recursive(swayc_t *c); -json_object *ipc_json_describe_window(swayc_t *c); - -#endif diff --git a/include/ipc-server.h b/include/ipc-server.h deleted file mode 100644 index 1d199134..00000000 --- a/include/ipc-server.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _SWAY_IPC_SERVER_H -#define _SWAY_IPC_SERVER_H - -#include - -#include "container.h" -#include "config.h" -#include "ipc.h" - -void ipc_init(void); -void ipc_terminate(void); -struct sockaddr_un *ipc_user_sockaddr(void); - -void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change); -void ipc_event_barconfig_update(struct bar_config *bar); -/** - * Send IPC mode event to all listening clients - */ -void ipc_event_mode(const char *mode); -/** - * Send IPC window change event - */ -void ipc_event_window(swayc_t *window, const char *change); -/** - * Sends an IPC modifier event to all listening clients. The modifier event - * includes a key 'change' with the value of state and a key 'modifier' with - * the name of that modifier. - */ -void ipc_event_modifier(uint32_t modifier, const char *state); -/** - * Send IPC keyboard binding event. - */ -void ipc_event_binding_keyboard(struct sway_binding *sb); -const char *swayc_type_string(enum swayc_types type); - -/** - * Send pixel data to registered clients. - */ -void ipc_get_pixels(wlc_handle output); - -#endif diff --git a/include/layout.h b/include/layout.h deleted file mode 100644 index b982365c..00000000 --- a/include/layout.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef _SWAY_LAYOUT_H -#define _SWAY_LAYOUT_H - -#include -#include "log.h" -#include "list.h" -#include "container.h" -#include "focus.h" - -extern list_t *scratchpad; - -extern int min_sane_w; -extern int min_sane_h; - -// Set initial values for root_container -void init_layout(void); - -// Returns the index of child for its parent -int index_child(const swayc_t *child); - -// Adds child to parent, if parent has no focus, it is set to child -// parent must be of type C_WORKSPACE or C_CONTAINER -void add_child(swayc_t *parent, swayc_t *child); - -// Adds child to parent at index, if parent has no focus, it is set to child -// parent must be of type C_WORKSPACE or C_CONTAINER -void insert_child(swayc_t *parent, swayc_t *child, int index); - -// Adds child as floating window to ws, if there is no focus it is set to child. -// ws must be of type C_WORKSPACE -void add_floating(swayc_t *ws, swayc_t *child); - -// insert child after sibling in parents children. -swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); - -// Replace child with new_child in parents children -// new_child will inherit childs geometry, childs geometry will be reset -// if parents focus is on child, it will be changed to new_child -swayc_t *replace_child(swayc_t *child, swayc_t *new_child); - -// Remove child from its parent, if focus is on child, focus will be changed to -// a sibling, or to a floating window, or NULL -swayc_t *remove_child(swayc_t *child); - -// 2 containers are swapped, they inherit eachothers focus -void swap_container(swayc_t *a, swayc_t *b); - -// 2 Containers geometry are swapped, used with `swap_container` -void swap_geometry(swayc_t *a, swayc_t *b); - -void move_container(swayc_t* container, enum movement_direction direction); -void move_container_to(swayc_t* container, swayc_t* destination); -void move_workspace_to(swayc_t* workspace, swayc_t* destination); - -// Layout -/** - * Update child container geometries when switching between layouts. - */ -void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout); -void update_geometry(swayc_t *view); -void arrange_windows(swayc_t *container, double width, double height); -void arrange_backgrounds(void); - -swayc_t *get_focused_container(swayc_t *parent); -swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir); -swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_direction dir, swayc_t *limit); - -void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge); - -void layout_log(const swayc_t *c, int depth); -void swayc_log(log_importance_t verbosity, swayc_t *cont, const char* format, ...) __attribute__((format(printf,3,4))); - -/** - * Get default layout. - */ -enum swayc_layouts default_layout(swayc_t *output); - -#endif diff --git a/include/lock/lock.h b/include/lock/lock.h deleted file mode 100644 index 1cf66e89..00000000 --- a/include/lock/lock.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _SWAYLOCK_H -#define _SWAYLOCK_H - -#include "client/cairo.h" - -enum scaling_mode { - SCALING_MODE_STRETCH, - SCALING_MODE_FILL, - SCALING_MODE_FIT, - SCALING_MODE_CENTER, - SCALING_MODE_TILE, -}; - -enum auth_state { - AUTH_STATE_IDLE, - AUTH_STATE_INPUT, - AUTH_STATE_BACKSPACE, - AUTH_STATE_VALIDATING, - AUTH_STATE_INVALID, -}; - -struct render_data { - list_t *surfaces; - // Output specific images - cairo_surface_t **images; - // OR one image for all outputs: - cairo_surface_t *image; - int num_images; - int color_set; - uint32_t color; - enum scaling_mode scaling_mode; - enum auth_state auth_state; -}; - -void render(struct render_data* render_data); - -#endif diff --git a/include/output.h b/include/output.h deleted file mode 100644 index e8afd5ed..00000000 --- a/include/output.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _SWAY_OUTPUT_H -#define _SWAY_OUTPUT_H - -#include "container.h" -#include "focus.h" - -// Position is absolute coordinates on the edge where the adjacent output -// should be searched for. -swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos); -swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir, const struct wlc_point *abs_pos, bool pick_closest); - -// Place absolute coordinates for given container into given wlc_point. -void get_absolute_position(swayc_t *container, struct wlc_point *point); - -// Place absolute coordinates for the center point of given container into -// given wlc_point. -void get_absolute_center_position(swayc_t *container, struct wlc_point *point); - -// stable sort workspaces on this output -void sort_workspaces(swayc_t *output); - -void output_get_scaled_size(wlc_handle handle, struct wlc_size *size); - -#endif diff --git a/include/resize.h b/include/resize.h deleted file mode 100644 index 0d382994..00000000 --- a/include/resize.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _SWAY_RESIZE_H -#define _SWAY_RESIZE_H -#include - -enum resize_dim_types { - RESIZE_DIM_PX, - RESIZE_DIM_PPT, - RESIZE_DIM_DEFAULT, -}; - -bool set_size(int dimension, bool use_width); -bool resize(int dimension, bool use_width, enum resize_dim_types dim_type); - -#endif diff --git a/include/sway/border.h b/include/sway/border.h new file mode 100644 index 00000000..c30c9da3 --- /dev/null +++ b/include/sway/border.h @@ -0,0 +1,28 @@ +#ifndef _SWAY_BORDER_H +#define _SWAY_BORDER_H +#include +#include "container.h" + +/** + * Border pixel buffer and corresponding geometry. + */ +struct border { + unsigned char *buffer; + struct wlc_geometry geometry; +}; + +/** + * Clear border buffer. + */ +void border_clear(struct border *border); + +/** + * Recursively update all of the borders within a container. + */ +void update_container_border(swayc_t *container); + +void render_view_borders(wlc_handle view); +int get_font_text_height(const char *font); +bool should_hide_top_border(swayc_t *con, double y); + +#endif diff --git a/include/sway/commands.h b/include/sway/commands.h new file mode 100644 index 00000000..cd0610f4 --- /dev/null +++ b/include/sway/commands.h @@ -0,0 +1,64 @@ +#ifndef _SWAY_COMMANDS_H +#define _SWAY_COMMANDS_H +#include +#include +#include +#include "config.h" + +/** + * Indicates the result of a command's execution. + */ +enum cmd_status { + CMD_SUCCESS, /**< The command was successful */ + CMD_FAILURE, /**< The command resulted in an error */ + CMD_INVALID, /**< Unknown command or parser error */ + CMD_DEFER, /**< Command execution deferred */ + // Config Blocks + CMD_BLOCK_END, + CMD_BLOCK_MODE, + CMD_BLOCK_BAR, + CMD_BLOCK_BAR_COLORS, + CMD_BLOCK_INPUT +}; + +/** + * Stores the result of executing a command. + */ +struct cmd_results { + enum cmd_status status; + char *input; + /** + * Human friendly error message, or NULL on success + */ + char *error; +}; + +/** + * Parse and handles a command. + */ +struct cmd_results *handle_command(char *command); +/** + * Parse and handles a command during config file loading. + * + * Do not use this under normal conditions. + */ +struct cmd_results *config_command(char *command, enum cmd_status block); + +/** + * Allocates a cmd_results object. + */ +struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *error, ...); +/** + * Frees a cmd_results object. + */ +void free_cmd_results(struct cmd_results *results); +/** + * Serializes cmd_results to a JSON string. + * + * Free the JSON string later on. + */ +const char *cmd_results_to_json(struct cmd_results *results); + +void remove_view_from_scratchpad(swayc_t *); + +#endif diff --git a/include/sway/config.h b/include/sway/config.h new file mode 100644 index 00000000..56deaf01 --- /dev/null +++ b/include/sway/config.h @@ -0,0 +1,320 @@ +#ifndef _SWAY_CONFIG_H +#define _SWAY_CONFIG_H + +#define PID_WORKSPACE_TIMEOUT 60 + +#include +#include +#include +#include +#include +#include +#include "wayland-desktop-shell-server-protocol.h" +#include "list.h" +#include "layout.h" +#include "container.h" + +/** + * Describes a variable created via the `set` command. + */ +struct sway_variable { + char *name; + char *value; +}; + +/** + * A key binding and an associated command. + */ +struct sway_binding { + int order; + bool release; + bool bindcode; + list_t *keys; + uint32_t modifiers; + char *command; +}; + +/** + * A mouse binding and an associated command. + */ +struct sway_mouse_binding { + uint32_t button; + char *command; +}; + +/** + * A "mode" of keybindings created via the `mode` command. + */ +struct sway_mode { + char *name; + list_t *bindings; +}; + +/** + * libinput options for input devices + */ +struct input_config { + char *identifier; + + int accel_profile; + int click_method; + int drag_lock; + int dwt; + int middle_emulation; + int natural_scroll; + float pointer_accel; + int scroll_method; + int send_events; + int tap; + + bool capturable; + struct wlc_geometry region; +}; + +/** + * Size and position configuration for a particular output. + * + * This is set via the `output` command. + */ +struct output_config { + char *name; + int enabled; + int width, height; + int x, y; + int scale; + char *background; + char *background_option; +}; + +/** + * Maps a workspace name to an output name. + * + * Set via `workspace output ` + */ +struct workspace_output { + char *output; + char *workspace; +}; + +struct pid_workspace { + pid_t *pid; + char *workspace; + time_t *time_added; +}; + +void pid_workspace_add(struct pid_workspace *pw); +void free_pid_workspace(struct pid_workspace *pw); + +struct bar_config { + /** + * One of "dock", "hide", "invisible" + * + * Always visible in dock mode. Visible only when modifier key is held in hide mode. + * Never visible in invisible mode. + */ + char *mode; + /** + * One of "show" or "hide". + * + * In "show" mode, it will always be shown on top of the active workspace. + */ + char *hidden_state; + /** + * Id name used to identify the bar through IPC. + * + * Defaults to bar-x, where x corresponds to the position of the + * embedding bar block in the config file (bar-0, bar-1, ...). + */ + char *id; + uint32_t modifier; + list_t *outputs; + enum desktop_shell_panel_position position; + list_t *bindings; + char *status_command; + bool pango_markup; + char *swaybar_command; + char *font; + int height; // -1 not defined + int tray_padding; + bool workspace_buttons; + bool wrap_scroll; + char *separator_symbol; + bool strip_workspace_numbers; + bool binding_mode_indicator; + bool verbose; + pid_t pid; + struct { + char background[10]; + char statusline[10]; + char separator[10]; + char focused_workspace_border[10]; + char focused_workspace_bg[10]; + char focused_workspace_text[10]; + char active_workspace_border[10]; + char active_workspace_bg[10]; + char active_workspace_text[10]; + char inactive_workspace_border[10]; + char inactive_workspace_bg[10]; + char inactive_workspace_text[10]; + char urgent_workspace_border[10]; + char urgent_workspace_bg[10]; + char urgent_workspace_text[10]; + char binding_mode_border[10]; + char binding_mode_bg[10]; + char binding_mode_text[10]; + } colors; +}; + +struct border_colors { + uint32_t border; + uint32_t background; + uint32_t text; + uint32_t indicator; + uint32_t child_border; +}; + +enum edge_border_types { + E_NONE, /**< Don't hide edge borders */ + E_VERTICAL, /**< hide vertical edge borders */ + E_HORIZONTAL, /**< hide horizontal edge borders */ + E_BOTH /**< hide vertical and horizontal edge borders */ +}; + +/** + * The configuration struct. The result of loading a config file. + */ +struct sway_config { + list_t *symbols; + list_t *modes; + list_t *bars; + list_t *cmd_queue; + list_t *workspace_outputs; + list_t *pid_workspaces; + list_t *output_configs; + list_t *input_configs; + list_t *criteria; + list_t *active_bar_modifiers; + struct sway_mode *current_mode; + struct bar_config *current_bar; + uint32_t floating_mod; + uint32_t dragging_key; + uint32_t resizing_key; + char *floating_scroll_up_cmd; + char *floating_scroll_down_cmd; + char *floating_scroll_left_cmd; + char *floating_scroll_right_cmd; + enum swayc_layouts default_orientation; + enum swayc_layouts default_layout; + char *font; + int font_height; + + // Flags + bool focus_follows_mouse; + bool mouse_warping; + bool active; + bool failed; + bool reloading; + bool reading; + bool auto_back_and_forth; + bool seamless_mouse; + + bool edge_gaps; + bool smart_gaps; + int gaps_inner; + int gaps_outer; + + list_t *config_chain; + const char *current_config; + + enum swayc_border_types border; + enum swayc_border_types floating_border; + int border_thickness; + int floating_border_thickness; + enum edge_border_types hide_edge_borders; + + // border colors + struct { + struct border_colors focused; + struct border_colors focused_inactive; + struct border_colors unfocused; + struct border_colors urgent; + struct border_colors placeholder; + uint32_t background; + } border_colors; + + // floating view + int32_t floating_maximum_width; + int32_t floating_maximum_height; + int32_t floating_minimum_width; + int32_t floating_minimum_height; +}; + +/** + * Loads the main config from the given path. is_active should be true when + * reloading the config. + */ +bool load_main_config(const char *path, bool is_active); + +/** + * Loads an included config. Can only be used after load_main_config. + */ +bool load_include_configs(const char *path, struct sway_config *config); + +/** + * Reads the config from the given FILE. + */ +bool read_config(FILE *file, struct sway_config *config); + +/** + * Free config struct + */ +void free_config(struct sway_config *config); +/** + * Does variable replacement for a string based on the config's currently loaded variables. + */ +char *do_var_replacement(char *str); + +int input_identifier_cmp(const void *item, const void *data); +void merge_input_config(struct input_config *dst, struct input_config *src); +void apply_input_config(struct input_config *ic, struct libinput_device *dev); +void free_input_config(struct input_config *ic); + +int output_name_cmp(const void *item, const void *data); +void merge_output_config(struct output_config *dst, struct output_config *src); +/** Sets up a WLC output handle based on a given output_config. + */ +void apply_output_config(struct output_config *oc, swayc_t *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); +int sway_binding_cmp_qsort(const void *a, const void *b); +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); + +void load_swaybars(); +void terminate_swaybg(pid_t pid); + +/** + * Allocate and initialize default bar configuration. + */ +struct bar_config *default_bar_config(void); + +/** + * Global config singleton. + */ +extern struct sway_config *config; + +#endif diff --git a/include/sway/container.h b/include/sway/container.h new file mode 100644 index 00000000..4dd7f3a0 --- /dev/null +++ b/include/sway/container.h @@ -0,0 +1,312 @@ +#ifndef _SWAY_CONTAINER_H +#define _SWAY_CONTAINER_H +#include +#include + +#include "list.h" + +typedef struct sway_container swayc_t; + +extern swayc_t root_container; + +/** + * Different kinds of containers. + * + * This enum is in order. A container will never be inside of a container below + * it on this list. + */ +enum swayc_types { + C_ROOT, /**< The root container. Only one of these ever exists. */ + C_OUTPUT, /**< An output (aka monitor, head, etc). */ + C_WORKSPACE, /**< A workspace. */ + C_CONTAINER, /**< A manually created container. */ + C_VIEW, /**< A view (aka window). */ + // Keep last + C_TYPES, +}; + +/** + * Different ways to arrange a container. + */ +enum swayc_layouts { + L_NONE, /**< Used for containers that have no layout (views, root) */ + L_HORIZ, + L_VERT, + L_STACKED, + L_TABBED, + L_FLOATING, /**< A psuedo-container, removed from the tree, to hold floating windows */ + // Keep last + L_LAYOUTS, +}; + +enum swayc_border_types { + B_NONE, /**< No border */ + B_PIXEL, /**< 1px border */ + B_NORMAL /**< Normal border with title bar */ +}; + +/** + * Stores information about a container. + * + * The tree is made of these. Views are containers that cannot have children. + */ +struct sway_container { + /** + * If this container maps to a WLC object, this is set to that object's + * handle. Otherwise, NULL. + */ + wlc_handle handle; + + enum swayc_types type; + enum swayc_layouts layout; + enum swayc_layouts prev_layout; + + /** + * Width and height of this container, without borders or gaps. + */ + double width, height; + + /** + * Views may request geometry, which is stored in this and ignored until + * the views are floated. + */ + int desired_width, desired_height; + + /** + * The coordinates that this view appear at, relative to the output they + * are located on (output containers have absolute coordinates). + */ + double x, y; + + /** + * Cached geometry used to store view/container geometry when switching + * between tabbed/stacked and horizontal/vertical layouts. + */ + struct wlc_geometry cached_geometry; + + /** + * False if this view is invisible. It could be in the scratchpad or on a + * workspace that is not shown. + */ + bool visible; + bool is_floating; + bool is_focused; + bool sticky; // floating view always visible on its output + + // Attributes that mostly views have. + char *name; + char *class; + char *app_id; + + // Used by output containers to keep track of swaybg child processes. + pid_t bg_pid; + + int gaps; + + list_t *children; + /** + * Children of this container that are floated. + */ + list_t *floating; + /** + * Unmanaged view handles in this container. + */ + list_t *unmanaged; + + /** + * The parent of this container. NULL for the root container. + */ + struct sway_container *parent; + /** + * Which of this container's children has focus. + */ + struct sway_container *focused; + /** + * If this container's children include a fullscreen view, this is that view. + */ + struct sway_container *fullscreen; + /** + * If this container is a view, this may be set to the window's decoration + * buffer (or NULL). + */ + struct border *border; + enum swayc_border_types border_type; + struct wlc_geometry border_geometry; + struct wlc_geometry title_bar_geometry; + struct wlc_geometry actual_geometry; + int border_thickness; +}; + +enum visibility_mask { + VISIBLE = true +} visible; + +/** + * Allocates a new output container. + */ +swayc_t *new_output(wlc_handle handle); +/** + * Allocates a new workspace container. + */ +swayc_t *new_workspace(swayc_t *output, const char *name); +/** + * Allocates a new container and places a child into it. + * + * This is used from the split command, which creates a new container with the + * requested layout and replaces the focused container in the tree with the new + * one. Then the removed container is added as a child of the new container. + */ +swayc_t *new_container(swayc_t *child, enum swayc_layouts layout); +/** + * Allocates a new view container. + * + * Pass in a sibling view, or a workspace to become this container's parent. + */ +swayc_t *new_view(swayc_t *sibling, wlc_handle handle); +/** + * Allocates a new floating view in the active workspace. + */ +swayc_t *new_floating_view(wlc_handle handle); + +void floating_view_sane_size(swayc_t *view); + +/** + * Frees an output's container. + */ +swayc_t *destroy_output(swayc_t *output); +/** + * Destroys a workspace container and returns the parent pointer, or NULL. + */ +swayc_t *destroy_workspace(swayc_t *workspace); +/** + * Destroys a container and all empty parents. Returns the topmost non-empty + * parent container, or NULL. + */ +swayc_t *destroy_container(swayc_t *container); +/** + * Destroys a view container and all empty parents. Returns the topmost + * non-empty parent container, or NULL. + */ +swayc_t *destroy_view(swayc_t *view); + +/** + * Finds a container based on test criteria. Returns the first container that + * passes the test. + */ +swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); +/** + * Finds a parent container with the given swayc_type. + */ +swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types); +/** + * Finds a parent with the given swayc_layout. + */ +swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts); +/** + * Finds the bottom-most focused container of a type. + */ +swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types); +/** + * Finds the bottom-most focused container of a layout. + */ +swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts); + +/** + * Gets the swayc_t associated with a wlc_handle. + */ +swayc_t *swayc_by_handle(wlc_handle handle); +/** + * Gets the named swayc_t. + */ +swayc_t *swayc_by_name(const char *name); +/** + * Gets the active output's container. + */ +swayc_t *swayc_active_output(void); +/** + * Gets the active workspace's container. + */ +swayc_t *swayc_active_workspace(void); +/** + * Gets the workspace for the given view container. + */ +swayc_t *swayc_active_workspace_for(swayc_t *view); +/** + * Finds the container currently underneath the pointer. + */ +swayc_t *container_under_pointer(void); + +/** + * Returns true if a container is fullscreen. + */ +bool swayc_is_fullscreen(swayc_t *view); +/** + * Returns true if this view is focused. + */ +bool swayc_is_active(swayc_t *view); +/** + * Returns true if the parent is an ancestor of the child. + */ +bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); +/** + * Returns true if the child is a desecendant of the parent. + */ +bool swayc_is_child_of(swayc_t *child, swayc_t *parent); + +/** + * Returns true if this container is an empty workspace. + */ +bool swayc_is_empty_workspace(swayc_t *container); + +/** + * Returns the top most tabbed or stacked parent container. Returns NULL if + * view is not in a tabbed/stacked layout. + */ +swayc_t *swayc_tabbed_stacked_ancestor(swayc_t *view); + +/** + * Returns the immediate tabbed or stacked parent container. Returns NULL if + * view is not directly in a tabbed/stacked layout. + */ +swayc_t *swayc_tabbed_stacked_parent(swayc_t *view); + +/** + * Returns the gap (padding) of the container. + * + * This returns the inner gaps for a view, the outer gaps for a workspace, and + * 0 otherwise. + */ +int swayc_gap(swayc_t *container); + +/** + * Maps a container's children over a function. + */ +void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); + +/** + * Set a view as visible or invisible. + * + * This will perform the required wlc calls as well; it is not sufficient to + * simply toggle the boolean in swayc_t. + */ +void set_view_visibility(swayc_t *view, void *data); +/** + * Set the gaps value for a view. + */ +void set_gaps(swayc_t *view, void *amount); +/** + * Add to the gaps value for a view. + */ +void add_gaps(swayc_t *view, void *amount); + +/** + * Issue wlc calls to make the visibility of a container consistent. + */ +void update_visibility(swayc_t *container); + +/** + * Close all child views of container + */ +void close_views(swayc_t *container); + +#endif diff --git a/include/sway/criteria.h b/include/sway/criteria.h new file mode 100644 index 00000000..5c71d172 --- /dev/null +++ b/include/sway/criteria.h @@ -0,0 +1,36 @@ +#ifndef _SWAY_CRITERIA_H +#define _SWAY_CRITERIA_H + +#include "container.h" +#include "list.h" + +/** + * Maps criteria (as a list of criteria tokens) to a command list. + * + * A list of tokens together represent a single criteria string (e.g. + * '[class="abc" title="xyz"]' becomes two criteria tokens). + * + * for_window: Views matching all criteria will have the bound command list + * executed on them. + * + * Set via `for_window `. + */ +struct criteria { + list_t *tokens; // struct crit_token, contains compiled regex. + char *crit_raw; // entire criteria string (for logging) + + char *cmdlist; +}; + +int criteria_cmp(const void *item, const void *data); +void free_criteria(struct criteria *crit); + +// Pouplate list with crit_tokens extracted from criteria string, returns error +// string or NULL if successful. +char *extract_crit_tokens(list_t *tokens, const char *criteria); + +// Returns list of criteria that match given container. These criteria have +// been set with `for_window` commands and have an associated cmdlist. +list_t *criteria_for(swayc_t *cont); + +#endif diff --git a/include/sway/extensions.h b/include/sway/extensions.h new file mode 100644 index 00000000..f6b0c00e --- /dev/null +++ b/include/sway/extensions.h @@ -0,0 +1,49 @@ +#ifndef _SWAY_EXTENSIONS_H +#define _SWAY_EXTENSIONS_H + +#include +#include +#include "wayland-desktop-shell-server-protocol.h" +#include "list.h" + +struct background_config { + wlc_handle output; + wlc_resource surface; + // we need the wl_resource of the surface in the destructor + struct wl_resource *wl_surface_res; + struct wl_client *client; + wlc_handle handle; +}; + +struct panel_config { + // wayland resource used in callbacks, is used to track this panel + struct wl_resource *wl_resource; + wlc_handle output; + wlc_resource surface; + // we need the wl_resource of the surface in the destructor + struct wl_resource *wl_surface_res; + enum desktop_shell_panel_position panel_position; + // used to determine if client is a panel + struct wl_client *client; + // wlc handle for this panel's surface, not set until panel is created + wlc_handle handle; +}; + +struct desktop_shell_state { + list_t *backgrounds; + list_t *panels; + list_t *lock_surfaces; + bool is_locked; +}; + +struct swaylock_state { + bool active; + wlc_handle output; + wlc_resource surface; +}; + +extern struct desktop_shell_state desktop_shell; + +void register_extensions(void); + +#endif diff --git a/include/sway/focus.h b/include/sway/focus.h new file mode 100644 index 00000000..b532edc2 --- /dev/null +++ b/include/sway/focus.h @@ -0,0 +1,43 @@ +#ifndef _SWAY_FOCUS_H +#define _SWAY_FOCUS_H +enum movement_direction { + MOVE_LEFT, + MOVE_RIGHT, + MOVE_UP, + MOVE_DOWN, + MOVE_PARENT, + MOVE_CHILD +}; + +#include "container.h" + +// focused_container - the container found by following the `focused` pointer +// from a given container to a container with `is_focused` boolean set +// --- +// focused_view - the container found by following the `focused` pointer from a +// given container to a view. +// --- + +swayc_t *get_focused_container(swayc_t *parent); +swayc_t *get_focused_view(swayc_t *parent); +swayc_t *get_focused_float(swayc_t *ws); + +// a special-case function to get the focused view, regardless +// of whether it's tiled or floating +swayc_t *get_focused_view_include_floating(swayc_t *parent); + +bool set_focused_container(swayc_t *container); +bool set_focused_container_for(swayc_t *ancestor, swayc_t *container); + +// lock focused container/view. locked by windows with OVERRIDE attribute +// and unlocked when they are destroyed + +extern bool locked_container_focus; + +// Prevents wss from being destroyed on focus switch +extern bool suspend_workspace_cleanup; + +bool move_focus(enum movement_direction direction); + +#endif + diff --git a/include/sway/handlers.h b/include/sway/handlers.h new file mode 100644 index 00000000..956b98f4 --- /dev/null +++ b/include/sway/handlers.h @@ -0,0 +1,11 @@ +#ifndef _SWAY_HANDLERS_H +#define _SWAY_HANDLERS_H +#include "container.h" +#include +#include + +void register_wlc_handlers(); + +extern uint32_t keys_pressed[32]; + +#endif diff --git a/include/sway/input.h b/include/sway/input.h new file mode 100644 index 00000000..4ed9bffe --- /dev/null +++ b/include/sway/input.h @@ -0,0 +1,23 @@ +#ifndef _SWAY_INPUT_H +#define _SWAY_INPUT_H + +#include +#include "config.h" +#include "list.h" + +struct input_config *new_input_config(const char* identifier); + +char* libinput_dev_unique_id(struct libinput_device *dev); + +/** + * Global input device list. + */ +extern list_t *input_devices; + +/** + * Pointer used when reading input blocked. + * Shared so that it can be cleared from commands.c when closing the block + */ +extern struct input_config *current_input_config; + +#endif diff --git a/include/sway/input_state.h b/include/sway/input_state.h new file mode 100644 index 00000000..903301fb --- /dev/null +++ b/include/sway/input_state.h @@ -0,0 +1,102 @@ +#ifndef _SWAY_KEY_STATE_H +#define _SWAY_KEY_STATE_H +#include +#include +#include "container.h" + +/* Keyboard state */ + +// returns true if key has been pressed, otherwise false +bool check_key(uint32_t key_sym, uint32_t key_code); + +// returns true if key_sym matches latest released key. +bool check_released_key(uint32_t key_sym); + +// sets a key as pressed +void press_key(uint32_t key_sym, uint32_t key_code); + +// unsets a key as pressed +void release_key(uint32_t key_sym, uint32_t key_code); + + +/* Pointer state */ + +enum pointer_values { + M_LEFT_CLICK = 272, + M_RIGHT_CLICK = 273, + M_SCROLL_CLICK = 274, + M_SCROLL_UP = 275, + M_SCROLL_DOWN = 276, +}; + +enum pointer_mode { + // Target + M_FLOATING = 1, + M_TILING = 2, + // Action + M_DRAGGING = 4, + M_RESIZING = 8, +}; + +struct pointer_button_state { + bool held; + // state at the point it was pressed + int x, y; + swayc_t *view; +}; + +extern struct pointer_state { + // mouse clicks + struct pointer_button_state left; + struct pointer_button_state right; + struct pointer_button_state scroll; + + // change in pointer position + struct { + int x, y; + } delta; + + // view pointer is currently over + swayc_t *view; + + // Pointer mode + int mode; +} pointer_state; + +enum modifier_state { + MOD_STATE_UNCHANGED = 0, + MOD_STATE_PRESSED = 1, + MOD_STATE_RELEASED = 2 +}; + +void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); +void center_pointer_on(swayc_t *view); + +// on button release unset mode depending on the button. +// on button press set mode conditionally depending on the button +void pointer_mode_set(uint32_t button, bool condition); + +// Update mode in mouse motion +void pointer_mode_update(void); + +// Reset mode on any keypress; +void pointer_mode_reset(void); + +void input_init(void); + +/** + * Check if state of mod changed from current state to new_state. + * + * Returns MOD_STATE_UNCHANGED if the state didn't change, MOD_STATE_PRESSED if + * the state changed to pressed and MOD_STATE_RELEASED if the state changed to + * released. + */ +uint32_t modifier_state_changed(uint32_t new_state, uint32_t mod); + +/** + * Update the current modifiers state to new_state. + */ +void modifiers_state_update(uint32_t new_state); + +#endif + diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h new file mode 100644 index 00000000..02b07a23 --- /dev/null +++ b/include/sway/ipc-json.h @@ -0,0 +1,14 @@ +#ifndef _SWAY_IPC_JSON_H +#define _SWAY_IPC_JSON_H + +#include +#include "config.h" +#include "container.h" + +json_object *ipc_json_get_version(); +json_object *ipc_json_describe_bar_config(struct bar_config *bar); +json_object *ipc_json_describe_container(swayc_t *c); +json_object *ipc_json_describe_container_recursive(swayc_t *c); +json_object *ipc_json_describe_window(swayc_t *c); + +#endif diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h new file mode 100644 index 00000000..1d199134 --- /dev/null +++ b/include/sway/ipc-server.h @@ -0,0 +1,41 @@ +#ifndef _SWAY_IPC_SERVER_H +#define _SWAY_IPC_SERVER_H + +#include + +#include "container.h" +#include "config.h" +#include "ipc.h" + +void ipc_init(void); +void ipc_terminate(void); +struct sockaddr_un *ipc_user_sockaddr(void); + +void ipc_event_workspace(swayc_t *old, swayc_t *new, const char *change); +void ipc_event_barconfig_update(struct bar_config *bar); +/** + * Send IPC mode event to all listening clients + */ +void ipc_event_mode(const char *mode); +/** + * Send IPC window change event + */ +void ipc_event_window(swayc_t *window, const char *change); +/** + * Sends an IPC modifier event to all listening clients. The modifier event + * includes a key 'change' with the value of state and a key 'modifier' with + * the name of that modifier. + */ +void ipc_event_modifier(uint32_t modifier, const char *state); +/** + * Send IPC keyboard binding event. + */ +void ipc_event_binding_keyboard(struct sway_binding *sb); +const char *swayc_type_string(enum swayc_types type); + +/** + * Send pixel data to registered clients. + */ +void ipc_get_pixels(wlc_handle output); + +#endif diff --git a/include/sway/layout.h b/include/sway/layout.h new file mode 100644 index 00000000..b982365c --- /dev/null +++ b/include/sway/layout.h @@ -0,0 +1,78 @@ +#ifndef _SWAY_LAYOUT_H +#define _SWAY_LAYOUT_H + +#include +#include "log.h" +#include "list.h" +#include "container.h" +#include "focus.h" + +extern list_t *scratchpad; + +extern int min_sane_w; +extern int min_sane_h; + +// Set initial values for root_container +void init_layout(void); + +// Returns the index of child for its parent +int index_child(const swayc_t *child); + +// Adds child to parent, if parent has no focus, it is set to child +// parent must be of type C_WORKSPACE or C_CONTAINER +void add_child(swayc_t *parent, swayc_t *child); + +// Adds child to parent at index, if parent has no focus, it is set to child +// parent must be of type C_WORKSPACE or C_CONTAINER +void insert_child(swayc_t *parent, swayc_t *child, int index); + +// Adds child as floating window to ws, if there is no focus it is set to child. +// ws must be of type C_WORKSPACE +void add_floating(swayc_t *ws, swayc_t *child); + +// insert child after sibling in parents children. +swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); + +// Replace child with new_child in parents children +// new_child will inherit childs geometry, childs geometry will be reset +// if parents focus is on child, it will be changed to new_child +swayc_t *replace_child(swayc_t *child, swayc_t *new_child); + +// Remove child from its parent, if focus is on child, focus will be changed to +// a sibling, or to a floating window, or NULL +swayc_t *remove_child(swayc_t *child); + +// 2 containers are swapped, they inherit eachothers focus +void swap_container(swayc_t *a, swayc_t *b); + +// 2 Containers geometry are swapped, used with `swap_container` +void swap_geometry(swayc_t *a, swayc_t *b); + +void move_container(swayc_t* container, enum movement_direction direction); +void move_container_to(swayc_t* container, swayc_t* destination); +void move_workspace_to(swayc_t* workspace, swayc_t* destination); + +// Layout +/** + * Update child container geometries when switching between layouts. + */ +void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout); +void update_geometry(swayc_t *view); +void arrange_windows(swayc_t *container, double width, double height); +void arrange_backgrounds(void); + +swayc_t *get_focused_container(swayc_t *parent); +swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir); +swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_direction dir, swayc_t *limit); + +void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge); + +void layout_log(const swayc_t *c, int depth); +void swayc_log(log_importance_t verbosity, swayc_t *cont, const char* format, ...) __attribute__((format(printf,3,4))); + +/** + * Get default layout. + */ +enum swayc_layouts default_layout(swayc_t *output); + +#endif diff --git a/include/sway/output.h b/include/sway/output.h new file mode 100644 index 00000000..e8afd5ed --- /dev/null +++ b/include/sway/output.h @@ -0,0 +1,24 @@ +#ifndef _SWAY_OUTPUT_H +#define _SWAY_OUTPUT_H + +#include "container.h" +#include "focus.h" + +// Position is absolute coordinates on the edge where the adjacent output +// should be searched for. +swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos); +swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir, const struct wlc_point *abs_pos, bool pick_closest); + +// Place absolute coordinates for given container into given wlc_point. +void get_absolute_position(swayc_t *container, struct wlc_point *point); + +// Place absolute coordinates for the center point of given container into +// given wlc_point. +void get_absolute_center_position(swayc_t *container, struct wlc_point *point); + +// stable sort workspaces on this output +void sort_workspaces(swayc_t *output); + +void output_get_scaled_size(wlc_handle handle, struct wlc_size *size); + +#endif diff --git a/include/sway/resize.h b/include/sway/resize.h new file mode 100644 index 00000000..0d382994 --- /dev/null +++ b/include/sway/resize.h @@ -0,0 +1,14 @@ +#ifndef _SWAY_RESIZE_H +#define _SWAY_RESIZE_H +#include + +enum resize_dim_types { + RESIZE_DIM_PX, + RESIZE_DIM_PPT, + RESIZE_DIM_DEFAULT, +}; + +bool set_size(int dimension, bool use_width); +bool resize(int dimension, bool use_width, enum resize_dim_types dim_type); + +#endif diff --git a/include/sway/workspace.h b/include/sway/workspace.h new file mode 100644 index 00000000..c268fafa --- /dev/null +++ b/include/sway/workspace.h @@ -0,0 +1,22 @@ +#ifndef _SWAY_WORKSPACE_H +#define _SWAY_WORKSPACE_H + +#include +#include +#include "list.h" +#include "layout.h" + +extern char *prev_workspace_name; + +char *workspace_next_name(const char *output_name); +swayc_t *workspace_create(const char*); +swayc_t *workspace_by_name(const char*); +swayc_t *workspace_by_number(const char*); +bool workspace_switch(swayc_t*); +swayc_t *workspace_output_next(); +swayc_t *workspace_next(); +swayc_t *workspace_output_prev(); +swayc_t *workspace_prev(); +swayc_t *workspace_for_pid(pid_t pid); + +#endif diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h new file mode 100644 index 00000000..a3c511d9 --- /dev/null +++ b/include/swaybar/bar.h @@ -0,0 +1,63 @@ +#ifndef _SWAYBAR_BAR_H +#define _SWAYBAR_BAR_H + +#include "client/registry.h" +#include "client/window.h" +#include "list.h" + +struct bar { + struct config *config; + struct status_line *status; + list_t *outputs; + + int ipc_event_socketfd; + int ipc_socketfd; + int status_read_fd; + pid_t status_command_pid; +}; + +struct output { + struct window *window; + struct registry *registry; + list_t *workspaces; + char *name; + int idx; +}; + +struct workspace { + int num; + char *name; + bool focused; + bool visible; + bool urgent; +}; + +/** Global bar state */ +extern struct bar swaybar; + +/** + * 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 */ diff --git a/include/swaybar/config.h b/include/swaybar/config.h new file mode 100644 index 00000000..934116ca --- /dev/null +++ b/include/swaybar/config.h @@ -0,0 +1,71 @@ +#ifndef _SWAYBAR_CONFIG_H +#define _SWAYBAR_CONFIG_H + +#include +#include + +#include "list.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 { + char *status_command; + bool pango_markup; + uint32_t position; + char *font; + char *sep_symbol; + char *mode; + bool strip_workspace_numbers; + bool binding_mode_indicator; + bool wrap_scroll; + bool workspace_buttons; + bool all_outputs; + list_t *outputs; + + int height; + + struct { + uint32_t background; + uint32_t statusline; + uint32_t separator; + + struct box_colors focused_workspace; + struct box_colors active_workspace; + struct box_colors inactive_workspace; + struct box_colors urgent_workspace; + struct box_colors binding_mode; + } colors; +}; + +/** + * Parse position top|bottom|left|right. + */ +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 */ diff --git a/include/swaybar/ipc.h b/include/swaybar/ipc.h new file mode 100644 index 00000000..c11931d0 --- /dev/null +++ b/include/swaybar/ipc.h @@ -0,0 +1,23 @@ +#ifndef _SWAYBAR_IPC_H +#define _SWAYBAR_IPC_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 */ + diff --git a/include/swaybar/render.h b/include/swaybar/render.h new file mode 100644 index 00000000..114f43f4 --- /dev/null +++ b/include/swaybar/render.h @@ -0,0 +1,22 @@ +#ifndef _SWAYBAR_RENDER_H +#define _SWAYBAR_RENDER_H + +#include "config.h" +#include "bar.h" + +/** + * Render swaybar. + */ +void render(struct output *output, struct config *config, struct status_line *line); + +/** + * 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 */ diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h new file mode 100644 index 00000000..9b77e8a7 --- /dev/null +++ b/include/swaybar/status_line.h @@ -0,0 +1,51 @@ +#ifndef _SWAYBAR_STATUS_LINE_H +#define _SWAYBAR_STATUS_LINE_H + +#include +#include + +#include "list.h" +#include "bar.h" + +typedef enum {UNDEF, TEXT, I3BAR} command_protocol; + +struct status_line { + list_t *block_line; + const char *text_line; + command_protocol protocol; +}; + +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; +}; + +/** + * Initialize status line struct. + */ +struct status_line *init_status_line(); + +/** + * handle status line activity. + */ +bool handle_status_line(struct bar *bar); + +/** + * Free status line struct. + */ +void free_status_line(struct status_line *line); + +#endif /* _SWAYBAR_STATUS_LINE_H */ diff --git a/include/swaylock/swaylock.h b/include/swaylock/swaylock.h new file mode 100644 index 00000000..1cf66e89 --- /dev/null +++ b/include/swaylock/swaylock.h @@ -0,0 +1,37 @@ +#ifndef _SWAYLOCK_H +#define _SWAYLOCK_H + +#include "client/cairo.h" + +enum scaling_mode { + SCALING_MODE_STRETCH, + SCALING_MODE_FILL, + SCALING_MODE_FIT, + SCALING_MODE_CENTER, + SCALING_MODE_TILE, +}; + +enum auth_state { + AUTH_STATE_IDLE, + AUTH_STATE_INPUT, + AUTH_STATE_BACKSPACE, + AUTH_STATE_VALIDATING, + AUTH_STATE_INVALID, +}; + +struct render_data { + list_t *surfaces; + // Output specific images + cairo_surface_t **images; + // OR one image for all outputs: + cairo_surface_t *image; + int num_images; + int color_set; + uint32_t color; + enum scaling_mode scaling_mode; + enum auth_state auth_state; +}; + +void render(struct render_data* render_data); + +#endif diff --git a/include/workspace.h b/include/workspace.h deleted file mode 100644 index c268fafa..00000000 --- a/include/workspace.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _SWAY_WORKSPACE_H -#define _SWAY_WORKSPACE_H - -#include -#include -#include "list.h" -#include "layout.h" - -extern char *prev_workspace_name; - -char *workspace_next_name(const char *output_name); -swayc_t *workspace_create(const char*); -swayc_t *workspace_by_name(const char*); -swayc_t *workspace_by_number(const char*); -bool workspace_switch(swayc_t*); -swayc_t *workspace_output_next(); -swayc_t *workspace_next(); -swayc_t *workspace_output_prev(); -swayc_t *workspace_prev(); -swayc_t *workspace_for_pid(pid_t pid); - -#endif diff --git a/sway/border.c b/sway/border.c index 5cb02274..65f69411 100644 --- a/sway/border.c +++ b/sway/border.c @@ -1,12 +1,12 @@ -#include "border.h" #include #include #include #include #include #include -#include "container.h" -#include "config.h" +#include "sway/border.h" +#include "sway/container.h" +#include "sway/config.h" #include "client/pango.h" void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { diff --git a/sway/commands.c b/sway/commands.c index 5a5bcd22..347b463b 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -16,24 +16,24 @@ #include #include #include +#include "sway/layout.h" +#include "sway/focus.h" +#include "sway/workspace.h" +#include "sway/commands.h" +#include "sway/container.h" +#include "sway/output.h" +#include "sway/handlers.h" +#include "sway/resize.h" +#include "sway/input_state.h" +#include "sway/criteria.h" +#include "sway/ipc-server.h" +#include "sway/input.h" +#include "sway/border.h" #include "stringop.h" -#include "layout.h" -#include "focus.h" -#include "log.h" -#include "util.h" -#include "workspace.h" -#include "commands.h" -#include "container.h" -#include "output.h" -#include "handlers.h" #include "sway.h" -#include "resize.h" -#include "input_state.h" -#include "criteria.h" -#include "ipc-server.h" +#include "util.h" #include "list.h" -#include "input.h" -#include "border.h" +#include "log.h" typedef struct cmd_results *sway_cmd(int argc, char **argv); diff --git a/sway/config.c b/sway/config.c index bed233bd..a187fe3e 100644 --- a/sway/config.c +++ b/sway/config.c @@ -12,17 +12,17 @@ #include #include #include "wayland-desktop-shell-server-protocol.h" +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/layout.h" +#include "sway/input_state.h" +#include "sway/criteria.h" +#include "sway/input.h" +#include "sway/border.h" #include "readline.h" #include "stringop.h" #include "list.h" #include "log.h" -#include "commands.h" -#include "config.h" -#include "layout.h" -#include "input_state.h" -#include "criteria.h" -#include "input.h" -#include "border.h" struct sway_config *config = NULL; diff --git a/sway/container.c b/sway/container.c index c922bac3..5614293c 100644 --- a/sway/container.c +++ b/sway/container.c @@ -3,17 +3,17 @@ #include #include #include -#include "config.h" -#include "stringop.h" -#include "container.h" -#include "workspace.h" -#include "focus.h" -#include "border.h" -#include "layout.h" -#include "input_state.h" +#include "sway/config.h" +#include "sway/container.h" +#include "sway/workspace.h" +#include "sway/focus.h" +#include "sway/border.h" +#include "sway/layout.h" +#include "sway/input_state.h" +#include "sway/ipc-server.h" +#include "sway/output.h" #include "log.h" -#include "ipc-server.h" -#include "output.h" +#include "stringop.h" #define ASSERT_NONNULL(PTR) \ sway_assert (PTR, #PTR "must be non-null") diff --git a/sway/criteria.c b/sway/criteria.c index 53435d29..739a183e 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -2,12 +2,12 @@ #include #include #include -#include "criteria.h" +#include "sway/criteria.h" +#include "sway/container.h" +#include "sway/config.h" #include "stringop.h" #include "list.h" #include "log.h" -#include "container.h" -#include "config.h" enum criteria_type { // *must* keep in sync with criteria_strings[] CRIT_CLASS, diff --git a/sway/debug_log.c b/sway/debug_log.c index 7c988464..8d891a44 100644 --- a/sway/debug_log.c +++ b/sway/debug_log.c @@ -10,7 +10,7 @@ #include #include #include -#include "workspace.h" +#include "sway/workspace.h" /* XXX:DEBUG:XXX */ static void container_log(const swayc_t *c, int depth) { diff --git a/sway/extensions.c b/sway/extensions.c index 4611f33e..70ec537d 100644 --- a/sway/extensions.c +++ b/sway/extensions.c @@ -4,11 +4,11 @@ #include #include "wayland-desktop-shell-server-protocol.h" #include "wayland-swaylock-server-protocol.h" -#include "layout.h" +#include "sway/layout.h" +#include "sway/input_state.h" +#include "sway/extensions.h" +#include "sway/ipc-server.h" #include "log.h" -#include "input_state.h" -#include "extensions.h" -#include "ipc-server.h" struct desktop_shell_state desktop_shell; diff --git a/sway/focus.c b/sway/focus.c index 145e5584..9207260d 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -1,13 +1,12 @@ #include - -#include "focus.h" +#include "sway/focus.h" +#include "sway/workspace.h" +#include "sway/layout.h" +#include "sway/config.h" +#include "sway/input_state.h" +#include "sway/ipc-server.h" +#include "sway/border.h" #include "log.h" -#include "workspace.h" -#include "layout.h" -#include "config.h" -#include "input_state.h" -#include "ipc-server.h" -#include "border.h" bool locked_container_focus = false; bool suspend_workspace_cleanup = false; diff --git a/sway/handlers.c b/sway/handlers.c index 846d0005..47af7bd5 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -7,25 +7,24 @@ #include #include #include - -#include "handlers.h" -#include "border.h" -#include "log.h" -#include "layout.h" -#include "config.h" -#include "commands.h" -#include "stringop.h" -#include "workspace.h" -#include "container.h" -#include "output.h" -#include "focus.h" -#include "input_state.h" -#include "resize.h" -#include "extensions.h" -#include "criteria.h" -#include "ipc-server.h" +#include "sway/handlers.h" +#include "sway/border.h" +#include "sway/layout.h" +#include "sway/config.h" +#include "sway/commands.h" +#include "sway/workspace.h" +#include "sway/container.h" +#include "sway/output.h" +#include "sway/focus.h" +#include "sway/input_state.h" +#include "sway/resize.h" +#include "sway/extensions.h" +#include "sway/criteria.h" +#include "sway/ipc-server.h" +#include "sway/input.h" #include "list.h" -#include "input.h" +#include "stringop.h" +#include "log.h" // Event should be sent to client #define EVENT_PASSTHROUGH false diff --git a/sway/input.c b/sway/input.c index 1f3e99e7..ae24cb49 100644 --- a/sway/input.c +++ b/sway/input.c @@ -4,8 +4,8 @@ #include #include #include -#include "config.h" -#include "input.h" +#include "sway/config.h" +#include "sway/input.h" #include "list.h" #include "log.h" diff --git a/sway/input_state.c b/sway/input_state.c index 7e31d3d9..68df17de 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -1,10 +1,9 @@ #include #include #include +#include "sway/input_state.h" +#include "sway/config.h" #include "log.h" -#include "config.h" - -#include "input_state.h" #define KEY_STATE_MAX_LENGTH 64 diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 1debca7b..3f03b9f1 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -2,9 +2,9 @@ #include #include #include -#include "container.h" +#include "sway/container.h" +#include "sway/ipc-json.h" #include "util.h" -#include "ipc-json.h" static json_object *ipc_json_create_rect(swayc_t *c) { json_object *rect = json_object_new_object(); diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 7039e348..70007f57 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -13,15 +13,15 @@ #include #include #include -#include "ipc-json.h" -#include "ipc-server.h" +#include "sway/ipc-json.h" +#include "sway/ipc-server.h" +#include "sway/config.h" +#include "sway/commands.h" +#include "sway/input.h" +#include "stringop.h" #include "log.h" -#include "config.h" -#include "commands.h" #include "list.h" -#include "stringop.h" #include "util.h" -#include "input.h" static int ipc_socket = -1; static struct wlc_event_source *ipc_event_source = NULL; diff --git a/sway/layout.c b/sway/layout.c index 01c8e4e3..cf6a111e 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -2,17 +2,17 @@ #include #include #include -#include "extensions.h" -#include "log.h" +#include "sway/extensions.h" +#include "sway/config.h" +#include "sway/container.h" +#include "sway/workspace.h" +#include "sway/focus.h" +#include "sway/output.h" +#include "sway/ipc-server.h" +#include "sway/border.h" +#include "sway/layout.h" #include "list.h" -#include "config.h" -#include "container.h" -#include "workspace.h" -#include "focus.h" -#include "output.h" -#include "ipc-server.h" -#include "border.h" -#include "layout.h" +#include "log.h" swayc_t root_container; list_t *scratchpad; diff --git a/sway/main.c b/sway/main.c index 51b12d20..972b260b 100644 --- a/sway/main.c +++ b/sway/main.c @@ -8,17 +8,17 @@ #include #include #include -#include "extensions.h" -#include "layout.h" -#include "stringop.h" -#include "config.h" -#include "log.h" -#include "readline.h" -#include "handlers.h" +#include "sway/extensions.h" +#include "sway/layout.h" +#include "sway/config.h" +#include "sway/handlers.h" +#include "sway/input.h" +#include "sway/ipc-server.h" #include "ipc-client.h" -#include "ipc-server.h" -#include "input.h" +#include "readline.h" +#include "stringop.h" #include "sway.h" +#include "log.h" static bool terminate_request = false; static int exit_value = 0; diff --git a/sway/output.c b/sway/output.c index 97b8a4a6..b337b143 100644 --- a/sway/output.c +++ b/sway/output.c @@ -1,7 +1,7 @@ #include #include #include -#include "output.h" +#include "sway/output.h" #include "log.h" #include "list.h" diff --git a/sway/resize.c b/sway/resize.c index 18bb86bb..b32d2431 100644 --- a/sway/resize.c +++ b/sway/resize.c @@ -1,11 +1,11 @@ #include #include -#include "layout.h" -#include "focus.h" +#include "sway/layout.h" +#include "sway/focus.h" +#include "sway/input_state.h" +#include "sway/handlers.h" +#include "sway/resize.h" #include "log.h" -#include "input_state.h" -#include "handlers.h" -#include "resize.h" static bool set_size_floating(int new_dimension, bool use_width) { swayc_t *view = get_focused_float(swayc_active_workspace()); diff --git a/sway/workspace.c b/sway/workspace.c index 9c3e69a9..7b24d7d9 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -6,18 +6,18 @@ #include #include #include -#include "ipc-server.h" -#include "extensions.h" -#include "workspace.h" -#include "layout.h" -#include "list.h" -#include "log.h" -#include "container.h" -#include "handlers.h" -#include "config.h" +#include "sway/ipc-server.h" +#include "sway/extensions.h" +#include "sway/workspace.h" +#include "sway/layout.h" +#include "sway/container.h" +#include "sway/handlers.h" +#include "sway/config.h" +#include "sway/focus.h" #include "stringop.h" -#include "focus.h" #include "util.h" +#include "list.h" +#include "log.h" #include "ipc.h" char *prev_workspace_name = NULL; diff --git a/swaybar/bar.c b/swaybar/bar.c index e3e53622..c6596864 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -5,15 +5,14 @@ #include #include #include - +#include "swaybar/ipc.h" +#include "swaybar/render.h" +#include "swaybar/config.h" +#include "swaybar/status_line.h" +#include "swaybar/bar.h" #include "ipc-client.h" #include "list.h" #include "log.h" -#include "bar/ipc.h" -#include "bar/render.h" -#include "bar/config.h" -#include "bar/status_line.h" -#include "bar/bar.h" static void bar_init(struct bar *bar) { bar->config = init_config(); diff --git a/swaybar/config.c b/swaybar/config.c index b5dca668..c5437ee7 100644 --- a/swaybar/config.c +++ b/swaybar/config.c @@ -3,7 +3,7 @@ #include "wayland-desktop-shell-client-protocol.h" #include "log.h" -#include "bar/config.h" +#include "swaybar/config.h" uint32_t parse_position(const char *position) { if (strcmp("top", position) == 0) { diff --git a/swaybar/ipc.c b/swaybar/ipc.c index ad4f9ef8..8d62d223 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -1,11 +1,10 @@ #include #include - +#include "swaybar/config.h" +#include "swaybar/ipc.h" #include "ipc-client.h" #include "list.h" #include "log.h" -#include "bar/config.h" -#include "bar/ipc.h" void ipc_send_workspace_command(const char *workspace_name) { uint32_t size = strlen("workspace ") + strlen(workspace_name) + 1; diff --git a/swaybar/main.c b/swaybar/main.c index d7534f5d..c9a554a3 100644 --- a/swaybar/main.c +++ b/swaybar/main.c @@ -3,9 +3,9 @@ #include #include #include +#include "swaybar/bar.h" #include "ipc-client.h" #include "log.h" -#include "bar/bar.h" /* global bar state */ struct bar swaybar; diff --git a/swaybar/render.c b/swaybar/render.c index cea36f52..83b4cec7 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -5,9 +5,9 @@ #include "client/cairo.h" #include "client/pango.h" #include "client/window.h" -#include "bar/config.h" -#include "bar/status_line.h" -#include "bar/render.h" +#include "swaybar/config.h" +#include "swaybar/status_line.h" +#include "swaybar/render.h" /* internal spacing */ diff --git a/swaybar/status_line.c b/swaybar/status_line.c index 33a8908f..c7055d4c 100644 --- a/swaybar/status_line.c +++ b/swaybar/status_line.c @@ -3,9 +3,9 @@ #include #include +#include "swaybar/config.h" +#include "swaybar/status_line.h" #include "log.h" -#include "bar/config.h" -#include "bar/status_line.h" #include "util.h" #define I3JSON_MAXDEPTH 4 diff --git a/swaylock/main.c b/swaylock/main.c index 3049934e..0637453c 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -12,13 +12,12 @@ #include #include #include - #include "client/window.h" #include "client/registry.h" #include "client/cairo.h" +#include "swaylock/swaylock.h" #include "ipc-client.h" #include "log.h" -#include "lock/lock.h" struct registry *registry; struct render_data render_data; -- cgit v1.2.3-54-g00ecf From 38ca94e0ed2fe33ab71076680e9f70409a2e4115 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 1 Sep 2016 08:34:52 -0400 Subject: Tweak how swaylock surfaces are handled Fixes #875 --- sway/extensions.c | 14 ++++---------- sway/focus.c | 15 +++++++-------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/sway/extensions.c b/sway/extensions.c index 70ec537d..60cd8d41 100644 --- a/sway/extensions.c +++ b/sway/extensions.c @@ -119,27 +119,21 @@ static void set_lock_surface(struct wl_client *client, struct wl_resource *resou if (!swayc_is_child_of(view, workspace)) { move_container_to(view, workspace); } - // make the view floating so it doesn't rearrange other - // siblings. + // make the view floating so it doesn't rearrange other siblings. if (!view->is_floating) { - // Remove view from its current location destroy_container(remove_child(view)); - // and move it into workspace floating add_floating(workspace, view); } wlc_view_set_state(view->handle, WLC_BIT_FULLSCREEN, true); - workspace->fullscreen = view; - ipc_event_window(view, "fullscreen_mode"); + wlc_view_bring_to_front(view->handle); + wlc_view_focus(view->handle); desktop_shell.is_locked = true; - // reset input state input_init(); - // set focus if the lockscreen is spawned on the currently - // active output + arrange_windows(workspace, -1, -1); swayc_t *focus_output = swayc_active_output(); if (focus_output == output) { set_focused_container(view); } - arrange_windows(workspace, -1, -1); list_add(desktop_shell.lock_surfaces, surface); wl_resource_set_destructor(surface, lock_surface_destructor); } else { diff --git a/sway/focus.c b/sway/focus.c index 9207260d..02e61ac2 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -3,6 +3,7 @@ #include "sway/workspace.h" #include "sway/layout.h" #include "sway/config.h" +#include "sway/extensions.h" #include "sway/input_state.h" #include "sway/ipc-server.h" #include "sway/border.h" @@ -88,7 +89,6 @@ swayc_t *get_focused_container(swayc_t *parent) { if (!parent) { return swayc_active_workspace(); } - // get focused container while (!parent->is_focused && parent->focused) { parent = parent->focused; } @@ -132,24 +132,24 @@ bool set_focused_container(swayc_t *c) { p->is_focused = false; } - // get new focused view and set focus to it. if (!(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { - // unactivate previous focus if (focused->type == C_VIEW) { wlc_view_set_state(focused->handle, WLC_BIT_ACTIVATED, false); } update_container_border(focused); - // activate current focus if (c->type == C_VIEW) { wlc_view_set_state(c->handle, WLC_BIT_ACTIVATED, true); } - // set focus - wlc_view_focus(c->handle); + if (!desktop_shell.is_locked) { + // If the system is locked, we do everything _but_ actually setting + // focus. This includes making our internals think that this view is + // focused. + wlc_view_focus(c->handle); + } if (c->parent->layout != L_TABBED && c->parent->layout != L_STACKED) { update_container_border(c); } - // rearrange if parent container is tabbed/stacked swayc_t *parent = swayc_tabbed_stacked_ancestor(c); if (parent != NULL) { arrange_backgrounds(); @@ -174,7 +174,6 @@ bool set_focused_container_for(swayc_t *a, swayc_t *c) { return false; } swayc_t *find = c; - // Ensure that a is an ancestor of c while (find != a && (find = find->parent)) { if (find == &root_container) { return false; -- cgit v1.2.3-54-g00ecf From 6addaca9fafbc20a0fa52f630e1002d6d9240b8f Mon Sep 17 00:00:00 2001 From: Lukas Lihotzki Date: Fri, 2 Sep 2016 00:46:36 +0200 Subject: Correct `hide_edge_borders` command `vertical` and `horizontal` should be swapped. If border_left and border_right were set to 0, the vertical borders instead of the horizontal borders would be hidden. i3 handles this command equally. --- sway/layout.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/layout.c b/sway/layout.c index cf6a111e..7f053d9b 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -575,7 +575,7 @@ void update_geometry(swayc_t *container) { // handle hide_edge_borders if (config->hide_edge_borders != E_NONE && (gap <= 0 || (config->smart_gaps && workspace->children->length == 1))) { - if (config->hide_edge_borders == E_HORIZONTAL || config->hide_edge_borders == E_BOTH) { + if (config->hide_edge_borders == E_VERTICAL || config->hide_edge_borders == E_BOTH) { if (geometry.origin.x == workspace->x) { border_left = 0; } @@ -585,7 +585,7 @@ void update_geometry(swayc_t *container) { } } - if (config->hide_edge_borders == E_VERTICAL || config->hide_edge_borders == E_BOTH) { + if (config->hide_edge_borders == E_HORIZONTAL || config->hide_edge_borders == E_BOTH) { if (geometry.origin.y == workspace->y || should_hide_top_border(container, geometry.origin.y)) { border_top = 0; } -- cgit v1.2.3-54-g00ecf