From 85fcd51ea3092fc206f0d6406a1f647a034d1faf Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 21 Nov 2017 06:07:41 +0530 Subject: [PATCH] Enable building of glfw-wayland backend --- .gitignore | 1 + glfw/glfw.py | 27 +++++++++++++++++++++++++-- glfw/source-info.json | 4 ++++ glfw/wl_init.c | 2 +- setup.py | 13 +++++++++++-- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 178fc5778..2d0817a91 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ asan-launcher kitty-profile dev __pycache__ +glfw/wayland-*-client-protocol.h diff --git a/glfw/glfw.py b/glfw/glfw.py index d99626643..8ca8c33cb 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -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 diff --git a/glfw/source-info.json b/glfw/source-info.json index 7c6803764..78f2fcf52 100644 --- a/glfw/source-info.json +++ b/glfw/source-info.json @@ -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", diff --git a/glfw/wl_init.c b/glfw/wl_init.c index 3841636f2..6e7003d1b 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -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; diff --git a/setup.py b/setup.py index f299795fe..a78dfe461 100755 --- a/setup.py +++ b/setup.py @@ -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)