| Well, thanks to Paul's smPauseWindow() routine I now have a program
that, given a node name, will tell you if the DECW session on that node
is paused or not. It requires the user to have access to the display
"<node>::0" The code follows a form-feed.
/*
Is_paused - program to determine, given a node name, if the DECW session
on that node is paused or not.
Input - node name via foreign command line
Output - returns 0 (failure, is not paused) or 1 (success, is paused) to DCL
Prints error message and returns 0 on any error.
Routines smPauseWindow() and smTestWindow() written by Paul S. Winalski
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <decw$include/Xlib.h>
main( int argc, char** argv )
{
Display *disp;
Window rWindow, sWindow, SmPauseWindow();
XWindowAttributes attr;
char display[64] = "";
int paused = 0;
/*
* Set up display name as "<node>::0"
*/
if (argc != 2)
{
fprintf(stderr, "%s\n", "Usage: is_paused <node>" );
return 0;
}
else
{
strcpy(display, argv[1]);
strcat(display, "::0");
}
/*
* Open up the display.
*/
if ((disp=XOpenDisplay(display)) == NULL)
{
fprintf(stderr, "Cannot open display '%s'\n", display);
return 0;
}
/*
* Test for pause window and return 1 or 0.
*/
rWindow = DefaultRootWindow(disp);
sWindow = SmPauseWindow(disp, rWindow);
if (sWindow == 0)
paused = 0;
else if (!XGetWindowAttributes (disp, sWindow, &attr))
{
fprintf (stderr, "XGetWindowAttributes failed.\n");
return 0;
}
else
paused = (attr.map_state == IsViewable);
if (paused)
fprintf(stdout, "Is paused\n" );
else
fprintf(stdout, "Is not paused\n" );
return paused;
}
static Window SmTestWindow(Display *dpy, Window w, XWindowAttributes *rootatt,
XWindowAttributes *childatt, int win_offset, int n_children)
{
Window r2;
Window parent;
Window *child1;
Window *child2;
unsigned int nc1;
XWindowAttributes attr;
if (childatt->width == rootatt->width - win_offset &&
childatt->height == rootatt->height - win_offset &&
childatt->x == 0 &&
childatt->y == 0)
{
if (!XQueryTree(dpy, w, &r2, &parent, &child1, &nc1))
return 0;
if (nc1 == 1)
{
if (!XGetWindowAttributes(dpy, child1[0], &attr))
return 0;
if (!XQueryTree(dpy, child1[0], &r2, &parent, &child2,
&nc1))
return 0;
if (attr.width == rootatt->width - win_offset &&
attr.height == rootatt->height - win_offset &&
attr.x == 0 &&
attr.y == 0 &&
nc1 == n_children)
return child1[0];
}
}
return 0;
}
Window SmPauseWindow(dpy, root)
Display *dpy;
Window root;
{
#define V_WINDOW_OFFSET 6
#define V_NCHILDREN 2
#define U_WINDOW_OFFSET 0
#define U_NCHILDREN 1
Window r2;
Window parent;
Window *child;
Window *child1;
Window *child2;
unsigned int nchildren, nc1;
XWindowAttributes rootatt, childatt;
int x, y, w, h, bw, d;
if (!XGetWindowAttributes(dpy, root, &rootatt))
return 0;
if (XQueryTree(dpy, root, &r2, &parent, &child, &nchildren))
{
int i;
Window w;
for (i = 0; i < nchildren; i++)
{
if (!XGetWindowAttributes(dpy, child[i], &childatt))
return 0;
w = SmTestWindow(dpy, child[i], &rootatt, &childatt,
V_WINDOW_OFFSET, V_NCHILDREN);
if (w)
return w;
w = SmTestWindow(dpy, child[i], &rootatt, &childatt,
U_WINDOW_OFFSET, U_NCHILDREN);
if (w)
return w;
}
}
/* If we get here, we can't find the proper window */
return 0;
}
|