Skip to content

Commit

Permalink
add xorg support
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeGuyNamedMay committed Jun 8, 2023
1 parent 8e24e1e commit 329f219
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 76 deletions.
37 changes: 37 additions & 0 deletions docs/src/lib/wallpaper-constructors.md
Original file line number Diff line number Diff line change
@@ -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;
};
```
42 changes: 12 additions & 30 deletions lib/constructors.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
};
Expand Down
6 changes: 5 additions & 1 deletion lib/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
16 changes: 0 additions & 16 deletions modules/feh/hm.nix

This file was deleted.

12 changes: 0 additions & 12 deletions modules/feh/nixos.nix

This file was deleted.

1 change: 0 additions & 1 deletion modules/sway/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ''
Expand Down
18 changes: 18 additions & 0 deletions modules/xorg/hm.nix
Original file line number Diff line number Diff line change
@@ -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}"));
}
14 changes: 14 additions & 0 deletions modules/xorg/nixos.nix
Original file line number Diff line number Diff line change
@@ -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}"));
}
15 changes: 4 additions & 11 deletions stylix/palette.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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.
Expand All @@ -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
'';
Expand All @@ -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.
Expand Down

0 comments on commit 329f219

Please sign in to comment.