From b2c7e9a206900af17145f3fe563a25c7a3c4a599 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 6 May 2021 12:36:30 +0300 Subject: Split view: Fixed theme and title updates Now every DocumentWidget is guaranteed a unique ID. The window title is updated when the keyroot chages. --- src/ui/documentwidget.c | 9 ++++++--- src/ui/widget.c | 6 ++++++ src/ui/widget.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/ui') diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 3175f274..5a5a4f84 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -298,10 +298,12 @@ struct Impl_DocumentWidget { iDefineObjectConstruction(DocumentWidget) +static int docEnum_ = 0; + void init_DocumentWidget(iDocumentWidget *d) { iWidget *w = as_Widget(d); init_Widget(w); - setId_Widget(w, "document000"); + setId_Widget(w, format_CStr("document%03d", ++docEnum_)); setFlags_Widget(w, hover_WidgetFlag, iTrue); init_PersistentDocumentState(&d->mod); d->flags = 0; @@ -880,7 +882,7 @@ static void updateWindowTitle_DocumentWidget_(const iDocumentWidget *d) { } /* Take away parts if it doesn't fit. */ const int avail = bounds_Widget(as_Widget(tabButton)).size.x - 3 * gap_UI; - iBool setWindow = (document_App() == d); + iBool setWindow = (document_App() == d && isUnderKeyRoot_Widget(d)); for (;;) { iString *text = collect_String(joinCStr_StringArray(title, " \u2014 ")); if (setWindow) { @@ -1953,7 +1955,8 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) } return iTrue; } - else if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed")) { + else if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "font.changed") || + equal_Command(cmd, "keyroot.changed")) { /* Alt/Option key may be involved in window size changes. */ setLinkNumberMode_DocumentWidget_(d, iFalse); d->phoneToolbar = findWidget_App("toolbar"); diff --git a/src/ui/widget.c b/src/ui/widget.c index 00fe0f5f..67ce1345 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c @@ -1346,6 +1346,12 @@ iBool isHover_Widget(const iAnyObject *d) { return get_Window()->hover == d; } +iBool isUnderKeyRoot_Widget(const iAnyObject *d) { + iAssert(isInstance_Object(d, &Class_Widget)); + const iWidget *w = d; + return w && get_Window() && w->root == get_Window()->keyRoot; +} + iBool isSelected_Widget(const iAnyObject *d) { if (d) { iAssert(isInstance_Object(d, &Class_Widget)); diff --git a/src/ui/widget.h b/src/ui/widget.h index 36797210..5b6b18e1 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -232,6 +232,7 @@ iBool isDisabled_Widget (const iAnyObject *); iBool isFocused_Widget (const iAnyObject *); iBool isHover_Widget (const iAnyObject *); iBool isSelected_Widget (const iAnyObject *); +iBool isUnderKeyRoot_Widget (const iAnyObject *); iBool isCommand_Widget (const iWidget *d, const SDL_Event *ev, const char *cmd); iBool hasParent_Widget (const iWidget *d, const iWidget *someParent); iBool isAffectedByVisualOffset_Widget -- cgit v1.2.3