aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/output.h4
-rw-r--r--sway/desktop/output.c66
-rw-r--r--sway/desktop/render.c8
3 files changed, 19 insertions, 59 deletions
diff --git a/include/sway/output.h b/include/sway/output.h
index 96986700..0ebcc77d 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -72,8 +72,8 @@ struct sway_output *output_get_in_direction(struct sway_output *reference,
72void output_add_workspace(struct sway_output *output, 72void output_add_workspace(struct sway_output *output,
73 struct sway_workspace *workspace); 73 struct sway_workspace *workspace);
74 74
75typedef void (*sway_surface_iterator_func_t)(struct sway_output *output, struct sway_view *view, 75typedef void (*sway_surface_iterator_func_t)(struct sway_output *output,
76 struct wlr_surface *surface, struct wlr_box *box, float rotation, 76 struct sway_view *view, struct wlr_surface *surface, struct wlr_box *box,
77 void *user_data); 77 void *user_data);
78 78
79void output_damage_whole(struct sway_output *output); 79void output_damage_whole(struct sway_output *output);
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index ab8fd7e8..aa148290 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -56,26 +56,6 @@ struct sway_output *all_output_by_name_or_id(const char *name_or_id) {
56 return NULL; 56 return NULL;
57} 57}
58 58
59/**
60 * Rotate a child's position relative to a parent. The parent size is (pw, ph),
61 * the child position is (*sx, *sy) and its size is (sw, sh).
62 */
63static void rotate_child_position(double *sx, double *sy, double sw, double sh,
64 double pw, double ph, float rotation) {
65 if (rotation == 0.0f) {
66 return;
67 }
68
69 // Coordinates relative to the center of the subsurface
70 double ox = *sx - pw/2 + sw/2,
71 oy = *sy - ph/2 + sh/2;
72 // Rotated coordinates
73 double rx = cos(-rotation)*ox - sin(-rotation)*oy,
74 ry = cos(-rotation)*oy + sin(-rotation)*ox;
75 *sx = rx + pw/2 - sw/2;
76 *sy = ry + ph/2 - sh/2;
77}
78
79struct surface_iterator_data { 59struct surface_iterator_data {
80 sway_surface_iterator_func_t user_iterator; 60 sway_surface_iterator_func_t user_iterator;
81 void *user_data; 61 void *user_data;
@@ -84,7 +64,6 @@ struct surface_iterator_data {
84 struct sway_view *view; 64 struct sway_view *view;
85 double ox, oy; 65 double ox, oy;
86 int width, height; 66 int width, height;
87 float rotation;
88}; 67};
89 68
90static bool get_surface_box(struct surface_iterator_data *data, 69static bool get_surface_box(struct surface_iterator_data *data,
@@ -99,14 +78,9 @@ static bool get_surface_box(struct surface_iterator_data *data,
99 int sw = surface->current.width; 78 int sw = surface->current.width;
100 int sh = surface->current.height; 79 int sh = surface->current.height;
101 80
102 double _sx = sx;
103 double _sy = sy;
104 rotate_child_position(&_sx, &_sy, sw, sh, data->width, data->height,
105 data->rotation);
106
107 struct wlr_box box = { 81 struct wlr_box box = {
108 .x = floor(data->ox + _sx), 82 .x = floor(data->ox + sx),
109 .y = floor(data->oy + _sy), 83 .y = floor(data->oy + sy),
110 .width = sw, 84 .width = sw,
111 .height = sh, 85 .height = sh,
112 }; 86 };
@@ -114,16 +88,13 @@ static bool get_surface_box(struct surface_iterator_data *data,
114 memcpy(surface_box, &box, sizeof(struct wlr_box)); 88 memcpy(surface_box, &box, sizeof(struct wlr_box));
115 } 89 }
116 90
117 struct wlr_box rotated_box;
118 wlr_box_rotated_bounds(&rotated_box, &box, data->rotation);
119
120 struct wlr_box output_box = { 91 struct wlr_box output_box = {
121 .width = output->width, 92 .width = output->width,
122 .height = output->height, 93 .height = output->height,
123 }; 94 };
124 95
125 struct wlr_box intersection; 96 struct wlr_box intersection;
126 return wlr_box_intersection(&intersection, &output_box, &rotated_box); 97 return wlr_box_intersection(&intersection, &output_box, &box);
127} 98}
128 99
129static void output_for_each_surface_iterator(struct wlr_surface *surface, 100static void output_for_each_surface_iterator(struct wlr_surface *surface,
@@ -136,7 +107,7 @@ static void output_for_each_surface_iterator(struct wlr_surface *surface,
136 return; 107 return;
137 } 108 }
138 109
139 data->user_iterator(data->output, data->view, surface, &box, data->rotation, 110 data->user_iterator(data->output, data->view, surface, &box,
140 data->user_data); 111 data->user_data);
141} 112}
142 113
@@ -152,7 +123,6 @@ void output_surface_for_each_surface(struct sway_output *output,
152 .oy = oy, 123 .oy = oy,
153 .width = surface->current.width, 124 .width = surface->current.width,
154 .height = surface->current.height, 125 .height = surface->current.height,
155 .rotation = 0,
156 }; 126 };
157 127
158 wlr_surface_for_each_surface(surface, 128 wlr_surface_for_each_surface(surface,
@@ -173,7 +143,6 @@ void output_view_for_each_surface(struct sway_output *output,
173 - view->geometry.y, 143 - view->geometry.y,
174 .width = view->container->current.content_width, 144 .width = view->container->current.content_width,
175 .height = view->container->current.content_height, 145 .height = view->container->current.content_height,
176 .rotation = 0, // TODO
177 }; 146 };
178 147
179 view_for_each_surface(view, output_for_each_surface_iterator, &data); 148 view_for_each_surface(view, output_for_each_surface_iterator, &data);
@@ -193,7 +162,6 @@ void output_view_for_each_popup_surface(struct sway_output *output,
193 - view->geometry.y, 162 - view->geometry.y,
194 .width = view->container->current.content_width, 163 .width = view->container->current.content_width,
195 .height = view->container->current.content_height, 164 .height = view->container->current.content_height,
196 .rotation = 0, // TODO
197 }; 165 };
198 166
199 view_for_each_popup_surface(view, output_for_each_surface_iterator, &data); 167 view_for_each_popup_surface(view, output_for_each_surface_iterator, &data);
@@ -216,7 +184,6 @@ void output_layer_for_each_surface(struct sway_output *output,
216 .oy = layer_surface->geo.y, 184 .oy = layer_surface->geo.y,
217 .width = surface->current.width, 185 .width = surface->current.width,
218 .height = surface->current.height, 186 .height = surface->current.height,
219 .rotation = 0,
220 }; 187 };
221 wlr_layer_surface_v1_for_each_surface(wlr_layer_surface_v1, 188 wlr_layer_surface_v1_for_each_surface(wlr_layer_surface_v1,
222 output_for_each_surface_iterator, &data); 189 output_for_each_surface_iterator, &data);
@@ -254,7 +221,6 @@ void output_layer_for_each_popup_surface(struct sway_output *output,
254 .oy = layer_surface->geo.y, 221 .oy = layer_surface->geo.y,
255 .width = surface->current.width, 222 .width = surface->current.width,
256 .height = surface->current.height, 223 .height = surface->current.height,
257 .rotation = 0,
258 }; 224 };
259 wlr_layer_surface_v1_for_each_popup_surface(wlr_layer_surface_v1, 225 wlr_layer_surface_v1_for_each_popup_surface(wlr_layer_surface_v1,
260 output_for_each_surface_iterator, &data); 226 output_for_each_surface_iterator, &data);
@@ -426,9 +392,9 @@ struct send_frame_done_data {
426 int msec_until_refresh; 392 int msec_until_refresh;
427}; 393};
428 394
429static void send_frame_done_iterator(struct sway_output *output, struct sway_view *view, 395static void send_frame_done_iterator(struct sway_output *output,
430 struct wlr_surface *surface, struct wlr_box *box, float rotation, 396 struct sway_view *view, struct wlr_surface *surface,
431 void *user_data) { 397 struct wlr_box *box, void *user_data) {
432 int view_max_render_time = 0; 398 int view_max_render_time = 0;
433 if (view != NULL) { 399 if (view != NULL) {
434 view_max_render_time = view->max_render_time; 400 view_max_render_time = view->max_render_time;
@@ -451,9 +417,9 @@ static void send_frame_done(struct sway_output *output, struct send_frame_done_d
451 output_for_each_surface(output, send_frame_done_iterator, data); 417 output_for_each_surface(output, send_frame_done_iterator, data);
452} 418}
453 419
454static void count_surface_iterator(struct sway_output *output, struct sway_view *view, 420static void count_surface_iterator(struct sway_output *output,
455 struct wlr_surface *surface, struct wlr_box *_box, float rotation, 421 struct sway_view *view, struct wlr_surface *surface,
456 void *data) { 422 struct wlr_box *box, void *data) {
457 size_t *n = data; 423 size_t *n = data;
458 (*n)++; 424 (*n)++;
459} 425}
@@ -657,18 +623,15 @@ void output_damage_whole(struct sway_output *output) {
657 } 623 }
658} 624}
659 625
660static void damage_surface_iterator(struct sway_output *output, struct sway_view *view, 626static void damage_surface_iterator(struct sway_output *output,
661 struct wlr_surface *surface, struct wlr_box *_box, float rotation, 627 struct sway_view *view, struct wlr_surface *surface,
662 void *_data) { 628 struct wlr_box *_box, void *_data) {
663 bool *data = _data; 629 bool *data = _data;
664 bool whole = *data; 630 bool whole = *data;
665 631
666 struct wlr_box box = *_box; 632 struct wlr_box box = *_box;
667 scale_box(&box, output->wlr_output->scale); 633 scale_box(&box, output->wlr_output->scale);
668 634
669 int center_x = box.x + box.width/2;
670 int center_y = box.y + box.height/2;
671
672 if (pixman_region32_not_empty(&surface->buffer_damage)) { 635 if (pixman_region32_not_empty(&surface->buffer_damage)) {
673 pixman_region32_t damage; 636 pixman_region32_t damage;
674 pixman_region32_init(&damage); 637 pixman_region32_init(&damage);
@@ -681,14 +644,11 @@ static void damage_surface_iterator(struct sway_output *output, struct sway_view
681 ceil(output->wlr_output->scale) - surface->current.scale); 644 ceil(output->wlr_output->scale) - surface->current.scale);
682 } 645 }
683 pixman_region32_translate(&damage, box.x, box.y); 646 pixman_region32_translate(&damage, box.x, box.y);
684 wlr_region_rotated_bounds(&damage, &damage, rotation,
685 center_x, center_y);
686 wlr_output_damage_add(output->damage, &damage); 647 wlr_output_damage_add(output->damage, &damage);
687 pixman_region32_fini(&damage); 648 pixman_region32_fini(&damage);
688 } 649 }
689 650
690 if (whole) { 651 if (whole) {
691 wlr_box_rotated_bounds(&box, &box, rotation);
692 wlr_output_damage_add_box(output->damage, &box); 652 wlr_output_damage_add_box(output->damage, &box);
693 } 653 }
694 654
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index 8f1e9c52..4ce5654e 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -131,9 +131,9 @@ damage_finish:
131 pixman_region32_fini(&damage); 131 pixman_region32_fini(&damage);
132} 132}
133 133
134static void render_surface_iterator(struct sway_output *output, struct sway_view *view, 134static void render_surface_iterator(struct sway_output *output,
135 struct wlr_surface *surface, struct wlr_box *_box, float rotation, 135 struct sway_view *view, struct wlr_surface *surface,
136 void *_data) { 136 struct wlr_box *_box, void *_data) {
137 struct render_data *data = _data; 137 struct render_data *data = _data;
138 struct wlr_output *wlr_output = output->wlr_output; 138 struct wlr_output *wlr_output = output->wlr_output;
139 pixman_region32_t *output_damage = data->damage; 139 pixman_region32_t *output_damage = data->damage;
@@ -153,7 +153,7 @@ static void render_surface_iterator(struct sway_output *output, struct sway_view
153 float matrix[9]; 153 float matrix[9];
154 enum wl_output_transform transform = 154 enum wl_output_transform transform =
155 wlr_output_transform_invert(surface->current.transform); 155 wlr_output_transform_invert(surface->current.transform);
156 wlr_matrix_project_box(matrix, &proj_box, transform, rotation, 156 wlr_matrix_project_box(matrix, &proj_box, transform, 0.0,
157 wlr_output->transform_matrix); 157 wlr_output->transform_matrix);
158 158
159 struct wlr_box dst_box = *_box; 159 struct wlr_box dst_box = *_box;