static void do_timer_proc(Timer tm, UINT id) { if ( tm->status != NAME_repeat ) { KillTimer(NULL, id); deleteHashTable(TimerTable, toInt(id)); assign(tm, status, NAME_idle); } executeTimer(tm); RedrawDisplayManager(TheDisplayManager()); }
static void x_event_window(PceWindow sw, XEvent *event) { EventObj ev; FrameObj fr = getFrameWindow(sw, OFF); FrameObj bfr; Any receiver = sw; #ifdef O_XDND if ( event->xany.type == MapNotify ) { if ( hasSendMethodObject(sw, NAME_dropFiles) ) setDndAwareFrame(fr); } #endif /*O_XDND*/ if ( fr && (bfr=blockedByModalFrame(fr)) ) { switch( event->xany.type ) { case KeyPress: { receiver = bfr; break; } case ButtonRelease: send(fr, NAME_bell, EAV); case ButtonPress: send(bfr, NAME_expose, EAV); default: return; } } if ( (ev = CtoEvent(sw, event)) ) { addCodeReference(ev); postNamedEvent(ev, receiver, DEFAULT, NAME_postEvent); delCodeReference(ev); freeableObj(ev); RedrawDisplayManager(TheDisplayManager()); /* optional? */ } }
status ws_dispatch(Int FD, Any timeout) { XtIntervalId tid = 0; XtInputId iid = 0; status rval = SUCCEED; int ofd = dispatch_fd; int fd = (isDefault(FD) ? dispatch_fd : isNil(FD) ? -1 : valInt(FD)); /* No context: wait for input */ /* timeout */ if ( ThePceXtAppContext == NULL ) { int ready; #ifdef HAVE_POLL int to; struct pollfd fds[1]; if ( isNil(timeout) ) { to = -1; } else if ( isDefault(timeout) ) { to = 250; } else if ( isInteger(timeout) ) { to = valInt(timeout); } else if ( instanceOfObject(timeout, ClassReal) ) { to = (int)(valReal(timeout)*1000.0); } else to = 256; fds[0].fd = fd; fds[0].events = POLLIN; ready = poll(fds, 1, to); #else struct timeval to; struct timeval *tp = &to; fd_set readfds; int setmax = 0; if ( isNil(timeout) ) { tp = NULL; } else if ( isDefault(timeout) ) { to.tv_sec = 0; to.tv_usec = 250000; } else { double v; if ( isInteger(timeout) ) v = (double)valInt(timeout)/1000.0; else if ( instanceOfObject(timeout, ClassReal) ) v = valReal(timeout); else v = 0.25; to.tv_sec = (long)v; to.tv_usec = (long)(v * 1000000.0) % 1000000; } FD_ZERO(&readfds); if ( fd >= 0 ) { FD_SET(fd, &readfds); setmax = max(setmax, fd); dispatch_fd = fd; } ready = select(setmax+1, &readfds, NULL, NULL, tp); #endif dispatch_fd = ofd; return (ready > 0 ? SUCCEED : FAIL); } /* A display: dispatch until there */ /* is input or a timeout */ if ( fd >= 0 ) { iid = XtAppAddInput(ThePceXtAppContext, fd, (XtPointer) XtInputReadMask, is_pending, NULL); dispatch_fd = fd; } if ( notNil(timeout) ) { long to = -1; if ( isInteger(timeout) ) to = valInt(timeout); else if ( instanceOfObject(timeout, ClassReal) ) to = (long)(valReal(timeout)*1000.0); if ( to > 0 ) tid = XtAppAddTimeOut(ThePceXtAppContext, to, is_timeout, (XtPointer) &rval); } DEBUG(NAME_dispatch, Cprintf("Dispatch: timeout = %s, tid = %p\n", pp(timeout), (void*)tid)); if ( pceMTTryLock(LOCK_PCE) ) { RedrawDisplayManager(TheDisplayManager()); pceMTUnlock(LOCK_PCE); } /* All callbacks must be locked! */ XtAppProcessEvent(ThePceXtAppContext, XtIMXEvent|XtIMTimer|XtIMAlternateInput); if ( tid && rval ) /* if rval = FAIL, we had a timeout */ XtRemoveTimeOut(tid); if ( iid ) XtRemoveInput(iid); dispatch_fd = ofd; considerLocStillEvent(); return rval; }