vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.4k stars 67 forks source link

Escape can close multiple windows. #70

Closed Gleefre closed 10 months ago

Gleefre commented 1 year ago

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: https://github.com/libsdl-org/SDL/issues/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.