dock autodetect monitor based on position

This commit is contained in:
vaxerski 2022-03-08 23:04:40 +01:00
parent 8d499c62ab
commit 6c02b3947a
3 changed files with 20 additions and 0 deletions

View file

@ -307,6 +307,16 @@ CWindow* Events::remapFloatingWindow(int windowID, int forcemonitor) {
+ ", " + std::to_string(PWINDOWINARR->getDefaultSize().x) + ", " + std::to_string(PWINDOWINARR->getDefaultSize().y));
PWINDOWINARR->setDock(true);
// since it's a dock get its monitor from the coords
const auto CENTERVEC = PWINDOWINARR->getDefaultPosition() + (PWINDOWINARR->getDefaultSize() / 2.f);
const auto MONITOR = g_pWindowManager->getMonitorFromCoord(CENTERVEC);
if (MONITOR) {
PWINDOWINARR->setMonitor(MONITOR->ID);
Debug::log(LOG, "Guessed dock's monitor to be " + std::to_string(MONITOR->ID) + ".");
} else {
Debug::log(LOG, "Couldn't guess dock's monitor. Leaving at " + std::to_string(PWINDOWINARR->getMonitor()) + ".");
}
}
}
}

View file

@ -2390,4 +2390,13 @@ bool CWindowManager::shouldBeManaged(const int& window) {
int CWindowManager::getBarHeightForMonitor(const int& mon) {
return (mon == ConfigManager::getInt("bar:monitor") ? (ConfigManager::getInt("bar:enabled") == 1 ? ConfigManager::getInt("bar:height") : ConfigManager::parseError == "" ? 0 : ConfigManager::getInt("bar:height")) : 0);
}
SMonitor* CWindowManager::getMonitorFromCoord(const Vector2D coord) {
for (auto& m : monitors) {
if (VECINRECT(coord, m.vecPosition.x, m.vecPosition.y, m.vecPosition.x + m.vecSize.x, m.vecPosition.y + m.vecSize.y))
return &m;
}
return nullptr;
}

View file

@ -107,6 +107,7 @@ public:
SMonitor* getMonitorFromWindow(CWindow*);
SMonitor* getMonitorFromCursor();
SMonitor* getMonitorFromCoord(const Vector2D);
Vector2D getCursorPos();