sdl: Check correct windowID based on event type. (#6703)

This commit is contained in:
Steveice10 2023-07-19 01:29:13 -07:00 committed by GitHub
parent e783b0d4a9
commit 71582a72a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

View File

@ -128,16 +128,54 @@ void EmuWindow_SDL2::InitializeSDL2() {
SDL_SetMainReady(); SDL_SetMainReady();
} }
u32 EmuWindow_SDL2::GetEventWindowId(const SDL_Event& event) const {
switch (event.type) {
case SDL_WINDOWEVENT:
return event.window.windowID;
case SDL_KEYDOWN:
case SDL_KEYUP:
return event.key.windowID;
case SDL_MOUSEMOTION:
return event.motion.windowID;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
return event.button.windowID;
case SDL_MOUSEWHEEL:
return event.wheel.windowID;
case SDL_FINGERDOWN:
case SDL_FINGERMOTION:
case SDL_FINGERUP:
return event.tfinger.windowID;
case SDL_TEXTEDITING:
return event.edit.windowID;
case SDL_TEXTEDITING_EXT:
return event.editExt.windowID;
case SDL_TEXTINPUT:
return event.text.windowID;
case SDL_DROPBEGIN:
case SDL_DROPFILE:
case SDL_DROPTEXT:
case SDL_DROPCOMPLETE:
return event.drop.windowID;
case SDL_USEREVENT:
return event.user.windowID;
default:
// Event is not for any particular window, so we can just pretend it's for this one.
return render_window_id;
}
}
void EmuWindow_SDL2::PollEvents() { void EmuWindow_SDL2::PollEvents() {
SDL_Event event; SDL_Event event;
std::vector<SDL_Event> other_window_events; std::vector<SDL_Event> other_window_events;
// SDL_PollEvent returns 0 when there are no more events in the event queue // SDL_PollEvent returns 0 when there are no more events in the event queue
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
if (event.window.windowID != render_window_id) { if (GetEventWindowId(event) != render_window_id) {
other_window_events.push_back(event); other_window_events.push_back(event);
continue; continue;
} }
switch (event.type) { switch (event.type) {
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
switch (event.window.event) { switch (event.window.event) {

View File

@ -8,6 +8,7 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
union SDL_Event;
struct SDL_Window; struct SDL_Window;
namespace Core { namespace Core {
@ -35,6 +36,9 @@ public:
void RequestClose(); void RequestClose();
protected: protected:
/// Gets the ID of the window an event originated from.
u32 GetEventWindowId(const SDL_Event& event) const;
/// Called by PollEvents when a key is pressed or released. /// Called by PollEvents when a key is pressed or released.
void OnKeyEvent(int key, u8 state); void OnKeyEvent(int key, u8 state);