Regra UDEV para detecção de mouse externo para ativar e desativar o Touchpad

1

A regra do udev a seguir funciona parcialmente, mas desativará o touchpad se o mouse Bluetooth for desconectado.

Eu tenho notado que xinput atualiza se o mouse é adicionado, o que pega a primeira parte da regra UDEV no entanto xinput não atualiza se esse mesmo mouse estiver desconectado, como em remover o mouse bluetooth da lista de xinput. Eu estava pensando que talvez esse seja o problema com a reativação do touchpad, mas não tenho idéia de como fazê-lo?

/etc/udev/rules.d/01-touchpad.rules

SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/username/.Xauthority", RUN+="/usr/bin/synclient TouchpadOff=1"
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/username/.Xauthority", RUN+="/usr/bin/synclient TouchpadOff=0"

De link

    
por zgwolfe 13.09.2016 / 23:06

2 respostas

0

Foi assim que funcionou para mim no Ubuntu 16.04.

Primeiro, crie o script para ativar e desativar o touchpad. Saiba como o touchpad é chamado:

xinput list

Emseguida,crieoarquivoNAMEOFSCRIPT.sh

#!/bin/sh # # Enables the touchpad if and only if there aren't any external mice connected. # # Originally from: # https://wiki.archlinux.org/index.php/Touchpad_Synaptics#System_with_multiple_X_sessions #Here puts how is named TOUCHPAD="PS/2 Synaptics TouchPad" FOUND=0 for MOUSE in 'find /sys/class/input -name mouse\*' do if [ "'cat $MOUSE/device/name'" != "$TOUCHPAD" ] then FOUND=1 #Find a Mouse device other than the TouchPad and record the variable. break fi done DISPLAY=:0 export DISPLAY for USER in 'w -h | cut -d\ -f1 | sort | uniq' do XAUTHORITY='sudo -Hiu $USER env | grep ^HOME= | cut -d= -f2'/.Xauthority export XAUTHORITY TOUCHPADDEVICE=$(($(xinput list | grep -i touchpad | cut -d= -f2 | cut -d[ -f1)+0)) #Find the Touchpad Id if [ $FOUND -eq 1 ]; then #If another device is founded, disable touchpad xinput disable $TOUCHPADDEVICE else #else enable touchpad xinput enable $TOUCHPADDEVICE fi done

Não se esqueça de torná-lo executável!

chmod +x NAMEOFSCRIPT.sh

Em seguida, crie a regra (requer raiz)

gksudo gedit /etc/udev/rules.d/01-touchpad_toggle.rules  

(Pode ser qualquer nome, de preferência atribuir 01 ao início)

SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/**$USERNAME**/.Xauthority", RUN+="**PATH TO NAMEOFSCRIPT.SH**" 
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/**$USERNAME**/.Xauthority", RUN+="**PATH TO NAMEOFSCRIPT.SH**" 

Se tudo correr bem, quando eu conectar o mouse USB, ele desativa o Touchpad e, quando desconectado, ativa-o. Para aqueles que têm problemas para serem reconhecidos pelo mouse USB, execute lsusb desconectado e, em seguida, lsusb conectado.

Fontes: link

    
por Gerardo F 10.09.2017 / 20:18
0

Eu quero adicionar uma edição para pessoas desesperadas com o touchpad do ALPS que é reconhecido no Ubuntu 16.04 como um mouse e não como touchpad.

É suficiente modificar o script da seguinte forma:

#!/bin/sh 
# 
# Enables the touchpad if and only if there aren't any external mice connected. 
# 
# Originally from: 
#     https://wiki.archlinux.org/index.php/Touchpad_Synaptics#System_with_multiple_X_sessions

# This supports also ALPS touchpads.

#Here puts how is named (Run 'xinput list' for the name to put below)
TOUCHPAD="ALP..." 
FOUND=0 

for MOUSE in 'find /sys/class/input -name mouse\*' 
do 
    if [ "'cat $MOUSE/device/name'" != "$TOUCHPAD" ] 
    then 
        FOUND=1 
  #Find a Mouse device other than the TouchPad and record the variable.
        break 
    fi 
done 

DISPLAY=:0 
export DISPLAY 
for USER in 'w -h | cut -d\  -f1 | sort | uniq' 
do 
    XAUTHORITY='sudo -Hiu $USER env | grep ^HOME= | cut -d= -f2'/.Xauthority 
    export XAUTHORITY 
    TOUCHPADDEVICE=$(($(xinput list | grep -i "$TOUCHPAD" | cut -d= -f2 | cut -d[ -f1)+0)) 
#Find the Touchpad Id
    if [ $FOUND -eq 1 ]; then
#If another device is founded, disable touchpad
        xinput disable $TOUCHPADDEVICE
    else
#else enable touchpad
        xinput enable $TOUCHPADDEVICE
    fi
done
    
por Almet 13.01.2018 / 07:14