WIP: Show active device
Signed-off-by: Vasiliy Doylov <nekocwd@mainlining.org>
This commit is contained in:
parent
475e40e70d
commit
c687581f14
5 changed files with 106 additions and 5 deletions
71
src/logic/pulse.vala
Normal file
71
src/logic/pulse.vala
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,5 +24,6 @@ int main (string[] args) {
|
||||||
Intl.textdomain (Config.GETTEXT_PACKAGE);
|
Intl.textdomain (Config.GETTEXT_PACKAGE);
|
||||||
|
|
||||||
var app = new Callpipe.Application ();
|
var app = new Callpipe.Application ();
|
||||||
|
CallPipe.Logic.Pulse.instance.init ();
|
||||||
return app.run (args);
|
return app.run (args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,16 @@ callpipe_sources = [
|
||||||
'main.vala',
|
'main.vala',
|
||||||
'application.vala',
|
'application.vala',
|
||||||
'window.vala',
|
'window.vala',
|
||||||
|
'logic/pulse.vala',
|
||||||
]
|
]
|
||||||
|
|
||||||
callpipe_deps = [
|
callpipe_deps = [
|
||||||
config_dep,
|
config_dep,
|
||||||
dependency('gtk4'),
|
dependency('gtk4'),
|
||||||
dependency('libadwaita-1', version: '>= 1.4'),
|
dependency('libadwaita-1', version: '>= 1.4'),
|
||||||
|
dependency('libpulse'),
|
||||||
|
dependency('libpulse-mainloop-glib'),
|
||||||
|
dependency('libpulse-simple'),
|
||||||
]
|
]
|
||||||
|
|
||||||
blueprints = custom_target(
|
blueprints = custom_target(
|
||||||
|
|
|
@ -18,12 +18,36 @@ template $CallpipeWindow: Adw.ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content: Label label {
|
content: ScrolledWindow {
|
||||||
label: _("Hello, World!");
|
Adw.Clamp {
|
||||||
|
margin-end: 12;
|
||||||
|
margin-start: 12;
|
||||||
|
valign: center;
|
||||||
|
halign: center;
|
||||||
|
|
||||||
styles [
|
Box {
|
||||||
"title-1",
|
orientation: vertical;
|
||||||
]
|
spacing: 12;
|
||||||
|
|
||||||
|
Label {
|
||||||
|
label: _("Output:");
|
||||||
|
|
||||||
|
styles [
|
||||||
|
"title-1",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
Label label {
|
||||||
|
wrap: true;
|
||||||
|
wrap-mode: char;
|
||||||
|
label: _("FIXME?");
|
||||||
|
|
||||||
|
styles [
|
||||||
|
"title-2",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,5 +25,6 @@ public class Callpipe.Window : Adw.ApplicationWindow {
|
||||||
|
|
||||||
public Window (Gtk.Application app) {
|
public Window (Gtk.Application app) {
|
||||||
Object (application: app);
|
Object (application: app);
|
||||||
|
CallPipe.Logic.Pulse.instance.bind_property ("active-name", label, "label", BindingFlags.DEFAULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue