diff options
author | Bartosz Jaroszewski <b.jarosze@gmail.com> | 2020-05-17 00:06:21 +0200 |
---|---|---|
committer | Bartosz Jaroszewski <b.jarosze@gmail.com> | 2020-05-17 00:06:21 +0200 |
commit | c54485722f91a53298849bff2e819c551fb93587 (patch) | |
tree | 6677ce7f7a778ea94e7eb60ca0645b8c41f959a2 | |
parent | 77f1f7685c9b82b9bdaf9359e123afb12210b22b (diff) |
add option to keep menu after toggling
-rw-r--r-- | Settings.ui | 42 | ||||
-rw-r--r-- | extension.js | 6 | ||||
-rw-r--r-- | prefs.js | 3 | ||||
-rw-r--r-- | schemas/org.gnome.shell.extensions.bluetooth-quick-connect.gschema.xml | 4 | ||||
-rw-r--r-- | ui.js | 17 |
5 files changed, 72 insertions, 0 deletions
diff --git a/Settings.ui b/Settings.ui index 047b045..39a2b12 100644 --- a/Settings.ui +++ b/Settings.ui @@ -232,6 +232,48 @@ SPDX-License-Identifier: GPL-2.0-or-later </child> </object> </child> + <child> + <object class="GtkListBoxRow"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <child> + <object class="GtkGrid"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_left">12</property> + <property name="margin_right">12</property> + <property name="margin_top">12</property> + <property name="margin_bottom">12</property> + <property name="column_spacing">32</property> + <child> + <object class="GtkSwitch" id="keep_menu_on_toggle"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="halign">end</property> + <property name="valign">center</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="keep_menu_on_toggle_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="label" translatable="yes">Keep the menu open after toggling the connection</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + </packing> + </child> + </object> + </child> + </object> + </child> </object> </child> <child type="label_item"> diff --git a/extension.js b/extension.js index 33de925..503535b 100644 --- a/extension.js +++ b/extension.js @@ -105,6 +105,7 @@ class BluetoothQuickConnect { this._connectSignal(this._menu, 'open-state-changed', (menu, isOpen) => { if (isOpen && this._autoPowerOnEnabled()) this._proxy.BluetoothAirplaneMode = false; + this._sync(); }); this._connectSignal(this._model, 'row-changed', () => this._sync()); @@ -198,6 +199,7 @@ class BluetoothQuickConnect { _addDevicesToMenu() { this._getPairedDevices().forEach((device) => { + device.item.isEmitActivatedEnabled = !this._keepMenuOnToggle(); this._menu.addMenuItem(device.item, 1); }); } @@ -232,6 +234,10 @@ class BluetoothQuickConnect { _autoPowerOffCheckingInterval() { return this._settings.get_int('bluetooth-auto-power-off-interval'); } + + _keepMenuOnToggle() { + return this._settings.get_boolean('keep-menu-on-toggle'); + } } let bluetoothQuickConnect = null; @@ -64,6 +64,9 @@ class SettingsBuilder { let autoPowerOffInterval = this._builder.get_object('auto_power_off_interval'); this._settings.bind('bluetooth-auto-power-off-interval', autoPowerOffInterval, 'value', Gio.SettingsBindFlags.DEFAULT); + + let keepMenuOnToggle = this._builder.get_object('keep_menu_on_toggle'); + this._settings.bind('keep-menu-on-toggle', keepMenuOnToggle, 'active', Gio.SettingsBindFlags.DEFAULT); } } diff --git a/schemas/org.gnome.shell.extensions.bluetooth-quick-connect.gschema.xml b/schemas/org.gnome.shell.extensions.bluetooth-quick-connect.gschema.xml index 684af11..60887ca 100644 --- a/schemas/org.gnome.shell.extensions.bluetooth-quick-connect.gschema.xml +++ b/schemas/org.gnome.shell.extensions.bluetooth-quick-connect.gschema.xml @@ -18,5 +18,9 @@ SPDX-License-Identifier: GPL-2.0-or-later <default>60</default> <summary>Checking interval for power off idling bluetooth</summary> </key> + <key name="keep-menu-on-toggle" type="b"> + <default>false</default> + <summary>Keep the menu open after toggling the connection</summary> + </key> </schema> </schemalist> @@ -27,6 +27,7 @@ var PopupSwitchWithButtonMenuItem = GObject.registerClass( this.label.x_expand = true; this._statusBin.x_expand = false; + this.isEmitActivatedEnabled = true; if (icon) { this.insert_child_at_index( @@ -71,9 +72,25 @@ var PopupSwitchWithButtonMenuItem = GObject.registerClass( button.connect('clicked', () => { this.emit('clicked'); + if (this.isEmitActivatedEnabled) + this.emit('activate', Clutter.get_current_event()); }); return button; } + + activate(event) { + if (this._switch.mapped) + this.toggle(); + + // we allow pressing space to toggle the switch + // without closing the menu + if (event.type() == Clutter.EventType.KEY_PRESS && + event.get_key_symbol() == Clutter.KEY_space) + return; + + if (this.isEmitActivatedEnabled) + this.emit('activate', event); + } } ); |