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

This is a discussion on Needed: Simple X app to bring itself (i.e., xterm) for foreground - Xwindows ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

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

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

    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.

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

    Kenny McCormack 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

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

    In article <12pm0jp1b73ihca@corp.supernews.com>,
    Thomas Dickey wrote:
    >Kenny McCormack 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


    Looks good. Thanks!


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

    In article <12pm0jp1b73ihca@corp.supernews.com>,
    Thomas Dickey wrote:
    >Kenny McCormack 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?


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

    On 2007-01-03, Kenny McCormack wrote:
    > In article <12pm0jp1b73ihca@corp.supernews.com>,
    > Thomas Dickey wrote:
    >>Kenny McCormack 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?


    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
    #include
    #include
    #include
    #include

    // 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
    spamtrap42@verizon.net
    (Yes, that is one of my email addresses.)

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

    In article ,
    Robert M. Riches Jr. 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. */
    /* 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
    #include
    #include
    #include
    #include

    // 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;
    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 (!strncasecmp( argv1, s1, strlen(argv1))) { // 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 (argc != 2) puts("Arg count"), exit(1);
    argv1 = argv[1];
    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);
    }

+ Reply to Thread