What is the screen locking mechanism under KDE?

I installed KDE desktop on my Ubuntu:

root@DESKTOP:/var/log# dpkg -l|fgrep -i kde-plasma-desktop
ii  kde-plasma-desktop                      5:63ubuntu16                               the KDE Plasma Desktop and minimal set of applications
root@DESKTOP:/var/log# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 11.04
Release:    11.04
Codename:   natty
root@DESKTOP:/var/log# 

I just wanted to know that if I press "CTRL+ALT+L" then what is the process/application that locks the screen? under GNOME it's gnome-screensaver. What is it under KDE?


Solution 1:

For systems running KDE 4.x that will be

qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock

For Ubuntu / Gnome: qdbus org.gnome.ScreenSaver /ScreenSaver Lock

Qdbus as written above, just sends a message on the message bus, which the screen-locker receives. The command will however lock the screen. qdbus just asks nicely "will someone lock the screen please?" The advantage of using qdbus, is that it is supported on other platforms than KDE. The text below works for KDE4 only.

Now watch and learn :o)

To figure this out in a little more detail, a bit of bash trickery is required:

  • list all processes while unlocked ps -ef;
  • lock the screen qdbus ..........;
  • wait a moment to get the screen locked sleep 1
  • then list the processes while locked ps -ef
  • find the differences between the output of both commands diff <( cmd1 ) <( cmd2 )

The command line:

diff <( ps -ef ) <( qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock; sleep 1; ps -ef )

0a1
> 
242d242
< jhendrix 17088 16352  0 21:11 pts/4    00:00:00 /bin/bash
245,246c245,247
< jhendrix 17091 17088  0 21:11 pts/4    00:00:00 ps -ef
< jhendrix 17092 17089  0 21:11 pts/4    00:00:00 qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
---
> jhendrix 17093  2801 11 21:11 ?        00:00:00 /usr/lib/kde4/libexec/kscreenlocker --forcelock
> jhendrix 17095 17093 11 21:11 ?        00:00:00 kblankscrn.kss -root
> jhendrix 17099 17089  0 21:11 pts/4    00:00:00 ps -ef

This narrows down the list of potential commands to lock the screen, doesn't it? Now the answer to your question is simple: To lock the screen from the commandline use: /usr/lib/kde4/libexec/kscreenlocker --forcelock the blankscrn.kss is a child process of kscreenlocker, so kscreenlocker is the one to run.

To view the command syntax: /usr/lib/kde4/libexec/kscreenlocker --help

What it does? It basically draws a big black window that covers the whole screen and it forces it to be on top of everything. It catches all keystrokes and pops up a login dialog.

Finally which package does it come in (kde-workspace-bin)?

$ dpkg -S /usr/lib/kde4/libexec/kscreenlocker

kde-workspace-bin: /usr/lib/kde4/libexec/kscreenlocker