Commit 6831f251 authored by Arjen Hiemstra's avatar Arjen Hiemstra Committed by Vlad Zahorodnii
Browse files

Remove the lookingglass effect

It has been broken for a while (at least as long as 5.25) with no
bugreports about it. It also doesn't look all that great from the video.
parent 28210372
Pipeline #218962 passed with stage
in 14 minutes and 38 seconds
......@@ -95,7 +95,6 @@ add_subdirectory(blur)
add_subdirectory(backgroundcontrast)
add_subdirectory(glide)
add_subdirectory(invert)
add_subdirectory(lookingglass)
add_subdirectory(magnifier)
add_subdirectory(mouseclick)
add_subdirectory(mousemark)
......
#######################################
# Effect
set(lookingglass_SOURCES
lookingglass.cpp
lookingglass.qrc
main.cpp
)
kconfig_add_kcfg_files(lookingglass_SOURCES
lookingglassconfig.kcfgc
)
kwin4_add_effect_module(kwin4_effect_lookingglass ${lookingglass_SOURCES})
target_link_libraries(kwin4_effect_lookingglass PRIVATE
kwineffects
kwinglutils
KF5::ConfigGui
KF5::ConfigWidgets
KF5::GlobalAccel
KF5::I18n
)
#######################################
# Config
if (KWIN_BUILD_KCMS)
set(kwin_lookingglass_config_SRCS lookingglass_config.cpp)
ki18n_wrap_ui(kwin_lookingglass_config_SRCS lookingglass_config.ui)
kconfig_add_kcfg_files(kwin_lookingglass_config_SRCS lookingglassconfig.kcfgc)
kwin_add_effect_config(kwin_lookingglass_config ${kwin_lookingglass_config_SRCS})
target_link_libraries(kwin_lookingglass_config
KF5::ConfigWidgets
KF5::CoreAddons
KF5::GlobalAccel
KF5::I18n
KF5::XmlGui
KWinEffectsInterface
)
endif()
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2007 Rivo Laks <rivolaks@hot.ee>
SPDX-FileCopyrightText: 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "lookingglass.h"
// KConfigSkeleton
#include "lookingglassconfig.h"
#include <QAction>
#include <kwinglplatform.h>
#include <kwinglutils.h>
#include <KGlobalAccel>
#include <KLocalizedString>
#include <KStandardAction>
#include <QFile>
#include <QVector2D>
#include <kmessagebox.h>
#include <cmath>
Q_LOGGING_CATEGORY(KWIN_LOOKINGGLASS, "kwin_effect_lookingglass", QtWarningMsg)
static void ensureResources()
{
// Must initialize resources manually because the effect is a static lib.
Q_INIT_RESOURCE(lookingglass);
}
namespace KWin
{
LookingGlassEffect::LookingGlassEffect()
: zoom(1.0f)
, target_zoom(1.0f)
, polling(false)
, m_texture(nullptr)
, m_fbo(nullptr)
, m_vbo(nullptr)
, m_shader(nullptr)
, m_lastPresentTime(std::chrono::milliseconds::zero())
, m_enabled(false)
, m_valid(false)
{
initConfig<LookingGlassConfig>();
QAction *a;
a = KStandardAction::zoomIn(this, SLOT(zoomIn()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Equal));
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Equal));
effects->registerGlobalShortcut(Qt::META | Qt::Key_Equal, a);
a = KStandardAction::zoomOut(this, SLOT(zoomOut()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Minus));
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Minus));
effects->registerGlobalShortcut(Qt::META | Qt::Key_Minus, a);
a = KStandardAction::actualSize(this, SLOT(toggle()), this);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_0));
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_0));
effects->registerGlobalShortcut(Qt::META | Qt::Key_0, a);
connect(effects, &EffectsHandler::mouseChanged, this, &LookingGlassEffect::slotMouseChanged);
connect(effects, &EffectsHandler::windowDamaged, this, &LookingGlassEffect::slotWindowDamaged);
reconfigure(ReconfigureAll);
}
LookingGlassEffect::~LookingGlassEffect() = default;
bool LookingGlassEffect::supported()
{
return effects->compositingType() == OpenGLCompositing && !GLPlatform::instance()->supports(LimitedNPOT);
}
void LookingGlassEffect::reconfigure(ReconfigureFlags)
{
LookingGlassConfig::self()->read();
initialradius = LookingGlassConfig::radius();
radius = initialradius;
qCDebug(KWIN_LOOKINGGLASS) << "Radius from config:" << radius;
m_valid = loadData();
}
bool LookingGlassEffect::loadData()
{
ensureResources();
const QSize screenSize = effects->virtualScreenSize();
int texw = screenSize.width();
int texh = screenSize.height();
// Create texture and render target
const int levels = std::log2(qMin(texw, texh)) + 1;
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 = 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.get());
m_shader->setUniform("u_textureSize", QVector2D(screenSize.width(), screenSize.height()));
} else {
qCCritical(KWIN_LOOKINGGLASS) << "The shader failed to load!";
return false;
}
m_vbo = std::make_unique<GLVertexBuffer>(GLVertexBuffer::Static);
QVector<float> verts;
QVector<float> texcoords;
texcoords << screenSize.width() << 0.0;
verts << screenSize.width() << 0.0;
texcoords << 0.0 << 0.0;
verts << 0.0 << 0.0;
texcoords << 0.0 << screenSize.height();
verts << 0.0 << screenSize.height();
texcoords << 0.0 << screenSize.height();
verts << 0.0 << screenSize.height();
texcoords << screenSize.width() << screenSize.height();
verts << screenSize.width() << screenSize.height();
texcoords << screenSize.width() << 0.0;
verts << screenSize.width() << 0.0;
m_vbo->setData(6, 2, verts.constData(), texcoords.constData());
return true;
}
void LookingGlassEffect::toggle()
{
if (target_zoom == 1.0f) {
target_zoom = 2.0f;
if (!polling) {
polling = true;
effects->startMousePolling();
}
m_enabled = true;
} else {
target_zoom = 1.0f;
if (polling) {
polling = false;
effects->stopMousePolling();
}
if (zoom == target_zoom) {
m_enabled = false;
}
}
effects->addRepaint(cursorPos().x() - radius, cursorPos().y() - radius, 2 * radius, 2 * radius);
}
void LookingGlassEffect::zoomIn()
{
target_zoom = qMin(7.0, target_zoom + 0.5);
m_enabled = true;
if (!polling) {
polling = true;
effects->startMousePolling();
}
effects->addRepaint(magnifierArea());
}
void LookingGlassEffect::zoomOut()
{
target_zoom -= 0.5;
if (target_zoom < 1) {
target_zoom = 1;
if (polling) {
polling = false;
effects->stopMousePolling();
}
if (zoom == target_zoom) {
m_enabled = false;
}
}
effects->addRepaint(magnifierArea());
}
QRect LookingGlassEffect::magnifierArea() const
{
return QRect(cursorPos().x() - radius, cursorPos().y() - radius, 2 * radius, 2 * radius);
}
void LookingGlassEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
{
const int time = m_lastPresentTime.count() ? (presentTime - m_lastPresentTime).count() : 0;
if (zoom != target_zoom) {
double diff = time / animationTime(500.0);
if (target_zoom > zoom) {
zoom = qMin(zoom * qMax(1.0 + diff, 1.2), target_zoom);
} else {
zoom = qMax(zoom * qMin(1.0 - diff, 0.8), target_zoom);
}
qCDebug(KWIN_LOOKINGGLASS) << "zoom is now " << zoom;
radius = qBound((double)initialradius, initialradius * zoom, 3.5 * initialradius);
if (zoom <= 1.0f) {
m_enabled = false;
}
effects->addRepaint(cursorPos().x() - radius, cursorPos().y() - radius, 2 * radius, 2 * radius);
}
if (zoom != target_zoom) {
m_lastPresentTime = presentTime;
} else {
m_lastPresentTime = std::chrono::milliseconds::zero();
}
if (m_valid && m_enabled) {
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
// Start rendering to texture
GLFramebuffer::pushFramebuffer(m_fbo.get());
}
effects->prePaintScreen(data, presentTime);
}
void LookingGlassEffect::slotMouseChanged(const QPoint &pos, const QPoint &old, Qt::MouseButtons,
Qt::MouseButtons, Qt::KeyboardModifiers, Qt::KeyboardModifiers)
{
if (pos != old && m_enabled) {
effects->addRepaint(pos.x() - radius, pos.y() - radius, 2 * radius, 2 * radius);
effects->addRepaint(old.x() - radius, old.y() - radius, 2 * radius, 2 * radius);
}
}
void LookingGlassEffect::slotWindowDamaged()
{
if (isActive()) {
effects->addRepaint(magnifierArea());
}
}
void LookingGlassEffect::paintScreen(int mask, const QRegion &region, ScreenPaintData &data)
{
// Call the next effect.
effects->paintScreen(mask, region, data);
if (m_valid && m_enabled) {
// Disable render texture
GLFramebuffer *target = GLFramebuffer::popFramebuffer();
Q_ASSERT(target == m_fbo.get());
Q_UNUSED(target);
m_texture->bind();
m_texture->generateMipmaps();
// Use the 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()));
m_shader->setUniform(GLShader::ModelViewProjectionMatrix, data.projectionMatrix());
m_vbo->render(GL_TRIANGLES);
m_texture->unbind();
}
}
bool LookingGlassEffect::isActive() const
{
return m_valid && m_enabled;
}
} // namespace
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2007 Rivo Laks <rivolaks@hot.ee>
SPDX-FileCopyrightText: 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KWIN_LOOKINGGLASS_H
#define KWIN_LOOKINGGLASS_H
#include <kwineffects.h>
namespace KWin
{
class GLFramebuffer;
class GLShader;
class GLTexture;
class GLVertexBuffer;
/**
* Enhanced magnifier
*/
class LookingGlassEffect : public Effect
{
Q_OBJECT
Q_PROPERTY(int initialRadius READ initialRadius)
public:
LookingGlassEffect();
~LookingGlassEffect() override;
void reconfigure(ReconfigureFlags) override;
void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override;
void paintScreen(int mask, const QRegion &region, ScreenPaintData &data) override;
bool isActive() const override;
static bool supported();
// for properties
int initialRadius() const
{
return initialradius;
}
QRect magnifierArea() const;
public Q_SLOTS:
void toggle();
void zoomIn();
void zoomOut();
void slotMouseChanged(const QPoint &pos, const QPoint &old,
Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons,
Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers);
void slotWindowDamaged();
private:
bool loadData();
double zoom;
double target_zoom;
bool polling; // Mouse polling
int radius;
int initialradius;
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;
};
} // namespace
#endif
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile arg="true"/>
<group name="Effect-lookingglass">
<entry name="Radius" type="UInt">
<default>200</default>
</entry>
</group>
</kcfg>
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/effects/lookingglass/">
<file>shaders/lookingglass.frag</file>
<file>shaders/lookingglass_core.frag</file>
</qresource>
</RCC>
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "lookingglass_config.h"
#include <config-kwin.h>
// KConfigSkeleton
#include "lookingglassconfig.h"
#include <kwineffects_interface.h>
#include <KActionCollection>
#include <KGlobalAccel>
#include <KLocalizedString>
#include <KPluginFactory>
#include <kconfiggroup.h>
#include <QAction>
#include <QDebug>
#include <QVBoxLayout>
#include <QWidget>
K_PLUGIN_CLASS(KWin::LookingGlassEffectConfig)
namespace KWin
{
LookingGlassEffectConfigForm::LookingGlassEffectConfigForm(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
LookingGlassEffectConfig::LookingGlassEffectConfig(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)
, m_ui(this)
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(&m_ui);
LookingGlassConfig::instance(KWIN_CONFIG);
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"));
m_actionCollection->setComponentDisplayName(i18n("KWin"));
m_actionCollection->setConfigGroup(QStringLiteral("LookingGlass"));
m_actionCollection->setConfigGlobal(true);
QAction *a;
a = m_actionCollection->addAction(KStandardAction::ZoomIn);
a->setProperty("isConfigurationAction", true);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Equal));
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Equal));
a = m_actionCollection->addAction(KStandardAction::ZoomOut);
a->setProperty("isConfigurationAction", true);
KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Minus));
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::META | Qt::Key_Minus));
a = m_actionCollection->addAction(KStandardAction::ActualSize);
a->setProperty("isConfigurationAction", true);
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);
}
LookingGlassEffectConfig::~LookingGlassEffectConfig()
{
// Undo (only) unsaved changes to global key shortcuts
m_ui.editor->undo();
}
void LookingGlassEffectConfig::save()
{
qDebug() << "Saving config of LookingGlass";
KCModule::save();
m_ui.editor->save(); // undo() will restore to this state from now on
OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
QStringLiteral("/Effects"),
QDBusConnection::sessionBus());
interface.reconfigureEffect(QStringLiteral("lookingglass"));
}
void LookingGlassEffectConfig::defaults()
{
m_ui.editor->allDefault();
KCModule::defaults();
}
} // namespace
#include "lookingglass_config.moc"
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KWIN_LOOKINGGLASS_CONFIG_H
#define KWIN_LOOKINGGLASS_CONFIG_H
#include <kcmodule.h>
#include "ui_lookingglass_config.h"
class KActionCollection;
namespace KWin
{
class LookingGlassEffectConfigForm : public QWidget, public Ui::LookingGlassEffectConfigForm
{
Q_OBJECT
public:
explicit LookingGlassEffectConfigForm(QWidget *parent);
};
class LookingGlassEffectConfig : public KCModule
{
Q_OBJECT
public:
explicit LookingGlassEffectConfig(QWidget *parent = nullptr, const QVariantList &args = QVariantList());
~LookingGlassEffectConfig() override;
void save() override;
void defaults() override;
private:
LookingGlassEffectConfigForm m_ui;
KActionCollection *m_actionCollection;
};
} // namespace
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KWin::LookingGlassEffectConfigForm</class>
<widget class="QWidget" name="KWin::LookingGlassEffectConfigForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>275</width>
<height>185</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="KShortcutsEditor" name="editor" native="true">
<property name="actionTypes">
<enum>KShortcutsEditor::GlobalAction</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">