Commit Graph

72 Commits

Author SHA1 Message Date
Florian Bruhin 5b6d2c60b4 Fix bindings.key_mappings with multiple keys
Otherwise, when e.g. doing "<Meta+Up>": "gg" in bindings.key_mappings,
there's a crash like:

    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/eventfilter.py", line 105, in eventFilter
        return handler(typing.cast(QKeyEvent, event))
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/eventfilter.py", line 75, in _handle_key_event
        return man.handle_event(event)
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/modeman.py", line 462, in handle_event
        return handler(cast(QKeyEvent, event))
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/modeman.py", line 283, in _handle_keypress
        match = parser.handle(event, dry_run=dry_run)
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/modeparsers.py", line 105, in handle
        match = super().handle(e, dry_run=dry_run)
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/basekeyparser.py", line 309, in handle
        result = self._match_key_mapping(result.sequence)
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/basekeyparser.py", line 246, in _match_key_mapping
        mapped = sequence.with_mappings(
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/keyutils.py", line 675, in with_mappings
        assert len(new_seq) == 1
    AssertionError

While this isn't the intended way to use this setting, we shouldn't
crash - and let's just make it work instead of forbidding it.
2021-03-20 11:10:30 +01:00
Florian Bruhin d0d7114923 Revert "old qt: Use ApplicationAttribute to switch Ctrl/Meta on Mac"
This reverts commit 1132324db9.

Causes various issues with Qt/QtWebEngine shortcuts.
Fixes #6174
Closes #6149
2021-02-24 09:57:06 +01:00
Florian Bruhin 1a4fff1a42 doc: Switch URLs to https 2021-01-26 15:19:01 +01:00
Florian Bruhin 41afe0febe Support Super as modifier name
See https://github.com/qutebrowser/qutebrowser/discussions/5999#discussioncomment-297309
2021-01-22 17:37:42 +01:00
Florian Bruhin 222f1f19a1 Bump copyright years
Closes #6015
2021-01-20 20:06:19 +01:00
Florian Bruhin 1132324db9 old qt: Use ApplicationAttribute to switch Ctrl/Meta on Mac 2020-11-04 18:30:04 +01:00
Florian Bruhin d6eebbd3f9 tests: Get rid of fake_keyevent
Use keyutils.KeyInfo(...).to_event() instead.
2020-06-17 16:00:23 +02:00
Florian Bruhin b25c7d5b36 modeparsers: Refactor how hints are handled
Instead of binding hints to fake :follow-hint commands, we now use a separate
CommandKeyParser and ask that for its match result.

If the key matches with the command parser, it is bound in hint mode, so we
clear the hint keystring and defer to the command handling instead.

If it doesn't, we continue hint handling as usual - however, the HintKeyParser
is now not a CommandKeyParser anymore, so we don't have to deal with command
parsing (and have a custom execute implementation instead).

Closes #4504
Fixes #4392
Fixes #4368
Helps with #5084, though it doesn't completely fix that yet.
Supersedes #3742 (fix for #3735)
Supersedes #4691 (fix for #4264)
2020-06-17 15:42:42 +02:00
Florian Bruhin 9e4276db9b Adjust copyrights for 2020 2020-01-04 18:21:17 +01:00
Florian Bruhin be31f1b6e0 Fix coverage 2019-09-13 13:12:54 +02:00
Florian Bruhin 9557885ace Add a proper MatchResult type instead of tuples 2019-09-13 13:12:54 +02:00
Florian Bruhin f8689774a0 Merge remote-tracking branch 'origin/pr/4730' into binding-trie 2019-09-12 11:52:29 +02:00
Florian Bruhin c6fac2157d Merge remote-tracking branch 'origin/pr/4691' 2019-09-11 16:03:39 +02:00
Florian Bruhin 2df9bf8e53 Merge remote-tracking branch 'origin/pr/4492' 2019-09-11 12:14:31 +02:00
Florian Bruhin 51e515f91c Merge remote-tracking branch 'origin/pr/4585' 2019-09-10 17:27:49 +02:00
Florian Bruhin 56c524d0fe Fix implicit int conversions for QKeySequence
This also fixes some calls to utils.KeySequence with a string.

See #4928
2019-08-18 02:06:09 +02:00
Jay Kamat c9522c1b69
Add tests for binding trie 2019-04-27 12:08:22 -07:00
user202729 e720df22c4 Add tests for modifier keys for test_is_special 2019-04-26 21:13:45 +07:00
user202729 902f942ac3 Add tests for is_special_hint_mode 2019-04-26 21:13:28 +07:00
user202729 60a52baaa6 Fix wrong test for keyutils.is_printable
According to is_special documentation, (Qt.Key,2, Qt.KeypadModifier)
should return True because it requires special representation <num-2>
2019-04-24 13:59:04 +07:00
Joel Bradshaw 3fce3baa69 Reduce rewriting to just surrogates
After testing, these are the only ones that cause problems
2019-03-09 15:26:13 -08:00
Jay Kamat 3e816f5f8b
Update copyright for 2019 2019-02-22 21:45:08 -08:00
user202729 1562074383 Add tests for AltGr modifier key 2019-02-17 10:08:29 +07:00
Florian Bruhin 94f998ac3a Adjust for new pytest import handling
See #4511
2019-02-16 20:00:01 +01:00
Joel Bradshaw b5490c690c Linting, review comments 2018-12-29 09:47:56 -08:00
Joel Bradshaw 3948365120 Take a different tack
We can just rewrite the key code to the actual Unicode code point.

This is much cleaner, as QKeySequence() behaves as expected when given
code points as input, so QKeySequence(ord("𩷶")).toString() == "𩷶".
2018-12-26 23:51:50 -08:00
Joel Bradshaw c2c64d0623 Never mind, early return is what we want
Also, add default variable so old code (e.g. tests) is okay, and
update keycode for the Chinese character even though it doesn't
really matter to the test
2018-12-24 00:37:18 -08:00
Joel Bradshaw 065ece5283 Attempt to add a test for this 2018-12-23 17:21:13 -08:00
Florian Bruhin 8459afb76e Recognize "Command"/"Cmd" in keybindings 2018-08-28 18:57:47 +02:00
George Edward Bulmer 0645865d22 Add test case for is_special in keyutils 2018-03-21 16:38:58 +00:00
Florian Bruhin 84c7c37e8e Swap Control/Meta back on macOS
Fixes #3697

(cherry picked from commit fd9e7bed7fd9842eac22ed304a094a92cc953577)
2018-03-14 19:40:56 +01:00
Florian Bruhin b88ac51d25 Fall back to non-keypad keys without any keypad bindings
Fixes #3701
2018-03-13 14:40:54 +01:00
Florian Bruhin ebb373ccad Make sure keys with modifiers get handled as special 2018-03-09 09:04:28 +01:00
Florian Bruhin 0d94c17edc Apply key_mappings to KeySequences correctly
Fixes #3678
2018-03-06 21:39:57 +01:00
Florian Bruhin 41dfa29648 Improve parsing of invalid keys
This should handle "<>" and "\x1f" correctly.
2018-03-06 06:29:38 +01:00
Florian Bruhin 7a9f8fda72 Get rid of unnecessary lambda 2018-03-05 23:07:03 +01:00
Florian Bruhin 2b84ea9dbe Make sure we have plain keys/modifiers where needed 2018-03-05 23:01:24 +01:00
Florian Bruhin 0ee7fac727 Update test_init_unknown/test_init_invalid for KeyboardModifierMask
-1 & Qt.KeyboardModifierMask == Qt.Key_unknown
2018-03-05 22:56:58 +01:00
Florian Bruhin 29fdd1acc4 Make sure all keyboard modifiers are handled correctly
This handles Qt.KeypadModifier (Num+...) correctly, adds tests for converting
modifiers to strings, and strips Qt.GroupSwitchModifier as QKeySequence doesn't
know about it.

Fixes #3675
2018-03-05 22:11:26 +01:00
Florian Bruhin d1854eddaf Handle invalid keys coming from Qt
When pressing a key which doesn't exist as Qt.Key, we don't get Qt.Key_unknown
like we'd expect, but we get 0x0 instead...

Let's add that as a new "nil" key (to not conflict with None/unknown/zero/...)
and handle it appropriately.

This can be reproduced by doing:
setxkbmap -layout us,gr -option grp:alt_shift_toggle
and pressing Alt-Shift/Shift-Alt.
2018-03-05 15:42:52 +01:00
Florian Bruhin 0967b6abd2 Fix handling of </> keys 2018-03-04 20:40:16 +01:00
Florian Bruhin d8bfe23c0d Fix lint 2018-03-04 20:21:58 +01:00
Florian Bruhin 2be7db29ed 100% coverage for keyinput.keyutils 2018-03-04 20:21:58 +01:00
Florian Bruhin 8da878c77c Make KeySequence.matchs() work correctly 2018-03-04 20:21:58 +01:00
Florian Bruhin 866c758660 Add more KeySequence tests 2018-03-04 20:21:58 +01:00
Florian Bruhin fb7c75a090 Improve keyutils tests 2018-03-04 20:21:58 +01:00
Florian Bruhin 3c9e8ff9ab Test and fix keyutils._parse_keystring 2018-03-04 20:21:58 +01:00
Florian Bruhin 7f8508a367 Change the way Space keybindings are handled
Using it as " " in a keystring won't work anymore, but instead <Space> and
<Shift-Space> does.
2018-03-04 20:21:58 +01:00
Florian Bruhin da60d11b24 Refactor keyutils tests 2018-03-04 20:21:58 +01:00
Florian Bruhin b3834835ed Bring back keyutils.is_modifier() and modifier handling
Turns out when we press yY, we get three events:

Qt.Key_Y, Qt.NoModifier
Qt.Key_Shift, Qt.ShiftModifier
Qt.Key_Y, Qt.ShiftModifier

If we don't ignore the second one, our keychain will be interrupted by the Shift
keypress.
2018-03-04 20:21:58 +01:00