Skip to content

Commit

Permalink
chore: add some interfaces about personalization
Browse files Browse the repository at this point in the history
add some interfaces about personalization

Log:
  • Loading branch information
wangfei committed Oct 15, 2024
1 parent 8cf037d commit e781599
Show file tree
Hide file tree
Showing 28 changed files with 1,051 additions and 598 deletions.
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Build-Depends: debhelper-compat (= 12), pkg-config,
qtbase5-private-dev, qtbase5-dev-tools, doxygen, graphviz, qttools5-dev,
libdtkcore-dev, librsvg2-dev, libfreeimage-dev, libraw-dev, libgtest-dev, libgmock-dev,
libqt5xdg-dev, libqt5xdgiconloader-dev, cmake, qt5-image-formats-plugins, libqt5waylandclient5-dev,
extra-cmake-modules, qtwayland5-dev-tools, qtwayland5-private-dev, libkf5wayland-dev
extra-cmake-modules, qtwayland5-dev-tools, qtwayland5-private-dev, libkf5wayland-dev, treeland-protocols
Standards-Version: 3.9.8

Package: libdtkgui5
Expand Down
3 changes: 2 additions & 1 deletion include/kernel/dguiapplicationhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class DGuiApplicationHelper : public QObject, public DCORE_NAMESPACE::DObject
IsXWindowPlatform = ReadOnlyLimit << 2,
IsTableEnvironment = ReadOnlyLimit << 3,
IsDeepinEnvironment = ReadOnlyLimit << 4,
IsSpecialEffectsEnvironment = ReadOnlyLimit << 5
IsSpecialEffectsEnvironment = ReadOnlyLimit << 5,
IsTreelandPlatform = ReadOnlyLimit << 6
};
Q_ENUM(Attribute)
Q_DECLARE_FLAGS(Attributes, Attribute)
Expand Down
37 changes: 37 additions & 0 deletions include/kernel/dplatforminterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef DPLATFORMINTERFACE_H
#define DPLATFORMINTERFACE_H

#include <QObject>
#include <QVariant>

#include "dtkgui_global.h"
#include <dobject.h>

DGUI_BEGIN_NAMESPACE

class DPlatformInterfacePrivate;
class DPlatformInterface : public QObject, public DCORE_NAMESPACE::DObject
{
Q_OBJECT
D_DECLARE_PRIVATE(DPlatformInterface)
public:
explicit DPlatformInterface(QObject *parent);

virtual int windowRadius() const;
virtual void setWindowRadius(int windowRadius);
virtual QByteArray fontName() const;
virtual void setFontName(const QByteArray &fontName);
virtual QByteArray monoFontName() const;
virtual void setMonoFontName(const QByteArray &monoFontName);
virtual QByteArray iconThemeName() const;
virtual void setIconThemeName(const QByteArray &iconThemeName);
virtual QByteArray cursorThemeName() const;
virtual void setCursorThemeName(const QByteArray &cursorThemeName);
};

DGUI_END_NAMESPACE
#endif
4 changes: 4 additions & 0 deletions include/kernel/dplatformtheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DPlatformTheme : public DNativeSettings
Q_PROPERTY(QByteArray themeName READ themeName WRITE setThemeName NOTIFY themeNameChanged)
Q_PROPERTY(QByteArray iconThemeName READ iconThemeName WRITE setIconThemeName NOTIFY iconThemeNameChanged)
Q_PROPERTY(QByteArray soundThemeName READ soundThemeName WRITE setSoundThemeName NOTIFY soundThemeNameChanged)
Q_PROPERTY(QByteArray cursorThemeName READ cursorThemeName WRITE setCursorThemeName NOTIFY cursorThemeNameChanged)
// Font
Q_PROPERTY(QByteArray fontName READ fontName WRITE setFontName NOTIFY fontNameChanged)
Q_PROPERTY(QByteArray monoFontName READ monoFontName WRITE setMonoFontName NOTIFY monoFontNameChanged)
Expand Down Expand Up @@ -94,6 +95,7 @@ class DPlatformTheme : public DNativeSettings
QByteArray themeName() const;
QByteArray iconThemeName() const;
QByteArray soundThemeName() const;
QByteArray cursorThemeName() const;

