Skip to content

Commit

Permalink
core: implement hyprlock-lock-notify-v1 functionality (#122)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Mihai Fufezan <[email protected]>
  • Loading branch information
PaideiaDilemma and fufexan authored Jan 27, 2025
1 parent 33ac8ca commit 15ca902
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 133 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.vscode/
build/
protocols/
protocols/
.clangd/
.direnv/
.cache/
compile_commands.json
67 changes: 35 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ message(STATUS "Checking deps...")

find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(hyprwayland-scanner 0.4.4 REQUIRED)
pkg_check_modules(
deps
REQUIRED
IMPORTED_TARGET
wayland-client
wayland-protocols
hyprlang>=0.4.0
hyprlang>=0.6.0
hyprutils>=0.2.0
sdbus-c++>=0.2.0)

Expand All @@ -50,45 +51,47 @@ add_executable(hypridle ${SRCFILES})
target_link_libraries(hypridle PRIVATE rt Threads::Threads PkgConfig::deps)

# protocols
find_program(WaylandScanner NAMES wayland-scanner)
message(STATUS "Found WaylandScanner at ${WaylandScanner}")
execute_process(
COMMAND pkg-config --variable=pkgdatadir wayland-protocols
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE WAYLAND_PROTOCOLS_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}")
pkg_get_variable(WAYLAND_SCANNER_PKGDATA_DIR wayland-scanner pkgdatadir)
message(STATUS "Found wayland-scanner pkgdatadir at ${WAYLAND_SCANNER_PKGDATA_DIR}")

function(protocol protoPath protoName external)
pkg_check_modules(hyprland_protocols_dep REQUIRED IMPORTED_TARGET hyprland-protocols>=0.6.0)
pkg_get_variable(HYPRLAND_PROTOCOLS hyprland-protocols pkgdatadir)
message(STATUS "Found hyprland-protocols at ${HYPRLAND_PROTOCOLS}")

function(protocolnew protoPath protoName external)
if(external)
execute_process(
COMMAND ${WaylandScanner} client-header ${protoPath}
protocols/${protoName}-protocol.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
execute_process(
COMMAND ${WaylandScanner} private-code ${protoPath}
protocols/${protoName}-protocol.c
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
target_sources(hypridle PRIVATE protocols/${protoName}-protocol.c)
set(path ${protoPath})
else()
execute_process(
COMMAND
${WaylandScanner} client-header ${WAYLAND_PROTOCOLS_DIR}/${protoPath}
protocols/${protoName}-protocol.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
execute_process(
COMMAND
${WaylandScanner} private-code ${WAYLAND_PROTOCOLS_DIR}/${protoPath}
protocols/${protoName}-protocol.c
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
target_sources(hypridle PRIVATE protocols/${protoName}-protocol.c)
set(path ${WAYLAND_PROTOCOLS_DIR}/${protoPath})
endif()
message(STATUS "Full proto path: ${path}")
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/protocols/${protoName}.cpp
${CMAKE_SOURCE_DIR}/protocols/${protoName}.hpp
COMMAND hyprwayland-scanner --client ${path}/${protoName}.xml
${CMAKE_SOURCE_DIR}/protocols/
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
target_sources(hypridle PRIVATE protocols/${protoName}.cpp
protocols/${protoName}.hpp)
endfunction()
function(protocolWayland)
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/protocols/wayland.cpp
${CMAKE_SOURCE_DIR}/protocols/wayland.hpp
COMMAND hyprwayland-scanner --wayland-enums --client
${WAYLAND_SCANNER_PKGDATA_DIR}/wayland.xml ${CMAKE_SOURCE_DIR}/protocols/
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
target_sources(hypridle PRIVATE protocols/wayland.cpp protocols/wayland.hpp)
endfunction()

make_directory(${CMAKE_SOURCE_DIR}/protocols) # we don't ship any custom ones so
# the dir won't be there
protocol("staging/ext-idle-notify/ext-idle-notify-v1.xml" "ext-idle-notify-v1"
false)

protocolwayland()

protocolnew("staging/ext-idle-notify" "ext-idle-notify-v1" false)
protocolnew("${HYPRLAND_PROTOCOLS}/protocols" "hyprland-lock-notify-v1" true)

# Installation
install(TARGETS hypridle)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ will make those events ignored.
- wayland-protocols
- hyprlang >= 0.4.0
- sdbus-c++
- hyprwayland-scanner

## Building & Installation

Expand Down
50 changes: 50 additions & 0 deletions flake.lock

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

12 changes: 12 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
};

hyprland-protocols = {
url = "github:hyprwm/hyprland-protocols";
inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
};

hyprwayland-scanner = {
url = "github:hyprwm/hyprwayland-scanner";
inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
};
};

outputs = {
Expand Down
10 changes: 7 additions & 3 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
lib,
stdenv,
cmake,
pkg-config,
hyprland-protocols,
hyprlang,
hyprutils,
hyprwayland-scanner,
lib,
pkg-config,
sdbus-cpp,
stdenv,
systemd,
wayland,
wayland-protocols,
Expand All @@ -19,11 +21,13 @@ stdenv.mkDerivation {

nativeBuildInputs = [
cmake
hyprwayland-scanner
pkg-config
wayland-scanner
];

buildInputs = [
hyprland-protocols
hyprlang
hyprutils
sdbus-cpp
Expand Down
2 changes: 2 additions & 0 deletions nix/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ in {
default = inputs.self.overlays.hypridle;

hypridle = lib.composeManyExtensions [
inputs.hyprland-protocols.overlays.default
inputs.hyprlang.overlays.default
inputs.hyprutils.overlays.default
inputs.hyprwayland-scanner.overlays.default
inputs.self.overlays.sdbuscpp
(final: prev: {
hypridle = prev.callPackage ./default.nix {
Expand Down
11 changes: 3 additions & 8 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ void CConfigManager::init() {

m_config.addConfigValue("general:lock_cmd", Hyprlang::STRING{""});
m_config.addConfigValue("general:unlock_cmd", Hyprlang::STRING{""});
m_config.addConfigValue("general:on_lock_cmd", Hyprlang::STRING{""});
m_config.addConfigValue("general:on_unlock_cmd", Hyprlang::STRING{""});
m_config.addConfigValue("general:before_sleep_cmd", Hyprlang::STRING{""});
m_config.addConfigValue("general:after_sleep_cmd", Hyprlang::STRING{""});
m_config.addConfigValue("general:ignore_dbus_inhibit", Hyprlang::INT{0});
m_config.addConfigValue("general:ignore_systemd_inhibit", Hyprlang::INT{0});
m_config.addConfigValue("general:inhibit_sleep", Hyprlang::INT{2});

m_config.commence();

Expand Down Expand Up @@ -77,11 +80,3 @@ Hyprlang::CParseResult CConfigManager::postParse() {
std::vector<CConfigManager::STimeoutRule> CConfigManager::getRules() {
return m_vRules;
}

std::string CConfigManager::getOnTimeoutCommand() {
return m_vRules.front().onTimeout;
}

void* const* CConfigManager::getValuePtr(const std::string& name) {
return m_config.getConfigValuePtr(name.c_str())->getDataStaticPtr();
}
7 changes: 5 additions & 2 deletions src/config/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ class CConfigManager {
std::string onResume = "";
};

std::string getOnTimeoutCommand();
std::vector<STimeoutRule> getRules();
void* const* getValuePtr(const std::string& name);

template <typename T>
Hyprlang::CSimpleConfigValue<T> getValue(const std::string& name) {
return Hyprlang::CSimpleConfigValue<T>(&m_config, name.c_str());
}

private:
Hyprlang::CConfig m_config;
Expand Down
Loading

0 comments on commit 15ca902

Please sign in to comment.