From a55a2a052d4c4b3368b5d9bc2529215b6a060bff Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Sat, 27 Jan 2024 11:50:32 +0100
Subject: [PATCH] Add Compose for the text editor

---
 Dockerfile         |  6 ++++++
 docker-compose.yml | 17 +++++++++++++++++
 run-texteditor.sh  | 27 +++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
 create mode 100644 docker-compose.yml
 create mode 100755 run-texteditor.sh

diff --git a/Dockerfile b/Dockerfile
index 6dd75e1..f72099e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,8 +10,14 @@ RUN go get -d -v ./...
 RUN go install -v ./go-wayland-simple-shm
 RUN go install -v ./go-wayland-smoke
 RUN go install -v ./go-wayland-imageviewer
+RUN go install -v ./go-wayland-texteditor
+RUN go install -v ./go-wayland-texteditor/editor_backend
 RUN go install -tags wayland -v ./go-wayland-cube
 
+RUN echo "#!/bin/sh" > /go/bin/texteditor
+RUN echo "cd /go/src/app/go-wayland-texteditor" >> /go/bin/texteditor
+RUN echo "/go/bin/editor_backend & /go/bin/go-wayland-texteditor" >> /go/bin/texteditor
+RUN chmod +x /go/bin/texteditor
 
 RUN apt-get --assume-yes install unzip build-essential autoconf libtool libxext-dev libx11-dev x11proto-gl-dev
 RUN wget https://github.com/NVIDIA/libglvnd/archive/refs/tags/v1.3.4.zip
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..6dbd8ce
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,17 @@
+version: '3'
+
+services:
+  texteditor:
+    build:
+      context: .
+      dockerfile: Dockerfile
+    environment:
+      - XDG_RUNTIME_DIR=/tmp
+      - WAYLAND_DISPLAY
+    volumes:
+      - ${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}:/tmp/${WAYLAND_DISPLAY}
+    user: "${UID}:${GID}"
+    command: ["/go/bin/texteditor"]
+    entrypoint:
+      - /go/bin/texteditor
+
diff --git a/run-texteditor.sh b/run-texteditor.sh
new file mode 100755
index 0000000..d4fd015
--- /dev/null
+++ b/run-texteditor.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+if [ ! -v XDG_RUNTIME_DIR ]
+then
+	echo "XDG_RUNTIME_DIR not set!"
+	exit -1
+fi
+
+wld="$WAYLAND_DISPLAY"
+
+if [ ! -f $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY  ]
+then
+	for i in {9..0}
+	do
+		if [ -f "$XDG_RUNTIME_DIR/wayland-$i" ]
+		then
+			wld="wayland-$i"
+			break
+		fi
+	done
+fi
+
+docker run -e=XDG_RUNTIME_DIR=/tmp \
+           -e=WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
+           -v=$XDG_RUNTIME_DIR/$wld:/tmp/$wld  \
+           --user=$(id -u):$(id -g) \
+          go-wayland-demos /go/bin/texteditor