Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide cursor on leave #7806

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/managers/PointerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,8 @@ void CPointerManager::recheckEnteredOutputs() {

// if we are using hw cursors, prevent
// 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))
s->monitor->output->moveCursor({-1337, -420});
setHWCursorBuffer(s, nullptr);

if (!currentCursorImage.surface)
continue;
Expand Down Expand Up @@ -307,6 +306,8 @@ void CPointerManager::resetCursorImage(bool apply) {
void CPointerManager::updateCursorBackend() {
static auto PNOHW = CConfigValue<Hyprlang::INT>("cursor:no_hardware_cursors");

const auto CURSORBOX = getCursorBoxGlobal();

for (auto const& m : g_pCompositor->m_vMonitors) {
auto state = stateFor(m);

Expand All @@ -315,6 +316,15 @@ void CPointerManager::updateCursorBackend() {
continue;
}

auto CROSSES = !m->logicalBox().intersection(CURSORBOX).empty();

if (!CROSSES) {
if (state->cursorFrontBuffer)
setHWCursorBuffer(state, nullptr);

continue;
}

if (state->softwareLocks > 0 || *PNOHW || !attemptHardwareCursor(state)) {
Debug::log(TRACE, "Output {} rejected hardware cursors, falling back to sw", m->szName);
state->box = getCursorBoxLogicalForMonitor(state->monitor.lock());
Expand All @@ -335,17 +345,34 @@ void CPointerManager::onCursorMoved() {
if (!hasCursor())
return;

const auto CURSORBOX = getCursorBoxGlobal();
bool recalc = false;

for (auto const& m : g_pCompositor->m_vMonitors) {
auto state = stateFor(m);

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)
continue;

const auto CURSORPOS = getCursorPosForMonitor(m);
m->output->moveCursor(CURSORPOS);
}

if (recalc)
updateCursorBackend();
}

bool CPointerManager::attemptHardwareCursor(SP<CPointerManager::SMonitorPointerState> state) {
Expand Down
Loading