QByteArray fontName() const;
QByteArray monoFontName() const;
Expand Down Expand Up @@ -147,6 +149,7 @@ public Q_SLOTS:
void setThemeName(const QByteArray &themeName);
void setIconThemeName(const QByteArray &iconThemeName);
void setSoundThemeName(const QByteArray &soundThemeName);
void setCursorThemeName(const QByteArray &cursorThemeName);
void setFontName(const QByteArray &fontName);
void setMonoFontName(const QByteArray &monoFontName);
void setFontPointSize(qreal fontPointSize);
Expand Down Expand Up @@ -196,6 +199,7 @@ public Q_SLOTS:
void themeNameChanged(QByteArray themeName);
void iconThemeNameChanged(QByteArray iconThemeName);
void soundThemeNameChanged(QByteArray soundThemeName);
void cursorThemeNameChanged(QByteArray cursorThemeName);
void fontNameChanged(QByteArray fontName);
void monoFontNameChanged(QByteArray monoFontName);
void fontPointSizeChanged(qreal fontPointSize);
Expand Down
37 changes: 37 additions & 0 deletions include/kernel/dxcbplatforminterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef DXCBPLATFORMINTERFACE_H
#define DXCBPLATFORMINTERFACE_H

#include "dplatforminterface.h"

DGUI_BEGIN_NAMESPACE

class DXCBPlatformInterfacePrivate;
class DXCBPlatformInterface : public DPlatformInterface
{
Q_OBJECT
D_DECLARE_PRIVATE(DXCBPlatformInterface)
public:
explicit DXCBPlatformInterface(quint32 window, QObject *parent);

int windowRadius() const override;
void setWindowRadius(int windowRadius) override;

QByteArray fontName() const override;
void setFontName(const QByteArray &fontName) override;

QByteArray monoFontName() const override;
void setMonoFontName(const QByteArray &monoFontName) override;

QByteArray iconThemeName() const override;
void setIconThemeName(const QByteArray &iconThemeName) override;

QByteArray cursorThemeName() const override;
void setCursorThemeName(const QByteArray &cursorThemeName) override;
};

DGUI_END_NAMESPACE
#endif
48 changes: 28 additions & 20 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ else()
find_package(Qt5 REQUIRED COMPONENTS WaylandClient XkbCommonSupport)
endif()

option(DTK_DISABLE_TREELAND "Disable TreeLand Protocols" OFF)
find_package(TreeLandProtocols)
set(TreeLandProtocols_FOUND ${TreeLandProtocols_FOUND})

add_library(${LIB_NAME} SHARED)

include(dbus/dbus.cmake)
Expand All @@ -12,30 +16,34 @@ include(kernel/kernel.cmake)
include(private/private.cmake)
include(util/util.cmake)

if("${QT_VERSION_MAJOR}" STREQUAL "6")
qt6_generate_wayland_protocol_client_sources(${LIB_NAME} FILES
${CMAKE_CURRENT_SOURCE_DIR}/wayland/protocol/treeland-personalization-manager-v1.xml
)
else()
# ECM setup
include(FeatureSummary)
find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ECM_MODULE_PATH}")
find_package(QtWaylandScanner)
ecm_add_qtwayland_client_protocol(${LIB_NAME}
PROTOCOL ${CMAKE_CURRENT_SOURCE_DIR}/wayland/protocol/treeland-personalization-manager-v1.xml
BASENAME treeland-personalization-manager-v1
)
if(NOT DTK_DISABLE_TREELAND AND TreeLandProtocols_FOUND)
message("Support Treeland!")
if("${QT_VERSION_MAJOR}" STREQUAL "6")
qt6_generate_wayland_protocol_client_sources(${LIB_NAME} FILES
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml
)
else()
# ECM setup
include(FeatureSummary)
find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${ECM_MODULE_PATH}")
find_package(QtWaylandScanner)
ecm_add_qtwayland_client_protocol(${LIB_NAME}
PROTOCOL ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml
BASENAME treeland-personalization-manager-v1
)
target_sources(${LIB_NAME} PRIVATE
${CLIENT_LIB_SRCS}
)
endif()
include(wayland/wayland.cmake)
target_sources(${LIB_NAME} PRIVATE
${CLIENT_LIB_SRCS}
${wayland_SRC}
)
else()
target_compile_definitions(${LIB_NAME} PRIVATE DTK_DISABLE_TREELAND)
endif()

