Added mediaplayer widget

This commit is contained in:
Pascal Thuma committed 2026-03-24 20:01:44 +01:00
1 parent 434128e6e1
commit 8954e05d39
3 files changed
+144 -6

No files matched your search

+37 -3
View File
@@ -10,8 +10,8 @@ window.Bar {
> centerbox { > centerbox {
background: $bg-color; background: $bg-color;
border-radius: 10px; border-radius: 10px;
margin: 8px; margin: 4px 8px; // Reduced vertical margin
padding: 4px 12px; padding: 0 12px; // Removed vertical padding
} }
.left-box, .left-box,
@@ -28,7 +28,7 @@ window.Bar {
.workspaces { .workspaces {
.workspace-btn { .workspace-btn {
min-width: 24px; min-width: 24px;
min-height: 24px; min-height: 24px; // Control height exactly here
padding: 0 4px; padding: 0 4px;
border-radius: 6px; border-radius: 6px;
background: transparent; background: transparent;
@@ -39,4 +39,38 @@ window.Bar {
} }
} }
} }
.clock-btn {
padding: 0 12px; // Reduced vertical padding
min-height: 24px;
}
.media-btn {
padding: 0 8px;
min-height: 24px;
.media-art {
border-radius: 4px;
-gtk-icon-size: 32px;
}
}
.system-tray {
background: rgba(150, 150, 150, 0.15); // Unified background for the tray
border-radius: 8px;
padding: 0 4px; // Reduced vertical padding
margin: 2px;
.tray-item {
padding: 2px 4px; // Reduced vertical padding
margin: 0;
background: transparent;
border: none;
box-shadow: none;
image {
-gtk-icon-size: 16px;
}
}
}
} }
+11 -3
View File
@@ -1,6 +1,8 @@
import app from "ags/gtk4/app" import app from "ags/gtk4/app"
import { Astal, Gtk, Gdk } from "ags/gtk4" import { Astal, Gtk, Gdk } from "ags/gtk4"
import Workspaces from "./Workspaces" import Workspaces from "./Workspaces"
import { Clock, SysTray } from "./System"
import Media from "./Media"
function Left() { function Left() {
return ( return (
@@ -12,8 +14,14 @@ function Left() {
function Center() { function Center() {
return ( return (
<box $type="center" halign={Gtk.Align.CENTER} cssClasses={["center-box"]}> <box
<label label="Center Widget Area" /> $type="center"
halign={Gtk.Align.CENTER}
cssClasses={["center-box"]}
spacing={8}
>
<Media />
<Clock />
</box> </box>
) )
} }
@@ -21,7 +29,7 @@ function Center() {
function Right() { function Right() {
return ( return (
<box $type="end" halign={Gtk.Align.END} cssClasses={["right-box"]}> <box $type="end" halign={Gtk.Align.END} cssClasses={["right-box"]}>
<label label="Right Widget Area" /> <SysTray />
</box> </box>
) )
} }
+96
View File
@@ -0,0 +1,96 @@
import { Gtk } from "ags/gtk4"
import AstalMpris from "gi://AstalMpris?version=0.1"
import { createBinding, With, onCleanup } from "ags"
export default function Media() {
const mpris = AstalMpris.Mpris.get_default()
return (
<box cssClasses={["media-container"]}>
<With value={createBinding(mpris, "players")}>
{(players: any[]) => {
if (!players || players.length === 0) {
return <box />
}
// We render all players but manage their visibility manually.
return (
<box
$={(box) => {
const updateVisibility = () => {
let hasPlaying = false
for (const player of players) {
if (
player.playback_status ===
AstalMpris.PlaybackStatus.PLAYING
) {
hasPlaying = true
break
}
}
let first = true
let child = box.get_first_child()
for (const player of players) {
if (!child) break
if (hasPlaying) {
child.set_visible(
player.playback_status ===
AstalMpris.PlaybackStatus.PLAYING,
)
} else {
child.set_visible(first)
first = false
}
child = child.get_next_sibling()
}
}
const connections = players.map((p) =>
p.connect("notify::playback-status", updateVisibility),
)
updateVisibility()
// Cleanup connections when this component is unmounted
onCleanup(() => {
players.forEach((p, i) => {
try {
p.disconnect(connections[i])
} catch (e) {}
})
})
}}
>
{players.map((player) => (
<button
cssClasses={["media-btn"]}
onClicked={() =>
console.log("Expand Media Controls - Phase 7")
}
>
<box spacing={8} valign={Gtk.Align.CENTER}>
{/* Fallback to an icon if cover-art is empty */}
<image
cssClasses={["media-art"]}
file={createBinding(player, "cover-art")}
iconName="audio-x-generic-symbolic"
/>
<label
cssClasses={["media-title"]}
label={createBinding(player, "title")}
maxWidthChars={25}
wrap={false}
ellipsize={3} // Pango.EllipsizeMode.END
/>
</box>
</button>
))}
</box>
)
}}
</With>
</box>
)
}