Skip to content

gtk: implement global shortcuts #7083

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pluiedev
Copy link
Member

It's been a lot of D-Bus related pain and suffering, but here it is.

I'm not sure about how well this is integrated inside App, but I'm fairly
proud of the standalone logic.

@pluiedev pluiedev requested a review from a team as a code owner April 14, 2025 08:46
@tristan957
Copy link
Member

I wonder what the diff would look like if we used libportal

@pluiedev
Copy link
Member Author

pluiedev commented Apr 14, 2025

Well... libportal doesn't implement this yet, and it doesn't seem like anyone else is interested. (There's an open PR from July 2024, but nobody's left a single comment yet: flatpak/libportal#153) Would make my day a whole lot easier if it were the case to be honest

It also would've been a lot easier if they made the API extensible so that you could write your own portal extensions via libportal, but sadly we can't have nice things

@pluiedev pluiedev force-pushed the push-ozotwnwrtutq branch 2 times, most recently from c043fcd to 2479f30 Compare April 14, 2025 16:03
It's been a lot of D-Bus related pain and suffering, but here it is.

I'm not sure about how well this is integrated inside App, but I'm fairly
proud of the standalone logic.
Compiling this list of known supported and unsupported platforms has been
amazingly painful. Never change, Linux desktop.
@pluiedev pluiedev force-pushed the push-ozotwnwrtutq branch from 2479f30 to 620e718 Compare April 14, 2025 16:03

/// Returns a XDG-compliant shortcuts string from a trigger.
/// Spec: https://specifications.freedesktop.org/shortcuts-spec/latest/
pub fn xdgShortcutFromTrigger(buf: []u8, trigger: input.Binding.Trigger) !?[:0]const u8 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we write tests for this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah that would be a good idea. Will do it tomorrow as it's quite late here

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work. That fact it's so encapsulated is really well done. I agree with @tristan957 on the test request for the one function, then I just hit the "red" button to consider the ArrayHashMap change.

/// Currently the unique ID is simply the serialized representation of the
/// trigger that was used for the action as triggers are unique in the keymap,
/// but this may change in the future.
map: std.StringHashMapUnmanaged(Binding.Action) = .{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an ArrayHashMap to avoid the tombstone issue for very long running Ghostty instances? ziglang/zig#17851

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't even aware that this was a thing! Yeah in that case we should go for it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. In this case it'd be pretty pathological because you only clear and re-add when settings are reloaded so a user would have to reload a lot but I've been bit enough by this bug that I instinctively think "why not"

var trigger_buf: [256]u8 = undefined;

self.map.clearRetainingCapacity();
var it = self.app.config.keybind.set.bindings.iterator();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: create better API for this, I don't think the apprt's should be doing this level of introspection. Its totally fine for this PR, but I'll get around to a better API soon, because its in the hot path of me implementing global shortcuts on macOS that don't require special permissions (that they do today).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants