Skip to content
Merged
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
45 changes: 45 additions & 0 deletions examples/qml/fpscounter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "fpscounter.h"
#include <QtCore/qtimer.h>
#include <QtQuick/qquickwindow.h>

class FPSCounterPrivate final {
Q_DISABLE_COPY(FPSCounterPrivate)
Q_DECLARE_PUBLIC(FPSCounter)

public:
FPSCounterPrivate(FPSCounter* qq);
~FPSCounterPrivate();

FPSCounter* q_ptr{ nullptr };
int frameCount{ 0 };
QMetaObject::Connection connection{};
};

FPSCounterPrivate::FPSCounterPrivate(FPSCounter* qq) : q_ptr{ qq } {
QObject::connect(q_ptr, &FPSCounter::windowChanged, q_ptr, [this](QQuickWindow* window){
if (connection) {
QObject::disconnect(std::exchange(connection, {}));
}
if (window) {
connection = QObject::connect(window, &QQuickWindow::frameSwapped, q_ptr, [this](){ ++frameCount; });
}
});
auto timer = new QTimer(q_ptr);
timer->setTimerType(Qt::PreciseTimer);
QObject::connect(timer, &QTimer::timeout, q_ptr, [this](){
Q_EMIT q_ptr->valueChanged();
frameCount = 0;
});
timer->start(1000);
}

FPSCounterPrivate::~FPSCounterPrivate() = default;

FPSCounter::FPSCounter(QQuickItem* parent) : QQuickItem{ parent }, d_ptr{ std::make_unique<FPSCounterPrivate>(this) } {}

FPSCounter::~FPSCounter() = default;

int FPSCounter::value() const {
Q_D(const FPSCounter);
return d->frameCount;
}
26 changes: 26 additions & 0 deletions examples/qml/fpscounter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <QtQuick/qquickitem.h>
#include <memory>

class FPSCounterPrivate;
class FPSCounter : public QQuickItem {
Q_OBJECT
Q_DECLARE_PRIVATE(FPSCounter)
Q_PROPERTY(int value READ value NOTIFY valueChanged FINAL)
#ifdef QML_ELEMENT
QML_ELEMENT
#endif

public:
explicit FPSCounter(QQuickItem* parent = nullptr);
~FPSCounter() override;

int value() const;

Q_SIGNALS:
void valueChanged();

private:
const std::unique_ptr<FPSCounterPrivate> d_ptr;
};
20 changes: 16 additions & 4 deletions examples/qml/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0

#include "fpscounter.h"
#include <QtCore/qloggingcategory.h>
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlApplicationEngine>
#include <QtQml/QQmlContext>
Expand All @@ -20,7 +22,10 @@ extern "C" {
int main(int argc, char *argv[]) {
qputenv("QT_WIN_DEBUG_CONSOLE", "attach"); // or "new": create a separate console window
qputenv("QSG_INFO", "1");
qputenv("QT_NO_OPENGL_BUGLIST", "1");
qputenv("QSG_NO_VSYNC", "1");
qputenv("QT_D3D_NO_VBLANK_THREAD", "1");
qputenv("QT_QPA_UPDATE_IDLE_TIME", "0");

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
qputenv("QT_QUICK_CONTROLS_STYLE", "Basic");
Expand All @@ -29,7 +34,7 @@ int main(int argc, char *argv[]) {
#endif

#ifdef Q_OS_WINDOWS
qputenv("QSG_RHI_BACKEND", "d3d11"); // options: d3d11, d3d12, opengl, vulkan
qputenv("QSG_RHI_BACKEND", "d3d11"); // options: d3d11, d3d12, opengl, vulkan
qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1");
#endif
//qputenv("QSG_RHI_HDR", "scrgb"); // other options: hdr10, p3
Expand All @@ -38,17 +43,24 @@ int main(int argc, char *argv[]) {
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif

QGuiApplication application(argc, argv);

QLoggingCategory::setFilterRules(QStringLiteral("qt.qpa.screen.updates=true"));

// Make sure alpha channel is requested, our special effects on Windows depends on it.
QQuickWindow::setDefaultAlphaBuffer(true);
QQmlApplicationEngine engine;

QQmlApplicationEngine engine{};
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
const bool curveRenderingAvailable = true;
constexpr bool curveRenderingAvailable = true;
#else
const bool curveRenderingAvailable = false;
constexpr bool curveRenderingAvailable = false;
#endif
engine.rootContext()->setContextProperty(QStringLiteral("$curveRenderingAvailable"), QVariant(curveRenderingAvailable));
QWK::registerTypes(&engine);
qmlRegisterType<FPSCounter>("QWK.Demo", 1, 0, "FPSCounter");
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));

return application.exec();
}
23 changes: 23 additions & 0 deletions examples/qml/main.qml
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QWK.Demo 1.0

FramelessWindow {
property FramelessWindow childWindow: FramelessWindow {
showWhenReady: false
}

FPSCounter {
property int maxVal: 0

id: fps
onValueChanged: fps.maxVal = Math.max(fps.value, fps.maxVal)
}

Text {
anchors {
bottom: buttonsRow.top
bottomMargin: 10
horizontalCenter: parent.horizontalCenter
}
font {
pixelSize: 25
bold: true
}
color: "green"
text: qsTr("FPS: ") + fps.value + qsTr(", Max: ") + fps.maxVal
}

Drawer {
id: drawer
width: 0.66 * parent.width
Expand All @@ -22,6 +44,7 @@ FramelessWindow {
}

Row {
id: buttonsRow
anchors {
horizontalCenter: parent.horizontalCenter
bottom: parent.bottom
Expand Down
40 changes: 23 additions & 17 deletions src/core/contexts/abstractwindowcontext_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,9 @@ namespace QWK {
bool isInSystemButtons(const QPoint &pos, WindowAgentBase::SystemButton *button) const;
bool isInTitleBarDraggableArea(const QPoint &pos) const;

inline bool isHostWidthFixed() const {
return m_windowHandle
? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
m_windowHandle->minimumWidth() == m_windowHandle->maximumWidth())
: false;
}
inline bool isHostHeightFixed() const {
return m_windowHandle
? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
m_windowHandle->minimumHeight() == m_windowHandle->maximumHeight())
: false;
}
inline bool isHostSizeFixed() const {
return m_windowHandle ? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
m_windowHandle->minimumSize() == m_windowHandle->maximumSize())
: false;
}
inline bool isHostWidthFixed() const;
inline bool isHostHeightFixed() const;
inline bool isHostSizeFixed() const;

virtual QString key() const;

Expand Down Expand Up @@ -167,6 +153,26 @@ namespace QWK {
}
#endif

inline bool AbstractWindowContext::isHostWidthFixed() const {
return m_windowHandle
? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
m_windowHandle->minimumWidth() == m_windowHandle->maximumWidth())
: false;
}

inline bool AbstractWindowContext::isHostHeightFixed() const {
return m_windowHandle
? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
m_windowHandle->minimumHeight() == m_windowHandle->maximumHeight())
: false;
}

inline bool AbstractWindowContext::isHostSizeFixed() const {
return m_windowHandle ? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
m_windowHandle->minimumSize() == m_windowHandle->maximumSize())
: false;
}

}

#endif // ABSTRACTWINDOWCONTEXT_P_H
3 changes: 1 addition & 2 deletions src/core/contexts/linuxwaylandcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace QWK {
seat, serial, x, y);
}

LinuxWaylandContext::LinuxWaylandContext() : QtWindowContext() {
}
LinuxWaylandContext::LinuxWaylandContext() = default;

LinuxWaylandContext::~LinuxWaylandContext() = default;

Expand Down
3 changes: 1 addition & 2 deletions src/core/contexts/linuxx11context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ union _XEvent {

namespace QWK {

LinuxX11Context::LinuxX11Context() : QtWindowContext() {
}
LinuxX11Context::LinuxX11Context() = default;

LinuxX11Context::~LinuxX11Context() = default;

Expand Down
Loading