Skip to content
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
28 changes: 28 additions & 0 deletions examples/test_toplevel_tag/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include <any>
#include <QApplication>
#include <QDebug>
#include <QLabel>

Check warning on line 11 in examples/test_toplevel_tag/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLabel> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLineEdit>

Check warning on line 12 in examples/test_toplevel_tag/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLineEdit> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMainWindow>

Check warning on line 13 in examples/test_toplevel_tag/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMainWindow> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QComboBox>

Check warning on line 14 in examples/test_toplevel_tag/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QComboBox> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPushButton>

Check warning on line 15 in examples/test_toplevel_tag/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPushButton> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 16 in examples/test_toplevel_tag/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QVBoxLayout>

Check warning on line 17 in examples/test_toplevel_tag/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QVBoxLayout> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtWaylandClient/QWaylandClientExtension>

class XdgToplevelTagManager
Expand Down Expand Up @@ -46,12 +47,23 @@
descEdit->setPlaceholderText("Enter description...");
auto *setTagBtn = new QPushButton("Set Tag", central);
auto *setDescBtn = new QPushButton("Set Description", central);
auto *fullscreenBtn = new QPushButton("Fullscreen", central);
auto *restoreBtn = new QPushButton("Restore", central);
auto *tagLabel = new QLabel("Supported Tags:", central);
auto *tagCombo = new QComboBox(central);
tagCombo->addItem("test:invalid tag");
tagCombo->addItem("org.deepin.treeland.im-candidate-panel");
tagCombo->addItem("org.deepin.treeland.privileged-overlay");
auto *statusLabel = new QLabel(central);

layout->addWidget(tagEdit);
layout->addWidget(descEdit);
layout->addWidget(tagLabel);
layout->addWidget(tagCombo);
layout->addWidget(setTagBtn);
layout->addWidget(setDescBtn);
layout->addWidget(fullscreenBtn);
layout->addWidget(restoreBtn);
layout->addWidget(statusLabel);
window.setCentralWidget(central);

Expand Down Expand Up @@ -108,6 +120,22 @@
}
});

QObject::connect(fullscreenBtn, &QPushButton::clicked,
&window, &QWidget::showFullScreen);

QObject::connect(restoreBtn, &QPushButton::clicked,
&window, &QWidget::showNormal);

QObject::connect(tagCombo,
&QComboBox::currentIndexChanged,
&window,
[tagCombo, tagEdit](int index) {
const QString text = tagCombo->itemText(index);
if (!text.isEmpty()) {
tagEdit->setText(text);
}
});

statusLabel->setText("Ready");
});

Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ find_package(QT NAMES Qt6 COMPONENTS Core REQUIRED)
find_package(Qt6 CONFIG REQUIRED ShaderTools Concurrent RemoteObjects Network)
find_package(Qt6 COMPONENTS Quick QuickControls2 REQUIRED)
if(Qt6_VERSION VERSION_GREATER_EQUAL 6.10)
find_package(Qt6 REQUIRED COMPONENTS QuickPrivate)
find_package(Qt6 REQUIRED COMPONENTS QuickPrivate QuickTemplates2Private)
endif()
pkg_search_module(PIXMAN REQUIRED IMPORTED_TARGET pixman-1)
pkg_search_module(WAYLAND REQUIRED IMPORTED_TARGET wayland-server)
Expand Down Expand Up @@ -389,6 +389,7 @@ target_link_libraries(libtreeland
Qt6::Quick
Qt6::QuickControls2
Qt6::QuickPrivate
Qt6::QuickTemplates2Private
Qt6::DBus
Qt6::Concurrent
Qt6::RemoteObjects
Expand Down
2 changes: 2 additions & 0 deletions src/common/treelandlogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ Q_LOGGING_CATEGORY(lcTlDdm, "treeland.ddm")

// Popup focus management
Q_LOGGING_CATEGORY(lcTlPopupFocus, "treeland.popup.focus")
// XDG shell
Q_LOGGING_CATEGORY(lcTlShellXdg, "treeland.shell.xdg", QtInfoMsg)
2 changes: 2 additions & 0 deletions src/common/treelandlogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcTlDdm)

// Popup focus management
Q_DECLARE_LOGGING_CATEGORY(lcTlPopupFocus)
// XDG shell
Q_DECLARE_LOGGING_CATEGORY(lcTlShellXdg)

#endif // TREELAND_LOGGING_H
41 changes: 24 additions & 17 deletions src/core/imcandidatepanelmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "imcandidatepanelmanager.h"
#include "common/treelandlogging.h"

