This MR serves as prerequistes for two open (in progress) MR:
https://gitlab.winehq.org/wine/wine/-/merge_requests/7586 - we don't properly handle ctrl-c in ReadConsole with control block + this revisits ctrl-break (or ctrl-break from unix console) to map it unconditionnaly of console mode (as native does) to a windows ctrl event + and transfer to windows layers the management of ctrl-c (for a unix console when ENABLE_PROCESSED_INPUT isn't set)
https://gitlab.winehq.org/wine/wine/-/merge_requests/7843 - add ASC in win32 edit mode to completely clear the current editi buffer
From: Eric Pouech epouech@codeweavers.com
Signed-off-by: Eric Pouech epouech@codeweavers.com --- programs/conhost/conhost.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c index 708696100d0..2b53aa102c8 100644 --- a/programs/conhost/conhost.c +++ b/programs/conhost/conhost.c @@ -943,6 +943,13 @@ static void edit_line_kill_prefix( struct console *console ) } }
+static void edit_line_clear( struct console *console ) +{ + struct edit_line *ctx = &console->edit_line; + edit_line_delete( console, 0, ctx->len ); + ctx->cursor = 0; +} + static void edit_line_kill_marked_zone( struct console *console ) { struct edit_line *ctx = &console->edit_line; @@ -1138,6 +1145,7 @@ static const struct edit_line_key_entry win32_std_key_map[] = { VK_DOWN, edit_line_move_to_next_hist }, { VK_INSERT, edit_line_toggle_insert }, { VK_F8, edit_line_find_in_history }, + { VK_ESCAPE, edit_line_clear }, { 0 } };
From: Eric Pouech epouech@codeweavers.com
ENABLE_PROCESSED_INPUT only applies to ctrl-c handling.
Signed-off-by: Eric Pouech epouech@codeweavers.com --- programs/conhost/conhost.c | 41 +++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c index 2b53aa102c8..5a543bb291d 100644 --- a/programs/conhost/conhost.c +++ b/programs/conhost/conhost.c @@ -1476,7 +1476,8 @@ static BOOL map_to_ctrlevent( struct console *console, const INPUT_RECORD *recor { if (record->EventType == KEY_EVENT) { - if (record->Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 && + if ((console->mode & ENABLE_PROCESSED_INPUT) && + record->Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 && !(record->Event.KeyEvent.dwControlKeyState & ENHANCED_KEY)) { *event = CTRL_C_EVENT; @@ -1498,6 +1499,8 @@ static BOOL map_to_ctrlevent( struct console *console, const INPUT_RECORD *recor NTSTATUS write_console_input( struct console *console, const INPUT_RECORD *records, unsigned int count, BOOL flush ) { + unsigned int i; + TRACE( "%u\n", count );
if (!count) return STATUS_SUCCESS; @@ -1510,35 +1513,27 @@ NTSTATUS write_console_input( struct console *console, const INPUT_RECORD *recor console->record_size = console->record_size * 2 + count; }
- if (console->mode & ENABLE_PROCESSED_INPUT) + for (i = 0; i < count; i++) { - unsigned int i; - for (i = 0; i < count; i++) - { - unsigned int event; + unsigned int event;
- if (map_to_ctrlevent( console, &records[i], &event )) + if (map_to_ctrlevent( console, &records[i], &event )) + { + if (records[i].Event.KeyEvent.bKeyDown) { - if (records[i].Event.KeyEvent.bKeyDown) - { - struct condrv_ctrl_event ctrl_event; - IO_STATUS_BLOCK io; + struct condrv_ctrl_event ctrl_event; + IO_STATUS_BLOCK io;
- ctrl_event.event = event; - ctrl_event.group_id = 0; - NtDeviceIoControlFile( console->server, NULL, NULL, NULL, &io, IOCTL_CONDRV_CTRL_EVENT, - &ctrl_event, sizeof(ctrl_event), NULL, 0 ); - } + ctrl_event.event = event; + ctrl_event.group_id = 0; + NtDeviceIoControlFile( console->server, NULL, NULL, NULL, &io, IOCTL_CONDRV_CTRL_EVENT, + &ctrl_event, sizeof(ctrl_event), NULL, 0 ); } - else - console->records[console->record_count++] = records[i]; } + else + console->records[console->record_count++] = records[i]; } - else - { - memcpy( console->records + console->record_count, records, count * sizeof(INPUT_RECORD) ); - console->record_count += count; - } + return flush ? process_console_input( console ) : STATUS_SUCCESS; }
From: Eric Pouech epouech@codeweavers.com
For a unix console, don't kill console directly when not in ENABLE_PROCESSED_INPUT mode.
This will allow proper handling of ctrl-c as a control character in ReadConsoleW with a control block,
Note: this patch can change behavior of a unix console (depending on console mode and how attached programs behave against a ctrl-c event).
If the unix console is not in ENABLE_PROCESSED_INPUT mode, ctrl-c will no longer kill immediately the console, but rather now generates a ctrl-c event to all applications attached to the console (or be handled in ReadConsole with a control context). This could mean that the application can also block its termination with a proper handler. If that's the case, the console won't be closed.
As a reminder, ctrl-\ is still a valid way to terminate all applications attached to a unix console whatever the console mode.
Signed-off-by: Eric Pouech epouech@codeweavers.com --- programs/conhost/conhost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c index 5a543bb291d..89c030e86c8 100644 --- a/programs/conhost/conhost.c +++ b/programs/conhost/conhost.c @@ -1768,7 +1768,7 @@ static DWORD WINAPI tty_input( void *param ) switch (ch) { case 3: /* end of text */ - if (console->is_unix && (console->mode & ENABLE_PROCESSED_INPUT)) + if (console->is_unix) { key_press( console, ch, 'C', LEFT_CTRL_PRESSED ); break;
This merge request was approved by Jacek Caban.