CLIM mail archive


changing the mouse-glyph

   Date: Thu, 29 Oct 92 14:08:30 EST
   From: Clinton Hyde <>

   I'd like to change the mouse glyph occasionally. in particular, I want
   a spinning watch or rotating something-or-other, to show 'app-busy'
   sort of things to the user. I've looked at the pointer object for a
   window, it's not very indicative of what happens. there's a slot
   called CURSOR-PATTERN which is unbound (it's a slot for a window, such
   as the root, and NOT a slot for a frame, which is consistent with the
   CLX docs).

   my CLX book says you can (SETF (xlib:WINDOW-CURSOR win)
   -some-new-cursor-) but I haven't tried that, since I don't know what
   the cursor should be...

   any suggestions? I may just try creating a pattern and a new std-ptr
   and stuff it into a window and see what happens. I have this feeling
   that isn't quite good enough, however...

As CLIM does not directly support cursor shapes, you will have to do
this non-portably at the CLX level.  Here is some sample code.  It
creates a cursor pixmap by drawing something into it, then installs
that pixmap as the cursor for the given CLIM window.  You can draw
anything you like.  CLX also has support for installing font glyphs as
cursors, so you can use a font that has arrow glyphs, etc.

(in-package :clim-user)

(defun install-circle-cursor (win)
  ;; Get the CLX window object from the CLIM window using an
  ;; undocumented internal interface.
  (let* ((xwin (clim::clx-stream-window win))
	 (pixmap (xlib:create-pixmap :width 10 :height 10 :depth 1
				     :drawable xwin))
	 (mask-pixmap (xlib:create-pixmap :width 10 :height 10 :depth 1
					  :drawable xwin))
	 (pgc (xlib:create-gcontext :drawable pixmap :foreground 1 :background 0)))
    ;; Cursor foreground is all 1's
    (xlib:draw-rectangle pixmap pgc 0 0 10 10 t)
    ;; Don't know why I have to clear the pixmap first.
    (xlib:with-gcontext (pgc :foreground 0)
      (xlib:draw-rectangle mask-pixmap pgc 0 0 10 10 t))
    ;; Cursor mask is a circle, so the cursor is a "see-through" circle
    (xlib:draw-arc mask-pixmap pgc 2 2 6 6 0 (* pi 2) nil)
    (let ((cursor (xlib:create-cursor :source pixmap
				      :mask mask-pixmap
				      ;; set "hot spot" to center
				      :x 5 :y 5
				      :foreground (xlib:make-color
						    :red 0.0
						    :green 0.0
						    :blue 0.0)
				      :background (xlib:make-color
						    :red 1.0
						    :green 1.0
						    :blue 1.0))))
      ;; Install the cursor;
      (setf (xlib:window-cursor xwin) cursor))
    ;; Make the change take effect.
    (xlib:display-force-output (xlib:drawable-display xwin))))



Main Index | Thread Index