[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

1371.0. "Can I tell if you're paused?" by CIM::KAIRYS (Michael Kairys) Tue Sep 05 1989 15:10

    I need a way to tell if a given session manager process on a given node
    in a cluster is paused. Is this possible?
    
    (I hope this hasn't been asked and answered; I did do a dir/title and
    dir/contains (enotes) search - honest!)

T.RTitleUserPersonal
Name
DateLines
1371.1PSW::WINALSKICareful with that VAX, EugeneTue Sep 05 1989 18:538
Use the SmPauseWindow() routine supplied with the Xfish sources
(PSW::PSW$DUA1:[WINALSKI.FISH]) to get the window ID of the Session Manager's
pause window.  If there is no pause window, you know you're not paused.  If
the pause window exists, is mapped, and is visible, then you know that the
session is paused.

--PSW

1371.2is_paused.cCIM::KAIRYSMichael KairysTue Sep 12 1989 11:54170
    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;
    }