25void syncWindowPixelSize() {
28 auto *sdlWin =
dynamic_cast<Window *
>(win);
30 SDL_Window *native =
static_cast<SDL_Window *
>(sdlWin->getHandle());
33 int lw = 0, lh = 0, pw = 0, ph = 0;
34 SDL_GetWindowSize(native, &lw, &lh);
35 SDL_Vulkan_GetDrawableSize(native, &pw, &ph);
36 if (pw <= 0 || ph <= 0) {
41 s.
width =
static_cast<uint16_t
>(std::max(lw, 1));
42 s.height =
static_cast<uint16_t
>(std::max(lh, 1));
44 sdlWin->updateSettings(
s,
true);
53int SDLCALL watchAppEvents(
void * , SDL_Event *event) {
54 auto *surfaceHost = eve::cap::query<IWindowSurfaceHost>();
55 if (!surfaceHost)
return 1;
57 switch (event->type) {
58 case SDL_APP_DIDENTERBACKGROUND:
60 surfaceHost->setActive(
false);
62 case SDL_APP_WILLENTERFOREGROUND:
63 case SDL_APP_DIDENTERFOREGROUND:
66 surfaceHost->requestSurfaceRecreate();
67 surfaceHost->setActive(
true);
68 syncWindowPixelSize();
78 bool shouldConsumePlatformEvent(
const void *nativeEvent)
override {
79 const auto &e = *
static_cast<const SDL_Event *
>(nativeEvent);
80 if (e.type == SDL_WINDOWEVENT && (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED ||
81 e.window.event == SDL_WINDOWEVENT_RESIZED))
82 syncWindowPixelSize();
88 void onPumpFinished()
override {
91 if (watchInstalled_)
return;
92 watchInstalled_ =
true;
93 SDL_AddEventWatch(watchAppEvents,
nullptr);
97 bool watchInstalled_ =
false;
102 static WindowEventSink sink;
103 eve::cap::addListener<eve::platform_event::IPlatformEventSink>(