From 525ade39faf3fb0d48367eb3250c0beaddf7bf0c Mon Sep 17 00:00:00 2001 From: PikachuHy Date: Tue, 8 Jun 2021 00:54:46 +0800 Subject: [PATCH] feat: msvc build compat --- CMakeLists.txt | 20 ++- src/CMakeLists.txt | 60 +++++---- .../linux}/blurhelper/windowblur.cpp | 0 .../linux}/blurhelper/windowblur.h | 0 src/{ => platforms/linux}/windowhelper.cpp | 0 src/{ => platforms/linux}/windowhelper.h | 0 .../windows/blurhelper/windowblur.cpp | 118 ++++++++++++++++++ src/platforms/windows/blurhelper/windowblur.h | 78 ++++++++++++ src/platforms/windows/windowhelper.cpp | 51 ++++++++ src/platforms/windows/windowhelper.h | 44 +++++++ 10 files changed, 343 insertions(+), 28 deletions(-) rename src/{ => platforms/linux}/blurhelper/windowblur.cpp (100%) rename src/{ => platforms/linux}/blurhelper/windowblur.h (100%) rename src/{ => platforms/linux}/windowhelper.cpp (100%) rename src/{ => platforms/linux}/windowhelper.h (100%) create mode 100644 src/platforms/windows/blurhelper/windowblur.cpp create mode 100644 src/platforms/windows/blurhelper/windowblur.h create mode 100644 src/platforms/windows/windowhelper.cpp create mode 100644 src/platforms/windows/windowhelper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f085f1..8be431d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,10 @@ option(COMPONENT_SYNCING "Build syncing component" ON) find_package(ECM 5.45.0 NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) -set(QT Core Widgets Quick QuickControls2 X11Extras DBus) +set(QT Core Widgets Quick QuickControls2 DBus) +if (UNIX) + set(QT ${QT} X11Extras) +endif () find_package(Qt5 REQUIRED ${QT}) find_package(KF5WindowSystem REQUIRED) @@ -47,10 +50,21 @@ else() message(FATAL_ERROR "qml directory cannot be detected.") endif() +# Install +if (MSVC) + # Install FishUI to vcpkg installed dir + # for example. + # _VCPKG_INSTALLED_DIR:PATH=C:/app/vcpkg/installed + # VCPKG_TARGET_TRIPLET:STRING=x64-windows + # The final installed dir is C:/app/vcpkg/installed/x64-windows/share/FishUI + set(CMAKECONFIG_INSTALL_DIR "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/FishUI") + set(CMAKE_INSTALL_PREFIX "${_VCPKG_INSTALLED_DIR}") +else() + set(CMAKECONFIG_INSTALL_DIR "/usr/lib/cmake/FishUI") +endif () +message(STATUS "install directory:" "${CMAKECONFIG_INSTALL_DIR}") add_subdirectory(src) -# Install -set(CMAKECONFIG_INSTALL_DIR "/usr/lib/cmake/FishUI") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/FishUIConfig.cmake.in" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec7a82f..d46c228 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,29 +1,38 @@ set(TARGET FishUI) set(MODULE_VERSION "1.0") -set(SOURCES - fishui.cpp - iconthemeprovider.cpp - thememanager.cpp - shadowhelper/windowshadow.cpp - shadowhelper/boxshadowrenderer.cpp - shadowhelper/tileset.cpp - blurhelper/windowblur.cpp - blurhelper/windowblur.h - windowhelper.cpp - iconitem.cpp - newiconitem.cpp - managedtexturenode.cpp - wheelhandler.cpp - - desktop/menupopupwindow.cpp - - fishui.qrc - fish-style/style.qrc -) - -add_library(${TARGET} SHARED ${SOURCES}) - +add_library(${TARGET} SHARED "") +target_sources(${TARGET} PRIVATE + fishui.cpp + iconthemeprovider.cpp + thememanager.cpp + shadowhelper/windowshadow.cpp + shadowhelper/boxshadowrenderer.cpp + shadowhelper/tileset.cpp + + iconitem.cpp + newiconitem.cpp + managedtexturenode.cpp + wheelhandler.cpp + + desktop/menupopupwindow.cpp + + fishui.qrc + fish-style/style.qrc + ) +if (MSVC) + target_sources(${TARGET} PRIVATE + platforms/windows/windowhelper.cpp platforms/windows/windowhelper.h + platforms/windows/blurhelper/windowblur.cpp platforms/windows/blurhelper/windowblur.h + ) + target_include_directories(${TARGET} PRIVATE platforms/windows) +else() + target_sources(${TARGET} PRIVATE + platforms/linux/windowhelper.cpp platforms/linux/windowhelper.h + platforms/linux/blurhelper/windowblur.cpp platforms/linux/blurhelper/windowblur.h + ) + target_include_directories(${TARGET} PRIVATE platforms/linux) +endif () target_link_libraries (${TARGET} PUBLIC Qt5::Core @@ -34,13 +43,14 @@ target_link_libraries (${TARGET} Qt5::Quick Qt5::QuickControls2 Qt5::GuiPrivate - Qt5::X11Extras KF5::WindowSystem ) +if (UNIX) + target_link_libraries(${TARGET} PRIVATE Qt5::X11Extras) +endif () generate_export_header(${TARGET} BASE_NAME ${TARGET}) install(TARGETS ${TARGET} EXPORT ${TARGET}Targets ${INSTALL_TARGETS_DEFAULT_ARGS}) - install(TARGETS ${TARGET} DESTINATION ${INSTALL_QMLDIR}/${TARGET}) # Install Controls diff --git a/src/blurhelper/windowblur.cpp b/src/platforms/linux/blurhelper/windowblur.cpp similarity index 100% rename from src/blurhelper/windowblur.cpp rename to src/platforms/linux/blurhelper/windowblur.cpp diff --git a/src/blurhelper/windowblur.h b/src/platforms/linux/blurhelper/windowblur.h similarity index 100% rename from src/blurhelper/windowblur.h rename to src/platforms/linux/blurhelper/windowblur.h diff --git a/src/windowhelper.cpp b/src/platforms/linux/windowhelper.cpp similarity index 100% rename from src/windowhelper.cpp rename to src/platforms/linux/windowhelper.cpp diff --git a/src/windowhelper.h b/src/platforms/linux/windowhelper.h similarity index 100% rename from src/windowhelper.h rename to src/platforms/linux/windowhelper.h diff --git a/src/platforms/windows/blurhelper/windowblur.cpp b/src/platforms/windows/blurhelper/windowblur.cpp new file mode 100644 index 0000000..2712cb8 --- /dev/null +++ b/src/platforms/windows/blurhelper/windowblur.cpp @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: cutefish + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "windowblur.h" + +#include +#include +#include +#include + +WindowBlur::WindowBlur(QObject *parent) noexcept + : QObject(parent) + , m_view(nullptr) + , m_enabled(false) + , m_windowRadius(0.0) +{ +} + +WindowBlur::~WindowBlur() +{ +} + +void WindowBlur::classBegin() +{ +} + +void WindowBlur::componentComplete() +{ + updateBlur(); +} + +void WindowBlur::setView(QWindow *view) +{ + if (view != m_view) { + m_view = view; + updateBlur(); + emit viewChanged(); + + connect(m_view, &QWindow::visibleChanged, this, &WindowBlur::onViewVisibleChanged); + } +} + +QWindow* WindowBlur::view() const +{ + return m_view; +} + +void WindowBlur::setGeometry(const QRect &rect) +{ + if (rect != m_rect) { + m_rect = rect; + updateBlur(); + emit geometryChanged(); + } +} + +QRect WindowBlur::geometry() const +{ + return m_rect; +} + +void WindowBlur::setEnabled(bool enabled) +{ + if (enabled != m_enabled) { + m_enabled = enabled; + updateBlur(); + emit enabledChanged(); + } +} + +bool WindowBlur::enabled() const +{ + return m_enabled; +} + +void WindowBlur::setWindowRadius(qreal radius) +{ + if (radius != m_windowRadius) { + m_windowRadius = radius; + updateBlur(); + emit windowRadiusChanged(); + } +} + +qreal WindowBlur::windowRadius() const +{ + return m_windowRadius; +} + +void WindowBlur::onViewVisibleChanged(bool visible) +{ + if (visible) + updateBlur(); +} + +void WindowBlur::updateBlur() +{ + if (!m_view) + return; + + qWarning() << "not implement"; +} diff --git a/src/platforms/windows/blurhelper/windowblur.h b/src/platforms/windows/blurhelper/windowblur.h new file mode 100644 index 0000000..ae86cdb --- /dev/null +++ b/src/platforms/windows/blurhelper/windowblur.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: cutefish + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef WINDOWBLUR_H +#define WINDOWBLUR_H + +#include +#include +#include +#include +#include +#include +#include + +class WindowBlur : public QObject, public QQmlParserStatus +{ + Q_OBJECT + Q_PROPERTY(QWindow *view READ view WRITE setView NOTIFY viewChanged) + Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry NOTIFY geometryChanged) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(qreal windowRadius READ windowRadius WRITE setWindowRadius NOTIFY windowRadiusChanged) + Q_INTERFACES(QQmlParserStatus) + +public: + WindowBlur(QObject *parent = nullptr) noexcept; + ~WindowBlur() override; + + void classBegin() override; + void componentComplete() override; + + void setView(QWindow *view); + QWindow *view() const; + + void setGeometry(const QRect &rect); + QRect geometry() const; + + void setEnabled(bool enabled); + bool enabled() const; + + void setWindowRadius(qreal radius); + qreal windowRadius() const; + +private slots: + void onViewVisibleChanged(bool); + +private: + void updateBlur(); + +signals: + void viewChanged(); + void enabledChanged(); + void windowRadiusChanged(); + void geometryChanged(); + +private: + QWindow *m_view; + QRect m_rect; + bool m_enabled; + qreal m_windowRadius; +}; + +#endif diff --git a/src/platforms/windows/windowhelper.cpp b/src/platforms/windows/windowhelper.cpp new file mode 100644 index 0000000..0a8a871 --- /dev/null +++ b/src/platforms/windows/windowhelper.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: cutefish + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "windowhelper.h" + +#include +#include +#include + +#include + +WindowHelper::WindowHelper(QObject *parent) + : QObject(parent) +{ +} + +void WindowHelper::startSystemMove(QWindow *w) +{ + doStartSystemMoveResize(w, 16); +} + +void WindowHelper::startSystemResize(QWindow *w, Qt::Edges edges) +{ + doStartSystemMoveResize(w, edges); +} + +void WindowHelper::minimizeWindow(QWindow *w) +{ + KWindowSystem::minimizeWindow(w->winId()); +} + +void WindowHelper::doStartSystemMoveResize(QWindow *w, int edges) +{ + qWarning() << "not implement"; +} diff --git a/src/platforms/windows/windowhelper.h b/src/platforms/windows/windowhelper.h new file mode 100644 index 0000000..609a002 --- /dev/null +++ b/src/platforms/windows/windowhelper.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: cutefish + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef WINDOWHELPER_H +#define WINDOWHELPER_H + +#include +#include + +class WindowHelper : public QObject +{ + Q_OBJECT + +public: + explicit WindowHelper(QObject *parent = nullptr); + + Q_INVOKABLE void startSystemMove(QWindow *w); + Q_INVOKABLE void startSystemResize(QWindow *w, Qt::Edges edges); + + Q_INVOKABLE void minimizeWindow(QWindow *w); + +private: + void doStartSystemMoveResize(QWindow *w, int edges); + +private: +}; + +#endif // WINDOWHELPER_H