// --------------------------------------------------------------------------- void X11GUIFactory::processEvents() { for(;;) { int nevents = XEventsQueued(xdisplay, QueuedAfterReading); if (nevents == 0) return; while(nevents--) { XEvent ev; XNextEvent(xdisplay,&ev); X11WindowImpl* impl = windowMap[ev.xany.window]; if (impl) impl->processEvent(ev); #ifdef RGL_X11_DEBUG else fprintf(stderr,"unknown window id %lx(code %lx)\n" , static_cast<long>(ev.xany.window) , static_cast<long>(ev.type) ); #endif } } }
static void borisgl_loop(void) { XEvent ev; while (1) { game_paint(); // glFlush(); glXSwapBuffers(dpy, win); // glXWaitGL(); while (XEventsQueued(dpy, QueuedAfterFlush)) { XNextEvent(dpy, &ev); switch (ev.type) { case KeyPress: if (XLookupKeysym(&ev.xkey, 0) == XK_Escape) return; break; case ClientMessage: if (ev.xclient.message_type == wm_protocols && (Atom)ev.xclient.data.l[0] == wm_delete_window) return; break; } } } }
/* * Enter a loop processing X events & polling chars until we see a result */ static void serverWait(VimRemotingClient *client, Window w, VimRemotingClient_EndCond endCond, void *endData, int seconds) { time_t start; time_t now; time_t lastChk = 0; XEvent event; XPropertyEvent *e = (XPropertyEvent *)&event; int fd = ConnectionNumber(client->dpy); time(&start); while (!endCond(endData)) { time(&now); /* Just look out for the answer without calling back into Vim */ pollFor(fd, ((start + seconds) - now) * 1000); if (!isWindowValid(client, w)) break; while (XEventsQueued(client->dpy, QueuedAfterReading) > 0) { XNextEvent(client->dpy, &event); if (event.type == PropertyNotify && e->window == client->window) { serverEventProc(client, &event); } } } }
JNIEXPORT int JNICALL Java_sun_awt_X11_XlibWrapper_XEventsQueued (JNIEnv *env, jclass clazz, jlong display, jint mode) { AWT_CHECK_HAVE_LOCK(); return XEventsQueued((Display *) display, mode); }
/* Ack! XPending() actually performs a blocking read if no events available */ static int X11_Pending(Display * display) { /* Flush the display connection and look to see if events are queued */ XFlush(display); if (XEventsQueued(display, QueuedAlready)) { return (1); } /* More drastic measures are required -- see if X is ready to talk */ { static struct timeval zero_time; /* static == 0 */ int x11_fd; fd_set fdset; x11_fd = ConnectionNumber(display); FD_ZERO(&fdset); FD_SET(x11_fd, &fdset); if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) { return (XPending(display)); } } /* Oh well, nothing is ready .. */ return (0); }
void X11Handler::onDataReadable() { if ( !XEventsQueued( _dpy, QueuedAfterFlush) ) XSync( _dpy, 0 ); while( XPending( _dpy ) ) handleEvents(); }
/** * XPending() actually performs a blocking read * if no events available. From Fakk2, by way of * Heretic2, by way of SDL, original idea GGI project. * The benefit of this approach over the quite * badly behaved XAutoRepeatOn/Off is that you get * focus handling for free, which is a major win * with debug and windowed mode. It rests on the * assumption that the X server will use the * same timestamp on press/release event pairs * for key repeats. */ static qboolean X11_PendingInput( void ) { assert( dpy != NULL ); // Flush the display connection // and look to see if events are queued XFlush( dpy ); if ( XEventsQueued( dpy, QueuedAlready ) ) { return qtrue; } // More drastic measures are required -- see if X is ready to talk { static struct timeval zero_time; int x11_fd; fd_set fdset; x11_fd = ConnectionNumber( dpy ); FD_ZERO( &fdset ); FD_SET( x11_fd, &fdset ); if ( select( x11_fd + 1, &fdset, NULL, NULL, &zero_time ) == 1 ) { return( XPending( dpy ) ); } } // Oh well, nothing is ready .. return qfalse; }
void processEvents() { PLock lock(&changeLock); XLockDisplay(disp()); while (XEventsQueued(disp(), QueuedAfterReading) > 0) { XEvent ev; XNextEvent(disp(), &ev); if (ev.type == ConfigureNotify) changedWindows.insert(ev.xconfigure.event); if (ev.type == MapNotify) changedWindows.insert(ev.xmap.event); if (ev.type == Expose) changedWindows.insert(ev.xexpose.window); if (ev.type == DestroyNotify) changedWindows.insert(ev.xdestroywindow.event); } XUnlockDisplay(disp()); }
MapSelect() { int n; XEvent event; n = XEventsQueued(dpy, QueuedAfterFlush); while (n--) { XNextEvent(dpy, &event); switch(event.type) { case KeyPress: if (KeySelect(&event)) return(1); break; case Expose: Show_Maps(numselect); break; case ButtonPress: if (ButtonSelect(&event)) return(1); break; } } return(0); }
/* EXPORT->HGetEvent: return next relevant event in event queue */ HEventRec HGetEvent(Boolean anyEvent, void (*action)(void)) { XEvent xev; HEventRec hev; Boolean found,dummy; XFlush(theDisp); found = FALSE; do { if(XEventsQueued(theDisp, QueuedAfterFlush) > 0 || action==NULL){ XNextEvent(theDisp, &xev); found = TRUE; if (xev.xany.window==theWindow || anyEvent){ switch (xev.type) { case ButtonPress: hev.event = HMOUSEDOWN; hev.x = xev.xbutton.x; hev.y = xev.xbutton.y; break; case ButtonRelease: hev.event = HMOUSEUP; hev.x = xev.xbutton.x; hev.y = xev.xbutton.y; break; case MotionNotify: hev.event = HMOUSEMOVE; hev.x = xev.xmotion.x; hev.y = xev.xmotion.y; break; case KeyPress: hev.event = HKEYPRESS; hev.x = xev.xkey.x; hev.y = xev.xkey.y; DecodeKeyPress(&(xev.xkey), &hev); break; case KeyRelease: hev.event = HKEYRELEASE; hev.x = xev.xkey.x; hev.y = xev.xkey.y; DecodeKeyPress(&(xev.xkey), &hev); break; case Expose: if (xev.xexpose.count==0) hev.event = HREDRAW; else found = FALSE; break; default: found = FALSE; } } } else if (action!=NULL){ (*action)(); XFlush(theDisp); /* execute a round-robin command to make sure that */ /* client doesnt get too far ahead of the server */ dummy = HMousePos(&hev.x,&hev.y); } } while (!found); return hev; }
void Application::run(int argc, char *argv[]) { DOUT("Application::run()"); ApplicationEventPtr applicationEvent = ApplicationEvent::create(ApplicationEvent::RUN()); eventDispatcher->dispatchEvent(applicationEvent); XEvent event; int fd = ConnectionNumber(hiddenMembers->display); while(running) { XFlush(hiddenMembers->display); struct timeval tv; fd_set rfds; FD_ZERO(&rfds); FD_SET(fd,&rfds); memset(&tv,0,sizeof(tv)); tv.tv_usec = 100000; /* delay in microseconds = 100 milliseconds */ if (select(fd+1,&rfds,0,0,&tv) > 0) { XSync(hiddenMembers->display, False); while(XEventsQueued(hiddenMembers->display, QueuedAlready) > 0) { XNextEvent(hiddenMembers->display, &event); switch (event.type) { case ClientMessage: if (event.xclient.data.l[0] == hiddenMembers->WM_WAKEUP) { DOUT("wakeup!"); break; } default: if (event.xclient.window) { linux_::WindowHandler* windowHandler = NULL; if (xWindows.find(event.xclient.window) != xWindows.end()) { windowHandler = xWindows[event.xclient.window]; } if (windowHandler != NULL) { windowHandler->handleEvent(event); } } break; } XFlush(hiddenMembers->display); } } eventDispatcher->processEvents(); } }
/// Ignore X events which have already arrived. This is to prevent /// checking the fullscreen status multiple times when there are /// multiple events in the event queue. Also, when the session state /// property is unsubscribed, the event queue is cleared, so that the /// events don't get processed if the property is re-subscribed. void SessionStatePlugin::cleanXEventQueue() { int numEvents = XEventsQueued(dpy, QueuedAfterReading); XEvent event; for (int i=0; i<numEvents; ++i) { XNextEvent(dpy, &event); } }
int XPending(Display * dpy) { #ifdef DEBUG printf("XPending "); #endif return XEventsQueued(dpy, QueuedAfterFlush); }
void StackDebugger::loadStack (CompWindowList &serverWindows, bool wait) { Window rootRet, parentRet; if (mServerChildren) XFree (mServerChildren); XSync (mDpy, FALSE); XGrabServer (mDpy); XQueryTree (mDpy, mRoot, &rootRet, &parentRet, &mServerChildren, &mServerNChildren); unsigned int n = XEventsQueued (mDpy, QueuedAfterFlush); mEvents.clear (); mEvents.resize (n); std::list <XEvent>::iterator it = mEvents.begin (); while (it != mEvents.end ()) { mFetchXEvent->getNextXEvent ((*it)); ++it; } XSync (mDpy, FALSE); /* It is possible that X might not be keeping up with us, so * we should give it about 300 ms in case the stacks are out of sync * in order to deliver any more events that might be pending */ mTimeoutRequired = false; mLastServerWindows = serverWindows; if (mServerNChildren != serverWindows.size () && wait) { struct pollfd pfd; pfd.events = POLLIN; pfd.revents = 0; pfd.fd = ConnectionNumber (mDpy); poll (&pfd, 1, 300); XEvent e; while (mFetchXEvent->getNextXEvent (e)) mEvents.push_back (e); mTimeoutRequired = true; } mDestroyedFrames.clear (); XUngrabServer (mDpy); XSync (mDpy, FALSE); }
int ui_event(void) { XEvent event; XFlush( display ); while( XEventsQueued( display, QueuedAlready ) ) { XNextEvent( display, &event ); switch(event.type) { case ConfigureNotify: xdisplay_configure_notify(event.xconfigure.width, event.xconfigure.height); break; case Expose: xdisplay_area( event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height ); break; case ButtonPress: ui_mouse_button( event.xbutton.button, 1 ); break; case ButtonRelease: ui_mouse_button( event.xbutton.button, 0 ); break; case MotionNotify: if( ui_mouse_grabbed ) { ui_mouse_motion( event.xmotion.x - 128, event.xmotion.y - 128 ); if( event.xmotion.x != 128 || event.xmotion.y != 128 ) XWarpPointer( display, None, xui_mainWindow, 0, 0, 0, 0, 128, 128 ); } break; case FocusOut: keyboard_release_all(); ui_mouse_suspend(); break; case FocusIn: ui_mouse_resume(); break; case KeyPress: xkeyboard_keypress(&(event.xkey)); break; case KeyRelease: xkeyboard_keyrelease(&(event.xkey)); break; case ClientMessage: if( event.xclient.format == 32 && event.xclient.data.l[0] == delete_window_atom ) { fuse_emulation_pause(); menu_file_exit(0); fuse_emulation_unpause(); } break; } } return 0; }
int CompressMNEvent(XEvent *event) { XEvent ahead; while (XEventsQueued(event->xmotion.display, QueuedAfterReading) > 0) { XPeekEvent(event->xmotion.display, &ahead); if (MotionNotify != ahead.type) return 1; if (ahead.xmotion.window != event->xmotion.window) return 1; XNextEvent(event->xmotion.display, event); } return 0; }
static gii_event_mask GII_xdga_eventpoll(gii_input *inp, void *arg) { xdga_priv *priv = XDGA_PRIV(inp); XEvent xev; XDGAEvent *dgaev = (XDGAEvent *)&xev; gii_event giiev; int n; int rc = 0; int dga_event_base = priv->event_base; XSync( priv->disp, False ); for(n=XEventsQueued(priv->disp, QueuedAfterReading); n ; n-- ) { int keycode; XNextEvent(priv->disp, &xev); keycode = dgaev->xkey.keycode; _giiEventBlank( &giiev, sizeof(gii_event) ); switch(dgaev->type - dga_event_base ) { case KeyPress: prepare_key_event(inp, &giiev, keycode, dgaev); if( TestFlag( priv->key_vector, keycode) ) { giiev.any.type = evKeyRepeat; rc |= emKeyRepeat; } else { giiev.any.type = evKeyPress; rc |= emKeyPress; } /*DPRINT("press(%c)\n", giiev.key.sym);*/ SetFlag(priv->key_vector, keycode); _giiEvQueueAdd(inp, &giiev ); break; case KeyRelease: prepare_key_event(inp, &giiev, keycode, dgaev); giiev.any.type = evKeyRelease; rc |= emKeyRelease; /* DPRINT("release(%c)\n", giiev.key.sym);*/ ClearFlag(priv->key_vector, keycode); _giiEvQueueAdd(inp, &giiev); break; } } return rc; }
static int processX(void) { XEvent event; if (XEventsQueued(xDisplay, QueuedAfterFlush) == 0) { return 0; } XNextEvent(xDisplay, &event); switch (event.type) { // the following event type is selected by KeyPressMask case KeyPress: keypress(&event); break; // the following event type is selected by ExposureMask case Expose: repaint(); break; // the following event types are selected by StructureNotifyMask case ConfigureNotify: windowWidth = event.xconfigure.width; windowHeight = event.xconfigure.height; glViewport(0, 0, windowWidth, windowHeight); break; case ReparentNotify: break; case DestroyNotify: exit(0); case CirculateNotify: case GravityNotify: case MapNotify: case UnmapNotify: // the following event types are always selected case MappingNotify: case ClientMessage: case SelectionClear: case SelectionNotify: case SelectionRequest: default: fprintf(stderr, "got event type %d\n", event.type); break; } return 1; }
void X11KeyFaker::readyRead() { if (dpy) { // Read incoming events and discard them. The only event // we care about is keyboard mapping changes. Since we // don't have any active windows, there's nothing more to do. while (XEventsQueued(dpy, QueuedAfterFlush)) { XEvent event; XNextEvent(dpy, &event); if (event.xany.type == MappingNotify) XRefreshKeyboardMapping(&event.xmapping); } } }
int XQLength(Display * dpy) { FUNC_ENTER; /* FIXME? * FLTK hack: FLTK spins calling XQLength and * then select(). Since Microwindows won't return * an event without having called GrPeekEvent, * using QueuedAfterReading rather than QueuedAlready * makes FLTK work. */ /*return XEventsQueued(dpy, QueuedAlready);*/ return XEventsQueued(dpy, QueuedAfterReading); }
static LCUI_BOOL X11_WaitEvent( void ) { int fd; fd_set fdset; struct timeval zero_time; XFlush( x11.display ); fd = ConnectionNumber( x11.display ); if( XEventsQueued(x11.display, QueuedAlready) ) { return TRUE; } FD_ZERO( &fdset ); FD_SET( fd, &fdset ); if( select(fd + 1, &fdset, NULL, NULL, &zero_time) == 1 ) { return XPending( x11.display ); } return FALSE; }
static gboolean read_events(gboolean block) { gint sth, n; n = XEventsQueued(t_display, QueuedAfterFlush) > 0; sth = FALSE; while((block && !sth) || n > 0) { XEvent e; if(XNextEvent(t_display, &e) != Success) return FALSE; grow(); ++qnum; qend = (qend + 1) % qsz; q[qend] = e; --n; sth = TRUE; } return sth; }
/* Discards keyrepeat by removing the keypress event from the queue. * The pair keyrelease/keypress is always put together in the queue, * by removing the keypress, we only worry about keyrelease. In case * of a keyrelease, we ignore it if the next event is a keypress (which * means repetition. Otherwise it is a real keyrelease. * * Returns 1 if the keypress is found in the queue and 0 otherwise. */ static int motKeyDiscardKeypressRepeat(XEvent *evt) { XEvent ahead; if (XEventsQueued(iupmot_display, QueuedAfterReading)) { XPeekEvent(iupmot_display, &ahead); if (ahead.type == KeyPress && ahead.xkey.window == evt->xkey.window && ahead.xkey.keycode == evt->xkey.keycode && ahead.xkey.time == evt->xkey.time) { /* Pop off the repeated KeyPress and ignore */ XNextEvent(iupmot_display, evt); /* Ignore the auto repeated KeyRelease/KeyPress pair */ return 1; } } /* No KeyPress found */ return 0; }
/* XNextEvent() with timeout */ static Bool XNextEventTimeout( Display *display, XEvent *event_return, struct timeval *timeout ) { int res; fd_set readfds; int display_fd = XConnectionNumber(display); /* small shortcut... */ if( timeout == NULL ) { XNextEvent(display, event_return); return(True); } FD_ZERO(&readfds); FD_SET(display_fd, &readfds); /* Note/bug: In the case of internal X events (like used to trigger callbacks * registered by XpGetDocumentData()&co.) select() will return with "new info" * - but XNextEvent() below processes these _internal_ events silently - and * will block if there are no other non-internal events. * The workaround here is to check with XEventsQueued() if there are non-internal * events queued - if not select() will be called again - unfortunately we use * the old timeout here instead of the "remaining" time... (this only would hurt * if the timeout would be really long - but for current use with values below * 1/2 secs it does not hurt... =:-) */ while( XEventsQueued(display, QueuedAfterFlush) == 0 ) { res = select(display_fd+1, &readfds, NULL, NULL, timeout); switch(res) { case -1: /* select() error - should not happen */ perror("XNextEventTimeout: select() failure"); return(False); case 0: /* timeout */ return(False); } } XNextEvent(display, event_return); return(True); }
static void DisplayFileProc( ClientData clientData, /* The display pointer. */ int flags) /* Should be TCL_READABLE. */ { TkDisplay *dispPtr = (TkDisplay *) clientData; Display *display = dispPtr->display; int numFound; XFlush(display); numFound = XEventsQueued(display, QueuedAfterReading); if (numFound == 0) { /* * Things are very tricky if there aren't any events readable at this * point (after all, there was supposedly data available on the * connection). A couple of things could have occurred: * * One possibility is that there were only error events in the input * from the server. If this happens, we should return (we don't want * to go to sleep in XNextEvent below, since this would block out * other sources of input to the process). * * Another possibility is that our connection to the server has been * closed. This will not necessarily be detected in XEventsQueued (!!) * so if we just return then there will be an infinite loop. To detect * such an error, generate a NoOp protocol request to exercise the * connection to the server, then return. However, must disable * SIGPIPE while sending the request, or else the process will die * from the signal and won't invoke the X error function to print a * nice (?!) message. */ void (*oldHandler)(); oldHandler = (void (*)()) signal(SIGPIPE, SIG_IGN); XNoOp(display); XFlush(display); (void) signal(SIGPIPE, oldHandler); } TransferXEventsToTcl(display); }
DWORD DriverPeekTypedEvent(int event_type, Window w) { XEvent Report; Bool bIsEvent; int nCount = 0; PRIVATEDISPLAY *dp; dp = GETDP(); if (XEventsQueued(dp->display,QueuedAfterFlush)) { while ((bIsEvent = (w == (Window)0))? XCheckTypedEvent(dp->display,event_type,&Report): XCheckTypedWindowEvent(dp->display,w,event_type,&Report)) { nCount++; DriverPrivateEvents(&Report); } } return (DWORD)nCount; }
/** * Checks for x window system messages (events). * * As an exception to other procedures in CYBOI, parameters are NOT handed over * as void* to this procedure, in order to avoid type casts and to gain faster * processing results. * * Another exception is that this procedure is actually a function, since it * returns a value, as opposed to other procedures in CYBOI which return * nothing (void). * * @param mt the mutex * @param d the display */ int sense_x_window_system_check_events(pthread_mutex_t* mt, struct _XDisplay* d) { // The number of events. int n = *NUMBER_0_INTEGER_MEMORY_MODEL; pthread_mutex_lock(mt); // Check the number of events in the event queue. // XEventsQueued always returns immediately without // input/ output if there are events already in the queue. // // There are three possible modes: // 1 QueuedAlready: XEventsQueued returns the number of events // already in the event queue (and never performs a system call). // XEventsQueued with mode QueuedAlready is identical // to the XQLength function. // 2 QueuedAfterFlush: XEventsQueued returns the number of events // already in the queue if the number is nonzero. If there are no // events in the queue, XEventsQueued flushes the output buffer, // attempts to read more events out of the applications connection, // and returns the number read. // 3 QueuedAfterReading: XEventsQueued returns the number of events // already in the queue if the number is nonzero. If there are no // events in the queue, XEventsQueued attempts to read more events // out of the applications connection WITHOUT flushing the output // buffer and returns the number read. // // The decision fell on mode number 3, because: // - mode number 1 did not display the x window initially, since // probably no expose events are placed in the queue at startup // - mode number 2 is undesirable, since it would flush the output // buffer and might thus cause this sense-thread to conflict // with the send_x_window_system procedure of the main thread n = XEventsQueued(d, QueuedAfterReading); pthread_mutex_unlock(mt); return n; }
static void ccm_display_process_events (CCMWatch* watch) { g_return_if_fail (watch != NULL); CCMDisplay* self = CCM_DISPLAY (watch); XEvent xevent; gboolean have_create_notify = FALSE; while (!have_create_notify && XEventsQueued (CCM_DISPLAY_XDISPLAY (self), QueuedAfterReading)) { XNextEvent (CCM_DISPLAY_XDISPLAY (self), &xevent); ccm_debug ("EVENT %i", xevent.type); if (xevent.type == self->priv->damage.event_base + XDamageNotify) { XDamageNotifyEvent* event_damage = (XDamageNotifyEvent *)&xevent; CCMDamageCallback* callback; callback = (CCMDamageCallback*)ccm_set_search (self->priv->registered_damage, G_TYPE_UINT, NULL, NULL, (gpointer)event_damage->damage, (CCMSetValueCompareFunc)ccm_damage_callback_compare_with_damage); if (callback) { g_signal_emit (self, signals[DAMAGE_EVENT], 0, event_damage->damage, callback->drawable); } } else { g_signal_emit (self, signals[EVENT], 0, &xevent); if (xevent.type == CreateNotify) have_create_notify = TRUE; } } }
static void do_gui(duc *duc, duc_graph *graph, duc_dir *dir) { pfd.fd = ConnectionNumber(dpy); pfd.events = POLLIN | POLLERR; int quit = 0; while(!quit) { if(redraw) { draw(); XFlush(dpy); redraw = 0; } int r = poll(&pfd, 1, 10); if(r == 0) { if(tooltip_moved) { tooltip_moved = 0; redraw = 1; } } while (XEventsQueued(dpy, QueuedAfterReading) > 0) { XEvent e; XNextEvent(dpy, &e); quit = handle_event(e); } } cairo_surface_destroy(cs); XCloseDisplay(dpy); }
void QXlibScreen::eventDispatcher() { ulong marker = XNextRequest(mDisplay->nativeDisplay()); // int i = 0; while (XPending(mDisplay->nativeDisplay())) { XEvent event; XNextEvent(mDisplay->nativeDisplay(), &event); /* done = */ handleEvent(&event); if (event.xany.serial >= marker) { #ifdef MYX11_DEBUG qDebug() << "potential livelock averted"; #endif #if 0 if (XEventsQueued(mDisplay->nativeDisplay(), QueuedAfterFlush)) { qDebug() << " with events queued"; QTimer::singleShot(0, this, SLOT(eventDispatcher())); } #endif break; } } }