diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,8 +75,6 @@ add_subdirectory(daemon) add_subdirectory(kcmodule) add_subdirectory(doc) -add_subdirectory(kconf_update) - install( FILES powerdevil.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR} ) diff --git a/daemon/powerdevilapp.h b/daemon/powerdevilapp.h --- a/daemon/powerdevilapp.h +++ b/daemon/powerdevilapp.h @@ -46,6 +46,7 @@ private: PowerDevil::Core *m_core; + void migratePre512KeyboardShortcuts(); }; #endif // POWERDEVILAPP_H diff --git a/daemon/powerdevilapp.cpp b/daemon/powerdevilapp.cpp --- a/daemon/powerdevilapp.cpp +++ b/daemon/powerdevilapp.cpp @@ -31,17 +31,22 @@ #include #include #include +#include +#include #include #include #include #include #include +#include +#include PowerDevilApp::PowerDevilApp(int &argc, char **argv) : QGuiApplication(argc, argv) , m_core(Q_NULLPTR) { + migratePre512KeyboardShortcuts(); } PowerDevilApp::~PowerDevilApp() @@ -137,6 +142,56 @@ QDBusConnection::sessionBus().registerObject(QLatin1String("/org/kde/Solid/PowerManagement/PolicyAgent"), PowerDevil::PolicyAgent::instance()); } + +/* + * 5.11 -> 5.12 migrated shortcuts from kded5 to the correct component name org_kde_powerdevil for good reasons +however despite a kconfupdate script working correctly and moving the old keys, +because kglobalaccel is running whilst we update it synced the old values, and then ignores the powerdevil copy +on future loads + +this removes the old powermanagent entries in the kded5 component at powerdevil startup +//which is at runtime where we can talk to kglobalaccel and then re-register ours + +this method can probably be deleted at some point in the future +*/ +void PowerDevilApp::migratePre512KeyboardShortcuts() +{ + auto configGroup = KSharedConfig::openConfig("powermanagementprofilesrc")->group("migration"); + if (!configGroup.hasKey("kdedShortcutMigration")) { + const QStringList actionIds({ + "Decrease Keyboard Brightness", + "Decrease Screen Brightness", + "Hibernate", + "Increase Keyboard Brightness", + "Increase Screen Brightness", + "PowerOff", + "Sleep", + "Toggle Keyboard Backlight" + }); + for (const QString &actionId: actionIds) { + QAction oldAction; + oldAction.setObjectName(actionId); + oldAction.setProperty("componentName", "kded5"); + + //claim the old shortcut so we can remove it.. + KGlobalAccel::self()->setShortcut(&oldAction, QList(), KGlobalAccel::Autoloading); + auto shortcuts = KGlobalAccel::self()->shortcut(&oldAction); + KGlobalAccel::self()->removeAllShortcuts(&oldAction); + + QAction newAction; + newAction.setObjectName(actionId); + newAction.setProperty("componentName", "org_kde_powerdevil"); + if (!shortcuts.isEmpty()) { + //register with no autoloading to sync config, we then delete our QAction, and powerdevil will + //re-register as normal + KGlobalAccel::self()->setShortcut(&newAction, shortcuts, KGlobalAccel::NoAutoloading); + } + } + } + configGroup.writeEntry(QStringLiteral("kdedShortcutMigration"), true); + configGroup.sync(); +} + int main(int argc, char **argv) { QGuiApplication::setDesktopSettingsAware(false); diff --git a/kconf_update/CMakeLists.txt b/kconf_update/CMakeLists.txt deleted file mode 100644 --- a/kconf_update/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -install(FILES powerdevil_move_shortcuts.upd DESTINATION ${KCONF_UPDATE_INSTALL_DIR}) diff --git a/kconf_update/powerdevil_move_shortcuts.upd b/kconf_update/powerdevil_move_shortcuts.upd deleted file mode 100644 --- a/kconf_update/powerdevil_move_shortcuts.upd +++ /dev/null @@ -1,12 +0,0 @@ -Version=5 -Id=powerdevil_move_shortcuts -File=kglobalshortcutsrc -Group=kded5, org_kde_powerdevil -Key=Hibernate -Key=PowerOff -Key=Sleep -Key=Decrease Keyboard Brightness -Key=Decrease Screen Brightness -Key=Increase Keyboard Brightness -Key=Increase Screen Brightness -Key=Toggle Keyboard Backlight