Skip to content

Commit 1f15edb

Browse files
committed
feat: add button to reset all applications to the default output
Closes: #77
1 parent d991ee3 commit 1f15edb

4 files changed

+115
-47
lines changed

extension.ts

+47-1
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616

1717
import Clutter from 'gi://Clutter';
1818
import type Gio from 'gi://Gio';
19+
import GLib from 'gi://GLib';
1920
import GObject from 'gi://GObject';
21+
import Gvc from 'gi://Gvc';
2022
import St from 'gi://St';
2123

22-
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
24+
import { gettext as _, Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
2325
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
2426
import { MediaSection } from 'resource:///org/gnome/shell/ui/mpris.js';
2527
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
2628
import { QuickSettingsMenu } from 'resource:///org/gnome/shell/ui/quickSettings.js';
29+
import * as Volume from 'resource:///org/gnome/shell/ui/status/volume.js';
2730

2831
import { LibPanel, Panel } from './libs/libpanel/main.js';
2932
import { update_settings } from './libs/preferences.js';
33+
import { get_pactl_path } from './libs/utils.js';
3034
import { ApplicationsMixer, ApplicationsMixerToggle, AudioProfileSwitcher, BalanceSlider, idle_ids, SinkMixer, wait_property } from './libs/widgets.js';
3135

3236
const DateMenu = Main.panel.statusArea.dateMenu;
@@ -70,6 +74,18 @@ export default class QSAP extends Extension {
7074
);
7175
this.settings.emit('changed::master-volume-sliders-show-current-device', 'master-volume-sliders-show-current-device');
7276

77+
this._scabaortd_callback = this.settings.connect(
78+
'changed::add-button-applications-output-reset-to-default',
79+
() => {
80+
if (this.settings.get_boolean('add-button-applications-output-reset-to-default')) {
81+
this._add_reset_applications_output();
82+
} else {
83+
this._remove_reset_applications_output();
84+
}
85+
}
86+
);
87+
this.settings.emit('changed::add-button-applications-output-reset-to-default', 'add-button-applications-output-reset-to-default');
88+
7389
this._master_volumes = [];
7490
this._sc_callback = this.settings.connect('changed', (_, name) => {
7591
if (name !== "autohide-profile-switcher") {
@@ -84,6 +100,9 @@ export default class QSAP extends Extension {
84100
this._unpatch_show_current_device(OutputVolumeSlider);
85101
this._unpatch_show_current_device(this.InputVolumeSlider);
86102

103+
this.settings.disconnect(this._scabaortd_callback);
104+
this._remove_reset_applications_output();
105+
87106
this.settings.disconnect(this._scasis_callback);
88107
this.settings.disconnect(this._sc_callback);
89108
for (const id of idle_ids) {
@@ -454,4 +473,31 @@ export default class QSAP extends Extension {
454473
delete slider._iconButton._qsap_y_align;
455474
delete slider._menuButton._qsap_y_expand;
456475
}
476+
477+
_add_reset_applications_output() {
478+
this._action_application_reset_output = OutputVolumeSlider.menu.addAction(_("Reset all applications to default output"), () => {
479+
const control = Volume.getMixerControl();
480+
481+
for (const stream of control.get_streams()) {
482+
if (stream.is_event_stream || !(stream instanceof Gvc.MixerSinkInput)) {
483+
continue;
484+
}
485+
486+
GLib.spawn_command_line_async(`${get_pactl_path(this.settings)[0]} move-sink-input ${stream.index} @DEFAULT_SINK@`);
487+
}
488+
489+
if (this._applications_mixer) {
490+
for (const slider of this._applications_mixer._slider_manager._sliders.values()) {
491+
slider._checkUsedSink()
492+
}
493+
}
494+
});
495+
}
496+
497+
_remove_reset_applications_output() {
498+
if (this._action_application_reset_output) {
499+
this._action_application_reset_output.destroy();
500+
}
501+
delete this._action_application_reset_output;
502+
}
457503
}

po/example.pot

+59-46
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-02-22 11:55+0100\n"
11+
"POT-Creation-Date: 2025-02-22 13:19+0100\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -17,6 +17,10 @@ msgstr ""
1717
"Content-Type: text/plain; charset=CHARSET\n"
1818
"Content-Transfer-Encoding: 8bit\n"
1919

20+
#: dist/extension.js:407
21+
msgid "Reset all applications to default output"
22+
msgstr ""
23+
2024
#: dist/prefs.js:25
2125
msgid "Where the panel should be"
2226
msgstr ""
@@ -70,203 +74,212 @@ msgid "Show the currently selected device for the main volume sliders"
7074
msgstr ""
7175

7276
#: dist/prefs.js:57
73-
msgid "Do not apply custom CSS"
77+
msgid "Add a button to reset all applications to the default output"
7478
msgstr ""
7579

7680
#: dist/prefs.js:58
77-
msgid "Disable the CSS in this extension that could override your theme"
81+
msgid ""
82+
"This button can be found in the device chooser of the main output slider"
7883
msgstr ""
7984

8085
#: dist/prefs.js:61
86+
msgid "Do not apply custom CSS"
87+
msgstr ""
88+
89+
#: dist/prefs.js:62
90+
msgid "Disable the CSS in this extension that could override your theme"
91+
msgstr ""
92+
93+
#: dist/prefs.js:65
8194
msgid "Path to the <tt>pactl</tt> executable"
8295
msgstr ""
8396

84-
#: dist/prefs.js:66
97+
#: dist/prefs.js:70
8598
msgid "Auto-hide"
8699
msgstr ""
87100

88-
#: dist/prefs.js:67
101+
#: dist/prefs.js:71
89102
msgid "Hide the profile switcher when the current device only has one profile"
90103
msgstr ""
91104

92-
#: dist/prefs.js:71
105+
#: dist/prefs.js:75
93106
msgid "Move media controls"
94107
msgstr ""
95108

96-
#: dist/prefs.js:72
109+
#: dist/prefs.js:76
97110
msgid ""
98111
"Move the media controls from the notifications panel instead of creating a "
99112
"new one"
100113
msgstr ""
101114

102-
#: dist/prefs.js:76
115+
#: dist/prefs.js:80
103116
msgid "Put the sliders in submenu"
104117
msgstr ""
105118

106-
#: dist/prefs.js:77
119+
#: dist/prefs.js:81
107120
msgid ""
108121
"<span color=\"darkorange\" weight=\"bold\">This will disable the ability to "
109122
"change the output device per application</span>"
110123
msgstr ""
111124

112-
#: dist/prefs.js:81
125+
#: dist/prefs.js:85
113126
msgid "Elements order"
114127
msgstr ""
115128

116-
#: dist/prefs.js:82
129+
#: dist/prefs.js:86
117130
msgid "Reorder elements in the new panel"
118131
msgstr ""
119132

120-
#: dist/prefs.js:86
133+
#: dist/prefs.js:90
121134
msgid "Profile switcher"
122135
msgstr ""
123136

124-
#: dist/prefs.js:87
137+
#: dist/prefs.js:91
125138
msgid "Allows you to quickly change the audio profile of the current device"
126139
msgstr ""
127140

128-
#: dist/prefs.js:92
141+
#: dist/prefs.js:96
129142
msgid "Speaker / Headphone volume slider"
130143
msgstr ""
131144

132-
#: dist/prefs.js:95
145+
#: dist/prefs.js:99
133146
msgid "Per-device volume sliders"
134147
msgstr ""
135148

136-
#: dist/prefs.js:98
149+
#: dist/prefs.js:102
137150
msgid "Audio balance slider"
138151
msgstr ""
139152

140-
#: dist/prefs.js:101
153+
#: dist/prefs.js:105
141154
msgid "Microphone volume slider"
142155
msgstr ""
143156

144-
#: dist/prefs.js:104
157+
#: dist/prefs.js:108
145158
msgid "Media controls"
146159
msgstr ""
147160

148-
#: dist/prefs.js:108
161+
#: dist/prefs.js:112
149162
msgid "Applications mixer"
150163
msgstr ""
151164

152-
#: dist/prefs.js:114
165+
#: dist/prefs.js:118
153166
msgid "The same sliders you can find in pavucontrol or in the sound settings"
154167
msgstr ""
155168

156-
#: dist/prefs.js:116
169+
#: dist/prefs.js:120
157170
msgid ""
158171
"<span color=\"darkorange\" weight=\"bold\"><tt>pactl</tt> was not found, you "
159172
"won't be able to change the output device per application</span>"
160173
msgstr ""
161174

162-
#: dist/prefs.js:121
175+
#: dist/prefs.js:125
163176
msgid ""
164177
"This slider allows you to change the balance of the current audio output"
165178
msgstr ""
166179

167-
#: dist/prefs.js:126
180+
#: dist/prefs.js:130
168181
msgid ""
169182
"<span color=\"red\" weight=\"bold\">This feature needs <tt>pactl</tt></span>"
170183
msgstr ""
171184

172-
#: dist/prefs.js:144
185+
#: dist/prefs.js:148
173186
msgid "Per-device sliders filtering"
174187
msgstr ""
175188

176-
#: dist/prefs.js:145
189+
#: dist/prefs.js:149
177190
msgid ""
178191
"Allows you to filter the per-device volume sliders. The content of the "
179192
"filters are <b>regexes</b> and are applied to the device's display name and "
180193
"pulseaudio name."
181194
msgstr ""
182195

183-
#: dist/prefs.js:146
196+
#: dist/prefs.js:150
184197
msgid "Device name"
185198
msgstr ""
186199

187-
#: dist/prefs.js:150
200+
#: dist/prefs.js:154
188201
msgid "Application mixer filtering"
189202
msgstr ""
190203

191-
#: dist/prefs.js:151
204+
#: dist/prefs.js:155
192205
msgid ""
193206
"Allows you to filter the applications that show up in the application mixer "
194207
"<b>using regexes</b>"
195208
msgstr ""
196209

197-
#: dist/prefs.js:152
210+
#: dist/prefs.js:156
198211
msgid "Application name"
199212
msgstr ""
200213

201-
#: dist/prefs.js:166
214+
#: dist/prefs.js:170
202215
msgid "LibPanel settings"
203216
msgstr ""
204217

205-
#: dist/prefs.js:167
218+
#: dist/prefs.js:171
206219
msgid ""
207220
"These settings are not specific to this extension, they apply to every panel"
208221
msgstr ""
209222

210-
#: dist/prefs.js:170
223+
#: dist/prefs.js:174
211224
msgid "Single-column mode"
212225
msgstr ""
213226

214-
#: dist/prefs.js:171
227+
#: dist/prefs.js:175
215228
msgid ""
216229
"Only one column of panels will be allowed. Also prevents the panel from "
217230
"being put at the left/right of the screen by libpanel."
218231
msgstr ""
219232

220-
#: dist/prefs.js:174
233+
#: dist/prefs.js:178
221234
msgid "Panel alignment"
222235
msgstr ""
223236

224-
#: dist/prefs.js:176
237+
#: dist/prefs.js:180
225238
msgid "Left"
226239
msgstr ""
227240

228-
#: dist/prefs.js:177
241+
#: dist/prefs.js:181
229242
msgid "Right"
230243
msgstr ""
231244

232-
#: dist/prefs.js:181
245+
#: dist/prefs.js:185
233246
msgid "Padding"
234247
msgstr ""
235248

236-
#: dist/prefs.js:182
249+
#: dist/prefs.js:186
237250
msgid "Use this to override the default padding of the panels"
238251
msgstr ""
239252

240-
#: dist/prefs.js:185
253+
#: dist/prefs.js:189
241254
msgid "Row spacing"
242255
msgstr ""
243256

244-
#: dist/prefs.js:186
257+
#: dist/prefs.js:190
245258
msgid "Use this to override the default row spacing of the panels"
246259
msgstr ""
247260

248-
#: dist/prefs.js:189
261+
#: dist/prefs.js:193
249262
msgid "Column spacing"
250263
msgstr ""
251264

252-
#: dist/prefs.js:190
265+
#: dist/prefs.js:194
253266
msgid "Use this to override the default column spacing of the panels"
254267
msgstr ""
255268

256-
#: dist/prefs.js:275
269+
#: dist/prefs.js:279
257270
msgid "Filtering mode"
258271
msgstr ""
259272

260-
#: dist/prefs.js:276
273+
#: dist/prefs.js:280
261274
msgid ""
262275
"On blocklist mode, matching elements are removed from the list. On allowlist "
263276
"mode, only matching elements will be shown"
264277
msgstr ""
265278

266-
#: dist/prefs.js:278
279+
#: dist/prefs.js:282
267280
msgid "Blocklist"
268281
msgstr ""
269282

270-
#: dist/prefs.js:279
283+
#: dist/prefs.js:283
271284
msgid "Allowlist"
272285
msgstr ""

prefs.ts

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ export default class QSAPPreferences extends ExtensionPreferences {
7272
title: _("Show the currently selected device for the main volume sliders"),
7373
}
7474
);
75+
main_group.add_switch("add-button-applications-output-reset-to-default",
76+
{
77+
title: _("Add a button to reset all applications to the default output"),
78+
subtitle: _("This button can be found in the device chooser of the main output slider")
79+
}
80+
);
7581

7682
main_group.add_switch("ignore-css",
7783
{

schemas/org.gnome.shell.extensions.quick-settings-audio-panel.gschema.xml

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<key name="master-volume-sliders-show-current-device" type="b">
3131
<default>false</default>
3232
</key>
33+
<key name="add-button-applications-output-reset-to-default" type="b">
34+
<default>false</default>
35+
</key>
3336

3437
<key name="ignore-css" type="b">
3538
<default>false</default>

0 commit comments

Comments
 (0)