Wednesday, May 1, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1623  / 3 Years ago, mon, august 9, 2021, 6:42:40

I have a cross-platform application that runs on Ubuntu 14.04 (GNOME). There I need to determine if the screensaver is active or not and if the screen is locked or not.



I found out that I can get the screensaver info with: gnome-screensaver-command -q



But I cannot seem to figure out how I can detect a screen lock. For example on Unity I can use:



gdbus call -e -d com.canonical.Unity -o /com/canonical/Unity/Session -m com.canonical.Unity.Session.IsLocked


but that's a Unity-specific item. So any ideas on how to get this info on Gnome machines?


More From » 14.04

 Answers
4

Found out that /org/gnome/SessionManager/Presence contains the current status of the user session.



It can be called by this:



gdbus call -e -d org.gnome.SessionManager -o /org/gnome/SessionManager/Presence -m org.freedesktop.DBus.Properties.Get /org/gnome/SessionManager/Presence status


Quick bash test:



#!/bin/bash
while true; do
echo "PRESENCE "
gdbus call -e -d org.gnome.SessionManager -o /org/gnome/SessionManager/Presence -m org.freedesktop.DBus.Properties.Get /org/gnome/SessionManager/Presence status
echo -e "
"
sleep 1
done


For example in Qt:



QProcess process;
process.start("sh", QStringList() << "-c"<< "gdbus call -e -d org.gnome.SessionManager -o /org/gnome/SessionManager/Presence -m org.freedesktop.DBus.Properties.Get /org/gnome/SessionManager/Presence status");
process.waitForFinished();
result = QString::fromLatin1(process.readAllStandardOutput());
int state = result.remove("(<uint32 ").remove(">,)").toInt();
if(state != 0) {
// user not active!
}

[#22599] Wednesday, August 11, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ightrushi

Total Points: 129
Total Questions: 125
Total Answers: 127

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
;