summaryrefslogtreecommitdiff
path: root/src/app.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-18 11:26:11 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-18 11:26:11 +0200
commitfa174461abdc5c33de16428109c7d46b4f150093 (patch)
tree21cf16a2426f8a6b76195e1816ceea69778fbd70 /src/app.c
parent21f6248a3dc906a0c296b937dd1aa697784e6ea3 (diff)
Scrollbar fading and periodic commands
Added a new mechanism to issue periodic but not per-frame commands. This is used for main-thread operations like checking if it's time to fade away the scrollbars. Scrollbars are faded away completely on Apple platforms. Adjusted list right margins accordingly.
Diffstat (limited to 'src/app.c')
-rw-r--r--src/app.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/app.c b/src/app.c
index 383b9e2a..c5ddc454 100644
--- a/src/app.c
+++ b/src/app.c
@@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
31#include "gmutil.h" 31#include "gmutil.h"
32#include "history.h" 32#include "history.h"
33#include "ipc.h" 33#include "ipc.h"
34#include "periodic.h"
34#include "ui/certimportwidget.h" 35#include "ui/certimportwidget.h"
35#include "ui/color.h" 36#include "ui/color.h"
36#include "ui/command.h" 37#include "ui/command.h"
@@ -108,7 +109,7 @@ struct Impl_App {
108 iVisited * visited; 109 iVisited * visited;
109 iBookmarks * bookmarks; 110 iBookmarks * bookmarks;
110 iWindow * window; 111 iWindow * window;
111 iSortedArray tickers; 112 iSortedArray tickers; /* per-frame callbacks, used for animations */
112 uint32_t lastTickerTime; 113 uint32_t lastTickerTime;
113 uint32_t elapsedSinceLastTicker; 114 uint32_t elapsedSinceLastTicker;
114 iBool isRunning; 115 iBool isRunning;
@@ -123,6 +124,7 @@ struct Impl_App {
123 iBool isFinishedLaunching; 124 iBool isFinishedLaunching;
124 iTime lastDropTime; /* for detecting drops of multiple items */ 125 iTime lastDropTime; /* for detecting drops of multiple items */
125 int autoReloadTimer; 126 int autoReloadTimer;
127 iPeriodic periodic;
126 /* Preferences: */ 128 /* Preferences: */
127 iBool commandEcho; /* --echo */ 129 iBool commandEcho; /* --echo */
128 iBool forceSoftwareRender; /* --sw */ 130 iBool forceSoftwareRender; /* --sw */
@@ -132,6 +134,8 @@ struct Impl_App {
132 134
133static iApp app_; 135static iApp app_;
134 136
137/*----------------------------------------------------------------------------------------------*/
138
135iDeclareType(Ticker) 139iDeclareType(Ticker)
136 140
137struct Impl_Ticker { 141struct Impl_Ticker {
@@ -144,6 +148,8 @@ static int cmp_Ticker_(const void *a, const void *b) {
144 return iCmp(elems[0]->context, elems[1]->context); 148 return iCmp(elems[0]->context, elems[1]->context);
145} 149}
146 150
151/*----------------------------------------------------------------------------------------------*/
152
147const iString *dateStr_(const iDate *date) { 153const iString *dateStr_(const iDate *date) {
148 return collectNewFormat_String("%d-%02d-%02d %02d:%02d:%02d", 154 return collectNewFormat_String("%d-%02d-%02d %02d:%02d:%02d",
149 date->year, 155 date->year,
@@ -611,6 +617,7 @@ static void init_App_(iApp *d, int argc, char **argv) {
611 d->visited = new_Visited(); 617 d->visited = new_Visited();
612 d->bookmarks = new_Bookmarks(); 618 d->bookmarks = new_Bookmarks();
613 d->tabEnum = 0; /* generates unique IDs for tab pages */ 619 d->tabEnum = 0; /* generates unique IDs for tab pages */
620 init_Periodic(&d->periodic);
614 setThemePalette_Color(d->prefs.theme); 621 setThemePalette_Color(d->prefs.theme);
615#if defined (iPlatformAppleDesktop) 622#if defined (iPlatformAppleDesktop)
616 setupApplication_MacOS(); 623 setupApplication_MacOS();
@@ -668,6 +675,10 @@ static void init_App_(iApp *d, int argc, char **argv) {
668} 675}
669 676
670static void deinit_App(iApp *d) { 677static void deinit_App(iApp *d) {
678#if defined (LAGRANGE_IDLE_SLEEP)
679 SDL_RemoveTimer(d->sleepTimer);
680#endif
681 SDL_RemoveTimer(d->autoReloadTimer);
671 saveState_App_(d); 682 saveState_App_(d);
672 deinit_Feeds(); 683 deinit_Feeds();
673 save_Keys(dataDir_App_()); 684 save_Keys(dataDir_App_());
@@ -681,13 +692,14 @@ static void deinit_App(iApp *d) {
681 delete_GmCerts(d->certs); 692 delete_GmCerts(d->certs);
682 save_MimeHooks(d->mimehooks); 693 save_MimeHooks(d->mimehooks);
683 delete_MimeHooks(d->mimehooks); 694 delete_MimeHooks(d->mimehooks);
684 deinit_SortedArray(&d->tickers);
685 delete_Window(d->window); 695 delete_Window(d->window);
686 d->window = NULL; 696 d->window = NULL;
687 deinit_CommandLine(&d->args); 697 deinit_CommandLine(&d->args);
688 iRelease(d->launchCommands); 698 iRelease(d->launchCommands);
689 delete_String(d->execPath); 699 delete_String(d->execPath);
690 deinit_Ipc(); 700 deinit_Ipc();
701 deinit_SortedArray(&d->tickers);
702 deinit_Periodic(&d->periodic);
691 iRecycle(); 703 iRecycle();
692} 704}
693 705
@@ -892,10 +904,11 @@ void processEvents_App(enum iAppEventMode eventMode) {
892 default: { 904 default: {
893#if defined (LAGRANGE_IDLE_SLEEP) 905#if defined (LAGRANGE_IDLE_SLEEP)
894 if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) { 906 if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) {
895 if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_) { 907 if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_ &&
908 isEmpty_SortedArray(&d->tickers)) {
896 if (!d->isIdling) { 909 if (!d->isIdling) {
897// printf("[App] idling...\n"); 910// printf("[App] idling...\n");
898 fflush(stdout); 911// fflush(stdout);
899 } 912 }
900 d->isIdling = iTrue; 913 d->isIdling = iTrue;
901 } 914 }
@@ -904,7 +917,7 @@ void processEvents_App(enum iAppEventMode eventMode) {
904 d->lastEventTime = SDL_GetTicks(); 917 d->lastEventTime = SDL_GetTicks();
905 if (d->isIdling) { 918 if (d->isIdling) {
906// printf("[App] ...woke up\n"); 919// printf("[App] ...woke up\n");
907 fflush(stdout); 920// fflush(stdout);
908 } 921 }
909 d->isIdling = iFalse; 922 d->isIdling = iFalse;
910#endif 923#endif
@@ -1043,9 +1056,9 @@ void refresh_App(void) {
1043#if defined (LAGRANGE_IDLE_SLEEP) 1056#if defined (LAGRANGE_IDLE_SLEEP)
1044 if (d->isIdling) return; 1057 if (d->isIdling) return;
1045#endif 1058#endif
1059 set_Atomic(&d->pendingRefresh, iFalse);
1046 destroyPending_Widget(); 1060 destroyPending_Widget();
1047 draw_Window(d->window); 1061 draw_Window(d->window);
1048 set_Atomic(&d->pendingRefresh, iFalse);
1049} 1062}
1050 1063
1051iBool isRefreshPending_App(void) { 1064iBool isRefreshPending_App(void) {
@@ -1175,6 +1188,10 @@ iMimeHooks *mimeHooks_App(void) {
1175 return app_.mimehooks; 1188 return app_.mimehooks;
1176} 1189}
1177 1190
1191iPeriodic *periodic_App(void) {
1192 return &app_.periodic;
1193}
1194
1178iBool isLandscape_App(void) { 1195iBool isLandscape_App(void) {
1179 const iInt2 size = rootSize_Window(get_Window()); 1196 const iInt2 size = rootSize_Window(get_Window());
1180 return size.x > size.y; 1197 return size.x > size.y;