aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormemchr <[email protected]>2023-09-11 09:09:34 +0000
committerGitHub <[email protected]>2023-09-11 10:09:34 +0100
commite96e0dc02d9368580100bbabd8f098746a42af6b (patch)
tree72853f4b696bc5c90b26d9cfb713772c04b9b8a8
parent3859607b6cf26ead21f4a23ee11458b7b67fe542 (diff)
downloadHyprland-e96e0dc02d9368580100bbabd8f098746a42af6b.tar.gz
Hyprland-e96e0dc02d9368580100bbabd8f098746a42af6b.zip
refactor: utilize 'middle()' method for window/montior center (#3253)
-rw-r--r--src/events/Monitors.cpp4
-rw-r--r--src/events/Windows.cpp8
-rw-r--r--src/helpers/Monitor.cpp4
-rw-r--r--src/helpers/Monitor.hpp1
-rw-r--r--src/layout/IHyprLayout.cpp5
-rw-r--r--src/layout/MasterLayout.cpp2
-rw-r--r--src/managers/KeybindManager.cpp19
7 files changed, 20 insertions, 23 deletions
diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp
index 8e45364a..88ba612d 100644
--- a/src/events/Monitors.cpp
+++ b/src/events/Monitors.cpp
@@ -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 {
diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp
index 9089567a..2d428a8a 100644
--- a/src/events/Windows.cpp
+++ b/src/events/Windows.cpp
@@ -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) {
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index 553fe3e5..46f82ddc 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -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;
+} \ No newline at end of file
diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp
index 11dad9f6..2c4d4a89 100644
--- a/src/helpers/Monitor.hpp
+++ b/src/helpers/Monitor.hpp
@@ -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;
diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp
index a000adb8..b0c1d50c 100644
--- a/src/layout/IHyprLayout.cpp
+++ b/src/layout/IHyprLayout.cpp
@@ -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)
diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp
index d9116467..7c8a127f 100644
--- a/src/layout/MasterLayout.cpp
+++ b/src/layout/MasterLayout.cpp
@@ -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, ' ');
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 29e0c12d..60163150 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -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) {