Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite of event engine #307

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Rewrite of event engine #307

wants to merge 26 commits into from

Conversation

boppreh
Copy link
Owner

@boppreh boppreh commented Oct 29, 2019

No description provided.

The first version that could suppress events was introduced by @xoviat
via #38. It was a separate module, using nested dictionaries to simulate
a state machine that had to be updated on every hotkey registered. It
also handled the entire hotkey process, including multi-steps and
timeouts. It was very complex, and had some bugs that we weren't sure
were fixable with that architecture.

The second version was developed in the `suppress` branch for over an
year. It used an explicit state machine for each key, divided by several
attributes (is it a modifier, was it processed by a key, etc). It
processed only single-step hotkeys. Multi-step hotkeys were simulated by
adding and removing hotkeys as necessary, and keeping track separately of
which events were suppressed from previous steps. This version worked
better, with fewer bugs and somewhat simpler, but the execution was
still hard to understand and some bugs were creeping in.

This commit introduces the third attempt at making a resiliant and
simple to understand key event suppression system. It borrows the
concept of multi-step hotkeys as being sequences of single-step hotkeys,
but revamps everything else.

The meat of the code is a set of global variables and a decision tree.

The decision tree is executed for each incoming event, and uses the
global state to decide if a given event should be:
1) Suppressed. It's part of a blocking hotkey and at least one callback
returned False. The event is blocked with no hope of recovery. For key
down events, the corresponding key up event will also be suppressed.
2) Delayed. This event is part of a *subset* of one or more blocking
hotkeys. We block it now, but may decide to resend it later.
3) Allowed. The event is passed along normally. If there were any
pending events, they are resent before allowing this one.

The global variables keep track of which keys the OS reports as
currently pressed (i.e. physically pressed keys), which keys were
allowed to be passed (i.e. logically pressed keys, from the point of
view of other applications), which key presses have been tentatively
suppressed, and which key presses were definitely suppressed by hotkeys.

It's still complex, but much easier to understand than the two previous
versions, doesn't have the same bugs (I hope it has no bugs at all), and
is much easier to debug and amend.

Third time is the charm, wish me luck.
@boppreh
Copy link
Owner Author

boppreh commented Oct 29, 2019

Note: not ready yet for merging. Deep changes with little testing and non-optimized structures.

boppreh and others added 2 commits March 23, 2020 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants