mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 01:38:02 +02:00
Do not depend on glfw just to parse the config file
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user