include(wayland/wayland.cmake)
target_sources(${LIB_NAME} PRIVATE
${wayland_SRC}
)

target_sources(${LIB_NAME} PRIVATE
${dbus_SRC}
${filedrag_SRC}
Expand Down
3 changes: 3 additions & 0 deletions src/kernel/dguiapplicationhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,9 @@ bool DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::Attribute attri
case IsSpecialEffectsEnvironment: {
return qgetenv("DTK_DISABLED_SPECIAL_EFFECTS").toInt() != 1;
}
case IsTreelandPlatform: {
return qgetenv("DDE_CURRENT_COMPOSITOR") == "TreeLand";
}
default:
return DGuiApplicationHelperPrivate::attributes.testFlag(attribute);
}
Expand Down
75 changes: 40 additions & 35 deletions src/kernel/dplatformhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "dplatformhandle.h"
#include "dplatformtheme.h"
#include "dwindowmanagerhelper.h"
#include "wayland/dcontextshellwindow.h"
#ifndef DTK_DISABLE_TREELAND
#include "wayland/personalizationwaylandclientextension.h"
#endif
#include <private/qwaylandwindow_p.h>

#include <QWindow>
Expand Down Expand Up @@ -97,11 +99,6 @@ static void setWindowProperty(QWindow *window, const char *name, const QVariant
reinterpret_cast<void(*)(QWindow *, const char *, const QVariant &)>(setWindowProperty)(window, name, value);
}

static bool isTreeLand()
{
return qEnvironmentVariable("DDE_CURRENT_COMPOSITOR") == "TreeLand";
};

/*!
\class Dtk::Gui::DPlatformHandle
\inmodule dtkgui
Expand Down Expand Up @@ -628,32 +625,35 @@ class Q_DECL_HIDDEN CreatorWindowEventFile : public QObject {
}
}

if (auto *w = qobject_cast<QWindow *>(watched); w && isTreeLand()) {
if(DContextShellWindow *window = DContextShellWindow::get(qobject_cast<QWindow *>(watched))) {
bool is_mouse_move = event->type() == QEvent::MouseMove && static_cast<QMouseEvent*>(event)->buttons() == Qt::LeftButton;
if (auto *w = qobject_cast<QWindow *>(watched); w && DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsTreelandPlatform)) {
bool is_mouse_move = event->type() == QEvent::MouseMove && static_cast<QMouseEvent*>(event)->buttons() == Qt::LeftButton;

if (event->type() == QEvent::MouseButtonRelease) {
m_windowMoving = false;
}
if (event->type() == QEvent::MouseButtonRelease) {
m_windowMoving = false;
}

// workaround for kwin: Qt receives no release event when kwin finishes MOVE operation,
// which makes app hang in windowMoving state. when a press happens, there's no sense of
// keeping the moving state, we can just reset ti back to normal.
if (event->type() == QEvent::MouseButtonPress) {
m_windowMoving = false;
}
// workaround for kwin: Qt receives no release event when kwin finishes MOVE operation,
// which makes app hang in windowMoving state. when a press happens, there's no sense of
// keeping the moving state, we can just reset ti back to normal.
if (event->type() == QEvent::MouseButtonPress) {
m_windowMoving = false;
}

// FIXME: We need to check whether the event is accepted.
// Only when the upper control does not accept the event,
// the window should be moved through the window.
// But every event here has been accepted. I don't know what happened.
if (is_mouse_move && w->geometry().contains(static_cast<QMouseEvent*>(event)->globalPos())) {

#ifndef DTK_DISABLE_TREELAND
if (!m_windowMoving && PersonalizationManager::instance()->noTitlebar()) {
#else
if (!m_windowMoving) {
#endif
m_windowMoving = true;

// FIXME: We need to check whether the event is accepted.
// Only when the upper control does not accept the event,
// the window should be moved through the window.
// But every event here has been accepted. I don't know what happened.
if (is_mouse_move && w->geometry().contains(static_cast<QMouseEvent*>(event)->globalPos())) {
if (!m_windowMoving && window->noTitlebar()) {
m_windowMoving = true;

event->accept();
static_cast<QtWaylandClient::QWaylandWindow *>(w->handle())->startSystemMove();
}
event->accept();
static_cast<QPlatformWindow *>(w->handle())->startSystemMove();
}
}
}
Expand All @@ -679,17 +679,16 @@ bool DPlatformHandle::setEnabledNoTitlebarForWindow(QWindow *window, bool enable
auto isDWaylandPlatform = [] {
return qApp->platformName() == "dwayland" || qApp->property("_d_isDwayland").toBool();
};
if (!(isDXcbPlatform() || isDWaylandPlatform() || isTreeLand()))
if (!(isDXcbPlatform() || isDWaylandPlatform() || DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsTreelandPlatform)))
return false;

if (window && isTreeLand()) {
DContextShellWindow *contextWindow = DContextShellWindow::get(window);
if (contextWindow->noTitlebar() == enable)
return true;
contextWindow->setNoTitlebar(enable);
#ifndef DTK_DISABLE_TREELAND
if (window && DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsTreelandPlatform)) {
PersonalizationManager::instance()->setNoTitlebar(window, enable);
window->installEventFilter(new CreatorWindowEventFile(window));
return true;
}
#endif

if (isEnabledNoTitlebar(window) == enable)
return true;
Expand Down Expand Up @@ -1209,6 +1208,12 @@ WId DPlatformHandle::windowLeader()

void DPlatformHandle::setWindowRadius(int windowRadius)
{
#ifndef DTK_DISABLE_TREELAND
if (DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsTreelandPlatform)) {
PersonalizationManager::instance()->setWindowRadius(m_window, windowRadius);
return;
}
#endif
setWindowProperty(m_window, _windowRadius, windowRadius);
resolve(m_window, PropRole::WindowRadius);
}
Expand Down
70 changes: 70 additions & 0 deletions src/kernel/dplatforminterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "dplatforminterface.h"
#include "private/dplatforminterface_p.h"

DGUI_BEGIN_NAMESPACE
DPlatformInterfacePrivate::DPlatformInterfacePrivate(DPlatformInterface *qq)
: DObjectPrivate(qq)
{
}

DPlatformInterfacePrivate::~DPlatformInterfacePrivate()
{
}

DPlatformInterface::DPlatformInterface(QObject *parent)
: QObject(parent)
{
}

int DPlatformInterface::windowRadius() const
{
return 0;
}

void DPlatformInterface::setWindowRadius(int windowRadius)
{
}

QByteArray DPlatformInterface::fontName() const
{
return "";
}

void DPlatformInterface::setFontName(const QByteArray &fontName)
{
}

QByteArray DPlatformInterface::monoFontName() const
{
return "";
}

void DPlatformInterface::setMonoFontName(const QByteArray &monoFontName)
{
}

QByteArray DPlatformInterface::iconThemeName() const
{
return "";
}

void DPlatformInterface::setIconThemeName(const QByteArray &iconThemeName)
{
}

QByteArray DPlatformInterface::cursorThemeName() const
{
return "";
}

void DPlatformInterface::setCursorThemeName(const QByteArray &cursorThemeName)
{
}

DGUI_END_NAMESPACE


Loading

0 comments on commit e781599

Please sign in to comment.