diff --git a/docs/src/lib/wallpaper-constructors.md b/docs/src/lib/wallpaper-constructors.md new file mode 100644 index 000000000..ff0938060 --- /dev/null +++ b/docs/src/lib/wallpaper-constructors.md @@ -0,0 +1,37 @@ +## mkStaticImage +takes an image, as well as optionally polarity, and an override, which can either be a path to a base16 yaml file or and attrset. +example +```nix +stylix.wallpaper = config.lib.stylix.mkStaticImage { + image = /path/to/image; + polarity = "dark"; + override = /path/to/scheme.yml; +} +``` +## mkStaticFill +takes a colorscheme as an input. +```nix +stylix.wallpaper = config.lib.stylix.mkStaticFill /path/to/scheme.yml; +``` +## mkSlideshow +takes an image directory, polarity, override, and a delay rate in seconds as an input. +```nix +stylix.wallpaper = config.lib.stylix.mkSlideshow { + imageDir = /path/to/dir; + delay = 300; +}; +``` +## mkAnimation +takes an animation (gif or similar format), as well as polarity and an override as an input. +```nix +stylix.wallpaper = config.lib.stylix.mkAnimation { + animation = /path/to/animation.gif; +}; +``` +## mkVideo +takes an video (mp4 or similar format), as well as polarity and an override as an input. +```nix +stylix.wallpaper = config.lib.stylix.mkAnimation { + video = /path/to/video.mp4; +}; +``` diff --git a/lib/constructors.nix b/lib/constructors.nix index 422e97af8..6b2f192ae 100644 --- a/lib/constructors.nix +++ b/lib/constructors.nix @@ -16,24 +16,6 @@ let in json; generateScheme = polarity: image: importJSON (paletteJSON polarity image); - defaultScheme = { - base00 = "ffffff"; - base01 = "ffffff"; - base02 = "ffffff"; - base03 = "ffffff"; - base04 = "ffffff"; - base05 = "ffffff"; - base06 = "ffffff"; - base07 = "ffffff"; - base08 = "ffffff"; - base09 = "ffffff"; - base0A = "ffffff"; - base0B = "ffffff"; - base0C = "ffffff"; - base0D = "ffffff"; - base0E = "ffffff"; - base0F = "ffffff"; - }; in { # constructors for the wallpaper types @@ -49,21 +31,21 @@ in }; }; - config.lib.stylix.mkStaticFill = colorScheme: let - scheme = if (builtins.isAttrs colorScheme) then (colorScheme) else builtins.fromJSON colorScheme; - schemeJson = if (builtins.isAttrs colorScheme) then (builtins.toJSON colorScheme) else colorScheme; - in { - type = "static"; - image = config.lib.stylix.pixel scheme.base00; - generatedColorScheme = { - json = schemeJson; - palette = scheme; - }; - }; + #config.lib.stylix.mkStaticFill = colorScheme: let + # scheme = if (builtins.isAttrs colorScheme) then (colorScheme) else builtins.fromJSON colorScheme; + # schemeJson = if (builtins.isAttrs colorScheme) then (builtins.toJSON colorScheme) else colorScheme; + #in { + # type = "static"; + # image = config.lib.stylix.pixel scheme.base00; + # generatedColorScheme = { + # json = schemeJson; + # palette = scheme; + # }; + #}; config.lib.stylix.mkAnimation = { animation, polarity ? "dark", override ? null}: let - image = pkgs.runCommand "image" { } '' + image = pkgs.runCommand "image.png" { } '' ${pkgs.ffmpeg}/bin/ffmpeg -i ${animation} -vf "select=eq(n\,0)" -q:v 3 -f image2 $out ''; in diff --git a/lib/types.nix b/lib/types.nix index 7a0ddcbe5..53a36c739 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -6,25 +6,25 @@ with lib; config.lib.stylix = { static = mkOptionType { name = "static"; - description = "Static Image Type"; - descriptionClass = "image"; + description = "static"; + descriptionClass = "static image"; }; animation = mkOptionType { name = "animation"; - description = "Animation Type"; + description = "animation"; descriptionClass = "non video animation"; }; video = mkOptionType { name = "video"; - description = "Video Type supporting all of the formats that the animation type does not"; + description = "video"; descriptionClass = "video"; }; slideshow = mkOptionType { name = "slideshow"; - description = "slideshow Type"; + description = "slideshow"; descriptionClass = "collection of images"; }; }; diff --git a/lib/utils.nix b/lib/utils.nix index 953c6aca1..a83ce8b14 100644 --- a/lib/utils.nix +++ b/lib/utils.nix @@ -29,5 +29,9 @@ in if (red + green + blue >= 150) then "light" else "dark"; # Generate a PNG image containing a named color - config.lib.stylix.pixel = color: pkgs.runCommand "${color}-pixel.png" {} "${pkgs.imagemagick}/bin/convert xc:#${color} png32:$out"; + #config.lib.stylix.pixel = color: pkgs.runCommand "${color}-pixel.png" {} "${pkgs.imagemagick}/bin/convert xc:#${color} png32:$out"; + config.lib.stylix.pixel = color: + pkgs.runCommand "${color}-pixel.png" { + color = config.lib.stylix.colors.withHashtag.${color}; + } "${pkgs.imagemagick}/bin/convert xc:$color png32:$out"; } diff --git a/modules/feh/hm.nix b/modules/feh/hm.nix deleted file mode 100644 index ec32035a9..000000000 --- a/modules/feh/hm.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ pkgs, config, lib, ... }: - -{ - options.stylix.targets.feh.enable = - config.lib.stylix.mkEnableTarget - "the desktop background using Feh" - (with config.xsession.windowManager; bspwm.enable - || herbstluftwm.enable - || i3.enable - || spectrwm.enable - || xmonad.enable); - - config.xsession.initExtra = - lib.mkIf config.stylix.targets.feh.enable - "${pkgs.feh}/bin/feh --no-fehbg --bg-scale ${config.stylix.wallpaper.image}"; -} diff --git a/modules/feh/nixos.nix b/modules/feh/nixos.nix deleted file mode 100644 index 8074896fe..000000000 --- a/modules/feh/nixos.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ pkgs, config, lib, ... }: - -{ - options.stylix.targets.feh.enable = - config.lib.stylix.mkEnableTarget - "the desktop background using Feh" - (with config.services.xserver.windowManager; xmonad.enable || i3.enable); - - config.services.xserver.displayManager.sessionCommands = - lib.mkIf config.stylix.targets.feh.enable - "${pkgs.feh}/bin/feh --no-fehbg --bg-scale ${config.stylix.wallpaper.image}"; -} diff --git a/modules/sway/hm.nix b/modules/sway/hm.nix index 9e5120b06..d89a0c017 100644 --- a/modules/sway/hm.nix +++ b/modules/sway/hm.nix @@ -21,7 +21,6 @@ in { (lib.mkIf config.stylix.targets.sway.enable { wayland.windowManager.sway.config = { inherit fonts; - startup = let slideshowScript = pkgs.writeScript "script.sh" '' diff --git a/modules/xorg/hm.nix b/modules/xorg/hm.nix new file mode 100644 index 000000000..45374a13e --- /dev/null +++ b/modules/xorg/hm.nix @@ -0,0 +1,18 @@ +{ pkgs, config, lib, ... }: + +{ + options.stylix.targets.xorg.enable = + config.lib.stylix.mkEnableTarget + "the desktop background using Feh" + (with config.xsession.windowManager; bspwm.enable + || herbstluftwm.enable + || i3.enable + || spectrwm.enable + || xmonad.enable); + + config.xsession.initExtra = lib.mkIf config.stylix.targets.xorg.enable + (if (config.lib.stylix.isAnimation config.stylix.wallpaper) then '' + ${pkgs.xwinwrap}/bin/xwinwrap -fs -ni -b -nf -ov -- mpv -wid WID --loop --no-audio ${config.stylix.wallpaper.animation} + '' else (if (config.lib.stylix.isVideo config.stylix.wallpaper) then '' + '' else "${pkgs.feh}/bin/feh --no-fehbg --bg-scale ${config.stylix.wallpaper.image}")); +} diff --git a/modules/xorg/nixos.nix b/modules/xorg/nixos.nix new file mode 100644 index 000000000..b5896f8ae --- /dev/null +++ b/modules/xorg/nixos.nix @@ -0,0 +1,14 @@ +{ pkgs, config, lib, ... }: + +{ + options.stylix.targets.xorg.enable = + config.lib.stylix.mkEnableTarget + "the desktop background of an xorg session" + (with config.services.xserver.windowManager; xmonad.enable || i3.enable); + + config.services.xserver.displayManager.sessionCommands = lib.mkIf config.stylix.targets.xorg.enable + (if (config.lib.stylix.isAnimation config.stylix.wallpaper) then '' + ${pkgs.xwinwrap}/bin/xwinwrap -fs -ni -b -nf -ov -- mpv -wid WID --loop --no-audio ${config.stylix.wallpaper.animation} + '' else (if (config.lib.stylix.isVideo config.stylix.wallpaper) then '' + '' else "${pkgs.feh}/bin/feh --no-fehbg --bg-scale ${config.stylix.wallpaper.image}")); +} diff --git a/stylix/palette.nix b/stylix/palette.nix index 568f92900..2f5b9e812 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -5,6 +5,7 @@ with lib; let cfg = config.stylix; + fromOs = import ./fromos.nix { inherit lib args; }; in { # TODO link to doc on how to do instead imports = [ @@ -39,15 +40,7 @@ in { image = config.stylix.image; polarity = config.stylix.polarity; }; - onlyScheme = lib.warn message config.lib.stylix.mkStaticFill config.stylix.base16Scheme; - bothSchemeAndWallpaper = lib.warn message config.lib.stylix.mkStaticImage { - image = config.stylix.image; - override = config.stylix.base16Scheme; - polarity = config.stylix.polarity; - }; - in if (config.stylix.image != null && config.stylix.base16Scheme != null) then bothSchemeAndWallpaper else - (if (config.stylix.image == null && config.stylix.base16Scheme != null) then onlyScheme else - (if (config.stylix.image != null && config.stylix.base16Scheme == null) then onlyWallpaper else (throw "you have not set a wallpaper or a scheme"))); + in fromOs [ "wallpaper" ] (if (config.stylix.image != null ) then onlyWallpaper else (throw "wallpaper was not set")); description = mdDoc '' Wallpaper image. @@ -58,7 +51,7 @@ in { image = mkOption { type = with types; nullOr (coercedTo package toString path); - default = null; + default = fromOs [ "image" ] null; description = mdDoc '' Outdated method to set the wallpaper image ''; @@ -79,7 +72,7 @@ in { This can be a path to a file, a string of YAML, or an attribute set. ''; type = with types; nullOr (oneOf [ path lines attrs]); - default = null; + default = fromOs [ "base16Scheme" ] null; defaultText = literalMD '' The colors used in the theming.