bulletmark / libinput-gestures

Actions gestures on your touchpad using libinput
3.9k stars 241 forks source link

Attaching/Detaching Apple Magic Trackpad 2 to/from machine requires restart to recognize gestures #261

Closed martinseener closed 4 years ago

martinseener commented 4 years ago
libinput-gestures: session cinnamon+x11 on Linux-5.3.0-40-generic-x86_64-with-LinuxMint-19.3-tricia, python 3.6.9, libinput 1.10.4
/usr/bin/libinput-gestures: hash 43697ae8c78269fe222a2bbd60d75a2f
Gestures configured in ~/.config/libinput-gestures.conf:
swipe left       4 _internal ws_left
swipe right      4 _internal ws_right
swipe up         3 xdotool key XF86AudioRaiseVolume
swipe down       3 xdotool key XF86AudioLowerVolume
swipe down       4 xdotool key Ctrl+Alt+Down
swipe right      3 xdotool key alt+Left
swipe left       3 xdotool key alt+Right
swipe up         4 xdotool key Ctrl+Alt+Up
pinch out        3 xdotool key super+s
libinput-gestures: device /dev/input/by-path/pci-0000:00:14.0-usb-0:2.3.4:1.1-event-mouse(event6): Apple Inc. Magic Trackpad 2

I'm using an Thinkpad X1 Carbon 7th with Linux Mint 19.3 and I use it standalone or sometimes attached to a Thinkpad USB-C Dock where the above mentioned Magic Trackpad 2 is attached. Everytime I unplug or re-plug the trackpad (or the whole dock) i have to restart libinput-gestures in order for my gestures above to be recognized again by the built-in trackpad or the magic trackpad.

As long as they're attached and libinput-gestures is restart, everything works perfect. Is there a way to detect (un-)plugs and restart libinput-gestures automatically or somehow otherwise recognize this? Already tried dbus-action but the setting shown there is only for Sleep and i wasn't able to figure out the event with dbus-action -m all (Only see NameOwnerChanged but this also happens without plugging something). Help is highly appreciated. Upon reboot everything works (have libinput-gestures-setup autostart activated).

Thanks for this nice tool. It really enables me to use the gestures kinda like with my personal macbook!

martinseener commented 4 years ago

Just tried dbus-monitor --session and saw the following events upon "detaching" the trackpad:

method call time=1589038718.316426 sender=:1.42 -> destination=org.freedesktop.DBus serial=34 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
   string "type='signal',interface='ca.desrt.dconf.Writer',path='/ca/desrt/dconf/Writer/user',arg0path='/org/cinnamon/settings-daemon/peripherals/input-devices/'"
method return time=1589038718.316482 sender=org.freedesktop.DBus -> destination=:1.42 serial=31 reply_serial=34
method call time=1589038718.316521 sender=:1.42 -> destination=org.freedesktop.DBus serial=35 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',interface='ca.desrt.dconf.Writer',path='/ca/desrt/dconf/Writer/user',arg0path='/org/cinnamon/settings-daemon/peripherals/input-devices/'"
method return time=1589038718.316602 sender=org.freedesktop.DBus -> destination=:1.42 serial=32 reply_serial=35

Upon re-attaching it i saw the following:

method call time=1589038725.523646 sender=:1.20 -> destination=org.freedesktop.DBus serial=33 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
   string "type='signal',interface='ca.desrt.dconf.Writer',path='/ca/desrt/dconf/Writer/user',arg0path='/org/gnome/libgnomekbd/keyboard/'"
method return time=1589038725.523710 sender=org.freedesktop.DBus -> destination=:1.20 serial=30 reply_serial=33
method call time=1589038725.523773 sender=:1.20 -> destination=org.freedesktop.DBus serial=34 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',interface='ca.desrt.dconf.Writer',path='/ca/desrt/dconf/Writer/user',arg0path='/org/gnome/libgnomekbd/keyboard/'"
method return time=1589038725.523803 sender=org.freedesktop.DBus -> destination=:1.20 serial=31 reply_serial=34
method call time=1589038725.529005 sender=:1.42 -> destination=org.freedesktop.DBus serial=36 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=AddMatch
   string "type='signal',interface='ca.desrt.dconf.Writer',path='/ca/desrt/dconf/Writer/user',arg0path='/org/cinnamon/settings-daemon/peripherals/input-devices/'"
method return time=1589038725.529063 sender=org.freedesktop.DBus -> destination=:1.42 serial=33 reply_serial=36
method call time=1589038725.529223 sender=:1.42 -> destination=org.freedesktop.DBus serial=37 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=RemoveMatch
   string "type='signal',interface='ca.desrt.dconf.Writer',path='/ca/desrt/dconf/Writer/user',arg0path='/org/cinnamon/settings-daemon/peripherals/input-devices/'"
method return time=1589038725.529263 sender=org.freedesktop.DBus -> destination=:1.42 serial=34 reply_serial=37

