diff options
Diffstat (limited to 'sway/desktop/output.c')
-rw-r--r-- | sway/desktop/output.c | 957 |
1 files changed, 89 insertions, 868 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 1e7494b3..a206ac6b 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -56,33 +56,15 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh, | |||
56 | *sy = ry + ph/2 - sh/2; | 56 | *sy = ry + ph/2 - sh/2; |
57 | } | 57 | } |
58 | 58 | ||
59 | /** | 59 | bool output_get_surface_box(struct root_geometry *geo, |
60 | * Contains a surface's root geometry information. For instance, when rendering | ||
61 | * a popup, this will contain the parent view's position and size. | ||
62 | */ | ||
63 | struct root_geometry { | ||
64 | double x, y; | ||
65 | int width, height; | ||
66 | float rotation; | ||
67 | }; | ||
68 | |||
69 | struct render_data { | ||
70 | struct root_geometry root_geo; | ||
71 | struct sway_output *output; | ||
72 | pixman_region32_t *damage; | ||
73 | struct sway_view *view; | ||
74 | float alpha; | ||
75 | }; | ||
76 | |||
77 | static bool get_surface_box(struct root_geometry *geo, | ||
78 | struct sway_output *output, struct wlr_surface *surface, int sx, int sy, | 60 | struct sway_output *output, struct wlr_surface *surface, int sx, int sy, |
79 | struct wlr_box *surface_box) { | 61 | struct wlr_box *surface_box) { |
80 | if (!wlr_surface_has_buffer(surface)) { | 62 | if (!wlr_surface_has_buffer(surface)) { |
81 | return false; | 63 | return false; |
82 | } | 64 | } |
83 | 65 | ||
84 | int sw = surface->current->width; | 66 | int sw = surface->current.width; |
85 | int sh = surface->current->height; | 67 | int sh = surface->current.height; |
86 | 68 | ||
87 | double _sx = sx, _sy = sy; | 69 | double _sx = sx, _sy = sy; |
88 | rotate_child_position(&_sx, &_sy, sw, sh, geo->width, geo->height, | 70 | rotate_child_position(&_sx, &_sy, sw, sh, geo->width, geo->height, |
@@ -110,24 +92,23 @@ static bool get_surface_box(struct root_geometry *geo, | |||
110 | return wlr_box_intersection(&output_box, &rotated_box, &intersection); | 92 | return wlr_box_intersection(&output_box, &rotated_box, &intersection); |
111 | } | 93 | } |
112 | 94 | ||
113 | static void surface_for_each_surface(struct wlr_surface *surface, | 95 | void output_surface_for_each_surface(struct wlr_surface *surface, |
114 | double ox, double oy, struct root_geometry *geo, | 96 | double ox, double oy, struct root_geometry *geo, |
115 | wlr_surface_iterator_func_t iterator, void *user_data) { | 97 | wlr_surface_iterator_func_t iterator, void *user_data) { |
116 | geo->x = ox; | 98 | geo->x = ox; |
117 | geo->y = oy; | 99 | geo->y = oy; |
118 | geo->width = surface->current->width; | 100 | geo->width = surface->current.width; |
119 | geo->height = surface->current->height; | 101 | geo->height = surface->current.height; |
120 | geo->rotation = 0; | 102 | geo->rotation = 0; |
121 | 103 | ||
122 | wlr_surface_for_each_surface(surface, iterator, user_data); | 104 | wlr_surface_for_each_surface(surface, iterator, user_data); |
123 | } | 105 | } |
124 | 106 | ||
125 | static void output_view_for_each_surface(struct sway_view *view, | 107 | void output_view_for_each_surface(struct sway_view *view, |
126 | struct root_geometry *geo, wlr_surface_iterator_func_t iterator, | 108 | struct sway_output *output, struct root_geometry *geo, |
127 | void *user_data) { | 109 | wlr_surface_iterator_func_t iterator, void *user_data) { |
128 | struct render_data *data = user_data; | 110 | geo->x = view->swayc->current.view_x - output->swayc->current.swayc_x; |
129 | geo->x = view->swayc->current.view_x - data->output->swayc->current.swayc_x; | 111 | geo->y = view->swayc->current.view_y - output->swayc->current.swayc_y; |
130 | geo->y = view->swayc->current.view_y - data->output->swayc->current.swayc_y; | ||
131 | geo->width = view->swayc->current.view_width; | 112 | geo->width = view->swayc->current.view_width; |
132 | geo->height = view->swayc->current.view_height; | 113 | geo->height = view->swayc->current.view_height; |
133 | geo->rotation = 0; // TODO | 114 | geo->rotation = 0; // TODO |
@@ -135,20 +116,20 @@ static void output_view_for_each_surface(struct sway_view *view, | |||
135 | view_for_each_surface(view, iterator, user_data); | 116 | view_for_each_surface(view, iterator, user_data); |
136 | } | 117 | } |
137 | 118 | ||
138 | static void layer_for_each_surface(struct wl_list *layer_surfaces, | 119 | void output_layer_for_each_surface(struct wl_list *layer_surfaces, |
139 | struct root_geometry *geo, wlr_surface_iterator_func_t iterator, | 120 | struct root_geometry *geo, wlr_surface_iterator_func_t iterator, |
140 | void *user_data) { | 121 | void *user_data) { |
141 | struct sway_layer_surface *layer_surface; | 122 | struct sway_layer_surface *layer_surface; |
142 | wl_list_for_each(layer_surface, layer_surfaces, link) { | 123 | wl_list_for_each(layer_surface, layer_surfaces, link) { |
143 | struct wlr_layer_surface *wlr_layer_surface = | 124 | struct wlr_layer_surface *wlr_layer_surface = |
144 | layer_surface->layer_surface; | 125 | layer_surface->layer_surface; |
145 | surface_for_each_surface(wlr_layer_surface->surface, | 126 | output_surface_for_each_surface(wlr_layer_surface->surface, |
146 | layer_surface->geo.x, layer_surface->geo.y, geo, iterator, | 127 | layer_surface->geo.x, layer_surface->geo.y, geo, iterator, |
147 | user_data); | 128 | user_data); |
148 | } | 129 | } |
149 | } | 130 | } |
150 | 131 | ||
151 | static void unmanaged_for_each_surface(struct wl_list *unmanaged, | 132 | void output_unmanaged_for_each_surface(struct wl_list *unmanaged, |
152 | struct sway_output *output, struct root_geometry *geo, | 133 | struct sway_output *output, struct root_geometry *geo, |
153 | wlr_surface_iterator_func_t iterator, void *user_data) { | 134 | wlr_surface_iterator_func_t iterator, void *user_data) { |
154 | struct sway_xwayland_unmanaged *unmanaged_surface; | 135 | struct sway_xwayland_unmanaged *unmanaged_surface; |
@@ -158,12 +139,12 @@ static void unmanaged_for_each_surface(struct wl_list *unmanaged, | |||
158 | double ox = unmanaged_surface->lx - output->swayc->current.swayc_x; | 139 | double ox = unmanaged_surface->lx - output->swayc->current.swayc_x; |
159 | double oy = unmanaged_surface->ly - output->swayc->current.swayc_y; | 140 | double oy = unmanaged_surface->ly - output->swayc->current.swayc_y; |
160 | 141 | ||
161 | surface_for_each_surface(xsurface->surface, ox, oy, geo, | 142 | output_surface_for_each_surface(xsurface->surface, ox, oy, geo, |
162 | iterator, user_data); | 143 | iterator, user_data); |
163 | } | 144 | } |
164 | } | 145 | } |
165 | 146 | ||
166 | static void drag_icons_for_each_surface(struct wl_list *drag_icons, | 147 | void output_drag_icons_for_each_surface(struct wl_list *drag_icons, |
167 | struct sway_output *output, struct root_geometry *geo, | 148 | struct sway_output *output, struct root_geometry *geo, |
168 | wlr_surface_iterator_func_t iterator, void *user_data) { | 149 | wlr_surface_iterator_func_t iterator, void *user_data) { |
169 | struct sway_drag_icon *drag_icon; | 150 | struct sway_drag_icon *drag_icon; |
@@ -172,7 +153,7 @@ static void drag_icons_for_each_surface(struct wl_list *drag_icons, | |||
172 | double oy = drag_icon->y - output->swayc->y; | 153 | double oy = drag_icon->y - output->swayc->y; |
173 | 154 | ||
174 | if (drag_icon->wlr_drag_icon->mapped) { | 155 | if (drag_icon->wlr_drag_icon->mapped) { |
175 | surface_for_each_surface(drag_icon->wlr_drag_icon->surface, | 156 | output_surface_for_each_surface(drag_icon->wlr_drag_icon->surface, |
176 | ox, oy, geo, iterator, user_data); | 157 | ox, oy, geo, iterator, user_data); |
177 | } | 158 | } |
178 | } | 159 | } |
@@ -185,722 +166,7 @@ static void scale_box(struct wlr_box *box, float scale) { | |||
185 | box->height *= scale; | 166 | box->height *= scale; |
186 | } | 167 | } |
187 | 168 | ||
188 | static void scissor_output(struct wlr_output *wlr_output, | 169 | struct sway_container *output_get_active_workspace(struct sway_output *output) { |
189 | pixman_box32_t *rect) { | ||
190 | struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); | ||
191 | assert(renderer); | ||
192 | |||
193 | struct wlr_box box = { | ||
194 | .x = rect->x1, | ||
195 | .y = rect->y1, | ||
196 | .width = rect->x2 - rect->x1, | ||
197 | .height = rect->y2 - rect->y1, | ||
198 | }; | ||
199 | |||
200 | int ow, oh; | ||
201 | wlr_output_transformed_resolution(wlr_output, &ow, &oh); | ||
202 | |||
203 | enum wl_output_transform transform = | ||
204 | wlr_output_transform_invert(wlr_output->transform); | ||
205 | wlr_box_transform(&box, transform, ow, oh, &box); | ||
206 | |||
207 | wlr_renderer_scissor(renderer, &box); | ||
208 | } | ||
209 | |||
210 | static void render_texture(struct wlr_output *wlr_output, | ||
211 | pixman_region32_t *output_damage, struct wlr_texture *texture, | ||
212 | const struct wlr_box *box, const float matrix[static 9], float alpha) { | ||
213 | struct wlr_renderer *renderer = | ||
214 | wlr_backend_get_renderer(wlr_output->backend); | ||
215 | |||
216 | pixman_region32_t damage; | ||
217 | pixman_region32_init(&damage); | ||
218 | pixman_region32_union_rect(&damage, &damage, box->x, box->y, | ||
219 | box->width, box->height); | ||
220 | pixman_region32_intersect(&damage, &damage, output_damage); | ||
221 | bool damaged = pixman_region32_not_empty(&damage); | ||
222 | if (!damaged) { | ||
223 | goto damage_finish; | ||
224 | } | ||
225 | |||
226 | int nrects; | ||
227 | pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); | ||
228 | for (int i = 0; i < nrects; ++i) { | ||
229 | scissor_output(wlr_output, &rects[i]); | ||
230 | wlr_render_texture_with_matrix(renderer, texture, matrix, alpha); | ||
231 | } | ||
232 | |||
233 | damage_finish: | ||
234 | pixman_region32_fini(&damage); | ||
235 | } | ||
236 | |||
237 | static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, | ||
238 | void *_data) { | ||
239 | struct render_data *data = _data; | ||
240 | struct wlr_output *wlr_output = data->output->wlr_output; | ||
241 | float rotation = data->root_geo.rotation; | ||
242 | pixman_region32_t *output_damage = data->damage; | ||
243 | float alpha = data->alpha; | ||
244 | |||
245 | struct wlr_texture *texture = wlr_surface_get_texture(surface); | ||
246 | if (!texture) { | ||
247 | return; | ||
248 | } | ||
249 | |||
250 | struct wlr_box box; | ||
251 | bool intersects = get_surface_box(&data->root_geo, data->output, surface, | ||
252 | sx, sy, &box); | ||
253 | if (!intersects) { | ||
254 | return; | ||
255 | } | ||
256 | |||
257 | scale_box(&box, wlr_output->scale); | ||
258 | |||
259 | float matrix[9]; | ||
260 | enum wl_output_transform transform = | ||
261 | wlr_output_transform_invert(surface->current->transform); | ||
262 | wlr_matrix_project_box(matrix, &box, transform, rotation, | ||
263 | wlr_output->transform_matrix); | ||
264 | |||
265 | render_texture(wlr_output, output_damage, texture, &box, matrix, alpha); | ||
266 | } | ||
267 | |||
268 | static void render_layer(struct sway_output *output, | ||
269 | pixman_region32_t *damage, struct wl_list *layer_surfaces) { | ||
270 | struct render_data data = { | ||
271 | .output = output, | ||
272 | .damage = damage, | ||
273 | .alpha = 1.0f, | ||
274 | }; | ||
275 | layer_for_each_surface(layer_surfaces, &data.root_geo, | ||
276 | render_surface_iterator, &data); | ||
277 | } | ||
278 | |||
279 | static void render_unmanaged(struct sway_output *output, | ||
280 | pixman_region32_t *damage, struct wl_list *unmanaged) { | ||
281 | struct render_data data = { | ||
282 | .output = output, | ||
283 | .damage = damage, | ||
284 | .alpha = 1.0f, | ||
285 | }; | ||
286 | unmanaged_for_each_surface(unmanaged, output, &data.root_geo, | ||
287 | render_surface_iterator, &data); | ||
288 | } | ||
289 | |||
290 | static void render_drag_icons(struct sway_output *output, | ||
291 | pixman_region32_t *damage, struct wl_list *drag_icons) { | ||
292 | struct render_data data = { | ||
293 | .output = output, | ||
294 | .damage = damage, | ||
295 | .alpha = 1.0f, | ||
296 | }; | ||
297 | drag_icons_for_each_surface(drag_icons, output, &data.root_geo, | ||
298 | render_surface_iterator, &data); | ||
299 | } | ||
300 | |||
301 | static void render_rect(struct wlr_output *wlr_output, | ||
302 | pixman_region32_t *output_damage, const struct wlr_box *_box, | ||
303 | float color[static 4]) { | ||
304 | struct wlr_renderer *renderer = | ||
305 | wlr_backend_get_renderer(wlr_output->backend); | ||
306 | |||
307 | struct wlr_box box; | ||
308 | memcpy(&box, _box, sizeof(struct wlr_box)); | ||
309 | box.x -= wlr_output->lx * wlr_output->scale; | ||
310 | box.y -= wlr_output->ly * wlr_output->scale; | ||
311 | |||
312 | pixman_region32_t damage; | ||
313 | pixman_region32_init(&damage); | ||
314 | pixman_region32_union_rect(&damage, &damage, box.x, box.y, | ||
315 | box.width, box.height); | ||
316 | pixman_region32_intersect(&damage, &damage, output_damage); | ||
317 | bool damaged = pixman_region32_not_empty(&damage); | ||
318 | if (!damaged) { | ||
319 | goto damage_finish; | ||
320 | } | ||
321 | |||
322 | int nrects; | ||
323 | pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects); | ||
324 | for (int i = 0; i < nrects; ++i) { | ||
325 | scissor_output(wlr_output, &rects[i]); | ||
326 | wlr_render_rect(renderer, &box, color, | ||
327 | wlr_output->transform_matrix); | ||
328 | } | ||
329 | |||
330 | damage_finish: | ||
331 | pixman_region32_fini(&damage); | ||
332 | } | ||
333 | |||
334 | static void premultiply_alpha(float color[4], float opacity) { | ||
335 | color[3] *= opacity; | ||
336 | color[0] *= color[3]; | ||
337 | color[1] *= color[3]; | ||
338 | color[2] *= color[3]; | ||
339 | } | ||
340 | |||
341 | static void render_view_surfaces(struct sway_view *view, | ||
342 | struct sway_output *output, pixman_region32_t *damage, float alpha) { | ||
343 | struct render_data data = { | ||
344 | .output = output, | ||
345 | .damage = damage, | ||
346 | .view = view, | ||
347 | .alpha = alpha, | ||
348 | }; | ||
349 | output_view_for_each_surface( | ||
350 | view, &data.root_geo, render_surface_iterator, &data); | ||
351 | } | ||
352 | |||
353 | static void render_saved_view(struct sway_view *view, | ||
354 | struct sway_output *output, pixman_region32_t *damage, float alpha) { | ||
355 | struct wlr_output *wlr_output = output->wlr_output; | ||
356 | |||
357 | int width, height; | ||
358 | struct wlr_texture *texture = | ||
359 | transaction_get_saved_texture(view, &width, &height); | ||
360 | if (!texture) { | ||
361 | return; | ||
362 | } | ||
363 | struct wlr_box box = { | ||
364 | .x = view->swayc->current.view_x - output->swayc->current.swayc_x, | ||
365 | .y = view->swayc->current.view_y - output->swayc->current.swayc_y, | ||
366 | .width = width, | ||
367 | .height = height, | ||
368 | }; | ||
369 | |||
370 | struct wlr_box output_box = { | ||
371 | .width = output->swayc->current.swayc_width, | ||
372 | .height = output->swayc->current.swayc_height, | ||
373 | }; | ||
374 | |||
375 | struct wlr_box intersection; | ||
376 | bool intersects = wlr_box_intersection(&output_box, &box, &intersection); | ||
377 | if (!intersects) { | ||
378 | return; | ||
379 | } | ||
380 | |||
381 | scale_box(&box, wlr_output->scale); | ||
382 | |||
383 | float matrix[9]; | ||
384 | wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, | ||
385 | wlr_output->transform_matrix); | ||
386 | |||
387 | render_texture(wlr_output, damage, texture, &box, matrix, alpha); | ||
388 | } | ||
389 | |||
390 | /** | ||
391 | * Render a view's surface and left/bottom/right borders. | ||
392 | */ | ||
393 | static void render_view(struct sway_output *output, pixman_region32_t *damage, | ||
394 | struct sway_container *con, struct border_colors *colors) { | ||
395 | struct sway_view *view = con->sway_view; | ||
396 | if (view->swayc->instructions->length) { | ||
397 | render_saved_view(view, output, damage, view->swayc->alpha); | ||
398 | } else { | ||
399 | render_view_surfaces(view, output, damage, view->swayc->alpha); | ||
400 | } | ||
401 | |||
402 | struct wlr_box box; | ||
403 | float output_scale = output->wlr_output->scale; | ||
404 | float color[4]; | ||
405 | struct sway_container_state *state = &con->current; | ||
406 | |||
407 | if (state->border != B_NONE) { | ||
408 | if (state->border_left) { | ||
409 | memcpy(&color, colors->child_border, sizeof(float) * 4); | ||
410 | premultiply_alpha(color, con->alpha); | ||
411 | box.x = state->swayc_x; | ||
412 | box.y = state->view_y; | ||
413 | box.width = state->border_thickness; | ||
414 | box.height = state->view_height; | ||
415 | scale_box(&box, output_scale); | ||
416 | render_rect(output->wlr_output, damage, &box, color); | ||
417 | } | ||
418 | |||
419 | if (state->border_right) { | ||
420 | if (state->parent->current.children->length == 1 | ||
421 | && state->parent->current.layout == L_HORIZ) { | ||
422 | memcpy(&color, colors->indicator, sizeof(float) * 4); | ||
423 | } else { | ||
424 | memcpy(&color, colors->child_border, sizeof(float) * 4); | ||
425 | } | ||
426 | premultiply_alpha(color, con->alpha); | ||
427 | box.x = state->view_x + state->view_width; | ||
428 | box.y = state->view_y; | ||
429 | box.width = state->border_thickness; | ||
430 | box.height = state->view_height; | ||
431 | scale_box(&box, output_scale); | ||
432 | render_rect(output->wlr_output, damage, &box, color); | ||
433 | } | ||
434 | |||
435 | if (state->border_bottom) { | ||
436 | if (state->parent->current.children->length == 1 | ||
437 | && con->current.parent->current.layout == L_VERT) { | ||
438 | memcpy(&color, colors->indicator, sizeof(float) * 4); | ||
439 | } else { | ||
440 | memcpy(&color, colors->child_border, sizeof(float) * 4); | ||
441 | } | ||
442 | premultiply_alpha(color, con->alpha); | ||
443 | box.x = state->swayc_x; | ||
444 | box.y = state->view_y + state->view_height; | ||
445 | box.width = state->swayc_width; | ||
446 | box.height = state->border_thickness; | ||
447 | scale_box(&box, output_scale); | ||
448 | render_rect(output->wlr_output, damage, &box, color); | ||
449 | } | ||
450 | } | ||
451 | } | ||
452 | |||
453 | /** | ||
454 | * Render a titlebar. | ||
455 | * | ||
456 | * Care must be taken not to render over the same pixel multiple times, | ||
457 | * otherwise the colors will be incorrect when using opacity. | ||
458 | * | ||
459 | * The height is: 1px border, 3px padding, font height, 3px padding, 1px border | ||
460 | * The left side for L_TABBED is: 1px border, 2px padding, title | ||
461 | * The left side for other layouts is: 3px padding, title | ||
462 | */ | ||
463 | static void render_titlebar(struct sway_output *output, | ||
464 | pixman_region32_t *output_damage, struct sway_container *con, | ||
465 | int x, int y, int width, | ||
466 | struct border_colors *colors, struct wlr_texture *title_texture, | ||
467 | struct wlr_texture *marks_texture) { | ||
468 | struct wlr_box box; | ||
469 | float color[4]; | ||
470 | struct sway_container_state *state = &con->current; | ||
471 | float output_scale = output->wlr_output->scale; | ||
472 | enum sway_container_layout layout = state->parent->current.layout; | ||
473 | list_t *children = state->parent->current.children; | ||
474 | bool is_last_child = children->items[children->length - 1] == con; | ||
475 | double output_x = output->swayc->current.swayc_x; | ||
476 | double output_y = output->swayc->current.swayc_y; | ||
477 | |||
478 | // Single pixel bar above title | ||
479 | memcpy(&color, colors->border, sizeof(float) * 4); | ||
480 | premultiply_alpha(color, con->alpha); | ||
481 | box.x = x; | ||
482 | box.y = y; | ||
483 | box.width = width; | ||
484 | box.height = TITLEBAR_BORDER_THICKNESS; | ||
485 | scale_box(&box, output_scale); | ||
486 | render_rect(output->wlr_output, output_damage, &box, color); | ||
487 | |||
488 | // Single pixel bar below title | ||
489 | size_t left_offset = 0, right_offset = 0; | ||
490 | bool connects_sides = false; | ||
491 | if (layout == L_HORIZ || layout == L_VERT || | ||
492 | (layout == L_STACKED && is_last_child)) { | ||
493 | if (con->type == C_VIEW) { | ||
494 | left_offset = state->border_left * state->border_thickness; | ||
495 | right_offset = state->border_right * state->border_thickness; | ||
496 | connects_sides = true; | ||
497 | } | ||
498 | } | ||
499 | box.x = x + left_offset; | ||
500 | box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; | ||
501 | box.width = width - left_offset - right_offset; | ||
502 | box.height = TITLEBAR_BORDER_THICKNESS; | ||
503 | scale_box(&box, output_scale); | ||
504 | render_rect(output->wlr_output, output_damage, &box, color); | ||
505 | |||
506 | if (layout == L_TABBED) { | ||
507 | // Single pixel left edge | ||
508 | box.x = x; | ||
509 | box.y = y + TITLEBAR_BORDER_THICKNESS; | ||
510 | box.width = TITLEBAR_BORDER_THICKNESS; | ||
511 | box.height = | ||
512 | container_titlebar_height() - TITLEBAR_BORDER_THICKNESS * 2; | ||
513 | scale_box(&box, output_scale); | ||
514 | render_rect(output->wlr_output, output_damage, &box, color); | ||
515 | |||
516 | // Single pixel right edge | ||
517 | box.x = (x + width - TITLEBAR_BORDER_THICKNESS) * output_scale; | ||
518 | render_rect(output->wlr_output, output_damage, &box, color); | ||
519 | } | ||
520 | |||
521 | size_t inner_width = width - TITLEBAR_H_PADDING * 2; | ||
522 | |||
523 | // Marks | ||
524 | size_t marks_width = 0; | ||
525 | if (config->show_marks && marks_texture) { | ||
526 | struct wlr_box texture_box; | ||
527 | wlr_texture_get_size(marks_texture, | ||
528 | &texture_box.width, &texture_box.height); | ||
529 | texture_box.x = (x - output_x + width - TITLEBAR_H_PADDING) | ||
530 | * output_scale - texture_box.width; | ||
531 | texture_box.y = (y - output_y + TITLEBAR_V_PADDING) * output_scale; | ||
532 | |||
533 | float matrix[9]; | ||
534 | wlr_matrix_project_box(matrix, &texture_box, | ||
535 | WL_OUTPUT_TRANSFORM_NORMAL, | ||
536 | 0.0, output->wlr_output->transform_matrix); | ||
537 | |||
538 | if (inner_width * output_scale < texture_box.width) { | ||
539 | texture_box.width = inner_width * output_scale; | ||
540 | } | ||
541 | render_texture(output->wlr_output, output_damage, marks_texture, | ||
542 | &texture_box, matrix, con->alpha); | ||
543 | marks_width = texture_box.width; | ||
544 | } | ||
545 | |||
546 | // Title text | ||
547 | size_t title_width = 0; | ||
548 | if (title_texture) { | ||
549 | struct wlr_box texture_box; | ||
550 | wlr_texture_get_size(title_texture, | ||
551 | &texture_box.width, &texture_box.height); | ||
552 | texture_box.x = (x - output_x + TITLEBAR_H_PADDING) * output_scale; | ||
553 | texture_box.y = (y - output_y + TITLEBAR_V_PADDING) * output_scale; | ||
554 | |||
555 | float matrix[9]; | ||
556 | wlr_matrix_project_box(matrix, &texture_box, | ||
557 | WL_OUTPUT_TRANSFORM_NORMAL, | ||
558 | 0.0, output->wlr_output->transform_matrix); | ||
559 | |||
560 | if (inner_width * output_scale - marks_width < texture_box.width) { | ||
561 | texture_box.width = inner_width * output_scale - marks_width; | ||
562 | } | ||
563 | render_texture(output->wlr_output, output_damage, title_texture, | ||
564 | &texture_box, matrix, con->alpha); | ||
565 | title_width = texture_box.width; | ||
566 | } | ||
567 | |||
568 | // Padding above title | ||
569 | memcpy(&color, colors->background, sizeof(float) * 4); | ||
570 | premultiply_alpha(color, con->alpha); | ||
571 | box.x = x + (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; | ||
572 | box.y = y + TITLEBAR_BORDER_THICKNESS; | ||
573 | box.width = width - (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS * 2; | ||
574 | box.height = TITLEBAR_V_PADDING - TITLEBAR_BORDER_THICKNESS; | ||
575 | scale_box(&box, output_scale); | ||
576 | render_rect(output->wlr_output, output_damage, &box, color); | ||
577 | |||
578 | // Padding below title | ||
579 | box.y = (y + TITLEBAR_V_PADDING + config->font_height) * output_scale; | ||
580 | render_rect(output->wlr_output, output_damage, &box, color); | ||
581 | |||
582 | // Filler between title and marks | ||
583 | box.width = inner_width * output_scale - title_width - marks_width; | ||
584 | if (box.width > 0) { | ||
585 | box.x = (x + TITLEBAR_H_PADDING) * output_scale + title_width; | ||
586 | box.y = (y + TITLEBAR_V_PADDING) * output_scale; | ||
587 | box.height = config->font_height * output_scale; | ||
588 | render_rect(output->wlr_output, output_damage, &box, color); | ||
589 | } | ||
590 | |||
591 | // Padding left of title | ||
592 | left_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; | ||
593 | box.x = x + left_offset; | ||
594 | box.y = y + TITLEBAR_V_PADDING; | ||
595 | box.width = TITLEBAR_H_PADDING - left_offset; | ||
596 | box.height = config->font_height; | ||
597 | scale_box(&box, output_scale); | ||
598 | render_rect(output->wlr_output, output_damage, &box, color); | ||
599 | |||
600 | // Padding right of marks | ||
601 | right_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; | ||
602 | box.x = x + width - TITLEBAR_H_PADDING; | ||
603 | box.y = y + TITLEBAR_V_PADDING; | ||
604 | box.width = TITLEBAR_H_PADDING - right_offset; | ||
605 | box.height = config->font_height; | ||
606 | scale_box(&box, output_scale); | ||
607 | render_rect(output->wlr_output, output_damage, &box, color); | ||
608 | |||
609 | if (connects_sides) { | ||
610 | // Left pixel in line with bottom bar | ||
611 | box.x = x; | ||
612 | box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; | ||
613 | box.width = state->border_thickness * state->border_left; | ||
614 | box.height = TITLEBAR_BORDER_THICKNESS; | ||
615 | scale_box(&box, output_scale); | ||
616 | render_rect(output->wlr_output, output_damage, &box, color); | ||
617 | |||
618 | // Right pixel in line with bottom bar | ||
619 | box.x = x + width - state->border_thickness * state->border_right; | ||
620 | box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; | ||
621 | box.width = state->border_thickness * state->border_right; | ||
622 | box.height = TITLEBAR_BORDER_THICKNESS; | ||
623 | scale_box(&box, output_scale); | ||
624 | render_rect(output->wlr_output, output_damage, &box, color); | ||
625 | } | ||
626 | } | ||
627 | |||
628 | /** | ||
629 | * Render the top border line for a view using "border pixel". | ||
630 | */ | ||
631 | static void render_top_border(struct sway_output *output, | ||
632 | pixman_region32_t *output_damage, struct sway_container *con, | ||
633 | struct border_colors *colors) { | ||
634 | struct sway_container_state *state = &con->current; | ||
635 | if (!state->border_top) { | ||
636 | return; | ||
637 | } | ||
638 | struct wlr_box box; | ||
639 | float color[4]; | ||
640 | float output_scale = output->wlr_output->scale; | ||
641 | |||
642 | // Child border - top edge | ||
643 | memcpy(&color, colors->child_border, sizeof(float) * 4); | ||
644 | premultiply_alpha(color, con->alpha); | ||
645 | box.x = state->swayc_x; | ||
646 | box.y = state->swayc_y; | ||
647 | box.width = state->swayc_width; | ||
648 | box.height = state->border_thickness; | ||
649 | scale_box(&box, output_scale); | ||
650 | render_rect(output->wlr_output, output_damage, &box, color); | ||
651 | } | ||
652 | |||
653 | static void render_container(struct sway_output *output, | ||
654 | pixman_region32_t *damage, struct sway_container *con, bool parent_focused); | ||
655 | |||
656 | /** | ||
657 | * Render a container's children using a L_HORIZ or L_VERT layout. | ||
658 | * | ||
659 | * Wrap child views in borders and leave child containers borderless because | ||
660 | * they'll apply their own borders to their children. | ||
661 | */ | ||
662 | static void render_container_simple(struct sway_output *output, | ||
663 | pixman_region32_t *damage, struct sway_container *con, | ||
664 | bool parent_focused) { | ||
665 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
666 | struct sway_container *focus = seat_get_focus(seat); | ||
667 | |||
668 | for (int i = 0; i < con->current.children->length; ++i) { | ||
669 | struct sway_container *child = con->current.children->items[i]; | ||
670 | |||
671 | if (child->type == C_VIEW) { | ||
672 | struct sway_view *view = child->sway_view; | ||
673 | struct border_colors *colors; | ||
674 | struct wlr_texture *title_texture; | ||
675 | struct wlr_texture *marks_texture; | ||
676 | struct sway_container_state *state = &child->current; | ||
677 | |||
678 | if (focus == child || parent_focused) { | ||
679 | colors = &config->border_colors.focused; | ||
680 | title_texture = child->title_focused; | ||
681 | marks_texture = view->marks_focused; | ||
682 | } else if (seat_get_focus_inactive(seat, con) == child) { | ||
683 | colors = &config->border_colors.focused_inactive; | ||
684 | title_texture = child->title_focused_inactive; | ||
685 | marks_texture = view->marks_focused_inactive; | ||
686 | } else { | ||
687 | colors = &config->border_colors.unfocused; | ||
688 | title_texture = child->title_unfocused; | ||
689 | marks_texture = view->marks_unfocused; | ||
690 | } | ||
691 | |||
692 | if (state->border == B_NORMAL) { | ||
693 | render_titlebar(output, damage, child, state->swayc_x, | ||
694 | state->swayc_y, state->swayc_width, colors, | ||
695 | title_texture, marks_texture); | ||
696 | } else { | ||
697 | render_top_border(output, damage, child, colors); | ||
698 | } | ||
699 | render_view(output, damage, child, colors); | ||
700 | } else { | ||
701 | render_container(output, damage, child, | ||
702 | parent_focused || focus == child); | ||
703 | } | ||
704 | } | ||
705 | } | ||
706 | |||
707 | /** | ||
708 | * Render a container's children using the L_TABBED layout. | ||
709 | */ | ||
710 | static void render_container_tabbed(struct sway_output *output, | ||
711 | pixman_region32_t *damage, struct sway_container *con, | ||
712 | bool parent_focused) { | ||
713 | if (!con->current.children->length) { | ||
714 | return; | ||
715 | } | ||
716 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
717 | struct sway_container *focus = seat_get_focus(seat); | ||
718 | struct sway_container *current = seat_get_active_current_child(seat, con); | ||
719 | struct border_colors *current_colors = &config->border_colors.unfocused; | ||
720 | struct sway_container_state *pstate = &con->current; | ||
721 | |||
722 | // Render tabs | ||
723 | for (int i = 0; i < con->current.children->length; ++i) { | ||
724 | struct sway_container *child = con->current.children->items[i]; | ||
725 | struct sway_view *view = child->type == C_VIEW ? child->sway_view : NULL; | ||
726 | struct sway_container_state *cstate = &child->current; | ||
727 | struct border_colors *colors; | ||
728 | struct wlr_texture *title_texture; | ||
729 | struct wlr_texture *marks_texture; | ||
730 | |||
731 | if (focus == child || parent_focused) { | ||
732 | colors = &config->border_colors.focused; | ||
733 | title_texture = child->title_focused; | ||
734 | marks_texture = view ? view->marks_focused : NULL; | ||
735 | } else if (child == current) { | ||
736 | colors = &config->border_colors.focused_inactive; | ||
737 | title_texture = child->title_focused_inactive; | ||
738 | marks_texture = view ? view->marks_focused_inactive : NULL; | ||
739 | } else { | ||
740 | colors = &config->border_colors.unfocused; | ||
741 | title_texture = child->title_unfocused; | ||
742 | marks_texture = view ? view->marks_unfocused : NULL; | ||
743 | } | ||
744 | |||
745 | int tab_width = pstate->swayc_width / pstate->children->length; | ||
746 | int x = pstate->swayc_x + tab_width * i; | ||
747 | // Make last tab use the remaining width of the parent | ||
748 | if (i == pstate->children->length - 1) { | ||
749 | tab_width = pstate->swayc_width - tab_width * i; | ||
750 | } | ||
751 | |||
752 | render_titlebar(output, damage, child, x, cstate->swayc_y, tab_width, | ||
753 | colors, title_texture, marks_texture); | ||
754 | |||
755 | if (child == current) { | ||
756 | current_colors = colors; | ||
757 | } | ||
758 | } | ||
759 | |||
760 | // Render surface and left/right/bottom borders | ||
761 | if (current) { | ||
762 | if (current->type == C_VIEW) { | ||
763 | render_view(output, damage, current, current_colors); | ||
764 | } else { | ||
765 | render_container(output, damage, current, | ||
766 | parent_focused || current == focus); | ||
767 | } | ||
768 | } | ||
769 | } | ||
770 | |||
771 | /** | ||
772 | * Render a container's children using the L_STACKED layout. | ||
773 | */ | ||
774 | static void render_container_stacked(struct sway_output *output, | ||
775 | pixman_region32_t *damage, struct sway_container *con, | ||
776 | bool parent_focused) { | ||
777 | if (!con->current.children->length) { | ||
778 | return; | ||
779 | } | ||
780 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
781 | struct sway_container *focus = seat_get_focus(seat); | ||
782 | struct sway_container *current = seat_get_active_current_child(seat, con); | ||
783 | struct border_colors *current_colors = &config->border_colors.unfocused; | ||
784 | struct sway_container_state *pstate = &con->current; | ||
785 | |||
786 | // Render titles | ||
787 | for (int i = 0; i < con->current.children->length; ++i) { | ||
788 | struct sway_container *child = con->current.children->items[i]; | ||
789 | struct sway_view *view = child->type == C_VIEW ? child->sway_view : NULL; | ||
790 | struct sway_container_state *cstate = &child->current; | ||
791 | struct border_colors *colors; | ||
792 | struct wlr_texture *title_texture; | ||
793 | struct wlr_texture *marks_texture; | ||
794 | |||
795 | if (focus == child || parent_focused) { | ||
796 | colors = &config->border_colors.focused; | ||
797 | title_texture = child->title_focused; | ||
798 | marks_texture = view ? view->marks_focused : NULL; | ||
799 | } else if (child == current) { | ||
800 | colors = &config->border_colors.focused_inactive; | ||
801 | title_texture = child->title_focused_inactive; | ||
802 | marks_texture = view ? view->marks_focused_inactive : NULL; | ||
803 | } else { | ||
804 | colors = &config->border_colors.unfocused; | ||
805 | title_texture = child->title_unfocused; | ||
806 | marks_texture = view ? view->marks_unfocused : NULL; | ||
807 | } | ||
808 | |||
809 | int y = pstate->swayc_y + container_titlebar_height() * i; | ||
810 | render_titlebar(output, damage, child, cstate->swayc_x, y, | ||
811 | cstate->swayc_width, colors, title_texture, marks_texture); | ||
812 | |||
813 | if (child == current) { | ||
814 | current_colors = colors; | ||
815 | } | ||
816 | } | ||
817 | |||
818 | // Render surface and left/right/bottom borders | ||
819 | if (current) { | ||
820 | if (current->type == C_VIEW) { | ||
821 | render_view(output, damage, current, current_colors); | ||
822 | } else { | ||
823 | render_container(output, damage, current, | ||
824 | parent_focused || current == focus); | ||
825 | } | ||
826 | } | ||
827 | } | ||
828 | |||
829 | static void render_container(struct sway_output *output, | ||
830 | pixman_region32_t *damage, struct sway_container *con, | ||
831 | bool parent_focused) { | ||
832 | switch (con->current.layout) { | ||
833 | case L_NONE: | ||
834 | case L_HORIZ: | ||
835 | case L_VERT: | ||
836 | render_container_simple(output, damage, con, parent_focused); | ||
837 | break; | ||
838 | case L_STACKED: | ||
839 | render_container_stacked(output, damage, con, parent_focused); | ||
840 | break; | ||
841 | case L_TABBED: | ||
842 | render_container_tabbed(output, damage, con, parent_focused); | ||
843 | break; | ||
844 | case L_FLOATING: | ||
845 | sway_assert(false, "Didn't expect to see floating here"); | ||
846 | } | ||
847 | } | ||
848 | |||
849 | static void render_floating_container(struct sway_output *soutput, | ||
850 | pixman_region32_t *damage, struct sway_container *con) { | ||
851 | if (con->type == C_VIEW) { | ||
852 | struct sway_view *view = con->sway_view; | ||
853 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
854 | struct sway_container *focus = seat_get_focus(seat); | ||
855 | struct border_colors *colors; | ||
856 | struct wlr_texture *title_texture; | ||
857 | struct wlr_texture *marks_texture; | ||
858 | |||
859 | if (focus == con) { | ||
860 | colors = &config->border_colors.focused; | ||
861 | title_texture = con->title_focused; | ||
862 | marks_texture = view->marks_focused; | ||
863 | } else { | ||
864 | colors = &config->border_colors.unfocused; | ||
865 | title_texture = con->title_unfocused; | ||
866 | marks_texture = view->marks_unfocused; | ||
867 | } | ||
868 | |||
869 | if (con->current.border == B_NORMAL) { | ||
870 | render_titlebar(soutput, damage, con, con->current.swayc_x, | ||
871 | con->current.swayc_y, con->current.swayc_width, colors, | ||
872 | title_texture, marks_texture); | ||
873 | } else if (con->current.border != B_NONE) { | ||
874 | render_top_border(soutput, damage, con, colors); | ||
875 | } | ||
876 | render_view(soutput, damage, con, colors); | ||
877 | } else { | ||
878 | render_container(soutput, damage, con, false); | ||
879 | } | ||
880 | } | ||
881 | |||
882 | static void render_floating(struct sway_output *soutput, | ||
883 | pixman_region32_t *damage) { | ||
884 | for (int i = 0; i < root_container.current.children->length; ++i) { | ||
885 | struct sway_container *output = | ||
886 | root_container.current.children->items[i]; | ||
887 | for (int j = 0; j < output->current.children->length; ++j) { | ||
888 | struct sway_container *ws = output->current.children->items[j]; | ||
889 | if (!workspace_is_visible(ws)) { | ||
890 | continue; | ||
891 | } | ||
892 | list_t *floating = | ||
893 | ws->current.ws_floating->current.children; | ||
894 | for (int k = 0; k < floating->length; ++k) { | ||
895 | struct sway_container *floater = floating->items[k]; | ||
896 | render_floating_container(soutput, damage, floater); | ||
897 | } | ||
898 | } | ||
899 | } | ||
900 | } | ||
901 | |||
902 | static struct sway_container *output_get_active_workspace( | ||
903 | struct sway_output *output) { | ||
904 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 170 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
905 | struct sway_container *focus = | 171 | struct sway_container *focus = |
906 | seat_get_focus_inactive(seat, output->swayc); | 172 | seat_get_focus_inactive(seat, output->swayc); |
@@ -915,117 +181,58 @@ static struct sway_container *output_get_active_workspace( | |||
915 | return workspace; | 181 | return workspace; |
916 | } | 182 | } |
917 | 183 | ||
918 | static void render_output(struct sway_output *output, struct timespec *when, | 184 | bool output_has_opaque_lockscreen(struct sway_output *output, |
919 | pixman_region32_t *damage) { | 185 | struct sway_seat *seat) { |
920 | struct wlr_output *wlr_output = output->wlr_output; | 186 | if (!seat->exclusive_client) { |
921 | 187 | return false; | |
922 | struct wlr_renderer *renderer = | ||
923 | wlr_backend_get_renderer(wlr_output->backend); | ||
924 | if (!sway_assert(renderer != NULL, | ||
925 | "expected the output backend to have a renderer")) { | ||
926 | return; | ||
927 | } | ||
928 | |||
929 | wlr_renderer_begin(renderer, wlr_output->width, wlr_output->height); | ||
930 | |||
931 | bool damage_whole_before_swap = false; | ||
932 | if (!pixman_region32_not_empty(damage)) { | ||
933 | // Output isn't damaged but needs buffer swap | ||
934 | goto renderer_end; | ||
935 | } | ||
936 | |||
937 | const char *damage_debug = getenv("SWAY_DAMAGE_DEBUG"); | ||
938 | if (damage_debug != NULL) { | ||
939 | if (strcmp(damage_debug, "highlight") == 0) { | ||
940 | wlr_renderer_clear(renderer, (float[]){1, 1, 0, 1}); | ||
941 | damage_whole_before_swap = true; | ||
942 | } else if (strcmp(damage_debug, "rerender") == 0) { | ||
943 | int width, height; | ||
944 | wlr_output_transformed_resolution(wlr_output, &width, &height); | ||
945 | pixman_region32_union_rect(damage, damage, 0, 0, width, height); | ||
946 | } | ||
947 | } | 188 | } |
948 | 189 | ||
949 | struct sway_container *workspace = output_get_active_workspace(output); | 190 | struct wlr_layer_surface *wlr_layer_surface; |
950 | struct sway_view *fullscreen_view = workspace->current.ws_fullscreen; | 191 | wl_list_for_each(wlr_layer_surface, &server.layer_shell->surfaces, link) { |
951 | 192 | if (wlr_layer_surface->output != output->wlr_output) { | |
952 | if (fullscreen_view) { | 193 | continue; |
953 | float clear_color[] = {0.0f, 0.0f, 0.0f, 1.0f}; | ||
954 | |||
955 | int nrects; | ||
956 | pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); | ||
957 | for (int i = 0; i < nrects; ++i) { | ||
958 | scissor_output(wlr_output, &rects[i]); | ||
959 | wlr_renderer_clear(renderer, clear_color); | ||
960 | } | 194 | } |
961 | 195 | struct wlr_surface *wlr_surface = wlr_layer_surface->surface; | |
962 | // TODO: handle views smaller than the output | 196 | if (wlr_surface->resource->client != seat->exclusive_client) { |
963 | render_view_surfaces(fullscreen_view, output, damage, 1.0f); | 197 | continue; |
964 | |||
965 | if (fullscreen_view->type == SWAY_VIEW_XWAYLAND) { | ||
966 | render_unmanaged(output, damage, | ||
967 | &root_container.sway_root->xwayland_unmanaged); | ||
968 | } | 198 | } |
969 | } else { | 199 | struct sway_layer_surface *sway_layer_surface = |
970 | float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; | 200 | layer_from_wlr_layer_surface(wlr_layer_surface); |
971 | 201 | pixman_box32_t output_box = { | |
972 | int nrects; | 202 | .x2 = output->swayc->current.swayc_width, |
973 | pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); | 203 | .y2 = output->swayc->current.swayc_height, |
974 | for (int i = 0; i < nrects; ++i) { | 204 | }; |
975 | scissor_output(wlr_output, &rects[i]); | 205 | pixman_region32_t surface_opaque_box; |
976 | wlr_renderer_clear(renderer, clear_color); | 206 | pixman_region32_init(&surface_opaque_box); |
207 | pixman_region32_copy(&surface_opaque_box, &wlr_surface->opaque_region); | ||
208 | pixman_region32_translate(&surface_opaque_box, | ||
209 | sway_layer_surface->geo.x, sway_layer_surface->geo.y); | ||
210 | bool contains = pixman_region32_contains_rectangle(&surface_opaque_box, | ||
211 | &output_box); | ||
212 | pixman_region32_fini(&surface_opaque_box); | ||
213 | if (contains) { | ||
214 | return true; | ||
977 | } | 215 | } |
978 | |||
979 | render_layer(output, damage, | ||
980 | &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]); | ||
981 | render_layer(output, damage, | ||
982 | &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); | ||
983 | |||
984 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
985 | struct sway_container *focus = seat_get_focus(seat); | ||
986 | render_container(output, damage, workspace, focus == workspace); | ||
987 | render_floating(output, damage); | ||
988 | |||
989 | render_unmanaged(output, damage, | ||
990 | &root_container.sway_root->xwayland_unmanaged); | ||
991 | render_layer(output, damage, | ||
992 | &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); | ||
993 | } | ||
994 | render_layer(output, damage, | ||
995 | &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); | ||
996 | render_drag_icons(output, damage, &root_container.sway_root->drag_icons); | ||
997 | |||
998 | renderer_end: | ||
999 | if (root_container.sway_root->debug_tree) { | ||
1000 | wlr_render_texture(renderer, root_container.sway_root->debug_tree, | ||
1001 | wlr_output->transform_matrix, 0, 0, 1); | ||
1002 | } | ||
1003 | |||
1004 | if (damage_whole_before_swap || root_container.sway_root->debug_tree) { | ||
1005 | int width, height; | ||
1006 | wlr_output_transformed_resolution(wlr_output, &width, &height); | ||
1007 | pixman_region32_union_rect(damage, damage, 0, 0, width, height); | ||
1008 | } | 216 | } |
1009 | 217 | return false; | |
1010 | wlr_renderer_scissor(renderer, NULL); | ||
1011 | wlr_renderer_end(renderer); | ||
1012 | if (!wlr_output_damage_swap_buffers(output->damage, when, damage)) { | ||
1013 | return; | ||
1014 | } | ||
1015 | output->last_frame = *when; | ||
1016 | } | 218 | } |
1017 | 219 | ||
1018 | struct send_frame_done_data { | 220 | struct send_frame_done_data { |
1019 | struct root_geometry root_geo; | 221 | struct root_geometry root_geo; |
1020 | struct sway_output *output; | 222 | struct sway_output *output; |
1021 | struct timespec *when; | 223 | struct timespec *when; |
224 | struct wl_client *exclusive_client; | ||
1022 | }; | 225 | }; |
1023 | 226 | ||
1024 | static void send_frame_done_iterator(struct wlr_surface *surface, | 227 | static void send_frame_done_iterator(struct wlr_surface *surface, |
1025 | int sx, int sy, void *_data) { | 228 | int sx, int sy, void *_data) { |
1026 | struct send_frame_done_data *data = _data; | 229 | struct send_frame_done_data *data = _data; |
230 | if (data->exclusive_client && | ||
231 | data->exclusive_client != surface->resource->client) { | ||
232 | return; | ||
233 | } | ||
1027 | 234 | ||
1028 | bool intersects = get_surface_box(&data->root_geo, data->output, surface, | 235 | bool intersects = output_get_surface_box(&data->root_geo, data->output, surface, |
1029 | sx, sy, NULL); | 236 | sx, sy, NULL); |
1030 | if (intersects) { | 237 | if (intersects) { |
1031 | wlr_surface_send_frame_done(surface, data->when); | 238 | wlr_surface_send_frame_done(surface, data->when); |
@@ -1034,19 +241,19 @@ static void send_frame_done_iterator(struct wlr_surface *surface, | |||
1034 | 241 | ||
1035 | static void send_frame_done_layer(struct send_frame_done_data *data, | 242 | static void send_frame_done_layer(struct send_frame_done_data *data, |
1036 | struct wl_list *layer_surfaces) { | 243 | struct wl_list *layer_surfaces) { |
1037 | layer_for_each_surface(layer_surfaces, &data->root_geo, | 244 | output_layer_for_each_surface(layer_surfaces, &data->root_geo, |
1038 | send_frame_done_iterator, data); | 245 | send_frame_done_iterator, data); |
1039 | } | 246 | } |
1040 | 247 | ||
1041 | static void send_frame_done_unmanaged(struct send_frame_done_data *data, | 248 | static void send_frame_done_unmanaged(struct send_frame_done_data *data, |
1042 | struct wl_list *unmanaged) { | 249 | struct wl_list *unmanaged) { |
1043 | unmanaged_for_each_surface(unmanaged, data->output, &data->root_geo, | 250 | output_unmanaged_for_each_surface(unmanaged, data->output, &data->root_geo, |
1044 | send_frame_done_iterator, data); | 251 | send_frame_done_iterator, data); |
1045 | } | 252 | } |
1046 | 253 | ||
1047 | static void send_frame_done_drag_icons(struct send_frame_done_data *data, | 254 | static void send_frame_done_drag_icons(struct send_frame_done_data *data, |
1048 | struct wl_list *drag_icons) { | 255 | struct wl_list *drag_icons) { |
1049 | drag_icons_for_each_surface(drag_icons, data->output, &data->root_geo, | 256 | output_drag_icons_for_each_surface(drag_icons, data->output, &data->root_geo, |
1050 | send_frame_done_iterator, data); | 257 | send_frame_done_iterator, data); |
1051 | } | 258 | } |
1052 | 259 | ||
@@ -1061,7 +268,7 @@ static void send_frame_done_container_iterator(struct sway_container *con, | |||
1061 | return; | 268 | return; |
1062 | } | 269 | } |
1063 | 270 | ||
1064 | output_view_for_each_surface(con->sway_view, &data->root_geo, | 271 | output_view_for_each_surface(con->sway_view, data->output, &data->root_geo, |
1065 | send_frame_done_iterator, data); | 272 | send_frame_done_iterator, data); |
1066 | } | 273 | } |
1067 | 274 | ||
@@ -1072,9 +279,12 @@ static void send_frame_done_container(struct send_frame_done_data *data, | |||
1072 | } | 279 | } |
1073 | 280 | ||
1074 | static void send_frame_done(struct sway_output *output, struct timespec *when) { | 281 | static void send_frame_done(struct sway_output *output, struct timespec *when) { |
282 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
1075 | struct send_frame_done_data data = { | 283 | struct send_frame_done_data data = { |
1076 | .output = output, | 284 | .output = output, |
1077 | .when = when, | 285 | .when = when, |
286 | .exclusive_client = output_has_opaque_lockscreen(output, seat) ? | ||
287 | seat->exclusive_client : NULL, | ||
1078 | }; | 288 | }; |
1079 | 289 | ||
1080 | struct sway_container *workspace = output_get_active_workspace(output); | 290 | struct sway_container *workspace = output_get_active_workspace(output); |
@@ -1125,7 +335,7 @@ static void damage_handle_frame(struct wl_listener *listener, void *data) { | |||
1125 | } | 335 | } |
1126 | 336 | ||
1127 | if (needs_swap) { | 337 | if (needs_swap) { |
1128 | render_output(output, &now, &damage); | 338 | output_render(output, &now, &damage); |
1129 | } | 339 | } |
1130 | 340 | ||
1131 | pixman_region32_fini(&damage); | 341 | pixman_region32_fini(&damage); |
@@ -1152,7 +362,7 @@ static void damage_surface_iterator(struct wlr_surface *surface, int sx, int sy, | |||
1152 | bool whole = data->whole; | 362 | bool whole = data->whole; |
1153 | 363 | ||
1154 | struct wlr_box box; | 364 | struct wlr_box box; |
1155 | bool intersects = get_surface_box(&data->root_geo, data->output, surface, | 365 | bool intersects = output_get_surface_box(&data->root_geo, data->output, surface, |
1156 | sx, sy, &box); | 366 | sx, sy, &box); |
1157 | if (!intersects) { | 367 | if (!intersects) { |
1158 | return; | 368 | return; |
@@ -1163,16 +373,22 @@ static void damage_surface_iterator(struct wlr_surface *surface, int sx, int sy, | |||
1163 | int center_x = box.x + box.width/2; | 373 | int center_x = box.x + box.width/2; |
1164 | int center_y = box.y + box.height/2; | 374 | int center_y = box.y + box.height/2; |
1165 | 375 | ||
1166 | if (pixman_region32_not_empty(&surface->current->surface_damage)) { | 376 | if (pixman_region32_not_empty(&surface->buffer_damage)) { |
377 | enum wl_output_transform transform = | ||
378 | wlr_output_transform_invert(surface->current.transform); | ||
379 | |||
1167 | pixman_region32_t damage; | 380 | pixman_region32_t damage; |
1168 | pixman_region32_init(&damage); | 381 | pixman_region32_init(&damage); |
1169 | pixman_region32_copy(&damage, &surface->current->surface_damage); | 382 | pixman_region32_copy(&damage, &surface->buffer_damage); |
1170 | wlr_region_scale(&damage, &damage, output->wlr_output->scale); | 383 | wlr_region_transform(&damage, &damage, transform, |
1171 | if (ceil(output->wlr_output->scale) > surface->current->scale) { | 384 | surface->current.buffer_width, surface->current.buffer_height); |
385 | wlr_region_scale(&damage, &damage, | ||
386 | output->wlr_output->scale / (float)surface->current.scale); | ||
387 | if (ceil(output->wlr_output->scale) > surface->current.scale) { | ||
1172 | // When scaling up a surface, it'll become blurry so we need to | 388 | // When scaling up a surface, it'll become blurry so we need to |
1173 | // expand the damage region | 389 | // expand the damage region |
1174 | wlr_region_expand(&damage, &damage, | 390 | wlr_region_expand(&damage, &damage, |
1175 | ceil(output->wlr_output->scale) - surface->current->scale); | 391 | ceil(output->wlr_output->scale) - surface->current.scale); |
1176 | } | 392 | } |
1177 | pixman_region32_translate(&damage, box.x, box.y); | 393 | pixman_region32_translate(&damage, box.x, box.y); |
1178 | wlr_region_rotated_bounds(&damage, &damage, rotation, | 394 | wlr_region_rotated_bounds(&damage, &damage, rotation, |
@@ -1196,7 +412,7 @@ void output_damage_surface(struct sway_output *output, double ox, double oy, | |||
1196 | .whole = whole, | 412 | .whole = whole, |
1197 | }; | 413 | }; |
1198 | 414 | ||
1199 | surface_for_each_surface(surface, ox, oy, &data.root_geo, | 415 | output_surface_for_each_surface(surface, ox, oy, &data.root_geo, |
1200 | damage_surface_iterator, &data); | 416 | damage_surface_iterator, &data); |
1201 | } | 417 | } |
1202 | 418 | ||
@@ -1215,7 +431,7 @@ static void output_damage_view(struct sway_output *output, | |||
1215 | .whole = whole, | 431 | .whole = whole, |
1216 | }; | 432 | }; |
1217 | 433 | ||
1218 | output_view_for_each_surface(view, &data.root_geo, | 434 | output_view_for_each_surface(view, output, &data.root_geo, |
1219 | damage_surface_iterator, &data); | 435 | damage_surface_iterator, &data); |
1220 | } | 436 | } |
1221 | 437 | ||
@@ -1247,11 +463,12 @@ static void output_damage_whole_container_iterator(struct sway_container *con, | |||
1247 | 463 | ||
1248 | void output_damage_whole_container(struct sway_output *output, | 464 | void output_damage_whole_container(struct sway_output *output, |
1249 | struct sway_container *con) { | 465 | struct sway_container *con) { |
466 | // Pad the box by 1px, because the width is a double and might be a fraction | ||
1250 | struct wlr_box box = { | 467 | struct wlr_box box = { |
1251 | .x = con->current.swayc_x - output->wlr_output->lx, | 468 | .x = con->current.swayc_x - output->wlr_output->lx - 1, |
1252 | .y = con->current.swayc_y - output->wlr_output->ly, | 469 | .y = con->current.swayc_y - output->wlr_output->ly - 1, |
1253 | .width = con->current.swayc_width, | 470 | .width = con->current.swayc_width + 2, |
1254 | .height = con->current.swayc_height, | 471 | .height = con->current.swayc_height + 2, |
1255 | }; | 472 | }; |
1256 | scale_box(&box, output->wlr_output->scale); | 473 | scale_box(&box, output->wlr_output->scale); |
1257 | wlr_output_damage_add_box(output->damage, &box); | 474 | wlr_output_damage_add_box(output->damage, &box); |
@@ -1276,19 +493,21 @@ static void handle_destroy(struct wl_listener *listener, void *data) { | |||
1276 | output->wlr_output->data = NULL; | 493 | output->wlr_output->data = NULL; |
1277 | free(output); | 494 | free(output); |
1278 | 495 | ||
1279 | arrange_and_commit(&root_container); | 496 | arrange_windows(&root_container); |
1280 | } | 497 | } |
1281 | 498 | ||
1282 | static void handle_mode(struct wl_listener *listener, void *data) { | 499 | static void handle_mode(struct wl_listener *listener, void *data) { |
1283 | struct sway_output *output = wl_container_of(listener, output, mode); | 500 | struct sway_output *output = wl_container_of(listener, output, mode); |
1284 | arrange_layers(output); | 501 | arrange_layers(output); |
1285 | arrange_and_commit(output->swayc); | 502 | arrange_windows(output->swayc); |
503 | transaction_commit_dirty(); | ||
1286 | } | 504 | } |
1287 | 505 | ||
1288 | static void handle_transform(struct wl_listener *listener, void *data) { | 506 | static void handle_transform(struct wl_listener *listener, void *data) { |
1289 | struct sway_output *output = wl_container_of(listener, output, transform); | 507 | struct sway_output *output = wl_container_of(listener, output, transform); |
1290 | arrange_layers(output); | 508 | arrange_layers(output); |
1291 | arrange_and_commit(output->swayc); | 509 | arrange_windows(output->swayc); |
510 | transaction_commit_dirty(); | ||
1292 | } | 511 | } |
1293 | 512 | ||
1294 | static void handle_scale_iterator(struct sway_container *view, void *data) { | 513 | static void handle_scale_iterator(struct sway_container *view, void *data) { |
@@ -1299,7 +518,8 @@ static void handle_scale(struct wl_listener *listener, void *data) { | |||
1299 | struct sway_output *output = wl_container_of(listener, output, scale); | 518 | struct sway_output *output = wl_container_of(listener, output, scale); |
1300 | arrange_layers(output); | 519 | arrange_layers(output); |
1301 | container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL); | 520 | container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL); |
1302 | arrange_and_commit(output->swayc); | 521 | arrange_windows(output->swayc); |
522 | transaction_commit_dirty(); | ||
1303 | } | 523 | } |
1304 | 524 | ||
1305 | struct sway_output *output_from_wlr_output(struct wlr_output *wlr_output) { | 525 | struct sway_output *output_from_wlr_output(struct wlr_output *wlr_output) { |
@@ -1309,7 +529,7 @@ struct sway_output *output_from_wlr_output(struct wlr_output *wlr_output) { | |||
1309 | void handle_new_output(struct wl_listener *listener, void *data) { | 529 | void handle_new_output(struct wl_listener *listener, void *data) { |
1310 | struct sway_server *server = wl_container_of(listener, server, new_output); | 530 | struct sway_server *server = wl_container_of(listener, server, new_output); |
1311 | struct wlr_output *wlr_output = data; | 531 | struct wlr_output *wlr_output = data; |
1312 | wlr_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); | 532 | wlr_log(WLR_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); |
1313 | 533 | ||
1314 | struct sway_output *output = calloc(1, sizeof(struct sway_output)); | 534 | struct sway_output *output = calloc(1, sizeof(struct sway_output)); |
1315 | if (!output) { | 535 | if (!output) { |
@@ -1368,5 +588,6 @@ void output_enable(struct sway_output *output) { | |||
1368 | output->damage_destroy.notify = damage_handle_destroy; | 588 | output->damage_destroy.notify = damage_handle_destroy; |
1369 | 589 | ||
1370 | arrange_layers(output); | 590 | arrange_layers(output); |
1371 | arrange_and_commit(&root_container); | 591 | arrange_windows(&root_container); |
592 | transaction_commit_dirty(); | ||
1372 | } | 593 | } |