Git Product home page Git Product logo

evdev-right-click-emulation's Introduction

evdev-right-click-emulation

A program that solves the problem of right clicks on Linux devices with a touchscreen. It implements the long-press-to-right-click gesture on Linux touchscreen devices while having no specific requirements on the desktop environment, display server or the distribution, which greatly improves the touch experience for users of Linux distributions.

It directly reads from evdev touchscreen input devices, parses the events, and triggers a right click with uinput when it detects a long press from a touchscreen. Since evdev is lower-level than libinput or any other user-space input driver, this program can work regardless of your choice of Xorg or Wayland.

This program started as a Python script that I published on Gist. However, the Python binding of libevdev had some mysterious bugs, and I thought it was not the best idea to run a Python interpreter to read every input event just to implement a simple feature. Thus I rewrote it in C, which is what is contained in this repository.

Dependencies

  • libevdev
  • libevdev headers (for development)

And of course glibc and your Linux kernel.

Building

make all

The compiled program lies in out/evdev-rce.

Usage

Simply run

out/evdev-rce

Or you may put this executable anywhere on your file system.

Note: this program needs to read from and write to /dev/input. Make sure the current user has the permission to do so, or you may use root.

There are some tunable options accessible through the following environment variables:

# Required interval in ms for a touch event to be considered a long press
# default = 1000ms
LONG_CLICK_INTERVAL=1000
# Allowed margin of error (in px) for a long press event
# i.e. the finger is considered still if its movement is within this range
# Note: the px here is not physical pixels on the screen. It's the physical
# pixels of the touch devices, which may have a different resolution.
# default = 100px
LONG_CLICK_FUZZ=100
# Uncomment to set a blacklist of devices that `evdev-rce` will not
# listen on for touch events. The names can be retrived by using `xinput`
# or simply by reading the output of `evdev-rce`
# (it will print out the names of all touch devices when starting,
#  e.g. "Found touch screen at <some_path>: <device_name>)
#TOUCH_DEVICE_BLACKLIST="device1 name|device2 name|..."
# Uncomment to set a whitelist of devices that `evdev-rce` will ONLY
# listen on. This overrides the blacklist - when whitelist is present,
# any device not in this list will be ignored.
#TOUCH_DEVICE_WHITELIST="device1 name|device2 name|..."

So you can run the program like

LONG_CLICK_INTERVAL=500 LONG_CLICK_FUZZ=50 evdev-rce

To customize those options.

evdev-right-click-emulation's People

Contributors

petercxy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

evdev-right-click-emulation's Issues

Single-Click no longer detected

Hey, thanks for this software - its completely changed the usability of my Linx8 tablet!

however after a couple of reboots I have found that the standard Single-Click event from tapping the touchscreen is no longer detected from within PCManFM-QT File Manager, the Desktop and the Right-Click menu itself..

I am still able to click on title bar actions and move windows around, also able to activate the system menu and interact with Cairo-dock and other programs like Discovery, Chromium and all the Settings..

does anyone have suggestions on how to remedy this?
thank you

Menu disappears once finger is off the screen

The menu disappears once the finger is off the screen.
So one long click > right click is simulated and the menu shows up
Need to select an option from the menu (finger is lifted from the touchscreen in order to select copy or paste for example) > menu disappears before I can do that.
Using Raspbian Bullseye.
Touchscreen: MageDok T116D Pro

No right-click on Surface Pro 3 touchscreen

