A simple program that provides DBus interface to control display temperature and brightness under wayland without flickering

Overview

wl-gammarelay-rs

Like wl-gammarelay, but written in rust, runs on a single thread, has three times less SLOC and uses DBus (for simplicity).

Dbus interface

$ busctl --user introspect rs.wl-gammarelay / rs.wl.gammarelay
NAME               TYPE      SIGNATURE RESULT/VALUE FLAGS
.ToggleInverted    method    -         -            -
.UpdateBrightness  method    d         -            -
.UpdateTemperature method    n         -            -
.Brightness        property  d         1            emits-change writable
.Inverted          property  b         false        emits-change writable
.Temperature       property  q         4500         emits-change writable

Installation

cargo install wl-gammarelay-rs

Status bar integration

i3status-rust

i3status-rust hueshift block has the builtin support for this backend on the async branch. See the documentation here.

Waybar

    "custom/wl-gammarelay-temperature": {
        "format": "{} ",
        "exec": "wl-gammarelay-rs watch {t}",
        "on-scroll-up": "busctl --user -- call rs.wl-gammarelay / rs.wl.gammarelay UpdateTemperature n +100",
        "on-scroll-down": "busctl --user -- call rs.wl-gammarelay / rs.wl.gammarelay UpdateTemperature n -100"
    },
    "custom/wl-gammarelay-brightness": {
        "format": "{}% ",
        "exec": "wl-gammarelay-rs watch {bp}",
        "on-scroll-up": "busctl --user -- call rs.wl-gammarelay / rs.wl.gammarelay UpdateBrightness d +0.02",
        "on-scroll-down": "busctl --user -- call rs.wl-gammarelay / rs.wl.gammarelay UpdateBrightness d -0.02"
    }

Watch for changes

You can run wl-gammarelay-rs watch <format> to watch for changes. Each time some property changes, a new line will be printed based on string. {t} expands into temperature, {b} into brightness (0 to 1) and {bp} expands into brightness in percents (0 to 100).

For example, if you want to monitor both temperature and brightness (in percents), you can run

$ wl-gammarelay-rs watch "{t}K {bp}%"
4000K 90%
4500K 90%
5000K 90%
5000K 100%
5000K 80%
5000K 100%
...

Example usage in scripts

# Set the temperature to `5000`
busctl --user set-property rs.wl-gammarelay / rs.wl.gammarelay Temperature q 5000

# Increase the temperature by `100`:
busctl --user call rs.wl-gammarelay / rs.wl.gammarelay UpdateTemperature n 100

# Decrease the temperature by `100`:
busctl --user -- call rs.wl-gammarelay / rs.wl.gammarelay UpdateTemperature n -100

# Invert colors
busctl --user set-property rs.wl-gammarelay / rs.wl.gammarelay Inverted b true

# Toggle inverted colors
busctl --user call rs.wl-gammarelay / rs.wl.gammarelay ToggleInverted

# Set the brightness to `100%`:
busctl --user set-property rs.wl-gammarelay / rs.wl.gammarelay Brightness d 1

# Increase the brightness by `10%`:
busctl --user call rs.wl-gammarelay / rs.wl.gammarelay UpdateBrightness d 0.1

# Decrease the brightness by `10%`:
busctl --user -- call rs.wl-gammarelay / rs.wl.gammarelay UpdateBrightness d -0.1
You might also like...
Cross-platform CLI Rimworld Mod manager. Still under development

rwm Inspired by Spoons rmm. This is a cross-platform Mod Manager for RimWorld intended to work with macOS, linux and Windows Up to now, you must have

A wayland native, highly customizable runner.

anyrun A wayland native krunner-like runner, made with customizability in mind. Features Style customizability with GTK+ CSS More info in Styling Can

💫 This program allows you to do requests in Rust without reqwest !

Zapros 💫 This program allows you to do requests in Rust without reqwest ! Usage : Get use crate::http_client::HttpClient; use crate::http_client::Htt

A program that provides LLMs with the ability to complete complex tasks using plugins.

SmartGPT SmartGPT is an experimental program meant to provide LLMs (particularly GPT-3.5 and GPT-4) with the ability to complete complex tasks without

