|
|
@ -39,8 +39,6 @@ ZoomEffect::ZoomEffect()
|
|
|
|
, mouseTracking(MouseTrackingProportional)
|
|
|
|
, mouseTracking(MouseTrackingProportional)
|
|
|
|
, mousePointer(MousePointerScale)
|
|
|
|
, mousePointer(MousePointerScale)
|
|
|
|
, focusDelay(350) // in milliseconds
|
|
|
|
, focusDelay(350) // in milliseconds
|
|
|
|
, imageWidth(0)
|
|
|
|
|
|
|
|
, imageHeight(0)
|
|
|
|
|
|
|
|
, isMouseHidden(false)
|
|
|
|
, isMouseHidden(false)
|
|
|
|
, xMove(0)
|
|
|
|
, xMove(0)
|
|
|
|
, yMove(0)
|
|
|
|
, yMove(0)
|
|
|
@ -157,13 +155,32 @@ 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.reset(new GLTexture(cursor.image()));
|
|
|
|
|
|
|
|
m_cursorTexture->setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_cursorTexture.data();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ZoomEffect::markCursorTextureDirty()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_cursorTextureDirty = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZoomEffect::showCursor()
|
|
|
|
void ZoomEffect::showCursor()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (isMouseHidden) {
|
|
|
|
if (isMouseHidden) {
|
|
|
|
disconnect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::recreateTexture);
|
|
|
|
disconnect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::markCursorTextureDirty);
|
|
|
|
// show the previously hidden mouse-pointer again and free the loaded texture/picture.
|
|
|
|
// show the previously hidden mouse-pointer again and free the loaded texture/picture.
|
|
|
|
effects->showCursor();
|
|
|
|
effects->showCursor();
|
|
|
|
texture.reset();
|
|
|
|
m_cursorTexture.reset();
|
|
|
|
isMouseHidden = false;
|
|
|
|
isMouseHidden = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -174,38 +191,18 @@ void ZoomEffect::hideCursor()
|
|
|
|
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 (!isMouseHidden) {
|
|
|
|
if (!isMouseHidden) {
|
|
|
|
// try to load the cursor-theme into a OpenGL texture and if successful then hide the mouse-pointer
|
|
|
|
// try to load the cursor-theme into a OpenGL texture and if successful then hide the mouse-pointer
|
|
|
|
recreateTexture();
|
|
|
|
GLTexture *texture = nullptr;
|
|
|
|
bool shouldHide = false;
|
|
|
|
|
|
|
|
if (effects->isOpenGLCompositing()) {
|
|
|
|
if (effects->isOpenGLCompositing()) {
|
|
|
|
shouldHide = !texture.isNull();
|
|
|
|
texture = ensureCursorTexture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (shouldHide) {
|
|
|
|
if (texture) {
|
|
|
|
effects->hideCursor();
|
|
|
|
effects->hideCursor();
|
|
|
|
connect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::recreateTexture);
|
|
|
|
connect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::markCursorTextureDirty);
|
|
|
|
isMouseHidden = true;
|
|
|
|
isMouseHidden = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZoomEffect::recreateTexture()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
effects->makeOpenGLContextCurrent();
|
|
|
|
|
|
|
|
const auto cursor = effects->cursorImage();
|
|
|
|
|
|
|
|
if (!cursor.image().isNull()) {
|
|
|
|
|
|
|
|
imageWidth = cursor.image().width();
|
|
|
|
|
|
|
|
imageHeight = cursor.image().height();
|
|
|
|
|
|
|
|
cursorHotSpot = cursor.hotSpot();
|
|
|
|
|
|
|
|
if (effects->isOpenGLCompositing()) {
|
|
|
|
|
|
|
|
texture.reset(new GLTexture(cursor.image()));
|
|
|
|
|
|
|
|
texture->setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
qCDebug(KWINEFFECTS) << "Falling back to proportional mouse tracking!";
|
|
|
|
|
|
|
|
mouseTracking = MouseTrackingProportional;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ZoomEffect::reconfigure(ReconfigureFlags)
|
|
|
|
void ZoomEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ZoomConfig::self()->read();
|
|
|
|
ZoomConfig::self()->read();
|
|
|
@ -325,29 +322,31 @@ void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& d
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
|
|
|
|
|
|
|
|
if (zoom != 1.0 && mousePointer != MousePointerHide) {
|
|
|
|
if (zoom != 1.0 && mousePointer != MousePointerHide) {
|
|
|
|
// Draw the mouse-texture at the position matching to zoomed-in image of the desktop. Hiding the
|
|
|
|
GLTexture *cursorTexture = ensureCursorTexture();
|
|
|
|
// previous mouse-cursor and drawing our own fake mouse-cursor is needed to be able to scale the
|
|
|
|
if (cursorTexture) {
|
|
|
|
// mouse-cursor up and to re-position those mouse-cursor to match to the chosen zoom-level.
|
|
|
|
const auto cursor = effects->cursorImage();
|
|
|
|
int w = imageWidth;
|
|
|
|
|
|
|
|
int h = imageHeight;
|
|
|
|
// Draw the mouse-texture at the position matching to zoomed-in image of the desktop. Hiding the
|
|
|
|
if (mousePointer == MousePointerScale) {
|
|
|
|
// previous mouse-cursor and drawing our own fake mouse-cursor is needed to be able to scale the
|
|
|
|
w *= zoom;
|
|
|
|
// mouse-cursor up and to re-position those mouse-cursor to match to the chosen zoom-level.
|
|
|
|
h *= zoom;
|
|
|
|
QSize cursorSize = cursor.image().size() / cursor.image().devicePixelRatio();
|
|
|
|
}
|
|
|
|
if (mousePointer == MousePointerScale) {
|
|
|
|
const QPoint p = effects->cursorPos() - cursorHotSpot;
|
|
|
|
cursorSize *= zoom;
|
|
|
|
QRect rect(p.x() * zoom + data.xTranslation(), p.y() * zoom + data.yTranslation(), w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (texture) {
|
|
|
|
const QPoint p = effects->cursorPos() - cursor.hotSpot();
|
|
|
|
texture->bind();
|
|
|
|
QRect rect(p * zoom + QPoint(data.xTranslation(), data.yTranslation()), cursorSize);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cursorTexture->bind();
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
auto s = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
|
|
|
auto s = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
|
|
|
QMatrix4x4 mvp = data.projectionMatrix();
|
|
|
|
QMatrix4x4 mvp = data.projectionMatrix();
|
|
|
|
mvp.translate(rect.x(), rect.y());
|
|
|
|
mvp.translate(rect.x(), rect.y());
|
|
|
|
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
|
|
|
s->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
|
|
|
texture->render(region, rect);
|
|
|
|
cursorTexture->render(region, rect);
|
|
|
|
ShaderManager::instance()->popShader();
|
|
|
|
ShaderManager::instance()->popShader();
|
|
|
|
texture->unbind();
|
|
|
|
cursorTexture->unbind();
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|