From: Hugh McMaster hugh.mcmaster@outlook.com
On Windows, application-specific settings are stored in the registry under HKCU\Console<app_name>.
Our implementation of conhost.exe does not know which process is connected to it, so we need to get the full process image name before loading any application-specific console settings. --- programs/conhost/conhost.c | 7 ++-- programs/conhost/conhost.h | 2 ++ programs/conhost/window.c | 71 ++++++++++++++++++++++---------------- 3 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c index c3a106c9321..227f3f76aef 100644 --- a/programs/conhost/conhost.c +++ b/programs/conhost/conhost.c @@ -2716,7 +2716,7 @@ static NTSTATUS console_input_ioctl( struct console *console, unsigned int code, static NTSTATUS process_console_ioctls( struct console *console ) { size_t out_size = 0, in_size; - unsigned int code; + unsigned int code, pid; int output; NTSTATUS status = STATUS_SUCCESS;
@@ -2734,6 +2734,7 @@ static NTSTATUS process_console_ioctls( struct console *console ) wine_server_set_reply( req, ioctl_buffer, ioctl_buffer_size ); status = wine_server_call( req ); code = reply->code; + pid = reply->pid; output = reply->output; out_size = reply->out_size; in_size = wine_server_reply_size( reply ); @@ -2753,6 +2754,9 @@ static NTSTATUS process_console_ioctls( struct console *console ) return status; }
+ if (!console->init && pid) + init_window_config( console, pid ); + if (code == IOCTL_CONDRV_INIT_OUTPUT) { TRACE( "initializing output %x\n", output ); @@ -2947,7 +2951,6 @@ int __cdecl wmain(int argc, WCHAR *argv[]) if (!init_window( &console )) return 1; GetStartupInfoW( &si ); set_console_title( &console, si.lpTitle, wcslen( si.lpTitle ) * sizeof(WCHAR) ); - ShowWindow( console.win, (si.dwFlags & STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOW ); }
return main_loop( &console, signal ); diff --git a/programs/conhost/conhost.h b/programs/conhost/conhost.h index 4464f51032f..e99fafa3f8e 100644 --- a/programs/conhost/conhost.h +++ b/programs/conhost/conhost.h @@ -75,6 +75,7 @@ struct edit_line struct console { HANDLE server; /* console server handle */ + BOOL init; /* TRUE if console has initialized */ unsigned int mode; /* input mode */ struct screen_buffer *active; /* active screen buffer */ int is_unix; /* UNIX terminal mode */ @@ -145,6 +146,7 @@ NTSTATUS change_screen_buffer_size( struct screen_buffer *screen_buffer, int new void update_console_font( struct console *console, const WCHAR *face_name, size_t face_name_size, unsigned int height, unsigned int weight ); BOOL init_window( struct console *console ); +void init_window_config( struct console *console, unsigned int pid ); void init_message_window( struct console *console ); void update_window_region( struct console *console, const RECT *update ); void update_window_config( struct console *console, BOOL delay ); diff --git a/programs/conhost/window.c b/programs/conhost/window.c index 3db4b159696..ce421eace0a 100644 --- a/programs/conhost/window.c +++ b/programs/conhost/window.c @@ -2392,33 +2392,32 @@ void update_window_region( struct console *console, const RECT *update ) update_window_config( console, TRUE ); }
-BOOL init_window( struct console *console ) +void init_window_config( struct console *console, unsigned int pid) { + DWORD len, i; + HANDLE h; + WCHAR buf[256]; struct console_config config; - WNDCLASSW wndclass; STARTUPINFOW si; - CHARSETINFO ci;
- static struct console_window console_window; + console->init = TRUE;
- console->window = &console_window; - if (!TranslateCharsetInfo( (DWORD *)(INT_PTR)GetACP(), &ci, TCI_SRCCODEPAGE )) - return FALSE; + if (!console->window || console->no_window) return;
- console->window->ui_charset = ci.ciCharset; + len = ARRAY_SIZE( buf ); + h = OpenProcess( PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid ); + QueryFullProcessImageNameW( h, 0, buf, &len ); + CloseHandle(h);
- GetStartupInfoW(&si); - if (si.lpTitle) - { - size_t i, title_len = wcslen( si.lpTitle ); - if (!(console->window->config_key = malloc( (title_len + 1) * sizeof(WCHAR) ))) - return FALSE; - for (i = 0; i < title_len; i++) - console->window->config_key[i] = si.lpTitle[i] == '\' ? '_' : si.lpTitle[i]; - console->window->config_key[title_len] = 0; - } + console->window->config_key = malloc( (len + 1) * sizeof(WCHAR) ); + + for (i = 0; i < len; i++) + console->window->config_key[i] = buf[i] == '\' ? '_' : buf[i]; + console->window->config_key[len] = 0;
load_config( console->window->config_key, &config ); + + GetStartupInfoW( &si ); if (si.dwFlags & STARTF_USECOUNTCHARS) { config.sb_width = si.dwXCountChars; @@ -2427,6 +2426,27 @@ BOOL init_window( struct console *console ) if (si.dwFlags & STARTF_USEFILLATTRIBUTE) config.attr = si.dwFillAttribute;
+ if (!config.face_name[0]) + set_first_font( console, &config ); + + apply_config( console, &config ); + + ShowWindow( console->win, (si.dwFlags & STARTF_USESHOWWINDOW) ? si.wShowWindow : SW_SHOW ); +} + +BOOL init_window( struct console *console ) +{ + WNDCLASSW wndclass; + CHARSETINFO ci; + + static struct console_window console_window; + + console->window = &console_window; + if (!TranslateCharsetInfo( (DWORD *)(INT_PTR)GetACP(), &ci, TCI_SRCCODEPAGE )) + return FALSE; + + console->window->ui_charset = ci.ciCharset; + wndclass.style = CS_DBLCLKS; wndclass.lpfnWndProc = window_proc; wndclass.cbClsExtra = 0; @@ -2439,17 +2459,10 @@ BOOL init_window( struct console *console ) wndclass.lpszClassName = L"WineConsoleClass"; RegisterClassW(&wndclass);
- if (!CreateWindowW( wndclass.lpszClassName, NULL, - WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX| - WS_MAXIMIZEBOX|WS_HSCROLL|WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, - 0, 0, 0, 0, wndclass.hInstance, console )) - return FALSE; - - if (!config.face_name[0]) - set_first_font( console, &config ); - - apply_config( console, &config ); - return TRUE; + return !!CreateWindowW( wndclass.lpszClassName, NULL, + WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX| + WS_MAXIMIZEBOX|WS_HSCROLL|WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, + 0, 0, 0, 0, wndclass.hInstance, console ); }
void init_message_window( struct console *console )