From 6f8e61786c1c1175c3c5badde13bae92ff5364b8 Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Tue, 22 Oct 2013 17:52:49 +1100 Subject: wineconsole --- programs/wineconsole/wineconsole.c | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/programs/wineconsole/wineconsole.c b/programs/wineconsole/wineconsole.c index 7698521..9ff5dbc 100644 --- a/programs/wineconsole/wineconsole.c +++ b/programs/wineconsole/wineconsole.c @@ -23,6 +23,11 @@ #include #include + +#ifdef HAVE_SYS_IOCTL_H +#include +#endif + #include "wine/server.h" #include "winecon_private.h" #include "winnls.h" @@ -32,6 +37,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(wineconsole); +static BOOL user_backend = TRUE; + void WINECON_Fatal(const char* msg) { WINE_ERR("%s\n", msg); @@ -95,8 +102,6 @@ void WINECON_ResizeWithContainer(struct inner_data* data, int width, int height) if (data->in_set_config) return; cfg = data->curcfg; - cfg.win_width = width; - cfg.win_height = height; /* auto size screen-buffer if it's now smaller than window */ if (cfg.sb_width < cfg.win_width) cfg.sb_width = cfg.win_width; @@ -110,6 +115,36 @@ void WINECON_ResizeWithContainer(struct inner_data* data, int width, int height) } /****************************************************************** + * WINECON_SetMaxWindowSize + * + * + */ +static COORD WINECON_SetMaxWindowSize(int font_width, int font_height) +{ + COORD c; + + if (user_backend) /* --backend=user or not specified */ + { + RECT workarea; + SystemParametersInfoW(SPI_GETWORKAREA, 0, &workarea, 0); + c.X = (workarea.right / font_width) - 4; + c.Y = (workarea.bottom / font_height) - 3; + } + else /* --backend=curses */ + { + struct winsize w; + ioctl(0, TIOCGWINSZ, &w); + c.X = w.ws_col; + c.Y = w.ws_row; + } + + if (c.X < 80) c.X = 80; + if (c.Y < 25) c.Y = 25; + + return c; +} + +/****************************************************************** * WINECON_SetHistorySize * * @@ -370,6 +405,9 @@ void WINECON_GrabChanges(struct inner_data* data) */ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cfg) { + COORD max_window; + int window_width, window_height; + if (data->in_set_config) return; data->in_set_config = TRUE; if (data->curcfg.cursor_size != cfg->cursor_size || @@ -399,8 +437,9 @@ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cf } data->curcfg.menu_mask = cfg->menu_mask; data->curcfg.quick_edit = cfg->quick_edit; - if (1 /* FIXME: font info has changed */) + if (data->curcfg.cell_width != cfg->cell_width || data->curcfg.cell_height != cfg->cell_height) { + max_window = WINECON_SetMaxWindowSize(cfg->cell_width, cfg->cell_height); data->fnSetFont(data, cfg->face_name, cfg->cell_height, cfg->font_weight); } if (data->curcfg.def_attr != cfg->def_attr) @@ -426,7 +465,7 @@ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cf } while (0) #define ChgWinHPos() do {pos.Left = cfg->win_pos.X - data->curcfg.win_pos.X; \ pos.Top = 0; \ - pos.Right = pos.Left + cfg->win_width - data->curcfg.win_width; \ + pos.Right = pos.Left + window_width - data->curcfg.win_width; \ pos.Bottom = 0; \ SetConsoleWindowInfo(data->hConOut, FALSE, &pos);\ } while (0) @@ -441,10 +480,14 @@ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cf #define ChgWinVPos() do {pos.Left = 0; \ pos.Top = cfg->win_pos.Y - data->curcfg.win_pos.Y; \ pos.Right = 0; \ - pos.Bottom = pos.Top + cfg->win_height - data->curcfg.win_height; \ + pos.Bottom = pos.Top + window_height - data->curcfg.win_height; \ SetConsoleWindowInfo(data->hConOut, FALSE, &pos);\ } while (0) + max_window = WINECON_SetMaxWindowSize(cfg->cell_width, cfg->cell_height); + window_width = cfg->sb_width > max_window.X ? max_window.X : cfg->sb_width; + window_height = cfg->sb_height > max_window.Y ? max_window.Y : cfg->sb_height; + do { COORD c; @@ -776,6 +819,7 @@ static UINT WINECON_ParseOptions(const char* lpCmdLine, struct wc_init* wci) { wci->backend = WCCURSES_InitBackend; wci->ptr += 16; + user_backend = FALSE; } else return IDS_CMD_INVALID_BACKEND; -- 1.7.10.4