uno-sdk icon indicating copy to clipboard operation
uno-sdk copied to clipboard

Add platform and wayland.libDecor init hints

Open markjfisher opened this issue 1 year ago • 0 comments

I wanted to add platform hints to my code as follows

glfw {
    errorCB = defaultErrorCB

    initHint {
        if (glfw.Platform.Wayland.supported) {
            platform = GLFW_PLATFORM_WAYLAND
            libDecor = GLFW_WAYLAND_PREFER_LIBDECOR
        }
    }

I can do this with the extensions:

var InitHint.platform: Int
    get() = throw Exception("No getting allowed")
    set(value) {
        glfwInitHint(GLFW_PLATFORM, value)
    }

var InitHint.libDecor: Int
    get() = throw Exception("No getting allowed")
    set(value) {
        glfwInitHint(GLFW_WAYLAND_LIBDECOR, value)
    }

but I thought I'd also contribute them to your repository if you're willing to take them!

I've actually put the libDecor in its own "wayland" block within InitHints, so it reads like this for normal usage:

glfw {
    errorCB = defaultErrorCB

    initHint {
        if (glfw.Platform.Wayland.supported) {
            platform = GLFW_PLATFORM_WAYLAND
            wayland {
                libDecor = GLFW_WAYLAND_PREFER_LIBDECOR
            }
        }
    }

I was torn on a name for platform, as it's already a property name. I went with simplicity though as we're already in the InitHints block, but it could also be platformHint.

Additionally, I kept them as properties rather than functions, despite not being able to read the value, as I feel the syntax is nicer, i.e. platform = GLFW_PLATFORM_XXX rather than platform(GLFW_PLATFORM_XXX) as everything else is assigning rather than calling.

markjfisher avatar Jan 15 '24 17:01 markjfisher