Skip to content
Draft
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_shortcut_capture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ qt_add_executable(${BIN_NAME}

qt_generate_wayland_protocol_client_sources(${BIN_NAME}
FILES
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-shortcut-manager-v2.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-shortcut-manager-unstable-v3.xml
)

target_link_libraries(${BIN_NAME}
Expand Down
32 changes: 16 additions & 16 deletions examples/test_shortcut_capture/main.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// Copyright (C) 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

// Test application for treeland_shortcut_capture_v1 (treeland-shortcut-manager-v2, version 2).
// Test application for treeland_shortcut_capture_v3 (treeland-shortcut-manager-unstable-v3, version 1).
// A window with a single button: click to request one-shot shortcut capture.
// The captured key sequence or failure reason is shown below the button.

#include "qwayland-treeland-shortcut-manager-v2.h"
#include "qwayland-treeland-shortcut-manager-unstable-v3.h"

Check warning on line 8 in examples/test_shortcut_capture/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "qwayland-treeland-shortcut-manager-unstable-v3.h" not found.

#include <private/qwaylandwindow_p.h>

Check warning on line 10 in examples/test_shortcut_capture/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QApplication>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWaylandClientExtension>

Check warning on line 16 in examples/test_shortcut_capture/main.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.
#include <QWidget>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

// Wraps the treeland_shortcut_capture_v1 Wayland object and emits Qt signals.
// Wraps the treeland_shortcut_capture_v3 Wayland object and emits Qt signals.
class ShortcutCapture
: public QObject
, public QtWayland::treeland_shortcut_capture_v1
, public QtWayland::treeland_shortcut_capture_v3
{
Q_OBJECT
public:
explicit ShortcutCapture(struct ::treeland_shortcut_capture_v1 *capture,
explicit ShortcutCapture(struct ::treeland_shortcut_capture_v3 *capture,
QObject *parent = nullptr)
: QObject(parent)
, QtWayland::treeland_shortcut_capture_v1(capture)
, QtWayland::treeland_shortcut_capture_v3(capture)
{
}

Expand All @@ -37,30 +37,30 @@

Q_SIGNALS:
void captured(const QString &key);
void failed(uint32_t reason);

Check warning on line 40 in examples/test_shortcut_capture/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'failed' shadows outer function

protected:
void treeland_shortcut_capture_v1_captured(const QString &key) override
void treeland_shortcut_capture_v3_captured(const QString &key) override

Check warning on line 43 in examples/test_shortcut_capture/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'treeland_shortcut_capture_v3_captured' is never used.
{
emit captured(key);
deleteLater();
}

void treeland_shortcut_capture_v1_failed(uint32_t reason) override
void treeland_shortcut_capture_v3_failed(uint32_t reason) override

Check warning on line 49 in examples/test_shortcut_capture/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'treeland_shortcut_capture_v3_failed' is never used.
{
emit failed(reason);
deleteLater();
}
};

class ShortcutManagerV2
: public QWaylandClientExtensionTemplate<ShortcutManagerV2>
, public QtWayland::treeland_shortcut_manager_v2
class ShortcutManagerV3
: public QWaylandClientExtensionTemplate<ShortcutManagerV3>
, public QtWayland::treeland_shortcut_manager_v3
{
Q_OBJECT
public:
explicit ShortcutManagerV2()
: QWaylandClientExtensionTemplate<ShortcutManagerV2>(2)
explicit ShortcutManagerV3()
: QWaylandClientExtensionTemplate<ShortcutManagerV3>(1)
{
}

Expand All @@ -85,7 +85,7 @@

static QString cancelReasonText(uint32_t reason)
{
using R = QtWayland::treeland_shortcut_capture_v1;
using R = QtWayland::treeland_shortcut_capture_v3;
switch (static_cast<R::failed_reason>(reason)) {
case R::failed_reason_busy:
return QStringLiteral("Another capture is already in progress (busy)");
Expand All @@ -105,7 +105,7 @@
qputenv("QT_QPA_PLATFORM", "wayland");
QApplication app(argc, argv);

ShortcutManagerV2 manager;
ShortcutManagerV3 manager;

// Main window
QWidget window;
Expand All @@ -124,7 +124,7 @@

// Disable button until the protocol is available
btn->setEnabled(false);
QObject::connect(&manager, &ShortcutManagerV2::activeChanged, btn, [&] {
QObject::connect(&manager, &ShortcutManagerV3::activeChanged, btn, [&] {
btn->setEnabled(manager.isActive());
});

Expand Down
5 changes: 3 additions & 2 deletions examples/test_shortcut_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Qt6 REQUIRED COMPONENTS WaylandClient)
find_package(Qt6 REQUIRED COMPONENTS Gui WaylandClient Widgets)
find_package(TreelandProtocols REQUIRED)

set(BIN_NAME test-shortcut-manager)
Expand All @@ -9,12 +9,13 @@ qt_add_executable(${BIN_NAME}

qt_generate_wayland_protocol_client_sources(${BIN_NAME}
FILES
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-shortcut-manager-v2.xml
${TREELAND_PROTOCOLS_DATA_DIR}/treeland-shortcut-manager-unstable-v3.xml
)

target_link_libraries(${BIN_NAME}
PRIVATE
Qt6::Gui
Qt6::Widgets
Qt6::WaylandClient
)

Expand Down
Loading
Loading