Skip to content

Commit

Permalink
Add wallpaperFillMode configuration option (#338)
Browse files Browse the repository at this point in the history
Co-authored-by: Heitor Augusto <[email protected]>
  • Loading branch information
bemyak and HeitorAugustoLN authored Aug 22, 2024
1 parent df4d1d3 commit 0b7f9b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/wallpapers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,16 @@
};
};
};

# Values are taken from
# https://invent.kde.org/plasma/kdeplasma-addons/-/blob/bc53d651cf60709396c9229f8c582ec8a9d2ee53/applets/mediaframe/package/contents/ui/ConfigGeneral.qml#L148-170
wallpaperFillModeTypes = {
"stretch" = 0; # a.k.a. Scaled
"preserveAspectFit" = 1; # a.k.a. Scaled Keep Proportions
"preserveAspectCrop" = 2; # a.k.a. Scaled And Cropped
"tile" = 3;
"tileVertically" = 4;
"tileHorizontally" = 5;
"pad" = 6; # a.k.a. Centered
};
}
4 changes: 4 additions & 0 deletions modules/panels.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
} @ args:
let
cfg = config.programs.plasma;
inherit (import ../lib/wallpapers.nix { inherit lib; }) wallpaperFillModeTypes;

hasWidget = widgetName: builtins.any (panel: builtins.any (widget: widget.name == widgetName) panel.widgets) cfg.panels;

# An attrset keeping track of the packages which should be added when a
Expand Down Expand Up @@ -211,6 +213,7 @@ in
"\"" + (builtins.toString path) + "\"" else
"[" + (builtins.concatStringsSep "," (map (s: "\"" + s + "\"") path)) + "]"});
desktop.writeConfig("SlideInterval", "${builtins.toString cfg.workspace.wallpaperSlideShow.interval}");
${lib.optionalString (cfg.workspace.wallpaperFillMode != null) ''desktop.writeConfig("FillMode", "${cfg.workspace.wallpaperFillMode}");''}
}
'' else "");
wallpaperPOTD = (if (cfg.workspace.wallpaperPictureOfTheDay != null) then ''
Expand All @@ -221,6 +224,7 @@ in
desktop.currentConfigGroup = ["Wallpaper", "org.kde.potd", "General"];
desktop.writeConfig("Provider", "${cfg.workspace.wallpaperPictureOfTheDay.provider}");
desktop.writeConfig("UpdateOverMeteredConnection", "${if (cfg.workspace.wallpaperPictureOfTheDay.updateOverMeteredConnection) then "1" else "0"}");
${lib.optionalString (cfg.workspace.wallpaperFillMode != null) ''desktop.writeConfig("FillMode", "${cfg.workspace.wallpaperFillMode}");''}
}
'' else "");
wallpaperPlainColor = (if (cfg.workspace.wallpaperPlainColor != null) then ''
Expand Down
13 changes: 12 additions & 1 deletion modules/workspace.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

let
cfg = config.programs.plasma;
inherit (import ../lib/wallpapers.nix { inherit lib; }) wallpaperPictureOfTheDayType wallpaperSlideShowType;
inherit (import ../lib/wallpapers.nix { inherit lib; }) wallpaperPictureOfTheDayType wallpaperSlideShowType wallpaperFillModeTypes;
inherit (import ./widgets/lib.nix { inherit lib; }) stringIfNotNull;

cursorType = with lib.types; submodule {
Expand Down Expand Up @@ -164,6 +164,17 @@ in
'';
};

wallpaperFillMode = lib.mkOption {
type = with lib.types; nullOr (enum (builtins.attrNames wallpaperFillModeTypes));
default = null;
example = "stretch";
description = ''
Defines how the wallpaper should be displayed on the screen.
Applies only to wallpaperPictureOfTheDay or wallpaperSlideShow.
'';
apply = value: if value == null then null else (builtins.toString wallpaperFillModeTypes.${value});
};

soundTheme = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
Expand Down

0 comments on commit 0b7f9b5

Please sign in to comment.