summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-21 14:12:55 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-21 14:12:55 +0300
commitca17138cf54ee42792628269a77cc45a44b8e8dc (patch)
treec8334482809e6a7fd812dc78caafcba3d81951d7 /src
parentbbba0d93270cc8a4ca71295cb1e0ab99e86e320d (diff)
parentce928050f3f48db8c1dc46030f36fefc705de987 (diff)
Merge branch 'release' into dev
Window state bug fixes from the release branch.
Diffstat (limited to 'src')
-rw-r--r--src/app.c26
-rw-r--r--src/ui/window.c27
-rw-r--r--src/ui/window.h1
3 files changed, 41 insertions, 13 deletions
diff --git a/src/app.c b/src/app.c
index 0a9acd21..839e8e65 100644
--- a/src/app.c
+++ b/src/app.c
@@ -139,19 +139,21 @@ static iString *serializePrefs_App_(const iApp *d) {
139 const iSidebarWidget *sidebar = findWidget_App("sidebar"); 139 const iSidebarWidget *sidebar = findWidget_App("sidebar");
140 appendFormat_String(str, "window.retain arg:%d\n", d->prefs.retainWindowSize); 140 appendFormat_String(str, "window.retain arg:%d\n", d->prefs.retainWindowSize);
141 if (d->prefs.retainWindowSize) { 141 if (d->prefs.retainWindowSize) {
142 const iBool isMaximized = (SDL_GetWindowFlags(d->window->win) & SDL_WINDOW_MAXIMIZED) != 0;
142 int w, h, x, y; 143 int w, h, x, y;
143 SDL_GetWindowSize(d->window->win, &w, &h); 144 x = d->window->lastRect.pos.x;
144 SDL_GetWindowPosition(d->window->win, &x, &y); 145 y = d->window->lastRect.pos.y;
145#if defined (iPlatformLinux) 146 w = d->window->lastRect.size.x;
146 /* Workaround for window position being unaffected by decorations on creation. */ { 147 h = d->window->lastRect.size.y;
147 int bl, bt;
148 SDL_GetWindowBordersSize(d->window->win, &bt, &bl, NULL, NULL);
149 x -= bl;
150 y -= bt;
151 }
152#endif
153 appendFormat_String(str, "window.setrect width:%d height:%d coord:%d %d\n", w, h, x, y); 148 appendFormat_String(str, "window.setrect width:%d height:%d coord:%d %d\n", w, h, x, y);
154 appendFormat_String(str, "sidebar.width arg:%d\n", width_SidebarWidget(sidebar)); 149 appendFormat_String(str, "sidebar.width arg:%d\n", width_SidebarWidget(sidebar));
150 /* On macOS, maximization should be applied at creation time or the window will take
151 a moment to animate to its maximized size. */
152#if !defined (iPlatformApple)
153 if (isMaximized) {
154 appendFormat_String(str, "~window.maximize\n");
155 }
156#endif
155 } 157 }
156 if (isVisible_Widget(sidebar)) { 158 if (isVisible_Widget(sidebar)) {
157 appendCStr_String(str, "sidebar.toggle\n"); 159 appendCStr_String(str, "sidebar.toggle\n");
@@ -800,6 +802,10 @@ iBool handleCommand_App(const char *cmd) {
800 d->prefs.retainWindowSize = arg_Command(cmd); 802 d->prefs.retainWindowSize = arg_Command(cmd);
801 return iTrue; 803 return iTrue;
802 } 804 }
805 else if (equal_Command(cmd, "window.maximize")) {
806 SDL_MaximizeWindow(d->window->win);
807 return iTrue;
808 }
803 else if (equal_Command(cmd, "zoom.set")) { 809 else if (equal_Command(cmd, "zoom.set")) {
804 setFreezeDraw_Window(get_Window(), iTrue); /* no intermediate draws before docs updated */ 810 setFreezeDraw_Window(get_Window(), iTrue); /* no intermediate draws before docs updated */
805 d->prefs.zoomPercent = arg_Command(cmd); 811 d->prefs.zoomPercent = arg_Command(cmd);
diff --git a/src/ui/window.c b/src/ui/window.c
index a7ec37dd..19432691 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);
@@ -596,6 +597,15 @@ SDL_Renderer *renderer_Window(const iWindow *d) {
596 return d->render; 597 return d->render;
597} 598}
598 599
600static iBool isMaximized_Window_(const iWindow *d) {
601#if !defined (iPlatformApple)
602 return (SDL_GetWindowFlags(d->win) & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED)) != 0;
603#else
604 iUnused(d);
605 return iFalse; /* There is fullscreen mode but that is not handled at the moment. */
606#endif
607}
608
599static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { 609static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) {
600 switch (ev->event) { 610 switch (ev->event) {
601#if defined (LAGRANGE_ENABLE_WINDOWPOS_FIX) 611#if defined (LAGRANGE_ENABLE_WINDOWPOS_FIX)
@@ -608,11 +618,22 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) {
608 } 618 }
609 return iFalse; 619 return iFalse;
610#endif 620#endif
611 case SDL_WINDOWEVENT_MOVED: 621 case SDL_WINDOWEVENT_MOVED: {
612 /* No need to do anything. */ 622 if (!isMaximized_Window_(d)) {
623 d->lastRect.pos = init_I2(ev->data1, ev->data2);
624 iInt2 border = zero_I2();
625#if !defined (iPlatformApple)
626 SDL_GetWindowBordersSize(d->win, &border.y, &border.x, NULL, NULL);
627#endif
628 d->lastRect.pos = max_I2(zero_I2(), sub_I2(d->lastRect.pos, border));
629 }
613 return iTrue; 630 return iTrue;
631 }
614 case SDL_WINDOWEVENT_RESIZED: 632 case SDL_WINDOWEVENT_RESIZED:
615 case SDL_WINDOWEVENT_SIZE_CHANGED: 633 case SDL_WINDOWEVENT_SIZE_CHANGED:
634 if (!isMaximized_Window_(d)) {
635 d->lastRect.size = init_I2(ev->data1, ev->data2);
636 }
616 updateRootSize_Window_(d); 637 updateRootSize_Window_(d);
617 return iTrue; 638 return iTrue;
618 case SDL_WINDOWEVENT_LEAVE: 639 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)
35struct Impl_Window { 35struct 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;