summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app.c34
-rw-r--r--src/app.h1
-rw-r--r--src/gmrequest.c2
-rw-r--r--src/ui/documentwidget.c40
-rw-r--r--src/ui/sidebarwidget.c1
-rw-r--r--src/ui/window.c3
6 files changed, 40 insertions, 41 deletions
diff --git a/src/app.c b/src/app.c
index 12f3393c..488e7b42 100644
--- a/src/app.c
+++ b/src/app.c
@@ -53,12 +53,14 @@ static const char *stateFileName_App_ = "state.bin";
53 53
54struct Impl_App { 54struct Impl_App {
55 iCommandLine args; 55 iCommandLine args;
56 iBool commandEcho; /* --echo */
56 iBool running; 57 iBool running;
57 iWindow * window; 58 iWindow * window;
58 iSortedArray tickers; 59 iSortedArray tickers;
59 iBool pendingRefresh; 60 iBool pendingRefresh;
60 iGmCerts * certs; 61 iGmCerts * certs;
61 iVisited * visited; 62 iVisited * visited;
63 int zoomPercent;
62 int tabEnum; 64 int tabEnum;
63 /* Preferences: */ 65 /* Preferences: */
64 iBool retainWindowSize; 66 iBool retainWindowSize;
@@ -104,6 +106,7 @@ static iString *serializePrefs_App_(const iApp *d) {
104 } 106 }
105 appendFormat_String(str, "sidebar.mode arg:%d\n", mode_SidebarWidget(sidebar)); 107 appendFormat_String(str, "sidebar.mode arg:%d\n", mode_SidebarWidget(sidebar));
106 appendFormat_String(str, "uiscale arg:%f\n", uiScale_Window(d->window)); 108 appendFormat_String(str, "uiscale arg:%f\n", uiScale_Window(d->window));
109 appendFormat_String(str, "zoom.set arg:%d\n", d->zoomPercent);
107 return str; 110 return str;
108} 111}
109 112
@@ -214,10 +217,12 @@ static void saveState_App_(const iApp *d) {
214static void init_App_(iApp *d, int argc, char **argv) { 217static void init_App_(iApp *d, int argc, char **argv) {
215 init_CommandLine(&d->args, argc, argv); 218 init_CommandLine(&d->args, argc, argv);
216 init_SortedArray(&d->tickers, sizeof(iTicker), cmp_Ticker_); 219 init_SortedArray(&d->tickers, sizeof(iTicker), cmp_Ticker_);
220 d->commandEcho = checkArgument_CommandLine(&d->args, "echo") != NULL;
217 d->running = iFalse; 221 d->running = iFalse;
218 d->window = NULL; 222 d->window = NULL;
219 d->retainWindowSize = iTrue; 223 d->retainWindowSize = iTrue;
220 d->pendingRefresh = iFalse; 224 d->pendingRefresh = iFalse;
225 d->zoomPercent = 100;
221 d->certs = new_GmCerts(dataDir_App_); 226 d->certs = new_GmCerts(dataDir_App_);
222 d->visited = new_Visited(); 227 d->visited = new_Visited();
223 d->tabEnum = 0; 228 d->tabEnum = 0;
@@ -336,6 +341,10 @@ iBool isRefreshPending_App(void) {
336 return app_.pendingRefresh; 341 return app_.pendingRefresh;
337} 342}
338 343
344int zoom_App(void) {
345 return app_.zoomPercent;
346}
347
339int run_App(int argc, char **argv) { 348int run_App(int argc, char **argv) {
340 init_App_(&app_, argc, argv); 349 init_App_(&app_, argc, argv);
341 const int rc = run_App_(&app_); 350 const int rc = run_App_(&app_);
@@ -365,9 +374,9 @@ void postCommand_App(const char *command) {
365 ev.user.data1 = strdup(command); 374 ev.user.data1 = strdup(command);
366 ev.user.data2 = NULL; 375 ev.user.data2 = NULL;
367 SDL_PushEvent(&ev); 376 SDL_PushEvent(&ev);
368#if !defined (NDEBUG) 377 if (app_.commandEcho) {
369 printf("[command] %s\n", command); fflush(stdout); 378 printf("[command] %s\n", command); fflush(stdout);
370#endif 379 }
371} 380}
372 381
373void postCommandf_App(const char *command, ...) { 382void postCommandf_App(const char *command, ...) {
@@ -542,11 +551,10 @@ iBool handleCommand_App(const char *cmd) {
542 SDL_PushEvent(&ev); 551 SDL_PushEvent(&ev);
543 } 552 }
544 else if (equal_Command(cmd, "preferences")) { 553 else if (equal_Command(cmd, "preferences")) {
545 iWindow *win = get_Window();
546 iWidget *dlg = makePreferences_Widget(); 554 iWidget *dlg = makePreferences_Widget();
547 setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->retainWindowSize); 555 setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->retainWindowSize);
548 setText_InputWidget(findChild_Widget(dlg, "prefs.uiscale"), 556 setText_InputWidget(findChild_Widget(dlg, "prefs.uiscale"),
549 collectNewFormat_String("%g", uiScale_Window(get_Window()))); 557 collectNewFormat_String("%g", uiScale_Window(d->window)));
550 setCommandHandler_Widget(dlg, handlePrefsCommands_); 558 setCommandHandler_Widget(dlg, handlePrefsCommands_);
551 } 559 }
552 else if (equal_Command(cmd, "restorewindow")) { 560 else if (equal_Command(cmd, "restorewindow")) {
@@ -559,8 +567,20 @@ iBool handleCommand_App(const char *cmd) {
559 postCommand_App("open url:about:home"); 567 postCommand_App("open url:about:home");
560 return iTrue; 568 return iTrue;
561 } 569 }
562 else if (equal_Command(cmd, "font.setfactor")) { 570 else if (equal_Command(cmd, "zoom.set")) {
563 setContentFontSize_Text((float) arg_Command(cmd) / 100.0f); 571 d->zoomPercent = arg_Command(cmd);
572 setContentFontSize_Text((float) d->zoomPercent / 100.0f);
573 postCommand_App("font.changed");
574 refresh_App();
575 return iTrue;
576 }
577 else if (equal_Command(cmd, "zoom.delta")) {
578 int delta = arg_Command(cmd);
579 if (d->zoomPercent < 100 || (delta < 0 && d->zoomPercent == 100)) {
580 delta /= 2;
581 }
582 d->zoomPercent = iClamp(d->zoomPercent + delta, 50, 200);
583 setContentFontSize_Text((float) d->zoomPercent / 100.0f);
564 postCommand_App("font.changed"); 584 postCommand_App("font.changed");
565 refresh_App(); 585 refresh_App();
566 return iTrue; 586 return iTrue;
diff --git a/src/app.h b/src/app.h
index 12c636ba..cf68fb5f 100644
--- a/src/app.h
+++ b/src/app.h
@@ -28,6 +28,7 @@ void processEvents_App (enum iAppEventMode mode);
28iBool handleCommand_App (const char *cmd); 28iBool handleCommand_App (const char *cmd);
29void refresh_App (void); 29void refresh_App (void);
30iBool isRefreshPending_App(void); 30iBool isRefreshPending_App(void);
31int zoom_App (void);
31 32
32iGmCerts * certs_App (void); 33iGmCerts * certs_App (void);
33iVisited * visited_App (void); 34iVisited * visited_App (void);
diff --git a/src/gmrequest.c b/src/gmrequest.c
index ce7a3522..996c77ea 100644
--- a/src/gmrequest.c
+++ b/src/gmrequest.c
@@ -287,7 +287,7 @@ void submit_GmRequest(iGmRequest *d) {
287" d\" YD d\" YD\n" 287" d\" YD d\" YD\n"
288" \"Y88888P' \"Y88888P'\n" 288" \"Y88888P' \"Y88888P'\n"
289"```\n" 289"```\n"
290"# A Beautiful Gemini Browser\n" 290"# A Beautiful Gemini Client\n"
291"## Version " LAGRANGE_APP_VERSION "\n\n" 291"## Version " LAGRANGE_APP_VERSION "\n\n"
292"=> https://skyjake.fi/@jk by Jaakko Keränen <code@iki.fi>\n" 292"=> https://skyjake.fi/@jk by Jaakko Keränen <code@iki.fi>\n"
293"Crafted with \u2615 in Finland\n"); 293"Crafted with \u2615 in Finland\n");
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 11b92e63..ff1c577a 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -76,13 +76,11 @@ struct Impl_Model {
76 /* state that persists across sessions */ 76 /* state that persists across sessions */
77 iHistory *history; 77 iHistory *history;
78 iString * url; 78 iString * url;
79 int textSizePercent;
80}; 79};
81 80
82void init_Model(iModel *d) { 81void init_Model(iModel *d) {
83 d->history = new_History(); 82 d->history = new_History();
84 d->url = new_String(); 83 d->url = new_String();
85 d->textSizePercent = 100;
86} 84}
87 85
88void deinit_Model(iModel *d) { 86void deinit_Model(iModel *d) {
@@ -92,13 +90,13 @@ void deinit_Model(iModel *d) {
92 90
93void serialize_Model(const iModel *d, iStream *outs) { 91void serialize_Model(const iModel *d, iStream *outs) {
94 serialize_String(d->url, outs); 92 serialize_String(d->url, outs);
95 write16_Stream(outs, d->textSizePercent); 93 write16_Stream(outs, 0 /*d->zoomPercent*/);
96 serialize_History(d->history, outs); 94 serialize_History(d->history, outs);
97} 95}
98 96
99void deserialize_Model(iModel *d, iStream *ins) { 97void deserialize_Model(iModel *d, iStream *ins) {
100 deserialize_String(d->url, ins); 98 deserialize_String(d->url, ins);
101 d->textSizePercent = read16_Stream(ins); 99 /*d->zoomPercent =*/ read16_Stream(ins);
102 deserialize_History(d->history, ins); 100 deserialize_History(d->history, ins);
103} 101}
104 102
@@ -204,7 +202,7 @@ static int documentWidth_DocumentWidget_(const iDocumentWidget *d) {
204 const iWidget *w = constAs_Widget(d); 202 const iWidget *w = constAs_Widget(d);
205 const iRect bounds = bounds_Widget(w); 203 const iRect bounds = bounds_Widget(w);
206 return iMini(bounds.size.x - gap_UI * d->pageMargin * 2, 204 return iMini(bounds.size.x - gap_UI * d->pageMargin * 2,
207 fontSize_UI * 38 * d->mod.textSizePercent / 100); /* TODO: Add user preference .*/ 205 fontSize_UI * 38 * zoom_App() / 100); /* TODO: Add user preference .*/
208} 206}
209 207
210static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) { 208static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) {
@@ -559,7 +557,7 @@ static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) {
559 const iGmResponse *resp = recent->cachedResponse; 557 const iGmResponse *resp = recent->cachedResponse;
560 d->state = fetching_RequestState; 558 d->state = fetching_RequestState;
561 /* Use the cached response data. */ 559 /* Use the cached response data. */
562 d->scrollY = d->initialScrollY = recent->scrollY; 560 d->scrollY = d->initialScrollY = recent->scrollY * gap_UI;
563 updateTrust_DocumentWidget_(d, resp); 561 updateTrust_DocumentWidget_(d, resp);
564 updateDocument_DocumentWidget_(d, resp); 562 updateDocument_DocumentWidget_(d, resp);
565 d->state = ready_RequestState; 563 d->state = ready_RequestState;
@@ -602,9 +600,8 @@ void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBoo
602iDocumentWidget *duplicate_DocumentWidget(const iDocumentWidget *orig) { 600iDocumentWidget *duplicate_DocumentWidget(const iDocumentWidget *orig) {
603 iDocumentWidget *d = new_DocumentWidget(); 601 iDocumentWidget *d = new_DocumentWidget();
604 delete_History(d->mod.history); 602 delete_History(d->mod.history);
605 d->mod.textSizePercent = orig->mod.textSizePercent; 603 d->initialScrollY = orig->scrollY;
606 d->initialScrollY = orig->scrollY; 604 d->mod.history = copy_History(orig->mod.history);
607 d->mod.history = copy_History(orig->mod.history);
608 setUrlFromCache_DocumentWidget(d, orig->mod.url, iTrue); 605 setUrlFromCache_DocumentWidget(d, orig->mod.url, iTrue);
609 return d; 606 return d;
610} 607}
@@ -811,20 +808,6 @@ static iBool handleMediaCommand_DocumentWidget_(iDocumentWidget *d, const char *
811 return iFalse; 808 return iFalse;
812} 809}
813 810
814static void changeTextSize_DocumentWidget_(iDocumentWidget *d, int delta) {
815 if (delta == 0) {
816 d->mod.textSizePercent = 100;
817 }
818 else {
819 if (d->mod.textSizePercent < 100 || (delta < 0 && d->mod.textSizePercent == 100)) {
820 delta /= 2;
821 }
822 d->mod.textSizePercent += delta;
823 d->mod.textSizePercent = iClamp(d->mod.textSizePercent, 50, 200);
824 }
825 postCommandf_App("font.setfactor arg:%d", d->mod.textSizePercent);
826}
827
828void updateSize_DocumentWidget(iDocumentWidget *d) { 811void updateSize_DocumentWidget(iDocumentWidget *d) {
829 setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d)); 812 setWidth_GmDocument(d->doc, documentWidth_DocumentWidget_(d));
830 updateVisible_DocumentWidget_(d); 813 updateVisible_DocumentWidget_(d);
@@ -1070,15 +1053,6 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1070 case ' ': 1053 case ' ':
1071 postCommand_Widget(w, "scroll.page arg:%d", key == SDLK_PAGEUP ? -1 : +1); 1054 postCommand_Widget(w, "scroll.page arg:%d", key == SDLK_PAGEUP ? -1 : +1);
1072 return iTrue; 1055 return iTrue;
1073 case SDLK_MINUS:
1074 case SDLK_EQUALS:
1075 case SDLK_0:
1076 if (mods == KMOD_PRIMARY) {
1077 changeTextSize_DocumentWidget_(
1078 d, key == SDLK_EQUALS ? 10 : key == SDLK_MINUS ? -10 : 0);
1079 return iTrue;
1080 }
1081 break;
1082 case SDLK_9: { 1056 case SDLK_9: {
1083 iBlock *seed = new_Block(64); 1057 iBlock *seed = new_Block(64);
1084 for (size_t i = 0; i < 64; ++i) { 1058 for (size_t i = 0; i < 64; ++i) {
@@ -1107,7 +1081,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1107 scroll_DocumentWidget_(d, -ev->wheel.y * get_Window()->pixelRatio); 1081 scroll_DocumentWidget_(d, -ev->wheel.y * get_Window()->pixelRatio);
1108#else 1082#else
1109 if (keyMods_Sym(SDL_GetModState()) == KMOD_PRIMARY) { 1083 if (keyMods_Sym(SDL_GetModState()) == KMOD_PRIMARY) {
1110 changeTextSize_DocumentWidget_(d, ev->wheel.y > 0 ? 10 : -10); 1084 postCommandf_App("zoom.delta arg:%d", ev->wheel.y > 0 ? 10 : -10);
1111 return iTrue; 1085 return iTrue;
1112 } 1086 }
1113 scroll_DocumentWidget_(d, -3 * ev->wheel.y * lineHeight_Text(default_FontId)); 1087 scroll_DocumentWidget_(d, -3 * ev->wheel.y * lineHeight_Text(default_FontId));
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index a5e0e4ee..ca10f0da 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -333,6 +333,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
333 return iTrue; 333 return iTrue;
334 } 334 }
335 else if (equal_Command(cmd, "tabs.changed") || equal_Command(cmd, "document.changed")) { 335 else if (equal_Command(cmd, "tabs.changed") || equal_Command(cmd, "document.changed")) {
336 d->scrollY = 0;
336 updateItems_SidebarWidget_(d); 337 updateItems_SidebarWidget_(d);
337 } 338 }
338 } 339 }
diff --git a/src/ui/window.c b/src/ui/window.c
index 599044aa..9c1b9bbe 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -74,6 +74,9 @@ static const iMenuItem navMenuItems[] = {
74 { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" }, 74 { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" },
75 { "---", 0, 0, NULL }, 75 { "---", 0, 0, NULL },
76 { "Toggle Sidebar", SDLK_s, KMOD_PRIMARY | KMOD_ALT, "sidebar.toggle" }, 76 { "Toggle Sidebar", SDLK_s, KMOD_PRIMARY | KMOD_ALT, "sidebar.toggle" },
77 { "Zoom In", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" },
78 { "Zoom Out", SDLK_MINUS, KMOD_PRIMARY, "zoom.delta arg:-10" },
79 { "Reset Zoom", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" },
77 { "---", 0, 0, NULL }, 80 { "---", 0, 0, NULL },
78 { "Preferences...", SDLK_COMMA, KMOD_PRIMARY, "preferences" }, 81 { "Preferences...", SDLK_COMMA, KMOD_PRIMARY, "preferences" },
79 { "---", 0, 0, NULL }, 82 { "---", 0, 0, NULL },