Skip to content

Commit

Permalink
bump hyprland-protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
PaideiaDilemma committed Jan 22, 2025
1 parent 37baf4f commit 8acef58
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function(protocol protoPath protoName external)
endif()
endfunction()

pkg_check_modules(hyprland_protocols_dep REQUIRED IMPORTED_TARGET hyprland-protocols>=0.4.0)
pkg_check_modules(hyprland_protocols_dep REQUIRED IMPORTED_TARGET hyprland-protocols>=0.6.0)
pkg_get_variable(HYPRLAND_PROTOCOLS hyprland-protocols pkgdatadir)
message(STATUS "hyprland-protocols dependency set to ${HYPRLAND_PROTOCOLS}")

Expand Down
17 changes: 9 additions & 8 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 27 additions & 15 deletions src/core/Hypridle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ void CHypridle::run() {
exit(1);
}

if (!m_sWaylandState.lockNotifier)
Debug::log(WARN,
"Compositor is missing hyprland-lock-notify-v1!\n"
"general:inhibit_sleep=3, general:on_lock_cmd and general:on_unlock_cmd will not work.");

static auto* const PINHIBIT = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:inhibit_sleep");
static auto* const PSLEEPCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:before_sleep_cmd");
static auto* const PLOCKCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:lock_cmd");
Expand All @@ -115,27 +120,29 @@ void CHypridle::run() {
m_inhibitSleepBehavior = SLEEP_INHIBIT_NORMAL;
break;
case 2: { // auto (enable, but wait until locked if before_sleep_cmd contains hyprlock, or loginctl lock-session and lock_cmd contains hyprlock.)
if (std::string{*PSLEEPCMD}.contains("hyprlock"))
m_inhibitSleepBehavior = SLEEP_INHIBIT_WAIT_FOR_LOCKED;
else if (std::string{*PLOCKCMD}.contains("hyprlock") && std::string{*PSLEEPCMD}.contains("lock-session"))
m_inhibitSleepBehavior = SLEEP_INHIBIT_WAIT_FOR_LOCKED;
if (m_sWaylandState.lockNotifier && std::string{*PSLEEPCMD}.contains("hyprlock"))
m_inhibitSleepBehavior = SLEEP_INHIBIT_LOCK_NOTIFY;
else if (m_sWaylandState.lockNotifier && std::string{*PLOCKCMD}.contains("hyprlock") && std::string{*PSLEEPCMD}.contains("lock-session"))
m_inhibitSleepBehavior = SLEEP_INHIBIT_LOCK_NOTIFY;
else
m_inhibitSleepBehavior = SLEEP_INHIBIT_NORMAL;
} break;
case 3: // wait until locked
m_inhibitSleepBehavior = SLEEP_INHIBIT_WAIT_FOR_LOCKED;
if (m_sWaylandState.lockNotifier)
m_inhibitSleepBehavior = SLEEP_INHIBIT_LOCK_NOTIFY;
break;
default: Debug::log(ERR, "Invalid inhibit_sleep value: {}", **PINHIBIT); break;
}

switch (m_inhibitSleepBehavior) {
case SLEEP_INHIBIT_NONE: Debug::log(LOG, "Sleep inhibition disabled"); break;
case SLEEP_INHIBIT_NORMAL: Debug::log(LOG, "Sleep inhibition enabled"); break;
case SLEEP_INHIBIT_WAIT_FOR_LOCKED: Debug::log(LOG, "Sleep inhibition enabled - inhibiting until the wayland session gets locked"); break;
case SLEEP_INHIBIT_LOCK_NOTIFY: Debug::log(LOG, "Sleep inhibition enabled - inhibiting until the wayland session gets locked"); break;
}

setupDBUS();
handleInhibitSleep(false);
if (m_inhibitSleepBehavior != SLEEP_INHIBIT_NONE)
inhibitSleep();
enterEventLoop();
}

Expand Down Expand Up @@ -382,17 +389,20 @@ void CHypridle::onLocked() {
Debug::log(LOG, "Wayland session got locked");
m_isLocked = true;

if (m_inhibitSleepBehavior == SLEEP_INHIBIT_WAIT_FOR_LOCKED)
uninhibitSleep();

if (const auto* const PLOCKCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:on_lock_cmd"); PLOCKCMD && strlen(*PLOCKCMD) > 0)
spawn(*PLOCKCMD);

if (m_inhibitSleepBehavior == SLEEP_INHIBIT_LOCK_NOTIFY)
uninhibitSleep();
}

void CHypridle::onUnlocked() {
Debug::log(LOG, "Wayland session got unlocked");
m_isLocked = false;

if (m_inhibitSleepBehavior == SLEEP_INHIBIT_LOCK_NOTIFY)
inhibitSleep();

if (const auto* const PUNLOCKCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:on_unlock_cmd"); PUNLOCKCMD && strlen(*PUNLOCKCMD) > 0)
spawn(*PUNLOCKCMD);
}
Expand Down Expand Up @@ -474,13 +484,13 @@ static void handleDbusSleep(sdbus::Message msg) {
std::string cmd = toSleep ? *PSLEEPCMD : *PAFTERSLEEPCMD;

if (!toSleep)
g_pHypridle->handleInhibitSleep(toSleep);
g_pHypridle->handleInhibitOnDbusSleep(toSleep);

if (!cmd.empty())
spawn(cmd);

if (toSleep)
g_pHypridle->handleInhibitSleep(toSleep);
g_pHypridle->handleInhibitOnDbusSleep(toSleep);
}

void handleDbusBlockInhibits(const std::string& inhibits) {
Expand Down Expand Up @@ -623,13 +633,15 @@ void CHypridle::setupDBUS() {
systemConnection.reset();
}

void CHypridle::handleInhibitSleep(bool toSleep) {
if (m_inhibitSleepBehavior == SLEEP_INHIBIT_NONE)
void CHypridle::handleInhibitOnDbusSleep(bool toSleep) {
if (m_inhibitSleepBehavior == SLEEP_INHIBIT_NONE || //
m_inhibitSleepBehavior == SLEEP_INHIBIT_LOCK_NOTIFY // Sleep inhibition handled via onLocked/onUnlocked
)
return;

if (!toSleep)
inhibitSleep();
else if (m_inhibitSleepBehavior != SLEEP_INHIBIT_WAIT_FOR_LOCKED)
else
uninhibitSleep();
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/Hypridle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CHypridle {
bool unregisterDbusInhibitCookie(const SDbusInhibitCookie& cookie);
bool unregisterDbusInhibitCookies(const std::string& ownerID);

void handleInhibitSleep(bool toSleep);
void handleInhibitOnDbusSleep(bool toSleep);
void inhibitSleep();
void uninhibitSleep();

Expand All @@ -58,7 +58,7 @@ class CHypridle {
enum {
SLEEP_INHIBIT_NONE,
SLEEP_INHIBIT_NORMAL,
SLEEP_INHIBIT_WAIT_FOR_LOCKED,
SLEEP_INHIBIT_LOCK_NOTIFY,
} m_inhibitSleepBehavior;

struct {
Expand Down

0 comments on commit 8acef58

Please sign in to comment.