workspace: detect hyprland lua config and change commands accordingly

detect if hyprland uses lua configuration. If so, the commands to switch
workspaces should be altered.

Signed-off-by: Jef Steelant <jef@steelant.be>
This commit is contained in:
Jef Steelant
2026-05-08 15:37:54 +02:00
parent 20b6b16ab2
commit c66e66d4b0
2 changed files with 20 additions and 1 deletions
@@ -107,9 +107,22 @@ bool HyprlandWorkspaceBackend::connectSocket() {
refreshSnapshot();
kLog.info("connected to hyprland IPC at {}", m_eventSocketPath);
updateConfigProvider();
return true;
}
void HyprlandWorkspaceBackend::updateConfigProvider() {
m_configLua = false;
const auto json = requestJson("j/status");
if (!json || !json->is_object()) {
return;
}
std::string configProvider = json->value("configProvider", "");
if (configProvider.compare("lua") == 0) {
m_configLua = true;
}
}
void HyprlandWorkspaceBackend::setChangeCallback(ChangeCallback callback) { m_changeCallback = std::move(callback); }
void HyprlandWorkspaceBackend::activate(const std::string& id) {
@@ -118,7 +131,11 @@ void HyprlandWorkspaceBackend::activate(const std::string& id) {
}
std::string response;
(void)sendRequest(std::format("dispatch workspace {}", id), response);
if (m_configLua) {
(void)sendRequest(std::format("dispatch hl.dsp.focus({{workspace = {}}})", id), response);
} else {
(void)sendRequest(std::format("dispatch workspace {}", id), response);
}
}
void HyprlandWorkspaceBackend::activateForOutput(wl_output* /*output*/, const std::string& id) { activate(id); }
@@ -56,6 +56,7 @@ private:
};
bool ensureSocketPaths();
void updateConfigProvider();
[[nodiscard]] bool sendRequest(const std::string& request, std::string& response) const;
[[nodiscard]] std::optional<nlohmann::json> requestJson(const std::string& request) const;
void refreshSnapshot();
@@ -85,6 +86,7 @@ private:
int m_eventSocketFd = -1;
std::string m_requestSocketPath;
std::string m_eventSocketPath;
bool m_configLua;
std::vector<char> m_readBuffer;
std::vector<WorkspaceState> m_workspaces;
std::unordered_map<std::uint64_t, ToplevelState> m_toplevels;