diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 32 | ||||
-rw-r--r-- | src/ui/window.c | 18 | ||||
-rw-r--r-- | src/ui/window.h | 1 |
3 files changed, 40 insertions, 11 deletions
@@ -136,19 +136,31 @@ static iString *serializePrefs_App_(const iApp *d) { | |||
136 | const iSidebarWidget *sidebar = findWidget_App("sidebar"); | 136 | const iSidebarWidget *sidebar = findWidget_App("sidebar"); |
137 | appendFormat_String(str, "window.retain arg:%d\n", d->retainWindowSize); | 137 | appendFormat_String(str, "window.retain arg:%d\n", d->retainWindowSize); |
138 | if (d->retainWindowSize) { | 138 | if (d->retainWindowSize) { |
139 | const iBool isMaximized = (SDL_GetWindowFlags(d->window->win) & SDL_WINDOW_MAXIMIZED) != 0; | ||
139 | int w, h, x, y; | 140 | int w, h, x, y; |
140 | SDL_GetWindowSize(d->window->win, &w, &h); | 141 | x = d->window->lastRect.pos.x; |
141 | SDL_GetWindowPosition(d->window->win, &x, &y); | 142 | y = d->window->lastRect.pos.y; |
142 | #if defined (iPlatformLinux) | 143 | w = d->window->lastRect.size.x; |
143 | /* Workaround for window position being unaffected by decorations on creation. */ { | 144 | h = d->window->lastRect.size.y; |
144 | int bl, bt; | 145 | #if 0 |
145 | SDL_GetWindowBordersSize(d->window->win, &bt, &bl, NULL, NULL); | 146 | SDL_GetWindowSize(d->window->win, &w, &h); |
146 | x -= bl; | 147 | SDL_GetWindowPosition(d->window->win, &x, &y); |
147 | y -= bt; | 148 | #i f defined (iPlatformLinux) |
149 | /* Workaround for window position being unaffected by decorations on creation. */ { | ||
150 | int bl, bt; | ||
151 | SDL_GetWindowBordersSize(d->window->win, &bt, &bl, NULL, NULL); | ||
152 | x -= bl; | ||
153 | y -= bt; | ||
154 | x = iMax(0, x); | ||
155 | y = iMax(0, y); | ||
156 | } | ||
148 | } | 157 | } |
149 | #endif | 158 | #endif |
150 | appendFormat_String(str, "window.setrect width:%d height:%d coord:%d %d\n", w, h, x, y); | 159 | appendFormat_String(str, "window.setrect width:%d height:%d coord:%d %d\n", w, h, x, y); |
151 | appendFormat_String(str, "sidebar.width arg:%d\n", width_SidebarWidget(sidebar)); | 160 | appendFormat_String(str, "sidebar.width arg:%d\n", width_SidebarWidget(sidebar)); |
161 | if (isMaximized) { | ||
162 | appendFormat_String(str, "~window.maximize\n"); | ||
163 | } | ||
152 | } | 164 | } |
153 | if (isVisible_Widget(sidebar)) { | 165 | if (isVisible_Widget(sidebar)) { |
154 | appendCStr_String(str, "sidebar.toggle\n"); | 166 | appendCStr_String(str, "sidebar.toggle\n"); |
@@ -802,6 +814,10 @@ iBool handleCommand_App(const char *cmd) { | |||
802 | d->retainWindowSize = arg_Command(cmd); | 814 | d->retainWindowSize = arg_Command(cmd); |
803 | return iTrue; | 815 | return iTrue; |
804 | } | 816 | } |
817 | else if (equal_Command(cmd, "window.maximize")) { | ||
818 | SDL_MaximizeWindow(d->window->win); | ||
819 | return iTrue; | ||
820 | } | ||
805 | else if (equal_Command(cmd, "downloads")) { | 821 | else if (equal_Command(cmd, "downloads")) { |
806 | setCStr_String(&d->downloadDir, suffixPtr_Command(cmd, "path")); | 822 | setCStr_String(&d->downloadDir, suffixPtr_Command(cmd, "path")); |
807 | return iTrue; | 823 | 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) { | |||
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; |