74 lines
2.2 KiB
Nix
74 lines
2.2 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
# Keyboard-driven screenshots copy to the clipboard before Satty opens for
|
|
# annotation. Satty copies annotated screenshots when it saves them.
|
|
let
|
|
execBind = key: command: {
|
|
_args = [
|
|
key
|
|
(luaCall "hl.dsp.exec_cmd" [ command ])
|
|
];
|
|
};
|
|
luaCall =
|
|
function: args:
|
|
lib.generators.mkLuaInline "${function}(${lib.concatMapStringsSep ", " toLua args})";
|
|
|
|
user = config.user.name;
|
|
|
|
grimblast = "${pkgs.grimblast}/bin/grimblast";
|
|
satty = "${pkgs.satty}/bin/satty";
|
|
tee = "${pkgs.coreutils}/bin/tee";
|
|
wl-copy = "${pkgs.wl-clipboard}/bin/wl-copy";
|
|
xdgUserDir = "${pkgs.xdg-user-dirs}/bin/xdg-user-dir";
|
|
|
|
# Copy the original screenshot before Satty opens.
|
|
# Satty copies and saves annotated screenshots when the user presses Enter.
|
|
capture =
|
|
target:
|
|
pkgs.writeShellScript "screenshot-${target}" ''
|
|
dir="$(${xdgUserDir} PICTURES)/Screenshots"
|
|
mkdir -p "$dir"
|
|
${grimblast} save ${target} - \
|
|
| ${tee} >(${wl-copy}) \
|
|
| ${satty} --filename - \
|
|
--output-filename "$dir/screenshot-%Y%m%d-%H%M%S.png" \
|
|
--copy-command ${wl-copy} \
|
|
--save-after-copy \
|
|
--early-exit \
|
|
--actions-on-enter save-to-clipboard
|
|
'';
|
|
|
|
toLua = lib.generators.toLua { };
|
|
in
|
|
{
|
|
options.modules.desktop.utilities.screenshot.enable =
|
|
lib.mkEnableOption "screenshots via grimblast and satty";
|
|
|
|
config = lib.mkIf config.modules.desktop.utilities.screenshot.enable {
|
|
home-manager.users.${user} = {
|
|
# satty is a one-shot annotation surface, so float it rather than letting
|
|
# it claim a tile in the layout.
|
|
wayland.windowManager.hyprland.settings.window_rule = [
|
|
{
|
|
name = "satty-float";
|
|
match.class = "^(com\\.gabm\\.satty)$";
|
|
float = true;
|
|
}
|
|
];
|
|
|
|
# Print with plain/Shift/Ctrl for region/window/full.
|
|
# Super+L is already the hjkl focus and movement bind, so screenshots take
|
|
# the Print key instead.
|
|
wayland.windowManager.hyprland.settings.bind = [
|
|
(execBind "Print" "${capture "area"}")
|
|
(execBind "SHIFT + Print" "${capture "active"}")
|
|
(execBind "CTRL + Print" "${capture "screen"}")
|
|
];
|
|
};
|
|
};
|
|
}
|