Poll Wacom input from "libinput debug-events" in Bash

Hey,

I am making a Bash shell script to grab input from libinput. There's a few reasons why I am doing it this way:

  1. Using Python with python-libinput does not work. I installed version 0.1.0 with pip, and it complains about "ContextType" not existing. So that's a no-go.
  2. I am trying to get away from my dependence on Xorg-related stuff, such as xsetwacom and xserver-input-wacom, and do things that are more compatible with Wayland.
  3. Both methods above do not have support for the four different modes when you press the center ring button on the ExpressKey pad. I plan to eventually support all of these events.

Without explaining my entire plan of this script, I figured I could ask the question that's harder for me to understand, and figure out the rest as I go along.

I want to poll the outputs from "libinput debug-events" in an infinite loop Bash script that will run in the background. This polling will happen, say, every 1 second.

This pseudocode down below can help explain what I am looking to do to start out my script:

#!/bin/bash
  
while true; do
  sleep 1
  OUTPUT=$(libinput debug-events | grep "TABLET_PAD_BUTTON")
  case ${OUTPUT} in
  "4 pressed (mode 0)")
    echo "Button 4"
    ;;
    # Etc . . .
  esac
done

My big problem is figuring out how to do this.

The thing is, "libinput debug-devices" works a lot like showkey or xev, but not exactly. For some reason, stdin for "TABLET_PAD_BUTTON" is "frozen" until I move the mouse around. Why this is, I have no idea. Regardless to say, I feel like I may be overcomplicating my problem, or I just don't really see a clear cut solution. Doing it this way just doesn't work right, as it is.

The libinput binary program will need to somehow exit after a period of time, because by default it is left running, so some sort of control implementation needs to exist there. Also, I notice that when it loops back to "OUTPUT=xyz" the existing variable data should be replaced by new input data again, which is great. That's exactly how it should work in that case.

Finally, this is a script that needs to run in the background (like a daemon process), and also accept input from libinput/udev devices at all times. And I'm not sure if Bash is powerful enough to tell the libinput binary to do that, is the thing.... If this really needs to be written in C, then perhaps there's no good solution here, and the thread can be closed if that's the case.

Anybody have any idea how I could approach this problem, or could even possibly provide a good bash script solution? Thank you very much in advance!

You might get more responses if you explain exactly what you are trying to accomplish.

1 Like

Well, okay.

For example, I want to store the output of

libinput debug-events | grep "TABLET_PAD_BUTTON"

in a variable, but since it grabs the input device (stdin), it doesn't seem possible. I also want the command to exit after 1 second. How would I do that?

Moderator comments were removed during original forum migration.