mirror of https://github.com/cutefishos/core
Add cpufreq tool
parent
6fee4db476
commit
5584fb1a7b
@ -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>
|
||||
Loading…
Reference in New Issue