diff options
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -124,7 +124,7 @@ struct Impl_App { | |||
124 | iMimeHooks * mimehooks; | 124 | iMimeHooks * mimehooks; |
125 | iGmCerts * certs; | 125 | iGmCerts * certs; |
126 | iVisited * visited; | 126 | iVisited * visited; |
127 | iBookmarks * bookmarks; | 127 | iBookmarks * bookmarks; |
128 | iMainWindow *window; | 128 | iMainWindow *window; |
129 | iPtrArray popupWindows; | 129 | iPtrArray popupWindows; |
130 | iSortedArray tickers; /* per-frame callbacks, used for animations */ | 130 | iSortedArray tickers; /* per-frame callbacks, used for animations */ |
@@ -333,7 +333,9 @@ static const char *dataDir_App_(void) { | |||
333 | 333 | ||
334 | static const char *downloadDir_App_(void) { | 334 | static const char *downloadDir_App_(void) { |
335 | #if defined (iPlatformAndroidMobile) | 335 | #if defined (iPlatformAndroidMobile) |
336 | return concatPath_CStr(SDL_AndroidGetInternalStoragePath(), "Downloads"); | 336 | const char *dir = concatPath_CStr(SDL_AndroidGetExternalStoragePath(), "Downloads"); |
337 | makeDirs_Path(collectNewCStr_String(dir)); | ||
338 | return dir; | ||
337 | #endif | 339 | #endif |
338 | #if defined (iPlatformLinux) || defined (iPlatformOther) | 340 | #if defined (iPlatformLinux) || defined (iPlatformOther) |
339 | /* Parse user-dirs.dirs using the `xdg-user-dir` tool. */ | 341 | /* Parse user-dirs.dirs using the `xdg-user-dir` tool. */ |
@@ -759,7 +761,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
759 | d->isSuspended = iFalse; | 761 | d->isSuspended = iFalse; |
760 | d->tempFilesPendingDeletion = new_StringSet(); | 762 | d->tempFilesPendingDeletion = new_StringSet(); |
761 | init_CommandLine(&d->args, argc, argv); | 763 | init_CommandLine(&d->args, argc, argv); |
762 | /* Where was the app started from? We ask SDL first because the command line alone | 764 | /* Where was the app started from? We ask SDL first because the command line alone |
763 | cannot be relied on (behavior differs depending on OS). */ { | 765 | cannot be relied on (behavior differs depending on OS). */ { |
764 | char *exec = SDL_GetBasePath(); | 766 | char *exec = SDL_GetBasePath(); |
765 | if (exec) { | 767 | if (exec) { |
@@ -1268,7 +1270,7 @@ static iBool nextEvent_App_(iApp *d, enum iAppEventMode eventMode, SDL_Event *ev | |||
1268 | /* SDL regression circa 2.0.18? SDL_PollEvent() doesn't always return | 1270 | /* SDL regression circa 2.0.18? SDL_PollEvent() doesn't always return |
1269 | events posted immediately beforehand. Waiting with a very short timeout | 1271 | events posted immediately beforehand. Waiting with a very short timeout |
1270 | seems to work better. */ | 1272 | seems to work better. */ |
1271 | #if defined (iPlatformLinux) | 1273 | #if defined (iPlatformLinux) && SDL_VERSION_ATLEAST(2, 0, 18) |
1272 | return SDL_WaitEventTimeout(event, 1); | 1274 | return SDL_WaitEventTimeout(event, 1); |
1273 | #else | 1275 | #else |
1274 | return SDL_PollEvent(event); | 1276 | return SDL_PollEvent(event); |
@@ -1289,9 +1291,10 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1289 | iRoot *oldCurrentRoot = current_Root(); /* restored afterwards */ | 1291 | iRoot *oldCurrentRoot = current_Root(); /* restored afterwards */ |
1290 | SDL_Event ev; | 1292 | SDL_Event ev; |
1291 | iBool gotEvents = iFalse; | 1293 | iBool gotEvents = iFalse; |
1294 | iBool gotRefresh = iFalse; | ||
1292 | iPtrArray windows; | 1295 | iPtrArray windows; |
1293 | init_PtrArray(&windows); | 1296 | init_PtrArray(&windows); |
1294 | while (nextEvent_App_(d, eventMode, &ev)) { | 1297 | while (nextEvent_App_(d, gotRefresh ? postedEventsOnly_AppEventMode : eventMode, &ev)) { |
1295 | #if defined (iPlatformAppleMobile) | 1298 | #if defined (iPlatformAppleMobile) |
1296 | if (processEvent_iOS(&ev)) { | 1299 | if (processEvent_iOS(&ev)) { |
1297 | continue; | 1300 | continue; |
@@ -1362,6 +1365,10 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1362 | dispatchCommands_Periodic(&d->periodic); | 1365 | dispatchCommands_Periodic(&d->periodic); |
1363 | continue; | 1366 | continue; |
1364 | } | 1367 | } |
1368 | if (ev.type == SDL_USEREVENT && ev.user.code == refresh_UserEventCode) { | ||
1369 | gotRefresh = iTrue; | ||
1370 | continue; | ||
1371 | } | ||
1365 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) | 1372 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
1366 | if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) { | 1373 | if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) { |
1367 | if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_ && | 1374 | if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_ && |
@@ -1391,6 +1398,16 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1391 | ev.key.keysym.mod = mapMods_Keys(ev.key.keysym.mod & ~KMOD_CAPS); | 1398 | ev.key.keysym.mod = mapMods_Keys(ev.key.keysym.mod & ~KMOD_CAPS); |
1392 | } | 1399 | } |
1393 | #if defined (iPlatformAndroidMobile) | 1400 | #if defined (iPlatformAndroidMobile) |
1401 | /* Use the system Back button to close panels, if they're open. */ | ||
1402 | if (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_AC_BACK) { | ||
1403 | SDL_UserEvent panelBackCmd = { .type = SDL_USEREVENT, | ||
1404 | .code = command_UserEventCode, | ||
1405 | .data1 = iDupStr("panel.close"), | ||
1406 | .data2 = d->window->base.keyRoot }; | ||
1407 | if (dispatchEvent_Window(&d->window->base, (SDL_Event *) &panelBackCmd)) { | ||
1408 | continue; /* Was handled by someone. */ | ||
1409 | } | ||
1410 | } | ||
1394 | /* Ignore all mouse events; just use touch. */ | 1411 | /* Ignore all mouse events; just use touch. */ |
1395 | if (ev.type == SDL_MOUSEBUTTONDOWN || | 1412 | if (ev.type == SDL_MOUSEBUTTONDOWN || |
1396 | ev.type == SDL_MOUSEBUTTONUP || | 1413 | ev.type == SDL_MOUSEBUTTONUP || |
@@ -2074,7 +2091,6 @@ iDocumentWidget *document_Command(const char *cmd) { | |||
2074 | } | 2091 | } |
2075 | 2092 | ||
2076 | iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNew) { | 2093 | iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNew) { |
2077 | //iApp *d = &app_; | ||
2078 | iWidget *tabs = findWidget_Root("doctabs"); | 2094 | iWidget *tabs = findWidget_Root("doctabs"); |
2079 | setFlags_Widget(tabs, hidden_WidgetFlag, iFalse); | 2095 | setFlags_Widget(tabs, hidden_WidgetFlag, iFalse); |
2080 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); | 2096 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); |
@@ -2090,6 +2106,7 @@ iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNe | |||
2090 | iRelease(doc); /* now owned by the tabs */ | 2106 | iRelease(doc); /* now owned by the tabs */ |
2091 | addTabCloseButton_Widget(tabs, as_Widget(doc), "tabs.close"); | 2107 | addTabCloseButton_Widget(tabs, as_Widget(doc), "tabs.close"); |
2092 | addChild_Widget(findChild_Widget(tabs, "tabs.buttons"), iClob(newTabButton)); | 2108 | addChild_Widget(findChild_Widget(tabs, "tabs.buttons"), iClob(newTabButton)); |
2109 | showOrHideNewTabButton_Root(tabs->root); | ||
2093 | if (switchToNew) { | 2110 | if (switchToNew) { |
2094 | postCommandf_App("tabs.switch page:%p", doc); | 2111 | postCommandf_App("tabs.switch page:%p", doc); |
2095 | } | 2112 | } |
@@ -2840,6 +2857,7 @@ iBool handleCommand_App(const char *cmd) { | |||
2840 | return iTrue; | 2857 | return iTrue; |
2841 | } | 2858 | } |
2842 | iDocumentWidget *doc = document_Command(cmd); | 2859 | iDocumentWidget *doc = document_Command(cmd); |
2860 | iAssert(doc); | ||
2843 | iDocumentWidget *origin = doc; | 2861 | iDocumentWidget *origin = doc; |
2844 | if (hasLabel_Command(cmd, "origin")) { | 2862 | if (hasLabel_Command(cmd, "origin")) { |
2845 | iDocumentWidget *cmdOrig = findWidget_App(cstr_Command(cmd, "origin")); | 2863 | iDocumentWidget *cmdOrig = findWidget_App(cstr_Command(cmd, "origin")); |