summaryrefslogtreecommitdiff
path: root/src/Compositor.cpp
diff options
context:
space:
mode:
authorMightyPlaza <123664421+MightyPlaza@users.noreply.github.com>2024-02-04 15:40:20 +0000
committerGitHub <noreply@github.com>2024-02-04 15:40:20 +0000
commitcbadf3e3f31ab5ad5d192daac5f2ca930d08b8fb (patch)
tree40fe310e5ffb955a19b32a2c8d234b3bdf9e45cb /src/Compositor.cpp
parent1ed4f1cb254ce4b4e55727d972998be1ef4baf22 (diff)
input: focus window on mouse down on decoration (#4514)
Also unifies vectorToWindow funcs
Diffstat (limited to 'src/Compositor.cpp')
-rw-r--r--src/Compositor.cpp147
1 files changed, 38 insertions, 109 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index db2e5f4a..cefd9652 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -685,27 +685,7 @@ bool CCompositor::windowExists(CWindow* pWindow) {
return false;
}
-CWindow* CCompositor::vectorToWindowTiled(const Vector2D& pos) {
- const auto PMONITOR = getMonitorFromVector(pos);
-
- if (PMONITOR->specialWorkspaceID) {
- for (auto& w : m_vWindows) {
- CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
- if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && box.containsPoint(pos) && !w->m_bIsFloating && !w->isHidden() && !w->m_bNoFocus)
- return w.get();
- }
- }
-
- for (auto& w : m_vWindows) {
- CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
- if (w->m_bIsMapped && box.containsPoint(pos) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bIsFloating && !w->isHidden() && !w->m_bNoFocus)
- return w.get();
- }
-
- return nullptr;
-}
-
-CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos, CWindow* pIgnoreWindow) {
+CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t properties, CWindow* pIgnoreWindow) {
const auto PMONITOR = getMonitorFromVector(pos);
static auto* const PRESIZEONBORDER = &g_pConfigManager->getConfigValuePtr("general:resize_on_border")->intValue;
static auto* const PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue;
@@ -714,52 +694,59 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos, CWindow* pIgnoreW
const auto BORDER_GRAB_AREA = *PRESIZEONBORDER ? *PBORDERSIZE + *PBORDERGRABEXTEND : 0;
// pinned windows on top of floating regardless
- for (auto& w : m_vWindows | std::views::reverse) {
- const auto BB = w->getWindowInputBox();
- CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA};
- if (w->m_bIsFloating && w->m_bIsMapped && !w->isHidden() && !w->m_bX11ShouldntFocus && w->m_bPinned && !w->m_bNoFocus && w.get() != pIgnoreWindow) {
- if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}))
- return w.get();
-
- if (!w->m_bIsX11) {
- if (w->hasPopupAt(pos))
+ if (properties & ALLOW_FLOATING) {
+ for (auto& w : m_vWindows | std::views::reverse) {
+ const auto BB = w->getWindowBoxUnified(properties);
+ CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA};
+ if (w->m_bIsFloating && w->m_bIsMapped && !w->isHidden() && !w->m_bX11ShouldntFocus && w->m_bPinned && !w->m_bNoFocus && w.get() != pIgnoreWindow) {
+ if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}))
return w.get();
+
+ if (!w->m_bIsX11) {
+ if (w->hasPopupAt(pos))
+ return w.get();
+ }
}
}
}
auto windowForWorkspace = [&](bool special) -> CWindow* {
- // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter.
- for (auto& w : m_vWindows | std::views::reverse) {
-
- if (special && !isWorkspaceSpecial(w->m_iWorkspaceID)) // because special floating may creep up into regular
- continue;
+ if (properties & ALLOW_FLOATING) {
+ // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter.
+ for (auto& w : m_vWindows | std::views::reverse) {
- const auto BB = w->getWindowInputBox();
- CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA};
- if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && !w->m_bNoFocus && w.get() != pIgnoreWindow) {
- // OR windows should add focus to parent
- if (w->m_bX11ShouldntFocus && w->m_iX11Type != 2)
+ if (special && !isWorkspaceSpecial(w->m_iWorkspaceID)) // because special floating may creep up into regular
continue;
- if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y})) {
+ const auto BB = w->getWindowBoxUnified(properties);
+ CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA};
+ if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && !w->m_bNoFocus && w.get() != pIgnoreWindow) {
+ // OR windows should add focus to parent
+ if (w->m_bX11ShouldntFocus && w->m_iX11Type != 2)
+ continue;
- if (w->m_bIsX11 && w->m_iX11Type == 2 && !wlr_xwayland_or_surface_wants_focus(w->m_uSurface.xwayland)) {
- // Override Redirect
- return g_pCompositor->m_pLastWindow; // we kinda trick everything here.
- // TODO: this is wrong, we should focus the parent, but idk how to get it considering it's nullptr in most cases.
- }
+ if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y})) {
- return w.get();
- }
+ if (w->m_bIsX11 && w->m_iX11Type == 2 && !wlr_xwayland_or_surface_wants_focus(w->m_uSurface.xwayland)) {
+ // Override Redirect
+ return g_pCompositor->m_pLastWindow; // we kinda trick everything here.
+ // TODO: this is wrong, we should focus the parent, but idk how to get it considering it's nullptr in most cases.
+ }
- if (!w->m_bIsX11) {
- if (w->hasPopupAt(pos))
return w.get();
+ }
+
+ if (!w->m_bIsX11) {
+ if (w->hasPopupAt(pos))
+ return w.get();
+ }
}
}
}
+ if (properties & FLOATING_ONLY)
+ return nullptr;
+
const int64_t WORKSPACEID = special ? PMONITOR->specialWorkspaceID : PMONITOR->activeWorkspace;
const auto PWORKSPACE = getWorkspaceByID(WORKSPACEID);
@@ -782,7 +769,7 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos, CWindow* pIgnoreW
if (special != isWorkspaceSpecial(w->m_iWorkspaceID))
continue;
- CBox box = {w->m_vPosition, w->m_vSize};
+ CBox box = (properties & USE_PROP_TILED) ? w->getWindowBoxUnified(properties) : CBox{w->m_vPosition, w->m_vSize};
if (!w->m_bIsFloating && w->m_bIsMapped && box.containsPoint(pos) && w->m_iWorkspaceID == WORKSPACEID && !w->isHidden() && !w->m_bX11ShouldntFocus && !w->m_bNoFocus &&
w.get() != pIgnoreWindow)
return w.get();
@@ -805,64 +792,6 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos, CWindow* pIgnoreW
return windowForWorkspace(false);
}
-CWindow* CCompositor::windowFromCursor() {
- const auto PMONITOR = getMonitorFromCursor();
-
- if (PMONITOR->specialWorkspaceID) {
- for (auto& w : m_vWindows | std::views::reverse) {
- CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
- if (w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) &&
- !w->isHidden() && !w->m_bNoFocus)
- return w.get();
- }
-
- for (auto& w : m_vWindows) {
- CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
- if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && !w->m_bNoFocus)
- return w.get();
- }
- }
-
- // pinned
- for (auto& w : m_vWindows | std::views::reverse) {
- CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
- if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && w->m_bPinned && !w->m_bNoFocus)
- return w.get();
- }
-
- // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter.
- for (auto& w : m_vWindows | std::views::reverse) {
- CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
- if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bPinned && !w->m_bNoFocus)
- return w.get();
- }
-
- for (auto& w : m_vWindows) {
- CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y};
- if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bNoFocus)
- return w.get();
- }
-
- return nullptr;
-}
-
-CWindow* CCompositor::windowFloatingFromCursor() {
- for (auto& w : m_vWindows | std::views::reverse) {
- CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
- if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && !w->isHidden() && w->m_bPinned && !w->m_bNoFocus)
- return w.get();
- }
-
- for (auto& w : m_vWindows | std::views::reverse) {
- CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y};
- if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() &&
- !w->m_bPinned && !w->m_bNoFocus)
- return w.get();
- }
-
- return nullptr;
-}
-
wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pWindow, Vector2D& sl) {
if (!windowValidMapped(pWindow))