Skip to content

fix: Add support for mouse chords and extended buttons#63

Merged
gdamore merged 1 commit intomainfrom
mouse-chords
Jan 4, 2026
Merged

fix: Add support for mouse chords and extended buttons#63
gdamore merged 1 commit intomainfrom
mouse-chords

Conversation

@gdamore
Copy link
Owner

@gdamore gdamore commented Jan 4, 2026

Summary by CodeRabbit

  • New Features

    • Added support for additional mouse buttons (buttons 4–7).
    • Introduced convenient mouse wheel buttons aggregate for simplified wheel handling.
  • Improvements

    • Enhanced simultaneous multi-button press detection and state tracking.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 4, 2026

📝 Walkthrough

Walkthrough

Refactored mouse button handling from boolean-based state to bitmask-based tracking, enabling simultaneous multi-button detection. Updated event parser to decode additional mouse buttons (buttons 4–7), normalized button input processing, and introduced state machine logic to manage button press/release events across multiple files.

Changes

Cohort / File(s) Summary
Mouse button enumeration
source/dcell/mouse.d
Added wheels enum member as convenience aggregate (wheelUp | wheelDown | wheelLeft | wheelRight); minor comment formatting change
Parser event handling and state tracking
source/dcell/parser.d
Replaced buttonDown boolean with buttonsDown bitmask field; updated mouse event parsing to normalize button input (0xff mask) and decode to Buttons enum; broadened button support from 0x43 to 0xC3 mask; added case handlers for buttons 4–7 (0x80–0x83); introduced state machine block (cases 'm' and 'M') to manage button state across events; removed legacy newMouseEvent(int, int, int) signature
Demo button display logic
demos/mouse/source/mouse.d
Replaced switch-based button dispatch with series of bitwise guards; initializes label to '?' and appends per-button indicators (B1–B8) using individual if (button & Buttons.buttonN) checks; enables multi-button display support

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Buttons dancing, bitmasks bright,
Multi-click support takes flight!
From single press to eight at once,
Mouse events juggle like cunning runts,
No more switch—just masks that bite! 🖱️

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main changes: adding support for mouse chords (multiple buttons simultaneously) and extended buttons (button4-button7). This is clearly reflected in the modifications across all three files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc411c2 and 3d30c8c.

📒 Files selected for processing (3)
  • demos/mouse/source/mouse.d
  • source/dcell/mouse.d
  • source/dcell/parser.d
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-12-15T05:12:35.344Z
Learnt from: gdamore
Repo: gdamore/dcell PR: 56
File: source/dcell/vt.d:2-2
Timestamp: 2025-12-15T05:12:35.344Z
Learning: In D (as used in gdamore/dcell), an enum-type variable like Attr attr can be referred to in case statements using either attr.EnumMember or Attr.EnumMember due to aliasing. For consistency and readability, prefer using the type name (Attr.EnumMember) in case statements instead of the lowercase variable name (attr.EnumMember). This guideline applies to D files across the repository (source/**/*.d or any .d files).

Applied to files:

  • source/dcell/mouse.d
  • demos/mouse/source/mouse.d
  • source/dcell/parser.d
📚 Learning: 2025-12-17T22:06:30.452Z
Learnt from: dejlek
Repo: gdamore/dcell PR: 60
File: demos/tutorial.md:26-26
Timestamp: 2025-12-17T22:06:30.452Z
Learning: In Dcell (D language), when handling EventType.resize events, do not access ev.mouse properties. To get the new terminal dimensions after a resize event, call s.size() instead.

Applied to files:

  • source/dcell/parser.d
🔇 Additional comments (6)
source/dcell/mouse.d (1)

16-41: LGTM! The wheels alias is a clean addition.

The new wheels alias correctly combines all wheel-related button flags (wheelUp | wheelDown | wheelLeft | wheelRight), providing a convenient aggregate for masking wheel events in the parser's state machine logic.

demos/mouse/source/mouse.d (1)

233-286: Bitwise handling supports multi-button detection.

The refactoring from switch-based to bitwise checks enables detecting multiple simultaneous button presses. The bStr correctly accumulates all pressed buttons (B1, B2, etc.), while lb retains only the last matched button character - this is reasonable for the demo's box-drawing purpose.

source/dcell/parser.d (4)

880-880: Cast to signed byte is correct for the switch cases.

The cast to byte is intentional since the extended button cases (0x80-0x83) need to be matched as negative values in the switch statement when using a signed type.


917-931: Extended button handling added for buttons 4-7.

The mapping for 0x80-0x83 to button4 through button7 aligns with the XTerm SGR mouse protocol. Note that button8 is defined in the Buttons enum but has no corresponding case here - please verify this is intentional (i.e., XTerm doesn't report values beyond 0x83 for extended buttons).


946-965: State machine correctly tracks multi-button chording.

The logic properly:

  • Suppresses spurious releases for buttons not tracked as pressed (line 949-952)
  • Accumulates pressed buttons and reports the cumulative state
  • Clears wheel flags immediately since they're impulse events without releases

One edge case to consider: if the parser starts receiving events mid-sequence (e.g., after a terminal reconnect), buttonsDown may not reflect actual button state, causing legitimate releases to be suppressed. This is an acceptable trade-off for debouncing spurious events.


369-369: Bitmask field enables multi-button state tracking.

The change from a boolean to a Buttons bitmask correctly supports tracking multiple simultaneously pressed buttons.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gdamore gdamore merged commit 3d30c8c into main Jan 4, 2026
5 checks passed
@gdamore gdamore deleted the mouse-chords branch January 4, 2026 17:30
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.

1 participant