diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 9abf67a3..a282b5d0 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -34,6 +34,7 @@ commands: splash hyprpaper reload + setcursor flags: -j -> output in JSON @@ -183,6 +184,17 @@ void hyprpaperRequest(int argc, char** argv) { requestHyprpaper(rq); } +void setcursorRequest(int argc, char** argv) { + if (argc < 4) { + std::cout << "setcursor requires 2 params"; + return; + } + + std::string rq = "setcursor " + std::string(argv[2]) + " " + std::string(argv[3]); + + request(rq); +} + void batchRequest(std::string arg) { std::string rq = "[[BATCH]]" + arg.substr(arg.find_first_of(" ") + 1); @@ -252,6 +264,7 @@ int main(int argc, char** argv) { else if (fullRequest.contains("/splash")) request(fullRequest); else if (fullRequest.contains("/devices")) request(fullRequest); else if (fullRequest.contains("/reload")) request(fullRequest); + else if (fullRequest.contains("/setcursor")) setcursorRequest(argc, argv); else if (fullRequest.contains("/dispatch")) dispatchRequest(argc, argv); else if (fullRequest.contains("/keyword")) keywordRequest(argc, argv); else if (fullRequest.contains("/hyprpaper")) hyprpaperRequest(argc, argv); diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index cd91955e..714a4f71 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -522,6 +522,56 @@ std::string dispatchBatch(std::string request) { return reply; } +std::string dispatchSetCursor(std::string request) { + std::string curitem = ""; + + auto nextItem = [&]() { + auto idx = request.find_first_of(' '); + + if (idx != std::string::npos) { + curitem = request.substr(0, idx); + request = request.substr(idx + 1); + } else { + curitem = request; + request = ""; + } + + curitem = removeBeginEndSpacesTabs(curitem); + }; + + nextItem(); + nextItem(); + + const auto THEME = curitem; + + nextItem(); + + const auto SIZE = curitem; + + if (!isNumber(SIZE)) { + return "size not int"; + } + + const auto SIZEINT = std::stoi(SIZE); + + if (SIZEINT < 1) { + return "size must be positive"; + } + + wlr_xcursor_manager_destroy(g_pCompositor->m_sWLRXCursorMgr); + + g_pCompositor->m_sWLRXCursorMgr = wlr_xcursor_manager_create(THEME.c_str(), SIZEINT); + + setenv("XCURSOR_SIZE", SIZE.c_str(), true); + setenv("XCURSOR_THEME", THEME.c_str(), true); + + for (auto& m : g_pCompositor->m_vMonitors) { + wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, m->scale); + } + + return "ok"; +} + std::string getReply(std::string request) { auto format = HyprCtl::FORMAT_NORMAL; @@ -567,6 +617,8 @@ std::string getReply(std::string request) { return dispatchRequest(request); else if (request.find("keyword") == 0) return dispatchKeyword(request); + else if (request.find("setcursor") == 0) + return dispatchSetCursor(request); else if (request.find("[[BATCH]]") == 0) return dispatchBatch(request); diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index b63a81ed..51ff65bb 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -158,6 +158,8 @@ void CMonitor::onConnect(bool noRule) { if (!g_pCompositor->m_pLastMonitor) // set the last monitor if it isnt set yet g_pCompositor->m_pLastMonitor = this; + wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, scale); + g_pEventManager->postEvent(SHyprIPCEvent{"monitoradded", szName}); }