Compare commits

...

3 commits

11 changed files with 120 additions and 13 deletions

View file

@ -31,5 +31,5 @@ find_package(Qt6 REQUIRED COMPONENTS ${QT_FPDEPS})
qt_standard_project_setup(REQUIRES 6.6)
add_subdirectory(src/wayland)
add_subdirectory(src/core)
add_subdirectory(src/wayland)

2
docs

@ -1 +1 @@
Subproject commit d603e3de533c74248621943bc85034620f4ef8c7
Subproject commit cc201afd3a352a28f5daddbe00d7aed974d52d30

View file

@ -1,5 +1,6 @@
qt_add_executable(quickshell
main.cpp
plugin.cpp
shell.cpp
variants.cpp
rootwrapper.cpp
@ -17,5 +18,3 @@ qt_add_executable(quickshell
)
qt_add_qml_module(quickshell URI QuickShell)
target_link_libraries(quickshell PRIVATE ${QT_DEPS} quickshell-waylandplugin)

11
src/core/doc.hpp Normal file
View file

@ -0,0 +1,11 @@
#pragma once
// hide a property, function, or signal from typegen
#define QSDOC_HIDE
// override the base class as seen by typegen
#define QSDOC_BASECLASS(baseclass)
// make the type visible in the docs even if not a QML_ELEMENT
#define QSDOC_ELEMENT
#define QSDOC_NAMED_ELEMENT(name)

View file

@ -8,6 +8,7 @@
#include <qstandardpaths.h>
#include <qstring.h>
#include "plugin.hpp"
#include "rootwrapper.hpp"
int main(int argc, char** argv) {
@ -38,6 +39,8 @@ int main(int argc, char** argv) {
return -1;
}
QuickshellPlugin::initPlugins();
// Base window transparency appears to be additive.
// Use a fully transparent window with a colored rect.
QQuickWindow::setDefaultAlphaBuffer(true);

View file

@ -2,6 +2,7 @@
#include <qtmetamacros.h>
#include "doc.hpp"
#include "windowinterface.hpp"
class Anchors {
@ -94,6 +95,7 @@ Q_ENUM_NS(Enum);
/// }
/// ```
class PanelWindowInterface: public WindowInterface {
QSDOC_NAMED_ELEMENT(PanelWindow);
// clang-format off
Q_OBJECT;
/// Anchors attach a shell window to the sides of the screen.

27
src/core/plugin.cpp Normal file
View file

@ -0,0 +1,27 @@
#include "plugin.hpp"
#include <algorithm>
#include <qvector.h> // NOLINT (what??)
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();
}
for (QuickshellPlugin* plugin: plugins) {
plugin->registerTypes();
}
}

29
src/core/plugin.hpp Normal file
View file

@ -0,0 +1,29 @@
#pragma once
#include <qcontainerfwd.h>
#include <qfunctionpointer.h>
class QuickshellPlugin {
public:
QuickshellPlugin() = default;
virtual ~QuickshellPlugin() = default;
QuickshellPlugin(QuickshellPlugin&&) = delete;
QuickshellPlugin(const QuickshellPlugin&) = delete;
void operator=(QuickshellPlugin&&) = delete;
void operator=(const QuickshellPlugin&) = delete;
virtual bool applies() { return true; }
virtual void init() {}
virtual void registerTypes() {}
static void registerPlugin(QuickshellPlugin& plugin);
static void initPlugins();
};
// NOLINTBEGIN
#define QS_REGISTER_PLUGIN(clazz) \
[[gnu::constructor]] void qsInitPlugin() { \
static clazz plugin; \
QuickshellPlugin::registerPlugin(plugin); \
}
// NOLINTEND

View file

@ -5,6 +5,11 @@ qt_add_library(quickshell-wayland STATIC
waylandlayershell.cpp
)
# required to make sure the constructor is linked
add_library(quickshell-wayland-init OBJECT init.cpp)
target_link_libraries(quickshell PRIVATE ${QT_DEPS} quickshell-waylandplugin quickshell-wayland-init)
qt_add_qml_module(quickshell-wayland URI QuickShell.Wayland)
find_package(PkgConfig REQUIRED)
@ -13,6 +18,7 @@ pkg_check_modules(wayland REQUIRED IMPORTED_TARGET wayland-client wayland-protoc
find_package(Qt6 REQUIRED COMPONENTS WaylandClient)
target_link_libraries(quickshell-wayland PRIVATE ${QT_DEPS} wayland-client)
target_link_libraries(quickshell-wayland-init PRIVATE ${QT_DEPS} wayland-client)
# wayland protocols

29
src/wayland/init.cpp Normal file
View file

@ -0,0 +1,29 @@
#include <qguiapplication.h>
#include <qqml.h>
#include "../core/plugin.hpp"
#include "waylandlayershell.hpp"
namespace {
class WaylandPlugin: public QuickshellPlugin {
bool applies() override { return QGuiApplication::platformName() == "wayland"; }
void registerTypes() override {
qmlRegisterType<WaylandPanelInterface>("QuickShell._WaylandOverlay", 1, 0, "PanelWindow");
// If any types are defined inside a module using QML_ELEMENT then all QML_ELEMENT types
// will not be registered. This can be worked around with a module import which makes
// the QML_ELMENT module import the old register-type style module.
qmlRegisterModuleImport(
"QuickShell",
QQmlModuleImportModuleAny,
"QuickShell._WaylandOverlay",
QQmlModuleImportLatest
);
}
};
QS_REGISTER_PLUGIN(WaylandPlugin);
} // namespace

View file

@ -7,10 +7,12 @@
#include <qtmetamacros.h>
#include <qtypes.h>
#include "../core/doc.hpp"
#include "../core/proxywindow.hpp"
#include "layershell.hpp"
class WaylandLayershell: public ProxyWindowBase {
QSDOC_BASECLASS(PanelWindowInterface);
// clang-format off
Q_OBJECT;
/// The shell layer the window sits in. Defaults to `Layer.Top`.
@ -22,10 +24,10 @@ class WaylandLayershell: public ProxyWindowBase {
/// The degree of keyboard focus taken. Defaults to `KeyboardFocus.None`.
Q_PROPERTY(KeyboardFocus::Enum keyboardFocus READ keyboardFocus WRITE setKeyboardFocus NOTIFY keyboardFocusChanged);
Q_PROPERTY(Anchors anchors READ anchors WRITE setAnchors NOTIFY anchorsChanged);
Q_PROPERTY(qint32 exclusiveZone READ exclusiveZone WRITE setExclusiveZone NOTIFY exclusiveZoneChanged);
Q_PROPERTY(ExclusionMode::Enum exclusionMode READ exclusionMode WRITE setExclusionMode NOTIFY exclusionModeChanged);
Q_PROPERTY(Margins margins READ margins WRITE setMargins NOTIFY marginsChanged);
QSDOC_HIDE Q_PROPERTY(Anchors anchors READ anchors WRITE setAnchors NOTIFY anchorsChanged);
QSDOC_HIDE Q_PROPERTY(qint32 exclusiveZone READ exclusiveZone WRITE setExclusiveZone NOTIFY exclusiveZoneChanged);
QSDOC_HIDE Q_PROPERTY(ExclusionMode::Enum exclusionMode READ exclusionMode WRITE setExclusionMode NOTIFY exclusionModeChanged);
QSDOC_HIDE Q_PROPERTY(Margins margins READ margins WRITE setMargins NOTIFY marginsChanged);
QML_ATTACHED(WaylandLayershell);
QML_ELEMENT;
// clang-format on
@ -68,10 +70,10 @@ signals:
void layerChanged();
void namespaceChanged();
void keyboardFocusChanged();
void anchorsChanged();
void exclusiveZoneChanged();
void exclusionModeChanged();
void marginsChanged();
QSDOC_HIDE void anchorsChanged();
QSDOC_HIDE void exclusiveZoneChanged();
QSDOC_HIDE void exclusionModeChanged();
QSDOC_HIDE void marginsChanged();
private slots:
void updateAutoExclusion();
@ -87,7 +89,6 @@ private:
class WaylandPanelInterface: public PanelWindowInterface {
Q_OBJECT;
QML_NAMED_ELEMENT(PanelWindow); // temp
public:
explicit WaylandPanelInterface(QObject* parent = nullptr);