diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-19 14:11:57 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-19 14:11:57 +0200 |
commit | 610bd7f31399a292216f66832cca843fc69a10de (patch) | |
tree | a6458e91a33bdb162ba4df5c350ba8e319864c55 /src | |
parent | 7a0980fd58308f7333254a1276e6dd5072326d98 (diff) |
iOS: Further tweaks for mobile
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 86 | ||||
-rw-r--r-- | src/history.c | 12 | ||||
-rw-r--r-- | src/history.h | 1 | ||||
-rw-r--r-- | src/ui/scrollwidget.c | 2 | ||||
-rw-r--r-- | src/ui/window.c | 26 |
5 files changed, 97 insertions, 30 deletions
@@ -82,7 +82,7 @@ static const char *defaultDataDir_App_ = "~/Library/Application Support/fi.skyja | |||
82 | #endif | 82 | #endif |
83 | #if defined (iPlatformAppleMobile) | 83 | #if defined (iPlatformAppleMobile) |
84 | #define EMB_BIN "../../Resources/resources.lgr" | 84 | #define EMB_BIN "../../Resources/resources.lgr" |
85 | static const char *defaultDataDir_App_ = "~/config"; | 85 | static const char *defaultDataDir_App_ = "~/Library/Application Support"; |
86 | #endif | 86 | #endif |
87 | #if defined (iPlatformMsys) | 87 | #if defined (iPlatformMsys) |
88 | #define EMB_BIN "../resources.lgr" | 88 | #define EMB_BIN "../resources.lgr" |
@@ -397,6 +397,9 @@ static void saveState_App_(const iApp *d) { | |||
397 | serializeState_DocumentWidget(i.object, stream_File(f)); | 397 | serializeState_DocumentWidget(i.object, stream_File(f)); |
398 | } | 398 | } |
399 | } | 399 | } |
400 | else { | ||
401 | fprintf(stderr, "[App] failed to save state: %s\n", strerror(errno)); | ||
402 | } | ||
400 | iRelease(f); | 403 | iRelease(f); |
401 | } | 404 | } |
402 | 405 | ||
@@ -600,6 +603,39 @@ const iString *debugInfo_App(void) { | |||
600 | return msg; | 603 | return msg; |
601 | } | 604 | } |
602 | 605 | ||
606 | static void clearCache_App_(void) { | ||
607 | iForEach(ObjectList, i, iClob(listDocuments_App())) { | ||
608 | clearCache_History(history_DocumentWidget(i.object)); | ||
609 | } | ||
610 | } | ||
611 | |||
612 | void trimCache_App(void) { | ||
613 | iApp *d = &app_; | ||
614 | size_t cacheSize = 0; | ||
615 | const size_t limit = d->prefs.maxCacheSize * 1000000; | ||
616 | iObjectList *docs = listDocuments_App(); | ||
617 | iForEach(ObjectList, i, docs) { | ||
618 | cacheSize += cacheSize_History(history_DocumentWidget(i.object)); | ||
619 | } | ||
620 | init_ObjectListIterator(&i, docs); | ||
621 | iBool wasPruned = iFalse; | ||
622 | while (cacheSize > limit) { | ||
623 | iDocumentWidget *doc = i.object; | ||
624 | const size_t pruned = pruneLeastImportant_History(history_DocumentWidget(doc)); | ||
625 | if (pruned) { | ||
626 | cacheSize -= pruned; | ||
627 | wasPruned = iTrue; | ||
628 | } | ||
629 | next_ObjectListIterator(&i); | ||
630 | if (!i.value) { | ||
631 | if (!wasPruned) break; | ||
632 | wasPruned = iFalse; | ||
633 | init_ObjectListIterator(&i, docs); | ||
634 | } | ||
635 | } | ||
636 | iRelease(docs); | ||
637 | } | ||
638 | |||
603 | iLocalDef iBool isWaitingAllowed_App_(iApp *d) { | 639 | iLocalDef iBool isWaitingAllowed_App_(iApp *d) { |
604 | #if defined (LAGRANGE_IDLE_SLEEP) | 640 | #if defined (LAGRANGE_IDLE_SLEEP) |
605 | if (d->isIdling) { | 641 | if (d->isIdling) { |
@@ -631,6 +667,14 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
631 | processEvents_App(postedEventsOnly_AppEventMode); | 667 | processEvents_App(postedEventsOnly_AppEventMode); |
632 | } | 668 | } |
633 | goto backToMainLoop; | 669 | goto backToMainLoop; |
670 | case SDL_APP_LOWMEMORY: | ||
671 | clearCache_App_(); | ||
672 | break; | ||
673 | case SDL_APP_TERMINATING: | ||
674 | case SDL_APP_WILLENTERBACKGROUND: | ||
675 | savePrefs_App_(d); | ||
676 | saveState_App_(d); | ||
677 | break; | ||
634 | case SDL_DROPFILE: { | 678 | case SDL_DROPFILE: { |
635 | iBool wasUsed = processEvent_Window(d->window, &ev); | 679 | iBool wasUsed = processEvent_Window(d->window, &ev); |
636 | if (!wasUsed) { | 680 | if (!wasUsed) { |
@@ -963,6 +1007,7 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { | |||
963 | postCommandf_App("prefs.dialogtab arg:%u", | 1007 | postCommandf_App("prefs.dialogtab arg:%u", |
964 | tabPageIndex_Widget(tabs, currentTabPage_Widget(tabs))); | 1008 | tabPageIndex_Widget(tabs, currentTabPage_Widget(tabs))); |
965 | destroy_Widget(d); | 1009 | destroy_Widget(d); |
1010 | postCommand_App("prefs.changed"); | ||
966 | return iTrue; | 1011 | return iTrue; |
967 | } | 1012 | } |
968 | else if (equal_Command(cmd, "quoteicon.set")) { | 1013 | else if (equal_Command(cmd, "quoteicon.set")) { |
@@ -1036,33 +1081,6 @@ iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNe | |||
1036 | return doc; | 1081 | return doc; |
1037 | } | 1082 | } |
1038 | 1083 | ||
1039 | void trimCache_App(void) { | ||
1040 | iApp *d = &app_; | ||
1041 | size_t cacheSize = 0; | ||
1042 | const size_t limit = d->prefs.maxCacheSize * 1000000; | ||
1043 | iObjectList *docs = listDocuments_App(); | ||
1044 | iForEach(ObjectList, i, docs) { | ||
1045 | cacheSize += cacheSize_History(history_DocumentWidget(i.object)); | ||
1046 | } | ||
1047 | init_ObjectListIterator(&i, docs); | ||
1048 | iBool wasPruned = iFalse; | ||
1049 | while (cacheSize > limit) { | ||
1050 | iDocumentWidget *doc = i.object; | ||
1051 | const size_t pruned = pruneLeastImportant_History(history_DocumentWidget(doc)); | ||
1052 | if (pruned) { | ||
1053 | cacheSize -= pruned; | ||
1054 | wasPruned = iTrue; | ||
1055 | } | ||
1056 | next_ObjectListIterator(&i); | ||
1057 | if (!i.value) { | ||
1058 | if (!wasPruned) break; | ||
1059 | wasPruned = iFalse; | ||
1060 | init_ObjectListIterator(&i, docs); | ||
1061 | } | ||
1062 | } | ||
1063 | iRelease(docs); | ||
1064 | } | ||
1065 | |||
1066 | static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { | 1084 | static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { |
1067 | iApp *d = &app_; | 1085 | iApp *d = &app_; |
1068 | if (equal_Command(cmd, "ident.temp.changed")) { | 1086 | if (equal_Command(cmd, "ident.temp.changed")) { |
@@ -1153,6 +1171,10 @@ iBool handleCommand_App(const char *cmd) { | |||
1153 | suffixPtr_Command(cmd, "where"))); | 1171 | suffixPtr_Command(cmd, "where"))); |
1154 | return iTrue; | 1172 | return iTrue; |
1155 | } | 1173 | } |
1174 | else if (equal_Command(cmd, "prefs.changed")) { | ||
1175 | savePrefs_App_(d); | ||
1176 | return iTrue; | ||
1177 | } | ||
1156 | else if (equal_Command(cmd, "prefs.dialogtab")) { | 1178 | else if (equal_Command(cmd, "prefs.dialogtab")) { |
1157 | d->prefs.dialogTab = arg_Command(cmd); | 1179 | d->prefs.dialogTab = arg_Command(cmd); |
1158 | return iTrue; | 1180 | return iTrue; |
@@ -1410,7 +1432,13 @@ iBool handleCommand_App(const char *cmd) { | |||
1410 | return iTrue; | 1432 | return iTrue; |
1411 | } | 1433 | } |
1412 | else if (equal_Command(cmd, "tabs.close")) { | 1434 | else if (equal_Command(cmd, "tabs.close")) { |
1413 | iWidget * tabs = findWidget_App("doctabs"); | 1435 | iWidget *tabs = findWidget_App("doctabs"); |
1436 | #if defined (iPlatformAppleMobile) | ||
1437 | /* Can't close the last on mobile. */ | ||
1438 | if (tabCount_Widget(tabs) == 1) { | ||
1439 | return iTrue; | ||
1440 | } | ||
1441 | #endif | ||
1414 | const iRangecc tabId = range_Command(cmd, "id"); | 1442 | const iRangecc tabId = range_Command(cmd, "id"); |
1415 | iWidget * doc = !isEmpty_Range(&tabId) ? findWidget_App(cstr_Rangecc(tabId)) | 1443 | iWidget * doc = !isEmpty_Range(&tabId) ? findWidget_App(cstr_Rangecc(tabId)) |
1416 | : document_App(); | 1444 | : document_App(); |
diff --git a/src/history.c b/src/history.c index 59d515dc..6876d8e3 100644 --- a/src/history.c +++ b/src/history.c | |||
@@ -299,6 +299,18 @@ size_t cacheSize_History(const iHistory *d) { | |||
299 | return cached; | 299 | return cached; |
300 | } | 300 | } |
301 | 301 | ||
302 | void clearCache_History(iHistory *d) { | ||
303 | lock_Mutex(d->mtx); | ||
304 | iForEach(Array, i, &d->recent) { | ||
305 | iRecentUrl *url = i.value; | ||
306 | if (url->cachedResponse) { | ||
307 | delete_GmResponse(url->cachedResponse); | ||
308 | url->cachedResponse = NULL; | ||
309 | } | ||
310 | } | ||
311 | unlock_Mutex(d->mtx); | ||
312 | } | ||
313 | |||
302 | size_t pruneLeastImportant_History(iHistory *d) { | 314 | size_t pruneLeastImportant_History(iHistory *d) { |
303 | size_t delta = 0; | 315 | size_t delta = 0; |
304 | size_t chosen = iInvalidPos; | 316 | size_t chosen = iInvalidPos; |
diff --git a/src/history.h b/src/history.h index 7c2684f1..ce3b8e47 100644 --- a/src/history.h +++ b/src/history.h | |||
@@ -56,6 +56,7 @@ iBool goForward_History (iHistory *); | |||
56 | iRecentUrl *recentUrl_History (iHistory *, size_t pos); | 56 | iRecentUrl *recentUrl_History (iHistory *, size_t pos); |
57 | iRecentUrl *mostRecentUrl_History (iHistory *); | 57 | iRecentUrl *mostRecentUrl_History (iHistory *); |
58 | iRecentUrl *findUrl_History (iHistory *, const iString *url); | 58 | iRecentUrl *findUrl_History (iHistory *, const iString *url); |
59 | void clearCache_History (iHistory *); | ||
59 | size_t pruneLeastImportant_History (iHistory *); | 60 | size_t pruneLeastImportant_History (iHistory *); |
60 | 61 | ||
61 | const iStringArray * searchContents_History (const iHistory *, const iRegExp *pattern); /* chronologically ascending */ | 62 | const iStringArray * searchContents_History (const iHistory *, const iRegExp *pattern); /* chronologically ascending */ |
diff --git a/src/ui/scrollwidget.c b/src/ui/scrollwidget.c index 34efba67..448103b5 100644 --- a/src/ui/scrollwidget.c +++ b/src/ui/scrollwidget.c | |||
@@ -137,7 +137,7 @@ static void draw_ScrollWidget_(const iScrollWidget *d) { | |||
137 | if (bounds.size.x > 0) { | 137 | if (bounds.size.x > 0) { |
138 | iPaint p; | 138 | iPaint p; |
139 | init_Paint(&p); | 139 | init_Paint(&p); |
140 | drawVLine_Paint(&p, topLeft_Rect(bounds), height_Rect(bounds), uiSeparator_ColorId); | 140 | //drawVLine_Paint(&p, topLeft_Rect(bounds), height_Rect(bounds), uiSeparator_ColorId); |
141 | const iRect thumbRect = shrunk_Rect( | 141 | const iRect thumbRect = shrunk_Rect( |
142 | thumbRect_ScrollWidget_(d), init_I2(isPressed ? gap_UI : (gap_UI * 4 / 3), gap_UI / 2)); | 142 | thumbRect_ScrollWidget_(d), init_I2(isPressed ? gap_UI : (gap_UI * 4 / 3), gap_UI / 2)); |
143 | fillRect_Paint(&p, thumbRect, isPressed ? uiBackgroundPressed_ColorId : tmQuote_ColorId); | 143 | fillRect_Paint(&p, thumbRect, isPressed ? uiBackgroundPressed_ColorId : tmQuote_ColorId); |
diff --git a/src/ui/window.c b/src/ui/window.c index 75dffb56..38df8682 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -136,6 +136,7 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { | |||
136 | #endif | 136 | #endif |
137 | 137 | ||
138 | #if !defined (iHaveNativeMenus) | 138 | #if !defined (iHaveNativeMenus) |
139 | #if !defined (iPlatformAppleMobile) | ||
139 | /* TODO: Submenus wouldn't hurt here. */ | 140 | /* TODO: Submenus wouldn't hurt here. */ |
140 | static const iMenuItem navMenuItems_[] = { | 141 | static const iMenuItem navMenuItems_[] = { |
141 | { "New Tab", 't', KMOD_PRIMARY, "tabs.new" }, | 142 | { "New Tab", 't', KMOD_PRIMARY, "tabs.new" }, |
@@ -162,6 +163,31 @@ static const iMenuItem navMenuItems_[] = { | |||
162 | { "---", 0, 0, NULL }, | 163 | { "---", 0, 0, NULL }, |
163 | { "Quit Lagrange", 'q', KMOD_PRIMARY, "quit" } | 164 | { "Quit Lagrange", 'q', KMOD_PRIMARY, "quit" } |
164 | }; | 165 | }; |
166 | #else | ||
167 | static const iMenuItem navMenuItems_[] = { | ||
168 | { "New Tab", 't', KMOD_PRIMARY, "tabs.new" }, | ||
169 | { "Close Tab", 'w', KMOD_PRIMARY, "tabs.close" }, | ||
170 | { "---", 0, 0, NULL }, | ||
171 | { "Save to Downloads", SDLK_s, KMOD_PRIMARY, "document.save" }, | ||
172 | { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" }, | ||
173 | { "---", 0, 0, NULL }, | ||
174 | { "Toggle Left Sidebar", SDLK_l, KMOD_PRIMARY | KMOD_SHIFT, "sidebar.toggle" }, | ||
175 | { "Toggle Right Sidebar", SDLK_p, KMOD_PRIMARY | KMOD_SHIFT, "sidebar2.toggle" }, | ||
176 | { "Zoom In", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" }, | ||
177 | { "Zoom Out", SDLK_MINUS, KMOD_PRIMARY, "zoom.delta arg:-10" }, | ||
178 | { "Reset Zoom", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" }, | ||
179 | { "---", 0, 0, NULL }, | ||
180 | { "List All Bookmarks", 0, 0, "!open url:about:bookmarks" }, | ||
181 | { "List Bookmarks by Tag", 0, 0, "!open url:about:bookmarks?tags" }, | ||
182 | { "List Bookmarks by Creation Time", 0, 0, "!open url:about:bookmarks?created" }, | ||
183 | { "---", 0, 0, NULL }, | ||
184 | { "Show Feed Entries", 0, 0, "!open url:about:feeds" }, | ||
185 | { "---", 0, 0, NULL }, | ||
186 | { "Preferences...", SDLK_COMMA, KMOD_PRIMARY, "preferences" }, | ||
187 | { "Help", SDLK_F1, 0, "!open url:about:help" }, | ||
188 | { "Release Notes", 0, 0, "!open url:about:version" }, | ||
189 | }; | ||
190 | #endif /* AppleMobile */ | ||
165 | #endif | 191 | #endif |
166 | 192 | ||
167 | #if defined (iHaveNativeMenus) | 193 | #if defined (iHaveNativeMenus) |