summaryrefslogtreecommitdiff
path: root/src/app.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.c')
-rw-r--r--src/app.c95
1 files changed, 45 insertions, 50 deletions
diff --git a/src/app.c b/src/app.c
index c0c0c47e..9c1ec7a4 100644
--- a/src/app.c
+++ b/src/app.c
@@ -94,17 +94,20 @@ struct Impl_App {
94 iTime lastDropTime; /* for detecting drops of multiple items */ 94 iTime lastDropTime; /* for detecting drops of multiple items */
95 /* Preferences: */ 95 /* Preferences: */
96 iBool commandEcho; /* --echo */ 96 iBool commandEcho; /* --echo */
97 iBool retainWindowSize; 97 iBool forceSoftwareRender; /* --sw */
98 iRect initialWindowRect; 98 iRect initialWindowRect;
99 iPrefs prefs;
100#if 0
101 iBool retainWindowSize;
99 float uiScale; 102 float uiScale;
100 int zoomPercent; 103 int zoomPercent;
101 iBool forceWrap; 104 iBool forceWrap;
102 iBool forceSoftwareRender;
103 enum iColorTheme theme; 105 enum iColorTheme theme;
104 iBool useSystemTheme; 106 iBool useSystemTheme;
105 iString gopherProxy; 107 iString gopherProxy;
106 iString httpProxy; 108 iString httpProxy;
107 iString downloadDir; 109 iString downloadDir;
110#endif
108}; 111};
109 112
110static iApp app_; 113static iApp app_;
@@ -134,8 +137,8 @@ const iString *dateStr_(const iDate *date) {
134static iString *serializePrefs_App_(const iApp *d) { 137static iString *serializePrefs_App_(const iApp *d) {
135 iString *str = new_String(); 138 iString *str = new_String();
136 const iSidebarWidget *sidebar = findWidget_App("sidebar"); 139 const iSidebarWidget *sidebar = findWidget_App("sidebar");
137 appendFormat_String(str, "window.retain arg:%d\n", d->retainWindowSize); 140 appendFormat_String(str, "window.retain arg:%d\n", d->prefs.retainWindowSize);
138 if (d->retainWindowSize) { 141 if (d->prefs.retainWindowSize) {
139 int w, h, x, y; 142 int w, h, x, y;
140 SDL_GetWindowSize(d->window->win, &w, &h); 143 SDL_GetWindowSize(d->window->win, &w, &h);
141 SDL_GetWindowPosition(d->window->win, &x, &y); 144 SDL_GetWindowPosition(d->window->win, &x, &y);
@@ -153,17 +156,17 @@ static iString *serializePrefs_App_(const iApp *d) {
153 if (isVisible_Widget(sidebar)) { 156 if (isVisible_Widget(sidebar)) {
154 appendCStr_String(str, "sidebar.toggle\n"); 157 appendCStr_String(str, "sidebar.toggle\n");
155 } 158 }
156 if (d->forceWrap) { 159 if (d->prefs.forceLineWrap) {
157 appendFormat_String(str, "forcewrap.toggle\n"); 160 appendFormat_String(str, "forcewrap.toggle\n");
158 } 161 }
159 appendFormat_String(str, "sidebar.mode arg:%d\n", mode_SidebarWidget(sidebar)); 162 appendFormat_String(str, "sidebar.mode arg:%d\n", mode_SidebarWidget(sidebar));
160 appendFormat_String(str, "uiscale arg:%f\n", uiScale_Window(d->window)); 163 appendFormat_String(str, "uiscale arg:%f\n", uiScale_Window(d->window));
161 appendFormat_String(str, "zoom.set arg:%d\n", d->zoomPercent); 164 appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent);
162 appendFormat_String(str, "theme.set arg:%d auto:1\n", d->theme); 165 appendFormat_String(str, "theme.set arg:%d auto:1\n", d->prefs.theme);
163 appendFormat_String(str, "ostheme arg:%d\n", d->useSystemTheme); 166 appendFormat_String(str, "ostheme arg:%d\n", d->prefs.useSystemTheme);
164 appendFormat_String(str, "proxy.gopher address:%s\n", cstr_String(&d->gopherProxy)); 167 appendFormat_String(str, "proxy.gopher address:%s\n", cstr_String(&d->prefs.gopherProxy));
165 appendFormat_String(str, "proxy.http address:%s\n", cstr_String(&d->httpProxy)); 168 appendFormat_String(str, "proxy.http address:%s\n", cstr_String(&d->prefs.httpProxy));
166 appendFormat_String(str, "downloads path:%s\n", cstr_String(&d->downloadDir)); 169 appendFormat_String(str, "downloads path:%s\n", cstr_String(&d->prefs.downloadDir));
167 return str; 170 return str;
168} 171}
169 172
@@ -299,24 +302,18 @@ static void init_App_(iApp *d, int argc, char **argv) {
299 d->lastTickerTime = SDL_GetTicks(); 302 d->lastTickerTime = SDL_GetTicks();
300 d->elapsedSinceLastTicker = 0; 303 d->elapsedSinceLastTicker = 0;
301 d->commandEcho = checkArgument_CommandLine(&d->args, "echo") != NULL; 304 d->commandEcho = checkArgument_CommandLine(&d->args, "echo") != NULL;
305 d->forceSoftwareRender = checkArgument_CommandLine(&d->args, "sw") != NULL;
302 d->initialWindowRect = init_Rect(-1, -1, 900, 560); 306 d->initialWindowRect = init_Rect(-1, -1, 900, 560);
303 d->theme = dark_ColorTheme; 307 init_Prefs(&d->prefs);
304 d->useSystemTheme = iTrue; 308 setCStr_String(&d->prefs.downloadDir, downloadDir_App_);
305 d->running = iFalse; 309 d->running = iFalse;
306 d->window = NULL; 310 d->window = NULL;
307 d->retainWindowSize = iTrue;
308 d->pendingRefresh = iFalse; 311 d->pendingRefresh = iFalse;
309 d->zoomPercent = 100;
310 d->forceWrap = iFalse;
311 d->forceSoftwareRender = checkArgument_CommandLine(&d->args, "sw") != NULL;
312 d->certs = new_GmCerts(dataDir_App_); 312 d->certs = new_GmCerts(dataDir_App_);
313 d->visited = new_Visited(); 313 d->visited = new_Visited();
314 d->bookmarks = new_Bookmarks(); 314 d->bookmarks = new_Bookmarks();
315 d->tabEnum = 0; /* generates unique IDs for tab pages */ 315 d->tabEnum = 0; /* generates unique IDs for tab pages */
316 init_String(&d->gopherProxy); 316 setThemePalette_Color(d->prefs.theme);
317 init_String(&d->httpProxy);
318 initCStr_String(&d->downloadDir, downloadDir_App_);
319 setThemePalette_Color(d->theme);
320#if defined (iPlatformApple) 317#if defined (iPlatformApple)
321 setupApplication_MacOS(); 318 setupApplication_MacOS();
322#endif 319#endif
@@ -390,9 +387,7 @@ static void init_App_(iApp *d, int argc, char **argv) {
390static void deinit_App(iApp *d) { 387static void deinit_App(iApp *d) {
391 saveState_App_(d); 388 saveState_App_(d);
392 savePrefs_App_(d); 389 savePrefs_App_(d);
393 deinit_String(&d->downloadDir); 390 deinit_Prefs(&d->prefs);
394 deinit_String(&d->httpProxy);
395 deinit_String(&d->gopherProxy);
396 save_Bookmarks(d->bookmarks, dataDir_App_); 391 save_Bookmarks(d->bookmarks, dataDir_App_);
397 delete_Bookmarks(d->bookmarks); 392 delete_Bookmarks(d->bookmarks);
398 save_Visited(d->visited, dataDir_App_); 393 save_Visited(d->visited, dataDir_App_);
@@ -414,7 +409,7 @@ const iString *dataDir_App(void) {
414} 409}
415 410
416const iString *downloadDir_App(void) { 411const iString *downloadDir_App(void) {
417 return collect_String(cleaned_Path(&app_.downloadDir)); 412 return collect_String(cleaned_Path(&app_.prefs.downloadDir));
418} 413}
419 414
420const iString *debugInfo_App(void) { 415const iString *debugInfo_App(void) {
@@ -538,12 +533,12 @@ uint32_t elapsedSinceLastTicker_App(void) {
538 return app_.elapsedSinceLastTicker; 533 return app_.elapsedSinceLastTicker;
539} 534}
540 535
541int zoom_App(void) { 536const iPrefs *prefs_App(void) {
542 return app_.zoomPercent; 537 return &app_.prefs;
543} 538}
544 539
545iBool forceLineWrap_App(void) { 540iBool forceLineWrap_App(void) {
546 return app_.forceWrap; 541 return app_.prefs.forceLineWrap;
547} 542}
548 543
549iBool forceSoftwareRender_App(void) { 544iBool forceSoftwareRender_App(void) {
@@ -559,16 +554,16 @@ iBool forceSoftwareRender_App(void) {
559} 554}
560 555
561enum iColorTheme colorTheme_App(void) { 556enum iColorTheme colorTheme_App(void) {
562 return app_.theme; 557 return app_.prefs.theme;
563} 558}
564 559
565const iString *schemeProxy_App(iRangecc scheme) { 560const iString *schemeProxy_App(iRangecc scheme) {
566 iApp *d = &app_; 561 iApp *d = &app_;
567 if (equalCase_Rangecc(scheme, "gopher")) { 562 if (equalCase_Rangecc(scheme, "gopher")) {
568 return &d->gopherProxy; 563 return &d->prefs.gopherProxy;
569 } 564 }
570 if (equalCase_Rangecc(scheme, "http") || equalCase_Rangecc(scheme, "https")) { 565 if (equalCase_Rangecc(scheme, "http") || equalCase_Rangecc(scheme, "https")) {
571 return &d->httpProxy; 566 return &d->prefs.httpProxy;
572 } 567 }
573 return NULL; 568 return NULL;
574} 569}
@@ -801,11 +796,11 @@ static iBool handleIdentityCreationCommands_(iWidget *dlg, const char *cmd) {
801iBool handleCommand_App(const char *cmd) { 796iBool handleCommand_App(const char *cmd) {
802 iApp *d = &app_; 797 iApp *d = &app_;
803 if (equal_Command(cmd, "window.retain")) { 798 if (equal_Command(cmd, "window.retain")) {
804 d->retainWindowSize = arg_Command(cmd); 799 d->prefs.retainWindowSize = arg_Command(cmd);
805 return iTrue; 800 return iTrue;
806 } 801 }
807 else if (equal_Command(cmd, "downloads")) { 802 else if (equal_Command(cmd, "downloads")) {
808 setCStr_String(&d->downloadDir, suffixPtr_Command(cmd, "path")); 803 setCStr_String(&d->prefs.downloadDir, suffixPtr_Command(cmd, "path"));
809 return iTrue; 804 return iTrue;
810 } 805 }
811 else if (equal_Command(cmd, "open")) { 806 else if (equal_Command(cmd, "open")) {
@@ -813,8 +808,8 @@ iBool handleCommand_App(const char *cmd) {
813 iUrl parts; 808 iUrl parts;
814 init_Url(&parts, url); 809 init_Url(&parts, url);
815 if (equalCase_Rangecc(parts.scheme, "mailto") || 810 if (equalCase_Rangecc(parts.scheme, "mailto") ||
816 (isEmpty_String(&d->httpProxy) && (equalCase_Rangecc(parts.scheme, "http") || 811 (isEmpty_String(&d->prefs.httpProxy) && (equalCase_Rangecc(parts.scheme, "http") ||
817 equalCase_Rangecc(parts.scheme, "https")))) { 812 equalCase_Rangecc(parts.scheme, "https")))) {
818 openInDefaultBrowser_App(url); 813 openInDefaultBrowser_App(url);
819 return iTrue; 814 return iTrue;
820 } 815 }
@@ -905,9 +900,9 @@ iBool handleCommand_App(const char *cmd) {
905 else if (equal_Command(cmd, "preferences")) { 900 else if (equal_Command(cmd, "preferences")) {
906 iWidget *dlg = makePreferences_Widget(); 901 iWidget *dlg = makePreferences_Widget();
907 updatePrefsThemeButtons_(dlg); 902 updatePrefsThemeButtons_(dlg);
908 setText_InputWidget(findChild_Widget(dlg, "prefs.downloads"), &d->downloadDir); 903 setText_InputWidget(findChild_Widget(dlg, "prefs.downloads"), &d->prefs.downloadDir);
909 setToggle_Widget(findChild_Widget(dlg, "prefs.ostheme"), d->useSystemTheme); 904 setToggle_Widget(findChild_Widget(dlg, "prefs.ostheme"), d->prefs.useSystemTheme);
910 setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->retainWindowSize); 905 setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->prefs.retainWindowSize);
911 setText_InputWidget(findChild_Widget(dlg, "prefs.uiscale"), 906 setText_InputWidget(findChild_Widget(dlg, "prefs.uiscale"),
912 collectNewFormat_String("%g", uiScale_Window(d->window))); 907 collectNewFormat_String("%g", uiScale_Window(d->window)));
913 setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.http"), 908 setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.http"),
@@ -943,8 +938,8 @@ iBool handleCommand_App(const char *cmd) {
943 } 938 }
944 else if (equal_Command(cmd, "zoom.set")) { 939 else if (equal_Command(cmd, "zoom.set")) {
945 setFreezeDraw_Window(get_Window(), iTrue); /* no intermediate draws before docs updated */ 940 setFreezeDraw_Window(get_Window(), iTrue); /* no intermediate draws before docs updated */
946 d->zoomPercent = arg_Command(cmd); 941 d->prefs.zoomPercent = arg_Command(cmd);
947 setContentFontSize_Text((float) d->zoomPercent / 100.0f); 942 setContentFontSize_Text((float) d->prefs.zoomPercent / 100.0f);
948 postCommand_App("font.changed"); 943 postCommand_App("font.changed");
949 postCommand_App("window.unfreeze"); 944 postCommand_App("window.unfreeze");
950 return iTrue; 945 return iTrue;
@@ -952,17 +947,17 @@ iBool handleCommand_App(const char *cmd) {
952 else if (equal_Command(cmd, "zoom.delta")) { 947 else if (equal_Command(cmd, "zoom.delta")) {
953 setFreezeDraw_Window(get_Window(), iTrue); /* no intermediate draws before docs updated */ 948 setFreezeDraw_Window(get_Window(), iTrue); /* no intermediate draws before docs updated */
954 int delta = arg_Command(cmd); 949 int delta = arg_Command(cmd);
955 if (d->zoomPercent < 100 || (delta < 0 && d->zoomPercent == 100)) { 950 if (d->prefs.zoomPercent < 100 || (delta < 0 && d->prefs.zoomPercent == 100)) {
956 delta /= 2; 951 delta /= 2;
957 } 952 }
958 d->zoomPercent = iClamp(d->zoomPercent + delta, 50, 200); 953 d->prefs.zoomPercent = iClamp(d->prefs.zoomPercent + delta, 50, 200);
959 setContentFontSize_Text((float) d->zoomPercent / 100.0f); 954 setContentFontSize_Text((float) d->prefs.zoomPercent / 100.0f);
960 postCommand_App("font.changed"); 955 postCommand_App("font.changed");
961 postCommand_App("window.unfreeze"); 956 postCommand_App("window.unfreeze");
962 return iTrue; 957 return iTrue;
963 } 958 }
964 else if (equal_Command(cmd, "forcewrap.toggle")) { 959 else if (equal_Command(cmd, "forcewrap.toggle")) {
965 d->forceWrap = !d->forceWrap; 960 d->prefs.forceLineWrap = !d->prefs.forceLineWrap;
966 updateSize_DocumentWidget(document_App()); 961 updateSize_DocumentWidget(document_App());
967 return iTrue; 962 return iTrue;
968 } 963 }
@@ -1002,20 +997,20 @@ iBool handleCommand_App(const char *cmd) {
1002 } 997 }
1003 else if (equal_Command(cmd, "theme.set")) { 998 else if (equal_Command(cmd, "theme.set")) {
1004 const int isAuto = argLabel_Command(cmd, "auto"); 999 const int isAuto = argLabel_Command(cmd, "auto");
1005 d->theme = arg_Command(cmd); 1000 d->prefs.theme = arg_Command(cmd);
1006 if (!isAuto) { 1001 if (!isAuto) {
1007 postCommand_App("ostheme arg:0"); 1002 postCommand_App("ostheme arg:0");
1008 } 1003 }
1009 setThemePalette_Color(d->theme); 1004 setThemePalette_Color(d->prefs.theme);
1010 postCommandf_App("theme.changed auto:%d", isAuto); 1005 postCommandf_App("theme.changed auto:%d", isAuto);
1011 return iTrue; 1006 return iTrue;
1012 } 1007 }
1013 else if (equal_Command(cmd, "ostheme")) { 1008 else if (equal_Command(cmd, "ostheme")) {
1014 d->useSystemTheme = arg_Command(cmd); 1009 d->prefs.useSystemTheme = arg_Command(cmd);
1015 return iTrue; 1010 return iTrue;
1016 } 1011 }
1017 else if (equal_Command(cmd, "os.theme.changed")) { 1012 else if (equal_Command(cmd, "os.theme.changed")) {
1018 if (d->useSystemTheme) { 1013 if (d->prefs.useSystemTheme) {
1019 const int dark = argLabel_Command(cmd, "dark"); 1014 const int dark = argLabel_Command(cmd, "dark");
1020 const int contrast = argLabel_Command(cmd, "contrast"); 1015 const int contrast = argLabel_Command(cmd, "contrast");
1021 postCommandf_App("theme.set arg:%d auto:1", 1016 postCommandf_App("theme.set arg:%d auto:1",
@@ -1025,11 +1020,11 @@ iBool handleCommand_App(const char *cmd) {
1025 return iFalse; 1020 return iFalse;
1026 } 1021 }
1027 else if (equal_Command(cmd, "proxy.gopher")) { 1022 else if (equal_Command(cmd, "proxy.gopher")) {
1028 setCStr_String(&d->gopherProxy, suffixPtr_Command(cmd, "address")); 1023 setCStr_String(&d->prefs.gopherProxy, suffixPtr_Command(cmd, "address"));
1029 return iTrue; 1024 return iTrue;
1030 } 1025 }
1031 else if (equal_Command(cmd, "proxy.http")) { 1026 else if (equal_Command(cmd, "proxy.http")) {
1032 setCStr_String(&d->httpProxy, suffixPtr_Command(cmd, "address")); 1027 setCStr_String(&d->prefs.httpProxy, suffixPtr_Command(cmd, "address"));
1033 return iTrue; 1028 return iTrue;
1034 } 1029 }
1035 else { 1030 else {