Skip to content

Commit

Permalink
Don't pass on key events when handling keybinding
Browse files Browse the repository at this point in the history
Always call the frontend's keyboard handle function so that we can
check if we are in the middle of handling a key sequence.
  • Loading branch information
sdilts committed Nov 2, 2024
1 parent d623523 commit 5bfd290
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion heart/src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void seat_handle_key(struct wl_listener *listener, void *data) {
}

// TODO: I don't know if this condition is correct
if(!handled || event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
if(!handled) {
wlr_seat_keyboard_notify_key(seat->seat, event->time_msec, event->keycode, event->state);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lisp/bindings/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
#:keysyms
#:modifiers
#:keysyms-len
#:key-state
#:wl-key-state
#:load-foreign-libraries))
29 changes: 15 additions & 14 deletions lisp/input.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
(defun execute-command (function key-sequence seat)
(funcall function key-sequence seat))

(defun check-and-run-keybinding (key seat)
(declare (type key key) (optimize speed))
(defun check-and-run-keybinding (key seat key-state)
(declare (type key key) (optimize (speed 3)))
(when (not (key-modifier-key-p key))
(let* ((key-state (mahogany-state-key-state *compositor-state*))
(handling-keybinding (key-state-active-p key-state)))
(let* ((handling-keybinding (key-state-active-p key-state)))
(log-string :trace "Already handling keybinding: ~A" handling-keybinding)
(flet ((reset-state ()
(log-string :trace "Reseting keyboard state")
Expand All @@ -30,13 +29,15 @@
(t nil)))
(log-string :trace "Keyboard state: ~A" (mahogany-state-key-state *compositor-state*)))))))

(defun handle-key-event (key seat)
(declare (type key key))
(cond
((check-and-run-keybinding key seat) t)
(t
;; TODO: add the keysym constants (or compute them at compile time)
;; in xkb library
(when (eql 65307 (key-keysym key))
(server-stop *compositor-state*)
t))))
(defun handle-key-event (key seat event-state)
(declare (type key key)
(type bit event-state)
(optimize(speed 3)))
(let ((key-state (mahogany-state-key-state *compositor-state*)))
(declare (type key-state key-state))
(if (= event-state 1)
(or (check-and-run-keybinding key seat key-state)
(when (eql 65307 (key-keysym key))
(server-stop *compositor-state*)
t))
(key-state-active-p key-state))))
7 changes: 5 additions & 2 deletions lisp/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
(cffi:defcallback keyboard-callback :bool
((seat (:pointer (:struct hrt:hrt-seat)))
(info (:pointer (:struct hrt:hrt-keypress-info))))
(cffi:with-foreign-slots ((hrt:keysyms hrt:modifiers hrt:keysyms-len) info (:struct hrt:hrt-keypress-info))
(cffi:with-foreign-slots ((hrt:keysyms hrt:modifiers hrt:keysyms-len hrt:wl-key-state)
info (:struct hrt:hrt-keypress-info))
;; I'm not sure why this is an array, but it's what tinywl does:
(dotimes (i hrt:keysyms-len)
(let ((key (make-key (cffi:mem-aref hrt:keysyms :uint32 i) hrt:modifiers)))
(handle-key-event key seat)))))
(when (handle-key-event key seat hrt:wl-key-state)
(return t))))))

(defmacro init-callback-struct (variable type &body sets)
(let ((vars (mapcar #'car sets)))
Expand Down

0 comments on commit 5bfd290

Please sign in to comment.