1 ;; Common Lisp bindings for GTK+ v2.x
2 ;; Copyright 2000-2005 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.23 2006-04-10 18:27:58 espen Exp $
30 (defbinding (gdk-init "gdk_parse_args") () nil
31 "Initializes the library without opening the display."
39 (defbinding %display-open () display
40 (display-name (or null string)))
42 (defun display-open (&optional display-name)
43 (let ((display (%display-open display-name)))
44 (unless (display-get-default)
45 (display-set-default display))
48 (defbinding %display-get-n-screens () int
51 (defbinding %display-get-screen () screen
55 (defun display-screens (&optional (display (display-get-default)))
57 for i from 0 below (%display-get-n-screens display)
58 collect (%display-get-screen display i)))
60 (defbinding display-get-default-screen
61 (&optional (display (display-get-default))) screen
64 (defbinding display-beep (&optional (display (display-get-default))) nil
67 (defbinding display-sync (&optional (display (display-get-default))) nil
70 (defbinding display-flush (&optional (display (display-get-default))) nil
73 (defbinding display-close (&optional (display (display-get-default))) nil
76 (defbinding display-get-event
77 (&optional (display (display-get-default))) event
80 (defbinding display-peek-event
81 (&optional (display (display-get-default))) event
84 (defbinding display-put-event
85 (event &optional (display (display-get-default))) event
89 (defbinding (display-connection-number "clg_gdk_connection_number")
90 (&optional (display (display-get-default))) int
97 (defbinding display-get-default () display)
99 (defbinding (display-manager "gdk_display_manager_get") () display-manager)
101 (defbinding (display-set-default "gdk_display_manager_set_default_display")
103 ((display-manager) display-manager)
110 (defbinding (events-pending-p "gdk_events_pending") () boolean)
112 (defbinding event-get () event)
114 (defbinding event-peek () event)
116 (defbinding event-get-graphics-expose () event
119 (defbinding event-put () event
122 ;(defbinding event-handler-set () ...)
124 (defbinding set-show-events () nil
125 (show-events boolean))
127 (defbinding get-show-events () boolean)
130 ;;; Miscellaneous functions
132 (defbinding screen-width () int)
133 (defbinding screen-height () int)
135 (defbinding screen-width-mm () int)
136 (defbinding screen-height-mm () int)
138 (defbinding pointer-grab
139 (window &key owner-events events confine-to cursor time) grab-status
141 (owner-events boolean)
143 (confine-to (or null window))
144 (cursor (or null cursor))
145 ((or time 0) (unsigned 32)))
147 (defbinding (pointer-ungrab "gdk_display_pointer_ungrab")
148 (&optional time (display (display-get-default))) nil
150 ((or time 0) (unsigned 32)))
152 (defbinding (pointer-is-grabbed-p "gdk_display_pointer_is_grabbed")
153 (&optional (display (display-get-default))) boolean)
155 (defbinding keyboard-grab (window &key owner-events time) grab-status
157 (owner-events boolean)
158 ((or time 0) (unsigned 32)))
160 (defbinding (keyboard-ungrab "gdk_display_keyboard_ungrab")
161 (&optional time (display (display-get-default))) nil
163 ((or time 0) (unsigned 32)))
167 (defbinding atom-intern (atom-name &optional only-if-exists) atom
168 ((string atom-name) string)
169 (only-if-exists boolean))
171 (defbinding atom-name () string
178 (defbinding visual-get-best-depth () int)
180 (defbinding visual-get-best-type () visual-type)
182 (defbinding visual-get-system () visual)
185 (defbinding (%visual-get-best-with-nothing "gdk_visual_get_best") () visual)
187 (defbinding %visual-get-best-with-depth () visual
190 (defbinding %visual-get-best-with-type () visual
193 (defbinding %visual-get-best-with-both () visual
197 (defun visual-get-best (&key depth type)
199 ((and depth type) (%visual-get-best-with-both depth type))
200 (depth (%visual-get-best-with-depth depth))
201 (type (%visual-get-best-with-type type))
202 (t (%visual-get-best-with-nothing))))
204 ;(defbinding query-depths ..)
206 ;(defbinding query-visual-types ..)
208 (defbinding list-visuals () (glist visual))
213 (defbinding window-destroy () nil
217 (defbinding window-at-pointer () window
221 (defbinding window-show () nil
224 (defbinding window-show-unraised () nil
227 (defbinding window-hide () nil
230 (defbinding window-is-visible-p () boolean
233 (defbinding window-is-viewable-p () boolean
236 (defbinding window-withdraw () nil
239 (defbinding window-iconify () nil
242 (defbinding window-deiconify () nil
245 (defbinding window-stick () nil
248 (defbinding window-unstick () nil
251 (defbinding window-maximize () nil
254 (defbinding window-unmaximize () nil
257 (defbinding window-fullscreen () nil
260 (defbinding window-unfullscreen () nil
263 (defbinding window-set-keep-above () nil
267 (defbinding window-set-keep-below () nil
271 (defbinding window-move () nil
276 (defbinding window-resize () nil
281 (defbinding window-move-resize () nil
288 (defbinding window-scroll () nil
293 (defbinding window-reparent () nil
299 (defbinding window-clear () nil
302 (defbinding %window-clear-area () nil
304 (x int) (y int) (width int) (height int))
306 (defbinding %window-clear-area-e () nil
308 (x int) (y int) (width int) (height int))
310 (defun window-clear-area (window x y width height &optional expose)
312 (%window-clear-area-e window x y width height)
313 (%window-clear-area window x y width height)))
315 (defbinding window-raise () nil
318 (defbinding window-lower () nil
321 (defbinding window-focus () nil
323 (timestamp unsigned-int))
325 (defbinding window-register-dnd () nil
328 (defbinding window-begin-resize-drag () nil
334 (timestamp unsigned-int))
336 (defbinding window-begin-move-drag () nil
341 (timestamp unsigned-int))
343 ;; komplett så langt
345 (defbinding window-set-user-data () nil
349 (defbinding window-set-override-redirect () nil
351 (override-redirect boolean))
353 ; (defbinding window-add-filter () nil
355 ; (defbinding window-remove-filter () nil
357 (defbinding window-shape-combine-mask () nil
363 (defbinding window-set-child-shapes () nil
366 (defbinding window-merge-child-shapes () nil
370 (defbinding window-set-static-gravities () boolean
372 (use-static boolean))
374 ; (defbinding add-client-message-filter ...
376 (defbinding window-set-cursor () nil
378 (cursor (or null cursor)))
380 (defbinding window-get-pointer () window
384 (mask modifier-type :out))
386 (defbinding %window-get-toplevels () (glist window))
388 (defun window-get-toplevels (&optional screen)
390 (error "Not implemented")
391 (%window-get-toplevels)))
393 (defbinding %get-default-root-window () window)
395 (defun get-root-window (&optional display)
397 (error "Not implemented")
398 (%get-default-root-window)))
406 (defbinding drag-status () nil
407 (context drag-context)
409 (time (unsigned 32)))
418 (defbinding rgb-init () nil)
425 (defmethod allocate-foreign ((cursor cursor) &key type mask fg bg
426 (x 0) (y 0) (display (display-get-default)))
428 (keyword (%cursor-new-for-display display type))
429 (pixbuf (%cursor-new-from-pixbuf display type x y))
430 (pixmap (%cursor-new-from-pixmap type mask fg bg x y))))
433 (defbinding %cursor-new-for-display () pointer
435 (cursor-type cursor-type))
437 (defbinding %cursor-new-from-pixmap () pointer
444 (defbinding %cursor-new-from-pixbuf () pointer
449 (defbinding %cursor-ref () pointer
452 (defbinding %cursor-unref () nil
455 (defmethod reference-foreign ((class (eql (find-class 'cursor))) location)
456 (declare (ignore class))
457 (%cursor-ref location))
459 (defmethod unreference-foreign ((class (eql (find-class 'cursor))) location)
460 (declare (ignore class))
461 (%cursor-unref location))
466 (defbinding pixmap-new (width height depth &key window) pixmap
470 (window (or null window)))
472 (defbinding %pixmap-colormap-create-from-xpm () pixmap
473 (window (or null window))
474 (colormap (or null colormap))
476 (color (or null color))
479 (defbinding %pixmap-colormap-create-from-xpm-d () pixmap
480 (window (or null window))
481 (colormap (or null colormap))
483 (color (or null color))
484 (data (vector string)))
486 (defun pixmap-create (source &key color window colormap)
488 (if (not (or window colormap))
491 (multiple-value-bind (pixmap mask)
493 ((or string pathname)
494 (%pixmap-colormap-create-from-xpm
495 window colormap color (namestring (truename source))))
497 (%pixmap-colormap-create-from-xpm-d window colormap color source)))
498 ;; (unreference-instance pixmap)
499 ;; (unreference-instance mask)
500 (values pixmap mask))))
506 (defbinding %color-copy () pointer
509 (defmethod allocate-foreign ((color color) &rest initargs)
510 (declare (ignore color initargs))
511 ;; Color structs are allocated as memory chunks by gdk, and since
512 ;; there is no gdk_color_new we have to use this hack to get a new
514 (with-memory (location #.(foreign-size (find-class 'color)))
515 (%color-copy location)))
517 (defun %scale-value (value)
520 (float (truncate (* value 65535)))))
522 (defmethod initialize-instance ((color color) &rest initargs
524 (declare (ignore initargs))
526 (with-slots ((%red red) (%green green) (%blue blue)) color
528 %red (%scale-value red)
529 %green (%scale-value green)
530 %blue (%scale-value blue))))
532 (defbinding color-parse (spec &optional (make-instance 'color)) boolean
534 (color color :in/return))
536 (defun ensure-color (color)
541 (make-instance 'color
542 :red (svref color 0) :green (svref color 1) :blue (svref color 2)))
544 (multiple-value-bind (succeeded-p color) (parse-color color)
547 (error "Parsing color specification ~S failed." color))))))
553 (defbinding drawable-get-size () nil
558 (defbinding (drawable-width "gdk_drawable_get_size") () nil
563 (defbinding (drawable-height "gdk_drawable_get_size") () nil
568 ;; (defbinding drawable-get-clip-region () region
569 ;; (drawable drawable))
571 ;; (defbinding drawable-get-visible-region () region
572 ;; (drawable drawable))
574 (defbinding draw-point () nil
575 (drawable drawable) (gc gc)
578 (defbinding %draw-points () nil
579 (drawable drawable) (gc gc)
583 ;; (defun draw-points (drawable gc &rest points)
587 (defbinding draw-line () nil
588 (drawable drawable) (gc gc)
592 ;; (defbinding draw-lines (drawable gc &rest points) nil
593 ;; (drawable drawable) (gc gc)
594 ;; (points (vector point))
595 ;; ((length points) int))
597 (defbinding draw-pixbuf
598 (drawable gc pixbuf src-x src-y dest-x dest-y &optional
599 width height (dither :none) (x-dither 0) (y-dither 0)) nil
600 (drawable drawable) (gc (or null gc))
602 (src-x int) (src-y int)
603 (dest-x int) (dest-y int)
604 ((or width -1) int) ((or height -1) int)
606 (x-dither int) (y-dither int))
608 ;; (defbinding draw-segments (drawable gc &rest points) nil
609 ;; (drawable drawable) (gc gc)
610 ;; (segments (vector segments))
611 ;; ((length segments) int))
613 (defbinding draw-rectangle () nil
614 (drawable drawable) (gc gc)
617 (width int) (height int))
619 (defbinding draw-arc () nil
620 (drawable drawable) (gc gc)
623 (width int) (height int)
624 (angle1 int) (angle2 int))
626 ;; (defbinding draw-polygon (drawable gc &rest points) nil
627 ;; (drawable drawable) (gc gc)
628 ;; (points (vector point))
629 ;; ((length points) int))
631 ;; (defbinding draw-trapezoid (drawable gc &rest points) nil
632 ;; (drawable drawable) (gc gc)
633 ;; (points (vector point))
634 ;; ((length points) int))
636 ;; (defbinding %draw-layout-line () nil
637 ;; (drawable drawable) (gc gc)
640 ;; (line pango:layout-line))
642 ;; (defbinding %draw-layout-line-with-colors () nil
643 ;; (drawable drawable) (gc gc)
646 ;; (line pango:layout-line)
647 ;; (foreground (or null color))
648 ;; (background (or null color)))
650 ;; (defun draw-layout-line (drawable gc font x y line &optional foreground background)
651 ;; (if (or foreground background)
652 ;; (%draw-layout-line-with-colors drawable gc font x y line foreground background)
653 ;; (%draw-layout-line drawable gc font x y line)))
655 (defbinding %draw-layout () nil
656 (drawable drawable) (gc gc)
659 (layout pango:layout))
661 (defbinding %draw-layout-with-colors () nil
662 (drawable drawable) (gc gc)
665 (layout pango:layout)
666 (foreground (or null color))
667 (background (or null color)))
669 (defun draw-layout (drawable gc font x y layout &optional foreground background)
670 (if (or foreground background)
671 (%draw-layout-with-colors drawable gc font x y layout foreground background)
672 (%draw-layout drawable gc font x y layout)))
674 (defbinding draw-drawable
675 (drawable gc src src-x src-y dest-x dest-y &optional width height) nil
676 (drawable drawable) (gc gc)
678 (src-x int) (src-y int)
679 (dest-x int) (dest-y int)
680 ((or width -1) int) ((or height -1) int))
682 (defbinding draw-image
683 (drawable gc image src-x src-y dest-x dest-y &optional width height) nil
684 (drawable drawable) (gc gc)
686 (src-x int) (src-y int)
687 (dest-x int) (dest-y int)
688 ((or width -1) int) ((or height -1) int))
690 (defbinding drawable-get-image () image
693 (width int) (height int))
695 (defbinding drawable-copy-to-image
696 (drawable src-x src-y width height &optional image dest-x dest-y) image
698 (image (or null image))
699 (src-x int) (src-y int)
700 ((if image dest-x 0) int)
701 ((if image dest-y 0) int)
702 (width int) (height int))
707 (defbinding keyval-name () string
708 (keyval unsigned-int))
710 (defbinding %keyval-from-name () unsigned-int
713 (defun keyval-from-name (name)
714 "Returns the keysym value for the given key name or NIL if it is not a valid name."
715 (let ((keyval (%keyval-from-name name)))
716 (unless (zerop keyval)
719 (defbinding keyval-to-upper () unsigned-int
720 (keyval unsigned-int))
722 (defbinding keyval-to-lower () unsigned-int
723 (keyval unsigned-int))
725 (defbinding (keyval-is-upper-p "gdk_keyval_is_upper") () boolean
726 (keyval unsigned-int))
728 (defbinding (keyval-is-lower-p "gdk_keyval_is_lower") () boolean
729 (keyval unsigned-int))
731 ;;; Cairo interaction
735 (defbinding cairo-create () cairo:context
738 (defmacro with-cairo-context ((cr drawable) &body body)
739 `(let ((,cr (cairo-create ,drawable)))
742 (unreference-foreign 'cairo:context (foreign-location ,cr))
743 (invalidate-instance ,cr))))
745 (defbinding cairo-set-source-color () nil
749 (defbinding cairo-set-source-pixbuf () nil
755 (defbinding cairo-rectangle () nil
757 (rectangle rectangle))
759 ;; (defbinding cairo-region () nil
760 ;; (cr cairo:context)