cmang / durdraw

Versatile ASCII and ANSI Art text editor for drawing in the Linux/Unix/macOS terminal, with animation, 256 and 16 colors, Unicode and CP437, and customizable themes
http://durdraw.org
BSD 3-Clause "New" or "Revised" License
709 stars 20 forks source link

Draw/Color/Erase: Mouse button can get stuck held down #17

Open cmang opened 10 months ago

cmang commented 10 months ago

There is an annoying bug with the mouse button getting stuck.

To reproduce: 1: Go into a mode where you can click and hold down to do something, like Draw, Erase or Color. 2: Click down on the mouse somewhere in the canvas, and drag the mouse cursor outside of your terminal window. 3: Let go of the mouse button while the cursor is outside of the terminal. 4: Move the mouse cursor back into the terminal window.

Durdraw will still think the mouse button is held down. You can reset this with a single click or double click, usually, and avoid the issue completely by avoiding dragging the cursor outside of the window with the mouse button held down.

This has to do with the (probably dumb) way that Durdraw interacts with Ncurses' mouse functions in /durdraw/durdraw_ui_curses.py, and stores the mouse state.

Here is a link to the appropriate section in a commit, in the monster mainLoop() method: https://github.com/cmang/durdraw/blob/32e601901477cf6ba25accb7cb09b3dffa5348ba/durdraw/durdraw_ui_curses.py#L1917C37-L1917C37

Any help would be appreciated!

cmang commented 8 months ago

If you find this bug annoying, 625c8c8 makes it so that pressing Esc (command-mode) or any esc-command un-sticks the mouse, to try to help with this issue.

Just a bit more detail... ncurses receives a mouse event when you press down the button, and when you release the button. Durdraw stores this state as a bool member variable called pressingButton (see durdraw_ui_curses.py if you dare).

If you release the button outside of the Xterm window, Durdraw never gets the mouse released event. Annoying. The ncurses mouse state does not seem to distinguish between dragging with the mouse button down, and dragging with it released.

Have any ncurses gurus found a workaround for this problem in implementing mouse click-dragging?