From 558c57029bfbfeddd91ebffd053008d89d70252a Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Sun, 23 Oct 2016 04:50:04 +0100 Subject: [PATCH] This is a working copy post-that-bug-which-caused-drm-not-to-exit. I think it was either some cache issue or the fact that I had the incf-pointer function (now update-pointer). ulubis.lisp now has two main loops depending on backend (this will come out in the future hopefully) and uses osicat instead of the sb-posix stuff. However it is currently using nix:poll (see https://github.com/osicat/osicat/pull/17) which has not yet been accepted but I want to commit stuff at least locally at the moment. Next step is to see if I can remove the callbacks from the functions in plumbing (I was half way there when the bug cropped up) which will hopefully allow ulubis to run on ccl as well --- build/build-ulubis-drm-gbm.lisp | 7 +-- build/build-ulubis-sdl.lisp | 6 +- install.lisp | 10 +++ ulubis.asd | 11 +++- ulubis.lisp | 107 +++++++++++++++++++++++++++++--- 5 files changed, 122 insertions(+), 19 deletions(-) create mode 100644 install.lisp diff --git a/build/build-ulubis-drm-gbm.lisp b/build/build-ulubis-drm-gbm.lisp index 29f3f5a..ebd841d 100644 --- a/build/build-ulubis-drm-gbm.lisp +++ b/build/build-ulubis-drm-gbm.lisp @@ -1,8 +1,7 @@ -(ql:quickload :ulubis) (ql:quickload :ulubis-drm-gbm) -(sb-ext:save-lisp-and-die "ulubis" - :executable t - :toplevel #'ulubis::run-compositor) +(format t "Building ulubis with DRM backend~%") + +(trivial-dump-core:save-executable "ulubis" #'ulubis::run-compositor) (quit) diff --git a/build/build-ulubis-sdl.lisp b/build/build-ulubis-sdl.lisp index bbee229..876e63d 100644 --- a/build/build-ulubis-sdl.lisp +++ b/build/build-ulubis-sdl.lisp @@ -1,8 +1,6 @@ -(ql:quickload :ulubis) (ql:quickload :ulubis-sdl) -(sb-ext:save-lisp-and-die "ulubis-sdl" - :executable t - :toplevel #'ulubis::run-compositor) +(trivial-dump-core:save-executable "ulubis-sdl" #'ulubis::run-compositor) (quit) + diff --git a/install.lisp b/install.lisp new file mode 100644 index 0000000..62c8e5f --- /dev/null +++ b/install.lisp @@ -0,0 +1,10 @@ + +(in-package :ulubis) + +(defun build (&optional path) + (let ((ulubis-path (namestring (ql:where-is-system :ulubis)))) + (load (concatenate 'string ulubis-path "build/build-ulubis-drm-gbm.lisp")))) + +(defun build-sdl (&optional path) + (let ((ulubis-path (namestring (ql:where-is-system :ulubis)))) + (load (concatenate 'string ulubis-path "build/build-ulubis-sdl.lisp")))) diff --git a/ulubis.asd b/ulubis.asd index 5044fd2..686c724 100644 --- a/ulubis.asd +++ b/ulubis.asd @@ -5,11 +5,14 @@ :author "Malcolm Still" :license "BSD 3-Clause" :depends-on (#:cffi + #:osicat #:swank #:cepl #:easing #:cl-xkb - #:cl-wayland) + #:cl-wayland + #:trivial-dump-core + #:uiop) :serial t :components ((:file "backend") (:file "animation") @@ -21,6 +24,10 @@ (:file "default-mode") (:file "alt-tab-mode") ;;(:file "backend-sdl/backend-sdl") + ;; #-ccl (:file "plumbing") - (:file "ulubis"))) + ;;#+ccl + ;;(:file "plumbing-unwrapped") + (:file "ulubis") + (:file "install"))) diff --git a/ulubis.lisp b/ulubis.lisp index 484c288..60f1dfb 100644 --- a/ulubis.lisp +++ b/ulubis.lisp @@ -3,7 +3,61 @@ (defparameter *compositor* nil) -(defun main-loop (event-loop) +#| +Smooth animation with +(defun main-loop-drm (event-loop) + (let ((wayland-fd (wl-event-loop-get-fd event-loop)) + (backend-fd (get-fd (backend *compositor*)))) + (nix:with-pollfds (pollfds + (wayland-pollfd wayland-fd nix:pollin nix:pollpri) + (backend-pollfd backend-fd nix:pollin nix:pollpri)) + (loop :while (running *compositor*) + :do (progn + (wl-event-loop-dispatch event-loop 0) + (wl-display-flush-clients (display *compositor*)) + (animation::update-animations (lambda () + (setf (render-needed *compositor*) t))) + (let ((event (nix:poll pollfds 2 5))) + (when (render-needed *compositor*) + (render (current-mode)) + (swap-buffers (backend *compositor*)) + (setf (render-needed *compositor*) nil)) + (when event + (when (= (nix:poll-return-event wayland-pollfd) nix:pollin) + ) + + (when (= (nix:poll-return-event backend-pollfd) nix:pollin) + (process-events (backend *compositor*)))))))))) +|# + + +(defun main-loop-drm (event-loop) + (let ((wayland-fd (wl-event-loop-get-fd event-loop)) + (backend-fd (get-fd (backend *compositor*)))) + (nix:with-pollfds (pollfds + (wayland-pollfd wayland-fd nix:pollin nix:pollpri) + (backend-pollfd backend-fd nix:pollin nix:pollpri)) + (initialize-animation event-loop) + (loop :while (running *compositor*) + :do (progn + (when (render-needed *compositor*) + (render (current-mode)) + (swap-buffers (backend *compositor*)) + (setf (render-needed *compositor*) nil)) + (wl-event-loop-dispatch event-loop 0) + (wl-display-flush-clients (display *compositor*)) + (alexandria:ignore-some-conditions (nix:eintr) + (let ((event (nix:poll pollfds 2 -1))) + (wl-event-loop-dispatch event-loop 0) + (wl-display-flush-clients (display *compositor*)) + (animation::update-animations (lambda () + (setf (render-needed *compositor*) t))) + (when event + (when (= (nix:poll-return-event backend-pollfd) nix:pollin) + (process-events (backend *compositor*))))))))))) + +#| +(defun main-loop-sdl (event-loop) (if (running *compositor*) (progn (wl-event-loop-dispatch event-loop 0) @@ -15,9 +69,31 @@ (render (current-mode)) (swap-buffers (backend *compositor*)) (setf (render-needed *compositor*) nil)) - (main-loop event-loop)) + (main-loop-sdl event-loop)) nil)) - +|# + +(defun main-loop-sdl (event-loop) + (let ((wayland-fd (wl-event-loop-get-fd event-loop))) + (nix:with-pollfds (pollfds + (wayland-pollfd wayland-fd nix:pollin nix:pollpri)) + (initialize-animation event-loop) + (loop :while (running *compositor*) + :do (progn + (when (render-needed *compositor*) + (render (current-mode)) + (swap-buffers (backend *compositor*)) + (setf (render-needed *compositor*) nil)) + (wl-event-loop-dispatch event-loop 0) + (wl-display-flush-clients (display *compositor*)) + (alexandria:ignore-some-conditions (nix:eintr) + (let ((event (nix:poll pollfds 1 5))) + (wl-event-loop-dispatch event-loop 0) + (wl-display-flush-clients (display *compositor*)) + (animation::update-animations (lambda () + (setf (render-needed *compositor*) t))) + (process-events (backend *compositor*))))))))) + (defun resize-surface-relative (surface delta-x delta-y) (with-slots (x y ->xdg-surface input-region) surface (let ((width (width (first (last (rects input-region))))) @@ -102,6 +178,7 @@ (mouse-button-handler (current-mode) time button state)) (defun window-event-handler () + (new-xkb-state *compositor*) (setf (render-needed *compositor*) t)) (defun call-keyboard-handler (time key state) @@ -134,7 +211,7 @@ ;; Initialise backend (format t "Initialising backend: ~A~%" backend-name) - (setf (backend *compositor*) (make-instance backend-name)) + (setf (backend *compositor*) (make-instance 'backend)) (initialise-backend (backend *compositor*) (screen-width *compositor*) (screen-height *compositor*) @@ -154,8 +231,12 @@ (setf (display *compositor*) (wl-display-create)) (format t "Opened socket: ~A~%" (wl-display-add-socket-auto (display *compositor*))) - (initialise-wayland) - (init-device-manager) + (format t "Initializing wayland~%") + (initialise-wayland) ;; plumbing.lisp + (format t "Initializing device manager~%") + (init-device-manager) ;; plumbing.lisp +;; (make-xdg-shell-server-interfaces) +;; (set-implementations) ;; plumbing-unwrapped.lisp (wl-global-create (display *compositor*) wl-compositor-interface 3 @@ -166,6 +247,7 @@ 1 (null-pointer) (callback shell-bind)) + (format t "Making xdg-shell-server interfaces~%") (make-xdg-shell-server-interfaces) ;;(make-xdg-interfaces) (wl-global-create (display *compositor*) @@ -175,7 +257,7 @@ (callback xdg-shell-bind)) (wl-global-create (display *compositor*) wl-seat-interface - 1 + 4 (null-pointer) (callback seat-bind)) @@ -185,14 +267,21 @@ (null-pointer) (callback device-manager-bind)) - (init-wl-output) + (init-wl-output) ;; plumbing.lisp +#| (wl-global-create (display *compositor*) ;; plumbing-unwrapped.lisp + wl-output-interface + 2 + (null-pointer) + (callback output-bind))|# ;; Initialise shared memory (wl-display-init-shm (display *compositor*)) ;; Run main loop (format t "Running main loop~%") (setf (running *compositor*) t) - (main-loop (wl-display-get-event-loop (display *compositor*)))) + (if (string-equal (symbol-name backend-name) "backend-drm-gbm") + (main-loop-drm (wl-display-get-event-loop (display *compositor*))) + (main-loop-sdl (wl-display-get-event-loop (display *compositor*))))) (when (display *compositor*) (wl-display-destroy (display *compositor*)) (setf (display *compositor*) nil))