Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ shared_module(
'src/Widgets/PlayerList.vala',
'src/Widgets/DeviceManagerWidget.vala',
'src/Widgets/DeviceItem.vala',
'src/Services/PulseAudioManager.vala',
'src/Services/MprisClient.vala',
'src/Services/Volume-control.vala',
'src/Services/Manager.vala',
'src/Services/DBus.vala',
'src/Services/Device.vala',
'src/Services/Manager.vala',
'src/Services/MediaPlayer.vala',
'src/Services/MprisClient.vala',
'src/Services/PulseAudioManager.vala',
'src/Services/Volume-control.vala',
gresource,
dependencies: [
dependency('glib-2.0'),
Expand Down
42 changes: 42 additions & 0 deletions src/Services/DBus.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2023 elementary, Inc. <https://elementary.io>
* SPDX-License-Identifier: GPL-3.0-or-later
*/

[DBus (name = "io.elementary.wingpanel.sound")]
public class Sound.DBus : GLib.Object {
[DBus (visible = false)]
public signal void on_handle_osd ();

private static GLib.Once<Sound.DBus> instance;

[DBus (visible = false)]
public static Sound.DBus get_default () {
return instance.once (() => {
return new Sound.DBus ();
});
}

private DBus () {
Object ();
}

[DBus (visible = false)]
public static void init () {
Bus.own_name (SESSION, "io.elementary.wingpanel.sound", NONE,
(connection) => {
try {
connection.register_object ("/io/elementary/wingpanel/sound", get_default ());
} catch (Error e) {
warning (e.message);
}
},
() => {},
() => warning ("Could not acquire name")
);
}

public void handle_osd () throws DBusError, IOError {
on_handle_osd ();
}
}
28 changes: 16 additions & 12 deletions src/Widgets/DisplayWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class DisplayWidget : Gtk.Box {
public signal void volume_press_event (Gdk.EventButton e);
public signal void mic_press_event (Gdk.EventButton e);

private Gtk.Revealer volume_levelbar_revealer;
private uint volume_timeout = 0;

construct {
Expand All @@ -42,7 +43,7 @@ public class DisplayWidget : Gtk.Box {
};
volume_levelbar.get_style_context ().add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

var volume_levelbar_revealer = new Gtk.Revealer () {
volume_levelbar_revealer = new Gtk.Revealer () {
child = volume_levelbar,
reveal_child = false,
transition_type = SLIDE_LEFT
Expand Down Expand Up @@ -119,19 +120,22 @@ public class DisplayWidget : Gtk.Box {
}
});

notify["volume"].connect (() => {
if (volume_timeout != 0) {
Source.remove (volume_timeout);
volume_timeout = 0;
}
Sound.DBus.init ();
Sound.DBus.get_default ().on_handle_osd.connect (show_volume_levelbar);
}

volume_levelbar_revealer.reveal_child = true;
public void show_volume_levelbar () {
if (volume_timeout != 0) {
Source.remove (volume_timeout);
volume_timeout = 0;
}

if (volume_timeout == 0) {
volume_timeout = Timeout.add_seconds (1, () => {
volume_levelbar_revealer.reveal_child = false;
});
}
volume_levelbar_revealer.reveal_child = true;

volume_timeout = Timeout.add_seconds (1, () => {
volume_levelbar_revealer.reveal_child = false;
volume_timeout = 0;
return Source.REMOVE;
});
}
}