diff --git a/effects/zoom/accessibilityintegration.cpp b/effects/zoom/accessibilityintegration.cpp index 088c7c407..ec31894fc 100644 --- a/effects/zoom/accessibilityintegration.cpp +++ b/effects/zoom/accessibilityintegration.cpp @@ -1,91 +1,110 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2020 Vlad Zahorodnii This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "accessibilityintegration.h" using namespace QAccessibleClient; // Whatever, sue me... namespace KWin { ZoomAccessibilityIntegration::ZoomAccessibilityIntegration(QObject *parent) : QObject(parent) { } void ZoomAccessibilityIntegration::setFocusTrackingEnabled(bool enabled) { if (m_isFocusTrackingEnabled == enabled) { return; } m_isFocusTrackingEnabled = enabled; updateAccessibilityRegistry(); } bool ZoomAccessibilityIntegration::isFocusTrackingEnabled() const { return m_isFocusTrackingEnabled; } +void ZoomAccessibilityIntegration::setTextCaretTrackingEnabled(bool enabled) +{ + if (m_isTextCaretTrackingEnabled == enabled) { + return; + } + m_isTextCaretTrackingEnabled = enabled; + updateAccessibilityRegistry(); +} + +bool ZoomAccessibilityIntegration::isTextCaretTrackingEnabled() const +{ + return m_isTextCaretTrackingEnabled; +} + void ZoomAccessibilityIntegration::updateAccessibilityRegistry() { Registry::EventListeners eventListeners = Registry::NoEventListeners; + if (isTextCaretTrackingEnabled()) { + eventListeners |= Registry::TextCaretMoved; + } if (isFocusTrackingEnabled()) { eventListeners |= Registry::Focus; } if (eventListeners == Registry::NoEventListeners) { destroyAccessibilityRegistry(); return; } if (!m_accessibilityRegistry) { createAccessibilityRegistry(); } m_accessibilityRegistry->subscribeEventListeners(eventListeners); } void ZoomAccessibilityIntegration::createAccessibilityRegistry() { m_accessibilityRegistry = new Registry(this); + connect(m_accessibilityRegistry, &Registry::textCaretMoved, + this, &ZoomAccessibilityIntegration::slotFocusChanged); connect(m_accessibilityRegistry, &Registry::focusChanged, this, &ZoomAccessibilityIntegration::slotFocusChanged); } void ZoomAccessibilityIntegration::destroyAccessibilityRegistry() { if (!m_accessibilityRegistry) { return; } disconnect(m_accessibilityRegistry, nullptr, this, nullptr); m_accessibilityRegistry->deleteLater(); m_accessibilityRegistry = nullptr; } void ZoomAccessibilityIntegration::slotFocusChanged(const AccessibleObject &object) { emit focusPointChanged(object.focusPoint()); } } // namespace KWin diff --git a/effects/zoom/accessibilityintegration.h b/effects/zoom/accessibilityintegration.h index 99942177f..d753e333a 100644 --- a/effects/zoom/accessibilityintegration.h +++ b/effects/zoom/accessibilityintegration.h @@ -1,53 +1,57 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2020 Vlad Zahorodnii This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #pragma once #include namespace KWin { class ZoomAccessibilityIntegration : public QObject { Q_OBJECT public: explicit ZoomAccessibilityIntegration(QObject *parent = nullptr); void setFocusTrackingEnabled(bool enabled); bool isFocusTrackingEnabled() const; + void setTextCaretTrackingEnabled(bool enabled); + bool isTextCaretTrackingEnabled() const; + Q_SIGNALS: void focusPointChanged(const QPoint &point); private Q_SLOTS: void slotFocusChanged(const QAccessibleClient::AccessibleObject &object); private: void createAccessibilityRegistry(); void destroyAccessibilityRegistry(); void updateAccessibilityRegistry(); QAccessibleClient::Registry *m_accessibilityRegistry = nullptr; bool m_isFocusTrackingEnabled = false; + bool m_isTextCaretTrackingEnabled = false; }; } // namespace KWin diff --git a/effects/zoom/zoom.cpp b/effects/zoom/zoom.cpp index 95231a0a3..6e0fb60ad 100644 --- a/effects/zoom/zoom.cpp +++ b/effects/zoom/zoom.cpp @@ -1,529 +1,540 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2006 Lubos Lunak Copyright (C) 2010 Sebastian Sauer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "zoom.h" // KConfigSkeleton #include "zoomconfig.h" #if HAVE_ACCESSIBILITY #include "accessibilityintegration.h" #endif #include #include #include #include #include #include #include #include #include #ifdef KWIN_HAVE_XRENDER_COMPOSITING #include #include #endif namespace KWin { ZoomEffect::ZoomEffect() : Effect() , zoom(1) , target_zoom(1) , polling(false) , zoomFactor(1.25) , mouseTracking(MouseTrackingProportional) , mousePointer(MousePointerScale) , focusDelay(350) // in milliseconds , imageWidth(0) , imageHeight(0) , isMouseHidden(false) , xMove(0) , yMove(0) , moveFactor(20.0) { initConfig(); QAction* a = nullptr; a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_Equal); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_Equal); effects->registerGlobalShortcut(Qt::META + Qt::Key_Equal, a); effects->registerAxisShortcut(Qt::ControlModifier | Qt::MetaModifier, PointerAxisDown, a); a = KStandardAction::zoomOut(this, SLOT(zoomOut()), this); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_Minus); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_Minus); effects->registerGlobalShortcut(Qt::META + Qt::Key_Minus, a); effects->registerAxisShortcut(Qt::ControlModifier | Qt::MetaModifier, PointerAxisUp, a); a = KStandardAction::actualSize(this, SLOT(actualSize()), this); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_0); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_0); effects->registerGlobalShortcut(Qt::META + Qt::Key_0, a); a = new QAction(this); a->setObjectName(QStringLiteral("MoveZoomLeft")); a->setText(i18n("Move Zoomed Area to Left")); KGlobalAccel::self()->setDefaultShortcut(a, QList()); KGlobalAccel::self()->setShortcut(a, QList()); effects->registerGlobalShortcut(QKeySequence(), a); connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomLeft); a = new QAction(this); a->setObjectName(QStringLiteral("MoveZoomRight")); a->setText(i18n("Move Zoomed Area to Right")); KGlobalAccel::self()->setDefaultShortcut(a, QList()); KGlobalAccel::self()->setShortcut(a, QList()); effects->registerGlobalShortcut(QKeySequence(), a); connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomRight); a = new QAction(this); a->setObjectName(QStringLiteral("MoveZoomUp")); a->setText(i18n("Move Zoomed Area Upwards")); KGlobalAccel::self()->setDefaultShortcut(a, QList()); KGlobalAccel::self()->setShortcut(a, QList()); effects->registerGlobalShortcut(QKeySequence(), a); connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomUp); a = new QAction(this); a->setObjectName(QStringLiteral("MoveZoomDown")); a->setText(i18n("Move Zoomed Area Downwards")); KGlobalAccel::self()->setDefaultShortcut(a, QList()); KGlobalAccel::self()->setShortcut(a, QList()); effects->registerGlobalShortcut(QKeySequence(), a); connect(a, &QAction::triggered, this, &ZoomEffect::moveZoomDown); // TODO: these two actions don't belong into the effect. They need to be moved into KWin core a = new QAction(this); a->setObjectName(QStringLiteral("MoveMouseToFocus")); a->setText(i18n("Move Mouse to Focus")); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_F5); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_F5); effects->registerGlobalShortcut(Qt::META + Qt::Key_F5, a); connect(a, &QAction::triggered, this, &ZoomEffect::moveMouseToFocus); a = new QAction(this); a->setObjectName(QStringLiteral("MoveMouseToCenter")); a->setText(i18n("Move Mouse to Center")); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_F6); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_F6); effects->registerGlobalShortcut(Qt::META + Qt::Key_F6, a); connect(a, &QAction::triggered, this, &ZoomEffect::moveMouseToCenter); timeline.setDuration(350); timeline.setFrameRange(0, 100); connect(&timeline, &QTimeLine::frameChanged, this, &ZoomEffect::timelineFrameChanged); connect(effects, &EffectsHandler::mouseChanged, this, &ZoomEffect::slotMouseChanged); #if HAVE_ACCESSIBILITY m_accessibilityIntegration = new ZoomAccessibilityIntegration(this); connect(m_accessibilityIntegration, &ZoomAccessibilityIntegration::focusPointChanged, this, &ZoomEffect::moveFocus); #endif source_zoom = -1; // used to trigger initialZoom reading reconfigure(ReconfigureAll); } ZoomEffect::~ZoomEffect() { // switch off and free resources showCursor(); // Save the zoom value. ZoomConfig::setInitialZoom(target_zoom); ZoomConfig::self()->save(); } bool ZoomEffect::isFocusTrackingEnabled() const { #if HAVE_ACCESSIBILITY return m_accessibilityIntegration->isFocusTrackingEnabled(); #else return false; #endif } +bool ZoomEffect::isTextCaretTrackingEnabled() const +{ +#if HAVE_ACCESSIBILITY + return m_accessibilityIntegration->isTextCaretTrackingEnabled(); +#else + return false; +#endif +} + void ZoomEffect::showCursor() { if (isMouseHidden) { disconnect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::recreateTexture); // show the previously hidden mouse-pointer again and free the loaded texture/picture. effects->showCursor(); texture.reset(); #ifdef KWIN_HAVE_XRENDER_COMPOSITING xrenderPicture.reset(); #endif isMouseHidden = false; } } void ZoomEffect::hideCursor() { if (mouseTracking == MouseTrackingProportional && mousePointer == MousePointerKeep) return; // don't replace the actual cursor by a static image for no reason. if (!isMouseHidden) { // try to load the cursor-theme into a OpenGL texture and if successful then hide the mouse-pointer recreateTexture(); bool shouldHide = false; if (effects->isOpenGLCompositing()) { shouldHide = !texture.isNull(); } else if (effects->compositingType() == XRenderCompositing) { #ifdef KWIN_HAVE_XRENDER_COMPOSITING shouldHide = !xrenderPicture.isNull(); #endif } if (shouldHide) { effects->hideCursor(); connect(effects, &EffectsHandler::cursorShapeChanged, this, &ZoomEffect::recreateTexture); 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); } #ifdef KWIN_HAVE_XRENDER_COMPOSITING if (effects->compositingType() == XRenderCompositing) xrenderPicture.reset(new XRenderPicture(cursor.image())); #endif } else { qCDebug(KWINEFFECTS) << "Falling back to proportional mouse tracking!"; mouseTracking = MouseTrackingProportional; } } void ZoomEffect::reconfigure(ReconfigureFlags) { ZoomConfig::self()->read(); // On zoom-in and zoom-out change the zoom by the defined zoom-factor. zoomFactor = qMax(0.1, ZoomConfig::zoomFactor()); // Visibility of the mouse-pointer. mousePointer = MousePointerType(ZoomConfig::mousePointer()); // Track moving of the mouse. mouseTracking = MouseTrackingType(ZoomConfig::mouseTracking()); #if HAVE_ACCESSIBILITY // Enable tracking of the focused location. m_accessibilityIntegration->setFocusTrackingEnabled(ZoomConfig::enableFocusTracking()); + // Enable tracking of the text caret. + m_accessibilityIntegration->setTextCaretTrackingEnabled(ZoomConfig::enableTextCaretTracking()); #endif // The time in milliseconds to wait before a focus-event takes away a mouse-move. focusDelay = qMax(uint(0), ZoomConfig::focusDelay()); // The factor the zoom-area will be moved on touching an edge on push-mode or using the navigation KAction's. moveFactor = qMax(0.1, ZoomConfig::moveFactor()); if (source_zoom < 0) { // Load the saved zoom value. source_zoom = 1.0; target_zoom = ZoomConfig::initialZoom(); if (target_zoom > 1.0) zoomIn(target_zoom); } else { source_zoom = 1.0; } } void ZoomEffect::prePaintScreen(ScreenPrePaintData& data, int time) { if (zoom != target_zoom) { const float zoomDist = qAbs(target_zoom - source_zoom); if (target_zoom > zoom) zoom = qMin(zoom + ((zoomDist * time) / animationTime(150*zoomFactor)), target_zoom); else zoom = qMax(zoom - ((zoomDist * time) / animationTime(150*zoomFactor)), target_zoom); } if (zoom == 1.0) { showCursor(); } else { hideCursor(); data.mask |= PAINT_SCREEN_TRANSFORMED; } effects->prePaintScreen(data, time); } void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data) { if (zoom != 1.0) { data *= QVector2D(zoom, zoom); const QSize screenSize = effects->virtualScreenSize(); // mouse-tracking allows navigation of the zoom-area using the mouse. switch(mouseTracking) { case MouseTrackingProportional: data.setXTranslation(- int(cursorPoint.x() * (zoom - 1.0))); data.setYTranslation(- int(cursorPoint.y() * (zoom - 1.0))); prevPoint = cursorPoint; break; case MouseTrackingCentred: prevPoint = cursorPoint; // fall through case MouseTrackingDisabled: data.setXTranslation(qMin(0, qMax(int(screenSize.width() - screenSize.width() * zoom), int(screenSize.width() / 2 - prevPoint.x() * zoom)))); data.setYTranslation(qMin(0, qMax(int(screenSize.height() - screenSize.height() * zoom), int(screenSize.height() / 2 - prevPoint.y() * zoom)))); break; case MouseTrackingPush: { // touching an edge of the screen moves the zoom-area in that direction. int x = cursorPoint.x() * zoom - prevPoint.x() * (zoom - 1.0); int y = cursorPoint.y() * zoom - prevPoint.y() * (zoom - 1.0); int threshold = 4; xMove = yMove = 0; if (x < threshold) xMove = (x - threshold) / zoom; else if (x + threshold > screenSize.width()) xMove = (x + threshold - screenSize.width()) / zoom; if (y < threshold) yMove = (y - threshold) / zoom; else if (y + threshold > screenSize.height()) yMove = (y + threshold - screenSize.height()) / zoom; if (xMove) prevPoint.setX(qMax(0, qMin(screenSize.width(), prevPoint.x() + xMove))); if (yMove) prevPoint.setY(qMax(0, qMin(screenSize.height(), prevPoint.y() + yMove))); data.setXTranslation(- int(prevPoint.x() * (zoom - 1.0))); data.setYTranslation(- int(prevPoint.y() * (zoom - 1.0))); break; } } // use the focusPoint if focus tracking is enabled - if (isFocusTrackingEnabled()) { + if (isFocusTrackingEnabled() || isTextCaretTrackingEnabled()) { bool acceptFocus = true; if (mouseTracking != MouseTrackingDisabled && focusDelay > 0) { // Wait some time for the mouse before doing the switch. This serves as threshold // to prevent the focus from jumping around to much while working with the mouse. const int msecs = lastMouseEvent.msecsTo(lastFocusEvent); acceptFocus = msecs > focusDelay; } if (acceptFocus) { data.setXTranslation(- int(focusPoint.x() * (zoom - 1.0))); data.setYTranslation(- int(focusPoint.y() * (zoom - 1.0))); prevPoint = focusPoint; } } } effects->paintScreen(mask, region, data); if (zoom != 1.0 && 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. int w = imageWidth; int h = imageHeight; if (mousePointer == MousePointerScale) { w *= zoom; h *= zoom; } const QPoint p = effects->cursorPos() - cursorHotSpot; QRect rect(p.x() * zoom + data.xTranslation(), p.y() * zoom + data.yTranslation(), w, h); if (texture) { texture->bind(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); auto s = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture); QMatrix4x4 mvp = data.projectionMatrix(); mvp.translate(rect.x(), rect.y()); s->setUniform(GLShader::ModelViewProjectionMatrix, mvp); texture->render(region, rect); ShaderManager::instance()->popShader(); texture->unbind(); glDisable(GL_BLEND); } #ifdef KWIN_HAVE_XRENDER_COMPOSITING if (xrenderPicture) { #define DOUBLE_TO_FIXED(d) ((xcb_render_fixed_t) ((d) * 65536)) static const xcb_render_transform_t xrenderIdentity = { DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1) }; if (mousePointer == MousePointerScale) { xcb_render_set_picture_filter(xcbConnection(), *xrenderPicture, 4, const_cast("good"), 0, nullptr); const xcb_render_transform_t xform = { DOUBLE_TO_FIXED(1.0 / zoom), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1.0 / zoom), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(0), DOUBLE_TO_FIXED(1) }; xcb_render_set_picture_transform(xcbConnection(), *xrenderPicture, xform); } xcb_render_composite(xcbConnection(), XCB_RENDER_PICT_OP_OVER, *xrenderPicture, XCB_RENDER_PICTURE_NONE, effects->xrenderBufferPicture(), 0, 0, 0, 0, rect.x(), rect.y(), rect.width(), rect.height()); if (mousePointer == MousePointerScale) xcb_render_set_picture_transform(xcbConnection(), *xrenderPicture, xrenderIdentity); #undef DOUBLE_TO_FIXED } #endif } } void ZoomEffect::postPaintScreen() { if (zoom != target_zoom) effects->addRepaintFull(); effects->postPaintScreen(); } void ZoomEffect::zoomIn(double to) { source_zoom = zoom; if (to < 0.0) target_zoom *= zoomFactor; else target_zoom = to; if (!polling) { polling = true; effects->startMousePolling(); } cursorPoint = effects->cursorPos(); if (mouseTracking == MouseTrackingDisabled) prevPoint = cursorPoint; effects->addRepaintFull(); } void ZoomEffect::zoomOut() { source_zoom = zoom; target_zoom /= zoomFactor; if ((zoomFactor > 1 && target_zoom < 1.01) || (zoomFactor < 1 && target_zoom > 0.99)) { target_zoom = 1; if (polling) { polling = false; effects->stopMousePolling(); } } if (mouseTracking == MouseTrackingDisabled) prevPoint = effects->cursorPos(); effects->addRepaintFull(); } void ZoomEffect::actualSize() { source_zoom = zoom; target_zoom = 1; if (polling) { polling = false; effects->stopMousePolling(); } effects->addRepaintFull(); } void ZoomEffect::timelineFrameChanged(int /* frame */) { const QSize screenSize = effects->virtualScreenSize(); prevPoint.setX(qMax(0, qMin(screenSize.width(), prevPoint.x() + xMove))); prevPoint.setY(qMax(0, qMin(screenSize.height(), prevPoint.y() + yMove))); cursorPoint = prevPoint; effects->addRepaintFull(); } void ZoomEffect::moveZoom(int x, int y) { if (timeline.state() == QTimeLine::Running) timeline.stop(); const QSize screenSize = effects->virtualScreenSize(); if (x < 0) xMove = - qMax(1.0, screenSize.width() / zoom / moveFactor); else if (x > 0) xMove = qMax(1.0, screenSize.width() / zoom / moveFactor); else xMove = 0; if (y < 0) yMove = - qMax(1.0, screenSize.height() / zoom / moveFactor); else if (y > 0) yMove = qMax(1.0, screenSize.height() / zoom / moveFactor); else yMove = 0; timeline.start(); } void ZoomEffect::moveZoomLeft() { moveZoom(-1, 0); } void ZoomEffect::moveZoomRight() { moveZoom(1, 0); } void ZoomEffect::moveZoomUp() { moveZoom(0, -1); } void ZoomEffect::moveZoomDown() { moveZoom(0, 1); } void ZoomEffect::moveMouseToFocus() { QCursor::setPos(focusPoint.x(), focusPoint.y()); } void ZoomEffect::moveMouseToCenter() { const QRect r = effects->virtualScreenGeometry(); QCursor::setPos(r.x() + r.width() / 2, r.y() + r.height() / 2); } void ZoomEffect::slotMouseChanged(const QPoint& pos, const QPoint& old, Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers) { if (zoom == 1.0) return; cursorPoint = pos; if (pos != old) { lastMouseEvent = QTime::currentTime(); effects->addRepaintFull(); } } void ZoomEffect::moveFocus(const QPoint &point) { if (zoom == 1.0) return; focusPoint = point; lastFocusEvent = QTime::currentTime(); effects->addRepaintFull(); } bool ZoomEffect::isActive() const { return zoom != 1.0 || zoom != target_zoom; } } // namespace diff --git a/effects/zoom/zoom.h b/effects/zoom/zoom.h index 2c7bff41a..14b0211e2 100644 --- a/effects/zoom/zoom.h +++ b/effects/zoom/zoom.h @@ -1,135 +1,137 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2006 Lubos Lunak Copyright (C) 2010 Sebastian Sauer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #ifndef KWIN_ZOOM_H #define KWIN_ZOOM_H #include #include #include #include namespace KWin { #if HAVE_ACCESSIBILITY class ZoomAccessibilityIntegration; #endif class GLTexture; class XRenderPicture; class ZoomEffect : public Effect { Q_OBJECT Q_PROPERTY(qreal zoomFactor READ configuredZoomFactor) Q_PROPERTY(int mousePointer READ configuredMousePointer) Q_PROPERTY(int mouseTracking READ configuredMouseTracking) Q_PROPERTY(bool focusTrackingEnabled READ isFocusTrackingEnabled) + Q_PROPERTY(bool textCaretTrackingEnabled READ isTextCaretTrackingEnabled) Q_PROPERTY(int focusDelay READ configuredFocusDelay) Q_PROPERTY(qreal moveFactor READ configuredMoveFactor) Q_PROPERTY(qreal targetZoom READ targetZoom) public: ZoomEffect(); ~ZoomEffect() override; void reconfigure(ReconfigureFlags flags) override; void prePaintScreen(ScreenPrePaintData& data, int time) override; void paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data) override; void postPaintScreen() override; bool isActive() const override; // for properties qreal configuredZoomFactor() const { return zoomFactor; } int configuredMousePointer() const { return mousePointer; } int configuredMouseTracking() const { return mouseTracking; } bool isFocusTrackingEnabled() const; + bool isTextCaretTrackingEnabled() const; int configuredFocusDelay() const { return focusDelay; } qreal configuredMoveFactor() const { return moveFactor; } qreal targetZoom() const { return target_zoom; } private Q_SLOTS: inline void zoomIn() { zoomIn(-1.0); }; void zoomIn(double to); void zoomOut(); void actualSize(); void moveZoomLeft(); void moveZoomRight(); void moveZoomUp(); void moveZoomDown(); void moveMouseToFocus(); void moveMouseToCenter(); void timelineFrameChanged(int frame); void moveFocus(const QPoint &point); void slotMouseChanged(const QPoint& pos, const QPoint& old, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); void recreateTexture(); private: void showCursor(); void hideCursor(); void moveZoom(int x, int y); private: #if HAVE_ACCESSIBILITY ZoomAccessibilityIntegration *m_accessibilityIntegration = nullptr; #endif double zoom; double target_zoom; double source_zoom; bool polling; // Mouse polling double zoomFactor; enum MouseTrackingType { MouseTrackingProportional = 0, MouseTrackingCentred = 1, MouseTrackingPush = 2, MouseTrackingDisabled = 3 }; MouseTrackingType mouseTracking; enum MousePointerType { MousePointerScale = 0, MousePointerKeep = 1, MousePointerHide = 2 }; MousePointerType mousePointer; int focusDelay; QPoint cursorPoint; QPoint cursorHotSpot; QPoint focusPoint; QPoint prevPoint; QTime lastMouseEvent; QTime lastFocusEvent; QScopedPointer texture; #ifdef KWIN_HAVE_XRENDER_COMPOSITING QScopedPointer xrenderPicture; #endif int imageWidth; int imageHeight; bool isMouseHidden; QTimeLine timeline; int xMove, yMove; double moveFactor; }; } // namespace #endif diff --git a/effects/zoom/zoom.kcfg b/effects/zoom/zoom.kcfg index af37db08e..97a022dc3 100644 --- a/effects/zoom/zoom.kcfg +++ b/effects/zoom/zoom.kcfg @@ -1,31 +1,33 @@ 1.2 0 0 false + + false 350 20.0 1.0 diff --git a/effects/zoom/zoom_config.cpp b/effects/zoom/zoom_config.cpp index 9fc1f8610..d3f7984a2 100644 --- a/effects/zoom/zoom_config.cpp +++ b/effects/zoom/zoom_config.cpp @@ -1,154 +1,155 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2007 Rivo Laks Copyright (C) 2010 Sebastian Sauer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "zoom_config.h" // KConfigSkeleton #include "zoomconfig.h" #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY_WITH_JSON(ZoomEffectConfigFactory, "zoom_config.json", registerPlugin();) namespace KWin { ZoomEffectConfigForm::ZoomEffectConfigForm(QWidget* parent) : QWidget(parent) { setupUi(this); } ZoomEffectConfig::ZoomEffectConfig(QWidget* parent, const QVariantList& args) : KCModule(KAboutData::pluginData(QStringLiteral("zoom")), parent, args) { ZoomConfig::instance(KWIN_CONFIG); m_ui = new ZoomEffectConfigForm(this); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(m_ui); addConfig(ZoomConfig::self(), m_ui); connect(m_ui->editor, &KShortcutsEditor::keyChange, this, &ZoomEffectConfig::markAsChanged); #if !HAVE_ACCESSIBILITY m_ui->kcfg_EnableFocusTracking->setVisible(false); + m_ui->kcfg_EnableTextCaretTracking->setVisible(false); #endif // Shortcut config. The shortcut belongs to the component "kwin"! KActionCollection *actionCollection = new KActionCollection(this, QStringLiteral("kwin")); actionCollection->setComponentDisplayName(i18n("KWin")); actionCollection->setConfigGroup(QStringLiteral("Zoom")); actionCollection->setConfigGlobal(true); QAction* a; a = actionCollection->addAction(KStandardAction::ZoomIn); a->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_Equal); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_Equal); a = actionCollection->addAction(KStandardAction::ZoomOut); a->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_Minus); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_Minus); a = actionCollection->addAction(KStandardAction::ActualSize); a->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_0); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_0); a = actionCollection->addAction(QStringLiteral("MoveZoomLeft")); a->setIcon(QIcon::fromTheme(QStringLiteral("go-previous"))); a->setText(i18n("Move Left")); a->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::CTRL + Qt::Key_Left); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::CTRL + Qt::Key_Left); a = actionCollection->addAction(QStringLiteral("MoveZoomRight")); a->setIcon(QIcon::fromTheme(QStringLiteral("go-next"))); a->setText(i18n("Move Right")); a->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::CTRL + Qt::Key_Right); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::CTRL + Qt::Key_Right); a = actionCollection->addAction(QStringLiteral("MoveZoomUp")); a->setIcon(QIcon::fromTheme(QStringLiteral("go-up"))); a->setText(i18n("Move Up")); a->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::CTRL + Qt::Key_Up); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::CTRL + Qt::Key_Up); a = actionCollection->addAction(QStringLiteral("MoveZoomDown")); a->setIcon(QIcon::fromTheme(QStringLiteral("go-down"))); a->setText(i18n("Move Down")); a->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::CTRL + Qt::Key_Down); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::CTRL + Qt::Key_Down); a = actionCollection->addAction(QStringLiteral("MoveMouseToFocus")); a->setIcon(QIcon::fromTheme(QStringLiteral("view-restore"))); a->setText(i18n("Move Mouse to Focus")); a->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_F5); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_F5); a = actionCollection->addAction(QStringLiteral("MoveMouseToCenter")); a->setIcon(QIcon::fromTheme(QStringLiteral("view-restore"))); a->setText(i18n("Move Mouse to Center")); a->setProperty("isConfigurationAction", true); KGlobalAccel::self()->setDefaultShortcut(a, QList() << Qt::META + Qt::Key_F6); KGlobalAccel::self()->setShortcut(a, QList() << Qt::META + Qt::Key_F6); m_ui->editor->addCollection(actionCollection); load(); } ZoomEffectConfig::~ZoomEffectConfig() { // Undo (only) unsaved changes to global key shortcuts m_ui->editor->undoChanges(); } void ZoomEffectConfig::save() { m_ui->editor->save(); // undo() will restore to this state from now on KCModule::save(); OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Effects"), QDBusConnection::sessionBus()); interface.reconfigureEffect(QStringLiteral("zoom")); } } // namespace #include "zoom_config.moc" diff --git a/effects/zoom/zoom_config.ui b/effects/zoom/zoom_config.ui index 5b387b2a4..df941a7d1 100644 --- a/effects/zoom/zoom_config.ui +++ b/effects/zoom/zoom_config.ui @@ -1,181 +1,192 @@ KWin::ZoomEffectConfigForm 0 0 304 288 On zoom-in and zoom-out change the zoom by the defined zoom-factor. Zoom Factor: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter kcfg_ZoomFactor On zoom-in and zoom-out change the zoom by the defined zoom-factor. 2 9999.000000000000000 0.050000000000000 1.250000000000000 Enable tracking of the focused location. This needs QAccessible to be enabled per application ("export QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1"). Enable Focus Tracking + + + + Enable tracking of the text cursor. This needs QAccessible to be enabled per application ("export QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1"). + + + Enable Text Cursor Tracking + + + Mouse Pointer: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter kcfg_MousePointer Visibility of the mouse-pointer. Scale Keep Hide Track moving of the mouse. Proportional Centered Push Disabled Mouse Tracking: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter kcfg_MouseTracking 0 0 KShortcutsEditor QWidget
kshortcutseditor.h
1
kcfg_ZoomFactor kcfg_MousePointer kcfg_MouseTracking kcfg_EnableFocusTracking + kcfg_EnableTextCaretTracking