Skip to content

Commit

Permalink
Merge pull request #1719 from SequentialDesign/turn-right-gui-modifie…
Browse files Browse the repository at this point in the history
…r-into-hyper-modifier-in-sdl2-version

turn right gui mod into the hyper modifier in sdl2 version
  • Loading branch information
cxxxr authored Dec 30, 2024
2 parents c180db2 + 9a4962b commit 4499b6c
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions frontends/sdl2/keyboard.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,22 @@
(values (string (code-char code))
t)))))

(defun make-key (&key ctrl meta shift super sym)
(defun make-key (&key ctrl meta shift super hyper sym)
(when (equal sym (string #\yen_sign))
(setf sym "\\"))
(lem:make-key :ctrl ctrl
:meta meta
:super super
:hyper hyper
:shift shift
:sym sym))

(defstruct modifier
shift
ctrl
meta
super)
super
hyper)

(defstruct (key-event (:constructor %make-key-event))
code
Expand All @@ -81,7 +83,8 @@
`((:shift ,sdl2-ffi:+kmod-lshift+ ,sdl2-ffi:+kmod-rshift+)
(:ctrl ,sdl2-ffi:+kmod-lctrl+ ,sdl2-ffi:+kmod-rctrl+)
(:meta ,sdl2-ffi:+kmod-lalt+ ,sdl2-ffi:+kmod-ralt+)
(:super ,sdl2-ffi:+kmod-lgui+ ,sdl2-ffi:+kmod-rgui+)))
(:super ,sdl2-ffi:+kmod-lgui+)
(:hyper ,sdl2-ffi:+kmod-rgui+)))

(defun mod-p (mod mod-type)
(some (lambda (value)
Expand All @@ -93,14 +96,16 @@
(shift (mod-p mod :shift))
(ctrl (mod-p mod :ctrl))
(meta (mod-p mod :meta))
(super (mod-p mod :super)))
(make-modifier :shift shift :ctrl ctrl :meta meta :super super)))
(super (mod-p mod :super))
(hyper (mod-p mod :hyper)))
(make-modifier :shift shift :ctrl ctrl :meta meta :super super :hyper hyper)))

(defun update-modifier (modifier new-modifier)
(setf (modifier-shift modifier) (modifier-shift new-modifier))
(setf (modifier-ctrl modifier) (modifier-ctrl new-modifier))
(setf (modifier-meta modifier) (modifier-meta new-modifier))
(setf (modifier-super modifier) (modifier-super new-modifier)))
(setf (modifier-super modifier) (modifier-super new-modifier))
(setf (modifier-hyper modifier) (modifier-hyper new-modifier)))

(defvar *modifier* (make-modifier))
(defvar *textediting-text* "")
Expand Down Expand Up @@ -133,6 +138,7 @@
(let ((key (lem:make-key :ctrl (modifier-ctrl *modifier*)
:meta (modifier-meta *modifier*)
:super (modifier-super *modifier*)
:hyper (modifier-hyper *modifier*)
:shift nil
:sym sym)))
(when text-input-p
Expand All @@ -151,6 +157,7 @@
:ctrl (modifier-ctrl modifier)
:meta (modifier-meta modifier)
:super (modifier-super modifier)
:hyper (modifier-hyper modifier)
:sym sym)))
(send-key-event key))))))

Expand Down Expand Up @@ -223,7 +230,7 @@
(values (cdr elt) t)
(values char nil)))))

(defun make-key-with-shift-careful (&key shift ctrl meta super sym)
(defun make-key-with-shift-careful (&key shift ctrl meta super hyper sym)
(or (and (= 1 (length sym))
shift
(multiple-value-bind (char shift-p)
Expand All @@ -232,22 +239,26 @@
(make-key :ctrl ctrl
:meta meta
:super super
:hyper hyper
:shift nil
:sym (string char)))))
(make-key :ctrl ctrl
:meta meta
:super super
:hyper hyper
:shift shift
:sym sym)))

(defun handle-text-input-internal (text)
(unless (or (modifier-super *modifier*)
(unless (or (modifier-hyper *modifier*)
(modifier-super *modifier*)
(modifier-meta *modifier*)
(modifier-ctrl *modifier*))
(loop :for c :across text
:do (let ((key (make-key :ctrl (modifier-ctrl *modifier*)
:meta (modifier-meta *modifier*)
:super (modifier-super *modifier*)
:hyper (modifier-hyper *modifier*)
:shift nil
:sym (convert-to-sym (char-code c)))))
(send-key-event key)))))
Expand All @@ -263,11 +274,13 @@
(modifier-ctrl modifier)
(modifier-meta modifier)
(modifier-super modifier)
(modifier-hyper modifier)
(< 256 code)))
(let ((key (make-key-with-shift-careful :shift (modifier-shift modifier)
:ctrl (modifier-ctrl modifier)
:meta (modifier-meta modifier)
:super (modifier-super modifier)
:hyper (modifier-hyper modifier)
:sym sym)))
(send-key-event key)))))))

Expand Down

0 comments on commit 4499b6c

Please sign in to comment.