Skip to content
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

Keyboard shortcuts #181

Merged
merged 4 commits into from
Sep 4, 2024
Merged

Conversation

miek
Copy link
Member

@miek miek commented Aug 27, 2024

This adds keyboard shortcuts for common actions. Fixes #135

Initially I tried connecting them up to call Button::emit_clicked, which would've been a bit simpler, but I had issues with borrowing UI to get at the button & the callbacks needing to borrow it too (it also felt like a bit of a hack). So instead I've moved all the callbacks over to actions which seems to be the preferred way. This also required moving the logic for stop behaviour into a function rather than connecting/disconnecting signals.

For the shortcuts themselves, I've used conventional ones where possible. For scan I used Ctrl+R and F5, to mirror common browser refresh shortcuts. For capturing, I went for Ctrl+b and Ctrl+e, for begin and end respectively. I'm open to suggestions for anything different though.

I'm leaving this as draft for now as I've just remembered I need to handle the macOS keys properly, but otherwise it's open for any feedback.

src/ui.rs Outdated Show resolved Hide resolved
@miek miek marked this pull request as ready for review August 28, 2024 11:57
@martinling
Copy link
Member

I found that it was possible to simplify this quite a bit, see this commit.

I removed the stop_handle and cancel_handle fields from UserInterface, and stored those handles as fields on the StopState::Cynthion and StopState::Pcap variants.

The stop_pcap and stop_cynthion functions are very similar, and can be combined into a single stop_operation function which matches on the current StopState.

Then the stop_action becomes another simple use of the button_action! macro.

I haven't fully tested this, but see what you think.

@miek
Copy link
Member Author

miek commented Sep 2, 2024

I found that it was possible to simplify this quite a bit, see this commit.

Thanks! I like it. I've gone ahead and rebased everything with that change merged into the first commit.

src/ui.rs Outdated Show resolved Hide resolved
@martinling
Copy link
Member

This needs some documentation so that people can find out about the keyboard shortcuts.

Better still would be some indication of them within the UI - maybe a new item in the dropdown menu that leads to the About dialog?

@martinling
Copy link
Member

In fact GTK has a built-in ShortcutsWindow for this.

@miek
Copy link
Member Author

miek commented Sep 2, 2024

In fact GTK has a built-in ShortcutsWindow for this.

I did have a brief look into that, but found gtk-rs/gtk4-rs#1724 which points out that it'd need a very recent version of GTK to work without using XML to drive it.

@martinling
Copy link
Member

Ah, right. Doing it with XML doesn't look too awful, the XML file can be embedded into the binary at build time.

I'm fine with not pursuing that just now though as long as the keyboard shortcuts are added to the docs instead.

@miek
Copy link
Member Author

miek commented Sep 4, 2024

I've added the keyboard shortcuts to the docs (rendered here). I figured it was worth listing the linux/windows and mac ones separately for clarity and in case they diverge later. I tried using the inline-tab interface (like we use for build/install instructions) but it doesn't let you have sub-headings within it, so I just made them separate pages.

@miek miek requested a review from martinling September 4, 2024 12:50
Copy link
Member

@martinling martinling left a comment

Choose a reason for hiding this comment

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

That looks fine!

@martinling martinling merged commit efc0c26 into greatscottgadgets:main Sep 4, 2024
10 checks passed
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.

Add keyboard shortcuts
2 participants