summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-08-26 23:13:33 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-08-26 23:13:33 +1000
commit4f819c855714268978f368dbe667439e3de9ca39 (patch)
tree9158fd20cf479b5aa66cc22edafb32cb473c4f3c
parentnix: refactor (diff)
downloadcaelestia-shell-4f819c855714268978f368dbe667439e3de9ca39.tar.gz
caelestia-shell-4f819c855714268978f368dbe667439e3de9ca39.tar.bz2
caelestia-shell-4f819c855714268978f368dbe667439e3de9ca39.zip
internal: use systemd-inhibit
No need for custom inhibit script (it didn't even work anyways 💀)
-rw-r--r--assets/cpp/idle-inhibitor.cpp182
-rw-r--r--nix/default.nix27
-rw-r--r--services/IdleInhibitor.qml7
3 files changed, 4 insertions, 212 deletions
diff --git a/assets/cpp/idle-inhibitor.cpp b/assets/cpp/idle-inhibitor.cpp
deleted file mode 100644
index 9637b8c..0000000
--- a/assets/cpp/idle-inhibitor.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-#include <csignal>
-#include <cstring>
-#include <iostream>
-#include <unistd.h>
-#include <wayland-client-protocol.h>
-#include <wayland-client.h>
-
-// You'll need to generate these headers from the protocol XML files:
-// wayland-scanner client-header < idle-inhibit-unstable-v1.xml >
-// idle-inhibit-client-protocol.h wayland-scanner private-code <
-// idle-inhibit-unstable-v1.xml > idle-inhibit-protocol.c
-extern "C" {
-#include "idle-inhibitor.h"
-}
-
-class WaylandIdleInhibitor {
-private:
- struct wl_display *display;
- struct wl_registry *registry;
- struct wl_compositor *compositor;
- struct wl_surface *surface;
- struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager;
- struct zwp_idle_inhibitor_v1 *idle_inhibitor;
-
- static WaylandIdleInhibitor *instance;
-
- // Registry listener to get global objects
- static void registry_global(void *data, struct wl_registry *registry,
- uint32_t id, const char *interface,
- uint32_t version) {
- WaylandIdleInhibitor *inhibitor = static_cast<WaylandIdleInhibitor *>(data);
-
- if (strcmp(interface, wl_compositor_interface.name) == 0) {
- inhibitor->compositor = static_cast<struct wl_compositor *>(
- wl_registry_bind(registry, id, &wl_compositor_interface, 1));
- } else if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) ==
- 0) {
- inhibitor->idle_inhibit_manager =
- static_cast<struct zwp_idle_inhibit_manager_v1 *>(wl_registry_bind(
- registry, id, &zwp_idle_inhibit_manager_v1_interface, 1));
- }
- }
-
- static void registry_global_remove(void *data, struct wl_registry *registry,
- uint32_t id) {}
-
- static const struct wl_registry_listener registry_listener;
-
-public:
- WaylandIdleInhibitor()
- : display(nullptr), registry(nullptr), compositor(nullptr),
- surface(nullptr), idle_inhibit_manager(nullptr),
- idle_inhibitor(nullptr) {
- instance = this;
- }
-
- ~WaylandIdleInhibitor() { cleanup(); }
-
- bool initialize() {
- display = wl_display_connect(nullptr);
- if (!display) {
- return false;
- }
-
- registry = wl_display_get_registry(display);
- if (!registry) {
- return false;
- }
-
- wl_registry_add_listener(registry, &registry_listener, this);
-
- // Roundtrip to get all globals
- wl_display_roundtrip(display);
-
- if (!compositor || !idle_inhibit_manager) {
- return false;
- }
-
- return true;
- }
-
- bool createInvisibleSurface() {
- surface = wl_compositor_create_surface(compositor);
- if (!surface) {
- return false;
- }
-
- return true;
- }
-
- bool inhibitIdle() {
- if (!surface || !idle_inhibit_manager) {
- return false;
- }
-
- idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(
- idle_inhibit_manager, surface);
-
- if (!idle_inhibitor) {
- std::cerr << "Failed to create idle inhibitor\n";
- return false;
- }
-
- wl_display_roundtrip(display);
-
- std::cout << "Idle inhibition activated\n";
- return true;
- }
-
- void cleanup() {
- if (idle_inhibitor) {
- zwp_idle_inhibitor_v1_destroy(idle_inhibitor);
- idle_inhibitor = nullptr;
- }
-
- if (surface) {
- wl_surface_destroy(surface);
- surface = nullptr;
- }
-
- if (idle_inhibit_manager) {
- zwp_idle_inhibit_manager_v1_destroy(idle_inhibit_manager);
- idle_inhibit_manager = nullptr;
- }
-
- if (compositor) {
- wl_compositor_destroy(compositor);
- compositor = nullptr;
- }
-
- if (registry) {
- wl_registry_destroy(registry);
- registry = nullptr;
- }
-
- if (display) {
- wl_display_disconnect(display);
- display = nullptr;
- }
- }
-
- void run() {
- while (wl_display_dispatch(display) != -1)
- ;
- }
-
- static WaylandIdleInhibitor *getInstance() { return instance; }
-};
-
-WaylandIdleInhibitor *WaylandIdleInhibitor::instance = nullptr;
-
-const struct wl_registry_listener WaylandIdleInhibitor::registry_listener = {
- WaylandIdleInhibitor::registry_global,
- WaylandIdleInhibitor::registry_global_remove};
-
-void signalHandler(int signal) {
-
- WaylandIdleInhibitor *inhibitor = WaylandIdleInhibitor::getInstance();
- if (inhibitor) {
- inhibitor->cleanup();
- }
-
- exit(0);
-}
-
-int main() {
- signal(SIGINT, signalHandler);
- signal(SIGTERM, signalHandler);
- signal(SIGHUP, signalHandler);
-
- WaylandIdleInhibitor inhibitor;
-
- if (!(inhibitor.initialize() && inhibitor.createInvisibleSurface() &&
- inhibitor.inhibitIdle())) {
- std::cerr << "Cannot inhibit idle!" << std::endl;
- return 1;
- }
-
- inhibitor.run();
-
- return 0;
-}
diff --git a/nix/default.nix b/nix/default.nix
index c46aebb..8b1662b 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -93,29 +93,6 @@
'';
};
- idleInhibitor = stdenv.mkDerivation {
- pname = "wayland-idle-inhibitor";
- version = "1.0";
-
- src = ./../assets/cpp;
-
- nativeBuildInputs = [gcc wayland-scanner wayland-protocols];
- buildInputs = [wayland];
-
- buildPhase = ''
- wayland-scanner client-header < ${wayland-protocols}/share/wayland-protocols/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml > idle-inhibitor.h
- wayland-scanner private-code < ${wayland-protocols}/share/wayland-protocols/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml > idle-inhibitor.c
-
- gcc -o idle-inhibitor.o -c idle-inhibitor.c
- g++ -o inhibit_idle idle-inhibitor.cpp idle-inhibitor.o -lwayland-client
- '';
-
- installPhase = ''
- mkdir -p $out/bin
- install -Dm755 inhibit_idle $out/bin/inhibit_idle
- '';
- };
-
plugin = stdenv.mkDerivation {
pname = "caelestia-qt-plugin";
version = "0.0.1";
@@ -139,7 +116,7 @@ in
src = ./..;
nativeBuildInputs = [gcc makeWrapper qt6.wrapQtAppsHook];
- buildInputs = [quickshell plugin beatDetector idleInhibitor xkeyboard-config qt6.qtbase];
+ buildInputs = [quickshell plugin beatDetector xkeyboard-config qt6.qtbase];
propagatedBuildInputs = runtimeDeps;
patchPhase = ''
@@ -155,12 +132,10 @@ in
--prefix PATH : "${lib.makeBinPath runtimeDeps}" \
--set FONTCONFIG_FILE "${fontconfig}" \
--set CAELESTIA_BD_PATH ${beatDetector}/bin/beat_detector \
- --set CAELESTIA_II_PATH ${idleInhibitor}/bin/inhibit_idle \
--set CAELESTIA_XKB_RULES_PATH ${xkeyboard-config}/share/xkeyboard-config-2/rules/base.lst \
--add-flags "-p $out/share/caelestia-shell"
ln -sf ${beatDetector}/bin/beat_detector $out/bin
- ln -sf ${idleInhibitor}/bin/inhibit_idle $out/bin
'';
meta = {
diff --git a/services/IdleInhibitor.qml b/services/IdleInhibitor.qml
index 5bad30b..d975dab 100644
--- a/services/IdleInhibitor.qml
+++ b/services/IdleInhibitor.qml
@@ -9,14 +9,13 @@ Singleton {
property bool enabled: false
Process {
- id: idleInhibitProc
running: root.enabled
- command: [Quickshell.env("CAELESTIA_II_PATH") || "/usr/lib/caelestia/inhibit_idle"]
+ command: ["systemd-inhibit", "--what=idle", "--mode=block", "sleep", "inf"]
}
IpcHandler {
target: "idleInhibitor"
-
+
function isEnabled(): bool {
return root.enabled;
}
@@ -24,7 +23,7 @@ Singleton {
function toggle(): void {
root.enabled = !root.enabled;
}
-
+
function enable(): void {
root.enabled = true;
}