|  |     Hi again,
    
    actually there's not much more that you would need to test these
    routines, but here is a complete piece of code.  I couldn't test it
    because the station I am developing this piece of code on is out on a
    developers site.  But it should be close bar a few typos.
    The program should just open a small window (640*350) and then loop
    around waiting for button presses.  To exit press the right mouse
    button in the top left 10*10 corner of the window or break out.
    Another pain in the but is the code for readlocator_() the VMS version
    correctly reports the child window that the mouse was clicked in but in
    the ULTRIX version I have had to comment this out because it doesn't
    work either.
    ------------------Cut here-------------------
    
#include <stdio.h>
#ifdef VMS
#include <decw$include/Xlib.h>
#include <decw$include/Xutil.h>
#include <decw$include/Xatom.h>
#else
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#endif
Display              *Disp = NULL ;
Screen               *Screen1 ;
Visual               *DefScreenVis ;
Window               Win1, DefRootWin ;
XSetWindowAttributes WinAttr ;
Window               FocusReturn ;
int                  RevertToReturn ;
XWMHints             Win1WMHints = { InputHint|StateHint, FALSE, NormalState, 0, 0, 0, 0, 0 } ;
XSizeHints           Win1SizeHints = { USPosition|USSize|PMinSize|PMaxSize, 0, 0, 640, 350, 640, 350, 1020, 840 } ;
XWindowChanges       WindowChange ;
int                  DeviceWidth = 640, DeviceHeight = 350, WindowResizeIntercept() ;
main()
{
short int XPos, YPos, Button ;
    initgraphics_(0) ;
    
    for(;;)
    {
        readlocator_(&XPos, &YPos, &Button) ;
        if(Button) {
            printf("Rodent activity detected @ %d %d with button %d\n", XPos, YPos, Button) ;
            if(Button == 132 && XPos < 10 && YPos > 10) {
                exit(0) ;
            }
        }
    }
}
    
