Bug 392798 - Power button actions should be handled from lock screen
Summary: Power button actions should be handled from lock screen
Status: CONFIRMED
Alias: None
Product: Powerdevil
Classification: Plasma
Component: general (show other bugs)
Version: 5.16.0
Platform: Arch Linux Linux
: NOR wishlist
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-06 12:51 UTC by Kishore Gopalakrishnan
Modified: 2024-06-08 08:11 UTC (History)
41 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
add suspend action to KDE Plasma lock screen (1.35 KB, patch)
2020-03-29 11:07 UTC, Anatol Rosch
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kishore Gopalakrishnan 2018-04-06 12:51:57 UTC
In kscreenlocker version 5.12.4 (haven't tested with earlier versions), power button actions are not handled when the screen is locked.

Steps to reproduce:

1. Go to system settings > power management > energy saving and select an event to be triggered when power button is pressed (eg. suspend)

2. Lock screen

3. Press power button

Observed result: Nothing happens.

Expected result: The system should perform the action chosen to occur when the power button is pressed, even if the screen is locked.
Comment 1 Kai Uwe Broulik 2018-04-06 16:21:25 UTC
@Martin I thought this was intentional? We don't show a shutdown UI either.
Comment 2 Martin Flöser 2018-04-07 05:40:38 UTC
We don't show a UI, but the actions on power button and lid close should still work, shouldn't they? After all I doubt that powerdevil knows that the screen is locked and kscreenlocker knows nothing about physical buttons.
Comment 3 Kai Uwe Broulik 2018-04-07 08:34:18 UTC
I need to whitelist the global shortcuts for power off in kscreenlocker then.

However, how is allowing to press a keyboard combination to shutdown any different from clicking a UI button that we deliberately not out there to avoid "unauthorized interruption of a potentially running task" such as in a lab you always brought up?
Comment 4 Martin Flöser 2018-04-07 16:13:19 UTC
Is the power button just a global shortcut? I thought that this is a physical event. Now thinking about it I doubt it makes sense to allow it as we cannot show ksmserver's logout dialog.
Comment 5 David Edmundson 2018-04-07 16:17:57 UTC
shutdown is a problem as we potentially have app prompts for example if there's unsaved changes.

This doesn't apply for suspend/hibernate.
Comment 6 Nicolas Girard 2018-04-25 08:20:01 UTC
Confirmed here on Kubuntu 18.04beta.
kscreenlocker 5.12.4 as well.
Comment 7 Mayeul C. 2018-04-29 21:25:25 UTC
To be fair, I often just change TTY and press the suspend button there. It should also work with the power button to poweroff the computer (or ctrl-alt-del), so some points here are rather moot.

Showing a confirmation UI (maybe with a timer) would probably be a better solution. Ideally, the screen locker could know what kind of activity there is in the background (KTorrent downloading, disk copy, compilation) and show a message that some actions could be interrupted, but that might be just me overthinking this.
Comment 8 Brennan Kinney 2018-04-30 03:10:53 UTC
Can System Settings for the lockscreen not have a UI toggle for soft buttons to allow shutdown/suspend/hibernate? Sometimes I've suspended the machine only to find it wake up again shortly after, I have to manually type out the password again just to attempt a suspend once more.

It'd be nice if the user has allowed the lockscreen to display power button UI, that you could then do such actions via lockscreen without requiring an unlock. My machine isn't a laptop and it's power button isn't that accessible.

Suspend shouldn't cause any harm/risk to running processes and the like? If such a setting were off by default it shouldn't cause any harm/risk to other users that is mentioned for avoiding it?
Comment 9 Peter Wu 2018-06-13 17:16:01 UTC
This is possibly related to bug 336369 which requests a GUI item to trigger suspend while this bug requests functionality for normal power/suspend keys.

In that enhancement request, Kai said:
> We removed the shutdown option and the like due to security reasons, so it doesn't make sense to add a suspend option, I suppose?

There were also some arguments from Nate about how other platforms (Windows, macOS, GNOME) still provide the options to shutdown/suspend the device.

Given that in most cases (*handwaving*) Plasma runs on consumer laptops and desktops, and not in a lab setting, what about handling suspend/power buttons (and add GUI buttons if necessary) by default and provide a setting to disable it if necessary (for lab setups?)? In many setups, you could also pull out the battery, remove the power cable or force-press the power button.

To illustrate why I find this feature desirable: sometimes I lock a screen, walk away and when I return, I just want to suspend it using a shortcut from the lock screen. That does not work at the moment, I have to type a long password just to be able to suspend (inconvenient if I am in a hurry).
Comment 10 Jens 2018-11-11 12:54:48 UTC
Yes, please (pretty please) add an option to shutdown, logout, suspend etc. from the lock screen. It's fine to have an option to hide those buttons but this should not be the default.

Any security considerations are invalid if the machine is physically accessible (since a user could just pull the plug to "shut down", or press the power button a little longer). And I just switched from Unity on Ubuntu 16.04 to KDE (Neon) and I am sorely missing this feature too.

Thanks!
Comment 11 Bernie Innocenti 2019-06-15 12:46:22 UTC
I just noticed that I can't suspend my desktop from the lockscreen in Plasma 5.16, and I was surprised it wouldn't work the same way of closing the lid on a laptop.

Both Windows 10 and OSX can sleep / restart / shutdown from the lockscreen, while Gnome only supports sleep and restart (but the latter mysteriously shows a padlock when you click on it).

So, supporting sleep seems uncontroversial, while restart and shutdown might be what most users expect to find, but if there's no consensus we could move the discussion to a separate bug.
Comment 12 matthias sweertvaegher 2020-01-02 11:23:09 UTC
please make the power button work on the lock screen.

my situation:
I configured the power button to suspend the system. This works when logged in, but not on the lock screen. Funnily enough, when I close the lid, it does suspend! However, due to repetitive opening/closing of the lid, the hinges are now damaged so it is no longer an option to open/close the lid. This is a stationary laptop so we just leave it open. Although this laptop is aging, it runs linux just fine.

When do we need this behavior? During the evening, we leave the laptop on because you don't know whether you will use it shortly again or not. But when you're ready to go to sleep, the screen is already locked, and just pressing the power button is the only energy left to put the system to sleep ;) In any case, it's the most sensible action to take. Logging in, confronts you with new emails, new messages, etc, new stimuli you don't want when you want to finish the day.

