[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

3514.0. "More XSelectAsyncInput() help needed." by WPOPTH::ZAMBOTTI (It only works after you ask!) Tue Oct 23 1990 23:07

Hello again,

I am having problems either understanding async-input events or just using them!

I have a simple X library routine that selects async input for
StructureNotifyMask type events.

When ever the user resizes the window via the window manager resize gadget the
async call proceedure is called and the new size of window is correctly
reported.

This all works quiet well until a XSetFont() is called twice and then the
XSelectAsyncInput() call proceedure is never called again.

I was wondering if there is a particular method of calling X library routines
once an async input was declared so that that async input would not be
cancelled.

I have tried placing further XSelectAsyncInput() calls just after every
XSetFont() call but still the call proceedure is not entered.

Also XSetFont is not the only routine that cancels the XSelectAsyncInput()
routine, there are others but they are hard to pinpoint.

Following is some sample code which open a window draws it own simple buttons
and then waits for buttons to be cliked.

Clicking mouse button 3 (mb3) in the window will print the word "Hello" at that
point.  Clicking mb2 on the "Exit" button will terminate the program.

Clicking mb3 on the "Font" button will reselect the font (the same font).  Once
this button is pressed the async call proceedure will fail to function.

Try resizing the window.  You will notice that the buttons are redrawn and that
the window name reflects the new size of the window.  But this all stops the
moment you press on the "Font" button.

You may notice the XSelectAsyncInput() calls that are commented out in the code.
These were added in order to reset the async call proceedure, but that didn't
work either so they are now comments.

Please feel free to change the code.  If you can get it to always see the async
input routine I need to know what was done to achieve this.

----------------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 ;
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 ;
XFontStruct          *DotFont = NULL ;
int                  DeviceWidth = 640, DeviceHeight = 350, WindowResizeIntercept() ;

void readlocator_();
void initgraphics_();

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 == 130 && XPos < 50 && YPos < 50 && XPos > 0 && YPos > 0) {
                exit(0) ;
            }

            if(Button == 132 && XPos + YPos) {
                if(XPos > 50 && XPos < 100 && YPos < 50) {
                    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) ;
/*                  XSelectAsyncInput(Disp, Win1, StructureNotifyMask, WindowResizeIntercept, NULL) ; */
                    printf("Font\n") ;
                }
                else {
                    XDrawImageString(Disp, Win1, TextGC, XPos, YPos, "Hello", 5) ;
                    XFlush(Disp) ;
                }
            }
        }
    }
}


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) ;

    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) ;

    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) ;

    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) ;
    XSelectAsyncInput(Disp, Win1, StructureNotifyMask, WindowResizeIntercept, NULL) ;
}


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) ;
                XDrawRectangle(Disp, Win1, TextGC, 1, 1, 50, 50) ;
                XDrawImageString(Disp, Win1, TextGC, 4, 20, "Exit", 5) ;
                XDrawRectangle(Disp, Win1, TextGC, 50, 1, 50, 50) ;
                XDrawImageString(Disp, Win1, TextGC, 54, 20, "Font", 5) ;
                XFlush(Disp) ;
/*              XSelectAsyncInput(Disp, Win1, StructureNotifyMask, WindowResizeIntercept, NULL) ; */
                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 ;
        }
    }
}
T.RTitleUserPersonal
Name
DateLines
3514.1DECWIN::FISHERI like my species the way it is&quot; &quot;A narrow view...Thu Oct 25 1990 15:194
What version of VMS, please?  There were some bugs in, I think, V5.3 which were
fixed in V5.4.  Don't know for sure if this relates, but maybe.

Burns
3514.2ULTRIX 4.0 not VMS.WPOPTH::ZAMBOTTIIt only works after you ask!Sun Oct 28 1990 23:179
Hi,

re : .1

Not VMS but ULTRIX 4.0.  It seems to work OK from VMS!

regards,

Walter.
3514.3OXNARD::KLEEKen LeeMon Oct 29 1990 12:314
    Did you try Ultrix 4.1?
    
    Ken