[AGS] Brightness: Fix, add CLI

This commit is contained in:
Admin 2025-04-27 10:48:07 +02:00
parent 364b5cb0ef
commit 710eeb7fb4
2 changed files with 33 additions and 7 deletions

View File

@ -3,8 +3,7 @@ import style from "./style.scss"
import Bar from "./components/bar/Bar";
import AstalHyprland from "gi://AstalHyprland?version=0.1";
import { hyprToGdk } from "./util/hyprland";
import { writeFile } from "astal";
import Launcher from "./components/launcher/Launcher";
import Brightness from "./util/brightness";
App.start({
instanceName: "runner",
@ -58,6 +57,32 @@ App.start({
// res( notifications.cliHandler( args ) );
} else if ( args[ 0 ] === 'bar' ) {
res( Bar.cliHandler( args ) );
} else if ( args[ 0 ] === 'brightness' ) {
try {
const brightness = Brightness.get_default();
if ( brightness.screenAvailable ) {
if ( args[ 1 ] === 'increase' ) {
brightness.screen += args.length > 1 ? parseInt( args[ 2 ] ) / 100 : 1;
} else if ( args[ 1 ] === 'decrease' ) {
brightness.screen -= args.length > 1 ? parseInt( args[ 2 ] ) / 100 : 1;
} else if ( args[ 1 ] === 'set' ) {
if ( args.length > 1 ) {
brightness.screen = parseInt( args[ 2 ] ) / 100;
} else {
res( 'Argument <brightness> unspecified' );
return;
}
} else {
res( 'Unknown command ' + args[ 1 ] );
return;
}
res( 'Ok' );
} else {
res( 'No controllable screen available' );
}
} catch ( e ) {
res( 'Error running brightness change' );
}
}
// } else if ( args[ 0 ] === 'launcher' ) {
// if ( args[ 1 ] === 'show' ) {

View File

@ -4,19 +4,20 @@ import Brightness from "../../../../util/brightness";
const brightness = Brightness.get_default();
const BrightnessModule = () => {
print( brightness.screen * 100 );
const setBrightness = (value: number) => {
brightness.set_property('screen', value / 100);
brightness.screen = value;
}
return (
<box visible={bind(brightness, 'screenAvailable')}>
<image iconName={"brightness-high-symbolic"}></image>
<label label={bind(brightness, "screen").as(b => `${Math.round(100 * b)}%`)}></label>
<slider
value={bind(brightness, "screen").as(b => 100 * b)}
value={Math.round( brightness.screen * 100) / 100}
hexpand
max={100}
min={0}
step={1}
max={1}
min={0.01}
step={0.01}
vexpand
onChangeValue={self => setBrightness(self.value)}
></slider>