Extracting device XID using libinput_device_get_sysname#16
Extracting device XID using libinput_device_get_sysname#16cdurden wants to merge 1 commit intoNICHOLAS85:orientationawarenessfrom
Conversation
|
Thanks for the links! I indeed looked into using int id = atoi(sysname+5);I'm curious as to why |
|
If I can't find a direct way to convert |
|
I looked at the output of the command "libinput debug-events" and I saw
that the first field it prints is "eventX," where X is the XID (Correction: this is called the sysname/device node, which is not the same as the XID). So I looked
in the source code for that tool and I found that this string "eventX" is
the return value of libinput_device_get_sysname. So I assumed that this
function can be used to get the XID, even though the documentation doesn't
really say what it does.
That function returns a char pointer, so I thought I could just use pointer
arithmetic to shave off the characters "event." I think sysname+5 is a
pointer to the 6th character of sysname. I think atoi should use all of the
remaining characters of sysname up to the null character, converting to
integer. Not sure why this would not give the XID.
|
|
Ahh I understand better now. That line does indeed work as you're describing, it returns an integer with the devices eventX however it seems that is not what xinput expects when referring to a device's XID. For example /dev/input/event9 on my machine (Wacom HID 4833 Finger touch) has an xid of 16 at the moment. These two values don't seem to have any correlation afaik. |
|
I see. While it might help, I'm not convinced that the {device node - device id/XID} map will resolve the issue in all cases. For instance, it appears that my stylus and eraser have one device node and they appear as two distinct xinput devices with distinct XIDs. Furthermore, it is possible to set distinct Coordinate Transformation Matrices for these two xinput devices. I've thought of two avenues for trying to further address this issue. Getting and setting device orientation information using libinput? First, is it possible to set screen orientations using libinput instead of xinput? It seems that most of the setups I've seen handle orientation changes by updating the Coordinate Transformation Matrices, but libinput has the functions “Coordinate Transformation Matrix” and “libinput Calibration Matrix” - how are they related? Continuing with xinput implementation Since a given libinput device can be associated with multiple xinput devices, I suggest comparing the Coordinate Transformation Matrices for all xinput devices associated with a given libinput device. If the matrices are different, then I think it would make sense to issue a warning to indicate that there is some ambiguity about the orientation for that set of devices. If the Coordinate Transformation Matrices are consistent, then update the orientation as expected. This might not be ideal. But if libinput does not see the eraser and stylus as distinct devices, would we even be able to tell which of these inputs produced a given gesture? If not, we might as well treat them as one thing, and just make sure that everything is consistent. |
I actually started implementing this orientation awareness feature using the libinput calibration matrix information however stopped once I discovered, like you, that most methods of screen rotation involved manipulating a device's Coordinate transformation matrix instead. I do not know of any applications which manipulate the former instead of the latter but if you know of any please share.
Your suggestion sounds reasonable. My only concern is potential energy use/gesture latency. As this is currently implemented, it reads the device's Coordinate Transformation Matrix each time a gesture concludes. This is because Gebaar has no knowledge of when a screen has actually rotated and must determine this on a per-gesture basis which I understand is an inefficient process. This could be solved with the integration of screen rotation logic and matrix caching but for now I don't have plans on implementing that. The comparison you suggest can't be run just once as the matrices would most likely always match in a devices default orientation. So this means it would be run on each gestures conclusion. If you believe this additional logic wouldn't cause too much of a slowdown or isn't cause for concern let me know! |
|
Getting and setting device orientation information using libinput? For now, here's a higher-level implementation that sets the device orientation using libinput:
Continuing with xinput implementation Are you still interested in working on this implementation? I haven't noticed major slowdowns. For speed, I would suggest using conditional compilation to do the additional logic by default. Then the code would issue a warning if necessary to help users identify any issues/confusions about mappings of the devices. To increase the speed, a compile-time option could be used to override the default logic. |
|
I opened an issue on libinput's GitLab site to ask some questions about this. |
|
Just updated the orientationawareness branch in c96aa3a to use a device node - device id map which should be more accurate than the current map. It doesn't solve the problem of two devices sharing the same node but it is an improvement from how it was done before. |
We can't uniquely map vendor ID and product ID to an XID for our input device. This leads to possible confusion when mapping a vendor ID and product ID to an XID, particularly for touchscreen devices (See the section on
libinput_device_get_device_group()at Initialization and manipulation of input devices). This pull request attempts to get the XID directly from the libinput device object usinglibinput_device_get_sysname.Background
There is a 1:1 mapping between libinput devices and
/dev/input/eventXdevice nodes. (Source)Based on the code in the libinput-tools here, it looks like
libinput_device_get_sysnamereturnseventXNote: The
Xin/dev/input/eventXrepresents is here called the XID . This appears to be consistent with the use of the name XID in the xinput documentation.