From 99f97b07eb9606bbe6a2cbea21421243ccd99f16 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Thu, 30 Jun 2016 16:11:54 +0200 Subject: [PATCH] fix(bspwm): Look for socket path in env variable Fixes jaagr/lemonbuddy#29 --- README.md | 3 +++ src/modules/bspwm.cpp | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 37ffccd2..221e8e74 100644 --- a/README.md +++ b/README.md @@ -498,6 +498,9 @@ The configuration syntax is based on the `ini` file format. #### Module `internal/bspwm` + +To specify a custom path to the bspwm socket, you can set the environment variable `$BSPWM_SOCKET`. + ~~~ ini [module/bspwm] type = internal/bspwm diff --git a/src/modules/bspwm.cpp b/src/modules/bspwm.cpp index 8012325a..5845aba6 100644 --- a/src/modules/bspwm.cpp +++ b/src/modules/bspwm.cpp @@ -18,6 +18,15 @@ using namespace bspwm; #define DEFAULT_WS_ICON "workspace_icon-default" #define DEFAULT_WS_LABEL "%icon% %name%" +std::string get_socket_path() +{ + std::string socket_path = BSPWM_SOCKET_PATH; + const char *env_bs = std::getenv("BSPWM_SOCKET"); + if (env_bs != nullptr) + socket_path = std::string(env_bs); + return socket_path; +} + bspwm::payload_t generate_payload(std::string command) { bspwm::payload_t payload; @@ -41,11 +50,13 @@ bool send_payload(int fd, bspwm::payload_t payload) int create_subscriber() { - int socket_fd; - if ((socket_fd = io::socket::open(BSPWM_SOCKET_PATH)) == -1) - throw ModuleError("Could not connect to socket"); + int socket_fd = -1; + std::string socket_path = get_socket_path(); + + if ((socket_fd = io::socket::open(socket_path)) == -1) + throw ModuleError("bspwm: Could not connect to socket: "+ socket_path); if (!send_payload(socket_fd, generate_payload("subscribe report"))) - throw ModuleError("Failed to subscribe to bspwm changes"); + throw ModuleError("bspwm: Failed to subscribe to bspwm changes"); return socket_fd; } @@ -269,9 +280,10 @@ bool BspwmModule::handle_command(std::string cmd) << std::atoi(cmd.substr(std::strlen(EVENT_CLICK)).c_str()); int payload_fd; + std::string socket_path = get_socket_path(); - if ((payload_fd = io::socket::open(BSPWM_SOCKET_PATH)) == -1) - this->logger->error("bspwm: Failed to open socket"); + if ((payload_fd = io::socket::open(socket_path)) == -1) + this->logger->error("bspwm: Failed to open socket: "+ socket_path); else if (!send_payload(payload_fd, generate_payload(payload_s.str()))) this->logger->error("bspwm: Failed to change desktop");