Skip to content

Commit

Permalink
Add media label
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Aug 26, 2023
1 parent 441d346 commit 58c57de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
30 changes: 20 additions & 10 deletions src/AppRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

public class Sound.AppRow : Gtk.Grid {
private App? app;
private Gtk.Label title_label;
private Gtk.Label app_name_label;
private Gtk.Label media_name_label;
private Gtk.Image image;
private Gtk.Button icon_button;
private Gtk.Scale volume_scale;
Expand All @@ -18,12 +19,19 @@ public class Sound.AppRow : Gtk.Grid {
pixel_size = 32
};

title_label = new Gtk.Label ("") {
ellipsize = Pango.EllipsizeMode.END,
valign = Gtk.Align.END,
app_name_label = new Gtk.Label ("") {
ellipsize = END,
valign = END,
xalign = 0
};
title_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
app_name_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);

media_name_label = new Gtk.Label ("") {
ellipsize = END,
valign = END,
xalign = 0
};
media_name_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);

icon_button = new Gtk.Button.from_icon_name ("audio-volume-muted") {
can_focus = false
Expand All @@ -47,10 +55,11 @@ public class Sound.AppRow : Gtk.Grid {
margin_bottom = 6;
margin_start = 6;

attach (image, 0, 0, 1, 2);
attach (title_label, 1, 0, 2);
attach (icon_button, 1, 1);
attach (volume_scale, 2, 1);
attach (image, 0, 0, 1, 3);
attach (app_name_label, 1, 0, 2);
attach (media_name_label, 1, 1, 2);
attach (icon_button, 1, 2);
attach (volume_scale, 2, 2);
attach (mute_switch, 3, 0, 1, 2);

volume_scale.change_value.connect ((type, new_value) => {
Expand Down Expand Up @@ -78,6 +87,7 @@ public class Sound.AppRow : Gtk.Grid {
}

private void update () {
media_name_label.label = app.media_name;
volume_scale.set_value (app.volume);
mute_switch.state = !app.muted;
volume_scale.sensitive = !app.muted;
Expand All @@ -96,7 +106,7 @@ public class Sound.AppRow : Gtk.Grid {
public void bind_app (App app) {
this.app = app;

title_label.label = app.display_name;
app_name_label.label = app.display_name;
image.set_from_gicon (app.icon, Gtk.IconSize.DND);

app.notify["volume"].connect (update);
Expand Down
5 changes: 2 additions & 3 deletions src/PulseAudioManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,8 @@ public class Sound.PulseAudioManager : GLib.Object {
apps.append (app);
}

if (!app.channel_map.equal (sink_input.channel_map)) {
app.channel_map = sink_input.channel_map;
}
app.media_name = sink_input.name;
app.channel_map = sink_input.channel_map;

if ((sink_input.mute != 0) != app.muted) {
app.muted = sink_input.mute != 0;
Expand Down

0 comments on commit 58c57de

Please sign in to comment.