forked from quickshell/quickshell
feat: basic plugin system
The wayland plugin now uses it.
This commit is contained in:
parent
6c6272e523
commit
3bd587cfcc
8 changed files with 94 additions and 4 deletions
35
src/core/plugin.cpp
Normal file
35
src/core/plugin.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "plugin.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
#include <qvector.h> // NOLINT (what??)
|
||||
|
||||
// defined by moc. see below comment.
|
||||
void qml_register_types_QuickShell(); // NOLINT
|
||||
|
||||
static QVector<QuickshellPlugin*> plugins; // NOLINT
|
||||
|
||||
void QuickshellPlugin::registerPlugin(QuickshellPlugin& plugin) { plugins.push_back(&plugin); }
|
||||
|
||||
void QuickshellPlugin::initPlugins() {
|
||||
plugins.erase(
|
||||
std::remove_if(
|
||||
plugins.begin(),
|
||||
plugins.end(),
|
||||
[](QuickshellPlugin* plugin) { return !plugin->applies(); }
|
||||
),
|
||||
plugins.end()
|
||||
);
|
||||
|
||||
for (QuickshellPlugin* plugin: plugins) {
|
||||
plugin->init();
|
||||
}
|
||||
|
||||
// This seems incredibly stupid but it appears qt will not register the module types
|
||||
// if types are already defined for the module, meaning qmlRegisterType does not work
|
||||
// unless the module types are already registered.
|
||||
qml_register_types_QuickShell();
|
||||
|
||||
for (QuickshellPlugin* plugin: plugins) {
|
||||
plugin->registerTypes();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue