From 20577d184c030a23a6b384b8570f583bb32f14d2 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 25 Apr 2026 15:24:42 +0200 Subject: wf-recorder --- accounts/gkleen@sif/niri.nix | 1 + accounts/gkleen@sif/shell/default.nix | 2 + .../shell/quickshell/Services/ScreenRecord.qml | 63 ++++++++++++++++++++++ accounts/gkleen@sif/shell/quickshell/UnixIPC.qml | 9 ++++ overlays/quickshell/close-stdin.patch | 13 +++++ overlays/quickshell/default.nix | 1 + 6 files changed, 89 insertions(+) create mode 100644 accounts/gkleen@sif/shell/quickshell/Services/ScreenRecord.qml create mode 100644 overlays/quickshell/close-stdin.patch diff --git a/accounts/gkleen@sif/niri.nix b/accounts/gkleen@sif/niri.nix index 098386d0..b30c5701 100644 --- a/accounts/gkleen@sif/niri.nix +++ b/accounts/gkleen@sif/niri.nix @@ -994,6 +994,7 @@ in { }; "Mod+Semicolon".action = shell { Notifications = { DismissGroup = {}; }; }; "Mod+Shift+Semicolon".action = shell { Notifications = { DismissAll = {}; }; }; + "Mod+Print".action = shell { ScreenRecord = { Toggle = {}; }; }; })) (map ({ name, selector, spawn, key, ...}: if key != null && selector != null && spawn != null then bind key { action = focus-or-spawn-action selector name spawn; } else null) cfg.scratchspaces) (map ({ name, moveKey, ...}: if moveKey != null then bind moveKey { action = move-column-to-workspace name; } else null) cfg.scratchspaces) diff --git a/accounts/gkleen@sif/shell/default.nix b/accounts/gkleen@sif/shell/default.nix index 18cec3fd..09eb6863 100644 --- a/accounts/gkleen@sif/shell/default.nix +++ b/accounts/gkleen@sif/shell/default.nix @@ -109,6 +109,8 @@ hash = "sha256-QMGl7soAhErrrnY3aKOZpt49yebkSNzy10p/v5OaqQ0="; }); worktime = builtins.toJSON (lib.getExe pkgs.worktime); + slurp = builtins.toJSON (lib.getExe pkgs.slurp); + wf-recorder = builtins.toJSON (lib.getExe pkgs.wf-recorder); }; }; }; diff --git a/accounts/gkleen@sif/shell/quickshell/Services/ScreenRecord.qml b/accounts/gkleen@sif/shell/quickshell/Services/ScreenRecord.qml new file mode 100644 index 00000000..eb415452 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/Services/ScreenRecord.qml @@ -0,0 +1,63 @@ +pragma Singleton + +import Quickshell +import Quickshell.Io + +Singleton { + id: root + property bool active: false + property bool slurpSuccess: false + + onActiveChanged: { + if (!active) { + slurp.running = false; + screenRecorder.running = false; + } + if (active) + slurp.running = true; + } + + Process { + id: screenRecorder + running: false + onRunningChanged: { + console.log("wf-recorder running: ", screenRecorder.running); + + if (!screenRecorder.running && !slurp.running) + root.active = false; + } + stderr: SplitParser { + onRead: line => console.log("wf-recorder stderr: ", line) + } + stdout: SplitParser { + onRead: line => console.log("wf-recorder stdout: ", line) + } + } + + Process { + id: slurp + running: false + command: [ @slurp@, "-o", "-d" ] + stdout: StdioCollector {} + stderr: SplitParser { + onRead: line => console.log("slurp stderr: ", line) + } + onExited: exitCode => { + if (exitCode !== 0) { + console.log("slurp failed: ", exitCode); + root.active = false; + return; + } + console.log("slurp succeeded: ", slurp.stdout.text); + + const nowDate = new Date(); + + screenRecorder.command = [ + @wf-recorder@, + "-g", slurp.stdout.text, + "-f", `${Quickshell.env("HOME")}/screenshots/${nowDate.toLocaleString(Qt.locale(), "yyyy-MM-ddThh:mm:ss")}.mkv`, + ]; + screenRecorder.running = true; + } + } +} diff --git a/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml b/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml index 05a40dbc..3d950031 100644 --- a/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml +++ b/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml @@ -39,6 +39,8 @@ Scope { root.onCommandMpris(command.Mpris); else if (command.Notifications) root.onCommandNotifications(command.Notifications); + else if (command.ScreenRecord) + root.onCommandScreenRecord(command.ScreenRecord); else console.warn("UnixIPC: Command not handled:", JSON.stringify(command)); } @@ -94,4 +96,11 @@ Scope { notif.dismiss(); } } + + function onCommandScreenRecord(command) { + if (command.Toggle) + ScreenRecord.active = !ScreenRecord.active; + else + console.warn("UnixIPC.ScreenRecord: Command not handled:", JSON.stringify(command)); + } } diff --git a/overlays/quickshell/close-stdin.patch b/overlays/quickshell/close-stdin.patch new file mode 100644 index 00000000..230c602c --- /dev/null +++ b/overlays/quickshell/close-stdin.patch @@ -0,0 +1,13 @@ +diff --git i/src/io/process.cpp w/src/io/process.cpp +index 6055e2c..f528438 100644 +--- i/src/io/process.cpp ++++ w/src/io/process.cpp +@@ -210,7 +210,7 @@ void Process::startProcessIfReady() { + + if (this->mStdoutParser == nullptr) this->process->closeReadChannel(QProcess::StandardOutput); + if (this->mStderrParser == nullptr) this->process->closeReadChannel(QProcess::StandardError); +- if (!this->mStdinEnabled) this->process->closeWriteChannel(); ++ if (!this->mStdinEnabled) this->process->setStandardInputFile(QProcess::nullDevice()); + + this->setupEnvironment(this->process); + this->process->start(cmd, args); diff --git a/overlays/quickshell/default.nix b/overlays/quickshell/default.nix index 942eb931..9aefeeb4 100644 --- a/overlays/quickshell/default.nix +++ b/overlays/quickshell/default.nix @@ -19,6 +19,7 @@ ./lock-state-changed.patch ./pipewire.patch ./io.patch + ./close-stdin.patch ]; }); } -- cgit v1.2.3