Input event reduction



Well, I think I have asked this already some years ago at gtk-list.
(And I spent some hours experimenting with stuff like event_pending()
and such, without success.)

It is still the old problem: We have input events, for example
keystrokes, and a function that can only process a few events per
second.

What we want: If there are more than one event of this type pending (in
the queue) than discard all but the last one.

That seems to be really hard in GTK3.

One solution, which is used in the NEd Nim editor: Create a separate
task, send the events though a channel to that task. That channel
behaves like a queue, so the task can discard events easily and process
always only the last one. Problem is, that GTK is not thread safe, so
that task can not do GUI update itself, but has to use an Idle_Add
function. All that works fine, but that is more than 10 lines of code
for such a trivial problem.

Currently I get the "changed" signal of a GTk Text Buffer -- when the
user types fast, there may be up to ten function calls per second
initiated. Processing these realtime is still possible on a fast CPU,
but to save resources (battery power for example) it would be better to
drop a few events when there are many, but always process the last one.
(Task here is smart syntax check or syntax highlight, so the last input
is always what matters most.)

Timer events would be an option, but that would imply a permanent
delay. What we want instead is immediate reaction when there are input
events.



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