As far as I know, there is no way to reliably get a process ID from an X window ID for local clients (to implement Richard's View Source idea). I would love to be wrong!
(1) Did I miss something? Can this be done now?
(2) If this can't be done now, what would it take? Could we create an X extension so that the server can supply connection info for a window, and then trace that connection info back to a specific process?