Revert "plugins/zoom: Port to CursorItem"

This reverts commit e40f632c9b.

It broke non default mouse tracking modes. There are just too many
options, so revert the change instead.
This commit is contained in:
Vlad Zahorodnii 2024-03-10 12:36:00 +02:00
parent af7388c8a3
commit 93326f3e50
2 changed files with 71 additions and 23 deletions

View file

@ -26,11 +26,8 @@
#include "core/rendertarget.h" #include "core/rendertarget.h"
#include "core/renderviewport.h" #include "core/renderviewport.h"
#include "cursor.h"
#include "effect/effecthandler.h" #include "effect/effecthandler.h"
#include "opengl/glutils.h" #include "opengl/glutils.h"
#include "scene/cursoritem.h"
#include "scene/workspacescene.h"
using namespace std::chrono_literals; using namespace std::chrono_literals;
@ -46,6 +43,7 @@ ZoomEffect::ZoomEffect()
, mouseTracking(MouseTrackingProportional) , mouseTracking(MouseTrackingProportional)
, mousePointer(MousePointerScale) , mousePointer(MousePointerScale)
, focusDelay(350) // in milliseconds , focusDelay(350) // in milliseconds
, isMouseHidden(false)
, xMove(0) , xMove(0)
, yMove(0) , yMove(0)
, moveFactor(20.0) , moveFactor(20.0)
@ -161,12 +159,36 @@ bool ZoomEffect::isTextCaretTrackingEnabled() const
#endif #endif
} }
GLTexture *ZoomEffect::ensureCursorTexture()
{
if (!m_cursorTexture || m_cursorTextureDirty) {
m_cursorTexture.reset();
m_cursorTextureDirty = false;
const auto cursor = effects->cursorImage();
if (!cursor.image().isNull()) {
m_cursorTexture = GLTexture::upload(cursor.image());
if (!m_cursorTexture) {
return nullptr;
}
m_cursorTexture->setWrapMode(GL_CLAMP_TO_EDGE);
}
}
return m_cursorTexture.get();
}
void ZoomEffect::markCursorTextureDirty()
{
m_cursorTextureDirty = true;
}
void ZoomEffect::showCursor() void ZoomEffect::showCursor()
{ {
if (m_cursorHidden) { if (isMouseHidden) {
m_cursorItem.reset(); disconnect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::markCursorTextureDirty);
m_cursorHidden = false; // show the previously hidden mouse-pointer again and free the loaded texture/picture.
effects->showCursor(); effects->showCursor();
m_cursorTexture.reset();
isMouseHidden = false;
} }
} }
@ -175,17 +197,16 @@ void ZoomEffect::hideCursor()
if (mouseTracking == MouseTrackingProportional && mousePointer == MousePointerKeep) { if (mouseTracking == MouseTrackingProportional && mousePointer == MousePointerKeep) {
return; // don't replace the actual cursor by a static image for no reason. return; // don't replace the actual cursor by a static image for no reason.
} }
if (!m_cursorHidden) { if (!isMouseHidden) {
effects->hideCursor(); // try to load the cursor-theme into a OpenGL texture and if successful then hide the mouse-pointer
m_cursorHidden = true; GLTexture *texture = nullptr;
if (effects->isOpenGLCompositing()) {
if (mousePointer == MousePointerKeep || mousePointer == MousePointerScale) { texture = ensureCursorTexture();
Cursor *cursor = Cursors::self()->mouse(); }
m_cursorItem = std::make_unique<CursorItem>(effects->scene()->overlayItem()); if (texture) {
m_cursorItem->setPosition(cursor->pos()); effects->hideCursor();
connect(cursor, &Cursor::posChanged, m_cursorItem.get(), [this, cursor]() { connect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::markCursorTextureDirty);
m_cursorItem->setPosition(cursor->pos()); isMouseHidden = true;
});
} }
} }
} }
@ -245,9 +266,6 @@ void ZoomEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseco
showCursor(); showCursor();
} else { } else {
hideCursor(); hideCursor();
if (mousePointer == MousePointerScale) {
m_cursorItem->setTransform(QTransform::fromScale(zoom, zoom));
}
} }
effects->prePaintScreen(data, presentTime); effects->prePaintScreen(data, presentTime);
@ -386,6 +404,34 @@ void ZoomEffect::paintScreen(const RenderTarget &renderTarget, const RenderViewp
offscreen.texture->render(offscreen.viewport.size() * scale); offscreen.texture->render(offscreen.viewport.size() * scale);
} }
ShaderManager::instance()->popShader(); ShaderManager::instance()->popShader();
if (mousePointer != MousePointerHide) {
// Draw the mouse-texture at the position matching to zoomed-in image of the desktop. Hiding the
// previous mouse-cursor and drawing our own fake mouse-cursor is needed to be able to scale the
// mouse-cursor up and to re-position those mouse-cursor to match to the chosen zoom-level.
GLTexture *cursorTexture = ensureCursorTexture();
if (cursorTexture) {
const auto cursor = effects->cursorImage();
QSizeF cursorSize = QSizeF(cursor.image().size()) / cursor.image().devicePixelRatio();
if (mousePointer == MousePointerScale) {
cursorSize *= zoom;
}
const QPointF p = (effects->cursorPos() - cursor.hotSpot()) * zoom + QPoint(xTranslation, yTranslation);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
auto s = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture | ShaderTrait::TransformColorspace);
s->setColorspaceUniformsFromSRGB(renderTarget.colorDescription());
QMatrix4x4 mvp = viewport.projectionMatrix();
mvp.translate(p.x() * scale, p.y() * scale);
s->setUniform(GLShader::Mat4Uniform::ModelViewProjectionMatrix, mvp);
cursorTexture->render(cursorSize * scale);
ShaderManager::instance()->popShader();
glDisable(GL_BLEND);
}
}
} }
void ZoomEffect::postPaintScreen() void ZoomEffect::postPaintScreen()

View file

@ -23,7 +23,6 @@ namespace KWin
class ZoomAccessibilityIntegration; class ZoomAccessibilityIntegration;
#endif #endif
class CursorItem;
class GLFramebuffer; class GLFramebuffer;
class GLTexture; class GLTexture;
class GLVertexBuffer; class GLVertexBuffer;
@ -97,7 +96,9 @@ private:
QRect viewport; QRect viewport;
}; };
GLTexture *ensureCursorTexture();
OffscreenData *ensureOffscreenData(const RenderTarget &renderTarget, const RenderViewport &viewport, Output *screen); OffscreenData *ensureOffscreenData(const RenderTarget &renderTarget, const RenderViewport &viewport, Output *screen);
void markCursorTextureDirty();
#if HAVE_ACCESSIBILITY #if HAVE_ACCESSIBILITY
ZoomAccessibilityIntegration *m_accessibilityIntegration = nullptr; ZoomAccessibilityIntegration *m_accessibilityIntegration = nullptr;
@ -126,8 +127,9 @@ private:
QPoint prevPoint; QPoint prevPoint;
QTime lastMouseEvent; QTime lastMouseEvent;
QTime lastFocusEvent; QTime lastFocusEvent;
std::unique_ptr<CursorItem> m_cursorItem; std::unique_ptr<GLTexture> m_cursorTexture;
bool m_cursorHidden = false; bool m_cursorTextureDirty = false;
bool isMouseHidden;
QTimeLine timeline; QTimeLine timeline;
int xMove, yMove; int xMove, yMove;
double moveFactor; double moveFactor;