diff options
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 32 |
1 files changed, 25 insertions, 7 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) { |
@@ -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; |
@@ -1314,9 +1317,9 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1314 | d->isSuspended = iFalse; | 1317 | d->isSuspended = iFalse; |
1315 | break; | 1318 | break; |
1316 | case SDL_APP_DIDENTERFOREGROUND: | 1319 | case SDL_APP_DIDENTERFOREGROUND: |
1317 | gotEvents = iTrue; | ||
1318 | d->warmupFrames = 5; | 1320 | d->warmupFrames = 5; |
1319 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) | 1321 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
1322 | gotEvents = iTrue; | ||
1320 | d->isIdling = iFalse; | 1323 | d->isIdling = iFalse; |
1321 | d->lastEventTime = SDL_GetTicks(); | 1324 | d->lastEventTime = SDL_GetTicks(); |
1322 | #endif | 1325 | #endif |
@@ -1366,6 +1369,10 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1366 | iRelease(ev.user.data1); | 1369 | iRelease(ev.user.data1); |
1367 | continue; | 1370 | continue; |
1368 | } | 1371 | } |
1372 | if (ev.type == SDL_USEREVENT && ev.user.code == refresh_UserEventCode) { | ||
1373 | gotRefresh = iTrue; | ||
1374 | continue; | ||
1375 | } | ||
1369 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) | 1376 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
1370 | if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) { | 1377 | if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) { |
1371 | if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_ && | 1378 | if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_ && |
@@ -1384,8 +1391,8 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1384 | // fflush(stdout); | 1391 | // fflush(stdout); |
1385 | } | 1392 | } |
1386 | d->isIdling = iFalse; | 1393 | d->isIdling = iFalse; |
1387 | #endif | ||
1388 | gotEvents = iTrue; | 1394 | gotEvents = iTrue; |
1395 | #endif | ||
1389 | /* Keyboard modifier mapping. */ | 1396 | /* Keyboard modifier mapping. */ |
1390 | if (ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP) { | 1397 | if (ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP) { |
1391 | /* Track Caps Lock state as a modifier. */ | 1398 | /* Track Caps Lock state as a modifier. */ |
@@ -1395,6 +1402,16 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1395 | ev.key.keysym.mod = mapMods_Keys(ev.key.keysym.mod & ~KMOD_CAPS); | 1402 | ev.key.keysym.mod = mapMods_Keys(ev.key.keysym.mod & ~KMOD_CAPS); |
1396 | } | 1403 | } |
1397 | #if defined (iPlatformAndroidMobile) | 1404 | #if defined (iPlatformAndroidMobile) |
1405 | /* Use the system Back button to close panels, if they're open. */ | ||
1406 | if (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_AC_BACK) { | ||
1407 | SDL_UserEvent panelBackCmd = { .type = SDL_USEREVENT, | ||
1408 | .code = command_UserEventCode, | ||
1409 | .data1 = iDupStr("panel.close"), | ||
1410 | .data2 = d->window->base.keyRoot }; | ||
1411 | if (dispatchEvent_Window(&d->window->base, (SDL_Event *) &panelBackCmd)) { | ||
1412 | continue; /* Was handled by someone. */ | ||
1413 | } | ||
1414 | } | ||
1398 | /* Ignore all mouse events; just use touch. */ | 1415 | /* Ignore all mouse events; just use touch. */ |
1399 | if (ev.type == SDL_MOUSEBUTTONDOWN || | 1416 | if (ev.type == SDL_MOUSEBUTTONDOWN || |
1400 | ev.type == SDL_MOUSEBUTTONUP || | 1417 | ev.type == SDL_MOUSEBUTTONUP || |
@@ -2078,7 +2095,6 @@ iDocumentWidget *document_Command(const char *cmd) { | |||
2078 | } | 2095 | } |
2079 | 2096 | ||
2080 | iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNew) { | 2097 | iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNew) { |
2081 | //iApp *d = &app_; | ||
2082 | iWidget *tabs = findWidget_Root("doctabs"); | 2098 | iWidget *tabs = findWidget_Root("doctabs"); |
2083 | setFlags_Widget(tabs, hidden_WidgetFlag, iFalse); | 2099 | setFlags_Widget(tabs, hidden_WidgetFlag, iFalse); |
2084 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); | 2100 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); |
@@ -2094,6 +2110,7 @@ iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNe | |||
2094 | iRelease(doc); /* now owned by the tabs */ | 2110 | iRelease(doc); /* now owned by the tabs */ |
2095 | addTabCloseButton_Widget(tabs, as_Widget(doc), "tabs.close"); | 2111 | addTabCloseButton_Widget(tabs, as_Widget(doc), "tabs.close"); |
2096 | addChild_Widget(findChild_Widget(tabs, "tabs.buttons"), iClob(newTabButton)); | 2112 | addChild_Widget(findChild_Widget(tabs, "tabs.buttons"), iClob(newTabButton)); |
2113 | showOrHideNewTabButton_Root(tabs->root); | ||
2097 | if (switchToNew) { | 2114 | if (switchToNew) { |
2098 | postCommandf_App("tabs.switch page:%p", doc); | 2115 | postCommandf_App("tabs.switch page:%p", doc); |
2099 | } | 2116 | } |
@@ -2876,6 +2893,7 @@ iBool handleCommand_App(const char *cmd) { | |||
2876 | return iTrue; | 2893 | return iTrue; |
2877 | } | 2894 | } |
2878 | iDocumentWidget *doc = document_Command(cmd); | 2895 | iDocumentWidget *doc = document_Command(cmd); |
2896 | iAssert(doc); | ||
2879 | iDocumentWidget *origin = doc; | 2897 | iDocumentWidget *origin = doc; |
2880 | if (hasLabel_Command(cmd, "origin")) { | 2898 | if (hasLabel_Command(cmd, "origin")) { |
2881 | iDocumentWidget *cmdOrig = findWidget_App(cstr_Command(cmd, "origin")); | 2899 | iDocumentWidget *cmdOrig = findWidget_App(cstr_Command(cmd, "origin")); |