From 2604ea787dd8516ebf0674c2a8efef30fb1eac21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Oliveira?= Date: Wed, 8 Jun 2011 19:19:05 +0000 Subject: [PATCH] First take at global idle hooks. --- glut/interface.lisp | 15 +++++++++++---- glut/package.lisp | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/glut/interface.lisp b/glut/interface.lisp index fa2e81c..8d1a4f1 100644 --- a/glut/interface.lisp +++ b/glut/interface.lisp @@ -2,7 +2,7 @@ ;;; ;;; interface.lisp --- CLOS interface to the GLUT API. ;;; -;;; Copyright (c) 2006, Luis Oliveira +;;; Copyright (c) 2006-2011, Luis Oliveira ;;; All rights reserved. ;;; ;;; Redistribution and use in source and binary forms, with or without @@ -237,9 +237,13 @@ Lexically binds CURRENT-WINDOW to the respective object." ,@body) (set-window ,current-id))))) +(defparameter *global-idle-hooks* nil + "A list of functions to be called without arguments from GLUT's idle event.") + ;;; We do some extra stuff to provide an IDLE event per-window since ;;; GLUT's IDLE event is global. (define-glut-event idle (window) + (mapc #'funcall *global-idle-hooks*) (loop for win in *windows-with-idle-event* do (with-window win (idle win)))) @@ -280,6 +284,8 @@ Lexically binds CURRENT-WINDOW to the respective object." (call-next-method)) (defmethod display-window ((win base-window)) + (when *global-idle-hooks* + (register-callback (find-event-or-lose :idle))) (values)) (defmethod enable-event ((window base-window) event-name) @@ -291,7 +297,6 @@ Lexically binds CURRENT-WINDOW to the respective object." (when (eq event-name :idle) (push window *windows-with-idle-event*))))) - (defmethod disable-event ((window base-window) event-name) (if (eq event-name :display) (warn "GLUT would be upset if we set the DISPLAY callback to NULL. ~ @@ -310,7 +315,8 @@ Lexically binds CURRENT-WINDOW to the respective object." (delete window *windows-with-idle-event*)) ;; We need to disable the idle callback here too in ;; addition to close. - (when (null *windows-with-idle-event*) + (when (and (null *windows-with-idle-event*) + (null *global-idle-hooks*)) (unregister-callback event))))))) (defun destroy-current-window () @@ -334,7 +340,8 @@ Lexically binds CURRENT-WINDOW to the respective object." (when (not (destroyed w)) (setf (destroyed w) t) (destroy-window (id w))) - (when (null *windows-with-idle-event*) + (when (and (null *windows-with-idle-event*) + (null *global-idle-hooks*)) (unregister-callback (find-event-or-lose :idle))) #+darwin (progn diff --git a/glut/package.lisp b/glut/package.lisp index b8d984d..84d5d9a 100644 --- a/glut/package.lisp +++ b/glut/package.lisp @@ -96,6 +96,7 @@ #:enable-tick #:disable-tick ;; specials + #:*global-idle-hooks* #:*run-main-loop-after-display*) ;; everything else (:shadow #:get)