#!/usr/bin/env bash
# Toggle the warm/low-contrast screen shader.  fp16 rendering is switched off
# with it: the shader is written for 8-bit output.
shader="$HOME/.config/eww/shaders/read-mode.glsl"

active() { hyprctl getoption decoration:screen_shader 2>/dev/null | grep -qF "$shader"; }

case ${1:-} in
  status) active && echo true || echo false ;;
  *)
    if active; then
      hyprctl eval 'hl.config({ decoration = { screen_shader = "" } })' >/dev/null
      hyprctl eval 'hl.config({ render = { use_fp16 = 2 } })' >/dev/null
      state=false
    else
      hyprctl eval 'hl.config({ render = { use_fp16 = 0 } })' >/dev/null
      hyprctl eval "hl.config({ decoration = { screen_shader = \"$shader\" } })" >/dev/null
      state=true
    fi
    eww update read-mode="$state" 2>/dev/null
    echo "$state"
    ;;
esac
