From: Wang Yin
Subject: Why CLX demos don't work?
Date: 
Message-ID: <m3oewclm79.fsf@wangyin.com>
Hi,

I need some graphics utility in my code. I need only a canvas that I
can draw some lines, points, on it. I tried to use CLX with CMU
CL. And I tried the following code that comes with CMU CL source:



;;; -*- Mode:Lisp; Syntax: Common-lisp; Package:XLIB; Base:10; Lowercase: Yes -*-

(in-package :xlib)

(defun hello-world (host &rest args &key (string "Hello World") (font "fixed"))
  ;; CLX demo, says STRING using FONT in its own window on HOST
  (let ((display nil)
	(abort t))
    (unwind-protect
	(progn 
	  (setq display (open-display host))
	  (multiple-value-prog1
	    (let* ((screen (display-default-screen display))
		   (black (screen-black-pixel screen))
		   (white (screen-white-pixel screen))
		   (font (open-font display font))
		   (border 1)			; Minimum margin around the text
		   (width (+ (text-width font string) (* 2 border)))
		   (height (+ (max-char-ascent font) (max-char-descent font) (* 2 border)))
		   (x (truncate (- (screen-width screen) width) 2))
		   (y (truncate (- (screen-height screen) height) 2))
		   (window (create-window :parent (screen-root screen)
					  :x x :y y :width width :height height
					  :background black
					  :border white
					  :border-width 1
					  :colormap (screen-default-colormap screen)
					  :bit-gravity :center
					  :event-mask '(:exposure :button-press)))
		   (gcontext (create-gcontext :drawable window
					      :background black
					      :foreground white
					      :font font)))
	      ;; Set window manager hints
	      (set-wm-properties window
				 :name 'hello-world
				 :icon-name string
				 :resource-name string
				 :resource-class 'hello-world
				 :command (list* 'hello-world host args)
				 :x x :y y :width width :height height
				 :min-width width :min-height height
				 :input :off :initial-state :normal)
	      (map-window window)		; Map the window
	      ;; Handle events
	      (event-case (display :discard-p t :force-output-p t)
		(exposure  ;; Come here on exposure events
		  (window count)
		  (when (zerop count) ;; Ignore all but the last exposure event
		    (with-state (window)
		      (let ((x (truncate (- (drawable-width window) width) 2))
			    (y (truncate (- (+ (drawable-height window)
					       (max-char-ascent font))
					    (max-char-descent font))
					 2)))
			;; Draw text centered in widnow
			(clear-area window)
			(draw-glyphs window gcontext x y string)))
		    ;; Returning non-nil causes event-case to exit
		    nil))
		(button-press () t)))  ;; Pressing any mouse-button exits
	    (setq abort nil)))
      ;; Ensure display is closed when done
      (when display
	(close-display display :abort abort)))))


I required :clx first with (require :clx)
But when I execute the code. I get the error:

* 
; Loading #p"/usr/local/lib/cmucl/lib/subsystems/clx-library.x86f".
T
* 
#<The XLIB package, 1432/2372 internal, 560/590 external>
* 
HELLO-WORLD
* 
; In: LAMBDA (HOST &REST ARGS &KEY (STRING "Hello World") ...)

;   (WITH-STATE (WINDOW)
;               (LET #
;                 #
;                 #))
; --> WITH-STACK-LIST 
; ==>
;   (LET (#)
;     (DECLARE # #)
;     (WITH-STACK-LIST* # #))
; Note: DYNAMIC-EXTENT declaration not implemented.
; 
; --> WITH-STACK-LIST LET WITH-STACK-LIST* 
; ==>
;   (LET (#)
;     (DECLARE # #)
;     (MULTIPLE-VALUE-PROG1 # #))
; Note: DYNAMIC-EXTENT declaration not implemented.


Error in function OPEN-X-STREAM:
   Failed to connect to X11 server: wangyin (display 0)

Restarts:
  0: [ABORT] Return to Top-Level.

Debug  (type H for help)

(OPEN-X-STREAM "wangyin" 0 #<unused-arg>)
Source: Error finding source: 
Error in function DEBUG::GET-FILE-TOP-LEVEL-FORM:  Source file no longer exists:
  target:clx/dependent.lisp.
0] 

I've set my X server as xhost +. Why can't CLX connect to the server?

I don't think CLX suit my simple needs. Anyone has better suggestions
for a simpler graphics package?


-- 
Wang Yin
EDA Lab,
Deparment of Computer Science and Technology,
Tsinghua University,
100084
Beijing China
From: Eric Marsden
Subject: Re: Why CLX demos don't work?
Date: 
Message-ID: <wzifzhol0v6.fsf@melbourne.laas.fr>
>>>>> "wy" == Wang Yin <ยทยท@wangyin.com> writes:

  wy> Error in function OPEN-X-STREAM:
  wy> Failed to connect to X11 server: wangyin (display 0)

  wy> I've set my X server as xhost +. Why can't CLX connect to the server?

do xlib programs work when using the same display specifier?  Try
something like "xclock -display wangyin:0" to see whether that works.
It may be that your X11 server is only accepting local connections
(over a Unix socket). Check whether "netstat -an | grep 6000" has a
line saying that the server is listening for TCP connections. If not,
you can tell CLX to connect to your X11 server over a Unix socket, by
changing the line containing open-display to

   (xlib:open-display "localhost" :protocol :unix)


You can avoid disabling X11 authorization by using the function
EXT:OPEN-CLX-DISPLAY instead of XLIB:OPEN-DISPLAY. This CMUCL-specific
function is able to extract a "magic cookie" from your ~/.Xauthority
file and present it to the X server; see

   <URL:http://www.cons.org/cmucl/doc/clx-authorization.html>
   
-- 
Eric Marsden                          <URL:http://www.laas.fr/~emarsden/>