mirror of
https://gitdl.cn/https://github.com/chakralinux/desktop.git
synced 2025-02-04 05:47:14 +08:00
419 lines
16 KiB
Plaintext
419 lines
16 KiB
Plaintext
diff -up kdebase-workspace-4.3.95/libs/solid/control/powermanager.cpp.brightness_keys kdebase-workspace-4.3.95/libs/solid/control/powermanager.cpp
|
|
--- kdebase-workspace-4.3.95/libs/solid/control/powermanager.cpp.brightness_keys 2010-01-06 11:00:01.000000000 -0600
|
|
+++ kdebase-workspace-4.3.95/libs/solid/control/powermanager.cpp 2010-01-23 12:35:12.385641003 -0600
|
|
@@ -25,6 +25,8 @@
|
|
#include "ifaces/powermanager.h"
|
|
#include <kdebug.h>
|
|
#include <kglobal.h>
|
|
+#include <QDBusInterface>
|
|
+#include <QDBusPendingCall>
|
|
#include <QX11Info>
|
|
|
|
K_GLOBAL_STATIC(Solid::Control::PowerManagerPrivate, globalPowerManager)
|
|
@@ -160,7 +162,8 @@ bool Solid::Control::PowerManager::setBr
|
|
#ifdef Q_WS_WIN
|
|
return false;
|
|
#else
|
|
- return ( xrandr_brightlight( QX11Info::display(), brightness ) >= 0 );
|
|
+ if ( xrandr_brightlight( QX11Info::display(), brightness ) < 0 )
|
|
+ return false;
|
|
#endif
|
|
}
|
|
else
|
|
@@ -170,8 +173,12 @@ bool Solid::Control::PowerManager::setBr
|
|
SOLID_CALL(Ifaces::PowerManager *, globalPowerManager->managerBackend(), setBrightness(brightness, device));
|
|
}
|
|
//TODO - This should be done better, it will return true even if one of the calls returns false. SOLID_CALL does not allow us to get the return value.
|
|
- return true;
|
|
}
|
|
+
|
|
+ QDBusInterface iface("org.kde.kded", "/modules/powerdevil", "org.kde.PowerDevil", QDBusConnection::sessionBus());
|
|
+ if (iface.isValid())
|
|
+ iface.asyncCall("notifyOfBrightnessChange", (int) Solid::Control::PowerManager::brightness());
|
|
+ return true;
|
|
}
|
|
else
|
|
{
|
|
diff -up kdebase-workspace-4.3.95/plasma/generic/applets/battery/battery.cpp.brightness_keys kdebase-workspace-4.3.95/plasma/generic/applets/battery/battery.cpp
|
|
--- kdebase-workspace-4.3.95/plasma/generic/applets/battery/battery.cpp.brightness_keys 2010-01-23 12:35:12.366629154 -0600
|
|
+++ kdebase-workspace-4.3.95/plasma/generic/applets/battery/battery.cpp 2010-01-23 12:35:12.386640293 -0600
|
|
@@ -31,9 +31,13 @@
|
|
#include <QGraphicsGridLayout>
|
|
#include <QGraphicsLinearLayout>
|
|
#include <QDBusPendingCall>
|
|
+#include <QDesktopWidget>
|
|
#include <QLabel>
|
|
+#include <QProgressBar>
|
|
#include <QPropertyAnimation>
|
|
+#include <QTimer>
|
|
|
|
+#include <KApplication>
|
|
#include <KDebug>
|
|
#include <KIcon>
|
|
#include <KSharedConfig>
|
|
@@ -87,7 +91,8 @@ Battery::Battery(QObject *parent, const
|
|
m_labelAlpha(0),
|
|
m_labelAnimation(0),
|
|
m_acAlpha(0),
|
|
- m_acAnimation(0)
|
|
+ m_acAnimation(0),
|
|
+ m_brightnessDisplay(0)
|
|
{
|
|
//kDebug() << "Loading applet battery";
|
|
setAcceptsHoverEvents(true);
|
|
@@ -314,6 +319,7 @@ void Battery::hoverLeaveEvent(QGraphicsS
|
|
|
|
Battery::~Battery()
|
|
{
|
|
+ delete m_brightnessDisplay;
|
|
}
|
|
|
|
void Battery::suspend()
|
|
@@ -334,13 +340,17 @@ void Battery::hibernate()
|
|
|
|
void Battery::brightnessChanged(const int brightness)
|
|
{
|
|
- Solid::Control::PowerManager::setBrightness(brightness);
|
|
+ if (!m_ignoreBrightnessChange) {
|
|
+ Solid::Control::PowerManager::setBrightness(brightness);
|
|
+ }
|
|
}
|
|
|
|
-void Battery::updateSlider(const float brightness)
|
|
+void Battery::updateSlider(int brightness)
|
|
{
|
|
- if (m_brightnessSlider->value() != (int)brightness) {
|
|
- m_brightnessSlider->setValue((int) brightness);
|
|
+ if (m_brightnessSlider->value() != brightness) {
|
|
+ m_ignoreBrightnessChange = true;
|
|
+ m_brightnessSlider->setValue(brightness);
|
|
+ m_ignoreBrightnessChange = false;
|
|
}
|
|
}
|
|
|
|
@@ -363,6 +373,7 @@ void Battery::initExtenderItem(Plasma::E
|
|
// as the battery applet is also embedded into the battery's extender.
|
|
if (!m_isEmbedded && item->name() == "powermanagement") {
|
|
int row = 0;
|
|
+ m_ignoreBrightnessChange = false;
|
|
|
|
m_controls = new QGraphicsWidget(item);
|
|
m_controls->setMinimumWidth(360);
|
|
@@ -427,16 +438,12 @@ void Battery::initExtenderItem(Plasma::E
|
|
|
|
m_brightnessSlider = new Plasma::Slider(m_controls);
|
|
m_brightnessSlider->setRange(0, 100);
|
|
- m_brightnessSlider->setValue(Solid::Control::PowerManager::brightness());
|
|
+ updateSlider(Solid::Control::PowerManager::brightness());
|
|
m_brightnessSlider->nativeWidget()->setTickInterval(10);
|
|
m_brightnessSlider->setOrientation(Qt::Horizontal);
|
|
connect(m_brightnessSlider, SIGNAL(valueChanged(int)),
|
|
this, SLOT(brightnessChanged(int)));
|
|
|
|
- Solid::Control::PowerManager::Notifier *notifier = Solid::Control::PowerManager::notifier();
|
|
-
|
|
- connect(notifier, SIGNAL(brightnessChanged(float)),
|
|
- this, SLOT(updateSlider(float)));
|
|
m_controlsLayout->addItem(m_brightnessSlider, row, 1);
|
|
row++;
|
|
|
|
@@ -527,6 +534,21 @@ void Battery::initExtenderItem(Plasma::E
|
|
item->setTitle(i18n("Power Management"));
|
|
|
|
setupFonts();
|
|
+
|
|
+ m_brightnessDisplay = new QProgressBar();
|
|
+ m_brightnessDisplay->setWindowFlags(Qt::X11BypassWindowManagerHint);
|
|
+ QDesktopWidget* desktop = KApplication::kApplication()->desktop();
|
|
+ //Getting QRect of the screen where cursor is positioned
|
|
+ QRect rect = desktop->screenGeometry(QCursor::pos());
|
|
+ int width = (rect.width()/2) - (m_brightnessDisplay->width()/2);
|
|
+ int height = (rect.height()/2) - (m_brightnessDisplay->height()/2);
|
|
+ width += rect.x();
|
|
+ height += rect.y();
|
|
+ m_brightnessDisplay->move(width, height);
|
|
+ m_brightnessDisplayTimer = new QTimer(this);
|
|
+ connect(m_brightnessDisplayTimer, SIGNAL(timeout()), this, SLOT(hideOSD()));
|
|
+ QDBusConnection::sessionBus().connect("org.kde.kded", "/modules/powerdevil", "org.kde.PowerDevil",
|
|
+ "brightnessChanged", this, SLOT(showBrightnessOSD(int,bool)));
|
|
}
|
|
}
|
|
|
|
@@ -657,7 +679,7 @@ void Battery::updateStatus()
|
|
}
|
|
|
|
if (m_brightnessSlider) {
|
|
- m_brightnessSlider->setValue(Solid::Control::PowerManager::brightness());
|
|
+ updateSlider(Solid::Control::PowerManager::brightness());
|
|
}
|
|
}
|
|
|
|
@@ -999,4 +1021,34 @@ qreal Battery::acAlpha()
|
|
return m_acAlpha;
|
|
}
|
|
|
|
+void Battery::showBrightnessOSD(int brightness, bool byFnKey)
|
|
+{
|
|
+ if (byFnKey) {
|
|
+ m_brightnessDisplay->setValue(brightness);
|
|
+ m_brightnessDisplay->show();
|
|
+
|
|
+ //FIXME, how to get this to work before it is displayed for the first time?
|
|
+ QDesktopWidget* desktop = KApplication::kApplication()->desktop();
|
|
+ //Getting QRect of the screen where cursor is positioned
|
|
+ QRect rect = desktop->screenGeometry(QCursor::pos());
|
|
+ int width = (rect.width()/2) - (m_brightnessDisplay->width()/2);
|
|
+ int height = (rect.height()/2) - (m_brightnessDisplay->height()/2);
|
|
+ width += rect.x();
|
|
+ height += rect.y();
|
|
+ m_brightnessDisplay->move(width, height);
|
|
+
|
|
+ m_brightnessDisplayTimer->setInterval(2000);
|
|
+ m_brightnessDisplayTimer->start();
|
|
+
|
|
+ if (m_extenderVisible && m_brightnessSlider) {
|
|
+ updateSlider(brightness);
|
|
+ }
|
|
+ }
|
|
+}
|
|
+
|
|
+void Battery::hideOSD()
|
|
+{
|
|
+ m_brightnessDisplay->hide();
|
|
+}
|
|
+
|
|
#include "battery.moc"
|
|
diff -up kdebase-workspace-4.3.95/plasma/generic/applets/battery/battery.h.brightness_keys kdebase-workspace-4.3.95/plasma/generic/applets/battery/battery.h
|
|
--- kdebase-workspace-4.3.95/plasma/generic/applets/battery/battery.h.brightness_keys 2010-01-19 17:19:14.000000000 -0600
|
|
+++ kdebase-workspace-4.3.95/plasma/generic/applets/battery/battery.h 2010-01-23 12:35:12.386640293 -0600
|
|
@@ -39,6 +39,8 @@ namespace Plasma
|
|
class Slider;
|
|
}
|
|
|
|
+class QProgressBar;
|
|
+
|
|
class Battery : public Plasma::PopupApplet
|
|
{
|
|
Q_OBJECT
|
|
@@ -83,7 +85,7 @@ class Battery : public Plasma::PopupAppl
|
|
void sourceAdded(const QString &source);
|
|
void sourceRemoved(const QString &source);
|
|
void brightnessChanged(const int brightness);
|
|
- void updateSlider(const float brightness);
|
|
+ void updateSlider(int brightness);
|
|
void setFullBrightness();
|
|
void openConfig();
|
|
void setProfile(const QString &profile);
|
|
@@ -91,6 +93,8 @@ class Battery : public Plasma::PopupAppl
|
|
void hibernate();
|
|
void updateBattery();
|
|
void setupFonts();
|
|
+ void showBrightnessOSD(int brightness, bool byFnKey);
|
|
+ void hideOSD();
|
|
|
|
private:
|
|
void connectSources();
|
|
@@ -172,6 +176,10 @@ class Battery : public Plasma::PopupAppl
|
|
QPropertyAnimation *m_labelAnimation;
|
|
qreal m_acAlpha;
|
|
QPropertyAnimation *m_acAnimation;
|
|
+
|
|
+ bool m_ignoreBrightnessChange;
|
|
+ QProgressBar* m_brightnessDisplay;
|
|
+ QTimer* m_brightnessDisplayTimer;
|
|
};
|
|
|
|
K_EXPORT_PLASMA_APPLET(battery, Battery)
|
|
diff -up kdebase-workspace-4.3.95/powerdevil/daemon/org.kde.PowerDevil.xml.brightness_keys kdebase-workspace-4.3.95/powerdevil/daemon/org.kde.PowerDevil.xml
|
|
--- kdebase-workspace-4.3.95/powerdevil/daemon/org.kde.PowerDevil.xml.brightness_keys 2009-09-04 06:30:55.000000000 -0500
|
|
+++ kdebase-workspace-4.3.95/powerdevil/daemon/org.kde.PowerDevil.xml 2010-01-23 12:35:12.386640293 -0600
|
|
@@ -42,6 +42,10 @@
|
|
<arg type="as" direction="out" />
|
|
</method>
|
|
|
|
+ <method name="notifyOfBrightnessChange">
|
|
+ <arg type="i" direction="in" />
|
|
+ </method>
|
|
+
|
|
<signal name="lidClosed">
|
|
<arg type="i" direction="out" />
|
|
<arg type="s" direction="out" />
|
|
@@ -56,5 +60,9 @@
|
|
</signal>
|
|
<signal name="DPMSconfigUpdated">
|
|
</signal>
|
|
+ <signal name="brightnessChanged">
|
|
+ <arg type="i" direction="out" />
|
|
+ <arg type="b" direction="out" />
|
|
+ </signal>
|
|
</interface>
|
|
</node>
|
|
diff -up kdebase-workspace-4.3.95/powerdevil/daemon/PowerDevilDaemon.cpp.brightness_keys kdebase-workspace-4.3.95/powerdevil/daemon/PowerDevilDaemon.cpp
|
|
--- kdebase-workspace-4.3.95/powerdevil/daemon/PowerDevilDaemon.cpp.brightness_keys 2009-12-10 17:14:04.000000000 -0600
|
|
+++ kdebase-workspace-4.3.95/powerdevil/daemon/PowerDevilDaemon.cpp 2010-01-23 12:35:12.387639722 -0600
|
|
@@ -26,6 +26,8 @@
|
|
|
|
#include <kdemacros.h>
|
|
#include <KAboutData>
|
|
+#include <KAction>
|
|
+#include <KActionCollection>
|
|
#include <KPluginFactory>
|
|
#include <KNotification>
|
|
#include <KIcon>
|
|
@@ -93,6 +95,7 @@ public:
|
|
: notifier(Solid::Control::PowerManager::notifier())
|
|
, currentConfig(0)
|
|
, status(PowerDevilDaemon::NoAction)
|
|
+ , brightnessInHardware(false)
|
|
, ckSessionInterface(0) {}
|
|
|
|
Solid::Control::PowerManager::Notifier *notifier;
|
|
@@ -119,6 +122,8 @@ public:
|
|
|
|
int batteryPercent;
|
|
int brightness;
|
|
+ int cachedBrightness;
|
|
+ bool brightnessInHardware;
|
|
bool isPlugged;
|
|
|
|
// ConsoleKit stuff
|
|
@@ -174,6 +179,18 @@ PowerDevilDaemon::PowerDevilDaemon(QObje
|
|
d->ksmServerIface = new OrgKdeKSMServerInterfaceInterface("org.kde.ksmserver", "/KSMServer",
|
|
QDBusConnection::sessionBus(), this);
|
|
|
|
+ QDBusInterface halManager("org.freedesktop.Hal",
|
|
+ "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager",
|
|
+ QDBusConnection::systemBus());
|
|
+ QStringList panelDevices = halManager.call("FindDeviceByCapability",
|
|
+ "laptop_panel").arguments().at(0).toStringList();
|
|
+ if (!panelDevices.empty()) {
|
|
+ QDBusInterface deviceInterface("org.freedesktop.Hal", panelDevices.at(0), "org.freedesktop.Hal.Device",
|
|
+ QDBusConnection::systemBus());
|
|
+ d->brightnessInHardware = deviceInterface.call("GetPropertyBoolean",
|
|
+ "laptop_panel.brightness_in_hardware").arguments().at(0).toBool();
|
|
+ }
|
|
+
|
|
/* Not needed anymore; I am not sure if we will need that in a future, so I leave it here
|
|
* just in case.
|
|
*
|
|
@@ -198,6 +215,17 @@ PowerDevilDaemon::PowerDevilDaemon(QObje
|
|
QDBusConnection::sessionBus().registerService("org.kde.powerdevil");
|
|
// All systems up Houston, let's go!
|
|
refreshStatus();
|
|
+
|
|
+ d->cachedBrightness = (int) Solid::Control::PowerManager::brightness();
|
|
+ KActionCollection* actionCollection = new KActionCollection( this );
|
|
+
|
|
+ KAction* globalAction = static_cast< KAction* >( actionCollection->addAction( "Increase Screen Brightness" ));
|
|
+ globalAction->setGlobalShortcut(KShortcut(Qt::Key_MonBrightnessUp));
|
|
+ connect(globalAction, SIGNAL(triggered(bool)), SLOT(increaseBrightness()));
|
|
+
|
|
+ globalAction = static_cast< KAction* >( actionCollection->addAction( "Decrease Screen Brightness" ));
|
|
+ globalAction->setGlobalShortcut(KShortcut(Qt::Key_MonBrightnessDown));
|
|
+ connect(globalAction, SIGNAL(triggered(bool)), SLOT(decreaseBrightness()));
|
|
}
|
|
|
|
PowerDevilDaemon::~PowerDevilDaemon()
|
|
@@ -661,24 +689,40 @@ void PowerDevilDaemon::buttonPressed(int
|
|
}
|
|
}
|
|
|
|
-void PowerDevilDaemon::decreaseBrightness()
|
|
+void PowerDevilDaemon::incDecBrightness(bool increase)
|
|
{
|
|
if (!checkIfCurrentSessionActive()) {
|
|
return;
|
|
}
|
|
+
|
|
+ int currentBrightness = (int) Solid::Control::PowerManager::brightness();
|
|
+ if ((currentBrightness == d->cachedBrightness) && !d->brightnessInHardware)
|
|
+ {
|
|
+ int newBrightness;
|
|
+ if (increase) {
|
|
+ newBrightness = qMin(100, currentBrightness + 10);
|
|
+ }
|
|
+ else {
|
|
+ newBrightness = qMax(0, currentBrightness - 10);
|
|
+ }
|
|
|
|
- int currentBrightness = qMax(0, (int)(Solid::Control::PowerManager::brightness() - 10));
|
|
- Solid::Control::PowerManager::setBrightness(currentBrightness);
|
|
+ Solid::Control::PowerManager::setBrightness(newBrightness);
|
|
+ currentBrightness = (int) Solid::Control::PowerManager::brightness();
|
|
+ }
|
|
+
|
|
+ if (!d->brightnessInHardware) {
|
|
+ emitBrightnessChanged(currentBrightness, true);
|
|
+ }
|
|
}
|
|
|
|
-void PowerDevilDaemon::increaseBrightness()
|
|
+void PowerDevilDaemon::decreaseBrightness()
|
|
{
|
|
- if (!checkIfCurrentSessionActive()) {
|
|
- return;
|
|
- }
|
|
+ incDecBrightness(false);
|
|
+}
|
|
|
|
- int currentBrightness = qMin(100, (int)(Solid::Control::PowerManager::brightness() + 10));
|
|
- Solid::Control::PowerManager::setBrightness(currentBrightness);
|
|
+void PowerDevilDaemon::increaseBrightness()
|
|
+{
|
|
+ incDecBrightness(true);
|
|
}
|
|
|
|
void PowerDevilDaemon::shutdownNotification(bool automated)
|
|
@@ -1463,4 +1507,17 @@ void PowerDevilDaemon::setUpConsoleKit()
|
|
SLOT(refreshStatus()));
|
|
}
|
|
|
|
+void PowerDevilDaemon::notifyOfBrightnessChange(int brightness)
|
|
+{
|
|
+ emitBrightnessChanged(brightness, false);
|
|
+}
|
|
+
|
|
+void PowerDevilDaemon::emitBrightnessChanged(int brightness, bool byFnKey)
|
|
+{
|
|
+ if ((d->cachedBrightness != brightness) || byFnKey) {
|
|
+ d->cachedBrightness = brightness;
|
|
+ emit brightnessChanged(brightness, byFnKey);
|
|
+ }
|
|
+}
|
|
+
|
|
#include "PowerDevilDaemon.moc"
|
|
diff -up kdebase-workspace-4.3.95/powerdevil/daemon/PowerDevilDaemon.h.brightness_keys kdebase-workspace-4.3.95/powerdevil/daemon/PowerDevilDaemon.h
|
|
--- kdebase-workspace-4.3.95/powerdevil/daemon/PowerDevilDaemon.h.brightness_keys 2009-11-30 18:30:27.000000000 -0600
|
|
+++ kdebase-workspace-4.3.95/powerdevil/daemon/PowerDevilDaemon.h 2010-01-23 12:35:12.387639722 -0600
|
|
@@ -61,10 +61,13 @@ public Q_SLOTS:
|
|
|
|
SuspensionLockHandler *lockHandler();
|
|
|
|
+ void notifyOfBrightnessChange(int brightness);
|
|
+
|
|
private Q_SLOTS:
|
|
void acAdapterStateChanged(int state, bool forced = false);
|
|
void batteryChargePercentChanged(int percent, const QString &udi);
|
|
|
|
+ void incDecBrightness(bool increase);
|
|
void decreaseBrightness();
|
|
void increaseBrightness();
|
|
|
|
@@ -106,6 +109,7 @@ Q_SIGNALS:
|
|
void stateChanged(int, bool);
|
|
void profileChanged(const QString &, const QStringList &);
|
|
void DPMSconfigUpdated();
|
|
+ void brightnessChanged(int brightness, bool byFnKey);
|
|
|
|
private:
|
|
void lockScreen();
|
|
@@ -127,6 +131,8 @@ private:
|
|
|
|
bool checkIfCurrentSessionActive();
|
|
|
|
+ void emitBrightnessChanged(int brightness, bool byFnKey);
|
|
+
|
|
public:
|
|
enum IdleAction {
|
|
None = 0,
|