Skip to content

Commit

Permalink
Initial port
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Oct 13, 2023
1 parent ce10332 commit 8508a43
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 137 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Switchboard Sound Plug
# Sound Settings
[![Translation status](https://l10n.elementary.io/widgets/switchboard/-/switchboard-plug-sound/svg-badge.svg)](https://l10n.elementary.io/engage/switchboard/?utm_source=widget)

![screenshot](data/screenshot-output.png?raw=true)
Expand All @@ -11,7 +11,7 @@ You'll need the following dependencies:
* libgranite-dev
* libgtk-3-dev
* libpulse-dev
* libswitchboard-2.0-dev
* libswitchboard-3-dev
* meson
* valac

Expand Down
2 changes: 1 addition & 1 deletion data/icons.gresource.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/io/elementary/switchboard/sound/icons/scalable/devices/">
<gresource prefix="/io/elementary/settings/sound/icons/scalable/devices/">
<file alias="audio-speaker-center-back-testing.svg" compressed="true" preprocess="xml-stripblanks">audio-speaker-center-back-testing.svg</file>
<file alias="audio-speaker-center.svg" compressed="true" preprocess="xml-stripblanks">audio-speaker-center.svg</file>
<file alias="audio-speaker-center-testing.svg" compressed="true" preprocess="xml-stripblanks">audio-speaker-center-testing.svg</file>
Expand Down
2 changes: 1 addition & 1 deletion data/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
i18n.merge_file(
input: 'sound.metainfo.xml.in',
output: 'io.elementary.switchboard.sound.metainfo.xml',
output: meson.project_name() + '.metainfo.xml',
po_dir: meson.source_root() / 'po' / 'extra',
type: 'xml',
install: true,
Expand Down
6 changes: 3 additions & 3 deletions data/sound.metainfo.xml.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="addon">
<id>io.elementary.switchboard.sound</id>
<extends>io.elementary.switchboard</extends>
<translation type="gettext">sound-plug</translation>
<id>io.elementary.settings.sound</id>
<extends>io.elementary.settings</extends>
<translation type="gettext">io.elementary.settings.sound</translation>
<metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-2.0+</project_license>

Expand Down
7 changes: 3 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
project(
'sound',
'io.elementary.settings.sound',
'vala', 'c',
version: '2.3.3'
)

gettext_name = meson.project_name() + '-plug'
gnome = import('gnome')
i18n = import('i18n')

Expand All @@ -13,7 +12,7 @@ datadir = join_paths(prefix, get_option('datadir'))
libdir = join_paths(prefix, get_option('libdir'))

add_project_arguments(
'-DGETTEXT_PACKAGE="@0@"'.format(gettext_name),
'-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()),
language:'c'
)

Expand All @@ -30,7 +29,7 @@ plug_resources = gnome.compile_resources(

config_data = configuration_data()
config_data.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
config_data.set_quoted('GETTEXT_PACKAGE', meson.project_name() + '-plug')
config_data.set_quoted('GETTEXT_PACKAGE', meson.project_name())
config_file = configure_file(
input: 'src/Config.vala.in',
output: '@BASENAME@',
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion po/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
i18n.gettext(gettext_name,
i18n.gettext(meson.project_name(),
args: ['--directory=' + meson.source_root()],
preset: 'glib'
)
Expand Down
76 changes: 76 additions & 0 deletions src/CanberraGtk4.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2022 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/

/* code adapted from libcanberra */

namespace CanberraGtk4 {
private Canberra.Context? context = null;

public unowned Canberra.Context? context_get () {
Canberra.Proplist proplist;

if (context != null) {
return context;
} if (Canberra.Context.create (out context) != Canberra.SUCCESS) {
return null;
} if (Canberra.Proplist.create (out proplist) != Canberra.SUCCESS) {
return null;
}

unowned var name = GLib.Environment.get_application_name ();
if (name != null) {
proplist.sets (Canberra.PROP_APPLICATION_NAME, name);
} else {
proplist.sets (Canberra.PROP_APPLICATION_NAME, "libcanberra-gtk");
proplist.sets (Canberra.PROP_APPLICATION_VERSION, "%i.%i".printf (Canberra.MAJOR, Canberra.MINOR));
proplist.sets (Canberra.PROP_APPLICATION_ID, "org.freedesktop.libcanberra.gtk");
}

unowned var icon = Gtk.Window.get_default_icon_name ();
if (icon != null) {
proplist.sets (Canberra.PROP_APPLICATION_ICON_NAME, icon);
}

unowned var display = Gdk.Display.get_default ();
// if (display is Gdk.X11.Display) {
// unowned var display_name = display.get_name ();
// if (display_name != null) {
// proplist.sets (Canberra.PROP_WINDOW_X11_SCREEN, display_name);
// }

// var screen = "%i".printf (((Gdk.X11.Display) display).get_screen ().get_screen_number ());
// proplist.sets (Canberra.PROP_WINDOW_X11_SCREEN, screen);
// }

context.change_props_full (proplist);

var val = Value (typeof (string));
if (display.get_setting ("gtk-sound-theme-name", val)) {
context.change_props (Canberra.PROP_CANBERRA_XDG_THEME_NAME, val.get_string ());
}

val = Value (typeof (bool));
if (display.get_setting ("gtk-enable-event-sounds", val)) {
unowned var env = GLib.Environment.get_variable ("CANBERRA_FORCE_EVENT_SOUNDS");
context.change_props (Canberra.PROP_CANBERRA_ENABLE, env != null ? true : val.get_boolean ());
}

display.setting_changed.connect ((setting) => {
Value new_val;
if (setting == "gtk-sound-theme-name") {
new_val = Value (typeof (string));
display.get_setting ("gtk-sound-theme-name", new_val);
context.change_props (Canberra.PROP_CANBERRA_ENABLE, new_val.get_string ());
} else if (setting == "gtk-enable-event-sounds") {
new_val = Value (typeof (bool));
unowned var env = GLib.Environment.get_variable ("CANBERRA_FORCE_EVENT_SOUNDS");
display.get_setting ("gtk-enable-event-sounds", new_val);
context.change_props (Canberra.PROP_CANBERRA_ENABLE, env != null ? true : new_val.get_boolean ());
}
});

return context;
}
}
18 changes: 11 additions & 7 deletions src/DeviceRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ public class Sound.DeviceRow : Gtk.ListBoxRow {

public Device device { get; construct; }

private Gtk.RadioButton activate_radio;
private Gtk.CheckButton activate_radio;
private bool ignore_default = false;

public DeviceRow (Device device) {
Object (device: device);
}

construct {
activate_radio = new Gtk.RadioButton (null);
activate_radio = new Gtk.CheckButton ();

var image = new Gtk.Image.from_icon_name (device.icon_name, Gtk.IconSize.DND) {
var image = new Gtk.Image.from_icon_name (device.icon_name) {
pixel_size = 32,
tooltip_text = device.get_nice_form_factor (),
use_fallback = true
};
Expand All @@ -48,11 +49,14 @@ public class Sound.DeviceRow : Gtk.ListBoxRow {
};

unowned var description_style_context = description_label.get_style_context ();
description_style_context.add_class (Gtk.STYLE_CLASS_DIM_LABEL);
description_style_context.add_class (Granite.STYLE_CLASS_DIM_LABEL);
description_style_context.add_class (Granite.STYLE_CLASS_SMALL_LABEL);

var grid = new Gtk.Grid () {
margin = 6,
margin_top = 6,
margin_end = 6,
margin_bottom = 6,
margin_start = 6,
column_spacing = 12,
orientation = Gtk.Orientation.HORIZONTAL
};
Expand All @@ -61,7 +65,7 @@ public class Sound.DeviceRow : Gtk.ListBoxRow {
grid.attach (name_label, 2, 0);
grid.attach (description_label, 2, 1);

add (grid);
child = grid;

activate.connect (() => {
activate_radio.active = true;
Expand All @@ -85,7 +89,7 @@ public class Sound.DeviceRow : Gtk.ListBoxRow {
}

public void link_to_row (DeviceRow row) {
activate_radio.join_group (row.activate_radio);
activate_radio.group = row.activate_radio;
activate_radio.active = device.is_default;
}
}
6 changes: 3 additions & 3 deletions src/InputDeviceMonitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public class Sound.InputDeviceMonitor : GLib.Object {
};

var props = new PulseAudio.Proplist ();
props.sets (PulseAudio.Proplist.PROP_APPLICATION_NAME, "Switchboard sound");
props.sets (PulseAudio.Proplist.PROP_APPLICATION_ID, "org.pantheon.switchboard.plug.sound");
props.sets (PulseAudio.Proplist.PROP_APPLICATION_ICON_NAME, "multimedia-volume-control");
props.sets (PulseAudio.Proplist.PROP_APPLICATION_NAME, "Sound Settings");
props.sets (PulseAudio.Proplist.PROP_APPLICATION_ID, "io.elementary.setings.sound.sound");
props.sets (PulseAudio.Proplist.PROP_APPLICATION_ICON_NAME, "preferences-desktop-sound");
props.sets (PulseAudio.Proplist.PROP_APPLICATION_VERSION, "0.1");

steam = new PulseAudio.Stream (c, _("Peak detect"), ss, null, props);
Expand Down
21 changes: 10 additions & 11 deletions src/InputPanel.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class Sound.InputPanel : Gtk.Box {
construct {
margin_bottom = 12;

var no_device_grid = new Granite.Widgets.AlertView (
_("No Connected Audio Devices Detected"),
_("Check that all cables are securely attached and audio input devices are powered on."),
"audio-input-microphone-symbolic"
);
no_device_grid.show_all ();
var no_device_grid = new Granite.Placeholder (
_("No Connected Audio Devices Detected")
) {
description = _("Check that all cables are securely attached and audio input devices are powered on."),
icon = new ThemedIcon ("audio-input-microphone-symbolic")
};

devices_listbox = new Gtk.ListBox () {
activate_on_single_click = true,
Expand All @@ -34,7 +34,7 @@ public class Sound.InputPanel : Gtk.Box {
pam.set_default_device.begin (((Sound.DeviceRow) row).device);
});

var scrolled = new Gtk.ScrolledWindow (null, null) {
var scrolled = new Gtk.ScrolledWindow () {
child = devices_listbox
};

Expand Down Expand Up @@ -75,8 +75,8 @@ public class Sound.InputPanel : Gtk.Box {

orientation = VERTICAL;
spacing = 18;
add (devices_frame);
add (volume_grid);
append (devices_frame);
append (volume_grid);

device_monitor = new InputDeviceMonitor ();
device_monitor.update_fraction.connect ((fraction) => {
Expand Down Expand Up @@ -172,8 +172,7 @@ public class Sound.InputPanel : Gtk.Box {
device_row.link_to_row ((DeviceRow) row);
}

device_row.show_all ();
devices_listbox.add (device_row);
devices_listbox.append (device_row);
device_row.set_as_default.connect (() => {
pam.set_default_device.begin (device);
});
Expand Down
Loading

0 comments on commit 8508a43

Please sign in to comment.