• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Flushing events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Flushing events


  • Subject: Re: Flushing events
  • From: Ricky Sharp <email@hidden>
  • Date: Thu, 3 Nov 2005 17:38:03 -0600


On Nov 2, 2005, at 7:02 PM, Ricky Sharp wrote:

I have a need to flush all events before entering a local event loop. I've search for a 'flushEvents' API, but can't come up with any. The article at <http://www.cocoadev.com/index.pl? FlushAppEventQueue> didn't help much either.


I've seen discardEventsMatchingMask:beforeEvent:, but what I really need is a discardEventsMatchingMask:afterEvent:


Before I enter the local loop, I've thought of capturing the current timestamp and "eating" events that occurred before that time via the nextEventMatchingMask APIs.

Still no luck. I've come up with the following:

- (void)flushEvents_II
{
static unsigned int theEventMask =
NSLeftMouseDownMask |
NSLeftMouseUpMask |
NSRightMouseDownMask |
NSRightMouseUpMask |
NSOtherMouseDownMask |
NSOtherMouseUpMask |
NSKeyDownMask |
NSKeyUpMask;

unsigned int theNumberOfFlushedEvents = 0;
NSEvent* theEvent = nil;

do
{
theEvent = [NSApp nextEventMatchingMask:theEventMask
untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];

if (theEvent != nil)
{
++theNumberOfFlushedEvents;
NSLog(@"Flushed event %@", theEvent);
}
}
while (theEvent != nil);

NSLog(@"Flushed %u events", theNumberOfFlushedEvents);
NSLog(@"-----------------");
}



But this appears to work only some of the time which is quite annoying (more on it below).


The reason I need to flush events is that I have a kiosk-type app that always has one and only one window (which is always the main and key window).

The window's content represents a "screen". When I need to display a "dialog", I take a screenshot of the current window's contents and then remove the current content (all my custom UI views, controls, etc.). I then put up new views & controls with a background of that screenshot to serve as the backdrop of the dialog. The only controls now on the screen is that for my virtual dialog.

One such problem area is that I have a "Remove" button on a screen that brings up a "Are you sure" dialog when clicked. Part of the dialog's OK button's bounds intersects with the remove buttons bounds. If I double click on that particular area of the remove button, the first click brings up the dialog, and the second click then triggers the OK button immediately.

I wanted to flush events at the point where the dialog is brought up, but just before I enter the local modal event loop to handle events for the dialog.

In the Carbon flavor of my app, this wasn't an issue since there are FlushEvent APIs available. The only workaround I can come up with is to rearrange my UI such that "dangerous" buttons never overlap. But I'd like to save that as a last resort.

Going back to the code above, sometimes a run of the app will allow me to double-click on remove and I successfully flush one of the clicks (preventing OK from being triggered). My log reads like this:

Flushed event NSEvent: type=LMouseUp loc=(204,640) time=45484.0 flags=0x100 win=0 winNum=12130 ctxt=0x18ec3 evNum=5779 click=2 buttonNumber=0 pressure=0
Flushed 1 events


But for other runs of the app, double-clicks do not result in the code flushing them. AFAICT, I'm double-clicking with the same speed.

If nobody else has ever worked on this type of issue, I'll just file a DTS incident to see if any solution exists. I'll of course share any solution here.


___________________________________________________________ Ricky A. Sharp mailto:email@hidden Instant Interactive(tm) http://www.instantinteractive.com

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Flushing events
      • From: Ricky Sharp <email@hidden>
References: 
 >Flushing events (From: Ricky Sharp <email@hidden>)

  • Prev by Date: drop location feedback in NSTextView
  • Next by Date: Re: Reviews of "Advanced Mac OS X Programming"
  • Previous by thread: Flushing events
  • Next by thread: Re: Flushing events
  • Index(es):
    • Date
    • Thread