From be9d59999845d2ea128a4108b03783513c64ec8e Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 6 Jul 2025 08:33:57 +0100 Subject: [PATCH 1/3] allow negative mouse coordinates --- CHANGELOG.md | 1 + src/textual/_xterm_parser.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2533447e73..ffdbbc573d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed issue with the "transparent" CSS value not being transparent when set using python https://github.com/Textualize/textual/pull/5890 - Fixed issue with pushing screens when Input has mouse captured https://github.com/Textualize/textual/pull/5900 +- Implemented workaround for Ghostty bug which produces negative mouse coordinates ## Changed diff --git a/src/textual/_xterm_parser.py b/src/textual/_xterm_parser.py index ed4163fec6..0983c0a670 100644 --- a/src/textual/_xterm_parser.py +++ b/src/textual/_xterm_parser.py @@ -18,7 +18,7 @@ # to be unsuccessful? _MAX_SEQUENCE_SEARCH_THRESHOLD = 32 -_re_mouse_event = re.compile("^" + re.escape("\x1b[") + r"(\d+);(?P\d)\$y" ) @@ -50,7 +50,7 @@ class XTermParser(Parser[Message]): - _re_sgr_mouse = re.compile(r"\x1b\[<(\d+);(\d+);(\d+)([Mm])") + _re_sgr_mouse = re.compile(r"\x1b\[<(-?\d+);(-?\d+);(-?\d+)([Mm])") def __init__(self, debug: bool = False) -> None: self.last_x = 0.0 From 58f2256bf53a5d1c99276f77c98f267320ab6b83 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 6 Jul 2025 08:36:33 +0100 Subject: [PATCH 2/3] discard negative coords --- src/textual/_xterm_parser.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/textual/_xterm_parser.py b/src/textual/_xterm_parser.py index 0983c0a670..431a4866e7 100644 --- a/src/textual/_xterm_parser.py +++ b/src/textual/_xterm_parser.py @@ -78,6 +78,9 @@ def parse_mouse_code(self, code: str) -> Message | None: buttons = int(_buttons) x = float(int(_x) - 1) y = float(int(_y) - 1) + if x < 0 or y < 0: + # TODO: Workaround for Ghostty erroneous negative coordinate bug + return None if ( self.mouse_pixels and self.terminal_pixel_size is not None From 5d4d0f02c2aa2eb215be3666294eb85b442f9efc Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 6 Jul 2025 08:36:53 +0100 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffdbbc573d..cf6b986492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed issue with the "transparent" CSS value not being transparent when set using python https://github.com/Textualize/textual/pull/5890 - Fixed issue with pushing screens when Input has mouse captured https://github.com/Textualize/textual/pull/5900 -- Implemented workaround for Ghostty bug which produces negative mouse coordinates +- Implemented workaround for Ghostty bug which produces negative mouse coordinates https://github.com/Textualize/textual/pull/5926 ## Changed