summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-26 12:55:44 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-26 12:55:44 +0300
commita5ebd2d823bc334347e26f1b2d0d1f5852bf9985 (patch)
tree18c3e7cc917ff50cd4de56583da9ddbd37f96198 /src/ui
parentfe5c4c70cc19c1636af7b00ddbcbb6ae347acdf9 (diff)
X11: Tuning popup window behavior and appearance
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/util.c16
-rw-r--r--src/ui/window.c7
2 files changed, 18 insertions, 5 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index 2a0c89dc..c2bc8f08 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1047,10 +1047,15 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) {
1047 SDL_GetWindowSize(sdlWin, &winSize.x, &winSize.y); 1047 SDL_GetWindowSize(sdlWin, &winSize.x, &winSize.y);
1048 menuPos = sub_I2(add_I2(winPos, divi_I2(winSize, 2)), divi_I2(menuSize, 2)); 1048 menuPos = sub_I2(add_I2(winPos, divi_I2(winSize, 2)), divi_I2(menuSize, 2));
1049 } 1049 }
1050 SDL_Rect displayRect; 1050 iRect displayRect = zero_Rect();
1051 SDL_GetDisplayBounds(SDL_GetWindowDisplayIndex(get_Window()->win), &displayRect); 1051 for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
1052 menuPos.x = iMin(menuPos.x, displayRect.x + displayRect.w - menuSize.x); 1052 SDL_Rect dispBounds;
1053 menuPos.y = iMin(menuPos.y, displayRect.y + displayRect.h - menuSize.y); 1053 SDL_GetDisplayBounds(i, &dispBounds);
1054 displayRect = union_Rect(
1055 displayRect, init_Rect(dispBounds.x, dispBounds.y, dispBounds.w, dispBounds.h));
1056 }
1057 menuPos.x = iMin(menuPos.x, right_Rect(displayRect) - menuSize.x);
1058 menuPos.y = iMin(menuPos.y, bottom_Rect(displayRect) - menuSize.y);
1054 } 1059 }
1055 iWindow *win = newPopup_Window(menuPos, d); /* window takes the widget */ 1060 iWindow *win = newPopup_Window(menuPos, d); /* window takes the widget */
1056 SDL_SetWindowTitle(win->win, "Menu"); 1061 SDL_SetWindowTitle(win->win, "Menu");
@@ -1080,6 +1085,9 @@ void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) {
1080 d->rect.pos = init_I2(0, rootSize.y); 1085 d->rect.pos = init_I2(0, rootSize.y);
1081 } 1086 }
1082 } 1087 }
1088 else if (menuOpenFlags & center_MenuOpenFlags) {
1089 d->rect.pos = sub_I2(divi_I2(size_Root(d->root), 2), divi_I2(d->rect.size, 2));
1090 }
1083 else { 1091 else {
1084 d->rect.pos = windowToLocal_Widget(d, windowCoord); 1092 d->rect.pos = windowToLocal_Widget(d, windowCoord);
1085 } 1093 }
diff --git a/src/ui/window.c b/src/ui/window.c
index 77e49dbb..80493845 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -750,6 +750,7 @@ static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent
750 if (d->base.isMinimized) { 750 if (d->base.isMinimized) {
751 return iFalse; 751 return iFalse;
752 } 752 }
753 closePopups_App();
753 checkPixelRatioChange_Window_(as_Window(d)); 754 checkPixelRatioChange_Window_(as_Window(d));
754 const iInt2 newPos = init_I2(ev->data1, ev->data2); 755 const iInt2 newPos = init_I2(ev->data1, ev->data2);
755 if (isEqual_I2(newPos, init1_I2(-32000))) { /* magic! */ 756 if (isEqual_I2(newPos, init1_I2(-32000))) { /* magic! */
@@ -808,6 +809,7 @@ static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent
808 // updateSize_Window_(d, iTrue); 809 // updateSize_Window_(d, iTrue);
809 return iTrue; 810 return iTrue;
810 } 811 }
812 closePopups_App();
811 if (unsnap_MainWindow_(d, NULL)) { 813 if (unsnap_MainWindow_(d, NULL)) {
812 return iTrue; 814 return iTrue;
813 } 815 }
@@ -827,6 +829,7 @@ static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent
827 return iTrue; 829 return iTrue;
828 case SDL_WINDOWEVENT_MINIMIZED: 830 case SDL_WINDOWEVENT_MINIMIZED:
829 d->base.isMinimized = iTrue; 831 d->base.isMinimized = iTrue;
832 closePopups_App();
830 return iTrue; 833 return iTrue;
831#else /* if defined (!iPlatformDesktop) */ 834#else /* if defined (!iPlatformDesktop) */
832 case SDL_WINDOWEVENT_RESIZED: 835 case SDL_WINDOWEVENT_RESIZED:
@@ -861,6 +864,7 @@ static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent
861#if !defined (iPlatformDesktop) 864#if !defined (iPlatformDesktop)
862 setFreezeDraw_MainWindow(d, iTrue); 865 setFreezeDraw_MainWindow(d, iTrue);
863#endif 866#endif
867 closePopups_App();
864 return iFalse; 868 return iFalse;
865 case SDL_WINDOWEVENT_TAKE_FOCUS: 869 case SDL_WINDOWEVENT_TAKE_FOCUS:
866 SDL_SetWindowInputFocus(d->base.win); 870 SDL_SetWindowInputFocus(d->base.win);
@@ -1124,7 +1128,8 @@ void draw_Window(iWindow *d) {
1124 drawCount_ = 0; 1128 drawCount_ = 0;
1125#endif 1129#endif
1126 } 1130 }
1127// drawRectThickness_Paint(&p, (iRect){ zero_I2(), sub_I2(d->size, one_I2()) }, gap_UI / 4, uiSeparator_ColorId); 1131 drawRectThickness_Paint(
1132 &p, (iRect){ zero_I2(), sub_I2(d->size, one_I2()) }, gap_UI / 4, uiSeparator_ColorId);
1128 setCurrent_Root(NULL); 1133 setCurrent_Root(NULL);
1129 SDL_RenderPresent(d->render); 1134 SDL_RenderPresent(d->render);
1130} 1135}