2024-05-05 23:18:10 +02:00
|
|
|
#include "PointerManager.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
#include "../config/ConfigValue.hpp"
|
|
|
|
#include "../protocols/PointerGestures.hpp"
|
|
|
|
#include "../protocols/FractionalScale.hpp"
|
2024-09-06 01:58:57 +02:00
|
|
|
#include "../protocols/IdleNotify.hpp"
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "../protocols/core/Compositor.hpp"
|
2024-07-31 21:47:26 +02:00
|
|
|
#include "../protocols/core/Seat.hpp"
|
2024-07-05 23:05:03 +02:00
|
|
|
#include "eventLoop/EventLoopManager.hpp"
|
2024-05-10 19:27:57 +02:00
|
|
|
#include "SeatManager.hpp"
|
2024-07-21 13:09:54 +02:00
|
|
|
#include <cstring>
|
|
|
|
#include <gbm.h>
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
CPointerManager::CPointerManager() {
|
2024-08-11 20:42:18 +02:00
|
|
|
hooks.monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any data) {
|
|
|
|
auto PMONITOR = std::any_cast<CMonitor*>(data)->self.lock();
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
onMonitorLayoutChange();
|
|
|
|
|
2024-09-26 00:15:36 +02:00
|
|
|
PMONITOR->events.modeChanged.registerStaticListener([this](void* owner, std::any data) { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); }, nullptr);
|
|
|
|
PMONITOR->events.disconnect.registerStaticListener([this](void* owner, std::any data) { g_pEventLoopManager->doLater([this]() { onMonitorLayoutChange(); }); }, nullptr);
|
2024-05-05 23:18:10 +02:00
|
|
|
PMONITOR->events.destroy.registerStaticListener(
|
2024-05-23 21:19:14 +02:00
|
|
|
[this](void* owner, std::any data) {
|
|
|
|
if (g_pCompositor && !g_pCompositor->m_bIsShuttingDown)
|
|
|
|
std::erase_if(monitorStates, [](const auto& other) { return other->monitor.expired(); });
|
|
|
|
},
|
|
|
|
nullptr);
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
2024-07-22 19:19:37 +02:00
|
|
|
|
2024-07-30 15:32:38 +02:00
|
|
|
hooks.monitorPreRender = g_pHookSystem->hookDynamic("preMonitorCommit", [this](void* self, SCallbackInfo& info, std::any data) {
|
2024-07-22 19:19:37 +02:00
|
|
|
auto state = stateFor(std::any_cast<CMonitor*>(data)->self.lock());
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
state->cursorRendered = false;
|
|
|
|
});
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
2024-06-12 19:28:52 +02:00
|
|
|
void CPointerManager::lockSoftwareAll() {
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& state : monitorStates)
|
2024-06-12 19:28:52 +02:00
|
|
|
state->softwareLocks++;
|
|
|
|
|
|
|
|
updateCursorBackend();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::unlockSoftwareAll() {
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& state : monitorStates)
|
2024-06-12 19:28:52 +02:00
|
|
|
state->softwareLocks--;
|
|
|
|
|
|
|
|
updateCursorBackend();
|
|
|
|
}
|
|
|
|
|
2024-06-19 16:24:28 +02:00
|
|
|
void CPointerManager::lockSoftwareForMonitor(CMonitor* Monitor) {
|
2024-08-26 17:25:39 +02:00
|
|
|
for (auto const& m : g_pCompositor->m_vMonitors) {
|
2024-06-19 16:24:28 +02:00
|
|
|
if (m->ID == Monitor->ID) {
|
|
|
|
lockSoftwareForMonitor(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
void CPointerManager::lockSoftwareForMonitor(SP<CMonitor> mon) {
|
|
|
|
auto state = stateFor(mon);
|
|
|
|
state->softwareLocks++;
|
|
|
|
|
|
|
|
if (state->softwareLocks == 1)
|
|
|
|
updateCursorBackend();
|
|
|
|
}
|
|
|
|
|
2024-06-19 16:24:28 +02:00
|
|
|
void CPointerManager::unlockSoftwareForMonitor(CMonitor* Monitor) {
|
2024-08-26 17:25:39 +02:00
|
|
|
for (auto const& m : g_pCompositor->m_vMonitors) {
|
2024-06-19 16:24:28 +02:00
|
|
|
if (m->ID == Monitor->ID) {
|
|
|
|
unlockSoftwareForMonitor(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
void CPointerManager::unlockSoftwareForMonitor(SP<CMonitor> mon) {
|
|
|
|
auto state = stateFor(mon);
|
|
|
|
state->softwareLocks--;
|
|
|
|
if (state->softwareLocks < 0)
|
|
|
|
state->softwareLocks = 0;
|
|
|
|
|
|
|
|
if (state->softwareLocks == 0)
|
|
|
|
updateCursorBackend();
|
|
|
|
}
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
bool CPointerManager::softwareLockedFor(SP<CMonitor> mon) {
|
|
|
|
auto state = stateFor(mon);
|
|
|
|
return state->softwareLocks > 0 || state->hardwareFailed;
|
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
Vector2D CPointerManager::position() {
|
|
|
|
return pointerPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPointerManager::hasCursor() {
|
|
|
|
return currentCursorImage.pBuffer || currentCursorImage.surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
SP<CPointerManager::SMonitorPointerState> CPointerManager::stateFor(SP<CMonitor> mon) {
|
|
|
|
auto it = std::find_if(monitorStates.begin(), monitorStates.end(), [mon](const auto& other) { return other->monitor == mon; });
|
|
|
|
if (it == monitorStates.end())
|
|
|
|
return monitorStates.emplace_back(makeShared<CPointerManager::SMonitorPointerState>(mon));
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
void CPointerManager::setCursorBuffer(SP<Aquamarine::IBuffer> buf, const Vector2D& hotspot, const float& scale) {
|
2024-05-17 21:04:17 +02:00
|
|
|
damageIfSoftware();
|
2024-05-05 23:18:10 +02:00
|
|
|
if (buf == currentCursorImage.pBuffer) {
|
|
|
|
if (hotspot != currentCursorImage.hotspot || scale != currentCursorImage.scale) {
|
|
|
|
currentCursorImage.hotspot = hotspot;
|
|
|
|
currentCursorImage.scale = scale;
|
|
|
|
updateCursorBackend();
|
2024-05-17 21:04:17 +02:00
|
|
|
damageIfSoftware();
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
resetCursorImage(false);
|
|
|
|
|
|
|
|
if (buf) {
|
2024-07-21 13:09:54 +02:00
|
|
|
currentCursorImage.size = buf->size;
|
|
|
|
currentCursorImage.pBuffer = buf;
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
currentCursorImage.hotspot = hotspot;
|
|
|
|
currentCursorImage.scale = scale;
|
|
|
|
|
|
|
|
updateCursorBackend();
|
2024-05-17 21:04:17 +02:00
|
|
|
damageIfSoftware();
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CPointerManager::setCursorSurface(SP<CWLSurface> surf, const Vector2D& hotspot) {
|
2024-05-17 21:04:17 +02:00
|
|
|
damageIfSoftware();
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
if (surf == currentCursorImage.surface) {
|
2024-06-08 10:07:59 +02:00
|
|
|
if (hotspot != currentCursorImage.hotspot || (surf && surf->resource() ? surf->resource()->current.scale : 1.F) != currentCursorImage.scale) {
|
2024-05-05 23:18:10 +02:00
|
|
|
currentCursorImage.hotspot = hotspot;
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.scale = surf && surf->resource() ? surf->resource()->current.scale : 1.F;
|
2024-05-05 23:18:10 +02:00
|
|
|
updateCursorBackend();
|
2024-05-17 21:04:17 +02:00
|
|
|
damageIfSoftware();
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
resetCursorImage(false);
|
|
|
|
|
|
|
|
if (surf) {
|
|
|
|
currentCursorImage.surface = surf;
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.scale = surf->resource()->current.scale;
|
2024-05-05 23:18:10 +02:00
|
|
|
|
2024-07-29 19:02:58 +02:00
|
|
|
surf->resource()->map();
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
currentCursorImage.destroySurface = surf->events.destroy.registerListener([this](std::any data) { resetCursorImage(); });
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.commitSurface = surf->resource()->events.commit.registerListener([this](std::any data) {
|
|
|
|
damageIfSoftware();
|
2024-07-31 21:47:26 +02:00
|
|
|
currentCursorImage.size = currentCursorImage.surface->resource()->current.texture ? currentCursorImage.surface->resource()->current.bufferSize : Vector2D{};
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.scale = currentCursorImage.surface ? currentCursorImage.surface->resource()->current.scale : 1.F;
|
|
|
|
recheckEnteredOutputs();
|
|
|
|
updateCursorBackend();
|
|
|
|
damageIfSoftware();
|
|
|
|
});
|
2024-05-05 23:18:10 +02:00
|
|
|
|
2024-07-31 21:47:26 +02:00
|
|
|
if (surf->resource()->current.texture) {
|
|
|
|
currentCursorImage.size = surf->resource()->current.bufferSize;
|
2024-05-05 23:18:10 +02:00
|
|
|
timespec now;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
2024-06-08 10:07:59 +02:00
|
|
|
surf->resource()->frame(&now);
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentCursorImage.hotspot = hotspot;
|
|
|
|
|
|
|
|
recheckEnteredOutputs();
|
|
|
|
updateCursorBackend();
|
2024-05-17 21:04:17 +02:00
|
|
|
damageIfSoftware();
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::recheckEnteredOutputs() {
|
|
|
|
if (!hasCursor())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto box = getCursorBoxGlobal();
|
|
|
|
|
2024-08-26 17:25:39 +02:00
|
|
|
for (auto const& s : monitorStates) {
|
2024-05-05 23:18:10 +02:00
|
|
|
if (s->monitor.expired() || s->monitor->isMirror() || !s->monitor->m_bEnabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const bool overlaps = box.overlaps(s->monitor->logicalBox());
|
|
|
|
|
|
|
|
if (!s->entered && overlaps) {
|
|
|
|
s->entered = true;
|
|
|
|
|
|
|
|
if (!currentCursorImage.surface)
|
|
|
|
continue;
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.surface->resource()->enter(s->monitor.lock());
|
|
|
|
PROTO::fractional->sendScale(currentCursorImage.surface->resource(), s->monitor->scale);
|
|
|
|
g_pCompositor->setPreferredScaleForSurface(currentCursorImage.surface->resource(), s->monitor->scale);
|
2024-05-05 23:18:10 +02:00
|
|
|
} else if (s->entered && !overlaps) {
|
|
|
|
s->entered = false;
|
|
|
|
|
|
|
|
// if we are using hw cursors, prevent
|
|
|
|
// the cursor from being stuck at the last point.
|
2024-07-21 13:09:54 +02:00
|
|
|
if (!s->hardwareFailed && (s->monitor->output->getBackend()->capabilities() & Aquamarine::IBackendImplementation::eBackendCapabilities::AQ_BACKEND_CAPABILITY_POINTER))
|
2024-09-18 19:47:53 +02:00
|
|
|
setHWCursorBuffer(s, nullptr);
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
if (!currentCursorImage.surface)
|
|
|
|
continue;
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.surface->resource()->leave(s->monitor.lock());
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::resetCursorImage(bool apply) {
|
2024-05-17 21:04:17 +02:00
|
|
|
damageIfSoftware();
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
if (currentCursorImage.surface) {
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& m : g_pCompositor->m_vMonitors) {
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.surface->resource()->leave(m);
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
2024-07-29 19:02:58 +02:00
|
|
|
currentCursorImage.surface->resource()->unmap();
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
currentCursorImage.destroySurface.reset();
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.commitSurface.reset();
|
|
|
|
currentCursorImage.surface.reset();
|
2024-07-21 13:09:54 +02:00
|
|
|
} else if (currentCursorImage.pBuffer)
|
2024-05-05 23:18:10 +02:00
|
|
|
currentCursorImage.pBuffer = nullptr;
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
if (currentCursorImage.bufferTex)
|
|
|
|
currentCursorImage.bufferTex = nullptr;
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
currentCursorImage.scale = 1.F;
|
|
|
|
currentCursorImage.hotspot = {0, 0};
|
|
|
|
|
2024-08-26 17:25:39 +02:00
|
|
|
for (auto const& s : monitorStates) {
|
2024-05-10 00:08:40 +02:00
|
|
|
if (s->monitor.expired() || s->monitor->isMirror() || !s->monitor->m_bEnabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
s->entered = false;
|
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
if (!apply)
|
|
|
|
return;
|
|
|
|
|
2024-08-26 17:25:39 +02:00
|
|
|
for (auto const& ms : monitorStates) {
|
2024-05-16 20:34:36 +02:00
|
|
|
if (!ms->monitor || !ms->monitor->m_bEnabled || !ms->monitor->dpmsStatus) {
|
|
|
|
Debug::log(TRACE, "Not updating hw cursors: disabled / dpms off display");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
if (ms->cursorFrontBuffer) {
|
2024-07-21 13:09:54 +02:00
|
|
|
if (ms->monitor->output->getBackend()->capabilities() & Aquamarine::IBackendImplementation::eBackendCapabilities::AQ_BACKEND_CAPABILITY_POINTER)
|
|
|
|
ms->monitor->output->setCursor(nullptr, {});
|
2024-05-05 23:18:10 +02:00
|
|
|
ms->cursorFrontBuffer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::updateCursorBackend() {
|
|
|
|
static auto PNOHW = CConfigValue<Hyprlang::INT>("cursor:no_hardware_cursors");
|
|
|
|
|
2024-09-18 19:47:53 +02:00
|
|
|
const auto CURSORBOX = getCursorBoxGlobal();
|
|
|
|
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& m : g_pCompositor->m_vMonitors) {
|
2024-05-05 23:18:10 +02:00
|
|
|
auto state = stateFor(m);
|
|
|
|
|
2024-05-16 20:34:36 +02:00
|
|
|
if (!m->m_bEnabled || !m->dpmsStatus) {
|
|
|
|
Debug::log(TRACE, "Not updating hw cursors: disabled / dpms off display");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-09-18 19:47:53 +02:00
|
|
|
auto CROSSES = !m->logicalBox().intersection(CURSORBOX).empty();
|
|
|
|
|
|
|
|
if (!CROSSES) {
|
|
|
|
if (state->cursorFrontBuffer)
|
|
|
|
setHWCursorBuffer(state, nullptr);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
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());
|
|
|
|
state->hardwareFailed = true;
|
|
|
|
|
|
|
|
if (state->hwApplied)
|
|
|
|
setHWCursorBuffer(state, nullptr);
|
|
|
|
|
|
|
|
state->hwApplied = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
state->hardwareFailed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::onCursorMoved() {
|
|
|
|
if (!hasCursor())
|
|
|
|
return;
|
|
|
|
|
2024-09-18 19:47:53 +02:00
|
|
|
const auto CURSORBOX = getCursorBoxGlobal();
|
|
|
|
bool recalc = false;
|
|
|
|
|
2024-08-26 17:25:39 +02:00
|
|
|
for (auto const& m : g_pCompositor->m_vMonitors) {
|
2024-05-05 23:18:10 +02:00
|
|
|
auto state = stateFor(m);
|
|
|
|
|
|
|
|
state->box = getCursorBoxLogicalForMonitor(state->monitor.lock());
|
|
|
|
|
2024-09-18 19:47:53 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
if (state->hardwareFailed || !state->entered)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto CURSORPOS = getCursorPosForMonitor(m);
|
2024-07-21 13:09:54 +02:00
|
|
|
m->output->moveCursor(CURSORPOS);
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
2024-09-18 19:47:53 +02:00
|
|
|
|
|
|
|
if (recalc)
|
|
|
|
updateCursorBackend();
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CPointerManager::attemptHardwareCursor(SP<CPointerManager::SMonitorPointerState> state) {
|
|
|
|
auto output = state->monitor->output;
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
if (!(output->getBackend()->capabilities() & Aquamarine::IBackendImplementation::eBackendCapabilities::AQ_BACKEND_CAPABILITY_POINTER))
|
2024-05-05 23:18:10 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto CURSORPOS = getCursorPosForMonitor(state->monitor.lock());
|
2024-07-21 13:09:54 +02:00
|
|
|
state->monitor->output->moveCursor(CURSORPOS);
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
auto texture = getCurrentCursorTexture();
|
|
|
|
|
|
|
|
if (!texture) {
|
|
|
|
Debug::log(TRACE, "[pointer] no texture for hw cursor -> hiding");
|
|
|
|
setHWCursorBuffer(state, nullptr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto buffer = renderHWCursorBuffer(state, texture);
|
|
|
|
|
|
|
|
if (!buffer) {
|
|
|
|
Debug::log(TRACE, "[pointer] hw cursor failed rendering");
|
|
|
|
setHWCursorBuffer(state, nullptr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool success = setHWCursorBuffer(state, buffer);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
Debug::log(TRACE, "[pointer] hw cursor failed applying, hiding");
|
|
|
|
setHWCursorBuffer(state, nullptr);
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
state->hwApplied = true;
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
bool CPointerManager::setHWCursorBuffer(SP<SMonitorPointerState> state, SP<Aquamarine::IBuffer> buf) {
|
|
|
|
if (!(state->monitor->output->getBackend()->capabilities() & Aquamarine::IBackendImplementation::eBackendCapabilities::AQ_BACKEND_CAPABILITY_POINTER))
|
2024-05-05 23:18:10 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto HOTSPOT = transformedHotspot(state->monitor.lock());
|
|
|
|
|
|
|
|
Debug::log(TRACE, "[pointer] hw transformed hotspot for {}: {}", state->monitor->szName, HOTSPOT);
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
if (!state->monitor->output->setCursor(buf, HOTSPOT))
|
2024-05-05 23:18:10 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
state->cursorFrontBuffer = buf;
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
g_pCompositor->scheduleFrameForMonitor(state->monitor.get(), Aquamarine::IOutput::AQ_SCHEDULE_CURSOR_SHAPE);
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
SP<Aquamarine::IBuffer> CPointerManager::renderHWCursorBuffer(SP<CPointerManager::SMonitorPointerState> state, SP<CTexture> texture) {
|
2024-05-05 23:18:10 +02:00
|
|
|
auto output = state->monitor->output;
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
auto maxSize = output->cursorPlaneSize();
|
|
|
|
auto cursorSize = currentCursorImage.size;
|
2024-05-05 23:18:10 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
if (maxSize == Vector2D{})
|
2024-05-05 23:18:10 +02:00
|
|
|
return nullptr;
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
if (maxSize != Vector2D{-1, -1}) {
|
|
|
|
if (cursorSize.x > maxSize.x || cursorSize.y > maxSize.y) {
|
|
|
|
Debug::log(TRACE, "hardware cursor too big! {} > {}", currentCursorImage.size, maxSize);
|
2024-05-05 23:18:10 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2024-07-21 13:09:54 +02:00
|
|
|
} else
|
|
|
|
maxSize = cursorSize;
|
|
|
|
|
|
|
|
if (!state->monitor->cursorSwapchain || maxSize != state->monitor->cursorSwapchain->currentOptions().size) {
|
2024-05-05 23:18:10 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
if (!state->monitor->cursorSwapchain)
|
|
|
|
state->monitor->cursorSwapchain = Aquamarine::CSwapchain::create(state->monitor->output->getBackend()->preferredAllocator(), state->monitor->output->getBackend());
|
2024-05-05 23:18:10 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
auto options = state->monitor->cursorSwapchain->currentOptions();
|
|
|
|
options.size = maxSize;
|
2024-07-22 19:19:37 +02:00
|
|
|
options.length = 2;
|
2024-07-21 13:09:54 +02:00
|
|
|
options.scanout = true;
|
|
|
|
options.cursor = true;
|
|
|
|
options.multigpu = state->monitor->output->getBackend()->preferredAllocator()->drmFD() != g_pCompositor->m_iDRMFD;
|
|
|
|
// We do not set the format. If it's unset (DRM_FORMAT_INVALID) then the swapchain will pick for us,
|
|
|
|
// but if it's set, we don't wanna change it.
|
|
|
|
|
|
|
|
if (!state->monitor->cursorSwapchain->reconfigure(options)) {
|
|
|
|
Debug::log(TRACE, "Failed to reconfigure cursor swapchain");
|
2024-05-05 23:18:10 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 19:19:37 +02:00
|
|
|
// if we already rendered the cursor, revert the swapchain to avoid rendering the cursor over
|
|
|
|
// the current front buffer
|
|
|
|
// this flag will be reset in the preRender hook, so when we commit this buffer to KMS
|
|
|
|
if (state->cursorRendered)
|
|
|
|
state->monitor->cursorSwapchain->rollback();
|
|
|
|
|
|
|
|
state->cursorRendered = true;
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
auto buf = state->monitor->cursorSwapchain->next(nullptr);
|
2024-05-05 23:18:10 +02:00
|
|
|
if (!buf) {
|
|
|
|
Debug::log(TRACE, "Failed to acquire a buffer from the cursor swapchain");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CRegion damage = {0, 0, INT16_MAX, INT16_MAX};
|
|
|
|
|
|
|
|
g_pHyprRenderer->makeEGLCurrent();
|
2024-07-21 13:09:54 +02:00
|
|
|
g_pHyprOpenGL->m_RenderData.pMonitor = state->monitor.get();
|
|
|
|
|
|
|
|
auto RBO = g_pHyprRenderer->getOrCreateRenderbuffer(buf, state->monitor->cursorSwapchain->currentOptions().format);
|
|
|
|
if (!RBO) {
|
|
|
|
Debug::log(TRACE, "Failed to create cursor RB with format {}, mod {}", buf->dmabuf().format, buf->dmabuf().modifier);
|
|
|
|
static auto PDUMB = CConfigValue<Hyprlang::INT>("cursor:allow_dumb_copy");
|
|
|
|
if (!*PDUMB)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto bufData = buf->beginDataPtr(0);
|
|
|
|
auto bufPtr = std::get<0>(bufData);
|
|
|
|
|
|
|
|
// clear buffer
|
|
|
|
memset(bufPtr, 0, std::get<2>(bufData));
|
|
|
|
|
2024-07-31 21:47:26 +02:00
|
|
|
if (currentCursorImage.pBuffer) {
|
|
|
|
auto texAttrs = currentCursorImage.pBuffer->shm();
|
2024-07-21 13:09:54 +02:00
|
|
|
|
2024-07-31 21:47:26 +02:00
|
|
|
if (!texAttrs.success) {
|
|
|
|
Debug::log(TRACE, "Cannot use dumb copy on dmabuf cursor buffers");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto texData = currentCursorImage.pBuffer->beginDataPtr(GBM_BO_TRANSFER_WRITE);
|
|
|
|
auto texPtr = std::get<0>(texData);
|
|
|
|
Debug::log(TRACE, "cursor texture {}x{} {} {} {}", texAttrs.size.x, texAttrs.size.y, (void*)texPtr, texAttrs.format, texAttrs.stride);
|
2024-07-21 13:09:54 +02:00
|
|
|
// copy cursor texture
|
2024-07-31 21:47:26 +02:00
|
|
|
for (int i = 0; i < texAttrs.size.y; i++)
|
|
|
|
memcpy(bufPtr + i * buf->dmabuf().strides[0], texPtr + i * texAttrs.stride, texAttrs.stride);
|
|
|
|
} else if (currentCursorImage.surface && currentCursorImage.surface->resource()->role->role() == SURFACE_ROLE_CURSOR) {
|
|
|
|
const auto SURFACE = currentCursorImage.surface->resource();
|
|
|
|
auto& shmBuffer = CCursorSurfaceRole::cursorPixelData(SURFACE);
|
|
|
|
Debug::log(TRACE, "cursor texture pixel data length: {}B", shmBuffer.size());
|
|
|
|
|
|
|
|
if (shmBuffer.data()) {
|
|
|
|
// copy cursor texture
|
|
|
|
// assume format is 32bpp
|
|
|
|
size_t STRIDE = 4 * SURFACE->current.bufferSize.x;
|
|
|
|
for (int i = 0; i < SURFACE->current.bufferSize.y; i++)
|
|
|
|
memcpy(bufPtr + i * buf->dmabuf().strides[0], shmBuffer.data() + i * STRIDE, STRIDE);
|
|
|
|
} else {
|
|
|
|
// if there is no data, hide the cursor
|
|
|
|
memset(bufPtr, '\0', buf->size.x * buf->size.y * 4 /* assume 32bpp */);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Debug::log(TRACE, "Unsupported cursor buffer/surface, falling back to sw (can't dumb copy)");
|
|
|
|
return nullptr;
|
2024-07-21 13:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
buf->endDataPtr();
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
RBO->bind();
|
|
|
|
|
|
|
|
g_pHyprOpenGL->beginSimple(state->monitor.get(), damage, RBO);
|
|
|
|
g_pHyprOpenGL->clear(CColor{0.F, 0.F, 0.F, 0.F});
|
|
|
|
|
|
|
|
CBox xbox = {{}, Vector2D{currentCursorImage.size / currentCursorImage.scale * state->monitor->scale}.round()};
|
2024-07-21 13:09:54 +02:00
|
|
|
Debug::log(TRACE, "[pointer] monitor: {}, size: {}, hw buf: {}, scale: {:.2f}, monscale: {:.2f}, xbox: {}", state->monitor->szName, currentCursorImage.size, cursorSize,
|
2024-05-05 23:18:10 +02:00
|
|
|
currentCursorImage.scale, state->monitor->scale, xbox.size());
|
|
|
|
|
|
|
|
g_pHyprOpenGL->renderTexture(texture, &xbox, 1.F);
|
|
|
|
|
|
|
|
g_pHyprOpenGL->end();
|
|
|
|
glFlush();
|
|
|
|
g_pHyprOpenGL->m_RenderData.pMonitor = nullptr;
|
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
g_pHyprRenderer->onRenderbufferDestroy(RBO.get());
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::renderSoftwareCursorsFor(SP<CMonitor> pMonitor, timespec* now, CRegion& damage, std::optional<Vector2D> overridePos) {
|
|
|
|
if (!hasCursor())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto state = stateFor(pMonitor);
|
|
|
|
|
|
|
|
if ((!state->hardwareFailed && state->softwareLocks == 0)) {
|
|
|
|
if (currentCursorImage.surface)
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.surface->resource()->frame(now);
|
2024-05-05 23:18:10 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto box = state->box.copy();
|
|
|
|
if (overridePos.has_value()) {
|
|
|
|
box.x = overridePos->x;
|
|
|
|
box.y = overridePos->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (box.intersection(CBox{{}, {pMonitor->vecSize}}).empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto texture = getCurrentCursorTexture();
|
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
|
|
|
box.scale(pMonitor->scale);
|
2024-06-25 18:44:54 +02:00
|
|
|
box.x = std::round(box.x);
|
|
|
|
box.y = std::round(box.y);
|
2024-05-05 23:18:10 +02:00
|
|
|
|
2024-07-21 13:09:54 +02:00
|
|
|
g_pHyprOpenGL->renderTextureWithDamage(texture, &box, &damage, 1.F, 0, false, false, currentCursorImage.waitTimeline, currentCursorImage.waitPoint);
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
if (currentCursorImage.surface)
|
2024-06-08 10:07:59 +02:00
|
|
|
currentCursorImage.surface->resource()->frame(now);
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D CPointerManager::getCursorPosForMonitor(SP<CMonitor> pMonitor) {
|
|
|
|
return CBox{pointerPos - pMonitor->vecPosition, {0, 0}}
|
2024-07-21 13:09:54 +02:00
|
|
|
.transform(wlTransformToHyprutils(invertTransform(pMonitor->transform)), pMonitor->vecTransformedSize.x / pMonitor->scale,
|
|
|
|
pMonitor->vecTransformedSize.y / pMonitor->scale)
|
2024-05-05 23:18:10 +02:00
|
|
|
.pos() *
|
|
|
|
pMonitor->scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D CPointerManager::transformedHotspot(SP<CMonitor> pMonitor) {
|
2024-07-21 13:09:54 +02:00
|
|
|
if (!pMonitor->cursorSwapchain)
|
2024-05-09 20:17:04 +02:00
|
|
|
return {}; // doesn't matter, we have no hw cursor, and this is only for hw cursors
|
|
|
|
|
2024-05-31 12:38:52 +02:00
|
|
|
return CBox{currentCursorImage.hotspot * pMonitor->scale, {0, 0}}
|
2024-07-21 13:09:54 +02:00
|
|
|
.transform(wlTransformToHyprutils(invertTransform(pMonitor->transform)), pMonitor->cursorSwapchain->currentOptions().size.x,
|
|
|
|
pMonitor->cursorSwapchain->currentOptions().size.y)
|
2024-05-05 23:18:10 +02:00
|
|
|
.pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
CBox CPointerManager::getCursorBoxLogicalForMonitor(SP<CMonitor> pMonitor) {
|
|
|
|
return getCursorBoxGlobal().translate(-pMonitor->vecPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
CBox CPointerManager::getCursorBoxGlobal() {
|
2024-05-25 20:43:29 +02:00
|
|
|
return CBox{pointerPos, currentCursorImage.size / currentCursorImage.scale}.translate(-currentCursorImage.hotspot);
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D CPointerManager::closestValid(const Vector2D& pos) {
|
|
|
|
static auto PADDING = CConfigValue<Hyprlang::INT>("cursor:hotspot_padding");
|
|
|
|
|
2024-07-02 12:17:48 +02:00
|
|
|
auto CURSOR_PADDING = std::clamp((int)*PADDING, 0, 100);
|
2024-05-05 23:18:10 +02:00
|
|
|
CBox hotBox = {{pos.x - CURSOR_PADDING, pos.y - CURSOR_PADDING}, {2 * CURSOR_PADDING, 2 * CURSOR_PADDING}};
|
|
|
|
|
|
|
|
//
|
|
|
|
static auto INSIDE_LAYOUT = [this](const CBox& box) -> bool {
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& b : currentMonitorLayout.monitorBoxes) {
|
2024-05-05 23:18:10 +02:00
|
|
|
if (box.inside(b))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
static auto INSIDE_LAYOUT_COORD = [this](const Vector2D& vec) -> bool {
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& b : currentMonitorLayout.monitorBoxes) {
|
2024-05-05 23:18:10 +02:00
|
|
|
if (b.containsPoint(vec))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
static auto NEAREST_LAYOUT = [this](const Vector2D& vec) -> Vector2D {
|
|
|
|
Vector2D leader;
|
|
|
|
float distanceSq = __FLT_MAX__;
|
|
|
|
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& b : currentMonitorLayout.monitorBoxes) {
|
2024-05-05 23:18:10 +02:00
|
|
|
auto p = b.closestPoint(vec);
|
|
|
|
auto distSq = p.distanceSq(vec);
|
|
|
|
|
|
|
|
if (distSq < distanceSq) {
|
|
|
|
leader = p;
|
|
|
|
distanceSq = distSq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (distanceSq > 1337.69420e+20F)
|
|
|
|
return {0, 0}; // ???
|
|
|
|
|
|
|
|
return leader;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (INSIDE_LAYOUT(hotBox))
|
|
|
|
return pos;
|
|
|
|
|
|
|
|
Vector2D leader = NEAREST_LAYOUT(pos);
|
|
|
|
|
|
|
|
hotBox.x = leader.x - CURSOR_PADDING;
|
|
|
|
hotBox.y = leader.y - CURSOR_PADDING;
|
|
|
|
|
|
|
|
// push the hotbox around so that it fits in the layout
|
|
|
|
|
|
|
|
if (!INSIDE_LAYOUT_COORD(hotBox.middle() + Vector2D{CURSOR_PADDING, CURSOR_PADDING})) {
|
|
|
|
auto delta = NEAREST_LAYOUT(hotBox.middle() + Vector2D{CURSOR_PADDING, CURSOR_PADDING}) - (hotBox.middle() + Vector2D{CURSOR_PADDING, CURSOR_PADDING});
|
|
|
|
hotBox.translate(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!INSIDE_LAYOUT_COORD(hotBox.middle() - Vector2D{CURSOR_PADDING, CURSOR_PADDING})) {
|
|
|
|
auto delta = NEAREST_LAYOUT(hotBox.middle() - Vector2D{CURSOR_PADDING, CURSOR_PADDING}) - (hotBox.middle() - Vector2D{CURSOR_PADDING, CURSOR_PADDING});
|
|
|
|
hotBox.translate(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!INSIDE_LAYOUT_COORD(hotBox.middle() + Vector2D{CURSOR_PADDING, -CURSOR_PADDING})) {
|
|
|
|
auto delta = NEAREST_LAYOUT(hotBox.middle() + Vector2D{CURSOR_PADDING, -CURSOR_PADDING}) - (hotBox.middle() + Vector2D{CURSOR_PADDING, -CURSOR_PADDING});
|
|
|
|
hotBox.translate(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!INSIDE_LAYOUT_COORD(hotBox.middle() + Vector2D{-CURSOR_PADDING, CURSOR_PADDING})) {
|
|
|
|
auto delta = NEAREST_LAYOUT(hotBox.middle() + Vector2D{-CURSOR_PADDING, CURSOR_PADDING}) - (hotBox.middle() + Vector2D{-CURSOR_PADDING, CURSOR_PADDING});
|
|
|
|
hotBox.translate(delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hotBox.middle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::damageIfSoftware() {
|
2024-10-08 18:02:55 +02:00
|
|
|
auto b = getCursorBoxGlobal().expand(4);
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
static auto PNOHW = CConfigValue<Hyprlang::INT>("cursor:no_hardware_cursors");
|
|
|
|
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& mw : monitorStates) {
|
2024-09-11 10:30:21 +02:00
|
|
|
if (mw->monitor.expired() || !mw->monitor->output)
|
2024-05-05 23:18:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((mw->softwareLocks > 0 || mw->hardwareFailed || *PNOHW) && b.overlaps({mw->monitor->vecPosition, mw->monitor->vecSize})) {
|
2024-06-14 13:45:32 +02:00
|
|
|
g_pHyprRenderer->damageBox(&b, mw->monitor->shouldSkipScheduleFrameOnMouseEvent());
|
2024-05-05 23:18:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::warpTo(const Vector2D& logical) {
|
|
|
|
damageIfSoftware();
|
|
|
|
|
|
|
|
pointerPos = closestValid(logical);
|
|
|
|
recheckEnteredOutputs();
|
|
|
|
onCursorMoved();
|
|
|
|
|
|
|
|
damageIfSoftware();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::move(const Vector2D& deltaLogical) {
|
|
|
|
const auto oldPos = pointerPos;
|
2024-05-06 03:15:26 +02:00
|
|
|
auto newPos = oldPos + Vector2D{std::isnan(deltaLogical.x) ? 0.0 : deltaLogical.x, std::isnan(deltaLogical.y) ? 0.0 : deltaLogical.y};
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
warpTo(newPos);
|
|
|
|
}
|
|
|
|
|
2024-05-06 03:15:26 +02:00
|
|
|
void CPointerManager::warpAbsolute(Vector2D abs, SP<IHID> dev) {
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
SP<CMonitor> currentMonitor = g_pCompositor->m_pLastMonitor.lock();
|
2024-07-22 17:24:24 +02:00
|
|
|
if (!currentMonitor || !dev)
|
2024-05-06 03:15:26 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!std::isnan(abs.x))
|
|
|
|
abs.x = std::clamp(abs.x, 0.0, 1.0);
|
|
|
|
if (!std::isnan(abs.y))
|
|
|
|
abs.y = std::clamp(abs.y, 0.0, 1.0);
|
|
|
|
|
|
|
|
// in logical global
|
|
|
|
CBox mappedArea = currentMonitor->logicalBox();
|
2024-05-05 23:18:10 +02:00
|
|
|
|
|
|
|
switch (dev->getType()) {
|
2024-05-06 03:15:26 +02:00
|
|
|
case HID_TYPE_TABLET: {
|
|
|
|
CTablet* TAB = reinterpret_cast<CTablet*>(dev.get());
|
|
|
|
if (!TAB->boundOutput.empty()) {
|
|
|
|
if (const auto PMONITOR = g_pCompositor->getMonitorFromString(TAB->boundOutput); PMONITOR) {
|
|
|
|
currentMonitor = PMONITOR->self.lock();
|
|
|
|
mappedArea = currentMonitor->logicalBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-23 13:52:32 +02:00
|
|
|
mappedArea.translate(TAB->boundBox.pos());
|
|
|
|
if (!TAB->boundBox.empty()) {
|
|
|
|
mappedArea.w = TAB->boundBox.w;
|
|
|
|
mappedArea.h = TAB->boundBox.h;
|
|
|
|
}
|
2024-05-05 23:18:10 +02:00
|
|
|
break;
|
2024-05-06 03:15:26 +02:00
|
|
|
}
|
2024-05-05 23:18:10 +02:00
|
|
|
case HID_TYPE_TOUCH: {
|
2024-05-06 03:15:26 +02:00
|
|
|
ITouch* TOUCH = reinterpret_cast<ITouch*>(dev.get());
|
2024-05-05 23:18:10 +02:00
|
|
|
if (!TOUCH->boundOutput.empty()) {
|
2024-05-06 03:15:26 +02:00
|
|
|
if (const auto PMONITOR = g_pCompositor->getMonitorFromString(TOUCH->boundOutput); PMONITOR) {
|
2024-05-05 23:18:10 +02:00
|
|
|
currentMonitor = PMONITOR->self.lock();
|
2024-05-06 03:15:26 +02:00
|
|
|
mappedArea = currentMonitor->logicalBox();
|
|
|
|
}
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-07-29 16:27:09 +02:00
|
|
|
case HID_TYPE_POINTER: {
|
|
|
|
IPointer* POINTER = reinterpret_cast<IPointer*>(dev.get());
|
2024-07-29 18:13:17 +02:00
|
|
|
if (!POINTER->boundOutput.empty()) {
|
|
|
|
if (POINTER->boundOutput == "entire") {
|
|
|
|
// find x and y size of the entire space
|
|
|
|
Vector2D bottomRight = {-9999999, -9999999}, topLeft = {9999999, 9999999};
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& m : g_pCompositor->m_vMonitors) {
|
2024-07-29 18:13:17 +02:00
|
|
|
const auto EXTENT = m->logicalBox().extent();
|
|
|
|
const auto POS = m->logicalBox().pos();
|
|
|
|
if (EXTENT.x > bottomRight.x)
|
|
|
|
bottomRight.x = EXTENT.x;
|
|
|
|
if (EXTENT.y > bottomRight.y)
|
|
|
|
bottomRight.y = EXTENT.y;
|
|
|
|
if (POS.x < topLeft.x)
|
|
|
|
topLeft.x = POS.x;
|
|
|
|
if (POS.y < topLeft.y)
|
|
|
|
topLeft.y = POS.y;
|
|
|
|
}
|
|
|
|
mappedArea = {topLeft, bottomRight - topLeft};
|
|
|
|
} else if (const auto PMONITOR = g_pCompositor->getMonitorFromString(POINTER->boundOutput); PMONITOR) {
|
2024-07-29 16:27:09 +02:00
|
|
|
currentMonitor = PMONITOR->self.lock();
|
|
|
|
mappedArea = currentMonitor->logicalBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-05-05 23:18:10 +02:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
damageIfSoftware();
|
|
|
|
|
2024-05-06 03:15:26 +02:00
|
|
|
if (std::isnan(abs.x) || std::isnan(abs.y)) {
|
|
|
|
pointerPos.x = std::isnan(abs.x) ? pointerPos.x : mappedArea.x + mappedArea.w * abs.x;
|
|
|
|
pointerPos.y = std::isnan(abs.y) ? pointerPos.y : mappedArea.y + mappedArea.h * abs.y;
|
|
|
|
} else
|
|
|
|
pointerPos = mappedArea.pos() + mappedArea.size() * abs;
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
onCursorMoved();
|
|
|
|
recheckEnteredOutputs();
|
|
|
|
|
|
|
|
damageIfSoftware();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::onMonitorLayoutChange() {
|
|
|
|
currentMonitorLayout.monitorBoxes.clear();
|
2024-08-26 20:24:30 +02:00
|
|
|
for (auto const& m : g_pCompositor->m_vMonitors) {
|
2024-09-11 10:30:21 +02:00
|
|
|
if (m->isMirror() || !m->m_bEnabled || !m->output)
|
2024-05-05 23:18:10 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
currentMonitorLayout.monitorBoxes.emplace_back(CBox{m->vecPosition, m->vecSize});
|
|
|
|
}
|
|
|
|
|
|
|
|
damageIfSoftware();
|
|
|
|
|
|
|
|
pointerPos = closestValid(pointerPos);
|
|
|
|
updateCursorBackend();
|
|
|
|
recheckEnteredOutputs();
|
|
|
|
|
|
|
|
damageIfSoftware();
|
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
SP<CTexture> CPointerManager::getCurrentCursorTexture() {
|
2024-07-31 21:47:26 +02:00
|
|
|
if (!currentCursorImage.pBuffer && (!currentCursorImage.surface || !currentCursorImage.surface->resource()->current.texture))
|
2024-05-05 23:18:10 +02:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if (currentCursorImage.pBuffer) {
|
2024-07-21 13:09:54 +02:00
|
|
|
if (!currentCursorImage.bufferTex)
|
|
|
|
currentCursorImage.bufferTex = makeShared<CTexture>(currentCursorImage.pBuffer);
|
2024-06-08 10:07:59 +02:00
|
|
|
return currentCursorImage.bufferTex;
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
2024-07-31 21:47:26 +02:00
|
|
|
return currentCursorImage.surface->resource()->current.texture;
|
2024-05-05 23:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::attachPointer(SP<IPointer> pointer) {
|
|
|
|
if (!pointer)
|
|
|
|
return;
|
|
|
|
|
2024-09-09 22:29:00 +02:00
|
|
|
static auto PMOUSEDPMS = CConfigValue<Hyprlang::INT>("misc:mouse_move_enables_dpms");
|
|
|
|
|
|
|
|
//
|
2024-05-05 23:18:10 +02:00
|
|
|
auto listener = pointerListeners.emplace_back(makeShared<SPointerListener>());
|
|
|
|
|
|
|
|
listener->pointer = pointer;
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
listener->destroy = pointer->events.destroy.registerListener([this] (std::any d) {
|
|
|
|
detachPointer(nullptr);
|
|
|
|
});
|
|
|
|
|
|
|
|
listener->motion = pointer->pointerEvents.motion.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SMotionEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onMouseMoved(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-09-09 22:29:00 +02:00
|
|
|
|
|
|
|
if (!g_pCompositor->m_bDPMSStateON && *PMOUSEDPMS)
|
|
|
|
g_pKeybindManager->dpms("on");
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->motionAbsolute = pointer->pointerEvents.motionAbsolute.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SMotionAbsoluteEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onMouseWarp(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-09-09 22:29:00 +02:00
|
|
|
|
|
|
|
if (!g_pCompositor->m_bDPMSStateON && *PMOUSEDPMS)
|
|
|
|
g_pKeybindManager->dpms("on");
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->button = pointer->pointerEvents.button.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SButtonEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onMouseButton(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->axis = pointer->pointerEvents.axis.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SAxisEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onMouseWheel(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->frame = pointer->pointerEvents.frame.registerListener([this] (std::any e) {
|
2024-05-10 19:27:57 +02:00
|
|
|
g_pSeatManager->sendPointerFrame();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->swipeBegin = pointer->pointerEvents.swipeBegin.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SSwipeBeginEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onSwipeBegin(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-09-09 22:29:00 +02:00
|
|
|
|
|
|
|
if (!g_pCompositor->m_bDPMSStateON && *PMOUSEDPMS)
|
|
|
|
g_pKeybindManager->dpms("on");
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->swipeEnd = pointer->pointerEvents.swipeEnd.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SSwipeEndEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onSwipeEnd(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->swipeUpdate = pointer->pointerEvents.swipeUpdate.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SSwipeUpdateEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onSwipeUpdate(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->pinchBegin = pointer->pointerEvents.pinchBegin.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SPinchBeginEvent>(e);
|
|
|
|
|
|
|
|
PROTO::pointerGestures->pinchBegin(E.timeMs, E.fingers);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-09-09 22:29:00 +02:00
|
|
|
|
|
|
|
if (!g_pCompositor->m_bDPMSStateON && *PMOUSEDPMS)
|
|
|
|
g_pKeybindManager->dpms("on");
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->pinchEnd = pointer->pointerEvents.pinchEnd.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SPinchEndEvent>(e);
|
|
|
|
|
|
|
|
PROTO::pointerGestures->pinchEnd(E.timeMs, E.cancelled);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->pinchUpdate = pointer->pointerEvents.pinchUpdate.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SPinchUpdateEvent>(e);
|
|
|
|
|
|
|
|
PROTO::pointerGestures->pinchUpdate(E.timeMs, E.delta, E.scale, E.rotation);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->holdBegin = pointer->pointerEvents.holdBegin.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SHoldBeginEvent>(e);
|
|
|
|
|
|
|
|
PROTO::pointerGestures->holdBegin(E.timeMs, E.fingers);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->holdEnd = pointer->pointerEvents.holdEnd.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<IPointer::SHoldEndEvent>(e);
|
|
|
|
|
|
|
|
PROTO::pointerGestures->holdEnd(E.timeMs, E.cancelled);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
Debug::log(LOG, "Attached pointer {} to global", pointer->hlName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::attachTouch(SP<ITouch> touch) {
|
|
|
|
if (!touch)
|
|
|
|
return;
|
|
|
|
|
2024-09-09 22:29:00 +02:00
|
|
|
static auto PMOUSEDPMS = CConfigValue<Hyprlang::INT>("misc:mouse_move_enables_dpms");
|
|
|
|
|
|
|
|
//
|
2024-05-05 23:18:10 +02:00
|
|
|
auto listener = touchListeners.emplace_back(makeShared<STouchListener>());
|
|
|
|
|
|
|
|
listener->touch = touch;
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
listener->destroy = touch->events.destroy.registerListener([this] (std::any d) {
|
|
|
|
detachTouch(nullptr);
|
|
|
|
});
|
|
|
|
|
|
|
|
listener->down = touch->touchEvents.down.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<ITouch::SDownEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onTouchDown(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-09-09 22:29:00 +02:00
|
|
|
|
|
|
|
if (!g_pCompositor->m_bDPMSStateON && *PMOUSEDPMS)
|
|
|
|
g_pKeybindManager->dpms("on");
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->up = touch->touchEvents.up.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<ITouch::SUpEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onTouchUp(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->motion = touch->touchEvents.motion.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<ITouch::SMotionEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onTouchMove(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->cancel = touch->touchEvents.cancel.registerListener([this] (std::any e) {
|
|
|
|
//
|
|
|
|
});
|
|
|
|
|
|
|
|
listener->frame = touch->touchEvents.frame.registerListener([this] (std::any e) {
|
2024-05-10 19:27:57 +02:00
|
|
|
g_pSeatManager->sendTouchFrame();
|
2024-05-05 23:18:10 +02:00
|
|
|
});
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
Debug::log(LOG, "Attached touch {} to global", touch->hlName);
|
|
|
|
}
|
|
|
|
|
2024-05-06 03:15:26 +02:00
|
|
|
void CPointerManager::attachTablet(SP<CTablet> tablet) {
|
|
|
|
if (!tablet)
|
|
|
|
return;
|
|
|
|
|
2024-09-09 22:29:00 +02:00
|
|
|
static auto PMOUSEDPMS = CConfigValue<Hyprlang::INT>("misc:mouse_move_enables_dpms");
|
|
|
|
|
|
|
|
//
|
2024-05-06 03:15:26 +02:00
|
|
|
auto listener = tabletListeners.emplace_back(makeShared<STabletListener>());
|
|
|
|
|
|
|
|
listener->tablet = tablet;
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
listener->destroy = tablet->events.destroy.registerListener([this] (std::any d) {
|
|
|
|
detachTablet(nullptr);
|
|
|
|
});
|
|
|
|
|
|
|
|
listener->axis = tablet->tabletEvents.axis.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<CTablet::SAxisEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onTabletAxis(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-09-09 22:29:00 +02:00
|
|
|
|
|
|
|
if (!g_pCompositor->m_bDPMSStateON && *PMOUSEDPMS)
|
|
|
|
g_pKeybindManager->dpms("on");
|
2024-05-06 03:15:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->proximity = tablet->tabletEvents.proximity.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<CTablet::SProximityEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onTabletProximity(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-06 03:15:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->tip = tablet->tabletEvents.tip.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<CTablet::STipEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onTabletTip(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-09-09 22:29:00 +02:00
|
|
|
|
|
|
|
if (!g_pCompositor->m_bDPMSStateON && *PMOUSEDPMS)
|
|
|
|
g_pKeybindManager->dpms("on");
|
2024-05-06 03:15:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
listener->button = tablet->tabletEvents.button.registerListener([this] (std::any e) {
|
|
|
|
auto E = std::any_cast<CTablet::SButtonEvent>(e);
|
|
|
|
|
|
|
|
g_pInputManager->onTabletButton(E);
|
2024-09-06 01:58:57 +02:00
|
|
|
|
|
|
|
PROTO::idle->onActivity();
|
2024-05-06 03:15:26 +02:00
|
|
|
});
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
Debug::log(LOG, "Attached tablet {} to global", tablet->hlName);
|
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
void CPointerManager::detachPointer(SP<IPointer> pointer) {
|
|
|
|
std::erase_if(pointerListeners, [pointer](const auto& e) { return e->pointer.expired() || e->pointer == pointer; });
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPointerManager::detachTouch(SP<ITouch> touch) {
|
|
|
|
std::erase_if(touchListeners, [touch](const auto& e) { return e->touch.expired() || e->touch == touch; });
|
|
|
|
}
|
|
|
|
|
2024-05-06 03:15:26 +02:00
|
|
|
void CPointerManager::detachTablet(SP<CTablet> tablet) {
|
|
|
|
std::erase_if(tabletListeners, [tablet](const auto& e) { return e->tablet.expired() || e->tablet == tablet; });
|
|
|
|
}
|
|
|
|
|
2024-05-05 23:18:10 +02:00
|
|
|
void CPointerManager::damageCursor(SP<CMonitor> pMonitor) {
|
2024-08-26 17:25:39 +02:00
|
|
|
for (auto const& mw : monitorStates) {
|
2024-05-05 23:18:10 +02:00
|
|
|
if (mw->monitor != pMonitor)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto b = getCursorBoxGlobal().intersection(pMonitor->logicalBox());
|
|
|
|
|
|
|
|
if (b.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_pHyprRenderer->damageBox(&b);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2024-05-11 18:13:20 +02:00
|
|
|
|
|
|
|
Vector2D CPointerManager::cursorSizeLogical() {
|
|
|
|
return currentCursorImage.size / currentCursorImage.scale;
|
|
|
|
}
|