File indexing completed on 2024-11-10 04:57:13
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2006 Lubos Lunak <l.lunak@kde.org> 0006 SPDX-FileCopyrightText: 2010 Sebastian Sauer <sebsauer@kdab.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #pragma once 0012 0013 #include <config-kwin.h> 0014 0015 #include "effect/effect.h" 0016 #include <QTime> 0017 #include <QTimeLine> 0018 0019 namespace KWin 0020 { 0021 0022 #if HAVE_ACCESSIBILITY 0023 class ZoomAccessibilityIntegration; 0024 #endif 0025 0026 class GLFramebuffer; 0027 class GLTexture; 0028 class GLVertexBuffer; 0029 0030 class ZoomEffect 0031 : public Effect 0032 { 0033 Q_OBJECT 0034 Q_PROPERTY(qreal zoomFactor READ configuredZoomFactor) 0035 Q_PROPERTY(int mousePointer READ configuredMousePointer) 0036 Q_PROPERTY(int mouseTracking READ configuredMouseTracking) 0037 Q_PROPERTY(bool focusTrackingEnabled READ isFocusTrackingEnabled) 0038 Q_PROPERTY(bool textCaretTrackingEnabled READ isTextCaretTrackingEnabled) 0039 Q_PROPERTY(int focusDelay READ configuredFocusDelay) 0040 Q_PROPERTY(qreal moveFactor READ configuredMoveFactor) 0041 Q_PROPERTY(qreal targetZoom READ targetZoom) 0042 public: 0043 ZoomEffect(); 0044 ~ZoomEffect() override; 0045 void reconfigure(ReconfigureFlags flags) override; 0046 void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override; 0047 void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen) override; 0048 void postPaintScreen() override; 0049 bool isActive() const override; 0050 int requestedEffectChainPosition() const override; 0051 // for properties 0052 qreal configuredZoomFactor() const; 0053 int configuredMousePointer() const; 0054 int configuredMouseTracking() const; 0055 bool isFocusTrackingEnabled() const; 0056 bool isTextCaretTrackingEnabled() const; 0057 int configuredFocusDelay() const; 0058 qreal configuredMoveFactor() const; 0059 qreal targetZoom() const; 0060 private Q_SLOTS: 0061 inline void zoomIn() 0062 { 0063 zoomIn(-1.0); 0064 }; 0065 void zoomIn(double to); 0066 void zoomOut(); 0067 void actualSize(); 0068 void moveZoomLeft(); 0069 void moveZoomRight(); 0070 void moveZoomUp(); 0071 void moveZoomDown(); 0072 void moveMouseToFocus(); 0073 void moveMouseToCenter(); 0074 void timelineFrameChanged(int frame); 0075 void moveFocus(const QPoint &point); 0076 void slotMouseChanged(const QPointF &pos, const QPointF &old, 0077 Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, 0078 Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); 0079 void slotWindowAdded(EffectWindow *w); 0080 void slotWindowDamaged(); 0081 void slotScreenRemoved(Output *screen); 0082 0083 private: 0084 void showCursor(); 0085 void hideCursor(); 0086 void moveZoom(int x, int y); 0087 0088 private: 0089 struct OffscreenData 0090 { 0091 std::unique_ptr<GLTexture> texture; 0092 std::unique_ptr<GLFramebuffer> framebuffer; 0093 QRect viewport; 0094 }; 0095 0096 GLTexture *ensureCursorTexture(); 0097 OffscreenData *ensureOffscreenData(const RenderTarget &renderTarget, const RenderViewport &viewport, Output *screen); 0098 void markCursorTextureDirty(); 0099 0100 #if HAVE_ACCESSIBILITY 0101 ZoomAccessibilityIntegration *m_accessibilityIntegration = nullptr; 0102 #endif 0103 double zoom; 0104 double target_zoom; 0105 double source_zoom; 0106 bool polling; // Mouse polling 0107 double zoomFactor; 0108 enum MouseTrackingType { 0109 MouseTrackingProportional = 0, 0110 MouseTrackingCentred = 1, 0111 MouseTrackingPush = 2, 0112 MouseTrackingDisabled = 3, 0113 }; 0114 MouseTrackingType mouseTracking; 0115 enum MousePointerType { 0116 MousePointerScale = 0, 0117 MousePointerKeep = 1, 0118 MousePointerHide = 2, 0119 }; 0120 MousePointerType mousePointer; 0121 int focusDelay; 0122 QPoint cursorPoint; 0123 QPoint focusPoint; 0124 QPoint prevPoint; 0125 QTime lastMouseEvent; 0126 QTime lastFocusEvent; 0127 std::unique_ptr<GLTexture> m_cursorTexture; 0128 bool m_cursorTextureDirty = false; 0129 bool isMouseHidden; 0130 QTimeLine timeline; 0131 int xMove, yMove; 0132 double moveFactor; 0133 std::chrono::milliseconds lastPresentTime; 0134 std::map<Output *, OffscreenData> m_offscreenData; 0135 }; 0136 0137 } // namespace