aboutsummaryrefslogtreecommitdiffstats
path: root/include/sway/tree
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-29 12:15:31 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-29 14:21:42 -0400
commit874f009866abaf8ca43ed4cd88a69d22a3fbfc5a (patch)
tree05dff1efd73807aded434527ed1774250314116e /include/sway/tree
parentMerge pull request #1643 from acrisci/xdg-protocol-header (diff)
downloadsway-874f009866abaf8ca43ed4cd88a69d22a3fbfc5a.tar.gz
sway-874f009866abaf8ca43ed4cd88a69d22a3fbfc5a.tar.zst
sway-874f009866abaf8ca43ed4cd88a69d22a3fbfc5a.zip
move tree includes to their own directory
Diffstat (limited to 'include/sway/tree')
-rw-r--r--include/sway/tree/container.h136
-rw-r--r--include/sway/tree/layout.h51
-rw-r--r--include/sway/tree/view.h116
-rw-r--r--include/sway/tree/workspace.h26
4 files changed, 329 insertions, 0 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
new file mode 100644
index 00000000..5a2ae349
--- /dev/null
+++ b/include/sway/tree/container.h
@@ -0,0 +1,136 @@
1#ifndef _SWAY_CONTAINER_H
2#define _SWAY_CONTAINER_H
3#include <stdint.h>
4#include <sys/types.h>
5#include <wlr/types/wlr_box.h>
6#include <wlr/types/wlr_surface.h>
7#include "list.h"
8
9typedef struct sway_container swayc_t;
10
11extern swayc_t root_container;
12
13struct sway_view;
14struct sway_seat;
15
16/**
17 * Different kinds of containers.
18 *
19 * This enum is in order. A container will never be inside of a container below
20 * it on this list.
21 */
22enum swayc_types {
23 C_ROOT,
24 C_OUTPUT,
25 C_WORKSPACE,
26 C_CONTAINER,
27 C_VIEW,
28
29 C_TYPES,
30};
31
32enum swayc_layouts {
33 L_NONE,
34 L_HORIZ,
35 L_VERT,
36 L_STACKED,
37 L_TABBED,
38 L_FLOATING,
39
40 // Keep last
41 L_LAYOUTS,
42};
43
44enum swayc_border_types {
45 B_NONE,
46 B_PIXEL,
47 B_NORMAL,
48};
49
50struct sway_root;
51struct sway_output;
52struct sway_view;
53
54struct sway_container {
55 union {
56 // TODO: Encapsulate state for other node types as well like C_CONTAINER
57 struct sway_root *sway_root;
58 struct sway_output *sway_output;
59 struct sway_view *sway_view;
60 };
61
62 /**
63 * A unique ID to identify this container. Primarily used in the
64 * get_tree JSON output.
65 */
66 size_t id;
67
68 char *name;
69
70 enum swayc_types type;
71 enum swayc_layouts layout;
72 enum swayc_layouts prev_layout;
73 enum swayc_layouts workspace_layout;
74
75 // TODO convert to layout coordinates
76 double x, y;
77
78 // does not include borders or gaps.
79 double width, height;
80
81 list_t *children;
82
83 struct sway_container *parent;
84
85 list_t *marks; // list of char*
86
87 struct {
88 struct wl_signal destroy;
89 } events;
90};
91
92void swayc_descendants_of_type(swayc_t *root, enum swayc_types type,
93 void (*func)(swayc_t *item, void *data), void *data);
94
95// TODO only one container create function and pass the type?
96swayc_t *new_output(struct sway_output *sway_output);
97
98swayc_t *new_workspace(swayc_t *output, const char *name);
99
100swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view);
101
102swayc_t *destroy_output(swayc_t *output);
103swayc_t *destroy_view(swayc_t *view);
104
105swayc_t *next_view_sibling(struct sway_seat *seat);
106
107/**
108 * Finds a container based on test criteria. Returns the first container that
109 * passes the test.
110 */
111swayc_t *swayc_by_test(swayc_t *container,
112 bool (*test)(swayc_t *view, void *data), void *data);
113
114/**
115 * Finds a parent container with the given swayc_type.
116 */
117swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type);
118
119/**
120 * Maps a container's children over a function.
121 */
122void container_map(swayc_t *container,
123 void (*f)(swayc_t *view, void *data), void *data);
124
125swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
126 struct wlr_surface **surface, double *sx, double *sy);
127
128/**
129 * Apply the function for each child of the container breadth first.
130 */
131void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data),
132 void *data);
133
134swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout);
135
136#endif
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h
new file mode 100644
index 00000000..39b7fb24
--- /dev/null
+++ b/include/sway/tree/layout.h
@@ -0,0 +1,51 @@
1#ifndef _SWAY_LAYOUT_H
2#define _SWAY_LAYOUT_H
3
4#include <wlr/types/wlr_output_layout.h>
5#include "sway/tree/container.h"
6
7enum movement_direction {
8 MOVE_LEFT,
9 MOVE_RIGHT,
10 MOVE_UP,
11 MOVE_DOWN,
12 MOVE_PARENT,
13 MOVE_CHILD,
14 MOVE_NEXT,
15 MOVE_PREV,
16 MOVE_FIRST
17};
18
19struct sway_container;
20
21struct sway_root {
22 struct wlr_output_layout *output_layout;
23
24 struct wl_listener output_layout_change;
25
26 struct wl_list unmanaged_views; // sway_view::unmanaged_view_link
27
28 struct {
29 struct wl_signal new_container;
30 } events;
31};
32
33void init_layout(void);
34
35void add_child(struct sway_container *parent, struct sway_container *child);
36
37swayc_t *add_sibling(swayc_t *parent, swayc_t *child);
38
39struct sway_container *remove_child(struct sway_container *child);
40
41enum swayc_layouts default_layout(struct sway_container *output);
42
43void sort_workspaces(struct sway_container *output);
44
45void arrange_windows(struct sway_container *container,
46 double width, double height);
47
48swayc_t *get_swayc_in_direction(swayc_t *container,
49 struct sway_seat *seat, enum movement_direction dir);
50
51#endif
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
new file mode 100644
index 00000000..e5f53f4e
--- /dev/null
+++ b/include/sway/tree/view.h
@@ -0,0 +1,116 @@
1#ifndef _SWAY_VIEW_H
2#define _SWAY_VIEW_H
3#include <wayland-server.h>
4#include <wlr/types/wlr_surface.h>
5#include <wlr/types/wlr_xdg_shell_v6.h>
6#include <wlr/xwayland.h>
7
8struct sway_container;
9struct sway_view;
10
11struct sway_xdg_surface_v6 {
12 struct sway_view *view;
13
14 struct wl_listener commit;
15 struct wl_listener request_move;
16 struct wl_listener request_resize;
17 struct wl_listener request_maximize;
18 struct wl_listener destroy;
19
20 int pending_width, pending_height;
21};
22
23struct sway_xwayland_surface {
24 struct sway_view *view;
25
26 struct wl_listener commit;
27 struct wl_listener request_move;
28 struct wl_listener request_resize;
29 struct wl_listener request_maximize;
30 struct wl_listener request_configure;
31 struct wl_listener unmap_notify;
32 struct wl_listener map_notify;
33 struct wl_listener destroy;
34
35 int pending_width, pending_height;
36};
37
38struct sway_wl_shell_surface {
39 struct sway_view *view;
40
41 struct wl_listener commit;
42 struct wl_listener request_move;
43 struct wl_listener request_resize;
44 struct wl_listener request_maximize;
45 struct wl_listener destroy;
46
47 int pending_width, pending_height;
48};
49
50enum sway_view_type {
51 SWAY_WL_SHELL_VIEW,
52 SWAY_XDG_SHELL_V6_VIEW,
53 SWAY_XWAYLAND_VIEW,
54 // Keep last
55 SWAY_VIEW_TYPES,
56};
57
58enum sway_view_prop {
59 VIEW_PROP_TITLE,
60 VIEW_PROP_APP_ID,
61 VIEW_PROP_CLASS,
62 VIEW_PROP_INSTANCE,
63};
64
65struct sway_view {
66 enum sway_view_type type;
67 struct sway_container *swayc;
68 struct wlr_surface *surface;
69 int width, height;
70
71 union {
72 struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;
73 struct wlr_xwayland_surface *wlr_xwayland_surface;
74 struct wlr_wl_shell_surface *wlr_wl_shell_surface;
75 };
76
77 union {
78 struct sway_xdg_surface_v6 *sway_xdg_surface_v6;
79 struct sway_xwayland_surface *sway_xwayland_surface;
80 struct sway_wl_shell_surface *sway_wl_shell_surface;
81 };
82
83 struct {
84 const char *(*get_prop)(struct sway_view *view,
85 enum sway_view_prop prop);
86 void (*set_size)(struct sway_view *view,
87 int width, int height);
88 void (*set_position)(struct sway_view *view,
89 double ox, double oy);
90 void (*set_activated)(struct sway_view *view, bool activated);
91 void (*close)(struct sway_view *view);
92 } iface;
93
94 // only used for unmanaged views (shell specific)
95 struct wl_list unmanaged_view_link; // sway_root::unmanaged views
96};
97
98const char *view_get_title(struct sway_view *view);
99
100const char *view_get_app_id(struct sway_view *view);
101
102const char *view_get_class(struct sway_view *view);
103
104const char *view_get_instance(struct sway_view *view);
105
106void view_set_size(struct sway_view *view, int width, int height);
107
108void view_set_position(struct sway_view *view, double ox, double oy);
109
110void view_set_activated(struct sway_view *view, bool activated);
111
112void view_close(struct sway_view *view);
113
114void view_update_outputs(struct sway_view *view, const struct wlr_box *before);
115
116#endif
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h
new file mode 100644
index 00000000..c8ce40d1
--- /dev/null
+++ b/include/sway/tree/workspace.h
@@ -0,0 +1,26 @@
1#ifndef _SWAY_WORKSPACE_H
2#define _SWAY_WORKSPACE_H
3
4#include "sway/tree/container.h"
5
6extern char *prev_workspace_name;
7
8char *workspace_next_name(const char *output_name);
9
10swayc_t *workspace_create(const char *name);
11
12bool workspace_switch(swayc_t *workspace);
13
14struct sway_container *workspace_by_number(const char* name);
15
16swayc_t *workspace_by_name(const char*);
17
18struct sway_container *workspace_output_next(swayc_t *current);
19
20struct sway_container *workspace_next(swayc_t *current);
21
22struct sway_container *workspace_output_prev(swayc_t *current);
23
24struct sway_container *workspace_prev(swayc_t *current);
25
26#endif