Fixes #46 - Battery and Volume percentage values are now rounded to the nearest whole rather than down. (#52)
This commit is contained in:
@@ -35,7 +35,7 @@ const Volume = () => {
|
|||||||
|
|
||||||
const volPct = Widget.Label({
|
const volPct = Widget.Label({
|
||||||
vpack: "center",
|
vpack: "center",
|
||||||
label: audio.speaker.bind("volume").as((v) => `${Math.floor(v * 100)}%`),
|
label: audio.speaker.bind("volume").as((v) => `${Math.round(v * 100)}%`),
|
||||||
class_name: "bar-button-label volume",
|
class_name: "bar-button-label volume",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,65 +2,65 @@ const audio = await Service.import("audio");
|
|||||||
import { getIcon } from '../utils.js';
|
import { getIcon } from '../utils.js';
|
||||||
|
|
||||||
const renderActiveInput = () => {
|
const renderActiveInput = () => {
|
||||||
return [
|
return [
|
||||||
Widget.Box({
|
|
||||||
class_name: "menu-slider-container input",
|
|
||||||
children: [
|
|
||||||
Widget.Button({
|
|
||||||
vexpand: false,
|
|
||||||
vpack: "end",
|
|
||||||
setup: (self) => {
|
|
||||||
self.hook(audio, () => {
|
|
||||||
const mic = audio.microphone;
|
|
||||||
const className = `menu-active-button input ${mic.is_muted ? "muted" : ""}`;
|
|
||||||
return (self.class_name = className);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
on_primary_click: () =>
|
|
||||||
(audio.microphone.is_muted = !audio.microphone.is_muted),
|
|
||||||
child: Widget.Icon({
|
|
||||||
class_name: "menu-active-icon input",
|
|
||||||
setup: (self) => {
|
|
||||||
self.hook(audio, () => {
|
|
||||||
self.icon = getIcon(
|
|
||||||
audio.microphone.volume,
|
|
||||||
audio.microphone.is_muted,
|
|
||||||
)["mic"];
|
|
||||||
});
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
Widget.Box({
|
Widget.Box({
|
||||||
vertical: true,
|
class_name: "menu-slider-container input",
|
||||||
children: [
|
children: [
|
||||||
Widget.Label({
|
Widget.Button({
|
||||||
class_name: "menu-active input",
|
vexpand: false,
|
||||||
hpack: "start",
|
vpack: "end",
|
||||||
truncate: "end",
|
setup: (self) => {
|
||||||
wrap: true,
|
self.hook(audio, () => {
|
||||||
label: audio.bind("microphone").as((v) => v.description || ""),
|
const mic = audio.microphone;
|
||||||
}),
|
const className = `menu-active-button input ${mic.is_muted ? "muted" : ""}`;
|
||||||
Widget.Slider({
|
return (self.class_name = className);
|
||||||
value: audio.microphone.bind("volume").as((v) => v),
|
});
|
||||||
class_name: "menu-active-slider menu-slider inputs",
|
},
|
||||||
draw_value: false,
|
on_primary_click: () =>
|
||||||
hexpand: true,
|
(audio.microphone.is_muted = !audio.microphone.is_muted),
|
||||||
min: 0,
|
child: Widget.Icon({
|
||||||
max: 1,
|
class_name: "menu-active-icon input",
|
||||||
onChange: ({ value }) => (audio.microphone.volume = value),
|
setup: (self) => {
|
||||||
}),
|
self.hook(audio, () => {
|
||||||
],
|
self.icon = getIcon(
|
||||||
|
audio.microphone.volume,
|
||||||
|
audio.microphone.is_muted,
|
||||||
|
)["mic"];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
Widget.Box({
|
||||||
|
vertical: true,
|
||||||
|
children: [
|
||||||
|
Widget.Label({
|
||||||
|
class_name: "menu-active input",
|
||||||
|
hpack: "start",
|
||||||
|
truncate: "end",
|
||||||
|
wrap: true,
|
||||||
|
label: audio.bind("microphone").as((v) => v.description || ""),
|
||||||
|
}),
|
||||||
|
Widget.Slider({
|
||||||
|
value: audio.microphone.bind("volume").as((v) => v),
|
||||||
|
class_name: "menu-active-slider menu-slider inputs",
|
||||||
|
draw_value: false,
|
||||||
|
hexpand: true,
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
onChange: ({ value }) => (audio.microphone.volume = value),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
Widget.Label({
|
||||||
|
class_name: "menu-active-percentage input",
|
||||||
|
vpack: "end",
|
||||||
|
label: audio.microphone
|
||||||
|
.bind("volume")
|
||||||
|
.as((v) => `${Math.round(v * 100)}%`),
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
Widget.Label({
|
];
|
||||||
class_name: "menu-active-percentage input",
|
|
||||||
vpack: "end",
|
|
||||||
label: audio.microphone
|
|
||||||
.bind("volume")
|
|
||||||
.as((v) => `${Math.floor(v * 100)}%`),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { renderActiveInput };
|
export { renderActiveInput };
|
||||||
|
|||||||
@@ -2,66 +2,66 @@ const audio = await Service.import("audio");
|
|||||||
import { getIcon } from "../utils.js";
|
import { getIcon } from "../utils.js";
|
||||||
|
|
||||||
const renderActivePlayback = () => {
|
const renderActivePlayback = () => {
|
||||||
return [
|
return [
|
||||||
Widget.Box({
|
|
||||||
class_name: "menu-slider-container playback",
|
|
||||||
children: [
|
|
||||||
Widget.Button({
|
|
||||||
vexpand: false,
|
|
||||||
vpack: "end",
|
|
||||||
setup: (self) => {
|
|
||||||
self.hook(audio, () => {
|
|
||||||
const spkr = audio.speaker;
|
|
||||||
const className = `menu-active-button playback ${spkr.is_muted ? "muted" : ""}`;
|
|
||||||
return (self.class_name = className);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
on_primary_click: () =>
|
|
||||||
(audio.speaker.is_muted = !audio.speaker.is_muted),
|
|
||||||
child: Widget.Icon({
|
|
||||||
class_name: "menu-active-icon playback",
|
|
||||||
setup: (self) => {
|
|
||||||
self.hook(audio, () => {
|
|
||||||
self.icon = getIcon(
|
|
||||||
audio.speaker.volume,
|
|
||||||
audio.speaker.is_muted,
|
|
||||||
)["spkr"];
|
|
||||||
});
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
Widget.Box({
|
Widget.Box({
|
||||||
vertical: true,
|
class_name: "menu-slider-container playback",
|
||||||
children: [
|
children: [
|
||||||
Widget.Label({
|
Widget.Button({
|
||||||
class_name: "menu-active playback",
|
vexpand: false,
|
||||||
hpack: "start",
|
vpack: "end",
|
||||||
truncate: "end",
|
setup: (self) => {
|
||||||
expand: true,
|
self.hook(audio, () => {
|
||||||
wrap: true,
|
const spkr = audio.speaker;
|
||||||
label: audio.bind("speaker").as((v) => v.description || ""),
|
const className = `menu-active-button playback ${spkr.is_muted ? "muted" : ""}`;
|
||||||
}),
|
return (self.class_name = className);
|
||||||
Widget.Slider({
|
});
|
||||||
value: audio["speaker"].bind("volume"),
|
},
|
||||||
class_name: "menu-active-slider menu-slider playback",
|
on_primary_click: () =>
|
||||||
draw_value: false,
|
(audio.speaker.is_muted = !audio.speaker.is_muted),
|
||||||
hexpand: true,
|
child: Widget.Icon({
|
||||||
min: 0,
|
class_name: "menu-active-icon playback",
|
||||||
max: 1,
|
setup: (self) => {
|
||||||
onChange: ({ value }) => (audio.speaker.volume = value),
|
self.hook(audio, () => {
|
||||||
}),
|
self.icon = getIcon(
|
||||||
],
|
audio.speaker.volume,
|
||||||
|
audio.speaker.is_muted,
|
||||||
|
)["spkr"];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
Widget.Box({
|
||||||
|
vertical: true,
|
||||||
|
children: [
|
||||||
|
Widget.Label({
|
||||||
|
class_name: "menu-active playback",
|
||||||
|
hpack: "start",
|
||||||
|
truncate: "end",
|
||||||
|
expand: true,
|
||||||
|
wrap: true,
|
||||||
|
label: audio.bind("speaker").as((v) => v.description || ""),
|
||||||
|
}),
|
||||||
|
Widget.Slider({
|
||||||
|
value: audio["speaker"].bind("volume"),
|
||||||
|
class_name: "menu-active-slider menu-slider playback",
|
||||||
|
draw_value: false,
|
||||||
|
hexpand: true,
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
onChange: ({ value }) => (audio.speaker.volume = value),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
Widget.Label({
|
||||||
|
vpack: "end",
|
||||||
|
class_name: "menu-active-percentage playback",
|
||||||
|
label: audio.speaker
|
||||||
|
.bind("volume")
|
||||||
|
.as((v) => `${Math.round(v * 100)}%`),
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
Widget.Label({
|
];
|
||||||
vpack: "end",
|
|
||||||
class_name: "menu-active-percentage playback",
|
|
||||||
label: audio.speaker
|
|
||||||
.bind("volume")
|
|
||||||
.as((v) => `${Math.floor(v * 100)}%`),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { renderActivePlayback };
|
export { renderActivePlayback };
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ const Brightness = () => {
|
|||||||
class_name: "brightness-slider-label",
|
class_name: "brightness-slider-label",
|
||||||
label: brightness
|
label: brightness
|
||||||
.bind("screen")
|
.bind("screen")
|
||||||
.as((b) => `${Math.floor(b * 100)}%`),
|
.as((b) => `${Math.round(b * 100)}%`),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ export const OSDLabel = (ort: OSDOrientation) => {
|
|||||||
vpack: "center",
|
vpack: "center",
|
||||||
setup: self => {
|
setup: self => {
|
||||||
self.hook(brightness, () => {
|
self.hook(brightness, () => {
|
||||||
self.label = `${Math.floor(brightness.screen * 100)}`;
|
self.label = `${Math.round(brightness.screen * 100)}`;
|
||||||
}, "notify::screen")
|
}, "notify::screen")
|
||||||
self.hook(brightness, () => {
|
self.hook(brightness, () => {
|
||||||
self.label = `${Math.floor(brightness.kbd * 100)}`;
|
self.label = `${Math.round(brightness.kbd * 100)}`;
|
||||||
}, "notify::kbd")
|
}, "notify::kbd")
|
||||||
self.hook(audio, () => {
|
self.hook(audio, () => {
|
||||||
self.toggleClassName("overflow", audio.speaker.volume > 1)
|
self.toggleClassName("overflow", audio.speaker.volume > 1)
|
||||||
self.label = `${Math.floor(audio.speaker.volume * 100)}`;
|
self.label = `${Math.round(audio.speaker.volume * 100)}`;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class Brightness extends Service {
|
|||||||
if (percent > 1)
|
if (percent > 1)
|
||||||
percent = 1
|
percent = 1
|
||||||
|
|
||||||
sh(`brightnessctl set ${Math.floor(percent * 100)}% -q`).then(() => {
|
sh(`brightnessctl set ${Math.round(percent * 100)}% -q`).then(() => {
|
||||||
this.#screen = percent
|
this.#screen = percent
|
||||||
this.changed("screen")
|
this.changed("screen")
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user