-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Send broken keychains in passthrough modes to browser #3683
Open
jakanaka-evan
wants to merge
5
commits into
qutebrowser:main
Choose a base branch
from
jakanaka-evan:forward-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a3ebe0
Pass broken keychains to browser in passthrough modes
jakanakaevangeli 77481b4
Don't use key_mappings when passing keys
jakanakaevangeli a0a9ffc
Use ignore_event attribute on events
jakanakaevangeli f2c3d27
Respect input.partial_timeout in all modes
jakanakaevangeli 7124f42
Stop and disconnect input.partial_timeout
jakanakaevangeli File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,11 @@ | |
import traceback | ||
import enum | ||
|
||
from PyQt5.QtCore import pyqtSlot, Qt | ||
from PyQt5.QtWidgets import QApplication | ||
from PyQt5.QtCore import pyqtSlot, Qt, QEvent | ||
from PyQt5.QtGui import QKeySequence | ||
|
||
from qutebrowser.commands import runners, cmdexc | ||
from qutebrowser.config import config | ||
from qutebrowser.keyinput import basekeyparser, keyutils | ||
from qutebrowser.utils import usertypes, log, message, objreg, utils | ||
|
||
|
@@ -60,17 +60,11 @@ def execute(self, cmdstr, count=None): | |
|
||
class NormalKeyParser(CommandKeyParser): | ||
|
||
"""KeyParser for normal mode with added STARTCHARS detection and more. | ||
|
||
Attributes: | ||
_partial_timer: Timer to clear partial keypresses. | ||
""" | ||
"""KeyParser for normal mode with added STARTCHARS detection and more.""" | ||
|
||
def __init__(self, win_id, parent=None): | ||
super().__init__(win_id, parent, supports_count=True) | ||
self._read_config('normal') | ||
self._partial_timer = usertypes.Timer(self, 'partial-match') | ||
self._partial_timer.setSingleShot(True) | ||
self._inhibited = False | ||
self._inhibited_timer = usertypes.Timer(self, 'normal-inhibited') | ||
self._inhibited_timer.setSingleShot(True) | ||
|
@@ -95,15 +89,7 @@ def handle(self, e, *, dry_run=False): | |
"currently inhibited.".format(txt)) | ||
return QKeySequence.NoMatch | ||
|
||
match = super().handle(e, dry_run=dry_run) | ||
|
||
if match == QKeySequence.PartialMatch and not dry_run: | ||
timeout = config.val.input.partial_timeout | ||
if timeout != 0: | ||
self._partial_timer.setInterval(timeout) | ||
self._partial_timer.timeout.connect(self._clear_partial_match) | ||
self._partial_timer.start() | ||
return match | ||
return super().handle(e, dry_run=dry_run) | ||
|
||
def set_inhibited_timeout(self, timeout): | ||
"""Ignore keypresses for the given duration.""" | ||
|
@@ -115,36 +101,12 @@ def set_inhibited_timeout(self, timeout): | |
self._inhibited_timer.timeout.connect(self._clear_inhibited) | ||
self._inhibited_timer.start() | ||
|
||
@pyqtSlot() | ||
def _clear_partial_match(self): | ||
"""Clear a partial keystring after a timeout.""" | ||
self._debug_log("Clearing partial keystring {}".format( | ||
self._sequence)) | ||
self._sequence = keyutils.KeySequence() | ||
self.keystring_updated.emit(str(self._sequence)) | ||
|
||
@pyqtSlot() | ||
def _clear_inhibited(self): | ||
"""Reset inhibition state after a timeout.""" | ||
self._debug_log("Releasing inhibition state of normal mode.") | ||
self._inhibited = False | ||
|
||
@pyqtSlot() | ||
def _stop_timers(self): | ||
super()._stop_timers() | ||
self._partial_timer.stop() | ||
try: | ||
self._partial_timer.timeout.disconnect(self._clear_partial_match) | ||
except TypeError: | ||
# no connections | ||
pass | ||
self._inhibited_timer.stop() | ||
try: | ||
self._inhibited_timer.timeout.disconnect(self._clear_inhibited) | ||
except TypeError: | ||
# no connections | ||
pass | ||
|
||
|
||
class PassthroughKeyParser(CommandKeyParser): | ||
|
||
|
@@ -154,6 +116,7 @@ class PassthroughKeyParser(CommandKeyParser): | |
|
||
Attributes: | ||
_mode: The mode this keyparser is for. | ||
_orig_sequence: Current sequence with no key_mappings applied. | ||
""" | ||
|
||
do_log = False | ||
|
@@ -169,11 +132,65 @@ def __init__(self, win_id, mode, parent=None): | |
""" | ||
super().__init__(win_id, parent) | ||
self._read_config(mode) | ||
self._orig_sequence = keyutils.KeySequence() | ||
self._mode = mode | ||
|
||
def __repr__(self): | ||
return utils.get_repr(self, mode=self._mode) | ||
|
||
def handle(self, e, *, dry_run=False): | ||
"""Override to pass the chain through on NoMatch. | ||
|
||
Args: | ||
e: the KeyPressEvent from Qt. | ||
dry_run: Don't actually execute anything, only check whether there | ||
would be a match. | ||
|
||
Return: | ||
A self.Match member. | ||
""" | ||
if (keyutils.is_modifier_key(e.key()) or | ||
getattr(e, "ignore_event", False)): | ||
return QKeySequence.NoMatch | ||
|
||
orig_sequence = self._orig_sequence.append_event(e) | ||
match = super().handle(e, dry_run=dry_run) | ||
|
||
if not dry_run and match == QKeySequence.PartialMatch: | ||
self._orig_sequence = orig_sequence | ||
|
||
if dry_run or len(orig_sequence) == 1 or match != QKeySequence.NoMatch: | ||
return match | ||
|
||
self._forward_keystring(orig_sequence) | ||
return QKeySequence.ExactMatch | ||
|
||
def _forward_keystring(self, orig_sequence): | ||
window = QApplication.focusWindow() | ||
if window is None: | ||
return | ||
|
||
first = True | ||
for keyinfo in orig_sequence: | ||
press_event = keyinfo.to_event(QEvent.KeyPress) | ||
if first: | ||
press_event.ignore_event = True | ||
first = False | ||
release_event = keyinfo.to_event(QEvent.KeyRelease) | ||
QApplication.postEvent(window, press_event) | ||
QApplication.postEvent(window, release_event) | ||
|
||
@pyqtSlot() | ||
def clear_partial_match(self): | ||
"""Override to forward the original sequence to browser.""" | ||
self._forward_keystring(self._orig_sequence) | ||
self.clear_keystring() | ||
|
||
def clear_keystring(self): | ||
"""Override to also clear the original sequence.""" | ||
super().clear_keystring() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually additional things are done after the |
||
self._orig_sequence = keyutils.KeySequence() | ||
|
||
|
||
class PromptKeyParser(CommandKeyParser): | ||
|
||
|
@@ -296,6 +313,12 @@ def update_bindings(self, strings, preserve_filter=False): | |
if not preserve_filter: | ||
self._filtertext = '' | ||
|
||
@pyqtSlot() | ||
def clear_partial_match(self): | ||
"""Override to avoid clearing filter text after a timeout.""" | ||
if self._last_press != LastPress.filtertext: | ||
super().clear_partial_match() | ||
|
||
@pyqtSlot(str) | ||
def on_keystring_updated(self, keystr): | ||
"""Update hintmanager when the keystring was updated.""" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to duplicate a lot of the logic in
BaseKeyParser.match
, so I'm wondering whether there's a better way. MaybeKeySequence
should have anoriginal
attribute where the original is stored when usingwith_mappings
instead? Not sure how much easier this would make the code without seeing it though - what do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a patch that adds a
without_mappings
method toKeySequence
, to see how the code looks would look like. It's kind of clunky and incomplete though (even has pylint errors), becauseKeySequence
is used pretty much as an immutable object.If you want, I can rewrite the
KeySequence
class to be more mutable, but that would probably belong in it's own PR.https://gist.github.com/jakanaka-evan/4973c4a4e46e8e3bdae57b17dba0e26c