Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Needed: Simple X app to bring itself (i.e., xterm) for foreground

5 views
Skip to first unread message

Kenny McCormack

unread,
Jan 2, 2007, 7:50:23 PM1/2/07
to
Needed: Simple X app to bring itself (i.e., xterm) for foreground

I.e., I would like to be able to run something from a shell running in
an xterm that would bring the xterm to the foreground. Obviously, it
would be best if there was an existing app for this (maybe a feature of
some otherwise unrelated package). Otherwise, I'd appreciate tips on
how to write it in C. I have written (small) X apps before.

Or, maybe it can be in done in TCL/TK. I have some experience there as
well.

Thomas Dickey

unread,
Jan 2, 2007, 8:10:17 PM1/2/07
to
Kenny McCormack <gaz...@xmission.xmission.com> wrote:
> Needed: Simple X app to bring itself (i.e., xterm) for foreground

> I.e., I would like to be able to run something from a shell running in
> an xterm that would bring the xterm to the foreground. Obviously, it
> would be best if there was an existing app for this (maybe a feature of
> some otherwise unrelated package). Otherwise, I'd appreciate tips on
> how to write it in C. I have written (small) X apps before.

http://www.thrysoee.dk/xtermcontrol/

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net

Kenny McCormack

unread,
Jan 2, 2007, 9:51:08 PM1/2/07
to
In article <12pm0jp...@corp.supernews.com>,

Looks good. Thanks!

Kenny McCormack

unread,
Jan 3, 2007, 2:46:28 PM1/3/07
to
In article <12pm0jp...@corp.supernews.com>,
Thomas Dickey <dic...@saltmine.radix.net> wrote:
>Kenny McCormack <gaz...@xmission.xmission.com> wrote:
>> Needed: Simple X app to bring itself (i.e., xterm) for foreground
>
>> I.e., I would like to be able to run something from a shell running in
>> an xterm that would bring the xterm to the foreground. Obviously, it
>> would be best if there was an existing app for this (maybe a feature of
>> some otherwise unrelated package). Otherwise, I'd appreciate tips on
>> how to write it in C. I have written (small) X apps before.
>
>http://www.thrysoee.dk/xtermcontrol/

Oops - problem.

It looks good, but it seems to only work with genuine xterms. I use
rxvt and it doesn't work there.

So, anyone want to give me a C or TCL/TK solution?

Robert M. Riches Jr.

unread,
Jan 3, 2007, 3:02:23 PM1/3/07
to

Sorry for the long post, but you asked for it. :-) At
least it's not a binary.

Here's a program that raises a window based on the window's
title. You could change the string comparison against MAIN
to test for whether the window in question is the one you
want to raise. I'll lease the coding of that as an exercise
for the reader. :-)

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv cut here vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
/* xraisemain.c - This program raises the "main" window. */
/* */
/* Syntax: xraisemain */
/* */
/* To compile this program, use the following command line: */
/* */
/* cc -Wall -o xraisemain xraisemain.c -B /usr/X11R6/lib -lX11 */

// Include header files
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

// Define macros
#define DEBUG 0
#define DEBUGSTR "xraisemain: dbg: "
#define MAIN "main"

/////////////////////////////////////////////////////////////////////////////
//
// Function walktree() does one node in the tree. If it finds the window,
// this function raises it and calls exit();
//
/////////////////////////////////////////////////////////////////////////////

