नहीं। यही कारण है कि अधिकांश यूआई ढांचे (जीटीके, केडीई, आदि) कस्टम मुख्य लूप का उपयोग अधिक घटना स्रोतों को सुनने में सक्षम होने के लिए करते हैं।
आंतरिक रूप से, XNextEvent सॉकेट का उपयोग करता है, इसलिए इनपुट उपलब्ध होने पर यह जानने के लिए select()
पर कॉल किया जाता है। तो आप: ConnectionNumber(display)
पर फ़ाइल डिस्क्रिप्टर को प्राप्त करने के लिए कॉल करें जिसे आपको select()
आपको कई फ़ाइल डिस्क्रिप्टर सुनने की अनुमति देता है।
नमूना कोड http://www.linuxquestions.org/questions/showthread.php?p=2431345#post2431345
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
Display *dis;
Window win;
int x11_fd;
fd_set in_fds;
struct timeval tv;
XEvent ev;
int main() {
dis = XOpenDisplay(NULL);
win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 1, 1, 256, 256, \
0, BlackPixel (dis, 0), BlackPixel(dis, 0));
// You don't need all of these. Make the mask as you normally would.
XSelectInput(dis, win,
ExposureMask | KeyPressMask | KeyReleaseMask | PointerMotionMask |
ButtonPressMask | ButtonReleaseMask | StructureNotifyMask
);
XMapWindow(dis, win);
XFlush(dis);
// This returns the FD of the X11 display (or something like that)
x11_fd = ConnectionNumber(dis);
// Main loop
while(1) {
// Create a File Description Set containing x11_fd
FD_ZERO(&in_fds);
FD_SET(x11_fd, &in_fds);
// Set our timer. One second sounds good.
tv.tv_usec = 0;
tv.tv_sec = 1;
// Wait for X Event or a Timer
int num_ready_fds = select(x11_fd + 1, &in_fds, NULL, NULL, &tv);
if (num_ready_fds > 0)
printf("Event Received!\n");
else if (num_ready_fds == 0)
// Handle timer here
printf("Timer Fired!\n");
else
printf("An error occured!\n");
// Handle XEvents and flush the input
while(XPending(dis))
XNextEvent(dis, &ev);
}
return(0);
}
स्रोत
2011-12-21 16:21:08
हाय हारून यह एक शानदार समाधान है। यह केवल उस खिड़की में घटनाओं को पकड़ रहा है, क्या वैश्विक स्तर पर माउस घटनाओं को सुनना संभव है? और इस विधि के साथ माउस घटनाओं को ब्लॉक करने के लिए संभव है? – Noitidart
@ नोइटिडार्ट: शायद लेकिन मैं उस टिप्पणी में इसका उत्तर नहीं दे सकता। एक नया प्रश्न पूछें, कृपया और अधिक जानकारी देने के लिए मत भूलना कि आपको वास्तव में क्या हासिल करने की आवश्यकता है। –
आह धन्यवाद, मैंने यहां प्रश्न पोस्ट किया है: http://stackoverflow.com/questions/32262767/mouse-events-callback – Noitidart