gnome-dbus-api 0.1.5

A simple API to interact with GNOME DBus and Gsettings
Documentation

Rust dbus and dconf gnome api bindings

Crates.io docs.rs Crates.io Crates.io

A friendly API for interacting with gnome shell, freedesktop and other D-Bus services and settings available on Ubuntu gnome.

This project is thought to be used in Sittly a tauri based app, you will see this trending in the examples.

Disclaimer: I'm not a Rust expert, I'm learning Rust and I'm using this project to learn it. If you see something that can be improved, please open an issue or a PR.

Usage

System apps

This app struct is thought to be used in a GUI to display all the apps installed in the system.

Because of that app.icon is a png image that can be encoded in base64 using app.get_base64_icon() and displayed in a GUI.

use gnome_dbus_api::handlers::easy_gnome::apps::Apps;

#[derive(Serialize, Deserialize, Clone)]
struct AppStruct {
    name: String,
    icon: Option<String>,
    description: String,
}

async fn get_all_apps() -> Result<Vec<AppStruct>, String> {
  let apps_instance = Apps::new();
  let apps = apps_instance.get_apps();
  let apps_struct: Vec<AppStruct> = apps
      .iter()
      .map(|app| {
          let base64 = app.get_base64_icon();
          let app_struct = AppStruct {
              name: app.name.to_string(),
              icon: base64,
              description: match &app.description {
                  Some(description) => description.to_string(),
                  None => String::from(""),
              },
          };
          app_struct
      })
      .collect();
  Ok(apps_struct)
}

Screen

use gnome_dbus_api::handlers::easy_gnome::screen;

async fn brightness_up() -> Result<(), String> {
    screen::step_up().await;
    Ok(())
}
async fn brightness_down() -> Result<(), String> {
    screen::step_down().await;
    Ok(())
}
async fn get_brightness() -> Result<i32, String> {
    let brightness = screen::brightness().await;
    Ok(brightness)
}
async fn set_brightness(value: i32) -> Result<(), String> {
    screen::set_brightness(value).await;
    Ok(())
}

Night light

use gnome_dbus_api::handlers::easy_gnome::nightlight;

async fn get_nightlight_active() -> Result<bool, String> {
    let is_active: bool = nightlight::nightlight_active().await;
    Ok(is_active)
}
async fn get_temperature() -> Result<u32, String> {
    let temperature: u32 = nightlight::temperature().await;
    Ok(temperature)
}
async fn set_nightlight(status: bool) -> Result<(), String> {
    nightlight::set_nightlight_active(status).await;
    Ok(())
}
async fn set_temperature(temperature: u32) -> Result<(), String> {
    nightlight::set_temperature(temperature).await;
    Ok(())
}

Screenshot

use gnome_dbus_api::handlers::easy_gnome::screenshot;
async fn pick_color() {
  let (r, g, b) = screenshot::pick_color().await;
}

Power

use gnome_dbus_api::handlers::easy_gnome::power;
async fn power_off() {
power::power_off().await;
}
async fn reboot() {
power::reboot().await;
}
async fn suspend() {
power::suspend().await;
}

Features

  • Power management

    • Power off
    • Reboot
    • Suspend
  • Locales

    • Get x11 layout
  • Gnome extensions

    • Get extensions
    • Enable extension
    • Disable extension
    • Uninstall extension
  • Gnome shell screenshot

    • Pick color
  • Settings

    • Night light
      • Get night light status
      • Set night light status
      • Get night light temperature
      • Set night light temperature
  • Gsettings Dconf (https://crates.io/crates/dconf_rs/0.3.0)

    • image
    • org.gnome.desktop.peripherals.keyboard delay 500 (initial key repeat delay)
    • org.gnome.desktop.peripherals.keyboard repeat-interval 30 (initial key repeat delay)
    • org.gnome.desktop.peripherals.mouse natural-scroll true
    • org.gnome.desktop.peripherals.touchpad tap-to-click true
    • org.gnome.desktop.peripherals.touchpad two-finger-scrolling-enabled true
    • org.gnome.desktop.calendar show-weekdate
    • org.gnome.desktop.interface clock-format
    • org.gnome.desktop.interface clock-show-date true
    • org.gnome.desktop.interface clock-show-seconds false
    • org.gnome.desktop.interface clock-show-weekday true
    • org.gnome.desktop.interface color-scheme 'prefer-light'
    • org.gnome.desktop.interface cursor-blink true
    • org.gnome.desktop.interface cursor-blink-time 1200
    • org.gnome.desktop.interface cursor-size 24
    • org.gnome.desktop.interface cursor-blink-timeout 10
    • org.gnome.desktop.interface enable-hot-corners false
    • org.gnome.desktop.interface locate-pointer false (with ctrl key)
    • org.gnome.desktop.interface overlay-scrolling true
    • org.gnome.desktop.interface show-battery-percentage true
    • org.gnome.desktop.privacy disable-camera false
    • org.gnome.desktop.privacy disable-microphone false
    • org.gnome.desktop.privacy disable-sound-output false
    • org.gnome.desktop.privacy hide-identity false
    • org.gnome.desktop.screensaver picture-uri 'file:///home/julian/...'
    • org.gnome.desktop.background show-desktop-icons true
    • org.gnome.desktop.background picture-uri-dark 'file:///home/julian/Pictures/Wallpapers/image.webp'
    • org.gnome.shell development-tools true
    • org.gnome.shell disable-user-extensions false
    • org.gnome.desktop.a11y always-show-text-caret false
    • org.gnome.desktop.a11y always-show-universal-access-status false
    • org.gnome.desktop.a11y.applications screen-keyboard-enabled false
    • org.gnome.desktop.a11y.applications screen-magnifier-enabled false
    • org.gnome.desktop.a11y.applications screen-reader-enabled false
    • org.gnome.shell.extensions.dash-to-dock > XYZ
    • org.gnome.mutter center-new-windows
    • org.gnome.gnome-session auto-save-session false (restore open apps on login)

Interfaces

  • org.freedesktop.UPower: (https://crates.io/crates/upower_dbus)

  • net.hadess.PowerProfiles: power profiles (power save, balanced, performance)

    • active_profile (read/write)
    • PerformanceInhibited (read) (reason for performance being inhibited)
    • PerformanceDegraded (read) (reason for performance being degraded)
  • org.a11y.Bus: accessibility bus

    • isEnabled (read/write)
    • screenReaderEnabled (read/write)
  • org.bluez: bluetooth devices, devices stats

  • org.freedesktop.NetworkManager: network manager, wifi, connections

  • org.freedesktop.UDisks2: disks, partitions, filesystems

  • org.freedesktop.FileManager1: file manager (nautilus)

  • org.gnome.SettingsDaemon.*: settings daemon

    • org.gnome.SettingsDaemon.Power:
      • keyboard
        • brightness (r/w)
        • brightness-step-up
        • brightness-step-down
        • brightness-toggle
      • screen
        • brightness (r/w)
        • brightness-step-up
        • brightness-step-down
        • brightness-toggle

Gnome shell

Devtools

  • D-Spy: search for and inspect D-Bus services
    D-Spy example

Dbus sources

GSettings

Gnome mutter schema

Rust bindings

  • zbus a beatifully designed abstraction over D-Bus
  • zvariant a crate for working with D-Bus types