4

I have a frame.work ubuntu 21.10 laptop that I connect often to a usb-c hub that has a monitor, keyboard and mouse.

I currently pull my laptop out and plug in the usb-c hub but then open the laptop lid to un suspend, then close the lid to make my main monitor the only display.

I'd like to put the laptop in a holder that would make it difficult to connect to power and open the lid.

When the laptop lid is closed and on battery power, I'd like the laptop to suspend. When the laptop lid is closed and connected to ac power, I'd like the laptop to wake so that I can use it as soon as possible. When the laptop lid is closed and I disconnect ac power, I'd like the laptop to suspend after a few minutes.

If the laptop is connected to AC power, I'd like the power profile set to maximum. If the laptop is on battery, I'd like the power profile set to energy saver.

Is there any app or setting that does this? If not, how do I catch these events and set a service to manage these states?

MattK
  • 41
  • 3
  • There are a lot of points here. Another point to add is when laptop is plugged into docking station, you shouldn't have to lift the lid to wake it up. You should only have to jiggle the mouse or touch a single key like the first letter of your user id to wake up the system. The other issues you raised though can be addressed with udev (user space /dev) rules. – WinEunuuchs2Unix Mar 03 '22 at 01:11

2 Answers2

0

Don't you need to log in when your device is suspended? In that case the monitor would need to bypass the authentication process, and my guess is that by default, the system does not automatically read devices connected to the periphery in order to avoid vulnerabilities. ( cf article: "Numerous attacks have been demonstrated by vulnerable or malicious USB peripherals. USB attacks work by altering the firmware of USB devices so they register as deceptive device types when plugged into a machine. For example, a USB mass storage device could masquerade as a keyboard to gain the ability to inject malicious keystrokes." ).

Assuming working around this obstacle is possible, you would still have to deal with the resulting vulnerability. I don't think there exists an app for this feature unless the hardware provider offers a driver for that purpose or you write one yourself (can't tell you how you would do that though)

On the other hand, what you can do is disable the lock-on-suspend configuration. I use my Ubuntu 20.04 desktop with a projector permanently connected to it, and I wake it up with a wireless bluetooth keyboard without opening the lid. Read this for infos on how to change lock screen behaviour or this on how to change lid closing behaviour. Nevertheless, keyboard input is still required to wake the screen up.

Bazz
  • 1
  • 1
    There is no version of Ubuntu called Ubuntu 20 – David Feb 26 '22 at 06:19
  • Thanks Bazz! I do not want to unlock my computer, that's a good point to clarify. When I open my laptop lid I get the authentication prompt. I would like to see that prompt when I plug in AC power - I don't need it to suspend when AC power has been plugged in. I'd like it to unsuspend and present the login prompt - at which point I can use my USB peripherals to type in the password, just like when I open the laptop lid while it is connected to the hub.

    I have read the logind.conf docs and I don't think they allow me to unsuspend on ac power being connected - happy to know if that's wrong.

    – MattK Feb 26 '22 at 19:49
  • @Bazz when you live alone there is no need to have computer prompt for password when resuming from suspend or waking up from sleep. A simple password prompt when running sudo or rebooting once every few months should suffice. – WinEunuuchs2Unix Mar 03 '22 at 01:07
0

Here's what worked for me when plugging my closed laptop into my Lenovo DisplayLink hub:

  1. Used # udevadm monitor to identify the correct usb port when I connect my hub. (For me it was usb3.)

  2. sudo sh -c 'echo enabled > /sys/bus/usb/devices/[DEVICE]/power/wakeup'

My actual command was:

sudo sh -c 'echo enabled > /sys/bus/usb/devices/usb3/power/wakeup'

Kudos to these helpful articles:

  • Hi, does this help wake up external monitors connected to the usb-c dock (using displaylink driver) after suspend? – Johan May 18 '23 at 07:36