Skip to content

Commit

Permalink
Make closing on esc configurable (#153)
Browse files Browse the repository at this point in the history
* Make closing on esc configurable

* Use CLOSE-ON to set the scancode for closing the window

Defaults to esc.

* Exports close-on and sketch-close-on
  • Loading branch information
vydd authored Jan 28, 2024
1 parent 8053de2 commit 37baf60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
:sketch-resizable
:sketch-copy-pixels
:sketch-y-axis
:sketch-close-on

:title
:width
Expand All @@ -31,6 +32,7 @@
:resizable
:copy-pixels
:y-axis
:close-on

:*default-width*
:*default-height*
Expand Down
11 changes: 6 additions & 5 deletions src/sketch.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
(fullscreen :initform nil :accessor sketch-fullscreen :initarg :fullscreen)
(resizable :initform nil :accessor sketch-resizable :initarg :resizable)
(copy-pixels :initform nil :accessor sketch-copy-pixels :initarg :copy-pixels)
(y-axis :initform :down :accessor sketch-y-axis :initarg :y-axis)))
(y-axis :initform :down :accessor sketch-y-axis :initarg :y-axis)
(close-on :initform :scancode-escape :accessor sketch-close-on :initarg :close-on)))

(defclass sketch-window (kit.sdl2:gl-window)
((%sketch
Expand Down Expand Up @@ -250,11 +251,11 @@

;;; Default events

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

(defmethod close-window :before ((instance sketch-window))
(with-environment (slot-value (%sketch instance) '%env)
Expand Down

0 comments on commit 37baf60

Please sign in to comment.