That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.
That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.

📌 This program is designed to translate text into the correct layout when typing is incorrect. 📌 Example ghbdtn - привет Just (by default) pressing

A simple overlay for OBS to display consecutive keystrokes. Primarily for programming, especially for Vim.

Keystroke-Display A simple overlay for OBS to display consecutive keystrokes. Primarily for programming, especially for Vim. This will work on Windows

A silly program written in Rust to output nonsensical sentences in the command line interface.

A silly program written in Rust to output nonsensical sentences in the command line interface.

Add CLI & form interface to your program
Add CLI & form interface to your program

Add CLI & form interface to your program

A simple tui to view & control docker containers
A simple tui to view & control docker containers

oxker A simple tui to view & control docker containers Built in Rust, making heavy use of tui-rs & Bollard Download & install See releases download &

Comments
  • Fails to build on non-Linux

    Fails to build on non-Linux

    Regressed by b469d9e9aa53. Affects downstream package. CC @unrelentingtech

    • FreeBSD >= 13.0 has memfd_create(3) but https://github.com/rust-lang/libc/commit/0a57541a7101 cannot be used due to https://github.com/rust-lang/libc/issues/570. memfd_create can be replaced with shm_open(SHM_ANON, ...) which is supported on all FreeBSD versions.
    • OpenBSD has shm_mkstemp(3) but not exposed in libc crate
    • DragonFly and NetBSD have neither
    $ cargo build
    [...]
    error[E0433]: failed to resolve: could not find `MemfdOptions` in `memfd`
       --> src/wayland.rs:106:39
        |
    106 |                     let file = memfd::MemfdOptions::new().create("ramp")?;
        |                                       ^^^^^^^^^^^^ could not find `MemfdOptions` in `memfd`
    
    warning: unused import: `std::os::unix::io::AsRawFd`
      --> src/wayland.rs:12:5
       |
    12 | use std::os::unix::io::AsRawFd;
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `#[warn(unused_imports)]` on by default
    
    For more information about this error, try `rustc --explain E0433`.
    warning: `wl-gammarelay-rs` (bin "wl-gammarelay-rs") generated 1 warning
    error: could not compile `wl-gammarelay-rs` due to previous error; 1 warning emitted
    
    opened by jbeich 6
  • Can't compile using `cargo install wl-gammarelay-rs`

    Can't compile using `cargo install wl-gammarelay-rs`

    Output of rustup check: stable-x86_64-unknown-linux-gnu - Up to date : 1.58.1 (db9d1b20b 2022-01-20) rustup - Up to date : 1.24.3

    error[E0005]: refutable pattern in local binding: `_` not covered
     --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/wl-gammarelay-rs-0.2.0/src/dbus_client.rs:6:9
      |
    6 |     let zbus::Address::Unix(addr) = zbus::Address::session()?;
      |         ^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
      |
      = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
      = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
      = note: the matched value is of type `zbus::Address`
    help: you might want to use `if let` to ignore the variant that isn't matched
      |
    6 |     if let zbus::Address::Unix(addr) = zbus::Address::session()? { /* */ }
      |
    
    error[E0005]: refutable pattern in local binding: `_` not covered
      --> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/wl-gammarelay-rs-0.2.0/src/dbus_server.rs:14:9
       |
    14 |     let zbus::Address::Unix(addr) = zbus::Address::session()?;
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `_` not covered
       |
       = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
       = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
       = note: the matched value is of type `zbus::Address`
    help: you might want to use `if let` to ignore the variant that isn't matched
       |
    14 |     if let zbus::Address::Unix(addr) = zbus::Address::session()? { /* */ }
       |
    
    For more information about this error, try `rustc --explain E0005`.
    error: failed to compile `wl-gammarelay-rs v0.2.0`, intermediate artifacts can be found at `/tmp/cargo-installhvl4E7`
    
    Caused by:
      could not compile `wl-gammarelay-rs` due to 2 previous errors
    
    opened by egrist 6
  • Adjust color temperature of inverted colormap: flip gamma ramp left-to-right (rather than upside-down)

    Adjust color temperature of inverted colormap: flip gamma ramp left-to-right (rather than upside-down)

    My use case: I like to adjust the color temperature of my display (redhift style). I also frequently invert the colors of my display (by keystroke) because I visually prefer light-on-dark but have to look a lot at black-on-white documents.

    However, currently, adjusting the color temperature and inverting the display do not properly combine, as effectively the temperature-adjusted gamma ramp is inverted. This is because the gamma ramp is inverted upside-down:

    r[i] = u16::MAX - (v * white_r) as u16;
    

    To properly temperature-adjust the inverted gamma ramp, one should instead flip the gamma ramp left-to-right:

    r[ramp_size - 1 - i] = (v * white_r) as u16;
    

    With a linear gamma ramp and full brightness, both methods of course have the same effect. With a linear gamma ramp and reduced brightness setting, the original increases brightness due to the inversion (turning black into gray), while my proposed method reduces brightness even under inversion.

    Changing the behavior as I propose would probably destroy other users' use cases. But would you accept a patch that adds this behavior as a new option?

    enhancement 
    opened by piater 5
  • Add Gamma ramp; properly cumulate temp, brightness, gamma, inversion

    Add Gamma ramp; properly cumulate temp, brightness, gamma, inversion

    This works flawlessly for me, but check carefully - this is my first hackery in Rust, and I don't know Rust.

    You probably want to squash the commits (sorry) on merging.

    As an aside, I noticed that the symbols in the Waybar example (where Gamma uses γ) use Unicode code points from a private use area and are thus unlikely to be displayed properly for many users (including me).

    opened by piater 2
