LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to bring up application window to front from shell script. (https://www.linuxquestions.org/questions/linux-general-1/how-to-bring-up-application-window-to-front-from-shell-script-83545/)

aleksas_m 08-19-2003 12:54 PM

How to bring up application window to front from shell script.
 
How to bring up application window to front from shell script in X-Windows when you know window id?
I need this because I want to write script which would launch a dictionary only when it is not running and in other case it would bring existing dictionary window to front. When I would assign a shortcut to this script. This script would not let to clutter my window with several dictionary windows when I press couple of times a shortcut, by keeping a single window.

quest4knowledge 08-19-2003 01:02 PM

thats an interesting idea. Id like to know how too.

aleksas_m 08-21-2003 01:22 PM

I wrote a little program which takes window id (in hex) as argument and sends that window to top. Here is the source:

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

int main(int argc, char **argv)
{
if ( argc != 2 ) {
printf("Usage:\n\ttotop <window id>\n");
return 1;
}

Display *dsp = XOpenDisplay(NULL);

long id = strtol(argv[1], NULL, 16);
XRaiseWindow ( dsp, id );
XSetInputFocus ( dsp, id, RevertToNone, CurrentTime );

XCloseDisplay ( dsp );

return 0;
}

You can compile it with:
c++ totop.cpp -L/usr/X11R6/lib -lX11 -o totop
I assumed that you saved it in "totop.cpp".

It has problem I do not know how to fix: if window is in another virtual desktop this program doesn't work. Here another question rises: how to send window to current desktop?

You can get window id using xwininfo. A little script using this program used to call WordNet:

#!/bin/bash
if ps -A | grep wishwn; then # if WordNet already launched
id=$(xwininfo -name "WordNet 1.7.1 Browser" | grep id: | awk "{ print \$4 }")
totop $id
else # launch WordNet
wnb
fi


All times are GMT -5. The time now is 09:26 AM.