diff --git a/Cargo.lock b/Cargo.lock index c89da9d..4904171 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -342,21 +342,6 @@ dependencies = [ "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]] name = "bumpalo" version = "3.20.2" @@ -480,7 +465,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -823,12 +808,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" - [[package]] name = "endi" version = "1.1.1" @@ -1115,7 +1094,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" dependencies = [ "rustix 1.1.4", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -1209,7 +1188,7 @@ dependencies = [ "log", "presser", "thiserror 1.0.69", - "windows 0.58.0", + "windows", ] [[package]] @@ -1321,7 +1300,7 @@ dependencies = [ "js-sys", "log", "wasm-bindgen", - "windows-core 0.58.0", + "windows-core", ] [[package]] @@ -1610,15 +1589,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" -[[package]] -name = "itertools" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.17" @@ -1735,7 +1705,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" dependencies = [ "cfg-if", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -2325,7 +2295,7 @@ dependencies = [ "libc", "redox_syscall 0.5.18", "smallvec", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -3490,7 +3460,6 @@ dependencies = [ name = "wayland_panel" version = "0.1.0" dependencies = [ - "brightness", "chrono", "iced", "iced_layershell", @@ -3653,8 +3622,8 @@ dependencies = [ "wasm-bindgen", "web-sys", "wgpu-types", - "windows 0.58.0", - "windows-core 0.58.0", + "windows", + "windows-core", ] [[package]] @@ -3700,69 +3669,23 @@ version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" dependencies = [ - "windows-core 0.58.0", + "windows-core", "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]] name = "windows-core" version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" dependencies = [ - "windows-implement 0.58.0", - "windows-interface 0.58.0", - "windows-result 0.2.0", - "windows-strings 0.1.0", + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", "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]] name = "windows-implement" version = "0.58.0" @@ -3774,17 +3697,6 @@ dependencies = [ "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]] name = "windows-interface" version = "0.58.0" @@ -3796,39 +3708,12 @@ dependencies = [ "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]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "windows-result" version = "0.2.0" @@ -3838,34 +3723,16 @@ dependencies = [ "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]] name = "windows-strings" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "windows-result 0.2.0", + "windows-result", "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]] name = "windows-sys" version = "0.45.0" @@ -3899,7 +3766,7 @@ version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -3933,15 +3800,6 @@ dependencies = [ "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]] name = "windows_aarch64_gnullvm" version = "0.42.2" diff --git a/Cargo.toml b/Cargo.toml index b97f5a5..971025c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] -brightness = "0.8.0" chrono = "0.4.44" iced = { version = "0.14.0", default-features = false, features = ["wgpu", "wayland", "tokio"] } iced_layershell = { version = "0.16.0", default-features = false } diff --git a/src/app.rs b/src/app.rs index 0e03d92..f9d8e65 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,10 +5,10 @@ use crate::widgets::power_management::PowerManagementWidget; use crate::widgets::powerbutton::ShutdownWidget; use crate::widgets::spacer::Spacer; -use iced::Color; -use iced::Element; use iced::Subscription; use iced::Task; +use iced::{Color, Theme}; +use iced::{Element, color}; pub struct App { widgets: Vec>, @@ -68,7 +68,16 @@ impl App { } pub fn theme(&self, _id: iced::window::Id) -> iced::Theme { - iced::Theme::GruvboxDark + let palette = iced::theme::Palette { + background: color!(0x282828), // dark BG_0 + text: color!(0xfbf1c7), // dark FG0_29 + primary: color!(0x8A493B), // dark BLUE_4 + success: color!(0x98971a), // dark GREEN_2 + warning: color!(0xd79921), // dark YELLOW_3 + danger: color!(0xcc241d), // dark RED_1 + }; + + Theme::custom("Better gruvbox", palette) } pub fn subscription(&self) -> iced::Subscription { diff --git a/src/widgets/brightness.rs b/src/widgets/brightness.rs deleted file mode 100644 index 9aaa171..0000000 --- a/src/widgets/brightness.rs +++ /dev/null @@ -1,32 +0,0 @@ -use iced::{ - Subscription, Task, - widget::{Column, button, text}, -}; -use iced_layershell::reexport::{Anchor, NewLayerShellSettings, WithConnection}; -use zbus::Connection; - -use crate::widget::{Message, PanelWidget}; - -use brightness::Brightness; - -struct BrightnessWidget { - conn: Option, -} - -struct BrightnessConnection { - device: brightness::BrightnessDevice, -} - -impl PanelWidget for BrightnessWidget { - fn update(&mut self, message: &Message) -> Task { - todo!() - } - - fn subscribe(&self) -> Subscription { - todo!() - } - - fn view(&self) -> Option> { - todo!() - } -} diff --git a/src/widgets/focused_window.rs b/src/widgets/focused_window.rs deleted file mode 100644 index e4ffa18..0000000 --- a/src/widgets/focused_window.rs +++ /dev/null @@ -1,69 +0,0 @@ -use iced::{Subscription, Task, futures::SinkExt}; -use niri_ipc::{Event, Request, Response, Window, socket::Socket}; - -use crate::widget::{Message, PanelWidget}; - -pub struct FocusedWindowWidget { - focused_window: Option, -} - -impl FocusedWindowWidget { - pub fn new() -> Self { - Self { - focused_window: None, - } - } -} - -impl PanelWidget for FocusedWindowWidget { - fn update(&mut self, message: &Message) -> iced::Task { - let Message::FocusChanged(i) = message else { - return Task::none(); - }; - - self.focused_window = *i; - Task::none() - } - - fn subscribe(&self) -> Subscription { - Subscription::run(|| { - iced::stream::channel(16, async move |mut tx| { - use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; - use tokio::net::UnixStream; - - let socket_path = std::env::var("NIRI_SOCKET").unwrap(); - let mut stream = UnixStream::connect(socket_path).await.unwrap(); - - // Send the EventStream request as newline-delimited JSON - let request = serde_json::to_string(&niri_ipc::Request::EventStream).unwrap(); - stream - .write_all(format!("{request}\n").as_bytes()) - .await - .unwrap(); - - let mut reader = BufReader::new(stream); - let mut line = String::new(); - - loop { - line.clear(); - reader.read_line(&mut line).await.unwrap(); - - // First line back is the Reply, subsequent lines are Events - if let Ok(event) = serde_json::from_str::(line.trim()) - && let niri_ipc::Event::WindowFocusChanged { id } = event - { - let _ = tx.send(Message::FocusChanged(id)).await; - } - } - }) - }) - } - fn view(&self, _id: iced::window::Id) -> iced::Element<'_, Message> { - iced::widget::text!( - "{}", - self.focused_window - .map_or("None".into(), |f| format!("{}", f)) - ) - .into() - } -} diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 4fb01c4..15c857e 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -1,5 +1,4 @@ pub mod battery; -pub mod brightness; pub mod clock; pub mod power_management; pub mod powerbutton; diff --git a/src/widgets/power_management.rs b/src/widgets/power_management.rs index 81b5e58..889c3a2 100644 --- a/src/widgets/power_management.rs +++ b/src/widgets/power_management.rs @@ -3,8 +3,8 @@ use iced::{ widget::{Column, button, text}, }; use iced_layershell::reexport::{Anchor, NewLayerShellSettings}; -use ppd::{PpdProxy, Result}; -use zbus::Connection; +use ppd::{PpdProxyBlocking, Result}; +use zbus::blocking::Connection; use crate::widget::{Message, PanelWidget}; @@ -16,7 +16,7 @@ struct Connected<'a> { window: Option, current_mode: Box, modes: Box<[Box]>, - proxy: PpdProxy<'a>, + proxy: PpdProxyBlocking<'a>, } #[derive(Debug, Clone)] @@ -27,21 +27,22 @@ pub enum PowerManagement { impl PowerManagementWidget<'_> { pub fn new() -> Self { - Self { connection: None } + Self { + connection: Self::establish_connection().ok(), + } } - async fn establish_connection<'a>() -> Result> { - let conn = Connection::session().await?; - let proxy = PpdProxy::new(&conn).await?; + fn establish_connection<'a>() -> Result> { + let conn = Connection::system().unwrap(); + let proxy = PpdProxyBlocking::new(&conn)?; let modes: Box<[Box]> = proxy - .profiles() - .await? + .profiles()? .iter() .map(|f| f.profile.clone().into_boxed_str()) .collect(); - let current_mode = proxy.active_profile().await?.into_boxed_str(); + let current_mode = proxy.active_profile()?.into_boxed_str(); Ok(Connected { current_mode, @@ -54,14 +55,13 @@ impl PowerManagementWidget<'_> { impl PanelWidget for PowerManagementWidget<'_> { fn update(&mut self, message: &crate::widget::Message) -> iced::Task { - let Message::PowerManagement(msg) = message else { - return Task::none(); - }; - let Some(conn) = &mut self.connection else { return Task::none(); }; + let Message::PowerManagement(msg) = message else { + return Task::none(); + }; match msg { PowerManagement::ToggleWindow => match conn.window { Some(child) => { @@ -89,8 +89,8 @@ impl PanelWidget for PowerManagementWidget<'_> { PowerManagement::SetMode(mode) => { 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() } }