commit 552ddf727476683e2d0110fdf94826d64ae4c3e6 Author: Matthieu Bessat Date: Tue Mar 26 09:56:36 2024 +0100 feat: add change_temperature method diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..5c4f7b4 --- /dev/null +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..6497cff --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "auto_wlgamma" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1.0.81" +dbus = "0.9.7" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..09a6d4c --- /dev/null +++ b/src/main.rs @@ -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> { + let _ = change_temperature(2500); + + Ok(()) +} +