You are not logged in.

#1 2013-09-26 14:22:17

bobwya
Member
Registered: 2012-01-09
Posts: 36

Better solution to disabling touchpad on external mouse connection??

Hi all,

I've been playing around with a "clean" solution to disabling the Synaptics touchpad on my laptop - when I connected a USB external mouse OR when the USB mouse is already connected at boot...

I have a very hacked together solution... First for info the stock "mouse" devices on laptop...

lrwxrwxrwx  1 root root 0 26.09.2013 12:38 mouse0 -> ../../devices/virtual/input/input6/mouse0/
lrwxrwxrwx  1 root root 0 26.09.2013 12:38 mouse1 -> ../../devices/platform/i8042/serio4/input/input14/mouse1/

FYI MCE IR Keyboard/Mouse (ite-cir) and Synaptics touchpad respectively.

So I have a simple script...

#! /bin/bash

username=$(users | gawk '{print $1}')
export DISPLAY=":0"
export XAUTHORITY="/home/${username}/.Xauthority"


if $(lsusb -v | grep -q Mouse); then
        synclient TouchpadOff=1
else
        synclient TouchpadOff=0
fi

exit 0

that is called by a udev (/etc/udev/rules.d/01-touchpad.rules ) rule...

ACTION=="add", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{ID_CLASS}="mouse", PROGRAM="/root/Scripts/mouse_detect.sh"
ACTION=="remove", SUBSYSTEM=="input", KERNEL=="mouse[0-9]", ENV{ID_CLASS}="mouse", PROGRAM="/root/Scripts/mouse_detect.sh"

Problem is that solution does not fire when I logout and login again, or boot from cold, into KDM/KDE... My hack to solve this problem was the following (awful!!) systemd unit...

[Unit]
Description=Mouse Detect (on Desktop Environment startup)
After=display-manager.service
Requires=display-manager.service

[Service]
Type=oneshot
RestartSec=20
Restart=always
ExecStart=/root/Scripts/mouse_detect.sh

[Install]
WantedBy=graphical.target

It's stored as mouse-detect.service in /etc/systemd/system ... It fires too early, probably when KDM is active (hence why it auto-restarts every 20 seconds).... Not even sure if it's possible to get the mouse_detect.sh script to work during the KDM Session (as I'm not sure where the Xauthority information is stored for KDM and so on)...

If I make it the service unit stop on a successful run of synclient (e.g. Restart=onfailure) - it won't every refire - if say I logout and log back into my KDE session!!

Any thoughts on how to do this more cleanly?? smile
Given that the current solution works - I was just looking to learn some more - by implementing a less hacked version!!  cool

Thanks
Bob

Last edited by bobwya (2013-09-26 14:25:52)

Offline

#2 2013-09-26 16:05:03

Zamajalo
Member
From: Belgrade, Serbia
Registered: 2013-08-26
Posts: 17

Re: Better solution to disabling touchpad on external mouse connection??

What about using one simple udev rule? Manual can be found here

Last edited by Zamajalo (2013-09-26 16:08:39)


Using Arch Linux x86-64 (linux-ck-bobcat kernel) on AMD based laptop with HD 7400 series GPU.

dd if=/dev/null of=/dev/everything

Offline

#3 2013-09-26 17:18:39

bobwya
Member
Registered: 2012-01-09
Posts: 36

Re: Better solution to disabling touchpad on external mouse connection??

Zamajalo wrote:

What about using one simple udev rule? Manual can be found here

The udev rule falls down when you boot with a USB mouse already attached to the laptop - on boot (as I clearly stated). The rule only detects change of state (mouse attached or detached). Also what if you have 2 USB mice attached?? :-) The udev idea of what a "mouse" is - is also rather generic (e.g. touchpad, infrared remote control are definitely not USB mice!!)

The script is overkill for running from a udev rule (- although it does have the benefit of not have a hard-coded username). However the script is necessary to test for a mouse being attached - when a KDE session starts. That was basically what my question was about... How to run this script at the start of the KDE session - my use of lsusb is annoying - because it means the script must run as root (due to the verbose flag)... There must be a way to do this as a normal desktop user (and then the script should run OK in a normal autostart desktop script).

Thanks
Bob

Offline

#4 2013-09-26 18:24:07

Zamajalo
Member
From: Belgrade, Serbia
Registered: 2013-08-26
Posts: 17

Re: Better solution to disabling touchpad on external mouse connection??

Sorry, my bad.

Best way to enable/disable touchpad when mouse is inserted is udev... as far as I know.

Your second problem is that you can't disable touchpad on login, when mouse is present. One of solutions is to run your mouse presence check on login, You can (instead of calling lsusb) use xinput. I wrote this script and added it to XFCE's autostart (and tested it right now, works like a charm and should work with other desktop environments):

#!/bin/bash
list=`xinput --list | grep -i 'mouse'`

if [ ${#list} -eq 0 ]; then
	exec  `synclient touchpadoff=0`
	notify-send "Touchpad on" "Mouse not present"
else
	exec `synclient touchpadoff=1`
	notify-send "Touchpad off" "Mouse present"
fi

It's quite simple, and it doesn't require root permissions, and should fix the problem with not disabling touchpad when mouse is available on boot.

I only don't have 2 usb mice, so I can't test is it working in that situation smile

I hope this helps you somehow.


Using Arch Linux x86-64 (linux-ck-bobcat kernel) on AMD based laptop with HD 7400 series GPU.

dd if=/dev/null of=/dev/everything

Offline

#5 2014-05-04 23:27:24

toffi-fee
Member
Registered: 2014-05-04
Posts: 6

Re: Better solution to disabling touchpad on external mouse connection??

Hey, I hope it's okay to dig this up. Have you tried creating a .desktop file in /etc/xdg/autostart with following content?

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/path/to/your/script.sh
Name=DisableTouchpadOnMouse
Icon=

It works for me, since the desktop files are only called after the session is up.

Offline

Board footer

Powered by FluxBB