Turn mouse-pad off when connect external mouse

Hello,

I am quiet new to Endless :slight_smile: But so far it looks positive.

Just a quick question with hopefully a quick answer :slight_smile:

Is there a possibility to turn mouse-pad off when you plug in a external mouse true usb?
I have been searching, but didn’t found it yet. Maybe I’m overlooking something?

Thank you!

Hi,

this is a little more complex than it seems at a first glance. Essentially, you need to write a rule which is triggered by connecting the mouse. This rule then disables the internal touchpad and re-enables it, when the external mouse is disconnected.

Let’s do it.

Open a Terminal and make yourself root with:

sudo bash

Getting the required attributes to match the external mouse

Run:

udevadm monitor --kernel | grep mouse

then connect your mouse. You should see something like the following line. Remember the assigned mouse identifier (mouse1 in my case):

KERNEL[92396.856763] add      /devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.1/0003:046D:C534.0089/0003:046D:4054.008B/input/input126/mouse1 (input)
KERNEL[92403.075865] remove   /devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.1/0003:046D:C534.0089/0003:046D:4054.008B/input/input126/mouse1 (input)

Now query this device to retrieve it’s attributes. We need some of them to match the rule when connected:

udevadm info --query=all --attribute-walk /dev/input/mouse1

This will yield a long output. Search for your mouse and find the corresponding Vendor and Device ID. In my case, it’s:

ATTRS{idVendor}=="046d"
ATTRS{idProduct}=="c534"

Writing the Rule

Now we are ready to monitor the add and remove of the device. Create file /etc/udev/rules.d/99-mouse.rules and put the following lines in it:

KERNEL=="mouse?",SUBSYSTEMS=="usb",ATTRS{idVendor}=="046d",ATTRS{idProduct}=="c534",ACTION=="add",RUN+="/sysroot/home/egon/mouse.sh add"
KERNEL=="mouse?",SUBSYSTEMS=="usb",ATTRS{idVendor}=="046d",ATTRS{idProduct}=="c534",ACTION=="remove",RUN+="/sysroot/home/egon/mouse.sh remove"

You need to replace the Path to the shell script with your actual username. Please also note that you can’t simply used gedit to edit this file as it’s in a location where only root has write privileges. So use nano as the editor of your choice from within the terminal.

Writing the Script to do the heavy lifting

In the previous chapter, we referenced a file called mouse.sh which will essentially perform the necessary tasks of enabling and disabling the input devices. Create this file in your Home directory and put the following in it:

#!/bin/bash
export DISPLAY=:0
export DESTUSER=egon

echo $(whoami) $(date) ${1} DISPLAY=${DISPLAY}

if [ $(whoami) == "root" ]; then
	# we need to restart ourself as the appropriate user to be 
	# able to connect to the x-server without making further
	# changes to the system
	su --command "${0} ${1}" ${DESTUSER}
else
	if [ "${1}" == "add" ]; then
		xinput disable "Bluetooth Mouse M336/M337/M535 Mouse"
	fi

	if [ "${1}" == "remove" ]; then
		xinput enable "Bluetooth Mouse M336/M337/M535 Mouse"
	fi
fi

You need to adopt it to your needs, like changing the user (egon) to yours and also change the name of the device to enable/disable. To find your device name, use the following command in a terminal - open a new one where your are not root:

xinput list

this will yield something like:

|⎡ Virtual core pointer                    |id=2|[master pointer  (3)]|
|---|---|---|
|⎜   ↳ Virtual core XTEST pointer              |id=4|[slave  pointer  (2)]|
|⎜   ↳ Bluetooth Mouse M336/M337/M535 Mouse    |id=13|[slave  pointer  (2)]|
|⎣ Virtual core keyboard                   |id=3|[master keyboard (2)]|
|    ↳ Virtual core XTEST keyboard             |id=5|[slave  keyboard (3)]|
|    ↳ Power Button                            |id=6|[slave  keyboard (3)]|
|    ↳ Power Button                            |id=8|[slave  keyboard (3)]|
|    ↳ Sleep Button                            |id=9|[slave  keyboard (3)]|
|    ↳ Fujitsu FUJ02E3                         |id=7|[slave  keyboard (3)]|
|    ↳ Bluetooth Mouse M336/M337/M535 Keyboard |id=12|[slave  keyboard (3)]|
|    ↳ Sennheiser Sennheiser USB Headset       |id=11|[slave  keyboard (3)]|
|    ↳ Bluetooth Mouse M336/M337/M535 Consumer Control|id=14|[slave  keyboard (3)]|
|    ↳ Sennheiser Sennheiser USB Headset Consumer Control|id=10|[slave  keyboard (3)]|
|    ↳ Keyboard K380 System Control            |id=15|[slave  keyboard (3)]|
|    ↳ Keyboard K380 Keyboard                  |id=16|[slave  keyboard (3)]|
|    ↳ Keyboard K380 Consumer Control          |id=17|[slave  keyboard (3)]|

In my case i disabled the Bluetooth Mouse whenever i connect a external Logitech Nano Receiver based Mouse.

Uh whaat ??

I like your enthusiasm! And thank you very much for this explanation!

But I am new to all of this “coding, writing”.

I feel kinda frustrated as there isn’t just a simple switch to turn on or off.

There is an option to turn mouse-pad off, so why not give it an extra option?

As I said, this is all new to me and I’m already stuck on the first line…

I thought I could handle a pc quiet well, but now I just feel stupid.

Thank you!

Hi,

don’t feel stupid - some things which are simple on Windows, are hard on Linux, and Vice-Versa. This one’s a hard one on Linux, even for many People who use Linux on a daily basis.

I searched quite a bit for a simple solution to the issue before writing this article and it seems that this is a feature not many people need, so that’s probably the reason it hasn’t been implemented in the GUI yet.

Thank you egrath ! Really appreciate it !!
I think I will just turn off the mouse-pad when I’m on my desk and turn on before I unplug my external mouse… for now :slight_smile:

:+1:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.