Skip to content

Commit de41e6e

Browse files
committed
Incorporate review feedback by @tronical
1 parent 6502f4e commit de41e6e

5 files changed

Lines changed: 15 additions & 14 deletions

File tree

docs/astro/src/content/docs/reference/keyboard-input/overview.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ As another example, `@keys(Control + Plus)` is equivalent to `@keys(Control + Sh
104104

105105
### Physical Key Bindings
106106

107-
If you want to match a physical key position instead of the character produced on the current keyboard layout, use `@physical-keys(..)`.
107+
Use `@physical-keys(..)` to match a physical key position instead of the character produced on the current keyboard layout.
108+
For example, WASD bindings in a game should use `@physical-keys(..)` so the movement keys are always in the same position on all layouts.
108109

109-
Physical key names reuse familiar `Key` names such as `A`, `Digit1`, `BackQuote`, or `LeftArrow`, but they refer to a physical key location instead of logical text.
110-
Today these names refer to positions on a U.S. keyboard layout.
110+
Physical key names reuse familiar `Key` names such as `A`, `Digit1`, `BackQuote`, or `LeftArrow`, but they refer to a physical key location on a U.S. keyboard layout, instead of logical text.
111111
Unlike `@keys(..)`, `@physical-keys(..)` does not currently accept string literals.
112112

113113
```slint

internal/compiler/builtins.slint

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,8 @@ component MenuItem {
13221322
/// The keyboard shortcut for this `MenuItem`.
13231323
///
13241324
/// This property can only be set in a `MenuItem` that is part of a <Link type="MenuBar"/>.
1325+
///
1326+
/// Only shortcuts created with @keys() are supported, @physical-keys() are not supported.
13251327
in property <keys> shortcut;
13261328
/// When true, a checkmark will be shown next to the title of the `MenuItem`.
13271329
/// \default false

internal/compiler/passes/lower_menus.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -664,13 +664,13 @@ fn lower_menu_items(
664664
);
665665
}
666666
if in_menubar
667-
&& let Some(binding) = element.borrow().bindings.get("shortcut")
668-
&& matches!(&binding.borrow().expression, Expression::Keys(k) if k.is_physical)
667+
&& let Some(binding) = element.borrow().binding("shortcut")
668+
&& matches!(&binding.expression.ignore_debug_hooks(), Expression::Keys(k) if k.is_physical)
669669
{
670-
diag.push_warning(
671-
"Physical keys in MenuItem shortcuts are interpreted as logical keys by native menu bars. Use @keys(...) for menu shortcuts instead"
670+
diag.push_error(
671+
"@physical-keys(..) in MenuItem shortcuts are not supported.\nUse @keys(...) for menu shortcuts instead"
672672
.into(),
673-
&*binding.borrow(),
673+
&*binding,
674674
);
675675
}
676676

internal/compiler/passes/resolving.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use i_slint_common::for_each_physical_keys;
2323
use smol_str::{SmolStr, ToSmolStr};
2424
use std::collections::BTreeMap;
2525
use std::rc::Rc;
26+
use std::sync::LazyLock;
2627
use unicode_segmentation::UnicodeSegmentation;
2728

2829
mod remove_noop;
@@ -2179,12 +2180,10 @@ fn with_physical_key_map<R>(
21792180
};
21802181
}
21812182

2182-
thread_local! {
2183-
pub static PHYSICAL_KEY_MAP: std::collections::HashMap< &'static str, &'static str> =
2184-
for_each_physical_keys!(generate_physical_key_map).into_iter().collect();
2185-
}
2183+
static PHYSICAL_KEY_MAP: LazyLock<std::collections::HashMap<&str, &str>> =
2184+
LazyLock::new(|| for_each_physical_keys!(generate_physical_key_map).into_iter().collect());
21862185

2187-
PHYSICAL_KEY_MAP.with(fun)
2186+
fun(&PHYSICAL_KEY_MAP)
21882187
}
21892188

21902189
fn lookup_physical_key(keycode: &str) -> Option<&'static str> {

internal/compiler/tests/syntax/elements/menu-shortcuts.slint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export component Test inherits Window {
99
}
1010
MenuItem {
1111
shortcut: @physical-keys(Control + N);
12-
// > <warning{Physical keys in MenuItem shortcuts are interpreted as logical keys by native menu bars. Use @keys(...) for menu shortcuts instead}
12+
// > <error{@physical-keys(..) in MenuItem shortcuts are not supported.↵Use @keys(...) for menu shortcuts instead}
1313
}
1414
}
1515
}

0 commit comments

Comments
 (0)