GithubHelp home page GithubHelp logo

loqusion / hyprshade Goto Github PK

View Code? Open in Web Editor NEW
226.0 2.0 7.0 125.99 MB

Hyprland shader configuration tool

License: MIT License

Python 94.31% GLSL 5.34% Shell 0.35%
blue-light-filter glsl-shaders hyprland nvidia accessibility color-blind shaders

hyprshade's Introduction

Hyprshade

Front-end to Hyprland's screen shader feature

NOTE: Hyprshade is not an official Hyprland tool

Screenshots

Unfiltered

Unfiltered

Vibrance

Vibrance

Blue Light Filter

Blue Light Filter

Description

Hyprshade takes full advantage of Hyprland's decoration:screen_shader feature by automating the process of switching screen shaders, either from a user-defined schedule or on the fly. It can be used as a replacement1 for apps that adjust the screen's color temperature such as f.lux, redshift, or gammastep with blue-light-filter, which is installed by default.

Installation

Arch Linux

Use your favorite AUR helper (e.g. paru):

paru -S hyprshade

Or manually:

sudo pacman -S --needed base-devel
git clone https://aur.archlinux.org/hyprshade.git
cd hyprshade
makepkg -si

PyPI

If your distribution isn't officially supported, you can also install directly from PyPI with pip:

pip install --user hyprshade

Or with pipx:

pipx install hyprshade

Usage

Usage: hyprshade [OPTIONS] COMMAND [ARGS]...

Commands:
  auto     Set screen shader on schedule
  current  Print current screen shader
  install  Install systemd user units
  ls       List available screen shaders
  off      Turn off screen shader
  on       Turn on screen shader
  toggle   Toggle screen shader

Commands which take a shader name accept either the basename:

hyprshade on blue-light-filter

...or a full path name:

hyprshade on ~/.config/hypr/shaders/blue-light-filter.glsl

If you provide the basename, Hyprshade searches in ~/.config/hypr/shaders and /usr/share/hyprshade.

Scheduling

Warning

For scheduling to work, systemd --user must have access to the environment variable HYPRLAND_INSTANCE_SIGNATURE.

Add the following line to hyprland.conf2:

exec-once = dbus-update-activation-environment --systemd HYPRLAND_INSTANCE_SIGNATURE

To have specific shaders enabled during certain periods of the day, you can create a config file in either ~/.config/hypr/hyprshade.toml or ~/.config/hyprshade/config.toml.

[[shades]]
name = "vibrance"
default = true  # shader to use during times when there is no other shader scheduled

[[shades]]
name = "blue-light-filter"
start_time = 19:00:00
end_time = 06:00:00   # optional if you have more than one shade with start_time

For starters, you can copy the example config:

cp /usr/share/hyprshade/examples/config.toml ~/.config/hypr/hyprshade.toml

After writing your config, install the systemd timer/service user units and enable the timer unit:

hyprshade install
systemctl --user enable --now hyprshade.timer

Tip

Run hyprshade install every time you make changes to hyprshade.toml to keep the user units in sync.

Tips

You probably want the following line in your hyprland.conf:

exec = hyprshade auto

This ensures that the correct shader is enabled when you log in.

FAQ

I tried to copy something from the examples/ or shaders/ directory, but it's not working. What gives?

If you try to copy things from the main branch while you are using a stable release, it may not work properly. This repository has a single-branch development scheme, where all development is done on the main branch and stable versions are pinned with tags. The only exception to this is that updates to the README pertaining to unreleased features are kept on separate branches to avoid advertising features not present in any stable version.

If you'd like to try out unreleased features, you can use a development version of Hyprshade — currently, the only officially supported way to do this is to use the hyprshade-git AUR package.

Footnotes

  1. Gradual color shifting currently unsupported.

  2. See also: Hyprland FAQ (cache)

hyprshade's People

Contributors

loqusion avatar mariasolos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hyprshade's Issues

Screenshots - Discussion

It would be nice if the README had screenshots of shaders for demonstration purposes. However, I (and others) have not been able to take proper screenshots (a screenshot is taken without the shader applied).

EDIT: Ok, screenshots with shaders are working again. I'll upload them soon.

`hyprshade install` cannot create the systemd file itself

After copying the configuration file according to the document, directly running hyprshade install will return an error:

Error: [Errno 2] No such file or directory: '/home/<username>/.config/systemd/user/hyprshade.service'

hyprshade install can run successfully only after manually creating this systemd file.

OS: Arch Linux x86_64
Kernel: 6.5.1
hyprshade version: aur/hyprshade-git 0.10.0.r1.g7b78d98-1, however, this error has occurred in previous versions.

Reduce intensity?

Is there a way to reduce intensity on the "night-light-filter"?
If not I think its a must have!

Replace blue-light-filter's code.

Please replace the code below with blue-light-shader.glsl. This one is properly formatted.

// from https://github.com/hyprwm/Hyprland/issues/1140#issuecomment-1335128437

precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D tex;

const float temperatureStrength = 1.0;
const float temperature = 4800.0;

