[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/plasma/applets/toggle-compositing
From: Martin Gräßlin <ubuntu () martin-graesslin ! com>
Date: 2009-04-18 10:23:14
Message-ID: 1240050194.437653.2481.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 955639 by graesslin:
Rework the toggle compositing plasmoid: it uses DBus to suspend/resume compositing \
instead of changing kwin's config file. It is ported to use IconWidget instead of the \
svg. The context menu allows to open kwincompositing. All files related to enabling \
the effects are removed as kwin's configuration is not changed any more
M +9 -7 CMakeLists.txt
D confirmation_dialog.cpp
D confirmation_dialog.hpp
A images/onoff_switch.svg images/onoff_switch.svg.old#946531
D images/onoff_switch.svg.old
D ktimerdialog.cpp
D ktimerdialog.h
M +99 -114 toggle_compositing.cpp
M +20 -19 toggle_compositing.hpp
--- trunk/playground/base/plasma/applets/toggle-compositing/CMakeLists.txt \
#955638:955639 @@ -2,7 +2,6 @@
find_package(KDE4 REQUIRED)
include(KDE4Defaults)
-
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
include_directories(
@@ -11,19 +10,22 @@
${KDE4_INCLUDES}
)
-set(toggle_compositing_SRCS toggle_compositing.cpp
- confirmation_dialog.cpp
- ktimerdialog.cpp)
+set(toggle_compositing_SRCS toggle_compositing.cpp)
+# this is very hackish - has to be replaced by KDEBASE_WORKSPACE_SRCS when moved to \
kwin +set(kwin_xml ${DATA_INSTALL_DIR}/../dbus-1/interfaces/org.kde.KWin.xml)
+set_source_files_properties(${kwin_xml} PROPERTIES INCLUDE "interface_util.h")
+QT4_ADD_DBUS_INTERFACE(toggle_compositing_SRCS ${kwin_xml} kwin_interface )
+
kde4_add_plugin(plasma_applet_toggle_compositing ${toggle_compositing_SRCS})
target_link_libraries(plasma_applet_toggle_compositing
- ${KDE4_PLASMA_LIBS} ${KDE4_SOLID_LIBS} ${KDE4_KDEUI_LIBS})
+ ${KDE4_PLASMA_LIBS})
install(TARGETS plasma_applet_toggle_compositing
DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES plasma-applet-toggle_compositing.desktop
DESTINATION ${SERVICES_INSTALL_DIR})
-#install(FILES images/onoff_switch.svg
-# DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/)
+install(FILES images/onoff_switch.svg
+ DESTINATION ${DATA_INSTALL_DIR}/desktoptheme/default/widgets/)
--- trunk/playground/base/plasma/applets/toggle-compositing/toggle_compositing.cpp \
#955638:955639 @@ -26,154 +26,139 @@
#include "toggle_compositing.hpp"
-#include "confirmation_dialog.hpp"
+#include "kwin_interface.h"
-#include <plasma/svg.h>
-#include <solid/powermanagement.h>
+#include <Plasma/IconWidget>
+#include <Plasma/ToolTipManager>
-#include <kdebug.h>
#include <ksharedconfig.h>
#include <kconfig.h>
-#include <QPen>
+#include <KIcon>
+#include <KIconLoader>
+#include <KToolInvocation>
+
+#include <QAction>
#include <QSizeF>
-#include <QPoint>
-#include <QTimer>
-#include <QPainter>
-#include <QGraphicsSceneMouseEvent>
#include <QtDBus/QtDBus>
+#include <QGraphicsLinearLayout>
ToggleCompositing::ToggleCompositing(QObject *parent, const QVariantList &args)
- :Plasma::Applet(parent, args){
-
+ :Plasma::Applet(parent, args)
+ , m_state( true )
+ , m_disabled( false )
+ , m_kwinInterface( NULL )
+ , m_icon( new Plasma::IconWidget )
+ {
+ setHasConfigurationInterface(false);
setBackgroundHints(NoBackground);
- resize(QSizeF(32,64));
- setAspectRatioMode(Plasma::KeepAspectRatio);
- m_btn = new Plasma::Svg(this);
- m_btn->setImagePath("widgets/onoff_switch");
- m_btn->resize(size());
- state_tmr= new QTimer();
- state_tmr->setInterval(5000);
- connect(state_tmr, SIGNAL(timeout()),
- this,SLOT(checkState()));
-}
+ resize(m_icon->sizeFromIconSize(IconSize(KIconLoader::Desktop)));
-void ToggleCompositing::init(){
+ m_kwinInterface = new OrgKdeKWinInterface( "org.kde.kwin", "/KWin", \
QDBusConnection::sessionBus() );
- kDebug() <<"state is :" << readState();
- state_tmr->start();
-}
+ connect(m_kwinInterface, SIGNAL(compositingToggled(bool)), this, \
SLOT(compositingToggled(bool))); + connect(m_icon, SIGNAL(clicked()), this, \
SLOT(clicked())); + }
-ToggleCompositing::~ToggleCompositing(){
+ToggleCompositing::~ToggleCompositing()
+ {
+ delete m_kwinInterface;
+ delete m_icon;
+ }
- state_tmr->stop();
-
- delete state_tmr;
- delete m_btn;
-
-}
+void ToggleCompositing::init()
+ {
+ createMenu();
+ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(this);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->setSpacing(0);
+ layout->addItem(m_icon);
+ readState();
+ updateIcon();
+ }
-bool ToggleCompositing::readState(void){
+void ToggleCompositing::createMenu()
+ {
+ QAction* configureEffects = new QAction( SmallIcon("configure"), \
i18n("&Configure Desktop Effects..."), this ); + m_actions.append( \
configureEffects ); + connect( configureEffects, SIGNAL(triggered(bool)), this, \
SLOT(configureCompositing())); + }
- KSharedConfigPtr mKWinConfig=KSharedConfig::openConfig("kwinrc");
- KConfigGroup config(mKWinConfig, "Compositing");
- m_state=config.readEntry("Enabled", false);
-
- return m_state;
-}
+QList<QAction*> ToggleCompositing::contextualActions()
+ {
+ return m_actions;
+ }
-void ToggleCompositing::writeState(bool state){
+void ToggleCompositing::configureCompositing()
+ {
+ QString error;
+ KToolInvocation::startServiceByDesktopName( "kwincompositing", QStringList(), \
&error ); + }
+void ToggleCompositing::readState()
+ {
+ // TODO: we have to read the state whenever kwin config is changed
KSharedConfigPtr mKWinConfig=KSharedConfig::openConfig("kwinrc");
KConfigGroup config(mKWinConfig, "Compositing");
- m_state=config.readEntry("Enabled", false);
+ // TODO: compositing prefs
+ m_disabled = !config.readEntry("Enabled", true);
- if(m_state!=state){
+ if( !m_disabled && m_kwinInterface->compositingActive() )
+ m_state = true;
+ else
+ m_state = false;
+ }
- config.writeEntry("Enabled", state);
- m_state=state;
- mKWinConfig->sync();
+void ToggleCompositing::compositingToggled( bool active )
+ {
+ m_state = active;
+ m_icon->setSvg( "widgets/onoff_switch", m_state?"on":"off" );
+ updateIcon();
+ }
+void ToggleCompositing::clicked()
+ {
+ if( !m_disabled )
+ m_kwinInterface->toggleCompositing();
}
-}
-void ToggleCompositing::toggleState(void){
-
- kDebug() <<"state was :" << m_state;
- writeState(not m_state);
- reload();
- kDebug() <<"state is :" << m_state;
-}
-
-void ToggleCompositing::checkState(void){
-
- bool old_state=m_state;
-
- if(old_state!=readState())
- update();
-
-}
-
-void ToggleCompositing::reload(void){
-
- QDBusMessage message = QDBusMessage::createSignal("/KWin",
- "org.kde.KWin",
- "reloadConfig");
- QDBusConnection::sessionBus().send(message);
-
-}
-
-bool ToggleCompositing::tryChangeState(void){
-
- toggleState();
-
- update();
- if(m_state){
- ConfirmDialog confdial;
- if(!confdial.exec()){
- toggleState();
- update();
- return false;
+void ToggleCompositing::updateIcon()
+ {
+ Plasma::ToolTipContent data;
+ data.setMainText( i18n("Compositing state") );
+ if( m_disabled )
+ {
+ // Compositing is disabled in settings
+ data.setSubText( i18n("Compositing is disabled in settings") );
}
+ else
+ {
+ if( m_state )
+ {
+ data.setSubText( i18n("Compositing is active") );
+ m_icon->setSvg( "widgets/onoff_switch", "on" );
+ }
+ else
+ {
+ data.setSubText( i18n("Compositing is temporarily suspended") );
+ m_icon->setSvg( "widgets/onoff_switch", "off" );
+ }
+ }
+ data.setImage( KIcon("kwin") );
+ m_icon->update();
+ Plasma::ToolTipManager::self()->setContent( this, data );
}
- return true;
-}
-void ToggleCompositing::mousePressEvent(QGraphicsSceneMouseEvent *event){
-
- if (event->buttons () == Qt::LeftButton &&
- rect().contains(event->pos()) ){
-
- tryChangeState();
-
- return;
- }
-
- Applet::mousePressEvent(event);
-
-}
-
-void ToggleCompositing::paintInterface(QPainter *p,
- const QStyleOptionGraphicsItem *option,
- const QRect &contentsRect){
- Q_UNUSED(option)
- Q_UNUSED(contentsRect)
-
- QString elementid=(m_state)?"on":"off";
-
- m_btn->paint(p, QRectF( QPointF( 0, 0 ),
- m_btn->elementSize(elementid) ),
- elementid);
-}
-
void ToggleCompositing::constraintsEvent(Plasma::Constraints constraints)
{
setBackgroundHints(Plasma::Applet::NoBackground);
- if (constraints & Plasma::SizeConstraint)
- m_btn->resize(geometry().size());
+// if (constraints & Plasma::SizeConstraint)
+// m_btn->resize(geometry().size());
+ // TODO: constraint handling
+ updateIcon();
}
#include "toggle_compositing.moc"
--- trunk/playground/base/plasma/applets/toggle-compositing/toggle_compositing.hpp \
#955638:955639 @@ -27,17 +27,19 @@
#ifndef TOGGLE_COMPOSITING_HPP
#define TOGGLE_COMPOSITING_HPP
+#include <QList>
+
#include <Plasma/Applet>
+#include "kwin_interface.h"
+
namespace Plasma {
- class Svg;
+ class IconWidget;
}
-class QString;
-class QTimer;
-class QGraphicsSceneMouseEvent;
+class QAction;
class ToggleCompositing : public Plasma::Applet{
Q_OBJECT
@@ -46,27 +48,26 @@
~ToggleCompositing();
void init();
- void paintInterface(QPainter *painter,
- const QStyleOptionGraphicsItem *option,
- const QRect& contentsRect);
- void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ virtual QList<QAction*> contextualActions();
- bool readState(void);
- bool tryChangeState(void);
-
- public slots:
- void checkState(void);
-
protected:
void constraintsEvent(Plasma::Constraints);
- void toggleState(void);
- void reload(void);
- void writeState(bool);
+ void createMenu();
+ private slots:
+ void compositingToggled( bool active );
+ void clicked();
+ void updateIcon();
+ void configureCompositing();
+
private:
- QTimer *state_tmr;
+ void readState(void);
+
bool m_state;
- Plasma::Svg *m_btn;
+ bool m_disabled;
+ OrgKdeKWinInterface* m_kwinInterface;
+ Plasma::IconWidget* m_icon;
+ QList<QAction*> m_actions;
};
K_EXPORT_PLASMA_APPLET(toggle_compositing, ToggleCompositing )
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic