From 71f36a90918bfe178d7f5ca0650a8a491e08d28a Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Thu, 5 Dec 2013 12:46:23 +1100 Subject: wineconsole-sb --- programs/wineconsole/curses.c | 18 ++++++++++++++++++ programs/wineconsole/user.c | 21 +++++++++++++++++++++ programs/wineconsole/winecon_private.h | 1 + programs/wineconsole/wineconsole.c | 11 +++++++++-- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/programs/wineconsole/curses.c b/programs/wineconsole/curses.c index 77d7718..f24fe28 100644 --- a/programs/wineconsole/curses.c +++ b/programs/wineconsole/curses.c @@ -241,6 +241,23 @@ sym_not_found: #define acs_map (*p_acs_map) /****************************************************************** + * WCCURSES_GetMaxConsoleWindowSize + * + * Calculates the maximum possible console window size. + */ +static COORD WCCURSES_GetMaxConsoleWindowSize(int cell_width, int cell_height) +{ + COORD c; + + getmaxyx(stdscr, c.Y, c.X); + + if (c.X < 80) c.X = 80; + if (c.Y < 25) c.Y = 25; + + return c; +} + +/****************************************************************** * WCCURSES_ResizeScreenBuffer * * @@ -1047,6 +1064,7 @@ enum init_return WCCURSES_InitBackend(struct inner_data* data) if (!data->private) return init_failed; data->fnMainLoop = WCCURSES_MainLoop; + data->fnGetMaxConsoleWindowSize = WCCURSES_GetMaxConsoleWindowSize; data->fnPosCursor = WCCURSES_PosCursor; data->fnShapeCursor = WCCURSES_ShapeCursor; data->fnComputePositions = WCCURSES_ComputePositions; diff --git a/programs/wineconsole/user.c b/programs/wineconsole/user.c index 5c8c2c0..4070b02 100644 --- a/programs/wineconsole/user.c +++ b/programs/wineconsole/user.c @@ -42,6 +42,26 @@ const COLORREF WCUSER_ColorMap[16] = static BOOL WCUSER_SetFont(struct inner_data* data, const LOGFONTW* font); /****************************************************************** + * WCUSER_GetMaxConsoleWindowSize + * + * Calculates the maximum possible console window size. + */ +static COORD WCUSER_GetMaxConsoleWindowSize(int cell_width, int cell_height) +{ + RECT workarea; + COORD c; + + SystemParametersInfoW(SPI_GETWORKAREA, 0, &workarea, 0); + c.X = ((workarea.right - workarea.left) / cell_width) - 4; + c.Y = ((workarea.bottom - workarea.top) / cell_height) - 3; + + if (c.X < 80) c.X = 80; + if (c.Y < 25) c.Y = 25; + + return c; +} + +/****************************************************************** * WCUSER_FillMemDC * * Fills the Mem DC with current cells values @@ -1419,6 +1439,7 @@ enum init_return WCUSER_InitBackend(struct inner_data* data) if (!data->private) return init_failed; data->fnMainLoop = WCUSER_MainLoop; + data->fnGetMaxConsoleWindowSize = WCUSER_GetMaxConsoleWindowSize; data->fnPosCursor = WCUSER_PosCursor; data->fnShapeCursor = WCUSER_ShapeCursor; data->fnComputePositions = WCUSER_ComputePositions; diff --git a/programs/wineconsole/winecon_private.h b/programs/wineconsole/winecon_private.h index 1daf581..c39700c 100644 --- a/programs/wineconsole/winecon_private.h +++ b/programs/wineconsole/winecon_private.h @@ -65,6 +65,7 @@ struct inner_data { BOOL dying; /* to TRUE when we've been notified by server that child has died */ int (*fnMainLoop)(struct inner_data* data); + COORD (*fnGetMaxConsoleWindowSize)(int cell_width, int cell_height); void (*fnPosCursor)(const struct inner_data* data); void (*fnShapeCursor)(struct inner_data* data, int size, int vis, BOOL force); void (*fnComputePositions)(struct inner_data* data); diff --git a/programs/wineconsole/wineconsole.c b/programs/wineconsole/wineconsole.c index 7698521..5b67103 100644 --- a/programs/wineconsole/wineconsole.c +++ b/programs/wineconsole/wineconsole.c @@ -370,6 +370,9 @@ void WINECON_GrabChanges(struct inner_data* data) */ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cfg) { + COORD maxconwin; + int window_width, window_height; + if (data->in_set_config) return; data->in_set_config = TRUE; if (data->curcfg.cursor_size != cfg->cursor_size || @@ -408,6 +411,10 @@ void WINECON_SetConfig(struct inner_data* data, const struct config_data* cf data->curcfg.def_attr = cfg->def_attr; SetConsoleTextAttribute(data->hConOut, cfg->def_attr); } + maxconwin = data->fnGetMaxConsoleWindowSize(cfg->cell_width, cfg->cell_height); + window_width = cfg->sb_width > maxconwin.X ? maxconwin.X : cfg->sb_width; + window_height = cfg->sb_height > maxconwin.Y ? maxconwin.Y : cfg->sb_height; + /* now let's look at the window / sb size changes... * since the server checks that sb is always bigger than window, * we have to take care of doing the operations in the right order @@ -426,7 +433,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,7 +448,7 @@ 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) -- 1.7.10.4