Start work on graphics applet
This commit is contained in:
parent
fc8e6e4d4d
commit
e03225384b
5 changed files with 142 additions and 1 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
|
@ -218,6 +218,17 @@ dependencies = [
|
|||
"cache-padded",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cosmic-applet-graphics"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gtk4",
|
||||
"once_cell",
|
||||
"relm4-macros",
|
||||
"tokio",
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cosmic-applet-network"
|
||||
version = "0.1.0"
|
||||
|
|
|
|||
|
|
@ -29,4 +29,4 @@ zvariant = "3"
|
|||
layer-shell = ["gdk4-wayland", "libcosmic/layer-shell"]
|
||||
|
||||
[workspace]
|
||||
members = ["applets/cosmic-applet-network"]
|
||||
members = ["applets/cosmic-applet-graphics", "applets/cosmic-applet-network"]
|
||||
|
|
|
|||
13
applets/cosmic-applet-graphics/Cargo.toml
Normal file
13
applets/cosmic-applet-graphics/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "cosmic-applet-graphics"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
gtk4 = "0.4.6"
|
||||
once_cell = "1.9.0"
|
||||
relm4-macros = "0.4.2"
|
||||
tokio = { version = "1.16.1", features = ["full"] }
|
||||
zbus = "2.1.1"
|
||||
75
applets/cosmic-applet-graphics/src/dbus.rs
Normal file
75
applets/cosmic-applet-graphics/src/dbus.rs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
//! # DBus interface proxy for: `com.system76.PowerDaemon`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
||||
//! Source: `Interface '/com/system76/PowerDaemon' from service 'com.system76.PowerDaemon' on system 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::IntrospectableProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(interface = "com.system76.PowerDaemon")]
|
||||
trait PowerDaemon {
|
||||
/// Balanced method
|
||||
fn balanced(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Battery method
|
||||
fn battery(&self) -> zbus::Result<()>;
|
||||
|
||||
/// GetChargeProfiles method
|
||||
fn get_charge_profiles(
|
||||
&self,
|
||||
) -> zbus::Result<Vec<std::collections::HashMap<String, zbus::zvariant::OwnedValue>>>;
|
||||
|
||||
/// GetChargeThresholds method
|
||||
fn get_charge_thresholds(&self) -> zbus::Result<(u8, u8)>;
|
||||
|
||||
/// GetDefaultGraphics method
|
||||
fn get_default_graphics(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetExternalDisplaysRequireDGPU method
|
||||
fn get_external_displays_require_dgpu(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetGraphics method
|
||||
fn get_graphics(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetGraphicsPower method
|
||||
fn get_graphics_power(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// GetProfile method
|
||||
fn get_profile(&self) -> zbus::Result<String>;
|
||||
|
||||
/// GetSwitchable method
|
||||
fn get_switchable(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Performance method
|
||||
fn performance(&self) -> zbus::Result<()>;
|
||||
|
||||
/// SetChargeThresholds method
|
||||
fn set_charge_thresholds(&self, thresholds: &(u8, u8)) -> zbus::Result<()>;
|
||||
|
||||
/// SetGraphics method
|
||||
fn set_graphics(&self, vendor: &str) -> zbus::Result<()>;
|
||||
|
||||
/// SetGraphicsPower method
|
||||
fn set_graphics_power(&self, power: bool) -> zbus::Result<()>;
|
||||
|
||||
/// HotPlugDetect signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn hot_plug_detect(&self, port: u64) -> zbus::Result<()>;
|
||||
|
||||
/// PowerProfileSwitch signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn power_profile_switch(&self, profile: &str) -> zbus::Result<()>;
|
||||
}
|
||||
42
applets/cosmic-applet-graphics/src/main.rs
Normal file
42
applets/cosmic-applet-graphics/src/main.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
#[macro_use]
|
||||
extern crate relm4_macros;
|
||||
|
||||
pub mod dbus;
|
||||
use gtk4::{gio::ApplicationFlags, prelude::*, Orientation};
|
||||
use once_cell::sync::Lazy;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
|
||||
|
||||
fn main() {
|
||||
let application = gtk4::Application::new(
|
||||
Some("com.system76.cosmic.applets.graphics"),
|
||||
ApplicationFlags::default(),
|
||||
);
|
||||
application.connect_activate(build_ui);
|
||||
application.run();
|
||||
}
|
||||
|
||||
fn build_ui(application: >k4::Application) {
|
||||
let window = gtk4::ApplicationWindow::builder()
|
||||
.application(application)
|
||||
.title("COSMIC Graphics Applet")
|
||||
.default_width(400)
|
||||
.default_height(300)
|
||||
.build();
|
||||
|
||||
view! {
|
||||
main_box = gtk4::Box {
|
||||
set_orientation: Orientation::Vertical,
|
||||
set_spacing: 10,
|
||||
set_margin_top: 20,
|
||||
set_margin_bottom: 20,
|
||||
set_margin_start: 24,
|
||||
set_margin_end: 24
|
||||
}
|
||||
}
|
||||
|
||||
window.show();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue