This commit is contained in:
Jiří Maxmilián Stříbrný 2026-04-05 11:19:11 +02:00
parent 620e1feac5
commit bd5868593d
4 changed files with 185 additions and 150 deletions

172
Cargo.lock generated
View file

@ -342,6 +342,21 @@ dependencies = [
"piper", "piper",
] ]
[[package]]
name = "brightness"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96cbd6161e57989ea8b90d5adc0faf20eda8c0995a14cdbc63a8855ab7e4149e"
dependencies = [
"blocking",
"cfg-if",
"futures",
"itertools",
"thiserror 2.0.18",
"windows 0.61.3",
"zbus",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.20.2" version = "3.20.2"
@ -465,7 +480,7 @@ dependencies = [
"js-sys", "js-sys",
"num-traits", "num-traits",
"wasm-bindgen", "wasm-bindgen",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@ -808,6 +823,12 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76"
[[package]]
name = "either"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]] [[package]]
name = "endi" name = "endi"
version = "1.1.1" version = "1.1.1"
@ -1094,7 +1115,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
dependencies = [ dependencies = [
"rustix 1.1.4", "rustix 1.1.4",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@ -1188,7 +1209,7 @@ dependencies = [
"log", "log",
"presser", "presser",
"thiserror 1.0.69", "thiserror 1.0.69",
"windows", "windows 0.58.0",
] ]
[[package]] [[package]]
@ -1300,7 +1321,7 @@ dependencies = [
"js-sys", "js-sys",
"log", "log",
"wasm-bindgen", "wasm-bindgen",
"windows-core", "windows-core 0.58.0",
] ]
[[package]] [[package]]
@ -1589,6 +1610,15 @@ version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "itertools"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.17" version = "1.0.17"
@ -1705,7 +1735,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@ -2295,7 +2325,7 @@ dependencies = [
"libc", "libc",
"redox_syscall 0.5.18", "redox_syscall 0.5.18",
"smallvec", "smallvec",
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@ -3460,6 +3490,7 @@ dependencies = [
name = "wayland_panel" name = "wayland_panel"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"brightness",
"chrono", "chrono",
"iced", "iced",
"iced_layershell", "iced_layershell",
@ -3622,8 +3653,8 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
"wgpu-types", "wgpu-types",
"windows", "windows 0.58.0",
"windows-core", "windows-core 0.58.0",
] ]
[[package]] [[package]]
@ -3669,23 +3700,69 @@ version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6"
dependencies = [ dependencies = [
"windows-core", "windows-core 0.58.0",
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
[[package]]
name = "windows"
version = "0.61.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
dependencies = [
"windows-collections",
"windows-core 0.61.2",
"windows-future",
"windows-link 0.1.3",
"windows-numerics",
]
[[package]]
name = "windows-collections"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8"
dependencies = [
"windows-core 0.61.2",
]
[[package]] [[package]]
name = "windows-core" name = "windows-core"
version = "0.58.0" version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99"
dependencies = [ dependencies = [
"windows-implement", "windows-implement 0.58.0",
"windows-interface", "windows-interface 0.58.0",
"windows-result", "windows-result 0.2.0",
"windows-strings", "windows-strings 0.1.0",
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
[[package]]
name = "windows-core"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
dependencies = [
"windows-implement 0.60.2",
"windows-interface 0.59.3",
"windows-link 0.1.3",
"windows-result 0.3.4",
"windows-strings 0.4.2",
]
[[package]]
name = "windows-future"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
dependencies = [
"windows-core 0.61.2",
"windows-link 0.1.3",
"windows-threading",
]
[[package]] [[package]]
name = "windows-implement" name = "windows-implement"
version = "0.58.0" version = "0.58.0"
@ -3697,6 +3774,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "windows-implement"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "windows-interface" name = "windows-interface"
version = "0.58.0" version = "0.58.0"
@ -3708,12 +3796,39 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "windows-interface"
version = "0.59.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-link"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]] [[package]]
name = "windows-link" name = "windows-link"
version = "0.2.1" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-numerics"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
dependencies = [
"windows-core 0.61.2",
"windows-link 0.1.3",
]
[[package]] [[package]]
name = "windows-result" name = "windows-result"
version = "0.2.0" version = "0.2.0"
@ -3723,16 +3838,34 @@ dependencies = [
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
[[package]]
name = "windows-result"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
dependencies = [
"windows-link 0.1.3",
]
[[package]] [[package]]
name = "windows-strings" name = "windows-strings"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10"
dependencies = [ dependencies = [
"windows-result", "windows-result 0.2.0",
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
[[package]]
name = "windows-strings"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
dependencies = [
"windows-link 0.1.3",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.45.0" version = "0.45.0"
@ -3766,7 +3899,7 @@ version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [ dependencies = [
"windows-link", "windows-link 0.2.1",
] ]
[[package]] [[package]]
@ -3800,6 +3933,15 @@ dependencies = [
"windows_x86_64_msvc 0.52.6", "windows_x86_64_msvc 0.52.6",
] ]
[[package]]
name = "windows-threading"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6"
dependencies = [
"windows-link 0.1.3",
]
[[package]] [[package]]
name = "windows_aarch64_gnullvm" name = "windows_aarch64_gnullvm"
version = "0.42.2" version = "0.42.2"

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
brightness = "0.8.0"
chrono = "0.4.44" chrono = "0.4.44"
iced = { version = "0.14.0", default-features = false, features = ["wgpu", "wayland", "tokio"] } iced = { version = "0.14.0", default-features = false, features = ["wgpu", "wayland", "tokio"] }
iced_layershell = { version = "0.16.0", default-features = false } iced_layershell = { version = "0.16.0", default-features = false }

View file

@ -2,138 +2,31 @@ use iced::{
Subscription, Task, Subscription, Task,
widget::{Column, button, text}, widget::{Column, button, text},
}; };
use iced_layershell::reexport::{Anchor, NewLayerShellSettings}; use iced_layershell::reexport::{Anchor, NewLayerShellSettings, WithConnection};
use ppd::{PpdProxyBlocking, Result}; use zbus::Connection;
use zbus::blocking::Connection;
use crate::widget::{Message, PanelWidget}; use crate::widget::{Message, PanelWidget};
pub struct PowerManagementWidget<'a> { use brightness::Brightness;
connection: Option<Connected<'a>>,
struct BrightnessWidget {
conn: Option<BrightnessConnection>,
} }
struct Connected<'a> { struct BrightnessConnection {
window: Option<iced::window::Id>, device: brightness::BrightnessDevice,
current_mode: Box<str>,
modes: Box<[Box<str>]>,
proxy: PpdProxyBlocking<'a>,
} }
#[derive(Debug, Clone)] impl PanelWidget for BrightnessWidget {
pub enum PowerManagement { fn update(&mut self, message: &Message) -> Task<Message> {
ToggleWindow, todo!()
SetMode(String),
}
impl PowerManagementWidget<'_> {
pub fn new() -> Self {
Self {
connection: Self::establish_connection().ok(),
}
} }
fn establish_connection<'a>() -> Result<Connected<'a>> { fn subscribe(&self) -> Subscription<Message> {
let conn = Connection::system().unwrap(); todo!()
let proxy = PpdProxyBlocking::new(&conn)?; }
let modes: Box<[Box<str>]> = proxy fn view(&self) -> Option<iced::Element<'_, Message>> {
.profiles()? todo!()
.iter()
.map(|f| f.profile.clone().into_boxed_str())
.collect();
let current_mode = proxy.active_profile()?.into_boxed_str();
Ok(Connected {
current_mode,
modes,
proxy,
window: None,
})
}
}
impl PanelWidget for PowerManagementWidget<'_> {
fn update(&mut self, message: &crate::widget::Message) -> iced::Task<crate::widget::Message> {
let Message::PowerManagement(msg) = message else {
return Task::none();
};
let Some(conn) = &mut self.connection else {
return Task::none();
};
match msg {
PowerManagement::ToggleWindow => match conn.window {
Some(child) => {
conn.window = None;
Task::done(Message::RemoveWindow(child))
}
None => {
let id = iced::window::Id::unique();
conn.window = Some(id);
Task::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((220, 400)),
anchor: Anchor::Top,
layer: iced_layershell::reexport::Layer::Overlay,
keyboard_interactivity:
iced_layershell::reexport::KeyboardInteractivity::OnDemand,
exclusive_zone: None,
..Default::default()
},
id,
})
}
},
PowerManagement::SetMode(mode) => {
let _ = conn.proxy.set_active_profile(mode.into());
conn.current_mode = conn.proxy.active_profile().unwrap().into_boxed_str();
Task::none()
}
}
}
fn subscribe(&self) -> iced::Subscription<crate::widget::Message> {
Subscription::none()
}
fn view(&self) -> Option<iced::Element<'_, crate::widget::Message>> {
let Some(conn) = &self.connection else {
return None;
};
let output = button(text!("{}", conn.current_mode))
.on_press(Message::PowerManagement(PowerManagement::ToggleWindow))
.into();
Some(output)
}
fn render_window(
&self,
id: iced::window::Id,
) -> Option<iced::Element<'_, crate::widget::Message>> {
let Some(conn) = &self.connection else {
return None;
};
if conn.window != Some(id) {
return None;
}
let output = Column::with_children(conn.modes.iter().map(|f| {
button(text!("{}", f))
.on_press(Message::PowerManagement(PowerManagement::SetMode(
f.clone().into_string(),
)))
.into()
}))
.into();
Some(output)
} }
} }

View file

@ -3,8 +3,8 @@ use iced::{
widget::{Column, button, text}, widget::{Column, button, text},
}; };
use iced_layershell::reexport::{Anchor, NewLayerShellSettings}; use iced_layershell::reexport::{Anchor, NewLayerShellSettings};
use ppd::{PpdProxyBlocking, Result}; use ppd::{PpdProxy, Result};
use zbus::blocking::Connection; use zbus::Connection;
use crate::widget::{Message, PanelWidget}; use crate::widget::{Message, PanelWidget};
@ -16,7 +16,7 @@ struct Connected<'a> {
window: Option<iced::window::Id>, window: Option<iced::window::Id>,
current_mode: Box<str>, current_mode: Box<str>,
modes: Box<[Box<str>]>, modes: Box<[Box<str>]>,
proxy: PpdProxyBlocking<'a>, proxy: PpdProxy<'a>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -27,22 +27,21 @@ pub enum PowerManagement {
impl PowerManagementWidget<'_> { impl PowerManagementWidget<'_> {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self { connection: None }
connection: Self::establish_connection().ok(),
}
} }
fn establish_connection<'a>() -> Result<Connected<'a>> { async fn establish_connection<'a>() -> Result<Connected<'a>> {
let conn = Connection::system().unwrap(); let conn = Connection::session().await?;
let proxy = PpdProxyBlocking::new(&conn)?; let proxy = PpdProxy::new(&conn).await?;
let modes: Box<[Box<str>]> = proxy let modes: Box<[Box<str>]> = proxy
.profiles()? .profiles()
.await?
.iter() .iter()
.map(|f| f.profile.clone().into_boxed_str()) .map(|f| f.profile.clone().into_boxed_str())
.collect(); .collect();
let current_mode = proxy.active_profile()?.into_boxed_str(); let current_mode = proxy.active_profile().await?.into_boxed_str();
Ok(Connected { Ok(Connected {
current_mode, current_mode,
@ -90,8 +89,8 @@ impl PanelWidget for PowerManagementWidget<'_> {
PowerManagement::SetMode(mode) => { PowerManagement::SetMode(mode) => {
let _ = conn.proxy.set_active_profile(mode.into()); let _ = conn.proxy.set_active_profile(mode.into());
conn.current_mode = mode.clone().into_boxed_str();
conn.current_mode = conn.proxy.active_profile().unwrap().into_boxed_str();
Task::none() Task::none()
} }
} }