2017-09-04 16:35:23 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.feh;
|
|
|
|
|
2020-09-27 14:20:19 +02:00
|
|
|
bindingsOf = t: with types; attrsOf (nullOr (either t (listOf t)));
|
|
|
|
|
2024-11-14 18:16:21 +01:00
|
|
|
renderThemes = options:
|
|
|
|
let
|
|
|
|
render =
|
|
|
|
mapAttrsToList (theme: options: "${theme} ${escapeShellArgs options}");
|
|
|
|
in concatStringsSep "\n" (render options);
|
|
|
|
|
2020-09-27 14:20:19 +02:00
|
|
|
renderBindings = bindings:
|
|
|
|
let
|
|
|
|
enabled = filterAttrs (n: v: v != null) bindings;
|
|
|
|
disabled = filterAttrs (n: v: v == null) bindings;
|
|
|
|
render = mapAttrsToList renderBinding;
|
|
|
|
in concatStringsSep "\n" (render disabled ++ render enabled);
|
|
|
|
|
|
|
|
renderBinding = func: key:
|
|
|
|
if key == null then
|
|
|
|
func
|
|
|
|
else if isList key then
|
|
|
|
concatStringsSep " " ([ func ] ++ map toString key)
|
|
|
|
else
|
|
|
|
"${func} ${toString key}";
|
2017-09-04 16:35:23 +02:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2017-09-04 16:35:23 +02:00
|
|
|
options.programs.feh = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "feh - a fast and light image viewer";
|
2017-09-04 16:35:23 +02:00
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
package = mkPackageOption pkgs "feh" { };
|
2023-01-02 20:36:23 +01:00
|
|
|
|
2020-01-30 10:44:54 +01:00
|
|
|
buttons = mkOption {
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2020-09-27 14:20:19 +02:00
|
|
|
type = with types; bindingsOf (either str int);
|
2020-02-02 00:39:17 +01:00
|
|
|
example = {
|
|
|
|
zoom_in = 4;
|
|
|
|
zoom_out = "C-4";
|
2020-09-27 14:20:19 +02:00
|
|
|
prev_img = [ 3 "C-3" ];
|
2020-02-02 00:39:17 +01:00
|
|
|
};
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-01-30 10:44:54 +01:00
|
|
|
Override feh's default mouse button mapping. If you want to disable an
|
2020-09-27 14:20:19 +02:00
|
|
|
action, set its value to null. If you want to bind multiple buttons to
|
|
|
|
an action, set its value to a list.
|
2024-11-14 18:16:21 +01:00
|
|
|
See <https://man.finalrewind.org/1/feh/#BUTTONS_CONFIG_SYNTAX> for
|
2020-01-30 10:44:54 +01:00
|
|
|
default bindings and available commands.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-09-04 16:35:23 +02:00
|
|
|
keybindings = mkOption {
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2020-09-27 14:20:19 +02:00
|
|
|
type = bindingsOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
example = {
|
|
|
|
zoom_in = "plus";
|
|
|
|
zoom_out = "minus";
|
2020-09-27 14:20:19 +02:00
|
|
|
prev_img = [ "h" "Left" ];
|
2020-02-02 00:39:17 +01:00
|
|
|
};
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-01-30 10:44:54 +01:00
|
|
|
Override feh's default keybindings. If you want to disable a keybinding
|
2020-09-27 14:20:19 +02:00
|
|
|
set its value to null. If you want to bind multiple keys to an action,
|
|
|
|
set its value to a list.
|
2024-11-14 18:16:21 +01:00
|
|
|
See <https://man.finalrewind.org/1/feh/#KEYS_CONFIG_SYNTAX> for
|
2017-09-04 16:35:23 +02:00
|
|
|
default bindings and available commands.
|
|
|
|
'';
|
|
|
|
};
|
2024-11-14 18:16:21 +01:00
|
|
|
|
|
|
|
themes = mkOption {
|
|
|
|
default = { };
|
|
|
|
type = with types; attrsOf (listOf str);
|
|
|
|
example = {
|
|
|
|
feh = [ "--image-bg" "black" ];
|
|
|
|
webcam = [ "--multiwindow" "--reload" "20" ];
|
|
|
|
present = [ "--full-screen" "--sort" "name" "--hide-pointer" ];
|
|
|
|
booth = [ "--full-screen" "--hide-pointer" "--slideshow-delay" "20" ];
|
|
|
|
imagemap = [
|
|
|
|
"-rVq"
|
|
|
|
"--thumb-width"
|
|
|
|
"40"
|
|
|
|
"--thumb-height"
|
|
|
|
"30"
|
|
|
|
"--index-info"
|
|
|
|
"%n\\n%wx%h"
|
|
|
|
];
|
|
|
|
example = [ "--info" "foo bar" ];
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Define themes for feh.
|
|
|
|
See <https://man.finalrewind.org/1/feh/#THEMES_CONFIG_SYNTAX> for
|
|
|
|
important guidelines and limitations related to theme configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-09-04 16:35:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-02-02 00:39:17 +01:00
|
|
|
assertions = [{
|
|
|
|
assertion = ((filterAttrs (n: v: v == "") cfg.keybindings) == { });
|
|
|
|
message =
|
|
|
|
"To disable a keybinding, use `null` instead of an empty string.";
|
|
|
|
}];
|
2020-01-30 10:44:54 +01:00
|
|
|
|
2023-01-02 20:36:23 +01:00
|
|
|
home.packages = [ cfg.package ];
|
2017-09-04 16:35:23 +02:00
|
|
|
|
2020-09-27 14:20:19 +02:00
|
|
|
xdg.configFile."feh/buttons" =
|
|
|
|
mkIf (cfg.buttons != { }) { text = renderBindings cfg.buttons + "\n"; };
|
2017-09-04 16:35:23 +02:00
|
|
|
|
2020-09-27 14:20:19 +02:00
|
|
|
xdg.configFile."feh/keys" = mkIf (cfg.keybindings != { }) {
|
|
|
|
text = renderBindings cfg.keybindings + "\n";
|
|
|
|
};
|
2024-11-14 18:16:21 +01:00
|
|
|
|
|
|
|
xdg.configFile."feh/themes" =
|
|
|
|
mkIf (cfg.themes != { }) { text = renderThemes cfg.themes + "\n"; };
|
2017-09-04 16:35:23 +02:00
|
|
|
};
|
|
|
|
}
|