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#285
  • Loading branch information
deepin-ci-robot committed Dec 3, 2024
1 parent 4122505 commit e4c7098
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 29 deletions.
19 changes: 13 additions & 6 deletions src/kernel/dguiapplicationhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,17 +1682,24 @@ bool DGuiApplicationHelper::loadTranslator(const QList<QLocale> &localeFallback)
#else
auto qTranslationsPath = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
#endif
loadTranslator("qt", {qTranslationsPath}, localeFallback);
loadTranslator("qtbase", {qTranslationsPath}, localeFallback);

DCORE_USE_NAMESPACE
QList<QString> translateDirs;
auto appName = qApp->applicationName();
//("/home/user/.local/share", "/usr/local/share", "/usr/share")
auto dataDirs = DStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
QList<QString> qtranslateDirs = { qTranslationsPath };
for (const auto &path : dataDirs) {
DPathBuf pathBuf(path);
qtranslateDirs << (pathBuf / "qt" QT_STRINGIFY(QT_VERSION_MAJOR) / "translations").toString();
}

loadTranslator("qt", qtranslateDirs, localeFallback);
loadTranslator("qtbase", qtranslateDirs, localeFallback);

QList<QString> translateDirs;
auto appName = qApp->applicationName();
for (const auto &path : dataDirs) {
DPathBuf DPathBuf(path);
translateDirs << (DPathBuf / appName / "translations").toString();
DPathBuf pathBuf(path);
translateDirs << (pathBuf / appName / "translations").toString();
}

// ${translateDir}/${appName}_${localeName}.qm
Expand Down
81 changes: 58 additions & 23 deletions src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ bool MoveWindowHelper::windowEvent(QWindow *w, QEvent *event)
return true;
}


class Q_DECL_HIDDEN WindowEventFilter : public QObject {
public:
WindowEventFilter(QObject *parent = nullptr, DTreeLandPlatformWindowInterface *interface = nullptr)
Expand All @@ -158,7 +157,8 @@ class Q_DECL_HIDDEN WindowEventFilter : public QObject {
if (event->type() == QEvent::PlatformSurface) {
QPlatformSurfaceEvent *se = static_cast<QPlatformSurfaceEvent*>(event);
if (se->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
m_interface->doSetEnabledNoTitlebar();
m_interface->initWaylandWindow();
m_interface->onSurfaceCreated();
}
}
return QObject::eventFilter(watched, event);
Expand All @@ -182,13 +182,49 @@ DTreeLandPlatformWindowInterface::DTreeLandPlatformWindowInterface(QObject *pare
if (!MoveWindowHelper::mapped.value(window)) {
Q_UNUSED(new MoveWindowHelper(window))
}

initWaylandWindow();
}

DTreeLandPlatformWindowInterface::~DTreeLandPlatformWindowInterface()
{

}

void DTreeLandPlatformWindowInterface::onSurfaceCreated()
{
if (m_isNoTitlebar) {
doSetEnabledNoTitlebar();
}
if (m_isWindowBlur) {
doSetEnabledBlurWindow();
}
}

void DTreeLandPlatformWindowInterface::onSurfaceDestroyed()
{
if (m_windowContext) {
m_windowContext->deleteLater();
m_windowContext = nullptr;
}
}

void DTreeLandPlatformWindowInterface::initWaylandWindow()
{
// force create window handle
m_window->winId();

auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(m_window->handle());

if (!waylandWindow) {
qWarning() << "waylandWindow is nullptr!!!";
return;
}

connect(waylandWindow, &QtWaylandClient::QWaylandWindow::wlSurfaceCreated, this, &DTreeLandPlatformWindowInterface::onSurfaceCreated, Qt::UniqueConnection);
connect(waylandWindow, &QtWaylandClient::QWaylandWindow::wlSurfaceDestroyed, this, &DTreeLandPlatformWindowInterface::onSurfaceDestroyed, Qt::UniqueConnection);
}

PersonalizationWindowContext *DTreeLandPlatformWindowInterface::getWindowContext()
{
if (!m_manager->isSupported()) {
Expand All @@ -201,34 +237,21 @@ PersonalizationWindowContext *DTreeLandPlatformWindowInterface::getWindowContext
if (m_windowContext) {
return m_windowContext;
}
m_window->winId();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto waylandWindow = m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
#else

auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(m_window->handle());
#endif
if (!waylandWindow) {
qWarning() << "waylandWindow is nullptr!!!";
return nullptr;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto surface = waylandWindow->surface();
#else

auto surface = waylandWindow->waylandSurface()->object();
#endif
if (!surface) {
qWarning() << "waylandSurface is nullptr!!!";
return nullptr;
}

if (!m_windowContext) {
m_windowContext = new PersonalizationWindowContext(m_manager->get_window_context(surface));
connect(m_window, &QWindow::visibleChanged, m_windowContext, [this](bool visible){
if (!visible) {
m_windowContext->deleteLater();
m_windowContext = nullptr;
}
});
}

return m_windowContext;
Expand All @@ -244,20 +267,33 @@ void DTreeLandPlatformWindowInterface::handlePendingTasks()

bool DTreeLandPlatformWindowInterface::setEnabledNoTitlebar(bool enable)
{
if (m_isNoTitlebar == enable) {
return true;
}
m_isNoTitlebar = enable;
doSetEnabledNoTitlebar();
return true;
}

void DTreeLandPlatformWindowInterface::setEnableBlurWindow(bool enable)
{
auto handleFunc = [this, enable](){
if (m_isWindowBlur == enable) {
return;
}
m_isWindowBlur = enable;
doSetEnabledBlurWindow();
}

void DTreeLandPlatformWindowInterface::doSetEnabledNoTitlebar()
{
auto handleFunc = [this](){
auto windowContext = getWindowContext();
if (!windowContext) {
qWarning() << "windowContext is nullptr!";
return;
}
windowContext->set_blend_mode(enable ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent);
windowContext->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable);
return;
};
if (m_manager->isActive()) {
handleFunc();
Expand All @@ -266,16 +302,15 @@ void DTreeLandPlatformWindowInterface::setEnableBlurWindow(bool enable)
}
}

void DTreeLandPlatformWindowInterface::doSetEnabledNoTitlebar()
void DTreeLandPlatformWindowInterface::doSetEnabledBlurWindow()
{
auto handleFunc = [this](){
auto windowContext = getWindowContext();
if (!windowContext) {
qWarning() << "windowContext is nullptr!";
return false;
return;
}
windowContext->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable);
return true;
windowContext->set_blend_mode(m_isWindowBlur ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent);
};
if (m_manager->isActive()) {
handleFunc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "dtkgui_global.h"
#include "dtreelandplatforminterface.h"
#include <QObject>
#include <QtWaylandClient/private/qwaylandwindow_p.h>

DGUI_USE_NAMESPACE
class DTreeLandPlatformWindowInterface : public QObject
Expand All @@ -19,7 +20,13 @@ class DTreeLandPlatformWindowInterface : public QObject
bool setEnabledNoTitlebar(bool enable);
void setEnableBlurWindow(bool enable);
void doSetEnabledNoTitlebar();
void doSetEnabledBlurWindow();
[[nodiscard]]QWindow *getWindow() const { return m_window; }
void initWaylandWindow();

public slots:
void onSurfaceCreated();
void onSurfaceDestroyed();

private:
PersonalizationWindowContext *getWindowContext();
Expand All @@ -31,6 +38,7 @@ class DTreeLandPlatformWindowInterface : public QObject
PersonalizationManager *m_manager = nullptr;
PersonalizationWindowContext *m_windowContext = nullptr;
bool m_isNoTitlebar = true;
bool m_isWindowBlur = false;
};

#endif // DTREELANDPLATFORMWINDOWINTERFACE_H

0 comments on commit e4c7098

Please sign in to comment.