perf(ags): add throttle to brightness slider
This commit is contained in:
parent
bb6c5c1781
commit
cd38ec8c10
1 changed files with 32 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
const { Box, Slider, Label, Icon } = ags.Widget;
|
const { Box, Slider, Label, Icon, EventBox } = ags.Widget;
|
||||||
const { Audio } = ags.Service;
|
const { Audio } = ags.Service;
|
||||||
const { exec } = ags.Utils;
|
const { exec } = ags.Utils;
|
||||||
|
|
||||||
|
@ -10,6 +10,18 @@ const items = {
|
||||||
0: 'audio-volume-muted-symbolic',
|
0: 'audio-volume-muted-symbolic',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let throttleTimer;
|
||||||
|
|
||||||
|
const throttle = (callback, time) => {
|
||||||
|
if (throttleTimer) return;
|
||||||
|
throttleTimer = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
callback();
|
||||||
|
throttleTimer = false;
|
||||||
|
}, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const SliderBox = Box({
|
export const SliderBox = Box({
|
||||||
className: 'slider-box',
|
className: 'slider-box',
|
||||||
vertical: true,
|
vertical: true,
|
||||||
|
@ -64,12 +76,25 @@ export const SliderBox = Box({
|
||||||
icon: 'display-brightness-symbolic',
|
icon: 'display-brightness-symbolic',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
Slider({
|
EventBox({
|
||||||
value: `${exec('brightnessctl get') / 2.55}`,
|
onHover: box => box.child._canChange = false,
|
||||||
onChange: "brightnessctl set {}%",
|
onHoverLost: box => box.child._canChange = true,
|
||||||
min: 0,
|
child: Slider({
|
||||||
max: 100,
|
properties: [
|
||||||
draw_value: false,
|
['canChange', true],
|
||||||
|
],
|
||||||
|
onChange: ({ value }) => {
|
||||||
|
throttle(() => exec('brightnessctl set ' + value + ' %'), 20);
|
||||||
|
},
|
||||||
|
connections: [[1000, slider => {
|
||||||
|
if (slider._canChange) {
|
||||||
|
slider.value = exec('brightnessctl get');
|
||||||
|
}
|
||||||
|
}]],
|
||||||
|
min: 0,
|
||||||
|
max: 255,
|
||||||
|
draw_value: false,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue