diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-18 14:03:05 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-18 14:03:05 +0300 |
commit | 70afbe693135d69c3855fc2b5bb28249ce471cc9 (patch) | |
tree | e8ba5592e5c82f1ddf9ff45b660d178514f01ae1 /src/app.c | |
parent | 9fd5f867ae1a3d5ed8278359582cd99ca89a0318 (diff) |
Added build option to disable IPC
It may take a while to add D-Bus support, so adding a way to disable the incompatible IPC mechanism for Flatpak builds.
IssueID #245
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 38 |
1 files changed, 23 insertions, 15 deletions
@@ -117,7 +117,7 @@ struct Impl_App { | |||
117 | uint32_t lastTickerTime; | 117 | uint32_t lastTickerTime; |
118 | uint32_t elapsedSinceLastTicker; | 118 | uint32_t elapsedSinceLastTicker; |
119 | iBool isRunning; | 119 | iBool isRunning; |
120 | #if defined (LAGRANGE_IDLE_SLEEP) | 120 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
121 | iBool isIdling; | 121 | iBool isIdling; |
122 | uint32_t lastEventTime; | 122 | uint32_t lastEventTime; |
123 | int sleepTimer; | 123 | int sleepTimer; |
@@ -169,7 +169,7 @@ static iString *serializePrefs_App_(const iApp *d) { | |||
169 | iString *str = new_String(); | 169 | iString *str = new_String(); |
170 | const iSidebarWidget *sidebar = findWidget_App("sidebar"); | 170 | const iSidebarWidget *sidebar = findWidget_App("sidebar"); |
171 | const iSidebarWidget *sidebar2 = findWidget_App("sidebar2"); | 171 | const iSidebarWidget *sidebar2 = findWidget_App("sidebar2"); |
172 | #if defined (LAGRANGE_CUSTOM_FRAME) | 172 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) |
173 | appendFormat_String(str, "customframe arg:%d\n", d->prefs.customFrame); | 173 | appendFormat_String(str, "customframe arg:%d\n", d->prefs.customFrame); |
174 | #endif | 174 | #endif |
175 | appendFormat_String(str, "window.retain arg:%d\n", d->prefs.retainWindowSize); | 175 | appendFormat_String(str, "window.retain arg:%d\n", d->prefs.retainWindowSize); |
@@ -184,7 +184,7 @@ static iString *serializePrefs_App_(const iApp *d) { | |||
184 | appendFormat_String(str, "sidebar2.width arg:%f gaps:1\n", width_SidebarWidget(sidebar2)); | 184 | appendFormat_String(str, "sidebar2.width arg:%f gaps:1\n", width_SidebarWidget(sidebar2)); |
185 | /* On macOS, maximization should be applied at creation time or the window will take | 185 | /* On macOS, maximization should be applied at creation time or the window will take |
186 | a moment to animate to its maximized size. */ | 186 | a moment to animate to its maximized size. */ |
187 | #if defined (LAGRANGE_CUSTOM_FRAME) | 187 | #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) |
188 | if (snap_Window(d->window)) { | 188 | if (snap_Window(d->window)) { |
189 | if (~SDL_GetWindowFlags(d->window->win) & SDL_WINDOW_MINIMIZED) { | 189 | if (~SDL_GetWindowFlags(d->window->win) & SDL_WINDOW_MINIMIZED) { |
190 | /* Save the actual visible window position, too, because snapped windows may | 190 | /* Save the actual visible window position, too, because snapped windows may |
@@ -337,7 +337,7 @@ static void loadPrefs_App_(iApp *d) { | |||
337 | d->initialWindowRect = init_Rect( | 337 | d->initialWindowRect = init_Rect( |
338 | pos.x, pos.y, argLabel_Command(cmd, "width"), argLabel_Command(cmd, "height")); | 338 | pos.x, pos.y, argLabel_Command(cmd, "width"), argLabel_Command(cmd, "height")); |
339 | } | 339 | } |
340 | #if !defined (LAGRANGE_DOWNLOAD_EDIT) | 340 | #if !defined (LAGRANGE_ENABLE_DOWNLOAD_EDIT) |
341 | else if (equal_Command(cmd, "downloads")) { | 341 | else if (equal_Command(cmd, "downloads")) { |
342 | continue; /* can't change downloads directory */ | 342 | continue; /* can't change downloads directory */ |
343 | } | 343 | } |
@@ -353,7 +353,7 @@ static void loadPrefs_App_(iApp *d) { | |||
353 | /* Default CA setup. */ | 353 | /* Default CA setup. */ |
354 | setCACertificates_TlsRequest(&d->prefs.caFile, &d->prefs.caPath); | 354 | setCACertificates_TlsRequest(&d->prefs.caFile, &d->prefs.caPath); |
355 | } | 355 | } |
356 | #if !defined (LAGRANGE_CUSTOM_FRAME) | 356 | #if !defined (LAGRANGE_ENABLE_CUSTOM_FRAME) |
357 | d->prefs.customFrame = iFalse; | 357 | d->prefs.customFrame = iFalse; |
358 | #endif | 358 | #endif |
359 | iRelease(f); | 359 | iRelease(f); |
@@ -447,7 +447,7 @@ static void saveState_App_(const iApp *d) { | |||
447 | iRelease(f); | 447 | iRelease(f); |
448 | } | 448 | } |
449 | 449 | ||
450 | #if defined (LAGRANGE_IDLE_SLEEP) | 450 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
451 | static uint32_t checkAsleep_App_(uint32_t interval, void *param) { | 451 | static uint32_t checkAsleep_App_(uint32_t interval, void *param) { |
452 | iApp *d = param; | 452 | iApp *d = param; |
453 | iUnused(d); | 453 | iUnused(d); |
@@ -470,6 +470,7 @@ static void terminate_App_(int rc) { | |||
470 | exit(rc); | 470 | exit(rc); |
471 | } | 471 | } |
472 | 472 | ||
473 | #if defined (LAGRANGE_ENABLE_IPC) | ||
473 | static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance, | 474 | static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance, |
474 | const iStringList *openCmds) { | 475 | const iStringList *openCmds) { |
475 | iString *cmds = new_String(); | 476 | iString *cmds = new_String(); |
@@ -520,6 +521,7 @@ static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance, | |||
520 | // } | 521 | // } |
521 | terminate_App_(0); | 522 | terminate_App_(0); |
522 | } | 523 | } |
524 | #endif /* defined (LAGRANGE_ENABLE_IPC) */ | ||
523 | 525 | ||
524 | static void init_App_(iApp *d, int argc, char **argv) { | 526 | static void init_App_(iApp *d, int argc, char **argv) { |
525 | init_CommandLine(&d->args, argc, argv); | 527 | init_CommandLine(&d->args, argc, argv); |
@@ -600,6 +602,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
600 | } | 602 | } |
601 | } | 603 | } |
602 | } | 604 | } |
605 | #if defined (LAGRANGE_ENABLE_IPC) | ||
603 | /* Only one instance is allowed to run at a time; the runtime files (bookmarks, etc.) | 606 | /* Only one instance is allowed to run at a time; the runtime files (bookmarks, etc.) |
604 | are not shareable. */ { | 607 | are not shareable. */ { |
605 | init_Ipc(dataDir_App_()); | 608 | init_Ipc(dataDir_App_()); |
@@ -614,6 +617,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
614 | } | 617 | } |
615 | listen_Ipc(); /* We'll respond to commands from other instances. */ | 618 | listen_Ipc(); /* We'll respond to commands from other instances. */ |
616 | } | 619 | } |
620 | #endif | ||
617 | printf("Lagrange: A Beautiful Gemini Client\n"); | 621 | printf("Lagrange: A Beautiful Gemini Client\n"); |
618 | const iBool isFirstRun = | 622 | const iBool isFirstRun = |
619 | !fileExistsCStr_FileInfo(cleanedPath_CStr(concatPath_CStr(dataDir_App_(), "prefs.cfg"))); | 623 | !fileExistsCStr_FileInfo(cleanedPath_CStr(concatPath_CStr(dataDir_App_(), "prefs.cfg"))); |
@@ -686,7 +690,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
686 | postCommand_App("window.unfreeze"); | 690 | postCommand_App("window.unfreeze"); |
687 | d->autoReloadTimer = SDL_AddTimer(60 * 1000, postAutoReloadCommand_App_, NULL); | 691 | d->autoReloadTimer = SDL_AddTimer(60 * 1000, postAutoReloadCommand_App_, NULL); |
688 | postCommand_App("document.autoreload"); | 692 | postCommand_App("document.autoreload"); |
689 | #if defined (LAGRANGE_IDLE_SLEEP) | 693 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
690 | d->isIdling = iFalse; | 694 | d->isIdling = iFalse; |
691 | d->lastEventTime = 0; | 695 | d->lastEventTime = 0; |
692 | d->sleepTimer = SDL_AddTimer(1000, checkAsleep_App_, d); | 696 | d->sleepTimer = SDL_AddTimer(1000, checkAsleep_App_, d); |
@@ -707,7 +711,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
707 | } | 711 | } |
708 | 712 | ||
709 | static void deinit_App(iApp *d) { | 713 | static void deinit_App(iApp *d) { |
710 | #if defined (LAGRANGE_IDLE_SLEEP) | 714 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
711 | SDL_RemoveTimer(d->sleepTimer); | 715 | SDL_RemoveTimer(d->sleepTimer); |
712 | #endif | 716 | #endif |
713 | SDL_RemoveTimer(d->autoReloadTimer); | 717 | SDL_RemoveTimer(d->autoReloadTimer); |
@@ -729,7 +733,9 @@ static void deinit_App(iApp *d) { | |||
729 | deinit_CommandLine(&d->args); | 733 | deinit_CommandLine(&d->args); |
730 | iRelease(d->launchCommands); | 734 | iRelease(d->launchCommands); |
731 | delete_String(d->execPath); | 735 | delete_String(d->execPath); |
736 | #if defined (LAGRANGE_ENABLE_IPC) | ||
732 | deinit_Ipc(); | 737 | deinit_Ipc(); |
738 | #endif | ||
733 | deinit_SortedArray(&d->tickers); | 739 | deinit_SortedArray(&d->tickers); |
734 | deinit_Periodic(&d->periodic); | 740 | deinit_Periodic(&d->periodic); |
735 | deinit_Lang(); | 741 | deinit_Lang(); |
@@ -875,7 +881,7 @@ iLocalDef iBool isWaitingAllowed_App_(iApp *d) { | |||
875 | if (d->warmupFrames > 0) { | 881 | if (d->warmupFrames > 0) { |
876 | return iFalse; | 882 | return iFalse; |
877 | } | 883 | } |
878 | #if defined (LAGRANGE_IDLE_SLEEP) | 884 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
879 | if (d->isIdling) { | 885 | if (d->isIdling) { |
880 | return iFalse; | 886 | return iFalse; |
881 | } | 887 | } |
@@ -928,7 +934,7 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
928 | case SDL_APP_DIDENTERFOREGROUND: | 934 | case SDL_APP_DIDENTERFOREGROUND: |
929 | gotEvents = iTrue; | 935 | gotEvents = iTrue; |
930 | d->warmupFrames = 5; | 936 | d->warmupFrames = 5; |
931 | #if defined (LAGRANGE_IDLE_SLEEP) | 937 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
932 | d->isIdling = iFalse; | 938 | d->isIdling = iFalse; |
933 | d->lastEventTime = SDL_GetTicks(); | 939 | d->lastEventTime = SDL_GetTicks(); |
934 | #endif | 940 | #endif |
@@ -962,7 +968,7 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
962 | break; | 968 | break; |
963 | } | 969 | } |
964 | default: { | 970 | default: { |
965 | #if defined (LAGRANGE_IDLE_SLEEP) | 971 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
966 | if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) { | 972 | if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) { |
967 | if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_ && | 973 | if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_ && |
968 | isEmpty_SortedArray(&d->tickers)) { | 974 | isEmpty_SortedArray(&d->tickers)) { |
@@ -1051,7 +1057,7 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
1051 | } | 1057 | } |
1052 | } | 1058 | } |
1053 | } | 1059 | } |
1054 | #if defined (LAGRANGE_IDLE_SLEEP) | 1060 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
1055 | if (d->isIdling && !gotEvents && isFinished_Anim(&d->window->rootOffset)) { | 1061 | if (d->isIdling && !gotEvents && isFinished_Anim(&d->window->rootOffset)) { |
1056 | /* This is where we spend most of our time when idle. 60 Hz still quite a lot but we | 1062 | /* This is where we spend most of our time when idle. 60 Hz still quite a lot but we |
1057 | can't wait too long after the user tries to interact again with the app. In any | 1063 | can't wait too long after the user tries to interact again with the app. In any |
@@ -1124,7 +1130,7 @@ static int run_App_(iApp *d) { | |||
1124 | void refresh_App(void) { | 1130 | void refresh_App(void) { |
1125 | iApp *d = &app_; | 1131 | iApp *d = &app_; |
1126 | destroyPending_Widget(); | 1132 | destroyPending_Widget(); |
1127 | #if defined (LAGRANGE_IDLE_SLEEP) | 1133 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
1128 | if (d->warmupFrames == 0 && d->isIdling) { | 1134 | if (d->warmupFrames == 0 && d->isIdling) { |
1129 | return; | 1135 | return; |
1130 | } | 1136 | } |
@@ -1201,7 +1207,7 @@ int run_App(int argc, char **argv) { | |||
1201 | 1207 | ||
1202 | void postRefresh_App(void) { | 1208 | void postRefresh_App(void) { |
1203 | iApp *d = &app_; | 1209 | iApp *d = &app_; |
1204 | #if defined (LAGRANGE_IDLE_SLEEP) | 1210 | #if defined (LAGRANGE_ENABLE_IDLE_SLEEP) |
1205 | d->isIdling = iFalse; | 1211 | d->isIdling = iFalse; |
1206 | #endif | 1212 | #endif |
1207 | const iBool wasPending = exchange_Atomic(&d->pendingRefresh, iTrue); | 1213 | const iBool wasPending = exchange_Atomic(&d->pendingRefresh, iTrue); |
@@ -1342,7 +1348,7 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) { | |||
1342 | if (equal_Command(cmd, "prefs.dismiss") || equal_Command(cmd, "preferences")) { | 1348 | if (equal_Command(cmd, "prefs.dismiss") || equal_Command(cmd, "preferences")) { |
1343 | setUiScale_Window(get_Window(), | 1349 | setUiScale_Window(get_Window(), |
1344 | toFloat_String(text_InputWidget(findChild_Widget(d, "prefs.uiscale")))); | 1350 | toFloat_String(text_InputWidget(findChild_Widget(d, "prefs.uiscale")))); |
1345 | #if defined (LAGRANGE_DOWNLOAD_EDIT) | 1351 | #if defined (LAGRANGE_ENABLE_DOWNLOAD_EDIT) |
1346 | postCommandf_App("downloads path:%s", | 1352 | postCommandf_App("downloads path:%s", |
1347 | cstr_String(text_InputWidget(findChild_Widget(d, "prefs.downloads")))); | 1353 | cstr_String(text_InputWidget(findChild_Widget(d, "prefs.downloads")))); |
1348 | #endif | 1354 | #endif |
@@ -2142,6 +2148,7 @@ iBool handleCommand_App(const char *cmd) { | |||
2142 | } | 2148 | } |
2143 | return iFalse; | 2149 | return iFalse; |
2144 | } | 2150 | } |
2151 | #if defined (LAGRANGE_ENABLE_IPC) | ||
2145 | else if (equal_Command(cmd, "ipc.list.urls")) { | 2152 | else if (equal_Command(cmd, "ipc.list.urls")) { |
2146 | iProcessId pid = argLabel_Command(cmd, "pid"); | 2153 | iProcessId pid = argLabel_Command(cmd, "pid"); |
2147 | if (pid) { | 2154 | if (pid) { |
@@ -2158,6 +2165,7 @@ iBool handleCommand_App(const char *cmd) { | |||
2158 | signal_Ipc(arg_Command(cmd)); | 2165 | signal_Ipc(arg_Command(cmd)); |
2159 | return iTrue; | 2166 | return iTrue; |
2160 | } | 2167 | } |
2168 | #endif /* defined (LAGRANGE_ENABLE_IPC) */ | ||
2161 | else { | 2169 | else { |
2162 | return iFalse; | 2170 | return iFalse; |
2163 | } | 2171 | } |