From 9936f538e10f86b0770b5c9e80aa55b181d1bbdb Mon Sep 17 00:00:00 2001 From: soraefir Date: Wed, 17 Jun 2026 19:18:50 +0200 Subject: [PATCH] more and fixes --- .../apps/eww/bar/scripts/airplane-mode | 19 +++ .../apps/eww/bar/scripts/do-not-disturb | 15 ++ .../wayland/apps/eww/bar/scripts/read-mode | 23 +++ .../apps/eww/bar/shaders/read-mode.glsl | 133 ++++++++++++++++++ .../wayland/apps/eww/bar/windows/clock.yuck | 23 +-- modules/home/wayland/apps/eww/default.nix | 3 + modules/home/wayland/apps/kanshi/default.nix | 54 ++++--- modules/home/wayland/hyprland/config.nix | 1 + 8 files changed, 242 insertions(+), 29 deletions(-) create mode 100644 modules/home/wayland/apps/eww/bar/scripts/airplane-mode create mode 100644 modules/home/wayland/apps/eww/bar/scripts/do-not-disturb create mode 100644 modules/home/wayland/apps/eww/bar/scripts/read-mode create mode 100644 modules/home/wayland/apps/eww/bar/shaders/read-mode.glsl diff --git a/modules/home/wayland/apps/eww/bar/scripts/airplane-mode b/modules/home/wayland/apps/eww/bar/scripts/airplane-mode new file mode 100644 index 0000000..6241b71 --- /dev/null +++ b/modules/home/wayland/apps/eww/bar/scripts/airplane-mode @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +is_active() { + rfkill list wifi 2>/dev/null | grep -q "Soft blocked: yes" +} + +case "$1" in + status) + is_active && echo true || echo false + ;; + *) + if is_active; then + rfkill unblock all + echo false + else + rfkill block all + echo true + fi + ;; +esac diff --git a/modules/home/wayland/apps/eww/bar/scripts/do-not-disturb b/modules/home/wayland/apps/eww/bar/scripts/do-not-disturb new file mode 100644 index 0000000..2acf892 --- /dev/null +++ b/modules/home/wayland/apps/eww/bar/scripts/do-not-disturb @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +case "$1" in + status) + dunstctl is-paused + ;; + *) + if dunstctl is-paused | grep -q true; then + dunstctl set-paused false + echo false + else + dunstctl set-paused true + echo true + fi + ;; +esac diff --git a/modules/home/wayland/apps/eww/bar/scripts/read-mode b/modules/home/wayland/apps/eww/bar/scripts/read-mode new file mode 100644 index 0000000..85a0c7e --- /dev/null +++ b/modules/home/wayland/apps/eww/bar/scripts/read-mode @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +SHADER="$HOME/.config/eww/shaders/read-mode.glsl" + +is_active() { + hyprctl getoption decoration:screen_shader | grep -qF "$SHADER" +} + +case "$1" in + status) + is_active && echo true || echo false + ;; + *) + if is_active; then + hyprctl eval 'hl.config({ decoration = { screen_shader = "" } })' + hyprctl eval 'hl.config({ render = { use_fp16 = 2 } })' + echo false + else + hyprctl eval 'hl.config({ render = { use_fp16 = 0 } })' + hyprctl eval "hl.config({ decoration = { screen_shader = \"$SHADER\" } })" + echo true + fi + ;; +esac diff --git a/modules/home/wayland/apps/eww/bar/shaders/read-mode.glsl b/modules/home/wayland/apps/eww/bar/shaders/read-mode.glsl new file mode 100644 index 0000000..25479a9 --- /dev/null +++ b/modules/home/wayland/apps/eww/bar/shaders/read-mode.glsl @@ -0,0 +1,133 @@ +#version 320 es + +/* + I love e-ink displays! + The mathematical philosophy here is using deterministic logic (Bayer matrices, arithmetic hashing) + to simulate physical chaos (paper grain, ink bleed). I picked up these concepts in a course + and this is easily the best real-world application of them I've found. + It works brilliantly-looks like real paper, killed my eye strain, and even reduced the insane + reflections from my glossy surface display. + + by @snes19xx, https://github.com/snes19xx +*/ + + +precision highp float; +in vec2 v_texcoord; +uniform sampler2D tex; +out vec4 fragColor; + +// 4x4 Bayer Matrix +// this grid helps break up smooth gradients into texture so it looks less "digital" +float getBayer(vec2 pos) { + int x = int(mod(pos.x, 4.0)); + int y = int(mod(pos.y, 4.0)); + const mat4 bayer = mat4( + 0.0, 12.0, 3.0, 15.0, + 8.0, 4.0, 11.0, 7.0, + 2.0, 14.0, 1.0, 13.0, + 10.0, 6.0, 9.0, 5.0 + ); + return bayer[x][y] / 16.0; +} + +// High-performance "Hash12" - No trigonometry +// old hash used sin() which is slow on gpu. this one just mashes bits together. +// (https://www.shadertoy.com/view/4djSRW) +float hash(vec2 p) { + // fract() keeps only the decimal part for the wave-like dusty pattern + // .1031 is a special prime number to avoid perfect alignments with pixel grid + vec3 p3 = fract(vec3(p.xyx) * .1031); + + // dot product mixes the x, y, z values so they depend on each other + p3 += dot(p3, p3.yzx + 33.33); + + // return the final entangled decimal. deterministically random (afaik). + return fract((p3.x + p3.y) * p3.z); +} + +// Multi-octave noise for realistic paper fiber texture +float paperTexture(vec2 uv) { + float n = 0.0; + n += hash(uv * 0.3) * 0.6; // Very large fibers + n += hash(uv * 0.8) * 0.4; // Large fibers + n += hash(uv * 2.5) * 0.3; // Medium detail + n += hash(uv * 6.0) * 0.2; // Fine grain + n += hash(uv * 15.0) * 0.1; // Very fine grain + return n / 1.6; // Normalize +} + +// Directional paper grain (simulates paper fibers running in one direction) +float directionalGrain(vec2 uv) { + vec2 direction = vec2(0.7, 0.3); // Fiber direction + float grain = 0.0; + grain += hash(uv * 3.0 + direction * 2.0) * 0.5; + grain += hash(uv * 8.0 + direction * 5.0) * 0.3; + return grain / 0.8; +} + +// Subtle vignette for paper edge darkening +float vignette(vec2 uv) { + vec2 center = uv - 0.5; + float dist = length(center); + // smoothstep creates a signmoid (S-curve) so the shadow falls off naturally + return 1.0 - smoothstep(0.4, 1.2, dist) * 0.15; +} + +void main() { + vec4 pixColor = texture(tex, v_texcoord); + + // Luma Conversion + // not using average (r+g+b)/3 because eyes see green brighter than blue. + float gray = dot(pixColor.rgb, vec3(0.299, 0.587, 0.114)); + + // E-ink characteristic response curve + // real e-ink isn't linear. this exponent simulates ink clumping. + gray = pow(gray, 1.2); + + // Better contrast with slight S-curve + // clips pure blacks/whites but keeps the middle smooth. + gray = smoothstep(0.08, 0.92, gray); + + // Mid-tone boost + float midBoost = smoothstep(0.3, 0.5, gray) * (1.0 - smoothstep(0.5, 0.7, gray)); + gray += midBoost * 0.1; + + vec2 screenPos = gl_FragCoord.xy; + + // PAPER GRAIN + float paperGrain = (paperTexture(screenPos * 0.3) - 0.5) * 0.035; + float dirGrain = (directionalGrain(screenPos * 0.4) - 0.5) * 0.025; // directional grain + + float bayerValue = getBayer(screenPos); + + // Apply to bright areas (paper), but also slightly to mid-tones for more visible grain + float textureMask = smoothstep(0.5, 0.95, gray); // Lower threshold for more coverage + + // Apply both grain types + gray += paperGrain * textureMask; + gray += dirGrain * textureMask * 0.7; // Directional grain is slightly weaker + + // Increased dithering for more texture + float ditherStrength = 0.025; // Increased from 0.018 + gray += (bayerValue - 0.5) * ditherStrength * textureMask; + + // Vignette for paper edges + float vig = vignette(v_texcoord); + gray *= vig; + + gray = clamp(gray, 0.0, 1.0); + + // E-ink colors with slight warmth variation + vec3 paperColor = vec3(0.94, 0.92, 0.86); + vec3 inkColor = vec3(0.10, 0.10, 0.12); + + // More noticeable color variation for paper texture + float colorVariation = hash(screenPos * 0.08) * 0.02; // Increased from 0.01 + paperColor += vec3(colorVariation, colorVariation * 0.5, -colorVariation * 0.2); + + // linear interpolation. paints the gray value onto our specific color palette. + vec3 finalColor = mix(inkColor, paperColor, gray); + + fragColor = vec4(finalColor, pixColor.a); +} \ No newline at end of file diff --git a/modules/home/wayland/apps/eww/bar/windows/clock.yuck b/modules/home/wayland/apps/eww/bar/windows/clock.yuck index d621741..97fe9c1 100644 --- a/modules/home/wayland/apps/eww/bar/windows/clock.yuck +++ b/modules/home/wayland/apps/eww/bar/windows/clock.yuck @@ -69,8 +69,11 @@ ; --- Quick Actions --- -(defpoll power-save :interval "5s" :initial "false" "scripts/power-save status") -(defpoll night-light :interval "5s" :initial "false" "scripts/nightlight status") +(defpoll power-save :interval "5s" :initial "false" "scripts/power-save status") +(defpoll night-light :interval "5s" :initial "false" "scripts/nightlight status") +(defpoll read-mode :interval "5s" :initial "false" "scripts/read-mode status") +(defpoll airplane-mode :interval "5s" :initial "false" "scripts/airplane-mode status") +(defpoll do-not-disturb :interval "5s" :initial "false" "scripts/do-not-disturb status") (defwidget quick-btn [icon label onclick active] (button :class "quick-btn ${active ? 'quick-btn-active' : ''}" @@ -84,13 +87,17 @@ (section-header :title "Quick Actions" :accent "quick-accent") (box :orientation "v" :space-evenly false :class "quick-grid" :spacing 4 (box :orientation "h" :space-evenly true - (quick-btn :icon "󰸉" :label "Wallpaper" :onclick "scripts/wallpaper" :active false) - (quick-btn :icon "󱐋" :label "Power Save" :onclick "scripts/power-save" :active {power-save}) - (quick-btn :icon "󰌵" :label "Night Light" :onclick "scripts/nightlight" :active {night-light})) + (quick-btn :icon "󰌵" :label "Night Light" :onclick "scripts/nightlight" :active {night-light}) + (quick-btn :icon "󰂺" :label "Read Mode" :onclick "scripts/read-mode" :active {read-mode}) + (quick-btn :icon "󰸉" :label "Wallpaper" :onclick "scripts/wallpaper" :active false)) (box :orientation "h" :space-evenly true - (quick-btn :icon "󰹑" :label "Screenshot" :onclick "scripts/screenshot" :active false) - (quick-btn :icon "󰌾" :label "Lock" :onclick "scripts/lock" :active false) - (quick-btn :icon "󱉨" :label "Color Pick" :onclick "scripts/color-pick" :active false))))) + (quick-btn :icon "󱐋" :label "Power Save" :onclick "scripts/power-save" :active {power-save}) + (quick-btn :icon "󰀞" :label "Airplane" :onclick "scripts/airplane-mode" :active {airplane-mode}) + (quick-btn :icon "󰂛" :label "Do Not Dist" :onclick "scripts/do-not-disturb" :active {do-not-disturb})) + (box :orientation "h" :space-evenly true + (quick-btn :icon "󰹑" :label "Screenshot" :onclick "scripts/screenshot" :active false) + (quick-btn :icon "󰌾" :label "Lock" :onclick "scripts/lock" :active false) + (quick-btn :icon "󱉨" :label "Color Pick" :onclick "scripts/color-pick" :active false))))) ; --- Brightness --- diff --git a/modules/home/wayland/apps/eww/default.nix b/modules/home/wayland/apps/eww/default.nix index 4c83d10..f197e17 100755 --- a/modules/home/wayland/apps/eww/default.nix +++ b/modules/home/wayland/apps/eww/default.nix @@ -23,6 +23,9 @@ let scripts = { "scripts/brightness" = mkScript "brightness" ./bar/scripts/brightness [ pkgs.brightnessctl ]; "scripts/nightlight" = mkScript "nightlight" ./bar/scripts/nightlight [ pkgs.wlsunset ]; + "scripts/read-mode" = mkScript "read-mode" ./bar/scripts/read-mode [ pkgs.hyprland ]; + "scripts/airplane-mode" = mkScript "airplane-mode" ./bar/scripts/airplane-mode [ pkgs.util-linux ]; + "scripts/do-not-disturb" = mkScript "do-not-disturb" ./bar/scripts/do-not-disturb [ pkgs.dunst ]; "scripts/panel-toggle" = mkScript "panel-toggle" ./bar/scripts/panel-toggle [ pkgs.eww pkgs.util-linux openOnCurrentScreen ]; "scripts/powermenu-toggle" = mkScript "powermenu-toggle" ./bar/scripts/powermenu-toggle [ pkgs.eww openOnCurrentScreen ]; "scripts/power-save" = mkScript "power-save" ./bar/scripts/power-save [ pkgs.eww ]; diff --git a/modules/home/wayland/apps/kanshi/default.nix b/modules/home/wayland/apps/kanshi/default.nix index 24b8020..c16d9e0 100644 --- a/modules/home/wayland/apps/kanshi/default.nix +++ b/modules/home/wayland/apps/kanshi/default.nix @@ -1,5 +1,13 @@ -{ config, lib, pkgs, ... }: -let +{ config, lib, pkgs, ... }: +let + # Close the bar if it's already open (wrong screen), then open on the target screen. + moveOrOpenBar = screen: "${pkgs.writeShellScript "kanshi-eww-bar-${toString screen}" '' + if ${pkgs.eww}/bin/eww active-windows 2>/dev/null | grep -qx "bar"; then + ${pkgs.eww}/bin/eww close bar + fi + ${pkgs.eww}/bin/eww open bar --screen ${toString screen} + ''}"; + baseOutput = { position = "0,0"; scale = 1.0; @@ -7,6 +15,9 @@ let status = "enable"; transform = "normal"; }; + aocT = "AOC 24E1W1 GNSKCHA086899"; + aocB = "AOC 24E1W1 GNSKBHA080346"; + lgM = "LG Electronics LG ULTRAGEAR+ 511NTDVGC194"; in { @@ -50,37 +61,38 @@ in { name = "tower_00"; outputs = [ { - criteria = "AOC 24E1W1 GNSKCHA086899"; + criteria = aocT; position = "0,0"; } { - criteria = "AOC 24E1W1 GNSKBHA080346"; + criteria = aocB; position = "0,1080"; } { - criteria = "LG Electronics LG ULTRAGEAR+ 511NTDVGC194"; + criteria = lgM; position = "1920,720"; } ]; - exec = [ - "${pkgs.eww}/bin/eww open bar --screen 0" + exec = [ + (moveOrOpenBar 0) "${pkgs.writeShellScript "kanshi-hyprland-init" '' #!/usr/bin/env bash ${pkgs.hyprland}/bin/hyprctl eval ' - hl.workspace_rule({ workspace = "1", monitor = "DP-1", default = true }) - hl.workspace_rule({ workspace = "2", monitor = "DP-2", default = true }) - hl.workspace_rule({ workspace = "3", monitor = "DP-1", default = true }) - hl.workspace_rule({ workspace = "4", monitor = "DP-1", default = true }) - hl.workspace_rule({ workspace = "5", monitor = "DP-1", default = true }) - hl.workspace_rule({ workspace = "6", monitor = "DP-1", default = true }) - hl.workspace_rule({ workspace = "7", monitor = "DP-1", default = true }) - hl.workspace_rule({ workspace = "8", monitor = "DP-2", default = true }) - hl.workspace_rule({ workspace = "9", monitor = "DP-1", default = true }) - hl.workspace_rule({ workspace = "name:X", monitor = "DP-3", default = true }) + hl.workspace_rule({ workspace = "1", monitor = "desc:${aocB}", default = true }) + hl.workspace_rule({ workspace = "2", monitor = "desc:${aocT}", default = true }) + hl.workspace_rule({ workspace = "3", monitor = "desc:${aocB}", default = true }) + hl.workspace_rule({ workspace = "4", monitor = "desc:${aocB}", default = true }) + hl.workspace_rule({ workspace = "5", monitor = "desc:${aocB}", default = true }) + hl.workspace_rule({ workspace = "6", monitor = "desc:${aocB}", default = true }) + hl.workspace_rule({ workspace = "7", monitor = "desc:${aocB}", default = true }) + hl.workspace_rule({ workspace = "8", monitor = "desc:${aocT}", default = true }) + hl.workspace_rule({ workspace = "9", monitor = "desc:${aocB}", default = true }) + hl.workspace_rule({ workspace = "name:X", monitor = "desc:${lgM}", default = true }) ' - ${pkgs.hyprland}/bin/hyprctl eval 'hl.dispatch(hl.dsp.focus({ monitor = "DP-2" })); hl.dispatch(hl.dsp.focus({ workspace = "2" }));' - ${pkgs.hyprland}/bin/hyprctl eval 'hl.dispatch(hl.dsp.focus({ monitor = "DP-3" })); hl.dispatch(hl.dsp.focus({ workspace = "name:X" }));' - #${pkgs.hyprland}/bin/hyprctl eval 'hl.monitor({ output = "DP-3", cm = "hdr" });' + ${pkgs.hyprland}/bin/hyprctl eval 'hl.dispatch(hl.dsp.focus({ monitor = "desc:${aocT}" })); hl.dispatch(hl.dsp.focus({ workspace = "2" }));' + ${pkgs.hyprland}/bin/hyprctl eval 'hl.dispatch(hl.dsp.focus({ monitor = "desc:${lgM}" })); hl.dispatch(hl.dsp.focus({ workspace = "name:X" }));' + #${pkgs.hyprland}/bin/hyprctl eval 'hl.monitor({ output = "desc:${lgM}", cm = "hdr" });' + ${pkgs.hyprland}/bin/hyprctl eval 'hl.dispatch(hl.dsp.focus({ monitor = "desc:${aocB}" }));' ''}" "${pkgs.awww}/bin/awww restore" @@ -118,7 +130,7 @@ in { ''}" "${pkgs.awww}/bin/awww restore" - "${pkgs.eww}/bin/eww open bar --screen 0" + (moveOrOpenBar 0) ]; };} {profile = { diff --git a/modules/home/wayland/hyprland/config.nix b/modules/home/wayland/hyprland/config.nix index 8185be7..4f5ef0c 100644 --- a/modules/home/wayland/hyprland/config.nix +++ b/modules/home/wayland/hyprland/config.nix @@ -24,6 +24,7 @@ startupScript = pkgs.writeShellScriptBin "hyprland-start" '' + ${pkgs.eww}/bin/eww open bar & ${pkgs.awww}/bin/awww-daemon & ${pkgs.awww}/bin/awww restore &