Do not depend on glfw just to parse the config file
This commit is contained in:
parent
6b9c71ec62
commit
f1494b64e5
@ -20,6 +20,7 @@ from .conf.utils import (
|
|||||||
from .config_data import all_options, parse_mods, type_map
|
from .config_data import all_options, parse_mods, type_map
|
||||||
from .constants import cache_dir, defconf, is_macos
|
from .constants import cache_dir, defconf, is_macos
|
||||||
from .utils import log_error
|
from .utils import log_error
|
||||||
|
from .key_names import get_key_name_lookup
|
||||||
|
|
||||||
named_keys = {
|
named_keys = {
|
||||||
"'": 'APOSTROPHE',
|
"'": 'APOSTROPHE',
|
||||||
@ -47,11 +48,12 @@ def parse_shortcut(sc):
|
|||||||
key = getattr(defines, 'GLFW_KEY_' + named_keys.get(key, key), None)
|
key = getattr(defines, 'GLFW_KEY_' + named_keys.get(key, key), None)
|
||||||
is_native = False
|
is_native = False
|
||||||
if key is None:
|
if key is None:
|
||||||
if parts[-1].startswith('0x'):
|
q = parts[-1]
|
||||||
|
if q.startswith('0x'):
|
||||||
with suppress(Exception):
|
with suppress(Exception):
|
||||||
key = int(parts[-1], 16)
|
key = int(q, 16)
|
||||||
else:
|
else:
|
||||||
key = defines.key_for_native_key_name(parts[-1])
|
key = get_key_name_lookup()(q)
|
||||||
is_native = key is not None
|
is_native = key is not None
|
||||||
return mods, is_native, key
|
return mods, is_native, key
|
||||||
|
|
||||||
|
|||||||
41
kitty/key_names.py
Normal file
41
kitty/key_names.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from .constants import is_macos
|
||||||
|
|
||||||
|
|
||||||
|
def null_lookup(name, case_sensitive=False):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if is_macos:
|
||||||
|
def get_key_name_lookup():
|
||||||
|
return null_lookup
|
||||||
|
else:
|
||||||
|
|
||||||
|
def load_libxkb_lookup():
|
||||||
|
import ctypes
|
||||||
|
lib = ctypes.CDLL('libxkbcommon.so')
|
||||||
|
f = lib.xkb_keysym_from_name
|
||||||
|
f.argtypes = [ctypes.c_char_p, ctypes.c_int]
|
||||||
|
f.restype = ctypes.c_int
|
||||||
|
|
||||||
|
def xkb_lookup(name, case_sensitive=False):
|
||||||
|
name = name.encode('utf-8')
|
||||||
|
return f(name, int(case_sensitive)) or None
|
||||||
|
|
||||||
|
return xkb_lookup
|
||||||
|
|
||||||
|
def get_key_name_lookup():
|
||||||
|
ans = getattr(get_key_name_lookup, 'ans', None)
|
||||||
|
if ans is None:
|
||||||
|
try:
|
||||||
|
ans = load_libxkb_lookup()
|
||||||
|
except Exception as e:
|
||||||
|
print('Failed to load libxkbcommon.xkb_keysym_from_name with error:', e, file=sys.stderr)
|
||||||
|
ans = null_lookup
|
||||||
|
get_key_name_lookup.ans = ans
|
||||||
|
return ans
|
||||||
@ -244,7 +244,6 @@ def _main():
|
|||||||
args, rest = parse_args(args=args)
|
args, rest = parse_args(args=args)
|
||||||
args.args = rest
|
args.args = rest
|
||||||
if args.debug_config:
|
if args.debug_config:
|
||||||
init_glfw(args.debug_keyboard) # needed for parsing native keysyms
|
|
||||||
create_opts(args, debug_config=True)
|
create_opts(args, debug_config=True)
|
||||||
return
|
return
|
||||||
if getattr(args, 'detach', False):
|
if getattr(args, 'detach', False):
|
||||||
@ -258,9 +257,9 @@ def _main():
|
|||||||
if not is_first:
|
if not is_first:
|
||||||
talk_to_instance(args)
|
talk_to_instance(args)
|
||||||
return
|
return
|
||||||
init_glfw(args.debug_keyboard) # needed for parsing native keysyms
|
|
||||||
bad_lines = []
|
bad_lines = []
|
||||||
opts = create_opts(args, accumulate_bad_lines=bad_lines)
|
opts = create_opts(args, accumulate_bad_lines=bad_lines)
|
||||||
|
init_glfw(args.debug_keyboard)
|
||||||
setup_environment(opts, args)
|
setup_environment(opts, args)
|
||||||
try:
|
try:
|
||||||
with setup_profiling(args):
|
with setup_profiling(args):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user