I'm afraid I can't give you a specific answer (because I don't know the tech well), but I believe you can find it out using D-Bus and ConsoleKit.
For example, when I switch from X to a VT and back, I get this listening on dbus-monitor
:
$ dbus-monitor --system | grep ConsoleKit
signal sender=:1.16 -> dest=(null destination) serial=19039 path=/org/freedesktop/ConsoleKit/Session2; interface=org.freedesktop.ConsoleKit.Session; member=ActiveChanged
signal sender=:1.16 -> dest=(null destination) serial=19040 path=/org/freedesktop/ConsoleKit/Seat1; interface=org.freedesktop.ConsoleKit.Seat; member=ActiveSessionChanged
signal sender=:1.16 -> dest=(null destination) serial=19041 path=/org/freedesktop/ConsoleKit/Session2; interface=org.freedesktop.ConsoleKit.Session; member=ActiveChanged
signal sender=:1.16 -> dest=(null destination) serial=19042 path=/org/freedesktop/ConsoleKit/Seat1; interface=org.freedesktop.ConsoleKit.Seat; member=ActiveSessionChanged
string "/org/freedesktop/ConsoleKit/Session2"
Specifically, you could use the GetActiveSession method. Here's how with dbus-send
(may require sudo
):
$ dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Seat1 org.freedesktop.ConsoleKit.Seat.GetActiveSession
Then, depending on your application, you'll want to check out the returned object's properties, which should be an object path to a Session.
The other question that muru has linked in the comments ( TTY[1-6]: Lock screen after delay (like a screensaver) ) offers us the tool to locking the tty , vlock
. At the simplest level , you can combine vlock -a
with pm-suspend
into a .bashrc
function or a script. Here's mine:
$ cat lockTTY.sh
#!/bin/bash
(sleep 3; sudo pm-suspend) &
vlock -a
What is happening here ? Basically we're launching pm-suspend
with delay in subshell , in background. Meanwhile we use vlock -a
to lock all the ttys. After 3 seconds, the laptop suspends.
The catch here however is the sudo pm-suspend
part. You have to prevent sudo
from asking you password for pm-suspend
. In order to do that, we add the following line at the end of /etc/sudosers
file
$USERNAME ALL = NOPASSWD: /usr/sbin/pm-suspend
Of course , replace $USERNAME
with your actual username. You might call sudo visudo
to open that file with your default text editor set in /etc/alternatives/editor
, just to be safe, but any editor called with proper permissions will do.
What does this script allows us to do ? Suspend and lock with processes still running. vlock -a
has big advantage in preventing switching to other consoles, so it's not just one console being locked, but all of them - you cannot just switch to another tty if one is locked.
You could also suspend first and lock second, i.e. call pm-suspend
first and vlock -a
second. But that means upon resume there is possibility someome may see your screen for a fraction of a second before vlock
kicks in.
What would be the simple and dirty solution in case you don't trust vlock
and don't want to install it ? Create a script /etc/pm/sleep.d/10_lockTTY
with the following contents:
#!/bin/bash
case "${1}" in
hibernate|sleep)
;;
resume|thaw)
for NUM in $(seq 1 6); do service tty$NUM restart; done
;;
esac
This will reset all ttys upon return from suspend, but mind - any processes you had there will be killed.
Best Answer
GPM is just the application you are looking for! It stands for "General Purpose Mouse":
And can be installed by running:
Screenshot:
FYI: I have put a red box around the mouse just to make it obvious where and what it is. I have also selected some text above just to show that this can be done.