pointermgr: Hide hardware cursor on leave (#7806)

This commit is contained in:
Vaxry 2024-09-18 18:47:53 +01:00 committed by GitHub
parent 94140e886e
commit e6cf643f5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -208,9 +208,8 @@ void CPointerManager::recheckEnteredOutputs() {
// if we are using hw cursors, prevent // if we are using hw cursors, prevent
// the cursor from being stuck at the last point. // the cursor from being stuck at the last point.
// if we are leaving it, move it to narnia.
if (!s->hardwareFailed && (s->monitor->output->getBackend()->capabilities() & Aquamarine::IBackendImplementation::eBackendCapabilities::AQ_BACKEND_CAPABILITY_POINTER)) if (!s->hardwareFailed && (s->monitor->output->getBackend()->capabilities() & Aquamarine::IBackendImplementation::eBackendCapabilities::AQ_BACKEND_CAPABILITY_POINTER))
s->monitor->output->moveCursor({-1337, -420}); setHWCursorBuffer(s, nullptr);
if (!currentCursorImage.surface) if (!currentCursorImage.surface)
continue; continue;
@ -269,6 +268,8 @@ void CPointerManager::resetCursorImage(bool apply) {
void CPointerManager::updateCursorBackend() { void CPointerManager::updateCursorBackend() {
static auto PNOHW = CConfigValue<Hyprlang::INT>("cursor:no_hardware_cursors"); static auto PNOHW = CConfigValue<Hyprlang::INT>("cursor:no_hardware_cursors");
const auto CURSORBOX = getCursorBoxGlobal();
for (auto const& m : g_pCompositor->m_vMonitors) { for (auto const& m : g_pCompositor->m_vMonitors) {
auto state = stateFor(m); auto state = stateFor(m);
@ -277,6 +278,15 @@ void CPointerManager::updateCursorBackend() {
continue; continue;
} }
auto CROSSES = !m->logicalBox().intersection(CURSORBOX).empty();
if (!CROSSES) {
if (state->cursorFrontBuffer)
setHWCursorBuffer(state, nullptr);
continue;
}
if (state->softwareLocks > 0 || *PNOHW || !attemptHardwareCursor(state)) { if (state->softwareLocks > 0 || *PNOHW || !attemptHardwareCursor(state)) {
Debug::log(TRACE, "Output {} rejected hardware cursors, falling back to sw", m->szName); Debug::log(TRACE, "Output {} rejected hardware cursors, falling back to sw", m->szName);
state->box = getCursorBoxLogicalForMonitor(state->monitor.lock()); state->box = getCursorBoxLogicalForMonitor(state->monitor.lock());
@ -297,17 +307,34 @@ void CPointerManager::onCursorMoved() {
if (!hasCursor()) if (!hasCursor())
return; return;
const auto CURSORBOX = getCursorBoxGlobal();
bool recalc = false;
for (auto const& m : g_pCompositor->m_vMonitors) { for (auto const& m : g_pCompositor->m_vMonitors) {
auto state = stateFor(m); auto state = stateFor(m);
state->box = getCursorBoxLogicalForMonitor(state->monitor.lock()); state->box = getCursorBoxLogicalForMonitor(state->monitor.lock());
auto CROSSES = !m->logicalBox().intersection(CURSORBOX).empty();
if (!CROSSES && state->cursorFrontBuffer) {
Debug::log(TRACE, "onCursorMoved for output {}: cursor left the viewport, removing it from the backend", m->szName);
setHWCursorBuffer(state, nullptr);
continue;
} else if (CROSSES && !state->cursorFrontBuffer) {
Debug::log(TRACE, "onCursorMoved for output {}: cursor entered the output, but no front buffer, forcing recalc", m->szName);
recalc = true;
}
if (state->hardwareFailed || !state->entered) if (state->hardwareFailed || !state->entered)
continue; continue;
const auto CURSORPOS = getCursorPosForMonitor(m); const auto CURSORPOS = getCursorPosForMonitor(m);
m->output->moveCursor(CURSORPOS); m->output->moveCursor(CURSORPOS);
} }
if (recalc)
updateCursorBackend();
} }
bool CPointerManager::attemptHardwareCursor(SP<CPointerManager::SMonitorPointerState> state) { bool CPointerManager::attemptHardwareCursor(SP<CPointerManager::SMonitorPointerState> state) {