Commit 57ba878c authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Improve the behaviour of the power button on mobile

Summary:
On Mobile, if the power button is pressed for short time, suspend to Ram as
requested by Bhushan. If the power button is pressed for over a second show a
menu asking whether to reboot, shut down and others like we show on the
desktop.

Albeit pretty cool and useful, this can't be translated into the desktop
because there press time is always 0ms for some reason.

See https://phabricator.kde.org/D26899

Reviewers: #plasma, bshah, broulik

Reviewed By: #plasma, broulik

Subscribers: z3ntu, broulik, PureTryOut, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27193
parent 24e2b609
......@@ -73,6 +73,11 @@ HandleButtonEvents::HandleButtonEvents(QObject *parent)
accel->setGlobalShortcut(globalAction, Qt::Key_PowerOff);
connect(globalAction, SIGNAL(triggered(bool)), SLOT(powerOffButtonTriggered()));
globalAction = actionCollection->addAction("PowerDown");
globalAction->setText(i18nc("@action:inmenu Global shortcut", "Power Down"));
accel->setGlobalShortcut(globalAction, Qt::Key_PowerDown);
connect(globalAction, &QAction::triggered, this, &HandleButtonEvents::powerDownButtonTriggered);
connect(new KScreen::GetConfigOperation(KScreen::GetConfigOperation::NoEDID), &KScreen::ConfigOperation::finished,
this, [this](KScreen::ConfigOperation *op) {
m_screenConfiguration = qobject_cast<KScreen::GetConfigOperation *>(op)->config();
......@@ -210,6 +215,11 @@ void HandleButtonEvents::powerOffButtonTriggered()
onButtonPressed(BackendInterface::PowerButton);
}
void HandleButtonEvents::powerDownButtonTriggered()
{
onButtonPressed(BackendInterface::PowerDownButton);
}
void HandleButtonEvents::suspendToDisk()
{
onButtonPressed(BackendInterface::HibernateButton);
......
......@@ -60,6 +60,7 @@ public Q_SLOTS:
private Q_SLOTS:
void onButtonPressed(PowerDevil::BackendInterface::ButtonType type);
void powerOffButtonTriggered();
void powerDownButtonTriggered();
void suspendToRam();
void suspendToDisk();
......
......@@ -65,12 +65,13 @@ public:
* This enum type defines the types of system button events.
*
* - UnknownButtonType: An unknown button
* - PowerDown: A power down pressed event, generally used to turn on or off the system. KWin emits on long power button presses.
* - PowerButton: A power button pressed event, generally used to turn on or off the system
* - SleepButton: A sleep button pressed event, generally used to make the system asleep
* - LidOpen: A laptop lid open event
* - LidClose: A laptop lid close event
*/
enum ButtonType{ UnknownButtonType, PowerButton, SleepButton, LidOpen, LidClose, HibernateButton };
enum ButtonType{ UnknownButtonType, PowerButton, PowerDownButton, SleepButton, LidOpen, LidClose, HibernateButton };
Q_ENUM(ButtonType)
/**
......
......@@ -58,26 +58,29 @@ void ProfileGenerator::generateProfiles(bool toRam, bool toDisk)
KConfigGroup acProfile(profilesConfig, "AC");
acProfile.writeEntry("icon", "battery-charging");
const bool mobile = !qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_MOBILE");
const Modes defaultPowerButtonAction = mobile ? LockScreenMode : LogoutDialogMode;
// We want to dim the screen after a while, definitely
{
KConfigGroup dimDisplay(&acProfile, "DimDisplay");
dimDisplay.writeEntry< int >("idleTime", 300000);
}
// Show the dialog when power button is pressed and suspend on suspend button pressed and lid closed (if supported)
auto initLid = [toRam](KConfigGroup &profile)
{
KConfigGroup handleButtonEvents(&acProfile, "HandleButtonEvents");
const bool mobile = !qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_MOBILE");
const Modes defaultPowerButtonAction = mobile ? ToRamMode : LogoutDialogMode;
KConfigGroup handleButtonEvents(&profile, "HandleButtonEvents");
handleButtonEvents.writeEntry< uint >("powerButtonAction", defaultPowerButtonAction);
handleButtonEvents.writeEntry< uint >("powerDownAction", LogoutDialogMode);
if (toRam) {
handleButtonEvents.writeEntry< uint >("lidAction", ToRamMode);
} else {
handleButtonEvents.writeEntry< uint >("lidAction", TurnOffScreenMode);
}
}
};
// Show the dialog when power button is pressed and suspend on suspend button pressed and lid closed (if supported)
initLid(acProfile);
// And we also want to turn off the screen after another while
{
......@@ -94,15 +97,8 @@ void ProfileGenerator::generateProfiles(bool toRam, bool toDisk)
dimDisplay.writeEntry< int >("idleTime", 120000);
}
// Show the dialog when power button is pressed and suspend on suspend button pressed and lid closed (if supported)
{
KConfigGroup handleButtonEvents(&batteryProfile, "HandleButtonEvents");
handleButtonEvents.writeEntry< uint >("powerButtonAction", defaultPowerButtonAction);
if (toRam) {
handleButtonEvents.writeEntry< uint >("lidAction", ToRamMode);
} else {
handleButtonEvents.writeEntry< uint >("lidAction", TurnOffScreenMode);
}
}
initLid(batteryProfile);
// We want to turn off the screen after another while
{
KConfigGroup dpmsControl(&batteryProfile, "DPMSControl");
......@@ -130,15 +126,8 @@ void ProfileGenerator::generateProfiles(bool toRam, bool toDisk)
dimDisplay.writeEntry< int >("idleTime", 60000);
}
// Show the dialog when power button is pressed and suspend on suspend button pressed and lid closed (if supported)
{
KConfigGroup handleButtonEvents(&lowBatteryProfile, "HandleButtonEvents");
handleButtonEvents.writeEntry< uint >("powerButtonAction", defaultPowerButtonAction);
if (toRam) {
handleButtonEvents.writeEntry< uint >("lidAction", ToRamMode);
} else {
handleButtonEvents.writeEntry< uint >("lidAction", TurnOffScreenMode);
}
}
initLid(lowBatteryProfile);
// We want to turn off the screen after another while
{
KConfigGroup dpmsControl(&lowBatteryProfile, "DPMSControl");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment