Skip to content

Commit f7fa350

Browse files
Use default fullscreen shortcut on mac
1 parent 6f9ae13 commit f7fa350

3 files changed

Lines changed: 47 additions & 17 deletions

File tree

editor/src/messages/input_mapper/input_mappings.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ pub fn input_mappings() -> Mapping {
5555
entry!(KeyDown(KeyZ); modifiers=[Accel, MouseLeft], action_dispatch=DocumentMessage::Noop),
5656
//
5757
// AppWindowMessage
58-
entry!(KeyDown(F11); action_dispatch=AppWindowMessage::Fullscreen),
58+
entry!(KeyDown(F11); active=cfg!(not(target_os = "macos")), action_dispatch=AppWindowMessage::Fullscreen),
59+
entry!(KeyDown(KeyF); modifiers=[Accel, Meta], active=cfg!(target_os = "macos"), action_dispatch=AppWindowMessage::Fullscreen),
60+
entry!(KeyDown(KeyQ); modifiers=[Accel], active=cfg!(target_os = "macos"), action_dispatch=AppWindowMessage::Close),
5961
//
6062
// ClipboardMessage
6163
entry!(KeyDown(KeyX); modifiers=[Accel], action_dispatch=ClipboardMessage::Cut),
@@ -474,7 +476,7 @@ pub fn input_mappings() -> Mapping {
474476
// Sort `pointer_shake`
475477
sort(&mut pointer_shake);
476478

477-
let mut mapping = Mapping {
479+
Mapping {
478480
key_up,
479481
key_down,
480482
key_up_no_repeat,
@@ -483,16 +485,7 @@ pub fn input_mappings() -> Mapping {
483485
wheel_scroll,
484486
pointer_move,
485487
pointer_shake,
486-
};
487-
488-
if cfg!(target_os = "macos") {
489-
let remove: [&[&[MappingEntry; 0]; 0]; 0] = [];
490-
let add = [entry!(KeyDown(KeyQ); modifiers=[Accel], action_dispatch=AppWindowMessage::Close)];
491-
492-
apply_mapping_patch(&mut mapping, remove, add);
493488
}
494-
495-
mapping
496489
}
497490

498491
/// Default mappings except that scrolling without modifier keys held down is bound to zooming instead of vertical panning

editor/src/messages/input_mapper/utility_types/macros.rs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,83 @@ macro_rules! modifiers {
2525
/// When an action is currently available, and the user enters that input, the action's message is dispatched on the message bus.
2626
macro_rules! entry {
2727
// Pattern with canonical parameter
28-
($input:expr_2021; $(modifiers=[$($modifier:ident),*],)? $(refresh_keys=[$($refresh:ident),* $(,)?],)? canonical, action_dispatch=$action_dispatch:expr_2021$(,)?) => {
29-
entry!($input; $($($modifier),*)?; $($($refresh),*)?; $action_dispatch; true)
28+
(
29+
$input:expr_2021;
30+
$(modifiers=[$($modifier:ident),*],)?
31+
$(refresh_keys=[$($refresh:ident),* $(,)?],)?
32+
canonical,
33+
$(active=$active:expr,)?
34+
action_dispatch=$action_dispatch:expr_2021$(,)?
35+
) => {
36+
entry!(
37+
$input;
38+
$($($modifier),*)?;
39+
$($($refresh),*)?;
40+
$action_dispatch;
41+
true;
42+
true $( && $active )?
43+
)
3044
};
3145

3246
// Pattern without canonical parameter
33-
($input:expr_2021; $(modifiers=[$($modifier:ident),*],)? $(refresh_keys=[$($refresh:ident),* $(,)?],)? action_dispatch=$action_dispatch:expr_2021$(,)?) => {
34-
entry!($input; $($($modifier),*)?; $($($refresh),*)?; $action_dispatch; false)
47+
(
48+
$input:expr_2021;
49+
$(modifiers=[$($modifier:ident),*],)?
50+
$(refresh_keys=[$($refresh:ident),* $(,)?],)?
51+
$(active=$active:expr,)?
52+
action_dispatch=$action_dispatch:expr_2021$(,)?
53+
) => {
54+
entry!(
55+
$input;
56+
$($($modifier),*)?;
57+
$($($refresh),*)?;
58+
$action_dispatch;
59+
false;
60+
true $( && $active )?
61+
)
3562
};
3663

3764
// Implementation macro to avoid code duplication
38-
($input:expr; $($modifier:ident),*; $($refresh:ident),*; $action_dispatch:expr; $canonical:expr) => {
65+
($input:expr; $($modifier:ident),*; $($refresh:ident),*; $action_dispatch:expr; $canonical:expr; $active:expr) => {
66+
3967
&[&[
4068
// Cause the `action_dispatch` message to be sent when the specified input occurs.
4169
MappingEntry {
4270
action: $action_dispatch.into(),
4371
input: $input,
4472
modifiers: modifiers!($($modifier),*),
4573
canonical: $canonical,
74+
active: $active,
4675
},
4776

48-
// Also cause the `action_dispatch` message to be sent when any of the specified refresh keys change.
4977
$(
5078
MappingEntry {
5179
action: $action_dispatch.into(),
5280
input: InputMapperMessage::KeyDown(Key::$refresh),
5381
modifiers: modifiers!(),
5482
canonical: $canonical,
83+
active: $active,
5584
},
5685
MappingEntry {
5786
action: $action_dispatch.into(),
5887
input: InputMapperMessage::KeyUp(Key::$refresh),
5988
modifiers: modifiers!(),
6089
canonical: $canonical,
90+
active: $active,
6191
},
6292
MappingEntry {
6393
action: $action_dispatch.into(),
6494
input: InputMapperMessage::KeyDownNoRepeat(Key::$refresh),
6595
modifiers: modifiers!(),
6696
canonical: $canonical,
97+
active: $active,
6798
},
6899
MappingEntry {
69100
action: $action_dispatch.into(),
70101
input: InputMapperMessage::KeyUpNoRepeat(Key::$refresh),
71102
modifiers: modifiers!(),
72103
canonical: $canonical,
104+
active: $active,
73105
},
74106
)*
75107
]]
@@ -97,6 +129,9 @@ macro_rules! mapping {
97129
for entry_slice in $entry {
98130
// Each entry in the slice (usually just one, except when `refresh_keys` adds additional key entries)
99131
for entry in entry_slice.into_iter() {
132+
if !entry.active {
133+
continue;
134+
}
100135
let corresponding_list = match entry.input {
101136
InputMapperMessage::KeyDown(key) => &mut key_down[key as usize],
102137
InputMapperMessage::KeyUp(key) => &mut key_up[key as usize],

editor/src/messages/input_mapper/utility_types/misc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ pub struct MappingEntry {
125125
pub modifiers: KeyStates,
126126
/// True indicates that this takes priority as the labeled hotkey shown in UI menus and tooltips instead of an alternate binding for the same action
127127
pub canonical: bool,
128+
/// Whether this mapping is active
129+
pub active: bool,
128130
}
129131

130132
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]

0 commit comments

Comments
 (0)