| 1 | ;; Common Lisp bindings for GTK+ 2.x |
| 2 | ;; Copyright 2008 Espen S. Johnsen <espen@users.sf.net> |
| 3 | ;; |
| 4 | ;; Permission is hereby granted, free of charge, to any person obtaining |
| 5 | ;; a copy of this software and associated documentation files (the |
| 6 | ;; "Software"), to deal in the Software without restriction, including |
| 7 | ;; without limitation the rights to use, copy, modify, merge, publish, |
| 8 | ;; distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | ;; permit persons to whom the Software is furnished to do so, subject to |
| 10 | ;; the following conditions: |
| 11 | ;; |
| 12 | ;; The above copyright notice and this permission notice shall be |
| 13 | ;; included in all copies or substantial portions of the Software. |
| 14 | ;; |
| 15 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | |
| 23 | ;; $Id: main-loop.lisp,v 1.1 2008-12-10 02:51:59 espen Exp $ |
| 24 | |
| 25 | |
| 26 | (in-package "GLIB") |
| 27 | |
| 28 | (use-prefix "g") |
| 29 | |
| 30 | ;;; Main loop |
| 31 | |
| 32 | (defbinding %main-loop-ref () pointer |
| 33 | (location pointer)) |
| 34 | |
| 35 | (defbinding %main-loop-unref () nil |
| 36 | (location pointer)) |
| 37 | |
| 38 | (defbinding %main-loop-new () pointer |
| 39 | (context (or null pointer)) |
| 40 | (is-running boolean)) |
| 41 | |
| 42 | (eval-when (:compile-toplevel :load-toplevel :execute) |
| 43 | (defclass main-loop (ref-counted-object) |
| 44 | ((is-running |
| 45 | :allocation :virtual :getter "g_main_loop_is_running" |
| 46 | :reader main-loop-is-running-p :type boolean) |
| 47 | (context |
| 48 | :allocation :virtual :getter "g_main_loop_get_context" |
| 49 | :reader main-loop-context :type pointer)) |
| 50 | (:metaclass proxy-class) |
| 51 | (:ref %main-loop-ref) |
| 52 | (:unref %main-loop-unref))) |
| 53 | |
| 54 | (defmethod allocate-foreign ((main-loop main-loop) &key context is-running) |
| 55 | (%main-loop-new context is-running)) |
| 56 | |
| 57 | (defbinding main-loop-run () nil |
| 58 | main-loop) |
| 59 | |
| 60 | (defbinding main-loop-quit () nil |
| 61 | main-loop) |
| 62 | |
| 63 | (defbinding %main-context-new () pointer) |
| 64 | |
| 65 | (defbinding %main-context-unref () nil |
| 66 | pointer) |
| 67 | |
| 68 | (defmacro with-main-loop ((&optional main-loop) &body body) |
| 69 | (let ((%main-loop (make-symbol "MAIN-LOOP")) |
| 70 | (%main-context (make-symbol "MAIN-CONTEXT"))) |
| 71 | `(let* ((,%main-context (%main-context-new)) |
| 72 | (,%main-loop (or ,main-loop (make-instance 'main-loop :context ,%main-context)))) |
| 73 | (main-loop-run ,%main-loop) |
| 74 | (unwind-protect |
| 75 | (progn ,@body) |
| 76 | (main-loop-quit ,%main-loop) |
| 77 | (%main-context-unref ,%main-context))))) |
| 78 | |