mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-02 12:05:58 +01:00
refactor: utilize 'middle()' method for window/montior center (#3253)
This commit is contained in:
parent
3859607b6c
commit
e96e0dc02d
7 changed files with 20 additions and 23 deletions
|
@ -98,7 +98,7 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
|
|||
|
||||
g_pHyprRenderer->m_pMostHzMonitor = PNEWMONITOR;
|
||||
|
||||
const auto POS = PNEWMONITOR->vecPosition + PNEWMONITOR->vecSize / 2.f;
|
||||
const auto POS = PNEWMONITOR->middle();
|
||||
if (g_pCompositor->m_sSeat.mouse)
|
||||
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, POS.x, POS.y);
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ void Events::listener_newOutput(wl_listener* listener, void* data) {
|
|||
|
||||
if (firstLaunch) {
|
||||
firstLaunch = false;
|
||||
const auto POS = PNEWMONITOR->vecPosition + PNEWMONITOR->vecSize / 2.f;
|
||||
const auto POS = PNEWMONITOR->middle();
|
||||
if (g_pCompositor->m_sSeat.mouse)
|
||||
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, POS.x, POS.y);
|
||||
} else {
|
||||
|
|
|
@ -385,7 +385,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
|
|||
if (ARGS[1] == "1")
|
||||
RESERVEDOFFSET = (PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight) / 2.f;
|
||||
|
||||
PWINDOW->m_vRealPosition = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f - PWINDOW->m_vRealSize.goalv() / 2.f + RESERVEDOFFSET;
|
||||
PWINDOW->m_vRealPosition = PMONITOR->middle() - PWINDOW->m_vRealSize.goalv() / 2.f + RESERVEDOFFSET;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -893,8 +893,7 @@ void Events::listener_activateXDG(wl_listener* listener, void* data) {
|
|||
g_pCompositor->moveWindowToTop(PWINDOW);
|
||||
|
||||
g_pCompositor->focusWindow(PWINDOW);
|
||||
Vector2D middle = PWINDOW->m_vRealPosition.goalv() + PWINDOW->m_vRealSize.goalv() / 2.f;
|
||||
g_pCompositor->warpCursorTo(middle);
|
||||
g_pCompositor->warpCursorTo(PWINDOW->middle());
|
||||
}
|
||||
|
||||
void Events::listener_activateX11(void* owner, void* data) {
|
||||
|
@ -928,8 +927,7 @@ void Events::listener_activateX11(void* owner, void* data) {
|
|||
g_pCompositor->moveWindowToTop(PWINDOW);
|
||||
|
||||
g_pCompositor->focusWindow(PWINDOW);
|
||||
Vector2D middle = PWINDOW->m_vRealPosition.goalv() + PWINDOW->m_vRealSize.goalv() / 2.f;
|
||||
g_pCompositor->warpCursorTo(middle);
|
||||
g_pCompositor->warpCursorTo(PWINDOW->middle());
|
||||
}
|
||||
|
||||
void Events::listener_configureX11(void* owner, void* data) {
|
||||
|
|
|
@ -629,3 +629,7 @@ void CMonitor::moveTo(const Vector2D& pos) {
|
|||
if (!isMirror())
|
||||
wlr_output_layout_add(g_pCompositor->m_sWLROutputLayout, output, (int)vecPosition.x, (int)vecPosition.y);
|
||||
}
|
||||
|
||||
Vector2D CMonitor::middle() {
|
||||
return vecPosition + vecSize / 2.f;
|
||||
}
|
|
@ -107,6 +107,7 @@ class CMonitor {
|
|||
void setSpecialWorkspace(CWorkspace* const pWorkspace);
|
||||
void setSpecialWorkspace(const int& id);
|
||||
void moveTo(const Vector2D& pos);
|
||||
Vector2D middle();
|
||||
|
||||
std::shared_ptr<CMonitor>* m_pThisWrap = nullptr;
|
||||
bool m_bEnabled = false;
|
||||
|
|
|
@ -511,8 +511,7 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) {
|
|||
return m_pLastTiledWindow;
|
||||
|
||||
// if we don't, let's try to find any window that is in the middle
|
||||
if (const auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(pWindow->m_vRealPosition.goalv() + pWindow->m_vRealSize.goalv() / 2.f);
|
||||
PWINDOWCANDIDATE && PWINDOWCANDIDATE != pWindow)
|
||||
if (const auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(pWindow->middle()); PWINDOWCANDIDATE && PWINDOWCANDIDATE != pWindow)
|
||||
return PWINDOWCANDIDATE;
|
||||
|
||||
// if not, floating window
|
||||
|
@ -527,7 +526,7 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) {
|
|||
}
|
||||
|
||||
// if it was a tiled window, we first try to find the window that will replace it.
|
||||
const auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(pWindow->m_vRealPosition.goalv() + pWindow->m_vRealSize.goalv() / 2.f);
|
||||
const auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(pWindow->middle());
|
||||
|
||||
if (!PWINDOWCANDIDATE || pWindow == PWINDOWCANDIDATE || !PWINDOWCANDIDATE->m_bIsMapped || PWINDOWCANDIDATE->isHidden() || PWINDOWCANDIDATE->m_bX11ShouldntFocus ||
|
||||
PWINDOWCANDIDATE->m_iX11Type == 2 || PWINDOWCANDIDATE->m_iMonitorID != g_pCompositor->m_pLastMonitor->ID)
|
||||
|
|
|
@ -999,7 +999,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri
|
|||
return;
|
||||
|
||||
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
|
||||
g_pCompositor->warpCursorTo(PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f);
|
||||
g_pCompositor->warpCursorTo(PWINDOWTOCHANGETO->middle());
|
||||
};
|
||||
|
||||
CVarList vars(message, 0, ' ');
|
||||
|
|
|
@ -211,12 +211,10 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) {
|
|||
const auto PNEWWINDOW = PNEWWORKSPACE->getLastFocusedWindow();
|
||||
if (PNEWWINDOW) {
|
||||
g_pCompositor->focusWindow(PNEWWINDOW);
|
||||
Vector2D middle = PNEWWINDOW->m_vRealPosition.goalv() + PNEWWINDOW->m_vRealSize.goalv() / 2.f;
|
||||
g_pCompositor->warpCursorTo(middle);
|
||||
g_pCompositor->warpCursorTo(PNEWWINDOW->middle());
|
||||
} else {
|
||||
g_pCompositor->focusWindow(nullptr);
|
||||
Vector2D middle = monitor->vecPosition + monitor->vecSize / 2.f;
|
||||
g_pCompositor->warpCursorTo(middle);
|
||||
g_pCompositor->warpCursorTo(monitor->middle());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -241,8 +239,7 @@ void CKeybindManager::switchToWindow(CWindow* PWINDOWTOCHANGETO) {
|
|||
g_pCompositor->setWindowFullscreen(PWINDOWTOCHANGETO, true, FSMODE);
|
||||
} else {
|
||||
g_pCompositor->focusWindow(PWINDOWTOCHANGETO);
|
||||
Vector2D middle = PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f;
|
||||
g_pCompositor->warpCursorTo(middle);
|
||||
g_pCompositor->warpCursorTo(PWINDOWTOCHANGETO->middle());
|
||||
|
||||
g_pInputManager->m_pForcedFocus = PWINDOWTOCHANGETO;
|
||||
g_pInputManager->simulateMouseMovement();
|
||||
|
@ -780,7 +777,7 @@ void CKeybindManager::centerWindow(std::string args) {
|
|||
if (args == "1")
|
||||
RESERVEDOFFSET = (PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight) / 2.f;
|
||||
|
||||
PWINDOW->m_vRealPosition = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f - PWINDOW->m_vRealSize.goalv() / 2.f + RESERVEDOFFSET;
|
||||
PWINDOW->m_vRealPosition = PMONITOR->middle() - PWINDOW->m_vRealSize.goalv() / 2.f + RESERVEDOFFSET;
|
||||
PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goalv();
|
||||
}
|
||||
|
||||
|
@ -857,7 +854,7 @@ void CKeybindManager::changeworkspace(std::string args) {
|
|||
PMONITORWORKSPACEOWNER->changeWorkspace(pWorkspaceToChangeTo);
|
||||
|
||||
if (PMONITOR != PMONITORWORKSPACEOWNER) {
|
||||
g_pCompositor->warpCursorTo(PMONITORWORKSPACEOWNER->vecPosition + PMONITORWORKSPACEOWNER->vecSize / 2.f);
|
||||
g_pCompositor->warpCursorTo(PMONITORWORKSPACEOWNER->middle());
|
||||
g_pCompositor->setActiveMonitor(PMONITORWORKSPACEOWNER);
|
||||
if (const auto PLASTWINDOW = pWorkspaceToChangeTo->getLastFocusedWindow(); PLASTWINDOW)
|
||||
g_pCompositor->focusWindow(PLASTWINDOW);
|
||||
|
@ -898,7 +895,7 @@ void CKeybindManager::changeworkspace(std::string args) {
|
|||
PMONITORWORKSPACEOWNER->changeWorkspace(pWorkspaceToChangeTo);
|
||||
|
||||
if (PMONITOR != PMONITORWORKSPACEOWNER) {
|
||||
g_pCompositor->warpCursorTo(PMONITORWORKSPACEOWNER->vecPosition + PMONITORWORKSPACEOWNER->vecSize / 2.f);
|
||||
g_pCompositor->warpCursorTo(PMONITORWORKSPACEOWNER->middle());
|
||||
|
||||
if (const auto PLASTWINDOW = pWorkspaceToChangeTo->getLastFocusedWindow(); PLASTWINDOW)
|
||||
g_pCompositor->focusWindow(PLASTWINDOW);
|
||||
|
@ -1633,9 +1630,7 @@ void CKeybindManager::focusWindow(std::string regexp) {
|
|||
|
||||
g_pCompositor->focusWindow(PWINDOW);
|
||||
|
||||
const auto MIDPOINT = PWINDOW->m_vRealPosition.goalv() + PWINDOW->m_vRealSize.goalv() / 2.f;
|
||||
|
||||
g_pCompositor->warpCursorTo(MIDPOINT);
|
||||
g_pCompositor->warpCursorTo(PWINDOW->middle());
|
||||
}
|
||||
|
||||
void CKeybindManager::setSubmap(std::string submap) {
|
||||
|
|
Loading…
Reference in a new issue