Compare commits
3 Commits
logical_si
...
issue15
Author | SHA1 | Date | |
---|---|---|---|
b0ead07f61 | |||
8581d6850b | |||
92cb3a6661 |
@ -109,9 +109,10 @@ static int
|
||||
event_watcher(void *data, SDL_Event *event) {
|
||||
(void) data;
|
||||
if (event->type == SDL_WINDOWEVENT
|
||||
&& event->window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
// called from another thread, not very safe, but it's a workaround!
|
||||
screen_render(&screen);
|
||||
&& event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
||||
// In practice, it seems to always be called from the same thread in
|
||||
// that specific case. Anyway, it's just a workaround.
|
||||
screen_handle_window_event(&screen, &event->window);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -113,6 +113,13 @@ get_optimal_size(struct size current_size, struct size content_size) {
|
||||
h = MIN(current_size.height, display_size.height);
|
||||
}
|
||||
|
||||
if (h == w * content_size.height / content_size.width
|
||||
|| w == h * content_size.width / content_size.height) {
|
||||
// The size is already optimal, if we ignore rounding errors due to
|
||||
// integer window dimensions
|
||||
return (struct size) {w, h};
|
||||
}
|
||||
|
||||
bool keep_width = content_size.width * h > content_size.height * w;
|
||||
if (keep_width) {
|
||||
// remove black borders on top and bottom
|
||||
@ -512,11 +519,24 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
|
||||
content_size.height);
|
||||
}
|
||||
|
||||
static void
|
||||
screen_reset_logical_size(struct screen *screen) {
|
||||
// Re-apply the current logical size.
|
||||
if (SDL_RenderSetLogicalSize(screen->renderer, screen->content_size.width,
|
||||
screen->content_size.height)) {
|
||||
LOGE("Could not reset renderer logical size: %s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
screen_handle_window_event(struct screen *screen,
|
||||
const SDL_WindowEvent *event) {
|
||||
switch (event->event) {
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
// Re-apply the current logical size, in case the window has been
|
||||
// moved to a screen with a different HiDPI scaling
|
||||
// <https://github.com/Genymobile/scrcpy/issues/15>
|
||||
screen_reset_logical_size(screen);
|
||||
screen_render(screen);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
|
Reference in New Issue
Block a user