Search Unity

Adding support for touchscreen on Linux

Discussion in 'Input System' started by hallgeir, Jun 15, 2021.

  1. hallgeir

    hallgeir

    Joined:
    Aug 21, 2020
    Posts:
    4
    We're using Elo touchscreens connected to computers running Ubuntu for our kiosk-like installation.
    For now we've been using Elos drivers to simulate mouse input from touch, but now we need multitouch, which the screen supports. However Unity as noted in the documentation here: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/manual/Touch.html, does not support touch input on Linux.

    Is there a way for me (using Input System) to _add_ support for this myself? That is, make an .so file that Unity can load that will produce touch input events? If so, can anybody point me in the right direction?

    If not, I'll create an .so file that fetches the input from the OS and create a parallel input system, but this would be far less elegant, and more of a pain to test since we mostly develop on Windows machines.
     
    sai_chan likes this.
  2. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    A bit low level, but you can create Touchscreen state structs and use InputSystem.QueueStateEvent(...); to push them into input system event buffer. This way you could extend functionality from C# (or native if you want).
     
    sai_chan likes this.
  3. hallgeir

    hallgeir

    Joined:
    Aug 21, 2020
    Posts:
    4
    Ah, brilliant! Kinda expected it to be low level, so that's fine. Was something like this I was looking for.
    I'll play around with it during the week and report back here for future reference if someone else has the same use case.
    Thank you!
     
    sai_chan likes this.
  4. hallgeir

    hallgeir

    Joined:
    Aug 21, 2020
    Posts:
    4
    Reporting back:
    This aproach works well. I've written a small library (available here: https://github.com/Istarnion/magic_touchscreen) that is easier to call from C#. Then we have a MonoBehaviour that calls this library, and fills the Unity data structures and pushes them to QueueStateEvent().
    TouchscreenState is no longer public in InputSystem 1.0, but We're able to create a "fake" touchscreen device by calling InputSystem.AddDevice<Touchscreen>(), then create TouchState events to push to QueueState. InputSystem handles a lot internally, and is very nice to use.
     
  5. mylastggeast

    mylastggeast

    Joined:
    Jun 14, 2021
    Posts:
    41
    Hello!
    I am trying to port my game from mobile to SteamDeck. I want to avoid using Proton since it seems to be very unstable and causing all sorts of issues with Unity, and touch simply doesn't work properly either.
    I am able to build a native Linux game but as you pointed out Linux multi-touch is not supported in the input system.
    Would it be possible to use your library in this case?
     
  6. noemis

    noemis

    Joined:
    Jan 27, 2014
    Posts:
    76
    hey @hallgeir

    I currently also look into using an unity app on a linux machine in kiosk mode and same problem occured: unitys input system does not support multitouch on linux in 2023 (@dmytro_at_unity) - sad!

    I tried to understand your solution but did not get far. I downloaded "Magic Touchscreen" from git, unpacked, installed libevdev-dev (and also make), opened a terminal, navigate to the directory and entered "make"

    I tried this on a (l)ubuntu 22.04 and got this error:


    blendfx@blendfx-quieter3:~/Desktop/magic_touchscreen-main$ make
    clang -shared -fPIC -I /usr/include/libevdev-1.0 src/magicts.cpp -o libmagicts.so -levdev
    make: clang: No such file or directory
    make: *** [Makefile:11: libmagicts.so] Error 127


    And even, if this would work, I think I'd be a bit lost, what to do next. Is a plugin generated, which I have to copy to the asset folder?

    I hope you or maybe someone else could help. Best would be, unity would implement native support for multitouch.
     
    mylastggeast likes this.
  7. noemis

    noemis

    Joined:
    Jan 27, 2014
    Posts:
    76
    Maybe it's possible to precompile a package (maybe prepare a unitypackage?) with a simple c# sample script. That'd be awesome.
     
    mylastggeast likes this.
  8. hallgeir

    hallgeir

    Joined:
    Aug 21, 2020
    Posts:
    4
    @mylastggeast Sorry, I didn't get notified of your post, sorry!
    I'm not familiar with the SteamDeck, so not sure if it'll work or not. If it uses evdev then that's promising. Do you have terminal access so you could install evtest? Then you could test if you get the ABS_MT_* events needed for this library.

    @noemis You'll also need to install clang, the compiler (or you could try to compile with gcc which is probably already installed). This will result in libmagicts.so which you'll include in your Unity project as a native plugin for Unity.
    Then you can access the functions through C# to pump the touch events into Unitys new input system.
    I haven't included a Unity example for this in the repo because I want to use this for non-unity projects as well, but I'll look into making some examples. I can't guarantee a time for this right now though, sorry :/
     
    mylastggeast likes this.
  9. mylastggeast

    mylastggeast

    Joined:
    Jun 14, 2021
    Posts:
    41
    @hallgeir
    Thanks for the update! I am not sure about evdev on Deck either, but I will take a look and report back!
     
  10. noemis

    noemis

    Joined:
    Jan 27, 2014
    Posts:
    76
    @hallgeir thank you, for your fast response and hint. I'm not very familiar with linux and compiling stuff.
    When I noticed that clang is missing, I just opened the package manager and searched for clang - but with no results. But "sudo apt install clang" installed something (yeah) and now it gives me another error:


    clang -shared -fPIC -I /usr/include/libevdev-1.0 src/magicts.cpp -o libmagicts.so -levdev
    src/magicts.cpp:13:10: fatal error: 'libevdev/libevdev.h' file not found
    #include <libevdev/libevdev.h>
    ^~~~~~~~~~~~~~~~~~~~~
    1 error generated.
    make: *** [Makefile:11: libmagicts.so] Error 1


    If I look at the path "/usr/include/libevdev-1.0" there's indeed nothing. Again looking in the package manager and searching for "libevdev" shows me, that there's a "libevdev2" package. So it seems, there are some differences to your machine. Maybe you have another hint, which brings me forward... If you advise to install another distro - would be also fine for me.
     
    Last edited: Jun 12, 2023
  11. dutchdriver

    dutchdriver

    Joined:
    Oct 4, 2022
    Posts:
    1
    Hi @noemis, it's just a matter of installing libevdev-dev, by running:
    sudo apt install libevdev-dev