Port Zoom effect to XCB and some small improvements

* use xcb_fixes_foo
* drop QX11Info - we don't need it in the effects
* use QScopedPointer for GLTexture/XRenderPicture
* remove commented code
* use kDebug instead of qDebug

Of course XCursor library is still used as there is no XCB replacement.
What could be considered is adding a getCursor hook into the
EffectsHandler as also the ScreenShot Effect is getting the cursor and
using XCursor doesn't seem future proof to me ;-)

Sorry for putting everything into one commit.

REVIEW: 109083
icc-effect-5.14.5
Martin Gräßlin 2013-02-21 19:38:03 +01:00
parent 6d97690042
commit a3faf455b9
2 changed files with 15 additions and 27 deletions

View File

@ -23,11 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// KConfigSkeleton // KConfigSkeleton
#include "zoomconfig.h" #include "zoomconfig.h"
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QtDebug>
#include <QtGui/QX11Info>
#include <QtGui/QApplication> #include <QtGui/QApplication>
#include <QtGui/QStyle> #include <QtGui/QStyle>
#include <QtGui/QVector2D> #include <QtGui/QVector2D>
@ -37,14 +32,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kstandardaction.h> #include <kstandardaction.h>
#include <KDE/KConfigGroup> #include <KDE/KConfigGroup>
#include <KDE/KLocale> #include <KDE/KLocale>
#include <KDE/KDebug>
#include <kwinglutils.h> #include <kwinglutils.h>
#ifdef KWIN_HAVE_XRENDER_COMPOSITING #ifdef KWIN_HAVE_XRENDER_COMPOSITING
#include <kwinxrenderutils.h> #include <kwinxrenderutils.h>
#include <xcb/render.h> #include <xcb/render.h>
#endif #endif
#include <xcb/xfixes.h>
#include <X11/extensions/Xfixes.h>
#include <X11/Xcursor/Xcursor.h> #include <X11/Xcursor/Xcursor.h>
namespace KWin namespace KWin
@ -63,10 +59,6 @@ ZoomEffect::ZoomEffect()
, followFocus(true) , followFocus(true)
, mousePointer(MousePointerScale) , mousePointer(MousePointerScale)
, focusDelay(350) // in milliseconds , focusDelay(350) // in milliseconds
, texture(0)
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
, xrenderPicture(0)
#endif
, imageWidth(0) , imageWidth(0)
, imageHeight(0) , imageHeight(0)
, isMouseHidden(false) , isMouseHidden(false)
@ -138,13 +130,10 @@ void ZoomEffect::showCursor()
{ {
if (isMouseHidden) { if (isMouseHidden) {
// show the previously hidden mouse-pointer again and free the loaded texture/picture. // show the previously hidden mouse-pointer again and free the loaded texture/picture.
Display* display = QX11Info::display(); xcb_xfixes_show_cursor(connection(), rootWindow());
XFixesShowCursor(display, DefaultRootWindow(display)); texture.reset();
delete texture;
texture = 0;
#ifdef KWIN_HAVE_XRENDER_COMPOSITING #ifdef KWIN_HAVE_XRENDER_COMPOSITING
delete xrenderPicture; xrenderPicture.reset();
xrenderPicture = 0;
#endif #endif
isMouseHidden = false; isMouseHidden = false;
} }
@ -159,10 +148,10 @@ void ZoomEffect::hideCursor()
recreateTexture(); recreateTexture();
bool shouldHide = false; bool shouldHide = false;
if (effects->isOpenGLCompositing()) { if (effects->isOpenGLCompositing()) {
shouldHide = (texture != NULL); shouldHide = !texture.isNull();
} else if (effects->compositingType() == XRenderCompositing) { } else if (effects->compositingType() == XRenderCompositing) {
#ifdef KWIN_HAVE_XRENDER_COMPOSITING #ifdef KWIN_HAVE_XRENDER_COMPOSITING
shouldHide = (xrenderPicture != NULL); shouldHide = !xrenderPicture.isNull();
#endif #endif
} }
if (shouldHide) { if (shouldHide) {
@ -195,15 +184,15 @@ void ZoomEffect::recreateTexture()
imageHeight = ximg->height; imageHeight = ximg->height;
QImage img((uchar*)ximg->pixels, imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied); QImage img((uchar*)ximg->pixels, imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied);
if (effects->isOpenGLCompositing()) if (effects->isOpenGLCompositing())
texture = new GLTexture(img); texture.reset(new GLTexture(img));
#ifdef KWIN_HAVE_XRENDER_COMPOSITING #ifdef KWIN_HAVE_XRENDER_COMPOSITING
if (effects->compositingType() == XRenderCompositing) if (effects->compositingType() == XRenderCompositing)
xrenderPicture = new XRenderPicture(QPixmap::fromImage(img)); xrenderPicture.reset(new XRenderPicture(QPixmap::fromImage(img)));
#endif #endif
XcursorImageDestroy(ximg); XcursorImageDestroy(ximg);
} }
else { else {
qDebug() << "Loading cursor image (" << theme << ") FAILED -> falling back to proportional mouse tracking!"; kDebug(1212) << "Loading cursor image (" << theme << ") FAILED -> falling back to proportional mouse tracking!";
mouseTracking = MouseTrackingProportional; mouseTracking = MouseTrackingProportional;
} }
} }
@ -341,7 +330,7 @@ void ZoomEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
w *= zoom; w *= zoom;
h *= zoom; h *= zoom;
} }
QPoint p = QCursor::pos(); const QPoint p = effects->cursorPos();
QRect rect(p.x() * zoom + data.xTranslation(), p.y() * zoom + data.yTranslation(), w, h); QRect rect(p.x() * zoom + data.xTranslation(), p.y() * zoom + data.yTranslation(), w, h);
if (texture) { if (texture) {
@ -398,7 +387,7 @@ void ZoomEffect::zoomIn(double to)
effects->startMousePolling(); effects->startMousePolling();
} }
if (mouseTracking == MouseTrackingDisabled) if (mouseTracking == MouseTrackingDisabled)
prevPoint = QCursor::pos(); prevPoint = effects->cursorPos();
effects->addRepaintFull(); effects->addRepaintFull();
} }
@ -414,7 +403,7 @@ void ZoomEffect::zoomOut()
} }
} }
if (mouseTracking == MouseTrackingDisabled) if (mouseTracking == MouseTrackingDisabled)
prevPoint = QCursor::pos(); prevPoint = effects->cursorPos();
effects->addRepaintFull(); effects->addRepaintFull();
} }
@ -486,7 +475,6 @@ void ZoomEffect::moveMouseToFocus()
void ZoomEffect::moveMouseToCenter() void ZoomEffect::moveMouseToCenter()
{ {
//QRect r = effects->clientArea(KWin::ScreenArea, effects->activeScreen(), effects->currentDesktop());
QRect r(0, 0, displayWidth(), displayHeight()); QRect r(0, 0, displayWidth(), displayHeight());
QCursor::setPos(r.x() + r.width() / 2, r.y() + r.height() / 2); QCursor::setPos(r.x() + r.width() / 2, r.y() + r.height() / 2);
} }

View File

@ -116,9 +116,9 @@ private:
QPoint prevPoint; QPoint prevPoint;
QTime lastMouseEvent; QTime lastMouseEvent;
QTime lastFocusEvent; QTime lastFocusEvent;
GLTexture* texture; QScopedPointer<GLTexture> texture;
#ifdef KWIN_HAVE_XRENDER_COMPOSITING #ifdef KWIN_HAVE_XRENDER_COMPOSITING
XRenderPicture* xrenderPicture; QScopedPointer<XRenderPicture> xrenderPicture;
#endif #endif
int imageWidth; int imageWidth;
int imageHeight; int imageHeight;