summaryrefslogtreecommitdiff
path: root/src/app.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.c')
-rw-r--r--src/app.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/app.c b/src/app.c
index ec8b59b3..010c6d74 100644
--- a/src/app.c
+++ b/src/app.c
@@ -559,6 +559,7 @@ static iBool loadState_App_(iApp *d) {
559 const int winState = read32_File(f); 559 const int winState = read32_File(f);
560 const int keyRoot = (winState & 1); 560 const int keyRoot = (winState & 1);
561 const iBool isCurrent = (winState & current_WindowStateFlag) != 0; 561 const iBool isCurrent = (winState & current_WindowStateFlag) != 0;
562// printf("[State] '%.4s' split:%d state:%x\n", magic, splitMode, winState);
562 if (numWins == 1) { 563 if (numWins == 1) {
563 win = d->window; 564 win = d->window;
564 } 565 }
@@ -575,7 +576,7 @@ static iBool loadState_App_(iApp *d) {
575 setCurrent_Root(NULL); 576 setCurrent_Root(NULL);
576 win->pendingSplitMode = splitMode; 577 win->pendingSplitMode = splitMode;
577 setSplitMode_MainWindow(win, splitMode | noEvents_WindowSplit); 578 setSplitMode_MainWindow(win, splitMode | noEvents_WindowSplit);
578 win->base.keyRoot = d->window->base.roots[keyRoot]; 579 win->base.keyRoot = win->base.roots[keyRoot];
579 } 580 }
580 else if (!memcmp(magic, magicSidebar_App_, 4)) { 581 else if (!memcmp(magic, magicSidebar_App_, 4)) {
581 if (!win) { 582 if (!win) {
@@ -1061,8 +1062,8 @@ static void init_App_(iApp *d, int argc, char **argv) {
1061 } 1062 }
1062 postCommand_App("~navbar.actions.changed"); 1063 postCommand_App("~navbar.actions.changed");
1063 postCommand_App("~toolbar.actions.changed"); 1064 postCommand_App("~toolbar.actions.changed");
1064 postCommand_Root(NULL, "~window.unfreeze"); 1065 postCommand_App("~window.unfreeze");
1065 postCommand_Root(NULL, "font.reset"); 1066 postCommand_App("font.reset");
1066 d->autoReloadTimer = SDL_AddTimer(60 * 1000, postAutoReloadCommand_App_, NULL); 1067 d->autoReloadTimer = SDL_AddTimer(60 * 1000, postAutoReloadCommand_App_, NULL);
1067 postCommand_Root(NULL, "document.autoreload"); 1068 postCommand_Root(NULL, "document.autoreload");
1068#if defined (LAGRANGE_ENABLE_IDLE_SLEEP) 1069#if defined (LAGRANGE_ENABLE_IDLE_SLEEP)
@@ -1390,6 +1391,12 @@ static iPtrArray *listWindows_App_(const iApp *d, iPtrArray *windows) {
1390 return windows; 1391 return windows;
1391} 1392}
1392 1393
1394iPtrArray *listWindows_App(void) {
1395 iPtrArray *wins = new_PtrArray();
1396 listWindows_App_(&app_, wins);
1397 return wins;
1398}
1399
1393void processEvents_App(enum iAppEventMode eventMode) { 1400void processEvents_App(enum iAppEventMode eventMode) {
1394 iApp *d = &app_; 1401 iApp *d = &app_;
1395 iRoot *oldCurrentRoot = current_Root(); /* restored afterwards */ 1402 iRoot *oldCurrentRoot = current_Root(); /* restored afterwards */
@@ -1672,6 +1679,9 @@ static void runTickers_App_(iApp *d) {
1672 iConstForEach(Array, i, &pending->values) { 1679 iConstForEach(Array, i, &pending->values) {
1673 const iTicker *ticker = i.value; 1680 const iTicker *ticker = i.value;
1674 if (ticker->callback) { 1681 if (ticker->callback) {
1682 if (ticker->root) {
1683 setCurrent_Window(ticker->root->window);
1684 }
1675 setCurrent_Root(ticker->root); /* root might be NULL */ 1685 setCurrent_Root(ticker->root); /* root might be NULL */
1676 ticker->callback(ticker->context); 1686 ticker->callback(ticker->context);
1677 } 1687 }
@@ -1864,9 +1874,9 @@ void postCommand_Root(iRoot *d, const char *command) {
1864 } 1874 }
1865 SDL_Event ev = { .type = SDL_USEREVENT }; 1875 SDL_Event ev = { .type = SDL_USEREVENT };
1866 ev.user.code = command_UserEventCode; 1876 ev.user.code = command_UserEventCode;
1867// ev.user.windowID = id_Window(get_Window());
1868 ev.user.data1 = strdup(command); 1877 ev.user.data1 = strdup(command);
1869 ev.user.data2 = d; /* all events are root-specific */ 1878 ev.user.data2 = d; /* all events are root-specific */
1879 ev.user.windowID = d ? id_Window(d->window) : 0; /* root-specific means window-specific */
1870 SDL_PushEvent(&ev); 1880 SDL_PushEvent(&ev);
1871 iWindow *win = get_Window(); 1881 iWindow *win = get_Window();
1872#if defined (iPlatformAndroid) 1882#if defined (iPlatformAndroid)
@@ -1969,6 +1979,10 @@ size_t windowIndex_App(const iMainWindow *win) {
1969 return indexOf_PtrArray(&app_.mainWindows, win); 1979 return indexOf_PtrArray(&app_.mainWindows, win);
1970} 1980}
1971 1981
1982const iPtrArray *mainWindows_App(void) {
1983 return &app_.mainWindows;
1984}
1985
1972void setActiveWindow_App(iMainWindow *win) { 1986void setActiveWindow_App(iMainWindow *win) {
1973 iApp *d = &app_; 1987 iApp *d = &app_;
1974 d->window = win; 1988 d->window = win;
@@ -2527,12 +2541,16 @@ iBool handleCommand_App(const char *cmd) {
2527 return iTrue; 2541 return iTrue;
2528 } 2542 }
2529 else if (equal_Command(cmd, "window.maximize")) { 2543 else if (equal_Command(cmd, "window.maximize")) {
2530 if (!argLabel_Command(cmd, "toggle")) { 2544 const size_t winIndex = argU32Label_Command(cmd, "index");
2531 setSnap_MainWindow(d->window, maximized_WindowSnap); 2545 if (winIndex < size_PtrArray(&d->mainWindows)) {
2532 } 2546 iMainWindow *win = at_PtrArray(&d->mainWindows, winIndex);
2533 else { 2547 if (!argLabel_Command(cmd, "toggle")) {
2534 setSnap_MainWindow(d->window, snap_MainWindow(d->window) == maximized_WindowSnap ? 0 : 2548 setSnap_MainWindow(win, maximized_WindowSnap);
2535 maximized_WindowSnap); 2549 }
2550 else {
2551 setSnap_MainWindow(
2552 win, snap_MainWindow(win) == maximized_WindowSnap ? 0 : maximized_WindowSnap);
2553 }
2536 } 2554 }
2537 return iTrue; 2555 return iTrue;
2538 } 2556 }