@@ -98,6 +98,8 @@ namespace fs = std::filesystem;
9898class UnixSocketBridge final : public SlimeVRBridge {
9999private:
100100 static constexpr std::string_view TMP_DIR = " /tmp" ;
101+ static constexpr std::string_view XDG_DATA_DIR_DEFAULT = " .local/share" ;
102+ static constexpr std::string_view SLIMEVR_DATA_DIR = " slimevr" ;
101103 static constexpr std::string_view SOCKET_NAME = " SlimeVRInput" ;
102104 inline static constexpr int HEADER_SIZE = 4 ;
103105 inline static constexpr int BUFFER_SIZE = 1024 ;
@@ -140,12 +142,28 @@ class UnixSocketBridge final : public SlimeVRBridge {
140142
141143 void connect () final {
142144 if (!client.IsOpen ()) {
145+ fs::path socket;
143146 // TODO: do this once in the constructor or something
144- if (const char * ptr = std::getenv (" XDG_RUNTIME_DIR" )) {
147+ if (const char * ptr = std::getenv (" XDG_RUNTIME_DIR" )) {
145148 const fs::path xdg_runtime = ptr;
146- client.Open ((xdg_runtime / SOCKET_NAME).native ());
147- } else {
148- client.Open ((fs::path (TMP_DIR) / SOCKET_NAME).native ());
149+ socket = (xdg_runtime / SOCKET_NAME);
150+ }
151+ if (!fs::exists (socket)) {
152+ socket = (fs::path (TMP_DIR) / SOCKET_NAME);
153+ }
154+ // try using home dir if the vrserver is run in a chroot like
155+ if (!fs::exists (socket)) {
156+ if (const char * ptr = std::getenv (" XDG_DATA_DIR" )) {
157+ const fs::path data_dir = ptr;
158+ socket = (data_dir / SLIMEVR_DATA_DIR / SOCKET_NAME);
159+ } else if (const char * ptr = std::getenv (" HOME" )) {
160+ const fs::path home = ptr;
161+ socket = (home / XDG_DATA_DIR_DEFAULT / SLIMEVR_DATA_DIR / SOCKET_NAME);
162+ }
163+ }
164+ if (fs::exists (socket)) {
165+ fmt::print (" bridge socket: {}" , std::string (socket));
166+ client.Open (socket.native ());
149167 }
150168 }
151169 }
0 commit comments