Skip to content

Pen/Tablet Input Support #99

Closed
Closed

Description

I propose we support pen tablet input, such as on devices like the Surface Pro/Studio, Galaxy Note, and eventually the Apple Pencil. These devices support things like pressure sensitivity and rotation/gyro. I don't think this is necessarily relevant to games (although it definitely can be), but it's definitely relevant to the larger digital 3D community.

Activity

  1. added
    S - api
    S - enhancement
    on Dec 11, 2016
  2. added a commit that references this issue on Mar 29, 2017
  3. added
    H - help wanted
    C - needs discussion
    D - hard
    P - normal
    P - low
    and removed
    P - normal
    on May 6, 2018
  4. tangmi commented on Mar 22, 2019

    @tangmi
    Contributor

    There is an issue open on imgui (ocornut/imgui#2372) that has a little documentation and discussion on how to handle pen input across platforms that might be relevant when work on this starts.

  5. DorianRudolph commented on Jul 26, 2020

    @DorianRudolph

    I made a preliminary implementation for pen support on X11 here https://github.com/DorianRudolph/winit/tree/stylus

    Pen pressure can already be accessed on X11 via the raw axis events, but there you get no information about the range of values.

  6. lehmanju commented on Aug 14, 2020

    @lehmanju

    @DorianRudolph What is the state of your implementation? Any help needed? I could look into stylus support for Wayland but first we should probably make sure the API exposed in Winit is correct.

  7. kchibisov commented on Aug 14, 2020

    @kchibisov
    Member

    @lehmanju if you're interested in contributing Wayland bits, you may add helper for table input to https://github.com/smithay/client-toolkit , since it's something that will be required anyway.

  8. 33 remaining items

  9. Doublonmousse commented on Jun 30, 2024

    @Doublonmousse

    As the windows side of the implementation was mentioned, and the proposed implementation is relying on the Win32 API, I would like to say that the Win32 API is limited in some ways that create unwanted behavior (as in, different from any other implementation, with my main gripe being the absence of information on the button presses when hovering. The result is that buttons are usually not working correctly on windows for any application using gtk3/gtk4 or qt).

    I've listed my concerns (and a fix using additional WinRT API calls) on an existing PR here: #2396 (comment)

    Other Windows-specific features related to pens are only available using WinRT APIS (haptic feedback, pressure levels with more than 1024 levels)

  10. Doublonmousse commented on Jun 30, 2024

    @Doublonmousse

    Another thing to note on windows is that pen APIs are split between Windows Ink (what we get from the Win32 or WinRT APIS) and Wintab, and these two are still used today.

    Windows Ink is used by all modern tablets with a pen digitizer on the screen, whilst Wintab is still widely used by external graphical tablets (wacom, huion). And of course, if your graphical tablet uses Wintab as the API and you're getting events from the Windows Ink API, these events are seen as mouse events, not pen events ...

    Usually you have to choose one of the two APIs to catch pen events and restart the app if you want to switch APIs.

    https://crates.io/crates/wintab_lite This seems like the only rust crate that deals with wintab right now, although, as I've only looked at the Windows ink part, I'm not familiar with the wintab part. (I know both qt and gtk have a wintab option, so there's other C/C++ code that implement the Wintab API).

  11. thehappycheese commented on Aug 15, 2024

    @thehappycheese

    https://crates.io/crates/wintab_lite This seems like the only rust crate that deals with wintab right now, although, as I've only looked at the Windows ink part, I'm not familiar with the wintab part. (I know both qt and gtk have a wintab option, so there's other C/C++ code that implement the Wintab API).

    Oh hi there :) I am the author of that wintab_lite crate.

    FYI i gave up trying to integrate with winit because winit blocks access to the window event loop by making it private.

    wintab does provide an alternative polling-based api to obtain events, I think that method sucks. It is prone to overflowing buffers on the driver side which causes inexplicable bad behaviour. For this reason I think winit's choice to hide the event loop is not compatible with wintab... unless i am somehow mistaken.

    This is unfortunate, because I find Windows Ink to be highly unreliable and flakey. Wintab has been working solid as a rock for decades.

  12. Doublonmousse commented on Aug 15, 2024

    @Doublonmousse

    Hey. I think part of the reason windows Ink is flaky is the use of the win32 API over the WinRT one (hence why I tried to use WinRT calls in addition to the win32 ones to get the missing info or more info on events, and that gives correct info for pure windows ink devices like a surface pen). That means that for most windows software supporting windows ink that aren't WinUI note taking applications the support is limited and has been for a while now.

    But also, as far as external graphics tablets are concerned, it's clear to me the optional windows ink mode is usually less polished and featured, although the fault may be split between drivers manufacturers who already have a good wintab drivers not needing an Ink one, and Windows Ink being less featured than wintab (sometimes using the open tablet driver + windows ink can give you some level of functionality that the official driver lacks in windows ink mode).

    But enough ranting, do you think integrating your crate inside of the event loop (not doing this as an external crate, but injecting the necessary code inside of the winit crate directly, similarly to me doing win32 and WinRT calls to get pen info here 0ba247b) could be done instead ?
    (also if someone know a better way to get pen info from WinRT let me know)

    One other point you might have an answer to : on most toolkits that have wintab and windows ink support, you can usually only choose one and need to restart to use the other one (that's the case for both gtk and qt). Is there a fundamental limitation that makes having both activated at the same time impossible ?
    Cause if you have a device that has both a windows ink device (like a pen digitiser) + an external graphics tablet that uses wintab (and you don't want/can't use the windows ink option), there's always one device that won't work correctly.

    Anyway, once the API is decided in #3833 and proper platform-dependent support can be added to winit, I'd like to make sure it doesn't have the usual limitations other windows implementation have on the windows ink side.
    And if we can do better, why not try to have support for both at the same time (windows ink and wintab) without a need for a restart ?

  13. daxpedda commented on Aug 15, 2024

    @daxpedda
    Member

    FYI i gave up trying to integrate with winit because winit blocks access to the window event loop by making it private.

    wintab does provide an alternative polling-based api to obtain events, I think that method sucks. It is prone to overflowing buffers on the driver side which causes inexplicable bad behaviour. For this reason I think winit's choice to hide the event loop is not compatible with wintab... unless i am somehow mistaken.

    We plan to address this with #2120 and the move to a trait-based API, #3432, with the goal that external crates can integrate with Winit exactly like wintab_lite could do.

    I was a bit shocked with the terms "private" and "hide the event loop", the event loop is a function and integrating with it requires more API then just "making it public". But maybe I'm missing something, I'm not very familiar with the Windows backend.

    But enough ranting, do you think integrating your crate inside of the event loop (not doing this as an external crate, but injecting the necessary code inside of the winit crate directly, similarly to me doing win32 and WinRT calls to get pen info here 0ba247b) could be done instead ?

    On first inspection I don't think its viable to add Wintab support directly into Winit. We want to limit the scope to cross-platform functionality and only implement and expose whats absolutely necessary.

    But as said above, I think its incredibly important that Winit allows external crates to integrate into the event loop exactly for reasons like this. On the other hand, I would love to see Wintab and Windows Ink support in winit-extra (doesn't exist yet).

  14. thehappycheese commented on Aug 15, 2024

    @thehappycheese

    Do you think integrating your crate inside of the event loop (not doing this as an external crate, but injecting the necessary code inside of the winit crate directly, similarly to me doing win32 and WinRT calls to get pen info here 0ba247b) could be done instead?

    I am sure a built in solution would work great :) My plate is a little full at the moment to try help, but feel free to copy-pasta my code all you like. I spent a lot of time adding nice rust documentaiton to it.

    Is there a fundamental limitation that makes having both activated at the same time impossible

    Not as far as I know... I have a Huion device, the configuration software has a toggle to turn windows ink on and off... as far as I can tell the toggle is broken and does nothing. It still works in windows ink apps. Maybe windows has some fallback and translates wintab into windows ink... i didnt look into it.

    I can tell you this though; for about a month windows ink was not working for me. The fix: disable logitech RGB LED driver that I didnt even know existed. Go figure? It did not interfere with wintab though.

    We plan to address this with #2120 and the move to a trait-based API, #3432, with the goal that external crates can integrate with Winit exactly like wintabl_lite could do.

    I was a bit shocked with the terms "private" and "hide the event loop", the event loop is a function and integrating with it requires more API then just "making it public". But maybe I'm missing something, I'm not very familiar with the Windows backend.

    Ah thats exciting to hear! By private I mean that at the time I looked, the values windows passed to the message / wparam / lparam parameters of the callback registered with CreateWindowExA() do not appear to be avaliable through the winit API. I dont remember the exact details... I think winit maybe sets up the window / event loop / polling differently to what I understand.

    On first inspection I don't think its viable to add Wintab support directly into Winit. We want to limit the scope to cross-platform functionality and only implement and expose whats absolutely necessary.

    Possibly licencing is also an issue for serious projects? Wacom's licence / coppyright notice on thier repo seem contradictory to my primitive understanding of these things.

    Thank you all for your hard work on winit though, it is otherwise absolutly fantastic and it sounds like its going to be even better in the future! <3

  15. wareya commented on May 2, 2025

    @wareya

    Pen pressure in particular actually worked (accidentally?) (at least on Windows) in winit 0.30.10, but on the current git version it does not. The pressure data used to be present in a Touch event, now it's not conveyed to the application at all.

    On windows, wayland, and mac OS, the standard and most widely-usable version (on each platform) of tablet pointer events comes through the normal window event channel, and is inaccessible elsewhere, so it shouldn't be considered out of scope. All desktop platforms are converging on first-class support for tablet events in the same way that touch, mouse, and keypress inputs are are first-class supported everywhere. For example, Wintab32 and RealTimeStylus are outdated red herrings and are only useful in extremely niche situations or on ancient hardware with broken drivers; WM_POINTER is literally just The Way to do tablet input on windows right now.

    0.30.10:

    Touch(Touch { device_id: DeviceId(DeviceId(0)), phase: Moved, location: PhysicalPosition { x: 816.0188976377954, y: 279.0062992125984 }, force: Some(Normalized(0.8818359375)), id: 400 })

    Current git:

    PointerMoved { device_id: None, position: PhysicalPosition { x: 468.0094488188977, y: 269.9937007874016 }, primary: true, source: Unknown }

  16. added a commit that references this issue on Aug 3, 2025
    d37dc28
  17. Demohstens commented on Aug 10, 2025

    @Demohstens

    Whether intentional or not, currently winit calls RegisterTouchWindow which causes windows so send WM_TOUCH events which do not contain pressure information instead of the WM_POINTER* events which do. The PR #991 did add handling for WM_POINTER* so removing the call (for windows versions 8+) should result in Pressure functionality being restored.

    As it is right now windows will send WM_TOUCH events which set Force to None in the event loop.

  18. added 2 commits that reference this issue on Aug 12, 2025
    93b3fa0
    c8c54c3
  19. added 2 commits that reference this issue on Oct 7, 2025
    6d11fb7
    1e5dc2e
  20. added a commit that references this issue on Oct 7, 2025
    f046e77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C - needs discussionD - hardH - help wantedP - lowS - apiS - enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions