diff options
Diffstat (limited to 'src/ui/window.c')
-rw-r--r-- | src/ui/window.c | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index bd1254d7..85666233 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -378,7 +378,7 @@ void create_Window_(iWindow *d, iRect rect, uint32_t flags) { | |||
378 | /* We are drawing a custom frame so hide the default one. */ | 378 | /* We are drawing a custom frame so hide the default one. */ |
379 | flags |= SDL_WINDOW_BORDERLESS; | 379 | flags |= SDL_WINDOW_BORDERLESS; |
380 | } | 380 | } |
381 | #endif | 381 | #endif |
382 | } | 382 | } |
383 | #if 0 | 383 | #if 0 |
384 | if (SDL_CreateWindowAndRenderer( | 384 | if (SDL_CreateWindowAndRenderer( |
@@ -398,7 +398,7 @@ void create_Window_(iWindow *d, iRect rect, uint32_t flags) { | |||
398 | exit(-3); | 398 | exit(-3); |
399 | } | 399 | } |
400 | if (forceSoftwareRender_App()) { | 400 | if (forceSoftwareRender_App()) { |
401 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); | 401 | SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); |
402 | } | 402 | } |
403 | d->render = SDL_CreateRenderer( | 403 | d->render = SDL_CreateRenderer( |
404 | d->win, | 404 | d->win, |
@@ -481,7 +481,7 @@ void init_Window(iWindow *d, enum iWindowType type, iRect rect, uint32_t flags) | |||
481 | SDL_GetRendererInfo(d->render, &info); | 481 | SDL_GetRendererInfo(d->render, &info); |
482 | printf("[window] renderer: %s%s\n", | 482 | printf("[window] renderer: %s%s\n", |
483 | info.name, | 483 | info.name, |
484 | info.flags & SDL_RENDERER_ACCELERATED ? " (accelerated)" : ""); | 484 | info.flags & SDL_RENDERER_ACCELERATED ? " (accelerated)" : ""); |
485 | } | 485 | } |
486 | drawBlank_Window_(d); | 486 | drawBlank_Window_(d); |
487 | d->pixelRatio = pixelRatio_Window_(d); /* point/pixel conversion */ | 487 | d->pixelRatio = pixelRatio_Window_(d); /* point/pixel conversion */ |
@@ -770,6 +770,23 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
770 | return iFalse; | 770 | return iFalse; |
771 | } | 771 | } |
772 | 772 | ||
773 | static void savePlace_MainWindow_(iAny *mainWindow) { | ||
774 | iMainWindow *d = mainWindow; | ||
775 | if (isNormalPlacement_MainWindow_(d)) { | ||
776 | iInt2 newPos; | ||
777 | SDL_GetWindowPosition(d->base.win, &newPos.x, &newPos.y); | ||
778 | // printf("savePlace_MainWindow_ sets normalRect %d,%d\n", newPos.x, newPos.y); | ||
779 | d->place.normalRect.pos = newPos; | ||
780 | iInt2 border = zero_I2(); | ||
781 | #if !defined(iPlatformApple) | ||
782 | SDL_GetWindowBordersSize(d->base.win, &border.y, &border.x, NULL, NULL); | ||
783 | #endif | ||
784 | iAssert(~SDL_GetWindowFlags(d->base.win) & SDL_WINDOW_MAXIMIZED); | ||
785 | d->place.normalRect.pos = | ||
786 | max_I2(zero_I2(), sub_I2(d->place.normalRect.pos, border)); | ||
787 | } | ||
788 | } | ||
789 | |||
773 | static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent *ev) { | 790 | static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent *ev) { |
774 | switch (ev->event) { | 791 | switch (ev->event) { |
775 | #if defined(iPlatformDesktop) | 792 | #if defined(iPlatformDesktop) |
@@ -782,10 +799,14 @@ static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent | |||
782 | postRefresh_App(); | 799 | postRefresh_App(); |
783 | #if defined(LAGRANGE_ENABLE_WINDOWPOS_FIX) | 800 | #if defined(LAGRANGE_ENABLE_WINDOWPOS_FIX) |
784 | if (d->place.initialPos.x >= 0) { | 801 | if (d->place.initialPos.x >= 0) { |
785 | int bx, by; | 802 | /* Must not move a maximized window. */ |
786 | SDL_GetWindowBordersSize(d->base.win, &by, &bx, NULL, NULL); | 803 | if (snap_MainWindow(d) == 0) { |
787 | SDL_SetWindowPosition( | 804 | int bx, by; |
788 | d->base.win, d->place.initialPos.x + bx, d->place.initialPos.y + by); | 805 | SDL_GetWindowBordersSize(d->base.win, &by, &bx, NULL, NULL); |
806 | // printf("EXPOSED sets position %d %d\n", d->place.initialPos.x, d->place.initialPos.y); | ||
807 | SDL_SetWindowPosition( | ||
808 | d->base.win, d->place.initialPos.x + bx, d->place.initialPos.y + by); | ||
809 | } | ||
789 | d->place.initialPos = init1_I2(-1); | 810 | d->place.initialPos = init1_I2(-1); |
790 | } | 811 | } |
791 | #endif | 812 | #endif |
@@ -836,16 +857,7 @@ static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent | |||
836 | if (unsnap_MainWindow_(d, &newPos)) { | 857 | if (unsnap_MainWindow_(d, &newPos)) { |
837 | return iTrue; | 858 | return iTrue; |
838 | } | 859 | } |
839 | if (isNormalPlacement_MainWindow_(d)) { | 860 | addTicker_App(savePlace_MainWindow_, d); |
840 | d->place.normalRect.pos = newPos; | ||
841 | // printf("normal rect set (move)\n"); fflush(stdout); | ||
842 | iInt2 border = zero_I2(); | ||
843 | #if !defined(iPlatformApple) | ||
844 | SDL_GetWindowBordersSize(d->base.win, &border.y, &border.x, NULL, NULL); | ||
845 | #endif | ||
846 | d->place.normalRect.pos = | ||
847 | max_I2(zero_I2(), sub_I2(d->place.normalRect.pos, border)); | ||
848 | } | ||
849 | return iTrue; | 861 | return iTrue; |
850 | } | 862 | } |
851 | case SDL_WINDOWEVENT_RESIZED: | 863 | case SDL_WINDOWEVENT_RESIZED: |
@@ -858,8 +870,8 @@ static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent | |||
858 | return iTrue; | 870 | return iTrue; |
859 | } | 871 | } |
860 | if (isNormalPlacement_MainWindow_(d)) { | 872 | if (isNormalPlacement_MainWindow_(d)) { |
873 | // printf("RESIZED sets normalRect\n"); | ||
861 | d->place.normalRect.size = init_I2(ev->data1, ev->data2); | 874 | d->place.normalRect.size = init_I2(ev->data1, ev->data2); |
862 | // printf("normal rect set (resize)\n"); fflush(stdout); | ||
863 | } | 875 | } |
864 | checkPixelRatioChange_Window_(as_Window(d)); | 876 | checkPixelRatioChange_Window_(as_Window(d)); |
865 | postRefresh_App(); | 877 | postRefresh_App(); |
@@ -871,6 +883,8 @@ static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent | |||
871 | d->base.isMinimized = iFalse; | 883 | d->base.isMinimized = iFalse; |
872 | postRefresh_App(); | 884 | postRefresh_App(); |
873 | return iTrue; | 885 | return iTrue; |
886 | case SDL_WINDOWEVENT_MAXIMIZED: | ||
887 | return iTrue; | ||
874 | case SDL_WINDOWEVENT_MINIMIZED: | 888 | case SDL_WINDOWEVENT_MINIMIZED: |
875 | d->base.isMinimized = iTrue; | 889 | d->base.isMinimized = iTrue; |
876 | closePopups_App(); | 890 | closePopups_App(); |
@@ -1596,6 +1610,12 @@ void setSnap_MainWindow(iMainWindow *d, int snapMode) { | |||
1596 | if (snapMode & bottomBit_WindowSnap) { | 1610 | if (snapMode & bottomBit_WindowSnap) { |
1597 | newRect.pos.y += newRect.size.y; | 1611 | newRect.pos.y += newRect.size.y; |
1598 | } | 1612 | } |
1613 | if (newRect.size.x) { | ||
1614 | // printf("snap:%d newrect:%d,%d %dx%d\n", snapMode, newRect.pos.x, newRect.pos.y, newRect.size.x, newRect.size.y); | ||
1615 | SDL_SetWindowPosition(d->base.win, newRect.pos.x, newRect.pos.y); | ||
1616 | SDL_SetWindowSize(d->base.win, newRect.size.x, newRect.size.y); | ||
1617 | postCommand_App("window.resized"); | ||
1618 | } | ||
1599 | /* Update window controls. */ | 1619 | /* Update window controls. */ |
1600 | iForIndices(rootIndex, d->base.roots) { | 1620 | iForIndices(rootIndex, d->base.roots) { |
1601 | iRoot *root = d->base.roots[rootIndex]; | 1621 | iRoot *root = d->base.roots[rootIndex]; |
@@ -1606,11 +1626,6 @@ void setSnap_MainWindow(iMainWindow *d, int snapMode) { | |||
1606 | /* Show and hide the title bar. */ | 1626 | /* Show and hide the title bar. */ |
1607 | const iBool wasVisible = isVisible_Widget(winBar); | 1627 | const iBool wasVisible = isVisible_Widget(winBar); |
1608 | setFlags_Widget(winBar, hidden_WidgetFlag, d->place.snap == fullscreen_WindowSnap); | 1628 | setFlags_Widget(winBar, hidden_WidgetFlag, d->place.snap == fullscreen_WindowSnap); |
1609 | if (newRect.size.x) { | ||
1610 | SDL_SetWindowPosition(d->base.win, newRect.pos.x, newRect.pos.y); | ||
1611 | SDL_SetWindowSize(d->base.win, newRect.size.x, newRect.size.y); | ||
1612 | postCommand_App("window.resized"); | ||
1613 | } | ||
1614 | if (wasVisible != isVisible_Widget(winBar)) { | 1629 | if (wasVisible != isVisible_Widget(winBar)) { |
1615 | arrange_Widget(root->widget); | 1630 | arrange_Widget(root->widget); |
1616 | postRefresh_App(); | 1631 | postRefresh_App(); |