diff --git a/home/programs/graphical/wms/hyprland/config/keybinds.nix b/home/programs/graphical/wms/hyprland/config/keybinds.nix index 91bfa5a..9b3143f 100644 --- a/home/programs/graphical/wms/hyprland/config/keybinds.nix +++ b/home/programs/graphical/wms/hyprland/config/keybinds.nix @@ -1,4 +1,4 @@ -{ +{ config, ... }: { wayland.windowManager.hyprland = { settings = { "$MOUSE_LMB" = "mouse:272"; @@ -9,6 +9,9 @@ "$XF86Favorites" = "164"; + "$SCREENSHOT_FORMAT" = "${config.xdg.userDirs.extraConfig.XDG_SCREENSHOTS_DIR}/Screenshot_''$(date +%Y-%m-%d_%H-%M-%S).png"; + "$SCREENSHOT_DELAY" = "2000"; + bind = [ # # Active window @@ -36,7 +39,21 @@ # # Screenshots # - # TODO: requires script + "ALT, Print, exec, wl-copy \"$(hyprpicker)\" && notify-send 'Picked color' \"$(wl-paste) (saved to clipboard)\"" + ", Print, exec, hyprland-screenshot --notify --copy --target area" + "SUPER, Print, exec, hyprland-screenshot --notify --copy --target area --edit" + "SHIFT, Print, exec, hyprland-screenshot --notify --save $SCREENSHOT_FORMAT --target area" + "CTRL, Print, exec, hyprland-screenshot --notify --copy --target area --delay $SCREENSHOT_DELAY" + "SUPER_SHIFT, Print, exec, hyprland-screenshot --notify --save $SCREENSHOT_FORMAT --target area --edit" + "SUPER_CTRL, Print, exec, hyprland-screenshot --notify --copy --target area --delay $SCREENSHOT_DELAY --edit" + "SUPER_SHIFT_CTRL, Print, exec, hyprland-screenshot --notify --save $SCREENSHOT_FORMAT --target area --delay $SCREENSHOT_DELAY --edit" + "CTRL, T, exec, hyprland-screenshot --save $SCREENSHOT_FORMAT --target all" + #" , Print, exec, screenshot --save $SCREENSHOT_FORMAT --target all" + + # XF86Favorites key for recording + # (don't question me, I had it free) + ", $XF86Favorites, exec, quick-record --notify toggle" + "SUPER, $XF86Favorites, exec, quick-record toggle" # # Brightness control diff --git a/home/programs/graphical/wms/hyprland/default.nix b/home/programs/graphical/wms/hyprland/default.nix index 7b1ce94..fac274d 100644 --- a/home/programs/graphical/wms/hyprland/default.nix +++ b/home/programs/graphical/wms/hyprland/default.nix @@ -17,7 +17,9 @@ in { config = mkIf cfg.enable { home.packages = [ hyprPkgs.hyprland-move-window + hyprPkgs.hyprland-screenshot pkgs.brightnessctl + pkgs.hyprpicker hyprPkgs.brightness ]; diff --git a/home/programs/graphical/wms/hyprland/packages/default.nix b/home/programs/graphical/wms/hyprland/packages/default.nix index f5c76ee..c3d2e3a 100644 --- a/home/programs/graphical/wms/hyprland/packages/default.nix +++ b/home/programs/graphical/wms/hyprland/packages/default.nix @@ -5,6 +5,7 @@ packages = { hyprland-move-window = pkgs.callPackage ./hyprland-move-window {}; brightness = pkgs.callPackage ./brightness {}; + hyprland-screenshot = pkgs.callPackage ./hyprland-screenshot {}; }; in packages diff --git a/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/default.nix b/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/default.nix new file mode 100644 index 0000000..06cfe2e --- /dev/null +++ b/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/default.nix @@ -0,0 +1,24 @@ +# - `grim`: screenshot utility for wayland +# - `slurp`: to select an area +# - `hyprctl`: to read properties of current window +# - `wl-copy`: clipboard utility +# - `jq`: json utility to parse hyprctl output +# - `notify-send`: to show notifications +# - `swappy`: for editing the screenshots (only required for --edit) + +{pkgs, ...}: +pkgs.writeShellApplication { + name = "hyprland-screenshot"; + runtimeInputs = with pkgs; [ + jq + grim + slurp + swappy + wl-clipboard + libnotify + hyprland + ]; + text = '' + ${builtins.readFile ./hyprland-screenshot.sh} + ''; +} diff --git a/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/hyprland-screenshot.sh b/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/hyprland-screenshot.sh new file mode 100644 index 0000000..a48af52 --- /dev/null +++ b/home/programs/graphical/wms/hyprland/packages/hyprland-screenshot/hyprland-screenshot.sh @@ -0,0 +1,216 @@ +#!/bin/sh + +# Inspired by grimblast (https://github.com/hyprwm/contrib/blob/main/grimblast/grimblast) + +# Helper functions + +die() { + MSG="${1}" + ERR_CODE="${2:-1}" + URGENCY="${3:-critical}" + + >&2 echo "$MSG" + if [ "$NOTIFY" = "yes" ]; then + notify-send -a screenshot -u "$URGENCY" "Error ($ERR_CODE)" "$MSG" + fi + exit "$ERR_CODE" +} + +# Argument parsing + +SAVE_METHOD= +SAVE_FILE= +TARGET= +NOTIFY=no +CURSOR=no +EDIT=no +DELAY=0 + +while [ "${1-}" ]; do + case "$1" in + -h | --help) + >&2 cat <