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

Send broken keychains in passthrough modes to browser #3683

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jakanaka-evan
Copy link

@jakanaka-evan jakanaka-evan commented Mar 7, 2018

Fixes #1044.


This change is Reviewable

@qutebrowser-bot qutebrowser-bot added status: needs review component: keyinput Issues related to processing keypresses. priority: 3 - wishlist Issues which are not important and/or where it's unclear whether they're feasible. labels Mar 7, 2018
@The-Compiler
Copy link
Member

All the code movement makes it really difficult to review this (and introduces a high chance of conflicts) I'm afraid. Can you please open a separate PR for getting rid of keyparser.py (which should be straightforward to merge), and then rebase this (or open a new PR) based on that?

Some early feedback:

  • In e3e19b5 (in press), you're basically reimplementing Qt's event handling (for QLineEdit objects). I'd much prefer sending those events to the application (so they are handled correctly in any case) and finding some clean way to ignore them instead.
  • I don't understand 8cff673 and unfortunately the commit message just reiterates what the code already says, but doesn't say why this is done 😉

@jakanaka-evan
Copy link
Author

This PR is now based on #3689.

@The-Compiler
Copy link
Member

Hmm, looks like the move is still there... Can you please rebase on the latest master?

@@ -154,6 +155,8 @@ class PassthroughKeyParser(CommandKeyParser):

Attributes:
_mode: The mode this keyparser is for.
_orig_sequence: Cuerrent sequence with no key_mappings applied
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cuerrent -> Current

@@ -154,6 +155,8 @@ class PassthroughKeyParser(CommandKeyParser):

Attributes:
_mode: The mode this keyparser is for.
_orig_sequence: Cuerrent sequence with no key_mappings applied
_ignore_next_key: Whether to pass the next key through
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a period here and on the line above.


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a period.

if window is None:
return match

self._ignore_next_key = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems rather brittle, as you're not guaranteed that the event you posted will be the next event which is received. I haven't tested it, but it likely also breaks if there's more than one key in the original sequence.

I'm okay with it when there's no other solution, but I'd like to check whether there's a better way. Can you try adding an attribute to the press_event / release_event object and see whether it's still there (via getattr(e, 'ignore', False) or so) when you get it back?

A self.Match member.
"""
if keyutils.is_modifier_key(e.key()) or self._ignore_next_key:
self._ignore_next_key = self._ignore_next_key and dry_run
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this - why do you only want to set self._ignore_next_key if dry_run is set?


def __repr__(self):
return utils.get_repr(self, mode=self._mode)

def handle(self, e, *, dry_run=False):
Copy link
Member

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. Maybe KeySequence should have an original attribute where the original is stored when using with_mappings instead? Not sure how much easier this would make the code without seeing it though - what do you think?

Copy link
Author

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 to KeySequence, to see how the code looks would look like. It's kind of clunky and incomplete though (even has pylint errors), because KeySequence 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


def clear_keystring(self):
"""Override to also clear the original sequence."""
if self._orig_sequence:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bother with the check? You can just clear it unconditionally.

"""Override to also clear the original sequence."""
if self._orig_sequence:
self._orig_sequence = keyutils.KeySequence()
super().clear_keystring()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually additional things are done after the super() call, not before it.

@The-Compiler
Copy link
Member

I planned to take a look at this during my holidays before starting to learn for exams, but I didn't manage to do so (mainly because of a lot of issues with Qt 5.11...). I'll get back to it in September though!

Copy link
Member

@jgkamat jgkamat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an opinion between the alternative patch and the current one, but something that does need to be fixed is not respecting input.partial_timeout in passthrough mode. Since lifting it into commandkeyparser is probably not desirable, maybe there could be a helper function to set up the timeouts? A little bit of duplication is probably fine though :)

@jakanaka-evan
Copy link
Author

jakanaka-evan commented Sep 21, 2018

The last two commits address the partial_timeout issue for all modes (it was
lifted into BaseKeyParser). I can separate them into a new PR if you want.

brightonanc added a commit to brightonanc/qutebrowser that referenced this pull request May 5, 2022
brightonanc added a commit to brightonanc/qutebrowser that referenced this pull request Jul 14, 2022
brightonanc added a commit to brightonanc/qutebrowser that referenced this pull request Jun 11, 2023
brightonanc added a commit to brightonanc/qutebrowser that referenced this pull request Sep 3, 2023
brightonanc added a commit to brightonanc/qutebrowser that referenced this pull request Nov 24, 2023
brightonanc added a commit to brightonanc/qutebrowser that referenced this pull request Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: keyinput Issues related to processing keypresses. priority: 3 - wishlist Issues which are not important and/or where it's unclear whether they're feasible.
Projects
Development

Successfully merging this pull request may close these issues.

Map keychains in passthrough-keymodes
5 participants