Merge pull request #5926 from Textualize/fix-ghostty-mouse

allow negative mouse coordinates
This commit is contained in:
Will McGugan
2025-07-06 08:40:50 +01:00
committed by GitHub
2 changed files with 6 additions and 2 deletions

View File

@@ -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 https://github.com/Textualize/textual/pull/5926
## Changed

View File

@@ -18,7 +18,7 @@ from textual.message import Message
# to be unsuccessful?
_MAX_SEQUENCE_SEARCH_THRESHOLD = 32
_re_mouse_event = re.compile("^" + re.escape("\x1b[") + r"(<?[\d;]+[mM]|M...)\Z")
_re_mouse_event = re.compile("^" + re.escape("\x1b[") + r"(<?[-?\d;]+[mM]|M...)\Z")
_re_terminal_mode_response = re.compile(
"^" + re.escape("\x1b[") + r"\?(?P<mode_id>\d+);(?P<setting_parameter>\d)\$y"
)
@@ -50,7 +50,7 @@ IS_ITERM = (
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
@@ -78,6 +78,9 @@ class XTermParser(Parser[Message]):
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