diff --git a/src/kwindoweffects.h b/src/kwindoweffects.h index 22675ce..8d507d3 100644 --- a/src/kwindoweffects.h +++ b/src/kwindoweffects.h @@ -1,167 +1,167 @@ /* * Copyright 2009 Marco Martin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KWINDOWEFFECTS_H #define KWINDOWEFFECTS_H #include "kwindowsystem_export.h" #ifndef KWINDOWSYSTEM_NO_QWIDGET #include // for WId, etc. #else class QWidget; #endif #include #include /** * Namespace for common standardized window effects */ namespace KWindowEffects { enum Effect { Slide = 1, PresentWindows = 3, PresentWindowsGroup = 4, HighlightWindows = 5, BlurBehind = 7, Dashboard = 8, BackgroundContrast = 9 }; enum SlideFromLocation { NoEdge = 0, TopEdge, RightEdge, BottomEdge, LeftEdge }; /** * @return if an atom property is available * * @param effect the effect we want to check */ KWINDOWSYSTEM_EXPORT bool isEffectAvailable(Effect effect); /** * Mark a window as sliding from screen edge * * @param id of the window on which we want to apply the effect * @param location edge of the screen from which we want the sliding effect. * Desktop and Floating won't have effect. * @param offset distance in pixels from the screen edge defined by location */ KWINDOWSYSTEM_EXPORT void slideWindow(WId id, SlideFromLocation location, int offset); /** * Mark a window as sliding from screen edge * This is an overloaded member function provided for convenience * * @param widget QWidget corresponding to the top level window we want to animate * @param location edge of the screen from which we want the sliding effect. * Desktop and Floating won't have effect. */ KWINDOWSYSTEM_EXPORT void slideWindow(QWidget *widget, SlideFromLocation location); /** * @return dimension of all the windows passed as parameter * * @param ids all the windows we want the size */ KWINDOWSYSTEM_EXPORT QList windowSizes(const QList &ids); /** * Activate the Present Windows effect for the given groups of windows. * * @param controller The window which is the controller of this effect. The property * will be set on this window. It will be removed by the effect * @param ids all the windows which should be presented. */ KWINDOWSYSTEM_EXPORT void presentWindows(WId controller, const QList &ids); /** * Activate the Present Windows effect for the windows of the given desktop. * * @param controller The window which is the controller of this effect. The property * will be set on this window. It will be removed by the effect * @param desktop The desktop whose windows should be presented. -1 for all desktops */ KWINDOWSYSTEM_EXPORT void presentWindows(WId controller, int desktop = NET::OnAllDesktops); /** * Highlight the selected windows, making all the others translucent * * @param controller The window which is the controller of this effect. The property * will be set on this window. It will be removed by the effect * @param ids all the windows which should be highlighted. */ KWINDOWSYSTEM_EXPORT void highlightWindows(WId controller, const QList &ids); /** * Instructs the window manager to blur the background * in the specified region behind the given window. * The given region will overwrite any previous blur-behind region. * Passing a null region will enable the blur effect for the whole window. * The region is relative to the top-left corner of the client area. * * If @a enable is @c false, blur will be disabled for the whole window * (@a region is ignored). * * Note that you will usually want to set the region to the shape of the window, * excluding any shadow or halo. * * @param window The window for which to enable the blur effect * @param enable Enable the effect if @c true, disable it if @c false - * @param region The region within the window where the background will be blurred + * @param region The region within the window where the background will be blurred, specified in logical pixels */ KWINDOWSYSTEM_EXPORT void enableBlurBehind(WId window, bool enable = true, const QRegion ®ion = QRegion()); /** * Instructs the window manager to modify the color of the background * in the specified region behind the given window, * in order to improve the contrast and readability of any text * in the translucent window. * The given region will overwrite any previous backgroundcontrast region. * Passing a null region will enable the blur effect for the whole window. * The region is relative to the top-left corner of the client area. * * If @a enable is @c false, blur will be disabled for the whole window * (@a region is ignored). * * Note that you will usually want to set the region to the shape of the window, * excluding any shadow or halo. * * @param window The window for which to enable the background contrast effect * @param enable Enable the effect if @c true, disable it if @c false * @param brightness How to modify the area brightness: from 0 (make it black) to 2 (make it white), 1 leaves it unchanged - * @param region The region within the window where the background will be modified + * @param region The region within the window where the background will be modified, specified in logical pixels */ KWINDOWSYSTEM_EXPORT void enableBackgroundContrast(WId window, bool enable = true, qreal contrast = 1, qreal intensity = 1, qreal saturation = 1, const QRegion ®ion = QRegion()); /** * Instructs the window manager to handle the given window as dashboard window as * Dashboard windows should be handled diffrently and may have special effects * applied to them. * * @param window The window for which to enable the blur effect */ KWINDOWSYSTEM_EXPORT void markAsDashboard(WId window); } #endif diff --git a/src/platforms/xcb/kwindoweffects.cpp b/src/platforms/xcb/kwindoweffects.cpp index d17e0b6..fa65dad 100644 --- a/src/platforms/xcb/kwindoweffects.cpp +++ b/src/platforms/xcb/kwindoweffects.cpp @@ -1,347 +1,351 @@ /* * Copyright 2009 Marco Martin * Copyright 2014 Martin Gräßlin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "kwindoweffects_x11.h" #include +#include #include "kwindowsystem.h" #include #include #include #include #include static const char DASHBOARD_WIN_CLASS[] = "dashboard\0dashboard"; using namespace KWindowEffects; KWindowEffectsPrivateX11::KWindowEffectsPrivateX11() { } KWindowEffectsPrivateX11::~KWindowEffectsPrivateX11() { } bool KWindowEffectsPrivateX11::isEffectAvailable(Effect effect) { if (!KWindowSystem::self()->compositingActive()) { return false; } QByteArray effectName; switch (effect) { case Slide: effectName = QByteArrayLiteral("_KDE_SLIDE"); break; case PresentWindows: effectName = QByteArrayLiteral("_KDE_PRESENT_WINDOWS_DESKTOP"); break; case PresentWindowsGroup: effectName = QByteArrayLiteral("_KDE_PRESENT_WINDOWS_GROUP"); break; case HighlightWindows: effectName = QByteArrayLiteral("_KDE_WINDOW_HIGHLIGHT"); break; case BlurBehind: effectName = QByteArrayLiteral("_KDE_NET_WM_BLUR_BEHIND_REGION"); break; case Dashboard: // TODO: Better namespacing for atoms effectName = QByteArrayLiteral("_WM_EFFECT_KDE_DASHBOARD"); break; case BackgroundContrast: effectName = QByteArrayLiteral("_KDE_NET_WM_BACKGROUND_CONTRAST_REGION"); break; default: return false; } // hackish way to find out if KWin has the effect enabled, // TODO provide proper support xcb_connection_t *c = QX11Info::connection(); xcb_list_properties_cookie_t propsCookie = xcb_list_properties_unchecked(c, QX11Info::appRootWindow()); xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData()); QScopedPointer props(xcb_list_properties_reply(c, propsCookie, nullptr)); QScopedPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); if (!atom || !props) { return false; } xcb_atom_t *atoms = xcb_list_properties_atoms(props.data()); for (int i = 0; i < props->atoms_len; ++i) { if (atoms[i] == atom->atom) { return true; } } return false; } void KWindowEffectsPrivateX11::slideWindow(WId id, SlideFromLocation location, int offset) { xcb_connection_t *c = QX11Info::connection(); if (!c) { return; } const QByteArray effectName = QByteArrayLiteral("_KDE_SLIDE"); xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData()); const int size = 2; int32_t data[size]; data[0] = offset; switch (location) { case LeftEdge: data[1] = 0; break; case TopEdge: data[1] = 1; break; case RightEdge: data[1] = 2; break; case BottomEdge: data[1] = 3; default: break; } QScopedPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); if (!atom) { return; } if (location == NoEdge) { xcb_delete_property(c, id, atom->atom); } else { xcb_change_property(c, XCB_PROP_MODE_REPLACE, id, atom->atom, atom->atom, 32, size, data); } } void KWindowEffectsPrivateX11::slideWindow(QWidget *widget, SlideFromLocation location) { slideWindow(widget->effectiveWinId(), location, -1); } QList KWindowEffectsPrivateX11::windowSizes(const QList &ids) { QList windowSizes; Q_FOREACH (WId id, ids) { if (id > 0) { KWindowInfo info(id, NET::WMGeometry | NET::WMFrameExtents); windowSizes.append(info.frameGeometry().size()); } else { windowSizes.append(QSize()); } } return windowSizes; } void KWindowEffectsPrivateX11::presentWindows(WId controller, const QList &ids) { xcb_connection_t *c = QX11Info::connection(); if (!c) { return; } const int numWindows = ids.count(); QVarLengthArray data(numWindows); int actualCount = 0; for (int i = 0; i < numWindows; ++i) { data[i] = ids.at(i); ++actualCount; } if (actualCount != numWindows) { data.resize(actualCount); } if (data.isEmpty()) { return; } const QByteArray effectName = QByteArrayLiteral("_KDE_PRESENT_WINDOWS_GROUP"); xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData()); QScopedPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); if (!atom) { return; } xcb_change_property(c, XCB_PROP_MODE_REPLACE, controller, atom->atom, atom->atom, 32, data.size(), data.constData()); } void KWindowEffectsPrivateX11::presentWindows(WId controller, int desktop) { xcb_connection_t *c = QX11Info::connection(); if (!c) { return; } const QByteArray effectName = QByteArrayLiteral("_KDE_PRESENT_WINDOWS_DESKTOP"); xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData()); QScopedPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); if (!atom) { return; } int32_t data = desktop; xcb_change_property(c, XCB_PROP_MODE_REPLACE, controller, atom->atom, atom->atom, 32, 1, &data); } void KWindowEffectsPrivateX11::highlightWindows(WId controller, const QList &ids) { xcb_connection_t *c = QX11Info::connection(); if (!c) { return; } const QByteArray effectName = QByteArrayLiteral("_KDE_WINDOW_HIGHLIGHT"); xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData()); QScopedPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); if (!atom) { return; } const int numWindows = ids.count(); if (numWindows == 0) { xcb_delete_property(c, controller, atom->atom); return; } QVarLengthArray data(numWindows); int actualCount = 0; for (int i = 0; i < numWindows; ++i) { data[i] = ids.at(i); ++actualCount; } if (actualCount != numWindows) { data.resize(actualCount); } if (data.isEmpty()) { return; } xcb_change_property(c, XCB_PROP_MODE_REPLACE, controller, atom->atom, atom->atom, 32, data.size(), data.constData()); } void KWindowEffectsPrivateX11::enableBlurBehind(WId window, bool enable, const QRegion ®ion) { xcb_connection_t *c = QX11Info::connection(); if (!c) { return; } const QByteArray effectName = QByteArrayLiteral("_KDE_NET_WM_BLUR_BEHIND_REGION"); xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData()); QScopedPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); if (!atom) { return; } if (enable) { QVector rects = region.rects(); QVector data; data.reserve(rects.count() * 4); Q_FOREACH (const QRect &r, rects) { - data << r.x() << r.y() << r.width() << r.height(); + // kwin on X uses device pixels, convert from logical + auto dpr = qApp->devicePixelRatio(); + data << r.x() * dpr << r.y() * dpr << r.width() * dpr << r.height() * dpr; } xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, atom->atom, XCB_ATOM_CARDINAL, 32, data.size(), data.constData()); } else { xcb_delete_property(c, window, atom->atom); } } void KWindowEffectsPrivateX11::enableBackgroundContrast(WId window, bool enable, qreal contrast, qreal intensity, qreal saturation, const QRegion ®ion) { xcb_connection_t *c = QX11Info::connection(); const QByteArray effectName = QByteArrayLiteral("_KDE_NET_WM_BACKGROUND_CONTRAST_REGION"); xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData()); QScopedPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); if (!atom) { return; } if (enable) { QVector rects = region.rects(); QVector data; data.reserve(rects.count() * 4 + 16); Q_FOREACH (const QRect &r, rects) { - data << r.x() << r.y() << r.width() << r.height(); + auto dpr = qApp->devicePixelRatio(); + data << r.x() * dpr << r.y() * dpr << r.width() * dpr << r.height() * dpr; } QMatrix4x4 satMatrix; //saturation QMatrix4x4 intMatrix; //intensity QMatrix4x4 contMatrix; //contrast //Saturation matrix if (!qFuzzyCompare(saturation, 1.0)) { const qreal rval = (1.0 - saturation) * .2126; const qreal gval = (1.0 - saturation) * .7152; const qreal bval = (1.0 - saturation) * .0722; satMatrix = QMatrix4x4(rval + saturation, rval, rval, 0.0, gval, gval + saturation, gval, 0.0, bval, bval, bval + saturation, 0.0, 0, 0, 0, 1.0); } //IntensityMatrix if (!qFuzzyCompare(intensity, 1.0)) { intMatrix.scale(intensity, intensity, intensity); } //Contrast Matrix if (!qFuzzyCompare(contrast, 1.0)) { const float transl = (1.0 - contrast) / 2.0; contMatrix = QMatrix4x4(contrast, 0, 0, 0.0, 0, contrast, 0, 0.0, 0, 0, contrast, 0.0, transl, transl, transl, 1.0); } QMatrix4x4 colorMatrix = contMatrix * satMatrix * intMatrix; colorMatrix = colorMatrix.transposed(); uint32_t *rawData = reinterpret_cast(colorMatrix.data()); for (int i = 0; i < 16; ++i) { data << rawData[i]; } xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, atom->atom, atom->atom, 32, data.size(), data.constData()); } else { xcb_delete_property(c, window, atom->atom); } } void KWindowEffectsPrivateX11::markAsDashboard(WId window) { xcb_connection_t *c = QX11Info::connection(); if (!c) { return; } xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, XCB_ATOM_WM_CLASS, XCB_ATOM_STRING, 8, 19, DASHBOARD_WIN_CLASS); }