osds: config show value

This commit is contained in:
2 * r + 2 * t 2025-01-16 12:14:22 +11:00
parent d2457db2c3
commit f2945d0715
2 changed files with 26 additions and 19 deletions

View file

@ -28,11 +28,13 @@ export const osds = {
position: Astal.WindowAnchor.RIGHT, position: Astal.WindowAnchor.RIGHT,
margin: 20, margin: 20,
hideDelay: 1500, hideDelay: 1500,
showValue: true,
}, },
brightness: { brightness: {
position: Astal.WindowAnchor.LEFT, position: Astal.WindowAnchor.LEFT,
margin: 20, margin: 20,
hideDelay: 1500, hideDelay: 1500,
showValue: true,
}, },
}; };

View file

@ -131,26 +131,30 @@ const SliderOsd = ({
cr.setAntialias(cairo.Antialias.BEST); cr.setAntialias(cairo.Antialias.BEST);
// Progress number, at top/right // Progress number, at top/right
const numLayout = parent.create_pango_layout(String(Math.round(progressValue * 100))); let nw = 0;
const [nw, nh] = numLayout.get_pixel_size(); let nh = 0;
let diff; if (config[type].showValue) {
if (vertical) { const numLayout = parent.create_pango_layout(String(Math.round(progressValue * 100)));
diff = ((1 - progressValue) * height) / nh; [nw, nh] = numLayout.get_pixel_size();
cr.moveTo((width - nw) / 2, radius / 2); let diff;
} else { if (vertical) {
diff = ((1 - progressValue) * width) / nw; diff = ((1 - progressValue) * height) / nh;
cr.moveTo(width - nw - radius, (height - nh) / 2); cr.moveTo((width - nw) / 2, radius / 2);
} else {
diff = ((1 - progressValue) * width) / nw;
cr.moveTo(width - nw - radius, (height - nh) / 2);
}
diff = Math.max(0, Math.min(1, diff));
cr.setSourceRGBA(
mix(bg.red, fg.red, diff),
mix(bg.green, fg.green, diff),
mix(bg.blue, fg.blue, diff),
mix(bg.alpha, fg.alpha, diff)
);
PangoCairo.show_layout(cr, numLayout);
} }
diff = Math.max(0, Math.min(1, diff));
cr.setSourceRGBA(
mix(bg.red, fg.red, diff),
mix(bg.green, fg.green, diff),
mix(bg.blue, fg.blue, diff),
mix(bg.alpha, fg.alpha, diff)
);
PangoCairo.show_layout(cr, numLayout);
// Progress icon, follows progress // Progress icon, follows progress
if (fontDesc === null) { if (fontDesc === null) {
@ -168,6 +172,7 @@ const SliderOsd = ({
iconLayout.set_text(icon.get(), -1); iconLayout.set_text(icon.get(), -1);
const [iw, ih] = iconLayout.get_pixel_size(); const [iw, ih] = iconLayout.get_pixel_size();
let diff;
if (vertical) { if (vertical) {
diff = (progressValue * height) / ih; diff = (progressValue * height) / ih;
cr.moveTo( cr.moveTo(