aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-01-23 22:06:29 +0900
committerOphestra <cat@gensokyo.uk>2025-01-23 22:06:29 +0900
commit045983d7f419aff089e81f0e7c770dcf84f4a2eb (patch)
tree6d569e0a64c68be41c3a7d8fae07ebbb0367c4e9
parent7106b0096863e89e1a6809d8c2bed78adf6a3ba5 (diff)
wl: separate inline C
Having a huge blurb of inline C hurts readability on web pages and some text editors. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--wl/wayland-bind.c (renamed from wl/c.go)28
-rw-r--r--wl/wayland-bind.h3
-rw-r--r--wl/wl.go24
3 files changed, 29 insertions, 26 deletions
diff --git a/wl/c.go b/wl/wayland-bind.c
index b571e063..a177a378 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 <stdint.h>
+#include "wayland-bind.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -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 00000000..67898fc6
--- /dev/null
+++ b/wl/wayland-bind.h
@@ -0,0 +1,3 @@
+#include <stdint.h>
+
+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 00000000..2eb0e89f
--- /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)]
+}