Dynamic detection of wayland

This commit is contained in:
Kovid Goyal 2017-11-21 06:26:55 +05:30
parent eb8f4e0b3c
commit 47dec2c2e9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 19 additions and 13 deletions

View File

@ -14,6 +14,7 @@ version = (0, 5, 1)
str_version = '.'.join(map(str, version))
_plat = sys.platform.lower()
is_macos = 'darwin' in _plat
base = os.path.dirname(os.path.abspath(__file__))
ScreenGeometry = namedtuple('ScreenGeometry', 'xstart ystart xnum ynum dx dy')
@ -58,4 +59,11 @@ except KeyError:
print('Failed to read login shell from /etc/passwd for current user, falling back to /bin/sh', file=sys.stderr)
shell_path = '/bin/sh'
iswayland = False
def glfw_path(module):
return os.path.join(base, 'glfw-{}.so'.format(module))
is_wayland = False
if os.environ.get('WAYLAND_DISPLAY') and os.path.exists(glfw_path('wayland')):
is_wayland = True

View File

@ -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 is_macos, iswayland, logo_data_file
from .constants import is_macos, is_wayland, logo_data_file, glfw_path
from .fast_data_types import (
change_wcwidth, create_os_window, glfw_init, glfw_terminate,
install_sigchld_handler, set_default_window_icon, set_logical_dpi,
@ -25,8 +25,6 @@ from .utils import (
)
from .window import load_shader_programs
base = os.path.dirname(os.path.abspath(__file__))
def load_all_shaders():
load_shader_programs()
@ -34,20 +32,20 @@ def load_all_shaders():
def init_graphics():
glfw_module = 'cocoa' if is_macos else 'x11'
if not glfw_init(os.path.join(base, 'glfw-{}.so'.format(glfw_module))):
glfw_module = 'cocoa' if is_macos else ('wayland' if is_wayland else 'x11')
if not glfw_init(glfw_path(glfw_module)):
raise SystemExit('GLFW initialization failed')
return glfw_module
def run_app(opts, args):
set_scale(opts.box_drawing_scale)
set_options(opts, iswayland, args.debug_gl)
set_options(opts, is_wayland, args.debug_gl)
load_cached_values()
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 is_macos: # no window icons on wayland
if not is_wayland 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())

View File

@ -17,7 +17,7 @@ from contextlib import contextmanager
from functools import lru_cache
from time import monotonic
from .constants import appname, is_macos, iswayland
from .constants import appname, is_macos, is_wayland
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
@ -117,7 +117,7 @@ def parse_color_set(raw):
def set_primary_selection(text):
if is_macos or iswayland:
if is_macos or is_wayland:
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 is_macos or iswayland:
if is_macos or is_wayland:
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')
@ -197,7 +197,7 @@ def end_startup_notification_x11(ctx):
def init_startup_notification(window, startup_id=None):
if is_macos or iswayland:
if is_macos or is_wayland:
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 is_macos or iswayland:
if is_macos or is_wayland:
return
try:
end_startup_notification_x11(ctx)