diff --git a/ui/shared/power/brightness_slider.js b/ui/shared/power/brightness_slider.js index 317da0e..78ae1f5 100644 --- a/ui/shared/power/brightness_slider.js +++ b/ui/shared/power/brightness_slider.js @@ -15,10 +15,6 @@ import { keyboardBrightness, } from "beaver://shared/power/brightness.js"; -// Never let the screen go fully dark from this control: the user would have no -// way to see the UI to turn it back up. -const MIN_PERCENT = 5; - export class BrightnessSlider extends LitElement { // Pointer currently captured for a drag, or null. #pointerId = null; @@ -30,6 +26,9 @@ export class BrightnessSlider extends LitElement { // Either screenBrightness or keyboardBrightness, according to the 'kind' property. #device = null; + // Never let the screen go fully dark from this control, but allow 0 for keyboard lights. + #minPercent = 5; + static properties = { percent: { type: Number }, kind: { type: String }, @@ -127,7 +126,7 @@ export class BrightnessSlider extends LitElement { constructor() { super(); - this.percent = MIN_PERCENT; + this.percent = this.#minPercent; // Hidden until a backlight is found, so shells can mount us unconditionally. this.hidden = true; } @@ -145,6 +144,7 @@ export class BrightnessSlider extends LitElement { async #init() { if (this.kind == "keyboard") { this.#device = keyboardBrightness; + this.#minPercent = 0; } else { this.#device = screenBrightness; } @@ -179,7 +179,7 @@ export class BrightnessSlider extends LitElement { } const ratio = (event.clientX - rect.left) / rect.width; const percent = Math.round( - Math.min(100, Math.max(MIN_PERCENT, ratio * 100)), + Math.min(100, Math.max(this.#minPercent, ratio * 100)), ); if (percent === this.percent) { return; @@ -255,7 +255,7 @@ export class BrightnessSlider extends LitElement { role="slider" tabindex="0" aria-label="Screen brightness" - aria-valuemin="${MIN_PERCENT}" + aria-valuemin="${this.#minPercent}" aria-valuemax="100" aria-valuenow="${this.percent}" @pointerdown=${this.#onPointerDown} @@ -287,7 +287,10 @@ export class BrightnessSlider extends LitElement { return; } event.preventDefault(); - this.percent = Math.min(100, Math.max(MIN_PERCENT, this.percent + step)); + this.percent = Math.min( + 100, + Math.max(this.#minPercent, this.percent + step), + ); this.#device.set(this.percent); }; }