From 12ca32e0d4f55825e0127254c362aa21b06194ff Mon Sep 17 00:00:00 2001 From: Uyanide Date: Wed, 8 Oct 2025 15:04:27 +0200 Subject: [PATCH] fix: screenshot on hyprland --- .memo/hyprland-ricing.txt | 2 +- .memo/niri-ricing.txt | 1 - .scripts/screenshot | 40 ++++++++++++++++++-------------------- hypr/hyprland/execs.conf | 3 ++- hypr/hyprland/general.conf | 8 ++++---- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/.memo/hyprland-ricing.txt b/.memo/hyprland-ricing.txt index 4c762c6..973f357 100644 --- a/.memo/hyprland-ricing.txt +++ b/.memo/hyprland-ricing.txt @@ -10,7 +10,6 @@ full KDE Plasma 6 setup # non-essential for sure # hypr* hyprland -hyprpaper hypridle hyprlock hyprshot @@ -29,6 +28,7 @@ kitty # normal terminal ghostty # floating terminal, for btop for example # under surface +swww # wallpaper daemon mako # notification daemon gnome-keyring # --password-store=gnome-libsecret wl-clipboard diff --git a/.memo/niri-ricing.txt b/.memo/niri-ricing.txt index b32e4e1..4f3570b 100644 --- a/.memo/niri-ricing.txt +++ b/.memo/niri-ricing.txt @@ -2,5 +2,4 @@ things I have installed: everything in `./hyprland-ricing.txt`, in addition to: -swww xwayland-satellite diff --git a/.scripts/screenshot b/.scripts/screenshot index 3bb7130..6dd1c98 100755 --- a/.scripts/screenshot +++ b/.scripts/screenshot @@ -5,6 +5,7 @@ import os from datetime import datetime from enum import Enum import time +from pathlib import Path # autopep8: off import gi @@ -19,23 +20,20 @@ class ScreenshotType(Enum): WINDOW = "window" -SCREENSHOT_DIR = os.path.join( - os.environ.get("XDG_PICTURES_DIR", os.path.expanduser("~/Pictures")), - "Screenshots" -) +SCREENSHOT_DIR = Path.home() / "Pictures" / "Screenshots" -def wait_until_file_exists(filepath: str, timeout: int = 5): +def wait_until_file_exists(filepath: Path, timeout: int = 5): """Wait until a file exists or timeout.""" start_time = time.time() - while not os.path.isfile(filepath): + while not filepath.exists(): if time.time() - start_time > timeout: return False time.sleep(0.1) return True -def take_screenshot(typeStr: str, filepath: str): +def take_screenshot(filepath: Path, typeStr: str): type = ScreenshotType(typeStr) currentDesktop = os.environ.get("XDG_CURRENT_DESKTOP", "") if "Hyprland" in currentDesktop: @@ -44,7 +42,7 @@ def take_screenshot(typeStr: str, filepath: str): ScreenshotType.AREA: f"hyprshot -z -m region -o {SCREENSHOT_DIR} -f ", ScreenshotType.WINDOW: f"hyprshot -z -m window -o {SCREENSHOT_DIR} -f ", } - os.system(f"{cmd[type]}{filepath}") + os.system(f"{cmd[type]}{filepath.name}") wait_until_file_exists(filepath) elif "niri" in currentDesktop: cmd = { @@ -52,24 +50,24 @@ def take_screenshot(typeStr: str, filepath: str): ScreenshotType.AREA: f"niri msg action screenshot", ScreenshotType.WINDOW: f"niri msg action screenshot-window", } - niriScreenshotPath = SCREENSHOT_DIR + os.sep + ".niri_screenshot.png" - if os.path.isfile(niriScreenshotPath): - os.remove(niriScreenshotPath) + niriScreenshotPath = SCREENSHOT_DIR / ".niri_screenshot.png" + if niriScreenshotPath.exists(): + niriScreenshotPath.unlink() os.system(cmd[type]) wait_until_file_exists(niriScreenshotPath) - if os.path.isfile(niriScreenshotPath): - os.rename(niriScreenshotPath, filepath) + if niriScreenshotPath.exists(): + niriScreenshotPath.rename(filepath) wait_until_file_exists(filepath) else: print("Unsupported desktop environment.") exit(1) -def edit_screenshot(filepath: str): - os.system(f"gradia {SCREENSHOT_DIR}{os.sep}{filepath}") +def edit_screenshot(filepath: Path): + os.system(f"gradia {filepath}") -def file_name(dir, prefix="screenshot", ext=".png"): +def file_name(dir: Path, prefix="screenshot", ext=".png"): timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") return f"{prefix}_{timestamp}{ext}" @@ -84,15 +82,15 @@ if __name__ == "__main__": args = parser.parse_args() # file path - os.makedirs(SCREENSHOT_DIR, exist_ok=True) + SCREENSHOT_DIR.mkdir(parents=True, exist_ok=True) filename = file_name(SCREENSHOT_DIR) - filepath = os.path.join(SCREENSHOT_DIR, filename) + filepath = SCREENSHOT_DIR / filename # take screenshot - take_screenshot(args.type, filepath) + take_screenshot(filepath, args.type) # check if successful - if not os.path.isfile(filepath): + if not filepath.exists(): print("Failed to take screenshot.") exit(1) @@ -104,7 +102,7 @@ if __name__ == "__main__": def edit_callback(n, action, user_data): global editing editing = True - edit_screenshot(filename) + edit_screenshot(filepath) n.close() loop.quit() diff --git a/hypr/hyprland/execs.conf b/hypr/hyprland/execs.conf index e6884a4..e79f5a1 100755 --- a/hypr/hyprland/execs.conf +++ b/hypr/hyprland/execs.conf @@ -3,7 +3,8 @@ exec-once = config-switch Hyprland # Bar, wallpaper exec-once = waybar -exec-once = hyprpaper +exec-once = swww-daemon -n background +exec-once = sleep 1 && swww img -n background $(find $HOME/.local/share/wallpaper/current -type f | head -n 1) --transition-type fade --transition-duration 2 # Input method exec-once = fcitx5 diff --git a/hypr/hyprland/general.conf b/hypr/hyprland/general.conf index 0965c46..89ce80a 100755 --- a/hypr/hyprland/general.conf +++ b/hypr/hyprland/general.conf @@ -176,10 +176,10 @@ xwayland { force_zero_scaling = true } -# debug { -# overlay = true -# disable_logs = false -# } +debug { + # overlay = true + disable_logs = false +} experimental { xx_color_management_v4 = true