[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

3242.0. "Configure Notify Events VMS vs ULTRIX" by WPOMM2::ZAMBOTTI (It only works after you ask!) Wed Aug 22 1990 04:22

    Hello,
    
    I have been working on an application that needs to receive an event
    when ever the user resizes the window via the window manager by using
    the resize gadget.
    
    I have the code working fime on VMS DECwindows by using the
    XSelectAsyncInput() routine.  Unfortunately this doesn't seem to work
    under ULTRIX DECwindows 2.2(d).
    
    What happens with both the VMS and ULTRIX version is ;- when the window
    is first created my async routine gets called three times once when the
    window is created once for the backing pixel mapping and once for the
    window resize request.   This would indicate that the
    XSelectAsyncInput() routine has functioned correctly, because my async
    event routine is reached (3 times).
    
    What happens in the VMS version after the window is opened is when ever
    the window is resized then my async routine is executed again and this
    is what I execepted.  I have print statements in the code so I know for
    sure that routine is entered.
    
    But in the ULTRIX version it doesn't matter how many times you resize
    the async routine is never executed.
    
    My code fragments follow 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
#include "halo.h"

Display              *Disp = NULL ;
Screen               *Screen1 ;
Visual               *DefScreenVis ;
GC                   GCID, TextCurGC, TextGC, HatchGC, MoveGC, LineGC, TempGC, BandGC ;
Window               Win1, DefRootWin ;
XSetWindowAttributes WinAttr ;
XGCValues            GCVals ;
Window               FocusReturn ;
int                  RevertToReturn, XErrorIntersept() ;
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                  HaloErrCode = 0, HaloFunc = 0, WindowResizeIntercept() ;
extern int           TextForeground, TextBackground, DeviceWidth, DeviceHeight ;


void initgraphics_(mode)

short int     *mode ;

{
char    WindowName[20] ;

    HaloFunc = 113 ;

    if(Disp != NULL) {
        return ;
    }

    Disp = XOpenDisplay(NULL) ;

    if(Disp == NULL) {
        HaloErrCode = 3 ;
        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 ; /* have also tried NotUseful but no different */
                                                                         
    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) ;
}

extern int   DeviceWidth, DeviceHeight ;
extern float WorldWidth, WorldHeight ;

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 ;
        }
    }
}
    
    
    I assume that because the async routine is only called because of an
    event in the first place that the XPending() call is not necessary, but
    anyway I have it.
    
    Can anyone shed some light on why this fails on ULTRIX but works on VMS
    and also how I can get it going!
    
    Regards,
    
    Walter Zambotti.
T.RTitleUserPersonal
Name
DateLines
3242.1ABYSS::dikeWed Aug 22 1990 09:217
You don't call XSelectInput anywhere.  XSelectAsyncInput doesn't cause any X
protocol.  It is just an addition to Xlib, so you have to XSelectInput on any
events you want to receive asynchronously.

If it works on VMS, then it looks like they changed XSelectAsyncInput to call
XSelectInput.  That wasn't the way it was originally designed.
				Jeff
3242.2GILROY::kleeKen LeeWed Aug 22 1990 13:517
He shouldn't need an XSelectInput since the event mask is contained in
the XCreateWindow request.

There were bugs in the UWS2.2 version of XSelectAsyncEvent.  Please try
a more recent version.  Your program is not complete, so I couldn't try it here.

Ken
3242.3ABYSS::dikeWed Aug 22 1990 14:004
I didn't notice the create call.  Consider my objection withdrawn.

It would be nice to have a complete program that can be compiled and run.
				Jeff
3242.4The complete (isolated) code...WPOMM2::ZAMBOTTIIt only works after you ask!Wed Aug 22 1990 23:05163
    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 ;
        }
    }
}
3242.5GILROY::kleeKen LeeThu Aug 23 1990 14:134
I tried it on my UWS4.0 PMAX and the async events came through fine.  I
recommend that you upgrade to UWS4.0 or later.

Ken
3242.6Font selection breaks async inputWPOMM2::ZAMBOTTIIt only works after you ask!Thu Sep 20 1990 02:32200
    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 ;
        }
    }
}