Update eventFilter to track releases
This commit is contained in:
parent
5ee6b2adfa
commit
8cba290dae
@ -76,6 +76,9 @@ class ModeManager(QObject):
|
|||||||
_mode_stack: A list of the modes we're currently in, with the active
|
_mode_stack: A list of the modes we're currently in, with the active
|
||||||
one on the right.
|
one on the right.
|
||||||
_forward_unbound_keys: If we should forward unbound keys.
|
_forward_unbound_keys: If we should forward unbound keys.
|
||||||
|
_releaseevents_to_pass: A list of keys where the keyPressEvent was
|
||||||
|
passed through, so the release event should as
|
||||||
|
well.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
entered: Emitted when a mode is entered.
|
entered: Emitted when a mode is entered.
|
||||||
@ -94,6 +97,7 @@ class ModeManager(QObject):
|
|||||||
self._handlers = {}
|
self._handlers = {}
|
||||||
self.passthrough = []
|
self.passthrough = []
|
||||||
self._mode_stack = []
|
self._mode_stack = []
|
||||||
|
self._releaseevents_to_pass = []
|
||||||
self._forward_unbound_keys = config.get('general',
|
self._forward_unbound_keys = config.get('general',
|
||||||
'forward_unbound_keys')
|
'forward_unbound_keys')
|
||||||
|
|
||||||
@ -195,38 +199,33 @@ class ModeManager(QObject):
|
|||||||
|
|
||||||
handler = self._handlers[self.mode]
|
handler = self._handlers[self.mode]
|
||||||
|
|
||||||
if self.mode in self.passthrough:
|
if typ == QEvent.KeyPress:
|
||||||
# We're currently in a passthrough mode so we pass everything
|
logging.debug("KeyPress, calling handler {}".format(handler))
|
||||||
# through.*and* let the passthrough keyhandler know.
|
self.key_pressed.emit(evt)
|
||||||
# FIXME what if we leave the passthrough mode right here?
|
handled = handler(evt) if handler is not None else False
|
||||||
logging.debug("We're in a passthrough mode -> passing through")
|
|
||||||
if typ == QEvent.KeyPress:
|
if handled:
|
||||||
logging.debug("KeyPress, calling handler {}".format(handler))
|
filter_this = True
|
||||||
self.key_pressed.emit(evt)
|
elif self.mode in self.passthrough or self._forward_unbound_keys:
|
||||||
if handler is not None:
|
filter_this = False
|
||||||
handler(evt)
|
|
||||||
else:
|
else:
|
||||||
logging.debug("KeyRelease, not calling anything")
|
filter_this = True
|
||||||
return False
|
|
||||||
|
if not filter_this:
|
||||||
|
self._releaseevents_to_pass.append(evt)
|
||||||
|
|
||||||
|
logging.debug("handled: {}, forward_unbound_keys: {}, "
|
||||||
|
"passthrough: {} --> filter: {}".format(
|
||||||
|
handled, self._forward_unbound_keys,
|
||||||
|
self.mode in self.passthrough, filter_this))
|
||||||
else:
|
else:
|
||||||
logging.debug("We're in a non-passthrough mode")
|
# KeyRelease, handle like matching KeyPress
|
||||||
if typ == QEvent.KeyPress:
|
if evt in self._releaseevents_to_pass:
|
||||||
# KeyPress in a non-passthrough mode - call handler and filter
|
# remove all occurences
|
||||||
# event from widgets (unless unhandled and configured to pass
|
self._releaseevents_to_pass = [e for e in
|
||||||
# unhandled events through)
|
self._releaseevents_to_pass if e != evt]
|
||||||
logging.debug("KeyPress, calling handler {}".format(handler))
|
filter_this = False
|
||||||
self.key_pressed.emit(evt)
|
|
||||||
handled = handler(evt) if handler is not None else False
|
|
||||||
logging.debug("handled: {}, forward_unbound_keys: {} -> "
|
|
||||||
"filtering: {}".format(
|
|
||||||
handled, self._forward_unbound_keys,
|
|
||||||
handled or not self._forward_unbound_keys))
|
|
||||||
if handled or not self._forward_unbound_keys:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
else:
|
else:
|
||||||
# KeyRelease in a non-passthrough mode - filter event and
|
filter_this = True
|
||||||
# ignore it entirely.
|
logging.debug("KeyRelease --> filter: {}".format(filter_this))
|
||||||
logging.debug("KeyRelease, not calling anything and filtering")
|
return filter_this
|
||||||
return True
|
|
||||||
|
Loading…
Reference in New Issue
Block a user