Take mouse button codes from curses, not hardcoded integers - #2
Merged
Conversation
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.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mouse mode (F8) only responded to left click. Right click and both scroll directions did nothing.
Cause
handle_mousecomparedevent.mouse_codeagainst hardcoded integers:Those are
NCURSES_MOUSE_VERSION1 values, which allocated six bits per button. Version 2 packs them into five to make room for button 5, so every constant moved:BUTTON1_RELEASED= 1BUTTON3_RELEASED= 1024BUTTON4_PRESSED= 65536BUTTON5_PRESSED= 2097152Left click worked by coincidence —
BUTTON1_RELEASEDis 1 under both versions.Fix
Match against the curses constants.
BUTTON5is only defined when ncurses is built with mouse version 2, so it falls back to 0 and wheel-down is simply unavailable there rather than mismatched.Verification
Driving the real
handle_mousewith the constants this ncurses reports:set_single_cursorset_single_cursoradd_cursorjump_upjump_downAn unrecognised code still returns
False.test.shpasses, flake8 clean.Same class of bug as the hardcoded 5xx keycodes fixed in 0.3.0.