Check warning on line 5 in src/core/imcandidatepanelmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "common/treelandlogging.h" not found.

#include "output/output.h"

Check warning on line 7 in src/core/imcandidatepanelmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "output/output.h" not found.
#include "workspace/workspace.h"

Check warning on line 8 in src/core/imcandidatepanelmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "workspace/workspace.h" not found.
#include "rootsurfacecontainer.h"
#include "shellhandler.h"
#include "surface/surfacewrapper.h"
Expand Down Expand Up @@ -78,28 +80,33 @@
{
return m_imCandidatePanelAtom;
}

bool IMCandidatePanelManager::checkAndApplyIMCandidatePanel(
SurfaceWrapper *wrapper,
WAYLIB_SERVER_NAMESPACE::WXdgToplevelSurface *surface)
bool IMCandidatePanelManager::checkAndApplyIMCandidatePanel(SurfaceWrapper *wrapper)
{
if (surface->tag() != IM_CANDIDATE_PANEL)
return false;
if (wrapper->isIMCandidatePanel())
auto *shellSurface = wrapper->shellSurface();
if (auto *xdgSurface
= qobject_cast<WAYLIB_SERVER_NAMESPACE::WXdgToplevelSurface *>(shellSurface)) {
if (xdgSurface->tag() != IM_CANDIDATE_PANEL)
return false;
} else if (auto *xwaylandSurface
= qobject_cast<WAYLIB_SERVER_NAMESPACE::WXWaylandSurface *>(shellSurface)) {
if (!isIMCandidatePanel(xwaylandSurface))
return false;
} else {
return false;
applyIMCandidatePanel(wrapper);
return true;
}
}

bool IMCandidatePanelManager::checkAndApplyIMCandidatePanel(
SurfaceWrapper *wrapper,
WAYLIB_SERVER_NAMESPACE::WXWaylandSurface *surface)
{
if (!isIMCandidatePanel(surface))
return false;
if (wrapper->isIMCandidatePanel())
return false;
applyIMCandidatePanel(wrapper);

if (auto *xdgSurface = qobject_cast<WAYLIB_SERVER_NAMESPACE::WXdgToplevelSurface *>(shellSurface)) {
qCDebug(lcTlShellXdg) << "IM candidate panel applied" << wrapper
<< "appId =" << wrapper->appId()
<< "tag =" << xdgSurface->tag();
} else {
qCDebug(lcTlShellXdg) << "IM candidate panel applied (XWayland)" << wrapper
<< "appId =" << wrapper->appId();
}
return true;
}

Expand Down Expand Up @@ -244,7 +251,7 @@
bool value = IMCandidatePanelManager::parseIMCandidatePanelProperty(result, atom);
s->setProperty("imCandidatePanel", value);
if (wrapper) {
self->checkAndApplyIMCandidatePanel(wrapper, s);
self->checkAndApplyIMCandidatePanel(wrapper);
}
});
}
6 changes: 1 addition & 5 deletions src/core/imcandidatepanelmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Output;

namespace WAYLIB_SERVER_NAMESPACE {
class WInputMethodHelper;
class WXdgToplevelSurface;
class WXWayland;
class WXWaylandSurface;
} // namespace WAYLIB_SERVER_NAMESPACE
Expand All @@ -35,10 +34,7 @@ class IMCandidatePanelManager : public QObject

bool isIMCandidatePanel(SurfaceWrapper *wrapper) const;
bool isIMCandidatePanel(WAYLIB_SERVER_NAMESPACE::WXWaylandSurface *surface) const;
bool checkAndApplyIMCandidatePanel(SurfaceWrapper *wrapper,
WAYLIB_SERVER_NAMESPACE::WXdgToplevelSurface *surface);
bool checkAndApplyIMCandidatePanel(SurfaceWrapper *wrapper,
WAYLIB_SERVER_NAMESPACE::WXWaylandSurface *surface);
bool checkAndApplyIMCandidatePanel(SurfaceWrapper *wrapper);
xcb_atom_t imCandidatePanelAtom() const;

// Parse IM candidate panel property from async result map
Expand Down
2 changes: 2 additions & 0 deletions src/core/rootsurfacecontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class RootSurfaceContainer : public SurfaceContainer
PopupZOrder = 5,
CaptureLayerZOrder = 6,
LockScreenZOrder = 7,
GlobalOverlayZOrder = 100,
PrivilegedOverlayZOrder = 200, // Privileged overlay, above lock screen & lock screen popups
};

void init(WServer *server);
Expand Down
78 changes: 69 additions & 9 deletions src/core/shellhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <QColor>
#include <QPointer>
#include <QTimer>
#include <private/qquickoverlay_p.h>

