feat: handle WM_LBUTTONDOWN WM_LBUTTONUP

This commit is contained in:
H999 2025-01-17 22:28:47 +07:00 committed by GitHub
parent 0ba9d35705
commit 40305fc9b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,9 @@
#include <assert.h>
#include <string.h>
#include <windowsx.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#include "events.h"
#include "icon.h"
@ -325,6 +327,7 @@ sc_screen_frame_sink_push(struct sc_frame_sink *sink, const AVFrame *frame) {
bool
sc_screen_init(struct sc_screen *screen,
const struct sc_screen_params *params) {
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
screen->resize_pending = false;
screen->has_frame = false;
screen->fullscreen = false;
@ -859,6 +862,32 @@ sc_screen_handle_event(struct sc_screen *screen, const SDL_Event *event) {
break;
}
return true;
case SDL_SYSWMEVENT:
if (event -> syswm.msg) {
UINT msg = event -> syswm.msg -> msg.win.msg;
if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP) {
LPARAM lParam = event -> syswm.msg -> msg.win.lParam;
int32_t x = GET_X_LPARAM(lParam);
int32_t y = GET_Y_LPARAM(lParam);
SDL_Event sdlEvent;
SDL_zero(sdlEvent);
switch (msg) {
case WM_LBUTTONDOWN:
sdlEvent.type = SDL_MOUSEBUTTONDOWN;
sdlEvent.button.state = SDL_PRESSED;
break;
case WM_LBUTTONUP:
sdlEvent.type = SDL_MOUSEBUTTONUP;
sdlEvent.button.state = SDL_RELEASED;
break;
}
sdlEvent.button.button = SDL_BUTTON_LEFT;
sdlEvent.button.x = x;
sdlEvent.button.y = y;
SDL_PushEvent(&sdlEvent);
}
}
return true;
}
if (sc_screen_is_relative_mode(screen)