Fix some more stuff (and break some :D)
This commit is contained in:
parent
ddcb5445a2
commit
a8aaf01ff0
@ -136,9 +136,10 @@ class KeyConfig:
|
|||||||
"""Make sure the given mode exists and normalize the key."""
|
"""Make sure the given mode exists and normalize the key."""
|
||||||
if mode not in configdata.DATA['bindings.default'].default:
|
if mode not in configdata.DATA['bindings.default'].default:
|
||||||
raise configexc.KeybindingError("Invalid mode {}!".format(mode))
|
raise configexc.KeybindingError("Invalid mode {}!".format(mode))
|
||||||
if utils.is_special_key(key):
|
# FIXME needed?
|
||||||
# <Ctrl-t>, <ctrl-T>, and <ctrl-t> should be considered equivalent
|
# if utils.is_special_key(key):
|
||||||
return utils.normalize_keystr(key)
|
# # <Ctrl-t>, <ctrl-T>, and <ctrl-t> should be considered equivalent
|
||||||
|
# return utils.normalize_keystr(key)
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def get_bindings_for(self, mode):
|
def get_bindings_for(self, mode):
|
||||||
@ -160,10 +161,11 @@ class KeyConfig:
|
|||||||
cmd = cmd.strip()
|
cmd = cmd.strip()
|
||||||
cmd_to_keys.setdefault(cmd, [])
|
cmd_to_keys.setdefault(cmd, [])
|
||||||
# put special bindings last
|
# put special bindings last
|
||||||
if utils.is_special_key(key):
|
# FIXME update
|
||||||
cmd_to_keys[cmd].append(key)
|
# if utils.is_special_key(key):
|
||||||
else:
|
# cmd_to_keys[cmd].append(key)
|
||||||
cmd_to_keys[cmd].insert(0, key)
|
# else:
|
||||||
|
cmd_to_keys[cmd].insert(0, key.toString())
|
||||||
return cmd_to_keys
|
return cmd_to_keys
|
||||||
|
|
||||||
def get_command(self, key, mode, default=False):
|
def get_command(self, key, mode, default=False):
|
||||||
|
@ -117,10 +117,10 @@ class ConfigCommands:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# No --default -> print binding
|
# No --default -> print binding
|
||||||
if utils.is_special_key(key):
|
#if utils.is_special_key(key):
|
||||||
# self._keyconfig.get_command does this, but we also need it
|
# # self._keyconfig.get_command does this, but we also need it
|
||||||
# normalized for the output below
|
# # normalized for the output below
|
||||||
key = utils.normalize_keystr(key)
|
# key = utils.normalize_keystr(key)
|
||||||
with self._handle_config_error():
|
with self._handle_config_error():
|
||||||
cmd = self._keyconfig.get_command(key, mode)
|
cmd = self._keyconfig.get_command(key, mode)
|
||||||
if cmd is None:
|
if cmd is None:
|
||||||
|
@ -173,20 +173,24 @@ class BaseKeyParser(QObject):
|
|||||||
Return:
|
Return:
|
||||||
A self.Match member.
|
A self.Match member.
|
||||||
"""
|
"""
|
||||||
txt = e.text()
|
|
||||||
key = e.key()
|
key = e.key()
|
||||||
|
txt = utils.keyevent_to_string(e)
|
||||||
self._debug_log("Got key: 0x{:x} / text: '{}'".format(key, txt))
|
self._debug_log("Got key: 0x{:x} / text: '{}'".format(key, txt))
|
||||||
|
|
||||||
if len(txt) == 1:
|
if txt is None:
|
||||||
category = unicodedata.category(txt)
|
|
||||||
is_control_char = (category == 'Cc')
|
|
||||||
else:
|
|
||||||
is_control_char = False
|
|
||||||
|
|
||||||
if (not txt) or is_control_char:
|
|
||||||
self._debug_log("Ignoring, no text char")
|
self._debug_log("Ignoring, no text char")
|
||||||
return QKeySequence.NoMatch
|
return QKeySequence.NoMatch
|
||||||
|
|
||||||
|
# if len(txt) == 1:
|
||||||
|
# category = unicodedata.category(txt)
|
||||||
|
# is_control_char = (category == 'Cc')
|
||||||
|
# else:
|
||||||
|
# is_control_char = False
|
||||||
|
|
||||||
|
# if (not txt) or is_control_char:
|
||||||
|
# self._debug_log("Ignoring, no text char")
|
||||||
|
# return QKeySequence.NoMatch
|
||||||
|
|
||||||
count, cmd_input = self._split_count(self._keystring + txt)
|
count, cmd_input = self._split_count(self._keystring + txt)
|
||||||
match, binding = self._match_key(cmd_input)
|
match, binding = self._match_key(cmd_input)
|
||||||
if match == QKeySequence.NoMatch:
|
if match == QKeySequence.NoMatch:
|
||||||
@ -233,7 +237,7 @@ class BaseKeyParser(QObject):
|
|||||||
return (None, None)
|
return (None, None)
|
||||||
|
|
||||||
for seq, cmd in self.bindings.items():
|
for seq, cmd in self.bindings.items():
|
||||||
match = seq.matches(utils.parse_keystring(cmd_input))
|
match = seq.matches(cmd_input)
|
||||||
if match != QKeySequence.NoMatch:
|
if match != QKeySequence.NoMatch:
|
||||||
return (match, cmd)
|
return (match, cmd)
|
||||||
|
|
||||||
|
@ -56,7 +56,8 @@ class PassthroughKeyParser(CommandKeyParser):
|
|||||||
_mode: The mode this keyparser is for.
|
_mode: The mode this keyparser is for.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
do_log = False
|
# FIXME
|
||||||
|
# do_log = False
|
||||||
passthrough = True
|
passthrough = True
|
||||||
|
|
||||||
def __init__(self, win_id, mode, parent=None, warn=True):
|
def __init__(self, win_id, mode, parent=None, warn=True):
|
||||||
|
@ -106,7 +106,6 @@ class KeyHintView(QLabel):
|
|||||||
bindings_dict = config.key_instance.get_bindings_for(modename)
|
bindings_dict = config.key_instance.get_bindings_for(modename)
|
||||||
bindings = [(k, v) for (k, v) in sorted(bindings_dict.items())
|
bindings = [(k, v) for (k, v) in sorted(bindings_dict.items())
|
||||||
if k.startswith(prefix) and
|
if k.startswith(prefix) and
|
||||||
not utils.is_special_key(k) and
|
|
||||||
not blacklisted(k) and
|
not blacklisted(k) and
|
||||||
(takes_count(v) or not countstr)]
|
(takes_count(v) or not countstr)]
|
||||||
|
|
||||||
|
@ -293,8 +293,6 @@ class FullscreenNotification(QLabel):
|
|||||||
bindings = all_bindings.get('fullscreen --leave')
|
bindings = all_bindings.get('fullscreen --leave')
|
||||||
if bindings:
|
if bindings:
|
||||||
key = bindings[0]
|
key = bindings[0]
|
||||||
if utils.is_special_key(key):
|
|
||||||
key = key.strip('<>').capitalize()
|
|
||||||
self.setText("Press {} to exit fullscreen.".format(key))
|
self.setText("Press {} to exit fullscreen.".format(key))
|
||||||
else:
|
else:
|
||||||
self.setText("Page is now fullscreen.")
|
self.setText("Page is now fullscreen.")
|
||||||
|
@ -33,6 +33,7 @@ import functools
|
|||||||
import contextlib
|
import contextlib
|
||||||
import socket
|
import socket
|
||||||
import shlex
|
import shlex
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
from PyQt5.QtCore import Qt, QUrl
|
from PyQt5.QtCore import Qt, QUrl
|
||||||
@ -418,10 +419,22 @@ def keyevent_to_string(e):
|
|||||||
return None
|
return None
|
||||||
mod = e.modifiers()
|
mod = e.modifiers()
|
||||||
parts = []
|
parts = []
|
||||||
|
|
||||||
for (mask, s) in modmask2str.items():
|
for (mask, s) in modmask2str.items():
|
||||||
if mod & mask and s not in parts:
|
if mod & mask and s not in parts:
|
||||||
parts.append(s)
|
parts.append(s)
|
||||||
parts.append(key_to_string(e.key()))
|
|
||||||
|
key_string = key_to_string(e.key())
|
||||||
|
if len(key_string) == 1:
|
||||||
|
category = unicodedata.category(key_string)
|
||||||
|
is_control_char = (category == 'Cc')
|
||||||
|
else:
|
||||||
|
is_control_char = False
|
||||||
|
|
||||||
|
if e.modifiers() == Qt.ShiftModifier and not is_control_char:
|
||||||
|
parts = []
|
||||||
|
|
||||||
|
parts.append(key_string)
|
||||||
return normalize_keystr('+'.join(parts))
|
return normalize_keystr('+'.join(parts))
|
||||||
|
|
||||||
|
|
||||||
@ -466,6 +479,8 @@ def is_special_key(keystr):
|
|||||||
|
|
||||||
def _parse_single_key(keystr):
|
def _parse_single_key(keystr):
|
||||||
"""Convert a single key string to a (Qt.Key, Qt.Modifiers, text) tuple."""
|
"""Convert a single key string to a (Qt.Key, Qt.Modifiers, text) tuple."""
|
||||||
|
# FIXME remove
|
||||||
|
|
||||||
if is_special_key(keystr):
|
if is_special_key(keystr):
|
||||||
# Special key
|
# Special key
|
||||||
keystr = keystr[1:-1]
|
keystr = keystr[1:-1]
|
||||||
|
Loading…
Reference in New Issue
Block a user