#define WithQuickAndDirtyLuminancePreservation
const float LuminancePreservationFactor = 1.0;

// function from https://www.shadertoy.com/view/4sc3D7
vec3 colorTemperatureToRGB(const in float temperature) {
  // values from: http://blenderartists.org/forum/showthread.php?270332-OSL-Goodness&p=2268693&viewfull=1#post2268693
  mat3 m = (temperature <= 6500.0) ?
    mat3 (
      vec3 (0.0, -2902.1955373783176   , -8257.7997278925690   ),
      vec3 (0.0,  1669.5803561666639   ,  2575.2827530017594   ),
      vec3 (1.0,     1.3302673723350029,     1.8993753891711275)
    ) :
    mat3 (
      vec3 ( 1745.0425298314172    ,  1216.6168361476490    , -8257.7997278925690   ),
      vec3 (-2666.3474220535695    , -2173.1012343082230    ,  2575.2827530017594   ),
      vec3 (    0.55995389139931482,     0.70381203140554553,     1.8993753891711275)
    );
  return mix (
    clamp (
      vec3 (
        m[0] / (
          vec3 (
            clamp (
              temperature,
              1000.0,
              40000.0
            )
          ) + m[1]
        ) + m[2]
      ),
      vec3(0.0),
      vec3(1.0)
    ),
    vec3(1.0),
    smoothstep(
      1000.0,
      0.0,
      temperature
    )
  );
}

void main() {
  vec4 pixColor = texture2D (
    tex,
    v_texcoord
  );

  // RGB
  vec3 color = vec3 (
    pixColor[0],
    pixColor[1],
    pixColor[2]
  );

  #ifdef WithQuickAndDirtyLuminancePreservation
  color *= mix (
    1.0,
    dot (
      color,
      vec3 (
        0.2126,
        0.7152,
        0.0722
      )
    ) / max (
      dot (
        color,
        vec3 (
          0.2126,
          0.7152,
          0.0722
        )
      ),
      1e-5
    ),
    LuminancePreservationFactor
  );
  #endif

  color = mix (
    color,
    color * colorTemperatureToRGB (
      temperature
    ),
    temperatureStrength
  );

  vec4 outCol = vec4 (
    color,
    pixColor[3]
  );

  gl_FragColor = outCol;
}

3DLUT shader as an temporary solution for Color Management for hyprland

I'm surprised no one has made a 3DLUT shader using a PNG like Reshade, libretro or some art applications like i think blender as a compromise until Color Management actually reaches wayland/hyprland/AMDGPU, this of course has the downside of being on all monitors until hyprland's shader API gets more developed but a option is better than none.

  • This'll probably be better in some ways as i believe the AMDGPU Display Core driver will be limited to 9^3 or 17^3 ICCs, far from the biggest which is 65^3(though this is probably overkill by a huge margin),

    • These ICCs don't have any color correction just gamma correction(at least the "2DLUTs" made by Displaycal/Argyllcms), You can make 3DLUTs that have the color correction in a ICC format but argyll-dispwin(argyllcms tool to apply ICCs to X11) won't apply them because they are missing a vgt tag so this'll be a benefit over X11 too.
  • You could make an arbitrary PNG in a 3DLUT format to apply whatever colors you want if you wanted to for some reason.

  • It'd also be nice for Nvidia users as i don't think Nvidia supports CM at all even on X11.

Currently this is the only thing holding me back from using wayland/hyprland and it'd be nice to at least see some solution for it, even if i have to do it myself but i'd need some pointers as i know nothing of GLSL, if this requires some C or other backend code or how i'd integrate it into hyprshade(if needed).

AUR installation fails with `hyprland exists in filesytem`

Installing hyprshade with yay fails with:

