diff --git a/src/effect/effecthandler.cpp b/src/effect/effecthandler.cpp index 6c942e7b65..66f3a290a2 100644 --- a/src/effect/effecthandler.cpp +++ b/src/effect/effecthandler.cpp @@ -432,6 +432,11 @@ bool EffectsHandler::hasActiveFullScreenEffect() const return fullscreen_effect; } +bool EffectsHandler::isColorPickerActive() const +{ + return isEffectActive(QStringLiteral("colorpicker")); +} + bool EffectsHandler::grabKeyboard(Effect *effect) { if (keyboard_grab_effect != nullptr) { diff --git a/src/effect/effecthandler.h b/src/effect/effecthandler.h index 6ad2cf31f5..20774b3343 100644 --- a/src/effect/effecthandler.h +++ b/src/effect/effecthandler.h @@ -146,6 +146,7 @@ class KWIN_EXPORT EffectsHandler : public QObject Q_PROPERTY(QSize virtualScreenSize READ virtualScreenSize NOTIFY virtualScreenSizeChanged) Q_PROPERTY(QRect virtualScreenGeometry READ virtualScreenGeometry NOTIFY virtualScreenGeometryChanged) Q_PROPERTY(bool hasActiveFullScreenEffect READ hasActiveFullScreenEffect NOTIFY hasActiveFullScreenEffectChanged) + Q_PROPERTY(bool colorPickerActive READ isColorPickerActive NOTIFY colorPickerActiveChanged) /** * The status of the session i.e if the user is logging out @@ -699,10 +700,15 @@ public: KSharedConfigPtr inputConfig() const; /** - * Returns if activeFullScreenEffect is set + * Returns true if activeFullScreenEffect is set */ bool hasActiveFullScreenEffect() const; + /** + * Returns true if color picker effect is currently picking colors. + */ + bool isColorPickerActive() const; + /** * Render the supplied OffscreenQuickView onto the scene * It can be called at any point during the scene rendering @@ -1032,6 +1038,8 @@ Q_SIGNALS: */ void hasActiveFullScreenEffectChanged(); + void colorPickerActiveChanged(); + /** * This signal is emitted when the session state was changed * @since 5.18 diff --git a/src/plugins/colorpicker/colorpicker.cpp b/src/plugins/colorpicker/colorpicker.cpp index bc5a36cc52..bc61ebb6d8 100644 --- a/src/plugins/colorpicker/colorpicker.cpp +++ b/src/plugins/colorpicker/colorpicker.cpp @@ -51,7 +51,10 @@ ColorPickerEffect::ColorPickerEffect() QDBusConnection::sessionBus().registerObject(QStringLiteral("/ColorPicker"), this, QDBusConnection::ExportScriptableContents); } -ColorPickerEffect::~ColorPickerEffect() = default; +ColorPickerEffect::~ColorPickerEffect() +{ + setPicking(false); +} void ColorPickerEffect::paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen) { @@ -67,7 +70,7 @@ void ColorPickerEffect::paintScreen(const RenderTarget &renderTarget, const Rend glReadPixels(texturePosition.x(), renderTarget.size().height() - texturePosition.y() - PIXEL_SIZE, PIXEL_SIZE, PIXEL_SIZE, GL_RGBA, GL_FLOAT, data.data()); QVector3D sRGB = 255 * renderTarget.colorDescription().mapTo(QVector3D(data[0], data[1], data[2]), sRGBencoding); QDBusConnection::sessionBus().send(m_replyMessage.createReply(QColor(sRGB.x(), sRGB.y(), sRGB.z()))); - m_picking = false; + setPicking(false); m_scheduledPosition = QPoint(-1, -1); } } @@ -81,7 +84,7 @@ QColor ColorPickerEffect::pick() sendErrorReply(QDBusError::Failed, "Color picking is already in progress"); return QColor(); } - m_picking = true; + setPicking(true); m_replyMessage = message(); setDelayedReply(true); showInfoMessage(); @@ -91,7 +94,7 @@ QColor ColorPickerEffect::pick() if (p == QPointF(-1, -1)) { // error condition QDBusConnection::sessionBus().send(m_replyMessage.createErrorReply(QStringLiteral("org.kde.kwin.ColorPicker.Error.Cancelled"), "Color picking got cancelled")); - m_picking = false; + setPicking(false); } else { m_scheduledPosition = p; effects->addRepaintFull(); @@ -110,9 +113,17 @@ void ColorPickerEffect::hideInfoMessage() effects->hideOnScreenMessage(); } +void ColorPickerEffect::setPicking(bool picking) +{ + if (m_picking != picking) { + m_picking = picking; + Q_EMIT effects->colorPickerActiveChanged(); + } +} + bool ColorPickerEffect::isActive() const { - return m_picking && ((m_scheduledPosition != QPoint(-1, -1))) && !effects->isScreenLocked(); + return m_picking && !effects->isScreenLocked(); } } // namespace diff --git a/src/plugins/colorpicker/colorpicker.h b/src/plugins/colorpicker/colorpicker.h index 648c9ee46d..b6bef8d7f9 100644 --- a/src/plugins/colorpicker/colorpicker.h +++ b/src/plugins/colorpicker/colorpicker.h @@ -41,6 +41,7 @@ public Q_SLOTS: private: void showInfoMessage(); void hideInfoMessage(); + void setPicking(bool picking); QDBusMessage m_replyMessage; QPointF m_scheduledPosition; diff --git a/src/plugins/dialogparent/package/contents/code/main.js b/src/plugins/dialogparent/package/contents/code/main.js index 6402815f24..b6d20bd280 100644 --- a/src/plugins/dialogparent/package/contents/code/main.js +++ b/src/plugins/dialogparent/package/contents/code/main.js @@ -20,7 +20,7 @@ var dialogParentEffect = { dialogParentEffect.restartAnimation(window); } }); - window.windowModalityChanged.connect(dialogParentEffect.modalDialogChanged); + window.windowModalityChanged.connect(dialogParentEffect.windowModalityChanged); window.windowDesktopsChanged.connect(dialogParentEffect.cancelAnimationInstant); window.windowDesktopsChanged.connect(dialogParentEffect.restartAnimation); @@ -97,23 +97,19 @@ var dialogParentEffect = { // effect has to come after the full screen effect in the effect chain, // otherwise this slot will be invoked before the full screen effect can mark // itself as a full screen effect. - if (effects.hasActiveFullScreenEffect) { + if (dialogParentEffect.globallyInhibited()) { return; } - var windows = effects.stackingOrder; - for (var i = 0; i < windows.length; ++i) { - var window = windows[i]; + const windows = effects.stackingOrder; + for (const window of windows) { dialogParentEffect.cancelAnimationInstant(window); dialogParentEffect.restartAnimation(window); } }, - modalDialogChanged: function(dialog) { + windowModalityChanged: function (window) { "use strict"; - if (dialog.modal === false) - dialogParentEffect.dialogLostModality(dialog); - else if (dialog.modal === true) - dialogParentEffect.dialogGotModality(dialog); + dialogParentEffect.refreshWindowEffect(window); }, restartAnimation: function (window) { "use strict"; @@ -125,19 +121,21 @@ var dialogParentEffect = { complete(window.dialogParentAnimation); } }, - activeFullScreenEffectChanged: function () { + activeFullScreenOrColorPickerChanged: function () { "use strict"; - var windows = effects.stackingOrder; - for (var i = 0; i < windows.length; ++i) { - var dialog = windows[i]; - if (!dialog.modal) { - continue; - } - if (effects.hasActiveFullScreenEffect) { - dialogParentEffect.dialogLostModality(dialog); - } else { - dialogParentEffect.dialogGotModality(dialog); - } + const windows = effects.stackingOrder; + for (const window of windows) { + dialogParentEffect.refreshWindowEffect(window); + } + }, + globallyInhibited: function () { + return effects.hasActiveFullScreenEffect || effects.colorPickerActive; + }, + refreshWindowEffect: function (window) { + if (dialogParentEffect.globallyInhibited() || !window.modal) { + dialogParentEffect.dialogLostModality(window); + } else { + dialogParentEffect.dialogGotModality(window); } }, init: function () { @@ -147,7 +145,9 @@ var dialogParentEffect = { effects.windowClosed.connect(dialogParentEffect.windowClosed); effects.desktopChanged.connect(dialogParentEffect.desktopChanged); effects.activeFullScreenEffectChanged.connect( - dialogParentEffect.activeFullScreenEffectChanged); + dialogParentEffect.activeFullScreenOrColorPickerChanged); + effects.colorPickerActiveChanged.connect( + dialogParentEffect.activeFullScreenOrColorPickerChanged); windows = effects.stackingOrder; for (i = 0; i < windows.length; i += 1) {