summaryrefslogtreecommitdiff
path: root/src/managers
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-10-14 20:46:32 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-10-14 20:46:32 +0100
commit34cd8b125ad9f03ababd7789ebe12eac69e23227 (patch)
tree5595368acdc5d1612c276350bf430a79667fe6dc /src/managers
parentb0544dbfffb79e1aa043c7626fbcbc86b8ee9379 (diff)
rework focus system to be more safe and faster
Diffstat (limited to 'src/managers')
-rw-r--r--src/managers/AnimationManager.cpp2
-rw-r--r--src/managers/KeybindManager.cpp58
-rw-r--r--src/managers/input/InputManager.cpp19
-rw-r--r--src/managers/input/InputManager.hpp7
-rw-r--r--src/managers/input/Tablets.cpp2
-rw-r--r--src/managers/input/Touch.cpp37
6 files changed, 73 insertions, 52 deletions
diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp
index c5d7bb1d..b465a3b5 100644
--- a/src/managers/AnimationManager.cpp
+++ b/src/managers/AnimationManager.cpp
@@ -153,7 +153,7 @@ void CAnimationManager::tick() {
g_pHyprRenderer->damageWindow(PWINDOW);
} else if (PWORKSPACE) {
for (auto& w : g_pCompositor->m_vWindows) {
- if (!w->m_bIsMapped || w->m_bHidden)
+ if (!w->m_bIsMapped || w->isHidden())
continue;
if (w->m_iWorkspaceID != PWORKSPACE->m_iID)
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 1684222a..dabbe35d 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -568,23 +568,21 @@ void CKeybindManager::toggleActiveFloating(std::string args) {
if (!PWINDOW)
return;
- if (g_pCompositor->windowValidMapped(PWINDOW)) {
- // remove drag status
- g_pInputManager->currentlyDraggedWindow = nullptr;
+ // remove drag status
+ g_pInputManager->currentlyDraggedWindow = nullptr;
- if (PWINDOW->m_iWorkspaceID == SPECIAL_WORKSPACE_ID)
- return;
+ if (PWINDOW->m_iWorkspaceID == SPECIAL_WORKSPACE_ID)
+ return;
- PWINDOW->m_bIsFloating = !PWINDOW->m_bIsFloating;
+ PWINDOW->m_bIsFloating = !PWINDOW->m_bIsFloating;
- g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(PWINDOW);
- }
+ g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(PWINDOW);
}
void CKeybindManager::toggleActivePseudo(std::string args) {
const auto ACTIVEWINDOW = g_pCompositor->m_pLastWindow;
- if (!g_pCompositor->windowValidMapped(ACTIVEWINDOW))
+ if (!ACTIVEWINDOW)
return;
ACTIVEWINDOW->m_bIsPseudotiled = !ACTIVEWINDOW->m_bIsPseudotiled;
@@ -826,7 +824,7 @@ void CKeybindManager::changeworkspace(std::string args) {
void CKeybindManager::fullscreenActive(std::string args) {
const auto PWINDOW = g_pCompositor->m_pLastWindow;
- if (!g_pCompositor->windowValidMapped(PWINDOW))
+ if (!PWINDOW)
return;
if (PWINDOW->m_iWorkspaceID == SPECIAL_WORKSPACE_ID)
@@ -846,7 +844,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
PWINDOW = g_pCompositor->m_pLastWindow;
}
- if (!g_pCompositor->windowValidMapped(PWINDOW))
+ if (!PWINDOW)
return;
const auto OLDWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID);
@@ -934,7 +932,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
PWINDOW = g_pCompositor->m_pLastWindow;
}
- if (!g_pCompositor->windowValidMapped(PWINDOW))
+ if (!PWINDOW)
return;
int workspaceToMoveTo = 0;
@@ -1040,16 +1038,6 @@ void CKeybindManager::moveFocusTo(std::string args) {
}
};
- if (!g_pCompositor->windowValidMapped(PLASTWINDOW)) {
- const auto PWINDOWTOCHANGETO = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace);
- if (!PWINDOWTOCHANGETO)
- return;
-
- switchToWindow(PWINDOWTOCHANGETO);
-
- return;
- }
-
const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
if (PWINDOWTOCHANGETO) {
@@ -1094,12 +1082,12 @@ void CKeybindManager::moveActiveTo(std::string args) {
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
- if (!g_pCompositor->windowValidMapped(PLASTWINDOW) || PLASTWINDOW->m_bIsFullscreen)
+ if (!PLASTWINDOW || PLASTWINDOW->m_bIsFullscreen)
return;
const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
- if (!g_pCompositor->windowValidMapped(PWINDOWTOCHANGETO))
+ if (!PWINDOWTOCHANGETO)
return;
g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, PWINDOWTOCHANGETO);
@@ -1145,7 +1133,7 @@ void CKeybindManager::alterSplitRatio(std::string args) {
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
- if (!g_pCompositor->windowValidMapped(PLASTWINDOW))
+ if (!PLASTWINDOW)
return;
g_pLayoutManager->getCurrentLayout()->alterSplitRatioBy(PLASTWINDOW, splitratio);
@@ -1175,7 +1163,7 @@ void CKeybindManager::moveCursorToCorner(std::string arg) {
const auto PWINDOW = g_pCompositor->m_pLastWindow;
- if (!g_pCompositor->windowValidMapped(PWINDOW))
+ if (!PWINDOW)
return;
switch (CORNER) {
@@ -1377,7 +1365,7 @@ void CKeybindManager::forceRendererReload(std::string args) {
}
void CKeybindManager::resizeActive(std::string args) {
- if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow) || g_pCompositor->m_pLastWindow->m_bIsFullscreen)
+ if (!g_pCompositor->m_pLastWindow || g_pCompositor->m_pLastWindow->m_bIsFullscreen)
return;
const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealSize.goalv());
@@ -1385,11 +1373,11 @@ void CKeybindManager::resizeActive(std::string args) {
g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - g_pCompositor->m_pLastWindow->m_vRealSize.goalv());
if (g_pCompositor->m_pLastWindow->m_vRealSize.goalv().x > 1 && g_pCompositor->m_pLastWindow->m_vRealSize.goalv().y > 1)
- g_pCompositor->m_pLastWindow->m_bHidden = false;
+ g_pCompositor->m_pLastWindow->setHidden(false);
}
void CKeybindManager::moveActive(std::string args) {
- if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow) || g_pCompositor->m_pLastWindow->m_bIsFullscreen)
+ if (!g_pCompositor->m_pLastWindow || g_pCompositor->m_pLastWindow->m_bIsFullscreen)
return;
const auto POS = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealPosition.goalv());
@@ -1437,11 +1425,11 @@ void CKeybindManager::resizeWindow(std::string args) {
g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - PWINDOW->m_vRealSize.goalv(), PWINDOW);
if (PWINDOW->m_vRealSize.goalv().x > 1 && PWINDOW->m_vRealSize.goalv().y > 1)
- PWINDOW->m_bHidden = false;
+ PWINDOW->setHidden(false);
}
void CKeybindManager::circleNext(std::string arg) {
- if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow))
+ if (!g_pCompositor->m_pLastWindow)
return;
auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) {
@@ -1592,7 +1580,7 @@ void CKeybindManager::layoutmsg(std::string msg) {
void CKeybindManager::toggleOpaque(std::string unused) {
const auto PWINDOW = g_pCompositor->m_pLastWindow;
- if (!g_pCompositor->windowValidMapped(PWINDOW))
+ if (!PWINDOW)
return;
PWINDOW->m_sAdditionalConfigData.forceOpaque = !PWINDOW->m_sAdditionalConfigData.forceOpaque;
@@ -1632,7 +1620,7 @@ void CKeybindManager::swapnext(std::string arg) {
CWindow* toSwap = nullptr;
- if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow))
+ if (!g_pCompositor->m_pLastWindow)
return;
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
@@ -1673,7 +1661,7 @@ void CKeybindManager::swapActiveWorkspaces(std::string args) {
}
void CKeybindManager::pinActive(std::string args) {
- if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow) || !g_pCompositor->m_pLastWindow->m_bIsFloating || g_pCompositor->m_pLastWindow->m_bIsFullscreen)
+ if (!g_pCompositor->m_pLastWindow || !g_pCompositor->m_pLastWindow->m_bIsFloating || g_pCompositor->m_pLastWindow->m_bIsFullscreen)
return;
g_pCompositor->m_pLastWindow->m_bPinned = !g_pCompositor->m_pLastWindow->m_bPinned;
@@ -1726,6 +1714,6 @@ void CKeybindManager::mouse(std::string args) {
}
void CKeybindManager::bringActiveToTop(std::string args) {
- if (g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow) && g_pCompositor->m_pLastWindow->m_bIsFloating)
+ if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsFloating)
g_pCompositor->moveWindowToTop(g_pCompositor->m_pLastWindow);
}
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index 5ef257e3..c04c1f3e 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -35,6 +35,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
static auto *const PHOGFOCUS = &g_pConfigManager->getConfigValuePtr("misc:layers_hog_keyboard_focus")->intValue;
static auto *const PFLOATBEHAVIOR = &g_pConfigManager->getConfigValuePtr("input:float_switch_override_focus")->intValue;
+ m_pFoundSurfaceToFocus = nullptr;
+ m_pFoundLSToFocus = nullptr;
+ m_pFoundWindowToFocus = nullptr;
+
if (!g_pCompositor->m_bReadyToProcess)
return;
@@ -159,7 +163,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
// only check floating because tiled cant be over fullscreen
for (auto w = g_pCompositor->m_vWindows.rbegin(); w != g_pCompositor->m_vWindows.rend(); w++) {
wlr_box 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_bIsMapped && ((*w)->m_bCreatedOverFullscreen || (*w)->m_bPinned)) || ((*w)->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && PMONITOR->specialWorkspaceOpen)) && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y) && g_pCompositor->isWorkspaceVisible((*w)->m_iWorkspaceID) && !(*w)->m_bHidden) {
+ if ((((*w)->m_bIsFloating && (*w)->m_bIsMapped && ((*w)->m_bCreatedOverFullscreen || (*w)->m_bPinned)) || ((*w)->m_iWorkspaceID == SPECIAL_WORKSPACE_ID && PMONITOR->specialWorkspaceOpen)) && wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y) && g_pCompositor->isWorkspaceVisible((*w)->m_iWorkspaceID) && !(*w)->isHidden()) {
pFoundWindow = (*w).get();
if (!pFoundWindow->m_bIsX11) {
@@ -264,9 +268,16 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
}
}
+ // set the values for use
+ if (refocus) {
+ m_pFoundLSToFocus = pFoundLayerSurface;
+ m_pFoundWindowToFocus = pFoundWindow;
+ m_pFoundSurfaceToFocus = foundSurface;
+ }
+
if (pFoundWindow) {
if (*PFOLLOWMOUSE != 1 && !refocus) {
- if (pFoundWindow != g_pCompositor->m_pLastWindow && g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow) && g_pCompositor->m_pLastWindow->m_bIsFloating != pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR) {
+ if (pFoundWindow != g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsFloating != pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR) {
// enter if change floating style
if (*PFOLLOWMOUSE != 3 && allowKeyboardRefocus)
g_pCompositor->focusWindow(pFoundWindow, foundSurface);
@@ -396,7 +407,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) {
refocus();
// if clicked on a floating window make it top
- if (g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow) && g_pCompositor->m_pLastWindow->m_bIsFloating)
+ if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsFloating)
g_pCompositor->moveWindowToTop(g_pCompositor->m_pLastWindow);
break;
@@ -415,7 +426,7 @@ void CInputManager::processMouseDownKill(wlr_pointer_button_event* e) {
case WLR_BUTTON_PRESSED: {
const auto PWINDOW = g_pCompositor->m_pLastWindow;
- if (!g_pCompositor->windowValidMapped(PWINDOW)){
+ if (!PWINDOW) {
Debug::log(ERR, "Cannot kill invalid window!");
break;
}
diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp
index 8e94a5d6..81f84c9b 100644
--- a/src/managers/input/InputManager.hpp
+++ b/src/managers/input/InputManager.hpp
@@ -20,6 +20,8 @@ enum eMouseBindMode {
struct STouchData {
CWindow* touchFocusWindow = nullptr;
+ SLayerSurface* touchFocusLS = nullptr;
+ wlr_surface* touchFocusSurface = nullptr;
Vector2D touchSurfaceOrigin;
};
@@ -140,6 +142,11 @@ private:
STabletTool* ensureTabletToolPresent(wlr_tablet_tool*);
void applyConfigToKeyboard(SKeyboard*);
+
+ // this will be set after a refocus()
+ wlr_surface* m_pFoundSurfaceToFocus = nullptr;
+ SLayerSurface* m_pFoundLSToFocus = nullptr;
+ CWindow* m_pFoundWindowToFocus = nullptr;
};
inline std::unique_ptr<CInputManager> g_pInputManager;
diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp
index 173f6961..5253152e 100644
--- a/src/managers/input/Tablets.cpp
+++ b/src/managers/input/Tablets.cpp
@@ -219,7 +219,7 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) {
void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool motion) {
const auto PTOOL = g_pInputManager->ensureTabletToolPresent(pTool);
- if (const auto PWINDOW = g_pCompositor->m_pLastWindow; g_pCompositor->windowValidMapped(PWINDOW)) {
+ if (const auto PWINDOW = g_pCompositor->m_pLastWindow; PWINDOW) {
const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal();
const auto LOCAL = CURSORPOS - PWINDOW->m_vRealPosition.goalv();
diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp
index e140d8a1..b5a52c05 100644
--- a/src/managers/input/Touch.cpp
+++ b/src/managers/input/Touch.cpp
@@ -15,32 +15,39 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) {
refocus();
- m_sTouchData.touchFocusWindow = nullptr;
+ m_sTouchData.touchFocusWindow = m_pFoundWindowToFocus;
+ m_sTouchData.touchFocusSurface = m_pFoundSurfaceToFocus;
+ m_sTouchData.touchFocusLS = m_pFoundLSToFocus;
- if (g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) {
- Vector2D local;
- if (g_pCompositor->m_pLastWindow->m_bIsX11) {
- local = g_pInputManager->getMouseCoordsInternal() - g_pCompositor->m_pLastWindow->m_vRealPosition.goalv();
+ Vector2D local;
+
+ if (m_sTouchData.touchFocusWindow) {
+ if (m_sTouchData.touchFocusWindow->m_bIsX11) {
+ local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusWindow->m_vRealPosition.goalv();
} else {
- g_pCompositor->vectorWindowToSurface(g_pInputManager->getMouseCoordsInternal(), g_pCompositor->m_pLastWindow, local);
+ g_pCompositor->vectorWindowToSurface(g_pInputManager->getMouseCoordsInternal(), m_sTouchData.touchFocusWindow, local);
}
m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local;
+ } else if (m_sTouchData.touchFocusLS) {
+ local = g_pInputManager->getMouseCoordsInternal() - Vector2D(m_sTouchData.touchFocusLS->geometry.x, m_sTouchData.touchFocusLS->geometry.y) - g_pCompositor->m_pLastMonitor->vecPosition;
- wlr_seat_touch_notify_down(g_pCompositor->m_sSeat.seat, g_pCompositor->m_pLastFocus, e->time_msec, e->touch_id, local.x, local.y);
-
- m_sTouchData.touchFocusWindow = g_pCompositor->m_pLastWindow;
+ m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local;
+ } else {
+ return; // oops, nothing found.
}
+
+ wlr_seat_touch_notify_down(g_pCompositor->m_sSeat.seat, m_sTouchData.touchFocusSurface, e->time_msec, e->touch_id, local.x, local.y);
}
void CInputManager::onTouchUp(wlr_touch_up_event* e){
- if (m_sTouchData.touchFocusWindow) {
+ if (m_sTouchData.touchFocusSurface) {
wlr_seat_touch_notify_up(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id);
}
}
void CInputManager::onTouchMove(wlr_touch_motion_event* e){
- if (g_pCompositor->windowValidMapped(m_sTouchData.touchFocusWindow)) {
+ if (m_sTouchData.touchFocusWindow && g_pCompositor->windowValidMapped(m_sTouchData.touchFocusWindow)) {
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusWindow->m_iMonitorID);
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PMONITOR->vecPosition.x + e->x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e->y * PMONITOR->vecSize.y);
@@ -48,6 +55,14 @@ void CInputManager::onTouchMove(wlr_touch_motion_event* e){
const auto local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchSurfaceOrigin;
wlr_seat_touch_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id, local.x, local.y);
+ } else if (m_sTouchData.touchFocusLS) {
+ const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusLS->monitorID);
+
+ wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PMONITOR->vecPosition.x + e->x * PMONITOR->vecSize.x, PMONITOR->vecPosition.y + e->y * PMONITOR->vecSize.y);
+
+ const auto local = g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchSurfaceOrigin;
+
+ wlr_seat_touch_notify_motion(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id, local.x, local.y);
}
}