Skip to content

Commit 2ee5fc6

Browse files
committed
Add keyboard shortcut to toggle global bypass
1 parent 4e66767 commit 2ee5fc6

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

[email protected]/extension.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ const EEPSIndicator = GObject.registerClass(
6464
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
6565
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
6666
() => this._loadNext('input'));
67+
Main.wm.addKeybinding(
68+
'toggle-global-bypass',
69+
this.settings,
70+
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
71+
Shell.ActionMode.NORMAL | Shell.ActionMode.OVERVIEW | Shell.ActionMode.POPUP,
72+
() => this._toggleGlobalBypass());
6773

6874
this._icon = new St.Icon({style_class: 'system-status-icon'});
6975
this._icon.gicon = Gio.icon_new_for_string(
@@ -76,6 +82,14 @@ const EEPSIndicator = GObject.registerClass(
7682
this._refreshMenu();
7783
}
7884

85+
async _toggleGlobalBypass() {
86+
await this._refreshMenu();
87+
this._enableGlobalBypass(!this.enableBypass);
88+
await this._refreshMenu();
89+
if (!this.menu.isOpen)
90+
this.menu.toggle();
91+
}
92+
7993
_loadNext(presetType) {
8094
let nextPreset;
8195
if (presetType === 'output') {
@@ -570,6 +584,7 @@ export default class EEPSExtension extends Extension {
570584
}
571585
Main.wm.removeKeybinding('cycle-output-presets');
572586
Main.wm.removeKeybinding('cycle-input-presets');
587+
Main.wm.removeKeybinding('toggle-global-bypass');
573588
this._indicator.destroy();
574589
this._indicator = null;
575590
this._settings = null;

[email protected]/preferences/prefsPage.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export var EEPSPrefsPage = GObject.registerClass(
2323

2424
// Shortcut group
2525
// --------------
26-
let resetShortcutsButton = new Gtk.Button({
26+
this.resetShortcutsButton = new Gtk.Button({
2727
icon_name: 'view-refresh-symbolic',
2828
valign: Gtk.Align.CENTER,
2929
css_classes: ['destructive-action'],
@@ -32,7 +32,7 @@ export var EEPSPrefsPage = GObject.registerClass(
3232
});
3333
let shortcutGroup = new Adw.PreferencesGroup({
3434
title: _('Keyboard Shortcuts'),
35-
header_suffix: resetShortcutsButton,
35+
header_suffix: this.resetShortcutsButton,
3636
});
3737

3838
// Cycle Output Presets Keyboard shortcut
@@ -49,38 +49,51 @@ export var EEPSPrefsPage = GObject.registerClass(
4949
_('Cycle Input Presets'),
5050
_('Keyboard shortcut to cycle through input presets')
5151
);
52+
// Toggle Global Bypass Keyboard shortcut
53+
this.toggleBypassRow = new ShortcutRow(
54+
this._settings,
55+
'toggle-global-bypass',
56+
_('Toggle Global Bypass'),
57+
_('Keyboard shortcut to toggle global bypass')
58+
);
5259

5360
// Hide/Show delete button
54-
if (!(this.outputShortcutRow.isAcceleratorChanged() || this.inputShortcutRow.isAcceleratorChanged()))
55-
resetShortcutsButton.visible = false;
61+
if (!this._isAnyAcceleratorChanged())
62+
this.resetShortcutsButton.visible = false;
5663

5764

5865
// Add elements
5966
shortcutGroup.add(this.outputShortcutRow);
6067
shortcutGroup.add(this.inputShortcutRow);
68+
shortcutGroup.add(this.toggleBypassRow);
6169
this.add(shortcutGroup);
6270

6371

6472
// Bind signals
6573
// --------------
66-
resetShortcutsButton.connect('clicked', this._resetShortcuts.bind(this));
67-
this._settings.connect('changed::cycle-output-presets', () => {
68-
if (this.outputShortcutRow.isAcceleratorChanged() || this.inputShortcutRow.isAcceleratorChanged())
69-
resetShortcutsButton.visible = true;
70-
else
71-
resetShortcutsButton.visible = false;
72-
});
73-
this._settings.connect('changed::cycle-input-presets', () => {
74-
if (this.outputShortcutRow.isAcceleratorChanged() || this.inputShortcutRow.isAcceleratorChanged())
75-
resetShortcutsButton.visible = true;
76-
else
77-
resetShortcutsButton.visible = false;
78-
});
74+
this.resetShortcutsButton.connect('clicked', this._resetShortcuts.bind(this));
75+
this._settings.connect('changed::cycle-output-presets', this._changeResetButtonVisibility.bind(this));
76+
this._settings.connect('changed::cycle-input-presets', this._changeResetButtonVisibility.bind(this));
77+
this._settings.connect('changed::toggle-global-bypass', this._changeResetButtonVisibility.bind(this));
78+
}
79+
80+
_changeResetButtonVisibility() {
81+
if (this._isAnyAcceleratorChanged())
82+
this.resetShortcutsButton.visible = true;
83+
else
84+
this.resetShortcutsButton.visible = false;
85+
}
86+
87+
_isAnyAcceleratorChanged() {
88+
return this.outputShortcutRow.isAcceleratorChanged() ||
89+
this.inputShortcutRow.isAcceleratorChanged() ||
90+
this.toggleBypassRow.isAcceleratorChanged();
7991
}
8092

8193
_resetShortcuts() {
8294
this.outputShortcutRow.resetAccelerator();
8395
this.inputShortcutRow.resetAccelerator();
96+
this.toggleBypassRow.resetAccelerator();
8497
}
8598
});
8699

[email protected]/schemas/org.gnome.shell.extensions.eepresetselector.gschema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@
1212
<summary>Cycle through input presets shortcut key</summary>
1313
<description>Sets the cycle-input-presets shortcut key.</description>
1414
</key>
15+
<key name="toggle-global-bypass" type="as">
16+
<default><![CDATA[['<Control><Super>b']]]></default>
17+
<summary>Toggle global bypass shortcut key</summary>
18+
<description>Sets the shortcut key for toggling global bypass feature.</description>
19+
</key>
1520
</schema>
1621
</schemalist>

0 commit comments

Comments
 (0)