Using SDL in plug-ins. Possible?

Hello!
I intend to use SDL as the backend of my UI engine in not just standalone desktop applications, but also in plug-ins (on Windows and macOS).
I am studying SDL, and the UI seems to work very well in the standalone, however I am not sure if it is possible to use it in plug-ins where I have no access to, and cannot replace the main message loop, because it runs in the host application.
Is it possible to handle SDL events in a plug-in, and how?
Is event handling mandatory when SDL_INIT_VIDEO is enabled?

Thanks!
John

Not 100%, but think you could try event watch. This was maybe a similar usecase I had once:

static int joyEventWatch(void *userdata, SDL_Event *event) {
    if (event->type == SDL_JOYAXISMOTION || event->type == SDL_JOYBUTTONUP || event->type == SDL_JOYBUTTONDOWN || event->type == SDL_JOYHATMOTION ) {
        SDL_LockMutex(joyEventQueueMutex);
        joyEventQueue.push(*event);
        SDL_UnlockMutex(joyEventQueueMutex);
     }
}

SDL_Event getJoyEvent() {
	SDL_Event result; //  can't result = { .type = 0 } because MSVC dislikes it.
	result.type = 0;  // if 0, means there wasn't an event.

    SDL_LockMutex(joyEventQueueMutex);
    if (!joyEventQueue.empty()) {
        result = joyEventQueue.front();
        joyEventQueue.pop();
    }
    SDL_UnlockMutex(joyEventQueueMutex);
    
    return result;
}

void set_joy_event_watch() {
    joyEventQueueMutex = SDL_CreateMutex();
    SDL_AddEventWatch(joyEventWatch, nullptr);
}

Thanks for the reply!

On macOS all the UI handling runs in the main thread, so it may be possible to use SDL_PeepEvents to handle any SDL events whenever my window receives any messages.
On Windows maybe SetWindowsHookEx could be used.

I was wondering if anyone has experience in using SDL in situations when the main event loop is run by another application.

I will try to explain in words what the above code does, just in case is useful.

So, for context, my usecase was I had a plugin that would handle joystick differently from the main software, so I used SDL_AddEventWatch to watch for when some events happened, and then I pickup the events and push them in my own queue. This is done from the plugin side at startup.

Then, instead of my plugin use SDL Event loop, it uses it’s own getEvent function (getJoyEvent in case above), to pull events from it’s queue, at it’s own pace.

Again, if it doesn’t fit your case, it’s alright, just thought I would explain the code because it took me a little time figuring how I would do this at the time I wrote it - with a friends help.

Thanks for the explanation!
What I am looking for is how to add SDL event handling to an existing (non-SDL) event loop on Windows and macOS. E.g. when another application loads your plug-in which uses SDL. Is this possible?

Thanks!
John