From f70097e670adddb5a02fb0994804532d6b483b72 Mon Sep 17 00:00:00 2001 From: LionHeartP Date: Tue, 28 Apr 2026 19:09:47 +0300 Subject: [PATCH] fix: update window close and exit dispatchers for Hyprland 0.55+ (lua) (#24) * fix: update window close and exit dispatchers for Hyprland 0.55+ IPC (lua) * detect hyprlang or lua and run the appropriate commands * remove unneeded {} --- src/state/AppState.cpp | 20 +++++++++++++++++++- src/state/AppState.hpp | 4 +++- src/ui/UI.cpp | 3 ++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/state/AppState.cpp b/src/state/AppState.cpp index 3dbe202..704b8fc 100644 --- a/src/state/AppState.cpp +++ b/src/state/AppState.cpp @@ -49,7 +49,12 @@ void CApp::quit() { return; } g_logger->log(LOG_TRACE, "CApp::quit: using close for {}", m_class); - auto ret = HyprlandIPC::getFromSocket(std::format("/dispatch closewindow address:{}", m_address)); + std::string cmd; + if (State::state()->m_useLua) + cmd = std::format("/dispatch hl.dsp.window.close({{ window = 'address:{}' }})", m_address); + else + cmd = std::format("/dispatch closewindow address:{}", m_address); + auto ret = HyprlandIPC::getFromSocket(cmd); if (!ret) g_logger->log(LOG_ERR, "Failed closing window {}: ipc err", m_class); else if (*ret != "ok") @@ -99,6 +104,19 @@ bool CApp::operator==(const glz::generic& object) const { bool CAppState::init() { + // detect config provider + { + const auto RET = HyprlandIPC::getFromSocket("j/status"); + if (RET) { + auto jsonRaw = glz::read_json(*RET); + if (jsonRaw && jsonRaw->get_object().contains("configProvider")) { + std::string provider = jsonRaw->get_object()["configProvider"].get_string(); + m_useLua = (provider == "lua"); + g_logger->log(LOG_DEBUG, "Detected config provider: {}", m_useLua ? "lua" : "hyprlang"); + } + } + } + // windows { const auto RET = HyprlandIPC::getFromSocket("j/clients"); diff --git a/src/state/AppState.hpp b/src/state/AppState.hpp index b3ba86b..96abeea 100644 --- a/src/state/AppState.hpp +++ b/src/state/AppState.hpp @@ -36,6 +36,8 @@ namespace State { public: CAppState() = default; ~CAppState() = default; + + bool m_useLua = false; CAppState(const CAppState&) = delete; CAppState(CAppState&) = delete; @@ -59,4 +61,4 @@ namespace State { }; SP state(); -}; \ No newline at end of file +}; diff --git a/src/ui/UI.cpp b/src/ui/UI.cpp index 73b7576..1f29801 100644 --- a/src/ui/UI.cpp +++ b/src/ui/UI.cpp @@ -216,7 +216,8 @@ void CUI::exit(bool closeHl) { if (closeHl && !m_noExit && !State::state()->m_dryRun) { //NOLINTNEXTLINE - HyprlandIPC::getFromSocket("/dispatch exit"); + std::string cmd = State::state()->m_useLua ? "/dispatch hl.dsp.exit()" : "/dispatch exit"; + HyprlandIPC::getFromSocket(cmd); if (m_postExitCmd) { CProcess proc("/bin/sh", {"-c", m_postExitCmd.value()}); proc.runAsync();