diff options
-rw-r--r-- | include/sway/container.h | 4 | ||||
-rw-r--r-- | include/sway/layout.h | 8 | ||||
-rw-r--r-- | sway/config/output.c | 17 | ||||
-rw-r--r-- | sway/desktop/output.c | 12 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 6 | ||||
-rw-r--r-- | sway/tree/container.c | 9 | ||||
-rw-r--r-- | sway/tree/layout.c | 17 |
7 files changed, 43 insertions, 30 deletions
diff --git a/include/sway/container.h b/include/sway/container.h index e3f84fc6..b15e0428 100644 --- a/include/sway/container.h +++ b/include/sway/container.h | |||
@@ -57,9 +57,9 @@ enum swayc_border_types { | |||
57 | B_NORMAL, /**< Normal border with title bar */ | 57 | B_NORMAL, /**< Normal border with title bar */ |
58 | }; | 58 | }; |
59 | 59 | ||
60 | struct sway_root; | ||
60 | struct sway_output; | 61 | struct sway_output; |
61 | struct sway_view; | 62 | struct sway_view; |
62 | struct wlr_output_layout; | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Stores information about a container. | 65 | * Stores information about a container. |
@@ -69,7 +69,7 @@ struct wlr_output_layout; | |||
69 | struct sway_container { | 69 | struct sway_container { |
70 | union { | 70 | union { |
71 | // TODO: Encapsulate state for other node types as well like C_CONTAINER | 71 | // TODO: Encapsulate state for other node types as well like C_CONTAINER |
72 | struct wlr_output_layout *output_layout; // C_ROOT | 72 | struct sway_root *sway_root; // C_ROOT |
73 | struct sway_output *sway_output; // C_OUTPUT | 73 | struct sway_output *sway_output; // C_OUTPUT |
74 | struct sway_view *sway_view; // C_VIEW | 74 | struct sway_view *sway_view; // C_VIEW |
75 | }; | 75 | }; |
diff --git a/include/sway/layout.h b/include/sway/layout.h index f3b62b05..bfd96a02 100644 --- a/include/sway/layout.h +++ b/include/sway/layout.h | |||
@@ -1,8 +1,16 @@ | |||
1 | #ifndef _SWAY_LAYOUT_H | 1 | #ifndef _SWAY_LAYOUT_H |
2 | #define _SWAY_LAYOUT_H | 2 | #define _SWAY_LAYOUT_H |
3 | 3 | ||
4 | #include <wlr/types/wlr_output_layout.h> | ||
5 | |||
4 | struct sway_container; | 6 | struct sway_container; |
5 | 7 | ||
8 | struct sway_root { | ||
9 | struct wlr_output_layout *output_layout; | ||
10 | |||
11 | struct wl_listener output_layout_change; | ||
12 | }; | ||
13 | |||
6 | void init_layout(void); | 14 | void init_layout(void); |
7 | void add_child(struct sway_container *parent, struct sway_container *child); | 15 | void add_child(struct sway_container *parent, struct sway_container *child); |
8 | struct sway_container *remove_child(struct sway_container *child); | 16 | struct sway_container *remove_child(struct sway_container *child); |
diff --git a/sway/config/output.c b/sway/config/output.c index b06c7c0e..ed47a617 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -99,7 +99,8 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { | |||
99 | 99 | ||
100 | struct wlr_output *wlr_output = output->sway_output->wlr_output; | 100 | struct wlr_output *wlr_output = output->sway_output->wlr_output; |
101 | if (oc && oc->enabled == 0) { | 101 | if (oc && oc->enabled == 0) { |
102 | wlr_output_layout_remove(root_container.output_layout, wlr_output); | 102 | wlr_output_layout_remove(root_container.sway_root->output_layout, |
103 | wlr_output); | ||
103 | destroy_output(output); | 104 | destroy_output(output); |
104 | return; | 105 | return; |
105 | } | 106 | } |
@@ -117,19 +118,21 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { | |||
117 | if (oc && oc->transform >= 0) { | 118 | if (oc && oc->transform >= 0) { |
118 | sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform); | 119 | sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform); |
119 | wlr_output_transform(wlr_output, oc->transform); | 120 | wlr_output_transform(wlr_output, oc->transform); |
120 | wl_signal_emit(&output->sway_output->events.transform, output->sway_output); | 121 | wl_signal_emit(&output->sway_output->events.transform, |
122 | output->sway_output); | ||
121 | } | 123 | } |
122 | 124 | ||
123 | // Find position for it | 125 | // Find position for it |
124 | if (oc && (oc->x != -1 || oc->y != -1)) { | 126 | if (oc && (oc->x != -1 || oc->y != -1)) { |
125 | sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); | 127 | sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); |
126 | wlr_output_layout_add(root_container.output_layout, wlr_output, oc->x, | 128 | wlr_output_layout_add(root_container.sway_root->output_layout, |
127 | oc->y); | 129 | wlr_output, oc->x, oc->y); |
128 | } else { | 130 | } else { |
129 | wlr_output_layout_add_auto(root_container.output_layout, wlr_output); | 131 | wlr_output_layout_add_auto(root_container.sway_root->output_layout, |
132 | wlr_output); | ||
130 | } | 133 | } |
131 | struct wlr_box *output_layout_box = | 134 | struct wlr_box *output_layout_box = wlr_output_layout_get_box( |
132 | wlr_output_layout_get_box(root_container.output_layout, wlr_output); | 135 | root_container.sway_root->output_layout, wlr_output); |
133 | output->x = output_layout_box->x; | 136 | output->x = output_layout_box->x; |
134 | output->y = output_layout_box->y; | 137 | output->y = output_layout_box->y; |
135 | output->width = output_layout_box->width; | 138 | output->width = output_layout_box->width; |
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index f44cda1a..bcdaa7d2 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -72,8 +72,7 @@ static void output_frame_view(swayc_t *view, void *data) { | |||
72 | } | 72 | } |
73 | 73 | ||
74 | static void output_frame_notify(struct wl_listener *listener, void *data) { | 74 | static void output_frame_notify(struct wl_listener *listener, void *data) { |
75 | struct sway_output *soutput = wl_container_of( | 75 | struct sway_output *soutput = wl_container_of(listener, soutput, frame); |
76 | listener, soutput, frame); | ||
77 | struct wlr_output *wlr_output = data; | 76 | struct wlr_output *wlr_output = data; |
78 | struct sway_server *server = soutput->server; | 77 | struct sway_server *server = soutput->server; |
79 | 78 | ||
@@ -93,20 +92,17 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { | |||
93 | } | 92 | } |
94 | 93 | ||
95 | static void output_resolution_notify(struct wl_listener *listener, void *data) { | 94 | static void output_resolution_notify(struct wl_listener *listener, void *data) { |
96 | struct sway_output *soutput = wl_container_of( | 95 | struct sway_output *soutput = wl_container_of(listener, soutput, resolution); |
97 | listener, soutput, resolution); | ||
98 | arrange_windows(soutput->swayc, -1, -1); | 96 | arrange_windows(soutput->swayc, -1, -1); |
99 | } | 97 | } |
100 | 98 | ||
101 | static void output_scale_notify(struct wl_listener *listener, void *data) { | 99 | static void output_scale_notify(struct wl_listener *listener, void *data) { |
102 | struct sway_output *soutput = wl_container_of( | 100 | struct sway_output *soutput = wl_container_of(listener, soutput, scale); |
103 | listener, soutput, scale); | ||
104 | arrange_windows(soutput->swayc, -1, -1); | 101 | arrange_windows(soutput->swayc, -1, -1); |
105 | } | 102 | } |
106 | 103 | ||
107 | static void output_transform_notify(struct wl_listener *listener, void *data) { | 104 | static void output_transform_notify(struct wl_listener *listener, void *data) { |
108 | struct sway_output *soutput = wl_container_of( | 105 | struct sway_output *soutput = wl_container_of(listener, soutput, transform); |
109 | listener, soutput, transform); | ||
110 | arrange_windows(soutput->swayc, -1, -1); | 106 | arrange_windows(soutput->swayc, -1, -1); |
111 | } | 107 | } |
112 | 108 | ||
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 65c7e1ec..e3799d2d 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -55,7 +55,7 @@ static void set_position(struct sway_view *view, double ox, double oy) { | |||
55 | if (!sway_assert(root, "output must be within tree to set position")) { | 55 | if (!sway_assert(root, "output must be within tree to set position")) { |
56 | return; | 56 | return; |
57 | } | 57 | } |
58 | struct wlr_output_layout *layout = root->output_layout; | 58 | struct wlr_output_layout *layout = root->sway_root->output_layout; |
59 | struct wlr_output_layout_output *loutput = | 59 | struct wlr_output_layout_output *loutput = |
60 | wlr_output_layout_get(layout, output->sway_output->wlr_output); | 60 | wlr_output_layout_get(layout, output->sway_output->wlr_output); |
61 | if (!sway_assert(loutput, "output must be within layout to set position")) { | 61 | if (!sway_assert(loutput, "output must be within layout to set position")) { |
@@ -147,14 +147,14 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { | |||
147 | // TODO remove from the tree when the surface goes away (unmapped) | 147 | // TODO remove from the tree when the surface goes away (unmapped) |
148 | sway_view->surface = xsurface->surface; | 148 | sway_view->surface = xsurface->surface; |
149 | sway_surface->view = sway_view; | 149 | sway_surface->view = sway_view; |
150 | 150 | ||
151 | // TODO: | 151 | // TODO: |
152 | // - Wire up listeners | 152 | // - Wire up listeners |
153 | // - Handle popups | 153 | // - Handle popups |
154 | // - Look up pid and open on appropriate workspace | 154 | // - Look up pid and open on appropriate workspace |
155 | // - Set new view to maximized so it behaves nicely | 155 | // - Set new view to maximized so it behaves nicely |
156 | // - Criteria | 156 | // - Criteria |
157 | 157 | ||
158 | sway_surface->commit.notify = handle_commit; | 158 | sway_surface->commit.notify = handle_commit; |
159 | wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit); | 159 | wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit); |
160 | sway_surface->destroy.notify = handle_destroy; | 160 | sway_surface->destroy.notify = handle_destroy; |
diff --git a/sway/tree/container.c b/sway/tree/container.c index e4c27d61..f70bccdc 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -26,13 +26,6 @@ void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, | |||
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | static void update_root_geometry() { | ||
30 | struct wlr_box *box = | ||
31 | wlr_output_layout_get_box(root_container.output_layout, NULL); | ||
32 | root_container.width = box->width; | ||
33 | root_container.height = box->height; | ||
34 | } | ||
35 | |||
36 | static swayc_t *new_swayc(enum swayc_types type) { | 29 | static swayc_t *new_swayc(enum swayc_types type) { |
37 | // next id starts at 1 because 0 is assigned to root_container in layout.c | 30 | // next id starts at 1 because 0 is assigned to root_container in layout.c |
38 | static size_t next_id = 1; | 31 | static size_t next_id = 1; |
@@ -94,7 +87,6 @@ swayc_t *new_output(struct sway_output *sway_output) { | |||
94 | sway_log(L_DEBUG, "Creating default workspace %s", ws_name); | 87 | sway_log(L_DEBUG, "Creating default workspace %s", ws_name); |
95 | new_workspace(output, ws_name); | 88 | new_workspace(output, ws_name); |
96 | free(ws_name); | 89 | free(ws_name); |
97 | update_root_geometry(); | ||
98 | return output; | 90 | return output; |
99 | } | 91 | } |
100 | 92 | ||
@@ -195,7 +187,6 @@ swayc_t *destroy_output(swayc_t *output) { | |||
195 | 187 | ||
196 | sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); | 188 | sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); |
197 | free_swayc(output); | 189 | free_swayc(output); |
198 | update_root_geometry(); | ||
199 | 190 | ||
200 | return &root_container; | 191 | return &root_container; |
201 | } | 192 | } |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index cb39a361..fd17f8a5 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <wlr/types/wlr_output.h> | 7 | #include <wlr/types/wlr_output.h> |
8 | #include <wlr/types/wlr_output_layout.h> | 8 | #include <wlr/types/wlr_output_layout.h> |
9 | #include "sway/container.h" | 9 | #include "sway/container.h" |
10 | #include "sway/layout.h" | ||
10 | #include "sway/output.h" | 11 | #include "sway/output.h" |
11 | #include "sway/view.h" | 12 | #include "sway/view.h" |
12 | #include "list.h" | 13 | #include "list.h" |
@@ -14,13 +15,27 @@ | |||
14 | 15 | ||
15 | swayc_t root_container; | 16 | swayc_t root_container; |
16 | 17 | ||
18 | static void output_layout_change_notify(struct wl_listener *listener, void *data) { | ||
19 | struct wlr_box *box = wlr_output_layout_get_box( | ||
20 | root_container.sway_root->output_layout, NULL); | ||
21 | root_container.width = box->width; | ||
22 | root_container.height = box->height; | ||
23 | } | ||
24 | |||
17 | void init_layout(void) { | 25 | void init_layout(void) { |
18 | root_container.id = 0; // normally assigned in new_swayc() | 26 | root_container.id = 0; // normally assigned in new_swayc() |
19 | root_container.type = C_ROOT; | 27 | root_container.type = C_ROOT; |
20 | root_container.layout = L_NONE; | 28 | root_container.layout = L_NONE; |
21 | root_container.name = strdup("root"); | 29 | root_container.name = strdup("root"); |
22 | root_container.children = create_list(); | 30 | root_container.children = create_list(); |
23 | root_container.output_layout = wlr_output_layout_create(); | 31 | |
32 | root_container.sway_root = calloc(1, sizeof(*root_container.sway_root)); | ||
33 | root_container.sway_root->output_layout = wlr_output_layout_create(); | ||
34 | |||
35 | root_container.sway_root->output_layout_change.notify = | ||
36 | output_layout_change_notify; | ||
37 | wl_signal_add(&root_container.sway_root->output_layout->events.change, | ||
38 | &root_container.sway_root->output_layout_change); | ||
24 | } | 39 | } |
25 | 40 | ||
26 | void add_child(swayc_t *parent, swayc_t *child) { | 41 | void add_child(swayc_t *parent, swayc_t *child) { |