diff --git a/installer/gui.py b/installer/gui.py index 16f6e6b2..0d9fbd16 100644 --- a/installer/gui.py +++ b/installer/gui.py @@ -54,6 +54,7 @@ class App: self.vars['lang'] = tk.StringVar() self.lang_code = default_game_language(ui_lang) self.screen = None + self.fitted = None # the (width, height) fit last gave the window root.title(self.cat('ui.title')) icon = layout.runtime / 'totk.ico' @@ -144,12 +145,16 @@ class App: def fit(self): """Size the window to its largest screen (an unpacked frame still reports the size its children ask for), so a screen or language switch neither cuts text nor moves the buttons. The window only grows: opening the log - makes it taller, and a size the user dragged it to stays.""" + makes it taller, and a size the user dragged it to stays. Every text change that can add lines calls it again, + or pack takes the missing height from the button bars.""" self.root.update_idletasks() sizes = [(f.winfo_reqwidth(), f.winfo_reqheight()) for f in self.frames.values()] chrome = self.root.winfo_reqheight() - self.body.winfo_reqheight() # the title row above the body w = max(self.root.winfo_reqwidth(), max(s[0] for s in sizes) + 2 * PAD) h = chrome + max(s[1] for s in sizes) + 2 * PAD + if (w, h) == self.fitted: # refresh_run calls it on every poll: leave the window alone while nothing grew + return + self.fitted = (w, h) self.root.minsize(w, h) self.root.geometry(f'{max(w, self.root.winfo_width())}x{max(h, self.root.winfo_height())}') @@ -160,6 +165,10 @@ class App: def build_form(self): f = ttk.Frame(self.body) + bar = ttk.Frame(f) # packed first so pack shrinks the text above it, never the buttons + bar.pack(side='bottom', fill='x', pady=(12, 0)) + self.start_button = self.button(bar, 'ui.start', self.start) + self.start_button.pack(side='right') self.form_intro = self.label(f, 'ui.intro', wraplength=620, justify='left') self.form_intro.pack(anchor='w', pady=(0, 8)) self.notice(f).pack(fill='x', pady=(0, 10)) @@ -191,14 +200,16 @@ class App: self.form_error = ttk.Label(f, style='Err.TLabel', wraplength=620, justify='left') self.form_error.pack(anchor='w', pady=(8, 0)) self.label(f, 'ui.keys_private', wraplength=620, justify='left').pack(anchor='w', pady=(8, 0)) - bar = ttk.Frame(f) - bar.pack(side='bottom', fill='x', pady=(12, 0)) - self.start_button = self.button(bar, 'ui.start', self.start) - self.start_button.pack(side='right') return f def build_run(self): f = ttk.Frame(self.body) + bar = ttk.Frame(f) + bar.pack(side='bottom', fill='x', pady=(8, 0)) + self.cancel_button = self.button(bar, 'ui.cancel', self.cancel) + self.cancel_button.pack(side='right') + self.log_toggle = self.button(bar, 'ui.show_log', self.toggle_log) + self.log_toggle.pack(side='left') self.run_header = ttk.Label(f, font=('Segoe UI', 11, 'bold')) self.run_header.pack(anchor='w') self.step_rows = {} @@ -212,12 +223,6 @@ class App: self.space_label.pack(anchor='w') self.warn_label = ttk.Label(f, wraplength=620, justify='left', foreground='#9a6700') self.warn_label.pack(anchor='w') - bar = ttk.Frame(f) - bar.pack(side='bottom', fill='x', pady=(8, 0)) - self.cancel_button = self.button(bar, 'ui.cancel', self.cancel) - self.cancel_button.pack(side='right') - self.log_toggle = self.button(bar, 'ui.show_log', self.toggle_log) - self.log_toggle.pack(side='left') self.log_frame = ttk.Frame(f) self.log = tk.Text(self.log_frame, height=10, wrap='word', state='disabled', font=('Consolas', 9)) scroll = ttk.Scrollbar(self.log_frame, command=self.log.yview) @@ -229,6 +234,13 @@ class App: def build_finish(self): f = ttk.Frame(self.body) + bar = ttk.Frame(f) + bar.pack(side='bottom', fill='x', pady=(12, 0)) + self.button(bar, 'ui.close', self.on_close).pack(side='right') + self.open_button = self.button(bar, 'ui.open_folder', self.open_folder) + self.open_button.pack(side='right', padx=(0, 8)) + self.back_button = self.button(bar, 'ui.back', lambda: self.show('form')) + self.back_button.pack(side='left') self.finish_title = ttk.Label(f, style='Title.TLabel', wraplength=620, justify='left') self.finish_title.pack(anchor='w') self.finish_text = ttk.Label(f, wraplength=620, justify='left') @@ -237,13 +249,6 @@ class App: self.finish_steps.pack(fill='x', pady=(0, 8)) self.finish_notice = self.notice(f) self.finish_notice.pack(fill='x', pady=(8, 0)) - bar = ttk.Frame(f) - bar.pack(side='bottom', fill='x', pady=(12, 0)) - self.button(bar, 'ui.close', self.on_close).pack(side='right') - self.open_button = self.button(bar, 'ui.open_folder', self.open_folder) - self.open_button.pack(side='right', padx=(0, 8)) - self.back_button = self.button(bar, 'ui.back', lambda: self.show('form')) - self.back_button.pack(side='left') return f # ---- form ----------------------------------------------------------------------------------------------------- @@ -261,6 +266,7 @@ class App: self.vars['lang'].set(self.lang_label(state['lang'])) else: self.update_hint.configure(text='') + self.fit() def pick_file(self, name, pick_id): types = [(self.cat('ui.type_game'), '*.nsp *.xci'), (self.cat('ui.type_all'), '*.*')] @@ -284,6 +290,7 @@ class App: problems = form.problems() if problems: self.form_error.configure(text=' '.join(self.cat(p) for p in problems)) + self.fit() return self.form_error.configure(text='') command = form.command(self.layout.python, root=self.layout.root if self.layout.dev else None, @@ -386,6 +393,7 @@ class App: self.bar.configure(value=frac * 1000) self.space_label.configure(text=m.need_text(self.cat)) self.warn_label.configure(text='\n'.join(self.cat(i, **p) for i, p in m.warnings)) + self.fit() # new step rows and warnings make the screen taller def toggle_log(self): self.log_open = not self.log_open diff --git a/runtime/cfg.h b/runtime/cfg.h index 7d641216..c0c5dd55 100644 --- a/runtime/cfg.h +++ b/runtime/cfg.h @@ -6,7 +6,7 @@ // is kept). A name without the TOTK_ prefix goes to getenv unchanged. Safe from any thread once cfg_init has returned. const char *cfg_get(const char *name); -// Reads totk.ini once, first thing in main. Logs the file, its key count, unknown keys and environment overrides. +// Reads totk.ini once, from mem_init after the address space is claimed and before any setting is read. Logs the file, its key count, unknown keys and environment overrides. void cfg_init(void); // Replaces the loaded keys with those of the file at path (tests). 1 when the file was read, 0 when missing. diff --git a/runtime/main.c b/runtime/main.c index 2a8b61dd..0c743345 100644 --- a/runtime/main.c +++ b/runtime/main.c @@ -427,10 +427,9 @@ static void portable_paths(RtConfig *c) { } int main(int argc, char **argv) { - mem_init(); // first: claim the guest address space before anything else can land there + mem_init(); // first: claim the guest address space before anything else can land there; reads totk.ini setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); - cfg_init(); // before any setting is read AddVectoredExceptionHandler(0, crash_handler); parse_trace(); prof_start(); diff --git a/runtime/memory.c b/runtime/memory.c index 9c718dea..0af559d7 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -275,6 +275,9 @@ void mem_init(void) { AddVectoredExceptionHandler(1, thaw_handler); // before the crash handler alias_pages = VirtualAlloc(NULL, ALIAS_PAGES, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (!alias_pages) rt_fatal("memory: cannot allocate the alias page map"); + // totk.ini is read here, once the address space is claimed and before the first setting: the pool size below + // depends on TOTK_APP_POOL and on the resolution settings (resolution.c decides them once, on this first call). + cfg_init(); const char *pool = cfg_get("TOTK_APP_POOL"); L = (RtGuestLayout){ .aslr = {low, RT_ADDRESS_LIMIT - low},