mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-11-13 20:25:53 +08:00
[feat] expose system controls and verify remote unlock completion
This commit is contained in:
1 parent
6bfcd5cf3d
commit
dd4baf2fc4
16 files changed
+222
-15
No files matched your search
@@ -7,11 +7,54 @@
|
||||
#include "screen_lock.h"
|
||||
|
||||
#include <dbus/dbus.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "rd_log.h"
|
||||
|
||||
namespace crossdesk {
|
||||
|
||||
ScreenLockState QueryScreenLock() {
|
||||
dbus_threads_init_default();
|
||||
DBusConnection* connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, nullptr);
|
||||
if (!connection) return ScreenLockState::unknown;
|
||||
dbus_connection_set_exit_on_disconnect(connection, false);
|
||||
ScreenLockState state = ScreenLockState::unknown;
|
||||
DBusMessage* query = dbus_message_new_method_call("org.freedesktop.login1",
|
||||
"/org/freedesktop/login1", "org.freedesktop.login1.Manager", "GetSessionByPID");
|
||||
if (query) {
|
||||
dbus_uint32_t pid = getpid();
|
||||
dbus_message_append_args(query, DBUS_TYPE_UINT32, &pid, DBUS_TYPE_INVALID);
|
||||
DBusMessage* session = dbus_connection_send_with_reply_and_block(connection, query, 500, nullptr);
|
||||
dbus_message_unref(query);
|
||||
const char* path = nullptr;
|
||||
if (session && dbus_message_get_args(session, nullptr, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) {
|
||||
query = dbus_message_new_method_call("org.freedesktop.login1", path,
|
||||
"org.freedesktop.DBus.Properties", "Get");
|
||||
const char* interface = "org.freedesktop.login1.Session";
|
||||
const char* property = "LockedHint";
|
||||
if (query) {
|
||||
dbus_message_append_args(query, DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID);
|
||||
DBusMessage* reply = dbus_connection_send_with_reply_and_block(connection, query, 500, nullptr);
|
||||
dbus_message_unref(query);
|
||||
DBusMessageIter outer, value;
|
||||
if (reply && dbus_message_iter_init(reply, &outer) && dbus_message_iter_get_arg_type(&outer) == DBUS_TYPE_VARIANT) {
|
||||
dbus_message_iter_recurse(&outer, &value);
|
||||
if (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_BOOLEAN) {
|
||||
dbus_bool_t locked = false;
|
||||
dbus_message_iter_get_basic(&value, &locked);
|
||||
state = locked ? ScreenLockState::locked : ScreenLockState::unlocked;
|
||||
}
|
||||
}
|
||||
if (reply) dbus_message_unref(reply);
|
||||
}
|
||||
}
|
||||
if (session) dbus_message_unref(session);
|
||||
}
|
||||
dbus_connection_close(connection);
|
||||
dbus_connection_unref(connection);
|
||||
return state;
|
||||
}
|
||||
|
||||
bool LockScreen() {
|
||||
dbus_threads_init_default();
|
||||
DBusError error;
|
||||
|
||||
Reference in new issue
Block a user