summaryrefslogtreecommitdiff
path: root/src/caelestia
diff options
context:
space:
mode:
authoranders130 <93037023+anders130@users.noreply.github.com>2025-08-13 08:07:12 +0200
committerGitHub <noreply@github.com>2025-08-13 16:07:12 +1000
commit1fcfb83fba25d6713f9f7815ee62acd2fc84afb5 (patch)
tree1c13c542392ab13d5af278adf36dfb4136376f0b /src/caelestia
parent[CI] chore: update flake (diff)
downloadcaelestia-cli-1fcfb83fba25d6713f9f7815ee62acd2fc84afb5.tar.gz
caelestia-cli-1fcfb83fba25d6713f9f7815ee62acd2fc84afb5.tar.bz2
caelestia-cli-1fcfb83fba25d6713f9f7815ee62acd2fc84afb5.zip
record: fix multi-monitor and moving across filesystems (#38)
* fix(record): support differing filesystems for recording destination * fix(record): for multi-monitor-systems wl-screenrec needs a -o argument * fix(record): replace path.rename with shutil.move * fix(record): use json option to retrieve hyprland focused monitor * use generator --------- Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Diffstat (limited to 'src/caelestia')
-rw-r--r--src/caelestia/subcommands/record.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/caelestia/subcommands/record.py b/src/caelestia/subcommands/record.py
index 69c961e..b7f0f65 100644
--- a/src/caelestia/subcommands/record.py
+++ b/src/caelestia/subcommands/record.py
@@ -1,3 +1,5 @@
+import json
+import shutil
import subprocess
import time
from argparse import Namespace
@@ -14,12 +16,14 @@ class Command:
self.args = args
def run(self) -> None:
- proc = subprocess.run(["pidof", "wl-screenrec"])
- if proc.returncode == 0:
+ if self.proc_running():
self.stop()
else:
self.start()
+ def proc_running(self) -> bool:
+ return subprocess.run(["pidof", "wl-screenrec"], stdout=subprocess.DEVNULL).returncode == 0
+
def start(self) -> None:
args = []
@@ -30,6 +34,11 @@ class Command:
region = self.args.region
args += ["-g", region.strip()]
+ monitors = json.loads(subprocess.check_output(["hyprctl", "monitors", "-j"]))
+ focused_monitor = next(monitor for monitor in monitors if monitor["focused"])
+ if focused_monitor:
+ args += ["-o", focused_monitor["name"]]
+
if self.args.sound:
sources = subprocess.check_output(["pactl", "list", "short", "sources"], text=True).splitlines()
for source in sources:
@@ -56,12 +65,17 @@ class Command:
notify("Recording failed", f"Recording failed to start: {proc.communicate()[1]}")
def stop(self) -> None:
+ # Start killing recording process
subprocess.run(["pkill", "wl-screenrec"])
+ # Wait for recording to finish to avoid corrupted video file
+ while self.proc_running():
+ time.sleep(0.1)
+
# Move to recordings folder
new_path = recordings_dir / f"recording_{datetime.now().strftime('%Y%m%d_%H-%M-%S')}.mp4"
recordings_dir.mkdir(exist_ok=True, parents=True)
- recording_path.rename(new_path)
+ shutil.move(recording_path, new_path)
# Close start notification
try:
@@ -75,7 +89,8 @@ class Command:
"--object-path=/org/freedesktop/Notifications",
"--method=org.freedesktop.Notifications.CloseNotification",
notif,
- ]
+ ],
+ stdout=subprocess.DEVNULL,
)
except IOError:
pass