diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-21 12:40:46 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-21 12:40:46 +0300 |
commit | e83ff095348ed3bb6173c38a8e7bff8b1aaf324c (patch) | |
tree | ef23f49350bb7caf5a1da751e2edf1c68927b5fd /src/ui | |
parent | 09e1f89c21f9c8fbdcfbe801cc796865809161c1 (diff) |
Restoring maximized windows
Window position and size are stored when move/resize events are received, not only when the window is closed.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/window.c | 18 | ||||
-rw-r--r-- | src/ui/window.h | 1 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index a7ec37dd..6c7775ee 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -507,6 +507,7 @@ void init_Window(iWindow *d, iRect rect) { | |||
507 | theWindow_ = d; | 507 | theWindow_ = d; |
508 | iZap(d->cursors); | 508 | iZap(d->cursors); |
509 | d->initialPos = rect.pos; | 509 | d->initialPos = rect.pos; |
510 | d->lastRect = rect; | ||
510 | d->pendingCursor = NULL; | 511 | d->pendingCursor = NULL; |
511 | d->isDrawFrozen = iTrue; | 512 | d->isDrawFrozen = iTrue; |
512 | uint32_t flags = 0; | 513 | uint32_t flags = 0; |
@@ -525,7 +526,7 @@ void init_Window(iWindow *d, iRect rect) { | |||
525 | exit(-2); | 526 | exit(-2); |
526 | } | 527 | } |
527 | } | 528 | } |
528 | if (left_Rect(rect) >= 0) { | 529 | if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) { |
529 | SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); | 530 | SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect)); |
530 | } | 531 | } |
531 | SDL_SetWindowMinimumSize(d->win, 400, 250); | 532 | SDL_SetWindowMinimumSize(d->win, 400, 250); |
@@ -608,11 +609,22 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
608 | } | 609 | } |
609 | return iFalse; | 610 | return iFalse; |
610 | #endif | 611 | #endif |
611 | case SDL_WINDOWEVENT_MOVED: | 612 | case SDL_WINDOWEVENT_MOVED: { |
612 | /* No need to do anything. */ | 613 | if (!(SDL_GetWindowFlags(d->win) & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) { |
614 | d->lastRect.pos = init_I2(ev->data1, ev->data2); | ||
615 | iInt2 border = zero_I2(); | ||
616 | #if defined (iPlatformMsys) || defined (iPlatformLinux) | ||
617 | SDL_GetWindowBordersSize(d->win, &border.y, &border.x, NULL, NULL); | ||
618 | #endif | ||
619 | d->lastRect.pos = max_I2(zero_I2(), sub_I2(d->lastRect.pos, border)); | ||
620 | } | ||
613 | return iTrue; | 621 | return iTrue; |
622 | } | ||
614 | case SDL_WINDOWEVENT_RESIZED: | 623 | case SDL_WINDOWEVENT_RESIZED: |
615 | case SDL_WINDOWEVENT_SIZE_CHANGED: | 624 | case SDL_WINDOWEVENT_SIZE_CHANGED: |
625 | if (!(SDL_GetWindowFlags(d->win) & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) { | ||
626 | d->lastRect.size = init_I2(ev->data1, ev->data2); | ||
627 | } | ||
616 | updateRootSize_Window_(d); | 628 | updateRootSize_Window_(d); |
617 | return iTrue; | 629 | return iTrue; |
618 | case SDL_WINDOWEVENT_LEAVE: | 630 | case SDL_WINDOWEVENT_LEAVE: |
diff --git a/src/ui/window.h b/src/ui/window.h index b067d30e..da4a2123 100644 --- a/src/ui/window.h +++ b/src/ui/window.h | |||
@@ -35,6 +35,7 @@ iDeclareTypeConstructionArgs(Window, iRect rect) | |||
35 | struct Impl_Window { | 35 | struct Impl_Window { |
36 | SDL_Window * win; | 36 | SDL_Window * win; |
37 | iInt2 initialPos; | 37 | iInt2 initialPos; |
38 | iRect lastRect; /* updated when window is moved/resized */ | ||
38 | iBool isDrawFrozen; /* avoids premature draws while restoring window state */ | 39 | iBool isDrawFrozen; /* avoids premature draws while restoring window state */ |
39 | SDL_Renderer *render; | 40 | SDL_Renderer *render; |
40 | iWidget * root; | 41 | iWidget * root; |