CV_IMPL int cvWaitKey (int maxWait) { EventRecord theEvent; // wait at least for one event (to allow mouse, etc. processing), exit if maxWait milliseconds passed (nullEvent) UInt32 start = TickCount(); int iters=0; do { // remaining time until maxWait is over UInt32 wait = EventTimeToTicks (maxWait / 1000.0) - (TickCount() - start); if ((int)wait <= 0) { if( maxWait > 0 && iters > 0 ) break; wait = 1; } iters++; WaitNextEvent (everyEvent, &theEvent, maxWait > 0 ? wait : kDurationForever, NULL); } while (lastKey == NO_KEY && theEvent.what != nullEvent); int key = lastKey; lastKey = NO_KEY; return key; }
NLM_EXTERN EIO_Status VecScreenWaitForReply ( CONN conn ) { time_t currtime, starttime; time_t max = 0; EIO_Status status; STimeout timeout; #ifdef OS_MAC EventRecord currEvent; #endif if (conn == NULL) return eIO_Unknown; #ifdef OS_MAC timeout.sec = 0; timeout.usec = 0; #else timeout.sec = 100; timeout.usec = 0; #endif starttime = GetSecs (); while ((status = CONN_Wait (conn, eIO_Read, &timeout)) == eIO_Timeout && max < 300) { currtime = GetSecs (); max = currtime - starttime; #ifdef OS_MAC WaitNextEvent (0, &currEvent, 0, NULL); #endif } return status; }
static PyObject *Evt_WaitNextEvent(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; Boolean _rv; EventMask eventMask; EventRecord theEvent; UInt32 sleep; Handle mouseregion = (Handle)0; if (!PyArg_ParseTuple(_args, "Hl|O&", &eventMask, &sleep, OptResObj_Convert, &mouseregion)) return NULL; _rv = WaitNextEvent(eventMask, &theEvent, sleep, (RgnHandle)mouseregion); _res = Py_BuildValue("bO&", _rv, PyMac_BuildEventRecord, &theEvent); return _res; }
static void ctl_pass_playing_list(int init_number_of_files, char * /*init_list_of_files*/ []) { EventRecord event; if( init_number_of_files!=0 ){ cmsg(CMSG_FATAL, VERB_NORMAL, "ctl_pass_playing_list: Sorry. Fatal error."); } #ifdef MAC_USE_OMS mac_oms_setup(); #endif { FSSpec spec; OSErr err; err=FSMakeFSSpec(0, 0, MAC_STARTUP_FOLDER_NAME, &spec); if( err==noErr ){ mac_add_fsspec( &spec ); } } gQuit=false; while(!gQuit) { WaitNextEvent(everyEvent, &event, 1,0); mac_HandleEvent(&event); } DoQuit(); }
/* ----------- entry point */ int main( void) { EventRecord event; initialize_application(); while (!quitting) { if(WaitNextEvent(everyEvent, &event, 1, NULL)) { /* Process the event.. */ process_event(&event); } else { short index; /* Idling code.. */ idle(); /* Do things that can only be done at system time */ for(index= 0; index<new_endpoint_cache.count; ++index) { attach_new_endpoint_to_application(new_endpoint_cache.endpoints[index].endpoint, new_endpoint_cache.endpoints[index].title, true); } new_endpoint_cache.count= 0; } } app_done = true; return 0; }
static int HandleMacEvents(void) { EventRecord theEvent; int eventFound = 0, needsUpdate = 0; Point currentMouse; WindowRef windowRef; Rect mouseRect; /* * Check for mouse moved events. These events aren't placed on the * system event queue unless we call WaitNextEvent. */ GetGlobalMouse(¤tMouse); if ((notifier.eventProcPtr != NULL) && !EqualPt(currentMouse, notifier.lastMousePosition)) { notifier.lastMousePosition = currentMouse; theEvent.what = nullEvent; if ((*notifier.eventProcPtr)(&theEvent) == true) { eventFound = 1; } } /* * Check for update events. Since update events aren't generated * until we call GetNextEvent, we may need to force a call to * GetNextEvent, even if the queue is empty. */ for (windowRef = FrontWindow(); windowRef != NULL; windowRef = GetNextWindow(windowRef)) { GetWindowUpdateRgn(windowRef, notifier.utilityRgn); if (!EmptyRgn(notifier.utilityRgn)) { needsUpdate = 1; break; } } /* * Process events from the OS event queue. */ while (needsUpdate || (GetEvQHdr()->qHead != NULL)) { GetGlobalMouse(¤tMouse); SetRect(&mouseRect, currentMouse.h, currentMouse.v, currentMouse.h + 1, currentMouse.v + 1); RectRgn(notifier.utilityRgn, &mouseRect); WaitNextEvent(everyEvent, &theEvent, 5, notifier.utilityRgn); needsUpdate = 0; if ((notifier.eventProcPtr != NULL) && ((*notifier.eventProcPtr)(&theEvent) == true)) { eventFound = 1; } } return eventFound; }
void MacIdle(void) { extern logical anywarns; static long time = 0; EventRecord myEvent; WindowPtr whichWindow; #if TARGET_API_MAC_CARBON Rect tempRect; #endif char theChar; if (TickCount()<time) return; if (mac_quit_now) { anywarns = FALSE; /* kludge so that window doesn't sit around */ my_exit(1); } #if !TARGET_API_MAC_CARBON SystemTask(); #endif if (WaitNextEvent(everyEvent, &myEvent, 1, nil)) { if (!SIOUXHandleOneEvent(&myEvent)) switch (myEvent.what) { case mouseDown: switch (FindWindow(myEvent.where,&whichWindow)) { case inMenuBar: MenuSelect(myEvent.where); break; #if !TARGET_API_MAC_CARBON case inSysWindow: SystemClick(&myEvent,whichWindow); break; #endif case inContent: SelectWindow(whichWindow); break; case inDrag: #if TARGET_API_MAC_CARBON GetRegionBounds(GetGrayRgn(),&tempRect); DragWindow(whichWindow,myEvent.where,&tempRect); #else DragWindow(whichWindow,myEvent.where,&qd.screenBits.bounds); #endif break; } break; case keyDown: theChar = myEvent.message & charCodeMask; break; case updateEvt: BeginUpdate((WindowPtr) myEvent.message); EndUpdate((WindowPtr) myEvent.message); break; } } time=TickCount()+20; }
// YieldSomeTime() just cooperatively yields some time to other processes running on classic Mac OS static Boolean YieldSomeTime(UInt32 milliseconds) { extern Boolean SIOUXQuitting; EventRecord e; WaitNextEvent(everyEvent, &e, milliseconds / 17, NULL); SIOUXHandleOneEvent(&e); return(SIOUXQuitting); }
// we call WNE to allow tasks that own the resource the blue is waiting on system // task time, in case they are blocked on an ST remote call (or a memory allocation // for that matter). static void idle() { if(at_st()) { EventRecord sEvent; bool bEvent = WaitNextEvent(0U, &sEvent, 0UL, NULL); } }
void doEventLoop() { EventRecord event; WindowPtr window; short clickArea; Rect screenRect; RgnHandle rgnHandle = NewRgn(); for (;;) { if (WaitNextEvent( everyEvent, &event, 0, nil )) { if (event.what == mouseDown) { clickArea = FindWindow( event.where, &window ); if (clickArea == inDrag) { //screenRect = (**GetGrayRgn ()).rgnBBox; GetRegionBounds(GetGrayRgn(), &screenRect); DragWindow( window, event.where, &screenRect ); } else if (clickArea == inContent) { if (window != FrontWindow()) SelectWindow( window ); } else if (clickArea == inGoAway) if (TrackGoAway( window, event.where )) return; } else if (event.what == updateEvt) { window = (WindowPtr)event.message; //SetPort( window ); SetPortWindowPort( window ); BeginUpdate( window ); drawPixelImageData(); EndUpdate( window ); QDFlushPortBuffer(GetWindowPort(window), GetPortVisibleRegion(GetWindowPort(window), rgnHandle)); } else if (event.what == activateEvt) { /*if (event.modifiers & activeFlag) { window = (WindowPtr)event.message; SetPortWindowPort(window); drawPixelImageData(); QDFlushPortBuffer(GetWindowPort(window), GetPortVisibleRegion(GetWindowPort(window), rgnHandle)); }*/ /*if (event.modifiers & activeFlag) PostEvent(updateEvt, (unsigned long)gWindow);*/ } } } DisposeRgn(rgnHandle); }
/* If this function is NULL, polling is not needed */ static int GSDLLCALL gsdll_poll(void *handle) { EventRecord eventStructure; while (WaitNextEvent(everyEvent, &eventStructure, 0, NULL)) doEvents(&eventStructure); return (gDone ? e_Fatal : 0); }
/* ================== Sys_SendKeyEvents ================== */ void Sys_SendKeyEvents (void) { Boolean gotEvent; EventRecord event; if ( !glConfig.isFullscreen || sys_waitNextEvent->value ) { // this call involves 68k code and task switching. // do it on the desktop, or if they explicitly ask for // it when fullscreen gotEvent = WaitNextEvent(everyEvent, &event, 0, nil); } else { gotEvent = GetOSEvent( everyEvent, &event ); } // generate faked events from modifer changes Sys_ModifierEvents( event.modifiers ); sys_lastEventTic = event.when; if ( !gotEvent ) { return; } if ( Sys_ConsoleEvent(&event) ) { return; } switch(event.what) { case mouseDown: DoMouseDown(&event); break; case mouseUp: DoMouseUp(&event); break; case keyDown: DoKeyDown(&event); break; case keyUp: DoKeyUp(&event); break; case autoKey: DoKeyDown(&event); break; case updateEvt: DoUpdate((WindowPtr) event.message); break; case diskEvt: DoDiskEvent(&event); break; case activateEvt: DoActivate((WindowPtr) event.message, event.modifiers); break; case osEvt: DoOSEvent(&event); break; default: break; } }
/* * Input thread reading from device. * Generates events on incoming data. */ static void* osxEventThread( DirectThread *thread, void *driver_data ) { OSXInputData *data = (OSXInputData*) driver_data; DFBOSX *dfb_osx = data->dfb_osx; while (!data->stop) { DFBInputEvent evt; EventRecord event; fusion_skirmish_prevail( &dfb_osx->lock ); /* Check for events */ while ( WaitNextEvent( everyEvent, &event, 0, nil) ) { fusion_skirmish_dismiss( &dfb_osx->lock ); switch (event.what) { case keyDown: case keyUp: case autoKey: if (event.what == keyUp) evt.type = DIET_KEYRELEASE; else evt.type = DIET_KEYPRESS; if (translate_key( event.message & (charCodeMask | keyCodeMask), &evt )) { dfb_input_dispatch( data->device, &evt ); } break; case mouseDown: evt.type = DIET_BUTTONPRESS; evt.button = DIBI_LEFT; dfb_input_dispatch( data->device, &evt ); break; case mouseUp: evt.type = DIET_BUTTONRELEASE; evt.button = DIBI_LEFT; dfb_input_dispatch( data->device, &evt ); break; default: printf("%d\n",event.what); break; } fusion_skirmish_prevail( &dfb_osx->lock ); } fusion_skirmish_dismiss( &dfb_osx->lock ); usleep(10000); direct_thread_testcancel( thread ); } return NULL; }
void doEventLoop() { EventRecord anEvent; WindowPtr evtWind; short clickArea; Rect screenRect; Point thePoint; Rect zoomFrom, zoomTo; zoomFrom.top = zoomTo.top = -1; while (!gDone) { if (WaitNextEvent( everyEvent, &anEvent, 0, nil )) { if (anEvent.what == mouseDown) { clickArea = FindWindow( anEvent.where, &evtWind ); if (clickArea == inDrag) { GetRegionBounds( GetGrayRgn(), &screenRect ); DragWindow( evtWind, anEvent.where, &screenRect ); } else if (clickArea == inContent) { if (evtWind != FrontWindow()) SelectWindow( evtWind ); else { thePoint = anEvent.where; GlobalToLocal( &thePoint ); //Handle click in window content here GetRect(&zoomFrom, &zoomTo); } } else if (clickArea == inGoAway) if (TrackGoAway( evtWind, anEvent.where )) gDone = true; } else if (anEvent.what == updateEvt) { evtWind = (WindowPtr)anEvent.message; SetPortWindowPort( evtWind ); BeginUpdate( evtWind ); //Call Draw Function here.... if (zoomFrom.top != -1) FrameRect(&zoomFrom); if (zoomTo.top != -1) FrameRect(&zoomTo); EndUpdate (evtWind); } } } }
static void maineventloop (void) { EventRecord ev; while (!flexitmainloop) { WaitNextEvent (everyEvent, &ev, 2, nil); handleevent (&ev); } /*while*/ } /*maineventloop*/
static Rboolean Quartz_Locator(double *x, double *y, NewDevDesc *dd) { EventRecord event; SInt16 key; Boolean gotEvent; Boolean mouseClick = false; Point myPoint; WindowPtr window; SInt16 partCode; GrafPtr savePort; Cursor arrow ; QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific; int useBeep = asLogical(GetOption(install("locatorBell"), R_NilValue)); GetPort(&savePort); SetPortWindowPort(xd->window); SetThemeCursor(kThemeCrossCursor); while(!mouseClick) { gotEvent = WaitNextEvent( everyEvent, &event, 0, nil); CGContextFlush( GetContext(xd) ); if (event.what == mouseDown) { partCode = FindWindow(event.where, &window); if ((window == (xd->window)) && (partCode == inContent)) { myPoint = event.where; GlobalToLocal(&myPoint); *x = (double)(myPoint.h); *y = (double)(myPoint.v); if(useBeep) SysBeep(1); mouseClick = true; } } if (event.what == keyDown) { key = (event.message & charCodeMask); if (key == 0x1b){ /* exits when the esc key is pressed */ SetPort(savePort); SetThemeCursor(kThemeIBeamCursor); return FALSE; } } } SetPort(savePort); SetThemeCursor(kThemeIBeamCursor); return TRUE; }
int main() { EventRecord dummyEvent; UInt8 theChar; SIOUXSettings.autocloseonquit = true; SIOUXSettings.asktosaveonclose = false; SIOUXSettings.showstatusline = true; printf( "FSCopyObject 1.5\n\n" ); printf( "This is a test application to demonstrate FSCopyObject and FSDeleteObjects.\n" ); printf( "Type 'c' to run FSCopyObject with kDupeActionStandard\n" ); printf( "Type 'R' to run FSCopyObject with kDupeActionReplace\n" ); printf( "Type 'r' to run FSCopyObject with kDupeActionRename\n" ); printf( "Type 'd' to run FSDeleteObjects\n\n" ); printf( "Type 'q' to quit\n\n" ); while( !SIOUXQuitting ) { WaitNextEvent( everyEvent, &dummyEvent, 10, NULL ); if( dummyEvent.what == keyDown ) { theChar = (UInt8) (dummyEvent.message & charCodeMask); switch( theChar ) { case 'c': TestFSCopyObject( kDupeActionStandard ); break; case 'R': TestFSCopyObject( kDupeActionReplace ); break; case 'r': TestFSCopyObject( kDupeActionRename ); break; case 'd': TestFSDeleteObjects(); break; case 'q': SIOUXQuitting = true; break; } } else { SIOUXHandleOneEvent(&dummyEvent); } } return 0; }
/* WaitNextEventOrQuit() */ Boolean WaitNextEventOrQuit(int mask,EventRecord *eventPtr,unsigned long sleep,RgnHandle mouseRgn) { Boolean wne; if(CommandPeriod()){ PrintfExit("User typed cmd-. Exiting."); } wne=WaitNextEvent(mask,eventPtr,sleep,mouseRgn); if(wne && IsCommandPeriod(eventPtr)){ PrintfExit("User typed cmd-. Exiting."); } return wne; }
/* ============= ReadCommandLineParms Read startup options from a text file or dialog box ============= */ char *ReadCommandLineParms( void ) { FILE *f; int len; char *buf; EventRecord event; // flush out all the events and see if shift is held down // to bring up the args window while ( WaitNextEvent(everyEvent, &event, 0, nil) ) { } if ( event.modifiers & 512 ) { static char text[1024]; int argc; char **argv; int i; argc = ccommand( &argv ); text[0] = 0; // concat all the args into a string // quote each arg seperately, because metrowerks does // its own quote combining from the dialog for ( i = 1 ; i < argc ; i++ ) { if ( argv[i][0] != '+' ) { Q_strcat( text, sizeof(text), "\"" ); } Q_strcat( text, sizeof(text), argv[i] ); if ( argv[i][0] != '+' ) { Q_strcat( text, sizeof(text), "\"" ); } Q_strcat( text, sizeof(text), " " ); } return text; } // otherwise check for a parms file f = fopen( "MacQuake3Parms.txt", "r" ); if ( !f ) { return ""; } len = FS_filelength( f ); buf = malloc( len + 1 ); if ( !buf ) { exit( 1 ); } buf[len] = 0; fread( buf, len, 1, f ); fclose( f ); return buf; }
void EventLoop() { Boolean gotEvent; EventRecord event; gQuitFlag = false; do { gotEvent = WaitNextEvent(everyEvent,&event,32767,nil); if (gotEvent) DoEvent(&event); } while (!gQuitFlag); ExitToShell(); }
void MainEventLoopPass() { EventRecord evt; Boolean notHandled = true; if (!gDone) /* after cx switch back ensure not done */ { if(WaitNextEvent(everyEvent, &evt, 1, gMouseRgn)) { if (gMouseRgn) SetRectRgn(gMouseRgn, evt.where.h, evt.where.v, evt.where.h + 1, evt.where.v + 1); HandleNextEvent(&evt); } } }
void doEventLoop() { EventRecord anEvent; WindowPtr evtWind; short clickArea; Rect screenRect; while (!gDone) { if (WaitNextEvent( everyEvent, &anEvent, 0, nil )) { if (anEvent.what == mouseDown) { clickArea = FindWindow( anEvent.where, &evtWind ); if (clickArea == inMenuBar) handleMenuSelection(MenuSelect(anEvent.where)); else if (clickArea == inDrag) { //screenRect = (**GetGrayRgn ()).rgnBBox; GetRegionBounds(GetGrayRgn(), &screenRect); DragWindow( evtWind, anEvent.where, &screenRect ); } else if (clickArea == inContent) { if (evtWind != FrontWindow()) SelectWindow( evtWind ); } else if (clickArea == inGoAway) if (TrackGoAway( evtWind, anEvent.where )) gDone = true; } else if (anEvent.what == updateEvt) { evtWind = (WindowPtr)anEvent.message; //SetPort( evtWind ); SetPortWindowPort( evtWind ); BeginUpdate( evtWind ); drawImage( evtWind ); EndUpdate (evtWind); } else if (anEvent.what == autoKey || anEvent.what == keyDown) handleKeyPress(&anEvent); } } }
void pause( void ) { EventRecord event; Str255 saveTitle; if( FrontWindow() ) { GetWTitle( FrontWindow(), saveTitle ); SetWTitle( FrontWindow(), "\p(paused)" ); } do { // wait } while( false == WaitNextEvent( mDownMask + keyDownMask, &event, 0, NULL ) ); if( FrontWindow() ) SetWTitle( FrontWindow(), saveTitle ); }
/* Resolve a host name and port to an IP address in network form */ int SDLNet_ResolveHost(IPaddress *address, const char *host, Uint16 port) { int retval = 0; /* Perform the actual host resolution */ if ( host == NULL ) { address->host = INADDR_ANY; } else { /* int a[4]; address->host = INADDR_NONE; if ( sscanf(host, "%d.%d.%d.%d", a, a+1, a+2, a+3) == 4 ) { if ( !(a[0] & 0xFFFFFF00) && !(a[1] & 0xFFFFFF00) && !(a[2] & 0xFFFFFF00) && !(a[3] & 0xFFFFFF00) ) { address->host = ((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]); if ( address->host == 0x7F000001 ) { address->host = OTlocalhost; } } } if ( address->host == INADDR_NONE ) {*/ InetHostInfo hinfo; /* Check for special case - localhost */ if ( strcmp(host, "localhost") == 0 ) return(SDLNet_ResolveHost(address, "127.0.0.1", port)); /* Have OpenTransport resolve the hostname for us */ retval = OTInetStringToAddress(dnsStatus.dns, (char *)host, &hinfo); if (retval == noErr) { while( dnsStatus.stat != dnsResolved ) {WaitNextEvent(everyEvent, 0, 1, NULL );} address->host = hinfo.addrs[0]; } //} } address->port = SDL_SwapBE16(port); /* Return the status */ return(retval); }
static void apple_main_event_loop() { Boolean gotEvent; EventRecord event; UInt32 timeout = 1*60; // number of ticks (1/60th of a second) VS("LOADER: Entering AppleEvent main loop.\n"); while (!gQuit) { gotEvent = WaitNextEvent(highLevelEventMask, &event, timeout, NULL); if (gotEvent) { VS("LOADER: Processing an AppleEvent.\n"); AEProcessAppleEvent(&event); } gQuit = true; } }
int _handle_user_event( unsigned long ticks) { EventRecord event; if( WaitNextEvent(everyEvent, &event, ticks, nil)){ long menuResult = 0; short menuID, menuItem; WindowPtr window; Str255 daName; switch ( event.what ) { case mouseDown: if( FindWindow(event.where, &window) == inMenuBar) menuResult = MenuSelect(event.where); break; case keyDown: if( event.modifiers & cmdKey ) menuResult = MenuKey((short)event.message & charCodeMask); break; case kHighLevelEvent: AEProcessAppleEvent(&event); break; } menuID = HiWord(menuResult); menuItem = LoWord(menuResult); switch ( menuID ) { case mFile: MLDone = MLAbort = 1; break; case mApple: switch ( menuItem ) { case iAbout: do_about_box(); break; default: GetMenuItemText(GetMenuHandle(mApple), menuItem, daName); break; } HiliteMenu(0); } } return MLDone; }
// Windows message queue - used by various dialogs int Game::process_messages() { while (1) { int res = ProcessNextEvent (); if (res == 0) { sys.signal_exit_flag = 1; return 0; } if (res == 1) continue; if( sys.paused_flag || !sys.active_flag ) { WaitNextEvent(); continue; } break; } return 1; }
long wait () { EventRecord event; WindowPtr window; MenuInfo **m; long r; Str255 tmp; /* wait for an event */ WaitNextEvent (everyEvent,&event,(long) 6,NIL); switch (event.what) { /* got one -- what is it? */ case mouseDown: /* mouse clicked */ switch (FindWindow (event.where,&window)) { case inMenuBar: /* menu bar item? */ /* yes, interesting event? */ if (r = MenuSelect (event.where)) { /* round-about test for Apple menu */ if ((*(m = GetMHandle (HiWord (r))))->menuData[1] == appleMark) { /* get desk accessory name */ GetItem (m,LoWord (r),tmp); OpenDeskAcc (tmp); /* fire it up */ SetPort (window); /* put us back at our window */ } else SysBeep (60); /* the fool forgot to disable it! */ } HiliteMenu (0); /* unhighlight it */ break; case inContent: /* some window was selected */ if (window != FrontWindow ()) SelectWindow (window); break; default: /* ignore all others */ break; } break; case keyDown: /* key hit - if COMMAND/. then punt */ if ((event.modifiers & cmdKey) && (event.message & charCodeMask) == '.') return NIL; break; default: /* ignore all others */ break; } return T; /* try wait test again */ }
void Tcl_Sleep( int ms) /* Number of milliseconds to sleep. */ { EventRecord dummy; void *timerToken; if (ms <= 0) { return; } timerToken = TclMacStartTimer((long) ms); while (1) { WaitNextEvent(0, &dummy, (ms / 16.66) + 1, NULL); if (TclMacTimerExpired(timerToken)) { break; } } TclMacRemoveTimer(timerToken); }
static boolean unixshellcallbackgroundtask (void) { /* 2005-10-02 creedon: created, cribbed from OpenTransportNetEvents.c: fwsbackgroundtask */ boolean fl = true; if (inmainthread ()) { EventRecord ev; short mask = osMask|activMask|mDownMask|keyDownMask; // |highLevelEventMask|updateMask long sleepTime = 6; // 1/10 of a second by default if (WaitNextEvent (mask, &ev, sleepTime, nil)) /* might return false to indicate a null event, but that's not an error */ fl = shellprocessevent (&ev); } else fl = langbackgroundtask (true); return (fl); }/* unixshellcallbackgroundtask */