From cebcaa86bcd706eb5df0df82e5af4738fda32a04 Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Fri, 3 Apr 2020 14:00:56 -0700 Subject: [PATCH 1/2] better handling of quit --- src/bridge/ui_commands.rs | 5 +++++ src/window.rs | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/bridge/ui_commands.rs b/src/bridge/ui_commands.rs index 4bbca9e..eb76ab9 100644 --- a/src/bridge/ui_commands.rs +++ b/src/bridge/ui_commands.rs @@ -21,6 +21,7 @@ pub enum UiCommand { Drag(u32, u32), FocusLost, FocusGained, + Quit } impl UiCommand { @@ -60,6 +61,10 @@ impl UiCommand { .command("if exists('#FocusGained') | doautocmd FocusGained | endif") .await .expect("Focus Gained Failed"), + UiCommand::Quit => { + nvim.command("qa!") + .await.ok(); // Ignoring result as it won't succeed since the app closed. + } } } diff --git a/src/window.rs b/src/window.rs index 99a3091..c0e3f4c 100644 --- a/src/window.rs +++ b/src/window.rs @@ -199,6 +199,10 @@ impl WindowWrapper { } } + pub fn handle_quit(&mut self) { + BRIDGE.queue_command(UiCommand::Quit); + } + pub fn handle_keyboard_input(&mut self, keycode: Option, text: Option) { let modifiers = self.context.keyboard().mod_state(); @@ -375,7 +379,7 @@ pub fn ui_loop() { .context .event_pump() .expect("Could not create sdl event pump"); - 'running: loop { + loop { let frame_start = Instant::now(); window.synchronize_settings(); @@ -386,12 +390,9 @@ pub fn ui_loop() { for event in event_pump.poll_iter() { match event { - Event::Quit { .. } => break 'running, - Event::KeyDown { - keycode: Some(received_keycode), - .. - } => { - keycode = Some(received_keycode); + Event::Quit { .. } => window.handle_quit(), + Event::KeyDown { keycode: received_keycode, .. } => { + keycode = received_keycode; } Event::TextInput { text, .. } => keytext = Some(text), Event::MouseMotion { x, y, .. } => window.handle_pointer_motion(x, y), From 18d37134c5fec86360bbf39fb6078b0c2492fed8 Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Fri, 3 Apr 2020 14:06:32 -0700 Subject: [PATCH 2/2] formatting --- src/bridge/ui_commands.rs | 5 ++--- src/window.rs | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/bridge/ui_commands.rs b/src/bridge/ui_commands.rs index eb76ab9..9e51fb5 100644 --- a/src/bridge/ui_commands.rs +++ b/src/bridge/ui_commands.rs @@ -21,7 +21,7 @@ pub enum UiCommand { Drag(u32, u32), FocusLost, FocusGained, - Quit + Quit, } impl UiCommand { @@ -62,8 +62,7 @@ impl UiCommand { .await .expect("Focus Gained Failed"), UiCommand::Quit => { - nvim.command("qa!") - .await.ok(); // Ignoring result as it won't succeed since the app closed. + nvim.command("qa!").await.ok(); // Ignoring result as it won't succeed since the app closed. } } } diff --git a/src/window.rs b/src/window.rs index c0e3f4c..dff20d0 100644 --- a/src/window.rs +++ b/src/window.rs @@ -391,7 +391,10 @@ pub fn ui_loop() { for event in event_pump.poll_iter() { match event { Event::Quit { .. } => window.handle_quit(), - Event::KeyDown { keycode: received_keycode, .. } => { + Event::KeyDown { + keycode: received_keycode, + .. + } => { keycode = received_keycode; } Event::TextInput { text, .. } => keytext = Some(text),