From 63e263caa002e82db521e7e7b0e9c871b5a5467a Mon Sep 17 00:00:00 2001 From: Uriel Date: Sun, 12 Feb 2023 11:17:24 -0300 Subject: [PATCH] use XDG_RUNTIME_DIR (#35) --- CMakeLists.txt | 2 ++ src/bridge/bridge-unix-sockets.cpp | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78407c2..0873831 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ cmake_minimum_required(VERSION 3.0.0) endif() #endif() +set (CMAKE_CXX_STANDARD 20) + # If the toolchain is already defined, do not attempt to find it if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) # If the VCPKG_ROOT environment variable is not defined, try to automatically define it from AppData/home diff --git a/src/bridge/bridge-unix-sockets.cpp b/src/bridge/bridge-unix-sockets.cpp index fcd55fc..e53e721 100644 --- a/src/bridge/bridge-unix-sockets.cpp +++ b/src/bridge/bridge-unix-sockets.cpp @@ -29,9 +29,13 @@ #include "unix-sockets.hpp" #include #include +#include +#include -#define SOCKET_PATH "/tmp/SlimeVRDriver" +#define TMP_DIR "/tmp" +#define SOCKET_NAME "SlimeVRDriver" +namespace fs = std::filesystem; namespace { inline constexpr int HEADER_SIZE = 4; @@ -152,7 +156,13 @@ bool sendBridgeMessage(messages::ProtobufMessage& message, SlimeVRDriver::VRDriv BridgeStatus runBridgeFrame(SlimeVRDriver::VRDriver& driver) { try { if (!client.IsOpen()) { - client.Open(SOCKET_PATH); + // TODO: do this once in the constructor or something + if(const char* ptr = std::getenv("XDG_RUNTIME_DIR")) { + const fs::path xdg_runtime = ptr; + client.Open((xdg_runtime / SOCKET_NAME).native()); + } else { + client.Open((fs::path(TMP_DIR) / SOCKET_NAME).native()); + } } client.UpdateOnce();