Skip to content

Commit

Permalink
[daemon] [settingsui] setting to keep display on when keyboard attached
Browse files Browse the repository at this point in the history
request prevent blanking from mce

Relates to #29
  • Loading branch information
kimmoli committed Sep 16, 2015
1 parent a18782f commit 7284c0d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 17 deletions.
1 change: 1 addition & 0 deletions daemon/src/defaultSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define FORCE_BACKLIGHT_ON false

#define TURN_DISPLAY_OFF_WHEN_REMOVED false
#define KEEP_DISPLAY_ON_WHEN_CONNECTED false

#define MASTER_LAYOUT "Scandic"

Expand Down
87 changes: 78 additions & 9 deletions daemon/src/tohkeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Tohkbd::Tohkbd(QObject *parent) :
gpioInterruptCounter = 0;
verboseMode = true;
turnDisplayOffWhenRemoved = false;
keepDisplayOnWhenConnected = false;
displayBlankPreventRequested = false;

fix_CapsLock = !checkSailfishVersion("1.1.7.0");
capsLock = false;
Expand Down Expand Up @@ -113,6 +115,10 @@ bool Tohkbd::init()
repeatTimer->setSingleShot(true);
connect(repeatTimer, SIGNAL(timeout()), this, SLOT(repeatTimerTimeout()));

displayBlankPreventTimer = new QTimer(this);
displayBlankPreventTimer->setSingleShot(true);
connect(displayBlankPreventTimer, SIGNAL(timeout()), this, SLOT(displayBlankPreventTimerTimeout()));

/* do this automatically at startup */
setVddState(true);
setInterruptEnable(true);
Expand Down Expand Up @@ -316,26 +322,32 @@ bool Tohkbd::setInterruptEnable(bool state)
*/
void Tohkbd::handleDisplayStatus(const QDBusMessage& msg)
{
QList<QVariant> args = msg.arguments();
const char *turn = qPrintable(args.at(0).toString());
bool __previousDisplayStatus = displayIsOn;
QString turn = msg.arguments().at(0).toString();

if (verboseMode)
printf("Display status changed to \"%s\"\n", turn);
printf("Display status changed to \"%s\"\n", qPrintable(turn));

if (strcmp(turn, "on") == 0)
if (turn.compare("on", Qt::CaseInsensitive) == 0)
{
controlLeds(true);
checkDoWeNeedBacklight();
displayIsOn = true;
slideEventEmitted = false;
}
else if (strcmp(turn, "off") == 0)
else if (turn.compare("off", Qt::CaseInsensitive) == 0)
{
displayIsOn = false;

backlightTimer->stop();
controlLeds(false);
}

if (displayIsOn != __previousDisplayStatus)
{
/* blank preventing or cancelling */
displayBlankPreventTimerTimeout();
}
}

/* Check is keypad present
Expand Down Expand Up @@ -409,11 +421,26 @@ bool Tohkbd::checkKeypadPresence()
changeOrientationLock();
}

if (turnDisplayOffWhenRemoved && !keypadIsPresent && displayIsOn)
if (keypadIsPresent)
{
/* if enabled and display is on, turn display off when keyboard is removed */
QDBusMessage m = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_DISPLAY_OFF_REQ);
QDBusConnection::systemBus().send(m);
/* If display is off, this does nothing. It is called again when display turns on */
displayBlankPreventTimerTimeout();
}
else // not present
{
if (keepDisplayOnWhenConnected)
{
displayBlankPreventTimerTimeout(true);
}
if (turnDisplayOffWhenRemoved && displayIsOn)
{
/* if enabled and display is on, turn display off when keyboard is removed */
if (verboseMode)
printf("request mce to turn display off\n");

QDBusMessage m = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_DISPLAY_OFF_REQ);
QDBusConnection::systemBus().send(m);
}
}
}

Expand Down Expand Up @@ -898,6 +925,39 @@ void Tohkbd::backlightTimerTimeout()
tca8424->setLeds(LED_BACKLIGHT_OFF);
}

/*
* Display blank prevention. If enabled and display is on, request blank prevent from mce
* and restart timer.
* otherwise, cancel request
*/
void Tohkbd::displayBlankPreventTimerTimeout(bool forceCancel)
{
if (keepDisplayOnWhenConnected && displayIsOn && !forceCancel)
{
if (verboseMode)
printf("requesting mce to prevent blanking\n");

QDBusMessage m = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_PREVENT_BLANK_REQ);
QDBusConnection::systemBus().send(m);
displayBlankPreventTimer->start(30000);
displayBlankPreventRequested = true;
}
else if (displayBlankPreventRequested || forceCancel)
{
if (verboseMode)
printf("cancelling blanking prevent request %s\n", forceCancel ? "(forced)" : "");

if (forceCancel)
{
displayBlankPreventTimer->stop();
}

QDBusMessage m = QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, MCE_CANCEL_PREVENT_BLANK_REQ);
QDBusConnection::systemBus().send(m);
displayBlankPreventRequested = false;
}
}

