internal: use systemd-inhibit
No need for custom inhibit script (it didn't even work anyways 💀)
This commit is contained in:
parent
aa66f3c880
commit
4f819c8557
3 changed files with 4 additions and 212 deletions
|
|
@ -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, ®istry_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;
|
|
||||||
}
|
|
||||||
|
|
@ -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 {
|
plugin = stdenv.mkDerivation {
|
||||||
pname = "caelestia-qt-plugin";
|
pname = "caelestia-qt-plugin";
|
||||||
version = "0.0.1";
|
version = "0.0.1";
|
||||||
|
|
@ -139,7 +116,7 @@ in
|
||||||
src = ./..;
|
src = ./..;
|
||||||
|
|
||||||
nativeBuildInputs = [gcc makeWrapper qt6.wrapQtAppsHook];
|
nativeBuildInputs = [gcc makeWrapper qt6.wrapQtAppsHook];
|
||||||
buildInputs = [quickshell plugin beatDetector idleInhibitor xkeyboard-config qt6.qtbase];
|
buildInputs = [quickshell plugin beatDetector xkeyboard-config qt6.qtbase];
|
||||||
propagatedBuildInputs = runtimeDeps;
|
propagatedBuildInputs = runtimeDeps;
|
||||||
|
|
||||||
patchPhase = ''
|
patchPhase = ''
|
||||||
|
|
@ -155,12 +132,10 @@ in
|
||||||
--prefix PATH : "${lib.makeBinPath runtimeDeps}" \
|
--prefix PATH : "${lib.makeBinPath runtimeDeps}" \
|
||||||
--set FONTCONFIG_FILE "${fontconfig}" \
|
--set FONTCONFIG_FILE "${fontconfig}" \
|
||||||
--set CAELESTIA_BD_PATH ${beatDetector}/bin/beat_detector \
|
--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 \
|
--set CAELESTIA_XKB_RULES_PATH ${xkeyboard-config}/share/xkeyboard-config-2/rules/base.lst \
|
||||||
--add-flags "-p $out/share/caelestia-shell"
|
--add-flags "-p $out/share/caelestia-shell"
|
||||||
|
|
||||||
ln -sf ${beatDetector}/bin/beat_detector $out/bin
|
ln -sf ${beatDetector}/bin/beat_detector $out/bin
|
||||||
ln -sf ${idleInhibitor}/bin/inhibit_idle $out/bin
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,8 @@ Singleton {
|
||||||
property bool enabled: false
|
property bool enabled: false
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: idleInhibitProc
|
|
||||||
running: root.enabled
|
running: root.enabled
|
||||||
command: [Quickshell.env("CAELESTIA_II_PATH") || "/usr/lib/caelestia/inhibit_idle"]
|
command: ["systemd-inhibit", "--what=idle", "--mode=block", "sleep", "inf"]
|
||||||
}
|
}
|
||||||
|
|
||||||
IpcHandler {
|
IpcHandler {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue