Use translucent/dialogs/background elements where possible

In effects it's obvious that compositing is enabled, so specifying the
translucent element is no problem.

In tabbox a context property "compositing" is injected which decides
whether "translucent" or "opaque" elements should be used. Here the
translucent elements are only used if the Blur effect is available - for
this a new Effect::Feature Blur is introduced and in addition it is
tested whether the theme provides the translucent element.

Also the masking is adjusted to ensure that only the shadow is not
blurred.

Reason for this change is that Plasma theme seems not always to pick up
whether compositing is used when used from inside KWin. It does not cover
the Desktop Change OSD which uses PlasmaCore.Dialog and there we cannot
(yet) inject that we use compositing.

Overall I'm quite unhappy with this patch and I do hope we can fix it in
the proper place in the lifetime of 4.10 and revert this patch.

CCBUG: 311995
REVIEW: 108438
This commit is contained in:
Martin Gräßlin 2013-01-16 14:50:43 +01:00
parent e128d5ad26
commit 0c92e1f30c
15 changed files with 71 additions and 30 deletions

View file

@ -55,6 +55,7 @@ public:
bool isCacheTexture() const {
return m_shouldCache;
}
virtual bool provides(Feature feature);
public Q_SLOTS:
void slotWindowAdded(KWin::EffectWindow *w);
@ -94,6 +95,16 @@ private:
typedef QHash<const EffectWindow*, BlurWindowInfo>::iterator CacheEntry;
};
inline
bool BlurEffect::provides(Effect::Feature feature)
{
if (feature == Blur) {
return true;
}
return KWin::Effect::provides(feature);
}
} // namespace KWin
#endif

View file

@ -41,6 +41,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QtGui/QVector2D>
#include <Plasma/FrameSvg>
#include <Plasma/PushButton>
#include <Plasma/Theme>
#include <Plasma/WindowEffects>
namespace KWin
@ -1418,7 +1419,11 @@ DesktopButtonsView::DesktopButtonsView(QWidget* parent)
scene->addItem(form);
m_frame = new Plasma::FrameSvg(this);
m_frame->setImagePath("dialogs/background");
if (Plasma::Theme::defaultTheme()->currentThemeHasImage("translucent/dialogs/background")) {
m_frame->setImagePath("translucent/dialogs/background");
} else {
m_frame->setImagePath("dialogs/background");
}
m_frame->setCacheAllRenderedFrames(true);
m_frame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
qreal left, top, right, bottom;
@ -1427,7 +1432,6 @@ DesktopButtonsView::DesktopButtonsView(QWidget* parent)
qreal height = form->size().height() + top + bottom;
m_frame->resizeFrame(QSizeF(width, height));
Plasma::WindowEffects::enableBlurBehind(winId(), true, m_frame->mask());
Plasma::WindowEffects::overrideShadow(winId(), true);
form->setPos(left, top);
scene->setSceneRect(QRectF(QPointF(0, 0), QSizeF(width, height)));
setScene(scene);

View file

@ -35,6 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QtGui/QGraphicsLinearLayout>
#include <Plasma/FrameSvg>
#include <Plasma/PushButton>
#include <Plasma/Theme>
#include <Plasma/WindowEffects>
#include <netwm_def.h>
@ -1961,7 +1962,11 @@ CloseWindowView::CloseWindowView(QWidget* parent)
scene->addItem(form);
m_frame = new Plasma::FrameSvg(this);
m_frame->setImagePath("dialogs/background");
if (Plasma::Theme::defaultTheme()->currentThemeHasImage("translucent/dialogs/background")) {
m_frame->setImagePath("translucent/dialogs/background");
} else {
m_frame->setImagePath("dialogs/background");
}
m_frame->setCacheAllRenderedFrames(true);
m_frame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
qreal left, top, right, bottom;
@ -1970,7 +1975,6 @@ CloseWindowView::CloseWindowView(QWidget* parent)
qreal height = form->size().height() + top + bottom;
m_frame->resizeFrame(QSizeF(width, height));
Plasma::WindowEffects::enableBlurBehind(winId(), true, m_frame->mask());
Plasma::WindowEffects::overrideShadow(winId(), true);
form->setPos(left, top);
scene->setSceneRect(QRectF(QPointF(0, 0), QSizeF(width, height)));
setScene(scene);

View file

