8

Already tried all solutions from: How do I disable the sleep button on my keyboard?

gsettings set org.gnome.settings-daemon.plugins.power button-suspend "nothing"
gsettings set org.gnome.settings-daemon.plugins.power button-sleep "nothing"
gsettings set org.gnome.settings-daemon.plugins.power button-hibernate "nothing"

and I have now with dconf-tools:

enter image description here

In my case HP Hewlett Packard WZ972AA ABA Classic Keyboard:

enter image description here

This "Moon" button still working.. Any another ideas?

7
+50

In addition to the Gnome Power settings you can set the systemd settings found in /etc/systemd/logind.conf:

My laptop looks like this:

$ cat /etc/systemd/logind.conf

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See logind.conf(5) for details.

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
HandleLidSwitch=ignore
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RemoveIPC=yes
#UserTasksMax=12288

Notice on my system the only option I've changed is HandleLidswitch. For your system I would override these defaults:

#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate

to this:

HandleSuspendKey=ignore
HandleHibernateKey=ignore

systemd is a little unique in that a line beginning with a hashtag (#) is not only a comment but also represents the default action taken.

Unfortunately I don't have your keyboard to test this configuration.

NOTE: After saving changes either reboot to activate or use:

sudo systemctl restart systemd-logind.service
3
  • 1
    this method doesn't works
    – Crantisz
    Mar 26 '19 at 6:44
  • 1
    @Crantisz I added sudo systemctl restart systemd-logind.service to answer. Do you have the same keyboard as shown in question? What make and model of computer do you have? Mar 26 '19 at 10:28
  • This worked for me on 18.04
    – Rolch2015
    Dec 6 '20 at 19:28
5

Not a solution, but a workaround, as it disables suspend.
Follow these two steps:

  1. Add HandleSuspendKey=ignore to the [Login] section of /etc/systemd/logind.conf.
    If you have enabled debug level in logind logs you get log entries like:

    ... systemd-logind[518]: Refusing operation, as it is turned off. 
    

    in the journal but it still suspends on some other trigger.

  2. Add /etc/systemd/sleep.conf with:

    [Sleep]
    SuspendMode=false
    

    Now it still reacts on suspend key presses, but fails with:

    ...systemd-logind[518]: Failed to process message type=method_call  
    sender=:1.54 destination=:1.1 path=/org/freedesktop/login1  
    interface=org.freedesktop.login1.Manager member=Suspend cookie=26  
    reply_cookie=0 signature=b error-name=n/a error-message=n/a:  
    Sleep verb not supported in journal
    

As said: It's a dirty workaround until someone can find a better solution.

3
  • @zx485 Could you please review my edits and also review the editing help to improve the readability of your own edits in the future... ;-)
    – Fabby
    Apr 6 '19 at 21:07
  • 1
    @Fabby: I reviewed your edit and admit that my edit was not the best. It was incomplete. I also read the editing help page - again.
    – zx485
    Apr 6 '19 at 21:28
  • @zx485 0:-) We live and we learn... ;-)
    – Fabby
    Apr 6 '19 at 21:48
3

Please try 'xev' to find out if the event (press button) is read by Linux. Maybe the button is direct triggering a function on the mainboard?

On the other hand, if you've got the keycode in xev, you should be able to remap the sleep button with something other. See: How do I remap certain keys or devices?

1
  • Here the log: KeymapNotify event, serial 112, synthetic NO, window 0x0, keys: 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    – Crantisz
    Mar 26 '19 at 6:44
2

It looks like the ability to configure this was removed from recent versions of gnome-settings-daemon in Ubuntu 18 and Ubuntu 20.

A quick and dirty solution is to killall gsd-media-keys which will prevent all media keys from being handled by gnome, likely including the lid switch. You'll likely have to have edited /etc/systemd/logind.conf to make sure logind handles the keys how you like, and restarted the logind service or your system.

To re-enable the ability to configure this, some small changes are needed to plugins/gsd-media-keys-manager.c inside the gnome-settings-daemon source. These changes are in a merge request at https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/issues/537 . Here is how to rebuild gnome-settings-daemon with configuration enabled. You'll have to enable source repositories in your package management system.

$ mkdir ~/local-debs
$ cd ~/local-debs

# install build dependencies
$ sudo apt-get build-dep gnome-settings-daemon

# extract distribution package source
$ sudo apt-get source gnome-settings-daemon

# download the changes
$ wget https://siasky.net/CABb_suQRoRKqFo9zJ9YvGIqlLcpila1OFjUtI-f7uS5xQ/suspend-button-settings

# apply the changes.  `true` as an editor skips editing by making it always successful.
$ cd gnome-settings-daemon-*/
$ patch -p1 < ../suspend-button-settings
$ EDITOR=true dpkg-source --commit . suspend-button-settings ../suspend-button-settings

# build the package, skipping tests and signing
$ DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -us -uc

# install the package
$ sudo dpkg -i ../*.deb

# reboot the system, relogin, or terminate and relaunch the `gsd-media-keys` process ...
# ... [do preferred choice] ...

# finally, disable the suspend button
$ gsettings set org.gnome.settings-daemon.plugins.power suspend-button-action "nothing"

# you can also set it to "interactive" instead of "nothing" to display a power popup

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.