aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/view.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-01 16:23:11 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-01 16:24:15 +1000
commitd10ccc1eb144e4de2477398f6b11753f6b7df70b (patch)
treea4792f1ca754ed427a5b472d1bcf3e75fcf1f2ef /sway/tree/view.c
parentMerge pull request #2395 from RedSoxFan/create-mouse-binding-list (diff)
downloadsway-d10ccc1eb144e4de2477398f6b11753f6b7df70b.tar.gz
sway-d10ccc1eb144e4de2477398f6b11753f6b7df70b.tar.zst
sway-d10ccc1eb144e4de2477398f6b11753f6b7df70b.zip
Correctly track saved surfaces during multiple transactions
Fixes #2364. Suppose a view is 600px wide, and we tell it to resize to 601px during a resize operation. We create a transaction, save the 600px buffer and send the configure. This buffer is saved into the associated instruction, and is rendered while we wait for the view to commit a 601px buffer. Before the view commits the 601px buffer, suppose we tell it to resize to 602px. The new transaction will also save the buffer, but it's still the 600px buffer because we haven't received a new one yet. Then suppose the view commits its original 601px buffer. This completes the first transaction, so we apply the 601px width to the container. There's still the second (now only) transaction remaining, so we render the saved buffer from that. But this is still the 600px buffer, and we believe it's 601px. Whoops. The problem here is we can't stack buffers like this. So this commit removes the saved buffer from the instructions, places it in the view instead, and re-saves the latest buffer every time the view completes a transaction and still has further pending transactions. As saved buffers are now specific to views rather than instructions, the functions for saving and removing the saved buffer have been moved to view.c. The calls to save and restore the buffer have been relocated to more appropriate functions too, favouring transaction_commit and transaction_apply rather than transaction_add_container and transaction_destroy.
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 8f54cc11..0dbd3812 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -2,6 +2,7 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include <wayland-server.h> 3#include <wayland-server.h>
4#include <wlr/render/wlr_renderer.h> 4#include <wlr/render/wlr_renderer.h>
5#include <wlr/types/wlr_buffer.h>
5#include <wlr/types/wlr_output_layout.h> 6#include <wlr/types/wlr_output_layout.h>
6#include "config.h" 7#include "config.h"
7#ifdef HAVE_XWAYLAND 8#ifdef HAVE_XWAYLAND
@@ -1070,3 +1071,22 @@ void view_set_urgent(struct sway_view *view, bool enable) {
1070bool view_is_urgent(struct sway_view *view) { 1071bool view_is_urgent(struct sway_view *view) {
1071 return view->urgent.tv_sec || view->urgent.tv_nsec; 1072 return view->urgent.tv_sec || view->urgent.tv_nsec;
1072} 1073}
1074
1075void view_remove_saved_buffer(struct sway_view *view) {
1076 if (!sway_assert(view->saved_buffer, "Expected a saved buffer")) {
1077 return;
1078 }
1079 wlr_buffer_unref(view->saved_buffer);
1080 view->saved_buffer = NULL;
1081}
1082
1083void view_save_buffer(struct sway_view *view) {
1084 if (!sway_assert(!view->saved_buffer, "Didn't expect saved buffer")) {
1085 view_remove_saved_buffer(view);
1086 }
1087 if (view->surface && wlr_surface_has_buffer(view->surface)) {
1088 view->saved_buffer = wlr_buffer_ref(view->surface->buffer);
1089 view->saved_buffer_width = view->surface->current.width;
1090 view->saved_buffer_height = view->surface->current.height;
1091 }
1092}