Skip to content

Commit

Permalink
Use XDG_RUNTIME_DIR
Browse files Browse the repository at this point in the history
Modeled after SlimeVR/SlimeVR-OpenVR-Driver#35

Co-authored-by: Uriel <urielfontan2002@gmail.com>
  • Loading branch information
kitlith and ImUrX committed Feb 13, 2023
1 parent 95f784e commit 3095a88
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ class NamedPipeBridge final: public SlimeVRBridge {
#else
#include "unix_sockets.hpp"

#include <cstdlib>
#include <filesystem>

namespace fs = std::filesystem;

class UnixSocketBridge final : public SlimeVRBridge {
private:
static constexpr std::string_view SOCKET_NAME = "/tmp/SlimeVRInput";
static constexpr std::string_view TMP_DIR = "/tmp";
static constexpr std::string_view SOCKET_NAME = "SlimeVRInput";
inline static constexpr int HEADER_SIZE = 4;
inline static constexpr int BUFFER_SIZE = 1024;
using ByteBuffer = std::array<uint8_t, BUFFER_SIZE>;
Expand Down Expand Up @@ -134,7 +140,13 @@ class UnixSocketBridge final : public SlimeVRBridge {

void connect() final {
if (!client.IsOpen()) {
client.Open(SOCKET_NAME);
// 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());
}
}
}
void reset() final {
Expand Down

0 comments on commit 3095a88

Please sign in to comment.