[colorcorrection] Introduce toggle Night Color shortcut
Summary: The new shortcut can be useful if a user wants to quickly disable the Night Color manager for a brief moment. FEATURE: 409083 Reviewers: #kwin, davidedmundson, romangg Reviewed By: #kwin, davidedmundson, romangg Subscribers: romangg, ngraham, broulik, davidedmundson, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D22287
This commit is contained in:
parent
6f7bea3acd
commit
b18351669a
3 changed files with 77 additions and 2 deletions
|
@ -31,9 +31,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include <colorcorrect_settings.h>
|
||||
|
||||
#include <QTimer>
|
||||
#include <KGlobalAccel>
|
||||
#include <KLocalizedString>
|
||||
|
||||
#include <QAction>
|
||||
#include <QDBusConnection>
|
||||
#include <QSocketNotifier>
|
||||
#include <QTimer>
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <sys/timerfd.h>
|
||||
|
@ -152,6 +156,53 @@ void Manager::reparseConfigAndReset()
|
|||
hardReset();
|
||||
}
|
||||
|
||||
// FIXME: The internal OSD service doesn't work on X11 right now. Once the QPA
|
||||
// is ported away from Wayland, drop this function in favor of the internal
|
||||
// OSD service.
|
||||
static void showStatusOsd(bool enabled)
|
||||
{
|
||||
// TODO: Maybe use different icons?
|
||||
const QString iconName = enabled
|
||||
? QStringLiteral("preferences-desktop-display-nightcolor-on")
|
||||
: QStringLiteral("preferences-desktop-display-nightcolor-off");
|
||||
|
||||
const QString text = enabled
|
||||
? i18nc("Night Color was enabled", "Night Color On")
|
||||
: i18nc("Night Color was disabled", "Night Color Off");
|
||||
|
||||
QDBusMessage message = QDBusMessage::createMethodCall(
|
||||
QStringLiteral("org.kde.plasmashell"),
|
||||
QStringLiteral("/org/kde/osdService"),
|
||||
QStringLiteral("org.kde.osdService"),
|
||||
QStringLiteral("showText"));
|
||||
message.setArguments({ iconName, text });
|
||||
|
||||
QDBusConnection::sessionBus().asyncCall(message);
|
||||
}
|
||||
|
||||
void Manager::toggle()
|
||||
{
|
||||
if (!kwinApp()->platform()->supportsGammaControl()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_active = !m_active;
|
||||
|
||||
showStatusOsd(m_active);
|
||||
|
||||
resetAllTimers();
|
||||
}
|
||||
|
||||
void Manager::initShortcuts()
|
||||
{
|
||||
QAction *toggleAction = new QAction(this);
|
||||
toggleAction->setProperty("componentName", QStringLiteral(KWIN_NAME));
|
||||
toggleAction->setObjectName(i18n("Toggle Night Color"));
|
||||
toggleAction->setText(i18n("Toggle Night Color"));
|
||||
KGlobalAccel::setGlobalShortcut(toggleAction, QList<QKeySequence>());
|
||||
input()->registerShortcut(QKeySequence(), toggleAction, this, &Manager::toggle);
|
||||
}
|
||||
|
||||
void Manager::readConfig()
|
||||
{
|
||||
Settings *s = Settings::self();
|
||||
|
|
|
@ -32,7 +32,7 @@ class QTimer;
|
|||
namespace KWin
|
||||
{
|
||||
|
||||
class Platform;
|
||||
class Workspace;
|
||||
|
||||
namespace ColorCorrect
|
||||
{
|
||||
|
@ -74,6 +74,24 @@ public:
|
|||
bool changeConfiguration(QHash<QString, QVariant> data);
|
||||
void autoLocationUpdate(double latitude, double longitude);
|
||||
|
||||
/**
|
||||
* Toggles the active state of the filter.
|
||||
*
|
||||
* A quick transition will be started if the difference between current screen
|
||||
* color temperature and target screen color temperature is too large. Target
|
||||
* temperature is defined in context of the new active state.
|
||||
*
|
||||
* If the filter becomes inactive after calling this method, the target color
|
||||
* temperature is 6500 K.
|
||||
*
|
||||
* If the filter becomes active after calling this method, the target screen
|
||||
* color temperature is defined by the current operation mode.
|
||||
*
|
||||
* Note that this method is a no-op if the underlying platform doesn't support
|
||||
* adjusting gamma ramps.
|
||||
**/
|
||||
void toggle();
|
||||
|
||||
// for auto tests
|
||||
void reparseConfigAndReset();
|
||||
|
||||
|
@ -85,6 +103,7 @@ Q_SIGNALS:
|
|||
void configChange(QHash<QString, QVariant> data);
|
||||
|
||||
private:
|
||||
void initShortcuts();
|
||||
void readConfig();
|
||||
void hardReset();
|
||||
void slowUpdate(int targetTemp);
|
||||
|
@ -139,6 +158,9 @@ private:
|
|||
int m_nightTargetTemp = DEFAULT_NIGHT_TEMPERATURE;
|
||||
|
||||
int m_failedCommitAttempts = 0;
|
||||
|
||||
// The Workspace class needs to call initShortcuts during initialization.
|
||||
friend class KWin::Workspace;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "useractions.h"
|
||||
#include "cursor.h"
|
||||
#include "client.h"
|
||||
#include "colorcorrection/manager.h"
|
||||
#include "composite.h"
|
||||
#include "input.h"
|
||||
#include "workspace.h"
|
||||
|
@ -1116,6 +1117,7 @@ void Workspace::initShortcuts()
|
|||
TabBox::TabBox::self()->initShortcuts();
|
||||
#endif
|
||||
VirtualDesktopManager::self()->initShortcuts();
|
||||
kwinApp()->platform()->colorCorrectManager()->initShortcuts();
|
||||
m_userActionsMenu->discard(); // so that it's recreated next time
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue