aboutsummaryrefslogtreecommitdiff
path: root/_posts/posts/2020-08-15-systemd-disable-wake-onmouse.md
diff options
context:
space:
mode:
Diffstat (limited to '_posts/posts/2020-08-15-systemd-disable-wake-onmouse.md')
-rw-r--r--_posts/posts/2020-08-15-systemd-disable-wake-onmouse.md74
1 files changed, 74 insertions, 0 deletions
diff --git a/_posts/posts/2020-08-15-systemd-disable-wake-onmouse.md b/_posts/posts/2020-08-15-systemd-disable-wake-onmouse.md
new file mode 100644
index 0000000..8122322
--- /dev/null
+++ b/_posts/posts/2020-08-15-systemd-disable-wake-onmouse.md
@@ -0,0 +1,74 @@
1---
2title: Disable mouse wake from suspend with systemd service
3permalink: /disable-mouse-wake-from-suspend-with-systemd-service.html
4date: 2020-08-15T12:00:00+02:00
5layout: post
6type: post
7draft: false
8---
9
10I recently bought [ThinkPad
11X220](https://www.laptopmag.com/reviews/laptops/lenovo-thinkpad-x220) just as a
12joke on eBay to test Linux distributions and play around with things and not
13destroy my main machine. Little to my knowledge I felt in love with it. Man,
14they really made awesome machines back then.
15
16After changing disk that came with it to SSD and installing Ubuntu to test if 
17everything works I noticed that even after a single touch of my external mouse
18the system would wake up from sleep even though the lid was shut down.
19
20I wouldn't even noticed it if laptop didn't have [LED
21sleep indicator](https://support.lenovo.com/lk/en/solutions/~/media/Images/ContentImages/p/pd025386_x1_status_03.ashx?w=426&h=262).
22I already had a bad experience with Linux and it's power management. I had a
23[Dell Inspiron 7537](https://www.pcmag.com/reviews/dell-inspiron-15-7537) laptop
24with a touchscreen and while traveling it decided to wake up and started cooking
25in my backpack to the point that the digitizer responsible for touch actually
26glue off and the whole screen got wrecked. So, I am a bit touchy about this.
27
28I went on solution hunting and to my surprise there is no easy way to disable
29specific devices to perform wake up. Why is this not under the power management 
30tab in setting is really strange.
31
32After googling for a solution I found [this nice article describing the
33solution](https://codetrips.com/2020/03/18/ubuntu-disable-mouse-wake-from-suspend/)
34that worked for me. The only problem with this solution was that he added his
35solution to `.bashrc` and this triggers `sudo` that asks for a password each
36time new terminal is opened, which get annoying quickly since I open a lot of
37terminals all the time.
38
39I followed his instructions and got to solution `sudo sh -c "echo 'disabled' >
40/sys/bus/usb/devices/2-1.1/power/wakeup"`.
41
42I created a system service file `sudo nano
43/etc/systemd/system/disable-mouse-wakeup.service` and removed `sudo` and
44replaced `sh` with `/usr/bin/sh` and pasted all that in `ExecStart`.
45
46```ini
47[Unit]
48Description=Disables wakeup on mouse event
49After=network.target
50StartLimitIntervalSec=0
51
52[Service]
53Type=simple
54Restart=always
55RestartSec=1
56User=root
57ExecStart=/usr/bin/sh -c "echo 'disabled' > /sys/bus/usb/devices/2-1.1/power/wakeup"
58
59[Install]
60WantedBy=multi-user.target
61```
62
63After that I enabled, started and checked status of service.
64
65```sh
66sudo systemctl enable disable-mouse-wakeup.service
67sudo systemctl start disable-mouse-wakeup.service
68sudo systemctl status disable-mouse-wakeup.service
69```
70
71This will permanently disable that device from wakeing up you computer on boot.
72If you have many devices you would like to surpress from waking up your machine
73I would create a shell script and call that instead of direclty doing it in
74service file.