Hi everyone
I write this demo below, but the window doesn’s go to (100, 200), and it doesn’t skip taskbar or switcher, and it’s not OnScreenDisplay.
waylandwindow.h
#ifndef WAYLANDWINDOW_H
#define WAYLANDWINDOW_H
#include <QWidget>
#include <connection_thread.h>
#include <registry.h>
#include <compositor.h>
#include <plasmashell.h>
#include <surface.h>
using namespace KWayland::Client;
class WaylandWindow : public QWidget
{
Q_OBJECT
public:
WaylandWindow(QWidget *parent = nullptr);
~WaylandWindow();
private:
void init();
private:
ConnectionThread *m_connection;
Compositor *m_compositor = nullptr;
Surface *m_surface = nullptr;
PlasmaShell *m_plasmaShell = nullptr;
PlasmaShellSurface *m_plasmaShellSurface = nullptr;
};
#endif // WAYLANDWINDOW_H
waylandwindow.cpp
#include "waylandwindow.h"
WaylandWindow::WaylandWindow(QWidget *parent)
: QWidget(parent)
, m_connection(ConnectionThread::fromApplication(this))
{
init();
}
WaylandWindow::~WaylandWindow()
{
}
void WaylandWindow::init()
{
Registry *registry = new Registry(this);
registry->create(m_connection);
connect(registry, &Registry::compositorAnnounced, this, [this, registry](quint32 name, quint32 version) {
m_compositor = registry->createCompositor(name, version, this);
m_surface = m_compositor->createSurface(this);
});
connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) {
m_plasmaShell = registry->createPlasmaShell(name, version, this);
m_plasmaShellSurface = m_plasmaShell->createSurface(m_surface, this);
m_plasmaShellSurface->setPosition(QPoint(100, 200));
m_plasmaShellSurface->setSkipTaskbar(true);
m_plasmaShellSurface->setSkipSwitcher(true);
m_plasmaShellSurface->setRole(PlasmaShellSurface::Role::OnScreenDisplay);
});
registry->setup();
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(wayland-client VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(KF5Wayland CONFIG)
# set_package_properties(KF5Wayland PROPERTIES TYPE OPTIONAL )
# add_feature_info("KF5Wayland" KF5Wayland_FOUND "Required for the awesome Wayland on Qt demo")
set(PROJECT_SOURCES
main.cpp
waylandwindow.cpp
waylandwindow.h
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(wayland-client
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET wayland-client APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(wayland-client SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(wayland-client
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(wayland-client PRIVATE Qt${QT_VERSION_MAJOR}::Widgets KF5::WaylandClient)
set_target_properties(wayland-client PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(wayland-client)
endif()
main.cpp
#include "waylandwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
WaylandWindow w;
w.show();
return a.exec();
}
In this demo, WaylandWindow inherits QWidget. But if I change it to inherit QQuickView, it seems to work.
I wonder why is this happening? Does PlasmaShellSurface only support QQuickView class?
Tested on kubuntu 2304.
Thanks in advance