Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: from linuxdeepin/dtkgui #77

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kernel/dplatformhandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ class Q_DECL_HIDDEN CreatorWindowEventFilter : public QObject {
initWindowRadius(window);

#ifndef DTK_DISABLE_TREELAND
if (DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsWaylandPlatform)) {
if (DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsWaylandPlatform) && PersonalizationManager::instance()->isSupported()) {
PersonalizationManager::instance()->setEnableTitleBar(window, false);
}
#endif
Expand Down
49 changes: 34 additions & 15 deletions src/wayland/personalizationwaylandclientextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ class PersonalizationManager_: public PersonalizationManager {};
Q_GLOBAL_STATIC(PersonalizationManager_, personalizationManager)

PersonalizationManager::PersonalizationManager()
: QWaylandClientExtensionTemplate<PersonalizationManager>(1)
: QWaylandClientExtensionTemplate<PersonalizationManager>(treeland_personalization_manager_v1_interface.version)
, m_isSupported(false)
{
if (QGuiApplication::platformName() == QLatin1String("wayland")) {
QtWaylandClient::QWaylandIntegration *waylandIntegration = static_cast<QtWaylandClient::QWaylandIntegration *>(QGuiApplicationPrivate::platformIntegration());
if (!waylandIntegration) {
qWarning() << "waylandIntegration is nullptr!!!";
return;
}
m_waylandDisplay = waylandIntegration->display();
if (!m_waylandDisplay) {
qWarning() << "waylandDisplay is nullptr!!!";
return;
}
addListener();
QtWaylandClient::QWaylandIntegration *waylandIntegration = static_cast<QtWaylandClient::QWaylandIntegration *>(QGuiApplicationPrivate::platformIntegration());
if (!waylandIntegration) {
qWarning() << "waylandIntegration is nullptr!!!";
return;
}
m_waylandDisplay = waylandIntegration->display();
if (!m_waylandDisplay) {
qWarning() << "waylandDisplay is nullptr!!!";
return;
}
addListener();
m_isSupported = m_waylandDisplay->hasRegistryGlobal(QString::fromUtf8(treeland_personalization_manager_v1_interface.name));
if (!m_isSupported) {
qWarning() << "PersonalizationManager is not support";
}
}

Expand All @@ -46,8 +49,16 @@ PersonalizationManager *PersonalizationManager::instance()
return personalizationManager;
}

bool PersonalizationManager::isSupported() const
{
return m_isSupported;
}

PersonalizationWindowContext *PersonalizationManager::getWindowContext(QWindow *window)
{
if (!m_isSupported) {
return nullptr;
}
if (!window) {
qWarning() << "window is nullptr!!!";
return nullptr;
Expand All @@ -73,8 +84,16 @@ PersonalizationWindowContext *PersonalizationManager::getWindowContext(QWindow *
qWarning() << "waylandSurface is nullptr!!!";
return nullptr;
}

// FIXME: Before calling get_window_context, it was not determined whether PersonalizationManager was isActive
auto context = new PersonalizationWindowContext(get_window_context(surface));
connect(window, &QWindow::destroy, context, &PersonalizationWindowContext::deleteLater);
connect(window, &QWindow::visibleChanged, context, [this, context, window](bool visible){
if (!visible) {
context->deleteLater();
m_windowContexts.remove(window);
}
});

m_windowContexts.insert(window, context);
return context;
}
Expand Down Expand Up @@ -121,7 +140,7 @@ void PersonalizationManager::setEnableTitleBar(QWindow *window, bool enable)
}

PersonalizationWindowContext::PersonalizationWindowContext(struct ::treeland_personalization_window_context_v1 *context)
: QWaylandClientExtensionTemplate<PersonalizationWindowContext>(1)
: QWaylandClientExtensionTemplate<PersonalizationWindowContext>(treeland_personalization_window_context_v1_interface.version)
, QtWayland::treeland_personalization_window_context_v1(context)
{
}
Expand Down
2 changes: 2 additions & 0 deletions src/wayland/personalizationwaylandclientextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
~PersonalizationManager();

void setEnableTitleBar(QWindow *window, bool enable);
bool isSupported() const;

protected:
explicit PersonalizationManager();
Expand All @@ -38,9 +39,10 @@
private:
QHash<QWindow *, PersonalizationWindowContext *> m_windowContexts;
QtWaylandClient::QWaylandDisplay *m_waylandDisplay = nullptr;
bool m_isSupported;
};

class PersonalizationWindowContext : public QWaylandClientExtensionTemplate<PersonalizationWindowContext>,

Check warning on line 45 in src/wayland/personalizationwaylandclientextension.h

View workflow job for this annotation

GitHub Actions / cppcheck

The one definition rule is violated, different classes/structs have the same name 'PersonalizationWindowContext'
public QtWayland::treeland_personalization_window_context_v1
{
Q_OBJECT
Expand Down
Loading