Compare commits

..

7 Commits

Author SHA1 Message Date
Romain Vimont
22ec47142c more logs 2020-05-13 11:47:59 +02:00
Romain Vimont
fe76bf3ebb fix 2020-05-13 11:45:58 +02:00
Romain Vimont
5024b67b9c tests 2020-05-13 11:37:50 +02:00
Romain Vimont
2b8239c047 log window flags on size change 2020-05-12 22:33:57 +02:00
Romain Vimont
bcb3942469 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-12 22:33:57 +02:00
Romain Vimont
b19d708a68 Workaround maximized+fullscreen on Windows
On Windows, in maximized+fullscreen state, 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).

Moreover, apply_pending_resize() asserts that fullscreen is disabled.

To avoid the issue, if fullscreen is set, just ignore the "restored"
event.
2020-05-12 22:33:57 +02:00
Romain Vimont
6dc113e67b 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 on 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-12 22:33:51 +02:00
2 changed files with 18 additions and 3 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_SIZE_CHANGED) {
&& event->window.event == SDL_WINDOWEVENT_RESIZED) {
// 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,6 +488,9 @@ 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;
@@ -496,7 +499,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);
LOGD("Resized to optimal size: %ux%u", optimal_size.width,
LOGI("Resized to optimal size: %ux%u", optimal_size.width,
optimal_size.height);
}
@@ -520,6 +523,7 @@ 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));
}
@@ -542,16 +546,27 @@ 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:
update_fullscreen_state(screen);
LOGI("SIZE_CHANGED %dx%d", event->data1, event->data2);
//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;