Skip to content

Fix mouse input interference when drawing with stylus (Wine/Bottles + OTD)#4

Open
jaivu wants to merge 3 commits intoGraham--M:mainfrom
jaivu:main
Open

Fix mouse input interference when drawing with stylus (Wine/Bottles + OTD)#4
jaivu wants to merge 3 commits intoGraham--M:mainfrom
jaivu:main

Conversation

@jaivu
Copy link
Copy Markdown

@jaivu jaivu commented Apr 30, 2026

Fix: Mouse Input Interference When Drawing with Stylus

Problem

When using Krita (and other drawing apps) under Wine/Bottles with XWinTab, the stylus produced dual input both a Wintab stroke and a mouse stroke simultaneously. This caused red (mouse) lines to appear alongside blue (stylus) lines when drawing.

The root cause: Wine's X11 driver subscribes to core X11 pointer events independently of XWinTab's XInput subscription. When the stylus moves, the X server generates two events one for XWinTab (XInput) and one for Wine (core pointer) so the app sees both pen and mouse input at the same time.

Additionally, the existing g_PenIsDown branching in on_event() had both branches doing identical work, so it wasn't actually filtering anything.


Changes in WinTab.c

1. Per-app mouse suppression hook (WH_MOUSE)

Installed on the app's message thread via SetWindowsHookExW in WTOpenW(), removed in WTClose().

App behavior is detected at open time using GetModuleFileNameW():

  • Generic apps (Krita etc.) block WM_LBUTTONDOWN/UP while pen is down. This stops the duplicate mouse stroke while still allowing WM_MOUSEMOVE so the brush cursor follows the pen.
  • Simple apps (MediBang, FireAlpaca) no mouse events blocked. These apps use WM_LBUTTONDOWN to trigger drawing mode but read position/pressure from Wintab packets directly, so blocking mouse events breaks pressure sensitivity. The x=0,y=0 button packet fix below is sufficient.

2. Fix x=0,y=0 button press packets

XCB button press/release events carry no coordinates (x=0, y=0). Previously these were forwarded as-is, causing MediBang and FireAlpaca to see the cursor jump to the top-left corner on every pen touch.

Fixed by tracking the last known position (g_lastPkX, g_lastPkY) from motion events and substituting it into button event packets.

3. Mouse mode toggle via barrel button (WH_KEYBOARD_LL)

For Krita users who need to interact with the UI using the pen (clicking buttons, panning etc.), a toggle is provided via the stylus lower barrel button.

Since OTD (OpenTabletDriver) injects barrel button events on its own thread, a thread-local WH_MOUSE hook cannot catch them. Instead, a system-wide WH_KEYBOARD_LL hook detects the mapped key (PageDown by default — configurable in OTD) and toggles g_mouseModeOverride. When active, WM_LBUTTONDOWN/UP suppression is disabled so the pen behaves like a mouse.


Tested with

  • Wacom CTL-490 + OpenTabletDriver v0.6.7
  • Krita (Windows) under Bottles/Wine
  • MediBang Paint (Windows) under Bottles/Wine
  • FireAlpaca (Windows) under Bottles/Wine

Result

  • No dual strokes in Krita
  • Pen pressure working in MediBang and FireAlpaca
  • Brush cursor follows pen during drawing
  • Barrel button toggles mouse mode in Krita

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