Releases(v0.3.0)
Owner
Max Verevkin
Max Verevkin
A lightweight and super fast cli todo program written in rust under 200 sloc

todo A lightweight and super fast cli todo program written in rust under 200 sloc installation AUR package: todo-bin use cargo build --release to comp

sioodmy 243 Dec 24, 2022
Rust code for T-Display S3 AMOLED, ESP32-S3 board with RM67162 AMOLED display

T-Display S3 AMOLED What is it? This is a Rust BSP for the Lilygo's T-Display S3 AMOLED board. RM67162 AMOLED driver in QSPI mode RM67162 AMOLED drive

BH1XUW 4 Jun 28, 2023
A launcher/menu program written in Rust for wlroots-based Wayland compositors

tehda tehda (ᴛᴀʏ-dah /ˈteɪ̯.dæ/ or /teh.da/; Finnish for "to do, perform, execute") is a launcher/menu program, like dmenu, rofi, or wofi, written in

Nadia 4 Jan 29, 2023
Raspberry Pi's CPU and GPU temperature exporter for Prometheus consumption.

Pi Temperature Exporter A simple application for collecting Raspberry Pi's CPU and GPU temperatures and exporting them for Prometheus consumption. Ins

Sergei 11 Mar 12, 2023
Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi.

Datalogger Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi. Index Install Git Cargo Master branch Latest release from crates.io

Marco Radocchia 2 Aug 2, 2022
Sero is a web server that allows you to easily host your static sites without pain. The idea was inspired by surge.sh but gives you full control.

sero Lightning-fast, static web publishing with zero configuration and full control ?? Table Of Contents ?? Table Of Contents ?? Tools ❓ About The Pro

Dmitry Miasnenko 6 Nov 13, 2023
Just a simple object renderer, written in under 500 lines using Rust.

All cargoes that the project runs are: bitflags: a crate for defining bitflag types cfg-if: a small macro crate for defining cfg-based - conditional c

null 3 May 4, 2023
Open source email client written in Rust and Dioxus. Under 🏗️

Blazemail A full-featued, beautiful, mail client that doesn't suck. Works on mac, windows, linux, mobile, web, etc. Features, status Blazemail is curr

Jon Kelley 13 Dec 19, 2022
A simple program for C program IO testing. Written in Rust

A simple program for C program IO testing. Written in Rust, using concurrency to speed up valgrind testing. Make sure to update settings at your first run of the program!

null 1 Feb 22, 2022
global state management for dioxus built on the concept of atoms. currently under 🏗

Fermi: A global state management solution for Dioxus, inspired by Recoil.Js Fermi provides primitives for managing global state in Dioxus applications

Dioxus 15 Feb 12, 2022