✨ feat(backlight): add page widget for backlight feature
This commit is contained in:
@@ -61,6 +61,11 @@ export default {
|
|||||||
gamma: "Gamma",
|
gamma: "Gamma",
|
||||||
temperature: "Temperature"
|
temperature: "Temperature"
|
||||||
},
|
},
|
||||||
|
backlight: {
|
||||||
|
title: "Backlight",
|
||||||
|
description: "Control the brightness of your screens",
|
||||||
|
refresh: "Refresh backlights"
|
||||||
|
},
|
||||||
bluetooth: {
|
bluetooth: {
|
||||||
title: "Bluetooth",
|
title: "Bluetooth",
|
||||||
description: "Manage Bluetooth devices",
|
description: "Manage Bluetooth devices",
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ export default {
|
|||||||
temperature: "Temperatura",
|
temperature: "Temperatura",
|
||||||
gamma: "Gama"
|
gamma: "Gama"
|
||||||
},
|
},
|
||||||
|
backlight: {
|
||||||
|
title: "Brilho",
|
||||||
|
description: "Controle o nível de brilho das suas telas",
|
||||||
|
refresh: "Recarregar"
|
||||||
|
},
|
||||||
bluetooth: {
|
bluetooth: {
|
||||||
title: "Bluetooth",
|
title: "Bluetooth",
|
||||||
description: "Gerencie dispositivos Bluetooth",
|
description: "Gerencie dispositivos Bluetooth",
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ export type i18nStruct = {
|
|||||||
title: string,
|
title: string,
|
||||||
interface: string
|
interface: string
|
||||||
},
|
},
|
||||||
|
backlight: {
|
||||||
|
title: string,
|
||||||
|
description: string,
|
||||||
|
refresh: string
|
||||||
|
},
|
||||||
bluetooth: {
|
bluetooth: {
|
||||||
title: string,
|
title: string,
|
||||||
description: string,
|
description: string,
|
||||||
|
|||||||
@@ -19,15 +19,22 @@ class Backlight extends GObject.Object {
|
|||||||
#maxBrightness: number;
|
#maxBrightness: number;
|
||||||
#brightness: number;
|
#brightness: number;
|
||||||
#available: boolean = true;
|
#available: boolean = true;
|
||||||
|
#monitor: Gio.FileMonitor;
|
||||||
|
|
||||||
@signal(Number) brightnessChanged(_: number): void {};
|
@signal(Number) brightnessChanged(_: number): void {};
|
||||||
|
|
||||||
|
@getter(String)
|
||||||
|
get name() { return this.#name; }
|
||||||
|
|
||||||
@getter(String)
|
@getter(String)
|
||||||
get path() { return this.#path; }
|
get path() { return this.#path; }
|
||||||
|
|
||||||
@getter(GObject.Object as unknown as ParamSpec<Backlight>)
|
@getter(GObject.Object as unknown as ParamSpec<Backlight>)
|
||||||
get default() { return Backlight.default; }
|
get default() { return Backlight.default; }
|
||||||
|
|
||||||
|
@getter(Object as unknown as ParamSpec<Array<Backlight>>)
|
||||||
|
get backlights() { return Backlight.backlights; }
|
||||||
|
|
||||||
@getter(Boolean)
|
@getter(Boolean)
|
||||||
get isDefault() { return this.path === this.default?.path; }
|
get isDefault() { return this.path === this.default?.path; }
|
||||||
|
|
||||||
@@ -97,6 +104,7 @@ class Backlight extends GObject.Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Backlight._backlights = backlights;
|
Backlight._backlights = backlights;
|
||||||
|
backlights.forEach(bk => bk.notify("backlights"));
|
||||||
return backlights;
|
return backlights;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +127,7 @@ class Backlight extends GObject.Object {
|
|||||||
this.#brightness = Number.parseInt(readFile(`${this.#path}/brightness`))
|
this.#brightness = Number.parseInt(readFile(`${this.#path}/brightness`))
|
||||||
|
|
||||||
|
|
||||||
monitorFile(`/sys/class/backlight/${name}/brightness`, () => {
|
this.#monitor = monitorFile(`/sys/class/backlight/${name}/brightness`, () => {
|
||||||
this.#brightness = this.readBrightness();
|
this.#brightness = this.readBrightness();
|
||||||
this.notify("brightness");
|
this.notify("brightness");
|
||||||
this.emit("brightness-changed", this.brightness);
|
this.emit("brightness-changed", this.brightness);
|
||||||
@@ -166,6 +174,10 @@ class Backlight extends GObject.Object {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vfunc_dispose(): void {
|
||||||
|
this.#monitor.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
public emit<Signal extends keyof typeof this.$signals>(
|
public emit<Signal extends keyof typeof this.$signals>(
|
||||||
signal: Signal,
|
signal: Signal,
|
||||||
...args: Parameters<(typeof this.$signals)[Signal]>
|
...args: Parameters<(typeof this.$signals)[Signal]>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { createBinding, With } from "ags";
|
|||||||
import { Backlight } from "../../modules/backlight";
|
import { Backlight } from "../../modules/backlight";
|
||||||
|
|
||||||
import AstalWp from "gi://AstalWp";
|
import AstalWp from "gi://AstalWp";
|
||||||
|
import { PageBacklight } from "./pages/Backlight";
|
||||||
|
|
||||||
|
|
||||||
export let slidersPages: Pages|undefined;
|
export let slidersPages: Pages|undefined;
|
||||||
@@ -65,6 +66,8 @@ export function Sliders() {
|
|||||||
Backlight.getDefault()!.brightness = value
|
Backlight.getDefault()!.brightness = value
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<Gtk.Button class={"more"} iconName={"go-next-symbolic"} onClicked={() =>
|
||||||
|
slidersPages?.toggle(PageBacklight)} />
|
||||||
</Gtk.Box>
|
</Gtk.Box>
|
||||||
}
|
}
|
||||||
</With>
|
</With>
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { Astal, Gtk } from "ags/gtk4";
|
||||||
|
import { tr } from "../../../i18n/intl";
|
||||||
|
import { Backlight } from "../../../modules/backlight";
|
||||||
|
import { Page } from "./Page";
|
||||||
|
import { createBinding, With } from "ags";
|
||||||
|
import { addSliderMarksFromMinMax } from "../../../modules/utils";
|
||||||
|
|
||||||
|
|
||||||
|
export const PageBacklight = new Page({
|
||||||
|
id: "backlight",
|
||||||
|
title: tr("control_center.pages.backlight.title"),
|
||||||
|
description: tr("control_center.pages.backlight.description"),
|
||||||
|
content: () => (
|
||||||
|
<With value={createBinding(Backlight.getDefault()!, "backlights")}>
|
||||||
|
{(bklights: Array<Backlight>) => bklights.length > 0 &&
|
||||||
|
<Gtk.Box orientation={Gtk.Orientation.VERTICAL} spacing={6}>
|
||||||
|
{bklights.map((bklight, i) =>
|
||||||
|
<Gtk.Box class={"bklight"} orientation={Gtk.Orientation.VERTICAL}
|
||||||
|
spacing={4}>
|
||||||
|
|
||||||
|
<Gtk.Label class={"subheader"} label={`Backlight ${i+1} (${bklight.name})`}
|
||||||
|
xalign={0} />
|
||||||
|
<Astal.Slider $={(self) => addSliderMarksFromMinMax(self)}
|
||||||
|
min={0} max={bklight.maxBrightness}
|
||||||
|
value={createBinding(bklight, "brightness")}
|
||||||
|
onChangeValue={(_, __, value) => {
|
||||||
|
bklight.brightness = value
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Gtk.Box>
|
||||||
|
)}
|
||||||
|
</Gtk.Box>
|
||||||
|
}
|
||||||
|
</With>
|
||||||
|
),
|
||||||
|
headerButtons: [{
|
||||||
|
icon: "arrow-circular-top-right",
|
||||||
|
tooltipText: tr("control_center.pages.backlight.refresh"),
|
||||||
|
actionClicked: () => Backlight.scan()
|
||||||
|
}]
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user