feat: add readme and clean up comments and code quality. Also update metadata so that it reads better in settings
This commit is contained in:
@@ -4,10 +4,6 @@ export const SCHEMA_ID = 'org.gnome.shell.extensions.ddcbrightness';
|
||||
/** VCP feature code used when none is configured (10 = brightness). */
|
||||
export const DEFAULT_VCP_CODE = '10';
|
||||
|
||||
/**
|
||||
* Scales the mandatory I2C delays ddcutil inserts around DDC/CI transactions.
|
||||
* Lower = faster but less tolerant of flaky monitors. Tune per hardware.
|
||||
*/
|
||||
export const DDCUTIL_SLEEP_MULTIPLIER = '0.5';
|
||||
|
||||
/** Prefix for all console logging from this extension. */
|
||||
|
||||
+5
-18
@@ -1,10 +1,9 @@
|
||||
import Gio from 'gi://Gio';
|
||||
import St from 'gi://St';
|
||||
import * as Slider from 'resource:///org/gnome/shell/ui/slider.js';
|
||||
import { DEFAULT_VCP_CODE, LOG_PREFIX } from './constants.js';
|
||||
import {DEFAULT_VCP_CODE, LOG_PREFIX} from './constants.js';
|
||||
import * as Ddcutil from './ddcutil.js';
|
||||
|
||||
/** A detected display plus the UI refs and runtime state attached to it. */
|
||||
export interface DisplayInfo {
|
||||
bus: string;
|
||||
name: string;
|
||||
@@ -13,30 +12,18 @@ export interface DisplayInfo {
|
||||
currentValue: number;
|
||||
slider: Slider.Slider | null;
|
||||
valueLabel: St.Label | null;
|
||||
// Reconciliation state for writes: `sentValue` is the value of the most
|
||||
// recent write handed to ddcutil; `inFlight` is true while that write runs.
|
||||
sentValue: number;
|
||||
inFlight: boolean;
|
||||
reading: boolean;
|
||||
updatingFromCode: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Owns the set of detected displays and all brightness operations on them
|
||||
* (detection, monitor mapping, reads, and writes via ddcutil).
|
||||
*
|
||||
* Writes use a reconciliation model rather than debouncing: `currentValue` is
|
||||
* the user's target and at most one write per display is ever in flight. When a
|
||||
* write finishes, if the target has since moved we immediately send the latest
|
||||
* value — so intermediate values are coalesced and we never queue stale writes.
|
||||
*/
|
||||
export class DisplayController {
|
||||
private _settings: Gio.Settings;
|
||||
private _displays: DisplayInfo[] = [];
|
||||
private _detectComplete = false;
|
||||
private _disposed = false;
|
||||
|
||||
/** Invoked after detection finishes so the UI can rebuild itself. */
|
||||
onDetectComplete: (() => void) | null = null;
|
||||
|
||||
constructor(settings: Gio.Settings) {
|
||||
@@ -55,18 +42,15 @@ export class DisplayController {
|
||||
return this._settings.get_string('vcp-code') || DEFAULT_VCP_CODE;
|
||||
}
|
||||
|
||||
/** Clear all state back to the pre-detection condition. */
|
||||
reset(): void {
|
||||
this._displays = [];
|
||||
this._detectComplete = false;
|
||||
}
|
||||
|
||||
/** Stop issuing further writes. Call before disposal. */
|
||||
cleanup(): void {
|
||||
this._disposed = true;
|
||||
}
|
||||
|
||||
/** Detect displays, map them to monitors, then read their brightness. */
|
||||
detect(): void {
|
||||
Ddcutil.detectDisplays((parsed) => {
|
||||
this._displays = parsed.map((p) => ({
|
||||
@@ -117,7 +101,10 @@ export class DisplayController {
|
||||
return global.display.get_primary_monitor();
|
||||
}
|
||||
|
||||
/** The display to act on for global actions, honoring "link displays". */
|
||||
/**
|
||||
* The display to act on for global actions, honoring "link displays".
|
||||
* This should grab the display that the active window is part of for adjusting when not linked
|
||||
*/
|
||||
getActiveDisplay(): DisplayInfo | null {
|
||||
if (this._settings.get_boolean('link-displays')) {
|
||||
return this._displays[0] ?? null;
|
||||
|
||||
@@ -42,7 +42,6 @@ export class BrightnessIndicator {
|
||||
this.rebuildMenu();
|
||||
}
|
||||
|
||||
/** The underlying panel button, for adding to the status area. */
|
||||
get button(): PanelMenu.Button {
|
||||
return this._button;
|
||||
}
|
||||
|
||||
+2
-7
@@ -3,16 +3,11 @@ import Meta from 'gi://Meta';
|
||||
import Shell from 'gi://Shell';
|
||||
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||||
|
||||
/** Map of settings key -> callback to run when the shortcut fires. */
|
||||
export type KeybindingActions = Record<string, () => void>;
|
||||
|
||||
/**
|
||||
* Registers the extension's keyboard shortcuts with the window manager and
|
||||
* keeps them in sync as their settings change.
|
||||
*/
|
||||
export class KeybindingManager {
|
||||
private _settings: Gio.Settings;
|
||||
private _actions: KeybindingActions;
|
||||
private readonly _settings: Gio.Settings;
|
||||
private readonly _actions: KeybindingActions;
|
||||
private _bindings: Map<string, number> = new Map();
|
||||
|
||||
constructor(settings: Gio.Settings, actions: KeybindingActions) {
|
||||
|
||||
Reference in New Issue
Block a user