From 6a08d04af9c22d2b6ec432b9ac48a299abcfb9f8 Mon Sep 17 00:00:00 2001 From: Squall Leonhart Date: Sun, 18 Feb 2024 15:52:11 +1100 Subject: [PATCH] UI: Make Alt+F4/Ctrl+Q more reliable (#1035) --- src/gui/MainWindow.cpp | 14 ++++++++++++++ src/gui/MainWindow.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index dc9ff0a8..d271ca3a 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1485,6 +1485,19 @@ void MainWindow::OnKeyUp(wxKeyEvent& event) g_window_info.has_screenshot_request = true; // async screenshot request } +void MainWindow::OnKeyDown(wxKeyEvent& event) +{ + if ((event.AltDown() && event.GetKeyCode() == WXK_F4) || + (event.CmdDown() && event.GetKeyCode() == 'Q')) + { + Close(true); + } + else + { + event.Skip(); + } +} + void MainWindow::OnChar(wxKeyEvent& event) { if (swkbd_hasKeyboardInputHook()) @@ -1590,6 +1603,7 @@ void MainWindow::CreateCanvas() // key events m_render_canvas->Bind(wxEVT_KEY_UP, &MainWindow::OnKeyUp, this); + m_render_canvas->Bind(wxEVT_KEY_DOWN, &MainWindow::OnKeyDown, this); m_render_canvas->Bind(wxEVT_CHAR, &MainWindow::OnChar, this); m_render_canvas->SetDropTarget(new wxAmiiboDropTarget(this)); diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 25100b72..88d2a1d3 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -124,6 +124,7 @@ public: void OnSetWindowTitle(wxCommandEvent& event); void OnKeyUp(wxKeyEvent& event); + void OnKeyDown(wxKeyEvent& event); void OnChar(wxKeyEvent& event); void OnToolsInput(wxCommandEvent& event);