0

The problem

When I close the lid, the computer hibernates and I would like it to keep hibernating until i open the lid and give it a mouse click or keystroke. The problem is that I have a bluetooth keyboard and mouse connected to it. So if I accidentally press a mouse button or a key on the keyboard it wakes from hibernation which is very annoying since I use this laptop at work and bring it with me to and from work every day including the mouse and keyboard.

I put these in my backpack and naturally, keys on both the mouse and keyboard are being pressed in my backpack thus waking the laptop which I do not want.

I have tried

I can turn off my mouse physically with a switch on the mouse and just turn it back on when I want to use it so the mouse is not the problem. They keyboard is. I have a Microsoft Surface keyboard that is connected not to a usb bluetooth dongle, but directly to the laptops bluetooth. There is no switch to turn the keyboard off either.

I can't seem to find proper infromation on what hibernate actually does either. The official ubuntu docs don't seem to detail hibernation or what is affected, what isn't and how things are affected.

What do I want?

I would like to know if and how to have something similar to

If lid closed => ignore input

or

On hibernate => disable bluetooth && on wake => Re-enable bluetooth.

1

You might try writing a service file, in /etc/systemd/system/kill_bluetooth_on_hibernate.service

[Unit]
Description=Kill bluetooth on hibernate
Before=hibernate.target

[Service]
Type=simple
ExecStart=/usr/bin/rfkill block bluetooth

[Install]
WantedBy=hibernate.target  # Note that this would work on suspend.target though
                           # I'm not to certain about hibernate.target

Make sure you remember to start it (and enable it if you want it to be persistent across boots).

systemctl restart kill_bluetooth_on_hiberate.service

The only problem I see with this, is now you won't be able to use your bluetooth keyboard/mouse to wake the computer at all when it is hibernating (unless this is what you want)

Also make sure that you have a separate service file to reenable bluetooth when the computer wakes up

/etc/systemd/system/root-resume.service

[Unit]
Description=Revive bluetooth on wakeup
After=hibernate.target

[Service]
Type=simple
ExecStart=/usr/bin/rfkill unblock bluetooth

[Install]
WantedBy=hibernate.target

Also start/enable this service as well

  • This kills only the built in bluetooth correct? My mouse is a logitech with a unifying usb dongle which means it won't be affected? Correct? So I can just power off my mouse with the physical switch on it and then back on when I want to wake my computer from Hibernate? – DannyBoy Mar 13 at 11:32
  • Yes this is correct. As for what hibernate does, it copies the system state to disk and powers off the machine – j-money Mar 13 at 11:39
  • I tried this approach but can't seem to get it to work. What it did was kill the bluetooth correctly, but when I started the laptop up again, the bluetooth never turns back on. When I check if it's blocked in the rfkill list, it is neither soft or hardblocked. I had to remove the .service files and restart the sysctl to get the bluetooth to work at all again. I understand the approach you suggest and think in theory it is a really nice one. I just can't seem to get it to work properly. – DannyBoy Mar 18 at 9:28
  • This may be a bug in ubuntu, as it works perfectly on my machine (running arch) you might try filing a bug report – j-money Mar 18 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.