Mandriva 2009.1: Lock KDE 4 on Suspend

In my installation, KDE failes to lock the screen on suspend / hibernate, even if the checkbox "lock screen" in the "Energieverwaltung" (how is this labeled in english? Power configuration? Don't know...) is enabled. So I've adapted this patch to Mandriva.

Create the file /etc/pm/sleep.d/50-lock with the following content:

  1. #!/bin/sh
  2.  
  3. lockX() {
  4. for x in /tmp/.X11-unix/*; do
  5. displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
  6. user=`w -hs | awk '{ if ($3 == ":'$displaynum'" || $2 == ":'$displaynum'" ) { print $1; exit; } }'`
  7. export DISPLAY=":$displaynum"
  8. su $user -c "dbus-send --session --dest=org.freedesktop.ScreenSaver --type=method_call --print-reply /ScreenSaver org.freedesktop.ScreenSaver.Lock"
  9. done
  10. }
  11.  
  12. case "$1" in
  13. hibernate|suspend)
  14. lockX
  15. ;;
  16. thaw|resume)
  17. ;;
  18. *) exit $NA
  19. ;;
  20. esac

Make this file executable (chmod 755 /etc/pm/sleep.d/50-lock). That's it. Pretty simple, isn't it?

Update 2009-05-30:

Here is another version of this script (from Ubuntu Bug #283315).

Comments

Makes sense...

"Power Management"? :-)

Hey,

thanks for the info. Another stupid error in KDE4 fixed ;-)