windowManager: Add switch-to-application-n keybindings

Having Unity-like shortcuts for activating the first nine applications
in the dash has been a long requested feature, but somehow nobody got
around to implement it.

As the shortcut is most useful outside the overview where the dash is
not visible, only consider favorite apps as they have a predictable
order.

https://bugzilla.gnome.org/show_bug.cgi?id=648000
This commit is contained in:
Florian Müllner 2019-01-29 11:48:06 +01:00 committed by Florian Müllner
parent 15e7625c80
commit 4590094605
2 changed files with 108 additions and 0 deletions

View File

@ -145,6 +145,42 @@
<summary>Keybinding that pauses and resumes all running tweens, for debugging purposes</summary> <summary>Keybinding that pauses and resumes all running tweens, for debugging purposes</summary>
<description></description> <description></description>
</key> </key>
<key name="switch-to-application-1" type="as">
<default>["&lt;Super&gt;1"]</default>
<summary>Switch to application 1</summary>
</key>
<key name="switch-to-application-2" type="as">
<default>["&lt;Super&gt;2"]</default>
<summary>Switch to application 2</summary>
</key>
<key name="switch-to-application-3" type="as">
<default>["&lt;Super&gt;3"]</default>
<summary>Switch to application 3</summary>
</key>
<key name="switch-to-application-4" type="as">
<default>["&lt;Super&gt;4"]</default>
<summary>Switch to application 4</summary>
</key>
<key name="switch-to-application-5" type="as">
<default>["&lt;Super&gt;5"]</default>
<summary>Switch to application 5</summary>
</key>
<key name="switch-to-application-6" type="as">
<default>["&lt;Super&gt;6"]</default>
<summary>Switch to application 6</summary>
</key>
<key name="switch-to-application-7" type="as">
<default>["&lt;Super&gt;7"]</default>
<summary>Switch to application 7</summary>
</key>
<key name="switch-to-application-8" type="as">
<default>["&lt;Super&gt;8"]</default>
<summary>Switch to application 8</summary>
</key>
<key name="switch-to-application-9" type="as">
<default>["&lt;Super&gt;9"]</default>
<summary>Switch to application 9</summary>
</key>
</schema> </schema>
<schema id="org.gnome.shell.keyboard" path="/org/gnome/shell/keyboard/" <schema id="org.gnome.shell.keyboard" path="/org/gnome/shell/keyboard/"

View File

@ -12,6 +12,7 @@ const Shell = imports.gi.Shell;
const Signals = imports.signals; const Signals = imports.signals;
const AltTab = imports.ui.altTab; const AltTab = imports.ui.altTab;
const AppFavorites = imports.ui.appFavorites;
const Dialog = imports.ui.dialog; const Dialog = imports.ui.dialog;
const WorkspaceSwitcherPopup = imports.ui.workspaceSwitcherPopup; const WorkspaceSwitcherPopup = imports.ui.workspaceSwitcherPopup;
const InhibitShortcutsDialog = imports.ui.inhibitShortcutsDialog; const InhibitShortcutsDialog = imports.ui.inhibitShortcutsDialog;
@ -938,6 +939,69 @@ var WindowManager = class {
Shell.ActionMode.POPUP, Shell.ActionMode.POPUP,
this._toggleCalendar.bind(this)); this._toggleCalendar.bind(this));
this.addKeybinding('switch-to-application-1',
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
this._switchToApplication.bind(this));
this.addKeybinding('switch-to-application-2',
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
this._switchToApplication.bind(this));
this.addKeybinding('switch-to-application-3',
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
this._switchToApplication.bind(this));
this.addKeybinding('switch-to-application-4',
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
this._switchToApplication.bind(this));
this.addKeybinding('switch-to-application-5',
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
this._switchToApplication.bind(this));
this.addKeybinding('switch-to-application-6',
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
this._switchToApplication.bind(this));
this.addKeybinding('switch-to-application-7',
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
this._switchToApplication.bind(this));
this.addKeybinding('switch-to-application-8',
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
this._switchToApplication.bind(this));
this.addKeybinding('switch-to-application-9',
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
Meta.KeyBindingFlags.IGNORE_AUTOREPEAT,
Shell.ActionMode.NORMAL |
Shell.ActionMode.OVERVIEW,
this._switchToApplication.bind(this));
global.display.connect('show-resize-popup', this._showResizePopup.bind(this)); global.display.connect('show-resize-popup', this._showResizePopup.bind(this));
global.display.connect('show-pad-osd', this._showPadOsd.bind(this)); global.display.connect('show-pad-osd', this._showPadOsd.bind(this));
global.display.connect('show-osd', (display, monitorIndex, iconName, label) => { global.display.connect('show-osd', (display, monitorIndex, iconName, label) => {
@ -2012,6 +2076,14 @@ var WindowManager = class {
Main.ctrlAltTabManager.popup(binding.is_reversed(), binding.get_name(), binding.get_mask()); Main.ctrlAltTabManager.popup(binding.is_reversed(), binding.get_name(), binding.get_mask());
} }
_switchToApplication(display, window, binding) {
let [,,,target] = binding.get_name().split('-');
let apps = AppFavorites.getAppFavorites().getFavorites();
let app = apps[target - 1];
if (app)
app.activate();
}
_toggleAppMenu(display, window, event, binding) { _toggleAppMenu(display, window, event, binding) {
Main.panel.toggleAppMenu(); Main.panel.toggleAppMenu();
} }