mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-10 07:45:59 +01:00
commit
b49d7007b5
5 changed files with 34 additions and 96 deletions
|
@ -245,7 +245,6 @@ void CCompositor::cleanup() {
|
||||||
|
|
||||||
// end threads
|
// end threads
|
||||||
g_pEventManager->m_tThread = std::thread();
|
g_pEventManager->m_tThread = std::thread();
|
||||||
HyprCtl::tThread = std::thread();
|
|
||||||
|
|
||||||
m_vWorkspaces.clear();
|
m_vWorkspaces.clear();
|
||||||
m_vWindows.clear();
|
m_vWindows.clear();
|
||||||
|
@ -1719,25 +1718,6 @@ CWindow* CCompositor::getWindowByRegex(const std::string& regexp) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_event_source* hyprCtlTickSource = nullptr;
|
|
||||||
|
|
||||||
int hyprCtlTick(void* data) {
|
|
||||||
HyprCtl::tickHyprCtl(); // so that we dont get that race condition multithread bullshit
|
|
||||||
|
|
||||||
wl_event_source_timer_update(hyprCtlTickSource, 16); // tick it 60/s, should be enough.
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCompositor::startHyprCtlTick() {
|
|
||||||
if (hyprCtlTickSource)
|
|
||||||
return;
|
|
||||||
|
|
||||||
hyprCtlTickSource = wl_event_loop_add_timer(m_sWLEventLoop, hyprCtlTick, nullptr);
|
|
||||||
|
|
||||||
wl_event_source_timer_update(hyprCtlTickSource, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCompositor::warpCursorTo(const Vector2D& pos) {
|
void CCompositor::warpCursorTo(const Vector2D& pos) {
|
||||||
|
|
||||||
// warpCursorTo should only be used for warps that
|
// warpCursorTo should only be used for warps that
|
||||||
|
|
|
@ -166,11 +166,8 @@ public:
|
||||||
void forceReportSizesToWindowsOnWorkspace(const int&);
|
void forceReportSizesToWindowsOnWorkspace(const int&);
|
||||||
bool cursorOnReservedArea();
|
bool cursorOnReservedArea();
|
||||||
|
|
||||||
|
|
||||||
std::string explicitConfigPath;
|
std::string explicitConfigPath;
|
||||||
|
|
||||||
void startHyprCtlTick();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initAllSignals();
|
void initAllSignals();
|
||||||
void setRandomSplash();
|
void setRandomSplash();
|
||||||
|
|
|
@ -721,9 +721,21 @@ std::string getReply(std::string request) {
|
||||||
return "unknown request";
|
return "unknown request";
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprCtl::tickHyprCtl() {
|
int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
|
||||||
if (!requestMade)
|
if (mask & WL_EVENT_ERROR || mask & WL_EVENT_HANGUP)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
|
sockaddr_in clientAddress;
|
||||||
|
socklen_t clientSize = sizeof(clientAddress);
|
||||||
|
|
||||||
|
const auto ACCEPTEDCONNECTION = accept(HyprCtl::iSocketFD, (sockaddr*)&clientAddress, &clientSize);
|
||||||
|
|
||||||
|
char readBuffer[1024];
|
||||||
|
|
||||||
|
auto messageSize = read(ACCEPTEDCONNECTION, readBuffer, 1024);
|
||||||
|
readBuffer[messageSize == 1024 ? 1023 : messageSize] = '\0';
|
||||||
|
|
||||||
|
std::string request(readBuffer);
|
||||||
|
|
||||||
std::string reply = "";
|
std::string reply = "";
|
||||||
|
|
||||||
|
@ -734,88 +746,38 @@ void HyprCtl::tickHyprCtl() {
|
||||||
reply = "Err: " + std::string(e.what());
|
reply = "Err: " + std::string(e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
request = reply;
|
write(ACCEPTEDCONNECTION, reply.c_str(), reply.length());
|
||||||
|
|
||||||
requestMade = false;
|
close(ACCEPTEDCONNECTION);
|
||||||
requestReady = true;
|
|
||||||
|
|
||||||
if (g_pConfigManager->m_bWantsMonitorReload) {
|
if (g_pConfigManager->m_bWantsMonitorReload) {
|
||||||
g_pConfigManager->ensureDPMS();
|
g_pConfigManager->ensureDPMS();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::string getRequestFromThread(std::string rq) {
|
return 0;
|
||||||
|
|
||||||
while (HyprCtl::request != "" || HyprCtl::requestMade || HyprCtl::requestReady) {
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
HyprCtl::request = rq;
|
|
||||||
HyprCtl::requestMade = true;
|
|
||||||
|
|
||||||
while (!HyprCtl::requestReady) {
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
HyprCtl::requestReady = false;
|
|
||||||
HyprCtl::requestMade = false;
|
|
||||||
|
|
||||||
std::string toReturn = HyprCtl::request;
|
|
||||||
|
|
||||||
HyprCtl::request = "";
|
|
||||||
|
|
||||||
return toReturn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HyprCtl::startHyprCtlSocket() {
|
void HyprCtl::startHyprCtlSocket() {
|
||||||
tThread = std::thread([&]() {
|
|
||||||
const auto SOCKET = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
|
|
||||||
if (SOCKET < 0) {
|
iSocketFD = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
Debug::log(ERR, "Couldn't start the Hyprland Socket. (1) IPC will not work.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX};
|
if (iSocketFD < 0) {
|
||||||
|
Debug::log(ERR, "Couldn't start the Hyprland Socket. (1) IPC will not work.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::string socketPath = "/tmp/hypr/" + g_pCompositor->m_szInstanceSignature + "/.socket.sock";
|
sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX};
|
||||||
|
|
||||||
strcpy(SERVERADDRESS.sun_path, socketPath.c_str());
|
std::string socketPath = "/tmp/hypr/" + g_pCompositor->m_szInstanceSignature + "/.socket.sock";
|
||||||
|
|
||||||
bind(SOCKET, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS));
|
strcpy(SERVERADDRESS.sun_path, socketPath.c_str());
|
||||||
|
|
||||||
// 10 max queued.
|
bind(iSocketFD, (sockaddr*)&SERVERADDRESS, SUN_LEN(&SERVERADDRESS));
|
||||||
listen(SOCKET, 10);
|
|
||||||
|
|
||||||
sockaddr_in clientAddress;
|
// 10 max queued.
|
||||||
socklen_t clientSize = sizeof(clientAddress);
|
listen(iSocketFD, 10);
|
||||||
|
|
||||||
char readBuffer[1024] = {0};
|
Debug::log(LOG, "Hypr socket started at %s", socketPath.c_str());
|
||||||
|
|
||||||
Debug::log(LOG, "Hypr socket started at %s", socketPath.c_str());
|
wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, iSocketFD, WL_EVENT_READABLE, hyprCtlFDTick, nullptr);
|
||||||
|
|
||||||
while(1) {
|
|
||||||
const auto ACCEPTEDCONNECTION = accept(SOCKET, (sockaddr*)&clientAddress, &clientSize);
|
|
||||||
|
|
||||||
if (ACCEPTEDCONNECTION < 0) {
|
|
||||||
Debug::log(ERR, "Couldn't listen on the Hyprland Socket. (3) IPC will not work.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto messageSize = read(ACCEPTEDCONNECTION, readBuffer, 1024);
|
|
||||||
readBuffer[messageSize == 1024 ? 1023 : messageSize] = '\0';
|
|
||||||
|
|
||||||
std::string request(readBuffer);
|
|
||||||
|
|
||||||
std::string reply = getRequestFromThread(request);
|
|
||||||
|
|
||||||
write(ACCEPTEDCONNECTION, reply.c_str(), reply.length());
|
|
||||||
|
|
||||||
close(ACCEPTEDCONNECTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
close(SOCKET);
|
|
||||||
});
|
|
||||||
|
|
||||||
tThread.detach();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
namespace HyprCtl {
|
namespace HyprCtl {
|
||||||
void startHyprCtlSocket();
|
void startHyprCtlSocket();
|
||||||
void tickHyprCtl();
|
|
||||||
|
|
||||||
// very simple thread-safe request method
|
// very simple thread-safe request method
|
||||||
inline bool requestMade = false;
|
inline bool requestMade = false;
|
||||||
|
@ -15,7 +14,9 @@ namespace HyprCtl {
|
||||||
|
|
||||||
inline std::ifstream requestStream;
|
inline std::ifstream requestStream;
|
||||||
|
|
||||||
inline std::thread tThread;
|
inline wl_event_source* hyprCtlTickSource = nullptr;
|
||||||
|
|
||||||
|
inline int iSocketFD = -1;
|
||||||
|
|
||||||
enum eHyprCtlOutputFormat {
|
enum eHyprCtlOutputFormat {
|
||||||
FORMAT_NORMAL = 0,
|
FORMAT_NORMAL = 0,
|
||||||
|
|
|
@ -22,8 +22,6 @@ CThreadManager::CThreadManager() {
|
||||||
|
|
||||||
HyprCtl::startHyprCtlSocket();
|
HyprCtl::startHyprCtlSocket();
|
||||||
|
|
||||||
g_pCompositor->startHyprCtlTick();
|
|
||||||
|
|
||||||
m_esConfigTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, handleTimer, this);
|
m_esConfigTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, handleTimer, this);
|
||||||
|
|
||||||
wl_event_source_timer_update(m_esConfigTimer, 1000);
|
wl_event_source_timer_update(m_esConfigTimer, 1000);
|
||||||
|
|
Loading…
Reference in a new issue