1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-10-06 09:17:07 +02:00

Merge branch 'master' into qt6-support

This commit is contained in:
Elias Steurer 2021-12-02 15:27:17 +01:00
commit 5b387545c1
13 changed files with 163 additions and 111 deletions

View File

@ -56,7 +56,7 @@ execute_process(
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_compile_definitions(COMPILE_INFO="${BUILD_DATE} + ${GIT_COMMIT_HASH}")
add_compile_definitions(COMPILE_INFO="Build Date: ${BUILD_DATE}. Git Hash: ${GIT_COMMIT_HASH}. ")
add_compile_definitions(SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
add_compile_definitions(SCREENPLAY_STEAM="${SCREENPLAY_STEAM}")
@ -76,6 +76,9 @@ add_subdirectory(CMake)
if(${SCREENPLAY_STEAM})
add_subdirectory(ScreenPlayWorkshop)
else()
# Only add target SteamSDKQtEnums
add_subdirectory(ScreenPlayWorkshop/SteamSDK)
endif()
if(WIN32)

View File

@ -204,7 +204,7 @@ target_link_libraries(
Qt6::Svg
Qt6::WebEngineQuick
Qt6::WebEngineCore
SteamSDK)
SteamSDKQtEnums)
if(${TESTS_ENABLED})
add_executable(tst_ScreenPlay tests/tst_main.cpp)

View File

@ -135,6 +135,41 @@ QVariant MonitorListModel::data(const QModelIndex& index, int role) const
*/
void MonitorListModel::loadMonitors()
{
#ifdef Q_OS_WIN
QModelIndex index;
ScreenPlayUtil::WinMonitorStats monitors;
// This offset lets us center the monitor selection view in the center
int offsetX = 0;
int offsetY = 0;
for (int i = 0; i < monitors.iMonitors.size(); i++) {
const int x = monitors.rcMonitors[i].left;
const int y = monitors.rcMonitors[i].top;
if (x < 0) {
offsetX += (x * -1);
}
if (y < 0) {
offsetY += (y * -1);
}
}
for (int i = 0; i < monitors.iMonitors.size(); i++) {
const int width = std::abs(monitors.rcMonitors[i].right - monitors.rcMonitors[i].left);
const int height = std::abs(monitors.rcMonitors[i].top - monitors.rcMonitors[i].bottom);
const int x = monitors.rcMonitors[i].left;
const int y = monitors.rcMonitors[i].top;
QRect availableVirtualGeometry(
x + offsetX,
y + offsetY,
width,
height);
beginInsertRows(index, m_monitorList.size(), m_monitorList.size());
m_monitorList.append(Monitor { i, availableVirtualGeometry, QApplication::screens().at(i) });
endInsertRows();
}
#else
QModelIndex index;
int offsetX = 0;
int offsetY = 0;
@ -148,7 +183,6 @@ void MonitorListModel::loadMonitors()
}
}
QModelIndex index;
for (int i = 0; i < QApplication::screens().count(); i++) {
QScreen* screen = QApplication::screens().at(i);
@ -166,6 +200,7 @@ void MonitorListModel::loadMonitors()
m_monitorList.append(Monitor { i, availableVirtualGeometry, screen });
endInsertRows();
}
#endif
emit monitorReloadCompleted();
}

View File

@ -174,6 +174,11 @@ void ScreenPlayWallpaper::processError(QProcess::ProcessError error)
*/
bool ScreenPlayWallpaper::setWallpaperValue(const QString& key, const QString& value, const bool save)
{
if (!m_connection) {
qWarning() << "Cannot set value for unconnected wallpaper!";
return false;
}
QJsonObject obj;
obj.insert(key, value);

View File

@ -26,3 +26,8 @@ target_include_directories(
PRIVATE src/)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core)
if(WIN32)
# Used for query windows monitor data
target_link_libraries(${PROJECT_NAME} PUBLIC shcore.lib)
endif()

View File

