diff --git a/src/logic/pulse.vala b/src/logic/pulse.vala new file mode 100644 index 0000000..dbebb31 --- /dev/null +++ b/src/logic/pulse.vala @@ -0,0 +1,71 @@ +using PulseAudio; +class CallPipe.Logic.Pulse : Object { + private GLibMainLoop p_loop = new GLibMainLoop (); + private Context context; + public string active_name { get; private set; } + construct { + context = new Context (p_loop.get_api (), Config.GETTEXT_PACKAGE); + context.set_state_callback (on_context_state_changed); + context.set_subscribe_callback (on_subscribe_callback); + this.context.connect (null, PulseAudio.Context.Flags.NOFAIL, null); + } + public void init () { + } + + private void on_subscribe_callback (Context c, Context.SubscriptionEventType t, uint32 idx) { + get_default_device (); + } + + private void on_context_state_changed (PulseAudio.Context ctx) { + switch (ctx.get_state ()) { + case Context.State.UNCONNECTED: + message ("PulseAudio state: UNCONNECTED"); + break; + case Context.State.CONNECTING: + message ("PulseAudio state: CONNECTING"); + break; + case Context.State.AUTHORIZING: + message ("PulseAudio state: AUTHORIZING"); + break; + case Context.State.SETTING_NAME: + message ("PulseAudio state: SETTING_NAME"); + break; + case Context.State.FAILED: + message ("PulseAudio state: FAILED"); + break; + case Context.State.TERMINATED: + message ("PulseAudio state: TERMINATED"); + break; + + case Context.State.READY: + message ("PulseAudio state: READY"); + context.subscribe ( + Context.SubscriptionMask.SINK + | Context.SubscriptionMask.SOURCE + | Context.SubscriptionMask.SINK_INPUT + | Context.SubscriptionMask.SOURCE_OUTPUT); + get_default_device (); + break; + } + } + + public void get_default_device () { + context.get_server_info ((ctx, info) => { + ctx.get_sink_info_by_name (info.default_sink_name, (ctx, i, eol) => { + if (eol == -1 || i == null) { + return; + } + active_name = "%s:%s".printf (i.description, i.active_port->name); + }); + }); + } + + private static Pulse _instance = null; + public static Pulse instance { + get { + if (_instance == null) + _instance = new Pulse (); + return _instance; + } + } +} diff --git a/src/main.vala b/src/main.vala index 9625957..a5c0fcb 100644 --- a/src/main.vala +++ b/src/main.vala @@ -24,5 +24,6 @@ int main (string[] args) { Intl.textdomain (Config.GETTEXT_PACKAGE); var app = new Callpipe.Application (); + CallPipe.Logic.Pulse.instance.init (); return app.run (args); } diff --git a/src/meson.build b/src/meson.build index 247e36b..b6bac1c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,12 +2,16 @@ callpipe_sources = [ 'main.vala', 'application.vala', 'window.vala', + 'logic/pulse.vala', ] callpipe_deps = [ config_dep, dependency('gtk4'), dependency('libadwaita-1', version: '>= 1.4'), + dependency('libpulse'), + dependency('libpulse-mainloop-glib'), + dependency('libpulse-simple'), ] blueprints = custom_target( diff --git a/src/window.blp b/src/window.blp index 1e40479..b60fcbe 100644 --- a/src/window.blp +++ b/src/window.blp @@ -18,12 +18,36 @@ template $CallpipeWindow: Adw.ApplicationWindow { } } - content: Label label { - label: _("Hello, World!"); + content: ScrolledWindow { + Adw.Clamp { + margin-end: 12; + margin-start: 12; + valign: center; + halign: center; - styles [ - "title-1", - ] + Box { + orientation: vertical; + spacing: 12; + + Label { + label: _("Output:"); + + styles [ + "title-1", + ] + } + + Label label { + wrap: true; + wrap-mode: char; + label: _("FIXME?"); + + styles [ + "title-2", + ] + } + } + } }; }; } diff --git a/src/window.vala b/src/window.vala index 5755177..944c7d3 100644 --- a/src/window.vala +++ b/src/window.vala @@ -25,5 +25,6 @@ public class Callpipe.Window : Adw.ApplicationWindow { public Window (Gtk.Application app) { Object (application: app); + CallPipe.Logic.Pulse.instance.bind_property ("active-name", label, "label", BindingFlags.DEFAULT); } }