1 ;; Common Lisp bindings for GTK+ v2.x
2 ;; Copyright 2000-2006 Espen S. Johnsen <espen@users.sf.net>
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:
12 ;; The above copyright notice and this permission notice shall be
13 ;; included in all copies or substantial portions of the Software.
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.
23 ;; $Id: gdk.lisp,v 1.42 2007/06/20 10:16:19 espen Exp $
30 (defbinding (gdk-init "gdk_parse_args") () nil
31 "Initializes the library without opening the display."
40 (defmethod print-object ((display display) stream)
41 (if (and (proxy-valid-p display) (slot-boundp display 'name))
42 (print-unreadable-object (display stream :type t :identity nil)
43 (format stream "~S at 0x~X"
44 (display-name display) (pointer-address (foreign-location display))))
47 (defbinding %display-open () display
48 (display-name (or null string)))
50 (defvar *display-aliases* ())
52 (defun display-add-alias (display alias)
53 (unless (rassoc display *display-aliases*)
54 (signal-connect display 'closed
55 #'(lambda (is-error-p)
56 (declare (ignore is-error-p))
57 (setq *display-aliases*
58 (delete-if #'(lambda (mapping)
59 (eq (cdr mapping) display))
61 (push (cons alias display) *display-aliases*)))
64 (defun display-open (&optional name)
67 (error "Opening display failed: ~A" name))))
68 (unless (display-get-default)
69 (display-set-default display))
70 (when (and (stringp name) (not (string= name (display-name display))))
71 (display-add-alias display name))
74 (defbinding %display-get-n-screens () int
77 (defbinding %display-get-screen () screen
81 (defun display-screens (&optional (display (display-get-default)))
83 for i from 0 below (%display-get-n-screens display)
84 collect (%display-get-screen display i)))
86 (defbinding display-get-default-screen
87 (&optional (display (display-get-default))) screen
90 (defbinding display-beep (&optional (display (display-get-default))) nil
93 (defbinding display-sync (&optional (display (display-get-default))) nil
96 (defbinding display-flush (&optional (display (display-get-default))) nil
99 (defbinding display-close (&optional (display (display-get-default))) nil
100 ((ensure-display display t) display))
102 (defbinding flush () nil)
104 (defbinding display-get-event
105 (&optional (display (display-get-default))) event
108 (defbinding display-peek-event
109 (&optional (display (display-get-default))) event
112 (defbinding display-put-event
113 (event &optional (display (display-get-default))) event
117 (defbinding (display-connection-number "clg_gdk_connection_number")
118 (&optional (display (display-get-default))) int
121 (defun find-display (name &optional (error-p t))
123 (find name (list-displays) :key #'display-name :test #'string=)
124 (cdr (assoc name *display-aliases* :test #'string=))
126 (error "No such display: ~A" name))))
128 ;; This will not detect connections to the same server that use
129 ;; different hostnames
130 (defun %find-similar-display (display)
131 (find (display-name display) (delete display (list-displays))
132 :key #'display-name :test #'string=))
134 (defun ensure-display (display &optional existing-only-p)
136 (null (display-get-default))
139 (find-display display existing-only-p)
140 (let* ((new (display-open display))
141 (existing (%find-similar-display new)))
144 (display-add-alias existing display)
152 (defbinding display-get-default () display)
154 (defbinding (display-set-default "gdk_display_manager_set_default_display")
156 ((display-manager) display-manager)
159 (defbinding (list-displays "gdk_display_manager_list_displays") ()
160 (gslist (static display))
161 ((display-manager) display-manager))
163 ;; The only purpose of exporting this is to make it possible for
164 ;; applications to connect to the display-opened signal
165 (defbinding (display-manager "gdk_display_manager_get") () display-manager)
167 (defbinding display-get-core-pointer
168 (&optional (display (display-get-default))) device
171 (defmacro with-default-display ((display) &body body)
172 (let ((saved-display (make-symbol "SAVED-DISPLAY"))
173 (current-display (make-symbol "CURRENT-DISPLAY")))
174 `(let* ((,current-display ,display)
175 (,saved-display (when ,current-display
177 (display-get-default)
178 (display-set-default (ensure-display ,current-display))))))
182 (display-set-default ,saved-display))))))
185 ;;; Primitive graphics structures (points, rectangles and regions)
187 (defbinding %rectangle-intersect () boolean
192 (defun rectangle-intersect (src1 src2 &optional (dest (make-instance 'rectangle)))
193 "Calculates the intersection of two rectangles. It is allowed for DEST to be the same as either SRC1 or SRC2. DEST is returned if the to rectangles intersect, otherwise NIL"
194 (when (%rectangle-intersect src1 src2 dest)
197 (defbinding rectangle-union (src1 src2 &optional (dest (make-instance 'rectangle))) nil
198 "Calculates the union of two rectangles. The union of rectangles SRC1 and SRC2 is the smallest rectangle which includes both SRC1 and SRC2 within it. It is allowed for DEST to be the same as either SRC1 or SRC2."
201 (dest rectangle :in/return))
203 (defun ensure-rectangle (rectangle)
205 (rectangle rectangle)
206 (vector (make-instance 'rectangle
207 :x (aref rectangle 0) :y (aref rectangle 1)
208 :width (aref rectangle 2) :height (aref rectangle 3)))))
211 (defbinding %region-new () pointer)
213 (defbinding %region-polygon () pointer
214 (points (vector (inlined point)))
216 (fill-rule fill-rule))
218 (defbinding %region-rectangle () pointer
219 (rectangle rectangle))
221 (defbinding %region-copy () pointer
224 (defbinding %region-destroy () nil
227 (defmethod allocate-foreign ((region region) &key rectangle polygon fill-rule)
229 ((and rectangle polygon)
230 (error "Only one of the keyword arguments :RECTANGLE and :POLYGON can be specified"))
231 (rectangle (%region-rectangle (ensure-rectangle rectangle)))
232 (polygon (%region-polygon polygon (length polygon) fill-rule))
235 (defun ensure-region (region)
238 ((or rectangle vector)
239 (make-instance 'region :rectangle (ensure-rectangle region)))
241 (make-instance 'region :polygon region))))
243 (defbinding region-get-clipbox (region &optional (rectangle (make-instance 'rectangle))) nil
245 (rectangle rectangle :in/return))
247 (defbinding %region-get-rectangles () nil
249 (rectangles pointer :out)
250 (n-rectangles int :out))
252 (defun region-get-rectangles (region)
253 "Obtains the area covered by the region as a list of rectangles."
254 (multiple-value-bind (location length) (%region-get-rectangles region)
256 (map-c-vector 'list #'identity location '(inlined rectangle) length :get)
257 (deallocate-memory location))))
259 (defbinding region-empty-p () boolean
262 (defbinding region-equal-p () boolean
266 (defbinding region-point-in-p () boolean
271 (defbinding region-rect-in (region rectangle) overlap-type
273 ((ensure-rectangle rectangle) rectangle))
275 (defbinding region-offset () nil
280 (defbinding region-shrink () nil
285 (defbinding region-intersect (source1 source2) nil
286 ((ensure-region source1) region :in/return)
287 ((ensure-region source2) region))
289 (defbinding region-union (source1 source2) nil
290 ((ensure-region source1) region :in/return)
291 ((ensure-region source2) region))
293 (defbinding region-subtract (source1 source2) nil
294 ((ensure-region source1) region :in/return)
295 ((ensure-region source2) region))
297 (defbinding region-xor (source1 source2) nil
298 ((ensure-region source1) region :in/return)
299 ((ensure-region source2) region))
304 (defbinding (events-pending-p "gdk_events_pending") () boolean)
306 (defbinding event-get () event)
308 (defbinding event-peek () event)
310 (defbinding event-get-graphics-expose () event
313 (defbinding event-put () event
316 ;(defbinding event-handler-set () ...)
318 (defbinding set-show-events () nil
319 (show-events boolean))
321 (defbinding get-show-events () boolean)
324 ;;; Miscellaneous functions
326 (defbinding screen-width () int
329 (defbinding screen-height () int
332 (defbinding screen-width-mm () int
335 (defbinding screen-height-mm () int
339 (defbinding pointer-grab
340 (window &key owner-events events confine-to cursor time) grab-status
342 (owner-events boolean)
344 (confine-to (or null window))
345 (cursor (or null cursor))
346 ((or time 0) (unsigned 32)))
348 (defbinding (pointer-ungrab "gdk_display_pointer_ungrab")
349 (&optional time (display (display-get-default))) nil
351 ((or time 0) (unsigned 32)))
353 (defbinding (pointer-is-grabbed-p "gdk_display_pointer_is_grabbed")
354 (&optional (display (display-get-default))) boolean
357 (defbinding keyboard-grab (window &key owner-events time) grab-status
359 (owner-events boolean)
360 ((or time 0) (unsigned 32)))
362 (defbinding (keyboard-ungrab "gdk_display_keyboard_ungrab")
363 (&optional time (display (display-get-default))) nil
365 ((or time 0) (unsigned 32)))
369 (defbinding atom-intern (atom-name &optional only-if-exists) atom
370 ((string atom-name) string)
371 (only-if-exists boolean))
373 (defbinding atom-name () string
380 (defbinding visual-get-best-depth () int)
382 (defbinding visual-get-best-type () visual-type)
384 (defbinding visual-get-system () visual)
387 (defbinding (%visual-get-best-with-nothing "gdk_visual_get_best") () visual)
389 (defbinding %visual-get-best-with-depth () visual
392 (defbinding %visual-get-best-with-type () visual
395 (defbinding %visual-get-best-with-both () visual
399 (defun visual-get-best (&key depth type)
401 ((and depth type) (%visual-get-best-with-both depth type))
402 (depth (%visual-get-best-with-depth depth))
403 (type (%visual-get-best-with-type type))
404 (t (%visual-get-best-with-nothing))))
406 ;(defbinding query-depths ..)
408 ;(defbinding query-visual-types ..)
410 (defbinding list-visuals () (glist visual))
415 (defbinding window-destroy () nil
418 (defbinding window-at-pointer () window
422 (defbinding window-show () nil
425 (defbinding window-show-unraised () nil
428 (defbinding window-hide () nil
431 (defbinding window-is-visible-p () boolean
434 (defbinding window-is-viewable-p () boolean
437 (defbinding window-withdraw () nil
440 (defbinding window-iconify () nil
443 (defbinding window-deiconify () nil
446 (defbinding window-stick () nil
449 (defbinding window-unstick () nil
452 (defbinding window-maximize () nil
455 (defbinding window-unmaximize () nil
458 (defbinding window-fullscreen () nil
461 (defbinding window-unfullscreen () nil
464 (defbinding window-set-keep-above () nil
468 (defbinding window-set-keep-below () nil
472 (defbinding window-move () nil
477 (defbinding window-resize () nil
482 (defbinding window-move-resize () nil
489 (defbinding window-scroll () nil
494 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
495 (defbinding window-move-region (window region dx dy) nil
497 ((ensure-region region) region)
501 (defbinding window-reparent () nil
507 (defbinding window-clear () nil
510 (defbinding %window-clear-area () nil
512 (x int) (y int) (width int) (height int))
514 (defbinding %window-clear-area-e () nil
516 (x int) (y int) (width int) (height int))
518 (defun window-clear-area (window x y width height &optional expose)
520 (%window-clear-area-e window x y width height)
521 (%window-clear-area window x y width height)))
523 (defbinding window-raise () nil
526 (defbinding window-lower () nil
529 (defbinding window-focus () nil
531 (timestamp unsigned-int))
533 (defbinding window-register-dnd () nil
536 (defbinding window-begin-resize-drag () nil
542 (timestamp unsigned-int))
544 (defbinding window-begin-move-drag () nil
549 (timestamp unsigned-int))
551 ;; Probably not needed
552 ;; (defbinding window-constrain-size () nil ..
554 (defbinding window-begin-paint-region (window region) nil
556 ((ensure-region region) region))
558 (defbinding window-end-paint () nil
561 (defmacro with-window-paint ((window region) &body body)
563 (window-begin-paint-region ,window ,region)
566 (window-end-paint ,window))))
568 ;; TODO: create wrapper function and use gdk_window_invalidate_maybe_recurse
569 ;; if last arg is a function
570 (defbinding window-invalidate-region (window region invalidate-children-p) nil
572 ((ensure-region region) region)
573 (invalidate-children-p boolean))
575 (defbinding window-get-update-area () region
578 (defbinding window-freeze-updates () nil
581 (defbinding window-thaw-updates () nil
584 (defbinding window-process-all-updates () nil)
586 (defbinding window-process-updates () nil
588 (update-children-p boolean))
590 (defbinding window-set-debug-updates () nil
593 (defbinding window-enable-synchronized-configure () nil
596 (defbinding window-configure-finished () nil
599 ;; Deprecated, use gobject user data mechanism
600 (defbinding window-set-user-data () nil
604 (defbinding window-set-override-redirect () nil
606 (override-redirect-p boolean))
608 (defbinding window-set-accept-focus () nil
610 (accept-focus-p boolean))
612 (defbinding window-set-focus-on-map () nil
614 (focus-on-map-p boolean))
617 ; (defbinding window-add-filter () nil
618 ; (defbinding window-remove-filter () nil
620 ;; New code should use window-shape-combine
621 (defbinding window-shape-combine-mask () nil
627 (defbinding %window-shape-combine-region () nil
629 (region (or null region))
633 (defun window-shape-combine (window shape offset-x offset-y)
635 (null (%window-shape-combine-region window nil 0 0))
636 (region (%window-shape-combine-region window shape offset-x offset-y))
637 (bitmap (window-shape-combine-mask window shape offset-x offset-y))))
639 (defbinding window-set-child-shapes () nil
642 (defbinding window-merge-child-shapes () nil
645 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.10.0")
647 (defbinding %window-input-shape-combine-mask () nil
653 (defbinding %window-input-shape-combine-region () nil
655 (region (or null region))
659 (defun window-input-shape-combine (window shape x y)
661 (null (%window-input-shape-combine-region window nil 0 0))
662 (region (%window-input-shape-combine-region window shape x y))
663 (bitmap (%window-input-shape-combine-mask window shape x y))))
665 (defbinding window-set-child-input-shapes () nil
668 (defbinding window-merge-child-input-shapes () nil
671 (defbinding window-set-static-gravities () boolean
673 (use-static-p boolean))
675 (defbinding window-set-title () nil
679 (defbinding window-set-background () nil
683 (defbinding window-set-back-pixmap (window pixmap &optional parent-relative-p) nil
685 (pixmap (or null pixmap))
686 (parent-relative-p boolean))
688 (defbinding window-set-cursor () nil
690 (cursor (or null cursor)))
692 (defbinding window-get-geometry () nil
700 ;(defbinding window-set-geometry-hints () nil
702 (defbinding window-set-icon-list () nil
704 (icons (glist pixbufs)))
706 (defbinding window-set-skip-taskbar-hint () nil
708 (skip-taskbar-p boolean))
710 (defbinding window-set-skip-pager-hint () nil
712 (skip-pager-p boolean))
714 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
715 (defbinding window-set-urgency-hint () nil
719 (defbinding window-get-position () nil
724 (defbinding window-get-root-origin () nil
729 (defbinding window-get-frame-extents (window &optional (extents (make-instance 'rect))) nil
731 (extents rectangle :in/return))
733 (defbinding window-get-origin () nil ; this may not work as
734 (window window) ; an int is actually returned
738 (defbinding window-get-pointer () window
742 (mask modifier-type :out))
744 ;(defbinding window-set-icon () nil
746 (defbinding window-set-icon-name () nil
750 (defbinding window-set-transient-for () nil
754 (defbinding window-set-role () nil
758 (defbinding %window-get-decorations () boolean
760 (decorations wm-decoration :out))
762 (defun %window-decorations-getter (window)
763 (nth-value 1 (%window-get-decorations window)))
765 (defun %window-decorations-boundp (window)
766 (%window-get-decorations window))
768 (defbinding %window-get-toplevels () (glist window))
770 (defun window-get-toplevels (&optional screen)
772 (error "Not implemented")
773 (%window-get-toplevels)))
775 (defbinding %get-default-root-window () window)
777 (defun get-root-window (&optional display)
779 (error "Not implemented")
780 (%get-default-root-window)))
788 (defbinding drag-status () nil
789 (context drag-context)
791 (time (unsigned 32)))
800 (defbinding rgb-init () nil)
807 (defmethod allocate-foreign ((cursor cursor) &key source mask fg bg
808 (x 0) (y 0) (display (display-get-default)))
810 (keyword (%cursor-new-for-display display source))
811 (pixbuf (%cursor-new-from-pixbuf display source x y))
812 (pixmap (%cursor-new-from-pixmap source mask
813 (or fg (ensure-color #(0.0 0.0 0.0)))
814 (or bg (ensure-color #(1.0 1.0 1.0))) x y))
815 (pathname (%cursor-new-from-pixbuf display (pixbuf-load source) x y))))
817 (defun ensure-cursor (cursor &rest args)
818 (if (typep cursor 'cursor)
820 (apply #'make-instance 'cursor :source cursor args)))
822 (defbinding %cursor-new-for-display () pointer
824 (cursor-type cursor-type))
826 (defbinding %cursor-new-from-pixmap () pointer
833 (defbinding %cursor-new-from-pixbuf () pointer
838 (defbinding %cursor-ref () pointer
841 (defbinding %cursor-unref () nil
847 (defbinding %pixmap-new () pointer
848 (window (or null window))
853 (defmethod allocate-foreign ((pximap pixmap) &key width height depth window)
854 (%pixmap-new window width height depth))
856 (defun pixmap-new (width height depth &key window)
857 (warn "PIXMAP-NEW is deprecated, use (make-instance 'pixmap ...) instead")
858 (make-instance 'pixmap :width width :height height :depth depth :window window))
860 (defbinding %pixmap-colormap-create-from-xpm () pixmap
861 (window (or null window))
862 (colormap (or null colormap))
864 (color (or null color))
867 (defbinding %pixmap-colormap-create-from-xpm-d () pixmap
868 (window (or null window))
869 (colormap (or null colormap))
871 (color (or null color))
872 (data (vector string)))
874 ;; Deprecated, use pixbufs instead
875 (defun pixmap-create (source &key color window colormap)
877 (if (not (or window colormap))
880 (multiple-value-bind (pixmap mask)
882 ((or string pathname)
883 (%pixmap-colormap-create-from-xpm window colormap color source))
885 (%pixmap-colormap-create-from-xpm-d window colormap color source)))
886 (values pixmap mask))))
891 (defbinding colormap-get-system () colormap)
893 (defbinding %color-copy () pointer
896 (defmethod allocate-foreign ((color color) &rest initargs)
897 (declare (ignore color initargs))
898 ;; Color structs are allocated as memory chunks by gdk, and since
899 ;; there is no gdk_color_new we have to use this hack to get a new
901 (with-memory (location #.(foreign-size (find-class 'color)))
902 (%color-copy location)))
904 (defun %scale-value (value)
907 (float (truncate (* value 65535)))))
909 (defmethod initialize-instance ((color color) &key (red 0.0) (green 0.0) (blue 0.0))
911 (with-slots ((%red red) (%green green) (%blue blue)) color
913 %red (%scale-value red)
914 %green (%scale-value green)
915 %blue (%scale-value blue))))
917 (defbinding %color-parse () boolean
919 (color color :in/return))
921 (defun color-parse (spec &optional (color (make-instance 'color)))
922 (multiple-value-bind (succeeded-p color) (%color-parse spec color)
925 (error "Parsing color specification ~S failed." spec))))
927 (defun ensure-color (color)
931 (string (color-parse color))
933 (make-instance 'color
934 :red (svref color 0) :green (svref color 1) :blue (svref color 2)))))
938 ;;; Drawable -- all the draw- functions are deprecated and will be
939 ;;; removed, use cairo for drawing instead.
941 (defbinding drawable-get-size () nil
946 (defbinding (drawable-width "gdk_drawable_get_size") () nil
951 (defbinding (drawable-height "gdk_drawable_get_size") () nil
956 ;; (defbinding drawable-get-clip-region () region
957 ;; (drawable drawable))
959 ;; (defbinding drawable-get-visible-region () region
960 ;; (drawable drawable))
962 (defbinding draw-point () nil
963 (drawable drawable) (gc gc)
966 (defbinding %draw-points () nil
967 (drawable drawable) (gc gc)
971 (defbinding draw-line () nil
972 (drawable drawable) (gc gc)
976 (defbinding draw-pixbuf
977 (drawable gc pixbuf src-x src-y dest-x dest-y &optional
978 width height (dither :none) (x-dither 0) (y-dither 0)) nil
979 (drawable drawable) (gc (or null gc))
981 (src-x int) (src-y int)
982 (dest-x int) (dest-y int)
983 ((or width -1) int) ((or height -1) int)
985 (x-dither int) (y-dither int))
987 (defbinding draw-rectangle () nil
988 (drawable drawable) (gc gc)
991 (width int) (height int))
993 (defbinding draw-arc () nil
994 (drawable drawable) (gc gc)
997 (width int) (height int)
998 (angle1 int) (angle2 int))
1000 (defbinding %draw-layout () nil
1001 (drawable drawable) (gc gc)
1004 (layout pango:layout))
1006 (defbinding %draw-layout-with-colors () nil
1007 (drawable drawable) (gc gc)
1010 (layout pango:layout)
1011 (foreground (or null color))
1012 (background (or null color)))
1014 (defun draw-layout (drawable gc font x y layout &optional foreground background)
1015 (if (or foreground background)
1016 (%draw-layout-with-colors drawable gc font x y layout foreground background)
1017 (%draw-layout drawable gc font x y layout)))
1019 (defbinding draw-drawable
1020 (drawable gc src src-x src-y dest-x dest-y &optional width height) nil
1021 (drawable drawable) (gc gc)
1023 (src-x int) (src-y int)
1024 (dest-x int) (dest-y int)
1025 ((or width -1) int) ((or height -1) int))
1027 (defbinding draw-image
1028 (drawable gc image src-x src-y dest-x dest-y &optional width height) nil
1029 (drawable drawable) (gc gc)
1031 (src-x int) (src-y int)
1032 (dest-x int) (dest-y int)
1033 ((or width -1) int) ((or height -1) int))
1035 (defbinding drawable-get-image () image
1038 (width int) (height int))
1040 (defbinding drawable-copy-to-image
1041 (drawable src-x src-y width height &optional image dest-x dest-y) image
1043 (image (or null image))
1044 (src-x int) (src-y int)
1045 ((if image dest-x 0) int)
1046 ((if image dest-y 0) int)
1047 (width int) (height int))
1052 (defbinding keyval-name () string
1053 (keyval unsigned-int))
1055 (defbinding %keyval-from-name () unsigned-int
1058 (defun keyval-from-name (name)
1059 "Returns the keysym value for the given key name or NIL if it is not a valid name."
1060 (let ((keyval (%keyval-from-name name)))
1061 (unless (zerop keyval)
1064 (defbinding keyval-to-upper () unsigned-int
1065 (keyval unsigned-int))
1067 (defbinding keyval-to-lower () unsigned-int
1068 (keyval unsigned-int))
1070 (defbinding (keyval-is-upper-p "gdk_keyval_is_upper") () boolean
1071 (keyval unsigned-int))
1073 (defbinding (keyval-is-lower-p "gdk_keyval_is_lower") () boolean
1074 (keyval unsigned-int))
1076 ;;; Cairo interaction
1078 #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.8.0")
1080 (defbinding cairo-create () cairo:context
1081 (drawable drawable))
1083 (defmacro with-cairo-context ((cr drawable) &body body)
1084 `(let ((,cr (cairo-create ,drawable)))
1087 (invalidate-instance ,cr t))))
1089 (defbinding cairo-set-source-color () nil
1093 (defbinding cairo-set-source-pixbuf () nil
1099 (defbinding cairo-rectangle () nil
1101 (rectangle rectangle))
1103 ;; (defbinding cairo-region () nil
1104 ;; (cr cairo:context)
1107 (defbinding (cairo-surface-get-window "clg_gdk_cairo_surface_get_window") () window
1108 (surface cairo:surface))
1113 ;;; Multi-threading support
1117 (defvar *global-lock* nil)
1119 (defun %global-lock-p ()
1120 (eq (car (sb-thread:mutex-value *global-lock*)) sb-thread:*current-thread*))
1122 (defun threads-enter ()
1124 (if (%global-lock-p)
1125 (incf (cdr (sb-thread:mutex-value *global-lock*)))
1126 (sb-thread:get-mutex *global-lock* (cons sb-thread:*current-thread* 0)))))
1128 (defun threads-leave (&optional flush-p)
1130 (assert (%global-lock-p))
1132 ((zerop (cdr (sb-thread:mutex-value *global-lock*)))
1135 (sb-thread:release-mutex *global-lock*))
1136 (t (decf (cdr (sb-thread:mutex-value *global-lock*)))))))
1138 (define-callback %enter-fn nil ()
1141 (define-callback %leave-fn nil ()
1144 (defbinding %threads-set-lock-functions (&optional) nil
1145 (%enter-fn callback)
1146 (%leave-fn callback))
1148 (defun threads-init ()
1149 (%threads-set-lock-functions)
1150 (setq *global-lock* (sb-thread:make-mutex :name "global GDK lock")))
1152 (defmacro with-global-lock (&body body)
1157 (threads-leave t))))
1159 (defun timeout-add-with-lock (interval function &optional (priority +priority-default+))
1160 (timeout-add interval
1162 (with-global-lock (funcall function)))
1165 (defun idle-add-with-lock (function &optional (priority +priority-default-idle+))
1168 (with-global-lock (funcall function)))
1174 (defmacro with-global-lock (&body body)
1177 (defun timeout-add-with-lock (interval function &optional (priority +priority-default+))
1178 (timeout-add interval function priority))
1180 (defun idle-add-with-lock (funcation &optional (priority +priority-default-idle+))
1181 (idle-add function priority)))