Skip to content
Open
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 examples/test_super_overlay_surface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ qt_add_executable(${BIN_NAME}
qt_generate_wayland_protocol_client_sources(${BIN_NAME}
NO_INCLUDE_CORE_ONLY
FILES
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-dde-shell-v1.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-dde-shell-unstable-v2.xml
)

target_link_libraries(${BIN_NAME}
Expand Down
113 changes: 62 additions & 51 deletions examples/test_super_overlay_surface/ddeshellwayland.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2024 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2024-2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "ddeshellwayland.h"
Expand All @@ -6,28 +6,28 @@
#include <private/qwaylandwindow_p.h>

#include <QHash>
#include <QPlatformSurfaceEvent>

Check warning on line 9 in examples/test_super_overlay_surface/ddeshellwayland.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 10 in examples/test_super_overlay_surface/ddeshellwayland.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#define TREELANDDDESHELLMANAGERV1VERSION 1
#define TREELANDDDESHELLMANAGERV2VERSION 1

class DDEShellManageV1
: public QWaylandClientExtensionTemplate<DDEShellManageV1>
, public QtWayland::treeland_dde_shell_manager_v1
class DDEShellManageV2
: public QWaylandClientExtensionTemplate<DDEShellManageV2>
, public QtWayland::treeland_dde_shell_manager_v2
{
public:
DDEShellManageV1()
: QWaylandClientExtensionTemplate<DDEShellManageV1>(TREELANDDDESHELLMANAGERV1VERSION)
DDEShellManageV2()
: QWaylandClientExtensionTemplate<DDEShellManageV2>(TREELANDDDESHELLMANAGERV2VERSION)
{
initialize();
}
};

class DDEShellSurface : public QtWayland::treeland_dde_shell_surface_v1
class DDEShellSurface : public QtWayland::treeland_dde_shell_surface_v2
{
public:
DDEShellSurface(struct ::treeland_dde_shell_surface_v1 *id)
: QtWayland::treeland_dde_shell_surface_v1(id)
DDEShellSurface(struct ::treeland_dde_shell_surface_v2 *id)

Check warning on line 29 in examples/test_super_overlay_surface/ddeshellwayland.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'DDEShellSurface' has a constructor with 1 argument that is not explicit. Such, so called "Converting constructors", should in general be explicit for type safety reasons as that prevents unintended implicit conversions.
: QtWayland::treeland_dde_shell_surface_v2(id)
{
}

Expand All @@ -41,13 +41,13 @@
{
public:
ShellIntegrationSingleton();
std::unique_ptr<DDEShellManageV1> shellManager;
std::unique_ptr<DDEShellManageV2> shellManager;
QHash<QWindow *, DDEShellWayland *> windows;
};

ShellIntegrationSingleton::ShellIntegrationSingleton()
{
shellManager = std::make_unique<DDEShellManageV1>();
shellManager = std::make_unique<DDEShellManageV2>();

Check warning on line 50 in examples/test_super_overlay_surface/ddeshellwayland.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

When an object of a class is created, the constructors of all member variables are called consecutively in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'shellManager' a value by passing the value to the constructor in the initialization list.
}

Q_GLOBAL_STATIC(ShellIntegrationSingleton, s_waylandIntegration)
Expand All @@ -71,6 +71,16 @@
, m_window(window)
{
m_window->installEventFilter(this);

// The QWaylandClientExtension binds the global asynchronously: at first
// construction it is usually not active yet. Retry creating the shell
// surface once the manager becomes active, otherwise requests sent before
// activation would only be cached locally and never reach the compositor.
connect(s_waylandIntegration->shellManager.get(),
&DDEShellManageV2::activeChanged,
this,
&DDEShellWayland::surfaceCreated);

platformSurfaceCreated(window);
}

Expand All @@ -84,6 +94,13 @@
auto surfaceEvent = static_cast<QPlatformSurfaceEvent *>(event);
if (surfaceEvent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
platformSurfaceCreated(window);
} else if (surfaceEvent->surfaceEventType()
== QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) {
// The v2 protocol requires the shell surface to be destroyed
// before the wl_surface. Destroy it now; otherwise the shell
// surface proxy would outlive the wl_surface and the compositor
// rejects the stale object ("invalid object") on teardown.
m_shellSurface.reset();
}
}
return false;
Expand All @@ -96,12 +113,15 @@
}

m_position = position;
m_cursorPlacement.reset();
if (m_shellSurface) {
m_shellSurface->set_surface_position(m_position->x(), m_position->y());
// v2 position hint is output-relative; passing a null output anchors
// the coordinates at the primary output origin.
m_shellSurface->set_position_hint(nullptr, position.x(), position.y());
}
}

void DDEShellWayland::setRole(QtWayland::treeland_dde_shell_surface_v1::role role)
void DDEShellWayland::setRole(QtWayland::treeland_dde_shell_surface_v2::role role)
{
if (role == m_role) {
return;
Expand All @@ -113,51 +133,44 @@
}
}

