小智 9
解决方案 - 自动
感谢 Esamo 和他的工作。
要在启动时添加用于连接鼠标的 AUTO 触发器:
创建文件: /etc/udev/rules.d/10-local.rules
填写以下内容:(将 $USER 替换为您的用户名)
ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/$USER/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/$USER/scripts/touchpad_switcher.sh false"
ACTION=="remove", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/$USER/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/$USER/scripts/touchpad_switcher.sh true"
Run Code Online (Sandbox Code Playgroud)
例子:
ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/dawid/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/dawid/scripts/touchpad_switcher.sh false"
ACTION=="remove", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{DISPLAY}=":0",ENV{XAUTHORITY}="/home/dawid/.Xauthority", ENV{ID_CLASS}="mouse", RUN+="/home/dawid/scripts/touchpad_switcher.sh true"
Run Code Online (Sandbox Code Playgroud)
接下来将您的脚本放置在您想要的任何位置。我把它放在 ~/scripts
touchpad_switcher.sh
#!/bin/sh
enabled=$1
touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2);
if $enabled
then
xinput set-prop $touchpad_id "Device Enabled" 1 | notify-send "The touchpad is now enabled." ""
else
xinput set-prop $touchpad_id "Device Enabled" 0 | notify-send "Disabling the touchpad..." ""
fi
Run Code Online (Sandbox Code Playgroud)
记得添加执行权限:
chmod +x touchpad_switcher.sh
现在只需重新启动!(仅仅重新启动 udev 似乎不起作用......)
其他一些有用的东西:
关于udev 规则的一些信息
解决方案 - 不是自动的
下面的脚本在执行时将禁用触摸板,如果连接了任何鼠标并显示通知。
touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2);
if xinput | grep -i "mouse" | grep -i "pointer"
then xinput set-prop $touchpad_id "Device Enabled" 0 |
notify-send "Disabling the touchpad..." ""
else xinput set-prop $touchpad_id "Device Enabled" 1 |
notify-send "The touchpad is now enabled." ""
fi
Run Code Online (Sandbox Code Playgroud)
还添加了一个相反的情况,尽管在我的情况下,无论如何触摸板都会在鼠标断开连接时启用。我已将脚本保存在一个文件中,并Unity Launcher
Terminal
在每次插入鼠标后从部分运行它。
先进的
更多的老鼠?
mouse
通过扩展"mouse"
片段中的值,基于xinput
设备列表的名称来澄清哪个应该停用触摸板。
害怕的老鼠从边缘跑到边缘?
我不得不为鼠标运行额外的命令 - 减少,cursor acceleration
因为它在每个连接上都被疯狂地设置为 10。实际上过了一段时间我制作了自动检测脚本(它获取鼠标 ID 和它的速度道具;不知道性能cut
)...
touchpad_id=$(xinput | grep -i "touchpad" | cut -f2 | cut -d '=' -f2);
mouse_id=$(xinput | grep -i "mouse" | grep -i 'pointer' | cut -f2 | cut -d '=' -f2);
mouse_prop=$(xinput list-props $mouse_id | grep -i "velocity" | cut -f2 | cut -d '(' -f2 | cut -d ')' -f1 );
if xinput | grep -i "mouse" | grep -i "pointer"
then xinput set-prop $touchpad_id "Device Enabled" 0 |
xinput set-prop $mouse_id $mouse_prop 3 |
notify-send "Disabling the touchpad..." ""
else xinput set-prop $touchpad_id "Device Enabled" 1 |
notify-send "The touchpad is now enabled." ""
fi
Run Code Online (Sandbox Code Playgroud)今天在上面学到了很多东西:D。
专业人士?
知道如何使其自动化会很有用。
也很好奇为什么不保存鼠标配置(2.)。
归档时间: |
|
查看次数: |
6831 次 |
最近记录: |