From 6bd4f08ff520962d418b42116e262282ad49d537 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 30 Apr 2021 14:21:49 +0300 Subject: Windows: Fixed custom frame in split modes Hide duplicated window controls. --- src/app.c | 10 ++++---- src/ui/root.c | 41 +++++++++++++++--------------- src/ui/root.h | 5 ++-- src/ui/window.c | 79 ++++++++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 87 insertions(+), 48 deletions(-) diff --git a/src/app.c b/src/app.c index 29a97c8f..74323b7d 100644 --- a/src/app.c +++ b/src/app.c @@ -375,7 +375,7 @@ static void savePrefs_App_(const iApp *d) { static const char *magicState_App_ = "lgL1"; static const char *magicTabDocument_App_ = "tabd"; -enum iDocumentStateFlag { +enum iDocumentStateFlag { current_DocumentStateFlag = iBit(1), rootIndex1_DocumentStateFlag = iBit(2) }; @@ -1127,9 +1127,9 @@ static int resizeWatcher_(void *user, SDL_Event *event) { resetFonts_Text(); { SDL_Event u = { .type = SDL_USEREVENT }; u.user.code = command_UserEventCode; - u.user.data1 = strdup("theme.changed"); + u.user.data1 = strdup("theme.changed auto:1"); /*u.user.windowID = id_Window(d->window);*/ - dispatchEvent_Widget(d->window->root, &u); + dispatchEvent_Window(d->window, &u); } #endif drawWhileResizing_Window(d->window, winev->data1, winev->data2); @@ -1328,7 +1328,7 @@ iAny *findWidget_App(const char *id) { if (found) { return found; } - } + } } return NULL; } @@ -2364,7 +2364,7 @@ iObjectList *listDocuments_App(const iRoot *rootOrNull) { if (isInstance_Object(i.object, &Class_DocumentWidget)) { pushBack_ObjectList(docs, i.object); } - } + } } } return docs; diff --git a/src/ui/root.c b/src/ui/root.c index 548c0ca8..3661229e 100644 --- a/src/ui/root.c +++ b/src/ui/root.c @@ -237,13 +237,13 @@ static int loadAnimIndex_ = 0; static iRoot * activeRoot_ = NULL; iDefineTypeConstruction(Root) - + void init_Root(iRoot *d) { - iZap(*d); + iZap(*d); } void deinit_Root(iRoot *d) { - iReleasePtr(&d->widget); + iReleasePtr(&d->widget); } void setCurrent_Root(iRoot *root) { @@ -267,7 +267,7 @@ iAnyObject *findWidget_Root(const char *id) { } void destroyPending_Root(iRoot *d) { - setCurrent_Root(d); + setCurrent_Root(d); iForEach(PtrSet, i, d->pendingDestruction) { iWidget *widget = *i.value; if (!isFinished_Anim(&widget->visualOffset)) { @@ -852,7 +852,7 @@ static iLabelWidget *newLargeIcon_LabelWidget(const char *text, const char *cmd) return lab; } -static int appIconSize_(void) { +int appIconSize_Root(void) { return lineHeight_Text(uiContent_FontId); } @@ -872,7 +872,7 @@ void updateMetrics_Root(iRoot *d) { setFixedSize_Widget(appMin, init_I2(gap_UI * 11.5f, height_Widget(appTitle))); setFixedSize_Widget(appMax, appMin->rect.size); setFixedSize_Widget(appClose, appMin->rect.size); - setFixedSize_Widget(appIcon, init_I2(appIconSize_(), appMin->rect.size.y)); + setFixedSize_Widget(appIcon, init_I2(appIconSize_Root(), appMin->rect.size.y)); } iWidget *navBar = findChild_Widget(d->widget, "navbar"); iWidget *lock = findChild_Widget(navBar, "navbar.lock"); @@ -900,11 +900,11 @@ void createUserInterface_Root(iRoot *d) { setFlags_Widget( root, resizeChildren_WidgetFlag | fixedSize_WidgetFlag | focusRoot_WidgetFlag, iTrue); setCommandHandler_Widget(root, handleRootCommands_); - + iWidget *div = makeVDiv_Widget(); setId_Widget(div, "navdiv"); addChild_Widget(root, iClob(div)); - + #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) /* Window title bar. */ if (prefs_App()->customFrame) { @@ -912,16 +912,17 @@ void createUserInterface_Root(iRoot *d) { iWidget *winBar = new_Widget(); setId_Widget(winBar, "winbar"); setFlags_Widget(winBar, - arrangeHeight_WidgetFlag | resizeChildren_WidgetFlag | + arrangeHeight_WidgetFlag | resizeWidthOfChildren_WidgetFlag | arrangeHorizontal_WidgetFlag | collapse_WidgetFlag, iTrue); iWidget *appIcon; - setId_Widget( - addChild_Widget(winBar, iClob(appIcon = makePadding_Widget(0))), "winbar.icon"); - iLabelWidget *appButton = - addChildFlags_Widget(winBar, - iClob(new_LabelWidget("Lagrange", NULL)), - fixedHeight_WidgetFlag | frameless_WidgetFlag); + setId_Widget(addChildFlags_Widget( + winBar, iClob(appIcon = makePadding_Widget(0)), collapse_WidgetFlag), + "winbar.icon"); + iLabelWidget *appButton = addChildFlags_Widget( + winBar, + iClob(new_LabelWidget("Lagrange", NULL)), + fixedHeight_WidgetFlag | frameless_WidgetFlag | collapse_WidgetFlag); setTextColor_LabelWidget(appButton, uiTextAppTitle_ColorId); setId_Widget(as_Widget(appButton), "winbar.app"); iLabelWidget *appTitle; @@ -936,16 +937,16 @@ void createUserInterface_Root(iRoot *d) { setId_Widget(addChildFlags_Widget( winBar, iClob(appMin = newLargeIcon_LabelWidget("\u2013", "window.minimize")), - frameless_WidgetFlag), + frameless_WidgetFlag | collapse_WidgetFlag), "winbar.min"); addChildFlags_Widget( winBar, iClob(appMax = newLargeIcon_LabelWidget("\u25a1", "window.maximize toggle:1")), - frameless_WidgetFlag); + frameless_WidgetFlag | collapse_WidgetFlag); setId_Widget(as_Widget(appMax), "winbar.max"); addChildFlags_Widget(winBar, iClob(appClose = newLargeIcon_LabelWidget(close_Icon, "window.close")), - frameless_WidgetFlag); + frameless_WidgetFlag | collapse_WidgetFlag); setId_Widget(as_Widget(appClose), "winbar.close"); setFont_LabelWidget(appClose, uiContent_FontId); addChild_Widget(div, iClob(winBar)); @@ -1087,7 +1088,7 @@ void createUserInterface_Root(iRoot *d) { "navbar.home"); #if defined (iPlatformMobile) const iBool isPhone = (deviceType_App() == phone_AppDeviceType); -#endif +#endif #if !defined (iHaveNativeMenus) # if defined (iPlatformAppleMobile) iLabelWidget *navMenu = @@ -1310,7 +1311,7 @@ iRect rect_Root(const iRoot *d) { if (d && d->widget) { return d->widget->rect; } - return zero_Rect(); + return zero_Rect(); } iRect safeRect_Root(const iRoot *d) { diff --git a/src/ui/root.h b/src/ui/root.h index 039e67ad..00555224 100644 --- a/src/ui/root.h +++ b/src/ui/root.h @@ -6,7 +6,7 @@ #include iDeclareType(Root) - + struct Impl_Root { iWidget * widget; iPtrArray *onTop; /* order is important; last one is topmost */ @@ -28,7 +28,7 @@ iAnyObject *findWidget_Root (const char *id); /* under curre iPtrArray * onTop_Root (iRoot *); void destroyPending_Root (iRoot *); - + void updateMetrics_Root (iRoot *); void updatePadding_Root (iRoot *); /* TODO: is part of metrics? */ void dismissPortraitPhoneSidebars_Root (iRoot *); @@ -39,3 +39,4 @@ iRect rect_Root (const iRoot *); iRect safeRect_Root (const iRoot *); iInt2 visibleSize_Root (const iRoot *); /* may be obstructed by software keyboard */ iBool isNarrow_Root (const iRoot *); +int appIconSize_Root (void); \ No newline at end of file diff --git a/src/ui/window.c b/src/ui/window.c index 61851ca5..b3840602 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -210,7 +210,7 @@ static void windowSizeChanged_Window_(iWindow *d) { updatePadding_Root(root); arrange_Widget(root->widget); } - } + } } static void updateSize_Window_(iWindow *d, iBool notifyAlways) { @@ -297,6 +297,16 @@ static void drawBlank_Window_(iWindow *d) { SDL_RenderPresent(d->render); } +static iRoot *rootAt_Window_(const iWindow *d, iInt2 coord) { + iForIndices(i, d->roots) { + iRoot *root = d->roots[i]; + if (root && contains_Rect(rect_Root(root), coord)) { + return root; + } + } + return d->roots[0]; +} + #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) static SDL_HitTestResult hitTest_Window_(SDL_Window *win, const SDL_Point *pos, void *data) { iWindow *d = data; @@ -312,8 +322,10 @@ static SDL_HitTestResult hitTest_Window_(SDL_Window *win, const SDL_Point *pos, const iBool isRight = pos->x >= w - gap_UI; const iBool isTop = pos->y < gap_UI && snap != yMaximized_WindowSnap; const iBool isBottom = pos->y >= h - gap_UI && snap != yMaximized_WindowSnap; - const int captionHeight = lineHeight_Text(uiContent_FontId) + gap_UI * 2; - const int rightEdge = left_Rect(bounds_Widget(findChild_Widget(d->root, "winbar.min"))); + const int captionHeight = lineHeight_Text(uiContent_FontId) + gap_UI * 2; + const int rightEdge = left_Rect(bounds_Widget(findChild_Widget( + rootAt_Window_(d, init_I2(pos->x, pos->y))->widget, + "winbar.min"))); d->place.lastHit = SDL_HITTEST_NORMAL; if (snap != maximized_WindowSnap) { if (isLeft) { @@ -486,7 +498,7 @@ void init_Window(iWindow *d, iRect rect) { #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) /* Load the app icon for drawing in the title bar. */ if (prefs_App()->customFrame) { - SDL_Surface *surf = loadImage_(&imageLagrange64_Embedded, appIconSize_()); + SDL_Surface *surf = loadImage_(&imageLagrange64_Embedded, appIconSize_Root()); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); d->appIcon = SDL_CreateTextureFromSurface(d->render, surf); free(surf->pixels); @@ -508,7 +520,7 @@ void deinit_Window(iWindow *d) { deinit_Root(d->roots[i]); } } - setCurrent_Root(NULL); + setCurrent_Root(NULL); deinit_Text(); SDL_DestroyRenderer(d->render); SDL_DestroyWindow(d->win); @@ -870,7 +882,7 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { } } if (isMetricsChange_UserEvent(&event)) { - iForIndices(i, d->roots) { + iForIndices(i, d->roots) { updateMetrics_Root(d->roots[i]); } } @@ -1005,7 +1017,7 @@ void draw_Window(iWindow *d) { /* App icon. */ const iWidget *appIcon = findChild_Widget(root->widget, "winbar.icon"); if (isVisible_Widget(appIcon)) { - const int size = appIconSize_(); + const int size = appIconSize_Root(); const iRect rect = bounds_Widget(appIcon); const iInt2 mid = mid_Rect(rect); const iBool isLight = isLight_ColorTheme(colorTheme_App()); @@ -1199,6 +1211,27 @@ void setSplitMode_Window(iWindow *d, int splitMode) { setCurrent_Root(NULL); } d->splitMode = splitMode; +#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) + /* Update custom frame controls. */{ + const iBool hideCtl0 = numRoots_Window(d) != 1; + iWidget *winBar = findChild_Widget(d->roots[0]->widget, "winbar"); + if (winBar) { + setFlags_Widget( + findChild_Widget(winBar, "winbar.min"), hidden_WidgetFlag, hideCtl0); + setFlags_Widget( + findChild_Widget(winBar, "winbar.max"), hidden_WidgetFlag, hideCtl0); + setFlags_Widget( + findChild_Widget(winBar, "winbar.close"), hidden_WidgetFlag, hideCtl0); + if (d->roots[1]) { + winBar = findChild_Widget(d->roots[1]->widget, "winbar"); + setFlags_Widget( + findChild_Widget(winBar, "winbar.icon"), hidden_WidgetFlag, iTrue); + setFlags_Widget( + findChild_Widget(winBar, "winbar.app"), hidden_WidgetFlag, iTrue); + } + } + } +#endif // windowSizeChanged_Window_(d); updateSize_Window_(d, iTrue); // postCommand_App("window.resized"); @@ -1277,20 +1310,24 @@ void setSnap_Window(iWindow *d, int snapMode) { newRect.pos.y += newRect.size.y; } /* Update window controls. */ - iWidget *winBar = findWidget_App("winbar"); - updateTextCStr_LabelWidget(findChild_Widget(winBar, "winbar.max"), - d->place.snap == maximized_WindowSnap ? "\u25a2" : "\u25a1"); - /* Show and hide the title bar. */ - const iBool wasVisible = isVisible_Widget(winBar); - setFlags_Widget(winBar, hidden_WidgetFlag, d->place.snap == fullscreen_WindowSnap); - if (newRect.size.x) { - SDL_SetWindowPosition(d->win, newRect.pos.x, newRect.pos.y); - SDL_SetWindowSize(d->win, newRect.size.x, newRect.size.y); - postCommand_App("window.resized"); - } - if (wasVisible != isVisible_Widget(winBar)) { - arrange_Widget(d->root); - postRefresh_App(); + iForIndices(rootIndex, d->roots) { + iRoot *root = d->roots[rootIndex]; + if (!root) continue; + iWidget *winBar = findChild_Widget(root->widget, "winbar"); + updateTextCStr_LabelWidget(findChild_Widget(winBar, "winbar.max"), + d->place.snap == maximized_WindowSnap ? "\u25a2" : "\u25a1"); + /* Show and hide the title bar. */ + const iBool wasVisible = isVisible_Widget(winBar); + setFlags_Widget(winBar, hidden_WidgetFlag, d->place.snap == fullscreen_WindowSnap); + if (newRect.size.x) { + SDL_SetWindowPosition(d->win, newRect.pos.x, newRect.pos.y); + SDL_SetWindowSize(d->win, newRect.size.x, newRect.size.y); + postCommand_App("window.resized"); + } + if (wasVisible != isVisible_Widget(winBar)) { + arrange_Widget(root->widget); + postRefresh_App(); + } } #endif /* defined (LAGRANGE_ENABLE_CUSTOM_FRAME) */ } -- cgit v1.2.3