Skip to content

compiler: Have a key-sequence type #8906

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 1 commit into
base: master
Choose a base branch
from

Conversation

hunger
Copy link
Member

@hunger hunger commented Jul 11, 2025

... which is lowered to a string for now.

Add a new type keyboard-shortcut, that is parsed from @keys(shift + control + a) and gets lowered to a string in Rust and C++ and the interpreter for now.

| Type::Image
| Type::Easing
| Type::Array(_)
| Type::KeyboardShortcut => {
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 tired to return a String that contains the stringified definition, but that causes infinite recursion... I need to check out why that happens in detail.

/// @keys(ctrl +shift + alt+meta+a)
/// @keys(control +shift + alt+meta+a)
/// ```
fn parse_keys(p: &mut impl Parser) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This should allow , separated lists of elements.

The logic to decide on the actual key being uses is also a bit simplistic: We should (in addition?) accept the keys from our Keys namespace. But So I should probably let all unknown identifiers through here and match them to the Keys namespace (or the single character).

... which is lowered to a string for now.
@hunger hunger force-pushed the tobias/keyboard-shortcut branch from 78e44e2 to 7b8e4d0 Compare July 11, 2025 17:41
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

Sorry i haven't took the time to review this before my vacations.
I've had a quick look at it and didn't see anything wrong.

I'm thinking we shouldn't merge this to master (stabilize) unless this is used. Would it be easy to gate this as an experimental feature? (the new type and the @keys)

@@ -839,6 +845,40 @@ impl Enumeration {
}
}

#[derive(Clone, Debug, Default)]
pub struct KeyboardModifiers {
Copy link
Member

Choose a reason for hiding this comment

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

don't we already have such a type somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do. But I can not get to it from here.

Copy link
Member Author

Choose a reason for hiding this comment

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

We do have this type in i_slint_core, but that is not listed in the compiler's Cargo.toml. I did not want to add it, as there is probably a reason for not having that.

let ctrl = if self.modifiers.control { "ctrl+" } else { "" };
let meta = if self.modifiers.meta { "meta+" } else { "" };
let shift = if self.modifiers.shift { "shift+" } else { "" };
write!(f, "{alt}{ctrl}{meta}{shift}{}", self.key)
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking we also want to support key that are not printable like arrows, enter, media keys, F keys and so on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that will be needed.

@hunger
Copy link
Member Author

hunger commented Jul 21, 2025

I wanted to keep this unmerged for the time being and build on top of this PR.

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.

2 participants