Automatically enable touchpad after suspend

/usr/bin/restart-touchpad.sh

#!/bin/bash
echo "Restarting Touchpad just in case"
declare -x DISPLAY=":0.0"
declare -x XAUTHORITY="/home/"$USER"/.Xauthority"
xinput disable 'PNP0C50:00 06CB:CDB0 Touchpad'
xinput enable 'PNP0C50:00 06CB:CDB0 Touchpad'

(you may need to make this file executable with sudo chmod +x /usr/bin/restart-touchpad.sh)


~/.config/systemd/user/restart-touchpad.service

[Unit]
Description=Restart Touchpad
After=basic.target suspend.target hibernate.target

[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/usr/bin/restart-touchpad.sh

WantedBy=basic.target suspend.target hibernate.target

Then enable it:

systemctl enable restart-touchpad.service --user --now

Let me know how it goes. I think it should work :grin:

(EDIT - it seems some users may need to replace “$USER” in the above script with their actual username to reflect the actual path, ex: /home/cscs/.Xauthority)

5 Likes

Thanks for helping out! There still seems to be an issue with the systemd service.

Aug 23 10:59:33 yoga14s EnableTouchpad.sh[8873]: Restarting Touchpad just in case
Aug 23 10:59:33 yoga14s EnableTouchpad.sh[8874]: No protocol specified
Aug 23 10:59:33 yoga14s EnableTouchpad.sh[8874]: Unable to connect to X server
Aug 23 10:59:33 yoga14s EnableTouchpad.sh[8875]: No protocol specified
Aug 23 10:59:33 yoga14s EnableTouchpad.sh[8875]: Unable to connect to X server
Aug 23 10:59:33 yoga14s systemd[1]: enabletouchpad.service: Main process exited, code=exited, status=1/FAILURE

Anyone else with the same error messages?

The command correctly restarts the touchpad after suspend. The issue seems to be on the systemd side.

I tested this and couldnt reproduce your issue …
Are you sure its copied correctly?
It must be a user service as shown above.
Maybe also check what is

echo "$DISPLAY"

echo “$DISPLAY”
:0

I had correctly copied the content of the files.

Anyone else?

Some additional information on the drivers in case it’s useful:

sudo dmesg | egrep -i “(elan|hid|i2c)”
[ 1.924330] hid: raw HID events driver © Jiri Kosina
[ 1.963418] i2c_hid i2c-PNP0C50:00: supply vdd not found, using dummy regulator
[ 1.963447] i2c_hid i2c-PNP0C50:00: supply vddl not found, using dummy regulator
[ 1.998501] i2c_hid i2c-ITE8353:00: supply vdd not found, using dummy regulator
[ 1.998515] i2c_hid i2c-ITE8353:00: supply vddl not found, using dummy regulator
[ 2.490113] i2c_hid i2c-PNP0C50:00: failed to retrieve report from device.
[ 2.490179] input: PNP0C50:00 06CB:CDB0 Mouse as /devices/platform/AMDI0010:00/i2c-0/i2c-PNP0C50:00/0018:06CB:CDB0.0001/input/input12
[ 2.490353] input: PNP0C50:00 06CB:CDB0 Touchpad as /devices/platform/AMDI0010:00/i2c-0/i2c-PNP0C50:00/0018:06CB:CDB0.0001/input/input13
[ 2.490464] hid-generic 0018:06CB:CDB0.0001: input,hidraw0: I2C HID v1.00 Mouse [PNP0C50:00 06CB:CDB0] on i2c-PNP0C50:00
[ 2.491079] hid-generic 0018:048D:8353.0002: hidraw1: I2C HID v1.00 Device [ITE8353:00 048D:8353] on i2c-ITE8353:00
[ 2.545474] i2c_hid i2c-PNP0C50:00: failed to retrieve report from device.
[ 2.545534] input: PNP0C50:00 06CB:CDB0 Mouse as /devices/platform/AMDI0010:00/i2c-0/i2c-PNP0C50:00/0018:06CB:CDB0.0001/input/input15
[ 2.545593] input: PNP0C50:00 06CB:CDB0 Touchpad as /devices/platform/AMDI0010:00/i2c-0/i2c-PNP0C50:00/0018:06CB:CDB0.0001/input/input16
[ 2.545628] hid-multitouch 0018:06CB:CDB0.0001: input,hidraw0: I2C HID v1.00 Mouse [PNP0C50:00 06CB:CDB0] on i2c-PNP0C50:00
[ 3.610592] Modules linked in: amd64_edac_mod(-) bnep uvcvideo btusb btrtl videobuf2_vmalloc btbcm videobuf2_memops videobuf2_v4l2 btintel videobuf2_common bluetooth videodev mc ecdh_generic ecc squashfs hid_sensor_als hid_sensor_trigger industrialio_triggered_buffer kfifo_buf hid_sensor_iio_common loop joydev mousedev industrialio hid_multitouch hid_sensor_hub snd_acp3x_pdm_dma snd_acp3x_rn snd_soc_dmic hid_generic wmi_bmof snd_soc_core snd_compress ac97_bus amdgpu snd_pcm_dmaengine iwlmvm nls_iso8859_1 mac80211 nls_cp437 snd_hda_codec_realtek edac_mce_amd vfat kvm_amd snd_hda_codec_generic ledtrig_audio fat kvm snd_hda_codec_hdmi libarc4 gpu_sched snd_hda_intel i2c_algo_bit snd_intel_dspcfg snd_hda_codec ttm irqbypass iwlwifi snd_hda_core drm_kms_helper snd_hwdep crct10dif_pclmul snd_pcm crc32_pclmul ghash_clmulni_intel aesni_intel cec snd_timer crypto_simd cryptd rc_core ideapad_laptop glue_helper cfg80211 sparse_keymap rapl syscopyarea input_leds pcspkr snd sysfillrect sysimgblt
[ 3.610618] tpm_crb k10temp fb_sys_fops sp5100_tco ccp soundcore snd_rn_pci_acp3x ucsi_acpi i2c_piix4 snd_pci_acp3x rfkill typec_ucsi tpm_tis typec evdev wmi battery i2c_hid mac_hid tpm_tis_core hid acpi_cpufreq tpm pinctrl_amd rng_core ac drm uinput sg crypto_user agpgart ip_tables x_tables ext4 crc32c_generic crc16 mbcache jbd2 serio_raw atkbd libps2 xhci_pci xhci_pci_renesas crc32c_intel xhci_hcd i8042 serio

lsmod | egrep -i “(elan|hid|i2c)”
hid_sensor_als 20480 0
hid_sensor_trigger 20480 2 hid_sensor_als
industrialio_triggered_buffer 16384 1 hid_sensor_trigger
hid_sensor_iio_common 20480 2 hid_sensor_trigger,hid_sensor_als
industrialio 90112 4 industrialio_triggered_buffer,hid_sensor_trigger,kfifo_buf,hid_sensor_als
hid_multitouch 32768 0
hid_sensor_hub 24576 3 hid_sensor_trigger,hid_sensor_iio_common,hid_sensor_als
hid_generic 16384 0
i2c_algo_bit 16384 1 amdgpu
i2c_piix4 28672 0
i2c_hid 32768 0
mac_hid 16384 0
hid 143360 4 i2c_hid,hid_multitouch,hid_sensor_hub,hid_generic

ls -l /sys/bus/i2c/devices/
total 0
lrwxrwxrwx 1 root root 0 Aug 23 10:42 i2c-0 -> …/…/…/devices/platform/AMDI0010:00/i2c-0
lrwxrwxrwx 1 root root 0 Aug 23 10:42 i2c-1 -> …/…/…/devices/platform/AMDI0010:03/i2c-1
lrwxrwxrwx 1 root root 0 Aug 23 11:06 i2c-2 -> …/…/…/devices/pci0000:00/0000:00:14.0/i2c-2
lrwxrwxrwx 1 root root 0 Aug 23 11:06 i2c-3 -> …/…/…/devices/pci0000:00/0000:00:14.0/i2c-3
lrwxrwxrwx 1 root root 0 Aug 23 11:06 i2c-4 -> …/…/…/devices/pci0000:00/0000:00:14.0/i2c-4
lrwxrwxrwx 1 root root 0 Aug 23 11:06 i2c-5 -> …/…/…/devices/pci0000:00/0000:00:08.1/0000:03:00.0/i2c-5
lrwxrwxrwx 1 root root 0 Aug 23 11:06 i2c-6 -> …/…/…/devices/pci0000:00/0000:00:08.1/0000:03:00.0/i2c-6
lrwxrwxrwx 1 root root 0 Aug 23 11:06 i2c-7 -> …/…/…/devices/pci0000:00/0000:00:08.1/0000:03:00.0/i2c-7
lrwxrwxrwx 1 root root 0 Aug 23 11:06 i2c-8 -> …/…/…/devices/pci0000:00/0000:00:08.1/0000:03:00.0/drm/card0/card0-eDP-1/i2c-8
lrwxrwxrwx 1 root root 0 Aug 23 11:06 i2c-9 -> …/…/…/devices/pci0000:00/0000:00:08.1/0000:03:00.0/drm/card0/card0-DP-1/i2c-9
lrwxrwxrwx 1 root root 0 Aug 23 10:42 i2c-ITE8353:00 -> …/…/…/devices/platform/AMDI0010:03/i2c-1/i2c-ITE8353:00
lrwxrwxrwx 1 root root 0 Aug 23 10:42 i2c-PNP0C50:00 -> …/…/…/devices/platform/AMDI0010:00/i2c-0/i2c-PNP0C50:00

Other Ideapad models seem to have issues with drivers but this one doesn’t seem to use elants - https://wiki.archlinux.org/index.php/Lenovo_IdeaPad_5_15are05#Touchpad`

A quick thing to check… … can you edit the script and replace “$USER” with your actual username and check that ? (so that it reflects the actual path, ex - /home/cscs/.Xauthority)

Yes!!! It works! Thank you, thank you, thank you! :grinning: :grinning:

Hm. Yeah thats more sure… but I thought I had gotten it with the env var … owell
but hey … glad it worked in the end :slight_smile:
cheers!

I was getting a Failed message on reboot and edited the systemd file to exclude the basic.target. My file now includes:

[Unit]
Description=Restart Touchpad
After=suspend.target hibernate.target

[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/usr/local/bin/EnableTouchpad.sh

[Install]
WantedBy=suspend.target hibernate.target

Once again, thanks @cscs!

1 Like

Ah … yes it was designed to start at first login too.
That can mean it starts too fast in that case … so in another case a ~ sleep 5 was put on the beginning because at boot the script started before the module was loaded.
But your solution makes more sense for your scenario - dont need it at boot, dont need a wait.
cheers :slight_smile:

Glad it works for h_ramus! :grinning:

On my side I get an error when trying to enable the service:

systemctl enable restart-touchpad.service --user --now

The output is:

The unit files have no installation config (WantedBy=, RequiredBy=, Also=, Alias= settings in the [Install] section, and DefaultInstance= for template units). This means they are not meant to be enabled using systemctl.

Possible reasons for having this kind of units are: • A unit may be statically enabled by being symlinked from another unit's .wants/ or .requires/ directory. • A unit's purpose may be to act as a helper for some other unit which has a requirement dependency on it. • A unit may be started when needed via activation (socket, path, timer, D-Bus, udev, scripted systemctl call, ...). • In case of template units, the unit is meant to be enabled with some instance name specified.

Whereas the file ~/.config/systemd/user/restart-touchpad.service does exist and is executable (owned by me).
I had to create the directories systemd/user in my .config, so I am wondering if systemd is really looking into it. Is there some sort of user declaration to be done with systemd?

Hi. I think the systemd restart-touchpad.service file was missing [Install]. Check that your file includes

[Install]
WantedBy=suspend.target hibernate.target

Thanks! I was able to enable the service with:

systemctl enable restart-touchpad.service --user --now

But it still does not work after suspend and when I look at the status with:

systemctl status restart-touchpad.service --user

I get:

● restart-touchpad.service - Restart Touchpad
Loaded: loaded (/home/bapman/.config/systemd/user/restart-touchpad.service; enabled; vendor preset: enabled)
Active: inactive (dead)

Although I went on suspend, there is no log of that in the status.

The content of /home/bapman/.config/systemd/user/restart-touchpad.service is:

[Unit]
Description=Restart Touchpad
After=suspend.target hibernate.target

[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/usr/local/bin/restart-touchpad.sh

[Install]
WantedBy=suspend.target hibernate.target

And when I source /usr/local/bin/restart-touchpad.sh directly from the terminal, it works!

Quick question. Did you enable the service after editing the systemd file? Enabling the systemd service binds the targets to the service making it run when either suspend or hibernate is activated.

If it was already enabled, try disabling and then enabling to rebind targets.

systemctl disable restart-touchpad && systemctl enable restart-touchpad

I tried it but it made no change.

Note that I need to add “--user” to every command or I get the error “Failed to disable unit: Unit file restart-touchpad.service does not exist.

systemctl disable restart-touchpad --user && systemctl enable restart-touchpad --user

hum…my systemd service is owned by root. Is your restart-touchpad.service owned by root or the user? If the user try chown to root:root and see if that works. If I add --user to the systemctl command it fails for me.

Now it works, thanks!

I followed the instructions given by cscs and the service was belonging to my user (and stored in ~/.config). With the service owned by root and stored in /etc/systemd/system/, it finally works!

Again, thanks to you and cscs.

That’s great to hear! Hopefully this settles the touchpad issues that one might face.

Someone found a way to edit acpi dsdt table to advertise the lid button and enable the laptop to wakeup when the lid opens.

The dsdt patch file is included in - https://gist.github.com/polikutinevgeny/7d673fe2453d88461ab06edfd7556d14. This is a comment to the original reddit post on enabling S3 sleep.

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