From 480fe2f859b191584113de6e483121d3893eaf3e Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 18 Mar 2021 13:37:23 +0200 Subject: Mobile improvements Seeing if a few forced redraws will take care of the squished view issue. On the phone, showing and hiding the sidebar is not supposed to resize any documents. --- src/app.c | 21 +++++++++++++++++++-- src/ui/documentwidget.c | 10 +++++++--- src/ui/scrollwidget.c | 2 +- src/ui/sidebarwidget.c | 5 +++-- 4 files changed, 30 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index c5ddc454..d5ec7091 100644 --- a/src/app.c +++ b/src/app.c @@ -125,6 +125,7 @@ struct Impl_App { iTime lastDropTime; /* for detecting drops of multiple items */ int autoReloadTimer; iPeriodic periodic; + int warmupFrames; /* forced refresh just after resuming from background */ /* Preferences: */ iBool commandEcho; /* --echo */ iBool forceSoftwareRender; /* --sw */ @@ -587,6 +588,7 @@ static void init_App_(iApp *d, int argc, char **argv) { const iBool isFirstRun = !fileExistsCStr_FileInfo(cleanedPath_CStr(concatPath_CStr(dataDir_App_(), "prefs.cfg"))); d->isFinishedLaunching = iFalse; + d->warmupFrames = 0; d->launchCommands = new_StringList(); iZap(d->lastDropTime); init_SortedArray(&d->tickers, sizeof(iTicker), cmp_Ticker_); @@ -835,6 +837,9 @@ void trimCache_App(void) { } iLocalDef iBool isWaitingAllowed_App_(iApp *d) { + if (d->warmupFrames > 0) { + return iFalse; + } #if defined (LAGRANGE_IDLE_SLEEP) if (d->isIdling) { return iFalse; @@ -874,6 +879,12 @@ void processEvents_App(enum iAppEventMode eventMode) { clearCache_App_(); break; case SDL_APP_DIDENTERFOREGROUND: + gotEvents = iTrue; + d->warmupFrames = 5; +#if defined (LAGRANGE_IDLE_SLEEP) + d->isIdling = iFalse; + d->lastEventTime = SDL_GetTicks(); +#endif postRefresh_App(); break; case SDL_APP_WILLENTERBACKGROUND: @@ -1039,7 +1050,7 @@ static int run_App_(iApp *d) { d->isRunning = iTrue; SDL_EventState(SDL_DROPFILE, SDL_ENABLE); /* open files via drag'n'drop */ #if defined (iPlatformDesktop) - SDL_AddEventWatch(resizeWatcher_, d); + SDL_AddEventWatch(resizeWatcher_, d); /* redraw window during resizing */ #endif while (d->isRunning) { processEvents_App(waitForNewEvents_AppEventMode); @@ -1054,11 +1065,17 @@ static int run_App_(iApp *d) { void refresh_App(void) { iApp *d = &app_; #if defined (LAGRANGE_IDLE_SLEEP) - if (d->isIdling) return; + if (d->warmupFrames == 0 && d->isIdling) { + return; + } #endif set_Atomic(&d->pendingRefresh, iFalse); destroyPending_Widget(); draw_Window(d->window); + if (d->warmupFrames > 0) { + printf("warmup frame: %d\n", d->warmupFrames); + d->warmupFrames--; + } } iBool isRefreshPending_App(void) { diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 72867133..341da6f8 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1493,8 +1493,12 @@ static const int homeRowKeys_[] = { 't', 'y', }; -static void updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumentWidget *d, - iBool keepCenter) { +static iBool updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumentWidget *d, + iBool keepCenter) { + const int newWidth = documentWidth_DocumentWidget_(d); + if (newWidth == size_GmDocument(d->doc).x) { + return iFalse; /* hasn't changed */ + } /* Font changes (i.e., zooming) will keep the view centered, otherwise keep the top of the visible area fixed. */ const iGmRun *run = keepCenter ? middleRun_DocumentWidget_(d) : d->firstVisibleRun; @@ -1505,7 +1509,7 @@ static void updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocument /* TODO: First *fully* visible run? */ voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds); } - setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); + setWidth_GmDocument(d->doc, newWidth); documentRunsInvalidated_DocumentWidget_(d); if (runLoc && !keepCenter) { run = findRunAtLoc_GmDocument(d->doc, runLoc); diff --git a/src/ui/scrollwidget.c b/src/ui/scrollwidget.c index a08b58d7..050681f4 100644 --- a/src/ui/scrollwidget.c +++ b/src/ui/scrollwidget.c @@ -116,7 +116,7 @@ static void unfade_ScrollWidget_(iScrollWidget *d, float opacity) { } static void checkVisible_ScrollWidget_(iScrollWidget *d) { - const iBool wasHidden = isVisible_Widget(d); + const iBool wasHidden = !isVisible_Widget(d); const iBool isHidden = d->thumbSize != 0 ? height_Rect(thumbRect_ScrollWidget_(d)) == 0 : iTrue; setFlags_Widget(as_Widget(d), hidden_WidgetFlag, isHidden); if (wasHidden && !isHidden) { diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index ac119575..8c1bb60d 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -699,8 +699,9 @@ static void checkModeButtonLayout_SidebarWidget_(iSidebarWidget *d) { } void setWidth_SidebarWidget(iSidebarWidget *d, int width) { + const iBool isFixedWidth = deviceType_App() == phone_AppDeviceType; iWidget *w = as_Widget(d); - if (deviceType_App() != phone_AppDeviceType) { /* phone doesn't allow resizing */ + if (!isFixedWidth) { /* Even less space if the other sidebar is visible, too. */ const int otherWidth = width_Widget(findWidget_App(d->side == left_SideBarSide ? "sidebar2" : "sidebar")); @@ -713,7 +714,7 @@ void setWidth_SidebarWidget(iSidebarWidget *d, int width) { arrange_Widget(findWidget_App("stack")); checkModeButtonLayout_SidebarWidget_(d); updateItemHeight_SidebarWidget_(d); - if (!isRefreshPending_App()) { + if (!isFixedWidth && !isRefreshPending_App()) { updateSize_DocumentWidget(document_App()); invalidate_ListWidget(d->list); } -- cgit v1.2.3