Phone: turns with the phone (portrait layout), fullscreen, picture the right way up; tap/drag fixes for touch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NMSrd5oe1GpUD7E6d825KP
This commit is contained in:
Nexoniarz 2026-10-19 23:07:37 +02:00
commit a5e0d2a9eb
5 changed files with 87 additions and 16 deletions

View file

@ -40,7 +40,11 @@ bool Window::init(const char* title, int width, int height, bool opengl) {
log::error("SDL_Init failed: {}", SDL_GetError());
return false;
}
window_ = SDL_CreateWindow(title, width, height, (opengl ? SDL_WINDOW_OPENGL : SDL_WINDOW_VULKAN) | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY);
SDL_WindowFlags flags = (opengl ? SDL_WINDOW_OPENGL : SDL_WINDOW_VULKAN) | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY;
#if defined(__ANDROID__)
flags |= SDL_WINDOW_FULLSCREEN; // (the whole screen: no status or navigation bar over the edges)
#endif
window_ = SDL_CreateWindow(title, width, height, flags);
if (!window_) {
log::error("SDL_CreateWindow failed: {}", SDL_GetError());
return false;

View file

@ -227,6 +227,9 @@ bool Device::createSwapchain() {
vkDeviceWaitIdle(device_);
VkSwapchainKHR old = swapchain_;
auto sc = vkb::SwapchainBuilder(physical_, device_, surface_)
#if defined(__ANDROID__) // (the compositor turns the picture with the phone: drawn as it's seen)
.set_pre_transform_flags(VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR)
#endif
.set_desired_format({VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR})
.set_desired_present_mode(vsync_ ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_MAILBOX_KHR)
.add_fallback_present_mode(vsync_ ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_IMMEDIATE_KHR)
@ -312,6 +315,13 @@ void Device::endFrame() {
pi.pSwapchains = &swapchain_;
pi.pImageIndices = &imageIndex_;
VkResult r = vkQueuePresentKHR(queue_, &pi);
#if defined(__ANDROID__) // (suboptimal every frame while the phone's turned: the compositor turns it; only a new size matters)
if (r == VK_SUBOPTIMAL_KHR) {
uint32_t w = 0, h = 0;
window_->pixelSize(w, h);
if (w == extent_.width && h == extent_.height) r = VK_SUCCESS;
}
#endif
if (r == VK_ERROR_OUT_OF_DATE_KHR || r == VK_SUBOPTIMAL_KHR) swapchainDirty_ = true;
else VK_CHECK(r);