Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/linuxbsd/wayland/SCsub
12222 views
#!/usr/bin/env python
from misc.utility.scons_hints import *

Import("env")

File = env.File

# TODO: Add warning to headers and code about their autogenerated status.
if env["use_sowrap"]:
    # We have to implement separate builders for so wrappers as the
    # autogenerated Wayland protocol wrapper must include them instead of the
    # native libraries.

    WAYLAND_BUILDERS_SOWRAP = {
        "WAYLAND_API_HEADER": Builder(
            action=env.Run(
                r"wayland-scanner -c client-header < ${SOURCE} | "
                r"sed 's:wayland-client-core\.h:../dynwrappers/wayland-client-core-so_wrap\.h:' > ${TARGET}",
            ),
            single_source=True,
        ),
        "WAYLAND_API_CODE": Builder(
            action=env.Run(
                r"wayland-scanner -c private-code < ${SOURCE} | "
                r"sed 's:wayland-util\.h:../dynwrappers/wayland-client-core-so_wrap\.h:' > ${TARGET}",
            ),
            single_source=True,
        ),
    }
    env.Append(BUILDERS=WAYLAND_BUILDERS_SOWRAP)
else:
    WAYLAND_BUILDERS = {
        "WAYLAND_API_HEADER": Builder(
            action=env.Run(r"wayland-scanner -c client-header < ${SOURCE} > ${TARGET}"),
            single_source=True,
        ),
        "WAYLAND_API_CODE": Builder(
            action=env.Run(r"wayland-scanner -c private-code < ${SOURCE} > ${TARGET}"),
            single_source=True,
        ),
    }
    env.Append(BUILDERS=WAYLAND_BUILDERS)


def generate_from_xml(name, path):
    header = env.WAYLAND_API_HEADER(File(f"protocol/{name}.gen.h"), path)
    source = env.WAYLAND_API_CODE(File(f"protocol/{name}.gen.c"), path)
    env.NoCache(header, source)

    return source


generated_sources = [
    # Core protocol
    generate_from_xml("wayland", "#thirdparty/wayland/protocol/wayland.xml"),
    # Stable protocols
    generate_from_xml("tablet", "#thirdparty/wayland-protocols/stable/tablet/tablet-v2.xml"),
    generate_from_xml("viewporter", "#thirdparty/wayland-protocols/stable/viewporter/viewporter.xml"),
    generate_from_xml("xdg_shell", "#thirdparty/wayland-protocols/stable/xdg-shell/xdg-shell.xml"),
    # Staging protocols
    generate_from_xml("cursor_shape", "#thirdparty/wayland-protocols/staging/cursor-shape/cursor-shape-v1.xml"),
    generate_from_xml(
        "fractional_scale", "#thirdparty/wayland-protocols/staging/fractional-scale/fractional-scale-v1.xml"
    ),
    generate_from_xml("xdg_activation", "#thirdparty/wayland-protocols/staging/xdg-activation/xdg-activation-v1.xml"),
    generate_from_xml(
        "xdg_system_bell", "#thirdparty/wayland-protocols/staging/xdg-system-bell/xdg-system-bell-v1.xml"
    ),
    generate_from_xml(
        "xdg_toplevel_icon", "#thirdparty/wayland-protocols/staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml"
    ),
    # Unstable protocols
    generate_from_xml(
        "idle_inhibit", "#thirdparty/wayland-protocols/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml"
    ),
    generate_from_xml(
        "pointer_constraints",
        "#thirdparty/wayland-protocols/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml",
    ),
    generate_from_xml(
        "pointer_gestures", "#thirdparty/wayland-protocols/unstable/pointer-gestures/pointer-gestures-unstable-v1.xml"
    ),
    generate_from_xml(
        "primary_selection",
        "#thirdparty/wayland-protocols/unstable/primary-selection/primary-selection-unstable-v1.xml",
    ),
    generate_from_xml(
        "relative_pointer", "#thirdparty/wayland-protocols/unstable/relative-pointer/relative-pointer-unstable-v1.xml"
    ),
    generate_from_xml("text_input", "#thirdparty/wayland-protocols/unstable/text-input/text-input-unstable-v3.xml"),
    generate_from_xml(
        "xdg_decoration", "#thirdparty/wayland-protocols/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"
    ),
    generate_from_xml(
        "xdg_foreign_v1", "#thirdparty/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v1.xml"
    ),  # Note: deprecated
    generate_from_xml(
        "xdg_foreign_v2", "#thirdparty/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v2.xml"
    ),
]

source_files = generated_sources + [
    File("detect_prime_egl.cpp"),
    File("display_server_wayland.cpp"),
    File("key_mapping_xkb.cpp"),
    File("wayland_thread.cpp"),
]

if env["use_sowrap"]:
    source_files.append(
        [
            File("dynwrappers/wayland-cursor-so_wrap.c"),
            File("dynwrappers/wayland-client-core-so_wrap.c"),
            File("dynwrappers/wayland-egl-core-so_wrap.c"),
        ]
    )

    if env["libdecor"]:
        source_files.append(File("dynwrappers/libdecor-so_wrap.c"))


if env["vulkan"]:
    source_files.append(File("rendering_context_driver_vulkan_wayland.cpp"))

if env["opengl3"]:
    source_files.append(File("egl_manager_wayland.cpp"))
    source_files.append(File("egl_manager_wayland_gles.cpp"))

Return("source_files")