From cecf808bcbc0ec112188cd0b0745cc964e1294f4 Mon Sep 17 00:00:00 2001 From: Allie Law Date: Thu, 17 Aug 2023 03:48:56 +0100 Subject: [PATCH] WIP: Whatever I did ages ago --- com.github.childishgiant.mixer.dev.json | 59 +++++++++++ src/appEntry.blp | 126 ++++++++---------------- src/application.vala | 11 ++- src/digest.vala | 4 +- src/pulseManager.vala | 11 +-- src/util.vala | 3 +- src/window.blp | 4 +- src/window.vala | 74 ++++++-------- 8 files changed, 143 insertions(+), 149 deletions(-) create mode 100644 com.github.childishgiant.mixer.dev.json diff --git a/com.github.childishgiant.mixer.dev.json b/com.github.childishgiant.mixer.dev.json new file mode 100644 index 0000000..f0c7b59 --- /dev/null +++ b/com.github.childishgiant.mixer.dev.json @@ -0,0 +1,59 @@ +{ + "app-id" : "com.github.childishgiant.mixer", + "runtime" : "org.gnome.Platform", + "runtime-version" : "master", + "sdk" : "org.gnome.Sdk", + "sdk-extensions" : [ + "org.freedesktop.Sdk.Extension.vala" + ], + "command" : "com.github.childishgiant.mixer", + "finish-args" : [ + "--share=ipc", + "--socket=fallback-x11", + "--socket=wayland", + "--socket=pulseaudio", + "--device=all", + "--env=G_MESSAGES_DEBUG=all" + ], + "build-options" : { + "append-path" : "/usr/lib/sdk/vala/bin", + "prepend-ld-library-path" : "/usr/lib/sdk/vala/lib" + }, + "cleanup" : [ + "/include", + "/lib/pkgconfig", + "/man", + "/share/doc", + "/share/gtk-doc", + "/share/man", + "/share/pkgconfig", + "/share/vala", + "*.la", + "*.a" + ], + "modules" : [ + { + "name" : "blueprint", + "buildsystem" : "meson", + "sources" : [ + { + "type" : "git", + "url" : "https://gitlab.gnome.org/jwestman/blueprint-compiler.git", + "tag" : "v0.6.0" + } + ] + }, + { + "name" : "mixer", + "builddir" : true, + "buildsystem" : "meson", + "sources" : [ + { + "type" : "dir", + "path" : "." + } + ] + } + ] +} + diff --git a/src/appEntry.blp b/src/appEntry.blp index e45573d..3e10ec6 100644 --- a/src/appEntry.blp +++ b/src/appEntry.blp @@ -2,100 +2,56 @@ using Gtk 4.0; using Adw 1; -template MixerAppEntry : Gtk.Grid { +template MixerAppEntry : Adw.ExpanderRow { + title: _("App Name"); - Gtk.Label name_label { - layout { - row: 0; - column: 0; - } - label: _("App Name"); - max-width-chars: 32; - ellipsize: end; + [prefix] + Gtk.Image icon { + icon-name: "applications-multimedia-symbolic"; } - Gtk.Label volume_label { - layout { - row: 0; - column: 1; - } - label: _("Volume:"); - halign: start; - } - Gtk.Scale volume_scale { - layout { - row: 0; - column: 2; - } - adjustment: Gtk.Adjustment { - page-increment: 5; - upper: 100; - lower: 0; - }; - draw-value: false; - hexpand: true; - } + [action] + Gtk.Box { + Gtk.Scale volume_scale { + adjustment: Gtk.Adjustment { + page-increment: .05; + upper: 1; + lower: 0; + }; + draw-value: false; + hexpand: true; + + } + Gtk.Button mute-button { + styles ["flat"] + valign: center; + icon-name: "audio-volume-high-symbolic"; + action-name: "mute"; - Gtk.Switch volume_switch { - layout { - row: 0; - column: 3; - } - valign: center; - } - - Gtk.Image icon { - layout { - row: 1; - column: 0; - } - icon-name: "audio-volume-high-symbolic"; - valign: start; - } - - Gtk.Label balance_label { - layout { - row: 1; - column: 1; - } - label: _("Balance:"); - halign: start; - valign: start; + } } - Gtk.Scale balance_scale { - layout { - row: 1; - column: 2; - } - adjustment: Gtk.Adjustment { - page-increment: 0.1; - upper: 1; - lower: -1; - }; - draw-value: false; - has-origin: false; - width-request: 150; - hexpand: true; + Adw.ActionRow balance_row { + title: _("Balance"); + + Gtk.Scale balance_scale { + adjustment: Gtk.Adjustment { + page-increment: 0.1; + upper: 1; + lower: -1; + }; + draw-value: false; + has-origin: false; + hexpand: true; + } } - Gtk.Label output_label { - layout { - row: 2; - column: 1; - } - label: _("Output:"); - halign: end; - } - Gtk.ComboBoxText dropdown { - layout { - row: 2; - column: 2; - } - width-request: 75; - } + Adw.ComboRow output_row { + title: _("Output"); + //model: StringList {strings [""] }; + model: StringList { strings ["test","test2"] }; + } } - diff --git a/src/application.vala b/src/application.vala index e529c6a..ed04b5c 100644 --- a/src/application.vala +++ b/src/application.vala @@ -41,7 +41,7 @@ namespace Mixer { flags: ApplicationFlags.FLAGS_NONE ); - this.add_main_option_entries(options); + this.add_main_option_entries (options); } @@ -62,8 +62,8 @@ namespace Mixer { public override void activate () { - debug("Mockup: %s".printf (mockup)); - debug(mockup == ""? "Mockup: %s".printf (mockup) : "No mockup"); + debug ("Mockup: %s".printf (mockup)); + debug (mockup == ""? "Mockup: %s".printf (mockup) : "No mockup"); if (print_version) { @@ -78,10 +78,11 @@ namespace Mixer { } // FIXME TODO mockup not working now. + // Just move it to a blp if (mockup != null) { - debug("Using mockup"); + debug ("Using mockup"); var cast_win = (Mixer.Window) win; - cast_win.populate(mockup); + cast_win.populate (mockup); return; } diff --git a/src/digest.vala b/src/digest.vala index 434581d..b53c4b2 100644 --- a/src/digest.vala +++ b/src/digest.vala @@ -20,7 +20,7 @@ public class Response : GLib.Object { public Response digest (PulseAudio.SinkInputInfo sink_input) { - // debug(sink_input.proplist.to_string()); + debug(sink_input.proplist.to_string()); Response app = new Response (); @@ -29,7 +29,7 @@ public Response digest (PulseAudio.SinkInputInfo sink_input) { debug ("Index: %d", (int)app.index); // Set name - app.name = sink_input.proplist.gets ("application.name"); + app.name = sink_input.proplist.gets ("application.name") + sink_input.proplist.gets("media.name"); debug ("\t Name: %s", app.name); // Set mute state diff --git a/src/pulseManager.vala b/src/pulseManager.vala index 1253a26..74733e5 100644 --- a/src/pulseManager.vala +++ b/src/pulseManager.vala @@ -142,7 +142,7 @@ public class PulseManager : Object { if (sink != null) { - // debug("Sink info: %s", sink.proplist.to_string()); + // debug("Sink info: %s", sink.proplist.to_string()); var sink_response = new Sink (); @@ -208,13 +208,13 @@ public class PulseManager : Object { return this.sinks; } - + private void success_cb (Context c, int success) { if (success == 0) { - debug("Failed: %s", c.errno().to_string()); + debug ("Failed: %s", c.errno( ).to_string( )); } } - + public void set_volume (Response app, Gtk.Scale balance_scale, Gtk.Scale volume_scale) { debug ("Setting volume and balance for %s (%i)", app.name, (int)app.index); @@ -225,7 +225,7 @@ public class PulseManager : Object { // Set volume debug ("Volume input: %s", volume.to_string ()); - var vol = PulseAudio.Volume.sw_from_linear (volume / 100); + var vol = PulseAudio.Volume.sw_from_linear (volume); cvol.set (app.channel_map.channels, vol); debug ("Volume: %s", vol.to_string ()); @@ -248,4 +248,3 @@ public class PulseManager : Object { } } - diff --git a/src/util.vala b/src/util.vala index 6e0e690..5c5c63f 100644 --- a/src/util.vala +++ b/src/util.vala @@ -7,5 +7,4 @@ int get_index (uint32[] arr, int val) { } } return -1; -} - +} \ No newline at end of file diff --git a/src/window.blp b/src/window.blp index 0b80010..e8d918f 100644 --- a/src/window.blp +++ b/src/window.blp @@ -26,9 +26,7 @@ template MixerWindow : Adw.ApplicationWindow { min-content-height: 120; propagate-natural-height: true; - Gtk.Box apps_grid { - orientation: vertical; - spacing: 6; + Adw.PreferencesGroup apps_grid { margin-top: 6; margin-bottom: 6; // Side margins to make scrolling easier diff --git a/src/window.vala b/src/window.vala index c48a840..6aff210 100644 --- a/src/window.vala +++ b/src/window.vala @@ -17,25 +17,15 @@ */ [GtkTemplate (ui = "/com/github/childishgiant/mixer/appEntry.ui")] -public class Mixer.AppEntry : Gtk.Grid { - [GtkChild] - public unowned Gtk.Label name_label; - [GtkChild] - public unowned Gtk.Label volume_label; +public class Mixer.AppEntry : Adw.ExpanderRow { [GtkChild] public unowned Gtk.Scale volume_scale; [GtkChild] - public unowned Gtk.Switch volume_switch; - [GtkChild] public unowned Gtk.Image icon; [GtkChild] - public unowned Gtk.Label balance_label; - [GtkChild] public unowned Gtk.Scale balance_scale; [GtkChild] - public unowned Gtk.Label output_label; - [GtkChild] - public unowned Gtk.ComboBoxText dropdown; + public unowned Adw.ComboRow output_row; } @@ -45,15 +35,14 @@ public class Mixer.AppEntry : Gtk.Grid { public class Mixer.Window : Adw.ApplicationWindow { [GtkChild] - private unowned Gtk.Box apps_grid; + private unowned Adw.PreferencesGroup apps_grid; private const int ONE_APP_HEIGHT = 117; - private const int SEPERATOR_HEIGHT = 13; public PulseManager pulse_manager; Response[] responses; Sink[] sinks; private uint32[] current_ids = {}; - private Adw.StatusPage no_apps = new Adw.StatusPage(); + private Adw.StatusPage no_apps = new Adw.StatusPage (); public Window (Gtk.Application app) { Object ( @@ -94,11 +83,11 @@ public class Mixer.Window : Adw.ApplicationWindow { } }); - present(); + present (); } - public void populate(string mockup = "", Response[]? _apps = null, Sink[]? _outputs = null) { + public void populate (string mockup = "", Response[]? _apps = null, Sink[]? _outputs = null) { debug ("Populate called"); @@ -176,18 +165,18 @@ public class Mixer.Window : Adw.ApplicationWindow { // If the mockup is invalid if (new_apps.length == 0) { - apps_grid.append ( new Gtk.Label ("Unknown mockup: " + mockup) { + apps_grid.add ( new Gtk.Label ("Unknown mockup: " + mockup) { vexpand = true, hexpand = true }); } } - apps_grid.append (no_apps); + apps_grid.add (no_apps); // If no apps are using audio if (new_apps.length == 0 && mockup == "" && to_update.length == 0) { // Add no apps message - apps_grid.append (no_apps); + apps_grid.add (no_apps); } else { @@ -206,7 +195,11 @@ public class Mixer.Window : Adw.ApplicationWindow { var app_widget = new Mixer.AppEntry (); // TODO Maybe show the ID if there are duplicate names - app_widget.name_label.label = app.name.to_string (); + app_widget.set_title(app.name.to_string ()); + + if (app.icon != "application-default-icon") { + app_widget.icon.icon_name = app.icon; + } // Add marks to balance slider app_widget.balance_scale.add_mark (-1, Gtk.PositionType.BOTTOM, _("Left")); @@ -216,7 +209,7 @@ public class Mixer.Window : Adw.ApplicationWindow { app_widget.balance_scale.set_value (app.balance); // Set volume slider to app's value - app.widget.volume_scale.set_value (app.balance) + app_widget.volume_scale.set_value (app.volume); // Make the volume slider function app_widget.volume_scale.value_changed.connect (() => { @@ -224,27 +217,25 @@ public class Mixer.Window : Adw.ApplicationWindow { }); // Set mute switch - app_widget.volume_switch.active = !app.muted; + //app_widget.volume_switch.active = !app.muted; // Make the mute switch function - app_widget.volume_switch.notify["active"].connect (() => { - pulse_manager.set_mute (app, !app_widget.volume_switch.active); - }); + //app_widget.volume_switch.notify["active"].connect (() => { + // pulse_manager.set_mute (app, !app_widget.volume_switch.active); + //}); // Make the switch disable the sliders - app_widget.volume_switch.bind_property ("active", app_widget.volume_scale, "sensitive", BindingFlags.SYNC_CREATE); + //app_widget.volume_switch.bind_property ("active", app_widget.volume_scale, "sensitive", BindingFlags.SYNC_CREATE); // If the app's in mono if (app.is_mono) { // Disable inputs on balance slider app_widget.balance_scale.sensitive = false; - // Also grey out the label - app_widget.balance_label.sensitive = false; // Give it a tooltip explaining this - app_widget.balance_scale.set_tooltip_text(_("This app is using mono audio")); + app_widget.balance_scale.set_tooltip_text( _("This app is using mono audio")); } else { // If not, make the switch toggle its input - app_widget.volume_switch.bind_property ("active", app_widget.balance_scale, "sensitive", BindingFlags.SYNC_CREATE); + //app_widget.volume_switch.bind_property ("active", app_widget.balance_scale, "sensitive", BindingFlags.SYNC_CREATE); // Make the balance slider function app_widget.balance_scale.value_changed.connect (() => { @@ -262,31 +253,22 @@ public class Mixer.Window : Adw.ApplicationWindow { for (int j = 0; j < outputs.length; j++) { var sink = outputs[j]; - app_widget.dropdown.append_text ("%s - %s".printf (sink.port_name, sink.port_description)); + // app_widget.dropdown.append_text ("%s - %s".printf (sink.port_name, sink.port_description)); // If this is the current output if (app.sink == sink.index) { - app_widget.dropdown.set_active (j); + // app_widget.dropdown.set_active (j); } } // Make the dropdown function - app_widget.dropdown.changed.connect (() => { - pulse_manager.move (app, outputs[app_widget.dropdown.active]); - }); + //app_widget.dropdown.changed.connect (() => { + // pulse_manager.move (app, outputs[app_widget.dropdown.active]); + //}); - // If this isn't the first app - if (i > 0 || to_update.length > 0) { - - // Add a separator above this app - var sep = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); - // TODO give the separator an id so I can remove it - debug ("Adding separator"); - apps_grid.append (sep); - } // Add this to the app grid - apps_grid.append(app_widget); + apps_grid.add( app_widget); }; }