diff --git a/autotests/mock_effectshandler.h b/autotests/mock_effectshandler.h index 00e7c56a5d..7c01b18792 100644 --- a/autotests/mock_effectshandler.h +++ b/autotests/mock_effectshandler.h @@ -255,7 +255,7 @@ public: Q_UNUSED(message) Q_UNUSED(iconName) } - void hideOnScreenMessage() override {} + void hideOnScreenMessage(OnScreenMessageHideFlags flags = OnScreenMessageHideFlags()) override { Q_UNUSED(flags)} private: bool m_animationsSuported = true; diff --git a/effects.cpp b/effects.cpp index f228fc4318..354b083d94 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1596,9 +1596,13 @@ void EffectsHandlerImpl::showOnScreenMessage(const QString &message, const QStri OSD::show(message, iconName); } -void EffectsHandlerImpl::hideOnScreenMessage() +void EffectsHandlerImpl::hideOnScreenMessage(OnScreenMessageHideFlags flags) { - OSD::hide(); + OSD::HideFlags osdFlags; + if (flags.testFlag(OnScreenMessageHideFlag::SkipsCloseAnimation)) { + osdFlags |= OSD::HideFlag::SkipCloseAnimation; + } + OSD::hide(osdFlags); } //**************************************** diff --git a/effects.h b/effects.h index c44a167d10..b1c96635ad 100644 --- a/effects.h +++ b/effects.h @@ -235,7 +235,7 @@ public: void startInteractivePositionSelection(std::function callback) override; void showOnScreenMessage(const QString &message, const QString &iconName = QString()) override; - void hideOnScreenMessage() override; + void hideOnScreenMessage(OnScreenMessageHideFlags flags = OnScreenMessageHideFlags()) override; Scene *scene() const { return m_scene; diff --git a/effects/screenshot/screenshot.cpp b/effects/screenshot/screenshot.cpp index 29dffe45c4..af1903eb76 100644 --- a/effects/screenshot/screenshot.cpp +++ b/effects/screenshot/screenshot.cpp @@ -91,10 +91,6 @@ void ScreenShotEffect::paintScreen(int mask, QRegion region, ScreenPaintData &da { m_cachedOutputGeometry = data.outputGeometry(); effects->paintScreen(mask, region, data); - - if (m_infoFrame) { - m_infoFrame->render(region); - } } void ScreenShotEffect::postPaintScreen() @@ -401,29 +397,21 @@ void ScreenShotEffect::interactive(QDBusUnixFileDescriptor fd, int mask) void ScreenShotEffect::showInfoMessage(InfoMessageMode mode) { - if (!m_infoFrame.isNull()) { - return; - } - m_infoFrame.reset(effects->effectFrame(EffectFrameStyled, false)); - QFont font; - font.setBold(true); - m_infoFrame->setFont(font); - QRect area = effects->clientArea(ScreenArea, effects->activeScreen(), effects->currentDesktop()); - m_infoFrame->setPosition(QPoint(area.x() + area.width() / 2, area.y() + area.height() / 3)); + QString text; switch (mode) { case InfoMessageMode::Window: - m_infoFrame->setText(i18n("Select window to screen shot with left click or enter.\nEscape or right click to cancel.")); + text = i18n("Select window to screen shot with left click or enter.\nEscape or right click to cancel."); break; case InfoMessageMode::Screen: - m_infoFrame->setText(i18n("Create screen shot with left click or enter.\nEscape or right click to cancel.")); + text = i18n("Create screen shot with left click or enter.\nEscape or right click to cancel."); break; } - effects->addRepaintFull(); + effects->showOnScreenMessage(text, QStringLiteral("spectacle")); } void ScreenShotEffect::hideInfoMessage() { - m_infoFrame.reset(); + effects->hideOnScreenMessage(EffectsHandler::OnScreenMessageHideFlag::SkipsCloseAnimation); } QString ScreenShotEffect::screenshotFullscreen(bool captureCursor) @@ -639,7 +627,7 @@ void ScreenShotEffect::convertFromGLImage(QImage &img, int w, int h) bool ScreenShotEffect::isActive() const { - return (m_scheduledScreenshot != NULL || !m_scheduledGeometry.isNull() || !m_infoFrame.isNull()) && !effects->isScreenLocked(); + return (m_scheduledScreenshot != NULL || !m_scheduledGeometry.isNull()) && !effects->isScreenLocked(); } void ScreenShotEffect::windowClosed( EffectWindow* w ) diff --git a/effects/screenshot/screenshot.h b/effects/screenshot/screenshot.h index ef0a10f5ea..7a9458a4ae 100644 --- a/effects/screenshot/screenshot.h +++ b/effects/screenshot/screenshot.h @@ -166,7 +166,6 @@ private: }; WindowMode m_windowMode = WindowMode::NoCapture; int m_fd = -1; - QScopedPointer m_infoFrame; }; } // namespace diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h index 9b50d4e27a..92f32a242c 100644 --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -1239,12 +1239,26 @@ public: **/ virtual void showOnScreenMessage(const QString &message, const QString &iconName = QString()) = 0; + /** + * Flags for how to hide a shown on-screen-message + * @see hideOnScreenMessage + * @since 5.9 + **/ + enum class OnScreenMessageHideFlag { + /** + * The on-screen-message should skip the close window animation. + * @see EffectWindow::skipsCloseAnimation + **/ + SkipsCloseAnimation = 1 + }; + Q_DECLARE_FLAGS(OnScreenMessageHideFlags, OnScreenMessageHideFlag) /** * Hides a previously shown on-screen-message again. + * @param flags The flags for how to hide the message * @see showOnScreenMessage * @since 5.9 **/ - virtual void hideOnScreenMessage() = 0; + virtual void hideOnScreenMessage(OnScreenMessageHideFlags flags = OnScreenMessageHideFlags()) = 0; Q_SIGNALS: /** diff --git a/onscreennotification.cpp b/onscreennotification.cpp index b32349e7a0..98adb00735 100644 --- a/onscreennotification.cpp +++ b/onscreennotification.cpp @@ -236,4 +236,11 @@ void OnScreenNotification::setContainsPointer(bool contains) m_animation->start(); } +void OnScreenNotification::setSkipCloseAnimation(bool skip) +{ + if (QQuickWindow *w = qobject_cast(m_mainItem.data())) { + w->setProperty("KWIN_SKIP_CLOSE_ANIMATION", skip); + } +} + #include "onscreennotification.moc" diff --git a/onscreennotification.h b/onscreennotification.h index 0c916122b8..92fddd0686 100644 --- a/onscreennotification.h +++ b/onscreennotification.h @@ -63,6 +63,7 @@ public: void setEngine(QQmlEngine *engine); void setContainsPointer(bool contains); + void setSkipCloseAnimation(bool skip); Q_SIGNALS: void visibleChanged(); diff --git a/osd.cpp b/osd.cpp index 8d2ec307c1..601b8607e4 100644 --- a/osd.cpp +++ b/osd.cpp @@ -68,12 +68,13 @@ void show(const QString &message, const QString &iconName) show(message, iconName, 0); } -void hide() +void hide(HideFlags flags) { if (!kwinApp()->shouldUseWaylandForCompositing()) { // FIXME: only supported on Wayland return; } + osd()->setSkipCloseAnimation(flags.testFlag(HideFlag::SkipCloseAnimation)); osd()->setVisible(false); } diff --git a/osd.h b/osd.h index 234ca65c5c..9e4582295f 100644 --- a/osd.h +++ b/osd.h @@ -22,6 +22,7 @@ #ifndef KWIN_OSD_H #define KWIN_OSD_H +#include #include namespace KWin @@ -32,7 +33,11 @@ namespace OSD void show(const QString &message, const QString &iconName = QString()); void show(const QString &message, int timeout); void show(const QString &message, const QString &iconName, int timeout); -void hide(); +enum class HideFlag { + SkipCloseAnimation = 1 +}; +Q_DECLARE_FLAGS(HideFlags, HideFlag) +void hide(HideFlags flags = HideFlags()); } }