This commit is contained in:
2025-11-06 21:20:56 +01:00
parent 8f022b7404
commit 1345e8b3c9
4 changed files with 22 additions and 17 deletions

View File

@@ -129,7 +129,7 @@ including:
ensures there is only one valid ssh-agent running at the same time. Useful when creating ssh-agent somewhere else than the login shell scripts or across sessions. ensures there is only one valid ssh-agent running at the same time. Useful when creating ssh-agent somewhere else than the login shell scripts or across sessions.
- `screenshot` - `screenshot-script`
takes a screenshot, and sends a notification asking whether to edit it by clicking on it. Works on both Hyprland and Niri. takes a screenshot, and sends a notification asking whether to edit it by clicking on it. Works on both Hyprland and Niri.

View File

@@ -29,9 +29,9 @@ bind = , mouse:277, exec, killall rofi || rofi -show drun
bind = Super, V, exec, pkill rofi || cliphist list | rofi -dmenu -config ~/.config/rofi/dmenu.rasi -display-columns 2 -i | cliphist decode | wl-copy # Clipboard history >> clipboard bind = Super, V, exec, pkill rofi || cliphist list | rofi -dmenu -config ~/.config/rofi/dmenu.rasi -display-columns 2 -i | cliphist decode | wl-copy # Clipboard history >> clipboard
bind = Super, Period, exec, pkill rofi || rofi-emoji # Pick emoji >> clipboard bind = Super, Period, exec, pkill rofi || rofi-emoji # Pick emoji >> clipboard
bind = Ctrl+Alt, Delete, exec, pkill wlogout || wlogout -p layer-shell # [hidden] bind = Ctrl+Alt, Delete, exec, pkill wlogout || wlogout -p layer-shell # [hidden]
bind = Super+Shift, S, exec, screenshot area # Screen snip bind = Super+Shift, S, exec, screenshot-script area # Screen snip
bind = Super+Ctrl+Shift, S, exec, screenshot window # Screen snip (window) bind = Super+Ctrl+Shift, S, exec, screenshot-script window # Screen snip (window)
bind = , Print, exec, screenshot full # Screen snip (whole screen) bind = , Print, exec, screenshot-script full # Screen snip (whole screen)
# Color picker # Color picker
bind = Super+Shift, C, exec, hyprpicker -a # Pick color (Hex) >> clipboard bind = Super+Shift, C, exec, hyprpicker -a # Pick color (Hex) >> clipboard
# Fullscreen screenshot # Fullscreen screenshot

View File

@@ -322,9 +322,9 @@ binds {
Mod+V { spawn-sh "pkill -x rofi || rofi-cliphist"; } Mod+V { spawn-sh "pkill -x rofi || rofi-cliphist"; }
Mod+Period { spawn-sh "pkill -x rofi || rofi-emoji"; } Mod+Period { spawn-sh "pkill -x rofi || rofi-emoji"; }
Ctrl+Alt+Delete { spawn-sh "pkill -x wlogout || wlogout -p layer-shell"; } Ctrl+Alt+Delete { spawn-sh "pkill -x wlogout || wlogout -p layer-shell"; }
Print { spawn-sh "screenshot full"; } Print { spawn-sh "screenshot-script full"; }
Mod+Shift+S { spawn-sh "screenshot area"; } Mod+Shift+S { spawn-sh "screenshot-script area > /home/kolkas/temp.log 2>&1"; }
Mod+Ctrl+Shift+S { spawn-sh "screenshot window"; } Mod+Ctrl+Shift+S { spawn-sh "screenshot-script window"; }
Mod+Shift+C { spawn-sh "hyprpicker -a"; } Mod+Shift+C { spawn-sh "hyprpicker -a"; }
// Session // Session

View File

@@ -1,11 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse import argparse
import os import subprocess
import time
from os import environ
from datetime import datetime from datetime import datetime
from enum import Enum from enum import Enum
import time
from pathlib import Path from pathlib import Path
from shutil import copy2
# autopep8: off # autopep8: off
import gi import gi
@@ -29,22 +31,22 @@ def wait_until_file_exists(filepath: Path, timeout: int = 5):
while not filepath.exists(): while not filepath.exists():
if time.time() - start_time > timeout: if time.time() - start_time > timeout:
return False return False
time.sleep(0.1) time.sleep(0.05)
return True return True
def take_screenshot(filepath: Path, typeStr: str): def take_screenshot(filepath: Path, typeStr: str):
type = ScreenshotType(typeStr) type = ScreenshotType(typeStr)
currentDesktop = os.environ.get("XDG_CURRENT_DESKTOP", "") currentDesktop = environ.get("XDG_CURRENT_DESKTOP", "")
if "Hyprland" in currentDesktop: if "Hyprland" in currentDesktop:
cmd = { cmd = {
ScreenshotType.FULL: f"hyprshot -z -m output -m active -o {SCREENSHOT_DIR} -f ", # since I only have one monitor ScreenshotType.FULL: f"hyprshot -z -m output -m active -o {SCREENSHOT_DIR} -f ", # since I only have one monitor
ScreenshotType.AREA: f"hyprshot -z -m region -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 ", ScreenshotType.WINDOW: f"hyprshot -z -m window -o {SCREENSHOT_DIR} -f ",
} }
if os.system(f"{cmd[type]}{filepath.name}"): process = subprocess.run(f"{cmd[type]}{filepath.name}", shell=True)
print("Failed to take screenshot.") if process.returncode != 0:
exit(1) raise RuntimeError("Failed to take screenshot.")
wait_until_file_exists(filepath) wait_until_file_exists(filepath)
elif "niri" in currentDesktop: elif "niri" in currentDesktop:
cmd = { cmd = {
@@ -55,12 +57,15 @@ def take_screenshot(filepath: Path, typeStr: str):
niriScreenshotPath = SCREENSHOT_DIR / ".niri_screenshot.png" niriScreenshotPath = SCREENSHOT_DIR / ".niri_screenshot.png"
if niriScreenshotPath.exists(): if niriScreenshotPath.exists():
niriScreenshotPath.unlink() niriScreenshotPath.unlink()
if os.system(cmd[type]): # if os.system(cmd[type]):
process = subprocess.run(cmd[type], shell=True)
if process.returncode != 0:
print("Failed to take screenshot.") print("Failed to take screenshot.")
exit(1) exit(1)
wait_until_file_exists(niriScreenshotPath) wait_until_file_exists(niriScreenshotPath)
if niriScreenshotPath.exists(): if niriScreenshotPath.exists():
niriScreenshotPath.rename(filepath) # niriScreenshotPath.rename(filepath)
copy2(niriScreenshotPath, filepath)
else: else:
print("Failed to take screenshot.") print("Failed to take screenshot.")
exit(1) exit(1)
@@ -71,7 +76,7 @@ def take_screenshot(filepath: Path, typeStr: str):
def edit_screenshot(filepath: Path): def edit_screenshot(filepath: Path):
os.system(f"gradia {filepath}") subprocess.run(f"gradia {filepath}", shell=True)
def file_name(dir: Path, prefix="screenshot", ext=".png"): def file_name(dir: Path, prefix="screenshot", ext=".png"):