1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-18 08:22:33 +02:00

Merge branch 'wip-layer-shell' into 172-add-wayland-layer-shell-support

This commit is contained in:
Elias Steurer 2023-08-04 11:20:30 +02:00
commit 994b0cd10a
6 changed files with 159 additions and 12 deletions

View File

@ -21,8 +21,13 @@ endif()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_CXX_STANDARD 20)
set(THIRD_PARTY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
set(THIRD_PARTY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/")
list(APPEND CMAKE_MODULE_PATH "${THIRD_PARTY_PATH}/ecm/modules")
list(APPEND CMAKE_MODULE_PATH "${THIRD_PARTY_PATH}/ecm/find-modules")
list(APPEND CMAKE_MODULE_PATH "${THIRD_PARTY_PATH}/ecm/kde-modules")
message(STATUS "[PROJECT] CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}")
option(OSX_BUNDLE "Enable distribution macOS bundle" OFF)
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.0")
@ -108,6 +113,12 @@ endif()
add_subdirectory(CMake)
add_subdirectory(ThirdParty)
# if(UNIX and not APPLE)
# # Needs to be append, because we include ecm as third party on linux
# list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
# else()
# endif()
add_subdirectory(Tools)
add_subdirectory(ScreenPlay)
@ -148,6 +159,7 @@ message(STATUS "[OPTION] SCREENPLAY_TESTS = ${SCREENPLAY_TESTS}")
message(STATUS "[PROJECT] SCREENPLAY_QML_MODULES_PATH = ${SCREENPLAY_QML_MODULES_PATH}")
message(STATUS "[PROJECT] CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
message(STATUS "[PROJECT] VCPKG_PATH = ${VCPKG_PATH}")
message(STATUS "[PROJECT] CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}")
message(STATUS "[PROJECT] VCPKG_TARGET_TRIPLET = ${VCPKG_TARGET_TRIPLET}")
message(STATUS "[PROJECT] CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}")
message(STATUS "[PROJECT] CMAKE_VERSION = ${CMAKE_VERSION}")

View File

@ -30,8 +30,8 @@ elseif(APPLE)
src/macintegration.h
src/macwindow.h)
elseif(UNIX)
set(SOURCES src/linuxx11window.cpp)
set(HEADER src/linuxx11window.h)
set(SOURCES src/linuxx11window.cpp src/linuxwaylandwindow.cpp)
set(HEADER src/linuxx11window.h src/linuxwaylandwindow.h)
endif()
set(SOURCES ${SOURCES} main.cpp src/basewindow.cpp)
@ -86,6 +86,9 @@ elseif(UNIX AND NOT APPLE)
endif()
if(UNIX AND NOT APPLE)
find_package(ECM CONFIG REQUIRED NO_MODULE)
find_package(LayerShellQt REQUIRED)
include(CopyRecursive)
copy_recursive(${CMAKE_CURRENT_SOURCE_DIR}/kde/ScreenPlay ${CMAKE_BINARY_DIR}/bin/kde/ScreenPlay "*")
endif()

View File

@ -16,6 +16,7 @@
Q_IMPORT_QML_PLUGIN(ScreenPlaySysInfoPlugin)
#elif defined(Q_OS_LINUX)
#include "src/linuxx11window.h"
#include "src/linuxwaylandwindow.h"
#elif defined(Q_OS_OSX)
#include "src/macwindow.h"
#endif
@ -39,7 +40,8 @@ int main(int argc, char* argv[])
#if defined(Q_OS_WIN)
WinWindow window;
#elif defined(Q_OS_LINUX)
LinuxX11Window window;
//LinuxX11Window window;
LinuxWaylandWindow window;
#elif defined(Q_OS_OSX)
MacWindow window;
#endif

View File

@ -0,0 +1,78 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "linuxwaylandwindow.h"
#include <QScreen>
#include "qwaylandlayersurface.h"
#include "qwaylandlayershellintegration.h"
#include <QGuiApplication>
ScreenPlay::WallpaperExitCode LinuxWaylandWindow::start()
{
if (!debugMode()) {
connect(m_sdk.get(), &ScreenPlaySDK::sdkDisconnected, this, &LinuxWaylandWindow::destroyThis);
}
qmlRegisterSingletonInstance<LinuxWaylandWindow>("ScreenPlayWallpaper", 1, 0, "Wallpaper", this);
QDir workingDir(QGuiApplication::instance()->applicationDirPath());
m_window.engine()->addImportPath(workingDir.path() + "/qml");
m_window.setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
m_window.setSource(QUrl("qrc:/qml/ScreenPlayWallpaper/qml/Wallpaper.qml"));
// Get the Wayland display
if (QGuiApplication::platformName() == "wayland") {
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
void *display = native->nativeResourceForWindow("display", nullptr);
// Create the layer shell
LayerShellQt::QWaylandLayerShellIntegration layerShell(display);
// Create the layer surface
LayerShellQt::QWaylandLayerSurface layerSurface(&layerShell, window.windowHandle());
// Set the layer to background
layerSurface.setLayer(LayerShellQt::zwlr_layer_shell_v1::layer::background);
// Set the size of the layer surface to match the screen size
QScreen *screen = QGuiApplication::primaryScreen();
layerSurface.setSize(screen->size().width(), screen->size().height());
// Set the anchor to all edges
layerSurface.setAnchor(LayerShellQt::zwlr_layer_surface_v1::anchor::top |
LayerShellQt::zwlr_layer_surface_v1::anchor::bottom |
LayerShellQt::zwlr_layer_surface_v1::anchor::left |
LayerShellQt::zwlr_layer_surface_v1::anchor::right);
}
m_window.show();
return ScreenPlay::WallpaperExitCode::Ok;
}
void LinuxWaylandWindow::setupWallpaperForOneScreen(int activeScreen)
{
}
void LinuxWaylandWindow::setupWallpaperForAllScreens()
{
}
void LinuxWaylandWindow::setupWallpaperForMultipleScreens(const QVector<int>& activeScreensList)
{
}
void LinuxWaylandWindow::setVisible(bool show)
{
m_window.setVisible(show);
}
void LinuxWaylandWindow::destroyThis()
{
QCoreApplication::quit();
}
void LinuxWaylandWindow::terminate()
{
QCoreApplication::quit();
}

View File

@ -0,0 +1,35 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#pragma once
#include <QDebug>
#include <QObject>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickView>
#include <QScreen>
#include <QSettings>
#include <QString>
#include <QVector>
#include "basewindow.h"
class LinuxWaylandWindow : public BaseWindow {
Q_OBJECT
public:
ScreenPlay::WallpaperExitCode start() override;
signals:
public slots:
void setVisible(bool show) override;
void destroyThis() override;
void terminate() override;
private:
QQuickView m_window;
void setupWallpaperForOneScreen(int activeScreen);
void setupWallpaperForAllScreens();
void setupWallpaperForMultipleScreens(const QVector<int>& activeScreensList);
};

View File

@ -8,13 +8,30 @@ FetchContent_Populate(
# https://bugreports.qt.io/browse/QTCREATORBUG-27083
SOURCE_DIR ${THIRD_PARTY_PATH}/QArchive)
FetchContent_Populate(
qml-plausible
GIT_REPOSITORY https://gitlab.com/kelteseth/qml-plausible.git
GIT_TAG 5069ba3bf25663ea06be8b94c398d6c61058d4d5
# Workaround because: 1. QtCreator cannot handle QML_ELEMENT stuff when it is in bin folder
# https://bugreports.qt.io/browse/QTCREATORBUG-27083
SOURCE_DIR ${THIRD_PARTY_PATH}/qml-plausible)
FetchContent_Populate(
qml-plausible
GIT_REPOSITORY https://gitlab.com/kelteseth/qml-plausible.git
GIT_TAG 5069ba3bf25663ea06be8b94c398d6c61058d4d5
# Workaround because: 1. QtCreator cannot handle QML_ELEMENT stuff when it is in bin folder
# https://bugreports.qt.io/browse/QTCREATORBUG-27083
SOURCE_DIR ${THIRD_PARTY_PATH}/qml-plausible)
add_subdirectory(qml-plausible)
add_subdirectory(QArchive)
if(UNIX AND NOT APPLE)
# FetchContent_Populate(
# ecm
# GIT_REPOSITORY https://github.com/KDE/extra-cmake-modules.git
# GIT_TAG ff820f0b556d169f210a1289b6bd67888ec492dd
# SOURCE_DIR ${THIRD_PARTY_PATH}/ecm)
# #add_subdirectory(ecm)
# list(APPEND CMAKE_MODULE_PATH "${THIRD_PARTY_PATH}/ecm/modules")
# FetchContent_Populate(
# layer-shell-qt
# GIT_REPOSITORY https://invent.kde.org/plasma/layer-shell-qt.git
# GIT_TAG d6aeaef1dc89b6b5ada0a835bf46d9adaee4838a
# SOURCE_DIR ${THIRD_PARTY_PATH}/layer-shell-qt)
add_subdirectory(layer-shell-qt)
endif()