From 66b7e007ccc31cc3c39c0080caca319d48aa6b15 Mon Sep 17 00:00:00 2001 From: Dom Date: Thu, 3 Sep 2026 19:02:15 -0300 Subject: [PATCH] Take mouse button codes from curses, not hardcoded integers handle_mouse compared against integers from NCURSES_MOUSE_VERSION 1, which allocated six bits per button. Version 2 packs them into five to make room for button 5, so every constant except BUTTON1_RELEASED moved: right click is 1024 rather than 4096, wheel up 65536 rather than 524288, wheel down 2097152 rather than 134217728. Only left click still worked, and by coincidence, because BUTTON1_RELEASED is 1 under both versions. BUTTON5 exists only under mouse version 2, so it degrades to no wheel-down event rather than a mismatched one. --- CHANGELOG.md | 11 +++++++++++ suplemon/main.py | 20 ++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 960789c..85ccb87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ Change Log ========== +## Unreleased + +**Fixed** + +- Mouse mode only responded to left click. The button codes were + hardcoded integers from `NCURSES_MOUSE_VERSION` 1, which gave each + button six bits; version 2 packs them into five to make room for + button 5, moving every value except `BUTTON1_RELEASED`. Right click + and both scroll directions were therefore matched against numbers + ncurses never sends. The codes now come from curses itself. + ## [v0.3.2](https://github.com/leancode/suplemon/tree/0.3.2) (2026-09-03) Nothing here changes the installed package. The launcher fix affects the diff --git a/suplemon/main.py b/suplemon/main.py index 2a2461c..55ad113 100644 --- a/suplemon/main.py +++ b/suplemon/main.py @@ -6,6 +6,7 @@ import os +import curses import sys from . import ui @@ -21,6 +22,12 @@ __version__ = "0.3.2" +# ncurses only defines BUTTON5 when built with NCURSES_MOUSE_VERSION 2. +# Without it there is no wheel-down event to match, so scrolling down is +# simply unavailable rather than mismatched. +BUTTON5_PRESSED = getattr(curses, "BUTTON5_PRESSED", 0) + + class App: def __init__(self, filenames=None, config_file=None, log_level=None): """ @@ -340,13 +347,18 @@ def handle_mouse(self, event): :rtype: boolean """ editor = self.get_editor() - if event.mouse_code == 1: # Left mouse button release + code = event.mouse_code + # These were hardcoded integers matching NCURSES_MOUSE_VERSION 1, + # which gave each button six bits. Version 2 packs them into five to + # make room for button 5, so every value except BUTTON1_RELEASED + # moved and only left click still worked. Ask curses instead. + if code & curses.BUTTON1_RELEASED: editor.set_single_cursor(event.mouse_pos) - elif event.mouse_code == 4096: # Right mouse button release + elif code & curses.BUTTON3_RELEASED: editor.add_cursor(event.mouse_pos) - elif event.mouse_code == 524288: # Wheel up + elif code & curses.BUTTON4_PRESSED: # Wheel up editor.jump_up() - elif event.mouse_code == 134217728: # Wheel down(and unfortunately left button drag) + elif BUTTON5_PRESSED and code & BUTTON5_PRESSED: editor.jump_down() else: return False