void walktree( Display * dpy, Window curwin) {
int res;
Window root;
Window parent;
Window * children;
unsigned int numchildren;
int i;
Window curchild;
XTextProperty tp;
char ** sarr;
int nums;
int j;
char * s1;

res = XQueryTree( dpy, curwin, &root, &parent, &children, &numchildren);
if (DEBUG) {
printf( "%s %s %d\n", DEBUGSTR, "main(): XQueryTree result:", res);
printf( "%s %s %d\n", DEBUGSTR, "main(): numchildren:", numchildren);
fflush(stdout);
}
for ( i = 0; numchildren > i; i++) { // per child
curchild = children[i];
if (DEBUG) {
printf( "%s %s %ld\n", DEBUGSTR, "main(): curchild:", curchild);
fflush(stdout);
}
res = XGetWMName( dpy, curchild, &tp);
if (DEBUG) {
printf( "%s %s %d\n", DEBUGSTR, "main(): XGetWMName result:", res);
fflush(stdout);
}
res = XTextPropertyToStringList( &tp, &sarr, &nums);
if (DEBUG) {
printf( "%s %s %d\n", DEBUGSTR, "main(): XTp2SL result:", res);
printf( "%s %s %d\n", DEBUGSTR, "main(): nums:", nums);
fflush(stdout);
}
if (1 == res) { // check names
for ( j = 0; nums > j; j++) { // per name
s1 = sarr[j];
if (DEBUG) {
printf( "%s %s %s\n", DEBUGSTR, "main(): s1:", s1);
fflush(stdout);
}
if (0 == strcmp( MAIN, s1)) { // found it
if (DEBUG) {
printf( "%s %s %lx\n", DEBUGSTR, "raising window:", curchild);
fflush(stdout);
}
res = XRaiseWindow( dpy, curchild);
if (DEBUG) {
printf( "%s %s %d\n", DEBUGSTR, "main(): raise res:", res);
fflush(stdout);
}
XCloseDisplay(dpy);
exit(0);
} // found it
} // per name
} // check names
if (DEBUG) {
printf( "%s %s\n", DEBUGSTR, "main(): recursive call");
fflush(stdout);
}
walktree( dpy, curchild);
} // per child

}

/////////////////////////////////////////////////////////////////////////////
//
// Function main() is the top level.
//
/////////////////////////////////////////////////////////////////////////////

int main( int argc, char **argv) {
Display * dpy;
Window defroot;

if (NULL == (dpy = XOpenDisplay(NULL))) {
fprintf( stderr, "xmock: can't open display.\n");
exit(1);
}
if (DEBUG) {
printf( "%s %s\n", DEBUGSTR, "main(): display open.");
fflush(stdout);
}
defroot = DefaultRootWindow(dpy);
if (DEBUG) {
printf( "%s %s %ld\n", DEBUGSTR, "main(): default root window:", defroot);
fflush(stdout);
}
walktree( dpy, defroot);
//
// If we get here, we didn't find it.
//
fprintf( stderr, "ERROR: xraisemain: did not find 'main'.\n");
exit(1);
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cut here ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

HTH

--
Robert Riches
spamt...@verizon.net
(Yes, that is one of my email addresses.)

Kenny McCormack

unread,
Jan 3, 2007, 6:25:34 PM1/3/07
to
In article <slrnepo2u...@one.localnet>,
Robert M. Riches Jr. <spamt...@verizon.net> wrote:
...

>Sorry for the long post, but you asked for it. :-) At
>least it's not a binary.
>
>Here's a program that raises a window based on the window's
>title. You could change the string comparison against MAIN
>to test for whether the window in question is the one you
>want to raise. I'll lease the coding of that as an exercise
>for the reader. :-)

Thanks much. Works fine. Here's my slightly edited version:

/* xraisemain.c - This program raises the "main" window. */

/* Written by: Robert M. Riches Jr. <spamt...@verizon.net> */


/* Syntax: xraisemain */
/* */
/* To compile this program, use the following command line: */
/* */

/* gcc -W -Wall -Werror -s -o xraise xraise.c -B /usr/X11R6/lib -lX11 */

// Include header files
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

// Define macros
#define DEBUG 0
#define DEBUGSTR "xraisemain: dbg: "

char *argv1;

/////////////////////////////////////////////////////////////////////////////
//
// Function walktree() does one node in the tree. If it finds the window,
// this function raises it and calls exit();
//
/////////////////////////////////////////////////////////////////////////////

void walktree( Display * dpy, Window curwin) {
int res;
Window root;
Window parent;
Window * children;

int i,numchildren;

if (!strncasecmp( argv1, s1, strlen(argv1))) { // found it

}

if (argc != 2) puts("Arg count"), exit(1);
argv1 = argv[1];

0 new messages