From 0fbf4aa619dfb02566095278487984f6dedf7712 Mon Sep 17 00:00:00 2001 From: pancakes
Date: Tue, 26 Aug 2025 13:34:11 +1000 Subject: [PATCH] Check for new songs --- DeltatuneWls/Program.cs | 44 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/DeltatuneWls/Program.cs b/DeltatuneWls/Program.cs index 84b7a42..f404a4b 100644 --- a/DeltatuneWls/Program.cs +++ b/DeltatuneWls/Program.cs @@ -1,4 +1,5 @@ using Gio; +using GLib; using Gtk; using ZwlrLayerShell; using Application = Gtk.Application; @@ -9,11 +10,31 @@ if (!LayerShell.IsSupported()) return 255; } +ApplicationWindow? window = null; + var application = Application.New("gay.pancakes.deltatune_wls", Gio.ApplicationFlags.FlagsNone); +GLib.Functions.TimeoutAdd(GLib.Constants.PRIORITY_DEFAULT, 500, () => +{ + if (window == null) return true; + + var playerctl = Subprocess.New(["playerctl", "metadata", "--format", "{{ title }}"], + SubprocessFlags.StdoutPipe | SubprocessFlags.StderrSilence); + + var pipe = playerctl.GetStdoutPipe(); + if (pipe == null) return true; + + var stdout = DataInputStream.New(pipe); + var line = stdout.ReadLineUtf8(out UIntPtr length, null); + + window.ActivateAction("new_song", Variant.NewString(line?.Trim() ?? "")); + + return true; +}); + application.OnActivate += (sender, eventArgs) => { - var window = ApplicationWindow.New((Application)sender); + window = ApplicationWindow.New((Application)sender); LayerShell.InitForWindow(window); LayerShell.SetNamespace(window, "deltatune-wls"); @@ -22,6 +43,27 @@ application.OnActivate += (sender, eventArgs) => LayerShell.SetAnchor(window, Edge.Top, true); LayerShell.SetMargin(window, 15); + var label = Label.New(null); + label.Halign = Align.Start; + + window.SetChild(label); + + window.OnDestroy += (widget, args1) => application.Quit(); + + var action = SimpleAction.NewStateful("new_song", VariantType.String, Variant.NewString("")); + action.OnActivate += (simpleAction, signalArgs) => + { + var title = simpleAction.GetState()!.GetString(out _); + var newTitle = signalArgs.Parameter!.GetString(out _); + + if (newTitle != title) + { + simpleAction.SetState(signalArgs.Parameter); + label.SetLabel($"♪ - {newTitle}"); + } + }; + window.AddAction(action); + window.Present(); };