@ -33,6 +33,17 @@
****************************************************************************/
#pragma once
#include <QtGlobal>
#if defined(Q_OS_WIN)
// Must be first!
#include <qt_windows.h>
#include "WinUser.h"
#include <ShellScalingApi.h>
#endif
#include "ScreenPlayUtil/contenttypes.h"
#include <QJsonArray>
#include <QJsonObject>
@ -41,6 +52,37 @@
#include <optional>
namespace ScreenPlayUtil {
#if defined(Q_OS_WIN)
struct WinMonitorStats {
std::vector<int> iMonitors;
std::vector<HMONITOR> hMonitors;
std::vector<HDC> hdcMonitors;
std::vector<RECT> rcMonitors;
std::vector<DEVICE_SCALE_FACTOR> scaleFactor;
std::vector<std::pair<UINT, UINT>> sizes;
static BOOL CALLBACK MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor,
LPARAM pData)
{
WinMonitorStats* pThis = reinterpret_cast<WinMonitorStats*>(pData);
auto scaleFactor = DEVICE_SCALE_FACTOR::DEVICE_SCALE_FACTOR_INVALID;
GetScaleFactorForMonitor(hMon, &scaleFactor);
UINT x = 0;
UINT y = 0;
GetDpiForMonitor(hMon, MONITOR_DPI_TYPE::MDT_RAW_DPI, &x, &y);
pThis->sizes.push_back({ x, y });
pThis->scaleFactor.push_back(scaleFactor);
pThis->hMonitors.push_back(hMon);
pThis->hdcMonitors.push_back(hdc);
pThis->rcMonitors.push_back(*lprcMonitor);
pThis->iMonitors.push_back(pThis->hdcMonitors.size());
return TRUE;
}
WinMonitorStats() { EnumDisplayMonitors(0, 0, MonitorEnum, (LPARAM)this); }
};
#endif
QJsonArray fillArray(const QVector<QString>& items);
ScreenPlay::SearchType::SearchType getSearchTypeFromInstalledType(const ScreenPlay::InstalledType::InstalledType type);
std::optional<ScreenPlay::InstalledType::InstalledType> getInstalledTypeFromString(const QString& type);

View File

@ -233,7 +233,7 @@ std::optional<ScreenPlay::InstalledType::InstalledType> getInstalledTypeFromStri
{
using ScreenPlay::InstalledType::InstalledType;
if (type.endsWith("Wallpaper")) {
if (type.endsWith("Wallpaper", Qt::CaseInsensitive)) {
if (type.startsWith("video", Qt::CaseInsensitive)) {
return InstalledType::VideoWallpaper;
}
@ -254,7 +254,7 @@ std::optional<ScreenPlay::InstalledType::InstalledType> getInstalledTypeFromStri
}
}
if (type.endsWith("Widget")) {
if (type.endsWith("Widget", Qt::CaseInsensitive)) {
if (type.startsWith("qml", Qt::CaseInsensitive)) {
return InstalledType::QMLWidget;
}
@ -266,28 +266,27 @@ std::optional<ScreenPlay::InstalledType::InstalledType> getInstalledTypeFromStri
return std::nullopt;
}
/*!
\brief Maps the video codec type from a QString to an enum. Used for parsing the project.json.
*/
std::optional<ScreenPlay::VideoCodec::VideoCodec> getVideoCodecFromString(const QString &type)
std::optional<ScreenPlay::VideoCodec::VideoCodec> getVideoCodecFromString(const QString& type)
{
if(type.isEmpty())
if (type.isEmpty())
return std::nullopt;
if(type.contains("vp8",Qt::CaseInsensitive))
if (type.contains("vp8", Qt::CaseInsensitive))
return ScreenPlay::VideoCodec::VideoCodec::VP8;
if(type.contains("vp9",Qt::CaseInsensitive))
if (type.contains("vp9", Qt::CaseInsensitive))
return ScreenPlay::VideoCodec::VideoCodec::VP9;
if(type.contains("av1",Qt::CaseInsensitive))
if (type.contains("av1", Qt::CaseInsensitive))
return ScreenPlay::VideoCodec::VideoCodec::AV1;
if(type.contains("h264",Qt::CaseInsensitive))
if (type.contains("h264", Qt::CaseInsensitive))
return ScreenPlay::VideoCodec::VideoCodec::H264;
if(type.contains("h265",Qt::CaseInsensitive))
if (type.contains("h265", Qt::CaseInsensitive))
return ScreenPlay::VideoCodec::VideoCodec::H264;
return std::nullopt;
@ -395,5 +394,4 @@ std::optional<QVector<int>> parseStringToIntegerList(const QString string)
return list;
}
}

View File

@ -83,6 +83,5 @@ if(WIN32)
# Disable console window on Windows
# https://stackoverflow.com/questions/8249028/how-do-i-keep-my-qt-c-program-from-opening-a-console-in-windows
set_property(TARGET ${PROJECT_NAME} PROPERTY WIN32_EXECUTABLE true)
target_link_libraries(${PROJECT_NAME} PRIVATE shcore.lib)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/index.html ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/index.html COPYONLY)
endif()

View File

