summaryrefslogtreecommitdiff
path: root/src/ui/window.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-02-13 21:15:51 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-02-13 21:16:15 +0200
commitd2f3c851a7273f35f128d4ea58b752251c5d5001 (patch)
treee0333a1e41e5e53f6b9de0e52ec38e0d69ea8e02 /src/ui/window.c
parentb8673100bd8d02dcfc997260fd6dc297287b8c71 (diff)
Windows: Custom frame preference; further minor tweaks
Diffstat (limited to 'src/ui/window.c')
-rw-r--r--src/ui/window.c111
1 files changed, 61 insertions, 50 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index ef4a6fca..39e43340 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -91,7 +91,7 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) {
91 return iFalse; 91 return iFalse;
92 } 92 }
93 else if (equal_Command(cmd, "window.focus.gained")) { 93 else if (equal_Command(cmd, "window.focus.gained")) {
94 setTextColor_LabelWidget(findWidget_App("winbar.app"), uiTextShortcut_ColorId); 94 setTextColor_LabelWidget(findWidget_App("winbar.app"), uiTextAppTitle_ColorId);
95 setTextColor_LabelWidget(findWidget_App("winbar.title"), uiTextStrong_ColorId); 95 setTextColor_LabelWidget(findWidget_App("winbar.title"), uiTextStrong_ColorId);
96 return iFalse; 96 return iFalse;
97 } 97 }
@@ -557,7 +557,8 @@ static void setupUserInterface_Window(iWindow *d) {
557 addChild_Widget(d->root, iClob(div)); 557 addChild_Widget(d->root, iClob(div));
558 558
559#if defined (LAGRANGE_CUSTOM_FRAME) 559#if defined (LAGRANGE_CUSTOM_FRAME)
560 /* Window title bar. */ { 560 /* Window title bar. */
561 if (prefs_App()->customFrame) {
561 setPadding1_Widget(div, 1); 562 setPadding1_Widget(div, 1);
562 iWidget *winBar = new_Widget(); 563 iWidget *winBar = new_Widget();
563 setPadding_Widget(winBar, 0, gap_UI / 3, 0, 0); 564 setPadding_Widget(winBar, 0, gap_UI / 3, 0, 0);
@@ -573,7 +574,7 @@ static void setupUserInterface_Window(iWindow *d) {
573 addChildFlags_Widget(winBar, 574 addChildFlags_Widget(winBar,
574 iClob(new_LabelWidget("Lagrange", NULL)), 575 iClob(new_LabelWidget("Lagrange", NULL)),
575 fixedHeight_WidgetFlag | frameless_WidgetFlag); 576 fixedHeight_WidgetFlag | frameless_WidgetFlag);
576 setTextColor_LabelWidget(appButton, uiTextShortcut_ColorId); 577 setTextColor_LabelWidget(appButton, uiTextAppTitle_ColorId);
577 setId_Widget(as_Widget(appButton), "winbar.app"); 578 setId_Widget(as_Widget(appButton), "winbar.app");
578 iLabelWidget *appTitle; 579 iLabelWidget *appTitle;
579 setFont_LabelWidget(appButton, uiContentBold_FontId); 580 setFont_LabelWidget(appButton, uiContentBold_FontId);
@@ -862,17 +863,21 @@ SDL_HitTestResult hitTest_Window(const iWindow *d, iInt2 pos) {
862iBool create_Window_(iWindow *d, iRect rect, uint32_t flags) { 863iBool create_Window_(iWindow *d, iRect rect, uint32_t flags) {
863 flags |= SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN; 864 flags |= SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN;
864#if defined (LAGRANGE_CUSTOM_FRAME) 865#if defined (LAGRANGE_CUSTOM_FRAME)
865 /* We are drawing a custom frame so hide the default one. */ 866 if (prefs_App()->customFrame) {
866 flags |= SDL_WINDOW_BORDERLESS; 867 /* We are drawing a custom frame so hide the default one. */
868 flags |= SDL_WINDOW_BORDERLESS;
869 }
867#endif 870#endif
868 if (SDL_CreateWindowAndRenderer( 871 if (SDL_CreateWindowAndRenderer(
869 width_Rect(rect), height_Rect(rect), flags, &d->win, &d->render)) { 872 width_Rect(rect), height_Rect(rect), flags, &d->win, &d->render)) {
870 return iFalse; 873 return iFalse;
871 } 874 }
872#if defined (LAGRANGE_CUSTOM_FRAME) 875#if defined (LAGRANGE_CUSTOM_FRAME)
873 /* Register a handler for window hit testing (drag, resize). */ 876 if (prefs_App()->customFrame) {
874 SDL_SetWindowHitTest(d->win, hitTest_Window_, d); 877 /* Register a handler for window hit testing (drag, resize). */
875 SDL_SetWindowResizable(d->win, SDL_TRUE); 878 SDL_SetWindowHitTest(d->win, hitTest_Window_, d);
879 SDL_SetWindowResizable(d->win, SDL_TRUE);
880 }
876#endif 881#endif
877 return iTrue; 882 return iTrue;
878} 883}
@@ -979,15 +984,16 @@ void init_Window(iWindow *d, iRect rect) {
979 updateRootSize_Window_(d, iFalse); 984 updateRootSize_Window_(d, iFalse);
980 d->appIcon = NULL; 985 d->appIcon = NULL;
981#if defined (LAGRANGE_CUSTOM_FRAME) 986#if defined (LAGRANGE_CUSTOM_FRAME)
982 /* Load the app icon for drawing in the title bar. */ { 987 /* Load the app icon for drawing in the title bar. */
988 if (prefs_App()->customFrame) {
983 SDL_Surface *surf = loadAppIconSurface_(appIconSize_()); 989 SDL_Surface *surf = loadAppIconSurface_(appIconSize_());
984 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); 990 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
985 d->appIcon = SDL_CreateTextureFromSurface(d->render, surf); 991 d->appIcon = SDL_CreateTextureFromSurface(d->render, surf);
986 free(surf->pixels); 992 free(surf->pixels);
987 SDL_FreeSurface(surf); 993 SDL_FreeSurface(surf);
994 /* We need to observe non-client-area events. */
995 SDL_EventState(SDL_SYSWMEVENT, SDL_TRUE);
988 } 996 }
989 /* We need to observe non-client-area events. */
990 SDL_EventState(SDL_SYSWMEVENT, SDL_TRUE);
991#endif 997#endif
992} 998}
993 999
@@ -1027,6 +1033,9 @@ static iBool isNormalPlacement_Window_(const iWindow *d) {
1027 1033
1028static iBool unsnap_Window_(iWindow *d, const iInt2 *newPos) { 1034static iBool unsnap_Window_(iWindow *d, const iInt2 *newPos) {
1029#if defined (LAGRANGE_CUSTOM_FRAME) 1035#if defined (LAGRANGE_CUSTOM_FRAME)
1036 if (!prefs_App()->customFrame) {
1037 return iFalse;
1038 }
1030 const int snap = snap_Window(d); 1039 const int snap = snap_Window(d);
1031 if (snap == yMaximized_WindowSnap || snap == left_WindowSnap || snap == right_WindowSnap) { 1040 if (snap == yMaximized_WindowSnap || snap == left_WindowSnap || snap == right_WindowSnap) {
1032 if (!newPos || (d->place.lastHit == SDL_HITTEST_RESIZE_LEFT || 1041 if (!newPos || (d->place.lastHit == SDL_HITTEST_RESIZE_LEFT ||
@@ -1088,7 +1097,8 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) {
1088 return iFalse; 1097 return iFalse;
1089 } 1098 }
1090#if defined (LAGRANGE_CUSTOM_FRAME) 1099#if defined (LAGRANGE_CUSTOM_FRAME)
1091 /* Set the snap position depending on where the mouse cursor is. */ { 1100 /* Set the snap position depending on where the mouse cursor is. */
1101 if (prefs_App()->customFrame) {
1092 SDL_Rect usable; 1102 SDL_Rect usable;
1093 iInt2 mouse = cursor_Win32(); /* SDL is unaware of the current cursor pos */ 1103 iInt2 mouse = cursor_Win32(); /* SDL is unaware of the current cursor pos */
1094 SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(d->win), &usable); 1104 SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(d->win), &usable);
@@ -1281,17 +1291,17 @@ void draw_Window(iWindow *d) {
1281 if (d->isDrawFrozen) { 1291 if (d->isDrawFrozen) {
1282 return; 1292 return;
1283 } 1293 }
1284//#if !defined (NDEBUG) 1294 const int winFlags = SDL_GetWindowFlags(d->win);
1285// printf("draw %d\n", d->frameTime); fflush(stdout); 1295 const iBool gotFocus = (winFlags & SDL_WINDOW_INPUT_FOCUS) != 0;
1286//#endif 1296 /* Clear the window. The clear color is visible as a border around the window
1287 /* Clear the window. */ 1297 when the custom frame is being used. */ {
1288 const int winFlags = SDL_GetWindowFlags(d->win); 1298 const iColor back = get_Color(gotFocus && d->place.snap != maximized_WindowSnap &&
1289 const iColor back = 1299 ~winFlags & SDL_WINDOW_FULLSCREEN_DESKTOP
1290 get_Color(winFlags & SDL_WINDOW_INPUT_FOCUS && d->place.snap != maximized_WindowSnap 1300 ? uiAnnotation_ColorId
1291 ? uiAnnotation_ColorId 1301 : uiSeparator_ColorId);
1292 : uiSeparator_ColorId); 1302 SDL_SetRenderDrawColor(d->render, back.r, back.g, back.b, 255);
1293 SDL_SetRenderDrawColor(d->render, back.r, back.g, back.b, 255); 1303 SDL_RenderClear(d->render);
1294 SDL_RenderClear(d->render); 1304 }
1295 /* Draw widgets. */ 1305 /* Draw widgets. */
1296 d->frameTime = SDL_GetTicks(); 1306 d->frameTime = SDL_GetTicks();
1297 draw_Widget(d->root); 1307 draw_Widget(d->root);
@@ -1302,6 +1312,10 @@ void draw_Window(iWindow *d) {
1302 const int size = appIconSize_(); 1312 const int size = appIconSize_();
1303 const iRect rect = bounds_Widget(appIcon); 1313 const iRect rect = bounds_Widget(appIcon);
1304 const iInt2 mid = mid_Rect(rect); 1314 const iInt2 mid = mid_Rect(rect);
1315 const iBool isLight = isLight_ColorTheme(colorTheme_App());
1316 iColor iconColor = get_Color(gotFocus || isLight ? white_ColorId : cyan_ColorId);
1317 SDL_SetTextureColorMod(d->appIcon, iconColor.r, iconColor.g, iconColor.b);
1318 SDL_SetTextureAlphaMod(d->appIcon, gotFocus || !isLight ? 255 : 92);
1305 SDL_RenderCopy( 1319 SDL_RenderCopy(
1306 d->render, 1320 d->render,
1307 d->appIcon, 1321 d->appIcon,
@@ -1401,38 +1415,25 @@ iWindow *get_Window(void) {
1401 return theWindow_; 1415 return theWindow_;
1402} 1416}
1403 1417
1404#if !defined (LAGRANGE_CUSTOM_FRAME)
1405void setSnap_Window(iWindow *d, int snapMode) { 1418void setSnap_Window(iWindow *d, int snapMode) {
1406 if (snapMode == maximized_WindowSnap) { 1419 if (!prefs_App()->customFrame) {
1407 SDL_MaximizeWindow(d->win); 1420 if (snapMode == maximized_WindowSnap) {
1408 } 1421 SDL_MaximizeWindow(d->win);
1409 else if (snapMode == fullscreen_WindowSnap) { 1422 }
1410 SDL_SetWindowFullscreen(d->win, SDL_WINDOW_FULLSCREEN_DESKTOP); 1423 else if (snapMode == fullscreen_WindowSnap) {
1411 } 1424 SDL_SetWindowFullscreen(d->win, SDL_WINDOW_FULLSCREEN_DESKTOP);
1412 else {
1413 if (snap_Window(d) == fullscreen_WindowSnap) {
1414 SDL_SetWindowFullscreen(d->win, 0);
1415 } 1425 }
1416 else { 1426 else {
1417 SDL_RestoreWindow(d->win); 1427 if (snap_Window(d) == fullscreen_WindowSnap) {
1428 SDL_SetWindowFullscreen(d->win, 0);
1429 }
1430 else {
1431 SDL_RestoreWindow(d->win);
1432 }
1418 } 1433 }
1434 return;
1419 } 1435 }
1420}
1421
1422int snap_Window(const iWindow *d) {
1423 const int flags = SDL_GetWindowFlags(d->win);
1424 if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) {
1425 return fullscreen_WindowSnap;
1426 }
1427 else if (flags & SDL_WINDOW_MAXIMIZED) {
1428 return maximized_WindowSnap;
1429 }
1430 return none_WindowSnap;
1431}
1432#endif
1433
1434#if defined (LAGRANGE_CUSTOM_FRAME) 1436#if defined (LAGRANGE_CUSTOM_FRAME)
1435void setSnap_Window(iWindow *d, int snapMode) {
1436 if (d->place.snap == snapMode) { 1437 if (d->place.snap == snapMode) {
1437 return; 1438 return;
1438 } 1439 }
@@ -1497,9 +1498,19 @@ void setSnap_Window(iWindow *d, int snapMode) {
1497 arrange_Widget(d->root); 1498 arrange_Widget(d->root);
1498 postRefresh_App(); 1499 postRefresh_App();
1499 } 1500 }
1501#endif /* defined (LAGRANGE_CUSTOM_FRAME) */
1500} 1502}
1501 1503
1502int snap_Window(const iWindow *d) { 1504int snap_Window(const iWindow *d) {
1505 if (!prefs_App()->customFrame) {
1506 const int flags = SDL_GetWindowFlags(d->win);
1507 if (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) {
1508 return fullscreen_WindowSnap;
1509 }
1510 else if (flags & SDL_WINDOW_MAXIMIZED) {
1511 return maximized_WindowSnap;
1512 }
1513 return none_WindowSnap;
1514 }
1503 return d->place.snap; 1515 return d->place.snap;
1504} 1516}
1505#endif