Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkgui
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkgui.

Source-pull-request: linuxdeepin/dtkgui#258
  • Loading branch information
deepin-ci-robot committed Oct 17, 2024
1 parent 098486f commit 2202279
Show file tree
Hide file tree
Showing 31 changed files with 1,325 additions and 649 deletions.
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
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
25 changes: 1 addition & 24 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,7 @@ include(filedrag/dfiledrag.cmake)
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
)
target_sources(${LIB_NAME} PRIVATE
${CLIENT_LIB_SRCS}
)
endif()

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

target_sources(${LIB_NAME} PRIVATE
${dbus_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
99 changes: 26 additions & 73 deletions src/kernel/dplatformhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "dplatformhandle.h"
#include "dplatformtheme.h"
#include "dwindowmanagerhelper.h"
#include "wayland/dcontextshellwindow.h"
#include "plugins/dplatforminterface.h"
#include <private/qwaylandwindow_p.h>

#include <QWindow>
Expand Down Expand Up @@ -97,11 +97,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 +623,30 @@ 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())) {
if (!m_windowMoving) {
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,41 +672,10 @@ 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);
window->installEventFilter(new CreatorWindowEventFile(window));
return true;
}

if (isEnabledNoTitlebar(window) == enable)
return true;

QFunctionPointer enable_no_titlear = nullptr;

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
enable_no_titlear = qApp->platformFunction(_setEnableNoTitlebar);
#endif

if (enable_no_titlear) {
bool ok = (*reinterpret_cast<bool(*)(QWindow*, bool)>(enable_no_titlear))(window, enable);
if (ok && enable) {
if (window->handle()) {
initWindowRadius(window);
} else {
window->installEventFilter(new CreatorWindowEventFile(window));
}
}

return ok;
}

return false;
return DPlatformInterface::self(window)->setEnabledNoTitlebar(window, enable);
}

/*!
Expand All @@ -724,17 +686,8 @@ bool DPlatformHandle::setEnabledNoTitlebarForWindow(QWindow *window, bool enable
*/
bool DPlatformHandle::isEnabledNoTitlebar(const QWindow *window)
{
QFunctionPointer is_enable_no_titlebar = nullptr;

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
is_enable_no_titlebar = qApp->platformFunction(_isEnableNoTitlebar);
#endif

if (is_enable_no_titlebar) {
return (*reinterpret_cast<bool(*)(const QWindow*)>(is_enable_no_titlebar))(window);
}

return false;
QWindow *w = const_cast<QWindow *>(window);
return DPlatformInterface::self(w)->isEnabledNoTitlebar(w);
}

inline DPlatformHandle::WMBlurArea operator *(const DPlatformHandle::WMBlurArea &area, qreal scale)
Expand Down
52 changes: 37 additions & 15 deletions src/kernel/dplatformtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "dplatformtheme.h"
#include "plugins/dplatforminterface.h"
#include "private/dplatformtheme_p.h"
#include "dguiapplicationhelper.h"

#ifndef DTK_DISABLE_XCB
#include "plugins/platform/xcb/dxcbplatforminterface.h"
#endif

#ifndef DTK_DISABLE_TREELAND
#include "plugins/platform/treeland/dtreelandplatforminterface.h"
#endif

#include <QVariant>
#include <QTimer>
Expand All @@ -19,7 +29,6 @@ DGUI_BEGIN_NAMESPACE
DPlatformThemePrivate::DPlatformThemePrivate(Dtk::Gui::DPlatformTheme *qq)
: DNativeSettingsPrivate(qq, QByteArrayLiteral("/deepin/palette"))
{

}

void DPlatformThemePrivate::_q_onThemePropertyChanged(const QByteArray &name, const QVariant &value)
Expand Down Expand Up @@ -142,6 +151,8 @@ DPlatformTheme::DPlatformTheme(quint32 window, QObject *parent)
{
D_D(DPlatformTheme);

d->platformInterface = DPlatformInterface::self(this);

d->theme = new DNativeSettings(window, QByteArray(), this);
#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
connect(this, &DPlatformTheme::windowChanged, std::bind(&DPlatformThemePrivate::onQtColorChanged, d, QPalette::Window, std::placeholders::_1));
Expand Down Expand Up @@ -387,7 +398,8 @@ int DPlatformTheme::dndDragThreshold() const

int DPlatformTheme::windowRadius() const
{
return windowRadius(-1);
Q_D(const DPlatformTheme);
return d->platformInterface->windowRadius();
}

int DPlatformTheme::windowRadius(int defaultValue) const
Expand All @@ -414,9 +426,9 @@ QByteArray DPlatformTheme::themeName() const

QByteArray DPlatformTheme::iconThemeName() const
{
FETCH_PROPERTY("Net/IconThemeName", iconThemeName)
Q_D(const DPlatformTheme);

return value.toByteArray();
return d->platformInterface->iconThemeName();
}

QByteArray DPlatformTheme::soundThemeName() const
Expand All @@ -426,18 +438,22 @@ QByteArray DPlatformTheme::soundThemeName() const
return value.toByteArray();
}

QByteArray DPlatformTheme::fontName() const
QByteArray DPlatformTheme::cursorThemeName() const
{
FETCH_PROPERTY("Qt/FontName", fontName)
Q_D(const DPlatformTheme);
return d->platformInterface->cursorThemeName();
}

return value.toByteArray();
QByteArray DPlatformTheme::fontName() const
{
Q_D(const DPlatformTheme);
return d->platformInterface->fontName();
}

QByteArray DPlatformTheme::monoFontName() const
{
FETCH_PROPERTY("Qt/MonoFontName", monoFontName)

return value.toByteArray();
Q_D(const DPlatformTheme);
return d->platformInterface->monoFontName();
}

qreal DPlatformTheme::fontPointSize() const
Expand Down Expand Up @@ -699,7 +715,7 @@ void DPlatformTheme::setIconThemeName(const QByteArray &iconThemeName)
{
D_D(DPlatformTheme);

d->theme->setSetting("Net/IconThemeName", iconThemeName);
d->platformInterface->setIconThemeName(iconThemeName);
}

void DPlatformTheme::setSoundThemeName(const QByteArray &soundThemeName)
Expand All @@ -709,18 +725,25 @@ void DPlatformTheme::setSoundThemeName(const QByteArray &soundThemeName)
d->theme->setSetting("Net/SoundThemeName", soundThemeName);
}

void DPlatformTheme::setCursorThemeName(const QByteArray &cursorThemeName)
{
D_D(DPlatformTheme);

d->platformInterface->setCursorThemeName(cursorThemeName);
}

void DPlatformTheme::setFontName(const QByteArray &fontName)
{
D_D(DPlatformTheme);

d->theme->setSetting("Qt/FontName", fontName);
d->platformInterface->setFontName(fontName);
}

void DPlatformTheme::setMonoFontName(const QByteArray &monoFontName)
{
D_D(DPlatformTheme);

d->theme->setSetting("Qt/MonoFontName", monoFontName);
d->platformInterface->setMonoFontName(monoFontName);
}

void DPlatformTheme::setFontPointSize(qreal fontPointSize)
Expand Down Expand Up @@ -896,8 +919,7 @@ void DPlatformTheme::setDotsPerInch(const QString &screenName, int dpi)
void DPlatformTheme::setWindowRadius(int windowRadius)
{
D_D(DPlatformTheme);

d->theme->setSetting("DTK/WindowRadius", windowRadius);
d->platformInterface->setWindowRadius(windowRadius);
}

DGUI_END_NAMESPACE
Expand Down
Loading

0 comments on commit 2202279

Please sign in to comment.