Compare commits
2 commits
main
...
brightness
| Author | SHA1 | Date | |
|---|---|---|---|
| bd5868593d | |||
| 620e1feac5 |
7 changed files with 278 additions and 42 deletions
172
Cargo.lock
generated
172
Cargo.lock
generated
|
|
@ -342,6 +342,21 @@ 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"
|
||||
|
|
@ -465,7 +480,7 @@ dependencies = [
|
|||
"js-sys",
|
||||
"num-traits",
|
||||
"wasm-bindgen",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -808,6 +823,12 @@ 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"
|
||||
|
|
@ -1094,7 +1115,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
|
||||
dependencies = [
|
||||
"rustix 1.1.4",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1188,7 +1209,7 @@ dependencies = [
|
|||
"log",
|
||||
"presser",
|
||||
"thiserror 1.0.69",
|
||||
"windows",
|
||||
"windows 0.58.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1300,7 +1321,7 @@ dependencies = [
|
|||
"js-sys",
|
||||
"log",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
"windows-core 0.58.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1589,6 +1610,15 @@ 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"
|
||||
|
|
@ -1705,7 +1735,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2295,7 +2325,7 @@ dependencies = [
|
|||
"libc",
|
||||
"redox_syscall 0.5.18",
|
||||
"smallvec",
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3460,6 +3490,7 @@ dependencies = [
|
|||
name = "wayland_panel"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"brightness",
|
||||
"chrono",
|
||||
"iced",
|
||||
"iced_layershell",
|
||||
|
|
@ -3622,8 +3653,8 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
"wgpu-types",
|
||||
"windows",
|
||||
"windows-core",
|
||||
"windows 0.58.0",
|
||||
"windows-core 0.58.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3669,23 +3700,69 @@ version = "0.58.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6"
|
||||
dependencies = [
|
||||
"windows-core",
|
||||
"windows-core 0.58.0",
|
||||
"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",
|
||||
"windows-interface",
|
||||
"windows-result",
|
||||
"windows-strings",
|
||||
"windows-implement 0.58.0",
|
||||
"windows-interface 0.58.0",
|
||||
"windows-result 0.2.0",
|
||||
"windows-strings 0.1.0",
|
||||
"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"
|
||||
|
|
@ -3697,6 +3774,17 @@ 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"
|
||||
|
|
@ -3708,12 +3796,39 @@ 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"
|
||||
|
|
@ -3723,16 +3838,34 @@ 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",
|
||||
"windows-result 0.2.0",
|
||||
"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"
|
||||
|
|
@ -3766,7 +3899,7 @@ version = "0.61.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3800,6 +3933,15 @@ 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"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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 }
|
||||
|
|
|
|||
15
src/app.rs
15
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<Box<dyn PanelWidget>>,
|
||||
|
|
@ -68,16 +68,7 @@ impl App {
|
|||
}
|
||||
|
||||
pub fn theme(&self, _id: iced::window::Id) -> iced::Theme {
|
||||
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)
|
||||
iced::Theme::GruvboxDark
|
||||
}
|
||||
|
||||
pub fn subscription(&self) -> iced::Subscription<Message> {
|
||||
|
|
|
|||
32
src/widgets/brightness.rs
Normal file
32
src/widgets/brightness.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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<BrightnessConnection>,
|
||||
}
|
||||
|
||||
struct BrightnessConnection {
|
||||
device: brightness::BrightnessDevice,
|
||||
}
|
||||
|
||||
impl PanelWidget for BrightnessWidget {
|
||||
fn update(&mut self, message: &Message) -> Task<Message> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn subscribe(&self) -> Subscription<Message> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn view(&self) -> Option<iced::Element<'_, Message>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
69
src/widgets/focused_window.rs
Normal file
69
src/widgets/focused_window.rs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
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<u64>,
|
||||
}
|
||||
|
||||
impl FocusedWindowWidget {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
focused_window: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PanelWidget for FocusedWindowWidget {
|
||||
fn update(&mut self, message: &Message) -> iced::Task<Message> {
|
||||
let Message::FocusChanged(i) = message else {
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
self.focused_window = *i;
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn subscribe(&self) -> Subscription<Message> {
|
||||
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::<niri_ipc::Event>(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()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
pub mod battery;
|
||||
pub mod brightness;
|
||||
pub mod clock;
|
||||
pub mod power_management;
|
||||
pub mod powerbutton;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ use iced::{
|
|||
widget::{Column, button, text},
|
||||
};
|
||||
use iced_layershell::reexport::{Anchor, NewLayerShellSettings};
|
||||
use ppd::{PpdProxyBlocking, Result};
|
||||
use zbus::blocking::Connection;
|
||||
use ppd::{PpdProxy, Result};
|
||||
use zbus::Connection;
|
||||
|
||||
use crate::widget::{Message, PanelWidget};
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ struct Connected<'a> {
|
|||
window: Option<iced::window::Id>,
|
||||
current_mode: Box<str>,
|
||||
modes: Box<[Box<str>]>,
|
||||
proxy: PpdProxyBlocking<'a>,
|
||||
proxy: PpdProxy<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -27,22 +27,21 @@ pub enum PowerManagement {
|
|||
|
||||
impl PowerManagementWidget<'_> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
connection: Self::establish_connection().ok(),
|
||||
}
|
||||
Self { connection: None }
|
||||
}
|
||||
|
||||
fn establish_connection<'a>() -> Result<Connected<'a>> {
|
||||
let conn = Connection::system().unwrap();
|
||||
let proxy = PpdProxyBlocking::new(&conn)?;
|
||||
async fn establish_connection<'a>() -> Result<Connected<'a>> {
|
||||
let conn = Connection::session().await?;
|
||||
let proxy = PpdProxy::new(&conn).await?;
|
||||
|
||||
let modes: Box<[Box<str>]> = proxy
|
||||
.profiles()?
|
||||
.profiles()
|
||||
.await?
|
||||
.iter()
|
||||
.map(|f| f.profile.clone().into_boxed_str())
|
||||
.collect();
|
||||
|
||||
let current_mode = proxy.active_profile()?.into_boxed_str();
|
||||
let current_mode = proxy.active_profile().await?.into_boxed_str();
|
||||
|
||||
Ok(Connected {
|
||||
current_mode,
|
||||
|
|
@ -55,13 +54,14 @@ impl PowerManagementWidget<'_> {
|
|||
|
||||
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();
|
||||
};
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue