I am wondering if there is any way to detect system wide events under linux such as:
- user un/locked session
- user logs in/out
- machine sent to suspend
- screensaver goes on
- and the monitor switches off due inactivity
I need this for a Qt project where i programmatically react to such events, but i am uncertain how and where to start. Maybe there is an api that i dont know yet.
Any hints? I would appreciate any help!
2 Answers
gnome-screensaver-commandwill give you information about the screen lock events
gnome-screensaver-command -q | grep "is active"if the command returns any result, then the screen is locked.
You can lock the screen with gnome-screensaver-command -l
Dont have any info abt suspend state
1You can use the dbus API to track this information.
See some examples which use the dbus-monitor command are here: Way to measure computer usage via screensaver active/not active time? - Ask Ubuntu.
E.g.:
dbus-monitor 'path=/org/gnome/ScreenSaver, member=ActiveChanged'This can also be done directly from c++, in a python program, etc., using the dbus API directly.