@ -324,7 +324,7 @@ public:
};
enum Feature {
Nothing = 0, Resize, GeometryTip, Outline, ScreenInversion
Nothing = 0, Resize, GeometryTip, Outline, ScreenInversion, Blur
};
/**

View file

@ -43,6 +43,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// KWin
#include "thumbnailitem.h"
#include <kwindowsystem.h>
#include "../effects.h"
#include "../client.h"
#include "../workspace.h"
@ -101,6 +102,19 @@ QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize
return icon;
}
static bool compositing()
{
#ifndef TABBOX_KCM
if (!Workspace::self()->compositing() || !effects) {
return false;
}
if (!static_cast<EffectsHandlerImpl*>(effects)->provides(Effect::Blur)) {
return false;
}
#endif
return Plasma::Theme::defaultTheme()->currentThemeHasImage("translucent/dialogs/background");
}
DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBoxMode mode, QWidget *parent)
: QDeclarativeView(parent)
, m_model(model)
@ -131,6 +145,7 @@ DeclarativeView::DeclarativeView(QAbstractItemModel *model, TabBoxConfig::TabBox
kdeclarative.setupBindings();
qmlRegisterType<ThumbnailItem>("org.kde.kwin", 0, 1, "ThumbnailItem");
rootContext()->setContextProperty("viewId", static_cast<qulonglong>(winId()));
rootContext()->setContextProperty("compositing", compositing());
if (m_mode == TabBoxConfig::ClientTabBox) {
rootContext()->setContextProperty("clientModel", model);
} else if (m_mode == TabBoxConfig::DesktopTabBox) {
@ -173,6 +188,7 @@ void DeclarativeView::showEvent(QShowEvent *event)
item->setProperty("currentIndex", tabBox->first().row());
connect(item, SIGNAL(currentIndexChanged(int)), SLOT(currentIndexChanged(int)));
}
rootContext()->setContextProperty("compositing", compositing());
slotUpdateGeometry();
QGraphicsView::showEvent(event);
}
@ -194,10 +210,9 @@ void DeclarativeView::resizeEvent(QResizeEvent *event)
m_frame->setImagePath(maskImagePath);
m_frame->resizeFrame(QSizeF(maskWidth, maskHeight));
QRegion mask = m_frame->mask().translated(maskLeftMargin, maskTopMargin);
if (Plasma::Theme::defaultTheme()->windowTranslucencyEnabled()) {
if (compositing()) {
// blur background
Plasma::WindowEffects::enableBlurBehind(winId(), true, mask);
Plasma::WindowEffects::overrideShadow(winId(), true);
clearMask();
} else {
// do not trim to mask with compositing enabled, otherwise shadows are cropped

View file

@ -23,6 +23,7 @@ install( FILES clients/window_strip/metadata.desktop DESTINATION ${SERVICES_INST
install (FILES IconTabBox.qml ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/big_icons/contents/ui)
install (FILES IconTabBox.qml ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/small_icons/contents/ui)
install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/)
install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/compact/contents/ui)
install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/informative/contents/ui)
install (FILES ShadowedSvgItem.qml DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/tabbox/present_windows/contents/ui)

View file

@ -22,24 +22,26 @@ import QtQuick 1.0
import org.kde.plasma.core 0.1 as PlasmaCore
Item {
property double leftMargin: background.margins.left + shadow.margins.left
property double topMargin: background.margins.top + shadow.margins.top
property double rightMargin: background.margins.right + shadow.margins.right
property double bottomMargin: background.margins.bottom + shadow.margins.bottom
property double centerWidth: background.width
property double centerHeight: background.height
property double leftMargin: shadow.margins.left + background.margins.left
property double topMargin: shadow.margins.top + background.margins.top
property double rightMargin: shadow.margins.right + background.margins.right
property double bottomMargin: shadow.margins.bottom + background.margins.bottom
property double centerWidth: shadow.width - shadow.margins.left - shadow.margins.right
property double centerHeight: shadow.height - shadow.margins.bottom - shadow.margins.top
property int centerTopMargin: shadow.margins.top
property int centerLeftMargin: shadow.margins.left
property alias maskImagePath: shadow.imagePath
PlasmaCore.FrameSvgItem {
id: shadow
imagePath: "dialogs/background"
imagePath: (compositing ? "translucent" : "opaque") + "/dialogs/background"
prefix: "shadow"
anchors.fill: parent
PlasmaCore.FrameSvgItem {
id: background
imagePath: "dialogs/background"
imagePath: shadow.imagePath
visible: false
anchors {
fill: parent
leftMargin: shadow.margins.left

View file

@ -30,7 +30,7 @@ Item {
property int optimalHeight: icons.iconSize + icons.margins.top + icons.margins.bottom + background.topMargin + background.bottomMargin + 40
property bool canStretchX: false
property bool canStretchY: false
property string maskImagePath: "dialogs/background"
property string maskImagePath: background.maskImagePath
property double maskWidth: background.centerWidth
property double maskHeight: background.centerHeight
property int maskTopMargin: background.centerTopMargin

View file

@ -31,7 +31,7 @@ Item {
property int optimalHeight: compactListView.rowHeight * compactListView.count + background.topMargin + background.bottomMargin
property bool canStretchX: true
property bool canStretchY: false
property string maskImagePath: "dialogs/background"
property string maskImagePath: background.maskImagePath
property double maskWidth: background.centerWidth
property double maskHeight: background.centerHeight
property int maskTopMargin: background.centerTopMargin

View file

@ -32,7 +32,7 @@ Item {
property int optimalHeight: listView.rowHeight * listView.count + background.topMargin + background.bottomMargin
property bool canStretchX: true
property bool canStretchY: false
property string maskImagePath: "dialogs/background"
property string maskImagePath: background.maskImagePath
property double maskWidth: background.centerWidth
property double maskHeight: background.centerHeight
property int maskTopMargin: background.centerTopMargin

View file

@ -30,7 +30,7 @@ Item {
property int optimalHeight: 0.9*screenHeight
property int imagePathPrefix: (new Date()).getTime()
property int standardMargin: 2
property string maskImagePath: "dialogs/background"
property string maskImagePath: background.maskImagePath
property double maskWidth: background.centerWidth
property double maskHeight: background.centerHeight
property int maskTopMargin: background.centerTopMargin

View file

@ -30,7 +30,7 @@ Item {
property int optimalHeight: icons.iconSize + icons.margins.top + icons.margins.bottom + background.topMargin + background.bottomMargin + 40
property bool canStretchX: false
property bool canStretchY: false
property string maskImagePath: "dialogs/background"
property string maskImagePath: background.maskImagePath
property double maskWidth: background.centerWidth
property double maskHeight: background.centerHeight
property int maskTopMargin: background.centerTopMargin

View file

@ -30,7 +30,7 @@ Item {
property int optimalHeight: textListView.rowHeight * textListView.count + background.topMargin + background.bottomMargin
property bool canStretchX: true
property bool canStretchY: false
property string maskImagePath: "dialogs/background"
property string maskImagePath: background.maskImagePath
property double maskWidth: background.centerWidth
property double maskHeight: background.centerHeight
property int maskTopMargin: background.centerTopMargin

View file

@ -32,7 +32,7 @@ Item {
property int optimalHeight: thumbnailListView.thumbnailWidth*(1.0/screenFactor) + hoverItem.margins.top + hoverItem.margins.bottom + background.topMargin + background.bottomMargin + 40
property bool canStretchX: false
property bool canStretchY: false
property string maskImagePath: "dialogs/background"
property string maskImagePath: background.maskImagePath
property double maskWidth: background.centerWidth
property double maskHeight: background.centerHeight
property int maskTopMargin: background.centerTopMargin

View file

@ -28,9 +28,14 @@ Item {
property bool allDesktops: true
property string longestCaption: ""
property int optimalWidth: listView.maxRowWidth
property int optimalHeight: listView.rowHeight * listView.count + background.margins.top + background.margins.bottom
property int optimalHeight: listView.rowHeight * listView.count + background.topMargin + background.bottomMargin
property bool canStretchX: true
property bool canStretchY: false
property string maskImagePath: background.maskImagePath
property double maskWidth: background.centerWidth
property double maskHeight: background.centerHeight
property int maskTopMargin: background.centerTopMargin
property int maskLeftMargin: background.centerLeftMargin
width: Math.min(Math.max(screenWidth * 0.2, optimalWidth), screenWidth * 0.8)
height: Math.min(optimalHeight, screenHeight * 0.8)
@ -57,10 +62,9 @@ Item {
visible: false
}
PlasmaCore.FrameSvgItem {
ShadowedSvgItem {
id: background
anchors.fill: parent
imagePath: "dialogs/background"
}
// delegate
@ -120,7 +124,7 @@ Item {
listView, "calculateMaxRowWidth");
width = Math.max(textElement.width, width);
textElement.destroy();
return width + 32 + hoverItem.margins.right + hoverItem.margins.left + background.margins.left + background.margins.right;
return width + 32 + hoverItem.margins.right + hoverItem.margins.left + background.leftMargin + background.rightMargin;
}
/**
* Calculates the height of one row based on the text height and icon size.
@ -150,10 +154,10 @@ Item {
property int imageId: 0
anchors {
fill: parent
topMargin: background.margins.top
leftMargin: background.margins.left
rightMargin: background.margins.right
bottomMargin: background.margins.bottom
topMargin: background.topMargin
leftMargin: background.leftMargin
rightMargin: background.rightMargin
bottomMargin: background.bottomMargin
}
clip: true
delegate: listDelegate