/* Change virtual keyboard active layout,
* uses private: vkbLayoutIsTohkbd
* true = change to harbour-tohkbd2.qml
Expand Down Expand Up @@ -1069,6 +1129,7 @@ void Tohkbd::reloadSettings()
forceLandscapeOrientation = settings.value("forceLandscapeOrientation", FORCE_LANDSCAPE_ORIENTATION).toBool();
forceBacklightOn = settings.value("forceBacklightOn", FORCE_BACKLIGHT_ON).toBool();
turnDisplayOffWhenRemoved = settings.value("turnDisplayOffWhenRemoved", TURN_DISPLAY_OFF_WHEN_REMOVED).toBool();
keepDisplayOnWhenConnected = settings.value("keepDisplayOnWhenConnected", KEEP_DISPLAY_ON_WHEN_CONNECTED).toBool();
settings.endGroup();
}

Expand Down Expand Up @@ -1218,6 +1279,14 @@ void Tohkbd::setSettingInt(const QString &key, const int &value)
turnDisplayOffWhenRemoved = (value == 1);
settings.endGroup();
}
else if (key == "keepDisplayOnWhenConnected" && (value == 0 || value == 1))
{
settings.beginGroup("generalsettings");
settings.setValue("keepDisplayOnWhenConnected", (value == 1));
keepDisplayOnWhenConnected = (value == 1);
displayBlankPreventTimerTimeout();
settings.endGroup();
}
else if (key == "verboseMode" && (value == 0 || value == 1))
{
settings.beginGroup("debug");
Expand Down
4 changes: 4 additions & 0 deletions daemon/src/tohkeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public slots:
void backlightTimerTimeout();
void presenceTimerTimeout();
void repeatTimerTimeout();
void displayBlankPreventTimerTimeout(bool forceCancel = false);

/* Interrupt */
void handleGpioInterrupt();
Expand Down Expand Up @@ -122,6 +123,7 @@ public slots:
QTimer *backlightTimer;
QTimer *presenceTimer;
QTimer *repeatTimer;
QTimer *displayBlankPreventTimer;

QString currentActiveLayout;
QString currentOrientationLock;
Expand All @@ -146,6 +148,8 @@ public slots:
bool capsLock;
bool verboseMode;
bool turnDisplayOffWhenRemoved;
bool keepDisplayOnWhenConnected;
bool displayBlankPreventRequested;

ComKimmoliTohkbd2userInterface *tohkbd2user;
ComKimmoliTohkbd2settingsuiInterface *tohkbd2settingsui;
Expand Down
20 changes: 16 additions & 4 deletions settings-ui/i18n/engineering_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,25 @@
<translation type="unfinished"></translation>
</message>
<message id="turn-display-off-when-removed-sw">
<source>Display Off when removed</source>
<extracomment>Display Off when removed switch text</extracomment>
<source>Display off when removed</source>
<oldsource>Display Off when removed</oldsource>
<extracomment>Display off when removed switch text</extracomment>
<translation type="unfinished"></translation>
</message>
<message id="turn-display-off-when-removed-desc">
<source>Turn display off when keyboard removed</source>
<extracomment>Display Off when removed switch description</extracomment>
<source>Turn display off when keyboard is removed</source>
<oldsource>Turn display off when keyboard removed</oldsource>
<extracomment>Display off when removed switch description</extracomment>
<translation type="unfinished"></translation>
</message>
<message id="keep-display-on-when-connected-sw">
<source>Display on when connected</source>
<extracomment>Keep display on when connected switch text</extracomment>
<translation type="unfinished"></translation>
</message>
<message id="keep-display-on-when-connected-desc">
<source>Keep display on when keyboard is connected</source>
<extracomment>Keep display on when connected switch description</extracomment>
<translation type="unfinished"></translation>
</message>
</context>
Expand Down
20 changes: 16 additions & 4 deletions settings-ui/qml/pages/GeneralSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,23 @@ Page
}
TextSwitch
{
//: Display Off when removed switch text
//% "Display Off when removed"
//: Keep display on when connected switch text
//% "Display on when connected"
text: qsTrId("keep-display-on-when-connected-sw")
//: Keep display on when connected switch description
//% "Keep display on when keyboard is connected"
description: qsTrId("keep-display-on-when-connected-desc")
onCheckedChanged: settingsui.setSettingInt("keepDisplayOnWhenConnected", checked ? 1 : 0)
width: parent.width - 2*Theme.paddingLarge
Component.onCompleted: checked = settings["keepDisplayOnWhenConnected"]
}
TextSwitch
{
//: Display off when removed switch text
//% "Display off when removed"
text: qsTrId("turn-display-off-when-removed-sw")
//: Display Off when removed switch description
//% "Turn display off when keyboard removed"
//: Display off when removed switch description
//% "Turn display off when keyboard is removed"
description: qsTrId("turn-display-off-when-removed-desc")
onCheckedChanged: settingsui.setSettingInt("turnDisplayOffWhenRemoved", checked ? 1 : 0)
width: parent.width - 2*Theme.paddingLarge
Expand Down
2 changes: 2 additions & 0 deletions settings-ui/src/settingsui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ QVariantMap SettingsUi::getCurrentSettings()
map.insert("modifierAltMode", settings.value("modifierAltMode", MODIFIER_ALT_MODE).toString());
map.insert("modifierSymMode", settings.value("modifierSymMode", MODIFIER_SYM_MODE).toString());
map.insert("turnDisplayOffWhenRemoved", settings.value("turnDisplayOffWhenRemoved", TURN_DISPLAY_OFF_WHEN_REMOVED).toBool());
map.insert("keepDisplayOnWhenConnected", settings.value("keepDisplayOnWhenConnected", KEEP_DISPLAY_ON_WHEN_CONNECTED).toBool());
settings.endGroup();

settings.beginGroup("debug");
Expand Down Expand Up @@ -283,6 +284,7 @@ void SettingsUi::setSettingsToDefault()
setSettingString("modifierSymMode", MODIFIER_SYM_MODE);
setSettingInt("verboseMode", VERBOSE_MODE_ENABLED ? 1 : 0);
setSettingInt("turnDisplayOffWhenRemoved", TURN_DISPLAY_OFF_WHEN_REMOVED ? 1 : 0);
setSettingInt("keepDisplayOnWhenConnected", KEEP_DISPLAY_ON_WHEN_CONNECTED ? 1: 0);

QThread::msleep(200);

Expand Down

0 comments on commit 7284c0d

Please sign in to comment.