return nearest mon if point out of range

This commit is contained in:
vaxerski 2022-05-25 18:40:03 +02:00
parent 5635c6385f
commit 08d4d987cf
4 changed files with 37 additions and 18 deletions

View file

@ -246,29 +246,32 @@ SMonitor* CCompositor::getMonitorFromID(const int& id) {
SMonitor* CCompositor::getMonitorFromCursor() {
const auto COORDS = Vector2D(m_sWLRCursor->x, m_sWLRCursor->y);
const auto OUTPUT = wlr_output_layout_output_at(m_sWLROutputLayout, COORDS.x, COORDS.y);
if (!OUTPUT) {
Debug::log(WARN, "getMonitorFromCursor: cursor outside monitors??");
return &m_lMonitors.front();
}
for (auto& m : m_lMonitors) {
if (m.output == OUTPUT)
return &m;
}
Debug::log(LOG, "Monitor not in list??");
return &m_lMonitors.front();
return getMonitorFromVector(COORDS);
}
SMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
const auto OUTPUT = wlr_output_layout_output_at(m_sWLROutputLayout, point.x, point.y);
if (!OUTPUT) {
Debug::log(WARN, "getMonitorFromVector: vector outside monitors? Returning front");
return &m_lMonitors.front();
float bestDistance = 0.f;
SMonitor* pBestMon = nullptr;
for (auto& m : m_lMonitors) {
float dist = vecToRectDistanceSquared(point, m.vecPosition, m.vecPosition + m.vecSize);
if (dist < bestDistance || !pBestMon) {
bestDistance = dist;
pBestMon = &m;
}
}
if (!pBestMon) { // ?????
Debug::log(WARN, "getMonitorFromVector no close mon???");
return &m_lMonitors.front();
}
return pBestMon;
}
return getMonitorFromOutput(OUTPUT);

View file

@ -140,4 +140,10 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
}
return result;
}
float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2) {
const float DX = std::max((double)0, std::max(p1.x - vec.x, vec.x - p2.x));
const float DY = std::max((double)0, std::max(p1.y - vec.y, vec.y - p2.y));
return DX * DX + DY * DY;
}

View file

@ -10,5 +10,6 @@ std::string removeBeginEndSpacesTabs(std::string);
bool isNumber(const std::string&);
bool isDirection(const std::string&);
int getWorkspaceIDFromString(const std::string&, std::string&);
float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2);
float getPlusMinusKeywordResult(std::string in, float relative);

View file

@ -184,9 +184,14 @@ void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) {
SDwindleNodeData* OPENINGON;
const auto MONFROMCURSOR = g_pCompositor->getMonitorFromCursor();
if (PMONITOR->ID == MONFROMCURSOR->ID && PNODE->workspaceID == PMONITOR->activeWorkspace)
if (PMONITOR->ID == MONFROMCURSOR->ID && PNODE->workspaceID == PMONITOR->activeWorkspace) {
OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowTiled(g_pInputManager->getMouseCoordsInternal()));
else
// happens on reserved area
if (!OPENINGON && g_pCompositor->getWindowsOnWorkspace(PNODE->workspaceID) > 0)
OPENINGON = getFirstNodeOnWorkspace(PMONITOR->activeWorkspace);
} else
OPENINGON = getFirstNodeOnWorkspace(PMONITOR->activeWorkspace);
Debug::log(LOG, "OPENINGON: %x, Workspace: %i, Monitor: %i", OPENINGON, PNODE->workspaceID, PMONITOR->ID);
@ -373,6 +378,10 @@ void CHyprDwindleLayout::changeWindowFloatingMode(CWindow* pWindow) {
const auto PNODE = getNodeFromWindow(pWindow);
if (!PNODE) {
const auto PNEWMON = g_pCompositor->getMonitorFromVector(pWindow->m_vRealPosition.vec() + pWindow->m_vRealSize.vec() / 2.f);
pWindow->m_iMonitorID = PNEWMON->ID;
pWindow->m_iWorkspaceID = PNEWMON->activeWorkspace;
// save real pos cuz the func applies the default 5,5 mid
const auto PSAVEDPOS = pWindow->m_vRealPosition.vec();
const auto PSAVEDSIZE = pWindow->m_vRealSize.vec();