lispgames / cl-sdl2

Common Lisp bindings for SDL2 using C2FFI.
MIT License
304 stars 82 forks source link

hide-cursor only works when using with-event-loop #102

Closed rfolland closed 6 years ago

rfolland commented 6 years ago

I found that hide-cursor has no effect unless I use with-event-loop. Using an ordinary do loop and rendering I cannot get the cursor to hide, neither in windowed or fullscreen-desktop mode. Just adding a with-event-loop polling for events in my do loop makes the cursor hide.

I am running this in Wayland/Weston on Arch Linux.

(eval-when (:compile-toplevel :load-toplevel :execute)
  (ql:quickload :bordeaux-threads)
  (ql:quickload :sdl2))

(defparameter *display* 0)

(defun sdl1 ()
  (sdl2:with-init (:video)
    (sdl2:hide-cursor)
    (sdl2:with-window (win
                       :x (sdl2:windowpos-centered *display*)
                       :y (sdl2:windowpos-centered *display*)
                       :flags '())
      (sdl2:with-renderer (ren win)
        (dotimes (n 2)
          (sdl2:with-event-loop (:method :poll)
            (:idle ()
                   (sdl2:set-render-draw-color ren (* n 50) (* n 50) (* n 50) 255)
                   (sdl2:render-clear ren)
                   (sdl2:render-present ren)
                   (sleep 2))
            (:quit () t)))))))

(defun sdltest (d)
  (setf *display* d)
  (bt:make-thread (lambda () (sdl2:make-this-thread-main #'sdl1))))
rfolland commented 6 years ago

The event loop is not neccessary, it is sufficient to just do an (sdl2:pump-events). But the cursor is only present when I have a keyboard and mouse connected. Which I do not need for this system, so that is a workaround for me anyway.