diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index a494100db7..cd9bdeed6e 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -162,6 +162,7 @@ if(KWIN_HAVE_OPENGL_COMPOSITING) magnifier_config.desktop mousemark_config.desktop sharpen_config.desktop + showfps_config.desktop snow_config.desktop trackmouse_config.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) @@ -177,6 +178,13 @@ if(KWIN_HAVE_OPENGL_COMPOSITING AND KWIN_HAVE_XRENDER_COMPOSITING) showfps.desktop showpaint.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) + SET(kwin4_effect_builtins_config_sources ${kwin4_effect_builtins_config_sources} + showfps_config.cpp + showfps_config.ui + ) + install( FILES + showfps_config.desktop + DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) endif(KWIN_HAVE_OPENGL_COMPOSITING AND KWIN_HAVE_XRENDER_COMPOSITING) # add the plugin diff --git a/effects/configs_builtins.cpp b/effects/configs_builtins.cpp index 36f06d9553..09cb832a06 100644 --- a/effects/configs_builtins.cpp +++ b/effects/configs_builtins.cpp @@ -38,6 +38,7 @@ along with this program. If not, see . #include "sharpen_config.h" #include "snow_config.h" #include "trackmouse_config.h" +#include "showfps_config.h" #endif #include @@ -65,6 +66,7 @@ KWIN_EFFECT_CONFIG_FACTORY registerPlugin("sharpen"); \ registerPlugin("snow"); \ registerPlugin("trackmouse"); \ + registerPlugin ("showfps"); \ #ifdef KWIN_HAVE_OPENGL_COMPOSITING K_PLUGIN_FACTORY_DEFINITION(EffectFactory, diff --git a/effects/showfps.cpp b/effects/showfps.cpp index 19b815c4fc..8d1bab4cf5 100644 --- a/effects/showfps.cpp +++ b/effects/showfps.cpp @@ -35,7 +35,7 @@ along with this program. If not, see . #endif #include - +#include namespace KWin { @@ -48,6 +48,7 @@ const int MAX_TIME = 100; ShowFpsEffect::ShowFpsEffect() : paints_pos( 0 ) , frames_pos( 0 ) + , fpsText(0) { for( int i = 0; i < NUM_PAINTS; @@ -73,8 +74,46 @@ ShowFpsEffect::ShowFpsEffect() else if ( y < 0 ) y = displayHeight() - MAX_TIME - y; fps_rect = QRect( x, y, FPS_WIDTH + 2*NUM_PAINTS, MAX_TIME ); + + config = effects->effectConfig("ShowFps"); + int textPosition = config.readEntry("TextPosition", int(INSIDE_GRAPH)); + textFont = config.readEntry("TextFont", QFont()); + textColor = config.readEntry("TextColor", QColor()); + double textAlpha = config.readEntry("TextAlpha", 1.0); + + if(!textColor.isValid()) + textColor = QPalette().color(QPalette::Active, QPalette::WindowText); + textColor.setAlphaF(textAlpha); + + switch(textPosition) + { + case TOP_LEFT: + fpsTextRect = QRect(0, 0, 100, 100); + textAlign = Qt::AlignTop|Qt::AlignLeft; + break; + case TOP_RIGHT: + fpsTextRect = QRect(displayWidth()-100, 0, 100, 100); + textAlign = Qt::AlignTop|Qt::AlignRight; + break; + case BOTTOM_LEFT: + fpsTextRect = QRect(0, displayHeight()-100, 100, 100); + textAlign = Qt::AlignBottom|Qt::AlignLeft; + break; + case BOTTOM_RIGHT: + fpsTextRect = QRect(displayWidth()-100, displayHeight()-100, 100, 100); + textAlign = Qt::AlignBottom|Qt::AlignRight; + break; + case NOWHERE: + fpsTextRect = QRect(); + break; + case INSIDE_GRAPH: + default: + fpsTextRect = QRect(x, y, FPS_WIDTH + NUM_PAINTS, MAX_TIME); + textAlign = Qt::AlignTop|Qt::AlignRight; + break; + } } - + void ShowFpsEffect::prePaintScreen( ScreenPrePaintData& data, int time ) { if( time == 0 ) { @@ -176,6 +215,9 @@ void ShowFpsEffect::paintGL( int fps ) // Paint amount of rendered pixels graph paintDrawSizeGraph( x, y ); + + // Paint FPS numerical value + paintFPSText(fps); // Paint paint sizes glPopAttrib(); @@ -382,4 +424,25 @@ void ShowFpsEffect::postPaintScreen() effects->addRepaint( fps_rect ); } +void ShowFpsEffect::paintFPSText(int fps) + { + if( !fpsTextRect.isValid()) + return; +#ifdef KWIN_HAVE_OPENGL_COMPOSITING + QImage im(100, 100, QImage::Format_ARGB32); + im.fill(Qt::transparent); + QPainter painter(&im); + painter.setFont(textFont); + painter.setPen(textColor); + painter.drawText(QRect(0, 0, 100, 100), textAlign, QString::number(fps)); + if(fpsText) + delete fpsText; + fpsText = new GLTexture(im); + fpsText->bind(); + fpsText->render(false, QRegion(fpsTextRect), fpsTextRect); + fpsText->unbind(); + effects->addRepaint(fpsTextRect); +#endif + } + } // namespace diff --git a/effects/showfps.h b/effects/showfps.h index e5742b1100..d6a3d0bed7 100644 --- a/effects/showfps.h +++ b/effects/showfps.h @@ -22,6 +22,7 @@ along with this program. If not, see . #define KWIN_SHOWFPS_H #include +#include #include @@ -37,12 +38,14 @@ class ShowFpsEffect virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ); virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); virtual void postPaintScreen(); + enum { INSIDE_GRAPH, NOWHERE, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; // fps text position private: void paintGL( int fps ); void paintXrender( int fps ); void paintFPSGraph(int x, int y); void paintDrawSizeGraph(int x, int y); void paintGraph( int x, int y, QList values, QList lines, bool colorize); + void paintFPSText(int fps); QTime t; enum { NUM_PAINTS = 100 }; // remember time needed to paint this many paints int paints[ NUM_PAINTS ]; // time needed to paint @@ -55,6 +58,12 @@ class ShowFpsEffect int x; int y; QRect fps_rect; + GLTexture *fpsText; + int textPosition; + QFont textFont; + QColor textColor; + QRect fpsTextRect; + int textAlign; }; } // namespace diff --git a/effects/showfps_config.cpp b/effects/showfps_config.cpp new file mode 100644 index 0000000000..d8f2de3f98 --- /dev/null +++ b/effects/showfps_config.cpp @@ -0,0 +1,121 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +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 "showfps_config.h" + +#include + +#include +#include + +#include +#ifndef KDE_USE_FINAL +KWIN_EFFECT_CONFIG_FACTORY +#endif + +namespace KWin +{ + +ShowFpsEffectConfig::ShowFpsEffectConfig(QWidget* parent, const QVariantList& args) : + KCModule(EffectFactory::componentData(), parent, args) + { + kDebug(); + + m_ui = new Ui::ShowFpsEffectConfigForm; + m_ui->setupUi(this); + + connect(m_ui->textPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(changed())); + connect(m_ui->textFont, SIGNAL(fontSelected(const QFont&)), this, SLOT(changed())); + connect(m_ui->textColor, SIGNAL(changed(const QColor&)), this, SLOT(changed())); + connect(m_ui->textAlpha, SIGNAL(valueChanged(double)), this, SLOT(changed())); + + load(); + } + +ShowFpsEffectConfig::~ShowFpsEffectConfig() + { + delete m_ui; + kDebug(); + } + +void ShowFpsEffectConfig::load() + { + kDebug(); + KCModule::load(); + + KConfigGroup conf = EffectsHandler::effectConfig("ShowFps"); + + int position = conf.readEntry("TextPosition", int(ShowFpsEffect::INSIDE_GRAPH)); + if(position > -1) + m_ui->textPosition->setCurrentIndex(position); + + QFont font = conf.readEntry("TextFont", QFont()); + m_ui->textFont->setFont(font); + + QColor color = conf.readEntry("TextColor", QColor()); + if(color.isValid()) + m_ui->textColor->setColor(color); + + double alpha = conf.readEntry("TextAlpha", 1.0); + m_ui->textAlpha->setValue(alpha); + + emit changed(false); + } + +void ShowFpsEffectConfig::save() + { + kDebug(); + KCModule::save(); + + KConfigGroup conf = EffectsHandler::effectConfig("ShowFps"); + + int position = m_ui->textPosition->currentIndex(); + conf.writeEntry("TextPosition", position); + + QFont font = m_ui->textFont->font(); + conf.writeEntry("TextFont", font); + + QColor color = m_ui->textColor->color(); + conf.writeEntry("TextColor", color); + + double alpha = m_ui->textAlpha->value(); + conf.writeEntry("TextAlpha", alpha); + + conf.sync(); + + emit changed(false); + EffectsHandler::sendReloadMessage("showfps"); + } + +void ShowFpsEffectConfig::defaults() + { + kDebug(); + + m_ui->textPosition->setCurrentIndex(0); + m_ui->textFont->setFont(QFont()); + m_ui->textColor->setColor(QColor()); + m_ui->textAlpha->setValue(1.0); + + emit changed(true); + } + +} // namespace + +#include "showfps_config.moc" diff --git a/effects/showfps_config.desktop b/effects/showfps_config.desktop new file mode 100644 index 0000000000..b729e0746f --- /dev/null +++ b/effects/showfps_config.desktop @@ -0,0 +1,57 @@ +[Desktop Entry] +Type=Service +X-KDE-ServiceTypes=KCModule + +X-KDE-Library=kcm_kwin4_effect_builtins +X-KDE-ParentComponents=kwin4_effect_showfps +X-KDE-PluginKeyword=showfps + +Name=Show FPS +Name[ar]=أظهر FPS +Name[bg]=Показване на к/с +Name[ca]=Mostra els FPS +Name[csb]=Wëskrzëni FPS +Name[da]=Vis FPS +Name[de]=Bilder pro Sekunde anzeigen +Name[el]=Εμφάνιση καρέ ανά δευτερόλεπτο +Name[eo]=Montri FPS +Name[es]=Muestra FPS +Name[et]=FPS-i näitamine +Name[eu]=Erakutsi FPS +Name[fa]=نمایش FPS +Name[fi]=Näytä FPS +Name[fr]=Affiche l'im/s +Name[fy]=FPS sjen litte +Name[ga]=Taispeáin FSS +Name[gl]=Mostrar os FPS +Name[he]=הצג מסגרות לשנייה +Name[hi]=एफ़पीएस दिखायें +Name[hu]=Képkockaszámláló megjelenítése +Name[is]=Sýna FPS (rammar á sekúndu) +Name[it]=Mostra FPS +Name[ja]=フレームレート (FPS) 表示 +Name[kk]=FPS-ты көрсету +Name[km]=បង្ហាញ FPS +Name[ko]=FPS 표시 +Name[lv]=Rādīt kadrus/sek +Name[nb]=Vis FPS +Name[nds]=Bps wiesen +Name[ne]=एफपीएस देखाउनुहोस् +Name[nl]=FPS tonen +Name[nn]=Vis FPS +Name[pa]=FPS ਵੇਖੋ +Name[pl]=Pokaż FPS +Name[pt]=Mostrar as IPS +Name[pt_BR]=Mostrar FPS +Name[se]=Čájet rámmaid sekunddas +Name[sl]=Sličice na sekundo +Name[sr]=Кадрови/секунди +Name[sr@latin]=Kadrovi/sekundi +Name[sv]=Visa ramar/s +Name[tr]=FPS Göster +Name[uk]=Показати FPS +Name[vi]=Hiện FPS +Name[wa]=Mostrer FPS +Name[x-test]=xxShow FPSxx +Name[zh_CN]=显示 FPS +Name[zh_TW]=顯示每秒幾張 diff --git a/effects/showfps_config.h b/effects/showfps_config.h new file mode 100644 index 0000000000..90dab68371 --- /dev/null +++ b/effects/showfps_config.h @@ -0,0 +1,52 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +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_SHOWFPS_CONFIG_H +#define KWIN_SHOWFPS_CONFIG_H + +#define KDE3_SUPPORT +#include +#undef KDE3_SUPPORT + +#include "ui_showfps_config.h" +#include "showfps.h" + +namespace KWin +{ + +class ShowFpsEffectConfig : public KCModule + { + Q_OBJECT + public: + explicit ShowFpsEffectConfig(QWidget* parent = 0, const QVariantList& args = QVariantList()); + ~ShowFpsEffectConfig(); + + public slots: + virtual void save(); + virtual void load(); + virtual void defaults(); + + private: + Ui::ShowFpsEffectConfigForm *m_ui; + }; + +} // namespace + +#endif diff --git a/effects/showfps_config.ui b/effects/showfps_config.ui new file mode 100644 index 0000000000..88a60225a5 --- /dev/null +++ b/effects/showfps_config.ui @@ -0,0 +1,193 @@ + + KWin::ShowFpsEffectConfigForm + + + + 0 + 0 + 400 + 194 + + + + Form + + + + + + Text + + + + + + + + Text Position + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Inside Graph + + + + + Nowhere + + + + + Top Left + + + + + Top Right + + + + + Bottom Left + + + + + Bottom Right + + + + + + + + + + + + Text Font + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Text Color + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Text Alpha + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 2 + + + 1.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + + + + + + + KColorButton + QPushButton +
kcolorbutton.h
+
+ + KFontRequester + QWidget +
kfontrequester.h
+
+
+ + +