On Wed, 24 Mar 2004 18:13:58 +0100 Marcus Schaefer <[EMAIL PROTECTED]> babbled:
(B
(B> Hi,
(B>
(B> > >I tried your example because I don't know the _NET_WM_PID property
(B> > >and was interested in it. Unfortunately the call to XGetWindowProperty()
(B> > >never filled the &prop data. Your code is checking against the return
(B> > >code of XGetWindowProperty() which is fine but prop equals to (nil) in
(B> > >all my tests. I was using metacity as suggested windowmanger.
(B> > >
(B> > >Do you have any idea why it fails ?
(B> > >
(B> > >The window Id which is required of course is obtained from a
(B> > >"xwininfo" call. I passed the information from this command to
(B> >
(B> > Using this (removed the uid stuff) works here:
(B> >
(B> > [EMAIL PROTECTED] fer]$ gcc test.c -L/usr/X11R6/lib/ -I/usr/X11R6/include/ -lX11
(B> > -o [EMAIL PROTECTED] fer]$ xwininfo
(B> >
(B> > xwininfo: Please select the window about which you
(B> > would like information by clicking the
(B> > mouse in that window.
(B> >
(B> > xwininfo: Window id: 0x1e00012 "[EMAIL PROTECTED]:~"
(B> > [...]
(B> > [EMAIL PROTECTED] fer]$ ./a.out 0x1e00012
(B> > pid of window 0x1e00012 = 24109
(B>
(B> Hmm, yes I see, I did it the same way but it doesn't work for me.
(B> The code I use is as follows:
(B>
(B> ----snip----
(B> #include <X11/Xlib.h>
(B> #include <X11/Xos.h>
(B> #include <X11/Xfuncs.h>
(B> #include <X11/Xutil.h>
(B> #include <stdio.h>
(B> #include <ctype.h>
(B>
(B> #include <X11/Xatom.h>
(B> #include <X11/Xmu/WinUtil.h>
(B>
(B>
(B> int main (int argc, char*argv[]) {
(B> Atom atom,actual_type;
(B> Display *dpy;
(B> int screen;
(B> char *atom_name;
(B> int actual_format;
(B> unsigned long nitems;
(B> unsigned long bytes_after;
(B> unsigned char *prop;
(B> int status;
(B> int pid;
(B> Window w=0;
(B>
(B> dpy = XOpenDisplay((char*)getenv("DISPLAY"));
(B> screen = DefaultScreen(dpy);
(B> if (argc!=2) {
(B> printf("Usage %s window-id\n",argv[0]);
(B> exit(-1);
(B> }
(B> sscanf(argv[1],"0x%x",(unsigned int*)(&w));
(B> atom = XInternAtom(dpy, "_NET_WM_PID", True);
(B> atom_name = XGetAtomName (dpy,atom);
(B> status = XGetWindowProperty(
(B> dpy, w, atom, 0, 1024,
(B> False, AnyPropertyType,
(B> &actual_type,
(B> &actual_format, &nitems,
(B> &bytes_after,
(B> &prop
(B> );
(B>
(B> if (status!=0) {
(B> printf("Cannot get _NET_WM_PID");
(B> exit(-2);
(B> }
(B> if (! prop) {
(B> printf ("No properties\n");
(B> exit (-3);
(B> }
(B>
(B> pid = prop[1] * 256;
(B> pid += prop[0];
(B> printf("pid of window 0x%x = %d\n",(unsigned int)w,pid);
(B>
(B> return 0;
(B> }
(B> ----snap---
(B>
(B> gcc id.c -L/usr/X11R6/lib/ -I/usr/X11R6/include/ -lX11 -o bla
(B>
(B> I'm running XFree86 Version 4.3.99.902 (4.4.0 RC 2) on kernel
(B> 2.6.4-6-default.
(B>
(B> any ideas ?
(B
(B_NET_WM_PID is a VOLUNTARY property set by some apps if they want to. not all x
(Bapps will set this - so windows wont necessarily have this property. see my
(BLD_PRELOAD hack for forcing a process id property to be set on ALL toplevel
(Bwindows of apps run under the preload
(B
(B--
(B------------- Codito, ergo sum - "I code, therefore I am" --------------
(BThe Rasterman (Carsten Haitzler) [EMAIL PROTECTED]
$B7'<*(B - $Bhttp://XFree86.Org/mailman/listinfo/devel