void DDEShellWayland::setAutoPlacement(int32_t yOffset)
void DDEShellWayland::setCursorPlacement(int32_t xOffset, int32_t yOffset)
{
if (yOffset == m_yOffset) {
const QPoint offset(xOffset, yOffset);
if (offset == m_cursorPlacement) {
return;
}

m_yOffset = yOffset;
m_cursorPlacement = offset;
m_position.reset();
if (m_shellSurface) {
m_shellSurface->set_auto_placement(yOffset);
m_shellSurface->set_cursor_placement_hint(xOffset, yOffset);
}
}

void DDEShellWayland::setSkipSwitcher(uint32_t skip)
{
if (skip == m_skipSwitcher) {
return;
}

m_skipSwitcher = skip;
m_skipFlags = skip ? (m_skipFlags | QtWayland::treeland_dde_shell_surface_v2::skip_flag_switcher)
: (m_skipFlags & ~QtWayland::treeland_dde_shell_surface_v2::skip_flag_switcher);
if (m_shellSurface) {
m_shellSurface->set_skip_switcher(skip);
m_shellSurface->set_skip_flags(m_skipFlags);
}
}

void DDEShellWayland::setSkipDockPreview(uint32_t skip)
{
if (skip == m_skipDockPreview) {
return;
}

m_skipDockPreview = skip;
m_skipFlags = skip ? (m_skipFlags | QtWayland::treeland_dde_shell_surface_v2::skip_flag_dock_preview)
: (m_skipFlags & ~QtWayland::treeland_dde_shell_surface_v2::skip_flag_dock_preview);
if (m_shellSurface) {
m_shellSurface->set_skip_dock_preview(skip);
m_shellSurface->set_skip_flags(m_skipFlags);
}
}

void DDEShellWayland::setSkipMutiTaskView(uint32_t skip)
{
if (skip == m_skipMutiTaskView) {
return;
}

m_skipMutiTaskView = skip;
m_skipFlags = skip ? (m_skipFlags | QtWayland::treeland_dde_shell_surface_v2::skip_flag_multitask_view)
: (m_skipFlags & ~QtWayland::treeland_dde_shell_surface_v2::skip_flag_multitask_view);
if (m_shellSurface) {
m_shellSurface->set_skip_muti_task_view(skip);
m_shellSurface->set_skip_flags(m_skipFlags);
}
}

Expand Down Expand Up @@ -194,11 +207,18 @@

void DDEShellWayland::surfaceCreated()
{
struct wl_surface *surface = nullptr;
if (!s_waylandIntegration->shellManager || !s_waylandIntegration->shellManager->isActive()) {
return;
}

// Already created for the current wayland surface: avoid binding the same
// wl_surface twice (the compositor raises already_shell_surface for a
// second attempt). activeChanged and surfaceCreated may both fire.
if (m_shellSurface) {
return;
}

struct wl_surface *surface = nullptr;
if (auto waylandWindow =
m_window->nativeInterface<QNativeInterface::Private::QWaylandWindow>()) {
surface = waylandWindow->surface();
Expand All @@ -216,24 +236,15 @@
}

if (m_position) {
m_shellSurface->set_surface_position(m_position->x(), m_position->y());
}

if (m_yOffset) {
m_shellSurface->set_auto_placement(m_yOffset.value());
m_shellSurface->set_position_hint(nullptr, m_position->x(), m_position->y());
}

if (m_skipDockPreview) {
m_shellSurface->set_skip_dock_preview(m_skipDockPreview.value());
if (m_cursorPlacement) {
m_shellSurface->set_cursor_placement_hint(m_cursorPlacement->x(),
m_cursorPlacement->y());
}

if (m_skipMutiTaskView) {
m_shellSurface->set_skip_muti_task_view(m_skipMutiTaskView.value());
}

if (m_skipSwitcher) {
m_shellSurface->set_skip_switcher(m_skipSwitcher.value());
}
m_shellSurface->set_skip_flags(m_skipFlags);

if (!m_acceptKeyboardFocus) {
m_shellSurface->set_accept_keyboard_focus(m_acceptKeyboardFocus);
Expand Down
16 changes: 7 additions & 9 deletions examples/test_super_overlay_surface/ddeshellwayland.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (C) 2024 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2024-2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#pragma once

#include "qwayland-treeland-dde-shell-v1.h"
#include "qwayland-treeland-dde-shell-unstable-v2.h"

Check warning on line 6 in examples/test_super_overlay_surface/ddeshellwayland.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "qwayland-treeland-dde-shell-unstable-v2.h" not found.

#include <QObject>

Check warning on line 8 in examples/test_super_overlay_surface/ddeshellwayland.h

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 9 in examples/test_super_overlay_surface/ddeshellwayland.h

View workflow job for this annotation

GitHub Actions / cppcheck

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

class DDEShellSurface;

Expand All @@ -18,8 +18,8 @@
~DDEShellWayland();

void setPosition(const QPoint &position);
void setRole(QtWayland::treeland_dde_shell_surface_v1::role role);
void setAutoPlacement(int32_t yOffset);
void setRole(QtWayland::treeland_dde_shell_surface_v2::role role);
void setCursorPlacement(int32_t xOffset, int32_t yOffset);
void setSkipSwitcher(uint32_t skip);
void setSkipDockPreview(uint32_t skip);
void setSkipMutiTaskView(uint32_t skip);
Expand All @@ -34,11 +34,9 @@

QWindow *m_window = nullptr;
std::optional<QPoint> m_position;
std::optional<QtWayland::treeland_dde_shell_surface_v1::role> m_role;
std::optional<int32_t> m_yOffset;
std::optional<bool> m_skipSwitcher;
std::optional<bool> m_skipDockPreview;
std::optional<bool> m_skipMutiTaskView;
std::optional<QtWayland::treeland_dde_shell_surface_v2::role> m_role;
std::optional<QPoint> m_cursorPlacement;
uint32_t m_skipFlags = 0;
bool m_acceptKeyboardFocus = true;

std::unique_ptr<DDEShellSurface> m_shellSurface;
Expand Down
Loading
Loading