Skip to content

Commit

Permalink
Make callback struct initizliation less verbose
Browse files Browse the repository at this point in the history
+ Add and use init-callback-struct macro.
  • Loading branch information
sdilts committed Oct 28, 2023
1 parent 5945ee9 commit f7afa6d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lisp/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,26 @@
#+ccl
(set-fpu-mode :overflow nil))

(defmacro init-callback-struct (variable type &body sets)
(let ((vars (mapcar #'car sets)))
`(cffi:with-foreign-slots (,vars ,variable ,type)
(setf ,@(loop for pair in sets
append (list (car pair) `(cffi:callback ,(cadr pair))))))))

(defun run-server ()
(disable-fpu-exceptions)
(hrt:load-foreign-libraries)
(log-init :level :trace)
(cffi:with-foreign-objects ((output-callbacks '(:struct hrt-output-callbacks))
(seat-callbacks '(:struct hrt-seat-callbacks))
(server '(:struct hrt-server)))
(cffi:with-foreign-slots ((output-added output-removed)
output-callbacks (:struct hrt-output-callbacks))
(setf output-added (cffi:callback output-callback)
output-removed (cffi:callback output-callback)))
(cffi:with-foreign-slots ((button-event wheel-event keyboard-keypress-event)
seat-callbacks (:struct hrt-seat-callbacks))
(setf button-event (cffi:callback cursor-callback)
wheel-event (cffi:callback cursor-callback)
keyboard-keypress-event (cffi:callback keyboard-callback)))
(init-callback-struct output-callbacks (:struct hrt-output-callbacks)
(output-added output-callback)
(output-removed output-callback))
(init-callback-struct seat-callbacks (:struct hrt-seat-callbacks)
(button-event cursor-callback)
(wheel-event cursor-callback)
(keyboard-keypress-event keyboard-callback))
(setf (mahogany-state-server *compositor-state*) server)
(log-string :debug "Initialized mahogany state")
(hrt-server-init server output-callbacks seat-callbacks 3)
Expand Down

0 comments on commit f7afa6d

Please sign in to comment.