mirror of
https://github.com/xsghetti/HyprCrux.git
synced 2025-07-03 13:50:38 -04:00
updates
This commit is contained in:
parent
1f8cb3c145
commit
610604e80f
253 changed files with 27055 additions and 44 deletions
59
.config/ags/services/brightness.js
Normal file
59
.config/ags/services/brightness.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
import Service from 'resource:///com/github/Aylur/ags/service.js';
|
||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||
const { exec, execAsync } = Utils;
|
||||
|
||||
import { clamp } from '../modules/.miscutils/mathfuncs.js';
|
||||
|
||||
class BrightnessService extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{ 'screen-changed': ['float'], },
|
||||
{ 'screen-value': ['float', 'rw'], },
|
||||
);
|
||||
}
|
||||
|
||||
_screenValue = 0;
|
||||
|
||||
// the getter has to be in snake_case
|
||||
get screen_value() { return this._screenValue; }
|
||||
|
||||
// the setter has to be in snake_case too
|
||||
set screen_value(percent) {
|
||||
percent = clamp(percent, 0, 1);
|
||||
this._screenValue = percent;
|
||||
|
||||
Utils.execAsync(`brightnessctl s ${percent * 100}% -q`)
|
||||
.then(() => {
|
||||
// signals has to be explicity emitted
|
||||
this.emit('screen-changed', percent);
|
||||
this.notify('screen-value');
|
||||
|
||||
// or use Service.changed(propName: string) which does the above two
|
||||
// this.changed('screen');
|
||||
})
|
||||
.catch(print);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
const current = Number(exec('brightnessctl g'));
|
||||
const max = Number(exec('brightnessctl m'));
|
||||
this._screenValue = current / max;
|
||||
}
|
||||
|
||||
// overwriting connectWidget method, lets you
|
||||
// change the default event that widgets connect to
|
||||
connectWidget(widget, callback, event = 'screen-changed') {
|
||||
super.connectWidget(widget, callback, event);
|
||||
}
|
||||
}
|
||||
|
||||
// the singleton instance
|
||||
const service = new BrightnessService();
|
||||
|
||||
// make it global for easy use with cli
|
||||
globalThis.brightness = service;
|
||||
|
||||
// export to use in other modules
|
||||
export default service;
|
Loading…
Add table
Add a link
Reference in a new issue