Operating System - HP-UX
1826350 Members
4492 Online
109692 Solutions
New Discussion

Re: change CDE workspace in a script

 
SOLVED
Go to solution
Tom Fellowes
Advisor

change CDE workspace in a script

How can I change my CDE workspace in a script? I have KeyBindings setup, but need to do this from within a script (do something, change to next workspace, do something else).

HP-UX 11.11 on b2600

TIA
Tom F
HTSI
Greenbelt, MD
4 REPLIES 4
RAC_1
Honored Contributor

Re: change CDE workspace in a script

Send -HUP signal to CDE session???
Never tried it though.

Anil
There is no substitute to HARDWORK
C. Beerse_1
Regular Advisor

Re: change CDE workspace in a script

The CDE workspace setup is saved in the users ~/.dt/sessions/ files and directories. Most are readable ascii files. As far as I know, they are read during logon. The 'return to home' session is only written if the 'set home session' is selected. The 'resume current session' is written on exit. Options are in StyleManager -> Startup.

You can savely edit the files from a script using your favorite tools like `sed`, `awk`, `perl` and such. Best to force 'set home session' with those settings since the 'resume current session' will overwrite the settings on exit. My way was to teach myself with reverse engineering: just set or unset the option and see what changes.
make everything as simple as possible, not simpler (A.Einstein??)
Alex Glennie
Honored Contributor
Solution

Re: change CDE workspace in a script

/* 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");
}

Requires CDE dev kit libs to compile : resulting switch executable usage :

switch Two

nb Uses CDE default naming convention wrt Workspaces ie doesn't cope with customised names for workspaces ... maybe of some use to you ?
Tom Fellowes
Advisor

Re: change CDE workspace in a script

Thanks to Alex. That was just what I was looking for! If only I could modify it to allow users to enter "next" to go to the next workspace. I gotta learn more C.