feat: add change_temperature method

This commit is contained in:
Matthieu Bessat 2024-03-26 09:56:36 +01:00
commit 552ddf7274
4 changed files with 105 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

71
Cargo.lock generated Normal file
View file

@ -0,0 +1,71 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anyhow"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
[[package]]
name = "auto_wlgamma"
version = "0.1.0"
dependencies = [
"anyhow",
"dbus",
]
[[package]]
name = "dbus"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b"
dependencies = [
"libc",
"libdbus-sys",
"winapi",
]
[[package]]
name = "libc"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libdbus-sys"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72"
dependencies = [
"pkg-config",
]
[[package]]
name = "pkg-config"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "auto_wlgamma"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.81"
dbus = "0.9.7"

25
src/main.rs Normal file
View file

@ -0,0 +1,25 @@
use std::time::Duration;
use dbus::{arg::Variant, blocking::Connection, Error};
use anyhow::{anyhow, Result};
fn change_temperature(temp: u16) -> Result<()> {
let conn = Connection::new_session()?;
let proxy = conn.with_proxy("rs.wl-gammarelay", "/", Duration::from_millis(5000));
let call_ret: Result<(), Error> = proxy.method_call(
"org.freedesktop.DBus.Properties", "Set", (
"rs.wl.gammarelay",
"Temperature",
Variant(temp)
)
);
call_ret.map_err(|_err| anyhow!("Failed to call dbus method"))
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let _ = change_temperature(2500);
Ok(())
}