From: scott@talguy.cxo.dec.com (Scott Johnson)
Subject: Forget the previous note about trouble with clx and lcl.
Reply-To: scott@talguy.cxo.dec.com (Scott Johnson)
Organization: Digital Equipment Corporation, Colorado Springs, Co
Date: Wed, 9 Sep 1992 22:31:36 GMT


Return-Path: scott
To: gilroy::"dec-support@lucid.com"
Cc: scott, gldoa::fuller
Subject: More Information for CLX Problem and help requested.
Date: Wed, 09 Sep 92 16:26:05 -0600
From: scott
X-Mts: smtp

Hi,

There seems to be a problem between lcl and the xlib/clx routines. If you can
help any, I would appreciate it.

The problem is that the lisp stuff does not succeed as does the same thing 
in c.  To demonstrate the problem, I create two decterm windows with on being
titled "talguy" and the other being titled "csc32".  The one titled "csc32"
is the one that gets popped to the top or pushed to the bottom of the stack
of windows.  Oh yeah, the windows do occlude each other. The decterm labeled 
"talguy" is on the top of and partially occludes the decterm labeled "csc32".

To perform the test using the lisp code, simply load the code and invoke
(decwindows-toggle-up) followed by a call to (decwindows-toggle-down).  The
c code will do this automatically when it is executed.  To succeed, the decterm
labeled "csc32" should pop to the top of the stack and then get pushed to the 
bottom of the stack.

Scott Johnson

-------------
test.lisp
-------------
;
; This is used to test a problem with clx.  It seems to have trouble finding
; a match for the title name when it calls clx:wm-name.  Unless it finds a 
; match, knowledge-window and driver-window are set to nil.  If
; these two variables are set to nil, then the call to circulate-window-up
; and circulate-window-down fails.
;
(IN-PACKAGE "USER")

#.(if (equal "DEC ULTRIX" (software-type))
    (rename-package "XLIB" "XLIB" '("CLX"))
)
                                                               
(progn
    (defvar display (clx:open-display (machine-instance)))
    (defvar screen (clx:display-default-screen display))
    (defvar root (clx:screen-root screen))
    (defvar knowledge-window nil)
    (defvar driver-window nil)
)

(defun windowlist (window-id)
   (if (not (null window-id))
      (progn
         (setq win (clx:wm-name window-id))
         (if (not (equal "" win))
		(format nil "The wm-name for ~D is ~A." window-id win))
         (if (equal "csc32" win)
            (setq knowledge-window window-id))
         (mapcar #'(lambda (x) 
            (if (null knowledge-window) (windowlist x))
                   )
            (clx:query-tree window-id)))))

(defun windowlist1 (window-id)
   (if (not (null window-id))
      (progn
         (setq win (clx:wm-name window-id))
         (if (not (equal "" win))
		(format nil "The wm-name for ~D is ~A." window-id win))
         (if (equal "talguy" win)
            (setq driver-window window-id))
         (mapcar #'(lambda (x) 
            (if (null driver-window) (windowlist1 x))
                   )
            (clx:query-tree window-id)))))

(progn
   (windowlist  root)
   (windowlist1 root)
   (if (equal "DEC ULTRIX" (software-type)) 
       (shell "clear")
       (spawn :command-string "set terminal/width=80" :parallel t)
)  )

(defun decwindows-toggle-up (&rest ignore) 
    (clx:circulate-window-up knowledge-window)
    (clx:set-input-focus display knowledge-window :none)
    (clx:query-tree root)
)

(defun decwindows-toggle-down (&rest ignore) 
     (clx:circulate-window-down knowledge-window)
     (clx:set-input-focus display driver-window :none)
     (clx:query-tree root)
)

---------
test.c
---------
#include <stdio.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

void windowlist();
void windowlist1();
void decwindows_toggle_up();
void decwindows_toggle_down();
Display *dpy;
Screen *screen; 
Window root;
Window knowledge_window;
Window driver_window;

main()
{

    char c;

    if (!(dpy = XOpenDisplay(NULL))) {
        printf("Can't open display.\n"); 
	exit(-1);
    }

    if (!(screen = DefaultScreenOfDisplay(dpy))) {
        printf("Can't get default screen.\n");
	exit(-1);
    }

    if (!(root = RootWindow(dpy,DefaultScreen(dpy)))) {
        printf("Can't get root window of screen.\n");
        exit(-1);
    }

    windowlist(root); 

    windowlist1(root);    

    decwindows_toggle_up();

    sleep(3);

    decwindows_toggle_down();

    sleep(3);
}

void windowlist(window_id)
Window window_id;
{
    int status;
    XTextProperty txt;
    Window root,parent,*children,*child;
    int num_children,i,total;
   
    XGetWMName(dpy,window_id,&txt);
    if ((txt.value != NULL) && (txt.encoding == 31) && (txt.format == 8))
        if (!strcmp(txt.value,"csc32")) {
           knowledge_window = window_id;
           printf("Assigned knowledge_window\n");
        }
    if (knowledge_window == NULL) {
	if (!(status = XQueryTree(dpy,window_id,&root,&parent,
                            &children,&num_children))) 
	    printf("Failed in call to XQueryTree()\n");
	else {
		total = num_children; 
                child = children;
                for (i=0; i<total; i++, child++) windowlist(*child);
                XFree(children);
        }
    }
}

void windowlist1(window_id)
Window window_id;
{
    int status;
    XTextProperty txt;
    Window root,parent,*children,*child;
    int num_children,i,total;
   
    XGetWMName(dpy,window_id,&txt);
    if ((txt.value != NULL) && (txt.encoding == 31) && (txt.format == 8))
        if (!strcmp(txt.value,"talguy")) {
           driver_window = window_id;
           printf("Assigned driver_window\n");
        }
    if (driver_window == NULL) {
	if (!(status = XQueryTree(dpy,window_id,&root,&parent,
                            &children,&num_children))) 
	    printf("Failed in call to XQueryTree()\n");
	else {
		total = num_children; 
                child = children;
                for (i=0; i<total; i++, child++) windowlist1(*child);
                XFree(children);
        }
    }
}


void decwindows_toggle_up()
{
    int status;
    Window lroot,parent,*children;
    int num_children;

    XCirculateSubwindowsUp(dpy,knowledge_window);
    XSetInputFocus(dpy,knowledge_window,RevertToNone,CurrentTime);
    XQueryTree(dpy,root,&lroot,&parent,&children,&num_children); 
}

void decwindows_toggle_down()
{
    Window lroot,parent,*children;
    int num_children;

    XCirculateSubwindowsDown(dpy,knowledge_window);
    XSetInputFocus(dpy,driver_window,RevertToNone,CurrentTime);
    XQueryTree(dpy,root,&lroot,&parent,&children,&num_children);
}


----------------------------------------------------------------------------

   Scott Johnson
   Digital Equipment Corporation
   Colorado Springs, Co