diff --git a/wl/c.go b/wl/wayland-bind.c similarity index 71% rename from wl/c.go rename to wl/wayland-bind.c index b571e06..a177a37 100644 --- a/wl/c.go +++ b/wl/wayland-bind.c @@ -1,17 +1,7 @@ -package wl - -//go:generate sh -c "wayland-scanner client-header `pkg-config --variable=datarootdir wayland-protocols`/wayland-protocols/staging/security-context/security-context-v1.xml security-context-v1-protocol.h" -//go:generate sh -c "wayland-scanner private-code `pkg-config --variable=datarootdir wayland-protocols`/wayland-protocols/staging/security-context/security-context-v1.xml security-context-v1-protocol.c" - -/* -#cgo linux pkg-config: --static wayland-client -#cgo freebsd openbsd LDFLAGS: -lwayland-client - -#include +#include "wayland-bind.h" #include #include #include - #include #include #include @@ -33,7 +23,7 @@ static const struct wl_registry_listener registry_listener = { .global_remove = registry_handle_global_remove, }; -static int32_t bind_wayland_fd(char *socket_path, int fd, const char *app_id, const char *instance_id, int sync_fd) { +int32_t bind_wayland_fd(char *socket_path, int fd, const char *app_id, const char *instance_id, int sync_fd) { int32_t res = 0; // refer to resErr for meaning struct wl_display *display; @@ -96,17 +86,3 @@ out: free((void *)instance_id); return res; } -*/ -import "C" -import "errors" - -var resErr = [...]error{ - 0: nil, - 1: errors.New("wl_display_connect_to_fd() failed"), - 2: errors.New("wp_security_context_v1 not available"), -} - -func bindWaylandFd(socketPath string, fd uintptr, appID, instanceID string, syncFD uintptr) error { - res := C.bind_wayland_fd(C.CString(socketPath), C.int(fd), C.CString(appID), C.CString(instanceID), C.int(syncFD)) - return resErr[int32(res)] -} diff --git a/wl/wayland-bind.h b/wl/wayland-bind.h new file mode 100644 index 0000000..67898fc --- /dev/null +++ b/wl/wayland-bind.h @@ -0,0 +1,3 @@ +#include + +int32_t bind_wayland_fd(char *socket_path, int fd, const char *app_id, const char *instance_id, int sync_fd); \ No newline at end of file diff --git a/wl/wl.go b/wl/wl.go new file mode 100644 index 0000000..2eb0e89 --- /dev/null +++ b/wl/wl.go @@ -0,0 +1,24 @@ +package wl + +//go:generate sh -c "wayland-scanner client-header `pkg-config --variable=datarootdir wayland-protocols`/wayland-protocols/staging/security-context/security-context-v1.xml security-context-v1-protocol.h" +//go:generate sh -c "wayland-scanner private-code `pkg-config --variable=datarootdir wayland-protocols`/wayland-protocols/staging/security-context/security-context-v1.xml security-context-v1-protocol.c" + +/* +#cgo linux pkg-config: --static wayland-client +#cgo freebsd openbsd LDFLAGS: -lwayland-client + +#include "wayland-bind.h" +*/ +import "C" +import "errors" + +var resErr = [...]error{ + 0: nil, + 1: errors.New("wl_display_connect_to_fd() failed"), + 2: errors.New("wp_security_context_v1 not available"), +} + +func bindWaylandFd(socketPath string, fd uintptr, appID, instanceID string, syncFD uintptr) error { + res := C.bind_wayland_fd(C.CString(socketPath), C.int(fd), C.CString(appID), C.CString(instanceID), C.int(syncFD)) + return resErr[int32(res)] +}