Description
I have a prompt_toolkit application which has mouse_support=True
in its Application
call. The mouse support works fine on OS X and Linux, but nothing happens when clicking on controls when running on Windows.
I've seen various issues on here about this (#1232, #1177 and #1059) and there are various fixes proposed.
The fix in #1177 partially worked for me, but also caused other issues. This fix changes a check from checking for an object being a Win32Output
instance, to checking for either a Win32Output
or Windows10_Output
instance. Altering the code as suggested in that issue led to a few other errors being raised - one of which I think is related to the work in #1347, where the way that mouse handlers are stored is changed, and this bit of code hasn't been updated.
I think I've managed to fix it, with the code looking this in the end:
from prompt_toolkit.output.win32 import Win32Output
from prompt_toolkit.output.windows10 import Windows10_Output
if isinstance(output, Win32Output) or isinstance(output, Windows10_Output):
screen_buffer_info = output.get_win32_screen_buffer_info()
rows_above_cursor = (
screen_buffer_info.dwCursorPosition.Y - event.app.renderer._cursor_pos.y
)
y -= rows_above_cursor
# Call the mouse event handler.
handler = event.app.renderer.mouse_handlers.mouse_handlers[x, y]
handler(MouseEvent(position=Point(x=x, y=y), event_type=event_type))
I ran into a few issues where it seemed like the mouse positions weren't being reported quite correctly (possibly due to issues with the ScrollablePane?), but I can't seem to reproduce them properly - so it might not be a problem. I'd be grateful for your experienced eye over the code though.