Skip to content

Commit

Permalink
Copy SDL2_SYSWMEVENT data into temporary memory for the event
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Feb 11, 2025
1 parent 5ccee77 commit 7a18b6c
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/events/SDL_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,52 @@
// Make sure the type in the SDL_Event aligns properly across the union
SDL_COMPILE_TIME_ASSERT(SDL_Event_type, sizeof(Uint32) == sizeof(SDL_EventType));

#define SDL2_SYSWMEVENT 0x201

#ifdef SDL_VIDEO_DRIVER_WINDOWS
#include "../core/windows/SDL_windows.h"
#endif

#ifdef SDL_VIDEO_DRIVER_X11
#include <X11/Xlib.h>
#endif

typedef struct SDL2_version
{
Uint8 major;
Uint8 minor;
Uint8 patch;
} SDL2_version;

typedef enum
{
SDL2_SYSWM_UNKNOWN
} SDL2_SYSWM_TYPE;

typedef struct SDL2_SysWMmsg
{
SDL2_version version;
SDL2_SYSWM_TYPE subsystem;
union
{
#ifdef SDL_VIDEO_DRIVER_WINDOWS
struct {
HWND hwnd; /**< The window for the message */
UINT msg; /**< The type of message */
WPARAM wParam; /**< WORD message parameter */
LPARAM lParam; /**< LONG message parameter */
} win;
#endif
#ifdef SDL_VIDEO_DRIVER_X11
struct {
XEvent event;
} x11;
#endif
/* Can't have an empty union */
int dummy;
} msg;
} SDL2_SysWMmsg;

typedef struct SDL_EventWatcher
{
SDL_EventFilter callback;
Expand Down Expand Up @@ -214,6 +260,17 @@ static void SDL_LinkTemporaryMemoryToEvent(SDL_EventEntry *event, const void *me
}
}

static void SDL_TransferSysWMMemoryToEvent(SDL_EventEntry *event)
{
SDL2_SysWMmsg **wmmsg = (SDL2_SysWMmsg **)((&event->event.common)+1);
SDL2_SysWMmsg *mem = SDL_AllocateTemporaryMemory(sizeof(*mem));
if (mem) {
SDL_copyp(mem, *wmmsg);
*wmmsg = mem;
SDL_LinkTemporaryMemoryToEvent(event, mem);
}
}

// Transfer the event memory from the thread-local event memory list to the event
static void SDL_TransferTemporaryMemoryToEvent(SDL_EventEntry *event)
{
Expand All @@ -238,6 +295,10 @@ static void SDL_TransferTemporaryMemoryToEvent(SDL_EventEntry *event)
case SDL_EVENT_CLIPBOARD_UPDATE:
SDL_LinkTemporaryMemoryToEvent(event, event->event.clipboard.mime_types);
break;
case SDL2_SYSWMEVENT:
// We need to copy the stack pointer into temporary memory
SDL_TransferSysWMMemoryToEvent(event);
break;
default:
break;
}
Expand Down

0 comments on commit 7a18b6c

Please sign in to comment.