From b4027118e65ac1f7a8b71d538ed323e23c482fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 7 Feb 2022 10:36:59 +0100 Subject: [PATCH 1/4] term: init: initialize selection pivot point coords to -1,-1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While this _shouldn’t_ be necessary (pivot points are only used while a selection is ongoing). But it doesn’t hurt to initialize them anyway. --- terminal.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/terminal.c b/terminal.c index 3b935909..81df743b 100644 --- a/terminal.c +++ b/terminal.c @@ -1158,6 +1158,10 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .selection = { .start = {-1, -1}, .end = {-1, -1}, + .pivot = { + .start = {-1, -1}, + .end = {-1, -1}, + }, .auto_scroll = { .fd = -1, }, From a187271ca4ba491c7614de540c4490e0f6fa118d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 7 Feb 2022 10:38:30 +0100 Subject: [PATCH 2/4] render: resize: finalize selection before reflowing the grid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a crash caused by the selection’s pivot point not being translated during reflow. While we could simply reflow the pivot point as well, testing shows irregular behavior with ongoing selections across window resizes, with different compositors behaving differently. For now, we simply finalize the selection, instead of trying to handle ongoing selections. Closes #922 --- render.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/render.c b/render.c index 024d0954..e189e1a0 100644 --- a/render.c +++ b/render.c @@ -3681,6 +3681,16 @@ maybe_resize(struct terminal *term, int width, int height, bool force) if (term->grid == &term->alt) selection_cancel(term); + else { + /* + * Don’t cancel, but make sure there aren’t any ongoing + * selections after the resize. + */ + tll_foreach(term->wl->seats, it) { + if (it->item.kbd_focus == term) + selection_finalize(&it->item, term, it->item.pointer.serial); + } + } struct coord *const tracking_points[] = { &term->selection.start, From 003ea4904d79dfce530d77adc29030f9fcd1e6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 7 Feb 2022 10:42:32 +0100 Subject: [PATCH 3/4] render: resize: add TODO: translate pivot coords --- render.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/render.c b/render.c index e189e1a0..953ec4da 100644 --- a/render.c +++ b/render.c @@ -3692,6 +3692,12 @@ maybe_resize(struct terminal *term, int width, int height, bool force) } } + /* + * TODO: if we remove the selection_finalize() call above (i.e. if + * we start allowing selections to be ongoing across resizes), the + * selection’s pivot point coordinates *must* be added to the + * tracking points list. + */ struct coord *const tracking_points[] = { &term->selection.start, &term->selection.end, From 09fd39bb29dea808ea12c1a601aba883c8938884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 7 Feb 2022 10:44:00 +0100 Subject: [PATCH 4/4] changelog: mouse selections are finalized on window resize --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2377b4c..abc72229 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,11 @@ ## Unreleased ### Added ### Changed + +* Mouse selections are now finalized when the window is resized + (https://codeberg.org/dnkl/foot/issues/922). + + ### Deprecated ### Removed ### Fixed @@ -48,6 +53,8 @@ (https://codeberg.org/dnkl/foot/issues/918). * “(null)” being logged as font-name (for some fonts) when warning about a non-monospaced primary font. +* Rare crash when the window is resized while a mouse selection is + ongoing (https://codeberg.org/dnkl/foot/issues/922). ### Security