Skip to content

Fix for mouse input when using PDCursesMod backend#117

Merged
pavkam merged 2 commits into
pavkam:mainfrom
jordan-hemming:pdcurses-mouse
Sep 30, 2025
Merged

Fix for mouse input when using PDCursesMod backend#117
pavkam merged 2 commits into
pavkam:mainfrom
jordan-hemming:pdcurses-mouse

Conversation

@jordan-hemming

Copy link
Copy Markdown
Contributor

Mouse movement events weren't working correctly on PDCursesMod. They would only occur when a button was pressed. Also pressing the Control key with a mouse button would report the Alt key being pressed (keyboard events were fine though).

It turns out that PDCurses uses different bits for the mouse event modifiers than either NCurses 5 or 6. PDCursesMod uses this same bitmask. Specifically:

Shift = 1<< 26
Control = 1 << 27
Alt = 1 << 28
ReportPosition = 1 << 29

These are left shifted by one compared to NCurses 6, with Shift and Control swapped. Since you already have different mouse event parsing for NCurses 5 and 6 I just added another one for PDCurses.

I took the liberty of adding a new overload to CursesMouseEventParser.Get which takes an enum rather than an integer as I thought this was more clear with the new addition (the old API is still available, marked as deprecated). If you'd prefer to just stick with the old API I can revert this change.

Tests have been updated as appropriate.

I've tested this with PDCursesMod-WinCon and PDCursesMod-WinGUI on Windows 11 x64, and it fixes mouse movement and the modifier keys.

PDCurses-WinCon still doesn't support the mouse correctly, but I think that's a problem upstream.

I've also tested NCurses 6 on Linux x64 to check that nothing is broken.

…e using an incompatable bit mask for mouse events.

Added new CursesMouseEventParser.Get API and marked the old one as obsolete.
Updated tests related to CursesMouseEventParser

@pavkam pavkam left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jordan-hemming, great work and many thanks for the fixes -- just one ask for you -- please add your name to the copyright headers and bump the years in them as well. I will get some time to instrument the repo with better workflows hopefully this week and then it will become easier.

@jordan-hemming

Copy link
Copy Markdown
Contributor Author

Will do. I assume you just want me to update the headers for the files I've modified, rather than for the whole project?

@pavkam

pavkam commented Sep 29, 2025

Copy link
Copy Markdown
Owner

Will do. I assume you just want me to update the headers for the files I've modified, rather than for the whole project?

The files you modified. I'll add a contributors file in another PR and make it cleaner

@pavkam
pavkam merged commit 3330198 into pavkam:main Sep 30, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants