diff --git a/src/main.rs b/src/main.rs index b72c795..0de485d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ use cmd_line::CmdLineSettings; use editor::start_editor; use renderer::{cursor_renderer::CursorSettings, RendererSettings}; use settings::SETTINGS; -use window::{create_window, WindowSettings}; +use window::{create_window, KeyboardSettings, WindowSettings}; pub use channel_utils::*; @@ -133,6 +133,7 @@ fn main() { WindowSettings::register(); RendererSettings::register(); CursorSettings::register(); + KeyboardSettings::register(); let running = Arc::new(AtomicBool::new(true)); diff --git a/src/window/settings.rs b/src/window/settings.rs index 772c666..f3c3d42 100644 --- a/src/window/settings.rs +++ b/src/window/settings.rs @@ -27,3 +27,9 @@ impl Default for WindowSettings { } } } + +#[derive(Clone, Default, SettingGroup)] +#[setting_prefix = "input"] +pub struct KeyboardSettings { + pub use_logo: bool, +} diff --git a/src/window/window_wrapper/keyboard_manager.rs b/src/window/window_wrapper/keyboard_manager.rs index f175eed..6c5825f 100644 --- a/src/window/window_wrapper/keyboard_manager.rs +++ b/src/window/window_wrapper/keyboard_manager.rs @@ -5,6 +5,8 @@ use winit::platform::modifier_supplement::KeyEventExtModifierSupplement; use crate::bridge::UiCommand; use crate::channel_utils::LoggingTx; +use crate::settings::SETTINGS; +use crate::window::KeyboardSettings; pub struct KeyboardManager { command_sender: LoggingTx, @@ -63,7 +65,9 @@ impl KeyboardManager { } Event::MainEventsCleared => { // And the window wasn't just focused. - if !self.ignore_input_this_frame { + let settings = SETTINGS.get::(); + + if !self.should_ignore_input(&settings) { // If we have a keyboard event this frame for key_event in self.queued_key_events.iter() { // And a key was pressed @@ -86,9 +90,14 @@ impl KeyboardManager { } } + fn should_ignore_input(&self, settings: &KeyboardSettings) -> bool { + self.ignore_input_this_frame || (self.logo && !settings.use_logo) + } + fn maybe_get_keybinding(&self, key_event: &KeyEvent) -> Option { // Determine if this key event represents a key which won't ever // present text. + if let Some(key_text) = is_control_key(key_event.logical_key) { Some(self.format_keybinding_string(true, true, key_text)) } else { @@ -117,31 +126,19 @@ impl KeyboardManager { } fn format_keybinding_string(&self, special: bool, use_shift: bool, text: &str) -> String { - let special = special || self.ctrl || use_alt(self.alt) || use_logo(self.logo); + let special = special || self.ctrl || use_alt(self.alt) || self.logo; let open = or_empty(special, "<"); let shift = or_empty(self.shift && use_shift, "S-"); let ctrl = or_empty(self.ctrl, "C-"); let alt = or_empty(use_alt(self.alt), "M-"); - let logo = or_empty(use_logo(self.logo), "D-"); + let logo = or_empty(self.logo, "D-"); let close = or_empty(special, ">"); format!("{}{}{}{}{}{}{}", open, shift, ctrl, alt, logo, text, close) } } -#[cfg(not(target_os = "windows"))] -fn use_logo(logo: bool) -> bool { - logo -} - -// The Windows key is used for OS-level shortcuts, -// so we want to ignore the logo key on this platform. -#[cfg(target_os = "windows")] -fn use_logo(_: bool) -> bool { - false -} - #[cfg(not(target_os = "macos"))] fn use_alt(alt: bool) -> bool { alt