summaryrefslogtreecommitdiff
path: root/src/app.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.c')
-rw-r--r--src/app.c71
1 files changed, 66 insertions, 5 deletions
diff --git a/src/app.c b/src/app.c
index d47c6ef1..686d8b82 100644
--- a/src/app.c
+++ b/src/app.c
@@ -125,7 +125,8 @@ struct Impl_App {
125 iGmCerts * certs; 125 iGmCerts * certs;
126 iVisited * visited; 126 iVisited * visited;
127 iBookmarks * bookmarks; 127 iBookmarks * bookmarks;
128 iMainWindow *window; 128 iMainWindow *window; /* currently active MainWindow */
129 iPtrArray mainWindows;
129 iPtrArray popupWindows; 130 iPtrArray popupWindows;
130 iSortedArray tickers; /* per-frame callbacks, used for animations */ 131 iSortedArray tickers; /* per-frame callbacks, used for animations */
131 uint32_t lastTickerTime; 132 uint32_t lastTickerTime;
@@ -474,7 +475,7 @@ static const char *magicTabDocument_App_ = "tabd";
474static const char *magicSidebar_App_ = "side"; 475static const char *magicSidebar_App_ = "side";
475 476
476enum iDocumentStateFlag { 477enum iDocumentStateFlag {
477 current_DocumentStateFlag = iBit(1), 478 current_DocumentStateFlag = iBit(1),
478 rootIndex1_DocumentStateFlag = iBit(2) 479 rootIndex1_DocumentStateFlag = iBit(2)
479}; 480};
480 481
@@ -946,8 +947,10 @@ static void init_App_(iApp *d, int argc, char **argv) {
946 d->initialWindowRect.size.y = toInt_String(value_CommandLineArg(arg, 0)); 947 d->initialWindowRect.size.y = toInt_String(value_CommandLineArg(arg, 0));
947 } 948 }
948 } 949 }
950 init_PtrArray(&d->mainWindows);
949 init_PtrArray(&d->popupWindows); 951 init_PtrArray(&d->popupWindows);
950 d->window = new_MainWindow(d->initialWindowRect); 952 d->window = new_MainWindow(d->initialWindowRect);
953 addWindow_App(d->window);
951 load_Visited(d->visited, dataDir_App_()); 954 load_Visited(d->visited, dataDir_App_());
952 load_Bookmarks(d->bookmarks, dataDir_App_()); 955 load_Bookmarks(d->bookmarks, dataDir_App_());
953 load_MimeHooks(d->mimehooks, dataDir_App_()); 956 load_MimeHooks(d->mimehooks, dataDir_App_());
@@ -1012,7 +1015,11 @@ static void deinit_App(iApp *d) {
1012 SDL_RemoveTimer(d->autoReloadTimer); 1015 SDL_RemoveTimer(d->autoReloadTimer);
1013 saveState_App_(d); 1016 saveState_App_(d);
1014 savePrefs_App_(d); 1017 savePrefs_App_(d);
1015 delete_MainWindow(d->window); 1018 iReverseForEach(PtrArray, j, &d->mainWindows) {
1019 delete_MainWindow(j.ptr);
1020 }
1021 iAssert(isEmpty_PtrArray(&d->mainWindows));
1022 deinit_PtrArray(&d->mainWindows);
1016 d->window = NULL; 1023 d->window = NULL;
1017 deinit_Feeds(); 1024 deinit_Feeds();
1018 save_Keys(dataDir_App_()); 1025 save_Keys(dataDir_App_());
@@ -1027,7 +1034,6 @@ static void deinit_App(iApp *d) {
1027 delete_GmCerts(d->certs); 1034 delete_GmCerts(d->certs);
1028 save_MimeHooks(d->mimehooks); 1035 save_MimeHooks(d->mimehooks);
1029 delete_MimeHooks(d->mimehooks); 1036 delete_MimeHooks(d->mimehooks);
1030 d->window = NULL;
1031 deinit_CommandLine(&d->args); 1037 deinit_CommandLine(&d->args);
1032 iRelease(d->launchCommands); 1038 iRelease(d->launchCommands);
1033 delete_String(d->execPath); 1039 delete_String(d->execPath);
@@ -1286,7 +1292,14 @@ static iPtrArray *listWindows_App_(const iApp *d, iPtrArray *windows) {
1286 iReverseConstForEach(PtrArray, i, &d->popupWindows) { 1292 iReverseConstForEach(PtrArray, i, &d->popupWindows) {
1287 pushBack_PtrArray(windows, i.ptr); 1293 pushBack_PtrArray(windows, i.ptr);
1288 } 1294 }
1289 pushBack_PtrArray(windows, d->window); 1295 if (d->window) {
1296 pushBack_PtrArray(windows, d->window);
1297 }
1298 iConstForEach(PtrArray, j, &d->mainWindows) {
1299 if (j.ptr != d->window) {
1300 pushBack_PtrArray(windows, j.ptr);
1301 }
1302 }
1290 return windows; 1303 return windows;
1291} 1304}
1292 1305
@@ -1843,6 +1856,26 @@ void removeTicker_App(iTickerFunc ticker, iAny *context) {
1843 remove_SortedArray(&d->tickers, &(iTicker){ context, NULL, ticker }); 1856 remove_SortedArray(&d->tickers, &(iTicker){ context, NULL, ticker });
1844} 1857}
1845 1858
1859void addWindow_App(iMainWindow *win) {
1860 iApp *d = &app_;
1861 pushBack_PtrArray(&d->mainWindows, win);
1862}
1863
1864void removeWindow_App(iMainWindow *win) {
1865 iApp *d = &app_;
1866 removeOne_PtrArray(&d->mainWindows, win);
1867}
1868
1869size_t numWindows_App(void) {
1870 return size_PtrArray(&app_.mainWindows);
1871}
1872
1873void setActiveWindow_App(iMainWindow *win) {
1874 iApp *d = &app_;
1875 d->window = win;
1876 printf("Active window: %p\n", win); fflush(stdout);
1877}
1878
1846void addPopup_App(iWindow *popup) { 1879void addPopup_App(iWindow *popup) {
1847 iApp *d = &app_; 1880 iApp *d = &app_;
1848 pushBack_PtrArray(&d->popupWindows, popup); 1881 pushBack_PtrArray(&d->popupWindows, popup);
@@ -2121,6 +2154,22 @@ iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNe
2121 return doc; 2154 return doc;
2122} 2155}
2123 2156
2157void closeWindow_App(iMainWindow *win) {
2158 iApp *d = &app_;
2159 delete_MainWindow(win);
2160 if (d->window == win) {
2161 /* Activate another window. */
2162 iForEach(PtrArray, i, &d->mainWindows) {
2163 if (i.ptr != d->window) {
2164 SDL_RaiseWindow(i.ptr);
2165 setActiveWindow_App(i.ptr);
2166 setCurrent_Window(i.ptr);
2167 break;
2168 }
2169 }
2170 }
2171}
2172
2124static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) { 2173static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) {
2125 iApp *d = &app_; 2174 iApp *d = &app_;
2126 if (equal_Command(cmd, "ident.showmore")) { 2175 if (equal_Command(cmd, "ident.showmore")) {
@@ -3016,6 +3065,15 @@ iBool handleCommand_App(const char *cmd) {
3016#endif 3065#endif
3017 return iFalse; 3066 return iFalse;
3018 } 3067 }
3068 else if (equal_Command(cmd, "window.new")) {
3069 iMainWindow *newWin = new_MainWindow(moved_Rect(d->initialWindowRect, init_I2(20, 20)));
3070 addWindow_App(newWin);
3071 SDL_ShowWindow(newWin->base.win);
3072 setCurrent_Window(newWin);
3073 postCommand_Root(newWin->base.roots[0], "navigate.home");
3074 postCommand_Root(newWin->base.roots[0], "window.unfreeze");
3075 return iTrue;
3076 }
3019 else if (equal_Command(cmd, "tabs.new")) { 3077 else if (equal_Command(cmd, "tabs.new")) {
3020 const iBool isDuplicate = argLabel_Command(cmd, "duplicate") != 0; 3078 const iBool isDuplicate = argLabel_Command(cmd, "duplicate") != 0;
3021 newTab_App(isDuplicate ? document_App() : NULL, iTrue); 3079 newTab_App(isDuplicate ? document_App() : NULL, iTrue);
@@ -3076,6 +3134,9 @@ iBool handleCommand_App(const char *cmd) {
3076 } 3134 }
3077 } 3135 }
3078 } 3136 }
3137 else if (numWindows_App() > 1) {
3138 closeWindow_App(d->window);
3139 }
3079 else { 3140 else {
3080 postCommand_App("quit"); 3141 postCommand_App("quit");
3081 } 3142 }