From 96c44ea337bd01d6772c19940d934af960811eb5 Mon Sep 17 00:00:00 2001 From: Ariazonaa <96840802+Ariazonaa@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:24:17 +0100 Subject: [PATCH 1/3] feat(gui): pick a custom keyboard lighting color A tenth control after the presets opens gpui-kit's color picker, so the keys can take any RGB color the config already stores. A palette pick or a hex commit is written at once; a slider drag is written once, when the picker closes. --- crates/openlogi-desktop/src/app.rs | 2 +- .../src/features/lighting/keyboard_rgb.rs | 140 ++++++++++++- .../features/lighting/keyboard_rgb/tests.rs | 184 ++++++++++++++++++ crates/openlogi-ui/locales/be.toml | 1 + crates/openlogi-ui/locales/cs.toml | 1 + crates/openlogi-ui/locales/da.toml | 1 + crates/openlogi-ui/locales/de.toml | 1 + crates/openlogi-ui/locales/el.toml | 1 + crates/openlogi-ui/locales/en.toml | 1 + crates/openlogi-ui/locales/es.toml | 1 + crates/openlogi-ui/locales/fi.toml | 1 + crates/openlogi-ui/locales/fr.toml | 1 + crates/openlogi-ui/locales/it.toml | 1 + crates/openlogi-ui/locales/ja.toml | 1 + crates/openlogi-ui/locales/ko.toml | 1 + crates/openlogi-ui/locales/nb.toml | 1 + crates/openlogi-ui/locales/nl.toml | 1 + crates/openlogi-ui/locales/pl.toml | 1 + crates/openlogi-ui/locales/pt-BR.toml | 1 + crates/openlogi-ui/locales/pt-PT.toml | 1 + crates/openlogi-ui/locales/ru.toml | 1 + crates/openlogi-ui/locales/sv.toml | 1 + crates/openlogi-ui/locales/tr.toml | 1 + crates/openlogi-ui/locales/uk.toml | 1 + crates/openlogi-ui/locales/zh-CN.toml | 1 + crates/openlogi-ui/locales/zh-HK.toml | 1 + crates/openlogi-ui/locales/zh-TW.toml | 1 + 27 files changed, 344 insertions(+), 6 deletions(-) create mode 100644 crates/openlogi-desktop/src/features/lighting/keyboard_rgb/tests.rs diff --git a/crates/openlogi-desktop/src/app.rs b/crates/openlogi-desktop/src/app.rs index 4da8bacab1..d44505aa96 100644 --- a/crates/openlogi-desktop/src/app.rs +++ b/crates/openlogi-desktop/src/app.rs @@ -330,7 +330,7 @@ impl AppView { let dpi_panel = cx.new(DpiPanel::new); let smartshift_panel = cx.new(SmartShiftPanel::new); let momentum_panel = cx.new(|cx| MomentumPanel::new(MomentumScope::SelectedDevice, cx)); - let lighting_panel = cx.new(LightingPanel::new); + let lighting_panel = cx.new(|cx| LightingPanel::new(window, cx)); let camera_preview = cx.new(CameraPreview::new); let camera_controls = cx.new(CameraControlsPanel::new); let light_panel = cx.new(LightPanel::new); diff --git a/crates/openlogi-desktop/src/features/lighting/keyboard_rgb.rs b/crates/openlogi-desktop/src/features/lighting/keyboard_rgb.rs index c2514375c2..c85fd5f377 100644 --- a/crates/openlogi-desktop/src/features/lighting/keyboard_rgb.rs +++ b/crates/openlogi-desktop/src/features/lighting/keyboard_rgb.rs @@ -7,11 +7,15 @@ use crate::ui::theme::FocusRingStyle as _; use gpui::{ - Context, InteractiveElement, IntoElement, ParentElement, Render, Role, - StatefulInteractiveElement as _, Styled, Subscription, Toggled, Window, div, px, rgb, + App, AppContext as _, Context, Entity, Hsla, InteractiveElement, IntoElement, ParentElement, + Render, Rgba, Role, StatefulInteractiveElement as _, Styled, Subscription, Toggled, Window, + div, prelude::FluentBuilder as _, px, rgb, }; use gpui_kit::base::Button as BaseButton; -use gpui_kit::component::{Selectable as _, h_flex, slider::Slider, v_flex}; +use gpui_kit::component::color_picker::{ColorPicker, ColorPickerEvent, ColorPickerState}; +use gpui_kit::component::{ + IconName, Selectable as _, Sizable as _, Size, h_flex, slider::Slider, v_flex, +}; use openlogi_core::color::Rgb; use openlogi_core::config::Lighting; @@ -41,13 +45,57 @@ const PALETTE: &[Rgb] = &[ Rgb::WHITE, ]; +/// The color the custom control stands for: the current color when the +/// lighting is on and it is none of the presets. +fn custom_color(current: &Lighting) -> Option { + (current.enabled && !PALETTE.contains(¤t.color)).then_some(current.color) +} + +/// A picker color as the 8-bit RGB the keyboard takes. The keys have no +/// alpha, so a translucent pick lights them at full color. +fn rgb_of(color: Hsla) -> Rgb { + #[expect( + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + reason = "clamped to 0.0..=255.0 before the cast" + )] + fn channel(value: f32) -> u8 { + (value.clamp(0., 1.) * 255.).round() as u8 + } + let color = Rgba::from(color); + Rgb::new(channel(color.r), channel(color.g), channel(color.b)) +} + +/// Light the keys in `color`, unless they already are. +fn commit_color(color: Rgb, cx: &mut App) { + let unchanged = AppState::try_read(cx).is_some_and(|state| { + let lighting = state.lighting(); + lighting.enabled && lighting.color == color + }); + if unchanged { + return; + } + AppState::apply(cx, |state| { + let mut next = state.lighting(); + next.enabled = true; + next.color = color; + state.commit_lighting(next) + }); +} + pub struct LightingPanel { brightness: CommitSlider, + /// The picker behind the custom-color control. + picker: Entity, + /// The color a slider drag left in the open picker. It is written when + /// the picker closes, so a drag does not stream writes to the keyboard. + pending: Option, _state_obs: Subscription, + _picker_subscriptions: [Subscription; 2], } impl LightingPanel { - pub fn new(cx: &mut Context) -> Self { + pub fn new(window: &mut Window, cx: &mut Context) -> Self { let initial = AppState::try_read(cx).map_or(100, |s| s.lighting().brightness); // The slider drives the device only on release, to avoid streaming a // frame burst to the keyboard for every intermediate drag value. @@ -66,11 +114,74 @@ impl LightingPanel { ); let state_obs = AppState::repaint_on(cx, |event| matches!(event, StateEvent::LightingChanged(_))); + let picker = cx.new(|cx| ColorPickerState::new(window, cx)); + // A palette pick or a hex commit closes the picker before it reports + // the color, so a closed picker's color is final; a slider drag reports + // every step while the picker stays open. + let change = cx.subscribe(&picker, |this, picker, event: &ColorPickerEvent, cx| { + let ColorPickerEvent::Change(Some(color)) = event else { + return; + }; + let color = rgb_of(*color); + if picker.read(cx).is_open() { + this.pending = Some(color); + } else { + this.pending = None; + commit_color(color, cx); + } + }); + let close = cx.observe(&picker, |this, picker, cx| { + if !picker.read(cx).is_open() + && let Some(color) = this.pending.take() + { + commit_color(color, cx); + } + }); Self { brightness, + picker, + pending: None, _state_obs: state_obs, + _picker_subscriptions: [change, close], } } + + /// The custom-color control: the picker's trigger in a swatch-sized ring. + /// It shows the current color when that is none of the presets, and a + /// palette icon otherwise. + fn custom_control(&self, current: &Lighting, pal: Palette) -> impl IntoElement { + let custom = custom_color(current); + let label = match custom { + Some(color) => format!("{} #{:06X}", tr!("lighting.custom_color"), color.packed()), + None => tr!("lighting.custom_color").to_string(), + }; + let outer = SWATCH_RING + SWATCH_RING_GAP; + div() + .flex() + .items_center() + .justify_center() + .size(px(SWATCH + 2. * outer)) + .p(px(SWATCH_RING_GAP)) + .rounded(pal.control_radius + px(outer)) + .border(px(SWATCH_RING)) + .border_color(if custom.is_some() { + theme::accent() + } else { + gpui::transparent_black() + }) + .child( + ColorPicker::new(&self.picker) + .with_size(Size::Size(px(SWATCH))) + .featured_colors( + PALETTE + .iter() + .map(|color| Hsla::from(rgb(color.packed()))) + .collect(), + ) + .accessibility_label(label) + .when(custom.is_none(), |picker| picker.icon(IconName::Palette)), + ) + } } impl Render for LightingPanel { @@ -83,10 +194,20 @@ impl Render for LightingPanel { // disturbing an in-progress drag. self.brightness.sync(lighting.brightness, window, cx); + // Keep the closed picker on the device's color, so it opens there + // after a device switch or a preset pick. + let color = Hsla::from(rgb(lighting.color.packed())); + let picker = self.picker.read(cx); + if !picker.is_open() && picker.value() != Some(color) { + self.picker + .update(cx, |picker, cx| picker.set_value(color, window, cx)); + } + let swatches: Vec<_> = PALETTE .iter() .map(|&color| swatch(color, &lighting, pal)) .collect(); + let custom = self.custom_control(&lighting, pal); v_flex() .gap_3() @@ -110,7 +231,13 @@ impl Render for LightingPanel { )) // The rings' clear gaps already space the faces; a full gap on top // would spread the row. - .child(h_flex().gap_1().flex_wrap().children(swatches)) + .child( + h_flex() + .gap_1() + .flex_wrap() + .children(swatches) + .child(custom), + ) .child( SliderRow::new( tr!("camera.brightness"), @@ -184,3 +311,6 @@ fn swatch(color: Rgb, current: &Lighting, pal: Palette) -> impl IntoElement { }); }) } + +#[cfg(test)] +mod tests; diff --git a/crates/openlogi-desktop/src/features/lighting/keyboard_rgb/tests.rs b/crates/openlogi-desktop/src/features/lighting/keyboard_rgb/tests.rs new file mode 100644 index 0000000000..d9b74b73de --- /dev/null +++ b/crates/openlogi-desktop/src/features/lighting/keyboard_rgb/tests.rs @@ -0,0 +1,184 @@ +use gpui::{Hsla, rgb}; +use openlogi_core::color::Rgb; +use openlogi_core::config::Lighting; + +use super::{PALETTE, custom_color, rgb_of}; + +fn lighting(enabled: bool, color: Rgb) -> Lighting { + Lighting { + enabled, + color, + ..Lighting::default() + } +} + +#[test] +fn a_preset_color_is_not_a_custom_color() { + assert_eq!(custom_color(&lighting(true, PALETTE[0])), None); +} + +#[test] +fn an_off_palette_color_is_the_custom_color() { + let color = Rgb::new(0x00, 0xff, 0xaa); + assert_eq!(custom_color(&lighting(true, color)), Some(color)); +} + +#[test] +fn lighting_off_selects_no_custom_color() { + assert_eq!( + custom_color(&lighting(false, Rgb::new(0x00, 0xff, 0xaa))), + None + ); +} + +#[test] +fn picker_colors_convert_without_alpha() { + let translucent = Hsla { + a: 0.3, + ..Hsla::from(rgb(0x0000_ffaa)) + }; + assert_eq!(rgb_of(translucent), Rgb::new(0x00, 0xff, 0xaa)); + for &color in PALETTE { + let hsla = Hsla::from(rgb(color.packed())); + assert_eq!(rgb_of(hsla), color, "#{:06x}", color.packed()); + } +} + +mod picker { + use std::sync::Arc; + + use gpui::{AppContext as _, Entity, TestAppContext, VisualTestContext, rgb}; + use gpui_kit::component::color_picker::ColorPickerState; + use openlogi_core::color::Rgb; + use openlogi_core::config::Config; + use openlogi_core::device::{Capabilities, DeviceKind}; + use tokio::sync::mpsc::UnboundedReceiver; + + use super::super::LightingPanel; + use crate::services::assets::AssetResolver; + use crate::services::ipc::Command; + use crate::state::{AppState, ConfigPersistence, Sources}; + + const CUSTOM: Rgb = Rgb::new(0x00, 0xff, 0xaa); + + /// A lighting keyboard as the selected device, and its panel. + fn panel( + cx: &mut TestAppContext, + ) -> ( + Entity, + UnboundedReceiver, + &mut VisualTestContext, + ) { + cx.update(gpui_kit::init); + let receiver = cx.update(|cx| { + let (sender, receiver) = tokio::sync::mpsc::unbounded_channel(); + let mut inventory = crate::state::tests::direct_inventory([1, 2, 3, 4]); + inventory.paired[0].kind = DeviceKind::Keyboard; + inventory.paired[0].capabilities = Some(Capabilities { + lighting: true, + ..Capabilities::default() + }); + let runtime: Arc = Arc::new(swr_gpui::GpuiRuntime::new(cx)); + let client = swr_core::SwrClient::builder().build(runtime.clone()); + let state = cx.new(|_| { + let mut state = AppState::new(Sources { + config: Config::ephemeral(), + inventories: &[inventory], + standalone: &[], + resolver: &AssetResolver::new(), + cameras: &[], + persistence: ConfigPersistence::MemoryOnly, + ipc_commands: sender, + }); + state.connect_device_reads(client, runtime); + state + }); + AppState::set_global(state, cx); + receiver + }); + let (panel, cx) = cx.add_window_view(LightingPanel::new); + cx.run_until_parked(); + (panel, receiver, cx) + } + + fn picker_of( + panel: &Entity, + cx: &mut VisualTestContext, + ) -> Entity { + cx.read(|cx| panel.read(cx).picker.clone()) + } + + fn current(cx: &mut VisualTestContext) -> (bool, Rgb) { + cx.read(|cx| { + let lighting = AppState::try_read(cx).unwrap().lighting(); + (lighting.enabled, lighting.color) + }) + } + + fn lighting_writes(receiver: &mut UnboundedReceiver) -> usize { + std::iter::from_fn(|| receiver.try_recv().ok()) + .filter(|command| matches!(command, Command::SetLighting(_))) + .count() + } + + #[gpui::test] + fn a_closed_picker_commits_its_color_at_once(cx: &mut TestAppContext) { + let _locale = crate::services::i18n::LOCALE_LOCK.lock().unwrap(); + let (panel, mut receiver, cx) = panel(cx); + lighting_writes(&mut receiver); + let picker = picker_of(&panel, cx); + cx.update(|window, cx| { + picker.update(cx, |picker, cx| { + picker.select_color(rgb(CUSTOM.packed()).into(), window, cx); + }); + }); + cx.run_until_parked(); + assert_eq!(current(cx), (true, CUSTOM)); + assert_eq!(lighting_writes(&mut receiver), 1); + } + + #[gpui::test] + fn an_open_picker_commits_only_when_it_closes(cx: &mut TestAppContext) { + let _locale = crate::services::i18n::LOCALE_LOCK.lock().unwrap(); + let (panel, mut receiver, cx) = panel(cx); + lighting_writes(&mut receiver); + let before = current(cx); + let picker = picker_of(&panel, cx); + cx.update(|window, cx| { + picker.update(cx, |picker, cx| { + picker.set_open(true, cx); + picker.update_color(rgb(0x11_2233).into(), window, cx); + picker.update_color(rgb(CUSTOM.packed()).into(), window, cx); + }); + }); + cx.run_until_parked(); + assert_eq!(current(cx), before, "a drag writes nothing"); + assert_eq!(lighting_writes(&mut receiver), 0); + cx.update(|_, cx| picker.update(cx, |picker, cx| picker.set_open(false, cx))); + cx.run_until_parked(); + assert_eq!(current(cx), (true, CUSTOM)); + assert_eq!( + lighting_writes(&mut receiver), + 1, + "closing writes the last color once" + ); + } + + #[gpui::test] + fn closing_an_unchanged_picker_writes_nothing(cx: &mut TestAppContext) { + let _locale = crate::services::i18n::LOCALE_LOCK.lock().unwrap(); + let (panel, mut receiver, cx) = panel(cx); + lighting_writes(&mut receiver); + let before = current(cx); + let picker = picker_of(&panel, cx); + cx.update(|_, cx| { + picker.update(cx, |picker, cx| { + picker.set_open(true, cx); + picker.set_open(false, cx); + }); + }); + cx.run_until_parked(); + assert_eq!(current(cx), before); + assert_eq!(lighting_writes(&mut receiver), 0); + } +} diff --git a/crates/openlogi-ui/locales/be.toml b/crates/openlogi-ui/locales/be.toml index 942dbe53b2..2136ac8165 100644 --- a/crates/openlogi-ui/locales/be.toml +++ b/crates/openlogi-ui/locales/be.toml @@ -746,6 +746,7 @@ applying_light_setting = "Прымяненне налады святла…" auto_on_with_camera = "Аўтаўключэнне з камерай" camera_light_auto_description = "Уключайце гэта святло, пакуль выкарыстоўваецца якая-небудзь камера, і выключайце, калі камеры перастаюць працаваць." keyboard_lighting_description = "Ужываецца OpenLogi, пакуль ён працуе, і не захоўваецца ў клавіятуры." +custom_color = "Свой колер" [action_ring] actions_ring = "Кола дзеянняў" diff --git a/crates/openlogi-ui/locales/cs.toml b/crates/openlogi-ui/locales/cs.toml index 4205c27a7b..8d5ea8cf6d 100644 --- a/crates/openlogi-ui/locales/cs.toml +++ b/crates/openlogi-ui/locales/cs.toml @@ -746,6 +746,7 @@ applying_light_setting = "Používání nastavení světla…" auto_on_with_camera = "Automaticky zapínat s kamerou" camera_light_auto_description = "Zapnout světlo, když se používá některá kamera, a vypnout ho, když jsou všechny kamery neaktivní." keyboard_lighting_description = "Platí, dokud běží OpenLogi; do klávesnice se neukládá." +custom_color = "Vlastní barva" [action_ring] actions_ring = "Kruh akcí" diff --git a/crates/openlogi-ui/locales/da.toml b/crates/openlogi-ui/locales/da.toml index 95f1836dff..02ca2fc1fa 100644 --- a/crates/openlogi-ui/locales/da.toml +++ b/crates/openlogi-ui/locales/da.toml @@ -746,6 +746,7 @@ applying_light_setting = "Anvender lysindstilling…" auto_on_with_camera = "Tænd automatisk med kameraet" camera_light_auto_description = "Tænd lyset, når et kamera er i brug, og sluk det, når ingen kameraer er aktive." keyboard_lighting_description = "Anvendes af OpenLogi, mens det kører, og gemmes ikke på tastaturet." +custom_color = "Egen farve" [action_ring] actions_ring = "Handlingsring" diff --git a/crates/openlogi-ui/locales/de.toml b/crates/openlogi-ui/locales/de.toml index ed69adb521..0c27212abf 100644 --- a/crates/openlogi-ui/locales/de.toml +++ b/crates/openlogi-ui/locales/de.toml @@ -746,6 +746,7 @@ applying_light_setting = "Beleuchtungseinstellung wird angewendet…" auto_on_with_camera = "Automatisch mit Kamera einschalten" camera_light_auto_description = "Beleuchtung einschalten, sobald eine Kamera verwendet wird, und ausschalten, wenn keine Kamera aktiv ist." keyboard_lighting_description = "Wird von OpenLogi angewendet, solange es läuft, und nicht auf der Tastatur gespeichert." +custom_color = "Eigene Farbe" [action_ring] actions_ring = "Aktionsring" diff --git a/crates/openlogi-ui/locales/el.toml b/crates/openlogi-ui/locales/el.toml index 4c64d289d7..8c52a518be 100644 --- a/crates/openlogi-ui/locales/el.toml +++ b/crates/openlogi-ui/locales/el.toml @@ -746,6 +746,7 @@ applying_light_setting = "Εφαρμογή ρύθμισης φωτισμού…" auto_on_with_camera = "Αυτόματη ενεργοποίηση με την κάμερα" camera_light_auto_description = "Ανάβει το φως όταν χρησιμοποιείται κάποια κάμερα και το σβήνει όταν καμία δεν είναι ενεργή." keyboard_lighting_description = "Εφαρμόζεται από το OpenLogi όσο εκτελείται και δεν αποθηκεύεται στο πληκτρολόγιο." +custom_color = "Προσαρμοσμένο χρώμα" [action_ring] actions_ring = "Δακτύλιος ενεργειών" diff --git a/crates/openlogi-ui/locales/en.toml b/crates/openlogi-ui/locales/en.toml index 4c65b41a47..379ae24cc3 100644 --- a/crates/openlogi-ui/locales/en.toml +++ b/crates/openlogi-ui/locales/en.toml @@ -746,6 +746,7 @@ applying_light_setting = "Applying light setting…" auto_on_with_camera = "Auto-on with camera" camera_light_auto_description = "Turn the light on when any camera is in use and off when all cameras are inactive." keyboard_lighting_description = "Applied by OpenLogi while it runs, not saved on the keyboard." +custom_color = "Custom color" [action_ring] actions_ring = "Actions Ring" diff --git a/crates/openlogi-ui/locales/es.toml b/crates/openlogi-ui/locales/es.toml index f6d1188f79..4ea4c6a4ea 100644 --- a/crates/openlogi-ui/locales/es.toml +++ b/crates/openlogi-ui/locales/es.toml @@ -746,6 +746,7 @@ applying_light_setting = "Aplicando el ajuste de luz…" auto_on_with_camera = "Encendido automático con la cámara" camera_light_auto_description = "Enciende la luz mientras se usa alguna cámara y la apaga cuando ninguna está activa." keyboard_lighting_description = "OpenLogi la aplica mientras se ejecuta; no se guarda en el teclado." +custom_color = "Color personalizado" [action_ring] actions_ring = "Anillo de acciones" diff --git a/crates/openlogi-ui/locales/fi.toml b/crates/openlogi-ui/locales/fi.toml index 15d30fefe2..5409660eba 100644 --- a/crates/openlogi-ui/locales/fi.toml +++ b/crates/openlogi-ui/locales/fi.toml @@ -746,6 +746,7 @@ applying_light_setting = "Otetaan valaistusasetusta käyttöön…" auto_on_with_camera = "Sytytä automaattisesti kameran kanssa" camera_light_auto_description = "Sytyttää valon, kun jokin kamera on käytössä, ja sammuttaa sen, kun kameroita ei käytetä." keyboard_lighting_description = "OpenLogi käyttää sitä ollessaan käynnissä; sitä ei tallenneta näppäimistöön." +custom_color = "Oma väri" [action_ring] actions_ring = "Toimintorengas" diff --git a/crates/openlogi-ui/locales/fr.toml b/crates/openlogi-ui/locales/fr.toml index 840355aab7..60e6b666ab 100644 --- a/crates/openlogi-ui/locales/fr.toml +++ b/crates/openlogi-ui/locales/fr.toml @@ -746,6 +746,7 @@ applying_light_setting = "Application du réglage d’éclairage…" auto_on_with_camera = "Allumage automatique avec la caméra" camera_light_auto_description = "Allume l’éclairage lorsqu’une caméra est utilisée et l’éteint lorsqu’aucune ne l’est." keyboard_lighting_description = "Appliqué par OpenLogi tant qu’il est ouvert, sans être enregistré sur le clavier." +custom_color = "Couleur personnalisée" [action_ring] actions_ring = "Anneau d’actions" diff --git a/crates/openlogi-ui/locales/it.toml b/crates/openlogi-ui/locales/it.toml index a0db0a4049..44d9cad41f 100644 --- a/crates/openlogi-ui/locales/it.toml +++ b/crates/openlogi-ui/locales/it.toml @@ -746,6 +746,7 @@ applying_light_setting = "Applicazione impostazione luce…" auto_on_with_camera = "Accensione automatica con la fotocamera" camera_light_auto_description = "Accendi questa luce quando una fotocamera è in uso e spegnila quando tutte si fermano." keyboard_lighting_description = "Applicata da OpenLogi mentre è in esecuzione, non salvata sulla tastiera." +custom_color = "Colore personalizzato" [action_ring] actions_ring = "Anello azioni" diff --git a/crates/openlogi-ui/locales/ja.toml b/crates/openlogi-ui/locales/ja.toml index 1c9ca01d96..5bac89254c 100644 --- a/crates/openlogi-ui/locales/ja.toml +++ b/crates/openlogi-ui/locales/ja.toml @@ -746,6 +746,7 @@ applying_light_setting = "ライト設定を適用中…" auto_on_with_camera = "カメラ使用時に自動点灯" camera_light_auto_description = "いずれかのカメラを使用している間はライトを点灯し、すべてのカメラが停止すると消灯します。" keyboard_lighting_description = "OpenLogi の実行中に適用され、キーボードには保存されません。" +custom_color = "カスタムカラー" [action_ring] actions_ring = "アクションリング" diff --git a/crates/openlogi-ui/locales/ko.toml b/crates/openlogi-ui/locales/ko.toml index d78ebab981..8fd6e2b82b 100644 --- a/crates/openlogi-ui/locales/ko.toml +++ b/crates/openlogi-ui/locales/ko.toml @@ -746,6 +746,7 @@ applying_light_setting = "조명 설정 적용 중…" auto_on_with_camera = "카메라 사용 시 자동 켜기" camera_light_auto_description = "카메라를 하나라도 사용 중이면 조명을 켜고 모든 카메라가 비활성 상태이면 끕니다." keyboard_lighting_description = "OpenLogi가 실행 중일 때 적용되며 키보드에는 저장되지 않습니다." +custom_color = "사용자 지정 색상" [action_ring] actions_ring = "액션 링" diff --git a/crates/openlogi-ui/locales/nb.toml b/crates/openlogi-ui/locales/nb.toml index 4e3232ba57..097407d118 100644 --- a/crates/openlogi-ui/locales/nb.toml +++ b/crates/openlogi-ui/locales/nb.toml @@ -746,6 +746,7 @@ applying_light_setting = "Bruker lysinnstilling…" auto_on_with_camera = "Slå på automatisk med kameraet" camera_light_auto_description = "Slå på lyset når et kamera er i bruk, og av når ingen kameraer er aktive." keyboard_lighting_description = "Brukes av OpenLogi mens det kjører, og lagres ikke på tastaturet." +custom_color = "Egendefinert farge" [action_ring] actions_ring = "Handlingsring" diff --git a/crates/openlogi-ui/locales/nl.toml b/crates/openlogi-ui/locales/nl.toml index 1e3fd284b6..04c9fa7c8d 100644 --- a/crates/openlogi-ui/locales/nl.toml +++ b/crates/openlogi-ui/locales/nl.toml @@ -746,6 +746,7 @@ applying_light_setting = "Verlichtingsinstelling toepassen…" auto_on_with_camera = "Automatisch aan met camera" camera_light_auto_description = "Schakel de verlichting in zodra een camera wordt gebruikt en uit wanneer geen camera actief is." keyboard_lighting_description = "Toegepast door OpenLogi zolang het draait, niet opgeslagen op het toetsenbord." +custom_color = "Aangepaste kleur" [action_ring] actions_ring = "Actiering" diff --git a/crates/openlogi-ui/locales/pl.toml b/crates/openlogi-ui/locales/pl.toml index 5467b90623..c43c0645a6 100644 --- a/crates/openlogi-ui/locales/pl.toml +++ b/crates/openlogi-ui/locales/pl.toml @@ -746,6 +746,7 @@ applying_light_setting = "Stosowanie ustawienia oświetlenia…" auto_on_with_camera = "Automatycznie z kamerą" camera_light_auto_description = "Włączaj światło, gdy używana jest dowolna kamera, i wyłączaj, gdy żadna nie jest aktywna." keyboard_lighting_description = "Stosowane przez OpenLogi, gdy działa; nie jest zapisywane w klawiaturze." +custom_color = "Własny kolor" [action_ring] actions_ring = "Pierścień akcji" diff --git a/crates/openlogi-ui/locales/pt-BR.toml b/crates/openlogi-ui/locales/pt-BR.toml index 9869ef834e..3a2ecf56cd 100644 --- a/crates/openlogi-ui/locales/pt-BR.toml +++ b/crates/openlogi-ui/locales/pt-BR.toml @@ -746,6 +746,7 @@ applying_light_setting = "Aplicando configuração da luz…" auto_on_with_camera = "Acender com a câmera" camera_light_auto_description = "Acenda a luz enquanto uma câmera estiver em uso e apague-a quando nenhuma estiver ativa." keyboard_lighting_description = "Aplicada pelo OpenLogi enquanto ele está em execução, sem ser salva no teclado." +custom_color = "Cor personalizada" [action_ring] actions_ring = "Anel de ações" diff --git a/crates/openlogi-ui/locales/pt-PT.toml b/crates/openlogi-ui/locales/pt-PT.toml index 3373ca0edd..1081c46bfe 100644 --- a/crates/openlogi-ui/locales/pt-PT.toml +++ b/crates/openlogi-ui/locales/pt-PT.toml @@ -746,6 +746,7 @@ applying_light_setting = "A aplicar a definição da luz…" auto_on_with_camera = "Acender com a câmara" camera_light_auto_description = "Acenda a luz enquanto uma câmara estiver em uso e apague-a quando nenhuma estiver ativa." keyboard_lighting_description = "Aplicada pelo OpenLogi enquanto está em execução, sem ser guardada no teclado." +custom_color = "Cor personalizada" [action_ring] actions_ring = "Anel de ações" diff --git a/crates/openlogi-ui/locales/ru.toml b/crates/openlogi-ui/locales/ru.toml index 26f4d07141..c9df514597 100644 --- a/crates/openlogi-ui/locales/ru.toml +++ b/crates/openlogi-ui/locales/ru.toml @@ -746,6 +746,7 @@ applying_light_setting = "Применение настройки освещен auto_on_with_camera = "Автовключение с камерой" camera_light_auto_description = "Включать свет при использовании любой камеры и выключать, когда камеры неактивны." keyboard_lighting_description = "Применяется OpenLogi, пока он запущен, и не сохраняется в клавиатуре." +custom_color = "Свой цвет" [action_ring] actions_ring = "Кольцо действий" diff --git a/crates/openlogi-ui/locales/sv.toml b/crates/openlogi-ui/locales/sv.toml index 017bb0977e..81a25a344c 100644 --- a/crates/openlogi-ui/locales/sv.toml +++ b/crates/openlogi-ui/locales/sv.toml @@ -746,6 +746,7 @@ applying_light_setting = "Tillämpar ljusinställning…" auto_on_with_camera = "Tänd automatiskt med kameran" camera_light_auto_description = "Tänd lampan när en kamera används och släck den när ingen kamera är aktiv." keyboard_lighting_description = "Tillämpas av OpenLogi medan det körs och sparas inte i tangentbordet." +custom_color = "Egen färg" [action_ring] actions_ring = "Åtgärdsring" diff --git a/crates/openlogi-ui/locales/tr.toml b/crates/openlogi-ui/locales/tr.toml index f023f8c0b5..3f25c93a0f 100644 --- a/crates/openlogi-ui/locales/tr.toml +++ b/crates/openlogi-ui/locales/tr.toml @@ -746,6 +746,7 @@ applying_light_setting = "Işık ayarı uygulanıyor…" auto_on_with_camera = "Kamerayla otomatik aç" camera_light_auto_description = "Herhangi bir kamera kullanılırken bu ışık açılır, kameralar durunca kapatılır." keyboard_lighting_description = "OpenLogi çalıştığı sürece uygulanır, klavyeye kaydedilmez." +custom_color = "Özel renk" [action_ring] actions_ring = "Eylem Halkası" diff --git a/crates/openlogi-ui/locales/uk.toml b/crates/openlogi-ui/locales/uk.toml index e092780acb..65fb925567 100644 --- a/crates/openlogi-ui/locales/uk.toml +++ b/crates/openlogi-ui/locales/uk.toml @@ -746,6 +746,7 @@ applying_light_setting = "Застосування налаштування св auto_on_with_camera = "Автоувімкнення разом із камерою" camera_light_auto_description = "Вмикати це світло, поки використовується будь-яка камера, і вимикати, коли камери зупиняються." keyboard_lighting_description = "Застосовується OpenLogi, поки він працює, і не зберігається в клавіатурі." +custom_color = "Власний колір" [action_ring] actions_ring = "Кільце дій" diff --git a/crates/openlogi-ui/locales/zh-CN.toml b/crates/openlogi-ui/locales/zh-CN.toml index 53008f036b..6cf332f54d 100644 --- a/crates/openlogi-ui/locales/zh-CN.toml +++ b/crates/openlogi-ui/locales/zh-CN.toml @@ -746,6 +746,7 @@ applying_light_setting = "正在应用灯光设置…" auto_on_with_camera = "随摄像头自动开启" camera_light_auto_description = "任意摄像头使用时开灯,所有摄像头均未使用时关灯。" keyboard_lighting_description = "由 OpenLogi 在运行时应用,不保存在键盘中。" +custom_color = "自定义颜色" [action_ring] actions_ring = "操作环" diff --git a/crates/openlogi-ui/locales/zh-HK.toml b/crates/openlogi-ui/locales/zh-HK.toml index b6a745ab89..181675aec2 100644 --- a/crates/openlogi-ui/locales/zh-HK.toml +++ b/crates/openlogi-ui/locales/zh-HK.toml @@ -746,6 +746,7 @@ applying_light_setting = "正在套用燈光設定…" auto_on_with_camera = "隨攝影機自動開啟" camera_light_auto_description = "任何攝影機使用時開燈,所有攝影機均未使用時關燈。" keyboard_lighting_description = "由 OpenLogi 在執行時套用,不會儲存在鍵盤中。" +custom_color = "自訂顏色" [action_ring] actions_ring = "動作環" diff --git a/crates/openlogi-ui/locales/zh-TW.toml b/crates/openlogi-ui/locales/zh-TW.toml index c08a6671cd..90179b9e19 100644 --- a/crates/openlogi-ui/locales/zh-TW.toml +++ b/crates/openlogi-ui/locales/zh-TW.toml @@ -746,6 +746,7 @@ applying_light_setting = "正在套用燈光設定…" auto_on_with_camera = "隨攝影機自動開啟" camera_light_auto_description = "任何攝影機使用時開燈,所有攝影機均未使用時關燈。" keyboard_lighting_description = "由 OpenLogi 在執行時套用,不會儲存在鍵盤中。" +custom_color = "自訂顏色" [action_ring] actions_ring = "動作環" From 3f9baa76ed46e2217dda2abe18c8f3489c3b571f Mon Sep 17 00:00:00 2001 From: Ariazonaa <96840802+Ariazonaa@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:56:53 +0100 Subject: [PATCH 2/3] fix(gui): track the custom color edit in one state and ring its focus The picker's open state and the dragged color now live in one PickerEdit with one transition, and the custom control draws the shared focus ring when the keyboard focuses its trigger. Tests drive the control as a user does: a click opens the picker, typed hex commits once, a click outside dismisses, focus traversal and Enter/Escape work, and the control wraps inside a narrow card at 125%. --- .../src/features/lighting/keyboard_rgb.rs | 99 ++++++--- .../features/lighting/keyboard_rgb/tests.rs | 190 +++++++++++++++--- 2 files changed, 230 insertions(+), 59 deletions(-) diff --git a/crates/openlogi-desktop/src/features/lighting/keyboard_rgb.rs b/crates/openlogi-desktop/src/features/lighting/keyboard_rgb.rs index c85fd5f377..6e79f126b6 100644 --- a/crates/openlogi-desktop/src/features/lighting/keyboard_rgb.rs +++ b/crates/openlogi-desktop/src/features/lighting/keyboard_rgb.rs @@ -7,9 +7,9 @@ use crate::ui::theme::FocusRingStyle as _; use gpui::{ - App, AppContext as _, Context, Entity, Hsla, InteractiveElement, IntoElement, ParentElement, - Render, Rgba, Role, StatefulInteractiveElement as _, Styled, Subscription, Toggled, Window, - div, prelude::FluentBuilder as _, px, rgb, + App, AppContext as _, Context, Entity, Focusable as _, Hsla, InteractiveElement, IntoElement, + ParentElement, Render, Rgba, Role, StatefulInteractiveElement as _, Styled, Subscription, + Toggled, Window, div, prelude::FluentBuilder as _, px, rgb, }; use gpui_kit::base::Button as BaseButton; use gpui_kit::component::color_picker::{ColorPicker, ColorPickerEvent, ColorPickerState}; @@ -66,6 +66,38 @@ fn rgb_of(color: Hsla) -> Rgb { Rgb::new(channel(color.r), channel(color.g), channel(color.b)) } +/// Where an edit in the custom-color picker stands. +/// +/// A palette pick or a hex commit closes the picker before it reports the +/// color, so a color a closed picker reports is final. A slider drag reports +/// every step while the picker stays open; only its last color is written, +/// once, when the picker closes. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum PickerEdit { + /// The picker is closed and holds nothing to write. + Closed, + /// The picker is open and nothing was dragged yet. + Open, + /// The picker is open after a drag that ended on this color. + Dragged(Rgb), +} + +impl PickerEdit { + /// The edit after the picker reports `open` and, on a change, `color`, + /// and the color to write now, if any. + fn next(self, open: bool, color: Option) -> (Self, Option) { + match (open, color, self) { + (false, Some(color), _) | (false, None, Self::Dragged(color)) => { + (Self::Closed, Some(color)) + } + (true, Some(color), _) => (Self::Dragged(color), None), + (false, None, _) => (Self::Closed, None), + (true, None, Self::Closed) => (Self::Open, None), + (true, None, edit) => (edit, None), + } + } +} + /// Light the keys in `color`, unless they already are. fn commit_color(color: Rgb, cx: &mut App) { let unchanged = AppState::try_read(cx).is_some_and(|state| { @@ -87,9 +119,8 @@ pub struct LightingPanel { brightness: CommitSlider, /// The picker behind the custom-color control. picker: Entity, - /// The color a slider drag left in the open picker. It is written when - /// the picker closes, so a drag does not stream writes to the keyboard. - pending: Option, + /// The edit in that picker. Only [`Self::picker_changed`] moves it. + edit: PickerEdit, _state_obs: Subscription, _picker_subscriptions: [Subscription; 2], } @@ -115,48 +146,55 @@ impl LightingPanel { let state_obs = AppState::repaint_on(cx, |event| matches!(event, StateEvent::LightingChanged(_))); let picker = cx.new(|cx| ColorPickerState::new(window, cx)); - // A palette pick or a hex commit closes the picker before it reports - // the color, so a closed picker's color is final; a slider drag reports - // every step while the picker stays open. - let change = cx.subscribe(&picker, |this, picker, event: &ColorPickerEvent, cx| { - let ColorPickerEvent::Change(Some(color)) = event else { - return; - }; - let color = rgb_of(*color); - if picker.read(cx).is_open() { - this.pending = Some(color); - } else { - this.pending = None; - commit_color(color, cx); - } - }); - let close = cx.observe(&picker, |this, picker, cx| { - if !picker.read(cx).is_open() - && let Some(color) = this.pending.take() - { - commit_color(color, cx); + let change = cx.subscribe(&picker, |this, _, event: &ColorPickerEvent, cx| { + if let ColorPickerEvent::Change(Some(color)) = event { + this.picker_changed(Some(rgb_of(*color)), cx); } }); + // Opening and closing only notify. + let open = cx.observe(&picker, |this, _, cx| this.picker_changed(None, cx)); Self { brightness, picker, - pending: None, + edit: PickerEdit::Closed, _state_obs: state_obs, - _picker_subscriptions: [change, close], + _picker_subscriptions: [change, open], + } + } + + /// Move the picker edit on a picker report, and write what it settles. + fn picker_changed(&mut self, color: Option, cx: &mut Context) { + let open = self.picker.read(cx).is_open(); + let (edit, write) = self.edit.next(open, color); + self.edit = edit; + if let Some(color) = write { + commit_color(color, cx); } } /// The custom-color control: the picker's trigger in a swatch-sized ring. /// It shows the current color when that is none of the presets, and a /// palette icon otherwise. - fn custom_control(&self, current: &Lighting, pal: Palette) -> impl IntoElement { + fn custom_control( + &self, + current: &Lighting, + pal: Palette, + window: &Window, + cx: &App, + ) -> impl IntoElement { let custom = custom_color(current); + // The trigger is the picker's own focus target, so the ring it shares + // with the swatches goes on this frame, under the same keyboard-only + // rule as `focus_visible`. + let focus_visible = self.picker.read(cx).focus_handle(cx).is_focused(window) + && window.last_input_was_keyboard(); let label = match custom { Some(color) => format!("{} #{:06X}", tr!("lighting.custom_color"), color.packed()), None => tr!("lighting.custom_color").to_string(), }; let outer = SWATCH_RING + SWATCH_RING_GAP; div() + .debug_selector(|| "lighting-custom-color".into()) .flex() .items_center() .justify_center() @@ -169,6 +207,7 @@ impl LightingPanel { } else { gpui::transparent_black() }) + .when(focus_visible, |frame| frame.focus_ring(pal)) .child( ColorPicker::new(&self.picker) .with_size(Size::Size(px(SWATCH))) @@ -207,7 +246,7 @@ impl Render for LightingPanel { .iter() .map(|&color| swatch(color, &lighting, pal)) .collect(); - let custom = self.custom_control(&lighting, pal); + let custom = self.custom_control(&lighting, pal, window, cx); v_flex() .gap_3() diff --git a/crates/openlogi-desktop/src/features/lighting/keyboard_rgb/tests.rs b/crates/openlogi-desktop/src/features/lighting/keyboard_rgb/tests.rs index d9b74b73de..684a9b988b 100644 --- a/crates/openlogi-desktop/src/features/lighting/keyboard_rgb/tests.rs +++ b/crates/openlogi-desktop/src/features/lighting/keyboard_rgb/tests.rs @@ -2,7 +2,7 @@ use gpui::{Hsla, rgb}; use openlogi_core::color::Rgb; use openlogi_core::config::Lighting; -use super::{PALETTE, custom_color, rgb_of}; +use super::{PALETTE, PickerEdit, custom_color, rgb_of}; fn lighting(enabled: bool, color: Rgb) -> Lighting { Lighting { @@ -44,13 +44,64 @@ fn picker_colors_convert_without_alpha() { } } +const DRAGGED: Rgb = Rgb::new(0x11, 0x22, 0x33); + +#[test] +fn a_color_reported_by_a_closed_picker_is_written_at_once() { + // A palette pick or a hex commit closes the picker, then reports. + for from in [ + PickerEdit::Closed, + PickerEdit::Open, + PickerEdit::Dragged(DRAGGED), + ] { + assert_eq!( + from.next(false, Some(Rgb::WHITE)), + (PickerEdit::Closed, Some(Rgb::WHITE)), + "{from:?}" + ); + } +} + +#[test] +fn a_drag_is_held_until_the_picker_closes() { + let (edit, write) = PickerEdit::Closed.next(true, None); + assert_eq!((edit, write), (PickerEdit::Open, None)); + let (edit, write) = edit.next(true, Some(Rgb::WHITE)); + assert_eq!((edit, write), (PickerEdit::Dragged(Rgb::WHITE), None)); + let (edit, write) = edit.next(true, Some(DRAGGED)); + assert_eq!((edit, write), (PickerEdit::Dragged(DRAGGED), None)); + assert_eq!(edit.next(false, None), (PickerEdit::Closed, Some(DRAGGED))); +} + +#[test] +fn closing_without_a_drag_writes_nothing() { + assert_eq!( + PickerEdit::Open.next(false, None), + (PickerEdit::Closed, None) + ); + assert_eq!( + PickerEdit::Closed.next(false, None), + (PickerEdit::Closed, None) + ); +} + +#[test] +fn a_finished_drag_is_not_written_twice() { + let (edit, write) = PickerEdit::Dragged(DRAGGED).next(false, None); + assert_eq!(write, Some(DRAGGED)); + assert_eq!(edit.next(false, None), (PickerEdit::Closed, None)); +} + mod picker { use std::sync::Arc; - use gpui::{AppContext as _, Entity, TestAppContext, VisualTestContext, rgb}; + use gpui::{ + AppContext as _, Entity, Focusable as _, Modifiers, TestAppContext, VisualTestContext, + point, px, rgb, size, + }; use gpui_kit::component::color_picker::ColorPickerState; use openlogi_core::color::Rgb; - use openlogi_core::config::Config; + use openlogi_core::config::{Config, UiScale}; use openlogi_core::device::{Capabilities, DeviceKind}; use tokio::sync::mpsc::UnboundedReceiver; @@ -58,6 +109,7 @@ mod picker { use crate::services::assets::AssetResolver; use crate::services::ipc::Command; use crate::state::{AppState, ConfigPersistence, Sources}; + use crate::ui::theme; const CUSTOM: Rgb = Rgb::new(0x00, 0xff, 0xaa); @@ -97,6 +149,7 @@ mod picker { receiver }); let (panel, cx) = cx.add_window_view(LightingPanel::new); + cx.simulate_resize(size(px(800.), px(600.))); cx.run_until_parked(); (panel, receiver, cx) } @@ -121,64 +174,143 @@ mod picker { .count() } + /// Click the custom-color control where a user would. + fn click_custom_control(cx: &mut VisualTestContext) { + cx.update(|window, cx| window.draw(cx).clear(cx)); + let control = cx + .debug_bounds("lighting-custom-color") + .expect("the custom-color control renders"); + cx.simulate_click(control.center(), Modifiers::none()); + cx.run_until_parked(); + } + + fn is_open(picker: &Entity, cx: &mut VisualTestContext) -> bool { + cx.read(|cx| picker.read(cx).is_open()) + } + #[gpui::test] - fn a_closed_picker_commits_its_color_at_once(cx: &mut TestAppContext) { + fn clicking_the_custom_control_opens_the_picker_without_a_write(cx: &mut TestAppContext) { let _locale = crate::services::i18n::LOCALE_LOCK.lock().unwrap(); let (panel, mut receiver, cx) = panel(cx); lighting_writes(&mut receiver); let picker = picker_of(&panel, cx); - cx.update(|window, cx| { - picker.update(cx, |picker, cx| { - picker.select_color(rgb(CUSTOM.packed()).into(), window, cx); - }); - }); + click_custom_control(cx); + assert!(is_open(&picker, cx)); + assert_eq!(lighting_writes(&mut receiver), 0); + } + + #[gpui::test] + fn a_typed_hex_color_is_written_once_and_closes_the_picker(cx: &mut TestAppContext) { + let _locale = crate::services::i18n::LOCALE_LOCK.lock().unwrap(); + let (panel, mut receiver, cx) = panel(cx); + lighting_writes(&mut receiver); + let picker = picker_of(&panel, cx); + click_custom_control(cx); + let hex = cx.read(|cx| picker.read(cx).hex_input().clone()); + cx.update(|window, cx| hex.update(cx, |input, cx| input.focus(window, cx))); + // The field holds the current color as `#RRGGBB`; keep the `#`. + cx.simulate_keystrokes("end backspace backspace backspace backspace backspace backspace"); + cx.simulate_input("00ffaa"); + cx.simulate_keystrokes("enter"); cx.run_until_parked(); + assert!(!is_open(&picker, cx)); assert_eq!(current(cx), (true, CUSTOM)); assert_eq!(lighting_writes(&mut receiver), 1); } #[gpui::test] - fn an_open_picker_commits_only_when_it_closes(cx: &mut TestAppContext) { + fn a_click_outside_closes_the_picker_without_a_write(cx: &mut TestAppContext) { let _locale = crate::services::i18n::LOCALE_LOCK.lock().unwrap(); let (panel, mut receiver, cx) = panel(cx); lighting_writes(&mut receiver); let before = current(cx); let picker = picker_of(&panel, cx); - cx.update(|window, cx| { - picker.update(cx, |picker, cx| { - picker.set_open(true, cx); - picker.update_color(rgb(0x11_2233).into(), window, cx); - picker.update_color(rgb(CUSTOM.packed()).into(), window, cx); - }); - }); + click_custom_control(cx); + assert!(is_open(&picker, cx)); + cx.simulate_click(point(px(790.), px(590.)), Modifiers::none()); cx.run_until_parked(); - assert_eq!(current(cx), before, "a drag writes nothing"); + assert!(!is_open(&picker, cx)); + assert_eq!(current(cx), before); assert_eq!(lighting_writes(&mut receiver), 0); - cx.update(|_, cx| picker.update(cx, |picker, cx| picker.set_open(false, cx))); + } + + #[gpui::test] + fn the_keyboard_reaches_opens_and_closes_the_picker(cx: &mut TestAppContext) { + let _locale = crate::services::i18n::LOCALE_LOCK.lock().unwrap(); + let (panel, mut receiver, cx) = panel(cx); + lighting_writes(&mut receiver); + let picker = picker_of(&panel, cx); + let focused = |cx: &mut VisualTestContext| { + cx.update(|window, cx| picker.read(cx).focus_handle(cx).is_focused(window)) + }; + // Move focus the way Tab does (the test window has no gpui-kit Root + // to bind the key), past the toggle and the nine swatches. + for _ in 0..16 { + if focused(cx) { + break; + } + cx.update(gpui::Window::focus_next); + } + assert!(focused(cx), "Tab order reaches the custom-color control"); + cx.simulate_keystrokes("enter"); cx.run_until_parked(); - assert_eq!(current(cx), (true, CUSTOM)); - assert_eq!( - lighting_writes(&mut receiver), - 1, - "closing writes the last color once" + assert!(is_open(&picker, cx)); + assert!( + cx.update(|window, _| window.last_input_was_keyboard()), + "a keyboard-focused control draws the shared focus ring" ); + cx.simulate_keystrokes("escape"); + cx.run_until_parked(); + assert!(!is_open(&picker, cx)); + assert_eq!(lighting_writes(&mut receiver), 0); } #[gpui::test] - fn closing_an_unchanged_picker_writes_nothing(cx: &mut TestAppContext) { + fn the_custom_control_stays_in_a_narrow_card_at_125_percent(cx: &mut TestAppContext) { + let _locale = crate::services::i18n::LOCALE_LOCK.lock().unwrap(); + let (_panel, _receiver, cx) = panel(cx); + // A column narrower than the Lighting card at the main window's + // minimum width, at the largest interface scale. + let width = px(360.); + cx.update(|window, _| theme::apply_scale(window, UiScale::ExtraLarge)); + cx.simulate_resize(size(width, px(600.))); + cx.update(|window, cx| window.draw(cx).clear(cx)); + let control = cx + .debug_bounds("lighting-custom-color") + .expect("the custom-color control renders"); + assert!( + control.right() <= width, + "{control:?} must wrap inside the {width:?} column" + ); + } + + /// The popover's sliders carry no debug selector in gpui-kit, so a test + /// cannot drag them; this drives the slider's reports through the picker + /// state the sliders update, then closes the picker by clicking outside. + #[gpui::test] + fn a_slider_drag_is_written_once_when_the_picker_closes(cx: &mut TestAppContext) { let _locale = crate::services::i18n::LOCALE_LOCK.lock().unwrap(); let (panel, mut receiver, cx) = panel(cx); lighting_writes(&mut receiver); let before = current(cx); let picker = picker_of(&panel, cx); - cx.update(|_, cx| { + click_custom_control(cx); + cx.update(|window, cx| { picker.update(cx, |picker, cx| { - picker.set_open(true, cx); - picker.set_open(false, cx); + picker.update_color(rgb(0x0011_2233).into(), window, cx); + picker.update_color(rgb(CUSTOM.packed()).into(), window, cx); }); }); cx.run_until_parked(); - assert_eq!(current(cx), before); + assert_eq!(current(cx), before, "a drag writes nothing"); assert_eq!(lighting_writes(&mut receiver), 0); + cx.simulate_click(point(px(790.), px(590.)), Modifiers::none()); + cx.run_until_parked(); + assert_eq!(current(cx), (true, CUSTOM)); + assert_eq!( + lighting_writes(&mut receiver), + 1, + "closing writes the last color once" + ); } } From 0f5f1eac0ac5c15bfb5afb2b8cac519fe5dbe592 Mon Sep 17 00:00:00 2001 From: Ariazonaa <96840802+Ariazonaa@users.noreply.github.com> Date: Thu, 26 Nov 2026 17:56:53 +0100 Subject: [PATCH 3/3] docs: describe the custom keyboard lighting color --- README.md | 2 +- docs/CONFIGURATION.md | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0ee953710c..4d06358c33 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Per-application profiles switch with the focused app. An `[apps]` alias lets one - + diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 6679e85317..ffc162b800 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -225,7 +225,12 @@ Common device fields are: - `action_ring`: default and complete per-application eight-slot layouts; `action_ring.per_app` takes the same selectors as `per_app_bindings`, including the Windows `exe:` fallback and `app:` keys -- `lighting`, `smartshift`, and camera controls / profiles +- `lighting`: `enabled`, `color` as `"RRGGBB"`, and `brightness` from 0 to 100. + The Lighting tab sets `color` from its nine presets or from the custom-color + control after them, which opens a color picker with a palette, sliders and a + hex field. A palette or hex pick applies at once; a slider drag applies once, + when the picker closes +- `smartshift` and camera controls / profiles - `camera_stream_mode`: the live preview's mode, a table of `width`, `height` (pixels) and `fps`. All three are required and must be positive, or the file does not load. Without the table, or when the camera no longer offers that
Keys and Backlight cards for an MX Keys SKeyboard
  • Fn Lock, and multi-platform keyboards that stay on the host OS layout
  • Backlight level, automatic brightness, battery saving, and how long the keys stay lit
  • The backlight level shown on screen as it changes
  • Static RGB on supported keyboards
Keyboard
  • Fn Lock, and multi-platform keyboards that stay on the host OS layout
  • Backlight level, automatic brightness, battery saving, and how long the keys stay lit
  • The backlight level shown on screen as it changes
  • Static RGB on supported keyboards, in a preset or any color you pick
Litra Glow lighting panel with brightness and color temperature