Get an X window ID

Pat Kane pekane52 at gmail.com
Thu May 17 09:00:33 PDT 2007


Are you allowed to change Xlib and the X server?

If so then this hack might help.

A while ago I needed to know, from inside the X server,
the PID of a process that created an X connection.

I used spare pad bytes in the  xConnClientPrefix initial
connection setup message to pass the PID from the client
to the X server.  Note that clients might not be on the
same machine so you also need the hostname of the client.

Here are the source changes:

  in ./X11/OpenDis.c XOpenDisplay(...)
  ------------------------------------
   ...
        client.nbytesAuthProto = conn_auth_namelen;
        client.nbytesAuthString = conn_auth_datalen;

   #ifdef PEK_PID_HACK
        /*
         * Prefix has three spare pad bytes:
         *  client.pad  -   8 bits
         *  client.pad2 -  16 bits
         * we will used them to send debug info to X server
         */
         client.pad = 0x5a;          /* magic number */
         client.pad2 = getpid();
    #endif


  in ./Xserver/dix/dispatch.c ProcInitialConnection()
  ---------------------------------------------------
        ...
        client->swapped = TRUE;
        SwapConnClientPrefix(prefix);
      }

   #ifdef PEK_PID_HACK
    if ( prefix->pad == 0x5a )
      save_procId   = (prefix->pad2 & 0xFFFF);
    else
      save_procId   = 0
   #endif


Pat
---


On 5/17/07, eberrocal at laurel.datsi.fi.upm.es
<eberrocal at laurel.datsi.fi.upm.es> wrote:
> My problem is that I need to know the ID of an X window.
>
> I have a program that lunch other program with the typical fork() and
> after execl().
>
> I have the ID of the process but I need the ID of the window because I
> need to send X events to this window.
>
> There are any form to get the window ID of a program (of what I have his
> process ID) ??:
>
> Thanks for your time.
>
> Edu.
>
> _______________________________________________
> xorg mailing list
> xorg at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xorg
>



More information about the xorg mailing list