From 2bedb6bba9900b0a07ed8a7f250e77604cc4727d Mon Sep 17 00:00:00 2001 From: Andreas Demmer Date: Fri, 23 Jul 2010 19:52:20 +0000 Subject: [PATCH] initial commit of the KWin dashboard effect svn path=/trunk/KDE/kdebase/workspace/; revision=1153704 --- effects/CMakeLists.txt | 3 +- effects/blur/blur.cpp | 14 +- effects/configs_builtins.cpp | 2 + effects/dashboard/CMakeLists.txt | 24 ++ effects/dashboard/dashboard.cpp | 136 +++++++++ effects/dashboard/dashboard.desktop | 17 ++ effects/dashboard/dashboard.h | 59 ++++ effects/dashboard/dashboard_config.cpp | 89 ++++++ effects/dashboard/dashboard_config.desktop | 9 + effects/dashboard/dashboard_config.h | 54 ++++ effects/dashboard/dashboard_config.ui | 310 +++++++++++++++++++++ lib/kwineffects.h | 3 +- 12 files changed, 708 insertions(+), 12 deletions(-) create mode 100644 effects/dashboard/CMakeLists.txt create mode 100644 effects/dashboard/dashboard.cpp create mode 100644 effects/dashboard/dashboard.desktop create mode 100644 effects/dashboard/dashboard.h create mode 100644 effects/dashboard/dashboard_config.cpp create mode 100644 effects/dashboard/dashboard_config.desktop create mode 100644 effects/dashboard/dashboard_config.h create mode 100644 effects/dashboard/dashboard_config.ui diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index d718aea7e7..0c06daee9a 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -25,7 +25,7 @@ macro( KWIN4_ADD_EFFECT_CONFIG name ) kde4_add_ui_files( kwin4_effect_src ${kwin4_effect_ui} ) kde4_add_plugin( kcm_kwin4_effect_${name} ${kwin4_effect_src} ) - target_link_libraries( kcm_kwin4_effect_${name} kwineffects ${KDE4_KIO_LIBS} ${KDE4_KDEUI_LIBS} kephal ) + target_link_libraries( kcm_kwin4_effect_${name} kwineffects ${KDE4_KIO_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_PLASMA_LIBS} kephal ) install( TARGETS kcm_kwin4_effect_${name} DESTINATION ${PLUGIN_INSTALL_DIR} ) endmacro( KWIN4_ADD_EFFECT_CONFIG ) @@ -53,6 +53,7 @@ set( kwin4_effect_include_directories ) # Common effects include( boxswitch/CMakeLists.txt ) +include( dashboard/CMakeLists.txt ) include( desktopgrid/CMakeLists.txt ) include( dialogparent/CMakeLists.txt ) include( diminactive/CMakeLists.txt ) diff --git a/effects/blur/blur.cpp b/effects/blur/blur.cpp index fbed1e3598..44c93f113f 100644 --- a/effects/blur/blur.cpp +++ b/effects/blur/blur.cpp @@ -25,12 +25,6 @@ namespace KWin { - -enum { - BlurRegionRole = 0x1C50A74B -}; - - KWIN_EFFECT(blur, BlurEffect) KWIN_EFFECT_SUPPORTED(blur, BlurEffect::supported()) @@ -97,9 +91,9 @@ void BlurEffect::updateBlurRegion(EffectWindow *w) const // Set the data to a dummy value. // This is needed to be able to distinguish between the value not // being set, and being set to an empty region. - w->setData(BlurRegionRole, 1); + w->setData(WindowBlurBehindRole, 1); } else - w->setData(BlurRegionRole, region); + w->setData(WindowBlurBehindRole, region); } void BlurEffect::windowAdded(EffectWindow *w) @@ -152,7 +146,7 @@ QRegion BlurEffect::blurRegion(const EffectWindow *w) const { QRegion region; - const QVariant value = w->data(BlurRegionRole); + const QVariant value = w->data(WindowBlurBehindRole); if (value.isValid()) { const QRegion appRegion = qvariant_cast(value); if (!appRegion.isEmpty()) { @@ -229,7 +223,7 @@ void BlurEffect::drawWindow(EffectWindow *w, int mask, QRegion region, WindowPai bool valid = target->valid() && shader->isValid(); QRegion shape; - const QVariant forceBlur = w->data( WindowForceBlurRole ); + const QVariant forceBlur = w->data( WindowBlurBehindRole ); if ((!effects->activeFullScreenEffect() || (forceBlur.isValid() && forceBlur.toBool() )) && hasAlpha && !w->isDesktop() && !transformed) shape = blurRegion(w).translated(w->geometry().topLeft()) & screen; diff --git a/effects/configs_builtins.cpp b/effects/configs_builtins.cpp index 53889c83e6..7580d52034 100644 --- a/effects/configs_builtins.cpp +++ b/effects/configs_builtins.cpp @@ -23,6 +23,7 @@ along with this program. If not, see . #include #include "boxswitch/boxswitch_config.h" +#include "dashboard/dashboard_config.h" #include "desktopgrid/desktopgrid_config.h" #include "diminactive/diminactive_config.h" #include "magiclamp/magiclamp_config.h" @@ -59,6 +60,7 @@ namespace KWin KWIN_EFFECT_CONFIG_MULTIPLE( builtins, KWIN_EFFECT_CONFIG_SINGLE( boxswitch, BoxSwitchEffectConfig ) + KWIN_EFFECT_CONFIG_SINGLE( dashboard, DashboardEffectConfig ) KWIN_EFFECT_CONFIG_SINGLE( desktopgrid, DesktopGridEffectConfig ) KWIN_EFFECT_CONFIG_SINGLE( diminactive, DimInactiveEffectConfig ) KWIN_EFFECT_CONFIG_SINGLE( magiclamp, MagicLampEffectConfig ) diff --git a/effects/dashboard/CMakeLists.txt b/effects/dashboard/CMakeLists.txt new file mode 100644 index 0000000000..792c87546e --- /dev/null +++ b/effects/dashboard/CMakeLists.txt @@ -0,0 +1,24 @@ +####################################### +# Effect + +# Source files +set( kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} + dashboard/dashboard.cpp + dashboard/dashboard.cpp ) + +# .desktop files +install( FILES + dashboard/dashboard.desktop + DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) + +####################################### +# Config + +# Source files +set( kwin4_effect_builtins_config_sources ${kwin4_effect_builtins_config_sources} + dashboard/dashboard_config.cpp + dashboard/dashboard_config.ui ) + +install( FILES + dashboard/dashboard_config.desktop + DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) diff --git a/effects/dashboard/dashboard.cpp b/effects/dashboard/dashboard.cpp new file mode 100644 index 0000000000..39a0ad794d --- /dev/null +++ b/effects/dashboard/dashboard.cpp @@ -0,0 +1,136 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2010 Andreas Demmer + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ + +#include "dashboard.h" + +namespace KWin +{ +KWIN_EFFECT(dashboard, DashboardEffect) + +DashboardEffect::DashboardEffect() + : transformWindow( false ) +{ + // propagate that the effect is loaded + propagate(); + + // read settings + reconfigure(ReconfigureAll); + } + +DashboardEffect::~DashboardEffect() + { + unpropagate(); + } + +void DashboardEffect::propagate() + { + // TODO: better namespacing for atoms + atom = XInternAtom( display(), "_WM_EFFECT_KDE_DASHBOARD", false ); + effects->registerPropertyType( atom, true ); + + // TODO: maybe not the best way to propagate the loaded effect + unsigned char dummy = 0; + XChangeProperty( display(), rootWindow(), atom, atom, 8, PropModeReplace, &dummy, 1 ); + } + +void DashboardEffect::unpropagate() + { + effects->registerPropertyType(atom, false); + XDeleteProperty(display(), rootWindow(), atom); + } + +void DashboardEffect::reconfigure( ReconfigureFlags ) + { + // read settings again + KConfigGroup config = EffectsHandler::effectConfig("Dashboard"); + + brightness = config.readEntry("Brightness", "50"); + saturation = config.readEntry("Saturation", "50"); + blur = config.readEntry("Blur", false); + } + +void DashboardEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) + { + if( transformWindow && ( w != window ) && w->isManaged() ) + { + // dashboard active, transform other windows + data.brightness = brightness.toDouble() / 100; + data.saturation = saturation.toDouble() / 100; + } + + effects->paintWindow( w, mask, region, data ); + } + +void DashboardEffect::postPaintScreen() + { + if( transformWindow ) + { + if( retransformWindow ) + { + retransformWindow = false; + transformWindow = false; + effects->addRepaintFull(); + } + } + + effects->postPaintScreen(); + } + +bool DashboardEffect::isDashboard ( EffectWindow *w ) + { + if( w->windowClass() == "dashboard dashboard") + { + return true; + } + else + { + return false; + } + } + +void DashboardEffect::windowActivated( EffectWindow *w ) + { + if( !w ) + return; + + // apply effect on dashboard activation + if( isDashboard( w ) ) + { + transformWindow = true; + window = w; + + if ( blur ) + { + w->setData( WindowBlurBehindRole, w->geometry() ); + } + + effects->addRepaintFull(); + } + else + { + if( transformWindow) + { + retransformWindow = true; + effects->addRepaintFull(); + } + } + } + +} // namespace diff --git a/effects/dashboard/dashboard.desktop b/effects/dashboard/dashboard.desktop new file mode 100644 index 0000000000..a8884c1adf --- /dev/null +++ b/effects/dashboard/dashboard.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Name=Dashboard +Icon=preferences-system-windows-effect-dashboard +Comment=Desaturate the desktop when displaying the Plasma dashboard + +Type=Service +X-KDE-ServiceTypes=KWin/Effect +X-KDE-PluginInfo-Author=Andreas Demmer +X-KDE-PluginInfo-Email=ademmer@opensuse.org +X-KDE-PluginInfo-Name=kwin4_effect_dashboard +X-KDE-PluginInfo-Version=0.1.0 +X-KDE-PluginInfo-Category=Appearance +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-Library=kwin4_effect_builtins +X-KDE-Ordering=85 diff --git a/effects/dashboard/dashboard.h b/effects/dashboard/dashboard.h new file mode 100644 index 0000000000..eec6fc2b30 --- /dev/null +++ b/effects/dashboard/dashboard.h @@ -0,0 +1,59 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2010 Andreas Demmer + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ + +#ifndef KWIN_DASHBOARD_H +#define KWIN_DASHBOARD_H + +#include +#include +#include +#include + +namespace KWin +{ + +class GLRenderTarget; +class GLTexture; + +class DashboardEffect : public KWin::Effect + { + public: + DashboardEffect(); + ~DashboardEffect(); + virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); + virtual void postPaintScreen(); + virtual void propagate(); + virtual void reconfigure( ReconfigureFlags ); + virtual void unpropagate(); + virtual void windowActivated( EffectWindow *w ); + private: + bool blur; + bool isDashboard( EffectWindow* w ); + bool transformWindow; + bool retransformWindow; + long atom; + QString brightness; + QString saturation; + EffectWindow* window; + }; + +} // namespace + +#endif diff --git a/effects/dashboard/dashboard_config.cpp b/effects/dashboard/dashboard_config.cpp new file mode 100644 index 0000000000..ec71946b7e --- /dev/null +++ b/effects/dashboard/dashboard_config.cpp @@ -0,0 +1,89 @@ +/* + * Copyright © 2010 Andreas Demmer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. if not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "dashboard_config.h" +#include + +namespace KWin +{ + +KWIN_EFFECT_CONFIG_FACTORY + +DashboardEffectConfig::DashboardEffectConfig(QWidget *parent, const QVariantList &args) + : KCModule(EffectFactory::componentData(), parent, args) +{ + ui.setupUi(this); + + connect(ui.brightness, SIGNAL(valueChanged(int)), SLOT(valueChanged(int))); + connect(ui.saturation, SIGNAL(valueChanged(int)), SLOT(valueChanged(int))); + connect(ui.blur, SIGNAL(stateChanged(int)), SLOT(valueChanged(int))); + + load(); +} + +DashboardEffectConfig::~DashboardEffectConfig() +{ +} + +void DashboardEffectConfig::load() +{ + KCModule::load(); + KConfigGroup config = EffectsHandler::effectConfig("Dashboard"); + + QString brightness = config.readEntry("Brightness", "5"); + ui.brightness->setValue(brightness.toInt()); + + QString saturation = config.readEntry("Saturation", "5"); + ui.saturation->setValue(saturation.toInt()); + + bool blur = config.readEntry("Blur", false); + ui.blur->setChecked(blur); + + emit changed(false); +} + +void DashboardEffectConfig::save() +{ + KCModule::save(); + + KConfigGroup config = EffectsHandler::effectConfig("Dashboard"); + + config.writeEntry("Brightness", ui.brightness->value()); + config.writeEntry("Saturation", ui.saturation->value()); + config.writeEntry("Blur", ui.blur->isChecked()); + + config.sync(); + + emit changed(false); + EffectsHandler::sendReloadMessage("dashboard"); +} + +void DashboardEffectConfig::valueChanged(int value) +{ + Q_UNUSED(value) + emit changed(true); +} + +void DashboardEffectConfig::defaults() +{ + emit changed(true); +} + +} // namespace KWin + diff --git a/effects/dashboard/dashboard_config.desktop b/effects/dashboard/dashboard_config.desktop new file mode 100644 index 0000000000..82bb2bb2ea --- /dev/null +++ b/effects/dashboard/dashboard_config.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Service +X-KDE-ServiceTypes=KCModule + +X-KDE-Library=kcm_kwin4_effect_builtins +X-KDE-ParentComponents=kwin4_effect_dashboard +X-KDE-PluginKeyword=dashboard + +Name=Dashboard diff --git a/effects/dashboard/dashboard_config.h b/effects/dashboard/dashboard_config.h new file mode 100644 index 0000000000..60151694f8 --- /dev/null +++ b/effects/dashboard/dashboard_config.h @@ -0,0 +1,54 @@ +/* + * Copyright © 2010 Andreas Demmer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. if not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KWIN_DASHBOARD_CONFIG_H +#define KWIN_DASHBOARD_CONFIG_H + +#include +#include "ui_dashboard_config.h" + +namespace KWin +{ + +class DashboardEffectConfig : public KCModule +{ + Q_OBJECT + +public: + explicit DashboardEffectConfig(QWidget *parent = 0, const QVariantList& args = QVariantList()); + ~DashboardEffectConfig(); + + void save(); + void load(); + void defaults(); + +private: + bool isBlurEffectAvailable (); + long net_wm_dashboard; + ::Ui::DashboardEffectConfig ui; + +private slots: + void valueChanged(int value); + +}; + +} // namespace KWin + +#endif + diff --git a/effects/dashboard/dashboard_config.ui b/effects/dashboard/dashboard_config.ui new file mode 100644 index 0000000000..8963042948 --- /dev/null +++ b/effects/dashboard/dashboard_config.ui @@ -0,0 +1,310 @@ + + + DashboardEffectConfig + + + + 0 + 0 + 400 + 260 + + + + + 0 + 0 + + + + + 400 + 260 + + + + + 400 + 260 + + + + Form + + + + + 10 + 10 + 381 + 241 + + + + + + + + 0 + 0 + + + + Background brightness + + + + + 20 + 28 + 341 + 41 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + darker + + + + + + + + 150 + 35 + + + + + 150 + 35 + + + + + 150 + 25 + + + + 100 + + + 10 + + + 20 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + 10 + + + + + + + lighter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Background saturation + + + + + 20 + 20 + 339 + 50 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + gray + + + + + + + + 150 + 35 + + + + + 150 + 35 + + + + + 150 + 25 + + + + 100 + + + 10 + + + 20 + + + Qt::Horizontal + + + false + + + false + + + QSlider::NoTicks + + + 10 + + + + + + + colored + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + Effects + + + + + 20 + 30 + 341 + 41 + + + + + + + Blur background (depends on "Blur" effect) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + diff --git a/lib/kwineffects.h b/lib/kwineffects.h index dd48e89fe2..3b69f73cea 100644 --- a/lib/kwineffects.h +++ b/lib/kwineffects.h @@ -194,7 +194,8 @@ enum DataRole WindowClosedGrabRole, WindowMinimizedGrabRole, WindowUnminimizedGrabRole, - WindowForceBlurRole ///< For fullscreen effects to enforce blurring of windows + WindowForceBlurRole, ///< For fullscreen effects to enforce blurring of windows, + WindowBlurBehindRole ///< For single windows to blur behind }; /**