http://www.linux.org.ru/forum/development/4997246?lastmod=1276351469892
Проблема. Хочу получать события от gedit'a. Код ниже не работает. Как сделать?
text
#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(2);
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 );
XSelectInput( dpy, w, KeyPressMask | KeyReleaseMask );
while (1) {
XEvent event;
XNextEvent( dpy, &event );
cout << "!" << endl;
}
XCloseDisplay( dpy );
return 0;
}