Compare commits

..

3 Commits

Author SHA1 Message Date
61e73b7b63 Apply resizing workaround on size changed
The "resized" event is called on user resizing only, while "size
changed" is called on any resize, including at every step of a
progressive resize animation.
2020-05-11 03:39:20 +02:00
5edd5a2617 Detect fullscreen changes
The window state may be changed by the window manager without scrcpy
being aware of it (for example the fullscreen mode on macOS).

Check on every "size changed" event whether the fullscreen mode has
changed.
2020-05-11 03:37:16 +02:00
9006f545fc Simplify size changes in fullscreen or maximized
If the content size changes (due to rotation for example) while the
window is maximized or fullscreen, the resize must be applied once
fullscreen and maximized are disabled.

The previous strategy consisted in storing the windowed size, computing
the target size on rotation, and applying it window restoration. But
tracking the windowed size (while ignoring the non-windowed size) was
tricky, due to unspecified order of SDL events (e.g. size changes can be
notified before "maximized" events), race conditions when reading window
flags, different behaviors on different platforms...

To simplify the whole resize management, store the old content size (the
frame size, possibly rotated) when it changes while the window is
maximized or fullscreen, so that the new optimal size can be computed on
window restoration.
2020-05-11 03:36:29 +02:00
2 changed files with 3 additions and 18 deletions

View File

@ -133,7 +133,7 @@ static int
event_watcher(void *data, SDL_Event *event) {
(void) data;
if (event->type == SDL_WINDOWEVENT
&& event->window.event == SDL_WINDOWEVENT_RESIZED) {
&& 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_render(&screen);

View File

@ -488,9 +488,6 @@ screen_resize_to_fit(struct screen *screen) {
return;
}
int flags = SDL_GetWindowFlags(screen->window);
LOGI("resize to fit (%d 0x%x)", screen->maximized, flags);
if (screen->maximized) {
SDL_RestoreWindow(screen->window);
screen->maximized = false;
@ -499,7 +496,7 @@ screen_resize_to_fit(struct screen *screen) {
struct size optimal_size =
get_optimal_window_size(screen, screen->content_size);
SDL_SetWindowSize(screen->window, optimal_size.width, optimal_size.height);
LOGI("Resized to optimal size: %ux%u", optimal_size.width,
LOGD("Resized to optimal size: %ux%u", optimal_size.width,
optimal_size.height);
}
@ -523,7 +520,6 @@ screen_resize_to_pixel_perfect(struct screen *screen) {
static inline bool
is_fullscreen(const struct screen *screen) {
uint32_t flags = SDL_GetWindowFlags(screen->window);
LOGI("flags = 0x%x", flags);
return !!(flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP));
}
@ -546,27 +542,16 @@ screen_handle_window_event(struct screen *screen,
const SDL_WindowEvent *event) {
switch (event->event) {
case SDL_WINDOWEVENT_EXPOSED:
LOGI("EXPOSED");
screen_render(screen);
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
LOGI("SIZE_CHANGED %dx%d", event->data1, event->data2);
//update_fullscreen_state(screen);
update_fullscreen_state(screen);
screen_render(screen);
break;
case SDL_WINDOWEVENT_MAXIMIZED:
LOGI("MAXIMIZED");
screen->maximized = true;
break;
case SDL_WINDOWEVENT_RESTORED:
LOGI("RESTORED");
if (screen->fullscreen) {
// On Windows, in maximized+fullscreen, disabling fullscreen
// mode unexpectedly triggers the "restored" then "maximized"
// events, leaving the window in a weird state (maximized
// according to the events, but not maximized visually).
break;
}
screen->maximized = false;
apply_pending_resize(screen);
break;