I don't know if there is a technical difference, but if the powerbutton is difficult to "grab" on the lockscreen, maybe support the dedicated suspend key?

thanks
matthias
Comment 13 Derek Christ 2020-02-11 20:27:31 UTC
I would very like to see such a feature, too.
It's very odd and inconvenient, that there is no way to suspend (or turn off the display) in the lockscreen. Also, the display timeout is in the lockscreen the same as normal, so it would take minutes until the dislay is turned off.
To my situation:
I take notes in the lectures with my notebook every day, and if the notebook accidently wakes up from suspend, I have no other way to turn the display back off than entering my password and after that press the power button. In windows I can press the power button right away and the problem is solved.
Comment 14 Anatol Rosch 2020-03-29 11:07:37 UTC
Created attachment 127083 [details]
add suspend action to KDE Plasma lock screen
Comment 15 Anatol Rosch 2020-03-29 11:08:50 UTC
In my opinion, the reasonable thing to do would be giving the users a simple option to re-enable power actions on lock screen, and let the user decide whether the alleged security implications affect them (and for the very common scenario of a single session per machine, they don't). Sadly, according to #336369, "adding options is not the correct approach, this is not KDE 3". After 5 more years, we still got nothing. 

A hack for LockScreenUi.qml that re-enables power key handling is available at https://unix.stackexchange.com/questions/441989/suspend-linux-from-kde-plasma-5-lockscreen/576694 , i've attached a patch for convenience. Confirmed on kded5 5.67.0 and plasmashell 5.17.5 (Gentoo).
Comment 16 Leandro Lucarella 2020-11-07 21:38:25 UTC
This is bugging me too often. Is very hard for me to see a reason why you wouldn't want to allow suspending, and in any case I think leaving the option to the user to allow reboot and power-off too (even if is burried in some "Advanced" setting somewhere) would make a lot of sense.
Comment 17 Kamil Dudka 2021-06-14 14:37:30 UTC
(In reply to Anatol Rosch from comment #14)
> Created attachment 127083 [details]
> add suspend action to KDE Plasma lock screen

Thanks for sharing!  The above patch has solved the problem for me.  The "Sleep" button in the UI is not aligned with the "Switch User" button but the HW button now finally makes the machine suspend even when the screen is locked.
Comment 18 ppaalanen 2022-02-05 10:05:13 UTC
I was looking for a way to have my desktop shut down on power button press, even if the screen is locked. I suppose this bug is it.

I'd like to point out that if someone is able to press the physical power button, they are also able to press it long enough that the machine cuts power without a normal shutdown. If they can access the power button, they could probably just pull the power cable, too. Therefore I think the security aspect of the justification to not allow shutdown while locked is very much undermined. Surely it's better to force programs to quit during normal shutdown than it is to kill power.
Comment 19 Nicolas Girard 2022-02-05 10:15:24 UTC
(In reply to ppaalanen from comment #18)
> 
> I'd like to point out that if someone is able to press the physical power
> button, they are also able to press it long enough that the machine cuts
> power without a normal shutdown. If they can access the power button, they
> could probably just pull the power cable, too. Therefore I think the
> security aspect of the justification to not allow shutdown while locked is
> very much undermined. Surely it's better to force programs to quit during
> normal shutdown than it is to kill power.

I completely agree.

The recent severity /priority downgrade (severity: normal -> wishlist ; priority: high -> normal) doesn't make sense to me **at all**.
Comment 20 bleyddyn.aprhys 2022-05-07 20:52:18 UTC
(In reply to Kamil Dudka from comment #17)
> (In reply to Anatol Rosch from comment #14)
> > Created attachment 127083 [details]
> > add suspend action to KDE Plasma lock screen
> 
> Thanks for sharing!  The above patch has solved the problem for me.  The
> "Sleep" button in the UI is not aligned with the "Switch User" button but
> the HW button now finally makes the machine suspend even when the screen is
> locked.

To have the buttons be aligned, add this to the new ActionButton block. The anchors section should look just liek the the one for the existing "Switch User" ActionButton.

                        anchors{
                            verticalCenter: parent.top
                        }
Comment 21 Kamil Dudka 2022-05-08 17:29:07 UTC
After upgrade to plasma 5.24.4 I can see "Sleep", "Hibernate", and "Switch User" buttons on my lock screen.  The first two hunks of attachment #127083 [details] are still needed to keep the HW power button functional while the screen is locked.
Comment 22 Miguel De Anda 2023-01-12 22:02:19 UTC
(In reply to Kamil Dudka from comment #21)
> After upgrade to plasma 5.24.4 I can see "Sleep", "Hibernate", and "Switch
> User" buttons on my lock screen.  The first two hunks of attachment #127083 [details]
> [details] are still needed to keep the HW power button functional while the
> screen is locked.

I never paid attention to the GUI update recently but it's still pretty bad that I need to turn on monitor, to sleep my computer. I've actually been logging in completely then hitting the power button. Always making sure nobody sees how silly my actions my appear.
Comment 23 Dm 2023-01-27 10:52:46 UTC
(kubuntu 22.04, plasma 5.24.7, KDE Frameworks 5.92.0, QT 5.15.3, X11)
There is a little hack: even when screen is locked, keyboard shortcuts are still available. So you can go to settings -> shortcuts -> power -> suspend (or hibernate) -> assign a new shortcut -> push power button (agree reassign)
Now suspend (or hibernate) works in every case (logged in or lockscreen)
Comment 24 Miguel De Anda 2023-02-16 04:23:30 UTC
(In reply to Dm from comment #23)
> (kubuntu 22.04, plasma 5.24.7, KDE Frameworks 5.92.0, QT 5.15.3, X11)
> There is a little hack: even when screen is locked, keyboard shortcuts are
> still available. So you can go to settings -> shortcuts -> power -> suspend
> (or hibernate) -> assign a new shortcut -> push power button (agree reassign)
> Now suspend (or hibernate) works in every case (logged in or lockscreen)

This seemed to work for me. I no longer have to switch the kvm and/or turn on monitor to log in to hit the power button.

I highly recommend manually removing the original shortcut since it suspended my computer mid-process.
Comment 25 Rewarp 2023-07-28 05:18:20 UTC
I would like to chime in with a particular setup that makes the lack of an easy access to the shutdown procedure from the power button from the lock screen dangerously insecure.

I am setting up servers for schools running openSUSE with docker containers containing various services, with the Plasma interface. They are designed to be as easy to use as possible since we are talking about primary and secondary schools. No one expects any teacher there to be a moonlighting sysadmin.

To shutdown the server properly in such a scenario would be too much of a hassle for them, so I used the system settings for power management to trigger a shutdown when the power button is pressed. However, the power button doesn't work if the screenlock is on. The screenlock should ideally be on so that teachers and trusted students can access the desktop interface for whatever reason. The only protection therefore for such a unit thus far in an exposed environment is the lack of a KVM. I can imagine that's not going to be much of a barrier for kids determined to do mischief.

So my hope is there will be a user toggle option that allows the power button to shutdown the system safely should it be necessary from the lockscreen.
Comment 26 Alex Lieflander 2023-10-02 02:23:15 UTC
(In reply to Dm from comment #23)
> (kubuntu 22.04, plasma 5.24.7, KDE Frameworks 5.92.0, QT 5.15.3, X11)
> There is a little hack: even when screen is locked, keyboard shortcuts are
> still available. So you can go to settings -> shortcuts -> power -> suspend
> (or hibernate) -> assign a new shortcut -> push power button (agree reassign)
> Now suspend (or hibernate) works in every case (logged in or lockscreen)
Another workaround is to use the "tiny-power-button" Linux kernel module. This module waits for power button presses (like the "button" module that most desktop environments use), but instead of sending the event to user-space it directly sends a shutdown signal to your init manager. This completely bypasses KDE-Plasma and thus allows the power button to work while the screen is locked.

Note:
1. Your kernel must have been compiled with the tiny-power-button module
2. Your init manager must support shutdown signals
3. This module only waits for power button presses
4. If compiled as a module, tiny-power-button must be loaded on every boot
5. The button module must not be loaded before or after the tiny-power-button module is loaded
6. If the button module was compiled directly into the kernel you may need to do other modifications

The relevant Kconfig option for note 1 is CONFIG_ACPI_TINY_POWER_BUTTON=m or CONFIG_ACPI_TINY_POWER_BUTTON=y. By default, the signal used in note 2 is different than SIGTERM and friends, and causes a graceful shutdown. Most init managers (like SystemD) support it, but you could theoretically use another signal at the risk of data loss. Due to note 3, events like closing the lid wouldn't work and thus this workaround may not be suitable for laptops. Note 4 can be achieved on most systems by adding "tiny-power-button" to /etc/modules. Note 5 can be achieved on most systems by adding "blacklist button" to /etc/modprobe.d/blacklist.conf. The problematic Kconfig option in note 6 would be CONFIG_ACPI_BUTTON=y, however you might still be able to use this workaround by adding additional boot arguments.
Comment 27 Andrew McNabb 2024-05-10 20:50:49 UTC
The workaround from comment #23 didn't work for me.

I went to Energy Saving and turned off suspending when the power button is pressed (to avoid suspending while trying to create the shortcut), and then I tried to create the shortcut. Unfortunately, when I tried to enter the shortcut key by pressing the power button, nothing happened at all; it just didn't register as a key press.