play/pause
This commit is contained in:
parent
672767a31e
commit
202f94f122
1 changed files with 38 additions and 15 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
import { bind, derive, Variable } from "astal";
|
import { bind, derive, Variable } from "astal";
|
||||||
|
import { Gdk } from "astal/gtk4";
|
||||||
import AstalMpris from "gi://AstalMpris";
|
import AstalMpris from "gi://AstalMpris";
|
||||||
|
import { Mathf } from "../util/Mathf";
|
||||||
|
|
||||||
function IntegerToMinuteSeconds(value: number) {
|
function IntegerToMinuteSeconds(value: number) {
|
||||||
const minutes = Math.floor(value / 60);
|
const minutes = Math.floor(value / 60);
|
||||||
|
|
@ -12,8 +14,9 @@ function FormatLabel(player: {
|
||||||
artist: string;
|
artist: string;
|
||||||
position: number;
|
position: number;
|
||||||
length: number;
|
length: number;
|
||||||
|
status: AstalMpris.PlaybackStatus;
|
||||||
}) {
|
}) {
|
||||||
return `${player.title} - ${player.artist} [${IntegerToMinuteSeconds(player.position)}/${IntegerToMinuteSeconds(player.length)}]`;
|
return `${player.status === AstalMpris.PlaybackStatus.PLAYING ? "" : ""} ${player.title} - ${player.artist} [${IntegerToMinuteSeconds(player.position)}/${IntegerToMinuteSeconds(player.length)}]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Mpris = function () {
|
const Mpris = function () {
|
||||||
|
|
@ -33,6 +36,24 @@ const Mpris = function () {
|
||||||
const activePlayer = players[index];
|
const activePlayer = players[index];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<button
|
||||||
|
cursor={Gdk.Cursor.new_from_name("pointer", null)}
|
||||||
|
onClicked={() =>
|
||||||
|
activePlayer.playbackStatus ===
|
||||||
|
AstalMpris.PlaybackStatus.PLAYING
|
||||||
|
? activePlayer.pause()
|
||||||
|
: activePlayer.play()
|
||||||
|
}
|
||||||
|
onScroll={(_, __, dy) => {
|
||||||
|
activeIndex.set(
|
||||||
|
Mathf.clamp(
|
||||||
|
activeIndex.get() - Mathf.sign(dy),
|
||||||
|
0,
|
||||||
|
players.length - 1,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<label
|
<label
|
||||||
label={bind(
|
label={bind(
|
||||||
derive(
|
derive(
|
||||||
|
|
@ -41,12 +62,14 @@ const Mpris = function () {
|
||||||
bind(activePlayer, "artist"),
|
bind(activePlayer, "artist"),
|
||||||
bind(activePlayer, "position"),
|
bind(activePlayer, "position"),
|
||||||
bind(activePlayer, "length"),
|
bind(activePlayer, "length"),
|
||||||
|
bind(activePlayer, "playback_status"),
|
||||||
],
|
],
|
||||||
(title, artist, position, length) =>
|
(title, artist, position, length, status) =>
|
||||||
FormatLabel({ title, artist, position, length }),
|
FormatLabel({ title, artist, position, length, status }),
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
</button>
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue