diff --git a/Cargo.lock b/Cargo.lock index d5af8c82..79dab522 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1324,7 +1324,7 @@ dependencies = [ [[package]] name = "cosmic-settings-subscriptions" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-settings-subscriptions#3a4e58559149fd5bf4d1d2c93229b2920ce03695" +source = "git+https://github.com/pop-os/cosmic-settings-subscriptions#21cc79434fa24f1fbd6dc4e8d394aa51d5ee12d9" dependencies = [ "futures", "iced_futures", @@ -1511,7 +1511,7 @@ version = "0.19.0" source = "git+https://github.com/gfx-rs/wgpu?rev=20fda69#20fda698341efbdc870b8027d6d49f5bf3f36109" dependencies = [ "bitflags 2.5.0", - "libloading 0.7.4", + "libloading 0.8.3", "winapi", ] @@ -1774,7 +1774,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading 0.7.4", + "libloading 0.8.3", ] [[package]] @@ -2608,7 +2608,7 @@ dependencies = [ "bitflags 2.5.0", "com", "libc", - "libloading 0.7.4", + "libloading 0.8.3", "thiserror", "widestring", "winapi", @@ -6476,7 +6476,7 @@ dependencies = [ "js-sys", "log", "naga", - "parking_lot 0.11.2", + "parking_lot 0.12.3", "profiling", "raw-window-handle", "smallvec", @@ -6503,7 +6503,7 @@ dependencies = [ "log", "naga", "once_cell", - "parking_lot 0.11.2", + "parking_lot 0.12.3", "profiling", "raw-window-handle", "rustc-hash", @@ -6537,13 +6537,13 @@ dependencies = [ "js-sys", "khronos-egl", "libc", - "libloading 0.7.4", + "libloading 0.8.3", "log", "metal", "naga", "objc", "once_cell", - "parking_lot 0.11.2", + "parking_lot 0.12.3", "profiling", "range-alloc", "raw-window-handle", diff --git a/cosmic-applet-battery/src/app.rs b/cosmic-applet-battery/src/app.rs index 1ca3ace9..1fa19dde 100644 --- a/cosmic-applet-battery/src/app.rs +++ b/cosmic-applet-battery/src/app.rs @@ -80,7 +80,8 @@ struct CosmicBatteryApplet { on_battery: bool, gpus: HashMap, time_remaining: Duration, - kbd_brightness: Option, + max_kbd_brightness: Option, + kbd_brightness: Option, max_screen_brightness: i32, screen_brightness: i32, popup: Option, @@ -163,8 +164,7 @@ enum Message { SetKbdBrightness(i32), SetScreenBrightness(i32), SetChargingLimit(chain::Toggler, bool), - UpdateKbdBrightness(Option), - InitKbdBacklight(UnboundedSender), + KeyboardBacklight(KeyboardBacklightUpdate), GpuOn(PathBuf, String, Option>), GpuOff(PathBuf), ToggleGpuApps(PathBuf), @@ -222,7 +222,6 @@ impl cosmic::Application for CosmicBatteryApplet { match message { Message::Frame(now) => self.timeline.now(now), Message::SetKbdBrightness(brightness) => { - let brightness = (brightness as f64 / 100.0).clamp(0., 1.); self.kbd_brightness = Some(brightness); if let Some(tx) = &self.kbd_sender { let _ = tx.send(KeyboardBacklightRequest::Set(brightness)); @@ -282,12 +281,17 @@ impl cosmic::Application for CosmicBatteryApplet { self.update_battery(percent, on_battery); self.time_remaining = Duration::from_secs(time_to_empty as u64); } - Message::UpdateKbdBrightness(b) => { - self.kbd_brightness = b; - } - Message::InitKbdBacklight(tx) => { - self.kbd_sender = Some(tx); - } + Message::KeyboardBacklight(event) => match event { + KeyboardBacklightUpdate::Sender(tx) => { + self.kbd_sender = Some(tx); + } + KeyboardBacklightUpdate::MaxBrightness(max_brightness) => { + self.max_kbd_brightness = Some(max_brightness); + } + KeyboardBacklightUpdate::Brightness(brightness) => { + self.kbd_brightness = Some(brightness); + } + }, Message::InitProfile(tx, profile) => { self.power_profile_sender.replace(tx); self.power_profile = profile; @@ -543,27 +547,32 @@ impl cosmic::Application for CosmicBatteryApplet { .into(), ]; - if let Some(kbd_brightness) = self.kbd_brightness { - content.push( - padded_control( - row![ - icon::from_name("keyboard-brightness-symbolic") - .size(24) - .symbolic(true), - slider( - 0..=100, - (kbd_brightness * 100.0) as i32, - Message::SetKbdBrightness - ), - text(format!("{:.0}%", kbd_brightness * 100.0)) + if let Some(max_kbd_brightness) = self.max_kbd_brightness { + if let Some(kbd_brightness) = self.kbd_brightness { + content.push( + padded_control( + row![ + icon::from_name("keyboard-brightness-symbolic") + .size(24) + .symbolic(true), + slider( + 0..=max_kbd_brightness, + kbd_brightness, + Message::SetKbdBrightness + ), + text(format!( + "{:.0}%", + 100. * kbd_brightness as f64 / max_kbd_brightness as f64 + )) .size(16) .width(Length::Fixed(40.0)) .horizontal_alignment(Horizontal::Right) - ] - .spacing(12), - ) - .into(), - ); + ] + .spacing(12), + ) + .into(), + ); + } } content.push(padded_control(divider::horizontal::default()).into()); @@ -684,10 +693,7 @@ impl cosmic::Application for CosmicBatteryApplet { time_to_empty, }, ), - kbd_backlight_subscription(0).map(|event| match event { - KeyboardBacklightUpdate::Brightness(b) => Message::UpdateKbdBrightness(b), - KeyboardBacklightUpdate::Sender(tx) => Message::InitKbdBacklight(tx), - }), + kbd_backlight_subscription(0).map(Message::KeyboardBacklight), power_profile_subscription(0).map(|event| match event { PowerProfileUpdate::Update { profile } => Message::Profile(profile), PowerProfileUpdate::Init(tx, p) => Message::InitProfile(p, tx),