Enable building of glfw-wayland backend

This commit is contained in:
Kovid Goyal 2017-11-21 06:07:41 +05:30
parent 9ec6cf721f
commit 85fcd51ea3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 42 additions and 5 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ asan-launcher
kitty-profile
dev
__pycache__
glfw/wayland-*-client-protocol.h

View File

@ -33,9 +33,10 @@ def init_env(env, pkg_config, at_least_version, module='x11'):
)
else:
ans.ldpaths.extend('-lrt -lm -ldl'.split())
sinfo = json.load(open(os.path.join(base, 'source-info.json')))
if module == 'x11':
for dep in 'x11 xrandr xinerama xcursor xkbcommon-x11'.split():
for dep in 'x11 xrandr xinerama xcursor xkbcommon xkbcommon-x11'.split():
ans.cflags.extend(pkg_config(dep, '--cflags-only-I'))
ans.ldpaths.extend(pkg_config(dep, '--libs'))
@ -43,12 +44,30 @@ def init_env(env, pkg_config, at_least_version, module='x11'):
for f in 'Cocoa IOKit CoreFoundation CoreVideo'.split():
ans.ldpaths.extend(('-framework', f))
sinfo = json.load(open(os.path.join(base, 'source-info.json')))
elif module == 'wayland':
at_least_version('wayland-protocols', 1, 1)
ans.wayland_packagedir = os.path.abspath(pkg_config('wayland-protocols', '--variable=pkgdatadir')[0])
ans.wayland_scanner = os.path.abspath(pkg_config('wayland-scanner', '--variable=wayland_scanner')[0])
ans.wayland_protocols = tuple(sinfo[module]['protocols'])
for dep in 'wayland-egl wayland-client wayland-scanner xkbcommon'.split():
ans.cflags.extend(pkg_config(dep, '--cflags-only-I'))
ans.ldpaths.extend(pkg_config(dep, '--libs'))
ans.sources = sinfo['common']['sources'] + sinfo[module]['sources']
ans.all_headers = [x for x in os.listdir(base) if x.endswith('.h')]
return ans
def build_wayland_protocols(env, run_tool, emphasis, newer, dest_dir):
for protocol in env.wayland_protocols:
src = os.path.join(env.wayland_packagedir, protocol)
dest = os.path.basename(src).rpartition('.')[0] + '-client-protocol.h'
dest = os.path.join(dest_dir, 'wayland-' + dest)
if newer(dest, src):
run_tool([env.wayland_scanner, 'client-header', src, dest],
desc='Generating {} ...'.format(emphasis(os.path.basename(dest))))
def collect_source_information():
raw = open('src/CMakeLists.txt').read()
@ -71,6 +90,10 @@ def collect_source_information():
if group == 'x11':
ans[group]['headers'].append('linux_joystick.h')
ans[group]['sources'].append('linux_joystick.c')
elif group == 'wayland':
ans[group]['protocols'] = p = []
for m in re.finditer(r'WAYLAND_PROTOCOLS_PKGDATADIR\}/([^"]+)"', raw):
p.append(m.group(1))
return ans

View File

@ -62,6 +62,10 @@
"egl_context.h",
"osmesa_context.h"
],
"protocols": [
"unstable/relative-pointer/relative-pointer-unstable-v1.xml",
"unstable/pointer-constraints/pointer-constraints-unstable-v1.xml"
],
"sources": [
"wl_init.c",
"wl_monitor.c",

2
glfw/wl_init.c vendored
View File

@ -131,7 +131,7 @@ static void pointerHandleAxis(void* data,
{
_GLFWwindow* window = _glfw.wl.pointerFocus;
double scrollFactor;
double x, y;
double x = 0.0, y = 0.0;
if (!window)
return;

View File

@ -384,11 +384,20 @@ def find_c_files():
def compile_glfw(incremental, compilation_database, all_keys):
modules = 'cocoa' if isosx else 'x11'
modules = 'cocoa' if isosx else 'x11 wayland'
for module in modules.split():
genv = glfw.init_env(env, pkg_config, at_least_version, module)
try:
genv = glfw.init_env(env, pkg_config, at_least_version, module)
except SystemExit as err:
if module != 'wayland':
raise
print(err.message, file=sys.stderr)
print('Disabling building of wayland backend', file=sys.stderr)
continue
sources = [os.path.join('glfw', x) for x in genv.sources]
all_headers = [os.path.join('glfw', x) for x in genv.all_headers]
if module == 'wayland':
glfw.build_wayland_protocols(genv, run_tool, emphasis, newer, os.path.join(base, 'glfw'))
compile_c_extension(genv, 'kitty/glfw-' + module, incremental, compilation_database, all_keys, sources, all_headers)