@ -17,11 +17,18 @@ Rectangle {
if (Wallpaper.videoCodec === VideoCodec.Unknown) {
Wallpaper.terminate()
}
// macOS only supports h264 via the native Qt MM
if (Qt.platform === "osx" && (Wallpaper.videoCodec === VideoCodec.VP8
|| Wallpaper.videoCodec === VideoCodec.VP9)) {
loader.source = "qrc:/ScreenPlayWallpaper/qml/MultimediaWebView.qml"
} else {
if (Qt.platform.os === "osx") {
if ((Wallpaper.videoCodec === VideoCodec.VP8
|| Wallpaper.videoCodec === VideoCodec.VP9)) {
loader.source = "qrc:/ScreenPlayWallpaper/qml/MultimediaWebView.qml"
} else {
loader.source = "qrc:/ScreenPlayWallpaper/qml/MultimediaView.qml"
}
}
if (Qt.platform.os === "windows") {
loader.source = "qrc:/ScreenPlayWallpaper/qml/MultimediaView.qml"
}
fadeIn()

View File

@ -1,41 +1,8 @@
#include "winwindow.h"
#include "WinUser.h"
#include "qqml.h"
#include <ShellScalingApi.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <windows.h>
struct WinMonitorStats {
std::vector<int> iMonitors;
std::vector<HMONITOR> hMonitors;
std::vector<HDC> hdcMonitors;
std::vector<RECT> rcMonitors;
std::vector<DEVICE_SCALE_FACTOR> scaleFactor;
std::vector<std::pair<UINT, UINT>> sizes;
static BOOL CALLBACK MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor,
LPARAM pData)
{
WinMonitorStats* pThis = reinterpret_cast<WinMonitorStats*>(pData);
auto scaleFactor = DEVICE_SCALE_FACTOR::DEVICE_SCALE_FACTOR_INVALID;
GetScaleFactorForMonitor(hMon, &scaleFactor);
UINT x = 0;
UINT y = 0;
GetDpiForMonitor(hMon, MONITOR_DPI_TYPE::MDT_RAW_DPI, &x, &y);
pThis->sizes.push_back({ x, y });
pThis->scaleFactor.push_back(scaleFactor);
pThis->hMonitors.push_back(hMon);
pThis->hdcMonitors.push_back(hdc);
pThis->rcMonitors.push_back(*lprcMonitor);
pThis->iMonitors.push_back(pThis->hdcMonitors.size());
return TRUE;
}
WinMonitorStats() { EnumDisplayMonitors(0, 0, MonitorEnum, (LPARAM)this); }
};
/*!
\brief Searches for the worker window for our window to parent to.
@ -225,11 +192,6 @@ WinWindow::WinWindow(
configureWindowGeometry();
if (hasWindowScaling()) {
qInfo() << "Monitor with scaling detected!";
configureWindowGeometry();
}
// We do not support autopause for multi monitor wallpaper
if (this->activeScreensList().length() == 1) {
if (checkWallpaperVisible) {
@ -294,13 +256,13 @@ void WinWindow::setupWallpaperForOneScreen(int activeScreen)
const QRect screenRect = QApplication::screens().at(activeScreen)->geometry();
const int boderWidth = 2;
const float scaling = getScaling(activeScreen);
const auto width = screenRect.width() * scaling + boderWidth;
const auto height = screenRect.height() * scaling + boderWidth;
const int borderOffset = -1;
const int x = screenRect.x() + m_zeroPoint.x() + borderOffset;
const int y = screenRect.y() + m_zeroPoint.y() + borderOffset;
ScreenPlayUtil::WinMonitorStats monitors;
const int width = std::abs(monitors.rcMonitors[activeScreen].right - monitors.rcMonitors[activeScreen].left);
const int height = std::abs(monitors.rcMonitors[activeScreen].top - monitors.rcMonitors[activeScreen].bottom);
const int x = monitors.rcMonitors[activeScreen].left + m_zeroPoint.x() + borderOffset;
const int y = monitors.rcMonitors[activeScreen].top + m_zeroPoint.y() + borderOffset;
qInfo() << QString("Setup window activeScreen: %1 scaling: %2 x: %3 y: %4 width: %5 height: %6").arg(activeScreen).arg(scaling).arg(x).arg(y).arg(width).arg(height);
{

View File

@ -34,54 +34,31 @@ set(HEADER
src/steamaccount.h
src/steamqmlimageprovider.h)
set(STEAM_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SteamSDK/redistributable_bin/")
if(WIN32)
set(WORKSHOP_PLUGIN_DIR ${CMAKE_BINARY_DIR}/bin/Workshop)
set(STEAM_LIB "${STEAM_LIB_PATH}/win64/steam_api64.lib")
set(STEAM_BIN "${STEAM_LIB_PATH}/win64/steam_api64.dll")
elseif(APPLE)
set(WORKSHOP_PLUGIN_DIR ${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/Workshop)
set(STEAM_LIB "${STEAM_LIB_PATH}/osx/libsteam_api.dylib")
set(STEAM_BIN ${STEAM_LIB})
elseif(UNIX)
set(WORKSHOP_PLUGIN_DIR ${CMAKE_BINARY_DIR}/bin/Workshop)
set(STEAM_LIB "${STEAM_LIB_PATH}/linux64/libsteam_api.so")
set(STEAM_BIN ${STEAM_LIB})
endif()
qt_add_qml_module(
${PROJECT_NAME}
OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/Workshop
OUTPUT_DIRECTORY ${WORKSHOP_PLUGIN_DIR}
URI "Workshop"
SOURCES ${SOURCES} ${HEADER}
VERSION
1.0)
# Needed by the automatic generated target missing includes
# https://github.com/qt/qtdeclarative/blob/7a7064e14f094e843e1ee832cc927e86f887621a/src/qml/Qt6QmlMacros.cmake#L2042
target_include_directories(${PROJECT_NAME} PUBLIC src/)
set(STEAM_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SteamSDK/redistributable_bin/")
if(WIN32)
set(STEAM_LIB "${STEAM_LIB_PATH}/win64/steam_api64.lib")
set(STEAM_BIN "${STEAM_LIB_PATH}/win64/steam_api64.dll")
elseif(APPLE)
set(STEAM_LIB "${STEAM_LIB_PATH}/osx/libsteam_api.dylib")
set(STEAM_BIN ${STEAM_LIB})
elseif(UNIX)
set(STEAM_LIB "${STEAM_LIB_PATH}/linux64/libsteam_api.so")
set(STEAM_BIN ${STEAM_LIB})
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Quick ${STEAM_LIB} ScreenPlayUtil SteamSDK)
if(APPLE)
set(workshop_install_dir ${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/Workshop)
add_custom_target(
build-time-make-directory
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${workshop_install_dir})
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMENT "Copying workshop plugin into ScreenPlay.app bundle"
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/Workshop/libworkshopplugin.dylib ${workshop_install_dir})
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMENT "Copying steam library into ScreenPlay.app bundle"
COMMAND ${CMAKE_COMMAND} -E copy ${STEAM_BIN} ${workshop_install_dir})
if(${SCREENPLAY_STEAM})
add_custom_command(
TARGET ${PROJECT_NAME}
@ -89,11 +66,24 @@ if(APPLE)
COMMENT "Copying steam_appid.txt into ScreenPlay.app bundle. This is for development only!"
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/steam_appid.txt
${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/)
endif()
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMENT "Copying libsteam_api.dylib into ScreenPlay.app bundle."
COMMAND ${CMAKE_COMMAND} -E copy ${STEAM_LIB}
${WORKSHOP_PLUGIN_DIR})
endif()
else()
if(${SCREENPLAY_STEAM})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/steam_appid.txt ${CMAKE_BINARY_DIR}/bin/steam_appid.txt COPYONLY)
configure_file(${STEAM_BIN} ${CMAKE_BINARY_DIR}/bin/ COPYONLY)
endif()
configure_file(${STEAM_BIN} ${CMAKE_BINARY_DIR}/bin/ COPYONLY)
endif()
# Needed by the automatic generated target missing includes
# https://github.com/qt/qtdeclarative/blob/7a7064e14f094e843e1ee832cc927e86f887621a/src/qml/Qt6QmlMacros.cmake#L2042
target_include_directories(${PROJECT_NAME} PUBLIC src/)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Quick ${STEAM_LIB} ScreenPlayUtil SteamSDK SteamSDKQtEnums)

View File

@ -50,11 +50,17 @@ set(HEADER
public/steam/steamps3params.h
public/steam/steamtypes.h
public/steam/steamuniverse.h
# CUSTOM
public/steam/steam_qt_enums_generated.h
# ENDCUSTOM
)
add_library(${PROJECT_NAME} STATIC ${HEADER})
target_include_directories(${PROJECT_NAME} PUBLIC public/)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core)
if(${SCREENPLAY_STEAM})
add_library(${PROJECT_NAME} STATIC ${HEADER})
target_include_directories(${PROJECT_NAME} PUBLIC public/)
target_link_libraries(${PROJECT_NAME})
endif()
# We allaways need the generated enums as a workaround to register these enums in app.cpp.
# Registering in the ScreenPlayWorkshop plugin does not work for some reason.
add_library(SteamSDKQtEnums STATIC public/steam/steam_qt_enums_generated.h)
target_include_directories(SteamSDKQtEnums PUBLIC public/)
target_link_libraries(SteamSDKQtEnums PRIVATE Qt6::Core)

View File

@ -45,7 +45,7 @@ if not args.build_type:
print("Build type argument is missing (release,debug). Example: python build.py -t release -steam=True")
sys.exit(1)
qt_version = "6.2.0"
qt_version = "6.2.1"
steam_build = "OFF"
if args.steam_build:
if args.steam_build: