Title: | DECWINDOWS 26-JAN-89 to 29-NOV-90 |
Notice: | See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit |
Moderator: | STAR::VATNE |
Created: | Mon Oct 30 1989 |
Last Modified: | Mon Dec 31 1990 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 3726 |
Total number of notes: | 19516 |
Hello, my original problem was to position the decterm window from which an application was started. I looked up this notes file which said that there was example code that could traverse the X window tree structure. Once I have the window I could use the XSet*() routines to manipulate the window. Sounded exactly what I wanted. I found a piece of code to do this in note 2885 which traverses the tree and raises the window (manipulates the window). I copied this across and compiled it up and ran it but it doesnt seem to work. I finally stripped it down so all it does is print the class, name, and window id/name of every thing it found in the tree. EVERY THING IS NULL !!!!!!!!!!!!!!!!!!! Except it manages to find that the "Icon Box" is named. Could somebody please assist me and enlighten me as to how I should correctly walk the tree. My platform is ULTRIX 4.0 RISC. The code I am using is presented below : ---------------Cut here----------------------- #ifndef DECTERM_CLASS #define DECTERM_CLASS ArgV[1] #define DECTERM_NAME ArgV[2] #endif #include <stdio.h> #include <signal.h> #include <X11/Xlib.h> #include <X11/Xutil.h> static void WalkWindowTree(); static int count; char *ArgV[3] ; main(argc, argv) unsigned int argc; char *argv[]; { Display *display; if (argc != 3) { fprintf(stderr, "%s decterm-class decterm-name\n", argv[0]) ; exit(1) ; } ArgV[1] = argv[1] ; ArgV[2] = argv[2] ; if (!(display = XOpenDisplay(NULL))) { fprintf(stderr, "Can't open display\n"); exit(0); } WalkWindowTree(display, RootWindow(display, DefaultScreen(display))); exit(1); } static void WalkWindowTree(display, window) Display *display; Window window; { Window root, parent, *children; int nchildren; XClassHint ch; char *name; ch.res_name = NULL; ch.res_class = NULL; if (XGetClassHint(display, window, &ch) == Success) { name = NULL; XFetchName(display, window, &name); if((!*DECTERM_CLASS || !strcmp(DECTERM_CLASS, ch.res_class)) && (!*DECTERM_NAME || !strcmp(DECTERM_NAME, ch.res_name))) { printf("class - \"%s\", ", ch.res_class) ; printf("name - \"%s\", ", ch.res_name) ; printf("window - %d, %s\n", window, name); if (name) XFree(name); if (ch.res_name) XFree(ch.res_name); if (ch.res_class) XFree(ch.res_class); } } XQueryTree(display, window, &root, &parent, &children, &nchildren); if (nchildren) { register int i; register Window *child; for (i = 0, child = children; i < nchildren; ++i, ++child) WalkWindowTree(display, *child); XFree(children); } return; }
T.R | Title | User | Personal Name | Date | Lines |
---|---|---|---|---|---|
3525.1 | What data are ya using ?? | WIDGIT::WEST | SCARY : A programmer with a screwdriver. | Thu Oct 25 1990 11:17 | 9 |
What are you passing in for DECTERM_CLASS and _NAME ? The class is DXterm under Ultrix and DECW$TERMINAL under VMS. I just glanced at the code at it _looks_ ok. -=> Jim <=- | |||||
3525.2 | Look in the gras? rags? gars? args! | WPOPTH::ZAMBOTTI | It only works after you ask! | Sun Oct 28 1990 23:11 | 31 |
re. 1 thankyou for confirming the class with me. I found the ultrix class name in the dxterm(1) reference section. Ithen changed my defines accordingly. When this failed I tried replacing static definers with strings from the command line. So instead of : #define DECTERM_CLASS "DXterm" #define DCCTERM_NAME "DECterm" I have : #define DECTERM_CLASS ArgV[1] #define DECTERM_NAME ArgV[2] So to use this program you would type from the command line : # walktree DXterm DECterm And the application would print every occurance of such (or should). To print every class and name use : # walktree "" "" this will supply two blank arguements to the program which interprets this as meaning any class and any name. I hope I havent stuffed up anything else along the way! Walter | |||||
3525.3 | decterm_name == dxterm | CSC32::B_BRADACH | Mon Oct 29 1990 10:23 | 8 | |
This works for me: #define DECTERM_CLASS "DXterm" #define DECTERM_NAME "dxterm" bernie csc/cs | |||||
3525.4 | Why does it work for you... | WPOPTH::ZAMBOTTI | It only works after you ask! | Tue Oct 30 1990 00:51 | 135 |
and not for me??? Here are my defines : #ifndef DECTERM_CLASS #define DECTERM_CLASS "DXterm" #define DECTERM_NAME "dxterm" #endif Here is a fragment of the code that walks the tree : ch.res_name = NULL; ch.res_class = NULL; if (XGetClassHint(display, window, &ch) == Success) { printf("class - \"%s\"\n", ch.res_class) ; /* debug print only */ if (ch.res_class && strcmp(ch.res_class, DECTERM_CLASS) == 0) { printf("name - \"%s\"\n", ch.res_name) ; /* debug print only */ if (ch.res_name && strcmp(ch.res_name, DECTERM_NAME) == 0) { name = NULL; XFetchName(display, window, &name); printf("window - %d, %s\n", window, name); /* debug print only */ Here is a section of the output : class - "(null)" class - "(null)" class - "(null)" class - "(null)" class - "(null)" class - "(null)" class - "(null)" class - "(null)" . . . And of course with the class always being equal to null this never gets to the next if to test the name and so forth. I added the printf statements to the code just to see what was going on. Not a lot as you can see! I am using ULTRIX 4.0 what about you? The entire code follows below if you are interested : #ifndef DECTERM_CLASS #define DECTERM_CLASS "DXterm" #define DECTERM_NAME "dxterm" #endif #include <stdio.h> #include <signal.h> #include <X11/Xlib.h> #include <X11/Xutil.h> static void WalkWindowTree(); static int count; main(argc, argv) unsigned int argc; char *argv[]; { Display *display; if (!(display = XOpenDisplay(NULL))) { fprintf(stderr, "Can't open display\n"); exit(0); } WalkWindowTree(display, RootWindow(display, DefaultScreen(display))); exit(1); } static void WalkWindowTree(display, window) Display *display; Window window; { Window root, parent, *children; int nchildren; XClassHint ch; char *name; ch.res_name = NULL; ch.res_class = NULL; if (XGetClassHint(display, window, &ch) == Success) { printf("class - \"%s\"\n", ch.res_class) ; if (ch.res_class && strcmp(ch.res_class, DECTERM_CLASS) == 0) { printf("name - \"%s\"\n", ch.res_name) ; if (ch.res_name && strcmp(ch.res_name, DECTERM_NAME) == 0) { name = NULL; XFetchName(display, window, &name); printf("window - %d, %s\n", window, name); if (name) XFree(name); printf("count = %d\n", count); if (count == 0){ count = 1; printf("Window Popup \n"); XRaiseWindow(display, window); XSetInputFocus(display, window, RevertToParent, CurrentTime); XFlush(display); sleep(5); XLowerWindow(display, window); XFlush(display); sleep(5); } } } if (ch.res_name) XFree(ch.res_name); if (ch.res_class) XFree(ch.res_class); } XQueryTree(display, window, &root, &parent, &children, &nchildren); if (nchildren) { register int i; register Window *child; for (i = 0, child = children; i < nchildren; ++i, ++child) WalkWindowTree(display, *child); XFree(children); } return; } | |||||
3525.5 | useing a 3.1 executable on 4.0 VAX | CSC32::B_BRADACH | Tue Oct 30 1990 13:02 | 10 | |
I am running on a VAXstation, ULTRIX 4.0. I had a 3.1 executable which I ran and worked just fine. Recompiled under 4.0 and code no longer works. It looks like the class name for decterm has changed. Does anyone know what's going on? bernie csc/cs | |||||
3525.6 | Success isn't always successful... :^) | WIDGIT::WEST | SCARY : A programmer with a screwdriver. | Wed Oct 31 1990 10:59 | 19 |
RE: <<< Note 3525.4 by WPOPTH::ZAMBOTTI "It only works after you ask!" >>> -< Why does it work for you... >- >> if (XGetClassHint(display, window, &ch) == Success) { Here is the problem. XGetClassHint has a return status. It will be non-zero if successful and zero otherwise. Success is defined as zero in X.h. This means that when XGetClassHint IS successful (non-zero) the above test will always fail. Does this mean that Success is defined wrong ? I'm not sure because all the X.h's I could find all have Success defined as zero. Anyway, don't do the check against Success and it will work. -=> Jim <=- |