Re: Ignoring piled up key-press-events



On Mon, 2008-12-15 at 23:45 +0200, Dov Grobgeld wrote:
> I have a problem that I have been stuck on for a while.
> 
> In my image viewer giv, I have a problem with a pileup of
> key-press-events. E.g. a space means load the next image. The problem
> is that I can't serve the keypress events at the full speed that they
> are generated, and gtk then piles them up. Thus, if I e.g. press and
> hold space, the image viewer will load new images long after I have
> let go of the space bar.
> 
> What I would like to do is to receive, but ignore, all keypress events
> until the previous command has been fully served, or equivalently at
> the end of serving a keypress event, clear all the key-press-events
> from the event buffer. 
> 
> What's the best way of implementing this in gtk?

make the event handler:

	a) increment a counter
	b) check if a particular idle handler has been installed; if not
             install it

then when the main event loop goes idle, your callback/handler will be
invoked. look at the counter, and increment that many images ahead. or
just one, or somewhere in between.

remember to return true from the idle handler so that its not called
again until necessary, and reset the idle handler id to -1, so that you
know it has been uninstalled.

> 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]