You are not logged in.

#1 2016-09-07 08:37:05

darch
Member
Registered: 2016-09-07
Posts: 2

[SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off

Hi there,

First off hello all, I'm new here! Just finised installing Arch on my thinkpad x220 and am working my way through the amazing wiki doing all the configurations.

I'm using the i3 window manager and wanted to configure my touchpad toggle on/off using the Fn button and a simple bash script using this guide here.

#!/bin/bash
if synclient -l | grep "TouchpadOff .*=.*0" ; then
    synclient TouchpadOff=1 ;
else
    synclient TouchpadOff=0 ;
fi

As I understand it reading here, the synaptics driver is being superceded by the libinput driver, however it appears that libinput does not support direct intervention via synclient.

Is there another way to implement a touchpad toggle on/off?

Last edited by darch (2017-02-08 21:31:40)

Offline

#2 2016-09-07 12:23:18

Ranmaru
Member
From: Japan
Registered: 2011-11-20
Posts: 60

Re: [SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off

Okay, this is hacky as hell, but it works using xinput instead of synclient.

#!/bin/bash

ID=`xinput --list | grep "TouchPad" | awk '{ print $6 }' | sed 's/id=//'`
status=`xinput list-props $ID | grep "Device Enabled" | awk '{ print $4 }'`

if [ $status == 1 ] ; then
	xinput set-prop $ID "Device Enabled" 0
else
	xinput set-prop $ID "Device Enabled" 1
fi

What this does it listing all your input devices, greps your touchpad and get its ID, checks whether it's already disabled via list-props, and if not, passes the disable command via set-props. If it is disabled, it does the same but passes the enable command.

If it doesn't work, echo the variables and make sure that awk gets the right things.

I am sure that there is a much cleaner solution, though.

Last edited by Ranmaru (2016-09-07 12:24:31)

Offline

#3 2016-09-07 14:13:30

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,722

Re: [SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off

Ranmaru wrote:

Okay, this is hacky as hell, but it works using xinput instead of synclient.


How about:

#!/bin/bash

if [ `xinput list-props "SynPS/2 Synaptics TouchPad" | grep "Device Enabled" | awk '{ print $4 }'` == 1 ]; then 

	xinput disable "SynPS/2 Synaptics TouchPad"
else
	xinput enable  "SynPS/2 Synaptics TouchPad"
fi

Not tested. Not a Bash jockey  I am sure there exists a better way to find the enabled state.  Check the name of your device and change the script as appropriate.

Personally, I have my system to disable the touchpad when I close the lid otherwise startling things happen and I'll open the lid to find hundreds of windows open.  I use acpi, like this:

#!/bin/bash
# Default acpi script that takes an entry for all actions

case "$1" in
    button/power)
        case "$2" in
            PBTN|PWRF)
                logger 'PowerButton pressed'
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    button/sleep)
        case "$2" in
            SLPB|SBTN)
                logger 'SleepButton pressed'
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC|ACAD|ADP0)
                case "$4" in
                    00000000)
                        logger 'AC unpluged'
                        ;;
                    00000001)
                        logger 'AC pluged'
                        ;;
                esac
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    battery)
        case "$2" in
            BAT0)
                case "$4" in
                    00000000)
                        logger 'Battery online'
                        ;;
                    00000001)
                        logger 'Battery offline'
                        ;;
                esac
                ;;
            CPU0)
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/lid)
        case "$3" in
            close)
                export XAUTHORITY=`ls -1 /home/*/.Xauthority | head -n 1`
                export DISPLAY=":`ls -1 /tmp/.X11-unix/ | sed -e s/^X//g | head -n 1`"
                xinput disable "SynPS/2 Synaptics TouchPad"
                #synclient TouchpadOff=1
                logger 'LID closed, touchpad off'
                ;;
            open)
                logger 'LID opened, touchpad on'
                export XAUTHORITY=`ls -1 /home/*/.Xauthority | head -n 1`
                export DISPLAY=":`ls -1 /tmp/.X11-unix/ | sed -e s/^X//g | head -n 1`"
                xinput enable "SynPS/2 Synaptics TouchPad"
                #synclient TouchpadOff=0
                ;;
            *)
                logger "ACPI action undefined: $3"
                ;;
        esac
        ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
esac
;;

Last edited by ewaller (2016-09-07 14:14:13)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#4 2016-09-07 14:40:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,546
Website

Re: [SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off

God kills a kitten every time you pipe through grep to awk.

xinput list-props "SynPS/2 Synaptics TouchPad" | grep -q "Device Enabled [^:]*: *1" &&
    xinput disable "SynPS/2 Synaptics TouchPad" ||
    xinput enable  "SynPS/2 Synaptics TouchPad"

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2016-09-07 14:58:47

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,422
Website

Re: [SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#6 2016-09-07 15:01:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,546
Website

Re: [SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off

That's not a problem in this case.  If it should be disabled and fails to disable, enabling it will do no harm.

Avoid overapplying heuristics without thinking about their current application tongue


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2016-09-07 15:03:12

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,722

Re: [SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off

Trilby wrote:

God kills a kitten every time you pipe through grep to awk.

Yeah, I know.   Could have written the whole thing in awk to begin with.  I decided to just make a first pass at improving what had been posted.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#8 2017-02-08 21:30:40

darch
Member
Registered: 2016-09-07
Posts: 2

Re: [SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off

Trilby wrote:

God kills a kitten every time you pipe through grep to awk.

xinput list-props "SynPS/2 Synaptics TouchPad" | grep -q "Device Enabled [^:]*:*1" &&
    xinput disable "SynPS/2 Synaptics TouchPad" ||
    xinput enable  "SynPS/2 Synaptics TouchPad"

Hi there, thanks for this elegant solution. Sorry for necro bumping, but I forgot about this thread.

I've found that the grep regex above will find the line whether the device is enabled or disabled, so changing the regex slightly removed the false positives. Not sure why it wasn't working before.

My final code:

if xinput list-props "SynPS/2 Synaptics TouchPad" | grep -q "Device Enabled [^:]*:[^10]*1"; then
     xinput disable "SynPS/2 Synaptics TouchPad"
else
     xinput enable "SynPS/2 Synaptics TouchPad"
fi

Then in my i3 config file I added the following line:

XF86TouchpadToggle exec ~/path/to/bash_script.sh

Thanks again.

Offline

#9 2017-02-08 21:55:26

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,546
Website

Re: [SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off

Sorry, somehow a space got lost after the colon.  I've revised the earlier post.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#10 2017-05-19 10:46:55

Ambrevar
Member
Registered: 2011-08-14
Posts: 212
Website

Re: [SOLVED]xf86-input-libinput vs synaptics: toggling the touchpad on/off

It's not a space but a tab on my system... So that'd be it for me:

xinput list-props "SynPS/2 Synaptics TouchPad" | grep -q "Device Enabled [^:]*:	1" &&
    xinput disable "SynPS/2 Synaptics TouchPad" ||
    xinput enable  "SynPS/2 Synaptics TouchPad"

Offline

Board footer

Powered by FluxBB