diff --git a/heart/src/keyboard.c b/heart/src/keyboard.c index 1917aae..8f57bb2 100644 --- a/heart/src/keyboard.c +++ b/heart/src/keyboard.c @@ -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); } } diff --git a/lisp/bindings/package.lisp b/lisp/bindings/package.lisp index 1c1cdd2..5b997e1 100644 --- a/lisp/bindings/package.lisp +++ b/lisp/bindings/package.lisp @@ -41,5 +41,5 @@ #:keysyms #:modifiers #:keysyms-len - #:key-state + #:wl-key-state #:load-foreign-libraries)) diff --git a/lisp/input.lisp b/lisp/input.lisp index 9ea453b..b44a1cd 100644 --- a/lisp/input.lisp +++ b/lisp/input.lisp @@ -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") @@ -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)))) diff --git a/lisp/main.lisp b/lisp/main.lisp index 65fa28a..d39f54a 100644 --- a/lisp/main.lisp +++ b/lisp/main.lisp @@ -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)))