mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 08:25:59 +01:00
return nearest mon if point out of range
This commit is contained in:
parent
5635c6385f
commit
08d4d987cf
4 changed files with 37 additions and 18 deletions
|
@ -246,29 +246,32 @@ SMonitor* CCompositor::getMonitorFromID(const int& id) {
|
||||||
|
|
||||||
SMonitor* CCompositor::getMonitorFromCursor() {
|
SMonitor* CCompositor::getMonitorFromCursor() {
|
||||||
const auto COORDS = Vector2D(m_sWLRCursor->x, m_sWLRCursor->y);
|
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) {
|
return getMonitorFromVector(COORDS);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
|
SMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
|
||||||
const auto OUTPUT = wlr_output_layout_output_at(m_sWLROutputLayout, point.x, point.y);
|
const auto OUTPUT = wlr_output_layout_output_at(m_sWLROutputLayout, point.x, point.y);
|
||||||
|
|
||||||
if (!OUTPUT) {
|
if (!OUTPUT) {
|
||||||
Debug::log(WARN, "getMonitorFromVector: vector outside monitors? Returning front");
|
float bestDistance = 0.f;
|
||||||
return &m_lMonitors.front();
|
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);
|
return getMonitorFromOutput(OUTPUT);
|
||||||
|
|
|
@ -141,3 +141,9 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
|
||||||
|
|
||||||
return result;
|
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;
|
||||||
|
}
|
|
@ -10,5 +10,6 @@ std::string removeBeginEndSpacesTabs(std::string);
|
||||||
bool isNumber(const std::string&);
|
bool isNumber(const std::string&);
|
||||||
bool isDirection(const std::string&);
|
bool isDirection(const std::string&);
|
||||||
int getWorkspaceIDFromString(const std::string&, 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);
|
float getPlusMinusKeywordResult(std::string in, float relative);
|
|
@ -184,9 +184,14 @@ void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) {
|
||||||
SDwindleNodeData* OPENINGON;
|
SDwindleNodeData* OPENINGON;
|
||||||
const auto MONFROMCURSOR = g_pCompositor->getMonitorFromCursor();
|
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()));
|
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);
|
OPENINGON = getFirstNodeOnWorkspace(PMONITOR->activeWorkspace);
|
||||||
|
|
||||||
Debug::log(LOG, "OPENINGON: %x, Workspace: %i, Monitor: %i", OPENINGON, PNODE->workspaceID, PMONITOR->ID);
|
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);
|
const auto PNODE = getNodeFromWindow(pWindow);
|
||||||
|
|
||||||
if (!PNODE) {
|
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
|
// save real pos cuz the func applies the default 5,5 mid
|
||||||
const auto PSAVEDPOS = pWindow->m_vRealPosition.vec();
|
const auto PSAVEDPOS = pWindow->m_vRealPosition.vec();
|
||||||
const auto PSAVEDSIZE = pWindow->m_vRealSize.vec();
|
const auto PSAVEDSIZE = pWindow->m_vRealSize.vec();
|
||||||
|
|
Loading…
Reference in a new issue