diff --git a/daemon/backends/CMakeLists.txt b/daemon/backends/CMakeLists.txt --- a/daemon/backends/CMakeLists.txt +++ b/daemon/backends/CMakeLists.txt @@ -38,6 +38,13 @@ kauth_install_helper_files(backlighthelper org.kde.powerdevil.backlighthelper root) kauth_install_actions(org.kde.powerdevil.backlighthelper ${CMAKE_CURRENT_SOURCE_DIR}/upower/backlight_helper_actions.actions) +## discrete gpu helper executable +add_executable(discretegpuhelper upower/discretegpuhelper.cpp ${PowerDevil_SOURCE_DIR}/daemon/powerdevil_debug.cpp ${discretegpuhelper_mocs}) +target_link_libraries(discretegpuhelper Qt5::Core KF5::Auth) +install(TARGETS discretegpuhelper DESTINATION ${KAUTH_HELPER_INSTALL_DIR}) +kauth_install_helper_files(discretegpuhelper org.kde.powerdevil.discretegpuhelper root) +kauth_install_actions(org.kde.powerdevil.discretegpuhelper ${CMAKE_CURRENT_SOURCE_DIR}/upower/discretegpu_helper_actions.actions) + add_library(powerdevilupowerbackend ${powerdevilupowerbackend_SRCS}) set_target_properties(powerdevilupowerbackend PROPERTIES PREFIX "") target_link_libraries(powerdevilupowerbackend diff --git a/daemon/backends/upower/discretegpu_helper_actions.actions b/daemon/backends/upower/discretegpu_helper_actions.actions new file mode 100644 --- /dev/null +++ b/daemon/backends/upower/discretegpu_helper_actions.actions @@ -0,0 +1,54 @@ +[Domain] +Name=KDE +Name[ar]=كدي +Name[ast]=KDE +Name[bs]=KDE +Name[ca]=KDE +Name[ca@valencia]=KDE +Name[cs]=KDE +Name[da]=KDE +Name[de]=KDE +Name[el]=KDE +Name[en_GB]=KDE +Name[es]=KDE +Name[et]=KDE +Name[fi]=KDE +Name[fr]=KDE +Name[gl]=KDE +Name[he]=KDE +Name[hu]=KDE +Name[ia]=KDE +Name[id]=KDE +Name[it]=KDE +Name[ja]=KDE +Name[ko]=KDE +Name[lt]=KDE +Name[nb]=KDE +Name[nds]=KDE +Name[nl]=KDE +Name[nn]=KDE +Name[pa]=KDE +Name[pl]=KDE +Name[pt]=KDE +Name[pt_BR]=KDE +Name[ro]=KDE +Name[ru]=KDE +Name[sk]=KDE +Name[sl]=KDE +Name[sr]=КДЕ +Name[sr@ijekavian]=КДЕ +Name[sr@ijekavianlatin]=KDE +Name[sr@latin]=KDE +Name[sv]=KDE +Name[tr]=KDE +Name[uk]=KDE +Name[x-test]=xxKDExx +Name[zh_CN]=KDE +Name[zh_TW]=KDE +Icon=kde + +[org.kde.powerdevil.discretegpuhelper.hasdualgpu] +Name=Check existence of discrete gpu +Description=System policies prevent you from checking the existence of discrete gpu. +Policy=yes +PolicyInactive=no diff --git a/daemon/backends/upower/discretegpuhelper.h b/daemon/backends/upower/discretegpuhelper.h new file mode 100644 --- /dev/null +++ b/daemon/backends/upower/discretegpuhelper.h @@ -0,0 +1,40 @@ +/* This file is part of the KDE project + * Copyright (C) 2016 Jan Grulich + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef DISCRETEGPUHELPER_H +#define DISCRETEGPUHELPER_H + +#include +#include + +using namespace KAuth; + +class DiscreteGpuHelper : public QObject +{ + Q_OBJECT +public: + DiscreteGpuHelper(QObject *parent = nullptr); + +public Q_SLOTS: + ActionReply hasdualgpu(const QVariantMap &args); + +}; + +#endif // DISCRETEGPUHELPER_H + diff --git a/daemon/backends/upower/discretegpuhelper.cpp b/daemon/backends/upower/discretegpuhelper.cpp new file mode 100644 --- /dev/null +++ b/daemon/backends/upower/discretegpuhelper.cpp @@ -0,0 +1,45 @@ +/* This file is part of the KDE project + * Copyright (C) 2016 Jan Grulich + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "discretegpuhelper.h" + +#include + +#include + +#define SWITCHEROO_SYSFS_PATH "/sys/kernel/debug/vgaswitcheroo/switch" + +DiscreteGpuHelper::DiscreteGpuHelper(QObject *parent) + : QObject(parent) +{ +} + +ActionReply DiscreteGpuHelper::hasdualgpu(const QVariantMap &args) +{ + Q_UNUSED(args); + + ActionReply reply; + reply.addData("hasdualgpu", QFile::exists(SWITCHEROO_SYSFS_PATH)); + // qCDebug(POWERDEVIL) << "data contains:" << reply.data()["hasdualgpu"]; + + return reply; +} + +KAUTH_HELPER_MAIN("org.kde.powerdevil.discretegpuhelper", DiscreteGpuHelper) + diff --git a/daemon/org.kde.Solid.PowerManagement.xml b/daemon/org.kde.Solid.PowerManagement.xml --- a/daemon/org.kde.Solid.PowerManagement.xml +++ b/daemon/org.kde.Solid.PowerManagement.xml @@ -25,6 +25,9 @@ + + +