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#292
  • Loading branch information
deepin-ci-robot authored and 18202781743 committed Dec 25, 2024
1 parent 02d4266 commit fd9efea
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 139 deletions.
25 changes: 10 additions & 15 deletions src/kernel/dplatformhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,8 @@ bool DPlatformHandle::isDXcbPlatform()
void DPlatformHandle::enableDXcbForWindow(QWindow *window)
{
DPlatformHandle handle(window);
#ifndef DTK_DISABLE_XCB
if (auto impl = dynamic_cast<DXCBPlatformWindowInterface *>(platformWindowImpl(&handle))) {
impl->setEnabled(true);
}
#endif
auto impl = platformWindowImpl(&handle);
impl->setEnabled(true);
}

/*!
Expand Down Expand Up @@ -518,12 +515,8 @@ void DPlatformHandle::enableDXcbForWindow(QWindow *window, bool redirectContent)
bool DPlatformHandle::isEnabledDXcb(const QWindow *window)
{
DPlatformHandle handle(const_cast<QWindow *>(window));
#ifndef DTK_DISABLE_XCB
if (auto impl = dynamic_cast<DXCBPlatformWindowInterface *>(platformWindowImpl(&handle))) {
return impl->isEnabled();
}
#endif
return false;
auto impl = platformWindowImpl(&handle);
return impl->isEnabled();
}

/*!
Expand Down Expand Up @@ -608,7 +601,8 @@ bool DPlatformHandle::setWindowBlurAreaByWM(QWindow *window, const QVector<DPlat
return impl->setWindowBlurArea(area);
}
#endif
return false;
handle.setEnableBlurWindow(true);
return true;
}

/*!
Expand Down Expand Up @@ -663,7 +657,8 @@ bool DPlatformHandle::setWindowBlurAreaByWM(QWindow *window, const QList<QPainte
return impl->setWindowBlurArea(paths);
}
#endif
return false;
handle.setEnableBlurWindow(true);
return true;
}

/*!
Expand Down Expand Up @@ -705,9 +700,9 @@ bool DPlatformHandle::setWindowBlurAreaByWM(QWindow *window, const QList<QPainte
*/
bool DPlatformHandle::setWindowWallpaperParaByWM(QWindow *window, const QRect &area, WallpaperScaleMode sMode, WallpaperFillMode fMode)
{
DPlatformHandle handler(window);
DPlatformHandle handle(window);
#ifndef DTK_DISABLE_XCB
if (auto impl = dynamic_cast<DXCBPlatformWindowInterface *>(platformWindowImpl(&handler))) {
if (auto impl = dynamic_cast<DXCBPlatformWindowInterface *>(platformWindowImpl(&handle))) {
return impl->setWindowWallpaperPara(area, sMode, fMode);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dplatformwindowinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void DPlatformWindowInterface::setBorderColor(const QColor &borderColor)

int DPlatformWindowInterface::shadowRadius() const
{
return -1;
return {};
}

void DPlatformWindowInterface::setShadowRadius(int shadowRadius)
Expand Down
219 changes: 107 additions & 112 deletions src/plugins/platform/treeland/dtreelandplatformwindowinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
DCORE_USE_NAMESPACE

DGUI_BEGIN_NAMESPACE

class Q_DECL_HIDDEN MoveWindowHelper : public QObject
{
public:
Expand Down Expand Up @@ -143,120 +142,102 @@ bool MoveWindowHelper::windowEvent(QWindow *w, QEvent *event)
return true;
}

class Q_DECL_HIDDEN WindowEventFilter : public QObject {
public:
WindowEventFilter(DTreeLandPlatformWindowInterface *interface = nullptr)
: QObject(interface)
{
QMap<QWindow *, DTreeLandPlatformWindowHelper*> DTreeLandPlatformWindowHelper::windowMap;
DTreeLandPlatformWindowHelper *DTreeLandPlatformWindowHelper::get(QWindow *window)
{
if (!PersonalizationManager::instance()->isSupported()) {
return nullptr;
}

DTreeLandPlatformWindowInterface *interface() const
{
return qobject_cast<DTreeLandPlatformWindowInterface *>(parent());
if (!window) {
return nullptr;
}

bool eventFilter(QObject *watched, QEvent *event) {
if (event->type() == QEvent::PlatformSurface) {
QPlatformSurfaceEvent *se = static_cast<QPlatformSurfaceEvent*>(event);
if (se->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
if (auto item = interface()) {
item->initWaylandWindow();
item->onSurfaceCreated();
}
}
}
return QObject::eventFilter(watched, event);
if (auto helper = windowMap.value(window)) {
return helper;
}
};
auto helper = new DTreeLandPlatformWindowHelper(window);
windowMap[window] = helper;
return helper;
}

DTreeLandPlatformWindowInterface::DTreeLandPlatformWindowInterface(QWindow *window, DPlatformHandle *platformHandle, QObject *parent)
: QObject(parent)
, DPlatformWindowInterface(window, platformHandle)
DTreeLandPlatformWindowHelper::DTreeLandPlatformWindowHelper(QWindow *window)
: QObject(window)
{
m_manager = PersonalizationManager::instance();
m_window->installEventFilter(new WindowEventFilter(this));
connect(m_manager, &PersonalizationManager::activeChanged, this, [this](){
if (m_manager->isActive()) {
handlePendingTasks();
}
});
window->installEventFilter(this);

if (!MoveWindowHelper::mapped.value(window)) {
Q_UNUSED(new MoveWindowHelper(window))
if (!PersonalizationManager::instance()->isActive()) {
qWarning() << "Personalization is not active" << window;
connect(PersonalizationManager::instance(), &PersonalizationManager::activeChanged, this, &DTreeLandPlatformWindowHelper::onActiveChanged, Qt::QueuedConnection);
}

initWaylandWindow();
if (window->handle()) {
initWaylandWindow();
}
}

DTreeLandPlatformWindowInterface::~DTreeLandPlatformWindowInterface()
DTreeLandPlatformWindowHelper::~DTreeLandPlatformWindowHelper()
{

windowMap.remove(window());
}

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

void DTreeLandPlatformWindowInterface::onSurfaceDestroyed()
{
if (m_windowContext) {
m_windowContext->deleteLater();
m_windowContext = nullptr;
bool DTreeLandPlatformWindowHelper::eventFilter(QObject *watched, QEvent *event) {
if (event->type() == QEvent::PlatformSurface) {
QPlatformSurfaceEvent *se = static_cast<QPlatformSurfaceEvent*>(event);
if (se->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
if (PersonalizationManager::instance()->isActive()) {
initWaylandWindow();
onSurfaceCreated();
}
}
}
return QObject::eventFilter(watched, event);
}

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

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

auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(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);
connect(waylandWindow, &QtWaylandClient::QWaylandWindow::wlSurfaceCreated, this, &DTreeLandPlatformWindowHelper::onSurfaceCreated, Qt::UniqueConnection);
connect(waylandWindow, &QtWaylandClient::QWaylandWindow::wlSurfaceDestroyed, this, &DTreeLandPlatformWindowHelper::onSurfaceDestroyed, Qt::UniqueConnection);
}

void DTreeLandPlatformWindowInterface::setEnabled(bool enabled)
void DTreeLandPlatformWindowHelper::onActiveChanged()
{
if (setEnabledNoTitlebar(enabled)) {
return;
if (PersonalizationManager::instance()->isActive()) {
qDebug() << "Personalization is actived, window" << window();
if (window()->handle()) {
onSurfaceCreated();
}
}
}

bool DTreeLandPlatformWindowInterface::isEnabled() const
void DTreeLandPlatformWindowHelper::onSurfaceCreated()
{
return isEnabledNoTitlebar();
Q_EMIT surfaceCreated();
}

PersonalizationWindowContext *DTreeLandPlatformWindowInterface::getWindowContext()
void DTreeLandPlatformWindowHelper::onSurfaceDestroyed()
{
if (!m_manager->isSupported()) {
return nullptr;
}
if (!m_window) {
qWarning() << "window is nullptr!!!";
return nullptr;
if (m_windowContext) {
m_windowContext->deleteLater();
m_windowContext = nullptr;
}
}

PersonalizationWindowContext *DTreeLandPlatformWindowHelper::windowContext() const
{
if (m_windowContext) {
return m_windowContext;
}

auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(m_window->handle());
if (!waylandWindow) {
qWarning() << "waylandWindow is nullptr!!!";
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window()->handle());
if (!waylandWindow)
return nullptr;
}

if (!waylandWindow->waylandSurface()) {
qWarning() << "waylandSurface is nullptr!!!";
Expand All @@ -270,20 +251,51 @@ PersonalizationWindowContext *DTreeLandPlatformWindowInterface::getWindowContext
}

if (!m_windowContext) {
m_windowContext = new PersonalizationWindowContext(m_manager->get_window_context(surface));
const_cast<DTreeLandPlatformWindowHelper *>(this)->m_windowContext = new PersonalizationWindowContext(PersonalizationManager::instance()->get_window_context(surface));
}

return m_windowContext;
}

void DTreeLandPlatformWindowInterface::handlePendingTasks()
DTreeLandPlatformWindowInterface::DTreeLandPlatformWindowInterface(QWindow *window, DPlatformHandle *platformHandle, QObject *parent)
: QObject(parent)
, DPlatformWindowInterface(window, platformHandle)
{
while (!m_pendingTasks.isEmpty()) {
auto handleFunc = m_pendingTasks.dequeue();
handleFunc();
if (!MoveWindowHelper::mapped.value(window)) {
Q_UNUSED(new MoveWindowHelper(window))
}

if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
connect(helper, &DTreeLandPlatformWindowHelper::surfaceCreated, this, &DTreeLandPlatformWindowInterface::onSurfaceCreated);
}
}

DTreeLandPlatformWindowInterface::~DTreeLandPlatformWindowInterface()
{
}

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

void DTreeLandPlatformWindowInterface::setEnabled(bool enabled)
{
if (setEnabledNoTitlebar(enabled)) {
return;
}
}

bool DTreeLandPlatformWindowInterface::isEnabled() const
{
return isEnabledNoTitlebar();
}

bool DTreeLandPlatformWindowInterface::isEnabledNoTitlebar() const
{
return m_isNoTitlebar;
Expand Down Expand Up @@ -329,57 +341,40 @@ void DTreeLandPlatformWindowInterface::setEnableBlurWindow(bool enable)

void DTreeLandPlatformWindowInterface::doSetEnabledNoTitlebar()
{
auto handleFunc = [this](){
auto windowContext = getWindowContext();
if (!windowContext) {
qWarning() << "windowContext is nullptr!";
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
auto context = helper->windowContext();
if (!context) {
return;
}
windowContext->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable);
return;
};
if (m_manager->isActive()) {
handleFunc();
} else {
m_pendingTasks.enqueue(handleFunc);
context->set_titlebar(m_isNoTitlebar ? PersonalizationWindowContext::enable_mode_disable : PersonalizationWindowContext::enable_mode_enable);
}
}

void DTreeLandPlatformWindowInterface::doSetWindowRadius()
{
auto handleFunc = [this](){
auto windowContext = getWindowContext();
if (!windowContext) {
qWarning() << "windowContext is nullptr!";
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
auto context = helper->windowContext();
if (!context) {
return;
}
windowContext->set_round_corner_radius(m_radius);
context->set_round_corner_radius(m_radius);
if (m_platformHandle) {
Q_EMIT m_platformHandle->windowRadiusChanged();
}
return;
};
if (m_manager->isActive()) {
handleFunc();
} else {
m_pendingTasks.enqueue(handleFunc);
}
}

void DTreeLandPlatformWindowInterface::doSetEnabledBlurWindow()
{
auto handleFunc = [this](){
auto windowContext = getWindowContext();
if (!windowContext) {
qWarning() << "windowContext is nullptr!";
if (auto helper = DTreeLandPlatformWindowHelper::get(m_window)) {
auto context = helper->windowContext();
if (!context) {
return;
}
windowContext->set_blend_mode(m_isWindowBlur ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent);
};
if (m_manager->isActive()) {
handleFunc();
} else {
m_pendingTasks.enqueue(handleFunc);
context->set_blend_mode(m_isWindowBlur ? PersonalizationWindowContext::blend_mode_blur : PersonalizationWindowContext::blend_mode_transparent);
if (m_platformHandle) {
Q_EMIT m_platformHandle->enableBlurWindowChanged();
}
}
}
DGUI_END_NAMESPACE
Loading

0 comments on commit fd9efea

Please sign in to comment.