feat: cosmic settings daemon (#8)
* feat: cosmic settings daemon * refactor: simplify by unifying trait for state and config * chore: add ping and pong methods * refactor: remove ping & pong methods * cleanup
This commit is contained in:
parent
2ef53b2bfa
commit
3644bc9099
4 changed files with 124 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
resolver = "2"
|
||||
|
||||
members = [
|
||||
"cosmic-settings-daemon",
|
||||
"mpris2",
|
||||
"networkmanager",
|
||||
"timedate",
|
||||
|
|
|
|||
15
cosmic-settings-daemon/Cargo.toml
Normal file
15
cosmic-settings-daemon/Cargo.toml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "cosmic-settings-daemon"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
zbus.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
futures = "0.3"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
zbus.workspace = true
|
||||
zbus.features = ["tokio"]
|
||||
33
cosmic-settings-daemon/examples/simple.rs
Normal file
33
cosmic-settings-daemon/examples/simple.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use futures::StreamExt;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> zbus::Result<()> {
|
||||
let connection = zbus::Connection::session().await?;
|
||||
|
||||
let proxy = cosmic_settings_daemon::CosmicSettingsDaemonProxy::new(&connection).await?;
|
||||
|
||||
println!("Display brightness: {}", proxy.display_brightness().await?);
|
||||
println!(
|
||||
"Keyboard brightness: {}",
|
||||
proxy.keyboard_brightness().await?
|
||||
);
|
||||
|
||||
let (config_path, name) = proxy
|
||||
.watch_config("com.system76.CosmicTheme.Light", 1)
|
||||
.await?;
|
||||
dbg!(&config_path, &name);
|
||||
let config_proxy = cosmic_settings_daemon::ConfigProxy::builder(&connection)
|
||||
.path(config_path)?
|
||||
.destination(name)?
|
||||
.build()
|
||||
.await?;
|
||||
let mut stream = config_proxy.receive_changed().await?;
|
||||
|
||||
println!("Watching config for the libcosmic light theme...");
|
||||
println!("Change the light theme in Settings > Appearance to trigger a signal.");
|
||||
while let Some(c) = stream.next().await {
|
||||
let c = c.args()?;
|
||||
println!("Config changed: {} {}", c.id, c.key);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
75
cosmic-settings-daemon/src/lib.rs
Normal file
75
cosmic-settings-daemon/src/lib.rs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
//! # DBus interface proxy for: `com.system76.CosmicSettingsDaemon`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `3.1.1` from DBus introspection data.
|
||||
//! Source: `Interface '/com/system76/CosmicSettingsDaemon' from service 'com.system76.CosmicSettingsDaemon' on session bus`.
|
||||
//!
|
||||
//! You may prefer to adapt it, instead of using it verbatim.
|
||||
//!
|
||||
//! More information can be found in the
|
||||
//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html)
|
||||
//! section of the zbus documentation.
|
||||
//!
|
||||
//! This DBus object implements
|
||||
//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
|
||||
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
|
||||
//!
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//! * [`zbus::fdo::PropertiesProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use zbus::{dbus_proxy, names::OwnedWellKnownName};
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "com.system76.CosmicSettingsDaemon",
|
||||
default_service = "com.system76.CosmicSettingsDaemon",
|
||||
default_path = "/com/system76/CosmicSettingsDaemon"
|
||||
)]
|
||||
trait CosmicSettingsDaemon {
|
||||
/// DecreaseDisplayBrightness method
|
||||
fn decrease_display_brightness(&self) -> zbus::Result<()>;
|
||||
|
||||
/// DecreaseKeyboardBrightness method
|
||||
fn decrease_keyboard_brightness(&self) -> zbus::Result<()>;
|
||||
|
||||
/// IncreaseDisplayBrightness method
|
||||
fn increase_display_brightness(&self) -> zbus::Result<()>;
|
||||
|
||||
/// IncreaseKeyboardBrightness method
|
||||
fn increase_keyboard_brightness(&self) -> zbus::Result<()>;
|
||||
|
||||
/// WatchConfig method
|
||||
fn watch_config(
|
||||
&self,
|
||||
id: &str,
|
||||
version: u64,
|
||||
) -> zbus::Result<(zbus::zvariant::OwnedObjectPath, OwnedWellKnownName)>;
|
||||
|
||||
/// WatchState method
|
||||
fn watch_state(
|
||||
&self,
|
||||
id: &str,
|
||||
version: u64,
|
||||
) -> zbus::Result<(zbus::zvariant::OwnedObjectPath, OwnedWellKnownName)>;
|
||||
|
||||
/// DisplayBrightness property
|
||||
#[dbus_proxy(property)]
|
||||
fn display_brightness(&self) -> zbus::Result<i32>;
|
||||
fn set_display_brightness(&self, value: i32) -> zbus::Result<()>;
|
||||
|
||||
/// KeyboardBrightness property
|
||||
#[dbus_proxy(property)]
|
||||
fn keyboard_brightness(&self) -> zbus::Result<i32>;
|
||||
fn set_keyboard_brightness(&self, value: i32) -> zbus::Result<()>;
|
||||
}
|
||||
|
||||
#[dbus_proxy(
|
||||
interface = "com.system76.CosmicSettingsDaemon.Config",
|
||||
default_service = "com.system76.CosmicSettingsDaemon.Config"
|
||||
)]
|
||||
trait Config {
|
||||
/// Changed signal
|
||||
#[dbus_proxy(signal)]
|
||||
async fn changed(&self, id: String, key: String) -> zbus::Result<()>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue