diff --git a/res/about/version.gmi b/res/about/version.gmi

index 46e36302..5c80b5f2 100644

--- a/res/about/version.gmi

+++ b/res/about/version.gmi

@@ -8,6 +8,7 @@



0.2.1

+* Windows: Fixed window size/state restoration issues when launching.



0.2

diff --git a/src/app.c b/src/app.c

index cb72509d..ee8bccb4 100644

--- a/src/app.c

+++ b/src/app.c

@@ -136,19 +136,31 @@ static iString *serializePrefs_App_(const iApp *d) {

 const iSidebarWidget *sidebar = findWidget_App("sidebar");

 appendFormat_String(str, "window.retain arg:%d\n", d->retainWindowSize);

 if (d->retainWindowSize) {

+ const iBool isMaximized = (SDL_GetWindowFlags(d->window->win) & SDL_WINDOW_MAXIMIZED) != 0;

     int w, h, x, y;

- SDL_GetWindowSize(d->window->win, &w, &h);

- SDL_GetWindowPosition(d->window->win, &x, &y);

-#if defined (iPlatformLinux)

- /* Workaround for window position being unaffected by decorations on creation. */ {

- int bl, bt;

- SDL_GetWindowBordersSize(d->window->win, &bt, &bl, NULL, NULL);

- x -= bl;

- y -= bt;

+ x = d->window->lastRect.pos.x;

+ y = d->window->lastRect.pos.y;

+ w = d->window->lastRect.size.x;

+ h = d->window->lastRect.size.y;

+#if 0

+ SDL_GetWindowSize(d->window->win, &w, &h);

+ SDL_GetWindowPosition(d->window->win, &x, &y);

+#i f defined (iPlatformLinux)

+ /* Workaround for window position being unaffected by decorations on creation. */ {

+ int bl, bt;

+ SDL_GetWindowBordersSize(d->window->win, &bt, &bl, NULL, NULL);

+ x -= bl;

+ y -= bt;

+ x = iMax(0, x);

+ y = iMax(0, y);

+ }

     }

#endif

     appendFormat_String(str, "window.setrect width:%d height:%d coord:%d %d\n", w, h, x, y);

     appendFormat_String(str, "sidebar.width arg:%d\n", width_SidebarWidget(sidebar));

+ if (isMaximized) {

+ appendFormat_String(str, "~window.maximize\n");

+ }

 }

 if (isVisible_Widget(sidebar)) {

     appendCStr_String(str, "sidebar.toggle\n");

@@ -802,6 +814,10 @@ iBool handleCommand_App(const char *cmd) {

     d->retainWindowSize = arg_Command(cmd);

     return iTrue;

 }

+ else if (equal_Command(cmd, "window.maximize")) {

+ SDL_MaximizeWindow(d->window->win);

+ return iTrue;

+ }

 else if (equal_Command(cmd, "downloads")) {

     setCStr_String(&d->downloadDir, suffixPtr_Command(cmd, "path"));

     return iTrue;

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) {

 theWindow_ = d;

 iZap(d->cursors);

 d->initialPos = rect.pos;

+ d->lastRect = rect;

 d->pendingCursor = NULL;

 d->isDrawFrozen = iTrue;

 uint32_t flags = 0;

@@ -525,7 +526,7 @@ void init_Window(iWindow *d, iRect rect) {

         exit(-2);

     }

 }

- if (left_Rect(rect) >= 0) {

+ if (left_Rect(rect) >= 0 || top_Rect(rect) >= 0) {

     SDL_SetWindowPosition(d->win, left_Rect(rect), top_Rect(rect));

 }

 SDL_SetWindowMinimumSize(d->win, 400, 250);

@@ -608,11 +609,22 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) {

         }

         return iFalse;

#endif

- case SDL_WINDOWEVENT_MOVED:

- /* No need to do anything. */

+ case SDL_WINDOWEVENT_MOVED: {

+ if (!(SDL_GetWindowFlags(d->win) & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {

+ d->lastRect.pos = init_I2(ev->data1, ev->data2);

+ iInt2 border = zero_I2();

+#if defined (iPlatformMsys) || defined (iPlatformLinux)

+ SDL_GetWindowBordersSize(d->win, &border.y, &border.x, NULL, NULL);

+#endif

+ d->lastRect.pos = max_I2(zero_I2(), sub_I2(d->lastRect.pos, border));

+ }

         return iTrue;

+ }

     case SDL_WINDOWEVENT_RESIZED:

     case SDL_WINDOWEVENT_SIZE_CHANGED:

+ if (!(SDL_GetWindowFlags(d->win) & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {

+ d->lastRect.size = init_I2(ev->data1, ev->data2);

+ }

         updateRootSize_Window_(d);

         return iTrue;

     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)

struct Impl_Window {

 SDL_Window *  win;

 iInt2         initialPos;

+ iRect lastRect; /* updated when window is moved/resized */

 iBool         isDrawFrozen; /* avoids premature draws while restoring window state */

 SDL_Renderer *render;

 iWidget *     root;

Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/dev/pcdiff/e83ff095348ed3bb6173c38a8e7bff8b1aaf324c
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
30.515432 milliseconds
Gemini-to-HTML Time
2.419744 milliseconds

This content has been proxied by September (ba2dc).