-
-
Notifications
You must be signed in to change notification settings - Fork 23
Add settings-daemon application launcher support #536
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
7 commits
Select commit
Hold shift + click to select a range
ff8a550
Add settings-daemon application launcher support
lenemter 9b7e521
Merge branch 'main' into lenemter/add-system-daemon-applications
lenemter 99e3fcf
Merge branch 'main' into lenemter/add-system-daemon-applications
lenemter 3efd30b
Address review comments
lenemter 7ee3721
Merge branch 'main' into lenemter/add-system-daemon-applications
lenemter 945ba3c
Merge branch 'main' into lenemter/add-system-daemon-applications
zeebok 826d96b
Merge branch 'main' into lenemter/add-system-daemon-applications
leonardo-lemos 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 was deleted.
Oops, something went wrong.
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,21 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-2.0-or-later | ||
| * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) | ||
| */ | ||
|
|
||
| namespace Keyboard.Shortcuts.CustomShortcuts { | ||
| public enum ActionType { | ||
| DESKTOP_FILE, | ||
| COMMAND_LINE | ||
| } | ||
|
|
||
| public struct ParsedShortcut { | ||
| ActionType type; | ||
| string target; | ||
| GLib.HashTable<string, Variant> parameters; | ||
| string[] keybindings; | ||
| } | ||
|
|
||
| public const string SETTINGS_SCHEMA = "io.elementary.settings-daemon.applications"; | ||
| public const string APPLICATION_SHORTCUTS = "application-shortcuts"; | ||
| } |
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,29 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) | ||
| */ | ||
|
|
||
| namespace Keyboard.Shortcuts.Utils { | ||
| public GLib.Icon? get_action_icon (GLib.DesktopAppInfo app_info, string action) { | ||
| unowned var icon_theme = Gtk.IconTheme.get_for_display (Gdk.Display.get_default ()); | ||
|
|
||
| GLib.Icon? action_icon = null; | ||
| try { | ||
| var keyfile = new GLib.KeyFile (); | ||
| keyfile.load_from_file (app_info.get_filename (), GLib.KeyFileFlags.NONE); | ||
|
|
||
| var group = "Desktop Action %s".printf (action); | ||
| if (keyfile.has_key (group, GLib.KeyFileDesktop.KEY_ICON)) { | ||
| var icon_name = keyfile.get_string (group, GLib.KeyFileDesktop.KEY_ICON); | ||
|
|
||
| if (icon_theme.has_icon (icon_name)) { | ||
| action_icon = new ThemedIcon (icon_name); | ||
| } | ||
| } | ||
| } catch (Error e) { | ||
| warning (e.message); | ||
| } | ||
|
|
||
| return action_icon; | ||
| } | ||
| } |
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,118 @@ | ||
| /* SPDX-License-Identifier: GPL-3.0-or-later | ||
| * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) | ||
| */ | ||
|
|
||
| public class Keyboard.Shortcuts.AppChooser : Granite.Dialog { | ||
| public signal void app_chosen (string filename, GLib.HashTable<string, Variant> parameters); | ||
| public signal void custom_command_chosen (string command, GLib.HashTable<string, Variant> parameters); | ||
|
|
||
| private Gtk.ListBox list; | ||
| private Gtk.SearchEntry search_entry; | ||
| private Gtk.Entry custom_entry; | ||
|
|
||
| construct { | ||
| search_entry = new Gtk.SearchEntry () { | ||
| placeholder_text = _("Search Applications") | ||
| }; | ||
| search_entry.set_key_capture_widget (this); | ||
|
|
||
| list = new Gtk.ListBox () { | ||
| hexpand = true, | ||
| vexpand = true | ||
| }; | ||
| list.add_css_class (Granite.STYLE_CLASS_RICH_LIST); | ||
| list.set_sort_func (sort_function); | ||
| list.set_filter_func (filter_function); | ||
|
|
||
| var scrolled = new Gtk.ScrolledWindow () { | ||
| child = list, | ||
| has_frame = true | ||
| }; | ||
|
|
||
| custom_entry = new Gtk.Entry () { | ||
| placeholder_text = _("Type in a custom command"), | ||
| primary_icon_activatable = false, | ||
| primary_icon_name = "utilities-terminal-symbolic" | ||
| }; | ||
|
|
||
| var box = new Gtk.Box (VERTICAL, 6); | ||
| box.append (search_entry); | ||
| box.append (scrolled); | ||
| box.append (custom_entry); | ||
|
|
||
| modal = true; | ||
| default_height = 500; | ||
| default_width = 400; | ||
| get_content_area ().append (box); | ||
| add_button (_("Cancel"), Gtk.ResponseType.CANCEL); | ||
|
|
||
| // TRANSLATORS: This string is used by screen reader | ||
| update_property (Gtk.AccessibleProperty.LABEL, _("Select an app"), -1); | ||
|
|
||
| search_entry.grab_focus (); | ||
| search_entry.search_changed.connect (() => { | ||
| list.invalidate_filter (); | ||
| }); | ||
|
|
||
| response.connect (hide); | ||
|
|
||
| list.row_activated.connect (on_app_selected); | ||
| custom_entry.activate.connect (on_custom_command_entered); | ||
| } | ||
|
|
||
| public void init_list (GLib.List<GLib.DesktopAppInfo> app_infos) { | ||
| foreach (var app_info in app_infos) { | ||
| var icon = app_info.get_icon () ?? new ThemedIcon ("application-default-icon"); | ||
| var name = app_info.get_name (); | ||
| var description = app_info.get_description (); | ||
| var filename = File.new_for_path (app_info.get_filename ()).get_basename (); | ||
|
|
||
| list.prepend (new AppChooserRow ({icon, null, name, description, null, filename})); | ||
|
|
||
| unowned var icon_theme = Gtk.IconTheme.get_for_display (Gdk.Display.get_default ()); | ||
| var actions = app_info.list_actions (); | ||
| for (var i = 0; i < actions.length; i++) { | ||
| var action = actions[i]; | ||
| var action_icon = Utils.get_action_icon (app_info, action); | ||
| var action_name = "%s → %s".printf (name, app_info.get_action_name (action)); | ||
| list.prepend (new AppChooserRow ({icon, action_icon, action_name, description, action, filename})); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private int sort_function (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) { | ||
| unowned AppChooserRow row_1 = (AppChooserRow) row1.get_child (); | ||
| unowned AppChooserRow row_2 = (AppChooserRow) row2.get_child (); | ||
|
|
||
| var name_1 = row_1.info.name; | ||
| var name_2 = row_2.info.name; | ||
|
|
||
| return name_1.collate (name_2); | ||
| } | ||
|
|
||
| private bool filter_function (Gtk.ListBoxRow list_box_row) { | ||
| var app_row = (AppChooserRow) list_box_row.get_child (); | ||
| return search_entry.text.down () in app_row.info.name.down () | ||
| || search_entry.text.down () in app_row.info.name.down (); | ||
| } | ||
|
|
||
| private void on_app_selected (Gtk.ListBoxRow list_box_row) { | ||
| var app_row = (AppChooserRow) list_box_row.get_child (); | ||
|
|
||
| var parameters = new GLib.HashTable<string, Variant> (null, null); | ||
| if (app_row.info.action != null) { | ||
| parameters["action"] = app_row.info.action; | ||
| } | ||
|
|
||
| app_chosen (app_row.info.filename, parameters); | ||
| hide (); | ||
| } | ||
|
|
||
| private void on_custom_command_entered () { | ||
| custom_command_chosen ( | ||
| custom_entry.text, | ||
| new GLib.HashTable<string, Variant> (null, null) | ||
| ); | ||
| hide (); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.