I just successfully compiled (using #5) and run evdev-rce on my Surface Pro 3. Unfortunately it does not generate any right-clicks at all, when touching the touchscreen for more than 1 second...

$ sudo out/evdev-rce 
[sudo] password for sph: 
Found touch screen at /dev/input/event8: Microsoft Surface Type Cover Touchpad
Found touch screen at /dev/input/event3: NTRG0001:01 1B96:1B05
Found touch screen at /dev/input/event2: NTRG0001:01 1B96:1B05
^C

and

$ xinput
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳ NTRG0001:01 1B96:1B05                   	id=9	[slave  pointer  (2)]
⎜   ↳ Microsoft Surface Type Cover Consumer Control	id=11	[slave  pointer  (2)]
⎜   ↳ Microsoft Surface Type Cover Mouse      	id=13	[slave  pointer  (2)]
⎜   ↳ Microsoft Surface Type Cover Touchpad   	id=14	[slave  pointer  (2)]
⎜   ↳ Simulated Right Button                  	id=17	[slave  pointer  (2)]
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ Video Bus                               	id=6	[slave  keyboard (3)]
    ↳ Surface Pro 3/4 Buttons                 	id=7	[slave  keyboard (3)]
    ↳ NTRG0001:01 1B96:1B05                   	id=8	[slave  keyboard (3)]
    ↳ Microsoft Surface Type Cover Keyboard   	id=10	[slave  keyboard (3)]
    ↳ Microsoft Surface Type Cover Consumer Control	id=12	[slave  keyboard (3)]
    ↳ Microsoft LifeCam Front: Micros         	id=15	[slave  keyboard (3)]
    ↳ Microsoft LifeCam Rear: Microso         	id=16	[slave  keyboard (3)]

I searched for evdev and rce in ~/.xsession-errors, but could not find any entry containing either of those two words.

If you need any further information, please feel free to ask!

can't compile on Debian sid with libevdev-dev 1.8.0

I've tried to compile on Debian sid, here is the result:

# make
gcc -Wall -std=c11 -D_POSIX_C_SOURCE=199309L -levdev -I/usr/include/libevdev-1.0 -c uinput.c -o out/uinput.o
gcc -Wall -std=c11 -D_POSIX_C_SOURCE=199309L -levdev -I/usr/include/libevdev-1.0 -c input.c -o out/input.o
gcc -Wall -std=c11 -D_POSIX_C_SOURCE=199309L -levdev -I/usr/include/libevdev-1.0 -c rce.c -o out/rce.o
gcc -Wall -std=c11 -D_POSIX_C_SOURCE=199309L -levdev -I/usr/include/libevdev-1.0 out/uinput.o out/input.o out/rce.o -o out/evdev-rce
/usr/bin/ld: out/uinput.o: in function `uinput_initialize':
uinput.c:(.text+0x9): undefined reference to `libevdev_new'
/usr/bin/ld: uinput.c:(.text+0x20): undefined reference to `libevdev_set_name'
/usr/bin/ld: uinput.c:(.text+0x31): undefined reference to `libevdev_enable_event_type'
/usr/bin/ld: uinput.c:(.text+0x4c): undefined reference to `libevdev_enable_event_code'
/usr/bin/ld: uinput.c:(.text+0x69): undefined reference to `libevdev_uinput_create_from_device'
/usr/bin/ld: uinput.c:(.text+0x81): undefined reference to `libevdev_free'
/usr/bin/ld: out/uinput.o: in function `uinput_send_right_click':
uinput.c:(.text+0xae): undefined reference to `libevdev_uinput_write_event'
/usr/bin/ld: uinput.c:(.text+0xc9): undefined reference to `libevdev_uinput_write_event'
/usr/bin/ld: uinput.c:(.text+0xe4): undefined reference to `libevdev_uinput_write_event'
/usr/bin/ld: uinput.c:(.text+0xff): undefined reference to `libevdev_uinput_write_event'
/usr/bin/ld: out/input.o: in function `free_evdev':
input.c:(.text+0x14): undefined reference to `libevdev_get_fd'
/usr/bin/ld: input.c:(.text+0x23): undefined reference to `libevdev_free'
/usr/bin/ld: out/input.o: in function `build_fd_set':
input.c:(.text+0xdf): undefined reference to `libevdev_get_fd'
/usr/bin/ld: out/input.o: in function `process_evdev_input':
input.c:(.text+0x4a9): undefined reference to `libevdev_get_fd'
/usr/bin/ld: input.c:(.text+0x4de): undefined reference to `libevdev_get_fd'
/usr/bin/ld: input.c:(.text+0x548): undefined reference to `libevdev_next_event'
/usr/bin/ld: input.c:(.text+0x5c0): undefined reference to `libevdev_uinput_destroy'
/usr/bin/ld: out/rce.o: in function `find_evdev':
rce.c:(.text+0x1ad): undefined reference to `libevdev_new_from_fd'
/usr/bin/ld: rce.c:(.text+0x1fa): undefined reference to `libevdev_has_event_type'
/usr/bin/ld: rce.c:(.text+0x213): undefined reference to `libevdev_has_event_type'
/usr/bin/ld: rce.c:(.text+0x231): undefined reference to `libevdev_has_event_code'
/usr/bin/ld: rce.c:(.text+0x24f): undefined reference to `libevdev_has_event_code'
/usr/bin/ld: rce.c:(.text+0x263): undefined reference to `libevdev_get_name'
/usr/bin/ld: rce.c:(.text+0x346): undefined reference to `libevdev_free'
collect2: error: ld returned 1 exit status
make: *** [Makefile:19: out/evdev-rce] Error 1
apt policy libevdev-dev
libevdev-dev:
  Installed: 1.8.0+dfsg-2
  Candidate: 1.8.0+dfsg-2
  Version table:
 *** 1.8.0+dfsg-2 500
        500 http://cdn-fastly.deb.debian.org/debian sid/main amd64 Packages
        100 /var/lib/dpkg/status

Menu closes right after finger is released

I'm running Manjaro Mate on a Dell Venue 11 pro, if that helps. whenever I hold down my finger, the right click is registered, but the moment I release my finger the menu deactivates. Is there a way to mitigate this? Thanks a lot for providing this software which makes Linux on non touch friendly DEs a lot more usable!

Unable to create uinput device

I try to run app but i get error Failed to create uinput device.
Before things app detects my display correct: Found touch screen at /dev/input/event4: raspberry-ts

Hardware: Raspberry pi 4 8gb, official rpi 7" touch display
Software: manjaro kde 20.08 arm64

Long press performs both left and right click

For example, when I long press on a hyperlink, the context menu shows, but the hyperlink opens right after I stop pressing. See this video:
simplescreenrecorder-2019-12-22_13 41 58
It seems that long press actually performs both left and right click.
The device I uses is wacom's tablet.

Running As a Service in Kubuntu 20.04

This may help someone.

It runs flawlessly as a service. After moving evdev-rce to /usr/local/sbin I created a evdev-rce.service file in /etc/systemd/system like this:

[Unit]
Description=Event Device Right Click Emulation
[Service]
ExecStart=/usr/local/sbin/evdev-rce
[Install]
WantedBy=multi-user.target

I had to do it because the program needed sudo to work.

I tested it with sudo systemctl start evdev-rce.service and noticed that long-press was also acting like a right click for the touchpad. I didn't want that, I only wanted it for the touchscreen so I stopped the service and added the environmental variable using:

sudo systemctl edit evdev-rce

and in the /etc/systemd/system/evdev-rce.service.d/override.conf created I added:

[Service]
Environment="TOUCH_DEVICE_WHITELIST=04F3:2A12"

To find the right ID to use for my device I ran this script found here: https://askubuntu.com/questions/520359/how-to-detect-touchscreen-devices-from-a-script

#!/bin/bash
tmp_dir=$(mktemp -d)
pushd $tmp_dir > /dev/null
# Export whole database 
udevadm info --export-db > udevdb.txt
csplit -s udevdb.txt /^$/ {*}

FILES=./xx*
for f in $FILES
do
  if [[ ! -z $(grep ID_INPUT_TOUCHSCREEN=1 $f) ]] && [[ ! -z $(grep " NAME=*" $f) ]]; 
  then
        # Extract touchscreen name
        grep " NAME=*" $f | cut -d "=" -f 2
  fi
done
popd > /dev/null
rm -rf $tmp_dir

Big thanks to artsin and Pablo Bianchi. The result gave me:

"CUST0000:00 04F3:2A12"

The first part, CUST0000:00 I didn't need. I used only the actual identifier, 04F3:2A12. This of course will be different for another machine. Then I tested again, and seeing it worked as I needed I installed it to run at startup with

sudo systemctl enable evdev-rce.service

It works flawlessly. This utility is a life-saver.

(solved) Program compiles on Raspbian 10 but not on Ubuntu 20.04 - ld cannot find symbols from libevdev

The program compiled well on Raspbian 10 with the following evdev-related packages installed (apt list --installed | grep evdev)

libevdev-dev/oldstable,now 1.6.0+dfsg-1 armhf [installed]
libevdev-doc/oldstable,now 1.6.0+dfsg-1 all [installed]
libevdev-tools/oldstable,now 1.6.0+dfsg-1 armhf [installed]
libevdev2/oldstable,now 1.6.0+dfsg-1 armhf [installed]
python-evdev/oldstable,now 1.1.2+dfsg-1+b1 armhf [installed]
python3-evdev/oldstable,now 1.1.2+dfsg-1+b1 armhf [installed,automatic]

But it fails on Ubuntu Mate 20.04 with the following evdev-related packages installed

libevdev-dev/focal-updates,now 1.9.0+dfsg-1ubuntu0.1 arm64 [installed]
libevdev-doc/focal-updates,now 1.9.0+dfsg-1ubuntu0.1 all [installed]
libevdev-tools/focal-updates,now 1.9.0+dfsg-1ubuntu0.1 arm64 [installed]
libevdev2/focal-updates,now 1.9.0+dfsg-1ubuntu0.1 arm64 [installed]
python3-libevdev/focal,now 0.5-1 all [installed]
xserver-xorg-input-evdev-dbg/focal,now 1:2.10.6-1 arm64 [installed]
xserver-xorg-input-evdev-dev-hwe-18.04/focal,now 3:14.5 arm64 [installed]
xserver-xorg-input-evdev-dev/focal,now 1:2.10.6-1 all [installed]
xserver-xorg-input-evdev-hwe-18.04-dbg/focal,now 3:14.5 arm64 [installed]
xserver-xorg-input-evdev-hwe-18.04/focal,now 3:14.5 arm64 [installed]
xserver-xorg-input-evdev/focal,now 1:2.10.6-1 arm64 [installed]

Compiling fails on linking with the following messages:

/usr/bin/ld: out/uinput.o: in function uinput_initialize': uinput.c:(.text+0x1c): undefined reference to libevdev_new'
/usr/bin/ld: uinput.c:(.text+0x30): undefined reference to
`libevdev_set_name'

(etc...)

Menu not opened at the touch location on Wayland

On Wayland (unlike on XOrg) touch input does not move the mouse pointer to the location of the touch. When a right-click is simulated, the popup menu opens at the current location of the cursor, not at the place of the touch. This may open a different menu than the intended one. (I don't know what happens on devices without a mouse at all.)

Is there a way to fix this? I'm afraid not without interacting more directly with Wayland, unless there is a way to simulate an absolute pointer device event that does cause Wayland to move the the cursor.

Compile Errors on Raspberry pi 4 running latest Raspbian (Bullseye)

Device: Raspad (Raspberry Pi 4)
Operating System: Raspberry OS (Bullseye)

Hi, I tried to install right click emulation on the latest release of the raspberry pi operating system. I got the compile errors listed below. I installed the emulation in the last release with no problems... Any hints would be appreciated....

gcc -Wall -std=c11 -D_POSIX_C_SOURCE=199309L -levdev -I/usr/include/libevdev-1.0 out/uinput.o out/input.o out/rce.o -o out/evdev-rce
/usr/bin/ld: out/uinput.o: in function uinput_initialize': uinput.c:(.text+0xc): undefined reference to libevdev_new'
/usr/bin/ld: uinput.c:(.text+0x1c): undefined reference to libevdev_set_name' /usr/bin/ld: uinput.c:(.text+0x28): undefined reference to libevdev_enable_event_type'
/usr/bin/ld: uinput.c:(.text+0x3c): undefined reference to libevdev_enable_event_code' /usr/bin/ld: uinput.c:(.text+0x58): undefined reference to libevdev_uinput_create_from_device'
/usr/bin/ld: uinput.c:(.text+0x74): undefined reference to libevdev_free' /usr/bin/ld: out/uinput.o: in function uinput_send_right_click':
uinput.c:(.text+0xb0): undefined reference to libevdev_uinput_write_event' /usr/bin/ld: uinput.c:(.text+0xc4): undefined reference to libevdev_uinput_write_event'
/usr/bin/ld: uinput.c:(.text+0xd8): undefined reference to libevdev_uinput_write_event' /usr/bin/ld: uinput.c:(.text+0xec): undefined reference to libevdev_uinput_write_event'
/usr/bin/ld: out/input.o: in function free_evdev': input.c:(.text+0x14): undefined reference to libevdev_get_fd'
/usr/bin/ld: input.c:(.text+0x20): undefined reference to libevdev_free' /usr/bin/ld: out/input.o: in function build_fd_set':
input.c:(.text+0x110): undefined reference to libevdev_get_fd' /usr/bin/ld: out/input.o: in function process_evdev_input':
input.c:(.text+0x578): undefined reference to libevdev_get_fd' /usr/bin/ld: input.c:(.text+0x5bc): undefined reference to libevdev_get_fd'
/usr/bin/ld: input.c:(.text+0x620): undefined reference to libevdev_next_event' /usr/bin/ld: input.c:(.text+0x6a8): undefined reference to libevdev_uinput_destroy'
/usr/bin/ld: out/rce.o: in function find_evdev': rce.c:(.text+0x1a4): undefined reference to libevdev_new_from_fd'
/usr/bin/ld: rce.c:(.text+0x1f4): undefined reference to libevdev_has_event_type' /usr/bin/ld: rce.c:(.text+0x210): undefined reference to libevdev_has_event_type'
/usr/bin/ld: rce.c:(.text+0x230): undefined reference to libevdev_has_event_code' /usr/bin/ld: rce.c:(.text+0x250): undefined reference to libevdev_has_event_code'
/usr/bin/ld: rce.c:(.text+0x268): undefined reference to libevdev_get_name' /usr/bin/ld: rce.c:(.text+0x344): undefined reference to libevdev_free'
collect2: error: ld returned 1 exit status
make: *** [Makefile:19: out/evdev-rce] Error 1

Program stops working when disconnecting and reconnecting touchscreen.

First of all, thank for writing this program, it's super handy!

I run autostart evdev-rce without problems. But if I close my Laptop, it stops working after opening it again. What opening and closing the Laptop of course does, is disconnecting and reconnecting the wacom touch input device.

Can this be fixed? Maybe there is also a way for me to automatically restart evdev-rce after such an event?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.