简体   繁体   English

evdev 如何判断是否移动 x11 光标?

[英]How does evdev determine whether or not to move the x11 cursor?

I'm starting to dig into the evdev api on linux for the purpose of playing around with uinput emulation.我开始深入研究 linux 上的 evdev api,目的是玩弄 uinput 仿真。 I noticed that between a joystick and a touch pad, there are different button/key event codes to distinguish between joypad button presses and mouse clicks.我注意到在操纵杆和触摸板之间,有不同的按钮/键事件代码来区分操纵杆按钮按下和鼠标点击。 But both devices have event codes for ABS_X and ABS_Y axis.但是两个设备都有 ABS_X 和 ABS_Y 轴的事件代码。

joystick dump:
#   Event type 3 (EV_ABS)
#     Event code 0 (ABS_X)
#       Value      128
#       Min          0
#       Max        255
#       Fuzz         0
#       Flat        15
#       Resolution   0
#     Event code 1 (ABS_Y)
#       Value      103
#       Min          0
#       Max        255
#       Fuzz         0
#       Flat        15
#       Resolution   0

touchpad dump:
#   Event type 3 (EV_ABS)
#     Event code 0 (ABS_X)
#       Value     3909
#       Min       1270
#       Max       5670
#       Fuzz         0
#       Flat         0
#       Resolution  44
#     Event code 1 (ABS_Y)
#       Value     3835
#       Min       1240
#       Max       4746
#       Fuzz         0
#       Flat         0
#       Resolution  66

So how does x11 know whether to treat the '/dev/input/eventX' node as a joystick or a mouse for the purpose of moving the on screen cursor?那么 x11 如何知道为了移动屏幕光标是将 '/dev/input/eventX' 节点视为操纵杆还是鼠标呢? Is there some ioctl I can use to set whether or not the device gets loaded by x11?是否有一些 ioctl 可以用来设置设备是否被 x11 加载? Something else that the driver needs to do to indicate this?司机还需要做些什么来表明这一点?

I looked around at some bug reports and found that there have been cases in old releases where the joypad did move the mouse when connected but I could not find any patches that would indicate what they changed to indicate that distinction to x11.我环顾了一些错误报告,发现在旧版本中存在连接时手柄确实会移动鼠标的情况,但我找不到任何补丁可以表明它们更改了什么以表明与 x11 的区别。

Before someone says it, I know that using libevdev if preferred over direct calls to uinput in practice, but this is for educational purposes only.在有人说出来之前,我知道在实践中使用 libevdev 比直接调用 uinput 更受欢迎,但这仅用于教育目的。 And even there, I have the same question.即使在那里,我也有同样的问题。

So I went through the uinput module documentation and sample code.所以我浏览了 uinput 模块文档和示例代码。 I noticed that in their example code for simulating a mouse, they added an event for the left mouse button ( BTN_LEFT ) via the ioctl calls我注意到在他们模拟鼠标的示例代码中,他们通过 ioctl 调用为鼠标左键( BTN_LEFT )添加了一个事件

ioctl(fd, UI_SET_EVBIT, EV_KEY);
ioctl(fd, UI_SET_KEYBIT, BTN_LEFT);

I found it odd that they included this event type since they are only moving(and not clicking) the mouse in the example code, and sure enough removing those ioctls caused the axis events not to effect the x11 pointer.我发现它们包含这种事件类型很奇怪,因为它们只是在示例代码中移动(而不是单击)鼠标,并且确实删除这些 ioctl 会导致轴事件不会影响 x11 指针。

Now in their example code they use relative axis events ( REL_X , REL_Y ) for the mouse move rather than the absolute events that I was referring to ( ABS_X , ABS_Y ).现在在他们的示例代码中,他们使用相对轴事件( REL_XREL_Y )来进行鼠标移动,而不是我所指的绝对事件( ABS_XABS_Y )。 This is because they are simulating an actual mouse rather than a touch pad.这是因为他们正在模拟实际的鼠标而不是触摸板。 But that did give me a hint that x11 looks for certain event types to be listed in the device bits to determine what kind of device it is.但这确实给了我一个提示,即 x11 会查找要在设备位中列出的某些事件类型,以确定它是哪种设备。

As further confirmation of this theory, I found this note in the detection section of gamepad devices in same documentation.作为对这一理论的进一步证实,我在同一文档的游戏手柄设备检测部分找到了此注释。 All gamepads that follow the protocol described here map BTN_GAMEPAD. This is an alias for BTN_SOUTH/BTN_A. It can be used to identify a gamepad as such. While this doesn't say anything about mice or touchpads explicitly it does support the idea that certain event bits set on input devices are used to determine how x11 treats the input from these devices.虽然这并没有明确说明鼠标或触摸板,但它确实支持在输入设备上设置的某些事件位用于确定 x11 如何处理来自这些设备的输入的想法。 I did find that creating a gamepad device that sets the BTN_GAMEPAD bit will still function as a mouse if you also set the BTN_LEFT bit and the REL_X REL_Y bits so it seems like what x11 is doing is just looking for a few key bits to be set to treat something as a mouse.我确实发现,如果您还设置了BTN_LEFT位和REL_X REL_Y位,那么创建一个设置BTN_GAMEPAD位的游戏手柄设备仍然可以用作鼠标,因此 x11 所做的似乎只是在寻找要设置的几个关键位把某物当作老鼠。

Okay so back to the touchpad/joystick problem, I have not yet figured out how to simulate a touch pad to test exactly which bits need to be set for x11 to recognize a device as a touch pad, though I suspect that the BTN_TOUCH event plays a role in it.好的,回到触摸板/操纵杆问题,我还没有想出如何模拟触摸板来准确测试需要为 x11 设置哪些位才能将设备识别为触摸板,尽管我怀疑BTN_TOUCH事件正在播放其中的一个角色。 Whatever combination of event bits that causes x11 to recognize the device as a touchpad and move the pointer, it stands to reason that this combination is not typically found on a gamepad and that is what indicates to x11 that the joypad should not move the cursor despite it having the ABS_X and ABS_Y axes just like the touch pad.无论何种事件位组合导致 x11 将设备识别为触摸板并移动指针,这种组合通常不会在游戏手柄上找到,这就是向 x11 表明游戏手柄不应移动光标的原因。它具有ABS_XABS_Y轴,就像触摸板一样。 If I have time later I will try to figure out exactly what the combination is and update this solution.如果我以后有时间,我会尝试弄清楚究竟是什么组合并更新此解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM