diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index 5372bc8506..05289d35ec 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -1620,7 +1620,7 @@ static void SDLTest_PrintEvent(const SDL_Event *event) case SDL_EVENT_WINDOW_SAFE_AREA_CHANGED: { SDL_Rect rect; - SDL_GetWindowSafeArea(SDL_GetWindowFromID(event->window.windowID), &rect); + SDL_GetWindowSafeArea(SDL_GetWindowFromEvent(event), &rect); SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " changed safe area to: %d,%d %dx%d\n", event->window.windowID, rect.x, rect.y, rect.w, rect.h); break; @@ -1661,7 +1661,7 @@ static void SDLTest_PrintEvent(const SDL_Event *event) SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " display changed to %" SDL_PRIs32, event->window.windowID, event->window.data1); break; case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED: - SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " display scale changed to %d%%", event->window.windowID, (int)(SDL_GetWindowDisplayScale(SDL_GetWindowFromID(event->window.windowID)) * 100.0f)); + SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " display scale changed to %d%%", event->window.windowID, (int)(SDL_GetWindowDisplayScale(SDL_GetWindowFromEvent(event)) * 100.0f)); break; case SDL_EVENT_WINDOW_OCCLUDED: SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " occluded", event->window.windowID); @@ -2089,7 +2089,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event switch (event->type) { case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED: if (state->auto_scale_content) { - SDL_Window *window = SDL_GetWindowFromID(event->window.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { float scale = SDL_GetDisplayContentScale(SDL_GetDisplayForWindow(window)); int w = state->window_w; @@ -2103,7 +2103,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event break; case SDL_EVENT_WINDOW_FOCUS_LOST: if (state->flash_on_focus_loss) { - SDL_Window *window = SDL_GetWindowFromID(event->window.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_FlashWindow(window, SDL_FLASH_UNTIL_FOCUSED); } @@ -2111,7 +2111,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event break; case SDL_EVENT_WINDOW_CLOSE_REQUESTED: { - SDL_Window *window = SDL_GetWindowFromID(event->window.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_HideWindow(window); } @@ -2127,7 +2127,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event /* Add hotkeys here */ case SDLK_PRINTSCREEN: { - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { for (i = 0; i < state->num_windows; ++i) { if (window == state->windows[i]) { @@ -2139,7 +2139,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_EQUALS: if (withControl) { /* Ctrl-+ double the size of the window */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { int w, h; SDL_GetWindowSize(window, &w, &h); @@ -2150,7 +2150,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_MINUS: if (withControl) { /* Ctrl-- half the size of the window */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { int w, h; SDL_GetWindowSize(window, &w, &h); @@ -2164,7 +2164,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_RIGHT: if (withAlt) { /* Alt-Up/Down/Left/Right switches between displays */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { int num_displays; const SDL_DisplayID *displays = SDL_GetDisplays(&num_displays); @@ -2195,7 +2195,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event } if (withShift) { /* Shift-Up/Down/Left/Right shift the window by 100px */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { const int delta = 100; int x, y; @@ -2222,7 +2222,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_O: if (withControl) { /* Ctrl-O (or Ctrl-Shift-O) changes window opacity. */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { float opacity = SDL_GetWindowOpacity(window); if (withShift) { @@ -2253,7 +2253,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event } else if (withControl) { if (withShift) { /* Ctrl-Shift-C copy screenshot! */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { for (i = 0; i < state->num_windows; ++i) { if (window == state->windows[i]) { @@ -2299,7 +2299,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_F: if (withControl) { /* Ctrl-F flash the window */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_FlashWindow(window, SDL_FLASH_BRIEFLY); } @@ -2308,7 +2308,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_G: if (withControl) { /* Ctrl-G toggle mouse grab */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_SetWindowMouseGrab(window, !SDL_GetWindowMouseGrab(window)); } @@ -2317,7 +2317,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_K: if (withControl) { /* Ctrl-K toggle keyboard grab */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_SetWindowKeyboardGrab(window, !SDL_GetWindowKeyboardGrab(window)); } @@ -2326,7 +2326,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_M: if (withControl) { /* Ctrl-M maximize */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_WindowFlags flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_MAXIMIZED) { @@ -2354,7 +2354,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_T: if (withControl) { /* Ctrl-T toggle topmost mode */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_WindowFlags flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_ALWAYS_ON_TOP) { @@ -2368,7 +2368,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_Z: if (withControl) { /* Ctrl-Z minimize */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_MinimizeWindow(window); } @@ -2377,7 +2377,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_RETURN: if (withControl) { /* Ctrl-Enter toggle fullscreen */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_WindowFlags flags = SDL_GetWindowFlags(window); if (!(flags & SDL_WINDOW_FULLSCREEN) || @@ -2390,7 +2390,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event } } else if (withAlt) { /* Alt-Enter toggle fullscreen desktop */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { SDL_WindowFlags flags = SDL_GetWindowFlags(window); if (!(flags & SDL_WINDOW_FULLSCREEN) || @@ -2407,7 +2407,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_B: if (withControl) { /* Ctrl-B toggle window border */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { const SDL_WindowFlags flags = SDL_GetWindowFlags(window); const SDL_bool b = (flags & SDL_WINDOW_BORDERLESS) ? SDL_TRUE : SDL_FALSE; @@ -2418,7 +2418,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event case SDLK_A: if (withControl) { /* Ctrl-A toggle aspect ratio */ - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { float min_aspect = 0.0f, max_aspect = 0.0f; @@ -2436,7 +2436,7 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event break; case SDLK_0: if (withControl) { - SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(event); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window); } break; diff --git a/test/checkkeys.c b/test/checkkeys.c index 3596605b64..66c2e7ed60 100644 --- a/test/checkkeys.c +++ b/test/checkkeys.c @@ -408,7 +408,7 @@ static void loop(void) break; case SDL_EVENT_FINGER_DOWN: { - SDL_Window *window = SDL_GetWindowFromID(event.tfinger.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(&event); if (SDL_TextInputActive(window)) { SDL_Log("Stopping text input for window %" SDL_PRIu32 "\n", event.tfinger.windowID); SDL_StopTextInput(window); @@ -420,7 +420,7 @@ static void loop(void) } case SDL_EVENT_MOUSE_BUTTON_DOWN: if (event.button.button == SDL_BUTTON_RIGHT) { - SDL_Window *window = SDL_GetWindowFromID(event.button.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(&event); if (SDL_TextInputActive(window)) { SDL_Log("Stopping text input for window %" SDL_PRIu32 "\n", event.button.windowID); SDL_StopTextInput(window); diff --git a/test/testwm.c b/test/testwm.c index dfd642a48e..b3fddb2838 100644 --- a/test/testwm.c +++ b/test/testwm.c @@ -167,7 +167,7 @@ static void loop(void) SDLTest_CommonEvent(state, &event, &done); if (event.type == SDL_EVENT_WINDOW_RESIZED) { - SDL_Window *window = SDL_GetWindowFromID(event.window.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(&event); if (window) { SDL_Log("Window %" SDL_PRIu32 " resized to %" SDL_PRIs32 "x%" SDL_PRIs32 "\n", event.window.windowID, @@ -176,7 +176,7 @@ static void loop(void) } } if (event.type == SDL_EVENT_WINDOW_MOVED) { - SDL_Window *window = SDL_GetWindowFromID(event.window.windowID); + SDL_Window *window = SDL_GetWindowFromEvent(&event); if (window) { SDL_Log("Window %" SDL_PRIu32 " moved to %" SDL_PRIs32 ",%" SDL_PRIs32 " (display %s)\n", event.window.windowID,