makes no sense
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<img src="https://git.uyani.de/Uyanide/dotfiles/raw/branch/main/assets/works-on-my-machines.png" alt="Works on my machine(s)" width="200" />
|
||||
<img src="https://raw.githubusercontent.com/Uyanide/dotfiles/refs/heads/main/assets/works-on-my-machines.png" alt="Works on my machine(s)" width="200" />
|
||||
|
||||
## How it looks like...
|
||||
|
||||
|
||||
@@ -7,5 +7,7 @@ for child in $(pgrep -P "$pid" 2>/dev/null); do
|
||||
kill "$child"
|
||||
done
|
||||
|
||||
sleep 0.3
|
||||
|
||||
kill "$pid"
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
import argparse
|
||||
import subprocess
|
||||
import time
|
||||
import fcntl
|
||||
from os import environ
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
@@ -36,7 +37,7 @@ class ScreenshotType(Enum):
|
||||
SCREENSHOT_DIR = Path.home() / "Pictures" / "Screenshots"
|
||||
|
||||
|
||||
def wait_until_file_exists(filepath: Path, timeout: int = 5):
|
||||
def wait_until_file_exists(filepath: Path, timeout: int = 1):
|
||||
"""Wait until a file exists or timeout."""
|
||||
start_time = time.time()
|
||||
while not filepath.exists():
|
||||
@@ -47,18 +48,28 @@ def wait_until_file_exists(filepath: Path, timeout: int = 5):
|
||||
|
||||
|
||||
def take_screenshot(filepath: Path, typeStr: str):
|
||||
lock_fd = open("/tmp/screenshot-script.lock", "w")
|
||||
try:
|
||||
fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except IOError:
|
||||
lock_fd.close()
|
||||
raise RuntimeError("Another screenshot is currently being taken.")
|
||||
|
||||
try:
|
||||
type = ScreenshotType(typeStr)
|
||||
currentDesktop = environ.get("XDG_CURRENT_DESKTOP", "")
|
||||
if "Hyprland" in currentDesktop:
|
||||
cmd = {
|
||||
ScreenshotType.FULL: f"hyprshot -z -m output -m active -o {SCREENSHOT_DIR} -f ", # since I only have one monitor
|
||||
# since I only have one monitor
|
||||
ScreenshotType.FULL: f"hyprshot -z -m output -m active -o {SCREENSHOT_DIR} -f ",
|
||||
ScreenshotType.AREA: f"hyprshot -z -m region -o {SCREENSHOT_DIR} -f ",
|
||||
ScreenshotType.WINDOW: f"hyprshot -z -m window -o {SCREENSHOT_DIR} -f ",
|
||||
}
|
||||
process = subprocess.run(f"{cmd[type]}{filepath.name}", shell=True)
|
||||
if process.returncode != 0:
|
||||
raise RuntimeError("Failed to take screenshot: hyprshot command failed.")
|
||||
wait_until_file_exists(filepath)
|
||||
if not wait_until_file_exists(filepath):
|
||||
raise RuntimeError("Failed to take screenshot: output file not found after hyprshot command.")
|
||||
elif "niri" in currentDesktop:
|
||||
cmd = {
|
||||
ScreenshotType.FULL: "niri msg action screenshot-screen",
|
||||
@@ -72,16 +83,20 @@ def take_screenshot(filepath: Path, typeStr: str):
|
||||
process = subprocess.run(cmd[type], shell=True)
|
||||
if process.returncode != 0:
|
||||
raise RuntimeError("Failed to take screenshot: niri built-in screenshot command failed.")
|
||||
wait_until_file_exists(niriScreenshotPath)
|
||||
if niriScreenshotPath.exists():
|
||||
|
||||
if wait_until_file_exists(niriScreenshotPath):
|
||||
# niriScreenshotPath.rename(filepath)
|
||||
copy2(niriScreenshotPath, filepath)
|
||||
else:
|
||||
raise RuntimeError("Failed to take screenshot: screenshot file nto found after niri command.")
|
||||
wait_until_file_exists(filepath)
|
||||
raise RuntimeError("Failed to take screenshot: output file not found after niri command.")
|
||||
if not wait_until_file_exists(filepath):
|
||||
raise RuntimeError("Failed to take screenshot: output file not found after copying.")
|
||||
else:
|
||||
# print("Unsupported desktop environment.")
|
||||
raise RuntimeError("Unsupported desktop environment.")
|
||||
finally:
|
||||
fcntl.flock(lock_fd, fcntl.LOCK_UN)
|
||||
lock_fd.close()
|
||||
|
||||
|
||||
def edit_screenshot(filepath: Path):
|
||||
|
||||
Reference in New Issue
Block a user