Skip to content

Commit ddd5f6f

Browse files
authored
winit: don't explicitly handle Cmd-Q and Alt-F4 (emilk#881)
Closes emilk#877 Still a problem: rust-windowing/winit#1998
1 parent 19d24bb commit ddd5f6f

File tree

12 files changed

+14
-49
lines changed

12 files changed

+14
-49
lines changed

egui-winit/CHANGELOG.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ All notable changes to the `egui-winit` integration will be noted in this file.
44

55

66
## Unreleased
7-
### Added ⭐
87
* Add helper `EpiIntegration` ([#871](https://github.com/emilk/egui/pull/871)).
9-
10-
### Fixed 🐛
118
* Fix shift key getting stuck enabled with the X11 option `shift:both_capslock` enabled ([#849](https://github.com/emilk/egui/pull/849)).
12-
9+
* Remove `State::is_quit_event` and `State::is_quit_shortcut` ([#881](https://github.com/emilk/egui/pull/881)).
1310

1411
## 0.15.0 - 2021-10-24
1512
First stand-alone release. Previously part of `egui_glium`.

egui-winit/src/epi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ impl EpiIntegration {
268268
}
269269

270270
pub fn on_event(&mut self, event: &winit::event::WindowEvent<'_>) {
271-
self.quit |= self.egui_winit.is_quit_event(event);
271+
use winit::event::WindowEvent;
272+
self.quit |= matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed);
272273
self.egui_winit.on_event(&self.egui_ctx, event);
273274
}
274275

egui-winit/src/lib.rs

-23
Original file line numberDiff line numberDiff line change
@@ -533,29 +533,6 @@ impl State {
533533
}
534534
}
535535

536-
/// Returns `true` if Alt-F4 (windows/linux) or Cmd-Q (Mac)
537-
pub fn is_quit_shortcut(&self, input: &winit::event::KeyboardInput) -> bool {
538-
if cfg!(target_os = "macos") {
539-
input.state == winit::event::ElementState::Pressed
540-
&& self.egui_input.modifiers.mac_cmd
541-
&& input.virtual_keycode == Some(winit::event::VirtualKeyCode::Q)
542-
} else {
543-
input.state == winit::event::ElementState::Pressed
544-
&& self.egui_input.modifiers.alt
545-
&& input.virtual_keycode == Some(winit::event::VirtualKeyCode::F4)
546-
}
547-
}
548-
549-
/// Returns `true` if this a close event or a Cmd-Q/Alt-F4 keyboard command.
550-
pub fn is_quit_event(&self, event: &winit::event::WindowEvent<'_>) -> bool {
551-
use winit::event::WindowEvent;
552-
match event {
553-
WindowEvent::CloseRequested | WindowEvent::Destroyed => true,
554-
WindowEvent::KeyboardInput { input, .. } => self.is_quit_shortcut(input),
555-
_ => false,
556-
}
557-
}
558-
559536
fn set_cursor_icon(&mut self, window: &winit::window::Window, cursor_icon: egui::CursorIcon) {
560537
// prevent flickering near frame boundary when Windows OS tries to control cursor icon for window resizing
561538
if self.current_cursor_icon == cursor_icon {

egui_glium/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to the `egui_glium` integration will be noted in this file.
44

55
## Unreleased
66
* Simplify `EguiGlium` interface ([#871](https://github.com/emilk/egui/pull/871)).
7+
* Remove `EguiGlium::is_quit_event` ([#881](https://github.com/emilk/egui/pull/881)).
78

89

910
## 0.15.0 - 2021-10-24

egui_glium/examples/native_texture.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ fn main() {
102102
glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(),
103103

104104
glutin::event::Event::WindowEvent { event, .. } => {
105-
if egui_glium.is_quit_event(&event) {
106-
*control_flow = glium::glutin::event_loop::ControlFlow::Exit;
105+
use glutin::event::WindowEvent;
106+
if matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed) {
107+
*control_flow = glutin::event_loop::ControlFlow::Exit;
107108
}
108109

109110
egui_glium.on_event(&event);

egui_glium/examples/pure_glium.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ fn main() {
7272
glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(),
7373

7474
glutin::event::Event::WindowEvent { event, .. } => {
75-
if egui_glium.is_quit_event(&event) {
76-
*control_flow = glium::glutin::event_loop::ControlFlow::Exit;
75+
use glutin::event::WindowEvent;
76+
if matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed) {
77+
*control_flow = glutin::event_loop::ControlFlow::Exit;
7778
}
7879

7980
egui_glium.on_event(&event);

egui_glium/src/epi_backend.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::*;
22
use egui::Color32;
3-
#[cfg(target_os = "windows")]
4-
use glium::glutin::platform::windows::WindowBuilderExtWindows;
3+
use glium::glutin;
54

65
impl epi::TextureAllocator for Painter {
76
fn alloc_srgba_premultiplied(

egui_glium/src/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ pub use epi_backend::{run, NativeOptions};
9797

9898
pub use egui_winit;
9999

100-
use glium::glutin;
101-
102100
// ----------------------------------------------------------------------------
103101

104102
/// Convenience wrapper for using [`egui`] from a [`glium`] app.
@@ -127,11 +125,6 @@ impl EguiGlium {
127125
self.egui_winit.on_event(&self.egui_ctx, event)
128126
}
129127

130-
/// Is this a close event or a Cmd-Q/Alt-F4 keyboard command?
131-
pub fn is_quit_event(&self, event: &glutin::event::WindowEvent<'_>) -> bool {
132-
self.egui_winit.is_quit_event(event)
133-
}
134-
135128
/// Returns `needs_repaint` and shapes to draw.
136129
pub fn run(
137130
&mut self,

egui_glow/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to the `egui_glow` integration will be noted in this file.
55
## Unreleased
66
* Make winit/glutin an optional dependency ([#868](https://github.com/emilk/egui/pull/868)).
77
* Simplify `EguiGlow` interface ([#871](https://github.com/emilk/egui/pull/871)).
8+
* Remove `EguiGlow::is_quit_event` ([#881](https://github.com/emilk/egui/pull/881)).
89

910

1011
## 0.15.0 - 2021-10-24

egui_glow/examples/pure_glow.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ fn main() {
9090
glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(),
9191

9292
glutin::event::Event::WindowEvent { event, .. } => {
93-
if egui_glow.is_quit_event(&event) {
93+
use glutin::event::WindowEvent;
94+
if matches!(event, WindowEvent::CloseRequested | WindowEvent::Destroyed) {
9495
*control_flow = glutin::event_loop::ControlFlow::Exit;
9596
}
9697

egui_glow/src/epi_backend.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use crate::*;
2-
#[cfg(target_os = "windows")]
3-
use glutin::platform::windows::WindowBuilderExtWindows;
42

53
struct RequestRepaintEvent;
64

egui_glow/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,6 @@ impl EguiGlow {
141141
self.egui_winit.on_event(&self.egui_ctx, event)
142142
}
143143

144-
/// Is this a close event or a Cmd-Q/Alt-F4 keyboard command?
145-
pub fn is_quit_event(&self, event: &glutin::event::WindowEvent<'_>) -> bool {
146-
self.egui_winit.is_quit_event(event)
147-
}
148-
149144
/// Returns `needs_repaint` and shapes to draw.
150145
pub fn run(
151146
&mut self,

0 commit comments

Comments
 (0)