summaryrefslogtreecommitdiff
path: root/src/app.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-14 14:09:59 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-14 14:09:59 +0300
commitc2dd6107db2ff4b8001085068f4c1c5971cdd9c3 (patch)
treef4dc684dae9611abf1f672c853de44c8911db8fd /src/app.c
parentbf390e96735a156cb221385cc057aeb957c088b9 (diff)
Cleaner window initialization
Create the window using the correct size and position, and don’t show the window contents while app state is being restored.
Diffstat (limited to 'src/app.c')
-rw-r--r--src/app.c74
1 files changed, 42 insertions, 32 deletions
diff --git a/src/app.c b/src/app.c
index cbd2b114..bdd345f7 100644
--- a/src/app.c
+++ b/src/app.c
@@ -55,19 +55,20 @@ static const char *stateFileName_App_ = "state.bin";
55 55
56struct Impl_App { 56struct Impl_App {
57 iCommandLine args; 57 iCommandLine args;
58 iBool commandEcho; /* --echo */
59 iBool running;
60 iWindow * window;
61 iSortedArray tickers;
62 iBool pendingRefresh;
63 iGmCerts * certs; 58 iGmCerts * certs;
64 iVisited * visited; 59 iVisited * visited;
65 iBookmarks * bookmarks; 60 iBookmarks * bookmarks;
66 int zoomPercent; 61 iWindow * window;
62 iSortedArray tickers;
63 iBool running;
64 iBool pendingRefresh;
67 int tabEnum; 65 int tabEnum;
68 /* Preferences: */ 66 /* Preferences: */
67 iBool commandEcho; /* --echo */
69 iBool retainWindowSize; 68 iBool retainWindowSize;
69 iRect initialWindowRect;
70 float uiScale; 70 float uiScale;
71 int zoomPercent;
71}; 72};
72 73
73static iApp app_; 74static iApp app_;
@@ -101,9 +102,10 @@ static iString *serializePrefs_App_(const iApp *d) {
101 int w, h, x, y; 102 int w, h, x, y;
102 SDL_GetWindowSize(d->window->win, &w, &h); 103 SDL_GetWindowSize(d->window->win, &w, &h);
103 SDL_GetWindowPosition(d->window->win, &x, &y); 104 SDL_GetWindowPosition(d->window->win, &x, &y);
104 appendFormat_String(str, "restorewindow width:%d height:%d coord:%d %d\n", w, h, x, y); 105 appendFormat_String(str, "window.setrect width:%d height:%d coord:%d %d\n", w, h, x, y);
105 appendFormat_String(str, "sidebar.width arg:%d\n", width_SidebarWidget(sidebar)); 106 appendFormat_String(str, "sidebar.width arg:%d\n", width_SidebarWidget(sidebar));
106 } 107 }
108 appendFormat_String(str, "retainwindow arg:%d\n", d->retainWindowSize);
107 if (isVisible_Widget(constAs_Widget(sidebar))) { 109 if (isVisible_Widget(constAs_Widget(sidebar))) {
108 appendCStr_String(str, "sidebar.toggle\n"); 110 appendCStr_String(str, "sidebar.toggle\n");
109 } 111 }
@@ -127,16 +129,22 @@ static void loadPrefs_App_(iApp *d) {
127 const iRangecc src = range_String(str); 129 const iRangecc src = range_String(str);
128 iRangecc line = iNullRange; 130 iRangecc line = iNullRange;
129 while (nextSplit_Rangecc(&src, "\n", &line)) { 131 while (nextSplit_Rangecc(&src, "\n", &line)) {
130 iString cmd; 132 iString cmdStr;
131 initRange_String(&cmd, line); 133 initRange_String(&cmdStr, line);
132 if (equal_Command(cstr_String(&cmd), "uiscale")) { 134 const char *cmd = cstr_String(&cmdStr);
133 /* Must be handled before the window is created. */ 135 /* Window init commands must be handled before the window is created. */
134 setUiScale_Window(get_Window(), argf_Command(cstr_String(&cmd))); 136 if (equal_Command(cmd, "uiscale")) {
137 setUiScale_Window(get_Window(), argf_Command(cmd));
138 }
139 else if (equal_Command(cmd, "window.setrect")) {
140 const iInt2 pos = coord_Command(cmd);
141 d->initialWindowRect = init_Rect(
142 pos.x, pos.y, argLabel_Command(cmd, "width"), argLabel_Command(cmd, "height"));
135 } 143 }
136 else { 144 else {
137 postCommandString_App(&cmd); 145 postCommandString_App(&cmdStr);
138 } 146 }
139 deinit_String(&cmd); 147 deinit_String(&cmdStr);
140 } 148 }
141 delete_String(str); 149 delete_String(str);
142 } 150 }
@@ -221,16 +229,17 @@ static void saveState_App_(const iApp *d) {
221static void init_App_(iApp *d, int argc, char **argv) { 229static void init_App_(iApp *d, int argc, char **argv) {
222 init_CommandLine(&d->args, argc, argv); 230 init_CommandLine(&d->args, argc, argv);
223 init_SortedArray(&d->tickers, sizeof(iTicker), cmp_Ticker_); 231 init_SortedArray(&d->tickers, sizeof(iTicker), cmp_Ticker_);
224 d->commandEcho = checkArgument_CommandLine(&d->args, "echo") != NULL; 232 d->commandEcho = checkArgument_CommandLine(&d->args, "echo") != NULL;
225 d->running = iFalse; 233 d->initialWindowRect = init_Rect(-1, -1, 800, 500);
226 d->window = NULL; 234 d->running = iFalse;
227 d->retainWindowSize = iTrue; 235 d->window = NULL;
228 d->pendingRefresh = iFalse; 236 d->retainWindowSize = iTrue;
229 d->zoomPercent = 100; 237 d->pendingRefresh = iFalse;
230 d->certs = new_GmCerts(dataDir_App_); 238 d->zoomPercent = 100;
231 d->visited = new_Visited(); 239 d->certs = new_GmCerts(dataDir_App_);
232 d->bookmarks = new_Bookmarks(); 240 d->visited = new_Visited();
233 d->tabEnum = 0; 241 d->bookmarks = new_Bookmarks();
242 d->tabEnum = 0; /* generates unique IDs for tab pages */
234 loadPrefs_App_(d); 243 loadPrefs_App_(d);
235 load_Visited(d->visited, dataDir_App_); 244 load_Visited(d->visited, dataDir_App_);
236 load_Bookmarks(d->bookmarks, dataDir_App_); 245 load_Bookmarks(d->bookmarks, dataDir_App_);
@@ -244,11 +253,12 @@ static void init_App_(iApp *d, int argc, char **argv) {
244 } 253 }
245 } 254 }
246#endif 255#endif
247 d->window = new_Window(); 256 d->window = new_Window(d->initialWindowRect);
248 /* Widget state init. */ 257 /* Widget state init. */
249 if (!loadState_App_(d)) { 258 if (!loadState_App_(d)) {
250 postCommand_App("navigate.home"); 259 postCommand_App("navigate.home");
251 } 260 }
261 postCommand_App("window.unblank");
252} 262}
253 263
254static void deinit_App(iApp *d) { 264static void deinit_App(iApp *d) {
@@ -423,6 +433,8 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) {
423 if (equal_Command(cmd, "prefs.dismiss") || equal_Command(cmd, "preferences")) { 433 if (equal_Command(cmd, "prefs.dismiss") || equal_Command(cmd, "preferences")) {
424 setUiScale_Window(get_Window(), 434 setUiScale_Window(get_Window(),
425 toFloat_String(text_InputWidget(findChild_Widget(d, "prefs.uiscale")))); 435 toFloat_String(text_InputWidget(findChild_Widget(d, "prefs.uiscale"))));
436 postCommandf_App("retainwindow arg:%d",
437 isSelected_Widget(findChild_Widget(d, "prefs.retainwindow")));
426 destroy_Widget(d); 438 destroy_Widget(d);
427 return iTrue; 439 return iTrue;
428 } 440 }
@@ -472,7 +484,11 @@ iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf) {
472 484
473iBool handleCommand_App(const char *cmd) { 485iBool handleCommand_App(const char *cmd) {
474 iApp *d = &app_; 486 iApp *d = &app_;
475 if (equal_Command(cmd, "open")) { 487 if (equal_Command(cmd, "retainwindow")) {
488 d->retainWindowSize = arg_Command(cmd);
489 return iTrue;
490 }
491 else if (equal_Command(cmd, "open")) {
476 const iString *url = collect_String(newCStr_String(suffixPtr_Command(cmd, "url"))); 492 const iString *url = collect_String(newCStr_String(suffixPtr_Command(cmd, "url")));
477 iUrl parts; 493 iUrl parts;
478 init_Url(&parts, url); 494 init_Url(&parts, url);
@@ -569,12 +585,6 @@ iBool handleCommand_App(const char *cmd) {
569 collectNewFormat_String("%g", uiScale_Window(d->window))); 585 collectNewFormat_String("%g", uiScale_Window(d->window)));
570 setCommandHandler_Widget(dlg, handlePrefsCommands_); 586 setCommandHandler_Widget(dlg, handlePrefsCommands_);
571 } 587 }
572 else if (equal_Command(cmd, "restorewindow")) {
573 d->retainWindowSize = iTrue;
574 resize_Window(d->window, argLabel_Command(cmd, "width"), argLabel_Command(cmd, "height"));
575 const iInt2 pos = coord_Command(cmd);
576 SDL_SetWindowPosition(d->window->win, pos.x, pos.y);
577 }
578 else if (equal_Command(cmd, "navigate.home")) { 588 else if (equal_Command(cmd, "navigate.home")) {
579 postCommand_App("open url:about:home"); 589 postCommand_App("open url:about:home");
580 return iTrue; 590 return iTrue;