Skip to content

Windows: Mouse input may stop working due to console mode handling in enable_application_mode() #6295

@pkellyuk

Description

@pkellyuk

Summary

I've been investigating an issue where mouse input stops working in Textual apps on Windows. I think I may have found something in enable_application_mode(), but I'm not entirely sure - would appreciate someone more familiar with the Windows console handling taking a look.

What I'm Seeing

Mouse selection and scrollbar interaction stop working shortly after a Textual app starts on Windows. The console mode flags for mouse input seem to get lost.

Where I Think the Issue Might Be

Looking at src/textual/drivers/win32.py in enable_application_mode():

set_console_mode(
    terminal_out, current_console_mode_out | ENABLE_VIRTUAL_TERMINAL_PROCESSING
)
set_console_mode(terminal_in, ENABLE_VIRTUAL_TERMINAL_INPUT)

I noticed that for stdout, existing flags are preserved with |, but for stdin it seems to just set ENABLE_VIRTUAL_TERMINAL_INPUT directly?

If I'm reading this correctly, wouldn't this overwrite any existing flags like ENABLE_MOUSE_INPUT (0x0010) and ENABLE_EXTENDED_FLAGS (0x0080)?

Possible Fix (if my analysis is correct)

Maybe the stdin line should be:

set_console_mode(terminal_in, current_console_mode_in | ENABLE_VIRTUAL_TERMINAL_INPUT)

Similar to how stdout is handled?

Reproduction

I've been testing with a stress test that monitors console mode flags. The corruption happens consistently within ~150ms on Windows 11.

Environment

  • Windows 11
  • Windows Terminal
  • Textual (latest)

I could be completely wrong about this - just trying to help track down the issue. Let me know if you need any more information!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions