drawkcaB | Backward Compatible logo

rants and tips about software

How to lock KDE session when power button is pressed?

I have a kid that likes to play around my laptop while I work on it and sometimes presses the power button. Default setup on Slackware 12.1 is that laptop starts the shutdown sequence right away. No need to mention how frustrating can that be if you’re in middle of something.

I decided to search for a way to prevent this from happening and have my screen lock instead. I searched a little bit, and here’s a nice way to do it.

To lock out KDE user session from the command line, you can use this command:

/usr/bin/dcop --all-users --all-sessions kdesktop KScreensaverIface lock

Now, we need to make sure this gets called when power button is pressed. Make sure that ‘button’ module of your kernel is loaded (you can check with ‘lsmod’ and load it with ‘modprobe’ if needed), and then go and edit this file:


/etc/acpi/acpi_handler.sh


Here’s what I have in it now:

#!/bin/sh
# Default acpi script that takes an entry for all actions

IFS=${IFS}/
set $@

case "$1" in
  button)
    case "$2" in
      power) /usr/bin/dcop --all-users --all-sessions kdesktop KScreensaverIface lock
         ;;
      *) logger "ACPI action $2 is not defined"
         ;;
    esac
    ;;
  *)
    logger "ACPI group $1 / action $2 is not defined"
    ;;
esac

And enjoy :)

Milan Babuškov, 2008-10-23
Copyright © Milan Babu┼íkov 2006-2014