effects: modernize some code
Mostly port away from manual memory management and clean up some headers
This commit is contained in:
parent
24dfdd70c0
commit
84acb768ee
52 changed files with 568 additions and 628 deletions
|
@ -1576,9 +1576,9 @@ KWaylandServer::Display *EffectsHandlerImpl::waylandDisplay() const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
EffectFrame *EffectsHandlerImpl::effectFrame(EffectFrameStyle style, bool staticSize, const QPoint &position, Qt::Alignment alignment) const
|
||||
std::unique_ptr<EffectFrame> EffectsHandlerImpl::effectFrame(EffectFrameStyle style, bool staticSize, const QPoint &position, Qt::Alignment alignment) const
|
||||
{
|
||||
return new EffectFrameImpl(style, staticSize, position, alignment);
|
||||
return std::make_unique<EffectFrameImpl>(style, staticSize, position, alignment);
|
||||
}
|
||||
|
||||
QVariant EffectsHandlerImpl::kwinOption(KWinOption kwopt)
|
||||
|
|
|
@ -166,7 +166,7 @@ public:
|
|||
|
||||
bool decorationsHaveAlpha() const override;
|
||||
|
||||
EffectFrame *effectFrame(EffectFrameStyle style, bool staticSize, const QPoint &position, Qt::Alignment alignment) const override;
|
||||
std::unique_ptr<EffectFrame> effectFrame(EffectFrameStyle style, bool staticSize, const QPoint &position, Qt::Alignment alignment) const override;
|
||||
|
||||
QVariant kwinOption(KWinOption kwopt) override;
|
||||
bool isScreenLocked() const override;
|
||||
|
|
|
@ -29,14 +29,14 @@ QTimer *ContrastEffect::s_contrastManagerRemoveTimer = nullptr;
|
|||
|
||||
ContrastEffect::ContrastEffect()
|
||||
{
|
||||
shader = ContrastShader::create();
|
||||
shader->init();
|
||||
m_shader = std::make_unique<ContrastShader>();
|
||||
m_shader->init();
|
||||
|
||||
// ### Hackish way to announce support.
|
||||
// Should be included in _NET_SUPPORTED instead.
|
||||
if (shader && shader->isValid()) {
|
||||
if (m_shader && m_shader->isValid()) {
|
||||
if (effects->xcbConnection()) {
|
||||
net_wm_contrast_region = effects->announceSupportProperty(s_contrastAtomName, this);
|
||||
m_net_wm_contrast_region = effects->announceSupportProperty(s_contrastAtomName, this);
|
||||
}
|
||||
if (effects->waylandDisplay()) {
|
||||
if (!s_contrastManagerRemoveTimer) {
|
||||
|
@ -59,8 +59,8 @@ ContrastEffect::ContrastEffect()
|
|||
connect(effects, &EffectsHandler::propertyNotify, this, &ContrastEffect::slotPropertyNotify);
|
||||
connect(effects, &EffectsHandler::virtualScreenGeometryChanged, this, &ContrastEffect::slotScreenGeometryChanged);
|
||||
connect(effects, &EffectsHandler::xcbConnectionChanged, this, [this]() {
|
||||
if (shader && shader->isValid()) {
|
||||
net_wm_contrast_region = effects->announceSupportProperty(s_contrastAtomName, this);
|
||||
if (m_shader && m_shader->isValid()) {
|
||||
m_net_wm_contrast_region = effects->announceSupportProperty(s_contrastAtomName, this);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -77,7 +77,6 @@ ContrastEffect::~ContrastEffect()
|
|||
if (s_contrastManager) {
|
||||
s_contrastManagerRemoveTimer->start(1000);
|
||||
}
|
||||
delete shader;
|
||||
}
|
||||
|
||||
void ContrastEffect::slotScreenGeometryChanged()
|
||||
|
@ -100,8 +99,8 @@ void ContrastEffect::updateContrastRegion(EffectWindow *w)
|
|||
float colorTransform[16];
|
||||
bool valid = false;
|
||||
|
||||
if (net_wm_contrast_region != XCB_ATOM_NONE) {
|
||||
const QByteArray value = w->readProperty(net_wm_contrast_region, net_wm_contrast_region, 32);
|
||||
if (m_net_wm_contrast_region != XCB_ATOM_NONE) {
|
||||
const QByteArray value = w->readProperty(m_net_wm_contrast_region, m_net_wm_contrast_region, 32);
|
||||
|
||||
if (value.size() > 0 && !((value.size() - (16 * sizeof(uint32_t))) % ((4 * sizeof(uint32_t))))) {
|
||||
const uint32_t *cardinals = reinterpret_cast<const uint32_t *>(value.constData());
|
||||
|
@ -211,7 +210,7 @@ void ContrastEffect::slotWindowDeleted(EffectWindow *w)
|
|||
|
||||
void ContrastEffect::slotPropertyNotify(EffectWindow *w, long atom)
|
||||
{
|
||||
if (w && atom == net_wm_contrast_region && net_wm_contrast_region != XCB_ATOM_NONE) {
|
||||
if (w && atom == m_net_wm_contrast_region && m_net_wm_contrast_region != XCB_ATOM_NONE) {
|
||||
updateContrastRegion(w);
|
||||
}
|
||||
}
|
||||
|
@ -347,7 +346,7 @@ void ContrastEffect::uploadGeometry(GLVertexBuffer *vbo, const QRegion ®ion)
|
|||
|
||||
bool ContrastEffect::shouldContrast(const EffectWindow *w, int mask, const WindowPaintData &data) const
|
||||
{
|
||||
if (!shader || !shader->isValid()) {
|
||||
if (!m_shader || !m_shader->isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -435,17 +434,17 @@ void ContrastEffect::doContrast(EffectWindow *w, const QRegion &shape, const QRe
|
|||
|
||||
// Draw the texture on the offscreen framebuffer object, while blurring it horizontally
|
||||
|
||||
shader->setColorMatrix(m_colorMatrices.value(w));
|
||||
shader->bind();
|
||||
m_shader->setColorMatrix(m_colorMatrices.value(w));
|
||||
m_shader->bind();
|
||||
|
||||
shader->setOpacity(opacity);
|
||||
m_shader->setOpacity(opacity);
|
||||
// Set up the texture matrix to transform from screen coordinates
|
||||
// to texture coordinates.
|
||||
QMatrix4x4 textureMatrix;
|
||||
textureMatrix.scale(1.0 / r.width(), -1.0 / r.height(), 1);
|
||||
textureMatrix.translate(-r.x(), -r.height() - r.y(), 0);
|
||||
shader->setTextureMatrix(textureMatrix);
|
||||
shader->setModelViewProjectionMatrix(screenProjection);
|
||||
m_shader->setTextureMatrix(textureMatrix);
|
||||
m_shader->setModelViewProjectionMatrix(screenProjection);
|
||||
|
||||
vbo->draw(GL_TRIANGLES, 0, actualShape.rectCount() * 6);
|
||||
|
||||
|
@ -458,7 +457,7 @@ void ContrastEffect::doContrast(EffectWindow *w, const QRegion &shape, const QRe
|
|||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
shader->unbind();
|
||||
m_shader->unbind();
|
||||
}
|
||||
|
||||
bool ContrastEffect::isActive() const
|
||||
|
|
|
@ -65,8 +65,8 @@ private:
|
|||
void uploadGeometry(GLVertexBuffer *vbo, const QRegion ®ion);
|
||||
|
||||
private:
|
||||
ContrastShader *shader;
|
||||
long net_wm_contrast_region = 0;
|
||||
std::unique_ptr<ContrastShader> m_shader;
|
||||
long m_net_wm_contrast_region = 0;
|
||||
QHash<const EffectWindow *, QMatrix4x4> m_colorMatrices;
|
||||
QHash<const EffectWindow *, QMetaObject::Connection> m_contrastChangedConnections; // used only in Wayland to keep track of effect changed
|
||||
static KWaylandServer::ContrastManagerInterface *s_contrastManager;
|
||||
|
|
|
@ -21,26 +21,15 @@ namespace KWin
|
|||
{
|
||||
|
||||
ContrastShader::ContrastShader()
|
||||
: mValid(false)
|
||||
, shader(nullptr)
|
||||
: m_valid(false)
|
||||
, m_shader(nullptr)
|
||||
, m_opacity(1)
|
||||
{
|
||||
}
|
||||
|
||||
ContrastShader::~ContrastShader()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
ContrastShader *ContrastShader::create()
|
||||
{
|
||||
return new ContrastShader();
|
||||
}
|
||||
|
||||
void ContrastShader::reset()
|
||||
{
|
||||
delete shader;
|
||||
shader = nullptr;
|
||||
m_shader.reset();
|
||||
|
||||
setIsValid(false);
|
||||
}
|
||||
|
@ -49,8 +38,8 @@ void ContrastShader::setOpacity(float opacity)
|
|||
{
|
||||
m_opacity = opacity;
|
||||
|
||||
ShaderManager::instance()->pushShader(shader);
|
||||
shader->setUniform(opacityLocation, opacity);
|
||||
ShaderManager::instance()->pushShader(m_shader.get());
|
||||
m_shader->setUniform(m_opacityLocation, opacity);
|
||||
ShaderManager::instance()->popShader();
|
||||
}
|
||||
|
||||
|
@ -65,8 +54,8 @@ void ContrastShader::setColorMatrix(const QMatrix4x4 &matrix)
|
|||
return;
|
||||
}
|
||||
|
||||
ShaderManager::instance()->pushShader(shader);
|
||||
shader->setUniform(colorMatrixLocation, matrix);
|
||||
ShaderManager::instance()->pushShader(m_shader.get());
|
||||
m_shader->setUniform(m_colorMatrixLocation, matrix);
|
||||
ShaderManager::instance()->popShader();
|
||||
}
|
||||
|
||||
|
@ -76,7 +65,7 @@ void ContrastShader::setTextureMatrix(const QMatrix4x4 &matrix)
|
|||
return;
|
||||
}
|
||||
|
||||
shader->setUniform(textureMatrixLocation, matrix);
|
||||
m_shader->setUniform(m_textureMatrixLocation, matrix);
|
||||
}
|
||||
|
||||
void ContrastShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix)
|
||||
|
@ -85,7 +74,7 @@ void ContrastShader::setModelViewProjectionMatrix(const QMatrix4x4 &matrix)
|
|||
return;
|
||||
}
|
||||
|
||||
shader->setUniform(mvpMatrixLocation, matrix);
|
||||
m_shader->setUniform(m_mvpMatrixLocation, matrix);
|
||||
}
|
||||
|
||||
void ContrastShader::bind()
|
||||
|
@ -94,7 +83,7 @@ void ContrastShader::bind()
|
|||
return;
|
||||
}
|
||||
|
||||
ShaderManager::instance()->pushShader(shader);
|
||||
ShaderManager::instance()->pushShader(m_shader.get());
|
||||
}
|
||||
|
||||
void ContrastShader::unbind()
|
||||
|
@ -179,26 +168,36 @@ void ContrastShader::init()
|
|||
stream2 << "}\n";
|
||||
stream2.flush();
|
||||
|
||||
shader = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentSource);
|
||||
m_shader = ShaderManager::instance()->loadShaderFromCode(vertexSource, fragmentSource);
|
||||
|
||||
if (shader->isValid()) {
|
||||
colorMatrixLocation = shader->uniformLocation("colorMatrix");
|
||||
textureMatrixLocation = shader->uniformLocation("textureMatrix");
|
||||
mvpMatrixLocation = shader->uniformLocation("modelViewProjectionMatrix");
|
||||
opacityLocation = shader->uniformLocation("opacity");
|
||||
if (m_shader->isValid()) {
|
||||
m_colorMatrixLocation = m_shader->uniformLocation("colorMatrix");
|
||||
m_textureMatrixLocation = m_shader->uniformLocation("textureMatrix");
|
||||
m_mvpMatrixLocation = m_shader->uniformLocation("modelViewProjectionMatrix");
|
||||
m_opacityLocation = m_shader->uniformLocation("opacity");
|
||||
|
||||
QMatrix4x4 modelViewProjection;
|
||||
const QSize screenSize = effects->virtualScreenSize();
|
||||
modelViewProjection.ortho(0, screenSize.width(), screenSize.height(), 0, 0, 65535);
|
||||
ShaderManager::instance()->pushShader(shader);
|
||||
shader->setUniform(colorMatrixLocation, QMatrix4x4());
|
||||
shader->setUniform(textureMatrixLocation, QMatrix4x4());
|
||||
shader->setUniform(mvpMatrixLocation, modelViewProjection);
|
||||
shader->setUniform(opacityLocation, (float)1.0);
|
||||
ShaderManager::instance()->pushShader(m_shader.get());
|
||||
m_shader->setUniform(m_colorMatrixLocation, QMatrix4x4());
|
||||
m_shader->setUniform(m_textureMatrixLocation, QMatrix4x4());
|
||||
m_shader->setUniform(m_mvpMatrixLocation, modelViewProjection);
|
||||
m_shader->setUniform(m_opacityLocation, (float)1.0);
|
||||
ShaderManager::instance()->popShader();
|
||||
}
|
||||
|
||||
setIsValid(shader->isValid());
|
||||
setIsValid(m_shader->isValid());
|
||||
}
|
||||
|
||||
void ContrastShader::setIsValid(bool value)
|
||||
{
|
||||
m_valid = value;
|
||||
}
|
||||
|
||||
bool ContrastShader::isValid() const
|
||||
{
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -19,42 +19,30 @@ class ContrastShader
|
|||
{
|
||||
public:
|
||||
ContrastShader();
|
||||
virtual ~ContrastShader();
|
||||
|
||||
void init();
|
||||
|
||||
static ContrastShader *create();
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return mValid;
|
||||
}
|
||||
|
||||
void setColorMatrix(const QMatrix4x4 &matrix);
|
||||
|
||||
void setTextureMatrix(const QMatrix4x4 &matrix);
|
||||
void setModelViewProjectionMatrix(const QMatrix4x4 &matrix);
|
||||
void setOpacity(float opacity);
|
||||
|
||||
float opacity() const;
|
||||
bool isValid() const;
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
|
||||
void setOpacity(float opacity);
|
||||
float opacity() const;
|
||||
|
||||
protected:
|
||||
void setIsValid(bool value)
|
||||
{
|
||||
mValid = value;
|
||||
}
|
||||
void setIsValid(bool value);
|
||||
void reset();
|
||||
|
||||
private:
|
||||
bool mValid;
|
||||
GLShader *shader;
|
||||
int mvpMatrixLocation;
|
||||
int textureMatrixLocation;
|
||||
int colorMatrixLocation;
|
||||
int opacityLocation;
|
||||
bool m_valid;
|
||||
std::unique_ptr<GLShader> m_shader;
|
||||
int m_mvpMatrixLocation;
|
||||
int m_textureMatrixLocation;
|
||||
int m_colorMatrixLocation;
|
||||
int m_opacityLocation;
|
||||
float m_opacity;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,25 +23,25 @@ BlurShader::BlurShader(QObject *parent)
|
|||
{
|
||||
ensureResources();
|
||||
|
||||
m_shaderDownsample.reset(ShaderManager::instance()->generateShaderFromFile(
|
||||
m_shaderDownsample = ShaderManager::instance()->generateShaderFromFile(
|
||||
ShaderTrait::MapTexture,
|
||||
QStringLiteral(":/effects/blur/shaders/vertex.vert"),
|
||||
QStringLiteral(":/effects/blur/shaders/downsample.frag")));
|
||||
QStringLiteral(":/effects/blur/shaders/downsample.frag"));
|
||||
|
||||
m_shaderUpsample.reset(ShaderManager::instance()->generateShaderFromFile(
|
||||
m_shaderUpsample = ShaderManager::instance()->generateShaderFromFile(
|
||||
ShaderTrait::MapTexture,
|
||||
QStringLiteral(":/effects/blur/shaders/vertex.vert"),
|
||||
QStringLiteral(":/effects/blur/shaders/upsample.frag")));
|
||||
QStringLiteral(":/effects/blur/shaders/upsample.frag"));
|
||||
|
||||
m_shaderCopysample.reset(ShaderManager::instance()->generateShaderFromFile(
|
||||
m_shaderCopysample = ShaderManager::instance()->generateShaderFromFile(
|
||||
ShaderTrait::MapTexture,
|
||||
QStringLiteral(":/effects/blur/shaders/vertex.vert"),
|
||||
QStringLiteral(":/effects/blur/shaders/copy.frag")));
|
||||
QStringLiteral(":/effects/blur/shaders/copy.frag"));
|
||||
|
||||
m_shaderNoisesample.reset(ShaderManager::instance()->generateShaderFromFile(
|
||||
m_shaderNoisesample = ShaderManager::instance()->generateShaderFromFile(
|
||||
ShaderTrait::MapTexture,
|
||||
QStringLiteral(":/effects/blur/shaders/vertex.vert"),
|
||||
QStringLiteral(":/effects/blur/shaders/noise.frag")));
|
||||
QStringLiteral(":/effects/blur/shaders/noise.frag"));
|
||||
|
||||
m_valid = m_shaderDownsample->isValid() && m_shaderUpsample->isValid() && m_shaderCopysample->isValid() && m_shaderNoisesample->isValid();
|
||||
|
||||
|
@ -72,27 +72,27 @@ BlurShader::BlurShader(QObject *parent)
|
|||
modelViewProjection.ortho(0, screenSize.width(), screenSize.height(), 0, 0, 65535);
|
||||
|
||||
// Add default values to the uniforms of the shaders
|
||||
ShaderManager::instance()->pushShader(m_shaderDownsample.data());
|
||||
ShaderManager::instance()->pushShader(m_shaderDownsample.get());
|
||||
m_shaderDownsample->setUniform(m_mvpMatrixLocationDownsample, modelViewProjection);
|
||||
m_shaderDownsample->setUniform(m_offsetLocationDownsample, float(1.0));
|
||||
m_shaderDownsample->setUniform(m_renderTextureSizeLocationDownsample, QVector2D(1.0, 1.0));
|
||||
m_shaderDownsample->setUniform(m_halfpixelLocationDownsample, QVector2D(1.0, 1.0));
|
||||
ShaderManager::instance()->popShader();
|
||||
|
||||
ShaderManager::instance()->pushShader(m_shaderUpsample.data());
|
||||
ShaderManager::instance()->pushShader(m_shaderUpsample.get());
|
||||
m_shaderUpsample->setUniform(m_mvpMatrixLocationUpsample, modelViewProjection);
|
||||
m_shaderUpsample->setUniform(m_offsetLocationUpsample, float(1.0));
|
||||
m_shaderUpsample->setUniform(m_renderTextureSizeLocationUpsample, QVector2D(1.0, 1.0));
|
||||
m_shaderUpsample->setUniform(m_halfpixelLocationUpsample, QVector2D(1.0, 1.0));
|
||||
ShaderManager::instance()->popShader();
|
||||
|
||||
ShaderManager::instance()->pushShader(m_shaderCopysample.data());
|
||||
ShaderManager::instance()->pushShader(m_shaderCopysample.get());
|
||||
m_shaderCopysample->setUniform(m_mvpMatrixLocationCopysample, modelViewProjection);
|
||||
m_shaderCopysample->setUniform(m_renderTextureSizeLocationCopysample, QVector2D(1.0, 1.0));
|
||||
m_shaderCopysample->setUniform(m_blurRectLocationCopysample, QVector4D(1.0, 1.0, 1.0, 1.0));
|
||||
ShaderManager::instance()->popShader();
|
||||
|
||||
ShaderManager::instance()->pushShader(m_shaderNoisesample.data());
|
||||
ShaderManager::instance()->pushShader(m_shaderNoisesample.get());
|
||||
m_shaderNoisesample->setUniform(m_mvpMatrixLocationNoisesample, modelViewProjection);
|
||||
m_shaderNoisesample->setUniform(m_offsetLocationNoisesample, float(1.0));
|
||||
m_shaderNoisesample->setUniform(m_renderTextureSizeLocationNoisesample, QVector2D(1.0, 1.0));
|
||||
|
@ -269,19 +269,19 @@ void BlurShader::bind(SampleType sampleType)
|
|||
|
||||
switch (sampleType) {
|
||||
case CopySampleType:
|
||||
ShaderManager::instance()->pushShader(m_shaderCopysample.data());
|
||||
ShaderManager::instance()->pushShader(m_shaderCopysample.get());
|
||||
break;
|
||||
|
||||
case UpSampleType:
|
||||
ShaderManager::instance()->pushShader(m_shaderUpsample.data());
|
||||
ShaderManager::instance()->pushShader(m_shaderUpsample.get());
|
||||
break;
|
||||
|
||||
case DownSampleType:
|
||||
ShaderManager::instance()->pushShader(m_shaderDownsample.data());
|
||||
ShaderManager::instance()->pushShader(m_shaderDownsample.get());
|
||||
break;
|
||||
|
||||
case NoiseSampleType:
|
||||
ShaderManager::instance()->pushShader(m_shaderNoisesample.data());
|
||||
ShaderManager::instance()->pushShader(m_shaderNoisesample.get());
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -47,10 +47,10 @@ public:
|
|||
void setBlurRect(const QRect &blurRect, const QSize &screenSize);
|
||||
|
||||
private:
|
||||
QScopedPointer<GLShader> m_shaderDownsample;
|
||||
QScopedPointer<GLShader> m_shaderUpsample;
|
||||
QScopedPointer<GLShader> m_shaderCopysample;
|
||||
QScopedPointer<GLShader> m_shaderNoisesample;
|
||||
std::unique_ptr<GLShader> m_shaderDownsample;
|
||||
std::unique_ptr<GLShader> m_shaderUpsample;
|
||||
std::unique_ptr<GLShader> m_shaderCopysample;
|
||||
std::unique_ptr<GLShader> m_shaderNoisesample;
|
||||
|
||||
int m_mvpMatrixLocationDownsample;
|
||||
int m_offsetLocationDownsample;
|
||||
|
|
|
@ -38,12 +38,10 @@ DesktopGridEffectConfigForm::DesktopGridEffectConfigForm(QWidget *parent)
|
|||
|
||||
DesktopGridEffectConfig::DesktopGridEffectConfig(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(parent, args)
|
||||
, m_ui(this)
|
||||
{
|
||||
m_ui = new DesktopGridEffectConfigForm(this);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
layout->addWidget(m_ui);
|
||||
layout->addWidget(&m_ui);
|
||||
|
||||
// Shortcut config. The shortcut belongs to the component "kwin"!
|
||||
m_actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
|
||||
|
@ -58,36 +56,36 @@ DesktopGridEffectConfig::DesktopGridEffectConfig(QWidget *parent, const QVariant
|
|||
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::CTRL | Qt::Key_F8));
|
||||
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::CTRL | Qt::Key_F8));
|
||||
|
||||
m_ui->shortcutEditor->addCollection(m_actionCollection);
|
||||
m_ui.shortcutEditor->addCollection(m_actionCollection);
|
||||
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18nc("Desktop name alignment:", "Disabled"), QVariant(Qt::Alignment()));
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18n("Top"), QVariant(Qt::AlignHCenter | Qt::AlignTop));
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18n("Top-Right"), QVariant(Qt::AlignRight | Qt::AlignTop));
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18n("Right"), QVariant(Qt::AlignRight | Qt::AlignVCenter));
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18n("Bottom-Right"), QVariant(Qt::AlignRight | Qt::AlignBottom));
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18n("Bottom"), QVariant(Qt::AlignHCenter | Qt::AlignBottom));
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18n("Bottom-Left"), QVariant(Qt::AlignLeft | Qt::AlignBottom));
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18n("Left"), QVariant(Qt::AlignLeft | Qt::AlignVCenter));
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18n("Top-Left"), QVariant(Qt::AlignLeft | Qt::AlignTop));
|
||||
m_ui->desktopNameAlignmentCombo->addItem(i18n("Center"), QVariant(Qt::AlignCenter));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18nc("Desktop name alignment:", "Disabled"), QVariant(Qt::Alignment()));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18n("Top"), QVariant(Qt::AlignHCenter | Qt::AlignTop));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18n("Top-Right"), QVariant(Qt::AlignRight | Qt::AlignTop));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18n("Right"), QVariant(Qt::AlignRight | Qt::AlignVCenter));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18n("Bottom-Right"), QVariant(Qt::AlignRight | Qt::AlignBottom));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18n("Bottom"), QVariant(Qt::AlignHCenter | Qt::AlignBottom));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18n("Bottom-Left"), QVariant(Qt::AlignLeft | Qt::AlignBottom));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18n("Left"), QVariant(Qt::AlignLeft | Qt::AlignVCenter));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18n("Top-Left"), QVariant(Qt::AlignLeft | Qt::AlignTop));
|
||||
m_ui.desktopNameAlignmentCombo->addItem(i18n("Center"), QVariant(Qt::AlignCenter));
|
||||
|
||||
DesktopGridConfig::instance(KWIN_CONFIG);
|
||||
addConfig(DesktopGridConfig::self(), m_ui);
|
||||
connect(m_ui->kcfg_DesktopLayoutMode, qOverload<int>(&QComboBox::currentIndexChanged), this, &DesktopGridEffectConfig::desktopLayoutSelectionChanged);
|
||||
connect(m_ui->desktopNameAlignmentCombo, qOverload<int>(&QComboBox::currentIndexChanged), this, &DesktopGridEffectConfig::markAsChanged);
|
||||
connect(m_ui->shortcutEditor, &KShortcutsEditor::keyChange, this, &DesktopGridEffectConfig::markAsChanged);
|
||||
addConfig(DesktopGridConfig::self(), &m_ui);
|
||||
connect(m_ui.kcfg_DesktopLayoutMode, qOverload<int>(&QComboBox::currentIndexChanged), this, &DesktopGridEffectConfig::desktopLayoutSelectionChanged);
|
||||
connect(m_ui.desktopNameAlignmentCombo, qOverload<int>(&QComboBox::currentIndexChanged), this, &DesktopGridEffectConfig::markAsChanged);
|
||||
connect(m_ui.shortcutEditor, &KShortcutsEditor::keyChange, this, &DesktopGridEffectConfig::markAsChanged);
|
||||
}
|
||||
|
||||
DesktopGridEffectConfig::~DesktopGridEffectConfig()
|
||||
{
|
||||
// If save() is called undo() has no effect
|
||||
m_ui->shortcutEditor->undo();
|
||||
m_ui.shortcutEditor->undo();
|
||||
}
|
||||
|
||||
void DesktopGridEffectConfig::save()
|
||||
{
|
||||
m_ui->shortcutEditor->save();
|
||||
DesktopGridConfig::setDesktopNameAlignment(m_ui->desktopNameAlignmentCombo->itemData(m_ui->desktopNameAlignmentCombo->currentIndex()).toInt());
|
||||
m_ui.shortcutEditor->save();
|
||||
DesktopGridConfig::setDesktopNameAlignment(m_ui.desktopNameAlignmentCombo->itemData(m_ui.desktopNameAlignmentCombo->currentIndex()).toInt());
|
||||
KCModule::save();
|
||||
DesktopGridConfig::self()->save();
|
||||
|
||||
|
@ -100,26 +98,26 @@ void DesktopGridEffectConfig::save()
|
|||
void DesktopGridEffectConfig::load()
|
||||
{
|
||||
KCModule::load();
|
||||
m_ui->desktopNameAlignmentCombo->setCurrentIndex(m_ui->desktopNameAlignmentCombo->findData(QVariant(DesktopGridConfig::desktopNameAlignment())));
|
||||
m_ui.desktopNameAlignmentCombo->setCurrentIndex(m_ui.desktopNameAlignmentCombo->findData(QVariant(DesktopGridConfig::desktopNameAlignment())));
|
||||
|
||||
desktopLayoutSelectionChanged();
|
||||
}
|
||||
|
||||
void DesktopGridEffectConfig::desktopLayoutSelectionChanged()
|
||||
{
|
||||
if (m_ui->kcfg_DesktopLayoutMode->currentIndex() == int(DesktopGridEffect::DesktopLayoutMode::LayoutCustom)) {
|
||||
m_ui->layoutRowsLabel->setEnabled(true);
|
||||
m_ui->kcfg_CustomLayoutRows->setEnabled(true);
|
||||
if (m_ui.kcfg_DesktopLayoutMode->currentIndex() == int(DesktopGridEffect::DesktopLayoutMode::LayoutCustom)) {
|
||||
m_ui.layoutRowsLabel->setEnabled(true);
|
||||
m_ui.kcfg_CustomLayoutRows->setEnabled(true);
|
||||
} else {
|
||||
m_ui->layoutRowsLabel->setEnabled(false);
|
||||
m_ui->kcfg_CustomLayoutRows->setEnabled(false);
|
||||
m_ui.layoutRowsLabel->setEnabled(false);
|
||||
m_ui.kcfg_CustomLayoutRows->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void DesktopGridEffectConfig::defaults()
|
||||
{
|
||||
KCModule::defaults();
|
||||
m_ui->desktopNameAlignmentCombo->setCurrentIndex(0);
|
||||
m_ui.desktopNameAlignmentCombo->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -42,7 +42,7 @@ private Q_SLOTS:
|
|||
void desktopLayoutSelectionChanged();
|
||||
|
||||
private:
|
||||
DesktopGridEffectConfigForm *m_ui;
|
||||
DesktopGridEffectConfigForm m_ui;
|
||||
KActionCollection *m_actionCollection;
|
||||
};
|
||||
|
||||
|
|
|
@ -56,10 +56,7 @@ InvertEffect::InvertEffect()
|
|||
connect(effects, &EffectsHandler::windowClosed, this, &InvertEffect::slotWindowClosed);
|
||||
}
|
||||
|
||||
InvertEffect::~InvertEffect()
|
||||
{
|
||||
delete m_shader;
|
||||
}
|
||||
InvertEffect::~InvertEffect() = default;
|
||||
|
||||
bool InvertEffect::supported()
|
||||
{
|
||||
|
@ -90,9 +87,9 @@ void InvertEffect::drawWindow(EffectWindow *w, int mask, const QRegion ®ion,
|
|||
bool useShader = m_valid && (m_allWindows != m_windows.contains(w));
|
||||
if (useShader) {
|
||||
ShaderManager *shaderManager = ShaderManager::instance();
|
||||
shaderManager->pushShader(m_shader);
|
||||
shaderManager->pushShader(m_shader.get());
|
||||
|
||||
data.shader = m_shader;
|
||||
data.shader = m_shader.get();
|
||||
}
|
||||
|
||||
effects->drawWindow(w, mask, region, data);
|
||||
|
|
|
@ -21,8 +21,7 @@ class GLShader;
|
|||
/**
|
||||
* Inverts desktop's colors
|
||||
*/
|
||||
class InvertEffect
|
||||
: public Effect
|
||||
class InvertEffect : public Effect
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -48,7 +47,7 @@ protected:
|
|||
private:
|
||||
bool m_inited;
|
||||
bool m_valid;
|
||||
GLShader *m_shader;
|
||||
std::unique_ptr<GLShader> m_shader;
|
||||
bool m_allWindows;
|
||||
QList<EffectWindow *> m_windows;
|
||||
};
|
||||
|
|
|
@ -73,13 +73,7 @@ LookingGlassEffect::LookingGlassEffect()
|
|||
reconfigure(ReconfigureAll);
|
||||
}
|
||||
|
||||
LookingGlassEffect::~LookingGlassEffect()
|
||||
{
|
||||
delete m_texture;
|
||||
delete m_fbo;
|
||||
delete m_shader;
|
||||
delete m_vbo;
|
||||
}
|
||||
LookingGlassEffect::~LookingGlassEffect() = default;
|
||||
|
||||
bool LookingGlassEffect::supported()
|
||||
{
|
||||
|
@ -105,25 +99,25 @@ bool LookingGlassEffect::loadData()
|
|||
|
||||
// Create texture and render target
|
||||
const int levels = std::log2(qMin(texw, texh)) + 1;
|
||||
m_texture = new GLTexture(GL_RGBA8, texw, texh, levels);
|
||||
m_texture = std::make_unique<GLTexture>(GL_RGBA8, texw, texh, levels);
|
||||
m_texture->setFilter(GL_LINEAR_MIPMAP_LINEAR);
|
||||
m_texture->setWrapMode(GL_CLAMP_TO_EDGE);
|
||||
|
||||
m_fbo = new GLFramebuffer(m_texture);
|
||||
m_fbo = std::make_unique<GLFramebuffer>(m_texture.get());
|
||||
if (!m_fbo->valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_shader = ShaderManager::instance()->generateShaderFromFile(ShaderTrait::MapTexture, QString(), QStringLiteral(":/effects/lookingglass/shaders/lookingglass.frag"));
|
||||
if (m_shader->isValid()) {
|
||||
ShaderBinder binder(m_shader);
|
||||
ShaderBinder binder(m_shader.get());
|
||||
m_shader->setUniform("u_textureSize", QVector2D(screenSize.width(), screenSize.height()));
|
||||
} else {
|
||||
qCCritical(KWIN_LOOKINGGLASS) << "The shader failed to load!";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_vbo = new GLVertexBuffer(GLVertexBuffer::Static);
|
||||
m_vbo = std::make_unique<GLVertexBuffer>(GLVertexBuffer::Static);
|
||||
QVector<float> verts;
|
||||
QVector<float> texcoords;
|
||||
texcoords << screenSize.width() << 0.0;
|
||||
|
@ -223,7 +217,7 @@ void LookingGlassEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::m
|
|||
if (m_valid && m_enabled) {
|
||||
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
||||
// Start rendering to texture
|
||||
GLFramebuffer::pushFramebuffer(m_fbo);
|
||||
GLFramebuffer::pushFramebuffer(m_fbo.get());
|
||||
}
|
||||
|
||||
effects->prePaintScreen(data, presentTime);
|
||||
|
@ -252,13 +246,13 @@ void LookingGlassEffect::paintScreen(int mask, const QRegion ®ion, ScreenPain
|
|||
if (m_valid && m_enabled) {
|
||||
// Disable render texture
|
||||
GLFramebuffer *target = GLFramebuffer::popFramebuffer();
|
||||
Q_ASSERT(target == m_fbo);
|
||||
Q_ASSERT(target == m_fbo.get());
|
||||
Q_UNUSED(target);
|
||||
m_texture->bind();
|
||||
m_texture->generateMipmaps();
|
||||
|
||||
// Use the shader
|
||||
ShaderBinder binder(m_shader);
|
||||
ShaderBinder binder(m_shader.get());
|
||||
m_shader->setUniform("u_zoom", (float)zoom);
|
||||
m_shader->setUniform("u_radius", (float)radius);
|
||||
m_shader->setUniform("u_cursor", QVector2D(cursorPos().x(), cursorPos().y()));
|
||||
|
|
|
@ -63,10 +63,10 @@ private:
|
|||
bool polling; // Mouse polling
|
||||
int radius;
|
||||
int initialradius;
|
||||
GLTexture *m_texture;
|
||||
GLFramebuffer *m_fbo;
|
||||
GLVertexBuffer *m_vbo;
|
||||
GLShader *m_shader;
|
||||
std::unique_ptr<GLTexture> m_texture;
|
||||
std::unique_ptr<GLFramebuffer> m_fbo;
|
||||
std::unique_ptr<GLVertexBuffer> m_vbo;
|
||||
std::unique_ptr<GLShader> m_shader;
|
||||
std::chrono::milliseconds m_lastPresentTime;
|
||||
bool m_enabled;
|
||||
bool m_valid;
|
||||
|
|
|
@ -38,16 +38,14 @@ LookingGlassEffectConfigForm::LookingGlassEffectConfigForm(QWidget *parent)
|
|||
|
||||
LookingGlassEffectConfig::LookingGlassEffectConfig(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(parent, args)
|
||||
, m_ui(this)
|
||||
{
|
||||
m_ui = new LookingGlassEffectConfigForm(this);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
layout->addWidget(m_ui);
|
||||
layout->addWidget(&m_ui);
|
||||
|
||||
LookingGlassConfig::instance(KWIN_CONFIG);
|
||||
addConfig(LookingGlassConfig::self(), m_ui);
|
||||
connect(m_ui->editor, &KShortcutsEditor::keyChange, this, &LookingGlassEffectConfig::markAsChanged);
|
||||
addConfig(LookingGlassConfig::self(), &m_ui);
|
||||
connect(m_ui.editor, &KShortcutsEditor::keyChange, this, &LookingGlassEffectConfig::markAsChanged);
|
||||
|
||||
// Shortcut config. The shortcut belongs to the component "kwin"!
|
||||
m_actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
|
||||
|
@ -72,13 +70,13 @@ LookingGlassEffectConfig::LookingGlassEffectConfig(QWidget *parent, const QVaria
|
|||
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_0));
|
||||
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_0));
|
||||
|
||||
m_ui->editor->addCollection(m_actionCollection);
|
||||
m_ui.editor->addCollection(m_actionCollection);
|
||||
}
|
||||
|
||||
LookingGlassEffectConfig::~LookingGlassEffectConfig()
|
||||
{
|
||||
// Undo (only) unsaved changes to global key shortcuts
|
||||
m_ui->editor->undo();
|
||||
m_ui.editor->undo();
|
||||
}
|
||||
|
||||
void LookingGlassEffectConfig::save()
|
||||
|
@ -86,7 +84,7 @@ void LookingGlassEffectConfig::save()
|
|||
qDebug() << "Saving config of LookingGlass";
|
||||
KCModule::save();
|
||||
|
||||
m_ui->editor->save(); // undo() will restore to this state from now on
|
||||
m_ui.editor->save(); // undo() will restore to this state from now on
|
||||
|
||||
OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/Effects"),
|
||||
|
@ -96,7 +94,7 @@ void LookingGlassEffectConfig::save()
|
|||
|
||||
void LookingGlassEffectConfig::defaults()
|
||||
{
|
||||
m_ui->editor->allDefault();
|
||||
m_ui.editor->allDefault();
|
||||
KCModule::defaults();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
void defaults() override;
|
||||
|
||||
private:
|
||||
LookingGlassEffectConfigForm *m_ui;
|
||||
LookingGlassEffectConfigForm m_ui;
|
||||
KActionCollection *m_actionCollection;
|
||||
};
|
||||
|
||||
|
|
|
@ -33,15 +33,13 @@ MagicLampEffectConfigForm::MagicLampEffectConfigForm(QWidget *parent)
|
|||
|
||||
MagicLampEffectConfig::MagicLampEffectConfig(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(parent, args)
|
||||
, m_ui(this)
|
||||
{
|
||||
m_ui = new MagicLampEffectConfigForm(this);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
layout->addWidget(m_ui);
|
||||
layout->addWidget(&m_ui);
|
||||
|
||||
MagicLampConfig::instance(KWIN_CONFIG);
|
||||
addConfig(MagicLampConfig::self(), m_ui);
|
||||
addConfig(MagicLampConfig::self(), &m_ui);
|
||||
}
|
||||
|
||||
void MagicLampEffectConfig::save()
|
||||
|
|
|
@ -34,7 +34,7 @@ public Q_SLOTS:
|
|||
void save() override;
|
||||
|
||||
private:
|
||||
MagicLampEffectConfigForm *m_ui;
|
||||
MagicLampEffectConfigForm m_ui;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -26,9 +26,9 @@ namespace KWin
|
|||
const int FRAME_WIDTH = 5;
|
||||
|
||||
MagnifierEffect::MagnifierEffect()
|
||||
: zoom(1)
|
||||
, target_zoom(1)
|
||||
, polling(false)
|
||||
: m_zoom(1)
|
||||
, m_targetZoom(1)
|
||||
, m_polling(false)
|
||||
, m_lastPresentTime(std::chrono::milliseconds::zero())
|
||||
, m_texture(nullptr)
|
||||
, m_fbo(nullptr)
|
||||
|
@ -58,10 +58,8 @@ MagnifierEffect::MagnifierEffect()
|
|||
|
||||
MagnifierEffect::~MagnifierEffect()
|
||||
{
|
||||
delete m_fbo;
|
||||
delete m_texture;
|
||||
// Save the zoom value.
|
||||
MagnifierConfig::setInitialZoom(target_zoom);
|
||||
MagnifierConfig::setInitialZoom(m_targetZoom);
|
||||
MagnifierConfig::self()->save();
|
||||
}
|
||||
|
||||
|
@ -76,10 +74,10 @@ void MagnifierEffect::reconfigure(ReconfigureFlags)
|
|||
int width, height;
|
||||
width = MagnifierConfig::width();
|
||||
height = MagnifierConfig::height();
|
||||
magnifier_size = QSize(width, height);
|
||||
m_magnifierSize = QSize(width, height);
|
||||
// Load the saved zoom value.
|
||||
target_zoom = MagnifierConfig::initialZoom();
|
||||
if (target_zoom != zoom) {
|
||||
m_targetZoom = MagnifierConfig::initialZoom();
|
||||
if (m_targetZoom != m_zoom) {
|
||||
toggle();
|
||||
}
|
||||
}
|
||||
|
@ -88,30 +86,28 @@ void MagnifierEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mill
|
|||
{
|
||||
const int time = m_lastPresentTime.count() ? (presentTime - m_lastPresentTime).count() : 0;
|
||||
|
||||
if (zoom != target_zoom) {
|
||||
if (m_zoom != m_targetZoom) {
|
||||
double diff = time / animationTime(500.0);
|
||||
if (target_zoom > zoom) {
|
||||
zoom = qMin(zoom * qMax(1 + diff, 1.2), target_zoom);
|
||||
if (m_targetZoom > m_zoom) {
|
||||
m_zoom = qMin(m_zoom * qMax(1 + diff, 1.2), m_targetZoom);
|
||||
} else {
|
||||
zoom = qMax(zoom * qMin(1 - diff, 0.8), target_zoom);
|
||||
if (zoom == 1.0) {
|
||||
m_zoom = qMax(m_zoom * qMin(1 - diff, 0.8), m_targetZoom);
|
||||
if (m_zoom == 1.0) {
|
||||
// zoom ended - delete FBO and texture
|
||||
delete m_fbo;
|
||||
delete m_texture;
|
||||
m_fbo = nullptr;
|
||||
m_texture = nullptr;
|
||||
m_fbo.reset();
|
||||
m_texture.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zoom != target_zoom) {
|
||||
if (m_zoom != m_targetZoom) {
|
||||
m_lastPresentTime = presentTime;
|
||||
} else {
|
||||
m_lastPresentTime = std::chrono::milliseconds::zero();
|
||||
}
|
||||
|
||||
effects->prePaintScreen(data, presentTime);
|
||||
if (zoom != 1.0) {
|
||||
if (m_zoom != 1.0) {
|
||||
data.paint |= magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH);
|
||||
}
|
||||
}
|
||||
|
@ -119,14 +115,14 @@ void MagnifierEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mill
|
|||
void MagnifierEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data)
|
||||
{
|
||||
effects->paintScreen(mask, region, data); // paint normal screen
|
||||
if (zoom != 1.0) {
|
||||
if (m_zoom != 1.0) {
|
||||
// get the right area from the current rendered screen
|
||||
const QRect area = magnifierArea();
|
||||
const QPoint cursor = cursorPos();
|
||||
|
||||
QRect srcArea(cursor.x() - (double)area.width() / (zoom * 2),
|
||||
cursor.y() - (double)area.height() / (zoom * 2),
|
||||
(double)area.width() / zoom, (double)area.height() / zoom);
|
||||
QRect srcArea(cursor.x() - (double)area.width() / (m_zoom * 2),
|
||||
cursor.y() - (double)area.height() / (m_zoom * 2),
|
||||
(double)area.width() / m_zoom, (double)area.height() / m_zoom);
|
||||
if (effects->isOpenGLCompositing()) {
|
||||
m_fbo->blitFromFramebuffer(effects->mapToRenderTarget(srcArea));
|
||||
// paint magnifier
|
||||
|
@ -184,7 +180,7 @@ void MagnifierEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintDa
|
|||
|
||||
void MagnifierEffect::postPaintScreen()
|
||||
{
|
||||
if (zoom != target_zoom) {
|
||||
if (m_zoom != m_targetZoom) {
|
||||
QRect framedarea = magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH);
|
||||
effects->addRepaint(framedarea);
|
||||
}
|
||||
|
@ -193,41 +189,39 @@ void MagnifierEffect::postPaintScreen()
|
|||
|
||||
QRect MagnifierEffect::magnifierArea(QPoint pos) const
|
||||
{
|
||||
return QRect(pos.x() - magnifier_size.width() / 2, pos.y() - magnifier_size.height() / 2,
|
||||
magnifier_size.width(), magnifier_size.height());
|
||||
return QRect(pos.x() - m_magnifierSize.width() / 2, pos.y() - m_magnifierSize.height() / 2,
|
||||
m_magnifierSize.width(), m_magnifierSize.height());
|
||||
}
|
||||
|
||||
void MagnifierEffect::zoomIn()
|
||||
{
|
||||
target_zoom *= 1.2;
|
||||
if (!polling) {
|
||||
polling = true;
|
||||
m_targetZoom *= 1.2;
|
||||
if (!m_polling) {
|
||||
m_polling = true;
|
||||
effects->startMousePolling();
|
||||
}
|
||||
if (effects->isOpenGLCompositing() && !m_texture) {
|
||||
effects->makeOpenGLContextCurrent();
|
||||
m_texture = new GLTexture(GL_RGBA8, magnifier_size.width(), magnifier_size.height());
|
||||
m_texture = std::make_unique<GLTexture>(GL_RGBA8, m_magnifierSize.width(), m_magnifierSize.height());
|
||||
m_texture->setYInverted(false);
|
||||
m_fbo = new GLFramebuffer(m_texture);
|
||||
m_fbo = std::make_unique<GLFramebuffer>(m_texture.get());
|
||||
}
|
||||
effects->addRepaint(magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH));
|
||||
}
|
||||
|
||||
void MagnifierEffect::zoomOut()
|
||||
{
|
||||
target_zoom /= 1.2;
|
||||
if (target_zoom <= 1) {
|
||||
target_zoom = 1;
|
||||
if (polling) {
|
||||
polling = false;
|
||||
m_targetZoom /= 1.2;
|
||||
if (m_targetZoom <= 1) {
|
||||
m_targetZoom = 1;
|
||||
if (m_polling) {
|
||||
m_polling = false;
|
||||
effects->stopMousePolling();
|
||||
}
|
||||
if (zoom == target_zoom) {
|
||||
if (m_zoom == m_targetZoom) {
|
||||
effects->makeOpenGLContextCurrent();
|
||||
delete m_fbo;
|
||||
delete m_texture;
|
||||
m_fbo = nullptr;
|
||||
m_texture = nullptr;
|
||||
m_fbo.reset();
|
||||
m_texture.reset();
|
||||
}
|
||||
}
|
||||
effects->addRepaint(magnifierArea().adjusted(-FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH));
|
||||
|
@ -235,24 +229,24 @@ void MagnifierEffect::zoomOut()
|
|||
|
||||
void MagnifierEffect::toggle()
|
||||
{
|
||||
if (zoom == 1.0) {
|
||||
if (target_zoom == 1.0) {
|
||||
target_zoom = 2;
|
||||
if (m_zoom == 1.0) {
|
||||
if (m_targetZoom == 1.0) {
|
||||
m_targetZoom = 2;
|
||||
}
|
||||
if (!polling) {
|
||||
polling = true;
|
||||
if (!m_polling) {
|
||||
m_polling = true;
|
||||
effects->startMousePolling();
|
||||
}
|
||||
if (effects->isOpenGLCompositing() && !m_texture) {
|
||||
effects->makeOpenGLContextCurrent();
|
||||
m_texture = new GLTexture(GL_RGBA8, magnifier_size.width(), magnifier_size.height());
|
||||
m_texture = std::make_unique<GLTexture>(GL_RGBA8, m_magnifierSize.width(), m_magnifierSize.height());
|
||||
m_texture->setYInverted(false);
|
||||
m_fbo = new GLFramebuffer(m_texture);
|
||||
m_fbo = std::make_unique<GLFramebuffer>(m_texture.get());
|
||||
}
|
||||
} else {
|
||||
target_zoom = 1;
|
||||
if (polling) {
|
||||
polling = false;
|
||||
m_targetZoom = 1;
|
||||
if (m_polling) {
|
||||
m_polling = false;
|
||||
effects->stopMousePolling();
|
||||
}
|
||||
}
|
||||
|
@ -262,7 +256,7 @@ void MagnifierEffect::toggle()
|
|||
void MagnifierEffect::slotMouseChanged(const QPoint &pos, const QPoint &old,
|
||||
Qt::MouseButtons, Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers)
|
||||
{
|
||||
if (pos != old && zoom != 1) {
|
||||
if (pos != old && m_zoom != 1) {
|
||||
// need full repaint as we might lose some change events on fast mouse movements
|
||||
// see Bug 187658
|
||||
effects->addRepaintFull();
|
||||
|
@ -278,7 +272,17 @@ void MagnifierEffect::slotWindowDamaged()
|
|||
|
||||
bool MagnifierEffect::isActive() const
|
||||
{
|
||||
return zoom != 1.0 || zoom != target_zoom;
|
||||
return m_zoom != 1.0 || m_zoom != m_targetZoom;
|
||||
}
|
||||
|
||||
QSize MagnifierEffect::magnifierSize() const
|
||||
{
|
||||
return m_magnifierSize;
|
||||
}
|
||||
|
||||
qreal MagnifierEffect::targetZoom() const
|
||||
{
|
||||
return m_targetZoom;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -19,8 +19,7 @@ namespace KWin
|
|||
class GLFramebuffer;
|
||||
class GLTexture;
|
||||
|
||||
class MagnifierEffect
|
||||
: public Effect
|
||||
class MagnifierEffect : public Effect
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QSize magnifierSize READ magnifierSize)
|
||||
|
@ -36,14 +35,8 @@ public:
|
|||
static bool supported();
|
||||
|
||||
// for properties
|
||||
QSize magnifierSize() const
|
||||
{
|
||||
return magnifier_size;
|
||||
}
|
||||
qreal targetZoom() const
|
||||
{
|
||||
return target_zoom;
|
||||
}
|
||||
QSize magnifierSize() const;
|
||||
qreal targetZoom() const;
|
||||
private Q_SLOTS:
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
|
@ -55,13 +48,13 @@ private Q_SLOTS:
|
|||
|
||||
private:
|
||||
QRect magnifierArea(QPoint pos = cursorPos()) const;
|
||||
double zoom;
|
||||
double target_zoom;
|
||||
bool polling; // Mouse polling
|
||||
double m_zoom;
|
||||
double m_targetZoom;
|
||||
bool m_polling; // Mouse polling
|
||||
std::chrono::milliseconds m_lastPresentTime;
|
||||
QSize magnifier_size;
|
||||
GLTexture *m_texture;
|
||||
GLFramebuffer *m_fbo;
|
||||
QSize m_magnifierSize;
|
||||
std::unique_ptr<GLTexture> m_texture;
|
||||
std::unique_ptr<GLFramebuffer> m_fbo;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -39,17 +39,15 @@ MagnifierEffectConfigForm::MagnifierEffectConfigForm(QWidget *parent)
|
|||
|
||||
MagnifierEffectConfig::MagnifierEffectConfig(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(parent, args)
|
||||
, m_ui(this)
|
||||
{
|
||||
m_ui = new MagnifierEffectConfigForm(this);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
layout->addWidget(m_ui);
|
||||
layout->addWidget(&m_ui);
|
||||
|
||||
MagnifierConfig::instance(KWIN_CONFIG);
|
||||
addConfig(MagnifierConfig::self(), m_ui);
|
||||
addConfig(MagnifierConfig::self(), &m_ui);
|
||||
|
||||
connect(m_ui->editor, &KShortcutsEditor::keyChange, this, &MagnifierEffectConfig::markAsChanged);
|
||||
connect(m_ui.editor, &KShortcutsEditor::keyChange, this, &MagnifierEffectConfig::markAsChanged);
|
||||
|
||||
// Shortcut config. The shortcut belongs to the component "kwin"!
|
||||
m_actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
|
||||
|
@ -74,20 +72,20 @@ MagnifierEffectConfig::MagnifierEffectConfig(QWidget *parent, const QVariantList
|
|||
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_0));
|
||||
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_0));
|
||||
|
||||
m_ui->editor->addCollection(m_actionCollection);
|
||||
m_ui.editor->addCollection(m_actionCollection);
|
||||
}
|
||||
|
||||
MagnifierEffectConfig::~MagnifierEffectConfig()
|
||||
{
|
||||
// Undo (only) unsaved changes to global key shortcuts
|
||||
m_ui->editor->undo();
|
||||
m_ui.editor->undo();
|
||||
}
|
||||
|
||||
void MagnifierEffectConfig::save()
|
||||
{
|
||||
qDebug() << "Saving config of Magnifier";
|
||||
|
||||
m_ui->editor->save(); // undo() will restore to this state from now on
|
||||
m_ui.editor->save(); // undo() will restore to this state from now on
|
||||
KCModule::save();
|
||||
OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/Effects"),
|
||||
|
@ -97,7 +95,7 @@ void MagnifierEffectConfig::save()
|
|||
|
||||
void MagnifierEffectConfig::defaults()
|
||||
{
|
||||
m_ui->editor->allDefault();
|
||||
m_ui.editor->allDefault();
|
||||
KCModule::defaults();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
void defaults() override;
|
||||
|
||||
private:
|
||||
MagnifierEffectConfigForm *m_ui;
|
||||
MagnifierEffectConfigForm m_ui;
|
||||
KActionCollection *m_actionCollection;
|
||||
};
|
||||
|
||||
|
|
|
@ -39,9 +39,9 @@ MouseClickEffect::MouseClickEffect()
|
|||
|
||||
reconfigure(ReconfigureAll);
|
||||
|
||||
m_buttons[0] = new MouseButton(i18nc("Left mouse button", "Left"), Qt::LeftButton);
|
||||
m_buttons[1] = new MouseButton(i18nc("Middle mouse button", "Middle"), Qt::MiddleButton);
|
||||
m_buttons[2] = new MouseButton(i18nc("Right mouse button", "Right"), Qt::RightButton);
|
||||
m_buttons[0] = std::make_unique<MouseButton>(i18nc("Left mouse button", "Left"), Qt::LeftButton);
|
||||
m_buttons[1] = std::make_unique<MouseButton>(i18nc("Middle mouse button", "Middle"), Qt::MiddleButton);
|
||||
m_buttons[2] = std::make_unique<MouseButton>(i18nc("Right mouse button", "Right"), Qt::RightButton);
|
||||
}
|
||||
|
||||
MouseClickEffect::~MouseClickEffect()
|
||||
|
@ -49,12 +49,6 @@ MouseClickEffect::~MouseClickEffect()
|
|||
if (m_enabled) {
|
||||
effects->stopMousePolling();
|
||||
}
|
||||
qDeleteAll(m_clicks);
|
||||
m_clicks.clear();
|
||||
|
||||
for (int i = 0; i < BUTTON_COUNT; ++i) {
|
||||
delete m_buttons[i];
|
||||
}
|
||||
}
|
||||
|
||||
void MouseClickEffect::reconfigure(ReconfigureFlags)
|
||||
|
@ -75,7 +69,7 @@ void MouseClickEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mil
|
|||
{
|
||||
const int time = m_lastPresentTime.count() ? (presentTime - m_lastPresentTime).count() : 0;
|
||||
|
||||
for (MouseEvent *click : qAsConst(m_clicks)) {
|
||||
for (auto &click : m_clicks) {
|
||||
click->m_time += time;
|
||||
}
|
||||
|
||||
|
@ -86,12 +80,10 @@ void MouseClickEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mil
|
|||
}
|
||||
|
||||
while (m_clicks.size() > 0) {
|
||||
MouseEvent *first = m_clicks[0];
|
||||
if (first->m_time <= m_ringLife) {
|
||||
if (m_clicks.front()->m_time <= m_ringLife) {
|
||||
break;
|
||||
}
|
||||
m_clicks.pop_front();
|
||||
delete first;
|
||||
}
|
||||
|
||||
if (isActive()) {
|
||||
|
@ -108,10 +100,10 @@ void MouseClickEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
|
|||
effects->paintScreen(mask, region, data);
|
||||
|
||||
paintScreenSetup(mask, region, data);
|
||||
for (const MouseEvent *click : qAsConst(m_clicks)) {
|
||||
for (const auto &click : m_clicks) {
|
||||
for (int i = 0; i < m_ringCount; ++i) {
|
||||
float alpha = computeAlpha(click, i);
|
||||
float size = computeRadius(click, i);
|
||||
float alpha = computeAlpha(click.get(), i);
|
||||
float size = computeRadius(click.get(), i);
|
||||
if (size > 0 && alpha > 0) {
|
||||
QColor color = m_colors[click->m_button];
|
||||
color.setAlphaF(alpha);
|
||||
|
@ -163,34 +155,34 @@ void MouseClickEffect::slotMouseChanged(const QPoint &pos, const QPoint &,
|
|||
return;
|
||||
}
|
||||
|
||||
MouseEvent *m = nullptr;
|
||||
std::unique_ptr<MouseEvent> m;
|
||||
int i = BUTTON_COUNT;
|
||||
while (--i >= 0) {
|
||||
MouseButton *b = m_buttons[i];
|
||||
MouseButton *b = m_buttons[i].get();
|
||||
if (isPressed(b->m_button, buttons, oldButtons)) {
|
||||
m = new MouseEvent(i, pos, 0, createEffectFrame(pos, b->m_labelDown), true);
|
||||
m = std::make_unique<MouseEvent>(i, pos, 0, createEffectFrame(pos, b->m_labelDown), true);
|
||||
break;
|
||||
} else if (isReleased(b->m_button, buttons, oldButtons) && (!b->m_isPressed || b->m_time > m_ringLife)) {
|
||||
// we might miss a press, thus also check !b->m_isPressed, bug #314762
|
||||
m = new MouseEvent(i, pos, 0, createEffectFrame(pos, b->m_labelUp), false);
|
||||
m = std::make_unique<MouseEvent>(i, pos, 0, createEffectFrame(pos, b->m_labelUp), false);
|
||||
break;
|
||||
}
|
||||
b->setPressed(b->m_button & buttons);
|
||||
}
|
||||
|
||||
if (m) {
|
||||
m_clicks.append(m);
|
||||
m_clicks.push_back(std::move(m));
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
EffectFrame *MouseClickEffect::createEffectFrame(const QPoint &pos, const QString &text)
|
||||
std::unique_ptr<EffectFrame> MouseClickEffect::createEffectFrame(const QPoint &pos, const QString &text)
|
||||
{
|
||||
if (!m_showText) {
|
||||
return nullptr;
|
||||
}
|
||||
QPoint point(pos.x() + m_ringMaxSize, pos.y());
|
||||
EffectFrame *frame = effects->effectFrame(EffectFrameStyled, false, point, Qt::AlignLeft);
|
||||
std::unique_ptr<EffectFrame> frame = effects->effectFrame(EffectFrameStyled, false, point, Qt::AlignLeft);
|
||||
frame->setFont(m_font);
|
||||
frame->setText(text);
|
||||
return frame;
|
||||
|
@ -201,7 +193,7 @@ void MouseClickEffect::repaint()
|
|||
if (m_clicks.size() > 0) {
|
||||
QRegion dirtyRegion;
|
||||
const int radius = m_ringMaxSize + m_lineWidth;
|
||||
for (MouseEvent *click : qAsConst(m_clicks)) {
|
||||
for (auto &click : m_clicks) {
|
||||
dirtyRegion |= QRect(click->m_pos.x() - radius, click->m_pos.y() - radius, 2 * radius, 2 * radius);
|
||||
if (click->m_frame) {
|
||||
// we grant the plasma style 32px padding for stuff like shadows...
|
||||
|
@ -242,7 +234,6 @@ void MouseClickEffect::toggleEnabled()
|
|||
effects->stopMousePolling();
|
||||
}
|
||||
|
||||
qDeleteAll(m_clicks);
|
||||
m_clicks.clear();
|
||||
m_tabletTools.clear();
|
||||
|
||||
|
@ -254,7 +245,7 @@ void MouseClickEffect::toggleEnabled()
|
|||
|
||||
bool MouseClickEffect::isActive() const
|
||||
{
|
||||
return m_enabled && (!m_clicks.isEmpty() || !m_tabletTools.isEmpty());
|
||||
return m_enabled && (m_clicks.size() != 0 || !m_tabletTools.isEmpty());
|
||||
}
|
||||
|
||||
void MouseClickEffect::drawCircle(const QColor &color, float cx, float cy, float r)
|
||||
|
@ -386,4 +377,54 @@ bool MouseClickEffect::tabletToolEvent(QTabletEvent *event)
|
|||
return false;
|
||||
}
|
||||
|
||||
QColor MouseClickEffect::color1() const
|
||||
{
|
||||
return m_colors[0];
|
||||
}
|
||||
|
||||
QColor MouseClickEffect::color2() const
|
||||
{
|
||||
return m_colors[1];
|
||||
}
|
||||
|
||||
QColor MouseClickEffect::color3() const
|
||||
{
|
||||
return m_colors[2];
|
||||
}
|
||||
|
||||
qreal MouseClickEffect::lineWidth() const
|
||||
{
|
||||
return m_lineWidth;
|
||||
}
|
||||
|
||||
int MouseClickEffect::ringLife() const
|
||||
{
|
||||
return m_ringLife;
|
||||
}
|
||||
|
||||
int MouseClickEffect::ringSize() const
|
||||
{
|
||||
return m_ringMaxSize;
|
||||
}
|
||||
|
||||
int MouseClickEffect::ringCount() const
|
||||
{
|
||||
return m_ringCount;
|
||||
}
|
||||
|
||||
bool MouseClickEffect::isShowText() const
|
||||
{
|
||||
return m_showText;
|
||||
}
|
||||
|
||||
QFont MouseClickEffect::font() const
|
||||
{
|
||||
return m_font;
|
||||
}
|
||||
|
||||
bool MouseClickEffect::isEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <KLocalizedString>
|
||||
#include <QFont>
|
||||
#include <QHash>
|
||||
#include <deque>
|
||||
#include <kwineffects.h>
|
||||
#include <kwinglutils.h>
|
||||
|
||||
|
@ -24,24 +25,18 @@ namespace KWin
|
|||
class MouseEvent
|
||||
{
|
||||
public:
|
||||
int m_button;
|
||||
QPoint m_pos;
|
||||
int m_time;
|
||||
EffectFrame *m_frame;
|
||||
bool m_press;
|
||||
|
||||
public:
|
||||
MouseEvent(int button, QPoint point, int time, EffectFrame *frame, bool press)
|
||||
MouseEvent(int button, QPoint point, int time, std::unique_ptr<EffectFrame> &&frame, bool press)
|
||||
: m_button(button)
|
||||
, m_pos(point)
|
||||
, m_time(time)
|
||||
, m_frame(frame)
|
||||
, m_frame(std::move(frame))
|
||||
, m_press(press){};
|
||||
|
||||
~MouseEvent()
|
||||
{
|
||||
delete m_frame;
|
||||
}
|
||||
int m_button;
|
||||
QPoint m_pos;
|
||||
int m_time;
|
||||
std::unique_ptr<EffectFrame> m_frame;
|
||||
bool m_press;
|
||||
};
|
||||
|
||||
class TabletToolEvent
|
||||
|
@ -55,13 +50,6 @@ public:
|
|||
|
||||
class MouseButton
|
||||
{
|
||||
public:
|
||||
QString m_labelUp;
|
||||
QString m_labelDown;
|
||||
Qt::MouseButtons m_button;
|
||||
bool m_isPressed;
|
||||
int m_time;
|
||||
|
||||
public:
|
||||
MouseButton(QString label, Qt::MouseButtons button)
|
||||
: m_labelUp(label)
|
||||
|
@ -83,6 +71,12 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString m_labelUp;
|
||||
QString m_labelDown;
|
||||
Qt::MouseButtons m_button;
|
||||
bool m_isPressed;
|
||||
int m_time;
|
||||
};
|
||||
|
||||
class MouseClickEffect
|
||||
|
@ -109,46 +103,16 @@ public:
|
|||
bool isActive() const override;
|
||||
|
||||
// for properties
|
||||
QColor color1() const
|
||||
{
|
||||
return m_colors[0];
|
||||
}
|
||||
QColor color2() const
|
||||
{
|
||||
return m_colors[1];
|
||||
}
|
||||
QColor color3() const
|
||||
{
|
||||
return m_colors[2];
|
||||
}
|
||||
qreal lineWidth() const
|
||||
{
|
||||
return m_lineWidth;
|
||||
}
|
||||
int ringLife() const
|
||||
{
|
||||
return m_ringLife;
|
||||
}
|
||||
int ringSize() const
|
||||
{
|
||||
return m_ringMaxSize;
|
||||
}
|
||||
int ringCount() const
|
||||
{
|
||||
return m_ringCount;
|
||||
}
|
||||
bool isShowText() const
|
||||
{
|
||||
return m_showText;
|
||||
}
|
||||
QFont font() const
|
||||
{
|
||||
return m_font;
|
||||
}
|
||||
bool isEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
QColor color1() const;
|
||||
QColor color2() const;
|
||||
QColor color3() const;
|
||||
qreal lineWidth() const;
|
||||
int ringLife() const;
|
||||
int ringSize() const;
|
||||
int ringCount() const;
|
||||
bool isShowText() const;
|
||||
QFont font() const;
|
||||
bool isEnabled() const;
|
||||
|
||||
bool tabletToolEvent(QTabletEvent *event) override;
|
||||
|
||||
|
@ -159,7 +123,7 @@ private Q_SLOTS:
|
|||
Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers);
|
||||
|
||||
private:
|
||||
EffectFrame *createEffectFrame(const QPoint &pos, const QString &text);
|
||||
std::unique_ptr<EffectFrame> createEffectFrame(const QPoint &pos, const QString &text);
|
||||
inline void drawCircle(const QColor &color, float cx, float cy, float r);
|
||||
inline void paintScreenSetup(int mask, QRegion region, ScreenPaintData &data);
|
||||
inline void paintScreenFinish(int mask, QRegion region, ScreenPaintData &data);
|
||||
|
@ -186,8 +150,8 @@ private:
|
|||
QFont m_font;
|
||||
std::chrono::milliseconds m_lastPresentTime = std::chrono::milliseconds::zero();
|
||||
|
||||
QList<MouseEvent *> m_clicks;
|
||||
MouseButton *m_buttons[BUTTON_COUNT];
|
||||
std::deque<std::unique_ptr<MouseEvent>> m_clicks;
|
||||
std::unique_ptr<MouseButton> m_buttons[BUTTON_COUNT];
|
||||
QHash<quint64, TabletToolEvent> m_tabletTools;
|
||||
|
||||
bool m_enabled;
|
||||
|
|
|
@ -36,13 +36,12 @@ MouseClickEffectConfigForm::MouseClickEffectConfigForm(QWidget *parent)
|
|||
|
||||
MouseClickEffectConfig::MouseClickEffectConfig(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(parent, args)
|
||||
, m_ui(this)
|
||||
{
|
||||
m_ui = new MouseClickEffectConfigForm(this);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(m_ui);
|
||||
layout->addWidget(&m_ui);
|
||||
|
||||
connect(m_ui->editor, &KShortcutsEditor::keyChange, this, &MouseClickEffectConfig::markAsChanged);
|
||||
connect(m_ui.editor, &KShortcutsEditor::keyChange, this, &MouseClickEffectConfig::markAsChanged);
|
||||
|
||||
// Shortcut config. The shortcut belongs to the component "kwin"!
|
||||
m_actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
|
||||
|
@ -54,22 +53,22 @@ MouseClickEffectConfig::MouseClickEffectConfig(QWidget *parent, const QVariantLi
|
|||
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Asterisk));
|
||||
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Asterisk));
|
||||
|
||||
m_ui->editor->addCollection(m_actionCollection);
|
||||
m_ui.editor->addCollection(m_actionCollection);
|
||||
|
||||
MouseClickConfig::instance(KWIN_CONFIG);
|
||||
addConfig(MouseClickConfig::self(), m_ui);
|
||||
addConfig(MouseClickConfig::self(), &m_ui);
|
||||
}
|
||||
|
||||
MouseClickEffectConfig::~MouseClickEffectConfig()
|
||||
{
|
||||
// Undo (only) unsaved changes to global key shortcuts
|
||||
m_ui->editor->undo();
|
||||
m_ui.editor->undo();
|
||||
}
|
||||
|
||||
void MouseClickEffectConfig::save()
|
||||
{
|
||||
KCModule::save();
|
||||
m_ui->editor->save(); // undo() will restore to this state from now on
|
||||
m_ui.editor->save(); // undo() will restore to this state from now on
|
||||
OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/Effects"),
|
||||
QDBusConnection::sessionBus());
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
void save() override;
|
||||
|
||||
private:
|
||||
MouseClickEffectConfigForm *m_ui;
|
||||
MouseClickEffectConfigForm m_ui;
|
||||
KActionCollection *m_actionCollection;
|
||||
};
|
||||
|
||||
|
|
|
@ -37,15 +37,13 @@ MouseMarkEffectConfigForm::MouseMarkEffectConfigForm(QWidget *parent)
|
|||
|
||||
MouseMarkEffectConfig::MouseMarkEffectConfig(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(parent, args)
|
||||
, m_ui(this)
|
||||
{
|
||||
m_ui = new MouseMarkEffectConfigForm(this);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
layout->addWidget(m_ui);
|
||||
layout->addWidget(&m_ui);
|
||||
|
||||
MouseMarkConfig::instance(KWIN_CONFIG);
|
||||
addConfig(MouseMarkConfig::self(), m_ui);
|
||||
addConfig(MouseMarkConfig::self(), &m_ui);
|
||||
|
||||
// Shortcut config. The shortcut belongs to the component "kwin"!
|
||||
m_actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
|
||||
|
@ -63,9 +61,9 @@ MouseMarkEffectConfig::MouseMarkEffectConfig(QWidget *parent, const QVariantList
|
|||
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F12));
|
||||
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F12));
|
||||
|
||||
m_ui->editor->addCollection(m_actionCollection);
|
||||
m_ui.editor->addCollection(m_actionCollection);
|
||||
|
||||
connect(m_ui->kcfg_LineWidth, qOverload<int>(&QSpinBox::valueChanged), this, [this]() {
|
||||
connect(m_ui.kcfg_LineWidth, qOverload<int>(&QSpinBox::valueChanged), this, [this]() {
|
||||
updateSpinBoxSuffix();
|
||||
});
|
||||
}
|
||||
|
@ -73,7 +71,7 @@ MouseMarkEffectConfig::MouseMarkEffectConfig(QWidget *parent, const QVariantList
|
|||
MouseMarkEffectConfig::~MouseMarkEffectConfig()
|
||||
{
|
||||
// Undo (only) unsaved changes to global key shortcuts
|
||||
m_ui->editor->undo();
|
||||
m_ui.editor->undo();
|
||||
}
|
||||
|
||||
void MouseMarkEffectConfig::load()
|
||||
|
@ -89,7 +87,7 @@ void MouseMarkEffectConfig::save()
|
|||
KCModule::save();
|
||||
|
||||
m_actionCollection->writeSettings();
|
||||
m_ui->editor->save(); // undo() will restore to this state from now on
|
||||
m_ui.editor->save(); // undo() will restore to this state from now on
|
||||
|
||||
OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/Effects"),
|
||||
|
@ -99,7 +97,7 @@ void MouseMarkEffectConfig::save()
|
|||
|
||||
void MouseMarkEffectConfig::updateSpinBoxSuffix()
|
||||
{
|
||||
m_ui->kcfg_LineWidth->setSuffix(i18ncp("Suffix", " pixel", " pixels", m_ui->kcfg_LineWidth->value()));
|
||||
m_ui.kcfg_LineWidth->setSuffix(i18ncp("Suffix", " pixel", " pixels", m_ui.kcfg_LineWidth->value()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
private:
|
||||
void updateSpinBoxSuffix();
|
||||
|
||||
MouseMarkEffectConfigForm *m_ui;
|
||||
MouseMarkEffectConfigForm m_ui;
|
||||
KActionCollection *m_actionCollection;
|
||||
};
|
||||
|
||||
|
|
|
@ -50,40 +50,33 @@ void ScreenEdgeEffect::ensureGlowSvg()
|
|||
|
||||
void ScreenEdgeEffect::cleanup()
|
||||
{
|
||||
for (QHash<ElectricBorder, Glow *>::iterator it = m_borders.begin();
|
||||
it != m_borders.end();
|
||||
++it) {
|
||||
effects->addRepaint((*it)->geometry);
|
||||
for (auto &[border, glow] : m_borders) {
|
||||
effects->addRepaint(glow->geometry);
|
||||
}
|
||||
qDeleteAll(m_borders);
|
||||
m_borders.clear();
|
||||
}
|
||||
|
||||
void ScreenEdgeEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
|
||||
{
|
||||
effects->prePaintScreen(data, presentTime);
|
||||
for (QHash<ElectricBorder, Glow *>::iterator it = m_borders.begin();
|
||||
it != m_borders.end();
|
||||
++it) {
|
||||
if ((*it)->strength == 0.0) {
|
||||
for (auto &[border, glow] : m_borders) {
|
||||
if (glow->strength == 0.0) {
|
||||
continue;
|
||||
}
|
||||
data.paint += (*it)->geometry;
|
||||
data.paint += glow->geometry;
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenEdgeEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data)
|
||||
{
|
||||
effects->paintScreen(mask, region, data);
|
||||
for (QHash<ElectricBorder, Glow *>::iterator it = m_borders.begin();
|
||||
it != m_borders.end();
|
||||
++it) {
|
||||
const qreal opacity = (*it)->strength;
|
||||
for (auto &[border, glow] : m_borders) {
|
||||
const qreal opacity = glow->strength;
|
||||
if (opacity == 0.0) {
|
||||
continue;
|
||||
}
|
||||
if (effects->isOpenGLCompositing()) {
|
||||
GLTexture *texture = (*it)->texture.data();
|
||||
GLTexture *texture = glow->texture.data();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
texture->bind();
|
||||
|
@ -91,16 +84,16 @@ void ScreenEdgeEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
|
|||
const QVector4D constant(opacity, opacity, opacity, opacity);
|
||||
binder.shader()->setUniform(GLShader::ModulationConstant, constant);
|
||||
QMatrix4x4 mvp = data.projectionMatrix();
|
||||
mvp.translate((*it)->geometry.x(), (*it)->geometry.y());
|
||||
mvp.translate(glow->geometry.x(), glow->geometry.y());
|
||||
binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
||||
texture->render((*it)->geometry);
|
||||
texture->render(glow->geometry);
|
||||
texture->unbind();
|
||||
glDisable(GL_BLEND);
|
||||
} else if (effects->compositingType() == QPainterCompositing) {
|
||||
QImage tmp((*it)->image->size(), QImage::Format_ARGB32_Premultiplied);
|
||||
QImage tmp(glow->image->size(), QImage::Format_ARGB32_Premultiplied);
|
||||
tmp.fill(Qt::transparent);
|
||||
QPainter p(&tmp);
|
||||
p.drawImage(0, 0, *(*it)->image.data());
|
||||
p.drawImage(0, 0, *glow->image.data());
|
||||
QColor color(Qt::transparent);
|
||||
color.setAlphaF(opacity);
|
||||
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
|
@ -108,11 +101,11 @@ void ScreenEdgeEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
|
|||
p.end();
|
||||
|
||||
QPainter *painter = effects->scenePainter();
|
||||
const QRect &rect = (*it)->geometry;
|
||||
const QSize &size = (*it)->pictureSize;
|
||||
const QRect &rect = glow->geometry;
|
||||
const QSize &size = glow->pictureSize;
|
||||
int x = rect.x();
|
||||
int y = rect.y();
|
||||
switch ((*it)->border) {
|
||||
switch (glow->border) {
|
||||
case ElectricTopRight:
|
||||
x = rect.x() + rect.width() - size.width();
|
||||
break;
|
||||
|
@ -134,19 +127,20 @@ void ScreenEdgeEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD
|
|||
|
||||
void ScreenEdgeEffect::edgeApproaching(ElectricBorder border, qreal factor, const QRect &geometry)
|
||||
{
|
||||
QHash<ElectricBorder, Glow *>::iterator it = m_borders.find(border);
|
||||
auto it = m_borders.find(border);
|
||||
if (it != m_borders.end()) {
|
||||
Glow *glow = it->second.get();
|
||||
// need to update
|
||||
effects->addRepaint((*it)->geometry);
|
||||
(*it)->strength = factor;
|
||||
if ((*it)->geometry != geometry) {
|
||||
(*it)->geometry = geometry;
|
||||
effects->addRepaint((*it)->geometry);
|
||||
effects->addRepaint(glow->geometry);
|
||||
glow->strength = factor;
|
||||
if (glow->geometry != geometry) {
|
||||
glow->geometry = geometry;
|
||||
effects->addRepaint(glow->geometry);
|
||||
if (border == ElectricLeft || border == ElectricRight || border == ElectricTop || border == ElectricBottom) {
|
||||
if (effects->isOpenGLCompositing()) {
|
||||
(*it)->texture.reset(createEdgeGlow<GLTexture>(border, geometry.size()));
|
||||
glow->texture.reset(createEdgeGlow<GLTexture>(border, geometry.size()));
|
||||
} else if (effects->compositingType() == QPainterCompositing) {
|
||||
(*it)->image.reset(createEdgeGlow<QImage>(border, geometry.size()));
|
||||
glow->image.reset(createEdgeGlow<QImage>(border, geometry.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,17 +151,17 @@ void ScreenEdgeEffect::edgeApproaching(ElectricBorder border, qreal factor, cons
|
|||
}
|
||||
} else if (factor != 0.0) {
|
||||
// need to generate new Glow
|
||||
Glow *glow = createGlow(border, factor, geometry);
|
||||
std::unique_ptr<Glow> glow = createGlow(border, factor, geometry);
|
||||
if (glow) {
|
||||
m_borders.insert(border, glow);
|
||||
effects->addRepaint(glow->geometry);
|
||||
m_borders[border] = std::move(glow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Glow *ScreenEdgeEffect::createGlow(ElectricBorder border, qreal factor, const QRect &geometry)
|
||||
std::unique_ptr<Glow> ScreenEdgeEffect::createGlow(ElectricBorder border, qreal factor, const QRect &geometry)
|
||||
{
|
||||
Glow *glow = new Glow();
|
||||
auto glow = std::make_unique<Glow>();
|
||||
glow->border = border;
|
||||
glow->strength = factor;
|
||||
glow->geometry = geometry;
|
||||
|
@ -184,7 +178,6 @@ Glow *ScreenEdgeEffect::createGlow(ElectricBorder border, qreal factor, const QR
|
|||
glow->texture->setWrapMode(GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
if (glow->texture.isNull()) {
|
||||
delete glow;
|
||||
return nullptr;
|
||||
}
|
||||
} else if (effects->compositingType() == QPainterCompositing) {
|
||||
|
@ -196,7 +189,6 @@ Glow *ScreenEdgeEffect::createGlow(ElectricBorder border, qreal factor, const QR
|
|||
glow->pictureSize = geometry.size();
|
||||
}
|
||||
if (glow->image.isNull()) {
|
||||
delete glow;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -305,7 +297,7 @@ T *ScreenEdgeEffect::createEdgeGlow(ElectricBorder border, const QSize &size)
|
|||
|
||||
bool ScreenEdgeEffect::isActive() const
|
||||
{
|
||||
return !m_borders.isEmpty() && !effects->isScreenLocked();
|
||||
return !m_borders.empty() && !effects->isScreenLocked();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -42,14 +42,14 @@ private Q_SLOTS:
|
|||
|
||||
private:
|
||||
void ensureGlowSvg();
|
||||
Glow *createGlow(ElectricBorder border, qreal factor, const QRect &geometry);
|
||||
std::unique_ptr<Glow> createGlow(ElectricBorder border, qreal factor, const QRect &geometry);
|
||||
template<typename T>
|
||||
T *createCornerGlow(ElectricBorder border);
|
||||
template<typename T>
|
||||
T *createEdgeGlow(ElectricBorder border, const QSize &size);
|
||||
QSize cornerGlowSize(ElectricBorder border);
|
||||
Plasma::Svg *m_glow = nullptr;
|
||||
QHash<ElectricBorder, Glow *> m_borders;
|
||||
std::map<ElectricBorder, std::unique_ptr<Glow>> m_borders;
|
||||
QTimer *m_cleanupTimer;
|
||||
};
|
||||
|
||||
|
|
|
@ -27,10 +27,10 @@ ScreenTransformEffect::ScreenTransformEffect()
|
|||
// Make sure that shaders in /effects/screentransform/shaders/* are loaded.
|
||||
ensureResources();
|
||||
|
||||
m_shader.reset(ShaderManager::instance()->generateShaderFromFile(
|
||||
m_shader = ShaderManager::instance()->generateShaderFromFile(
|
||||
ShaderTrait::MapTexture,
|
||||
QStringLiteral(":/effects/screentransform/shaders/crossfade.vert"),
|
||||
QStringLiteral(":/effects/screentransform/shaders/crossfade.frag")));
|
||||
QStringLiteral(":/effects/screentransform/shaders/crossfade.frag"));
|
||||
|
||||
m_modelViewProjectioMatrixLocation = m_shader->uniformLocation("modelViewProjectionMatrix");
|
||||
m_blendFactorLocation = m_shader->uniformLocation("blendFactor");
|
||||
|
|
|
@ -36,15 +36,11 @@ ShowFpsEffect::ShowFpsEffect()
|
|||
, m_noBenchmark(effects->effectFrame(EffectFrameUnstyled, false))
|
||||
{
|
||||
initConfig<ShowFpsConfig>();
|
||||
for (int i = 0;
|
||||
i < NUM_PAINTS;
|
||||
++i) {
|
||||
for (int i = 0; i < NUM_PAINTS; i++) {
|
||||
paints[i] = 0;
|
||||
paint_size[i] = 0;
|
||||
}
|
||||
for (int i = 0;
|
||||
i < MAX_FPS;
|
||||
++i) {
|
||||
for (int i = 0; i < MAX_FPS; i++) {
|
||||
frames[i] = 0;
|
||||
}
|
||||
if (m_showNoBenchmark) {
|
||||
|
@ -54,9 +50,7 @@ ShowFpsEffect::ShowFpsEffect()
|
|||
reconfigure(ReconfigureAll);
|
||||
}
|
||||
|
||||
ShowFpsEffect::~ShowFpsEffect()
|
||||
{
|
||||
}
|
||||
ShowFpsEffect::~ShowFpsEffect() = default;
|
||||
|
||||
void ShowFpsEffect::reconfigure(ReconfigureFlags)
|
||||
{
|
||||
|
@ -164,9 +158,7 @@ void ShowFpsEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData
|
|||
}
|
||||
const qint64 lastTimestamp = frames[lastFrame];
|
||||
int fps = 0;
|
||||
for (int i = 0;
|
||||
i < MAX_FPS;
|
||||
++i) {
|
||||
for (int i = 0; i < MAX_FPS; i++) {
|
||||
if (abs(lastTimestamp - frames[i]) < 1000) {
|
||||
++fps; // count all frames in the last second
|
||||
}
|
||||
|
|
|
@ -120,13 +120,13 @@ private:
|
|||
int x;
|
||||
int y;
|
||||
QRect fps_rect;
|
||||
QScopedPointer<GLTexture> fpsText;
|
||||
std::unique_ptr<GLTexture> fpsText;
|
||||
int textPosition;
|
||||
QFont textFont;
|
||||
QColor textColor;
|
||||
QRect fpsTextRect;
|
||||
int textAlign;
|
||||
QScopedPointer<EffectFrame> m_noBenchmark;
|
||||
std::unique_ptr<EffectFrame> m_noBenchmark;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -25,18 +25,12 @@ namespace KWin
|
|||
ShowFpsEffectConfig::ShowFpsEffectConfig(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(parent, args)
|
||||
{
|
||||
m_ui = new Ui::ShowFpsEffectConfigForm;
|
||||
m_ui->setupUi(this);
|
||||
m_ui.setupUi(this);
|
||||
|
||||
ShowFpsConfig::instance(KWIN_CONFIG);
|
||||
addConfig(ShowFpsConfig::self(), this);
|
||||
}
|
||||
|
||||
ShowFpsEffectConfig::~ShowFpsEffectConfig()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void ShowFpsEffectConfig::save()
|
||||
{
|
||||
KCModule::save();
|
||||
|
|
|
@ -22,13 +22,12 @@ class ShowFpsEffectConfig : public KCModule
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit ShowFpsEffectConfig(QWidget *parent = nullptr, const QVariantList &args = QVariantList());
|
||||
~ShowFpsEffectConfig() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void save() override;
|
||||
|
||||
private:
|
||||
Ui::ShowFpsEffectConfigForm *m_ui;
|
||||
Ui::ShowFpsEffectConfigForm m_ui;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace KWin
|
|||
|
||||
ShowPaintEffectConfig::ShowPaintEffectConfig(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(parent, args)
|
||||
, m_ui(new Ui::ShowPaintEffectConfig)
|
||||
, m_ui(std::make_unique<Ui::ShowPaintEffectConfig>())
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
|
@ -50,8 +50,6 @@ ShowPaintEffectConfig::~ShowPaintEffectConfig()
|
|||
{
|
||||
// If save() is called, undo() has no effect.
|
||||
m_ui->shortcutsEditor->undo();
|
||||
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void ShowPaintEffectConfig::save()
|
||||
|
|
|
@ -29,7 +29,7 @@ public Q_SLOTS:
|
|||
void defaults() override;
|
||||
|
||||
private:
|
||||
Ui::ShowPaintEffectConfig *m_ui;
|
||||
std::unique_ptr<Ui::ShowPaintEffectConfig> m_ui;
|
||||
};
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -149,7 +149,7 @@ void StartupFeedbackEffect::reconfigure(Effect::ReconfigureFlags flags)
|
|||
m_type = BlinkingFeedback;
|
||||
if (effects->compositingType() == OpenGLCompositing) {
|
||||
ensureResources();
|
||||
m_blinkingShader.reset(ShaderManager::instance()->generateShaderFromFile(ShaderTrait::MapTexture, QString(), QStringLiteral(":/effects/startupfeedback/shaders/blinking-startup.frag")));
|
||||
m_blinkingShader = ShaderManager::instance()->generateShaderFromFile(ShaderTrait::MapTexture, QString(), QStringLiteral(":/effects/startupfeedback/shaders/blinking-startup.frag"));
|
||||
if (m_blinkingShader->isValid()) {
|
||||
qCDebug(KWIN_STARTUPFEEDBACK) << "Blinking Shader is valid";
|
||||
} else {
|
||||
|
|
|
@ -83,11 +83,11 @@ private:
|
|||
int m_frame;
|
||||
int m_progress;
|
||||
std::chrono::milliseconds m_lastPresentTime;
|
||||
QScopedPointer<GLTexture> m_bouncingTextures[5];
|
||||
QScopedPointer<GLTexture> m_texture; // for passive and blinking
|
||||
std::unique_ptr<GLTexture> m_bouncingTextures[5];
|
||||
std::unique_ptr<GLTexture> m_texture; // for passive and blinking
|
||||
FeedbackType m_type;
|
||||
QRect m_currentGeometry, m_dirtyRect;
|
||||
QScopedPointer<GLShader> m_blinkingShader;
|
||||
std::unique_ptr<GLShader> m_blinkingShader;
|
||||
int m_cursorSize;
|
||||
KConfigWatcher::Ptr m_configWatcher;
|
||||
bool m_splashVisible;
|
||||
|
|
|
@ -38,14 +38,12 @@ ThumbnailAsideEffectConfigForm::ThumbnailAsideEffectConfigForm(QWidget *parent)
|
|||
|
||||
ThumbnailAsideEffectConfig::ThumbnailAsideEffectConfig(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(parent, args)
|
||||
, m_ui(this)
|
||||
{
|
||||
m_ui = new ThumbnailAsideEffectConfigForm(this);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(&m_ui);
|
||||
|
||||
layout->addWidget(m_ui);
|
||||
|
||||
connect(m_ui->editor, &KShortcutsEditor::keyChange, this, &ThumbnailAsideEffectConfig::markAsChanged);
|
||||
connect(m_ui.editor, &KShortcutsEditor::keyChange, this, &ThumbnailAsideEffectConfig::markAsChanged);
|
||||
|
||||
ThumbnailAsideConfig::instance(KWIN_CONFIG);
|
||||
addConfig(ThumbnailAsideConfig::self(), this);
|
||||
|
@ -63,19 +61,19 @@ ThumbnailAsideEffectConfig::ThumbnailAsideEffectConfig(QWidget *parent, const QV
|
|||
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::CTRL | Qt::Key_T));
|
||||
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::CTRL | Qt::Key_T));
|
||||
|
||||
m_ui->editor->addCollection(m_actionCollection);
|
||||
m_ui.editor->addCollection(m_actionCollection);
|
||||
}
|
||||
|
||||
ThumbnailAsideEffectConfig::~ThumbnailAsideEffectConfig()
|
||||
{
|
||||
// Undo (only) unsaved changes to global key shortcuts
|
||||
m_ui->editor->undo();
|
||||
m_ui.editor->undo();
|
||||
}
|
||||
|
||||
void ThumbnailAsideEffectConfig::save()
|
||||
{
|
||||
KCModule::save();
|
||||
m_ui->editor->save();
|
||||
m_ui.editor->save();
|
||||
OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/Effects"),
|
||||
QDBusConnection::sessionBus());
|
||||
|
|
|
@ -36,7 +36,7 @@ public:
|
|||
void save() override;
|
||||
|
||||
private:
|
||||
ThumbnailAsideEffectConfigForm *m_ui;
|
||||
ThumbnailAsideEffectConfigForm m_ui;
|
||||
KActionCollection *m_actionCollection;
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ TrackMouseEffect::TrackMouseEffect()
|
|||
: m_angle(0)
|
||||
{
|
||||
initConfig<TrackMouseConfig>();
|
||||
m_texture[0] = m_texture[1] = nullptr;
|
||||
if (effects->isOpenGLCompositing() || effects->compositingType() == QPainterCompositing) {
|
||||
m_angleBase = 90.0;
|
||||
}
|
||||
|
@ -58,10 +57,6 @@ TrackMouseEffect::~TrackMouseEffect()
|
|||
if (m_mousePolling) {
|
||||
effects->stopMousePolling();
|
||||
}
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
delete m_texture[i];
|
||||
m_texture[i] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void TrackMouseEffect::reconfigure(ReconfigureFlags)
|
||||
|
@ -240,7 +235,7 @@ void TrackMouseEffect::loadTexture()
|
|||
for (int i = 0; i < 2; ++i) {
|
||||
if (effects->isOpenGLCompositing()) {
|
||||
QImage img(f[i]);
|
||||
m_texture[i] = new GLTexture(img);
|
||||
m_texture[i] = std::make_unique<GLTexture>(img);
|
||||
m_lastRect[i].setSize(img.size());
|
||||
}
|
||||
if (effects->compositingType() == QPainterCompositing) {
|
||||
|
|
|
@ -57,7 +57,7 @@ private:
|
|||
bool m_mousePolling;
|
||||
float m_angle;
|
||||
float m_angleBase;
|
||||
GLTexture *m_texture[2];
|
||||
std::unique_ptr<GLTexture> m_texture[2];
|
||||
QAction *m_action;
|
||||
QImage m_image[2];
|
||||
Qt::KeyboardModifiers m_modifiers;
|
||||
|
|
|
@ -133,12 +133,7 @@ WobblyWindowsEffect::~WobblyWindowsEffect()
|
|||
{
|
||||
if (!windows.empty()) {
|
||||
// we should be empty at this point...
|
||||
// emit a warning and clean the list.
|
||||
qCDebug(KWIN_WOBBLYWINDOWS) << "Windows list not empty. Left items : " << windows.count();
|
||||
QHash<const EffectWindow *, WindowWobblyInfos>::iterator i;
|
||||
for (i = windows.begin(); i != windows.end(); ++i) {
|
||||
freeWobblyInfo(i.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,14 +474,14 @@ void WobblyWindowsEffect::initWobblyInfo(WindowWobblyInfos &wwi, QRect geometry)
|
|||
wwi.bezierHeight = m_yTesselation;
|
||||
wwi.bezierCount = m_xTesselation * m_yTesselation;
|
||||
|
||||
wwi.origin = new Pair[wwi.count];
|
||||
wwi.position = new Pair[wwi.count];
|
||||
wwi.velocity = new Pair[wwi.count];
|
||||
wwi.acceleration = new Pair[wwi.count];
|
||||
wwi.buffer = new Pair[wwi.count];
|
||||
wwi.constraint = new bool[wwi.count];
|
||||
wwi.origin.resize(wwi.count);
|
||||
wwi.position.resize(wwi.count);
|
||||
wwi.velocity.resize(wwi.count);
|
||||
wwi.acceleration.resize(wwi.count);
|
||||
wwi.buffer.resize(wwi.count);
|
||||
wwi.constraint.resize(wwi.count);
|
||||
|
||||
wwi.bezierSurface = new Pair[wwi.bezierCount];
|
||||
wwi.bezierSurface.resize(wwi.bezierCount);
|
||||
|
||||
wwi.status = Moving;
|
||||
wwi.clock = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
|
@ -526,18 +521,6 @@ void WobblyWindowsEffect::initWobblyInfo(WindowWobblyInfos &wwi, QRect geometry)
|
|||
}
|
||||
}
|
||||
|
||||
void WobblyWindowsEffect::freeWobblyInfo(WindowWobblyInfos &wwi) const
|
||||
{
|
||||
delete[] wwi.origin;
|
||||
delete[] wwi.position;
|
||||
delete[] wwi.velocity;
|
||||
delete[] wwi.acceleration;
|
||||
delete[] wwi.buffer;
|
||||
delete[] wwi.constraint;
|
||||
|
||||
delete[] wwi.bezierSurface;
|
||||
}
|
||||
|
||||
WobblyWindowsEffect::Pair WobblyWindowsEffect::computeBezierPoint(const WindowWobblyInfos &wwi, Pair point) const
|
||||
{
|
||||
const qreal tx = point.x;
|
||||
|
@ -871,7 +854,7 @@ bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow *w, qreal time)
|
|||
}
|
||||
}
|
||||
|
||||
heightRingLinearMean(&wwi.acceleration, wwi);
|
||||
heightRingLinearMean(wwi.acceleration, wwi);
|
||||
|
||||
#if defined COMPUTE_STATS
|
||||
Pair accBound = {m_maxAcceleration, m_minAcceleration};
|
||||
|
@ -894,7 +877,7 @@ bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow *w, qreal time)
|
|||
acc_sum += fabs(acc.x) + fabs(acc.y);
|
||||
}
|
||||
|
||||
heightRingLinearMean(&wwi.velocity, wwi);
|
||||
heightRingLinearMean(wwi.velocity, wwi);
|
||||
|
||||
// compute the new pos of each vertex.
|
||||
for (unsigned int i = 0; i < wwi.count; ++i) {
|
||||
|
@ -956,7 +939,6 @@ bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow *w, qreal time)
|
|||
#endif
|
||||
|
||||
if (wwi.status != Moving && acc_sum < m_stopAcceleration && vel_sum < m_stopVelocity) {
|
||||
freeWobblyInfo(wwi);
|
||||
windows.remove(w);
|
||||
unredirect(w);
|
||||
if (windows.isEmpty()) {
|
||||
|
@ -968,9 +950,8 @@ bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow *w, qreal time)
|
|||
return true;
|
||||
}
|
||||
|
||||
void WobblyWindowsEffect::heightRingLinearMean(Pair **data_pointer, WindowWobblyInfos &wwi)
|
||||
void WobblyWindowsEffect::heightRingLinearMean(QVector<Pair> &data, WindowWobblyInfos &wwi)
|
||||
{
|
||||
Pair *data = *data_pointer;
|
||||
Pair neibourgs[8];
|
||||
|
||||
// for corners
|
||||
|
@ -1102,8 +1083,8 @@ void WobblyWindowsEffect::heightRingLinearMean(Pair **data_pointer, WindowWobbly
|
|||
}
|
||||
}
|
||||
|
||||
Pair *tmp = data;
|
||||
*data_pointer = wwi.buffer;
|
||||
auto tmp = data;
|
||||
data = wwi.buffer;
|
||||
wwi.buffer = tmp;
|
||||
}
|
||||
|
||||
|
@ -1112,4 +1093,69 @@ bool WobblyWindowsEffect::isActive() const
|
|||
return !windows.isEmpty();
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::stiffness() const
|
||||
{
|
||||
return m_stiffness;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::drag() const
|
||||
{
|
||||
return m_drag;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::moveFactor() const
|
||||
{
|
||||
return m_move_factor;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::xTesselation() const
|
||||
{
|
||||
return m_xTesselation;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::yTesselation() const
|
||||
{
|
||||
return m_yTesselation;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::minVelocity() const
|
||||
{
|
||||
return m_minVelocity;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::maxVelocity() const
|
||||
{
|
||||
return m_maxVelocity;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::stopVelocity() const
|
||||
{
|
||||
return m_stopVelocity;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::minAcceleration() const
|
||||
{
|
||||
return m_minAcceleration;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::maxAcceleration() const
|
||||
{
|
||||
return m_maxAcceleration;
|
||||
}
|
||||
|
||||
qreal WobblyWindowsEffect::stopAcceleration() const
|
||||
{
|
||||
return m_stopAcceleration;
|
||||
}
|
||||
|
||||
bool WobblyWindowsEffect::isMoveWobble() const
|
||||
{
|
||||
return m_moveWobble;
|
||||
}
|
||||
|
||||
bool WobblyWindowsEffect::isResizeWobble() const
|
||||
{
|
||||
return m_resizeWobble;
|
||||
}
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -75,58 +75,19 @@ public:
|
|||
static bool supported();
|
||||
|
||||
// for properties
|
||||
qreal stiffness() const
|
||||
{
|
||||
return m_stiffness;
|
||||
}
|
||||
qreal drag() const
|
||||
{
|
||||
return m_drag;
|
||||
}
|
||||
qreal moveFactor() const
|
||||
{
|
||||
return m_move_factor;
|
||||
}
|
||||
qreal xTesselation() const
|
||||
{
|
||||
return m_xTesselation;
|
||||
}
|
||||
qreal yTesselation() const
|
||||
{
|
||||
return m_yTesselation;
|
||||
}
|
||||
qreal minVelocity() const
|
||||
{
|
||||
return m_minVelocity;
|
||||
}
|
||||
qreal maxVelocity() const
|
||||
{
|
||||
return m_maxVelocity;
|
||||
}
|
||||
qreal stopVelocity() const
|
||||
{
|
||||
return m_stopVelocity;
|
||||
}
|
||||
qreal minAcceleration() const
|
||||
{
|
||||
return m_minAcceleration;
|
||||
}
|
||||
qreal maxAcceleration() const
|
||||
{
|
||||
return m_maxAcceleration;
|
||||
}
|
||||
qreal stopAcceleration() const
|
||||
{
|
||||
return m_stopAcceleration;
|
||||
}
|
||||
bool isMoveWobble() const
|
||||
{
|
||||
return m_moveWobble;
|
||||
}
|
||||
bool isResizeWobble() const
|
||||
{
|
||||
return m_resizeWobble;
|
||||
}
|
||||
qreal stiffness() const;
|
||||
qreal drag() const;
|
||||
qreal moveFactor() const;
|
||||
qreal xTesselation() const;
|
||||
qreal yTesselation() const;
|
||||
qreal minVelocity() const;
|
||||
qreal maxVelocity() const;
|
||||
qreal stopVelocity() const;
|
||||
qreal minAcceleration() const;
|
||||
qreal maxAcceleration() const;
|
||||
qreal stopAcceleration() const;
|
||||
bool isMoveWobble() const;
|
||||
bool isResizeWobble() const;
|
||||
|
||||
protected:
|
||||
void apply(EffectWindow *w, int mask, WindowPaintData &data, WindowQuadList &quads) override;
|
||||
|
@ -144,21 +105,21 @@ private:
|
|||
|
||||
struct WindowWobblyInfos
|
||||
{
|
||||
Pair *origin;
|
||||
Pair *position;
|
||||
Pair *velocity;
|
||||
Pair *acceleration;
|
||||
Pair *buffer;
|
||||
QVector<Pair> origin;
|
||||
QVector<Pair> position;
|
||||
QVector<Pair> velocity;
|
||||
QVector<Pair> acceleration;
|
||||
QVector<Pair> buffer;
|
||||
|
||||
// if true, the physics system moves this point based only on it "normal" destination
|
||||
// given by the window position, ignoring neighbour points.
|
||||
bool *constraint;
|
||||
QVector<bool> constraint;
|
||||
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned int count;
|
||||
|
||||
Pair *bezierSurface;
|
||||
QVector<Pair> bezierSurface;
|
||||
unsigned int bezierWidth;
|
||||
unsigned int bezierHeight;
|
||||
unsigned int bezierCount;
|
||||
|
@ -197,11 +158,10 @@ private:
|
|||
bool m_resizeWobble;
|
||||
|
||||
void initWobblyInfo(WindowWobblyInfos &wwi, QRect geometry) const;
|
||||
void freeWobblyInfo(WindowWobblyInfos &wwi) const;
|
||||
|
||||
WobblyWindowsEffect::Pair computeBezierPoint(const WindowWobblyInfos &wwi, Pair point) const;
|
||||
|
||||
static void heightRingLinearMean(Pair **data_pointer, WindowWobblyInfos &wwi);
|
||||
static void heightRingLinearMean(QVector<Pair> &data, WindowWobblyInfos &wwi);
|
||||
|
||||
void setParameterSet(const ParameterSet &pset);
|
||||
};
|
||||
|
|
|
@ -132,7 +132,6 @@ ZoomEffect::~ZoomEffect()
|
|||
{
|
||||
// switch off and free resources
|
||||
showCursor();
|
||||
qDeleteAll(m_offscreenData);
|
||||
// Save the zoom value.
|
||||
ZoomConfig::setInitialZoom(target_zoom);
|
||||
ZoomConfig::self()->save();
|
||||
|
@ -163,11 +162,11 @@ GLTexture *ZoomEffect::ensureCursorTexture()
|
|||
m_cursorTextureDirty = false;
|
||||
const auto cursor = effects->cursorImage();
|
||||
if (!cursor.image().isNull()) {
|
||||
m_cursorTexture.reset(new GLTexture(cursor.image()));
|
||||
m_cursorTexture = std::make_unique<GLTexture>(cursor.image());
|
||||
m_cursorTexture->setWrapMode(GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
}
|
||||
return m_cursorTexture.data();
|
||||
return m_cursorTexture.get();
|
||||
}
|
||||
|
||||
void ZoomEffect::markCursorTextureDirty()
|
||||
|
@ -269,19 +268,16 @@ ZoomEffect::OffscreenData *ZoomEffect::ensureOffscreenData(EffectScreen *screen)
|
|||
const qreal devicePixelRatio = effects->renderTargetScale();
|
||||
const QSize nativeSize = rect.size() * devicePixelRatio;
|
||||
|
||||
OffscreenData *&data = m_offscreenData[effects->waylandDisplay() ? screen : nullptr];
|
||||
if (!data) {
|
||||
data = new OffscreenData;
|
||||
OffscreenData &data = m_offscreenData[effects->waylandDisplay() ? screen : nullptr];
|
||||
if (!data.texture || data.texture->size() != nativeSize) {
|
||||
data.texture.reset(new GLTexture(GL_RGBA8, nativeSize));
|
||||
data.texture->setFilter(GL_LINEAR);
|
||||
data.texture->setWrapMode(GL_CLAMP_TO_EDGE);
|
||||
data.framebuffer = std::make_unique<GLFramebuffer>(data.texture.get());
|
||||
}
|
||||
if (!data->texture || data->texture->size() != nativeSize) {
|
||||
data->texture.reset(new GLTexture(GL_RGBA8, nativeSize));
|
||||
data->texture->setFilter(GL_LINEAR);
|
||||
data->texture->setWrapMode(GL_CLAMP_TO_EDGE);
|
||||
data->framebuffer.reset(new GLFramebuffer(data->texture.data()));
|
||||
}
|
||||
if (!data->vbo || data->viewport != rect) {
|
||||
data->vbo.reset(new GLVertexBuffer(GLVertexBuffer::Static));
|
||||
data->viewport = rect;
|
||||
if (!data.vbo || data.viewport != rect) {
|
||||
data.vbo.reset(new GLVertexBuffer(GLVertexBuffer::Static));
|
||||
data.viewport = rect;
|
||||
|
||||
QVector<float> verts;
|
||||
QVector<float> texcoords;
|
||||
|
@ -301,10 +297,10 @@ ZoomEffect::OffscreenData *ZoomEffect::ensureOffscreenData(EffectScreen *screen)
|
|||
texcoords << 0.0 << 0.0;
|
||||
verts << rect.x() << rect.y() + rect.height();
|
||||
|
||||
data->vbo->setData(6, 2, verts.constData(), texcoords.constData());
|
||||
data.vbo->setData(6, 2, verts.constData(), texcoords.constData());
|
||||
}
|
||||
|
||||
return data;
|
||||
return &data;
|
||||
}
|
||||
|
||||
void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data)
|
||||
|
@ -312,7 +308,7 @@ void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &d
|
|||
OffscreenData *offscreenData = ensureOffscreenData(data.screen());
|
||||
|
||||
// Render the scene in an offscreen texture and then upscale it.
|
||||
GLFramebuffer::pushFramebuffer(offscreenData->framebuffer.data());
|
||||
GLFramebuffer::pushFramebuffer(offscreenData->framebuffer.get());
|
||||
effects->paintScreen(mask, region, data);
|
||||
GLFramebuffer::popFramebuffer();
|
||||
|
||||
|
@ -387,10 +383,10 @@ void ZoomEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &d
|
|||
|
||||
auto shader = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
||||
shader->setUniform(GLShader::ModelViewProjectionMatrix, data.projectionMatrix() * matrix);
|
||||
for (OffscreenData *data : std::as_const(m_offscreenData)) {
|
||||
data->texture->bind();
|
||||
data->vbo->render(GL_TRIANGLES);
|
||||
data->texture->unbind();
|
||||
for (auto &[screen, data] : m_offscreenData) {
|
||||
data.texture->bind();
|
||||
data.vbo->render(GL_TRIANGLES);
|
||||
data.texture->unbind();
|
||||
}
|
||||
ShaderManager::instance()->popShader();
|
||||
|
||||
|
@ -574,9 +570,9 @@ void ZoomEffect::slotWindowDamaged()
|
|||
|
||||
void ZoomEffect::slotScreenRemoved(EffectScreen *screen)
|
||||
{
|
||||
if (OffscreenData *offscreenData = m_offscreenData.take(screen)) {
|
||||
if (auto it = m_offscreenData.find(screen); it != m_offscreenData.end()) {
|
||||
effects->makeOpenGLContextCurrent();
|
||||
delete offscreenData;
|
||||
m_offscreenData.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -600,4 +596,34 @@ int ZoomEffect::requestedEffectChainPosition() const
|
|||
return 10;
|
||||
}
|
||||
|
||||
qreal ZoomEffect::configuredZoomFactor() const
|
||||
{
|
||||
return zoomFactor;
|
||||
}
|
||||
|
||||
int ZoomEffect::configuredMousePointer() const
|
||||
{
|
||||
return mousePointer;
|
||||
}
|
||||
|
||||
int ZoomEffect::configuredMouseTracking() const
|
||||
{
|
||||
return mouseTracking;
|
||||
}
|
||||
|
||||
int ZoomEffect::configuredFocusDelay() const
|
||||
{
|
||||
return focusDelay;
|
||||
}
|
||||
|
||||
qreal ZoomEffect::configuredMoveFactor() const
|
||||
{
|
||||
return moveFactor;
|
||||
}
|
||||
|
||||
qreal ZoomEffect::targetZoom() const
|
||||
{
|
||||
return target_zoom;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -50,32 +50,14 @@ public:
|
|||
bool isActive() const override;
|
||||
int requestedEffectChainPosition() const override;
|
||||
// for properties
|
||||
qreal configuredZoomFactor() const
|
||||
{
|
||||
return zoomFactor;
|
||||
}
|
||||
int configuredMousePointer() const
|
||||
{
|
||||
return mousePointer;
|
||||
}
|
||||
int configuredMouseTracking() const
|
||||
{
|
||||
return mouseTracking;
|
||||
}
|
||||
qreal configuredZoomFactor() const;
|
||||
int configuredMousePointer() const;
|
||||
int configuredMouseTracking() const;
|
||||
bool isFocusTrackingEnabled() const;
|
||||
bool isTextCaretTrackingEnabled() const;
|
||||
int configuredFocusDelay() const
|
||||
{
|
||||
return focusDelay;
|
||||
}
|
||||
qreal configuredMoveFactor() const
|
||||
{
|
||||
return moveFactor;
|
||||
}
|
||||
qreal targetZoom() const
|
||||
{
|
||||
return target_zoom;
|
||||
}
|
||||
int configuredFocusDelay() const;
|
||||
qreal configuredMoveFactor() const;
|
||||
qreal targetZoom() const;
|
||||
private Q_SLOTS:
|
||||
inline void zoomIn()
|
||||
{
|
||||
|
@ -106,9 +88,9 @@ private:
|
|||
private:
|
||||
struct OffscreenData
|
||||
{
|
||||
QScopedPointer<GLTexture> texture;
|
||||
QScopedPointer<GLFramebuffer> framebuffer;
|
||||
QScopedPointer<GLVertexBuffer> vbo;
|
||||
std::unique_ptr<GLTexture> texture;
|
||||
std::unique_ptr<GLFramebuffer> framebuffer;
|
||||
std::unique_ptr<GLVertexBuffer> vbo;
|
||||
QRect viewport;
|
||||
};
|
||||
|
||||
|
@ -143,14 +125,14 @@ private:
|
|||
QPoint prevPoint;
|
||||
QTime lastMouseEvent;
|
||||
QTime lastFocusEvent;
|
||||
QScopedPointer<GLTexture> m_cursorTexture;
|
||||
std::unique_ptr<GLTexture> m_cursorTexture;
|
||||
bool m_cursorTextureDirty = false;
|
||||
bool isMouseHidden;
|
||||
QTimeLine timeline;
|
||||
int xMove, yMove;
|
||||
double moveFactor;
|
||||
std::chrono::milliseconds lastPresentTime;
|
||||
QHash<EffectScreen *, OffscreenData *> m_offscreenData;
|
||||
std::map<EffectScreen *, OffscreenData> m_offscreenData;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -1246,8 +1246,9 @@ public:
|
|||
* EffectFrame.
|
||||
* @since 4.6
|
||||
*/
|
||||
virtual EffectFrame *effectFrame(EffectFrameStyle style, bool staticSize = true,
|
||||
const QPoint &position = QPoint(-1, -1), Qt::Alignment alignment = Qt::AlignCenter) const = 0;
|
||||
virtual std::unique_ptr<EffectFrame> effectFrame(EffectFrameStyle style, bool staticSize = true,
|
||||
const QPoint &position = QPoint(-1, -1),
|
||||
Qt::Alignment alignment = Qt::AlignCenter) const = 0;
|
||||
|
||||
/**
|
||||
* Allows an effect to trigger a reload of itself.
|
||||
|
|
|
@ -649,9 +649,6 @@ ShaderManager::~ShaderManager()
|
|||
while (!m_boundShaders.isEmpty()) {
|
||||
popShader();
|
||||
}
|
||||
|
||||
qDeleteAll(m_shaderHash);
|
||||
m_shaderHash.clear();
|
||||
}
|
||||
|
||||
QByteArray ShaderManager::generateVertexSource(ShaderTraits traits) const
|
||||
|
@ -786,12 +783,12 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const
|
|||
return source;
|
||||
}
|
||||
|
||||
GLShader *ShaderManager::generateShader(ShaderTraits traits)
|
||||
std::unique_ptr<GLShader> ShaderManager::generateShader(ShaderTraits traits)
|
||||
{
|
||||
return generateCustomShader(traits);
|
||||
}
|
||||
|
||||
GLShader *ShaderManager::generateCustomShader(ShaderTraits traits, const QByteArray &vertexSource, const QByteArray &fragmentSource)
|
||||
std::unique_ptr<GLShader> ShaderManager::generateCustomShader(ShaderTraits traits, const QByteArray &vertexSource, const QByteArray &fragmentSource)
|
||||
{
|
||||
const QByteArray vertex = vertexSource.isEmpty() ? generateVertexSource(traits) : vertexSource;
|
||||
const QByteArray fragment = fragmentSource.isEmpty() ? generateFragmentSource(traits) : fragmentSource;
|
||||
|
@ -804,7 +801,7 @@ GLShader *ShaderManager::generateCustomShader(ShaderTraits traits, const QByteAr
|
|||
qCDebug(LIBKWINGLUTILS) << "**************";
|
||||
#endif
|
||||
|
||||
GLShader *shader = new GLShader(GLShader::ExplicitLinking);
|
||||
std::unique_ptr<GLShader> shader{new GLShader(GLShader::ExplicitLinking)};
|
||||
shader->load(vertex, fragment);
|
||||
|
||||
shader->bindAttributeLocation("position", VA_Position);
|
||||
|
@ -838,7 +835,7 @@ static QString resolveShaderFilePath(const QString &filePath)
|
|||
return prefix + suffix + extension;
|
||||
}
|
||||
|
||||
GLShader *ShaderManager::generateShaderFromFile(ShaderTraits traits, const QString &vertexFile, const QString &fragmentFile)
|
||||
std::unique_ptr<GLShader> ShaderManager::generateShaderFromFile(ShaderTraits traits, const QString &vertexFile, const QString &fragmentFile)
|
||||
{
|
||||
auto loadShaderFile = [](const QString &filePath) {
|
||||
QFile file(filePath);
|
||||
|
@ -853,13 +850,13 @@ GLShader *ShaderManager::generateShaderFromFile(ShaderTraits traits, const QStri
|
|||
if (!vertexFile.isEmpty()) {
|
||||
vertexSource = loadShaderFile(resolveShaderFilePath(vertexFile));
|
||||
if (vertexSource.isEmpty()) {
|
||||
return new GLShader();
|
||||
return std::unique_ptr<GLShader>(new GLShader());
|
||||
}
|
||||
}
|
||||
if (!fragmentFile.isEmpty()) {
|
||||
fragmentSource = loadShaderFile(resolveShaderFilePath(fragmentFile));
|
||||
if (fragmentSource.isEmpty()) {
|
||||
return new GLShader();
|
||||
return std::unique_ptr<GLShader>(new GLShader());
|
||||
}
|
||||
}
|
||||
return generateCustomShader(traits, vertexSource, fragmentSource);
|
||||
|
@ -867,14 +864,11 @@ GLShader *ShaderManager::generateShaderFromFile(ShaderTraits traits, const QStri
|
|||
|
||||
GLShader *ShaderManager::shader(ShaderTraits traits)
|
||||
{
|
||||
GLShader *shader = m_shaderHash.value(traits);
|
||||
|
||||
std::unique_ptr<GLShader> &shader = m_shaderHash[traits];
|
||||
if (!shader) {
|
||||
shader = generateShader(traits);
|
||||
m_shaderHash.insert(traits, shader);
|
||||
}
|
||||
|
||||
return shader;
|
||||
return shader.get();
|
||||
}
|
||||
|
||||
GLShader *ShaderManager::getBoundShader() const
|
||||
|
@ -933,12 +927,12 @@ void ShaderManager::bindAttributeLocations(GLShader *shader) const
|
|||
shader->bindAttributeLocation("texCoord", VA_TexCoord);
|
||||
}
|
||||
|
||||
GLShader *ShaderManager::loadShaderFromCode(const QByteArray &vertexSource, const QByteArray &fragmentSource)
|
||||
std::unique_ptr<GLShader> ShaderManager::loadShaderFromCode(const QByteArray &vertexSource, const QByteArray &fragmentSource)
|
||||
{
|
||||
GLShader *shader = new GLShader(GLShader::ExplicitLinking);
|
||||
std::unique_ptr<GLShader> shader{new GLShader(GLShader::ExplicitLinking)};
|
||||
shader->load(vertexSource, fragmentSource);
|
||||
bindAttributeLocations(shader);
|
||||
bindFragDataLocations(shader);
|
||||
bindAttributeLocations(shader.get());
|
||||
bindFragDataLocations(shader.get());
|
||||
shader->link();
|
||||
return shader;
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ public:
|
|||
* @param fragmentSource The source code of the fragment shader.
|
||||
* @return The created shader
|
||||
*/
|
||||
GLShader *loadShaderFromCode(const QByteArray &vertexSource, const QByteArray &fragmentSource);
|
||||
std::unique_ptr<GLShader> loadShaderFromCode(const QByteArray &vertexSource, const QByteArray &fragmentSource);
|
||||
|
||||
/**
|
||||
* Creates a custom shader with the given @p traits and custom @p vertexSource and or @p fragmentSource.
|
||||
|
@ -258,7 +258,7 @@ public:
|
|||
* @return new generated shader
|
||||
* @since 5.6
|
||||
*/
|
||||
GLShader *generateCustomShader(ShaderTraits traits, const QByteArray &vertexSource = QByteArray(), const QByteArray &fragmentSource = QByteArray());
|
||||
std::unique_ptr<GLShader> generateCustomShader(ShaderTraits traits, const QByteArray &vertexSource = QByteArray(), const QByteArray &fragmentSource = QByteArray());
|
||||
|
||||
/**
|
||||
* Creates a custom shader with the given @p traits and custom @p vertexFile and or @p fragmentFile.
|
||||
|
@ -280,7 +280,7 @@ public:
|
|||
* @return new generated shader
|
||||
* @see generateCustomShader
|
||||
*/
|
||||
GLShader *generateShaderFromFile(ShaderTraits traits, const QString &vertexFile = QString(), const QString &fragmentFile = QString());
|
||||
std::unique_ptr<GLShader> generateShaderFromFile(ShaderTraits traits, const QString &vertexFile = QString(), const QString &fragmentFile = QString());
|
||||
|
||||
/**
|
||||
* @return a pointer to the ShaderManager instance
|
||||
|
@ -301,10 +301,10 @@ private:
|
|||
|
||||
QByteArray generateVertexSource(ShaderTraits traits) const;
|
||||
QByteArray generateFragmentSource(ShaderTraits traits) const;
|
||||
GLShader *generateShader(ShaderTraits traits);
|
||||
std::unique_ptr<GLShader> generateShader(ShaderTraits traits);
|
||||
|
||||
QStack<GLShader *> m_boundShaders;
|
||||
QHash<ShaderTraits, GLShader *> m_shaderHash;
|
||||
std::map<ShaderTraits, std::unique_ptr<GLShader>> m_shaderHash;
|
||||
static ShaderManager *s_shaderManager;
|
||||
};
|
||||
|
||||
|
|
|
@ -208,10 +208,7 @@ ScriptedEffect::ScriptedEffect()
|
|||
});
|
||||
}
|
||||
|
||||
ScriptedEffect::~ScriptedEffect()
|
||||
{
|
||||
qDeleteAll(m_shaders);
|
||||
}
|
||||
ScriptedEffect::~ScriptedEffect() = default;
|
||||
|
||||
bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript)
|
||||
{
|
||||
|
@ -813,21 +810,20 @@ uint ScriptedEffect::addFragmentShader(ShaderTrait traits, const QString &fragme
|
|||
auto shader = ShaderManager::instance()->generateShaderFromFile(static_cast<KWin::ShaderTraits>(int(traits)), {}, fragment);
|
||||
if (!shader->isValid()) {
|
||||
m_engine->throwError(QStringLiteral("Shader failed to load"));
|
||||
delete shader;
|
||||
// 0 is never a valid shader identifier, it's ensured the first shader gets id 1
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uint shaderId{m_nextShaderId};
|
||||
m_nextShaderId++;
|
||||
m_shaders.insert(shaderId, shader);
|
||||
m_shaders[shaderId] = std::move(shader);
|
||||
return shaderId;
|
||||
}
|
||||
|
||||
GLShader *ScriptedEffect::findShader(uint shaderId) const
|
||||
{
|
||||
if (auto it = m_shaders.find(shaderId); it != m_shaders.end()) {
|
||||
return it.value();
|
||||
return it->second.get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ private:
|
|||
int m_chainPosition;
|
||||
QHash<int, QAction *> m_touchScreenEdgeCallbacks;
|
||||
Effect *m_activeFullScreenEffect = nullptr;
|
||||
QHash<uint, GLShader*> m_shaders;
|
||||
std::map<uint, std::unique_ptr<GLShader>> m_shaders;
|
||||
uint m_nextShaderId{1u};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue