diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-18 13:37:23 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-18 13:37:23 +0200 |
commit | 480fe2f859b191584113de6e483121d3893eaf3e (patch) | |
tree | 84c74f42b348ec8c6d6a81d7cca57e3c939cb6c8 | |
parent | fa174461abdc5c33de16428109c7d46b4f150093 (diff) |
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.
-rw-r--r-- | src/app.c | 21 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 10 | ||||
-rw-r--r-- | src/ui/scrollwidget.c | 2 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 5 |
4 files changed, 30 insertions, 8 deletions
@@ -125,6 +125,7 @@ struct Impl_App { | |||
125 | iTime lastDropTime; /* for detecting drops of multiple items */ | 125 | iTime lastDropTime; /* for detecting drops of multiple items */ |
126 | int autoReloadTimer; | 126 | int autoReloadTimer; |
127 | iPeriodic periodic; | 127 | iPeriodic periodic; |
128 | int warmupFrames; /* forced refresh just after resuming from background */ | ||
128 | /* Preferences: */ | 129 | /* Preferences: */ |
129 | iBool commandEcho; /* --echo */ | 130 | iBool commandEcho; /* --echo */ |
130 | iBool forceSoftwareRender; /* --sw */ | 131 | iBool forceSoftwareRender; /* --sw */ |
@@ -587,6 +588,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
587 | const iBool isFirstRun = | 588 | const iBool isFirstRun = |
588 | !fileExistsCStr_FileInfo(cleanedPath_CStr(concatPath_CStr(dataDir_App_(), "prefs.cfg"))); | 589 | !fileExistsCStr_FileInfo(cleanedPath_CStr(concatPath_CStr(dataDir_App_(), "prefs.cfg"))); |
589 | d->isFinishedLaunching = iFalse; | 590 | d->isFinishedLaunching = iFalse; |
591 | d->warmupFrames = 0; | ||
590 | d->launchCommands = new_StringList(); | 592 | d->launchCommands = new_StringList(); |
591 | iZap(d->lastDropTime); | 593 | iZap(d->lastDropTime); |
592 | init_SortedArray(&d->tickers, sizeof(iTicker), cmp_Ticker_); | 594 | init_SortedArray(&d->tickers, sizeof(iTicker), cmp_Ticker_); |
@@ -835,6 +837,9 @@ void trimCache_App(void) { | |||
835 | } | 837 | } |
836 | 838 | ||
837 | iLocalDef iBool isWaitingAllowed_App_(iApp *d) { | 839 | iLocalDef iBool isWaitingAllowed_App_(iApp *d) { |
840 | if (d->warmupFrames > 0) { | ||
841 | return iFalse; | ||
842 | } | ||
838 | #if defined (LAGRANGE_IDLE_SLEEP) | 843 | #if defined (LAGRANGE_IDLE_SLEEP) |
839 | if (d->isIdling) { | 844 | if (d->isIdling) { |
840 | return iFalse; | 845 | return iFalse; |
@@ -874,6 +879,12 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
874 | clearCache_App_(); | 879 | clearCache_App_(); |
875 | break; | 880 | break; |
876 | case SDL_APP_DIDENTERFOREGROUND: | 881 | case SDL_APP_DIDENTERFOREGROUND: |
882 | gotEvents = iTrue; | ||
883 | d->warmupFrames = 5; | ||
884 | #if defined (LAGRANGE_IDLE_SLEEP) | ||
885 | d->isIdling = iFalse; | ||
886 | d->lastEventTime = SDL_GetTicks(); | ||
887 | #endif | ||
877 | postRefresh_App(); | 888 | postRefresh_App(); |
878 | break; | 889 | break; |
879 | case SDL_APP_WILLENTERBACKGROUND: | 890 | case SDL_APP_WILLENTERBACKGROUND: |
@@ -1039,7 +1050,7 @@ static int run_App_(iApp *d) { | |||
1039 | d->isRunning = iTrue; | 1050 | d->isRunning = iTrue; |
1040 | SDL_EventState(SDL_DROPFILE, SDL_ENABLE); /* open files via drag'n'drop */ | 1051 | SDL_EventState(SDL_DROPFILE, SDL_ENABLE); /* open files via drag'n'drop */ |
1041 | #if defined (iPlatformDesktop) | 1052 | #if defined (iPlatformDesktop) |
1042 | SDL_AddEventWatch(resizeWatcher_, d); | 1053 | SDL_AddEventWatch(resizeWatcher_, d); /* redraw window during resizing */ |
1043 | #endif | 1054 | #endif |
1044 | while (d->isRunning) { | 1055 | while (d->isRunning) { |
1045 | processEvents_App(waitForNewEvents_AppEventMode); | 1056 | processEvents_App(waitForNewEvents_AppEventMode); |
@@ -1054,11 +1065,17 @@ static int run_App_(iApp *d) { | |||
1054 | void refresh_App(void) { | 1065 | void refresh_App(void) { |
1055 | iApp *d = &app_; | 1066 | iApp *d = &app_; |
1056 | #if defined (LAGRANGE_IDLE_SLEEP) | 1067 | #if defined (LAGRANGE_IDLE_SLEEP) |
1057 | if (d->isIdling) return; | 1068 | if (d->warmupFrames == 0 && d->isIdling) { |
1069 | return; | ||
1070 | } | ||
1058 | #endif | 1071 | #endif |
1059 | set_Atomic(&d->pendingRefresh, iFalse); | 1072 | set_Atomic(&d->pendingRefresh, iFalse); |
1060 | destroyPending_Widget(); | 1073 | destroyPending_Widget(); |
1061 | draw_Window(d->window); | 1074 | draw_Window(d->window); |
1075 | if (d->warmupFrames > 0) { | ||
1076 | printf("warmup frame: %d\n", d->warmupFrames); | ||
1077 | d->warmupFrames--; | ||
1078 | } | ||
1062 | } | 1079 | } |
1063 | 1080 | ||
1064 | iBool isRefreshPending_App(void) { | 1081 | 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_[] = { | |||
1493 | 't', 'y', | 1493 | 't', 'y', |
1494 | }; | 1494 | }; |
1495 | 1495 | ||
1496 | static void updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumentWidget *d, | 1496 | static iBool updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocumentWidget *d, |
1497 | iBool keepCenter) { | 1497 | iBool keepCenter) { |
1498 | const int newWidth = documentWidth_DocumentWidget_(d); | ||
1499 | if (newWidth == size_GmDocument(d->doc).x) { | ||
1500 | return iFalse; /* hasn't changed */ | ||
1501 | } | ||
1498 | /* Font changes (i.e., zooming) will keep the view centered, otherwise keep the top | 1502 | /* Font changes (i.e., zooming) will keep the view centered, otherwise keep the top |
1499 | of the visible area fixed. */ | 1503 | of the visible area fixed. */ |
1500 | const iGmRun *run = keepCenter ? middleRun_DocumentWidget_(d) : d->firstVisibleRun; | 1504 | const iGmRun *run = keepCenter ? middleRun_DocumentWidget_(d) : d->firstVisibleRun; |
@@ -1505,7 +1509,7 @@ static void updateDocumentWidthRetainingScrollPosition_DocumentWidget_(iDocument | |||
1505 | /* TODO: First *fully* visible run? */ | 1509 | /* TODO: First *fully* visible run? */ |
1506 | voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds); | 1510 | voffset = visibleRange_DocumentWidget_(d).start - top_Rect(run->visBounds); |
1507 | } | 1511 | } |
1508 | setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); | 1512 | setWidth_GmDocument(d->doc, newWidth); |
1509 | documentRunsInvalidated_DocumentWidget_(d); | 1513 | documentRunsInvalidated_DocumentWidget_(d); |
1510 | if (runLoc && !keepCenter) { | 1514 | if (runLoc && !keepCenter) { |
1511 | run = findRunAtLoc_GmDocument(d->doc, runLoc); | 1515 | 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) { | |||
116 | } | 116 | } |
117 | 117 | ||
118 | static void checkVisible_ScrollWidget_(iScrollWidget *d) { | 118 | static void checkVisible_ScrollWidget_(iScrollWidget *d) { |
119 | const iBool wasHidden = isVisible_Widget(d); | 119 | const iBool wasHidden = !isVisible_Widget(d); |
120 | const iBool isHidden = d->thumbSize != 0 ? height_Rect(thumbRect_ScrollWidget_(d)) == 0 : iTrue; | 120 | const iBool isHidden = d->thumbSize != 0 ? height_Rect(thumbRect_ScrollWidget_(d)) == 0 : iTrue; |
121 | setFlags_Widget(as_Widget(d), hidden_WidgetFlag, isHidden); | 121 | setFlags_Widget(as_Widget(d), hidden_WidgetFlag, isHidden); |
122 | if (wasHidden && !isHidden) { | 122 | 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) { | |||
699 | } | 699 | } |
700 | 700 | ||
701 | void setWidth_SidebarWidget(iSidebarWidget *d, int width) { | 701 | void setWidth_SidebarWidget(iSidebarWidget *d, int width) { |
702 | const iBool isFixedWidth = deviceType_App() == phone_AppDeviceType; | ||
702 | iWidget *w = as_Widget(d); | 703 | iWidget *w = as_Widget(d); |
703 | if (deviceType_App() != phone_AppDeviceType) { /* phone doesn't allow resizing */ | 704 | if (!isFixedWidth) { |
704 | /* Even less space if the other sidebar is visible, too. */ | 705 | /* Even less space if the other sidebar is visible, too. */ |
705 | const int otherWidth = | 706 | const int otherWidth = |
706 | width_Widget(findWidget_App(d->side == left_SideBarSide ? "sidebar2" : "sidebar")); | 707 | width_Widget(findWidget_App(d->side == left_SideBarSide ? "sidebar2" : "sidebar")); |
@@ -713,7 +714,7 @@ void setWidth_SidebarWidget(iSidebarWidget *d, int width) { | |||
713 | arrange_Widget(findWidget_App("stack")); | 714 | arrange_Widget(findWidget_App("stack")); |
714 | checkModeButtonLayout_SidebarWidget_(d); | 715 | checkModeButtonLayout_SidebarWidget_(d); |
715 | updateItemHeight_SidebarWidget_(d); | 716 | updateItemHeight_SidebarWidget_(d); |
716 | if (!isRefreshPending_App()) { | 717 | if (!isFixedWidth && !isRefreshPending_App()) { |
717 | updateSize_DocumentWidget(document_App()); | 718 | updateSize_DocumentWidget(document_App()); |
718 | invalidate_ListWidget(d->list); | 719 | invalidate_ListWidget(d->list); |
719 | } | 720 | } |