| 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.
|
| 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...)
|
|
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 */
|