From 09e31ebfd847c2cb065506340b11a8da9b2042fe Mon Sep 17 00:00:00 2001 From: Szymon P Date: Wed, 25 Feb 2026 09:02:03 +0100 Subject: [PATCH] update: modules/hypr/hyprland.nix --- flake.nix | 1 + modules/hypr/hyprland.nix | 54 ++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 7f9e13d..4886373 100644 --- a/flake.nix +++ b/flake.nix @@ -44,6 +44,7 @@ pathConfig = { wallpaper = "Obrazy/tapety/catppuccin"; + screenshot = "Obrazy/zrzuty/"; }; }; diff --git a/modules/hypr/hyprland.nix b/modules/hypr/hyprland.nix index 5ea0a98..6bd535d 100644 --- a/modules/hypr/hyprland.nix +++ b/modules/hypr/hyprland.nix @@ -102,9 +102,14 @@ }; permission = [ - ".*(grim), screencopy, allow" - ".*(hyprlock), screencopy, allow" - ".*(xdg-desktop-portal-hyprland), screencopy, allow" + "${if isNixOS then "^${pkgs.grim}/bin/grim$" else "^/usr/bin/grim$"}" + "^${if isNixOS then "${pkgs.hyprlock}/bin/hyprlock" else "/usr/bin/hyprlock"}$, screencopy, allow" + "^${ + if isNixOS then + "${pkgs.xdg-desktop-portal-hyprland}/libexec/xdg-desktop-portal-hyprland" + else + "/usr/lib/xdg-desktop-portal-hyprland" + }$, screencopy, allow" ]; input = { @@ -308,9 +313,46 @@ ]; bindt = [ - ", PRINT, exec, ~/.local/bin/screenshot.sh region" - "$mainMod, PRINT, exec, ~/.local/bin/screenshot.sh fullscreen" - "alt_l, PRINT, exec, ~/.local/bin/screenshot.sh window" + ", PRINT, exec, ${pkgs.writeShellScript "region" '' + "$mainMod, PRINT, exec, ${pkgs.writeShellScript "screenshot-region" '' + MONITOR=$(hyprctl monitors -j | ${ + if isNixOS then "${pkgs.jq}/bin/jq" else "/usr/bin/jq" + } -r '.[] | select(.focused == true) | .name') + ${if isNixOS then "${pkgs.grim}/bin/grim" else "/usr/bin/grim"} -o "$MONITOR" - | ${ + if isNixOS then "${pkgs.satty}/bin/satty" else "/usr/bin/satty" + } -f - + ''}" + ''}" + + "$mainMod, PRINT, exec, ${pkgs.writeShellScript "screenshot-fullscreen" '' + target_path=${userConfig.pathConfig.screenshot}/$(date +'%d-%m-%Y_%H:%M:%S') + MONITOR=$(hyprctl monitors -j | ${ + if isNixOS then "${pkgs.jq}/bin/jq" else "/usr/bin/jq" + } -r '.[] | select(.focused == true) | .name') ${ + if isNixOS then "${pkgs.grim}/bin/grim" else "/usr/bin/grim" + } -o "$MONITOR" "$target_path" + ${if isNixOS then "${pkgs.wl-clipboard}/bin/wl-copy" else "/usr/bin/wl-copy"} < "$target_path" + ${ + if isNixOS then "${pkgs.libnotify}/bin/notify-send" else "/usr/bin/notify-send" + } -i "$target_path" -u low -a "Screenshot" "Screenshot fullscreen" "Saved and copied" + ''}" + + "alt_l, PRINT, exec, ${pkgs.writeShellScript "screenshot-window" '' + target_path="~/${userConfig.pathConfig.screenshot}/$(date +'%d-%m-%Y_%H-%M-%S').png" + mkdir -p "$(dirname "$target_path")" + + GEOMETRY=$(hyprctl activewindow -j | ${ + if isNixOS then "${pkgs.jq}/bin/jq" else "/usr/bin/jq" + } -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"') + + ${if isNixOS then "${pkgs.grim}/bin/grim" else "/usr/bin/grim"} -g "$GEOMETRY" "$target_path" + + ${if isNixOS then "${pkgs.wl-clipboard}/bin/wl-copy" else "/usr/bin/wl-copy"} < "$target_path" + + ${ + if isNixOS then "${pkgs.libnotify}/bin/notify-send" else "/usr/bin/notify-send" + } -i "$target_path" -u low -a "Screenshot" "Screenshot window" "Saved and copied" + ''}" ]; bindm = [