From ddd5f6f4f627f573bc598bf99d96b003abd45914 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 7 Nov 2021 20:58:02 +0100 Subject: [PATCH] winit: don't explicitly handle Cmd-Q and Alt-F4 (#881) Closes https://github.com/emilk/egui/issues/877 Still a problem: https://github.com/rust-windowing/winit/issues/1998 --- egui-winit/CHANGELOG.md | 5 +---- egui-winit/src/epi.rs | 3 ++- egui-winit/src/lib.rs | 23 ----------------------- egui_glium/CHANGELOG.md | 1 + egui_glium/examples/native_texture.rs | 5 +++-- egui_glium/examples/pure_glium.rs | 5 +++-- egui_glium/src/epi_backend.rs | 3 +-- egui_glium/src/lib.rs | 7 ------- egui_glow/CHANGELOG.md | 1 + egui_glow/examples/pure_glow.rs | 3 ++- egui_glow/src/epi_backend.rs | 2 -- egui_glow/src/lib.rs | 5 ----- 12 files changed, 14 insertions(+), 49 deletions(-) diff --git a/egui-winit/CHANGELOG.md b/egui-winit/CHANGELOG.md index 4dde4cde..3c1a56b7 100644 --- a/egui-winit/CHANGELOG.md +++ b/egui-winit/CHANGELOG.md @@ -4,12 +4,9 @@ All notable changes to the `egui-winit` integration will be noted in this file. ## Unreleased -### Added ⭐ * Add helper `EpiIntegration` ([#871](https://github.com/emilk/egui/pull/871)). - -### Fixed 🐛 * Fix shift key getting stuck enabled with the X11 option `shift:both_capslock` enabled ([#849](https://github.com/emilk/egui/pull/849)). - +* Remove `State::is_quit_event` and `State::is_quit_shortcut` ([#881](https://github.com/emilk/egui/pull/881)). ## 0.15.0 - 2021-10-24 First stand-alone release. Previously part of `egui_glium`. diff --git a/egui-winit/src/epi.rs b/egui-winit/src/epi.rs index 2cad172f..a10dcd7a 100644 --- a/egui-winit/src/epi.rs +++ b/egui-winit/src/epi.rs @@ -268,7 +268,8 @@ impl EpiIntegration { } pub fn on_event(&mut self, event: &winit::event::WindowEvent<'_>) { - self.quit |= self.egui_winit.is_quit_event(event); + use winit::event::WindowEvent; + self.quit |= matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed); self.egui_winit.on_event(&self.egui_ctx, event); } diff --git a/egui-winit/src/lib.rs b/egui-winit/src/lib.rs index 6ae789fa..7232a14b 100644 --- a/egui-winit/src/lib.rs +++ b/egui-winit/src/lib.rs @@ -533,29 +533,6 @@ impl State { } } - /// Returns `true` if Alt-F4 (windows/linux) or Cmd-Q (Mac) - pub fn is_quit_shortcut(&self, input: &winit::event::KeyboardInput) -> bool { - if cfg!(target_os = "macos") { - input.state == winit::event::ElementState::Pressed - && self.egui_input.modifiers.mac_cmd - && input.virtual_keycode == Some(winit::event::VirtualKeyCode::Q) - } else { - input.state == winit::event::ElementState::Pressed - && self.egui_input.modifiers.alt - && input.virtual_keycode == Some(winit::event::VirtualKeyCode::F4) - } - } - - /// Returns `true` if this a close event or a Cmd-Q/Alt-F4 keyboard command. - pub fn is_quit_event(&self, event: &winit::event::WindowEvent<'_>) -> bool { - use winit::event::WindowEvent; - match event { - WindowEvent::CloseRequested | WindowEvent::Destroyed => true, - WindowEvent::KeyboardInput { input, .. } => self.is_quit_shortcut(input), - _ => false, - } - } - fn set_cursor_icon(&mut self, window: &winit::window::Window, cursor_icon: egui::CursorIcon) { // prevent flickering near frame boundary when Windows OS tries to control cursor icon for window resizing if self.current_cursor_icon == cursor_icon { diff --git a/egui_glium/CHANGELOG.md b/egui_glium/CHANGELOG.md index e0a2e257..698be31d 100644 --- a/egui_glium/CHANGELOG.md +++ b/egui_glium/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to the `egui_glium` integration will be noted in this file. ## Unreleased * Simplify `EguiGlium` interface ([#871](https://github.com/emilk/egui/pull/871)). +* Remove `EguiGlium::is_quit_event` ([#881](https://github.com/emilk/egui/pull/881)). ## 0.15.0 - 2021-10-24 diff --git a/egui_glium/examples/native_texture.rs b/egui_glium/examples/native_texture.rs index c850135b..db5da4ad 100644 --- a/egui_glium/examples/native_texture.rs +++ b/egui_glium/examples/native_texture.rs @@ -102,8 +102,9 @@ fn main() { glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(), glutin::event::Event::WindowEvent { event, .. } => { - if egui_glium.is_quit_event(&event) { - *control_flow = glium::glutin::event_loop::ControlFlow::Exit; + use glutin::event::WindowEvent; + if matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed) { + *control_flow = glutin::event_loop::ControlFlow::Exit; } egui_glium.on_event(&event); diff --git a/egui_glium/examples/pure_glium.rs b/egui_glium/examples/pure_glium.rs index ad0bf572..a9610f3c 100644 --- a/egui_glium/examples/pure_glium.rs +++ b/egui_glium/examples/pure_glium.rs @@ -72,8 +72,9 @@ fn main() { glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(), glutin::event::Event::WindowEvent { event, .. } => { - if egui_glium.is_quit_event(&event) { - *control_flow = glium::glutin::event_loop::ControlFlow::Exit; + use glutin::event::WindowEvent; + if matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed) { + *control_flow = glutin::event_loop::ControlFlow::Exit; } egui_glium.on_event(&event); diff --git a/egui_glium/src/epi_backend.rs b/egui_glium/src/epi_backend.rs index 85d947f6..ea17bd76 100644 --- a/egui_glium/src/epi_backend.rs +++ b/egui_glium/src/epi_backend.rs @@ -1,7 +1,6 @@ use crate::*; use egui::Color32; -#[cfg(target_os = "windows")] -use glium::glutin::platform::windows::WindowBuilderExtWindows; +use glium::glutin; impl epi::TextureAllocator for Painter { fn alloc_srgba_premultiplied( diff --git a/egui_glium/src/lib.rs b/egui_glium/src/lib.rs index 750ac1ff..0cbab9b4 100644 --- a/egui_glium/src/lib.rs +++ b/egui_glium/src/lib.rs @@ -97,8 +97,6 @@ pub use epi_backend::{run, NativeOptions}; pub use egui_winit; -use glium::glutin; - // ---------------------------------------------------------------------------- /// Convenience wrapper for using [`egui`] from a [`glium`] app. @@ -127,11 +125,6 @@ impl EguiGlium { self.egui_winit.on_event(&self.egui_ctx, event) } - /// Is this a close event or a Cmd-Q/Alt-F4 keyboard command? - pub fn is_quit_event(&self, event: &glutin::event::WindowEvent<'_>) -> bool { - self.egui_winit.is_quit_event(event) - } - /// Returns `needs_repaint` and shapes to draw. pub fn run( &mut self, diff --git a/egui_glow/CHANGELOG.md b/egui_glow/CHANGELOG.md index 150543b5..4a0b85dd 100644 --- a/egui_glow/CHANGELOG.md +++ b/egui_glow/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to the `egui_glow` integration will be noted in this file. ## Unreleased * Make winit/glutin an optional dependency ([#868](https://github.com/emilk/egui/pull/868)). * Simplify `EguiGlow` interface ([#871](https://github.com/emilk/egui/pull/871)). +* Remove `EguiGlow::is_quit_event` ([#881](https://github.com/emilk/egui/pull/881)). ## 0.15.0 - 2021-10-24 diff --git a/egui_glow/examples/pure_glow.rs b/egui_glow/examples/pure_glow.rs index 1327fbd1..70f8c1c1 100644 --- a/egui_glow/examples/pure_glow.rs +++ b/egui_glow/examples/pure_glow.rs @@ -90,7 +90,8 @@ fn main() { glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(), glutin::event::Event::WindowEvent { event, .. } => { - if egui_glow.is_quit_event(&event) { + use glutin::event::WindowEvent; + if matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed) { *control_flow = glutin::event_loop::ControlFlow::Exit; } diff --git a/egui_glow/src/epi_backend.rs b/egui_glow/src/epi_backend.rs index 8191801d..e4f69b5f 100644 --- a/egui_glow/src/epi_backend.rs +++ b/egui_glow/src/epi_backend.rs @@ -1,6 +1,4 @@ use crate::*; -#[cfg(target_os = "windows")] -use glutin::platform::windows::WindowBuilderExtWindows; struct RequestRepaintEvent; diff --git a/egui_glow/src/lib.rs b/egui_glow/src/lib.rs index e60f811d..3d703ae6 100644 --- a/egui_glow/src/lib.rs +++ b/egui_glow/src/lib.rs @@ -141,11 +141,6 @@ impl EguiGlow { self.egui_winit.on_event(&self.egui_ctx, event) } - /// Is this a close event or a Cmd-Q/Alt-F4 keyboard command? - pub fn is_quit_event(&self, event: &glutin::event::WindowEvent<'_>) -> bool { - self.egui_winit.is_quit_event(event) - } - /// Returns `needs_repaint` and shapes to draw. pub fn run( &mut self,