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 12, 2024
1 parent 8cf037d commit 1e04332
Show file tree
Hide file tree
Showing 15 changed files with 603 additions and 561 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
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
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ else()
find_package(Qt5 REQUIRED COMPONENTS WaylandClient XkbCommonSupport)
endif()

find_package(TreeLandProtocols REQUIRED)

add_library(${LIB_NAME} SHARED)

include(dbus/dbus.cmake)
Expand All @@ -14,7 +16,7 @@ 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
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml
)
else()
# ECM setup
Expand All @@ -23,7 +25,7 @@ else()
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
PROTOCOL ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-personalization-manager-v1.xml
BASENAME treeland-personalization-manager-v1
)
target_sources(${LIB_NAME} PRIVATE
Expand Down
62 changes: 31 additions & 31 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 "wayland/personalizationwaylandclientextension.h"
#include <private/qwaylandwindow_p.h>

#include <QWindow>
Expand Down Expand Up @@ -100,7 +100,7 @@ static void setWindowProperty(QWindow *window, const char *name, const QVariant
static bool isTreeLand()
{
return qEnvironmentVariable("DDE_CURRENT_COMPOSITOR") == "TreeLand";
};
}

/*!
\class Dtk::Gui::DPlatformHandle
Expand Down Expand Up @@ -629,31 +629,29 @@ 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;
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 && PersonalizationManager::instance()->noTitlebar()) {
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<QtWaylandClient::QWaylandWindow *>(w->handle())->startSystemMove();
}
}
}
Expand Down Expand Up @@ -683,10 +681,7 @@ bool DPlatformHandle::setEnabledNoTitlebarForWindow(QWindow *window, bool enable
return false;

if (window && isTreeLand()) {
DContextShellWindow *contextWindow = DContextShellWindow::get(window);
if (contextWindow->noTitlebar() == enable)
return true;
contextWindow->setNoTitlebar(enable);
PersonalizationManager::instance()->setNoTitlebar(window, enable);
window->installEventFilter(new CreatorWindowEventFile(window));
return true;
}
Expand Down Expand Up @@ -1109,7 +1104,8 @@ void DPlatformHandle::setDisableWindowOverrideCursor(QWindow *window, bool disab

int DPlatformHandle::windowRadius() const
{
return m_window->property(_windowRadius).toInt();
return isTreeLand() ? PersonalizationManager::instance()->windowRadius() :
m_window->property(_windowRadius).toInt();
}

int DPlatformHandle::borderWidth() const
Expand Down Expand Up @@ -1209,8 +1205,12 @@ WId DPlatformHandle::windowLeader()

void DPlatformHandle::setWindowRadius(int windowRadius)
{
setWindowProperty(m_window, _windowRadius, windowRadius);
resolve(m_window, PropRole::WindowRadius);
if (isTreeLand()) {
PersonalizationManager::instance()->setWindowRadius(m_window, windowRadius);
} else {
setWindowProperty(m_window, _windowRadius, windowRadius);
resolve(m_window, PropRole::WindowRadius);
}
}

void DPlatformHandle::setBorderWidth(int borderWidth)
Expand Down
64 changes: 63 additions & 1 deletion src/kernel/dplatformtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "dplatformtheme.h"
#include "private/dplatformtheme_p.h"
#include "wayland/personalizationwaylandclientextension.h"

#include <QVariant>
#include <QTimer>
Expand All @@ -14,6 +15,11 @@

DGUI_BEGIN_NAMESPACE

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

// "/deepin/palette" 为调色板属性的存储位置
// 在x11平台下,将使用_DEEPIN_PALETTE作为存储调色板数据的窗口属性
DPlatformThemePrivate::DPlatformThemePrivate(Dtk::Gui::DPlatformTheme *qq)
Expand Down Expand Up @@ -387,6 +393,10 @@ int DPlatformTheme::dndDragThreshold() const

int DPlatformTheme::windowRadius() const
{
if (isTreeLand()) {
return PersonalizationManager::instance()->windowRadius();
}

return windowRadius(-1);
}

Expand Down Expand Up @@ -414,6 +424,10 @@ QByteArray DPlatformTheme::themeName() const

QByteArray DPlatformTheme::iconThemeName() const
{
if (isTreeLand()) {
return PersonalizationManager::instance()->iconTheme().toLatin1();
}

FETCH_PROPERTY("Net/IconThemeName", iconThemeName)

return value.toByteArray();
Expand All @@ -426,15 +440,34 @@ QByteArray DPlatformTheme::soundThemeName() const
return value.toByteArray();
}

QByteArray DPlatformTheme::cursorThemeName() const
{
if (isTreeLand()) {
return PersonalizationManager::instance()->cursorTheme().toLatin1();
}

FETCH_PROPERTY("Gtk/CursorThemeName", cursorThemeName)

return value.toByteArray();
}

QByteArray DPlatformTheme::fontName() const
{
if (isTreeLand()) {
return PersonalizationManager::instance()->fontName().toLatin1();
}

FETCH_PROPERTY("Qt/FontName", fontName)

return value.toByteArray();
}

QByteArray DPlatformTheme::monoFontName() const
{
if (isTreeLand()) {
return PersonalizationManager::instance()->monoFontName().toLatin1();
}

FETCH_PROPERTY("Qt/MonoFontName", monoFontName)

return value.toByteArray();
Expand Down Expand Up @@ -697,6 +730,11 @@ void DPlatformTheme::setThemeName(const QByteArray &themeName)

void DPlatformTheme::setIconThemeName(const QByteArray &iconThemeName)
{
if (isTreeLand()) {
PersonalizationManager::instance()->setIconTheme(iconThemeName);
return;
}

D_D(DPlatformTheme);

d->theme->setSetting("Net/IconThemeName", iconThemeName);
Expand All @@ -709,15 +747,35 @@ void DPlatformTheme::setSoundThemeName(const QByteArray &soundThemeName)
d->theme->setSetting("Net/SoundThemeName", soundThemeName);
}

void DPlatformTheme::setCursorThemeName(const QByteArray &cursorThemeName)
{
if (isTreeLand()) {
PersonalizationManager::instance()->setCursorTheme(cursorThemeName);
return;
}

D_D(DPlatformTheme);

d->theme->setSetting("Gtk/CursorThemeName", cursorThemeName);
}

void DPlatformTheme::setFontName(const QByteArray &fontName)
{
if (isTreeLand()) {
PersonalizationManager::instance()->setFontName(fontName);
return;
}
D_D(DPlatformTheme);

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

void DPlatformTheme::setMonoFontName(const QByteArray &monoFontName)
{
if (isTreeLand()) {
PersonalizationManager::instance()->setMonoFontName(monoFontName);
return;
}
D_D(DPlatformTheme);

d->theme->setSetting("Qt/MonoFontName", monoFontName);
Expand Down Expand Up @@ -895,8 +953,12 @@ void DPlatformTheme::setDotsPerInch(const QString &screenName, int dpi)

void DPlatformTheme::setWindowRadius(int windowRadius)
{
D_D(DPlatformTheme);
if (isTreeLand()) {
PersonalizationManager::instance()->setWindowRadius(windowRadius);
return;
}

D_D(DPlatformTheme);
d->theme->setSetting("DTK/WindowRadius", windowRadius);
}

Expand Down
Loading

0 comments on commit 1e04332

Please sign in to comment.