-
-
Notifications
You must be signed in to change notification settings - Fork 44
Allow launching apps via keyboard shortcuts #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
58242fc
Allow launching apps at indeces via command line
leolost2605 f423cb3
Use 1 based index and add safeguards
leolost2605 788ab22
Use dbus to grab the accelerators instead of relying on gala to forwa…
leolost2605 89815c6
Remove debugging
leolost2605 473cd0f
Merge branch 'main' into leolost/launch-index
leolost2605 f89c6f0
Update Application.vala
leolost2605 75714ca
Update Application.vala
leolost2605 82b5ff7
Add license header
leolost2605 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-3.0 | ||
| * SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io) | ||
| */ | ||
|
|
||
| /** | ||
|
leolost2605 marked this conversation as resolved.
|
||
| * ActionMode: | ||
| * @NONE: block action | ||
| * @NORMAL: allow action when in window mode, e.g. when the focus is in an application window | ||
| * @OVERVIEW: allow action while the overview is active | ||
| * @LOCK_SCREEN: allow action when the screen is locked, e.g. when the screen shield is shown | ||
| * @UNLOCK_SCREEN: allow action in the unlock dialog | ||
| * @LOGIN_SCREEN: allow action in the login screen | ||
| * @SYSTEM_MODAL: allow action when a system modal dialog (e.g. authentification or session dialogs) is open | ||
| * @LOOKING_GLASS: allow action in looking glass | ||
| * @POPUP: allow action while a shell menu is open | ||
| */ | ||
|
|
||
| [Flags] | ||
| public enum ActionMode { | ||
| NONE = 0, | ||
| NORMAL = 1 << 0, | ||
| OVERVIEW = 1 << 1, | ||
| LOCK_SCREEN = 1 << 2, | ||
| UNLOCK_SCREEN = 1 << 3, | ||
| LOGIN_SCREEN = 1 << 4, | ||
| SYSTEM_MODAL = 1 << 5, | ||
| LOOKING_GLASS = 1 << 6, | ||
| POPUP = 1 << 7, | ||
| } | ||
|
|
||
| [Flags] | ||
| public enum Meta.KeyBindingFlags { | ||
| NONE = 0, | ||
| PER_WINDOW = 1 << 0, | ||
| BUILTIN = 1 << 1, | ||
| IS_REVERSED = 1 << 2, | ||
| NON_MASKABLE = 1 << 3, | ||
| IGNORE_AUTOREPEAT = 1 << 4, | ||
| } | ||
|
|
||
| public struct Accelerator { | ||
| public string name; | ||
| public ActionMode mode_flags; | ||
| public Meta.KeyBindingFlags grab_flags; | ||
| } | ||
|
|
||
| [DBus (name = "org.gnome.Shell")] | ||
| public interface ShellKeyGrabber : GLib.Object { | ||
| public abstract signal void accelerator_activated (uint action, GLib.HashTable<string, GLib.Variant> parameters_dict); | ||
|
|
||
| public abstract uint grab_accelerator (string accelerator, ActionMode mode_flags, Meta.KeyBindingFlags grab_flags) throws GLib.DBusError, GLib.IOError; | ||
| public abstract uint[] grab_accelerators (Accelerator[] accelerators) throws GLib.DBusError, GLib.IOError; | ||
| public abstract bool ungrab_accelerator (uint action) throws GLib.DBusError, GLib.IOError; | ||
| public abstract bool ungrab_accelerators (uint[] actions) throws GLib.DBusError, GLib.IOError; | ||
|
|
||
| private static Settings settings; | ||
| private static ShellKeyGrabber? instance; | ||
|
|
||
| private static HashTable<uint, int> saved_action_ids; | ||
|
|
||
| public static void init () { | ||
| settings = new Settings ("io.elementary.dock.keybindings"); | ||
| saved_action_ids = new HashTable<uint, int> (null, null); | ||
|
|
||
| settings.changed.connect (() => { | ||
| ungrab_keybindings (); | ||
| setup_grabs (); | ||
| }); | ||
|
|
||
| Bus.watch_name (BusType.SESSION, "org.gnome.Shell", BusNameWatcherFlags.NONE, () => on_watch.begin (), () => instance = null); | ||
| } | ||
|
|
||
| private static async void on_watch () { | ||
| try { | ||
| instance = yield Bus.get_proxy (SESSION, "org.gnome.Shell", "/org/gnome/Shell"); | ||
| setup_grabs (); | ||
| } catch (Error e) { | ||
| warning ("Failed to connect to bus for keyboard shortcut grabs: %s", e.message); | ||
| } | ||
| } | ||
|
|
||
| private static void setup_grabs () requires (instance != null) { | ||
| for (int i = 1; i <= 9; i++) { | ||
| var keybindings = settings.get_strv ("launch-dock-%d".printf (i)); | ||
| Accelerator[] accelerators = {}; | ||
| for (int j = 0; j < keybindings.length; j++) { | ||
| accelerators += Accelerator () { | ||
| name = keybindings[j], | ||
| mode_flags = ActionMode.NONE, | ||
| grab_flags = Meta.KeyBindingFlags.NONE | ||
| }; | ||
|
|
||
| try { | ||
| foreach (var id in instance.grab_accelerators (accelerators)) { | ||
| saved_action_ids[id] = i; | ||
| } | ||
| } catch (Error e) { | ||
| critical ("Couldn't grab accelerators: %s", e.message); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| instance.accelerator_activated.connect (on_accelerator_activated); | ||
| } | ||
|
|
||
| private static void on_accelerator_activated (uint action, GLib.HashTable<string, GLib.Variant> parameters_dict) { | ||
| if (!(action in saved_action_ids)) { | ||
| return; | ||
| } | ||
|
|
||
| Dock.LauncherManager.get_default ().launch (saved_action_ids[action]); | ||
| } | ||
|
|
||
| private static void ungrab_keybindings () requires (instance != null) { | ||
| var actions = saved_action_ids.get_keys_as_array (); | ||
|
|
||
| try { | ||
| instance.ungrab_accelerators (actions); | ||
| } catch (Error e) { | ||
| critical ("Couldn't ungrab accelerators: %s", e.message); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.