diff --git a/glfw/glfw.py b/glfw/glfw.py index 8ca8c33cb..df2d188da 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -9,7 +9,7 @@ import shutil import sys _plat = sys.platform.lower() -isosx = 'darwin' in _plat +is_macos = 'darwin' in _plat base = os.path.dirname(os.path.abspath(__file__)) @@ -19,14 +19,14 @@ def init_env(env, pkg_config, at_least_version, module='x11'): x for x in ans.cflags if x not in '-Wpedantic -Wextra -pedantic-errors'.split() ] - if not isosx: + if not is_macos: ans.cflags.append('-pthread') ans.ldpaths.append('-pthread') ans.cflags.append('-fpic') ans.cflags.append('-D_GLFW_' + module.upper()) ans.cflags.append('-D_GLFW_BUILD_DLL') - if isosx: + if is_macos: ans.ldpaths.extend( "-framework Cocoa -framework IOKit -framework CoreFoundation -framework CoreVideo". split() diff --git a/kitty/cli.py b/kitty/cli.py index 4f2cc795f..fed069e9d 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -6,7 +6,7 @@ import argparse from gettext import gettext as _ from .config import load_config -from .constants import appname, str_version, isosx, defconf +from .constants import appname, str_version, is_macos, defconf from .layout import all_layouts @@ -70,7 +70,7 @@ def option_parser(): default=False, help=_('Output commands received from child process to stdout') ) - if not isosx: + if not is_macos: a( '--detach', action='store_true', diff --git a/kitty/constants.py b/kitty/constants.py index e74ce2b8b..266c39b3f 100644 --- a/kitty/constants.py +++ b/kitty/constants.py @@ -13,7 +13,7 @@ appname = 'kitty' version = (0, 5, 1) str_version = '.'.join(map(str, version)) _plat = sys.platform.lower() -isosx = 'darwin' in _plat +is_macos = 'darwin' in _plat ScreenGeometry = namedtuple('ScreenGeometry', 'xstart ystart xnum ynum dx dy') @@ -25,7 +25,7 @@ def _get_config_dir(): if 'KITTY_CONFIG_DIRECTORY' in os.environ: return os.path.abspath(os.path.expanduser(os.environ['VISE_CONFIG_DIRECTORY'])) - candidate = os.path.abspath(os.path.expanduser(os.environ.get('XDG_CONFIG_HOME') or ('~/Library/Preferences' if isosx else '~/.config'))) + candidate = os.path.abspath(os.path.expanduser(os.environ.get('XDG_CONFIG_HOME') or ('~/Library/Preferences' if is_macos else '~/.config'))) ans = os.path.join(candidate, appname) os.makedirs(ans, exist_ok=True) return ans diff --git a/kitty/fonts/list.py b/kitty/fonts/list.py index a39a1923b..8569c8cfb 100644 --- a/kitty/fonts/list.py +++ b/kitty/fonts/list.py @@ -3,9 +3,9 @@ # License: GPL v3 Copyright: 2017, Kovid Goyal import sys -from kitty.constants import isosx +from kitty.constants import is_macos -if isosx: +if is_macos: from .core_text import list_fonts else: from .fontconfig import list_fonts diff --git a/kitty/fonts/render.py b/kitty/fonts/render.py index 61fbefd46..2fbce2ba9 100644 --- a/kitty/fonts/render.py +++ b/kitty/fonts/render.py @@ -8,7 +8,7 @@ from collections import namedtuple from math import ceil, floor, pi, sin, sqrt from kitty.config import defaults -from kitty.constants import isosx +from kitty.constants import is_macos from kitty.fast_data_types import ( Screen, change_wcwidth, get_fallback_font, send_prerendered_sprites, set_font, set_font_size, set_logical_dpi, set_send_sprite_to_gpu, @@ -16,7 +16,7 @@ from kitty.fast_data_types import ( ) from kitty.fonts.box_drawing import render_box_char, render_missing_glyph -if isosx: +if is_macos: from .core_text import get_font_files, font_for_family else: from .fontconfig import get_font_files, font_for_family @@ -243,7 +243,7 @@ def test_fallback_font(qtext=None, bold=False, italic=False): def showcase(): change_wcwidth(True) - f = 'monospace' if isosx else 'Liberation Mono' + f = 'monospace' if is_macos else 'Liberation Mono' test_render_string('He\u0347\u0305llo\u0337, w\u0302or\u0306l\u0354d!', family=f) test_render_string('你好,世界', family=f) test_render_string('|\U0001F601|\U0001F64f|\U0001F63a|', family=f) diff --git a/kitty/main.py b/kitty/main.py index 3c29a9a64..d8efa5ef5 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -12,7 +12,7 @@ from .borders import load_borders_program from .boss import Boss from .cli import create_opts, option_parser from .config import initial_window_size, load_cached_values, save_cached_values -from .constants import isosx, iswayland, logo_data_file +from .constants import is_macos, iswayland, logo_data_file from .fast_data_types import ( change_wcwidth, create_os_window, glfw_init, glfw_terminate, install_sigchld_handler, set_default_window_icon, set_logical_dpi, @@ -34,7 +34,7 @@ def load_all_shaders(): def init_graphics(): - glfw_module = 'cocoa' if isosx else 'x11' + glfw_module = 'cocoa' if is_macos else 'x11' if not glfw_init(os.path.join(base, 'glfw-{}.so'.format(glfw_module))): raise SystemExit('GLFW initialization failed') return glfw_module @@ -47,7 +47,7 @@ def run_app(opts, args): w, h = initial_window_size(opts) window_id = create_os_window(w, h, encode_wm_class(args.name, args.cls), True, load_all_shaders) startup_ctx = init_startup_notification(window_id) - if not iswayland and not isosx: # no window icons on wayland + if not iswayland and not is_macos: # no window icons on wayland with open(logo_data_file, 'rb') as f: set_default_window_icon(f.read(), 256, 256) set_logical_dpi(*get_logical_dpi()) @@ -99,12 +99,12 @@ def main(): sys.setswitchinterval(1000.0) # we have only a single python thread except AttributeError: pass # python compiled without threading - if isosx: + if is_macos: ensure_osx_locale() try: locale.setlocale(locale.LC_ALL, '') except Exception: - if not isosx: + if not is_macos: raise print('Failed to set locale with LANG:', os.environ.get('LANG'), file=sys.stderr) os.environ.pop('LANG') diff --git a/kitty/utils.py b/kitty/utils.py index efeb2f540..bfde2c4ec 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -17,7 +17,7 @@ from contextlib import contextmanager from functools import lru_cache from time import monotonic -from .constants import appname, isosx, iswayland +from .constants import appname, is_macos, iswayland from .fast_data_types import ( GLSL_VERSION, glfw_get_physical_dpi, glfw_primary_monitor_content_scale, redirect_std_streams, wcwidth as wcwidth_impl, x11_display, x11_window_id @@ -78,7 +78,7 @@ def get_logical_dpi(override_dpi=None): if override_dpi is not None: get_logical_dpi.ans = override_dpi if not hasattr(get_logical_dpi, 'ans'): - if isosx: + if is_macos: # TODO: Investigate if this needs a different implementation on OS X get_logical_dpi.ans = glfw_get_physical_dpi() else: @@ -117,7 +117,7 @@ def parse_color_set(raw): def set_primary_selection(text): - if isosx or iswayland: + if is_macos or iswayland: return # There is no primary selection if isinstance(text, bytes): text = text.decode('utf-8') @@ -126,7 +126,7 @@ def set_primary_selection(text): def get_primary_selection(): - if isosx or iswayland: + if is_macos or iswayland: return '' # There is no primary selection from kitty.fast_data_types import get_primary_selection return (get_primary_selection() or b'').decode('utf-8', 'replace') @@ -155,7 +155,7 @@ def open_cmd(cmd, arg=None): def open_url(url, program='default'): if program == 'default': - cmd = ['open'] if isosx else ['xdg-open'] + cmd = ['open'] if is_macos else ['xdg-open'] else: cmd = shlex.split(program) return open_cmd(cmd, url) @@ -197,7 +197,7 @@ def end_startup_notification_x11(ctx): def init_startup_notification(window, startup_id=None): - if isosx or iswayland: + if is_macos or iswayland: return try: return init_startup_notification_x11(window, startup_id) @@ -209,7 +209,7 @@ def init_startup_notification(window, startup_id=None): def end_startup_notification(ctx): if not ctx: return - if isosx or iswayland: + if is_macos or iswayland: return try: end_startup_notification_x11(ctx) @@ -233,7 +233,7 @@ def remove_socket_file(s, path=None): def single_instance_unix(name): home = os.path.expanduser('~') candidates = [tempfile.gettempdir(), home] - if isosx: + if is_macos: from .fast_data_types import user_cache_dir candidates = [user_cache_dir(), '/Library/Caches'] for loc in candidates: @@ -294,6 +294,6 @@ def single_instance(group_id=None): def encode_wm_class(name, cls, title=appname): - if isosx: + if is_macos: return title return '\x01' + (name or cls) + '\x1e' + cls + '\x1e' + title diff --git a/kitty_tests/fonts.py b/kitty_tests/fonts.py index c69823889..2a96e7150 100644 --- a/kitty_tests/fonts.py +++ b/kitty_tests/fonts.py @@ -4,7 +4,7 @@ from collections import OrderedDict -from kitty.constants import isosx +from kitty.constants import is_macos from kitty.fast_data_types import ( change_wcwidth, set_logical_dpi, set_send_sprite_to_gpu, sprite_map_set_layout, sprite_map_set_limits, test_render_line, @@ -64,7 +64,7 @@ class Rendering(BaseTest): render_string('ab\u0347\u0305你好|\U0001F601|\U0001F64f|\U0001F63a|') text = 'He\u0347\u0305llo\u0341, w\u0302or\u0306l\u0354d!' # macOS has no fonts capable of rendering combining chars - if isosx: + if is_macos: text = text.encode('ascii', 'ignore').decode('ascii') cells = render_string(text)[-1] self.ae(len(cells), len(text.encode('ascii', 'ignore'))) diff --git a/setup.py b/setup.py index a78dfe461..e118494b1 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ version = tuple( ) ) _plat = sys.platform.lower() -isosx = 'darwin' in _plat +is_macos = 'darwin' in _plat is_travis = os.environ.get('TRAVIS') == 'true' env = None @@ -74,7 +74,7 @@ def at_least_version(package, major, minor=0): def cc_version(): - cc = os.environ.get('CC', 'clang' if isosx else 'gcc') + cc = os.environ.get('CC', 'clang' if is_macos else 'gcc') raw = subprocess.check_output([cc, '-dumpversion']).decode('utf-8') ver = raw.split('.')[:2] try: @@ -197,7 +197,7 @@ def kitty_env(): cflags.append('-DSECONDARY_VERSION={}'.format(version[1])) at_least_version('harfbuzz', 1, 5) cflags.extend(pkg_config('libpng', '--cflags-only-I')) - if isosx: + if is_macos: font_libs = ['-framework', 'CoreText', '-framework', 'CoreGraphics'] cflags.extend(pkg_config('freetype2', '--cflags-only-I')) font_libs += pkg_config('freetype2', '--libs') @@ -207,12 +207,12 @@ def kitty_env(): cflags.extend(pkg_config('harfbuzz', '--cflags-only-I')) font_libs.extend(pkg_config('harfbuzz', '--libs')) pylib = get_python_flags(cflags) - gl_libs = ['-framework', 'OpenGL'] if isosx else pkg_config('gl', '--libs') + gl_libs = ['-framework', 'OpenGL'] if is_macos else pkg_config('gl', '--libs') libpng = pkg_config('libpng', '--libs') ans.ldpaths += pylib + font_libs + gl_libs + libpng + [ '-lunistring' ] - if isosx: + if is_macos: ans.ldpaths.extend('-framework Cocoa'.split()) if is_travis and 'SW' in os.environ: cflags.append('-I{}/include'.format(os.environ['SW'])) @@ -369,7 +369,7 @@ def compile_c_extension(kenv, module, incremental, compilation_database, all_key def find_c_files(): ans, headers = [], [] d = os.path.join(base, 'kitty') - exclude = {'fontconfig.c', 'desktop.c'} if isosx else {'core_text.m', 'cocoa_window.m'} + exclude = {'fontconfig.c', 'desktop.c'} if is_macos else {'core_text.m', 'cocoa_window.m'} for x in os.listdir(d): ext = os.path.splitext(x)[1] if ext in ('.c', '.m') and os.path.basename(x) not in exclude: @@ -384,7 +384,7 @@ def find_c_files(): def compile_glfw(incremental, compilation_database, all_keys): - modules = 'cocoa' if isosx else 'x11 wayland' + modules = 'cocoa' if is_macos else 'x11 wayland' for module in modules.split(): try: genv = glfw.init_env(env, pkg_config, at_least_version, module) @@ -440,7 +440,7 @@ def build_asan_launcher(args): cc, ccver = cc_version() cflags = '-g3 -Wall -Werror -fpie -std=c99'.split() pylib = get_python_flags(cflags) - sanitize_lib = ['-lasan'] if cc == 'gcc' and not isosx else [] + sanitize_lib = ['-lasan'] if cc == 'gcc' and not is_macos else [] cflags.extend(get_sanitize_args(cc, ccver)) cmd = [cc] + cflags + [src, '-o', dest] + sanitize_lib + pylib run_tool(cmd, desc='Creating {} ...'.format(emphasis('asan-launcher'))) @@ -496,7 +496,7 @@ def package(args, for_bundle=False): # {{{ launcher_dir = os.path.join(ddir, 'bin') safe_makedirs(launcher_dir) build_linux_launcher(args, launcher_dir, for_bundle) - if not isosx: # {{{ linux desktop gunk + if not is_macos: # {{{ linux desktop gunk icdir = os.path.join(ddir, 'share', 'icons', 'hicolor', '256x256', 'apps') safe_makedirs(icdir) shutil.copy2('logo/kitty.png', icdir)