(13/13) checking for file conflicts                                      [#########################################] 100%
error: failed to commit transaction (conflicting files)
hyprland: /usr/bin/Hyprland exists in filesystem
hyprland: /usr/bin/hyprctl exists in filesystem
hyprland: /usr/lib/libwlroots.so.13032 exists in filesystem
hyprland: /usr/share/wayland-sessions exists in filesystem

I just reinstalled Hyprland but built it manually. Could that be linked?

Thanks! ❤️

systemd timer need an additional rule 'AccuracySec=1ms'

systemd tend to excute on some random secs to avoid cpu request peak.But hyprshade need to run exactly at starttime.
In install.py,

[Timer]
AccuracySec=1ms
{timer_config}

I found hyprshade failed to run ,or maybe it run before some secs leads to shade change didnot apply.So I add the rule in hyprshade.timer, have not test it.

Dedup `hyprshade ls` output

Example:

   bloom              /home/loqusion/.config/hypr/shaders
-  blue-light-filter  /home/loqusion/.config/hypr/shaders
   blue-light-filter  /usr/share/hyprshade/shaders
 * blue-light-filter  /home/loqusion/.config/hypr/shaders
   blur               /home/loqusion/.config/hypr/shaders
   crt                /home/loqusion/.config/hypr/shaders
   drugs              /home/loqusion/.config/hypr/shaders
   vibrance           /usr/share/hyprshade/shaders

Add grayscale shade

I'd like to see a grayscale shade for those who want a ereader like experience. This would help those who want a book like experience or not to get distracted by all the colors the screen displays.

Screenshot ... *without shader*

Hey, just a minor issue/request.

I would like to be able to take screenshots (currently using grim and slurp) in such a a way that the shader isn't present.

I saw that at one point this was behavior and it was "fixed" so I can understand if my request seems backwards. It would be nice because if you send the screenshot to someone that also has a filter on then they'll see the images as extra yellow due to the stacked filters. Overall keeping the filter applied on the screenshots is just a destructive operation and removes the true colors from the underlying image.

I do have a simple workaround so it's not thaat big of an issue, so it's just a nice-to-have:
hyprshade off && grim -g "$(slurp)" - | xsel -b && hyprshade on blue-light-filter.glsl

Thanks for making hyprshade.

Correct example

In your example file, the section config is [[shaders]]. However [[shades]] should be the right one. Also I cant get the temperature config to work with blue light filter whether it's [shades.config] or [shaders.config]

[[shades]]
name = "blue-light-filter"
start_time = 19:00:00
end_time = 06:00:00
[shades.config]
temperature = 3400

search shade by name have flaws

I create a new shade named 'blue-light-filter-gentle.glsl' in config/hypr/shaders, there already have a blue-light-filter.glsl in /usr/share/hyprshade/,but when blue-light-filter-gentle.glsl is applied when its blue-light-filter's turn, hyprshade auto can't switch to it.
I have to rename blue-light-filter-gentle.glsl to gentle-blue-light-filter.glsl, in that way hyprshade can tell them apart.
please check it ,I hope I am wrong.I just rename the file ,did not dig into the source file.

[Bug] Shader doesn't apply to cursor

The shaders apply to my whole screen except the cursor, I would attach a screenshot but not sure how to take one with a cursor in it.

Thanks for this awesome piece of software, would love if this issue could be resolved :)

Screen shader parser: Screen shader parse failed

When using the main branch of Hyprshade, shaders fail to parse correctly.

Steps to Reproduce

  1. Check out the main branch of the Hyprland repository.
  2. Attempt to run Hyprland with custom shaders (blue filters).

`ls` edge case

If any of the directories ls searches has any subdirectories, they will be treated as regular files due to the implementation of ls_dirs. This means any shader files within subdirectories will not be listed, and it also means that if you run the command with -l, it will panic.

`scandir_recrusive` edge cases

scandir_recursive is used to find shader files in one's shader directory. It has various issues that will probably only occur for less than 0.1% of users:

  • It should find and return files higher up the directory tree first via breadth-first search, but instead it does a reverse pre-order depth-first search. This can have various performance and resource usage implications in niche situations.
  • It doesn't properly handle cases where a symlink to a directory higher in the tree (e.g. a node is its own ancestor) causes an infinite loop which only breaks due to max_depth.

def scandir_recursive(
path: GenericPath[AnyStr], *, max_depth: int
) -> Iterator[os.DirEntry[AnyStr]]:
assert max_depth >= 0
dir_stack = []
with os.scandir(path) as it:
for direntry in it:
if not direntry.is_dir():
yield direntry
elif max_depth > 0:
dir_stack.append(direntry)
while dir_stack:
yield from scandir_recursive(dir_stack.pop(), max_depth=max_depth - 1)

Support shader directory searching `~/.config/hyprshade/shaders`

~/.config
❯ nix shell nixpkgs#hyprshade

~/.config 
❯ mkdir -p hyprshade/shaders

~/.config 
❯ cd hyprshade/

~/.config/hyprshade 
❯ nvim shaders/blue-light.glsl

~/.config/hyprshade  took 40s
❯ hyprshade on blue-light
Error: Shader 'blue-light' could not be found in any of the following directories:

[ble: exit 1]

~/.config/hyprshade 
❯ hyprshade on ./shaders/blue-light.glsl
Error: Shader 'blue-light' could not be found in any of the following directories:

[ble: exit 1]

~/.config/hyprshade 
❯ ls shaders
blue-light.glsl

~/.config/hyprshade 
❯ hyprshade on /home/x/.config/hyprshade/shaders/hyblue-light.glsl

~/.config/hyprshade 
❯ # success!

~/.config/hyprshade 
❯ mkdir ~/.config/hypr/shaders

~/.config/hyprshade 
❯ cp ./shaders/blue-light.glsl ../hypr/shaders/

~/.config/hyprshade 
❯ hyprshade off

~/.config/hyprshade 
❯ hyprshade on blue-light

~/.config/hyprshade 
❯ # success!
        
        

The program does not print the directories it searched, but to my understanding it looks in some share folder and in in ~/.config/hypr/shaders.

If the hyprshader config is allowed to live in ~/.config/hyprshader, I want to also put my shaders in ~/.config/hyprshader/shaders.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.