From e83ff095348ed3bb6173c38a8e7bff8b1aaf324c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= jaakko.keranen@iki.fi
Date: Mon, 21 Sep 2020 12:40:46 +0300
Subject: [PATCH 1/1] Restoring maximized windows
Window position and size are stored when move/resize events are received, not only when the window is closed.
res/about/version.gmi | 1 +
src/app.c | 32 ++++++++++++++++++++++++--------
src/ui/window.c | 18 +++++++++++++++---
src/ui/window.h | 1 +
4 files changed, 41 insertions(+), 11 deletions(-)
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 @@
+* Windows: Fixed window size/state restoration issues when launching.
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;
}
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->pendingCursor = NULL;
d->isDrawFrozen = iTrue;
uint32_t flags = 0;
@@ -525,7 +526,7 @@ void init_Window(iWindow *d, iRect rect) {
exit(-2);
}
}
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;
iBool isDrawFrozen; /* avoids premature draws while restoring window state */
SDL_Renderer *render;
iWidget * root;
--
2.25.1
text/plain
This content has been proxied by September (ba2dc).