Use importlib to load the shaders
This commit is contained in:
@@ -24,14 +24,14 @@ version: Version = Version(0, 19, 3)
|
|||||||
str_version: str = '.'.join(map(str, version))
|
str_version: str = '.'.join(map(str, version))
|
||||||
_plat = sys.platform.lower()
|
_plat = sys.platform.lower()
|
||||||
is_macos: bool = 'darwin' in _plat
|
is_macos: bool = 'darwin' in _plat
|
||||||
base = os.path.dirname(os.path.abspath(__file__))
|
kitty_lib_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
@run_once
|
@run_once
|
||||||
def kitty_exe() -> str:
|
def kitty_exe() -> str:
|
||||||
rpath = sys._xoptions.get('bundle_exe_dir')
|
rpath = sys._xoptions.get('bundle_exe_dir')
|
||||||
if not rpath:
|
if not rpath:
|
||||||
items = os.environ.get('PATH', '').split(os.pathsep) + [os.path.join(base, 'launcher')]
|
items = os.environ.get('PATH', '').split(os.pathsep) + [os.path.join(kitty_lib_dir, 'launcher')]
|
||||||
seen: Set[str] = set()
|
seen: Set[str] = set()
|
||||||
for candidate in filter(None, items):
|
for candidate in filter(None, items):
|
||||||
if candidate not in seen:
|
if candidate not in seen:
|
||||||
@@ -113,7 +113,7 @@ def wakeup() -> None:
|
|||||||
b.child_monitor.wakeup()
|
b.child_monitor.wakeup()
|
||||||
|
|
||||||
|
|
||||||
base_dir = os.path.dirname(base)
|
base_dir = os.path.dirname(kitty_lib_dir)
|
||||||
terminfo_dir = os.path.join(base_dir, 'terminfo')
|
terminfo_dir = os.path.join(base_dir, 'terminfo')
|
||||||
logo_png_file = os.path.join(base_dir, 'logo', 'kitty.png')
|
logo_png_file = os.path.join(base_dir, 'logo', 'kitty.png')
|
||||||
beam_cursor_data_file = os.path.join(base_dir, 'logo', 'beam-cursor.png')
|
beam_cursor_data_file = os.path.join(base_dir, 'logo', 'beam-cursor.png')
|
||||||
@@ -126,7 +126,7 @@ except KeyError:
|
|||||||
|
|
||||||
|
|
||||||
def glfw_path(module: str) -> str:
|
def glfw_path(module: str) -> str:
|
||||||
return os.path.join(base, 'glfw-{}.so'.format(module))
|
return os.path.join(kitty_lib_dir, 'glfw-{}.so'.format(module))
|
||||||
|
|
||||||
|
|
||||||
def detect_if_wayland_ok() -> bool:
|
def detect_if_wayland_ok() -> bool:
|
||||||
@@ -186,3 +186,8 @@ def resolve_custom_file(path: str) -> str:
|
|||||||
if not os.path.isabs(path):
|
if not os.path.isabs(path):
|
||||||
path = os.path.join(config_dir, path)
|
path = os.path.join(config_dir, path)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def read_kitty_resource(name: str) -> bytes:
|
||||||
|
from importlib.resources import read_binary
|
||||||
|
return read_binary('kitty', name)
|
||||||
|
|||||||
@@ -19,15 +19,14 @@ from typing import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from .constants import (
|
from .constants import (
|
||||||
appname, is_macos, is_wayland, shell_path, supports_primary_selection
|
appname, is_macos, is_wayland, read_kitty_resource, shell_path,
|
||||||
|
supports_primary_selection
|
||||||
)
|
)
|
||||||
from .options_stub import Options
|
from .options_stub import Options
|
||||||
from .rgb import Color, to_color
|
from .rgb import Color, to_color
|
||||||
from .types import ConvertibleToNumbers, run_once
|
from .types import ConvertibleToNumbers, run_once
|
||||||
from .typing import AddressFamily, PopenType, Socket, StartupCtx
|
from .typing import AddressFamily, PopenType, Socket, StartupCtx
|
||||||
|
|
||||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
|
|
||||||
|
|
||||||
def expandvars(val: str, env: Mapping[str, str] = {}, fallback_to_os_env: bool = True) -> str:
|
def expandvars(val: str, env: Mapping[str, str] = {}, fallback_to_os_env: bool = True) -> str:
|
||||||
|
|
||||||
@@ -59,11 +58,11 @@ def platform_window_id(os_window_id: int) -> Optional[int]:
|
|||||||
|
|
||||||
def load_shaders(name: str) -> Tuple[str, str]:
|
def load_shaders(name: str) -> Tuple[str, str]:
|
||||||
from .fast_data_types import GLSL_VERSION
|
from .fast_data_types import GLSL_VERSION
|
||||||
with open(os.path.join(BASE, '{}_vertex.glsl'.format(name))) as f:
|
|
||||||
vert = f.read().replace('GLSL_VERSION', str(GLSL_VERSION), 1)
|
def load(which: str) -> str:
|
||||||
with open(os.path.join(BASE, '{}_fragment.glsl'.format(name))) as f:
|
return read_kitty_resource(f'{name}_{which}.glsl').decode('utf-8').replace('GLSL_VERSION', str(GLSL_VERSION), 1)
|
||||||
frag = f.read().replace('GLSL_VERSION', str(GLSL_VERSION), 1)
|
|
||||||
return vert, frag
|
return load('vertex'), load('fragment')
|
||||||
|
|
||||||
|
|
||||||
def safe_print(*a: Any, **k: Any) -> None:
|
def safe_print(*a: Any, **k: Any) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user