Operating System - HP-UX
1830931 Members
2216 Online
110017 Solutions
New Discussion

Trying to determine which workspace given a PID

 
Boyd Kodama
Frequent Advisor

Trying to determine which workspace given a PID

HP-UX 10.20 (series 700) and CDE

I am trying to write a program (or script) such that an xterm will display in the same workspace of another xterm given its PID. Is there a way to determine which
workspace that may be from that PID?

thanks,

Boyd
Without Mondays, there weren't be any Fridays
3 REPLIES 3
Gregory Fruth
Esteemed Contributor

Re: Trying to determine which workspace given a PID

I dunno if there's an easy and reliable way to do it
without some X programming. But here are a few
bits that might be useful.

If you have the workspace name, you can say:
"xterm -xrm '*workspaceList: FOO' -e myprog"
or somesuch to start your app.

I don't know offhand how to get the workspace
name(s) for a window, but you can get the workspace
ID(s) using the xprop command. Use xprop with the
-id or -name options to have it run automatically.
You'll need to know the window ID or name of the
original xterm. Again, I dunno how you're going to do
that.

However, if you have control over the startup of the
original xterm you can *set* the window name using
the -T or -title options to xterm.

So...

xterm -title FOOBAR -e prog1
w=`xprop -name FOOBAR | grep _DT_WORKSPACE_PRESENCE`
(use awk or something to get the list of workspace IDs out of $w)
(somehow convert workspace IDs to names)
xterm -xrm '*workspaceList: $wsnames' -e prog2

HTH




Alex Glennie
Honored Contributor

Re: Trying to determine which workspace given a PID

Here's the source code for the switch program ..... thanks to HP's Graphics WTEC Team for providing it to me a while ago .... hope it helps ?

As before it switches workspaces programmatically and can be used with CDE's sessionetc file to start apps on desired w/spaces. It takes the w/space name as an argument.

/* include files */
#include
#include
#include


/* functions */
void main(int, char**);
void ws_change(Widget widget, Atom aWorkspace, XtPointer client_data);

/* global variables */
static XmString xms;
static Widget toplevel;
static Widget *wWs;
static Atom *paWsSet = NULL;
static unsigned long numWorkspaces;
static Atom *paWs;

static Display *display;
static Window root;
static int screen;
static Widget top, form, top1;
static XtAppContext app_context;
static Arg args[10];
static int n, i, status, pNumWorkspaces;
static Atom *ppaWorkspaces, foundWsAtom = NULL;
static DtWsmWorkspaceInfo *ppWsInfo;
static DtWsmCBContext wsmcontext;
static char *desiredWs;

/* main - main logic for program */
void main (int argc, char **argv)
{

/* initialize toolkit */
n = 0;
XtSetArg (args[n], XmNallowShellResize, True); n++;
XtSetArg (args[n], XtNmappedWhenManaged, False); n++;
toplevel = XtAppInitialize (&app_context, "Dtswitch", NULL, 0,
&argc, argv, NULL, args, n);
display = XtDisplay(toplevel);
screen = DefaultScreen(display);
root = RootWindow(display, screen);
XSynchronize(display, screen);

if ( argc != 2 )
{
printf("must provide name of a workspace to switch to\n");
printf("we'll just monitor workspace changes now\n");
desiredWs = NULL;
}
else
{
desiredWs = argv[1];
}

status = DtWsmGetWorkspaceList(display, root, &ppaWorkspaces,
&pNumWorkspaces);
if (status != Success )
{
printf("problem obtaining workspace list, exiting with status %d\n",
status);
exit(status);
}
/*
printf("Number of workspaces returned is %d\n", pNumWorkspaces);
*/
for (i=0;i {
status = DtWsmGetWorkspaceInfo(display, root, ppaWorkspaces[i],
&ppWsInfo);
if (status != Success )
{
printf("problem getting workspace info %d\n", status);
}
else
{
printf("Workspace %d , title is %s, name is %s\n",i,
ppWsInfo->pchTitle,
XGetAtomName(display,ppWsInfo->workspace));
if ((desiredWs != NULL) &&
(0 == strcmp(desiredWs, ppWsInfo->pchTitle)))
{
foundWsAtom = ppWsInfo->workspace;
}
}
}

wsmcontext = DtWsmAddCurrentWorkspaceCallback(toplevel, ws_change, NULL);
/*
printf("wsmcontext is %d\n", wsmcontext);
*/
XtRealizeWidget (toplevel);

if (foundWsAtom != None)
{
printf("Atom is %x, name is %s\n",
foundWsAtom,XGetAtomName(display, foundWsAtom));
XFlush(display);
status = DtWsmSetCurrentWorkspace(toplevel, foundWsAtom);
XFlush(display);
printf("status is %d\n",status);
/*
if ( status != Success )
{
printf("workspace %s does not exist\n", desiredWs);
}
*/
}
else
printf("Never found a match - workspace doesn't exist\n");
/*
XtAppMainLoop (app_context);
*/
}

void ws_change(Widget widget, Atom aWorkspace, XtPointer client_data)
{
printf("In the change workspace callback\n");
}


J. de Haan
Occasional Advisor

Re: Trying to determine which workspace given a PID

Since it costed me a few hours that I would like to spare anybody else who wants this, to get this compiled (works like a charm by the way ;-) ) I'll give the compiler options for anybody who wishes to compile this too. Just for the HP ANSI compiler though, sorry no gcc.

aCC -I /usr/dt/share/include -L /usr/dt/lib -lXt -lDtSvc switchws.c