diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-04-12 20:19:54 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-04-12 20:19:54 -0400 |
commit | cd1b32453a9296c18b28bff71607aeb22987b5cd (patch) | |
tree | c653c6d525b471914c01a9d7ae543f521b6138ed /include/sway | |
parent | 8e06985cc1b479724446fba752e0fecfb998e87b (diff) | |
parent | 5785170421dc38437acde8bb61068cd16fda716c (diff) |
Merge branch 'wlroots'
Diffstat (limited to 'include/sway')
28 files changed, 1003 insertions, 858 deletions
diff --git a/include/sway/border.h b/include/sway/border.h deleted file mode 100644 index c30c9da3..00000000 --- a/include/sway/border.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _SWAY_BORDER_H -#define _SWAY_BORDER_H -#include <wlc/wlc.h> -#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 index 660da2c2..dbebaa49 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -1,12 +1,7 @@ #ifndef _SWAY_COMMANDS_H #define _SWAY_COMMANDS_H -#include <stdbool.h> -#include <json-c/json.h> -#include <wlc/wlc.h> -#include "config.h" -// Container that a called command should act upon. Only valid in command functions. -extern swayc_t *current_container; +#include "config.h" /** * Indicates the result of a command's execution. @@ -22,6 +17,7 @@ enum cmd_status { CMD_BLOCK_BAR, CMD_BLOCK_BAR_COLORS, CMD_BLOCK_INPUT, + CMD_BLOCK_SEAT, CMD_BLOCK_COMMANDS, CMD_BLOCK_IPC, CMD_BLOCK_IPC_EVENTS, @@ -46,18 +42,13 @@ enum expected_args { EXPECTED_EQUAL_TO }; -struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val); -struct cmd_results *add_color(const char*, char*, const char*); -void input_cmd_apply(struct input_config *input); -void hide_view_in_scratchpad(swayc_t *sp_view); - -swayc_t *sp_view; -int sp_index; +struct cmd_results *checkarg(int argc, const char *name, + enum expected_args type, int val); /** - * Parse and handles a command. + * Parse and executes a command. */ -struct cmd_results *handle_command(char *command, enum command_context context); +struct cmd_results *execute_command(char *command, struct sway_seat *seat); /** * Parse and handles a command during config file loading. * @@ -68,7 +59,6 @@ struct cmd_results *config_command(char *command, enum cmd_status block); * Parses a command policy rule. */ struct cmd_results *config_commands_command(char *exec); - /** * Allocates a cmd_results object. */ @@ -84,11 +74,8 @@ void free_cmd_results(struct cmd_results *results); */ const char *cmd_results_to_json(struct cmd_results *results); -void remove_view_from_scratchpad(swayc_t *); - -/** - * Actual command function signatures for individual .c files in commands/ directory. - */ +struct cmd_results *add_color(const char *name, + char *buffer, const char *color); typedef struct cmd_results *sway_cmd(int argc, char **argv); @@ -108,6 +95,7 @@ sway_cmd cmd_commands; sway_cmd cmd_debuglog; sway_cmd cmd_default_border; sway_cmd cmd_default_floating_border; +sway_cmd cmd_default_orientation; sway_cmd cmd_exec; sway_cmd cmd_exec_always; sway_cmd cmd_exit; @@ -126,6 +114,7 @@ sway_cmd cmd_gaps; sway_cmd cmd_hide_edge_borders; sway_cmd cmd_include; sway_cmd cmd_input; +sway_cmd cmd_seat; sway_cmd cmd_ipc; sway_cmd cmd_kill; sway_cmd cmd_layout; @@ -134,10 +123,10 @@ sway_cmd cmd_mark; sway_cmd cmd_mode; sway_cmd cmd_mouse_warping; sway_cmd cmd_move; +sway_cmd cmd_opacity; sway_cmd cmd_new_float; sway_cmd cmd_new_window; sway_cmd cmd_no_focus; -sway_cmd cmd_orientation; sway_cmd cmd_output; sway_cmd cmd_permit; sway_cmd cmd_reject; @@ -153,6 +142,7 @@ sway_cmd cmd_splith; sway_cmd cmd_splitt; sway_cmd cmd_splitv; sway_cmd cmd_sticky; +sway_cmd cmd_swaybg_command; sway_cmd cmd_unmark; sway_cmd cmd_workspace; sway_cmd cmd_ws_auto_back_and_forth; @@ -195,17 +185,28 @@ sway_cmd bar_colors_cmd_statusline; sway_cmd bar_colors_cmd_focused_statusline; sway_cmd bar_colors_cmd_urgent_workspace; +sway_cmd input_cmd_seat; sway_cmd input_cmd_accel_profile; sway_cmd input_cmd_click_method; sway_cmd input_cmd_drag_lock; sway_cmd input_cmd_dwt; sway_cmd input_cmd_events; sway_cmd input_cmd_left_handed; +sway_cmd input_cmd_map_to_output; sway_cmd input_cmd_middle_emulation; sway_cmd input_cmd_natural_scroll; sway_cmd input_cmd_pointer_accel; sway_cmd input_cmd_scroll_method; sway_cmd input_cmd_tap; +sway_cmd input_cmd_xkb_layout; +sway_cmd input_cmd_xkb_model; +sway_cmd input_cmd_xkb_options; +sway_cmd input_cmd_xkb_rules; +sway_cmd input_cmd_xkb_variant; + +sway_cmd seat_cmd_attach; +sway_cmd seat_cmd_fallback; +sway_cmd seat_cmd_cursor; sway_cmd cmd_ipc_cmd; sway_cmd cmd_ipc_events; diff --git a/include/sway/config.h b/include/sway/config.h index a05d5ede..ed49fbbd 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -1,18 +1,18 @@ #ifndef _SWAY_CONFIG_H #define _SWAY_CONFIG_H - #define PID_WORKSPACE_TIMEOUT 60 - #include <libinput.h> #include <stdint.h> -#include <wlc/geometry.h> -#include <wlc/wlc.h> -#include <xkbcommon/xkbcommon.h> +#include <string.h> #include <time.h> -#include "wayland-desktop-shell-server-protocol.h" +#include <wlr/types/wlr_box.h> +#include <xkbcommon/xkbcommon.h> #include "list.h" -#include "layout.h" -#include "container.h" +#include "tree/layout.h" +#include "tree/container.h" +#include "wlr-layer-shell-unstable-v1-protocol.h" + +// TODO: Refactor this shit /** * Describes a variable created via the `set` command. @@ -47,11 +47,12 @@ struct sway_mouse_binding { */ struct sway_mode { char *name; - list_t *bindings; + list_t *keysym_bindings; + list_t *keycode_bindings; }; /** - * libinput options for input devices + * options for input devices */ struct input_config { char *identifier; @@ -68,8 +69,33 @@ struct input_config { int send_events; int tap; + char *xkb_layout; + char *xkb_model; + char *xkb_options; + char *xkb_rules; + char *xkb_variant; + + char *mapped_output; + bool capturable; - struct wlc_geometry region; + struct wlr_box region; +}; + +/** + * Options for misc device configurations that happen in the seat block + */ +struct seat_attachment_config { + char *identifier; + // TODO other things are configured here for some reason +}; + +/** + * Options for multiseat and other misc device configurations + */ +struct seat_config { + char *name; + int fallback; // -1 means not set + list_t *attachments; // list of seat_attachment configs }; /** @@ -81,8 +107,11 @@ struct output_config { char *name; int enabled; int width, height; + float refresh_rate; int x, y; - int scale; + float scale; + int32_t transform; + char *background; char *background_option; }; @@ -126,24 +155,13 @@ struct bar_config { char *id; uint32_t modifier; list_t *outputs; - enum desktop_shell_panel_position position; + char *position; list_t *bindings; char *status_command; bool pango_markup; char *swaybar_command; char *font; int height; // -1 not defined - -#ifdef ENABLE_TRAY - // Tray - char *tray_output; - char *icon_theme; - uint32_t tray_padding; - uint32_t activate_button; - uint32_t context_button; - uint32_t secondary_button; -#endif - bool workspace_buttons; bool wrap_scroll; char *separator_symbol; @@ -260,11 +278,13 @@ struct sway_config { list_t *pid_workspaces; list_t *output_configs; list_t *input_configs; + list_t *seat_configs; list_t *criteria; list_t *no_focus; list_t *active_bar_modifiers; struct sway_mode *current_mode; struct bar_config *current_bar; + char *swaybg_command; uint32_t floating_mod; uint32_t dragging_key; uint32_t resizing_key; @@ -272,8 +292,8 @@ struct sway_config { 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; + enum sway_container_layout default_orientation; + enum sway_container_layout default_layout; char *font; int font_height; @@ -286,7 +306,6 @@ struct sway_config { bool reloading; bool reading; bool auto_back_and_forth; - bool seamless_mouse; bool show_marks; bool edge_gaps; @@ -297,8 +316,8 @@ struct sway_config { list_t *config_chain; const char *current_config; - enum swayc_border_types border; - enum swayc_border_types floating_border; + enum sway_container_border border; + enum sway_container_border floating_border; int border_thickness; int floating_border_thickness; enum edge_border_types hide_edge_borders; @@ -323,6 +342,14 @@ struct sway_config { list_t *command_policies; list_t *feature_policies; list_t *ipc_policies; + + // Context for command handlers + struct { + struct input_config *input_config; + struct seat_config *seat_config; + struct sway_seat *seat; + struct sway_container *current_container; + } handler_context; }; void pid_workspace_add(struct pid_workspace *pw); @@ -348,6 +375,11 @@ bool read_config(FILE *file, struct sway_config *config); * Free config struct */ void free_config(struct sway_config *config); + +void config_clear_handler_context(struct sway_config *config); + +void free_sway_variable(struct sway_variable *var); + /** * Does variable replacement for a string based on the config's currently loaded variables. */ @@ -356,51 +388,74 @@ char *do_var_replacement(char *str); struct cmd_results *check_security_config(); int input_identifier_cmp(const void *item, const void *data); + +struct input_config *new_input_config(const char* identifier); + void merge_input_config(struct input_config *dst, struct input_config *src); -void apply_input_config(struct input_config *ic, struct libinput_device *dev); + +struct input_config *copy_input_config(struct input_config *ic); + void free_input_config(struct input_config *ic); +void apply_input_config(struct input_config *input); + +int seat_name_cmp(const void *item, const void *data); + +struct seat_config *new_seat_config(const char* name); + +void merge_seat_config(struct seat_config *dst, struct seat_config *src); + +struct seat_config *copy_seat_config(struct seat_config *seat); + +void free_seat_config(struct seat_config *ic); + +struct seat_attachment_config *seat_attachment_config_new(); + +struct seat_attachment_config *seat_config_get_attachment( + struct seat_config *seat_config, char *identifier); + +void apply_seat_config(struct seat_config *seat); + int output_name_cmp(const void *item, const void *data); + +void output_get_identifier(char *identifier, size_t len, + struct sway_output *output); + +struct output_config *new_output_config(const char *name); + 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); +void apply_output_config(struct output_config *oc, + struct sway_container *output); + +void free_output_config(struct output_config *oc); 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); +struct sway_binding *sway_binding_dup(struct sway_binding *sb); void load_swaybars(); + +void invoke_swaybar(struct bar_config *bar); + void terminate_swaybg(pid_t pid); -/** - * Allocate and initialize default bar configuration. - */ struct bar_config *default_bar_config(void); -/** - * Global config singleton. - */ +void free_bar_config(struct bar_config *bar); + +/* Global config singleton. */ extern struct sway_config *config; -/** - * Config file currently being read. - */ +/* Config file currently being read */ extern const char *current_config_path; #endif diff --git a/include/sway/container.h b/include/sway/container.h deleted file mode 100644 index 37192ce3..00000000 --- a/include/sway/container.h +++ /dev/null @@ -1,357 +0,0 @@ -#ifndef _SWAY_CONTAINER_H -#define _SWAY_CONTAINER_H -#include <sys/types.h> -#include <wlc/wlc.h> -#include <stdint.h> - -#include "list.h" - -typedef struct sway_container swayc_t; - -extern swayc_t root_container; -extern swayc_t *current_focus; - -/** - * 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 */ - - /* Awesome/Monad style auto layouts */ - L_AUTO_LEFT, - L_AUTO_RIGHT, - L_AUTO_TOP, - L_AUTO_BOTTOM, - - L_AUTO_FIRST = L_AUTO_LEFT, - L_AUTO_LAST = L_AUTO_BOTTOM, - - // 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; - - /** - * A unique ID to identify this container. Primarily used in the - * get_tree JSON output. - */ - size_t id; - - enum swayc_types type; - enum swayc_layouts layout; - enum swayc_layouts prev_layout; - enum swayc_layouts workspace_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 *instance; - 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; - - /** - * Number of master views in auto layouts. - */ - size_t nb_master; - - /** - * Number of slave groups (e.g. columns) in auto layouts. - */ - size_t nb_slave_groups; - - /** - * Marks applied to the container, list_t of char*. - */ - list_t *marks; -}; - -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); -/** - * Finds the first container following a callback. - */ -swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *), const void *data); - -/** - * 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); - -/** - * Assign layout to a container. Needed due to workspace container specifics. - * Workspace should always have either L_VERT or L_HORIZ layout. - */ -swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout); - -#endif diff --git a/include/sway/criteria.h b/include/sway/criteria.h index c5ed9857..ec256ddb 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h @@ -1,7 +1,7 @@ #ifndef _SWAY_CRITERIA_H #define _SWAY_CRITERIA_H -#include "container.h" +#include "tree/container.h" #include "list.h" /** @@ -31,12 +31,12 @@ 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); +list_t *criteria_for(struct sway_container *cont); // Returns a list of all containers that match the given list of tokens. -list_t *container_for(list_t *tokens); +list_t *container_for_crit_tokens(list_t *tokens); // Returns true if any criteria in the given list matches this container -bool criteria_any(swayc_t *cont, list_t *criteria); +bool criteria_any(struct sway_container *cont, list_t *criteria); #endif diff --git a/include/sway/debug.h b/include/sway/debug.h new file mode 100644 index 00000000..2430d319 --- /dev/null +++ b/include/sway/debug.h @@ -0,0 +1,7 @@ +#ifndef SWAY_DEBUG_H +#define SWAY_DEBUG_H + +extern bool enable_debug_tree; +void update_debug_tree(); + +#endif diff --git a/include/sway/desktop.h b/include/sway/desktop.h new file mode 100644 index 00000000..f1ad759a --- /dev/null +++ b/include/sway/desktop.h @@ -0,0 +1,4 @@ +#include <wlr/types/wlr_surface.h> + +void desktop_damage_surface(struct wlr_surface *surface, double lx, double ly, + bool whole); diff --git a/include/sway/extensions.h b/include/sway/extensions.h deleted file mode 100644 index 5212eb3a..00000000 --- a/include/sway/extensions.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _SWAY_EXTENSIONS_H -#define _SWAY_EXTENSIONS_H - -#include <wayland-server.h> -#include <wlc/wlc-wayland.h> -#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; -}; - -struct decoration_state { - list_t *csd_resources; -}; - -extern struct desktop_shell_state desktop_shell; -extern struct decoration_state decoration_state; - -void register_extensions(void); - -void server_decoration_enable_csd(wlc_handle handle); - -#endif diff --git a/include/sway/focus.h b/include/sway/focus.h deleted file mode 100644 index 652cdccc..00000000 --- a/include/sway/focus.h +++ /dev/null @@ -1,45 +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, - MOVE_NEXT, - MOVE_PREV, - MOVE_FIRST -}; - -#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 deleted file mode 100644 index 956b98f4..00000000 --- a/include/sway/handlers.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _SWAY_HANDLERS_H -#define _SWAY_HANDLERS_H -#include "container.h" -#include <stdbool.h> -#include <wlc/wlc.h> - -void register_wlc_handlers(); - -extern uint32_t keys_pressed[32]; - -#endif diff --git a/include/sway/input.h b/include/sway/input.h deleted file mode 100644 index 4ed9bffe..00000000 --- a/include/sway/input.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _SWAY_INPUT_H -#define _SWAY_INPUT_H - -#include <libinput.h> -#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/cursor.h b/include/sway/input/cursor.h new file mode 100644 index 00000000..fcd94437 --- /dev/null +++ b/include/sway/input/cursor.h @@ -0,0 +1,36 @@ +#ifndef _SWAY_INPUT_CURSOR_H +#define _SWAY_INPUT_CURSOR_H +#include <stdint.h> +#include "sway/input/seat.h" + +struct sway_cursor { + struct sway_seat *seat; + struct wlr_cursor *cursor; + struct wlr_xcursor_manager *xcursor_manager; + + struct wl_client *image_client; + + struct wl_listener motion; + struct wl_listener motion_absolute; + struct wl_listener button; + struct wl_listener axis; + + struct wl_listener touch_down; + struct wl_listener touch_up; + struct wl_listener touch_motion; + + struct wl_listener tool_axis; + struct wl_listener tool_tip; + struct wl_listener tool_button; + uint32_t tool_buttons; + + struct wl_listener request_set_cursor; +}; + +void sway_cursor_destroy(struct sway_cursor *cursor); +struct sway_cursor *sway_cursor_create(struct sway_seat *seat); +void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time); +void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, + uint32_t button, enum wlr_button_state state); + +#endif diff --git a/include/sway/input/input-manager.h b/include/sway/input/input-manager.h new file mode 100644 index 00000000..89a3ac71 --- /dev/null +++ b/include/sway/input/input-manager.h @@ -0,0 +1,64 @@ +#ifndef _SWAY_INPUT_INPUT_MANAGER_H +#define _SWAY_INPUT_INPUT_MANAGER_H +#include <libinput.h> +#include <wlr/types/wlr_input_inhibitor.h> +#include "sway/server.h" +#include "sway/config.h" +#include "list.h" + +/** + * The global singleton input manager + * TODO: make me not a global + */ +extern struct sway_input_manager *input_manager; + +struct sway_input_device { + char *identifier; + struct wlr_input_device *wlr_device; + struct wl_list link; + struct wl_listener device_destroy; +}; + +struct sway_input_manager { + struct sway_server *server; + struct wl_list devices; + struct wl_list seats; + + struct wlr_input_inhibit_manager *inhibit; + + struct wl_listener new_input; + struct wl_listener inhibit_activate; + struct wl_listener inhibit_deactivate; +}; + +struct sway_input_manager *input_manager_create(struct sway_server *server); + +bool input_manager_has_focus(struct sway_input_manager *input, + struct sway_container *container); + +void input_manager_set_focus(struct sway_input_manager *input, + struct sway_container *container); + +void input_manager_configure_xcursor(struct sway_input_manager *input); + +void input_manager_apply_input_config(struct sway_input_manager *input, + struct input_config *input_config); + +void input_manager_apply_seat_config(struct sway_input_manager *input, + struct seat_config *seat_config); + +struct sway_seat *input_manager_get_default_seat( + struct sway_input_manager *input); + +struct sway_seat *input_manager_get_seat(struct sway_input_manager *input, + const char *seat_name); + +/** + * Gets the last seat the user interacted with + */ +struct sway_seat *input_manager_current_seat(struct sway_input_manager *input); + +struct input_config *input_device_get_config(struct sway_input_device *device); + + +#endif diff --git a/include/sway/input/keyboard.h b/include/sway/input/keyboard.h new file mode 100644 index 00000000..8ec3eb35 --- /dev/null +++ b/include/sway/input/keyboard.h @@ -0,0 +1,30 @@ +#ifndef _SWAY_INPUT_KEYBOARD_H +#define _SWAY_INPUT_KEYBOARD_H + +#include "sway/input/seat.h" + +#define SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP 32 + +struct sway_keyboard { + struct sway_seat_device *seat_device; + + struct xkb_keymap *keymap; + + struct wl_listener keyboard_key; + struct wl_listener keyboard_modifiers; + + xkb_keysym_t pressed_keysyms_translated[SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP]; + uint32_t modifiers_translated; + + xkb_keysym_t pressed_keysyms_raw[SWAY_KEYBOARD_PRESSED_KEYSYMS_CAP]; + uint32_t modifiers_raw; +}; + +struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, + struct sway_seat_device *device); + +void sway_keyboard_configure(struct sway_keyboard *keyboard); + +void sway_keyboard_destroy(struct sway_keyboard *keyboard); + +#endif diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h new file mode 100644 index 00000000..ff76841e --- /dev/null +++ b/include/sway/input/seat.h @@ -0,0 +1,111 @@ +#ifndef _SWAY_INPUT_SEAT_H +#define _SWAY_INPUT_SEAT_H + +#include <wlr/types/wlr_layer_shell.h> +#include <wlr/types/wlr_seat.h> +#include "sway/input/input-manager.h" + +struct sway_seat_device { + struct sway_seat *sway_seat; + struct sway_input_device *input_device; + struct sway_keyboard *keyboard; + struct wl_list link; // sway_seat::devices +}; + +struct sway_seat_container { + struct sway_seat *seat; + struct sway_container *container; + + struct wl_list link; // sway_seat::focus_stack + + struct wl_listener destroy; +}; + +struct sway_seat { + struct wlr_seat *wlr_seat; + struct sway_cursor *cursor; + struct sway_input_manager *input; + + bool has_focus; + struct wl_list focus_stack; // list of containers in focus order + + // If the focused layer is set, views cannot receive keyboard focus + struct wlr_layer_surface *focused_layer; + + // If exclusive_client is set, no other clients will receive input events + struct wl_client *exclusive_client; + + struct wl_listener focus_destroy; + struct wl_listener new_container; + + struct wl_list devices; // sway_seat_device::link + + struct wl_list link; // input_manager::seats +}; + +struct sway_seat *seat_create(struct sway_input_manager *input, + const char *seat_name); + +void seat_destroy(struct sway_seat *seat); + +void seat_add_device(struct sway_seat *seat, + struct sway_input_device *device); + +void seat_configure_device(struct sway_seat *seat, + struct sway_input_device *device); + +void seat_remove_device(struct sway_seat *seat, + struct sway_input_device *device); + +void seat_configure_xcursor(struct sway_seat *seat); + +void seat_set_focus(struct sway_seat *seat, struct sway_container *container); + +void seat_set_focus_warp(struct sway_seat *seat, + struct sway_container *container, bool warp); + +void seat_set_focus_surface(struct sway_seat *seat, + struct wlr_surface *surface); + +void seat_set_focus_layer(struct sway_seat *seat, + struct wlr_layer_surface *layer); + +void seat_set_exclusive_client(struct sway_seat *seat, + struct wl_client *client); + +struct sway_container *seat_get_focus(struct sway_seat *seat); + +/** + * Return the last container to be focused for the seat (or the most recently + * opened if no container has received focused) that is a child of the given + * container. The focus-inactive container of the root window is the focused + * container for the seat (if the seat does have focus). This function can be + * used to determine what container gets focused next if the focused container + * is destroyed, or focus moves to a container with children and we need to + * descend into the next leaf in focus order. + */ +struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, + struct sway_container *container); + +/** + * Descend into the focus stack to find the focus-inactive view. Useful for + * container placement when they change position in the tree. + */ +struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat, + struct sway_container *container); + +/** + * Iterate over the focus-inactive children of the container calling the + * function on each. + */ +void seat_focus_inactive_children_for_each(struct sway_seat *seat, + struct sway_container *container, + void (*f)(struct sway_container *container, void *data), void *data); + +void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config); + +struct seat_config *seat_get_config(struct sway_seat *seat); + +bool seat_is_input_allowed(struct sway_seat *seat, struct wlr_surface *surface); + +#endif diff --git a/include/sway/input_state.h b/include/sway/input_state.h deleted file mode 100644 index fd5a3a25..00000000 --- a/include/sway/input_state.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef _SWAY_KEY_STATE_H -#define _SWAY_KEY_STATE_H -#include <stdbool.h> -#include <stdint.h> -#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(double new_x, double new_y, 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 index 3a5af0f5..7d87d377 100644 --- a/include/sway/ipc-json.h +++ b/include/sway/ipc-json.h @@ -1,15 +1,14 @@ #ifndef _SWAY_IPC_JSON_H #define _SWAY_IPC_JSON_H - #include <json-c/json.h> -#include "config.h" -#include "container.h" +#include "sway/tree/container.h" +#include "sway/input/input-manager.h" json_object *ipc_json_get_version(); + +json_object *ipc_json_describe_container(struct sway_container *c); +json_object *ipc_json_describe_container_recursive(struct sway_container *c); +json_object *ipc_json_describe_input(struct sway_input_device *device); json_object *ipc_json_describe_bar_config(struct bar_config *bar); -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); -json_object *ipc_json_describe_input(struct libinput_device *device); #endif diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index 1d199134..c3389fe8 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h @@ -1,41 +1,21 @@ #ifndef _SWAY_IPC_SERVER_H #define _SWAY_IPC_SERVER_H +#include <sys/socket.h> +#include "sway/tree/container.h" +#include "ipc.h" -#include <wlc/wlc.h> +struct sway_server; -#include "container.h" -#include "config.h" -#include "ipc.h" +void ipc_init(struct sway_server *server); -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_workspace(struct sway_container *old, + struct sway_container *new, const char *change); +void ipc_event_window(struct sway_container *window, const char *change); void ipc_event_barconfig_update(struct bar_config *bar); -/** - * 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/layers.h b/include/sway/layers.h new file mode 100644 index 00000000..ee47c5ad --- /dev/null +++ b/include/sway/layers.h @@ -0,0 +1,25 @@ +#ifndef _SWAY_LAYERS_H +#define _SWAY_LAYERS_H +#include <stdbool.h> +#include <wlr/types/wlr_box.h> +#include <wlr/types/wlr_surface.h> +#include <wlr/types/wlr_layer_shell.h> + +struct sway_layer_surface { + struct wlr_layer_surface *layer_surface; + struct wl_list link; + + struct wl_listener destroy; + struct wl_listener map; + struct wl_listener unmap; + struct wl_listener surface_commit; + struct wl_listener output_destroy; + + bool configured; + struct wlr_box geo; +}; + +struct sway_output; +void arrange_layers(struct sway_output *output); + +#endif diff --git a/include/sway/layout.h b/include/sway/layout.h deleted file mode 100644 index f0791588..00000000 --- a/include/sway/layout.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _SWAY_LAYOUT_H -#define _SWAY_LAYOUT_H - -#include <wlc/wlc.h> -#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, int move_amt); -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); - -bool is_auto_layout(enum swayc_layouts layout); -int auto_group_start_index(const swayc_t *container, int index); -int auto_group_end_index(const swayc_t *container, int index); -size_t auto_group_count(const swayc_t *container); -size_t auto_group_index(const swayc_t *container, int index); -bool auto_group_bounds(const swayc_t *container, size_t group_index, int *start, int *end); - -#endif diff --git a/include/sway/output.h b/include/sway/output.h index e1bdd3f0..56571548 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -1,25 +1,48 @@ #ifndef _SWAY_OUTPUT_H #define _SWAY_OUTPUT_H +#include <time.h> +#include <unistd.h> +#include <wayland-server.h> +#include <wlr/types/wlr_box.h> +#include <wlr/types/wlr_output.h> +#include "sway/tree/view.h" -#include "container.h" -#include "focus.h" +struct sway_server; +struct sway_container; -// 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_opposite_output(enum movement_direction dir, 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); +struct sway_output { + struct wlr_output *wlr_output; + struct sway_container *swayc; + struct sway_server *server; -// Place absolute coordinates for given container into given wlc_point. -void get_absolute_position(swayc_t *container, struct wlc_point *point); + struct wl_list layers[4]; // sway_layer_surface::link + struct wlr_box usable_area; -// 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); + struct timespec last_frame; + struct wlr_output_damage *damage; -// stable sort workspaces on this output -void sort_workspaces(swayc_t *output); + struct wl_listener destroy; + struct wl_listener mode; + struct wl_listener transform; + struct wl_listener scale; -void output_get_scaled_size(wlc_handle handle, struct wlc_size *size); + struct wl_listener damage_destroy; + struct wl_listener damage_frame; + + pid_t bg_pid; +}; + +void output_damage_whole(struct sway_output *output); + +void output_damage_surface(struct sway_output *output, double ox, double oy, + struct wlr_surface *surface, bool whole); + +void output_damage_view(struct sway_output *output, struct sway_view *view, + bool whole); + +void output_damage_whole_container(struct sway_output *output, + struct sway_container *con); + +struct sway_container *output_by_name(const char *name); #endif diff --git a/include/sway/server.h b/include/sway/server.h new file mode 100644 index 00000000..296fbf22 --- /dev/null +++ b/include/sway/server.h @@ -0,0 +1,57 @@ +#ifndef _SWAY_SERVER_H +#define _SWAY_SERVER_H +#include <stdbool.h> +#include <wayland-server.h> +#include <wlr/backend.h> +#include <wlr/backend/session.h> +#include <wlr/types/wlr_compositor.h> +#include <wlr/types/wlr_data_device.h> +#include <wlr/types/wlr_layer_shell.h> +#include <wlr/types/wlr_xdg_shell_v6.h> +#include <wlr/render/wlr_renderer.h> +// TODO WLR: make Xwayland optional +#include <wlr/xwayland.h> + +struct sway_server { + struct wl_display *wl_display; + struct wl_event_loop *wl_event_loop; + const char *socket; + + struct wlr_backend *backend; + + struct wlr_compositor *compositor; + struct wlr_data_device_manager *data_device_manager; + + struct sway_input_manager *input; + + struct wl_listener new_output; + + struct wlr_layer_shell *layer_shell; + struct wl_listener layer_shell_surface; + + struct wlr_xdg_shell_v6 *xdg_shell_v6; + struct wl_listener xdg_shell_v6_surface; + + struct wlr_xwayland *xwayland; + struct wlr_xcursor_manager *xcursor_manager; + struct wl_listener xwayland_surface; + struct wl_listener xwayland_ready; + + struct wlr_wl_shell *wl_shell; + struct wl_listener wl_shell_surface; +}; + +struct sway_server server; + +bool server_init(struct sway_server *server); +void server_fini(struct sway_server *server); +void server_run(struct sway_server *server); + +void handle_new_output(struct wl_listener *listener, void *data); + +void handle_layer_shell_surface(struct wl_listener *listener, void *data); +void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); +void handle_xwayland_surface(struct wl_listener *listener, void *data); +void handle_wl_shell_surface(struct wl_listener *listener, void *data); + +#endif diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h new file mode 100644 index 00000000..2a8b8aba --- /dev/null +++ b/include/sway/tree/container.h @@ -0,0 +1,192 @@ +#ifndef _SWAY_CONTAINER_H +#define _SWAY_CONTAINER_H +#include <stdint.h> +#include <sys/types.h> +#include <wlr/types/wlr_box.h> +#include <wlr/types/wlr_surface.h> +#include "list.h" + +extern struct sway_container root_container; + +struct sway_view; +struct sway_seat; + +/** + * Different kinds of containers. + * + * This enum is in order. A container will never be inside of a container below + * it on this list. + */ +enum sway_container_type { + C_ROOT, + C_OUTPUT, + C_WORKSPACE, + C_CONTAINER, + C_VIEW, + + // Keep last + C_TYPES, +}; + +enum sway_container_layout { + L_NONE, + L_HORIZ, + L_VERT, + L_STACKED, + L_TABBED, + L_FLOATING, +}; + +enum sway_container_border { + B_NONE, + B_PIXEL, + B_NORMAL, +}; + +struct sway_root; +struct sway_output; +struct sway_view; + +struct sway_container { + union { + // TODO: Encapsulate state for other node types as well like C_CONTAINER + struct sway_root *sway_root; + struct sway_output *sway_output; + struct sway_view *sway_view; + }; + + /** + * A unique ID to identify this container. Primarily used in the + * get_tree JSON output. + */ + size_t id; + + char *name; + + enum sway_container_type type; + enum sway_container_layout layout; + enum sway_container_layout prev_layout; + enum sway_container_layout workspace_layout; + + // For C_ROOT, this has no meaning + // For C_OUTPUT, this is the output position in layout coordinates + // For other types, this is the position in output-local coordinates + double x, y; + // does not include borders or gaps. + double width, height; + + list_t *children; + + struct sway_container *parent; + + list_t *marks; // list of char* + + float alpha; + + struct { + struct wl_signal destroy; + // Raised after the tree updates, but before arrange_windows + // Passed the previous parent + struct wl_signal reparent; + } events; +}; + +struct sway_container *container_create(enum sway_container_type type); + +const char *container_type_to_str(enum sway_container_type type); + +struct sway_container *output_create(struct sway_output *sway_output); + +/** + * Create a new container container. A container container can be a a child of + * a workspace container or another container container. + */ +struct sway_container *container_container_create(); + +/** + * Create a new output. Outputs are children of the root container and have no + * order in the tree structure. + */ +struct sway_container *output_create(struct sway_output *sway_output); + +/** + * Create a new workspace container. Workspaces are children of an output + * container and are ordered alphabetically by name. + */ +struct sway_container *workspace_create(struct sway_container *output, + const char *name); + +/* + * Create a new view container. A view can be a child of a workspace container + * or a container container and are rendered in the order and structure of + * how they are attached to the tree. + */ +struct sway_container *container_view_create( + struct sway_container *sibling, struct sway_view *sway_view); + +struct sway_container *container_destroy(struct sway_container *container); + +struct sway_container *container_close(struct sway_container *container); + +void container_descendants(struct sway_container *root, + enum sway_container_type type, + void (*func)(struct sway_container *item, void *data), void *data); + +/** + * Search a container's descendants a container based on test criteria. Returns + * the first container that passes the test. + */ +struct sway_container *container_find(struct sway_container *container, + bool (*test)(struct sway_container *view, void *data), void *data); + +/** + * Finds a parent container with the given struct sway_containerype. + */ +struct sway_container *container_parent(struct sway_container *container, + enum sway_container_type type); + +/** + * Find a container at the given coordinates. Returns the the surface and + * surface-local coordinates of the given layout coordinates if the container + * is a view and the view contains a surface at those coordinates. + */ +struct sway_container *container_at(struct sway_container *container, + double lx, double ly, struct wlr_surface **surface, + double *sx, double *sy); + +/** + * Apply the function for each descendant of the container breadth first. + */ +void container_for_each_descendant_bfs(struct sway_container *container, + void (*f)(struct sway_container *container, void *data), void *data); + +/** + * Apply the function for each child of the container depth first. + */ +void container_for_each_descendant_dfs(struct sway_container *container, + void (*f)(struct sway_container *container, void *data), void *data); + +/** + * Returns true if the given container is an ancestor of this container. + */ +bool container_has_anscestor(struct sway_container *container, + struct sway_container *anscestor); + +/** + * Returns true if the given container is a child descendant of this container. + */ +bool container_has_child(struct sway_container *con, + struct sway_container *child); + +void container_create_notify(struct sway_container *container); + +void container_damage_whole(struct sway_container *container); + +bool container_reap_empty(struct sway_container *con); + +struct sway_container *container_reap_empty_recursive( + struct sway_container *con); + +struct sway_container *container_flatten(struct sway_container *container); + +#endif diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h new file mode 100644 index 00000000..49ae00e4 --- /dev/null +++ b/include/sway/tree/layout.h @@ -0,0 +1,78 @@ +#ifndef _SWAY_LAYOUT_H +#define _SWAY_LAYOUT_H +#include <wlr/types/wlr_output_layout.h> +#include <wlr/render/wlr_texture.h> +#include "sway/tree/container.h" + +enum movement_direction { + MOVE_LEFT, + MOVE_RIGHT, + MOVE_UP, + MOVE_DOWN, + MOVE_PARENT, + MOVE_CHILD, +}; + +enum resize_edge { + RESIZE_EDGE_LEFT, + RESIZE_EDGE_RIGHT, + RESIZE_EDGE_TOP, + RESIZE_EDGE_BOTTOM, +}; + +struct sway_container; + +struct sway_root { + struct wlr_output_layout *output_layout; + + struct wl_listener output_layout_change; + + struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link + + struct wlr_texture *debug_tree; + + struct { + struct wl_signal new_container; + } events; +}; + +void layout_init(void); + +void container_add_child(struct sway_container *parent, + struct sway_container *child); + +struct sway_container *container_add_sibling(struct sway_container *parent, + struct sway_container *child); + +struct sway_container *container_remove_child(struct sway_container *child); + +struct sway_container *container_replace_child(struct sway_container *child, + struct sway_container *new_child); + +struct sway_container *container_set_layout(struct sway_container *container, + enum sway_container_layout layout); + +void container_move_to(struct sway_container* container, + struct sway_container* destination); + +void container_move(struct sway_container *container, + enum movement_direction dir, int move_amt); + +enum sway_container_layout container_get_default_layout( + struct sway_container *con); + +void container_sort_workspaces(struct sway_container *output); + +void arrange_windows(struct sway_container *container, + double width, double height); + +struct sway_container *container_get_in_direction(struct sway_container + *container, struct sway_seat *seat, enum movement_direction dir); + +struct sway_container *container_split(struct sway_container *child, + enum sway_container_layout layout); + +void container_recursive_resize(struct sway_container *container, + double amount, enum resize_edge edge); + +#endif diff --git a/include/sway/tree/output.h b/include/sway/tree/output.h new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/include/sway/tree/output.h diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h new file mode 100644 index 00000000..b51c54b5 --- /dev/null +++ b/include/sway/tree/view.h @@ -0,0 +1,186 @@ +#ifndef _SWAY_VIEW_H +#define _SWAY_VIEW_H +#include <wayland-server.h> +#include <wlr/types/wlr_surface.h> +#include <wlr/types/wlr_xdg_shell_v6.h> +#include <wlr/xwayland.h> +#include "sway/input/input-manager.h" +#include "sway/input/seat.h" + +struct sway_container; + +enum sway_view_type { + SWAY_VIEW_WL_SHELL, + SWAY_VIEW_XDG_SHELL_V6, + SWAY_VIEW_XWAYLAND, +}; + +enum sway_view_prop { + VIEW_PROP_TITLE, + VIEW_PROP_APP_ID, + VIEW_PROP_CLASS, + VIEW_PROP_INSTANCE, +}; + +struct sway_view_impl { + const char *(*get_prop)(struct sway_view *view, + enum sway_view_prop prop); + void (*configure)(struct sway_view *view, double ox, double oy, int width, + int height); + void (*set_activated)(struct sway_view *view, bool activated); + void (*for_each_surface)(struct sway_view *view, + wlr_surface_iterator_func_t iterator, void *user_data); + void (*close)(struct sway_view *view); + void (*destroy)(struct sway_view *view); +}; + +struct sway_view { + enum sway_view_type type; + const struct sway_view_impl *impl; + + struct sway_container *swayc; // NULL for unmanaged views + struct wlr_surface *surface; // NULL for unmapped views + int width, height; + + union { + struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; + struct wlr_xwayland_surface *wlr_xwayland_surface; + struct wlr_wl_shell_surface *wlr_wl_shell_surface; + }; + + struct { + struct wl_signal unmap; + } events; + + struct wl_listener surface_new_subsurface; + struct wl_listener container_reparent; +}; + +struct sway_xdg_shell_v6_view { + struct sway_view view; + + struct wl_listener commit; + struct wl_listener request_move; + struct wl_listener request_resize; + struct wl_listener request_maximize; + struct wl_listener new_popup; + struct wl_listener map; + struct wl_listener unmap; + struct wl_listener destroy; + + int pending_width, pending_height; +}; + +struct sway_xwayland_view { + struct sway_view view; + + struct wl_listener commit; + struct wl_listener request_move; + struct wl_listener request_resize; + struct wl_listener request_maximize; + struct wl_listener request_configure; + struct wl_listener map; + struct wl_listener unmap; + struct wl_listener destroy; + + int pending_width, pending_height; +}; + +struct sway_xwayland_unmanaged { + struct wlr_xwayland_surface *wlr_xwayland_surface; + struct wl_list link; + + int lx, ly; + + struct wl_listener request_configure; + struct wl_listener commit; + struct wl_listener map; + struct wl_listener unmap; + struct wl_listener destroy; +}; + +struct sway_wl_shell_view { + struct sway_view view; + + struct wl_listener commit; + struct wl_listener request_move; + struct wl_listener request_resize; + struct wl_listener request_maximize; + struct wl_listener destroy; + + int pending_width, pending_height; +}; + +struct sway_view_child; + +struct sway_view_child_impl { + void (*destroy)(struct sway_view_child *child); +}; + +/** + * A view child is a surface in the view tree, such as a subsurface or a popup. + */ +struct sway_view_child { + const struct sway_view_child_impl *impl; + + struct sway_view *view; + struct wlr_surface *surface; + + struct wl_listener surface_commit; + struct wl_listener surface_new_subsurface; + struct wl_listener surface_destroy; + struct wl_listener view_unmap; +}; + +struct sway_xdg_popup_v6 { + struct sway_view_child child; + + struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; + + struct wl_listener new_popup; + struct wl_listener unmap; + struct wl_listener destroy; +}; + +const char *view_get_title(struct sway_view *view); + +const char *view_get_app_id(struct sway_view *view); + +const char *view_get_class(struct sway_view *view); + +const char *view_get_instance(struct sway_view *view); + +void view_configure(struct sway_view *view, double ox, double oy, int width, + int height); + +void view_set_activated(struct sway_view *view, bool activated); + +void view_close(struct sway_view *view); + +void view_damage(struct sway_view *view, bool whole); + +void view_for_each_surface(struct sway_view *view, + wlr_surface_iterator_func_t iterator, void *user_data); + +// view implementation + +void view_init(struct sway_view *view, enum sway_view_type type, + const struct sway_view_impl *impl); + +void view_destroy(struct sway_view *view); + +void view_map(struct sway_view *view, struct wlr_surface *wlr_surface); + +void view_unmap(struct sway_view *view); + +void view_update_position(struct sway_view *view, double ox, double oy); + +void view_update_size(struct sway_view *view, int width, int height); + +void view_child_init(struct sway_view_child *child, + const struct sway_view_child_impl *impl, struct sway_view *view, + struct wlr_surface *surface); + +void view_child_destroy(struct sway_view_child *child); + +#endif diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h new file mode 100644 index 00000000..8d49fefb --- /dev/null +++ b/include/sway/tree/workspace.h @@ -0,0 +1,26 @@ +#ifndef _SWAY_WORKSPACE_H +#define _SWAY_WORKSPACE_H + +#include "sway/tree/container.h" + +extern char *prev_workspace_name; + +char *workspace_next_name(const char *output_name); + +bool workspace_switch(struct sway_container *workspace); + +struct sway_container *workspace_by_number(const char* name); + +struct sway_container *workspace_by_name(const char*); + +struct sway_container *workspace_output_next(struct sway_container *current); + +struct sway_container *workspace_next(struct sway_container *current); + +struct sway_container *workspace_output_prev(struct sway_container *current); + +struct sway_container *workspace_prev(struct sway_container *current); + +bool workspace_is_visible(struct sway_container *ws); + +#endif diff --git a/include/sway/workspace.h b/include/sway/workspace.h deleted file mode 100644 index c268fafa..00000000 --- a/include/sway/workspace.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _SWAY_WORKSPACE_H -#define _SWAY_WORKSPACE_H - -#include <wlc/wlc.h> -#include <unistd.h> -#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 |