void initgraphics_(mode)
short int     *mode ; /* not used */
{
char    WindowName[20] ;
    if(Disp != NULL) {
        return ;
    }
    Disp = XOpenDisplay(NULL) ;
    if(Disp == NULL) {
        return ;
    }
    printf("\033]21;Surpac Text\033\\") ; /* Rename the terminal window */
    printf("\033]2L;Surpac Text\033\\") ; /* Rename the terminal window icon */
    Screen1 = XDefaultScreenOfDisplay(Disp) ;
    DefRootWin = XDefaultRootWindow(Disp) ;
    DefScreenVis = XDefaultVisualOfScreen(Screen1) ;
    WinAttr.event_mask = StructureNotifyMask ;
    WinAttr.background_pixel = XBlackPixel(Disp, XDefaultScreen(Disp)) ;
    WinAttr.backing_store = Always ;
    Win1 = XCreateWindow(Disp, DefRootWin, 0, 0, 1020, 840, 0, CopyFromParent, InputOutput, CopyFromParent,
              CWEventMask|CWBackPixel|CWBackingStore, &WinAttr) ;
    XSelectAsyncInput(Disp, Win1, StructureNotifyMask, WindowResizeIntercept, NULL) ;
    sprintf(WindowName, "Surpac : %d %d", DeviceWidth, DeviceHeight) ;
    XStoreName(Disp, Win1, WindowName) ;
    XSetIconName(Disp, Win1, "Surpac Mining") ;
    WindowChange.width = Win1SizeHints.width = DeviceWidth ;
    WindowChange.height = Win1SizeHints.height = DeviceHeight ;
    XSetNormalHints(Disp, Win1, &Win1SizeHints) ;
    XConfigureWindow(Disp, Win1, CWWidth | CWHeight, &WindowChange) ;
    XMapWindow(Disp, Win1) ;
    XGetInputFocus(Disp, &FocusReturn, &RevertToReturn) ;
}
XEvent       WindowResize ;
WindowResizeIntercept(NotUsed)
long    NotUsed ;
{
char    WindowName[20] ;
    /* the next  "if" is redundant because this routine will only be called if an event has occurred anyway */
    if(XPending(Disp)) {                         
        XNextEvent(Disp, &WindowResize) ;
        switch(WindowResize.xconfigure.type) {
            case ConfigureNotify :
                DeviceWidth = WindowResize.xconfigure.width ;
                DeviceHeight = WindowResize.xconfigure.height ;
                printf("Surpac : %d %d\n", DeviceWidth, DeviceHeight) ;
                sprintf(WindowName, "Surpac : %d %d", DeviceWidth, DeviceHeight) ;
                XStoreName(Disp, Win1, WindowName) ;
                break ;
        }
    }
}
void readlocator_(x, y, status)
short int     *x, *y, *status ;
{
int     RootX, RootY, WinX, WinY, ButtonMask ;
Window  Root, Child ;
#ifdef VMS
    if(XQueryPointer(Disp, Win1, &Root, &Child, &RootX, &RootY, &WinX, &WinY, &ButtonMask) && Child == Win1) {
#else
    if(XQueryPointer(Disp, Win1, &Root, &Child, &RootX, &RootY, &WinX, &WinY, &ButtonMask) && /* Child == Win1 */) {
#endif
        if(WinX < 0 || WinX >= DeviceWidth || WinY < 0 || WinY >= DeviceHeight) {
            WinX = WinY = 0 ;
        }
        *x = WinX ;
        *y = WinY ;
        switch(ButtonMask & (Button1Mask | Button2Mask | Button3Mask)) {
            case Button1Mask : case Button2Mask : *status = 130 ; break ;
            case Button3Mask :                    *status = 132 ; break ;
            default :                             *status = 0 ;   break ;
        }
    }
}
 | 
|  |     Hi again,
    
    thankyou I have upgraded to 4.0 and still the problem exists.  With Ken
    Lee's Help I have managed to get the provided example (re . 4) working,
    thanks.
    
    I have found the problem in my application code.  When ever certain
    other X functions are called then the requested async input seems to
    turn off.
    
    In the example that follows you may resize the window as many times as
    you like (the new size is displayed in the window top border).  But if
    you change the font (XSetFont()) more than once then the async routine
    is no longer called.
    
    To change the font press MB3 (mouse button 3) where you would like the
    text to appear then press MB3 in the top left corner (X > 10 & X < 20 &
    Y > 10 & Y < 20).
    
    If you press in the font set area (described above) once then resize
    the window you will notice the window name change.  But change the font
    twice and resize the window you will notice the window name will not
    change.  The async input routine has somehow being cancelled.
    
    The code follows below.  I only tried this on the DECstation and not on
    VMS (could somebody try this for me).
    
    -----------------------------------------------------------------------
    
#include <stdio.h>
#ifdef VMS
#include <decw$include/Xlib.h>
#include <decw$include/Xutil.h>
#include <decw$include/Xatom.h>
#else
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#endif
Display              *Disp = NULL ;
Screen               *Screen1 ;
Visual               *DefScreenVis ;
Window               Win1, DefRootWin ;
XSetWindowAttributes WinAttr ;
Window               FocusReturn ;
XGCValues            GCVals ;
GC                   TextGC ;
int                  RevertToReturn ;
XWMHints             Win1WMHints = { InputHint|StateHint, False, NormalState, 0, 0, 0, 0, 0 } ;
XSizeHints           Win1SizeHints = { USPosition|USSize|PMinSize|PMaxSize, 0, 0, 640, 350, 640, 350, 1020, 840 } ;
XWindowChanges       WindowChange ;
int                  DeviceWidth = 640, DeviceHeight = 350, WindowResizeIntercept() ;
void readlocator_();
void initgraphics_();
main()
{
short int          XPos, YPos, Button, LastX, LastY ;
static XFontStruct *DotFont = NULL ;
    initgraphics_(0) ;
    
    for(;;)
    {
        readlocator_(&XPos, &YPos, &Button) ;
        if(Button) {
            printf("Rodent activity detected @ %d %d with button %d\n", XPos, YPos, Button) ;
            if(Button == 132 && XPos < 10 && YPos < 10) {
                exit(0) ;
            }
            if(Button == 132 && XPos < 20 && YPos < 20) {
                if(DotFont) {
                    XFreeFont(Disp, DotFont) ;
                }
		if((DotFont = XLoadQueryFont(Disp, "-dec-terminal-medium-r-wide--14-140-*-c-120-iso8859-1")) == NULL) {
		    fprintf(stderr, "Can't find font\n") ;
		    exit(1) ;
		}
                XSetFont(Disp, TextGC, DotFont->fid) ;
                XDrawImageString(Disp, Win1, TextGC, LastX, LastY, "Hello", 5) ;
                XFlush(Disp) ;
                printf("Font\n") ;
            }
            LastX = XPos ;
            LastY = YPos ;
        }
    }
}
    
void initgraphics_(mode)
short int     *mode ; /* not used */
{
char    WindowName[20] ;
    if(Disp != NULL) {
        return ;
    }
    Disp = XOpenDisplay(NULL) ;
    if(Disp == NULL) {
        return ;
    }
    Screen1 = XDefaultScreenOfDisplay(Disp) ;
    DefRootWin = XDefaultRootWindow(Disp) ;
    DefScreenVis = XDefaultVisualOfScreen(Screen1) ;
    WinAttr.event_mask = StructureNotifyMask ;
    WinAttr.background_pixel = XBlackPixel(Disp, XDefaultScreen(Disp)) ;
    WinAttr.backing_store = Always ;
    Win1 = XCreateWindow(Disp, DefRootWin, 0, 0, 1020, 840, 0, CopyFromParent,
	InputOutput, CopyFromParent,
	CWEventMask|CWBackPixel|CWBackingStore, &WinAttr) ;
    XSelectAsyncInput(Disp, Win1, StructureNotifyMask, WindowResizeIntercept, NULL) ;
    sprintf(WindowName, "Surpac : %d %d", DeviceWidth, DeviceHeight) ;
    XStoreName(Disp, Win1, WindowName) ;
    XSetIconName(Disp, Win1, "Surpac Mining") ;
    GCVals.background = XBlackPixelOfScreen(XDefaultScreenOfDisplay(Disp)) ;
    GCVals.foreground = XWhitePixelOfScreen(XDefaultScreenOfDisplay(Disp)) ;
    TextGC = XCreateGC(Disp, Win1, (GCForeground | GCBackground), &GCVals) ;
    WindowChange.width = Win1SizeHints.width = DeviceWidth ;
    WindowChange.height = Win1SizeHints.height = DeviceHeight ;
    XSetNormalHints(Disp, Win1, &Win1SizeHints) ;
    XConfigureWindow(Disp, Win1, CWWidth | CWHeight, &WindowChange) ;
    XMapWindow(Disp, Win1) ;
    XGetInputFocus(Disp, &FocusReturn, &RevertToReturn) ;
}
XEvent       WindowResize ;
WindowResizeIntercept(NotUsed)
long    NotUsed ;
{
char    WindowName[20] ;
        XNextEvent(Disp, &WindowResize) ;
        switch(WindowResize.xconfigure.type) {
            case ConfigureNotify :
                DeviceWidth = WindowResize.xconfigure.width ;
                DeviceHeight = WindowResize.xconfigure.height ;
                printf("async event received : %d %d\n", DeviceWidth, DeviceHeight) ;
                sprintf(WindowName, "Surpac : %d %d", DeviceWidth, DeviceHeight) ;
                XStoreName(Disp, Win1, WindowName) ;
		XFlush(Disp);
                break ;
        }
}
void readlocator_(x, y, status)
short int     *x, *y, *status ;
{
int     RootX, RootY, ButtonMask ;
short int WinX, WinY;
Window  Root, Child ;
#ifdef VMS
    if(XQueryPointer(Disp, Win1, &Root, &Child, &RootX, &RootY,
	&WinX, &WinY, &ButtonMask) && Child == Win1) {
#else
    if(XQueryPointer(Disp, Win1, &Root, &Child, &RootX, &RootY,
	&WinX, &WinY, &ButtonMask) /* && Child == Win1 */) {
#endif
	if(WinX < 0 || WinX >= DeviceWidth || WinY < 0 || WinY >= DeviceHeight)
	    WinX = WinY = 0 ;
        *x = WinX ;
        *y = WinY ;
        switch(ButtonMask & (Button1Mask | Button2Mask | Button3Mask)) {
            case Button1Mask : case Button2Mask : *status = 130 ; break ;
            case Button3Mask :                    *status = 132 ; break ;
            default :                             *status = 0 ;   break ;
        }
    }
}
    
 |