From 55ee9d0fff71c14c4c3e5cc946bb0dacb60da1a9 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Sat, 15 Feb 2025 19:29:46 -0500 Subject: [PATCH] Add option to show hotkeys overlay on secondary monitors gh-2237 --- ...shell.extensions.dash-to-panel.gschema.xml | 4 ++ src/overview.js | 30 ++++++-- src/panelManager.js | 2 +- src/prefs.js | 7 ++ src/taskbar.js | 19 ++++-- ui/BoxOverlayShortcut.ui | 68 ++++++++++--------- 6 files changed, 83 insertions(+), 47 deletions(-) diff --git a/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml b/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml index 0b611de..54bca26 100644 --- a/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml +++ b/schemas/org.gnome.shell.extensions.dash-to-panel.gschema.xml @@ -871,6 +871,10 @@ Prefix to use for hotkeys You can choose between Super or SuperAlt as the prefix for hotkeys. + + false + Show overlay on secondary monitors + false Show window previews diff --git a/src/overview.js b/src/overview.js index 2fe21e2..a315414 100644 --- a/src/overview.js +++ b/src/overview.js @@ -46,9 +46,10 @@ const T1 = 'swipeEndTimeout' const T2 = 'numberOverlayTimeout' export const Overview = class { - constructor() { + constructor(panelManager) { this._injectionManager = new InjectionManager() this._numHotkeys = 10 + this._panelManager = panelManager } enable(primaryPanel) { @@ -373,7 +374,7 @@ export const Overview = class { this._hotKeysEnabled = true if (SETTINGS.get_string('hotkeys-overlay-combo') === 'ALWAYS') - this.taskbar.toggleHotkeysNumberOverlay(true) + this._toggleHotkeysNumberOverlay(true) } _disableHotKeys() { @@ -418,7 +419,7 @@ export const Overview = class { this._hotKeysEnabled = false - this.taskbar.toggleHotkeysNumberOverlay(false) + this._toggleHotkeysNumberOverlay(false) } _optionalNumberOverlay() { @@ -435,8 +436,8 @@ export const Overview = class { SETTINGS.get_boolean('hot-keys') && SETTINGS.get_string('hotkeys-overlay-combo') === 'ALWAYS' ) - this.taskbar.toggleHotkeysNumberOverlay(true) - else this.taskbar.toggleHotkeysNumberOverlay(false) + this._toggleHotkeysNumberOverlay(true) + else this._toggleHotkeysNumberOverlay(false) }, ], [SETTINGS, 'changed::shortcut-num-keys', () => this._resetHotkeys()], @@ -468,7 +469,7 @@ export const Overview = class { if (hotkey_option === 'NEVER') return if (hotkey_option === 'TEMPORARILY' || overlayFromShortcut) - this.taskbar.toggleHotkeysNumberOverlay(true) + this._toggleHotkeysNumberOverlay(true) this._panel.intellihide.revealAndHold(Intellihide.Hold.TEMPORARY) @@ -484,7 +485,7 @@ export const Overview = class { timeout, () => { if (hotkey_option != 'ALWAYS') { - this.taskbar.toggleHotkeysNumberOverlay(false) + this._toggleHotkeysNumberOverlay(false) } this._panel.intellihide.release(Intellihide.Hold.TEMPORARY) @@ -492,6 +493,21 @@ export const Overview = class { ]) } + _toggleHotkeysNumberOverlay(show) { + // this.taskbar is the primary taskbar + this.taskbar.toggleHotkeysNumberOverlay(show) + + if (SETTINGS.get_boolean('overlay-on-secondary-switch')) { + // on secondary panels, show the overlay on icons matching the ones + // found on the primary panel (see Taksbar.hotkeyAppNumbers) + this._panelManager.allPanels.forEach((p) => { + if (p.isPrimary) return + + p.taskbar.toggleHotkeysNumberOverlay(show) + }) + } + } + _optionalClickToExit() { this._clickToExitEnabled = false if (SETTINGS.get_boolean('overview-click-to-exit')) diff --git a/src/panelManager.js b/src/panelManager.js index 7feaa3d..cbfc3e0 100755 --- a/src/panelManager.js +++ b/src/panelManager.js @@ -59,7 +59,7 @@ let tracker = Shell.WindowTracker.get_default() export const PanelManager = class { constructor() { - this.overview = new Overview.Overview() + this.overview = new Overview.Overview(this) this._injectionManager = new InjectionManager() } diff --git a/src/prefs.js b/src/prefs.js index 42ac665..0fa0812 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -2788,6 +2788,13 @@ const Preferences = class { this._settings.set_string('hotkeys-overlay-combo', widget.get_active_id()) }) + this._settings.bind( + 'overlay-on-secondary-switch', + this._builder.get_object('overlay_on_secondary_switch'), + 'active', + Gio.SettingsBindFlags.DEFAULT, + ) + this._settings.bind( 'shortcut-previews', this._builder.get_object('shortcut_preview_switch'), diff --git a/src/taskbar.js b/src/taskbar.js index f69641f..f119ea1 100644 --- a/src/taskbar.js +++ b/src/taskbar.js @@ -46,6 +46,8 @@ import { DTP_EXTENSION, SETTINGS } from './extension.js' const SearchController = Main.overview.searchController +export var hotkeyAppNumbers = {} + export const DASH_ANIMATION_TIME = 0.2 // Dash.DASH_ANIMATION_TIME is now private const DASH_ITEM_HOVER_TIMEOUT = 0.3 // Dash.DASH_ITEM_HOVER_TIMEOUT is now private export const MIN_ICON_SIZE = 4 @@ -1276,17 +1278,22 @@ export const Taskbar = class extends EventEmitter { } _updateHotkeysNumberOverlay() { - let seenApps = {} let counter = 0 + if (this.dtpPanel.isPrimary) hotkeyAppNumbers = {} + this._getAppIcons().forEach((icon) => { - if (!seenApps[icon.app] || this.allowSplitApps) { - seenApps[icon.app] = 1 - counter++ + if ( + this.dtpPanel.isPrimary && + (!hotkeyAppNumbers[icon.app] || this.allowSplitApps) + ) { + hotkeyAppNumbers[icon.app] = ++counter } - if (counter <= 10) { - icon.setHotkeysNumberOverlayLabel(counter == 10 ? 0 : counter) + let label = hotkeyAppNumbers[icon.app] + + if (label <= 10) { + icon.setHotkeysNumberOverlayLabel(label == 10 ? 0 : label) } else { // No overlay after 10 icon.setHotkeysNumberOverlayLabel(-1) diff --git a/ui/BoxOverlayShortcut.ui b/ui/BoxOverlayShortcut.ui index 5f87589..606dd35 100644 --- a/ui/BoxOverlayShortcut.ui +++ b/ui/BoxOverlayShortcut.ui @@ -1,29 +1,27 @@ - + + - + + 1000 + 250 10000 - 250 - 1000 - - vertical - 600 - 24 - 32 32 - 32 32 - + 32 + 32 + vertical + 24 + 600 - - Hotkeys prefix Hotkeys will either be Super+Number or Super+Alt+Num + Hotkeys prefix center @@ -35,11 +33,10 @@ - - Number overlay Temporarily show the application numbers over the icons when using the hotkeys. + Number overlay center @@ -52,49 +49,56 @@ - Hide timeout (ms) - center shortcut_time_adjustment + center - - Shortcut to show the overlay for 2 seconds Syntax: &lt;Shift&gt;, &lt;Ctrl&gt;, &lt;Alt&gt;, &lt;Super&gt; + Shortcut to show the overlay for 2 seconds + e.g. <Super>q center - 12 - e.g. <Super>q + 12 - - Show window previews on hotkey - Show previews when the application have multiple instances + On secondary monitors, show the overlay on icons matching the primary monitor + Show the overlay on all monitors - - center - - + + center + + + + + + + Show previews when the application have multiple instances + Show window previews on hotkey + + + center + + - - Hotkeys are activated with Select which keyboard number keys are used to activate the hotkeys + Hotkeys are activated with center @@ -107,9 +111,7 @@ - - - \ No newline at end of file +