-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add D-Bus signals to notify session lock and unlock states #609
base: main
Are you sure you want to change the base?
Changes from all commits
f9f77d3
a4a6a52
0817a59
00b02c0
b22009f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "DBusManager.hpp" | ||
#include "../helpers/Log.hpp" | ||
|
||
DBusManager& DBusManager::getInstance() { | ||
static DBusManager instance; | ||
return instance; | ||
} | ||
|
||
DBusManager::DBusManager() { | ||
initializeConnection(); | ||
} | ||
|
||
DBusManager::~DBusManager() { | ||
// Resources are automatically cleaned up. | ||
} | ||
|
||
void DBusManager::initializeConnection() { | ||
try { | ||
m_pConnection = sdbus::createSystemBusConnection(); | ||
|
||
const sdbus::ServiceName destination{"org.freedesktop.login1"}; | ||
const sdbus::ObjectPath loginPath{"/org/freedesktop/login1"}; | ||
const sdbus::ObjectPath sessionPath{"/org/freedesktop/login1/session/auto"}; | ||
|
||
m_pLoginProxy = sdbus::createProxy(*m_pConnection, destination, loginPath); | ||
m_pSessionProxy = sdbus::createProxy(*m_pConnection, destination, sessionPath); | ||
|
||
Debug::log(LOG, "[DBusManager] Initialized D-Bus connection. Service: {}. Login path: {}, Session path: {}", | ||
std::string(destination), std::string(loginPath), std::string(sessionPath)); | ||
} catch (const sdbus::Error& e) { | ||
Debug::log(ERR, "[DBusManager] D-Bus connection initialization failed: {}", e.what()); | ||
} | ||
} | ||
|
||
std::shared_ptr<sdbus::IConnection> DBusManager::getConnection() { | ||
return m_pConnection; | ||
} | ||
|
||
std::shared_ptr<sdbus::IProxy> DBusManager::getLoginProxy() { | ||
if (!m_pLoginProxy) | ||
initializeConnection(); | ||
|
||
return m_pLoginProxy; | ||
} | ||
|
||
std::shared_ptr<sdbus::IProxy> DBusManager::getSessionProxy() { | ||
if (!m_pSessionProxy) | ||
initializeConnection(); | ||
|
||
return m_pSessionProxy; | ||
} | ||
|
||
void DBusManager::setLockedHint(bool locked) { | ||
if (!m_pSessionProxy) { | ||
Debug::log(WARN, "[DBusManager] Cannot set locked hint: Proxy is not initialized."); | ||
return; | ||
} | ||
|
||
try { | ||
const sdbus::ServiceName interface{"org.freedesktop.login1.Session"}; | ||
m_pSessionProxy->callMethod("SetLockedHint").onInterface(interface).withArguments(locked); | ||
|
||
Debug::log(LOG, "[DBusManager] Sent 'SetLockedHint({})' on {}", locked, std::string(interface)); | ||
} catch (const sdbus::Error& e) { | ||
Debug::log(WARN, "[DBusManager] Failed to send 'SetLockedHint({})': {}", locked, e.what()); | ||
} | ||
} | ||
|
||
void DBusManager::sendUnlockSignal() { | ||
if (!m_pSessionProxy) { | ||
Debug::log(WARN, "[DBusManager] Unlock signal skipped: Proxy is not initialized."); | ||
return; | ||
} | ||
|
||
try { | ||
const sdbus::ServiceName interface{"org.freedesktop.login1.Session"}; | ||
m_pSessionProxy->callMethod("Unlock").onInterface(interface); | ||
|
||
Debug::log(LOG, "[DBusManager] Sent 'Unlock' on {}", std::string(interface)); | ||
} catch (const sdbus::Error& e) { | ||
Debug::log(WARN, "[DBusManager] Unlock signal failed: {}", e.what()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <sdbus-c++/sdbus-c++.h> | ||
|
||
class DBusManager { | ||
public: | ||
static DBusManager& getInstance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's not how we do singletons in hyprland. inline std::unique_ptr<CDBusManager> g_pDBusManager; |
||
|
||
std::shared_ptr<sdbus::IConnection> getConnection(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SP? |
||
std::shared_ptr<sdbus::IProxy> getLoginProxy(); | ||
std::shared_ptr<sdbus::IProxy> getSessionProxy(); | ||
|
||
void setLockedHint(bool locked); | ||
void sendUnlockSignal(); | ||
|
||
private: | ||
DBusManager(); | ||
~DBusManager(); | ||
|
||
void initializeConnection(); | ||
|
||
std::shared_ptr<sdbus::IConnection> m_pConnection; | ||
std::shared_ptr<sdbus::IProxy> m_pLoginProxy; | ||
std::shared_ptr<sdbus::IProxy> m_pSessionProxy; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "hyprlock.hpp" | ||
#include "DBusManager.hpp" | ||
#include "../helpers/Log.hpp" | ||
#include "../config/ConfigManager.hpp" | ||
#include "../renderer/Renderer.hpp" | ||
|
@@ -18,7 +19,6 @@ | |
#include <filesystem> | ||
#include <fstream> | ||
#include <algorithm> | ||
#include <sdbus-c++/sdbus-c++.h> | ||
#include <hyprutils/os/Process.hpp> | ||
|
||
using namespace Hyprutils::OS; | ||
|
@@ -422,8 +422,14 @@ void CHyprlock::run() { | |
exit(1); | ||
} | ||
|
||
auto& dbusManager = DBusManager::getInstance(); | ||
const auto dbusConn = dbusManager.getConnection(); | ||
dbusManager.setLockedHint(true); | ||
|
||
const auto fingerprintAuth = g_pAuth->getImpl(AUTH_IMPL_FINGERPRINT); | ||
const auto dbusConn = (fingerprintAuth) ? ((CFingerprint*)fingerprintAuth.get())->getConnection() : nullptr; | ||
if (fingerprintAuth){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no {} |
||
fingerprintAuth->init(); | ||
} | ||
|
||
registerSignalAction(SIGUSR1, handleUnlockSignal, SA_RESTART); | ||
registerSignalAction(SIGUSR2, handleForceUpdateSignal); | ||
|
@@ -995,6 +1001,11 @@ void CHyprlock::releaseSessionLock() { | |
ext_session_lock_v1_unlock_and_destroy(m_sLockState.lock); | ||
m_sLockState.lock = nullptr; | ||
|
||
// Notify unlock via D-Bus. | ||
auto& dbusManager = DBusManager::getInstance(); | ||
dbusManager.sendUnlockSignal(); | ||
dbusManager.setLockedHint(false); | ||
|
||
Debug::log(LOG, "Unlocked, exiting!"); | ||
|
||
m_bTerminate = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CDBusManager