feat: use new displays, for automatic automapaper

This commit is contained in:
Noa Aarts 2024-09-04 22:20:44 +02:00
parent 4c4beedc71
commit e3c6cdf606
Signed by: noa
GPG key ID: 1850932741EFF672
5 changed files with 350 additions and 286 deletions

View file

@ -27,7 +27,29 @@
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;
modules = { modules = {
hyprland.enable = true; hyprland = {
enable = true;
displays = [
{
name = "DP-3";
horizontal = 2560;
vertical = 1440;
horizontal-offset = 2560;
vertical-offset = 0;
refresh-rate = 360;
scale = "1";
}
{
name = "DP-2";
horizontal = 2560;
vertical = 1440;
horizontal-offset = 0;
vertical-offset = 0;
refresh-rate = 144;
scale = "1";
}
];
};
games.enable = true; games.enable = true;
apps = { apps = {
enable = true; enable = true;

View file

@ -29,7 +29,17 @@
modules = { modules = {
hyprland = { hyprland = {
enable = true; enable = true;
displays = [ "eDP-1, 2256x1504@60, 0x0, 1" ]; displays = [
{
name = "eDP-1";
horizontal = 2256;
vertical = 1504;
horizontal-offset = 0;
vertical-offset = 0;
refresh-rate = 60;
scale = "1";
}
];
}; };
games.enable = true; games.enable = true;
apps = { apps = {

View file

@ -6,188 +6,184 @@ in
options.modules.automapaper = { options.modules.automapaper = {
enable = lib.mkEnableOption "enable automapaper"; enable = lib.mkEnableOption "enable automapaper";
hyprland = lib.mkEnableOption "enable hyprland exec-once integration"; hyprland = lib.mkEnableOption "enable hyprland exec-once integration";
configurations = lib.mkOption { default-configuration = {
description = "automapaper configurations per monitor"; init = lib.mkOption
type = with lib.types; attrsOf (submodule { {
options = { type = lib.types.str;
init = lib.mkOption { description = "the shader executed to get the state for the initialisation, and re-initialisation steps";
type = str; default = ''
description = "the shader executed to get the state for the initialisation, and re-initialisation steps"; #version 310 es
}; precision highp float;
state = lib.mkOption {
type = str; uniform float time;
description = "the shader executed to increment the state to the next generation"; uniform vec2 resolution;
};
display = lib.mkOption { out vec4 stateColor;
type = str;
description = "the shader executed to display the state to the monitor"; float PHI = 1.61803398874989484820459; // Φ = Golden Ratio
};
horizontal = lib.mkOption { float gold_noise(in vec2 xy, in float seed){
type = int; return fract(tan(distance(xy*PHI, xy)*seed)*xy.x);
description = "the amount of horizontal cells in the state"; }
};
vertical = lib.mkOption { void main( void ) {
type = int;
description = "the amount of vertical cells in the state"; vec2 position = gl_FragCoord.xy;
}; float color = gold_noise(position.xy, fract(time));
tps = lib.mkOption {
type = int;
description = "the target amount of ticks to simulate each second"; stateColor = vec4(step(0.3, color), 0,0,step(0.3, color));
}; }'';
cycles = lib.mkOption {
type = int;
description = "the amount of state increments before the init shader is called again";
};
frames_per_tick = lib.mkOption {
type = int;
description = "the amount of times to call the display shader for each iteration of the state shader";
};
}; };
}); state = lib.mkOption {
type = lib.types.str;
description = "the shader executed to increment the state to the next generation";
default = ''
#version 310 es
precision highp float;
uniform sampler2D state;
uniform vec2 scale;
out vec4 stateColor;
vec4 get(int x, int y) {
return texture(state, (gl_FragCoord.xy + vec2(x, y)) / scale);
}
void main() {
int sum = int(get(-1, -1).r +
get(-1, 0).r +
get(-1, 1).r +
get( 0, -1).r +
get( 0, 1).r +
get( 1, -1).r +
get( 1, 0).r +
get( 1, 1).r);
vec4 current = get(0,0);
if (sum == 3) {
stateColor.r = 1.0;
stateColor.g = 1.0;
} else if (sum == 2) {
stateColor = current;
if (current.r == 0.0) {
stateColor.g = max(current.g - 0.01, 0.0);
}
} else {
stateColor = vec4(0.0, max(current.g - 0.01, 0.0), 0.0, 1.0);
}
}'';
};
display = lib.mkOption {
type = lib.types.str;
description = "the shader executed to display the state to the monitor";
default = ''
#version 310 es
precision
highp
float;
uniform sampler2D tex2D;
uniform sampler2D old2D;
uniform ivec2 resolution;
uniform float frame_part;
in highp vec2 texCoords;
out vec4 stateColor;
const vec4 bgColor = ${nix-colors.lib.conversions.hexToGLSLVec config.colorScheme.palette.base00};
// #26052e
const vec4 fgColor = ${nix-colors.lib.conversions.hexToGLSLVec config.colorScheme.palette.base01};
// #950fad
void main() {
vec2 canvasSize = vec2 (textureSize (tex2D, 0));
vec4 state = texture (tex2D, texCoords);
vec4 ostate = texture (old2D, texCoords);
vec2 localCoords = fract (gl_FragCoord.xy / vec2 (resolution) * canvasSize);
localCoords = localCoords - 0.5;
float dist = sqrt (dot (localCoords, localCoords));
float size = smoothstep (0.0, 1.0, pow(mix(ostate.g,state.g, frame_part), 3.0)) * 0.35;
float mask = 1.0 - step (size, dist);
float brightness = mix (ostate.r, state.r, frame_part) + 0.2 * pow(mix(ostate.g,state.g, frame_part), 3.0);
stateColor = mix (bgColor, fgColor, brightness * mask);
} '';
};
horizontal = lib.mkOption {
type = lib.types.int;
default = 10;
};
vertical = lib.mkOption {
type = lib.types.int;
default = 10;
};
tps = lib.mkOption {
type = lib.types.int;
description = "the target amount of ticks to simulate each second";
default = 30;
};
cycles = lib.mkOption {
type = lib.types.int;
description = "the amount of state increments before the init shader is called again";
default = 2500;
};
frames_per_tick = lib.mkOption {
type = lib.types.int;
description = "the amount of times to call the display shader for each iteration of the state shader";
default = 1;
};
}; };
}; };
config = lib.mkIf cfg.enable ( config = lib.mkIf cfg.enable
let
displays = lib.attrsets.mapAttrs
(displayName: displayConfig:
let
init = builtins.toFile "init.frag" displayConfig.init;
state = builtins.toFile "state.frag" displayConfig.state;
display = builtins.toFile "display.frag" displayConfig.display;
in
''
[display]
name="${displayName}"
horizontal=${builtins.toString displayConfig.horizontal}
vertical=${builtins.toString displayConfig.vertical}
tps=${builtins.toString displayConfig.tps}
state_frag="${state}"
init_frag="${init}"
display_frag="${display}"
cycles=${builtins.toString displayConfig.cycles}
frames_per_tick=${builtins.toString displayConfig.frames_per_tick}
''
)
cfg.configurations;
in
{ {
modules.automapaper.configurations = wayland.windowManager.hyprland.settings.exec-once =
let let
conf = { mkDisplayConfig = conf:
horizontal = 256; let
vertical = 144; init = builtins.toFile "init.frag" conf.init;
tps = 30; state = builtins.toFile "state.frag" conf.state;
init = '' display = builtins.toFile "display.frag" conf.display;
#version 310 es in
precision highp float; ''
[display]
uniform float time; name="${conf.name}"
uniform vec2 resolution; horizontal=${builtins.toString conf.horizontal}
vertical=${builtins.toString conf.vertical}
out vec4 stateColor; tps=${builtins.toString conf.tps}
state_frag="${state}"
float PHI = 1.61803398874989484820459; // Φ = Golden Ratio init_frag="${init}"
display_frag="${display}"
float gold_noise(in vec2 xy, in float seed){ cycles=${builtins.toString conf.cycles}
return fract(tan(distance(xy*PHI, xy)*seed)*xy.x); frames_per_tick=${builtins.toString conf.frames_per_tick}
} '';
confFile =
void main( void ) { let
def = config.modules.automapaper.default-configuration;
vec2 position = gl_FragCoord.xy; in
float color = gold_noise(position.xy, fract(time)); conf: builtins.toFile "${conf.name}.toml" (mkDisplayConfig {
name = conf.name;
horizontal = builtins.div conf.horizontal def.horizontal;
stateColor = vec4(step(0.3, color), 0,0,step(0.3, color)); vertical = builtins.div conf.vertical def.vertical;
}''; tps = def.tps;
state = '' state = def.state;
#version 310 es init = def.init;
precision highp float; display = def.display;
cycles = def.cycles;
uniform sampler2D state; frames_per_tick = def.frames_per_tick;
uniform vec2 scale; });
out vec4 stateColor;
vec4 get(int x, int y) {
return texture(state, (gl_FragCoord.xy + vec2(x, y)) / scale);
}
void main() {
int sum = int(get(-1, -1).r +
get(-1, 0).r +
get(-1, 1).r +
get( 0, -1).r +
get( 0, 1).r +
get( 1, -1).r +
get( 1, 0).r +
get( 1, 1).r);
vec4 current = get(0,0);
if (sum == 3) {
stateColor.r = 1.0;
stateColor.g = 1.0;
} else if (sum == 2) {
stateColor = current;
if (current.r == 0.0) {
stateColor.g = max(current.g - 0.01, 0.0);
}
} else {
stateColor = vec4(0.0, max(current.g - 0.01, 0.0), 0.0, 1.0);
}
}'';
display = ''
#version 310 es
precision highp float;
uniform sampler2D tex2D;
uniform sampler2D old2D;
uniform ivec2 resolution;
uniform float frame_part;
in highp vec2 texCoords;
out vec4 stateColor;
const vec4 bgColor = ${nix-colors.lib.conversions.hexToGLSLVec config.colorScheme.palette.base00}; // #26052e
const vec4 fgColor = ${nix-colors.lib.conversions.hexToGLSLVec config.colorScheme.palette.base01}; // #950fad
void main() {
vec2 canvasSize = vec2(textureSize(tex2D, 0));
vec4 state = texture(tex2D, texCoords);
vec4 ostate = texture(old2D, texCoords);
vec2 localCoords = fract(gl_FragCoord.xy / vec2(resolution) * canvasSize);
localCoords = localCoords - 0.5;
float dist = sqrt(dot(localCoords, localCoords));
float size = smoothstep(0.0, 1.0, pow(mix(ostate.g,state.g, frame_part), 3.0)) * 0.35;
float mask = 1.0 - step(size, dist);
float brightness = mix(ostate.r,state.r, frame_part) + 0.2 * pow(mix(ostate.g,state.g, frame_part), 3.0);
stateColor = mix(bgColor, fgColor, brightness * mask);
}'';
cycles = 2500;
frames_per_tick = 1;
};
displays_raw = config.modules.hyprland.displays;
displays = builtins.map (display_raw: builtins.head (lib.strings.splitString "," display_raw)) displays_raw;
in in
lib.mkIf cfg.hyprland (
builtins.listToAttrs builtins.map
(builtins.map (
(disp: { conf:
name = disp; "${inputs.automapaper.packages.${pkgs.system}.default}/bin/automapaper -c ${confFile conf}"
value = conf; )
}) config.modules.hyprland.displays
displays); );
wayland.windowManager.hyprland.settings.exec-once = lib.mkIf cfg.hyprland ( };
lib.mapAttrsToList
(name: config:
"${inputs.automapaper.packages.${pkgs.system}.default}/bin/automapaper -C ${builtins.toFile "${name}.toml" config}")
displays
);
}
);
} }

View file

@ -23,12 +23,48 @@ in
default = pkgs.xdg-desktop-portal-hyprland; default = pkgs.xdg-desktop-portal-hyprland;
}; };
displays = lib.mkOption { displays = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf
default = [ (lib.types.submodule {
"DP-3,2560x1440@360,2560x0,1" options = {
"DP-2,2560x1440@144,0x0,1" name = lib.mkOption
"Unknown-1,disable" # NOTE: still borked on 04-06-2024 {
]; type = lib.types.str;
description = "the display identifier";
example = "DP-2";
};
horizontal = lib.mkOption {
type = lib.types.ints.positive;
description = "the horizontal resolution";
example = 1920;
};
vertical = lib.mkOption {
type = lib.types.ints.positive;
description = "the vertical resolution";
example = 1080;
};
horizontal-offset = lib.mkOption {
type = lib.types.ints.unsigned;
description = "the horizontal resolution";
example = 1920;
};
vertical-offset = lib.mkOption {
type = lib.types.ints.unsigned;
description = "the vertical resolution";
example = 0;
};
refresh-rate = lib.mkOption {
type = lib.types.ints.unsigned;
description = "the refresh rate of the monitor";
example = 60;
};
scale = lib.mkOption {
type = lib.types.str;
description = "the scale of the monitor";
default = "1";
example = "1.5";
};
};
});
description = "the display layout to use"; description = "the display layout to use";
}; };
}; };
@ -89,105 +125,109 @@ in
wayland.windowManager.hyprland = { wayland.windowManager.hyprland = {
enable = true; enable = true;
package = cfg.package; package = cfg.package;
settings = { settings =
monitor = cfg.displays; let
windowrulev2 = [ make-display-string = display: "${display.name}, ${builtins.toString display.horizontal}x${builtins.toString display.vertical}@${builtins.toString display.refresh-rate}, ${builtins.toString display.horizontal-offset}x${builtins.toString display.vertical-offset}, ${display.scale}";
"opacity 1.0 0.6,class:^(kitty)$" in
"stayfocused,class:^(wofi)$" {
]; monitor = builtins.map make-display-string cfg.displays;
env = [ windowrulev2 = [
"WLR_NO_HARDWARE_CURSORS,1" "opacity 1.0 0.6,class:^(kitty)$"
]; "stayfocused,class:^(wofi)$"
exec-once = [ ];
"${pkgs.waybar}/bin/waybar" env = [
"${pkgs.dunst}/bin/dunst" "WLR_NO_HARDWARE_CURSORS,1"
"${cfg.package}/bin/hyprctl dispatcher focusmonitor 1" ];
"${pkgs.keepassxc}/bin/keepassxc" exec-once = [
"${pkgs.spotify}/bin/spotify" "${pkgs.waybar}/bin/waybar"
]; "${pkgs.dunst}/bin/dunst"
general = { "${cfg.package}/bin/hyprctl dispatcher focusmonitor 1"
sensitivity = "1.2"; "${pkgs.keepassxc}/bin/keepassxc"
gaps_in = "2"; "${pkgs.spotify}/bin/spotify"
gaps_out = "3"; ];
border_size = "3"; general = {
"col.active_border" = "0xff${config.colorScheme.palette.base01}"; sensitivity = "1.2";
"col.inactive_border" = "0xff${config.colorScheme.palette.base00}"; gaps_in = "2";
}; gaps_out = "3";
input = { border_size = "3";
touchpad = { "col.active_border" = "0xff${config.colorScheme.palette.base01}";
clickfinger_behavior = 1; "col.inactive_border" = "0xff${config.colorScheme.palette.base00}";
disable_while_typing = 1;
natural_scroll = 1;
tap-to-click = 1;
scroll_factor = 0.3;
}; };
}; input = {
misc = { touchpad = {
key_press_enables_dpms = true; clickfinger_behavior = 1;
}; disable_while_typing = 1;
decoration = { natural_scroll = 1;
rounding = "6"; tap-to-click = 1;
active_opacity = "1"; scroll_factor = 0.3;
inactive_opacity = "1"; };
}; };
animations = { misc = {
enabled = "1"; key_press_enables_dpms = true;
animation = [ };
"windows,1,2,default" decoration = {
"border,1,10,default" rounding = "6";
"fade,0,5,default" active_opacity = "1";
"workspaces,1,4,default" inactive_opacity = "1";
};
animations = {
enabled = "1";
animation = [
"windows,1,2,default"
"border,1,10,default"
"fade,0,5,default"
"workspaces,1,4,default"
];
};
"$mod" = "SUPER";
bind = [
"$mod,Return,exec,${cfg.terminal}/bin/${cfg.terminal.pname}"
"$mod,tab,cyclenext"
"SUPERSHIFT,Q,killactive"
"$mod,SPACE,exec,wofi-launch"
"$mod,P,exec,wofi-power"
"SUPERSHIFT,m,exit"
"$mod,H,movefocus,l"
"$mod,J,movefocus,u"
"$mod,K,movefocus,d"
"$mod,L,movefocus,r"
"SUPERSHIFT,H,movewindow,l"
"SUPERSHIFT,J,movewindow,u"
"SUPERSHIFT,K,movewindow,d"
"SUPERSHIFT,L,movewindow,r"
"$mod,F,togglefloating"
"$mod,X,togglespecialworkspace"
"SUPERSHIFT,X,movetoworkspace,special"
"SUPERSHIFT,S,exec,${pkgs.hyprshot}/bin/hyprshot -m region --clipboard-only"
"$mod,f11,fullscreen,0"
",XF86AudioLowerVolume,exec,${pkgs.wireplumber}/bin/wpctl set-volume @DEFAULT_SINK@ 1%-"
",XF86AudioRaiseVolume,exec,${pkgs.wireplumber}/bin/wpctl set-volume @DEFAULT_SINK@ 1%+"
",XF86AudioMute,exec,${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_SINK@ toggle"
",XF86AudioPlay,exec,${pkgs.playerctl}/bin/playerctl play-pause"
",XF86AudioPrev,exec,${pkgs.playerctl}/bin/playerctl previous"
",XF86AudioNext,exec,${pkgs.playerctl}/bin/playerctl next"
"$mod,mouse_up,workspace,r-1"
"$mod,mouse_down,workspace,r+1"
]
++ (
builtins.concatLists (builtins.genList
(
x:
let
ws = builtins.toString (x);
in
[
"$mod,${ws},workspace,${ws}"
"ALT,${ws},movetoworkspace,${ws}"
]
)
10)
);
bindm = [
"$mod,mouse:272,movewindow"
"$mod,mouse:273,resizewindow"
]; ];
}; };
"$mod" = "SUPER";
bind = [
"$mod,Return,exec,${cfg.terminal}/bin/${cfg.terminal.pname}"
"$mod,tab,cyclenext"
"SUPERSHIFT,Q,killactive"
"$mod,SPACE,exec,wofi-launch"
"$mod,P,exec,wofi-power"
"SUPERSHIFT,m,exit"
"$mod,H,movefocus,l"
"$mod,J,movefocus,u"
"$mod,K,movefocus,d"
"$mod,L,movefocus,r"
"SUPERSHIFT,H,movewindow,l"
"SUPERSHIFT,J,movewindow,u"
"SUPERSHIFT,K,movewindow,d"
"SUPERSHIFT,L,movewindow,r"
"$mod,F,togglefloating"
"$mod,X,togglespecialworkspace"
"SUPERSHIFT,X,movetoworkspace,special"
"SUPERSHIFT,S,exec,${pkgs.hyprshot}/bin/hyprshot -m region --clipboard-only"
"$mod,f11,fullscreen,0"
",XF86AudioLowerVolume,exec,${pkgs.wireplumber}/bin/wpctl set-volume @DEFAULT_SINK@ 1%-"
",XF86AudioRaiseVolume,exec,${pkgs.wireplumber}/bin/wpctl set-volume @DEFAULT_SINK@ 1%+"
",XF86AudioMute,exec,${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_SINK@ toggle"
",XF86AudioPlay,exec,${pkgs.playerctl}/bin/playerctl play-pause"
",XF86AudioPrev,exec,${pkgs.playerctl}/bin/playerctl previous"
",XF86AudioNext,exec,${pkgs.playerctl}/bin/playerctl next"
"$mod,mouse_up,workspace,r-1"
"$mod,mouse_down,workspace,r+1"
]
++ (
builtins.concatLists (builtins.genList
(
x:
let
ws = builtins.toString (x);
in
[
"$mod,${ws},workspace,${ws}"
"ALT,${ws},movetoworkspace,${ws}"
]
)
10)
);
bindm = [
"$mod,mouse:272,movewindow"
"$mod,mouse:273,resizewindow"
];
};
}; };
}; };
} }

View file

@ -42,10 +42,6 @@ in
]; ];
config = config =
let
displays_raw = config.modules.hyprland.displays;
displays = builtins.map (display_raw: builtins.head (lib.strings.splitString "," display_raw)) displays_raw;
in
lib.mkIf cfg.enable lib.mkIf cfg.enable
{ {
modules.waybar.enabled = ( modules.waybar.enabled = (
@ -75,7 +71,7 @@ in
margin-top = 8; margin-top = 8;
margin-left = 10; margin-left = 10;
margin-right = 10; margin-right = 10;
output = displays; output = builtins.map (display: display.name) config.modules.hyprland.displays;
modules-left = cfg.modules.left; modules-left = cfg.modules.left;
modules-center = cfg.modules.center; modules-center = cfg.modules.center;
modules-right = cfg.modules.right; modules-right = cfg.modules.right;