Add cpufreq tool

pull/9/head
reionwong 4 years ago
parent 6fee4db476
commit 5584fb1a7b

@ -25,3 +25,4 @@ add_subdirectory(settings-daemon)
add_subdirectory(shutdown-ui)
add_subdirectory(xembed-sni-proxy)
add_subdirectory(powerman)
add_subdirectory(cpufreq)

@ -0,0 +1,17 @@
project(cutefish-cpufreq)
set(TARGET cutefish-cpufreq)
set(SOURCES
main.cpp
)
add_executable(${TARGET} ${SOURCES} ${DBUS_SOURCES})
target_link_libraries(${TARGET}
Qt5::Core
Qt5::Quick
Qt5::DBus
Qt5::X11Extras
)
install(TARGETS ${TARGET} DESTINATION /usr/bin)
install(FILES org.cutefish.cpufreq.pkexec.policy DESTINATION /usr/share/polkit-1/actions/)

@ -0,0 +1,63 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Reion Wong <reionwong@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QFile>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCommandLineParser parser;
parser.setApplicationDescription(QStringLiteral("Cutefish CPU frequency tool"));
parser.addHelpOption();
QCommandLineOption setOption(QStringList() << "s" << "set" << "Setting");
parser.addOption(setOption);
QCommandLineOption numberOption(QStringList() << "c" << "number" << "Number");
parser.addOption(numberOption);
QCommandLineOption modeOption(QStringList() << "m" << "mode" << "Mode");
parser.addOption(modeOption);
parser.process(a);
// cutefish-cpufreq --set -n 0 -m performance
if (parser.isSet(setOption) && parser.isSet(numberOption) && parser.isSet(modeOption)) {
QString modeStr = parser.positionalArguments().last();
if (modeStr != "powersave" && modeStr != "performance") {
return -1;
}
QFile file(QString("/sys/devices/system/cpu/cpu%1/cpufreq/scaling_governor").arg(parser.positionalArguments().first()));
if (!file.open(QIODevice::WriteOnly)) {
return -1;
}
file.write(modeStr.toUtf8());
file.close();
}
return 0;
}

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<action id="org.cutefish.cpufreq.pkexec">
<message>Authentication is required to Change CPU configuration</message>
<icon_name>battery</icon_name>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/cutefish-cpufreq</annotate>
</action>
</policyconfig>

@ -20,6 +20,7 @@
#include "cpumanagement.h"
#include "cpumanagementadaptor.h"
#include <QProcess>
#include <QDebug>
#include <QDir>
#include <QFile>
@ -42,15 +43,16 @@ CPUManagement::CPUManagement(QObject *parent)
}
// Init mode
bool performance = true;
bool performance = false;
for (CpuItem *item : m_items) {
if (item->policy() == "powersave")
performance = false;
qDebug() << item->policy();
if (item->policy() == "performance") {
performance = true;
break;
}
}
if (performance)
m_currentMode = CPUManagement::Performance;
setMode(PowerSave);
}
void CPUManagement::setMode(int value)
@ -61,8 +63,12 @@ void CPUManagement::setMode(int value)
if (modeString.isEmpty() || mode == m_currentMode)
return;
for (CpuItem *item : m_items) {
item->setPolicy(modeString);
QProcess process;
for (int i = 0; i <= m_items.count(); ++i) {
process.start("pkexec", QStringList() << "cutefish-cpufreq"
<< "-s" << "-c" << QString::number(i)
<< "-m" << modeString);
process.waitForFinished(-1);
}
m_currentMode = mode;

Loading…
Cancel
Save