Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/AshellCustomIcon-Regular.otf
Binary file not shown.
3 changes: 3 additions & 0 deletions assets/key_backlight_off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions assets/key_backlight_on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion i18n/de-DE/ashell.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ settings-power-status-full = Voll
## Einstellungen — Kein Ruhezustand
settings-idle-inhibitor = Kein Ruhezustand

## Einstellungen – Tastaturbeleuchtung
settings-kbd-backlight = Tastatur

## Einstellungen — tooltips
settings-tooltip-empty = Ziemlich leer hier
settings-tooltip-empty-audio = Kein aktives Audio-Gerät
Expand Down Expand Up @@ -154,4 +157,4 @@ system-info-temperature = Temperatur
system-info-disk-usage = Festplattennutzung { $mount }
system-info-ip-address = IP-Adresse
system-info-download-speed = Download
system-info-upload-speed = Upload
system-info-upload-speed = Upload
3 changes: 3 additions & 0 deletions i18n/en-US/ashell.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ settings-power-status-full = Full
## Settings — idle inhibitor
settings-idle-inhibitor = Idle Inhibitor

## Settings - keyboard backlight
settings-kbd-backlight = Keyboard

## Settings — tooltips
settings-tooltip-empty = Nothing to show
settings-tooltip-empty-audio = No active audio device
Expand Down
3 changes: 3 additions & 0 deletions i18n/fr-FR/ashell.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ settings-power-status-unknown = Inconnu
## Paramètres — inhibiteur de veille
settings-idle-inhibitor = Inhibiteur de veille

## Paramètres - rétroéclairage du clavier
settings-kbd-backlight = Clavier

## Paramètres — infobulles
settings-tooltip-empty = Rien à afficher
settings-tooltip-empty-audio = Aucun périphérique audio actif
Expand Down
12 changes: 9 additions & 3 deletions src/components/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ pub enum StaticIcon {
KeyboardBatteryLow,
KeyboardBatteryAlert,
KeyboardBatteryCharging,
KeyboardBacklightOn,
KeyboardBacklightOff,
MouseBatteryFull,
MouseBatteryMedium,
MouseBatteryLow,
Expand Down Expand Up @@ -239,6 +241,8 @@ impl StaticIcon {
StaticIcon::HeadphoneBatteryLow => "\u{c000c}",
StaticIcon::HeadphoneBatteryAlert => "\u{c000d}",
StaticIcon::HeadphoneBatteryCharging => "\u{c000e}",
StaticIcon::KeyboardBacklightOn => "\u{c000f}",
StaticIcon::KeyboardBacklightOff => "\u{c0010}",
StaticIcon::GamepadBatteryFull => "\u{f074d}",
StaticIcon::GamepadBatteryMedium => "\u{f074f}",
StaticIcon::GamepadBatteryLow => "\u{f074e}",
Expand All @@ -251,7 +255,7 @@ impl StaticIcon {
}
}

fn is_custom_battery_icon(&self) -> bool {
fn is_custom_icon(&self) -> bool {
matches!(
self,
StaticIcon::KeyboardBatteryFull
Expand All @@ -269,19 +273,21 @@ impl StaticIcon {
| StaticIcon::HeadphoneBatteryLow
| StaticIcon::HeadphoneBatteryAlert
| StaticIcon::HeadphoneBatteryCharging
| StaticIcon::KeyboardBacklightOn
| StaticIcon::KeyboardBacklightOff
)
}

fn get_font(&self) -> &'static str {
if self.is_custom_battery_icon() {
if self.is_custom_icon() {
"Ashell Custom Icon"
} else {
"Symbols Nerd Font"
}
}

fn get_font_mono(&self) -> &'static str {
if self.is_custom_battery_icon() {
if self.is_custom_icon() {
"Ashell Custom Icon"
} else {
"Symbols Nerd Font Mono"
Expand Down
13 changes: 13 additions & 0 deletions src/modules/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub enum SubMenu {
Wifi,
Vpn,
Bluetooth,
KbdBacklight,
}

impl Settings {
Expand Down Expand Up @@ -267,6 +268,10 @@ impl Settings {
self.toggle_submenu_to(SubMenu::PeripheralMenu);
Action::None
}
power::Action::ToggleKbdBacklightMenu => {
self.toggle_submenu_to(SubMenu::KbdBacklight);
Action::None
}
power::Action::Command(task) => Action::Command(task.map(Message::Power)),
},
Message::Audio(msg) => match self.audio.update(msg) {
Expand Down Expand Up @@ -662,6 +667,14 @@ impl Settings {
self.power
.charge_limit_quick_setting_button()
.map(|(button, _)| (button.map(Message::Power), None)),
self.power
.kbd_backlight_quick_setting_button(self.sub_menu)
.map(|(button, submenu)| {
(
button.map(Message::Power),
submenu.map(|(expanded, e)| (expanded, e.map(Message::Power))),
)
}),
]
.into_iter()
.flatten()
Expand Down
88 changes: 87 additions & 1 deletion src/modules/settings/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ use crate::{
quick_setting_button, styled_button,
},
config::{PeripheralIndicators, SettingsFormat},
modules::settings::SubMenu,
services::{
ReadOnlyService, Service, ServiceEvent,
upower::{BatteryData, BatteryStatus, PowerProfile, UPowerCommand, UPowerService},
},
t,
theme::use_theme,
utils::{self, IndicatorState, format_duration},
utils::{self, IndicatorState, format_duration, remote_value},
};
use iced::{
Alignment, Element, Length, Subscription, Task, Theme,
alignment::Vertical,
slider,
widget::{Column, Row, column, container, row, text},
};

Expand Down Expand Up @@ -51,17 +53,21 @@ pub enum Message {
TogglePeripheralMenu,
TogglePowerProfile,
ToggleChargeLimit,
ToggleKbdBacklight,
ToggleKbdBacklightMenu,
Suspend,
Hibernate,
Reboot,
Shutdown,
Logout,
KbdBacklightChanged(remote_value::Message<i32>),
ConfigReloaded(PowerSettingsConfig),
}

pub enum Action {
None,
TogglePeripheralMenu,
ToggleKbdBacklightMenu,
Command(Task<Message>),
}

Expand Down Expand Up @@ -137,6 +143,24 @@ impl PowerSettings {
ServiceEvent::Error(_) => Action::None,
},
Message::TogglePeripheralMenu => Action::TogglePeripheralMenu,
Message::ToggleKbdBacklight => {
if let Some(service) = self.service.as_mut()
&& let Some(backlight) = service.kbd_backlight.as_mut()
{
let new_value = if backlight.current.value() == 0 {
backlight.retained.unwrap_or(backlight.max)
} else {
backlight.retained = Some(backlight.current.value());
0
};
self.update(Message::KbdBacklightChanged(
remote_value::Message::Request(new_value),
))
} else {
Action::None
}
}
Message::ToggleKbdBacklightMenu => Action::ToggleKbdBacklightMenu,
Message::TogglePowerProfile => match self.service.as_mut() {
Some(service) => Action::Command(
service
Expand Down Expand Up @@ -175,6 +199,24 @@ impl PowerSettings {
utils::launcher::logout(&self.config.logout_cmd);
Action::None
}
Message::KbdBacklightChanged(message) => {
if let Some(service) = self.service.as_mut() {
// Send
if let Some(value) = message.value() {
service.set_kbd_backlight(value);
}
// Drive UI updates
if let Some(kbd_backlight) = service.kbd_backlight.as_mut() {
return Action::Command(
kbd_backlight
.current
.update(message)
.map(Message::KbdBacklightChanged),
);
}
};
Action::None
}
Message::ConfigReloaded(config) => {
self.config = config;
Action::None
Expand Down Expand Up @@ -529,6 +571,50 @@ impl PowerSettings {
})
}

#[allow(clippy::type_complexity)]
pub fn kbd_backlight_quick_setting_button<'a>(
&'a self,
current_submenu: Option<SubMenu>,
) -> Option<(Element<'a, Message>, Option<(bool, Element<'a, Message>)>)> {
let kbd_backlight = self.service.as_ref()?.kbd_backlight.as_ref()?;
let is_on = kbd_backlight.current.value() != 0;
Some((
quick_setting_button(
if is_on {
StaticIcon::KeyboardBacklightOn
} else {
StaticIcon::KeyboardBacklightOff
},
t!("settings-kbd-backlight"),
None,
is_on,
Message::ToggleKbdBacklight,
None,
Some((
SubMenu::KbdBacklight,
current_submenu,
Message::ToggleKbdBacklightMenu,
)),
),
Some((
current_submenu == Some(SubMenu::KbdBacklight),
container(
Element::<'a, remote_value::Message<i32>>::from(
slider(
0..=kbd_backlight.max,
kbd_backlight.current.value(),
remote_value::Message::Request,
)
.on_release(remote_value::Message::Timeout),
)
.map(Message::KbdBacklightChanged),
)
.padding([use_theme(|t| t.space.xs), 0.0])
.into(),
)),
))
}

pub fn subscription(&self) -> Subscription<Message> {
UPowerService::subscribe().map(Message::Event)
}
Expand Down
16 changes: 16 additions & 0 deletions src/services/upower/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,19 @@ pub trait PowerProfiles {
#[zbus(property)]
fn set_active_profile(&self, profile: &str) -> zbus::Result<()>;
}

#[proxy(
default_service = "org.freedesktop.UPower",
default_path = "/org/freedesktop/UPower/KbdBacklight",
interface = "org.freedesktop.UPower.KbdBacklight"
)]
pub trait KbdBacklight {
fn get_max_brightness(&self) -> zbus::Result<i32>;

fn get_brightness(&self) -> zbus::Result<i32>;

fn set_brightness(&self, value: i32) -> zbus::Result<()>;

#[zbus(signal)]
fn brightness_changed(&self, value: i32) -> zbus::Result<()>;
}
Loading