Solaris dtwmrc help

Hi everyone... At work, on our Solaris OS, we have a custom sys.dtwmrc file that controls a custom right-click menu that launches a Java program. I need to edit the dtwmrc file to launch the Java program only if the program is not already running. If the program is already running, I need the program to simply be brought to the front (in front of all open windows).

I am not sure how to do this. After looking all over the internet, and finding basically nothing helpful, I decided to see if anyone here knows how to do this.

I noticed that the dtwmrc file launched programs like "f.exec" and "f.terminal". I need a simple "if statement" to check to see if the Java program is already running. Thing is, I don't know if "if statements" are supported in the dtwmrc file.

Is it possible to write custom functions for the "f." functions in the dtwmrc file? Are the "f.exec" functions compiled C programs, and where are they located on the Solaris OS? Any help would be appreciated, because I really don't know how to solve this problem.

There were no conditional statements I'm aware of with dtwm.

A simple workaround would be to replace the program you f.exec by a script that checks if the process is already running then only launch it if not the case.

I appreciate the response, but this won't work. Granted, it does solve the problem of checking to see if the program is running, but it will not bring the program to the front if it is already running. That is the problem I'm having. I need to bring the program in front of every active window. The only way I know of to do this is using something like "f.raise" in the dtwm, but I can't "interface" with the dtwm in Java code or a shell script.

For example, in shell script pseudo-code, I could put in something like:
"if [ program is not running ] then [ launch program]"

but in the else statement, I don't know how to do something like (or if it is even possible):
"else [ f.raise program ]".

By the way, I didn't mention in my first post that I'm working in the Common Desktop Environment, although you have probably figured that out already.

I overlook the window raise requirement.

Keeping my script solution, you need to lookup your target application window (xlswin maybe) and then call raise it programmatically by using something like dtwmcmd ( http://www.smart.net/~rlhamil/goodies/dtwmcmd.c ) or xraise ( xraise/xraise.c at master · en0/xraise · GitHub ).

Thanks... I tried to run "xlswin" on my Solaris machine, but the program isn't installed. Is "xlswin" another Solaris open source C project? If so, do you have a link to the code?

EDIT: I was typing it in wrong... It is "xlswins", not "xlswin".

Another, possibly easier and probably much more portable, approach would be to embed the "already running" check into the application itself.

Of course, that only works if you have control of the application...

Download xraise.c and compile with

gcc -lX11 -o xraise xraise.c

that makes a binary named "xraise".
run

xwininfo

and click on the window you want to raise.
You get something with window ID and a window name in quotes, e.g. "this is blabla".
Then you can raise it to the top with the command

./xraise "this is blabla"

In your start script put this command in the else branch.

Thanks for the response MadeInGermany. I followed your instructions and downloaded and compiled the C code for xraise. However, I can't get it to work. I ran the "xwininfo" program and got my window's info (it returned 0xc00005 "My Program"). I ran xraise: ./xraise "My Program" but it did nothing. No errors, just sat there (I had to CTRL-C it).

When I compiled the code, I noticed several warnings such as "return makes integer from pointer without a cast". Do you get these cast warnings when you compile the program?

Yes, I got the compile warnings, too.
Still it works for me, tested on a SparcStation, $DISPLAY was :0.0.
If it doesn't find the window:

$ ./xraise "xy not exist"
Cannot find a window by that name.
$ 

Changing the display variable had no effect. The program still won't do anything. It just hangs. These systems are pretty old, so that may have something to do with it.

I wrote my own C code to raise an X Window with the XRaiseWindow function (Xlib Programming Manual: XRaiseWindow). It works, but only if I hard-code the window's hex value (like 0xc00005) into the program before compiling. If I try to get the window's hex value from argv[] as a parameter, I get a BadWindow error.

Any idea on how to get the window's hex value as a parameter? Code:

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>

int main(int argc, char **argv) {
  Display *display = XOpenDisplay(NULL);
  Window window = argv[1];

  XRaiseWindow(display, window);
  XSetInputFocus(display, window, RevertToNone, CurrentTime);
  XCloseDisplay(display);
}

This will only work if I replace argv[1] with the actual hex value of the window gotten from the "xlswins" command.

Maybe you must convert the string argv[1] to an int?
Try

char *ep;
Window window = strtoul(argv[1], &ep, 16);

So just do that, run xlswins to retrieve the window id (if any) and use xraise the way it works for you.

Well, that worked perfectly. I was trying to cast the parameter like (int), which was apparently wrong.

Thanks for the help. Now I can parse out the window hex value with a simple shell script and raise it with this C code. Exactly what I wanted!