diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-03-29 23:41:33 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-03-29 23:41:33 -0400 |
commit | dc8c9fbeb664518c76066cc28ee29452c6c30128 (patch) | |
tree | 88c2de0d08e00b2a30cb20cdfadfa6e53f5c59b4 /include/sway/tree | |
parent | Merge pull request #1653 from swaywm/revert-1647-refactor-tree (diff) | |
download | sway-dc8c9fbeb664518c76066cc28ee29452c6c30128.tar.gz sway-dc8c9fbeb664518c76066cc28ee29452c6c30128.tar.zst sway-dc8c9fbeb664518c76066cc28ee29452c6c30128.zip |
Revert "Merge pull request #1653 from swaywm/revert-1647-refactor-tree"
This reverts commit 472e81f35d689d67cda241acafda91c688d61046, reversing
changes made to 6b7841b11ff4cd35f54d69dc92029855893e5ce0.
Diffstat (limited to 'include/sway/tree')
-rw-r--r-- | include/sway/tree/container.h | 137 | ||||
-rw-r--r-- | include/sway/tree/layout.h | 52 | ||||
-rw-r--r-- | include/sway/tree/view.h | 116 | ||||
-rw-r--r-- | include/sway/tree/workspace.h | 26 |
4 files changed, 331 insertions, 0 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h new file mode 100644 index 00000000..16df3ee7 --- /dev/null +++ b/include/sway/tree/container.h | |||
@@ -0,0 +1,137 @@ | |||
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 | |||
9 | extern struct sway_container root_container; | ||
10 | |||
11 | struct sway_view; | ||
12 | struct sway_seat; | ||
13 | |||
14 | /** | ||
15 | * Different kinds of containers. | ||
16 | * | ||
17 | * This enum is in order. A container will never be inside of a container below | ||
18 | * it on this list. | ||
19 | */ | ||
20 | enum sway_container_type { | ||
21 | C_ROOT, | ||
22 | C_OUTPUT, | ||
23 | C_WORKSPACE, | ||
24 | C_CONTAINER, | ||
25 | C_VIEW, | ||
26 | |||
27 | C_TYPES, | ||
28 | }; | ||
29 | |||
30 | enum sway_container_layout { | ||
31 | L_NONE, | ||
32 | L_HORIZ, | ||
33 | L_VERT, | ||
34 | L_STACKED, | ||
35 | L_TABBED, | ||
36 | L_FLOATING, | ||
37 | |||
38 | // Keep last | ||
39 | L_LAYOUTS, | ||
40 | }; | ||
41 | |||
42 | enum sway_container_border { | ||
43 | B_NONE, | ||
44 | B_PIXEL, | ||
45 | B_NORMAL, | ||
46 | }; | ||
47 | |||
48 | struct sway_root; | ||
49 | struct sway_output; | ||
50 | struct sway_view; | ||
51 | |||
52 | struct sway_container { | ||
53 | union { | ||
54 | // TODO: Encapsulate state for other node types as well like C_CONTAINER | ||
55 | struct sway_root *sway_root; | ||
56 | struct sway_output *sway_output; | ||
57 | struct sway_view *sway_view; | ||
58 | }; | ||
59 | |||
60 | /** | ||
61 | * A unique ID to identify this container. Primarily used in the | ||
62 | * get_tree JSON output. | ||
63 | */ | ||
64 | size_t id; | ||
65 | |||
66 | char *name; | ||
67 | |||
68 | enum sway_container_type type; | ||
69 | enum sway_container_layout layout; | ||
70 | enum sway_container_layout prev_layout; | ||
71 | enum sway_container_layout workspace_layout; | ||
72 | |||
73 | // TODO convert to layout coordinates | ||
74 | double x, y; | ||
75 | |||
76 | // does not include borders or gaps. | ||
77 | double width, height; | ||
78 | |||
79 | list_t *children; | ||
80 | |||
81 | struct sway_container *parent; | ||
82 | |||
83 | list_t *marks; // list of char* | ||
84 | |||
85 | struct { | ||
86 | struct wl_signal destroy; | ||
87 | } events; | ||
88 | }; | ||
89 | |||
90 | // TODO only one container create function and pass the type? | ||
91 | struct sway_container *container_output_create( | ||
92 | struct sway_output *sway_output); | ||
93 | |||
94 | struct sway_container *container_workspace_create( | ||
95 | struct sway_container *output, const char *name); | ||
96 | |||
97 | struct sway_container *container_view_create( | ||
98 | struct sway_container *sibling, struct sway_view *sway_view); | ||
99 | |||
100 | struct sway_container *container_output_destroy(struct sway_container *output); | ||
101 | |||
102 | struct sway_container *container_view_destroy(struct sway_container *view); | ||
103 | |||
104 | struct sway_container *container_set_layout(struct sway_container *container, | ||
105 | enum sway_container_layout layout); | ||
106 | |||
107 | void container_descendents(struct sway_container *root, | ||
108 | enum sway_container_type type, | ||
109 | void (*func)(struct sway_container *item, void *data), void *data); | ||
110 | |||
111 | /** | ||
112 | * Finds a container based on test criteria. Returns the first container that | ||
113 | * passes the test. | ||
114 | */ | ||
115 | struct sway_container *container_find(struct sway_container *container, | ||
116 | bool (*test)(struct sway_container *view, void *data), void *data); | ||
117 | |||
118 | /** | ||
119 | * Finds a parent container with the given struct sway_containerype. | ||
120 | */ | ||
121 | struct sway_container *container_parent(struct sway_container *container, | ||
122 | enum sway_container_type type); | ||
123 | |||
124 | /** | ||
125 | * Find a container at the given coordinates. | ||
126 | */ | ||
127 | struct sway_container *container_at(struct sway_container *parent, | ||
128 | double lx, double ly, struct wlr_surface **surface, | ||
129 | double *sx, double *sy); | ||
130 | |||
131 | /** | ||
132 | * Apply the function for each child of the container breadth first. | ||
133 | */ | ||
134 | void container_for_each_descendent(struct sway_container *container, | ||
135 | void (*f)(struct sway_container *container, void *data), void *data); | ||
136 | |||
137 | #endif | ||
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h new file mode 100644 index 00000000..ad52bdb0 --- /dev/null +++ b/include/sway/tree/layout.h | |||
@@ -0,0 +1,52 @@ | |||
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 | |||
7 | enum 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 | |||
19 | struct sway_container; | ||
20 | |||
21 | struct 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 | |||
33 | void layout_init(void); | ||
34 | |||
35 | void container_add_child(struct sway_container *parent, struct sway_container *child); | ||
36 | |||
37 | struct sway_container *container_add_sibling(struct sway_container *parent, | ||
38 | struct sway_container *child); | ||
39 | |||
40 | struct sway_container *container_remove_child(struct sway_container *child); | ||
41 | |||
42 | enum sway_container_layout container_get_default_layout(struct sway_container *output); | ||
43 | |||
44 | void container_sort_workspaces(struct sway_container *output); | ||
45 | |||
46 | void arrange_windows(struct sway_container *container, | ||
47 | double width, double height); | ||
48 | |||
49 | struct sway_container *container_get_in_direction(struct sway_container | ||
50 | *container, struct sway_seat *seat, enum movement_direction dir); | ||
51 | |||
52 | #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 | |||
8 | struct sway_container; | ||
9 | struct sway_view; | ||
10 | |||
11 | struct 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 | |||
23 | struct 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 | |||
38 | struct 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 | |||
50 | enum 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 | |||
58 | enum sway_view_prop { | ||
59 | VIEW_PROP_TITLE, | ||
60 | VIEW_PROP_APP_ID, | ||
61 | VIEW_PROP_CLASS, | ||
62 | VIEW_PROP_INSTANCE, | ||
63 | }; | ||
64 | |||
65 | struct 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 | |||
98 | const char *view_get_title(struct sway_view *view); | ||
99 | |||
100 | const char *view_get_app_id(struct sway_view *view); | ||
101 | |||
102 | const char *view_get_class(struct sway_view *view); | ||
103 | |||
104 | const char *view_get_instance(struct sway_view *view); | ||
105 | |||
106 | void view_set_size(struct sway_view *view, int width, int height); | ||
107 | |||
108 | void view_set_position(struct sway_view *view, double ox, double oy); | ||
109 | |||
110 | void view_set_activated(struct sway_view *view, bool activated); | ||
111 | |||
112 | void view_close(struct sway_view *view); | ||
113 | |||
114 | void 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..d73b29c1 --- /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 | |||
6 | extern char *prev_workspace_name; | ||
7 | |||
8 | char *workspace_next_name(const char *output_name); | ||
9 | |||
10 | struct sway_container *workspace_create(const char *name); | ||
11 | |||
12 | bool workspace_switch(struct sway_container *workspace); | ||
13 | |||
14 | struct sway_container *workspace_by_number(const char* name); | ||
15 | |||
16 | struct sway_container *workspace_by_name(const char*); | ||
17 | |||
18 | struct sway_container *workspace_output_next(struct sway_container *current); | ||
19 | |||
20 | struct sway_container *workspace_next(struct sway_container *current); | ||
21 | |||
22 | struct sway_container *workspace_output_prev(struct sway_container *current); | ||
23 | |||
24 | struct sway_container *workspace_prev(struct sway_container *current); | ||
25 | |||
26 | #endif | ||