Нужна помощь. Есть код (см. ниже). Что делаю: открываю gedit, затем создаю свое X-окно, и все keyevent'ы созданного окна пересылаю в gedit. Понятно, ожидаю печати в gedit, но хер там. Как исправить?
#include <X11/Xlib.h>
#include <cassert>
#include <unistd.h>
#include <cstdlib>
#include <cstdio>
#include <wait.h>
#include <iostream>
#include <fcntl.h>
#include <string>
using namespace std;
int main( int argc, char ** argv ) {
	string app = "gedit";
	int pid = fork();
	if ( pid == 0 ) {
		execlp( app.c_str(), app.c_str(), NULL );
		exit( 0 );
	} 
	int status;
	waitpid( pid, &status, WNOHANG );
	sleep(1);
	string cmd = 
		string() + "xwininfo -tree -root -int | grep " + app.c_str() + 
		" | awk '{ print $1 }' | tail -n 1"; 
	FILE * wininfo = popen( cmd.c_str(), "r" );
	char wid_str[ 80 ];
	fread( (void *) wid_str, sizeof( char ), sizeof( wid_str ), wininfo );
	
	pclose( wininfo );
	Window w = (Window) atol( wid_str );
	Display * dpy = XOpenDisplay( NULL ); 
	Window sw = XCreateSimpleWindow( dpy, DefaultRootWindow( dpy ),
		0, 0, 100, 100, 1, WhitePixel( dpy, DefaultScreen( dpy ) ),
				BlackPixel( dpy, DefaultScreen( dpy ) ) ); 
	XSelectInput( dpy, sw, KeyPressMask|KeyReleaseMask );
	XMapWindow( dpy, sw );
	XEvent event;
	while (1) {
		XNextEvent( dpy, &event );
		XSendEvent( dpy, w, False, KeyPressMask|KeyReleaseMask, &event );
	}
	return 0;
}

