vydd/sketch

Escape can close multiple windows.

Gleefre opened this issue · 0 comments

Default behaviour

By default sketch will close a window on a :keydown escape event:

;;; Default events

(defmethod kit.sdl2:keyboard-event :before ((instance sketch) state timestamp repeatp keysym)
  (declare (ignorable timestamp repeatp))
  (when (and (eql state :keydown)
             (sdl2:scancode= (sdl2:scancode-value keysym) :scancode-escape))
    (kit.sdl2:close-window instance)))

Problem

OS: Linux (ubuntu)
SDL version: 2.0.10

Create two windows, move one behind another. Put the mouse to the intersection of two windows.
On escape both are closed!

It seems that SDL is sending an extra :keydown event for all pressed keys when window regains focus.
When the first window closes, the second one is gaining focus, gets an additional :keydown event and closes.

Relevant discussions

Probably this issue on github is relevant: libsdl-org/SDL#4432

Solution?

An easy solution could be to move closing to a :keyup event, so that there is no additional :keydown event for the second window.