Code Monkey home page Code Monkey logo

dimmer's Introduction

dimmer

Dimmer smoothly transitions your screen from one brightness to another. Very simple, and only tested with Wayland and recent Linux kernels.

Usage

# Show usage information
dimmer --help

# Dim the screen to zero brightness over 5 seconds
dimmer

# Dim (or brighten) the screen to 30%, first saving the current brightness to a statefile
dimmer --save --duration 5s 30%

# Restore the screen from a previously saved brightness, using 2 seconds
dimmer --restore --duration 2s

Integration with swayidle

Many people like to automatically turnoff & lock their screen after a period of idleness and it would sure be nice if we could smoothly dim the screen before turning it off (and smoothly restore the brightness later). When we interact with the system during the dimming process, we'd like the dimming process to stop and the brightness to quickly be restored.

Swayidle offers no possibilities for signals to be send to a (dimming) process that is already running, so the reaction to the new user input would have to come from a new process. However, the swayidle(1) man-page recommends for security purposes to use the -w flag to wait for triggered commands to finish when used in combination with a screenlock, which would make it impossible for us to interrupt the screen dimming process on user input.

For this reason, I recommend running one swayidle process with the -w flag to trigger the locking command, and another swayidle process without the -w flag to trigger the dimmer commands.

Sway and swayidle configuration example

Excerpt from what a sway config (e.g. ~/.config/sway/config) could look like:

exec swayidle -w \
  timeout 620 'swaymsg "output * dpms off"' \
  timeout 625 'swaylock -f' \
  timeout 630 'systemctl suspend'

exec swayidle \
  timeout 600 'dimmer --save' \
  resume 'pkill dimmer; dimmer --restore --duration 1s'

Installation

Permissions

Setting the backlight works by writing to a special file in /sys (exposed by the kernel for this purpose), which on many distro's requires the user to be a member of a group, often video. If you receive a Permission denied error, chances are your user needs additional privileges to be able to write to the file.

Check ls -l /sys/class/backlight/*/brightness for the permissions on the backlight file and the group you can add your user to.

Nix Flakes Use as you would any nix flake, e.g. run directly with
nix run github:koenw/dimmer
Cargo Install to cargo's bin directory with
cargo install dimmer

dimmer's People

Contributors

koenw avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.