Skip to content

Commit

Permalink
Port decoration to Qt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
plfiorini committed Feb 8, 2024
1 parent 8542b1f commit 8c99ab3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ include(KDEInstallDirs)
set(KDE_SKIP_NULLPTR_WARNINGS_SETTINGS TRUE)
include(KDECompilerSettings NO_POLICY_SCOPE)

## Enable keywords such as emit:
# TODO: Replace keywords such as emit with Q_EMIT
remove_definitions(-DQT_NO_KEYWORDS)

## CMake settings:
include(KDECMakeSettings)

Expand All @@ -40,7 +44,7 @@ include(features.cmake)

## Add subdirectories:
if(FEATURE_qtintegration_material_decoration)
# add_subdirectory(src/plugins/decorations/material)
add_subdirectory(src/plugins/decorations/material)
endif()
if(FEATURE_qtintegration_platformtheme)
add_subdirectory(src/plugins/platformtheme)
Expand Down
1 change: 1 addition & 0 deletions features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ find_package(Qt6 "6.6.0"
Gui
Widgets
QuickControls2
WaylandClient
)

#### Features
Expand Down
42 changes: 28 additions & 14 deletions src/plugins/decorations/material/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
find_package(Wayland REQUIRED)
find_package(XkbCommon REQUIRED)
find_package(Qt5XkbCommonSupport REQUIRED PRIVATE)
#find_package(Qt6XkbCommonSupport REQUIRED PRIVATE)

liri_add_plugin(materialdecoration
TYPE
wayland-decoration-client
SOURCES
materialdecoration.cpp
materialdecoration.h
plugin.cpp
LIBRARIES
Qt5::XkbCommonSupport
Qt5::XkbCommonSupportPrivate
Qt5::WaylandClient
Qt5::WaylandClientPrivate
qt6_add_plugin(MaterialQtWaylandDecoration
SHARED
CLASS_NAME QWaylandMaterialDecorationPlugin
MANUAL_FINALIZATION
materialdecoration.cpp materialdecoration.h
plugin.cpp
)

set_target_properties(MaterialQtWaylandDecoration
PROPERTIES OUTPUT_NAME liri-material
)

target_link_libraries(MaterialQtWaylandDecoration
PUBLIC
Qt6::Core
Qt6::Gui
Qt6::WaylandClient
PRIVATE
Wayland::Client
XkbCommon::XkbCommon
#Qt6::XkbCommonSupport
#Qt6::XkbCommonSupportPrivate
Qt6::WaylandClientPrivate
)

liri_finalize_plugin(materialdecoration)
qt6_finalize_target(MaterialQtWaylandDecoration)

install(
TARGETS MaterialQtWaylandDecoration
DESTINATION ${KDE_INSTALL_PLUGINDIR}/wayland-decoration-client
)
15 changes: 9 additions & 6 deletions src/plugins/decorations/material/materialdecoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "materialdecoration.h"

using namespace Qt::StringLiterals;

QT_BEGIN_NAMESPACE

namespace QtWaylandClient {
Expand Down Expand Up @@ -95,8 +97,11 @@ QRectF QWaylandMaterialDecoration::minimizeButtonRect() const
(margins().top() - BUTTON_WIDTH) / 2, BUTTON_WIDTH, BUTTON_WIDTH);
}

QMargins QWaylandMaterialDecoration::margins() const
QMargins QWaylandMaterialDecoration::margins(MarginsType marginsType) const
{
if (marginsType == ShadowsOnly)
return QMargins();

// Title bar is 32dp plus borders
if (window() && window()->type() == Qt::Popup)
return QMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -171,7 +176,7 @@ void QWaylandMaterialDecoration::paint(QPaintDevice *device)
int dy = qFloor((top.height() - TITLE_FONT_SIZE) / 2);
QFont font = p.font();
font.setBold(true);
font.setFamily("Roboto");
font.setFamily("Roboto"_L1);
font.setPixelSize(TITLE_FONT_SIZE);
p.setFont(font);
QPoint windowTitlePoint(dx, dy - WINDOW_BORDER / 2);
Expand Down Expand Up @@ -295,15 +300,13 @@ bool QWaylandMaterialDecoration::handleMouse(QWaylandInputDevice *inputDevice, c
return true;
}

bool QWaylandMaterialDecoration::handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local,
const QPointF &global, Qt::TouchPointState state,
Qt::KeyboardModifiers mods)
bool QWaylandMaterialDecoration::handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global, QEventPoint::State state, Qt::KeyboardModifiers mods)
{
Q_UNUSED(inputDevice);
Q_UNUSED(global);
Q_UNUSED(mods);

bool handled = state == Qt::TouchPointPressed;
bool handled = state == QEventPoint::Pressed;
if (handled) {
if (closeButtonRect().contains(local))
QWindowSystemInterface::handleCloseEvent(window());
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/decorations/material/materialdecoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum Button
Minimize
};

class Q_WAYLAND_CLIENT_EXPORT QWaylandMaterialDecoration : public QWaylandAbstractDecoration
class Q_WAYLANDCLIENT_EXPORT QWaylandMaterialDecoration : public QWaylandAbstractDecoration
{
Q_OBJECT
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Expand All @@ -55,12 +55,14 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandMaterialDecoration : public QWaylandAbstra
void iconColorChanged();

protected:
QMargins margins() const override;
QMargins margins(MarginsType marginsType = Full) const override;

void paint(QPaintDevice *device) override;

bool handleMouse(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,
Qt::MouseButtons b, Qt::KeyboardModifiers mods) override;
bool handleTouch(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,
Qt::TouchPointState state, Qt::KeyboardModifiers mods) override;
QEventPoint::State state, Qt::KeyboardModifiers mods) override;

private:
void processMouseTop(QWaylandInputDevice *inputDevice, const QPointF &local, Qt::MouseButtons b,
Expand Down

0 comments on commit 8c99ab3

Please sign in to comment.