#include <algorithm>
#include <functional>
Expand All @@ -57,6 +58,7 @@
WAYLIB_SERVER_USE_NAMESPACE

#define TREELAND_XDG_SHELL_VERSION 5
const QLatin1String PRIVILEGED_OVERLAY_TAG("org.deepin.treeland.privileged-overlay");

ShellHandler::ShellHandler(RootSurfaceContainer *rootContainer, WServer *server)
: m_rootSurfaceContainer(rootContainer)
Expand All @@ -66,6 +68,7 @@ ShellHandler::ShellHandler(RootSurfaceContainer *rootContainer, WServer *server)
, m_topContainer(new LayerSurfaceContainer(rootContainer))
, m_overlayContainer(new LayerSurfaceContainer(rootContainer))
, m_popupContainer(new SurfaceContainer(rootContainer))
, m_privilegedOverlayContainer(new SurfaceContainer(rootContainer))
, m_windowConfigStore(new WindowConfigStore(this))
{
m_treelandForeignToplevel = server->attach<ForeignToplevelManagerInterfaceV1>();
Expand All @@ -90,7 +93,8 @@ ShellHandler::ShellHandler(RootSurfaceContainer *rootContainer, WServer *server)
m_overlayContainer->setObjectName(QStringLiteral("OverlayContainer"));
m_popupContainer->setZ(RootSurfaceContainer::PopupZOrder);
m_popupContainer->setObjectName(QStringLiteral("PopupContainer"));

m_privilegedOverlayContainer->setZ(RootSurfaceContainer::PrivilegedOverlayZOrder);
m_privilegedOverlayContainer->setObjectName(QStringLiteral("PrivilegedOverlayContainer"));
connect(m_rootSurfaceContainer->outputModel(),
&QAbstractItemModel::rowsInserted,
this,
Expand Down Expand Up @@ -407,6 +411,11 @@ ForeignToplevelManagerInterfaceV1 *ShellHandler::foreignToplevel() const
return m_treelandForeignToplevel;
}

SurfaceContainer *ShellHandler::privilegedOverlayContainer() const
{
return m_privilegedOverlayContainer;
}

void ShellHandler::createComponent(QmlEngine *engine, QQuickItem *parentItem)
{
m_windowMenu = engine->createWindowMenu(Helper::instance());
Expand Down Expand Up @@ -481,6 +490,10 @@ void ShellHandler::init(WServer *server, WSeat *seat)
&WInputMethodHelper::inputPopupSurfaceV2Removed,
this,
&ShellHandler::onInputPopupSurfaceV2Removed);

auto *overlay = QQuickOverlay::overlay(m_rootSurfaceContainer->window());
overlay->setZ(RootSurfaceContainer::GlobalOverlayZOrder);
overlay->setParentItem(m_rootSurfaceContainer);
}

