diff --git a/include/extern.h b/include/extern.h index e3e0ac152..5b0f69b8b 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2262,6 +2262,9 @@ extern int msgtype_type(const char *, boolean) NONNULLARG1; extern void hide_unhide_msgtypes(boolean, int); extern void msgtype_free(void); extern void options_free_window_colors(void); +#ifdef TTY_PERM_INVENT +extern void check_perm_invent_again(void); +#endif /* ### pager.c ### */ diff --git a/include/flag.h b/include/flag.h index 4fbfad0e7..01ad42fb0 100644 --- a/include/flag.h +++ b/include/flag.h @@ -319,6 +319,7 @@ struct instance_flags { boolean news; /* print news */ boolean num_pad; /* use numbers for movement commands */ boolean perm_invent; /* display persistent inventory window */ + boolean perm_invent_pending; /* need to try again */ boolean renameallowed; /* can change hero name during role selection */ boolean renameinprogress; /* we are changing hero name */ boolean sounds; /* master on/off switch for using soundlib */ diff --git a/include/wintype.h b/include/wintype.h index e3b38a959..095c1aa60 100644 --- a/include/wintype.h +++ b/include/wintype.h @@ -205,6 +205,7 @@ enum to_core_flags { too_small = 0x002, prohibited = 0x004, no_init_done = 0x008, + too_early = 0x010, }; enum from_core_requests { diff --git a/src/allmain.c b/src/allmain.c index 18e163b5a..0efec2ac9 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -720,6 +720,10 @@ init_sound_disp_gamewindows(void) display_nhwindow(WIN_MESSAGE, FALSE); clear_glyph_buffer(); display_nhwindow(WIN_MAP, FALSE); +#ifdef TTY_PERM_INVENT + if (iflags.perm_invent_pending) + check_perm_invent_again(); +#endif } void diff --git a/src/invent.c b/src/invent.c index 11bff7d23..4c9468366 100644 --- a/src/invent.c +++ b/src/invent.c @@ -6149,6 +6149,12 @@ sync_perminvent(void) || in_perm_invent_toggled) { wri = ctrl_nhwindow(WIN_INVEN, request_settings, &wri_info); if (wri != 0) { + if ((wri->tocore.tocore_flags & (too_early)) != 0) { + /* don't be too noisy about this as it's really + * a startup timing issue. Just set a marker. */ + iflags.perm_invent_pending = TRUE; + return; + } if ((wri->tocore.tocore_flags & (too_small | prohibited)) != 0) { /* sizes aren't good enough */ diff --git a/src/options.c b/src/options.c index b8b192fd2..805efe3d4 100644 --- a/src/options.c +++ b/src/options.c @@ -5384,7 +5384,11 @@ can_set_perm_invent(void) iflags.perminv_mode = InvOptOn; #ifdef TTY_PERM_INVENT - if (WINDOWPORT(tty) && !go.opt_initial) { + if ((WINDOWPORT(tty) +#ifdef WIN32 + || WINDOWPORT(safestartup) +#endif + ) && !go.opt_initial) { perm_invent_toggled(FALSE); /* perm_invent_toggled() -> sync_perminvent() @@ -5401,6 +5405,20 @@ can_set_perm_invent(void) return TRUE; } + +#ifdef TTY_PERM_INVENT +void +check_perm_invent_again(void) +{ + if (iflags.perm_invent_pending) { + iflags.perm_invent = FALSE; + if (can_set_perm_invent()) + iflags.perm_invent = TRUE; + iflags.perm_invent_pending = FALSE; + } +} +#endif + staticfn int handler_menustyle(void) { diff --git a/win/share/safeproc.c b/win/share/safeproc.c index aa2b3c478..efcb76097 100644 --- a/win/share/safeproc.c +++ b/win/share/safeproc.c @@ -510,13 +510,23 @@ safe_update_inventory(int arg UNUSED) return; } +#ifdef WIN32CON +extern win_request_info *tty_ctrl_nhwindow(winid window UNUSED, + int request UNUSED, + win_request_info *wri UNUSED); +#endif + win_request_info * safe_ctrl_nhwindow( winid window UNUSED, int request UNUSED, win_request_info *wri UNUSED) { +#ifdef WIN32CON + return (*tty_ctrl_nhwindow)(window, request, wri); +#else return (win_request_info *) 0; +#endif } /************************************************************** diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 207f396ac..81fc0630a 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -2861,22 +2861,29 @@ tty_ctrl_nhwindow( wri->tocore = zero_tocore; tty_ok = assesstty(ttyinvmode, &offx, &offy, &rows, &cols, &maxcol, &minrow, &maxrow); - wri->tocore.needrows = (int) (minrow + 1 + ROWNO + StatusRows()); - wri->tocore.needcols = (int) tty_perminv_mincol; - wri->tocore.haverows = (int) ttyDisplay->rows; - wri->tocore.havecols = (int) ttyDisplay->cols; - if (!tty_ok) { -#ifdef RESIZABLE - /* terminal isn't big enough right now but player might resize it - and then use 'm O' to try to set 'perm_invent' again */ - wri->tocore.tocore_flags |= too_small; -#else - wri->tocore.tocore_flags |= prohibited; -#endif + if (!tty_ok && rows == 0 && cols == 0) { + /* something is terribly wrong, possibly too early in startup */ + wri->tocore.tocore_flags |= too_early; } else { - maxslot = (maxrow - 2) * (!inuse_only ? 2 : 1); - wri->tocore.maxslot = maxslot; - } + wri->tocore.needrows = (int) (minrow + 1 + ROWNO + StatusRows()); + wri->tocore.needcols = (int) tty_perminv_mincol; + wri->tocore.haverows = (int) ttyDisplay->rows; + wri->tocore.havecols = (int) ttyDisplay->cols; + if (!tty_ok) { +#ifdef RESIZABLE + /* terminal isn't big enough right now but player might + * resize it and then use 'm O' to try to set 'perm_invent' + * again + */ + wri->tocore.tocore_flags |= too_small; +#else + wri->tocore.tocore_flags |= prohibited; +#endif + } else { + maxslot = (maxrow - 2) * (!inuse_only ? 2 : 1); + wri->tocore.maxslot = maxslot; + } + } #endif /* TTY_PERM_INVENT */ break; case set_menu_promptstyle: @@ -3542,6 +3549,14 @@ assesstty( show_gold = (invmode & InvShowGold) != 0 && !inuse_only; int perminv_minrow = tty_perminv_minrow + (show_gold ? 1 : 0); + if (!ttyDisplay) { + /* too early */ + *offx = *offy = *rows = *cols = 0; + *maxcol = 0; + *minrow = *maxrow = 0; + return !(*rows < perminv_minrow || *cols < tty_perminv_mincol); + } + *offx = 0; /* topline + map rows + status lines */ *offy = 1 + ROWNO + StatusRows(); /* 1 + 21 + (2 or 3) */