From c22b4809a58a520f3a01a1ef5c451edcf401f29c Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Mon, 28 May 2007 11:34:12 +0000 Subject: [PATCH] Add working config modules for PresentWindows and Shadow effects. You can configure shadow's offset and opacity and presentwindow's mouse activation areas (e.g. activate when mouse it at top-right corner). svn path=/trunk/KDE/kdebase/workspace/; revision=669040 --- effects/CMakeLists.txt | 16 ++++ effects/presentwindows.cpp | 6 +- effects/presentwindows_config.cpp | 128 ++++++++++++++++++++++++++ effects/presentwindows_config.desktop | 10 ++ effects/presentwindows_config.h | 43 +++++++++ effects/shadow.cpp | 12 ++- effects/shadow.h | 1 + effects/shadow_config.cpp | 107 +++++++++++++++++++++ effects/shadow_config.desktop | 10 ++ effects/shadow_config.h | 41 +++++++++ 10 files changed, 369 insertions(+), 5 deletions(-) create mode 100644 effects/presentwindows_config.cpp create mode 100644 effects/presentwindows_config.desktop create mode 100644 effects/presentwindows_config.h create mode 100644 effects/shadow_config.cpp create mode 100644 effects/shadow_config.desktop create mode 100644 effects/shadow_config.h diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 74cf672c47..ada18e68a3 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -6,6 +6,13 @@ macro(KWIN4_ADD_EFFECT name) install(TARGETS kwin4_effect_${name} DESTINATION ${PLUGIN_INSTALL_DIR}) endmacro(KWIN4_ADD_EFFECT) +macro(KWIN4_ADD_EFFECT_CONFIG name) + kde4_automoc(${ARGN}) + kde4_add_plugin(kcm_kwin4_effect_${name} ${ARGN}) + target_link_libraries(kcm_kwin4_effect_${name} ${KDE4_KUTILS_LIBS}) + install(TARGETS kcm_kwin4_effect_${name} DESTINATION ${PLUGIN_INSTALL_DIR}) +endmacro(KWIN4_ADD_EFFECT_CONFIG) + include_directories( ${CMAKE_SOURCE_DIR}/workspace/kwin/lib ) @@ -77,6 +84,15 @@ if(OPENGL_FOUND) data/blur-render.frag data/blur-render.vert DESTINATION ${DATA_INSTALL_DIR}/kwin ) + + # config modules + KWIN4_ADD_EFFECT_CONFIG( builtins presentwindows_config.cpp shadow_config.cpp ) + install( FILES + presentwindows_config.desktop + shadow_config.desktop + DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) + + endif(OPENGL_FOUND) # showfps - need both xrender and opengl diff --git a/effects/presentwindows.cpp b/effects/presentwindows.cpp index be42c2f245..7f631693b4 100644 --- a/effects/presentwindows.cpp +++ b/effects/presentwindows.cpp @@ -38,6 +38,8 @@ PresentWindowsEffect::PresentWindowsEffect() , filterTexture( NULL ) #endif { + KConfig c("kwinrc"); + KConfigGroup conf(&c, "Effect-PresentWindows"); KActionCollection* actionCollection = new KActionCollection( this ); KAction* a = (KAction*)actionCollection->addAction( "Expose" ); @@ -49,8 +51,8 @@ PresentWindowsEffect::PresentWindowsEffect() b->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::Key_F11)); connect(b, SIGNAL(triggered(bool)), this, SLOT(toggleActiveAllDesktops())); - borderActivate = ElectricTopRight; // TODO config options - borderActivateAll = ElectricNone; + borderActivate = (ElectricBorder)conf.readEntry("BorderActivate", (int)ElectricTopRight); + borderActivateAll = (ElectricBorder)conf.readEntry("BorderActivateAll", (int)ElectricNone); effects->reserveElectricBorder( borderActivate ); effects->reserveElectricBorder( borderActivateAll ); diff --git a/effects/presentwindows_config.cpp b/effects/presentwindows_config.cpp new file mode 100644 index 0000000000..b49a681112 --- /dev/null +++ b/effects/presentwindows_config.cpp @@ -0,0 +1,128 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#include "presentwindows_config.h" + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +KWIN_EFFECT_CONFIG( presentwindows, KWin::PresentWindowsEffectConfig ) + +namespace KWin +{ + +PresentWindowsEffectConfig::PresentWindowsEffectConfig(QWidget* parent, const QStringList& args) : + KCModule(KGenericFactory::componentData(), parent, args) + { + kDebug() << k_funcinfo << endl; + + QGridLayout* layout = new QGridLayout(this); + + layout->addWidget(new QLabel(i18n("Activate when cursor is at a specific edge " + "or corner of the screen:")), 0, 0, 1, 3); + layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Fixed), 1, 0, 2, 1); + + layout->addWidget(new QLabel("for windows on current desktop: "), 1, 1); + mActivateCombo = new QComboBox; + addItems(mActivateCombo); + connect(mActivateCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed())); + layout->addWidget(mActivateCombo, 1, 2); + + layout->addWidget(new QLabel("for windows all desktop: "), 2, 1); + mActivateAllCombo = new QComboBox; + addItems(mActivateAllCombo); + connect(mActivateAllCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changed())); + layout->addWidget(mActivateAllCombo, 2, 2); + + layout->addItem(new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 0, 1, 3); + + load(); + } + +PresentWindowsEffectConfig::~PresentWindowsEffectConfig() + { + kDebug() << k_funcinfo << endl; + } + +void PresentWindowsEffectConfig::addItems(QComboBox* combo) + { + combo->addItem(i18n("Top")); + combo->addItem(i18n("Top-right")); + combo->addItem(i18n("Right")); + combo->addItem(i18n("Bottom-right")); + combo->addItem(i18n("Bottom")); + combo->addItem(i18n("Bottom-left")); + combo->addItem(i18n("Left")); + combo->addItem(i18n("Top-left")); + combo->addItem(i18n("None")); + } + +void PresentWindowsEffectConfig::load() + { + kDebug() << k_funcinfo << endl; + KCModule::load(); + + KConfig c("kwinrc"); + KConfigGroup conf(&c, "Effect-PresentWindows"); + int activateBorder = conf.readEntry("BorderActivate", (int)ElectricTopRight); + if(activateBorder == (int)ElectricNone) + activateBorder--; + mActivateCombo->setCurrentIndex(activateBorder); + + int activateAllBorder = conf.readEntry("BorderActivateAll", (int)ElectricNone); + if(activateAllBorder == (int)ElectricNone) + activateAllBorder--; + mActivateAllCombo->setCurrentIndex(activateAllBorder); + emit changed(false); + } + +void PresentWindowsEffectConfig::save() + { + kDebug() << k_funcinfo << endl; + KCModule::save(); + + KConfig c("kwinrc"); + KConfigGroup conf(&c, "Effect-PresentWindows"); + + int activateBorder = mActivateCombo->currentIndex(); + if(activateBorder == (int)ELECTRIC_COUNT) + activateBorder = (int)ElectricNone; + conf.writeEntry("BorderActivate", activateBorder); + + int activateAllBorder = mActivateAllCombo->currentIndex(); + if(activateAllBorder == (int)ELECTRIC_COUNT) + activateAllBorder = (int)ElectricNone; + conf.writeEntry("BorderActivateAll", activateAllBorder); + conf.sync(); + + emit changed(false); + } + +void PresentWindowsEffectConfig::defaults() + { + kDebug() << k_funcinfo << endl; + mActivateCombo->setCurrentIndex( (int)ElectricTopRight ); + mActivateAllCombo->setCurrentIndex( (int)ElectricNone - 1 ); + emit changed(true); + } + + +} // namespace + +#include "presentwindows_config.moc" diff --git a/effects/presentwindows_config.desktop b/effects/presentwindows_config.desktop new file mode 100644 index 0000000000..af8aeb4a39 --- /dev/null +++ b/effects/presentwindows_config.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Service +ServiceTypes=KCModule + +X-KDE-Library=kcm_kwin4_effect_builtins +X-KDE-FactoryName=kcm_kwineffect_presentwindows +X-KDE-ParentComponents=kwin4_effect_presentwindows + +Name=PresentWindows diff --git a/effects/presentwindows_config.h b/effects/presentwindows_config.h new file mode 100644 index 0000000000..147ceed70e --- /dev/null +++ b/effects/presentwindows_config.h @@ -0,0 +1,43 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#ifndef KWIN_PRESENTWINDOWS_CONFIG_H +#define KWIN_PRESENTWINDOWS_CONFIG_H + +#include + +class QComboBox; + + +namespace KWin +{ + +class PresentWindowsEffectConfig : public KCModule + { + Q_OBJECT + public: + PresentWindowsEffectConfig(QWidget* parent = 0, const QStringList& args = QStringList()); + ~PresentWindowsEffectConfig(); + + virtual void save(); + virtual void load(); + virtual void defaults(); + + protected: + void addItems(QComboBox* combo); + + private: + QComboBox* mActivateCombo; + QComboBox* mActivateAllCombo; + }; + +} // namespace + +#endif diff --git a/effects/shadow.cpp b/effects/shadow.cpp index 97d550b919..fdf40fa05b 100644 --- a/effects/shadow.cpp +++ b/effects/shadow.cpp @@ -12,15 +12,21 @@ License. See the file "COPYING" for the exact licensing terms. #include +#include +#include + namespace KWin { KWIN_EFFECT( shadow, ShadowEffect ) ShadowEffect::ShadowEffect() - : shadowXOffset( 10 ) - , shadowYOffset( 10 ) { + KConfig c( "kwinrc" ); + KConfigGroup conf( &c, "Effect-Shadow" ); + shadowXOffset = conf.readEntry( "XOffset", 5 ); + shadowYOffset = conf.readEntry( "YOffset", 5 ); + shadowOpacity = (float)conf.readEntry( "Opacity", 0.2 ); } void ShadowEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time ) @@ -55,7 +61,7 @@ void ShadowEffect::drawShadow( EffectWindow* w, int mask, QRegion region, Window glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - glColor4f( 0, 0, 0, 0.2 * data.opacity ); // black + glColor4f( 0, 0, 0, shadowOpacity * data.opacity ); // black glPushMatrix(); if( mask & PAINT_WINDOW_TRANSFORMED ) diff --git a/effects/shadow.h b/effects/shadow.h index cec03be21a..3fca64e974 100644 --- a/effects/shadow.h +++ b/effects/shadow.h @@ -28,6 +28,7 @@ class ShadowEffect private: void drawShadow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); int shadowXOffset, shadowYOffset; + float shadowOpacity; }; } // namespace diff --git a/effects/shadow_config.cpp b/effects/shadow_config.cpp new file mode 100644 index 0000000000..dd9f5d1382 --- /dev/null +++ b/effects/shadow_config.cpp @@ -0,0 +1,107 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#include "shadow_config.h" + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +KWIN_EFFECT_CONFIG( shadow, KWin::ShadowEffectConfig ) + +namespace KWin +{ + +ShadowEffectConfig::ShadowEffectConfig(QWidget* parent, const QStringList& args) : + KCModule(KGenericFactory::componentData(), parent, args) + { + kDebug() << k_funcinfo << endl; + + QGridLayout* layout = new QGridLayout(this); + + layout->addWidget(new QLabel(i18n("X offset:")), 0, 0); + mShadowXOffset = new QSpinBox; + mShadowXOffset->setRange(-20, 20); + connect(mShadowXOffset, SIGNAL(valueChanged(int)), this, SLOT(changed())); + layout->addWidget(mShadowXOffset, 0, 1); + + layout->addWidget(new QLabel(i18n("Y offset:")), 1, 0); + mShadowYOffset = new QSpinBox; + mShadowYOffset->setRange(-20, 20); + connect(mShadowYOffset, SIGNAL(valueChanged(int)), this, SLOT(changed())); + layout->addWidget(mShadowYOffset, 1, 1); + + layout->addWidget(new QLabel(i18n("Shadow opacity:")), 2, 0); + mShadowOpacity = new QSpinBox; + mShadowOpacity->setRange(0, 100); + mShadowOpacity->setSuffix("%"); + connect(mShadowOpacity, SIGNAL(valueChanged(int)), this, SLOT(changed())); + layout->addWidget(mShadowOpacity, 2, 1); + + layout->addItem(new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 0, 1, 2); + + load(); + } + +ShadowEffectConfig::~ShadowEffectConfig() + { + kDebug() << k_funcinfo << endl; + } + +void ShadowEffectConfig::load() + { + kDebug() << k_funcinfo << endl; + KCModule::load(); + + KConfig c("kwinrc"); + KConfigGroup conf(&c, "Effect-Shadow"); + mShadowXOffset->setValue( conf.readEntry( "XOffset", 5 ) ); + mShadowYOffset->setValue( conf.readEntry( "YOffset", 5 ) ); + mShadowOpacity->setValue( (int)( conf.readEntry( "Opacity", 0.2 ) * 100 ) ); + + emit changed(false); + } + +void ShadowEffectConfig::save() + { + kDebug() << k_funcinfo << endl; + KCModule::save(); + + KConfig c("kwinrc"); + KConfigGroup conf(&c, "Effect-Shadow"); + conf.writeEntry( "XOffset", mShadowXOffset->value() ); + conf.writeEntry( "YOffset", mShadowYOffset->value() ); + conf.writeEntry( "Opacity", mShadowOpacity->value() / 100.0 ); + conf.sync(); + + emit changed(false); + } + +void ShadowEffectConfig::defaults() + { + kDebug() << k_funcinfo << endl; + mShadowXOffset->setValue( 5 ); + mShadowYOffset->setValue( 5 ); + mShadowOpacity->setValue( 20 ); + emit changed(true); + } + + +} // namespace + +#include "shadow_config.moc" diff --git a/effects/shadow_config.desktop b/effects/shadow_config.desktop new file mode 100644 index 0000000000..6752dc63d3 --- /dev/null +++ b/effects/shadow_config.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Encoding=UTF-8 +Type=Service +ServiceTypes=KCModule + +X-KDE-Library=kcm_kwin4_effect_builtins +X-KDE-FactoryName=kcm_kwineffect_shadow +X-KDE-ParentComponents=kwin4_effect_shadow + +Name=Shadow diff --git a/effects/shadow_config.h b/effects/shadow_config.h new file mode 100644 index 0000000000..9f33522ee5 --- /dev/null +++ b/effects/shadow_config.h @@ -0,0 +1,41 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#ifndef KWIN_SHADOW_CONFIG_H +#define KWIN_SHADOW_CONFIG_H + +#include + +class QSpinBox; + + +namespace KWin +{ + +class ShadowEffectConfig : public KCModule + { + Q_OBJECT + public: + ShadowEffectConfig(QWidget* parent = 0, const QStringList& args = QStringList()); + ~ShadowEffectConfig(); + + virtual void save(); + virtual void load(); + virtual void defaults(); + + private: + QSpinBox* mShadowXOffset; + QSpinBox* mShadowYOffset; + QSpinBox* mShadowOpacity; + }; + +} // namespace + +#endif