Please let me know if it helps somehow. Maybe you can help me here to find out what i should use for dbus-action tool for this kind of events. Would surely be also helpful for others later. Thanks alot for taking care!

bulletmark commented 4 years ago

Can you please do the following:

  1. Install dbus-action.
  2. Connect your touchpad.
  3. Run dbus-action -m all in a terminal.
  4. Disconnect your touchpad.
  5. Reconnect your touchpad.
  6. Paste the output of above command here. If there is a lot of noise then just paste the output obviously corresponding to the above two steps.

It should be possible to address this. I don't know a lot about dbus and just wrote dbus-action in a very simple way to address the suspend/resume issue. Likely I can extend it to your use-case.

martinseener commented 4 years ago

Hi @bulletmark, thanks for helping. In the first run, while still WiFi was active, the putput with both disconnect then reconnect was in there:

session org.freedesktop.DBus NameAcquired: :1.0
system org.freedesktop.DBus NameAcquired: :1.166
system org.freedesktop.DBus NameOwnerChanged: :1.167  :1.167
system org.freedesktop.DBus.Properties PropertiesChanged: org.freedesktop.NetworkManager.AccessPoint dbus.Dictionary({dbus.String('Strength'): dbus.Byte(67, variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
system org.freedesktop.DBus.Properties PropertiesChanged: org.freedesktop.NetworkManager.Device.Wireless dbus.Dictionary({dbus.String('Bitrate'): dbus.UInt32(780000, variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
system org.freedesktop.NetworkManager.AccessPoint PropertiesChanged: dbus.Dictionary({dbus.String('Strength'): dbus.Byte(67, variant_level=1)}, signature=dbus.Signature('sv'))
system org.freedesktop.NetworkManager.Device.Wireless PropertiesChanged: dbus.Dictionary({dbus.String('Bitrate'): dbus.UInt32(780000, variant_level=1)}, signature=dbus.Signature('sv'))
system org.freedesktop.DBus NameOwnerChanged: :1.168  :1.168
system org.freedesktop.DBus NameOwnerChanged: :1.168 :1.168 
system org.freedesktop.DBus.Properties PropertiesChanged: org.freedesktop.NetworkManager.Device.Wireless dbus.Dictionary({dbus.String('Bitrate'): dbus.UInt32(866700, variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
system org.freedesktop.NetworkManager.Device.Wireless PropertiesChanged: dbus.Dictionary({dbus.String('Bitrate'): dbus.UInt32(866700, variant_level=1)}, signature=dbus.Signature('sv'))
system org.freedesktop.DBus NameOwnerChanged: :1.169  :1.169
system org.freedesktop.DBus NameOwnerChanged: :1.170  :1.170
system org.freedesktop.DBus NameOwnerChanged: :1.170 :1.170 
system org.freedesktop.DBus NameOwnerChanged: :1.169 :1.169 
system org.freedesktop.DBus NameOwnerChanged: :1.167 :1.167 

With WiFi disabled I ran the same again:

mseener@Rubinesca ~ » sudo dbus-action -m all
session org.freedesktop.DBus NameAcquired: :1.0
system org.freedesktop.DBus NameAcquired: :1.190
system org.freedesktop.DBus NameOwnerChanged: :1.191  :1.191
system org.freedesktop.DBus NameOwnerChanged: :1.192  :1.192
system org.freedesktop.DBus NameOwnerChanged: :1.192 :1.192 
system org.freedesktop.DBus NameOwnerChanged: :1.193  :1.193
system org.freedesktop.DBus NameOwnerChanged: :1.194  :1.194
system org.freedesktop.DBus NameOwnerChanged: :1.194 :1.194 
system org.freedesktop.DBus NameOwnerChanged: :1.193 :1.193 
system org.freedesktop.DBus NameOwnerChanged: :1.191 :1.191 
system org.freedesktop.DBus NameOwnerChanged: :1.195  :1.195
system org.freedesktop.DBus NameOwnerChanged: :1.196  :1.196

For all tests I used "sudo dbus-action -m all". Obviously only those NameOwnerChanged things come up. Also interesting is, after reconnecting those GNOME defaults like 2-finger scrolling, Touch-click and so on work, but not those additional gestures configured.

bulletmark commented 4 years ago

Please do the test again as I stated, i.e. please do not run it using sudo.

martinseener commented 4 years ago

Hi, i did but sadly it doesn't help. This is the output containing both (disconnect/reconnect).

session org.freedesktop.DBus NameAcquired: :1.212
system org.freedesktop.DBus NameAcquired: :1.237
session org.kde.StatusNotifierItem NewIcon:
session org.freedesktop.DBus.Properties PropertiesChanged: org.x.StatusIcon dbus.Dictionary({dbus.String('IconName'): dbus.String('indicator-cpufreq-75', variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
session org.kde.StatusNotifierItem NewIcon:
session org.freedesktop.DBus.Properties PropertiesChanged: org.x.StatusIcon dbus.Dictionary({dbus.String('IconName'): dbus.String('indicator-cpufreq-50', variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
session org.kde.StatusNotifierItem NewIcon:
session org.freedesktop.DBus.Properties PropertiesChanged: org.x.StatusIcon dbus.Dictionary({dbus.String('IconName'): dbus.String('indicator-cpufreq-25', variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
system org.freedesktop.DBus NameOwnerChanged: :1.238  :1.238
session org.kde.StatusNotifierItem NewIcon:
session org.freedesktop.DBus.Properties PropertiesChanged: org.x.StatusIcon dbus.Dictionary({dbus.String('IconName'): dbus.String('indicator-cpufreq-75', variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
system org.freedesktop.DBus NameOwnerChanged: :1.239  :1.239
session org.kde.StatusNotifierItem NewIcon:
session org.freedesktop.DBus.Properties PropertiesChanged: org.x.StatusIcon dbus.Dictionary({dbus.String('IconName'): dbus.String('indicator-cpufreq-50', variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
system org.freedesktop.DBus NameOwnerChanged: :1.239 :1.239 
session org.kde.StatusNotifierItem NewIcon:
session org.freedesktop.DBus.Properties PropertiesChanged: org.x.StatusIcon dbus.Dictionary({dbus.String('IconName'): dbus.String('indicator-cpufreq-75', variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
session org.kde.StatusNotifierItem NewIcon:
session org.freedesktop.DBus.Properties PropertiesChanged: org.x.StatusIcon dbus.Dictionary({dbus.String('IconName'): dbus.String('indicator-cpufreq-25', variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
system org.freedesktop.DBus NameOwnerChanged: :1.240  :1.240
system org.freedesktop.DBus NameOwnerChanged: :1.241  :1.241
system org.freedesktop.DBus NameOwnerChanged: :1.241 :1.241 
system org.freedesktop.DBus NameOwnerChanged: :1.240 :1.240 
system org.freedesktop.DBus NameOwnerChanged: :1.238 :1.238 
system org.freedesktop.DBus NameOwnerChanged: :1.242  :1.242
session org.kde.StatusNotifierItem NewIcon:
session org.freedesktop.DBus.Properties PropertiesChanged: org.x.StatusIcon dbus.Dictionary({dbus.String('IconName'): dbus.String('indicator-cpufreq-50', variant_level=1)}, signature=dbus.Signature('sv')) dbus.Array([], signature=dbus.Signature('s'))
system org.freedesktop.DBus NameOwnerChanged: :1.243  :1.243

I ran without sudo and I also tried to directly connect/disconnect from the machine, with no ThinkDock in between. The only messages immediatly coming after disconnect and reconnect are those NameOwnerChanged ones.

bulletmark commented 4 years ago

I don't understand why you say "it doesn't help"? All we need is a single dbus message immediately after disconnect, and another distinct message immediately after re-connect, which we can discriminate and thus we can trigger on to stop and start libinput-gestures. So exactly which are the two NameOwnerChanged messages we can trigger off/on?

martinseener commented 4 years ago

I say that because it obviously doesn't seem to make any difference. The disconnect/reconnect in dbus-action only seem to trigger this NameOwnerChanged and the numbers behind them are counting up each time i disconnect/reconnect. So for the test above it was 1.237....now i tried again several times (3x after each other with about 5sec waiting in between). and the numbers are going up now until 1.290. So you obviously can't use them to distinguish wether it's the trackpad or not.

Or do I don't see anything that you do?

bulletmark commented 4 years ago

Well you did not identify the places in that log where you did the disconnect and reconnect so I could not tell. I'm surprised there is no unique dbus message indicating these actions. Can you please run the following Python code and see if there are messages when you disconnect/reconnect?

#!/usr/bin/python3
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib
DBusGMainLoop(set_as_default=True)

def cb(*args):
    print('Received:', args)

bus = dbus.SystemBus()
bus.add_signal_receiver(cb, 'InterfacesAdded',
        'org.freedesktop.DBus.ObjectManager')

GLib.MainLoop().run()
martinseener commented 4 years ago

Sorry! Then i just wasn't clear enough. I tried to run your python script as python3 test.py and once directly in the python3 CLI. The test.py just ran but upon disconnect/reconnect no ouput was raised. When run in CLI i got the following error:

Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>> from dbus.mainloop.glib import DBusGMainLoop
>>> from gi.repository import GLib
>>> DBusGMainLoop(set_as_default=True)
<dbus.mainloop.NativeMainLoop object at 0x7fe592eddd20>
>>> def cb(*args):
...     print('Received:', args)
... bus = dbus.SystemBus()
  File "<stdin>", line 3
    bus = dbus.SystemBus()
       ^
SyntaxError: invalid syntax
bulletmark commented 4 years ago

Don't worry about doing that test.

If you are keen you could try to write a udev rule that ran a user script when the device is disconnected and reconnected but it will be difficult because the script needs access to your session environment (which dbus-action gets because it is started by the session). Sorry, that is out of scope of this tool so I am closing this bug.