You are not logged in.

#1 2018-02-02 19:39:58

KoboldDresden
Member
From: Dresden, Germany
Registered: 2015-08-27
Posts: 6

GNOME: Touchpad on/off, when mouse connected/disconnected (script)

Save as file, exec chmod a+x <name of file> then, and put it in autostart

#!/bin/bash

# Use lsusb to find the id, then place them here
MOUSE_ID="045e:00cb"

while true; do
	TOUCHPAD_STATE=`gsettings get org.gnome.desktop.peripherals.touchpad send-events`
	MOUSE_PRESENT=`lsusb | grep "$MOUSE_ID"`


	if [ "$MOUSE_PRESENT" ] && [ "$TOUCHPAD_STATE" = "'enabled'" ]; then
		echo "Disable touchpad."
		gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled
	elif [ -z "$MOUSE_PRESENT" ] && [ "$TOUCHPAD_STATE" = "'disabled'" ]; then
		echo "Enable touchpad."
		gsettings set org.gnome.desktop.peripherals.touchpad send-events enabled
	fi

	sleep 1
done

exit 0

Last edited by KoboldDresden (2018-02-02 19:40:22)

Offline

#2 2018-02-02 19:52:28

ooo
Member
Registered: 2013-04-10
Posts: 1,638

Re: GNOME: Touchpad on/off, when mouse connected/disconnected (script)

Is there a reason for not simply using an udev rule to run the gsettings command when you plug/unplug the mouse?

Running an infinite looping bash script is extremely ugly solution for this imho.

Offline

#3 2018-02-02 20:22:41

KoboldDresden
Member
From: Dresden, Germany
Registered: 2015-08-27
Posts: 6

Re: GNOME: Touchpad on/off, when mouse connected/disconnected (script)

Arch now uses libinput for touchpad too, so we can't use synclient to switch the touchpad on/off. And gsettings must run in user mode. That is, why I use a bash script.

Offline

#4 2018-02-02 23:01:07

Steef435
Member
Registered: 2013-08-29
Posts: 577
Website

Re: GNOME: Touchpad on/off, when mouse connected/disconnected (script)

I would be unpleasantly surprised if GNOME didn't have some sort of setting for this. Have you thought of just unloading the driver module for your touchscreen? (in an udev rule)

Offline

#5 2018-02-02 23:11:40

Xabre
Member
From: Serbia
Registered: 2009-03-19
Posts: 750

Re: GNOME: Touchpad on/off, when mouse connected/disconnected (script)

gsettings get org.gnome.desktop.peripherals.touchpad send-events

so something like

#!/bin/bash

key="org.gnome.desktop.peripherals.touchpad"
val="send-events" ;curr="$key $val"

if [ "$(gsettings get $curr)" == "'enabled'" ]
then
 gsettings set $key $val disabled
else
 gsettings set $key $val enabled
fi

should be good enough.

EDIT: Duh, I've just realized you need a script to do it on mouse being plugged in. Still, might help with that too, gsettings is the way.

Last edited by Xabre (2018-02-02 23:17:09)

Offline

#6 2018-02-02 23:16:30

ooo
Member
Registered: 2013-04-10
Posts: 1,638

Re: GNOME: Touchpad on/off, when mouse connected/disconnected (script)

KoboldDresden wrote:

And gsettings must run in user mode.

I believe you could use 'su' in the user script to run gsettings as user, similarily to this.

However Xabre hinted an even better solution for your case.

EDIT: Xabre edited his post.

I think you could just use 'disabled-on-external-mouse' value for 'org.gnome.desktop.peripherals.touchpad send-events', and not use any scripts.

Last edited by ooo (2018-02-02 23:22:48)

Offline

#7 2018-02-03 09:50:27

KoboldDresden
Member
From: Dresden, Germany
Registered: 2015-08-27
Posts: 6

Re: GNOME: Touchpad on/off, when mouse connected/disconnected (script)

Thank you so much, your solution with 'disabled-on-external-mouse' is the right way.

Offline

Board footer

Powered by FluxBB