Skip to content

Commit

Permalink
add DBUS server
Browse files Browse the repository at this point in the history
  • Loading branch information
Junker committed Aug 14, 2022
1 parent 1f879ae commit 06e410b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ sources = [
'src/notification.vala',
'src/config-file.vala',
'src/status-icon.vala',
'src/settings-window.vala'
'src/settings-window.vala',
'src/dbus-server.vala'
]

install_desktoppath = join_paths(get_option('datadir'), 'applications')
Expand Down
32 changes: 32 additions & 0 deletions src/dbus-server.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[DBus (name = "app.junker.mictray")]
public class DbusServer : Object
{
public bool muted {
get { return pulse.muted; }
}

public void mute()
{
pulse.mute();
}

public void unmute()
{
pulse.unmute();
}

public void toggle_mute()
{
pulse.toggle_mute();
}

public void increase_volume()
{
pulse.increase_volume();
}

public void decrease_volume()
{
pulse.decrease_volume();
}
}
12 changes: 11 additions & 1 deletion src/mictray.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,26 @@ class MicTrayApp : Gtk.Application
pulse.current_source_name = config.source_name;
}

Bus.own_name(BusType.SESSION, "app.junker.mictray", BusNameOwnerFlags.ALLOW_REPLACEMENT, on_dbus_aquired);

Gtk.main();
}

private void on_dbus_aquired(DBusConnection conn) {
try {
conn.register_object("/app/junker/mictray", new DbusServer());
} catch (IOError e) {
stderr.printf("Could not register DBUS service\n");
}
}

public MicTrayApp()
{
Object (application_id: "app.junker.mictray");
}
}

static int main (string[] args)
static int main (string[] args)
{
app = new MicTrayApp();

Expand Down
9 changes: 8 additions & 1 deletion src/pulse.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using PulseAudio;
using Gee;


public class Pulse : Object
{
public string? current_source_name = null;
Expand Down Expand Up @@ -95,6 +94,14 @@ public class Pulse : Object
context.set_source_mute_by_name(this.current_source_name, false);
}

public void toggle_mute()
{
if (this.muted)
this.unmute();
else
this.mute();
}

public void increase_volume()
{
context.get_source_info_by_name(this.current_source_name, (ctx, info, eol) =>
Expand Down
7 changes: 2 additions & 5 deletions src/status-icon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public class MicStatusIcon : StatusIcon
{
if (event.button == 1)
{
if (pulse.muted)
pulse.unmute();
else
pulse.mute();
pulse.toggle_mute();
}
else if (event.button == 2)
{
Expand Down Expand Up @@ -72,7 +69,7 @@ public class MicStatusIcon : StatusIcon
{
var about = new Gtk.AboutDialog();
about.set_logo_icon_name("microphone-sensitivity-high");
about.set_version("0.2.5");
about.set_version("0.3.0");
about.set_program_name("MicTray");
about.set_comments("Microphone control application");
about.set_copyright("Dmitry Kosenkov");
Expand Down

0 comments on commit 06e410b

Please sign in to comment.