3

From what I understand, earlier versions of the Synaptic driver in Ubuntu had an 'absolute mode' for the trackpad which allowed the user to access absolute coordinates as well as relative coordinates. However, Synaptic decided to remove it(not sure why) and its no longer available. Is there any way to access the absolute mode in Ubuntu 20.04 LTS? I'd like to be able to get these coordinates in a C/C++ program but open to any other solutions (Rust, shell script, whatever works). I've come across similar posts but I'm still unable to find a satisfactory solution. Most recommend the evtest driver which does sport absolute mode but lacks other features(2 finger scrolling, etc.). I'm thinking reverting back to an older version of the Synaptic driver might help but wanted to know what I'd be missing out on. I mean, are there any important features in the more recent Synaptic driver that the old one with absolute mode doesn't?

Edit: I did a bit more digging and came across this page --> http://manpages.ubuntu.com/manpages/bionic/man1/python-evdev.1.html

It shows how to use a Python library, evdev, and how to use it to access system input events. Following the examples, I set it to watch my trackpad events and upon moving my finger I got a whole wall of information which unfortunately, I didn't understand. I did notice terms like ABS_X, ABS_Y but couldn't make anything of it. Regardless, it appears that I can access a lot of trackpad information through this library including something to do with absolute coordinates. How do I use this information? Can anyone show me how to write a simple Python function using evdev

def foo():
    ...
    return (x,y)

where (x,y) represents my finger postion on the trackpad?

Edit 2: Sample output of evdev monitoring my trackpad. Can any of this be used to get absolute coordinates?

absolute axis event at 1623586006.216310, ABS_MT_TRACKING_ID 
absolute axis event at 1623586006.216310, ABS_MT_POSITION_X 
absolute axis event at 1623586006.216310, ABS_MT_POSITION_Y 
absolute axis event at 1623586006.216310, ABS_MT_PRESSURE 
key event at 1623586006.216310, 330 (BTN_TOUCH), down
absolute axis event at 1623586006.216310, ABS_X 
absolute axis event at 1623586006.216310, ABS_Y 
absolute axis event at 1623586006.216310, ABS_PRESSURE 
key event at 1623586006.216310, 325 (BTN_TOOL_FINGER), down
synchronization event at 1623586006.216310, SYN_REPORT 
absolute axis event at 1623586006.231209, ABS_MT_PRESSURE 
absolute axis event at 1623586006.231209, ABS_PRESSURE
Polluks
  • 103
n0pe
  • 121

3 Answers3

0

Use

    >>> print(event)
    event at 1337197425.477827, code 04, type 04, val 458792

Right now you output the timestamp and code, but val should be your coordinate, see https://python-evdev.readthedocs.io/en/latest/_modules/evdev/events.html.

Polluks
  • 103
0

Sorry for the late answer. I hope this is still at least somewhat helpful. Anyways, I've been trying to figure this out. Most likely, if you followed the "tutorial" on the link you posted, you'll have print(evdev.categorize(event)) or something along the lines.

Now I have no idea what categorize does, but getting rid of the categorize function seems to print out what you're looking for; raw x and y position.

from evdev import InputDevice

device = InputDevice('/dev/input/event8')

for event in device.read_loop(): print(event)

The output from event is like so:

event at 1664686111.342840, code 53, type 03, val 1097
event at 1664686111.342840, code 54, type 03, val 736
event at 1664686111.342840, code 00, type 03, val 1097
event at 1664686111.342840, code 01, type 03, val 736
event at 1664686111.342840, code 05, type 04, val 201000

It seems like codes 53 and 54 contain the correct data. For me, at least. You might have to do some deduction to figure that out for yourself though. And I have no idea if your touchpad works the same way in evdev as it does for me, so this might not even work.

I'll come up with some code real quick for you to copy and paste:

from evdev import InputDevice
#SET THIS TO YOUR DEVICE
device = InputDevice('/dev/input/event8')

x = 0 y = 0

def get_xy_coords(e): #you may need to change this number here; i don't know if e.code == 53: global x x = e.value #this one too if e.code == 54: global y y = e.value

for event in device.read_loop(): get_xy_coords(event)

Here. This exact code will set x and y to their respective coordinates every read loop. Hope I could help, despite posting this a year later.

0

based on @Greyson Phipps answer, i created a simple script to make make touchpad behave like a drawing tablet https://github.com/Vaisakhkm2625/touchpaddraw

not ideal, as i am not a primarily python dev and this is a hacky solution, but works . works only in xorg.in wayland(gnome), this is getting 2 cursors, one with absolute and one with relative and jumbs between them....


import math
import os
import time

#get trackpad absolute coords from evdev import InputDevice

import argparse

from pynput import mouse from pynput.mouse import Button

Initialize parser

parser = argparse.ArgumentParser()

Adding optional argument

parser.add_argument("-d", "--device", help = "device (event*)")

Read arguments from command line

args = parser.parse_args()

#SET THIS TO YOUR DEVICE device = InputDevice('/dev/input/'+ args.device if args.device else 'event7')

touchpad_x_max = 1224 touchpad_y_max = 804

max_x = 1920 max_y = 1080

x = 0 y = 0

def get_xy_coords(e): #you may need to change this number here; i don't know if e.code == 53: global x x = e.value #this one too if e.code == 54: global y y = e.value

def mapFromTo(x,a,b,c,d):

y=(x-a)//(b-a)*(d-c)+c

y=(x-a)/(b-a)*(d-c)+c return y

x_pos =0 y_pos =0

mouse_controller = mouse.Controller() for event in device.read_loop(): #rows, cols = stdscr.getmaxyx() get_xy_coords(event) if event.code == 54: prev_x_pos = x_pos prev_y_pos = y_pos x_pos =math.floor(mapFromTo(x,0,touchpad_x_max,0,max_x)) y_pos =math.floor(mapFromTo(y,0,touchpad_y_max,0,max_y)) if (abs(prev_x_pos-x_pos)>15 or abs(prev_y_pos-y_pos)>15): mouse_controller.release(Button.left) mouse_controller.position = (x_pos,y_pos); mouse_controller.press(Button.left) mouse_controller.position = (x_pos,y_pos);

Vaisakh K M
  • 157
  • 6