WXWayland *ShellHandler::createXWayland(WServer *server,
Expand Down Expand Up @@ -600,6 +613,8 @@ void ShellHandler::ensureXdgWrapper(WXdgToplevelSurface *surface, const QString
handleDdeShellSurfaceAdded(surface->surface(), wrapper);
}
auto updateSurfaceWithParentContainer = [this, wrapper, surface] {
if (wrapper->surfaceRole() == SurfaceWrapper::SurfaceRole::PrivilegedOverlay)
return;
updateWrapperContainer(wrapper, surface->parentSurface());
};

Expand All @@ -617,14 +632,59 @@ void ShellHandler::ensureXdgWrapper(WXdgToplevelSurface *surface, const QString
}
Q_EMIT surfaceWrapperAdded(wrapper);

// IM candidate panel detection via xdg-toplevel-tag
if (m_imCandidatePanelManager) {
QPointer<SurfaceWrapper> wrapperPtr(wrapper);
QObject::connect(surface, &WXdgToplevelSurface::tagChanged, this, [this, surface, wrapperPtr]() {
if (wrapperPtr)
m_imCandidatePanelManager->checkAndApplyIMCandidatePanel(wrapperPtr, surface);
});
QPointer<SurfaceWrapper> wrapperPtr(wrapper);
QObject::connect(surface, &WXdgToplevelSurface::tagChanged, this, [this, wrapperPtr]() {
if (wrapperPtr) {
if (checkAndApplyPrivilegedOverlay(wrapperPtr))
return;
if (m_imCandidatePanelManager->checkAndApplyIMCandidatePanel(wrapperPtr))
return;
}
});
}

bool ShellHandler::checkAndApplyPrivilegedOverlay(SurfaceWrapper *wrapper)
{
auto *xdgSurface = qobject_cast<WXdgToplevelSurface *>(wrapper->shellSurface());
if (!xdgSurface) return false;
if (xdgSurface->tag() != PRIVILEGED_OVERLAY_TAG) {
if (wrapper->surfaceRole() == SurfaceWrapper::SurfaceRole::PrivilegedOverlay)
revokePrivilegedOverlay(wrapper);
return false;
}
applyPrivilegedOverlay(wrapper);
return true;
}

void ShellHandler::applyPrivilegedOverlay(SurfaceWrapper *wrapper)
{
qCInfo(lcTlShellXdg) << "Privileged overlay promoted (tag)"
<< "wrapper =" << wrapper << "appId =" << wrapper->appId();
// Move from the original container to the privileged overlay container
if (auto *oldContainer = wrapper->container())
oldContainer->removeSurface(wrapper);
m_privilegedOverlayContainer->addSurface(wrapper);
wrapper->disableWindowAnimation();
wrapper->setSurfaceRole(SurfaceWrapper::SurfaceRole::PrivilegedOverlay);
wrapper->setPositionAutomatic(false);
wrapper->setHasInitializeContainer(true);
wrapper->setSkipDockPreView(true);
wrapper->setSkipMutiTaskView(true);
}

void ShellHandler::revokePrivilegedOverlay(SurfaceWrapper *wrapper)
{
qCInfo(lcTlShellXdg) << "Privileged overlay revoked (tag removed)"
<< "wrapper =" << wrapper << "appId =" << wrapper->appId();
// Move from the privileged overlay container back to the workspace
if (auto *oldContainer = wrapper->container())
oldContainer->removeSurface(wrapper);
wrapper->setSurfaceRole(SurfaceWrapper::SurfaceRole::Normal);
wrapper->setPositionAutomatic(true);
wrapper->disableWindowAnimation(false);
wrapper->setSkipDockPreView(false);
wrapper->setSkipMutiTaskView(false);
m_workspace->addSurface(wrapper);
}

void ShellHandler::onXdgToplevelSurfaceRemoved(WXdgToplevelSurface *surface)
Expand Down Expand Up @@ -868,7 +928,7 @@ void ShellHandler::ensureXwaylandWrapper(WXWaylandSurface *surface, const QStrin

// IM candidate panel detection via XWayland xprop
if (m_imCandidatePanelManager
&& m_imCandidatePanelManager->checkAndApplyIMCandidatePanel(wrapper, surface)) {
&& m_imCandidatePanelManager->checkAndApplyIMCandidatePanel(wrapper)) {
Q_EMIT surfaceWrapperAdded(wrapper);
return;
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/shellhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ShellHandler : public QObject
WAYLIB_SERVER_NAMESPACE::WServer *server);
[[nodiscard]] Workspace *workspace() const;
[[nodiscard]] SurfaceContainer *popupContainer() const;
[[nodiscard]] SurfaceContainer *privilegedOverlayContainer() const;
[[nodiscard]] RootSurfaceContainer *rootSurfaceContainer() const;
[[nodiscard]] ForeignToplevelManagerInterfaceV1 *foreignToplevel() const;

Expand Down Expand Up @@ -169,7 +170,9 @@ private Q_SLOTS:
void onInitialPropertiesReady(WAYLIB_SERVER_NAMESPACE::WXWaylandSurface *surface,
const QString &appId,
const QMap<xcb_atom_t, QByteArray> &result);

bool checkAndApplyPrivilegedOverlay(SurfaceWrapper *wrapper);
void applyPrivilegedOverlay(SurfaceWrapper *wrapper);
void revokePrivilegedOverlay(SurfaceWrapper *wrapper);
WAYLIB_SERVER_NAMESPACE::WXdgShell *m_xdgShell = nullptr;
WAYLIB_SERVER_NAMESPACE::WLayerShell *m_layerShell = nullptr;
TreelandWallpaperShellInterfaceV1 *m_wallpaperShell = nullptr;
Expand All @@ -187,6 +190,7 @@ private Q_SLOTS:
LayerSurfaceContainer *m_topContainer = nullptr;
LayerSurfaceContainer *m_overlayContainer = nullptr;
SurfaceContainer *m_popupContainer = nullptr;
SurfaceContainer *m_privilegedOverlayContainer = nullptr;
IMCandidatePanelManager *m_imCandidatePanelManager = nullptr;
QObject *m_windowMenu = nullptr;
// Prelaunch wrappers created before binding to a real shell surface
Expand Down
Loading
Loading