aboutsummaryrefslogtreecommitdiff
path: root/include/sway/tree
diff options
context:
space:
mode:
Diffstat (limited to 'include/sway/tree')
-rw-r--r--include/sway/tree/container.h192
-rw-r--r--include/sway/tree/layout.h78
-rw-r--r--include/sway/tree/output.h0
-rw-r--r--include/sway/tree/view.h186
-rw-r--r--include/sway/tree/workspace.h26
5 files changed, 482 insertions, 0 deletions
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