SDL
SDL copied to clipboard
Android safe area problems
A few things wrong:
-
Initial safe area is all zeros.
-
On some devices (Samsing S20) the
WINDOW_SAFE_AREA_CHANGEDevent is a bit spammy:
0:10:04.903 WINDOW_SAFE_AREA_CHANGED 0, 0, 2178 x 1008
0:10:04.903 WINDOW_PIXEL_SIZE_CHANGED 2178 x 1008
0:10:04.903 WINDOW_RESIZED 2178 x 1008
0:10:04.894 WINDOW_SAFE_AREA_CHANGED 0, 0, 2400 x 1080
0:10:04.894 WINDOW_LEAVE_FULLSCREEN
---
0:09:41.194 WINDOW_SAFE_AREA_CHANGED 78, 72, 2178 x 1008
0:09:41.194 WINDOW_PIXEL_SIZE_CHANGED 2400 x 1080
0:09:41.194 WINDOW_RESIZED 2400 x 1080
0:09:41.167 WINDOW_SAFE_AREA_CHANGED 78, 72, 1956 x 936
0:09:41.167 WINDOW_ENTER_FULLSCREEN
-
Toggling fullscreen now causes a 1/3 second delay. Removing both
setOnApplyWindowInsetsListener(this)removes the delay. -
Safe area doesn't make much sense. It seems to be exactly the same area as non-fullscreen area, which doesn't take into account the curve at the bottom, maybe we're using the wrong settings?:
Here's the test code:
int main(int argc, char** argv) {
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
SDL_Window *w = SDL_CreateWindow("Test", 640, 480, 0);
SDL_Renderer *r = SDL_CreateRenderer(w, 0);
SDL_bool running = SDL_TRUE; SDL_bool background = SDL_FALSE;
while (running) {
SDL_PumpEvents();
SDL_Event event;
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENT_FIRST, SDL_EVENT_LAST) == 1) {
switch(event.type) {
case SDL_EVENT_KEY_UP:
case SDL_EVENT_QUIT:
running = SDL_FALSE;
break;
case SDL_EVENT_FINGER_UP:
SDL_SetWindowFullscreen(w, !(SDL_GetWindowFlags(w) & SDL_WINDOW_FULLSCREEN));
break;
case SDL_EVENT_DID_ENTER_FOREGROUND:
background = SDL_FALSE;
break;
case SDL_EVENT_WILL_ENTER_BACKGROUND:
background = SDL_TRUE;
break;
}
}
if(!background) {
SDL_SetRenderDrawColor(r, 128, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(r);
SDL_SetRenderDrawColor(r, 0, 128, 0, SDL_ALPHA_OPAQUE);
SDL_Rect safe;
SDL_GetWindowSafeArea(w, &safe);
SDL_FRect fsafe = {safe.x, safe.y, safe.w, safe.h};
SDL_RenderFillRect(r, &fsafe);
SDL_RenderPresent(r);
}
}
SDL_DestroyRenderer(r);
SDL_DestroyWindow(w);
SDL_Quit();
return 0;
}