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