Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SDL_GetWindowFromEvent #10459

Merged
merged 1 commit into from
Aug 3, 2024

Conversation

madebr
Copy link
Contributor

@madebr madebr commented Aug 2, 2024

Add SDL_GetWindowIDFromEvent SDL_GetWindowFromEvent as a convenience function to get the window id from a SDL_event.

To fix the imgui event handling without modifying imgui's code, you can do:

extern SDL_Window *imgui_sdl_window;
SDL_Event event;
SDL_Window *event_window = SDL_GetWindowFromEvent(&event);
if (event_window == imgui_sdl_window || event_window == NULL) {
    ImGui_ImplSDL3_ProcessEvent(&event);
}

@slouken
The xcode project needs an update: I added the new code to src/events/SDL_categories.c and src/events/SDL_categories_c.h
CI does not build any xcode test projects, so this issue is not caught.

Description

Existing Issue(s)

Fixes #10457

@slouken
Copy link
Collaborator

slouken commented Aug 2, 2024

Can you change it to SDL_GetWindowFromEvent()?

Also, can we add an Xcode build to CI, or is that crazy talk? :)

@madebr
Copy link
Contributor Author

madebr commented Aug 2, 2024

Also, can we add an Xcode build to CI, or is that crazy talk? :)

Xcode is built, see the tvOS (xcode) and iOS (xcode) jobs.
I'm just saying the xcode projects only build SDL3 and SDL3_test, no tests.
So a missing symbol is not catched.

@slouken
Copy link
Collaborator

slouken commented Aug 2, 2024

Also, can we add an Xcode build to CI, or is that crazy talk? :)

Xcode is built, see the tvOS (xcode) and iOS (xcode) jobs. I'm just saying the xcode projects only build SDL3 and SDL3_test, no tests. So a missing symbol is not catched.

Oh, gotcha.

include/SDL3/SDL_events.h Outdated Show resolved Hide resolved
@madebr
Copy link
Contributor Author

madebr commented Aug 2, 2024

Can you change it to SDL_GetWindowFromEvent()?

It still returns a SDL_WindowID? Or should it pull the window id through SDL_GetWindowFromID?

src/events/SDL_categories.c Outdated Show resolved Hide resolved
@slouken
Copy link
Collaborator

slouken commented Aug 2, 2024

Can you change it to SDL_GetWindowFromEvent()?

It still returns a SDL_WindowID? Or should it pull the window id through SDL_GetWindowFromID?

It should return SDL_Window *

@madebr madebr force-pushed the add-SDL_GetWindowIDFromEvent branch from 6605851 to 7b0adfc Compare August 3, 2024 00:05
@madebr madebr changed the title Added SDL_GetWindowIDFromEvent Added SDL_GetWindowFromEvent Aug 3, 2024
@@ -1400,6 +1400,20 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EventEnabled(Uint32 type);
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);

/**
* Get the associated window of an event.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Get the associated window of an event.
* Get window associated with an event.

/**
* Get the associated window of an event.
*
* \param event SDL event of which to get the window.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* \param event SDL event of which to get the window.
* \param event an event containing a `windowID`

src/events/SDL_categories.c Outdated Show resolved Hide resolved
src/events/SDL_categories.c Outdated Show resolved Hide resolved
@madebr madebr force-pushed the add-SDL_GetWindowIDFromEvent branch from 7b0adfc to 934dd8b Compare August 3, 2024 00:27
@madebr madebr force-pushed the add-SDL_GetWindowIDFromEvent branch from 934dd8b to c7dec9d Compare August 3, 2024 01:43
Comment on lines 222 to 225
case -1;
/* invalid event type (error is set by SDL_GetEventCategory) */
return NULL;
default:
/* event has no assiciated window (not an error) */
return NULL;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these to document the 2 cases.

@madebr madebr force-pushed the add-SDL_GetWindowIDFromEvent branch 3 times, most recently from 7d78ce0 to 78fa3b3 Compare August 3, 2024 01:48
@madebr madebr force-pushed the add-SDL_GetWindowIDFromEvent branch from 78fa3b3 to 3ea0167 Compare August 3, 2024 01:52
@madebr madebr merged commit f57c597 into libsdl-org:main Aug 3, 2024
38 checks passed
@madebr madebr deleted the add-SDL_GetWindowIDFromEvent branch August 3, 2024 02:37
@madebr
Copy link
Contributor Author

madebr commented Aug 3, 2024

(Don't forget about the xcode project)

lumpalette added a commit to lumpalette/SDL_cs that referenced this pull request Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Easy way to get a windowID from a SDL_Event
2 participants