1 | bool QApplication::x11EventFilter ( XEvent * ) |
1 | bool QCoreApplication::winEventFilter ( MSG * msg, long * result ) |
1 | bool QApplication::macEventFilter ( EventHandlerCallRef caller, EventRef event ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <stdio.h> #include <X11/X.h> #include <X11/Xlib.h> char line[80]; unsigned long winID, mask; XEvent ev; Display *disp; Status status; int main(int argc, char *argv[]){ disp = XOpenDisplay(NULL); if(!disp){ perror("Unable to open X display"); exit(1); } do{ printf("Enter a line: "); fgets(line, 80, stdin); if(line[0] != 'q'){ winID = strtol(line, NULL, 16); printf("You entered %d:0x%x\n", winID, winID); ev.xclient.type = ClientMessage; ev.xclient.window = winID; ev.xclient.message_type = 0; ev.xclient.format = 8; ev.xclient.data.b[0] = '2'; ev.xclient.data.b[1] = '0'; ev.xclient.data.b[2] = '0'; ev.xclient.data.b[3] = '8'; ev.xclient.data.b[4] = '\0'; mask = 0l; status = XSendEvent(disp, winID, False, mask, &ev); printf("The XSendEvent returned: %d\n", status); XFlush(disp); } }while(line[0] != 'q'); } |
1 | gcc xclient.c –o xclient –lX11 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <stdio.h> #include <qapplication.h> #include <qpushbutton.h> #include <qdialog.h> #include <X11/Xlib.h> class App: public QApplication { public: App(int argc, char **argv): QApplication(argc, argv) { } #if defined(Q_WS_X11) bool x11EventFilter(XEvent *xe) { switch (xe->type) { case ClientMessage: printf("Caught ClientMessage XEvent from Window %d \n", xe->xclient.window); printf("Receive message: %s\n", xe->xclient.data.s); return true; } return false; } #endif }; class Dialog: public QDialog { public: Dialog(QWidget *parent = 0): QDialog(parent) { QPushButton *done = new QPushButton("Done", this); connect(done, SIGNAL(clicked()), qApp, SLOT(quit())); } }; int main(int argc, char **argv) { App app(argc, argv); Dialog dialog; app.setMainWidget(&dialog); dialog.show(); return app.exec(); } |
1 2 | g++ qtx11filter.c -L/usr/lib/qt-3.3/lib -I/usr/lib/qt-3.3/include -lqt-mt –lX11 -o qtx11filter |
1 | ./qtx11filter |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |