diff options
author | Yuhang Zhao <2546789017@qq.com> | 2020-11-27 16:30:41 +0800 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2020-11-30 15:17:55 +0800 |
commit | 18bee52fe48500bca46de7e47d134940c48b524c (patch) | |
tree | ced76f72ab518b588adbb7f10d7cfc442e69cda0 | |
parent | d74d3191f93cac78aec4da072fdf68fe0ecdb040 (diff) |
Remove deprecated functions
According to Microsoft's documentation, DwmIsCompositionEnabled()
will always return true since Windows 8 [1].
And the DWM composition can't be disabled programmatically since
Windows 8 as well [2].
Since Qt 6 will only support Windows 10, it's apparently these two
functions and their usages are totally useless.
[1] https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmiscompositionenabled
[2] https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmenablecomposition
Change-Id: Ia4040118b719fa8edd8504f9112fbe7e3844e0fa
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
19 files changed, 18 insertions, 195 deletions
diff --git a/examples/winextras/musicplayer/doc/images/qtwinextras-musicplayer-non-composited.png b/examples/winextras/musicplayer/doc/images/qtwinextras-musicplayer-non-composited.png Binary files differdeleted file mode 100644 index e0a6afe..0000000 --- a/examples/winextras/musicplayer/doc/images/qtwinextras-musicplayer-non-composited.png +++ /dev/null diff --git a/examples/winextras/musicplayer/doc/src/qtwinextras-musicplayer.qdoc b/examples/winextras/musicplayer/doc/src/qtwinextras-musicplayer.qdoc index 8b8fd57..c27ec0f 100644 --- a/examples/winextras/musicplayer/doc/src/qtwinextras-musicplayer.qdoc +++ b/examples/winextras/musicplayer/doc/src/qtwinextras-musicplayer.qdoc @@ -47,38 +47,6 @@ integrate the window content to the window frame and to make the main window and the volume popup translucent and blurred. - The example applies a different look based on whether composition is enabled - or not. When composition is enabled, the main window is made translucent and - the window frame is extended to the client area to make the window content - integrate seamlessly to the window frame as shown above. When composition - is disabled, the colorization color is used as a background color. The - following screenshot illustrates how the Music Player example looks when - composition is disabled. - - \image qtwinextras-musicplayer-non-composited.png Screenshot of the Music Player example - - The respective code is a combination of extending or resetting the system - frame, adjusting the necessary QWidget attributes, and setting an appropriate - style sheet to achieve the desired look. - - \snippet musicplayer/musicplayer.cpp 1 - - The volume popup does not have a window frame so it is enough to make the - popup blurred when composition is enabled. Additionally, a style sheet is - applied to get a border that follows the colorization color. Just like for - the main window, when composition is disabled, the colorization color is - used as a background color. - - \snippet musicplayer/volumebutton.cpp 0 - - The example application respects the user's composition settings, reacts - to dynamic composition changes, and looks solid regardless of whether - composition is enabled or not. It accomplishes this by catching - QWinEvent::CompositionChange and QWinEvent::ColorizationChange events - and adjusting its looks accordingly. - - \snippet musicplayer/musicplayer.cpp 0 - \section1 Jump List The example creates a custom jump list to provide the user with fast diff --git a/examples/winextras/musicplayer/musicplayer.cpp b/examples/winextras/musicplayer/musicplayer.cpp index 4a598d8..0f335d2 100644 --- a/examples/winextras/musicplayer/musicplayer.cpp +++ b/examples/winextras/musicplayer/musicplayer.cpp @@ -71,7 +71,6 @@ MusicPlayer::MusicPlayer(QWidget *parent) : QWidget(parent) connect(&mediaPlayer, &QMediaPlayer::stateChanged, this, &MusicPlayer::updateState); - stylize(); setAcceptDrops(true); } @@ -131,15 +130,6 @@ void MusicPlayer::seekBackward() positionSlider->triggerAction(QSlider::SliderPageStepSub); } -//! [0] -bool MusicPlayer::event(QEvent *event) -{ - if (event->type() == QWinEvent::CompositionChange || event->type() == QWinEvent::ColorizationChange) - stylize(); - return QWidget::event(event); -} -//! [0] - //! [7] void MusicPlayer::showEvent(QShowEvent *event) { @@ -191,26 +181,6 @@ void MusicPlayer::mouseReleaseEvent(QMouseEvent *event) event->accept(); } -//! [1] -void MusicPlayer::stylize() -{ - if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows8) { - // Set styling options relevant only to Windows 7. - if (QtWin::isCompositionEnabled()) { - QtWin::extendFrameIntoClientArea(this, -1, -1, -1, -1); - setAttribute(Qt::WA_TranslucentBackground, true); - setAttribute(Qt::WA_NoSystemBackground, false); - setStyleSheet(QStringLiteral("MusicPlayer { background: transparent; }")); - } else { - QtWin::resetExtendedFrame(this); - setAttribute(Qt::WA_TranslucentBackground, false); - setStyleSheet(QStringLiteral("MusicPlayer { background: %1; }").arg(QtWin::realColorizationColor().name())); - } - volumeButton->stylize(); - } -} -//! [1] - void MusicPlayer::updateState(QMediaPlayer::State state) { if (state == QMediaPlayer::PlayingState) { diff --git a/examples/winextras/musicplayer/musicplayer.h b/examples/winextras/musicplayer/musicplayer.h index 49dd25b..58ea8c9 100644 --- a/examples/winextras/musicplayer/musicplayer.h +++ b/examples/winextras/musicplayer/musicplayer.h @@ -81,7 +81,6 @@ public slots: void seekBackward(); protected: - bool event(QEvent *event) override; void showEvent(QShowEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override; @@ -90,7 +89,6 @@ protected: void mouseReleaseEvent(QMouseEvent *event) override; private slots: - void stylize(); void updateState(QMediaPlayer::State state); void updatePosition(qint64 position); void updateDuration(qint64 duration); diff --git a/examples/winextras/musicplayer/volumebutton.cpp b/examples/winextras/musicplayer/volumebutton.cpp index 908dba1..9a8cc44 100644 --- a/examples/winextras/musicplayer/volumebutton.cpp +++ b/examples/winextras/musicplayer/volumebutton.cpp @@ -83,8 +83,6 @@ VolumeButton::VolumeButton(QWidget *parent) : menu = new QMenu(this); menu->addAction(action); setMenu(menu); - - stylize(); } void VolumeButton::increaseVolume() @@ -106,21 +104,3 @@ void VolumeButton::setVolume(int volume) { slider->setValue(volume); } - -//! [0] -void VolumeButton::stylize() -{ - if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows8) { - // Set styling options relevant only to Windows 7. - if (QtWin::isCompositionEnabled()) { - QtWin::enableBlurBehindWindow(menu); - QString css("QMenu { border: 1px solid %1; border-radius: 2px; background: transparent; }"); - menu->setStyleSheet(css.arg(QtWin::realColorizationColor().name())); - } else { - QtWin::disableBlurBehindWindow(menu); - QString css("QMenu { border: 1px solid black; background: %1; }"); - menu->setStyleSheet(css.arg(QtWin::realColorizationColor().name())); - } - } -} -//! [0] diff --git a/examples/winextras/musicplayer/volumebutton.h b/examples/winextras/musicplayer/volumebutton.h index c6673d2..cb193dc 100644 --- a/examples/winextras/musicplayer/volumebutton.h +++ b/examples/winextras/musicplayer/volumebutton.h @@ -71,7 +71,6 @@ public slots: void increaseVolume(); void descreaseVolume(); void setVolume(int volume); - void stylize(); signals: void volumeChanged(int volume); diff --git a/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-non-composited.png b/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-non-composited.png Binary files differdeleted file mode 100644 index 23fdc56..0000000 --- a/examples/winextras/quickplayer/doc/images/qtwinextras-quickplayer-non-composited.png +++ /dev/null diff --git a/examples/winextras/quickplayer/doc/src/qtwinextras-quickplayer.qdoc b/examples/winextras/quickplayer/doc/src/qtwinextras-quickplayer.qdoc index 02fe61c..1492865 100644 --- a/examples/winextras/quickplayer/doc/src/qtwinextras-quickplayer.qdoc +++ b/examples/winextras/quickplayer/doc/src/qtwinextras-quickplayer.qdoc @@ -44,23 +44,8 @@ integrate the window content to the window frame and to make the window translucent and blurred. - The example applies a different look based on whether composition is enabled - or not. When composition is enabled, the window is made translucent and - the window frame is extended to the client area to make the window content - integrate seamlessly to the window frame as shown above. - \snippet quickplayer/qml/main.qml dwm - When composition is disabled, the colorization color is used as a background - color for the window. - - \snippet quickplayer/qml/main.qml color - - The following screenshot illustrates how the Quick Player example looks when - composition is disabled. - - \image qtwinextras-quickplayer-non-composited.png Screenshot of the Quick Player example - \section1 Taskbar Overlay and Progress The example uses Windows Taskbar for two things; it sets an overlay icon diff --git a/examples/winextras/quickplayer/qml/main.qml b/examples/winextras/quickplayer/qml/main.qml index ec059e3..ec309a5 100644 --- a/examples/winextras/quickplayer/qml/main.qml +++ b/examples/winextras/quickplayer/qml/main.qml @@ -67,7 +67,7 @@ Window { minimumHeight: column.implicitHeight + 18 //! [color] - color: dwm.compositionEnabled ? "transparent" : dwm.realColorizationColor + color: "transparent" //! [color] //! [dwm] diff --git a/src/imports/winextras/plugins.qmltypes b/src/imports/winextras/plugins.qmltypes index fff1181..a23a7b1 100644 --- a/src/imports/winextras/plugins.qmltypes +++ b/src/imports/winextras/plugins.qmltypes @@ -14,7 +14,6 @@ Module { prototype: "QQuickItem" exports: ["QtWinExtras/DwmFeatures 1.0"] exportMetaObjectRevisions: [0] - Property { name: "compositionEnabled"; type: "bool" } Property { name: "colorizationColor"; type: "QColor"; isReadonly: true } Property { name: "realColorizationColor"; type: "QColor"; isReadonly: true } Property { name: "colorizationOpaqueBlend"; type: "bool"; isReadonly: true } diff --git a/src/imports/winextras/qquickdwmfeatures.cpp b/src/imports/winextras/qquickdwmfeatures.cpp index 124d957..7baf536 100644 --- a/src/imports/winextras/qquickdwmfeatures.cpp +++ b/src/imports/winextras/qquickdwmfeatures.cpp @@ -73,16 +73,6 @@ QQuickDwmFeatures::QQuickDwmFeatures(QQuickItem *parent) : QQuickDwmFeatures::~QQuickDwmFeatures() = default; -void QQuickDwmFeatures::setCompositionEnabled(bool enabled) -{ - QtWin::setCompositionEnabled(enabled); -} - -bool QQuickDwmFeatures::isCompositionEnabled() const -{ - return QtWin::isCompositionEnabled(); -} - QColor QQuickDwmFeatures::colorizationColor() const { return QtWin::colorizationColor(); @@ -325,9 +315,7 @@ bool QQuickDwmFeatures::eventFilter(QObject *object, QEvent *event) if (object == window()) { if (event->type() == QWinEvent::CompositionChange) { d->updateSurfaceFormat(); - if (static_cast<QWinCompositionChangeEvent *>(event)->isCompositionEnabled()) - d->updateAll(); - emit compositionEnabledChanged(); + d->updateAll(); } else if (event->type() == QWinEvent::ColorizationChange) { emit colorizationColorChanged(); emit realColorizationColorChanged(); @@ -388,11 +376,10 @@ void QQuickDwmFeaturesPrivate::updateSurfaceFormat() { Q_Q(QQuickDwmFeatures); if (q->window()) { - const bool compositionEnabled = q->isCompositionEnabled(); QSurfaceFormat format = q->window()->format(); - format.setAlphaBufferSize(compositionEnabled ? 8 : 0); + format.setAlphaBufferSize(8); q->window()->setFormat(format); - q->window()->setColor(compositionEnabled ? QColor(Qt::transparent) : originalSurfaceColor); + q->window()->setColor(Qt::transparent); } } diff --git a/src/imports/winextras/qquickdwmfeatures_p.h b/src/imports/winextras/qquickdwmfeatures_p.h index 3887d24..c420659 100644 --- a/src/imports/winextras/qquickdwmfeatures_p.h +++ b/src/imports/winextras/qquickdwmfeatures_p.h @@ -65,7 +65,6 @@ class QQuickDwmFeaturesPrivate; class QQuickDwmFeatures : public QQuickItem { Q_OBJECT - Q_PROPERTY(bool compositionEnabled READ isCompositionEnabled WRITE setCompositionEnabled NOTIFY compositionEnabledChanged) Q_PROPERTY(QColor colorizationColor READ colorizationColor NOTIFY colorizationColorChanged) Q_PROPERTY(QColor realColorizationColor READ realColorizationColor NOTIFY realColorizationColorChanged) Q_PROPERTY(bool colorizationOpaqueBlend READ colorizationOpaqueBlend NOTIFY colorizationOpaqueBlendChanged) @@ -83,8 +82,6 @@ public: explicit QQuickDwmFeatures(QQuickItem *parent = nullptr); ~QQuickDwmFeatures(); - void setCompositionEnabled(bool enabled); - bool isCompositionEnabled() const; QColor colorizationColor() const; QColor realColorizationColor() const; bool colorizationOpaqueBlend() const; @@ -116,7 +113,6 @@ public: Q_SIGNALS: void colorizationColorChanged(); void realColorizationColorChanged(); - void compositionEnabledChanged(); void colorizationOpaqueBlendChanged(); void topGlassMarginChanged(); void rightGlassMarginChanged(); diff --git a/src/winextras/qwinevent.cpp b/src/winextras/qwinevent.cpp index a1e77b4..6d5dbcb 100644 --- a/src/winextras/qwinevent.cpp +++ b/src/winextras/qwinevent.cpp @@ -58,8 +58,8 @@ QWinColorizationChangeEvent::QWinColorizationChangeEvent(QRgb color, bool opaque QWinColorizationChangeEvent::~QWinColorizationChangeEvent() = default; -QWinCompositionChangeEvent::QWinCompositionChangeEvent(bool enabled) - : QWinEvent(CompositionChange), enabled(enabled) +QWinCompositionChangeEvent::QWinCompositionChangeEvent() + : QWinEvent(CompositionChange) { } diff --git a/src/winextras/qwinevent.h b/src/winextras/qwinevent.h index ad77eb3..f4212fd 100644 --- a/src/winextras/qwinevent.h +++ b/src/winextras/qwinevent.h @@ -76,13 +76,8 @@ private: class Q_WINEXTRAS_EXPORT QWinCompositionChangeEvent : public QWinEvent { public: - explicit QWinCompositionChangeEvent(bool enabled); + explicit QWinCompositionChangeEvent(); ~QWinCompositionChangeEvent(); - - inline bool isCompositionEnabled() const { return enabled; } - -private: - bool enabled; }; QT_END_NAMESPACE diff --git a/src/winextras/qwineventfilter.cpp b/src/winextras/qwineventfilter.cpp index 4b88f54..db264b6 100644 --- a/src/winextras/qwineventfilter.cpp +++ b/src/winextras/qwineventfilter.cpp @@ -79,7 +79,7 @@ bool QWinEventFilter::nativeEventFilter(const QByteArray &, void *message, long event = new QWinColorizationChangeEvent(QRgb(msg->wParam), msg->lParam); break; case WM_DWMCOMPOSITIONCHANGED : - event = new QWinCompositionChangeEvent(QtWin::isCompositionEnabled()); + event = new QWinCompositionChangeEvent(); break; case WM_THEMECHANGED : event = new QWinEvent(QWinEvent::ThemeChange); diff --git a/src/winextras/qwinfunctions.cpp b/src/winextras/qwinfunctions.cpp index b0e0ff4..77e5733 100644 --- a/src/winextras/qwinfunctions.cpp +++ b/src/winextras/qwinfunctions.cpp @@ -1835,40 +1835,6 @@ void QtWin::disableBlurBehindWindow(QWindow *window) /*! \since 5.2 - Returns the DWM composition state. - */ -bool QtWin::isCompositionEnabled() -{ - QWinEventFilter::setup(); - - BOOL enabled = FALSE; - DwmIsCompositionEnabled(&enabled); - return enabled; -} - -/*! - \since 5.2 - - Sets whether the Windows Desktop composition is \a enabled. - - \note The underlying function was declared deprecated as of Windows 8 and - takes no effect. - */ - -QT_WARNING_PUSH -QT_WARNING_DISABLE_MSVC(4995) -void QtWin::setCompositionEnabled(bool enabled) -{ - QWinEventFilter::setup(); - - UINT compositionEnabled = enabled; - DwmEnableComposition(compositionEnabled); -} -QT_WARNING_POP - -/*! - \since 5.2 - Returns whether the colorization color is an opaque blend. */ bool QtWin::isCompositionOpaque() diff --git a/src/winextras/qwinfunctions.h b/src/winextras/qwinfunctions.h index 8f27a6f..dd17cef 100644 --- a/src/winextras/qwinfunctions.h +++ b/src/winextras/qwinfunctions.h @@ -118,8 +118,6 @@ namespace QtWin Q_WINEXTRAS_EXPORT void enableBlurBehindWindow(QWindow *window); Q_WINEXTRAS_EXPORT void disableBlurBehindWindow(QWindow *window); - Q_WINEXTRAS_EXPORT bool isCompositionEnabled(); - Q_WINEXTRAS_EXPORT void setCompositionEnabled(bool enabled); Q_WINEXTRAS_EXPORT bool isCompositionOpaque(); Q_WINEXTRAS_EXPORT void setCurrentProcessExplicitAppUserModelID(const QString &id); diff --git a/tests/manual/dwmfeatures/testwidget.cpp b/tests/manual/dwmfeatures/testwidget.cpp index e289946..189a44c 100644 --- a/tests/manual/dwmfeatures/testwidget.cpp +++ b/tests/manual/dwmfeatures/testwidget.cpp @@ -79,8 +79,7 @@ void TestWidget::changeEvent(QEvent *e) bool TestWidget::event(QEvent *e) { if (e->type() == QWinEvent::CompositionChange) { - auto *event = static_cast<QWinCompositionChangeEvent *>(e); - qDebug() << "Composition state change: " << event->isCompositionEnabled(); + qDebug() << "Composition state change."; } else if (e->type() == QWinEvent::ThemeChange) { qDebug() << "Theme change."; } @@ -123,9 +122,6 @@ void TestWidget::onNonClientAreaRenderingPolicyChanged() void TestWidget::onGlassMarginsChanged() { - if (!QtWin::isCompositionEnabled()) - return; - // what you see here is the only way to force widget to redraw itself // so it actually redraws itself without caching and without any glitch // but causes flickering :( diff --git a/tests/manual/quickdwmfeatures/main.qml b/tests/manual/quickdwmfeatures/main.qml index 3448a1f..0d32c98 100644 --- a/tests/manual/quickdwmfeatures/main.qml +++ b/tests/manual/quickdwmfeatures/main.qml @@ -48,21 +48,16 @@ Window { excludedFromPeek: cbExcludedFromPeek.checked peekDisallowed: cbPeekDisallowed.checked - - Component.onCompleted: { - cbCompositionEnabled.checked = compositionEnabled - compositionEnabled = Qt.binding(function () { return cbCompositionEnabled.checked }) - } } Rectangle { anchors.fill: parent - anchors.leftMargin: dwm.compositionEnabled ? dwm.leftGlassMargin : 0 - anchors.rightMargin: dwm.compositionEnabled ? dwm.rightGlassMargin : 0 - anchors.topMargin: dwm.compositionEnabled ? dwm.topGlassMargin : 0 - anchors.bottomMargin: dwm.compositionEnabled ? dwm.bottomGlassMargin : 0 + anchors.leftMargin: dwm.leftGlassMargin + anchors.rightMargin: dwm.rightGlassMargin + anchors.topMargin: dwm.topGlassMargin + anchors.bottomMargin: dwm.bottomGlassMargin - visible: !dwm.compositionEnabled || dwm.topGlassMargin > -1 && dwm.leftGlassMargin > -1 && dwm.rightGlassMargin > -1 && dwm.bottomGlassMargin > -1 && !cbBlurBehind.checked + visible: dwm.topGlassMargin > -1 && dwm.leftGlassMargin > -1 && dwm.rightGlassMargin > -1 && dwm.bottomGlassMargin > -1 && !cbBlurBehind.checked } GridLayout { @@ -71,39 +66,30 @@ Window { columns: 2 CheckBox { - id: cbCompositionEnabled - text: "Composition enabled" - Layout.columnSpan: 2 - } - - CheckBox { id: cbBlurBehind text: "Blur behind enabled" Layout.columnSpan: 2 - enabled: cbCompositionEnabled.checked } Label { text: "Top glass frame margin" } - SpinBox { id: sboxTop; minimumValue: -1; maximumValue: 40; value: 0; Layout.alignment: Qt.AlignRight; enabled: cbCompositionEnabled.checked } + SpinBox { id: sboxTop; minimumValue: -1; maximumValue: 40; value: 0; Layout.alignment: Qt.AlignRight } Label { text: "Right glass frame margin" } - SpinBox { id: sboxRight; minimumValue: -1; maximumValue: 40; value: 0; Layout.alignment: Qt.AlignRight; enabled: cbCompositionEnabled.checked } + SpinBox { id: sboxRight; minimumValue: -1; maximumValue: 40; value: 0; Layout.alignment: Qt.AlignRight } Label { text: "Bottom glass frame margin" } - SpinBox { id: sboxBottom; minimumValue: -1; maximumValue: 40; value: 0; Layout.alignment: Qt.AlignRight; enabled: cbCompositionEnabled.checked } + SpinBox { id: sboxBottom; minimumValue: -1; maximumValue: 40; value: 0; Layout.alignment: Qt.AlignRight } Label { text: "Left glass frame margin" } - SpinBox { id: sboxLeft; minimumValue: -1; maximumValue: 40; value: 0; Layout.alignment: Qt.AlignRight; enabled: cbCompositionEnabled.checked } + SpinBox { id: sboxLeft; minimumValue: -1; maximumValue: 40; value: 0; Layout.alignment: Qt.AlignRight } CheckBox { id: cbExcludedFromPeek text: "Excluded from peek" Layout.columnSpan: 2 - enabled: cbCompositionEnabled.checked } CheckBox { id: cbPeekDisallowed text: "Peek disallowed" Layout.columnSpan: 2 - enabled: cbCompositionEnabled.checked } Rectangle { |