Skip to content

Commit

Permalink
This is a working copy post-that-bug-which-caused-drm-not-to-exit. I …
Browse files Browse the repository at this point in the history
…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 osicat/osicat#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
  • Loading branch information
malcolmstill committed Oct 23, 2016
1 parent c9313fc commit 558c570
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 19 deletions.
7 changes: 3 additions & 4 deletions build/build-ulubis-drm-gbm.lisp
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 2 additions & 4 deletions build/build-ulubis-sdl.lisp
Original file line number Diff line number Diff line change
@@ -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)

10 changes: 10 additions & 0 deletions install.lisp
Original file line number Diff line number Diff line change
@@ -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"))))
11 changes: 9 additions & 2 deletions ulubis.asd
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")))

107 changes: 98 additions & 9 deletions ulubis.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)))))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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*)
Expand All @@ -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
Expand All @@ -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*)
Expand All @@ -175,7 +257,7 @@
(callback xdg-shell-bind))
(wl-global-create (display *compositor*)
wl-seat-interface
1
4
(null-pointer)
(callback seat-bind))

Expand All @@ -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))
Expand Down

0 comments on commit 558c570

Please sign in to comment.