Version: (using KDE Devel) Installed from: Compiled sources Knowing whether the display is locked can be useful for security applications. However, there is currently no way to check this. The locking is activated by kde_desktop, which informs only kdm (by sending "lock" to its socket, see kdebase/kdesktop/lock/lockprocess.cc), and kdm keeps this information to itself. I suggest adding an "is_locked" command to the kdm socket interface, which will query whether the current display is locked (i.e., returns d->hstent->lock ? "1\n" : "0\n" ). Or maybe, to allow for future expansion, a "status" command that will return a list of keywords, currently either "locked" or "unlocked". This way the locking status can then be checked easily, e.g., using "kdmctl is_locked". BTW, it would be useful to also have ways to get notified of change (by event instead of polling), and to check the status of the screen saver (as opposed to locking). But these probably can't be done by kdm.
doing this via kdm is certainly simple, but really ugly. the "lock" command is only a hint, and ugly enough as it is. it would be way better if kdm could find this out another way ... which brings us back to your request. unfortunately, i know neither what exists nor what would make sense if we need to invent something (and convince everybody else to use it).
This has nothing to do with kdm. There's dcop interface for kdesktop (dcop kdesktop KScreensaverIface) but there's no isLocked(), only isBlanked(), and that's KDE-specific anyway. I myself don't quite see the purpose of finding out whether the screen is locked.
Here's one use for this functionality: http://thinkwiki.org/wiki/Script_for_theft_alarm_using_HDAPS It activates an alarm if the laptop is physically moved when the display is locked. To check the locking, it employd an ugly distribution-specific kludge. More generally, a locked screen indicates the user doesn't want others to mess with the computer, and this may have implications for other devices.
I guess just checking whether the screen is blanked can do as well there.
No, a blanked screen means just that the user hasn't typed/mouses for a while, not that he wants to restrict access. When you sit with a laptop on your lap in a lecture, you don't want an alarm to go off whenever the screensaver kicks in.
i have to agree with eran, in all points. the kdm "lock" command is a security feature: prevent auto-relogin if the session (was) crashed while the screen locker was running. it would be *very* advantageous if this worked out of the box without making all screen lockers kdm-aware first.
in kde4, the GetActive function and the ActiveChanged signal of the the org.freedesktop.ScreenSaver D-Bus interface can be used to track the saver's status. it does not tell whether the saver is actually a locker, though.
In Plasma 5 the signal and function from comment #7 is a sufficient solution. It reflects correctly whether the screen is locked. As there are no screen savers any more it will return "true" whenever the screen is locked.