yt07+@ANDREW.CMU.EDU (Yin-Cheng Tsai) (02/01/89)
Hi, folks,
More questions are coming up when I really try to use the powerful
functions in Xlib.
Following is my source codes. There are two problems in these codes.
Problem 1:
I can/can't get the data from the command line. For instance,
"tst1 -dbase /usr/yt/.tstbase" DOESN'T work (defFile gets nothing)
"tst1 -xrm "*dataBase:/usr/yt/.tstbase" work (defFile = "/usr/yt/.tstbase")
Problem 2:
The children returned by "XQueryTree" are not windows (?). I try to get
the property of XA_WM_NAME, but just get Segmentation error.
Thanks for any help. I really appreciate it.
-- yin-cheng
##---------------------- tst1.c start from here ----------------------##
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/Xos.h> /* include file.h/string.h/strings.h */
#include <X11/Xatom.h>
static XrmOptionDescRec options[] = {
{"-display","*display", XrmoptionSepArg, (caddr_t) NULL},
{"-dbase", ".dataBase", XrmoptionSepArg, (caddr_t) NULL},
{"-pixmap", "*pixmap", XrmoptionSepArg, (caddr_t) NULL},
{"-width", "*width", XrmoptionSepArg, (caddr_t) NULL},
{"-height", "*height", XrmoptionSepArg, (caddr_t) NULL},
{"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL},
};
main (argc, argv)
int argc;
char *argv[];
{
char defFile[32], server[32], *string_type[20];
unsigned int nchild;
int index;
Window root, parent, *children;
XrmDatabase comDB, defDB, rootDB, resDB;
XrmValue value;
Display *display;
Pixmap pixmap;
XrmInitialize ();
XrmParseCommand (&comDB, options, sizeof(options)/sizeof(options[0]),
argv[0], &argc, argv);
if (XrmGetResource (comDB, ".dataBase", ".DataBase", string_type, &value))
strncpy (defFile, (char*) value.addr, (int) value.size);
else {
strcpy (defFile, getenv ("HOME"));
strcat (defFile, "/.xdef");
}
if (!access (defFile, F_OK)) {
if (!(defDB = XrmGetFileDatabase (defFile))) {
fprintf (stderr, "database file <%s> is not readable", defFile);
exit (-1);
}
XrmMergeDatabases (defDB, &resDB);
}
else
fprintf (stderr, "database file <%s> is not accessible\n", defFile);
if (XrmGetResource (comDB, ".display", ".Display", string_type, &value) ||
XrmGetResource (resDB, ".display", ".Display", string_type, &value))
strncpy (server, (char*) value.addr, (int) value.size);
else
server[0] = '\0';
if ((display = XOpenDisplay (server)) == NULL) {
fprintf (stderr, "no response from the X server <%s>\n",
strlen (server)? server:(char*) getenv("DISPLAY"));
exit (-1);
}
rootDB = XrmGetStringDatabase (XResourceManagerString (display));
XrmMergeDatabases (rootDB, &resDB);
XrmMergeDatabases (comDB, &resDB);
if (!XQueryTree (display, DefaultRootWindow (display), &root, &parent,
&children, &nchild)) {
fprintf (stderr, "can not query the tree\n");
exit (-1);
}
for (index = 0 ; index < nchild ; ++index) {
Atom actual_type;
int actual_format;
unsigned long nitems, bytes_after;
char *prop[20];
XGetWindowProperty (display, children[index], XA_WM_NAME, 0, 0,
False, AnyPropertyType, &actual_type, &actual_format,
&nitems, prop);
}
}rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (02/01/89)
I can/can't get the data from the command line.
Go back and read about resource databases again. Instead of
XrmGetResource (comDB, ".dataBase", ".DataBase", string_type, &value)
you need something like
char name[256], class[256];
strcpy(name, argv[0]);
strcat(name, ".dataBase");
strcpy(class, argv[0]);
strcat(class, ".DataBase");
XrmGetResource (comDB, name, class, string_type, &value)
I try to get the property of XA_WM_NAME, but just get Segmentation error.
PLEASE learn to use lint before bothering people on this list. Your call to
XGetWindowProperty is missing an argument and has another argument passed
incorrectly.