Search code examples
gtkvalagdk

Gdk Event device type wrong


I'm trying to capture pen input using Gdk (in vala). Here's my code

    var source = anEvent.get_device().get_source();

    if (source == Gdk.InputSource.MOUSE) {
        stdout.printf("mouse\n");
    } else if (source == Gdk.InputSource.PEN) {
        stdout.printf("pen\n");
    } else if (source == Gdk.InputSource.ERASER) {
        stdout.printf("eraser\n");
    } else {
        stdout.printf("something else\n");
    }
    Gtk.main_do_event(anEvent);

However, pen input seems to be recognised as a mouse input! Touch and keyboard input seems to be recognized correctly however. This is especially strange since I tested both with the integrated wacom pen on my Thinkpad X1 Yoga as well as a separate Intuos Pro, both which are recognized by Gnome. Also, switching between Xorg / Wayland makes no difference. What am I missing? Or is it simply an issue with Gdk / Gtk / Gnome? Thanks!


Solution

  • Solved it by using Gdk.DeviceToolType instead.

    var tool = anEvent.get_device_tool().get_tool_type();
    
    if (tool == Gdk.DeviceToolType.PEN) {
        stdout.printf("pen?\n");
    }
    
    ... 
    

    works instead.