[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

2717.0. "Change pointer shape on root window & back" by PEACHS::BELDIN () Fri May 04 1990 12:55

	A customer has written some code that changes the cursor to a 	
	watch for the entire screen of his workstation, while some action
	he has triggered is processing.  He wanted to be able to get
	back the original cursor back from the server before he did this
	so that he could restore it.

	Using the following code fragment

	XGetWindowProperty(window_display,          /* display for shell */
                       root,                    /* root window       */
                       XA_RESOURCE_MANAGER,     /* property_id       */
                       0,                       /* offset of data    */
                       100000/sizeof(long),     /* length of data    */
                       False,                   /* delete property?  */
                       PropertyType,            /* type of property  */
                       &PropertyType,           /* -- XA_STRING --   */
                       &PropertyFormat,         /* format - data type*/
                       &items,                  /* number of items   */
                       &bytesAfter,             /* number remaining  */
                       &value);                 /* array of property data */
                                                                                

	db = XrmGetStringDatabase(value);

	XrmGetResource(db,                          /* database id      */
                   "sm.pointer_shape",          /* name of resource */
                   NULL,                        /* class - no class name on
                                                   session manager */
                   &type,                       /* representation type */
                   &pointer_shape);             /* where shape is returned */


	The value returned to him in the pointer_shape.addr is a negative
	number.   He is running his application remotely from an Ultrix
	workstation on a VMS machine.

	Would he be running into strange problems if the fonts for 
	VMS and Ultrix do not match?  I'm not sure of the 'proper' way
	to save the pointer shape, change it and then set it back.  Is
	there a better way to achieve this?

	Rick Beldin
	Atlanta CSC








                                


















                                
T.RTitleUserPersonal
Name
DateLines
2717.1Use X{Set,Get}WindowAttributesOPHION::MIKEYMike YangFri May 04 1990 17:039
    Looking for the value of the sm.pointer_shape resource depends on the
    session manager, and also, VMS and Ultrix have different conventions
    for whether MIT cursor shapes have positive or negative values.  Also,
    the root window may be using a pixmap cursor.
    
    The correct way to save the cursor is to use XGetWindowAttributes to
    get the cursor of the root window, save this value, and use
    XSetWindowAttributes to set a new cursor.  When you're all done, use
    XSetWindowAttributes to restore the old cursor value.
2717.2XWindowAttributes has no cursorPEACHS::BELDINThu Jun 14 1990 14:5329
	Other things got in the way...

>    Looking for the value of the sm.pointer_shape resource depends on the
>    session manager, and also, VMS and Ultrix have different conventions
>    for whether MIT cursor shapes have positive or negative values.  Also,
>    the root window may be using a pixmap cursor.

	Good info - thanks. 

>    
>    The correct way to save the cursor is to use XGetWindowAttributes to
>    get the cursor of the root window, save this value, and use
>    XSetWindowAttributes to set a new cursor.  When you're all done, use
>    XSetWindowAttributes to restore the old cursor value.

	I have a question about this - XGetWindowAttributes takes as input
	a display, a window id and a XWindowAttributes structure.  Nowhere
	is there a mention of a 'cursor' in this structure.  Now, the
	XSetWindowAttributes structure does have a cursor field - but
	it appears to be used only by the XChangeAttributes routine.
	
	This doesn't appear to make sense.  On the one hand, you can 
	'get' certain attributes about a window, and set others, but there
	does not appear to be a one to one correspondence between the 
	attributes that you can CHANGE and those you can GET.  

	Could someone elaborate on this somewhat?

	Rick (Lost in X...)
2717.3XDefineCursor and XUndefineCursor did it...PEACHS::BELDINMon Jun 18 1990 15:21148
	Well, I took a slightly different tack to solving this problem.
	I did a XDefineCursor to set up the cursor, using the cursor
	font indices in the CursorFont.h file.  An UndefineCursor will
	reset the cursor to whatever it was set in your session manager.
	It works on VMS and Ultrix... 

	An interesting effect happens if you don't do an XUndefineCursor.
	The cursor stays whatever it was that you set it to, until you
	go to Customize Pointer under the session manager and force it
	to change.  You can get your Enterprise cursor if you want it...

	What follows is a short program that will change the cursor to
	a watch for the entire screen, and then restores it back to what
	it was.

/*****************************************************************************
**
** COPYRIGHT (c) 1988 BY
** DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
** ALL RIGHTS RESERVED
**
** THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE  WITHOUT  NOTICE
** AND  SHOULD  NOT  BE  CONSTRUED  AS  A COMMITMENT BY DIGITAL EQUIPMENT
** CORPORATION.
**
** DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR  RELIABILITY  OF  ITS
** SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
**
This sample program has been tested using on VMS V5.3-1 and DECwindows V2.0.  
However, we cannot guarantee its effectiveness because of the possibility of 
errors in transmitting or implementing it.  It is meant to
be used as a template for writing your own program, and it may require
modification for use on your system.  

*****************************************************************************/

/*
**  Include files
*/
#include <stdio.h>
#include <decw$include/cursorfont.h>
#include <decw$include/X.h>                                                
#include <decw$include/Xlib.h>
#include <decw$include/Xutil.h>
#include <decw$include/Xatom.h>   
/*
**  Function Prototypes
*/

Window WmRootWindow (Display*, Window);

/*****************************************************************************
**  main
**
**  FUNCTIONAL DESCRIPTION:
**
**  FORMAL PARAMETERS:
**
**      argc - Count of arguments passed on the command line.
**
**	argv - Array of pointers to command line arguments. If specified,
**	       argv[1] is assumed to point to the input file name string.
**
*****************************************************************************/
main(int argc, char *argv[])
{

    int input_width, input_height,  /* width and height of image            */
        fid,			    /* ddif frame id			    */
        psid,			    /* presentation surface id              */
        screen,			    /* screen number                        */
        X,Y,			    /* X,Y coordinates of this window	    */
				    /* relative to its parent		    */
        HEIGHT,WIDTH,		    /* Height and width of window in pels   */
        border_width,		    /* Width of window border in pels	    */
        DEPTH;			    /* Z depth of window		    */

    Window root,wmroot;		    /* Returned root window identifier	    */

    Display *display;		    /* display				    */

    char name[80];			    /* Character string data	    */

    Cursor watchcursor;

    char foo[10];

    /*
    **	Open connect to display
    */
    if (!(display = XOpenDisplay(getenv("DECW$DISPLAY"))))
	{
	    perror("Can't open display");
	    exit(-1);
	}

    /*
    **  Get screen stuff
    */
    screen = DefaultScreen(display);
    root = RootWindow(display, screen);
    wmroot = WmRootWindow(display, root);
    wmroot = WmRootWindow(display, wmroot);

    printf ("Change the cursor to a watch\n");
    watchcursor = XCreateFontCursor(display,XC_watch);
    XDefineCursor(display,wmroot,watchcursor);
    XFlush(display);	    

    printf ("Change the cursor back to default\n");
    gets (foo);
    
    XUndefineCursor(display,wmroot);
    XSync(display, True);

} /* main */

Window WmRootWindow (Display *dpy, Window root)
{
    Window parent;
    Window *child;
    unsigned int nchildren;
    XWindowAttributes rootatt, childatt;
    if (!XGetWindowAttributes (dpy, root, &rootatt)) {
	fprintf (stderr, "XGetWindowAttributes on root failed.\n");
	exit(1);
    }

    if (XQueryTree (dpy, root, &root, &parent, &child, &nchildren)) {
	int i;
	for (i = 0; i < nchildren; i++) {
	    if (!XGetWindowAttributes (dpy, child[i], &childatt)) {
		fprintf (stderr, "XGetWindowAttributes on child failed.\n");
		exit(1);
	    }
	    if ((rootatt.width == childatt.width) &&
		(rootatt.height == childatt.height))
		return child[i];
	}
	return root;
    } else {
	fprintf (stderr, "XQueryTree failed (window doesn't exist).\n");
	exit(1);
    }
} /* end WmRootWindow */