=> bef61b34d8a23e2e8594207c2876ce982fe0e15f
[1mdiff --git a/src/app.c b/src/app.c[m [1mindex d47c6ef1..686d8b82 100644[m [1m--- a/src/app.c[m [1m+++ b/src/app.c[m [36m@@ -125,7 +125,8 @@[m [mstruct Impl_App {[m iGmCerts * certs;[m iVisited * visited;[m iBookmarks * bookmarks;[m [31m- iMainWindow *window;[m [32m+[m[32m iMainWindow *window; /* currently active MainWindow */[m [32m+[m[32m iPtrArray mainWindows;[m iPtrArray popupWindows;[m iSortedArray tickers; /* per-frame callbacks, used for animations */[m uint32_t lastTickerTime;[m [36m@@ -474,7 +475,7 @@[m [mstatic const char *magicTabDocument_App_ = "tabd";[m static const char *magicSidebar_App_ = "side";[m [m enum iDocumentStateFlag {[m [31m- current_DocumentStateFlag = iBit(1),[m [32m+[m[32m current_DocumentStateFlag = iBit(1),[m rootIndex1_DocumentStateFlag = iBit(2)[m };[m [m [36m@@ -946,8 +947,10 @@[m [mstatic void init_App_(iApp *d, int argc, char **argv) {[m d->initialWindowRect.size.y = toInt_String(value_CommandLineArg(arg, 0));[m }[m }[m [32m+[m[32m init_PtrArray(&d->mainWindows);[m init_PtrArray(&d->popupWindows);[m d->window = new_MainWindow(d->initialWindowRect);[m [32m+[m[32m addWindow_App(d->window);[m load_Visited(d->visited, dataDir_App_());[m load_Bookmarks(d->bookmarks, dataDir_App_());[m load_MimeHooks(d->mimehooks, dataDir_App_());[m [36m@@ -1012,7 +1015,11 @@[m [mstatic void deinit_App(iApp *d) {[m SDL_RemoveTimer(d->autoReloadTimer);[m saveState_App_(d);[m savePrefs_App_(d);[m [31m- delete_MainWindow(d->window);[m [32m+[m[32m iReverseForEach(PtrArray, j, &d->mainWindows) {[m [32m+[m[32m delete_MainWindow(j.ptr);[m [32m+[m[32m }[m [32m+[m[32m iAssert(isEmpty_PtrArray(&d->mainWindows));[m [32m+[m[32m deinit_PtrArray(&d->mainWindows);[m d->window = NULL;[m deinit_Feeds();[m save_Keys(dataDir_App_());[m [36m@@ -1027,7 +1034,6 @@[m [mstatic void deinit_App(iApp *d) {[m delete_GmCerts(d->certs);[m save_MimeHooks(d->mimehooks);[m delete_MimeHooks(d->mimehooks);[m [31m- d->window = NULL;[m deinit_CommandLine(&d->args);[m iRelease(d->launchCommands);[m delete_String(d->execPath);[m [36m@@ -1286,7 +1292,14 @@[m [mstatic iPtrArray *listWindows_App_(const iApp *d, iPtrArray *windows) {[m iReverseConstForEach(PtrArray, i, &d->popupWindows) {[m pushBack_PtrArray(windows, i.ptr);[m }[m [31m- pushBack_PtrArray(windows, d->window);[m [32m+[m[32m if (d->window) {[m [32m+[m[32m pushBack_PtrArray(windows, d->window);[m [32m+[m[32m }[m [32m+[m[32m iConstForEach(PtrArray, j, &d->mainWindows) {[m [32m+[m[32m if (j.ptr != d->window) {[m [32m+[m[32m pushBack_PtrArray(windows, j.ptr);[m [32m+[m[32m }[m [32m+[m[32m }[m return windows;[m }[m [m [36m@@ -1843,6 +1856,26 @@[m [mvoid removeTicker_App(iTickerFunc ticker, iAny *context) {[m remove_SortedArray(&d->tickers, &(iTicker){ context, NULL, ticker });[m }[m [m [32m+[m[32mvoid addWindow_App(iMainWindow *win) {[m [32m+[m[32m iApp *d = &app_;[m [32m+[m[32m pushBack_PtrArray(&d->mainWindows, win);[m [32m+[m[32m}[m [32m+[m [32m+[m[32mvoid removeWindow_App(iMainWindow *win) {[m [32m+[m[32m iApp *d = &app_;[m [32m+[m[32m removeOne_PtrArray(&d->mainWindows, win);[m [32m+[m[32m}[m [32m+[m [32m+[m[32msize_t numWindows_App(void) {[m [32m+[m[32m return size_PtrArray(&app_.mainWindows);[m [32m+[m[32m}[m [32m+[m [32m+[m[32mvoid setActiveWindow_App(iMainWindow *win) {[m [32m+[m[32m iApp *d = &app_;[m [32m+[m[32m d->window = win;[m [32m+[m[32m printf("Active window: %p\n", win); fflush(stdout);[m [32m+[m[32m}[m [32m+[m void addPopup_App(iWindow *popup) {[m iApp *d = &app_;[m pushBack_PtrArray(&d->popupWindows, popup);[m [36m@@ -2121,6 +2154,22 @@[m [miDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf, iBool switchToNe[m return doc;[m }[m [m [32m+[m[32mvoid closeWindow_App(iMainWindow *win) {[m [32m+[m[32m iApp *d = &app_;[m [32m+[m[32m delete_MainWindow(win);[m [32m+[m[32m if (d->window == win) {[m [32m+[m[32m /* Activate another window. */[m [32m+[m[32m iForEach(PtrArray, i, &d->mainWindows) {[m [32m+[m[32m if (i.ptr != d->window) {[m [32m+[m[32m SDL_RaiseWindow(i.ptr);[m [32m+[m[32m setActiveWindow_App(i.ptr);[m [32m+[m[32m setCurrent_Window(i.ptr);[m [32m+[m[32m break;[m [32m+[m[32m }[m [32m+[m[32m }[m [32m+[m[32m }[m [32m+[m[32m}[m [32m+[m static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) {[m iApp *d = &app_;[m if (equal_Command(cmd, "ident.showmore")) {[m [36m@@ -3016,6 +3065,15 @@[m [miBool handleCommand_App(const char *cmd) {[m #endif[m return iFalse;[m }[m [32m+[m[32m else if (equal_Command(cmd, "window.new")) {[m [32m+[m[32m iMainWindow *newWin = new_MainWindow(moved_Rect(d->initialWindowRect, init_I2(20, 20)));[m [32m+[m[32m addWindow_App(newWin);[m [32m+[m[32m SDL_ShowWindow(newWin->base.win);[m [32m+[m[32m setCurrent_Window(newWin);[m [32m+[m[32m postCommand_Root(newWin->base.roots[0], "navigate.home");[m [32m+[m[32m postCommand_Root(newWin->base.roots[0], "window.unfreeze");[m [32m+[m[32m return iTrue;[m [32m+[m[32m }[m else if (equal_Command(cmd, "tabs.new")) {[m const iBool isDuplicate = argLabel_Command(cmd, "duplicate") != 0;[m newTab_App(isDuplicate ? document_App() : NULL, iTrue);[m [36m@@ -3076,6 +3134,9 @@[m [miBool handleCommand_App(const char *cmd) {[m }[m }[m }[m [32m+[m[32m else if (numWindows_App() > 1) {[m [32m+[m[32m closeWindow_App(d->window);[m [32m+[m[32m }[m else {[m postCommand_App("quit");[m }[m [1mdiff --git a/src/app.h b/src/app.h[m [1mindex 22fe5d46..74a5429b 100644[m [1m--- a/src/app.h[m [1m+++ b/src/app.h[m [36m@@ -122,6 +122,11 @@[m [miAny * findWidget_App (const char *id);[m void addTicker_App (iTickerFunc ticker, iAny *context);[m void addTickerRoot_App (iTickerFunc ticker, iRoot *root, iAny *context);[m void removeTicker_App (iTickerFunc ticker, iAny *context);[m [32m+[m[32mvoid addWindow_App (iMainWindow *win);[m [32m+[m[32mvoid removeWindow_App (iMainWindow *win);[m [32m+[m[32mvoid setActiveWindow_App (iMainWindow *win);[m [32m+[m[32mvoid closeWindow_App (iMainWindow *win);[m [32m+[m[32msize_t numWindows_App (void);[m void addPopup_App (iWindow *popup);[m void removePopup_App (iWindow *popup);[m void postRefresh_App (void);[m [1mdiff --git a/src/ui/window.c b/src/ui/window.c[m [1mindex 47abf878..bc32e479 100644[m [1m--- a/src/ui/window.c[m [1m+++ b/src/ui/window.c[m [36m@@ -80,6 +80,7 @@[m [miDefineTypeConstructionArgs(MainWindow, (iRect rect), rect)[m #if defined (iHaveNativeMenus)[m /* Using native menus. */[m static const iMenuItem fileMenuItems_[] = {[m [32m+[m[32m { "${menu.newwindow}", SDLK_n, KMOD_PRIMARY, "window.new" },[m { "${menu.newtab}", SDLK_t, KMOD_PRIMARY, "tabs.new" },[m { "${menu.openlocation}", SDLK_l, KMOD_PRIMARY, "navigate.focus" },[m { "---", 0, 0, NULL },[m [36m@@ -210,7 +211,9 @@[m [mstatic void windowSizeChanged_MainWindow_(iMainWindow *d) {[m [m static void setupUserInterface_MainWindow(iMainWindow *d) {[m #if defined (iHaveNativeMenus)[m [31m- insertMacMenus_();[m [32m+[m[32m if (numWindows_App() == 0) {[m [32m+[m[32m insertMacMenus_(); /* TODO: Shouldn't this be in the App? */[m [32m+[m[32m }[m #endif[m /* One root is created by default. */[m d->base.roots[0] = new_Root();[m [36m@@ -246,6 +249,7 @@[m [mstatic void updateSize_MainWindow_(iMainWindow *d, iBool notifyAlways) {[m [m void drawWhileResizing_MainWindow(iMainWindow *d, int w, int h) {[m if (!isDrawing_) {[m [32m+[m[32m setCurrent_Window(d);[m draw_MainWindow(d);[m }[m }[m [36m@@ -647,6 +651,7 @@[m [mvoid init_MainWindow(iMainWindow *d, iRect rect) {[m }[m [m void deinit_MainWindow(iMainWindow *d) {[m [32m+[m[32m removeWindow_App(d);[m if (d->backBuf) {[m SDL_DestroyTexture(d->backBuf);[m }[m [36m@@ -830,6 +835,9 @@[m [mstatic void savePlace_MainWindow_(iAny *mainWindow) {[m }[m [m static iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent *ev) {[m [32m+[m[32m if (ev->windowID != SDL_GetWindowID(d->base.win)) {[m [32m+[m[32m return iFalse;[m [32m+[m[32m }[m switch (ev->event) {[m #if defined(iPlatformDesktop)[m case SDL_WINDOWEVENT_EXPOSED:[m [36m@@ -953,6 +961,7 @@[m [mstatic iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent[m setCapsLockDown_Keys(iFalse);[m postCommand_App("window.focus.gained");[m d->base.isExposed = iTrue;[m [32m+[m[32m setActiveWindow_App(d);[m #if !defined (iPlatformDesktop)[m /* Returned to foreground, may have lost buffered content. */[m invalidate_MainWindow_(d, iTrue);[m [36m@@ -970,6 +979,11 @@[m [mstatic iBool handleWindowEvent_MainWindow_(iMainWindow *d, const SDL_WindowEvent[m SDL_SetWindowInputFocus(d->base.win);[m postRefresh_App();[m return iTrue;[m [32m+[m[32m case SDL_WINDOWEVENT_CLOSE:[m [32m+[m[32m if (numWindows_App() > 1) {[m [32m+[m[32m closeWindow_App(d);[m [32m+[m[32m }[m [32m+[m[32m return iTrue;[m default:[m break;[m }[m
text/gemini; charset=utf-8
This content has been proxied by September (ba2dc).