diff --git a/composite.cpp b/composite.cpp index db828bf72..1bfa66b0d 100644 --- a/composite.cpp +++ b/composite.cpp @@ -1,892 +1,891 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2006 Lubos Lunak This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ /* Code related to compositing (redirecting windows to pixmaps and tracking window damage). Docs: XComposite (the protocol, but the function calls map to it): http://gitweb.freedesktop.org/?p=xorg/proto/compositeproto.git;a=blob_plain;hb=HEAD;f=compositeproto.txt XDamage (again the protocol): http://gitweb.freedesktop.org/?p=xorg/proto/damageproto.git;a=blob_plain;hb=HEAD;f=damageproto.txt Paper including basics on compositing, XGL vs AIGLX, XRender vs OpenGL, etc.: http://www.vis.uni-stuttgart.de/~hopf/pub/LinuxTag2007_compiz_NextGenerationDesktop_Paper.pdf Composite HOWTO from Fredrik: http://ktown.kde.org/~fredrik/composite_howto.html */ #include #include "utils.h" #include #include "workspace.h" #include "client.h" #include "unmanaged.h" #include "deleted.h" #include "effects.h" #include "overlaywindow.h" #include "scene.h" #include "scene_xrender.h" #include "scene_opengl.h" #include "shadow.h" #include "compositingprefs.h" #include "notifications.h" #include #include #include #include #include #include #include #include #include #include namespace KWin { extern int currentRefreshRate(); //**************************************** // Workspace //**************************************** void Workspace::setupCompositing() { if (scene != NULL) return; if (compositingSuspended) { kDebug(1212) << "Compositing is suspended"; return; } else if (!CompositingPrefs::compositingPossible()) { kError(1212) << "Compositing is not possible"; return; } if (!options->compositingInitialized) options->reloadCompositingSettings(true); char selection_name[ 100 ]; sprintf(selection_name, "_NET_WM_CM_S%d", DefaultScreen(display())); cm_selection = new KSelectionOwner(selection_name); connect(cm_selection, SIGNAL(lostOwnership()), SLOT(lostCMSelection())); cm_selection->claim(true); // force claiming switch(options->compositingMode) { case OpenGLCompositing: { kDebug(1212) << "Initializing OpenGL compositing"; // Some broken drivers crash on glXQuery() so to prevent constant KWin crashes: KSharedConfigPtr unsafeConfigPtr(KSharedConfig::openConfig("kwinrc")); KConfigGroup unsafeConfig(unsafeConfigPtr, "Compositing"); if (unsafeConfig.readEntry("OpenGLIsUnsafe", false)) kWarning(1212) << "KWin has detected that your OpenGL library is unsafe to use"; else { unsafeConfig.writeEntry("OpenGLIsUnsafe", true); unsafeConfig.sync(); #ifndef KWIN_HAVE_OPENGLES if (!CompositingPrefs::hasGlx()) { unsafeConfig.writeEntry("OpenGLIsUnsafe", false); unsafeConfig.sync(); kDebug(1212) << "No glx extensions available"; break; } #endif scene = new SceneOpenGL(this); // TODO: Add 30 second delay to protect against screen freezes as well unsafeConfig.writeEntry("OpenGLIsUnsafe", false); unsafeConfig.sync(); if (!scene->initFailed()) break; // --> delete scene; scene = NULL; } // Do not Fall back to XRender - it causes problems when selfcheck fails during startup, but works later on break; } #ifdef KWIN_HAVE_XRENDER_COMPOSITING case XRenderCompositing: kDebug(1212) << "Initializing XRender compositing"; scene = new SceneXrender(this); break; #endif default: kDebug(1212) << "No compositing enabled"; delete cm_selection; return; } if (scene == NULL || scene->initFailed()) { kError(1212) << "Failed to initialize compositing, compositing disabled"; kError(1212) << "Consult http://techbase.kde.org/Projects/KWin/4.0-release-notes#Setting_up"; delete scene; scene = NULL; delete cm_selection; return; } xrrRefreshRate = KWin::currentRefreshRate(); fpsInterval = (options->maxFpsInterval << 10); if (scene->waitSyncAvailable()) { // if we do vsync, set the fps to the next multiple of the vblank rate vBlankInterval = (1000 << 10) / xrrRefreshRate; fpsInterval -= (fpsInterval % vBlankInterval); fpsInterval = qMax(fpsInterval, vBlankInterval); } else vBlankInterval = 1 << 10; // no sync - DO NOT set "0", would cause div-by-zero segfaults. vBlankPadding = 3; // vblank rounding errors... :-( nextPaintReference.start(); checkCompositeTimer(); XCompositeRedirectSubwindows(display(), rootWindow(), CompositeRedirectManual); new EffectsHandlerImpl(scene->compositingType()); // sets also the 'effects' pointer addRepaintFull(); foreach (Client * c, clients) c->setupCompositing(); foreach (Client * c, desktops) c->setupCompositing(); foreach (Unmanaged * c, unmanaged) c->setupCompositing(); discardPopup(); // force re-creation of the Alt+F3 popup (opacity option) } void Workspace::finishCompositing() { if (scene == NULL) return; m_finishingCompositing = true; delete cm_selection; foreach (Client * c, clients) scene->windowClosed(c, NULL); foreach (Client * c, desktops) scene->windowClosed(c, NULL); foreach (Unmanaged * c, unmanaged) scene->windowClosed(c, NULL); foreach (Deleted * c, deleted) scene->windowDeleted(c); foreach (Client * c, clients) c->finishCompositing(); foreach (Client * c, desktops) c->finishCompositing(); foreach (Unmanaged * c, unmanaged) c->finishCompositing(); foreach (Deleted * c, deleted) c->finishCompositing(); XCompositeUnredirectSubwindows(display(), rootWindow(), CompositeRedirectManual); delete effects; effects = NULL; delete scene; scene = NULL; compositeTimer.stop(); mousePollingTimer.stop(); repaints_region = QRegion(); for (ClientList::ConstIterator it = clients.constBegin(); it != clients.constEnd(); ++it) { // forward all opacity values to the frame in case there'll be other CM running if ((*it)->opacity() != 1.0) { NETWinInfo2 i(display(), (*it)->frameId(), rootWindow(), 0); i.setOpacity(static_cast< unsigned long >((*it)->opacity() * 0xffffffff)); } } discardPopup(); // force re-creation of the Alt+F3 popup (opacity option) // discard all Deleted windows (#152914) while (!deleted.isEmpty()) deleted.first()->discard(Allowed); m_finishingCompositing = false; } // OpenGL self-check failed, fallback to XRender void Workspace::fallbackToXRenderCompositing() { finishCompositing(); KConfigGroup config(KSharedConfig::openConfig("kwinrc"), "Compositing"); config.writeEntry("Backend", "XRender"); config.writeEntry("GraphicsSystem", "native"); config.sync(); if (Extensions::nonNativePixmaps()) { // must restart to change the graphicssystem restartKWin("automatic graphicssystem change for XRender backend"); return; } else { options->compositingMode = XRenderCompositing; setupCompositing(); } } void Workspace::lostCMSelection() { kDebug(1212) << "Lost compositing manager selection"; finishCompositing(); } // for the shortcut void Workspace::slotToggleCompositing() { suspendCompositing(!compositingSuspended); } // for the dbus call void Workspace::toggleCompositing() { slotToggleCompositing(); if (compositingSuspended) { // when disabled show a shortcut how the user can get back compositing QString shortcut, message; if (KAction* action = qobject_cast(keys->action("Suspend Compositing"))) shortcut = action->globalShortcut().primary().toString(QKeySequence::NativeText); if (!shortcut.isEmpty()) { // display notification only if there is the shortcut message = i18n("Desktop effects have been suspended by another application.
" "You can resume using the '%1' shortcut.", shortcut); Notify::raise(Notify::CompositingSuspendedDbus, message); } } } QStringList Workspace::activeEffects() const { if (effects) return static_cast< EffectsHandlerImpl* >(effects)->activeEffects(); return QStringList(); } void Workspace::updateCompositeBlocking(Client *c) { if (c) { // if c == 0 we just check if we can resume if (c->isBlockingCompositing()) { if (!compositingBlocked) // do NOT attempt to call suspendCompositing(true); from within the eventchain! QMetaObject::invokeMethod(this, "slotToggleCompositing", Qt::QueuedConnection); compositingBlocked = true; } } else if (compositingBlocked) { // lost a client and we're blocked - can we resume? // NOTICE do NOT check for "compositingSuspended" or "!compositing()" // only "resume" if it was really disabled for a block bool resume = true; for (ClientList::ConstIterator it = clients.constBegin(); it != clients.constEnd(); ++it) { if ((*it)->isBlockingCompositing()) { resume = false; break; } } if (resume) { // do NOT attempt to call suspendCompositing(false); from within the eventchain! compositingBlocked = false; if (compositingSuspended) QMetaObject::invokeMethod(this, "slotToggleCompositing", Qt::QueuedConnection); } } } void Workspace::suspendCompositing() { suspendCompositing(true); } void Workspace::suspendCompositing(bool suspend) { compositingSuspended = suspend; finishCompositing(); setupCompositing(); // will do nothing if suspended // notify decorations that composition state has changed if (hasDecorationPlugin()) { KDecorationFactory* factory = mgr->factory(); factory->reset(SettingCompositing); } emit compositingToggled(!compositingSuspended); } void Workspace::resetCompositing() { if (compositing()) { finishCompositing(); QTimer::singleShot(0, this, SLOT(setupCompositing())); } } void Workspace::addRepaint(int x, int y, int w, int h) { if (!compositing()) return; repaints_region += QRegion(x, y, w, h); checkCompositeTimer(); } void Workspace::addRepaint(const QRect& r) { if (!compositing()) return; repaints_region += r; checkCompositeTimer(); } void Workspace::addRepaint(const QRegion& r) { if (!compositing()) return; repaints_region += r; checkCompositeTimer(); } void Workspace::addRepaintFull() { if (!compositing()) return; repaints_region = QRegion(0, 0, displayWidth(), displayHeight()); checkCompositeTimer(); } void Workspace::timerEvent(QTimerEvent *te) { if (te->timerId() == compositeTimer.timerId()) { compositeTimer.stop(); performCompositing(); } else QObject::timerEvent(te); } void Workspace::performCompositing() { if (((repaints_region.isEmpty() && !windowRepaintsPending()) // no damage || !scene->overlayWindow()->isVisible())) { // nothing is visible anyway vBlankPadding += 3; scene->idle(); // Note: It would seem here we should undo suspended unredirect, but when scenes need // it for some reason, e.g. transformations or translucency, the next pass that does not // need this anymore and paints normally will also reset the suspended unredirect. // Otherwise the window would not be painted normally anyway. return; } // create a list of all windows in the stacking order ToplevelList windows = xStackingOrder(); foreach (EffectWindow *c, static_cast< EffectsHandlerImpl* >(effects)->elevatedWindows()) { Toplevel* t = static_cast< EffectWindowImpl* >(c)->window(); windows.removeAll(t); windows.append(t); } // skip windows that are not yet ready for being painted // TODO ? // this cannot be used so carelessly - needs protections against broken clients, the window // should not get focus before it's displayed, handle unredirected windows properly and so on. foreach (Toplevel *t, windows) if (!t->readyForPainting()) windows.removeAll(t); QRegion repaints = repaints_region; // clear all repaints, so that post-pass can add repaints for the next repaint repaints_region = QRegion(); if (scene->waitSyncAvailable()) { // vsync: paint the scene, than rebase the timer and use the duration for next timeout estimation scene->paint(repaints, windows); nextPaintReference.start(); } else { // no vsyc -> inversion: reset the timer, then paint the scene, this way we can provide a constant framerate nextPaintReference.start(); scene->paint(repaints, windows); } // reset the roundin error corrective... :-( vBlankPadding = 3; // Trigger at least one more pass even if there would be nothing to paint, so that scene->idle() // is called the next time. If there would be nothing pending, it will not restart the timer and // checkCompositeTime() would restart it again somewhen later, called from functions that // would again add something pending. checkCompositeTimer(); } void Workspace::performMousePoll() { checkCursorPos(); } bool Workspace::windowRepaintsPending() const { foreach (Toplevel * c, clients) if (!c->repaints().isEmpty()) return true; foreach (Toplevel * c, desktops) if (!c->repaints().isEmpty()) return true; foreach (Toplevel * c, unmanaged) if (!c->repaints().isEmpty()) return true; foreach (Toplevel * c, deleted) if (!c->repaints().isEmpty()) return true; return false; } void Workspace::setCompositeTimer() { if (!compositing()) // should not really happen, but there may be e.g. some damage events still pending return; // interval - "time since last paint completion" - "time we need to paint" uint passed = nextPaintReference.elapsed() << 10; uint delay = fpsInterval; if (scene->waitSyncAvailable()) { if (passed > fpsInterval) { delay = vBlankInterval; passed %= vBlankInterval; } delay -= ((passed + ((scene->estimatedRenderTime() + vBlankPadding) << 10)) % vBlankInterval); } else delay = qBound(0, int(delay - passed), 250 << 10); compositeTimer.start(delay >> 10, this); } void Workspace::startMousePolling() { mousePollingTimer.start(20); // 50Hz. TODO: How often do we really need to poll? } void Workspace::stopMousePolling() { mousePollingTimer.stop(); } bool Workspace::compositingActive() { return !m_finishingCompositing && compositing(); } // force is needed when the list of windows changes (e.g. a window goes away) void Workspace::checkUnredirect(bool force) { if (!compositing() || scene->overlayWindow()->window() == None || !options->unredirectFullscreen) return; if (force) forceUnredirectCheck = true; if (!unredirectTimer.isActive()) unredirectTimer.start(0); } void Workspace::delayedCheckUnredirect() { if (!compositing() || scene->overlayWindow()->window() == None || !options->unredirectFullscreen) return; ToplevelList list; bool changed = forceUnredirectCheck; foreach (Client * c, clients) list.append(c); foreach (Unmanaged * c, unmanaged) list.append(c); foreach (Toplevel * c, list) { if (c->updateUnredirectedState()) changed = true; } // no desktops, no Deleted ones if (!changed) return; forceUnredirectCheck = false; // Cut out parts from the overlay window where unredirected windows are, // so that they are actually visible. QRegion reg(0, 0, displayWidth(), displayHeight()); foreach (Toplevel * c, list) { if (c->unredirected()) reg -= c->geometry(); } scene->overlayWindow()->setShape(reg); } //**************************************** // Toplevel //**************************************** void Toplevel::setupCompositing() { if (!compositing()) return; damageRatio = 0.0; if (damage_handle != None) return; damage_handle = XDamageCreate(display(), frameId(), XDamageReportRawRectangles); damage_region = QRegion(0, 0, width(), height()); - effect_window = new EffectWindowImpl(); - effect_window->setWindow(this); + effect_window = new EffectWindowImpl(this); unredirect = false; workspace()->checkUnredirect(true); scene->windowAdded(this); } void Toplevel::finishCompositing() { damageRatio = 0.0; if (damage_handle == None) return; workspace()->checkUnredirect(true); if (effect_window->window() == this) { // otherwise it's already passed to Deleted, don't free data discardWindowPixmap(); delete effect_window; } XDamageDestroy(display(), damage_handle); damage_handle = None; damage_region = QRegion(); repaints_region = QRegion(); effect_window = NULL; } void Toplevel::discardWindowPixmap() { damageRatio = 0.0; addDamageFull(); if (window_pix == None) return; XFreePixmap(display(), window_pix); window_pix = None; if (effectWindow() != NULL && effectWindow()->sceneWindow() != NULL) effectWindow()->sceneWindow()->pixmapDiscarded(); } Pixmap Toplevel::createWindowPixmap() { assert(compositing()); if (unredirected()) return None; damageRatio = 0.0; grabXServer(); KXErrorHandler err; Pixmap pix = XCompositeNameWindowPixmap(display(), frameId()); // check that the received pixmap is valid and actually matches what we // know about the window (i.e. size) XWindowAttributes attrs; if (!XGetWindowAttributes(display(), frameId(), &attrs) || err.error(false) || attrs.width != width() || attrs.height != height() || attrs.map_state != IsViewable) { kDebug(1212) << "Creating window pixmap failed: " << this; XFreePixmap(display(), pix); pix = None; } ungrabXServer(); return pix; } // We must specify that the two events are a union so the compiler doesn't // complain about strict aliasing rules. typedef union { XEvent e; XDamageNotifyEvent de; } EventUnion; static QVector damageRects; void Toplevel::damageNotifyEvent(XDamageNotifyEvent* e) { if (damageRatio == 1.0) { // we know that we're completely damaged, no need to tell us again while (XPending(display())) { // drop events EventUnion e2; if (XPeekEvent(display(), &e2.e) && e2.e.type == Extensions::damageNotifyEvent() && e2.e.xany.window == frameId()) { XNextEvent(display(), &e2.e); continue; } break; } return; } const float area = rect().width()*rect().height(); damageRects.reserve(16); damageRects.clear(); damageRects << QRect(e->area.x, e->area.y, e->area.width, e->area.height); // we can not easily say anything about the overall ratio since the new rects may intersect the present float newDamageRatio = damageRects.last().width()*damageRects.last().height() / area; // compress while (XPending(display())) { EventUnion e2; if (XPeekEvent(display(), &e2.e) && e2.e.type == Extensions::damageNotifyEvent() && e2.e.xany.window == frameId()) { XNextEvent(display(), &e2.e); if (damageRatio >= 0.8 || newDamageRatio > 0.8 || damageRects.count() > 15) { // If there are too many damage events in the queue, just discard them // and damage the whole window. Otherwise the X server can just overload // us with a flood of damage events. Should be probably optimized // in the X server, as this is rather lame. newDamageRatio = 1.0; damageRects.clear(); continue; } damageRects << QRect(e2.de.area.x, e2.de.area.y, e2.de.area.width, e2.de.area.height); newDamageRatio += damageRects.last().width()*damageRects.last().height() / area; continue; } break; } if ((damageRects.count() == 1 && damageRects.last() == rect()) || (damageRects.isEmpty() && newDamageRatio == 1.0)) { addDamageFull(); } else { foreach (const QRect &r, damageRects) addDamage(r); } } void Client::damageNotifyEvent(XDamageNotifyEvent* e) { #ifdef HAVE_XSYNC if (syncRequest.isPending && isResize()) return; if (!ready_for_painting) { // avoid "setReadyForPainting()" function calling overhead if (syncRequest.counter == None) // cannot detect complete redraw, consider done now setReadyForPainting(); #else setReadyForPainting(); #endif } Toplevel::damageNotifyEvent(e); } void Toplevel::addDamage(const QRect& r) { addDamage(r.x(), r.y(), r.width(), r.height()); } void Toplevel::addDamage(int x, int y, int w, int h) { if (!compositing()) return; QRect r(x, y, w, h); // resizing the decoration may lag behind a bit and when shrinking there // may be a damage event coming with size larger than the current window size r &= rect(); if (r.isEmpty()) return; damage_region += r; int damageArea = 0; foreach (const QRect &r2, damage_region.rects()) damageArea += r2.width()*r2.height(); damageRatio = float(damageArea) / float(rect().width()*rect().height()); repaints_region += r; emit damaged(this, r); // discard lanczos texture if (effect_window) { QVariant cachedTextureVariant = effect_window->data(LanczosCacheRole); if (cachedTextureVariant.isValid()) { GLTexture *cachedTexture = static_cast< GLTexture*>(cachedTextureVariant.value()); delete cachedTexture; cachedTexture = 0; effect_window->setData(LanczosCacheRole, QVariant()); } } workspace()->checkCompositeTimer(); } void Toplevel::addDamageFull() { if (!compositing()) return; damage_region = rect(); repaints_region = rect(); damageRatio = 1.0; emit damaged(this, rect()); // discard lanczos texture if (effect_window) { QVariant cachedTextureVariant = effect_window->data(LanczosCacheRole); if (cachedTextureVariant.isValid()) { GLTexture *cachedTexture = static_cast< GLTexture*>(cachedTextureVariant.value()); delete cachedTexture; cachedTexture = 0; effect_window->setData(LanczosCacheRole, QVariant()); } } workspace()->checkCompositeTimer(); } void Toplevel::resetDamage(const QRect& r) { damage_region -= r; int damageArea = 0; foreach (const QRect &r2, damage_region.rects()) damageArea += r2.width()*r2.height(); damageRatio = float(damageArea) / float(rect().width()*rect().height()); } void Toplevel::addRepaint(const QRect& r) { addRepaint(r.x(), r.y(), r.width(), r.height()); } void Toplevel::addRepaint(int x, int y, int w, int h) { if (!compositing()) return; QRect r(x, y, w, h); r &= rect(); repaints_region += r; workspace()->checkCompositeTimer(); } void Toplevel::addRepaint(const QRegion& r) { if (!compositing()) return; repaints_region += r; workspace()->checkCompositeTimer(); } void Toplevel::addRepaintFull() { repaints_region = decorationRect(); workspace()->checkCompositeTimer(); } void Toplevel::resetRepaints(const QRect& r) { repaints_region -= r; } void Toplevel::addWorkspaceRepaint(int x, int y, int w, int h) { addWorkspaceRepaint(QRect(x, y, w, h)); } void Toplevel::addWorkspaceRepaint(const QRect& r2) { if (!compositing()) return; workspace()->addRepaint(r2); } bool Toplevel::updateUnredirectedState() { assert(compositing()); bool should = shouldUnredirect() && !unredirectSuspend && !shape() && !hasAlpha() && opacity() == 1.0 && !static_cast(effects)->activeFullScreenEffect(); if (should && !unredirect) { unredirect = true; kDebug(1212) << "Unredirecting:" << this; XCompositeUnredirectWindow(display(), frameId(), CompositeRedirectManual); return true; } else if (!should && unredirect) { unredirect = false; kDebug(1212) << "Redirecting:" << this; XCompositeRedirectWindow(display(), frameId(), CompositeRedirectManual); discardWindowPixmap(); return true; } return false; } void Toplevel::suspendUnredirect(bool suspend) { if (unredirectSuspend == suspend) return; unredirectSuspend = suspend; workspace()->checkUnredirect(); } //**************************************** // Client //**************************************** void Client::setupCompositing() { Toplevel::setupCompositing(); updateVisibility(); // for internalKeep() updateDecoration(true, true); move(calculateGravitation(true)); // we just polluted the gravity because the window likely has no decoration yet } void Client::finishCompositing() { Toplevel::finishCompositing(); updateVisibility(); updateDecoration(true, true); // for safety in case KWin is just resizing the window s_haveResizeEffect = false; } bool Client::shouldUnredirect() const { if (isActiveFullScreen()) { ToplevelList stacking = workspace()->xStackingOrder(); for (int pos = stacking.count() - 1; pos >= 0; --pos) { Toplevel* c = stacking.at(pos); if (c == this) // is not covered by any other window, ok to unredirect return true; if (c->geometry().intersects(geometry())) return false; } abort(); } return false; } //**************************************** // Unmanaged //**************************************** bool Unmanaged::shouldUnredirect() const { // the pixmap is needed for the login effect, a nicer solution would be the login effect increasing // refcount for the window pixmap (which would prevent unredirect), avoiding this hack if (resourceClass() == "ksplashx" || resourceClass() == "ksplashsimple" || resourceClass() == "ksplashqml" ) return false; // it must cover whole display or one xinerama screen, and be the topmost there if (geometry() == workspace()->clientArea(FullArea, geometry().center(), workspace()->currentDesktop()) || geometry() == workspace()->clientArea(ScreenArea, geometry().center(), workspace()->currentDesktop())) { ToplevelList stacking = workspace()->xStackingOrder(); for (int pos = stacking.count() - 1; pos >= 0; --pos) { Toplevel* c = stacking.at(pos); if (c == this) // is not covered by any other window, ok to unredirect return true; if (c->geometry().intersects(geometry())) return false; } abort(); } return false; } //**************************************** // Deleted //**************************************** bool Deleted::shouldUnredirect() const { return false; } } // namespace diff --git a/effects.cpp b/effects.cpp index d229f6d50..4bbcdf99d 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1,2084 +1,2084 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2006 Lubos Lunak Copyright (C) 2010, 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "effects.h" #include "deleted.h" #include "client.h" #include "group.h" #include "scene_xrender.h" #include "scene_opengl.h" #include "unmanaged.h" #ifdef KWIN_BUILD_TABBOX #include "tabbox.h" #endif #include "thumbnailitem.h" #include "workspace.h" #include "kwinglutils.h" #include #include "kdebug.h" #include "klibrary.h" #include "kdesktopfile.h" #include "kconfiggroup.h" #include "kstandarddirs.h" #include #include #include #include #include namespace KWin { //--------------------- // Static static QByteArray readWindowProperty(Window win, long atom, long type, int format) { int len = 32768; for (;;) { unsigned char* data; Atom rtype; int rformat; unsigned long nitems, after; if (XGetWindowProperty(QX11Info::display(), win, atom, 0, len, False, AnyPropertyType, &rtype, &rformat, &nitems, &after, &data) == Success) { if (after > 0) { XFree(data); len *= 2; continue; } if (long(rtype) == type && rformat == format) { int bytelen = format == 8 ? nitems : format == 16 ? nitems * sizeof(short) : nitems * sizeof(long); QByteArray ret(reinterpret_cast< const char* >(data), bytelen); XFree(data); return ret; } else { // wrong format, type or something XFree(data); return QByteArray(); } } else // XGetWindowProperty() failed return QByteArray(); } } static void deleteWindowProperty(Window win, long int atom) { XDeleteProperty(QX11Info::display(), win, atom); } //--------------------- EffectsHandlerImpl::EffectsHandlerImpl(CompositingType type) : EffectsHandler(type) , keyboard_grab_effect(NULL) , fullscreen_effect(0) , next_window_quad_type(EFFECT_QUAD_TYPE_START) , mouse_poll_ref_count(0) { // init is important, otherwise causes crashes when quads are build before the first painting pass start m_currentBuildQuadsIterator = m_activeEffects.end(); Workspace *ws = Workspace::self(); connect(ws, SIGNAL(currentDesktopChanged(int)), this, SLOT(slotDesktopChanged(int))); connect(ws, SIGNAL(clientAdded(KWin::Client*)), this, SLOT(slotClientAdded(KWin::Client*))); connect(ws, SIGNAL(unmanagedAdded(KWin::Unmanaged*)), this, SLOT(slotUnmanagedAdded(KWin::Unmanaged*))); connect(ws, SIGNAL(clientActivated(KWin::Client*)), this, SLOT(slotClientActivated(KWin::Client*))); connect(ws, SIGNAL(deletedRemoved(KWin::Deleted*)), this, SLOT(slotDeletedRemoved(KWin::Deleted*))); connect(ws, SIGNAL(numberDesktopsChanged(int)), SIGNAL(numberDesktopsChanged(int))); connect(ws, SIGNAL(mouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)), SIGNAL(mouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers))); connect(ws, SIGNAL(propertyNotify(long)), this, SLOT(slotPropertyNotify(long))); #ifdef KWIN_BUILD_TABBOX connect(ws->tabBox(), SIGNAL(tabBoxAdded(int)), SIGNAL(tabBoxAdded(int))); connect(ws->tabBox(), SIGNAL(tabBoxUpdated()), SIGNAL(tabBoxUpdated())); connect(ws->tabBox(), SIGNAL(tabBoxClosed()), SIGNAL(tabBoxClosed())); connect(ws->tabBox(), SIGNAL(tabBoxKeyEvent(QKeyEvent*)), SIGNAL(tabBoxKeyEvent(QKeyEvent*))); #endif // connect all clients foreach (Client *c, ws->clientList()) { setupClientConnections(c); } foreach (Unmanaged *u, ws->unmanagedList()) { setupUnmanagedConnections(u); } reconfigure(); } EffectsHandlerImpl::~EffectsHandlerImpl() { if (keyboard_grab_effect != NULL) ungrabKeyboard(); foreach (const EffectPair & ep, loaded_effects) unloadEffect(ep.first); foreach (const InputWindowPair & pos, input_windows) XDestroyWindow(display(), pos.second); } void EffectsHandlerImpl::setupClientConnections(Client* c) { connect(c, SIGNAL(windowClosed(KWin::Toplevel*,KWin::Deleted*)), this, SLOT(slotWindowClosed(KWin::Toplevel*))); connect(c, SIGNAL(clientMaximizedStateChanged(KWin::Client*,KDecorationDefines::MaximizeMode)), this, SLOT(slotClientMaximized(KWin::Client*,KDecorationDefines::MaximizeMode))); connect(c, SIGNAL(clientStartUserMovedResized(KWin::Client*)), this, SLOT(slotClientStartUserMovedResized(KWin::Client*))); connect(c, SIGNAL(clientStepUserMovedResized(KWin::Client*,QRect)), this, SLOT(slotClientStepUserMovedResized(KWin::Client*,QRect))); connect(c, SIGNAL(clientFinishUserMovedResized(KWin::Client*)), this, SLOT(slotClientFinishUserMovedResized(KWin::Client*))); connect(c, SIGNAL(opacityChanged(KWin::Toplevel*,qreal)), this, SLOT(slotOpacityChanged(KWin::Toplevel*,qreal))); connect(c, SIGNAL(clientMinimized(KWin::Client*,bool)), this, SLOT(slotClientMinimized(KWin::Client*,bool))); connect(c, SIGNAL(clientUnminimized(KWin::Client*,bool)), this, SLOT(slotClientUnminimized(KWin::Client*,bool))); connect(c, SIGNAL(geometryShapeChanged(KWin::Toplevel*,QRect)), this, SLOT(slotGeometryShapeChanged(KWin::Toplevel*,QRect))); connect(c, SIGNAL(damaged(KWin::Toplevel*,QRect)), this, SLOT(slotWindowDamaged(KWin::Toplevel*,QRect))); connect(c, SIGNAL(propertyNotify(KWin::Toplevel*,long)), this, SLOT(slotPropertyNotify(KWin::Toplevel*,long))); } void EffectsHandlerImpl::setupUnmanagedConnections(Unmanaged* u) { connect(u, SIGNAL(windowClosed(KWin::Toplevel*,KWin::Deleted*)), this, SLOT(slotWindowClosed(KWin::Toplevel*))); connect(u, SIGNAL(opacityChanged(KWin::Toplevel*,qreal)), this, SLOT(slotOpacityChanged(KWin::Toplevel*,qreal))); connect(u, SIGNAL(geometryShapeChanged(KWin::Toplevel*,QRect)), this, SLOT(slotGeometryShapeChanged(KWin::Toplevel*,QRect))); connect(u, SIGNAL(damaged(KWin::Toplevel*,QRect)), this, SLOT(slotWindowDamaged(KWin::Toplevel*,QRect))); connect(u, SIGNAL(propertyNotify(KWin::Toplevel*,long)), this, SLOT(slotPropertyNotify(KWin::Toplevel*,long))); } void EffectsHandlerImpl::reconfigure() { KSharedConfig::Ptr _config = KGlobal::config(); KConfigGroup conf(_config, "Plugins"); KService::List offers = KServiceTypeTrader::self()->query("KWin/Effect"); QStringList effectsToBeLoaded; QStringList checkDefault; // First unload necessary effects foreach (const KService::Ptr & service, offers) { KPluginInfo plugininfo(service); plugininfo.load(conf); if (plugininfo.isPluginEnabledByDefault()) { const QString key = plugininfo.pluginName() + QString::fromLatin1("Enabled"); if (!conf.hasKey(key)) checkDefault.append(plugininfo.pluginName()); } bool isloaded = isEffectLoaded(plugininfo.pluginName()); bool shouldbeloaded = plugininfo.isPluginEnabled(); if (!shouldbeloaded && isloaded) unloadEffect(plugininfo.pluginName()); if (shouldbeloaded) effectsToBeLoaded.append(plugininfo.pluginName()); } QStringList newLoaded; // Then load those that should be loaded foreach (const QString & effectName, effectsToBeLoaded) { if (!isEffectLoaded(effectName)) { if (loadEffect(effectName, checkDefault.contains(effectName))) newLoaded.append(effectName); } } foreach (const EffectPair & ep, loaded_effects) { if (!newLoaded.contains(ep.first)) // don't reconfigure newly loaded effects ep.second->reconfigure(Effect::ReconfigureAll); } } // the idea is that effects call this function again which calls the next one void EffectsHandlerImpl::prePaintScreen(ScreenPrePaintData& data, int time) { if (m_currentPaintScreenIterator != m_activeEffects.end()) { (*m_currentPaintScreenIterator++)->prePaintScreen(data, time); --m_currentPaintScreenIterator; } // no special final code } void EffectsHandlerImpl::paintScreen(int mask, QRegion region, ScreenPaintData& data) { if (m_currentPaintScreenIterator != m_activeEffects.end()) { (*m_currentPaintScreenIterator++)->paintScreen(mask, region, data); --m_currentPaintScreenIterator; } else scene->finalPaintScreen(mask, region, data); } void EffectsHandlerImpl::postPaintScreen() { if (m_currentPaintScreenIterator != m_activeEffects.end()) { (*m_currentPaintScreenIterator++)->postPaintScreen(); --m_currentPaintScreenIterator; } // no special final code } void EffectsHandlerImpl::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time) { if (m_currentPaintWindowIterator != m_activeEffects.end()) { (*m_currentPaintWindowIterator++)->prePaintWindow(w, data, time); --m_currentPaintWindowIterator; } // no special final code } void EffectsHandlerImpl::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) { if (m_currentPaintWindowIterator != m_activeEffects.end()) { (*m_currentPaintWindowIterator++)->paintWindow(w, mask, region, data); --m_currentPaintWindowIterator; } else scene->finalPaintWindow(static_cast(w), mask, region, data); } void EffectsHandlerImpl::paintEffectFrame(EffectFrame* frame, QRegion region, double opacity, double frameOpacity) { if (m_currentPaintEffectFrameIterator != m_activeEffects.end()) { (*m_currentPaintEffectFrameIterator++)->paintEffectFrame(frame, region, opacity, frameOpacity); --m_currentPaintEffectFrameIterator; } else { const EffectFrameImpl* frameImpl = static_cast(frame); frameImpl->finalRender(region, opacity, frameOpacity); } } void EffectsHandlerImpl::postPaintWindow(EffectWindow* w) { if (m_currentPaintWindowIterator != m_activeEffects.end()) { (*m_currentPaintWindowIterator++)->postPaintWindow(w); --m_currentPaintWindowIterator; } // no special final code } bool EffectsHandlerImpl::provides(Effect::Feature ef) { for (int i = 0; i < loaded_effects.size(); ++i) if (loaded_effects.at(i).second->provides(ef)) return true; return false; } void EffectsHandlerImpl::drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) { if (m_currentDrawWindowIterator != m_activeEffects.end()) { (*m_currentDrawWindowIterator++)->drawWindow(w, mask, region, data); --m_currentDrawWindowIterator; } else scene->finalDrawWindow(static_cast(w), mask, region, data); } void EffectsHandlerImpl::buildQuads(EffectWindow* w, WindowQuadList& quadList) { if (m_currentBuildQuadsIterator != m_activeEffects.end()) { (*m_currentBuildQuadsIterator++)->buildQuads(w, quadList); --m_currentBuildQuadsIterator; } } bool EffectsHandlerImpl::hasDecorationShadows() const { return Workspace::self()->hasDecorationShadows(); } bool EffectsHandlerImpl::decorationsHaveAlpha() const { return Workspace::self()->decorationHasAlpha(); } bool EffectsHandlerImpl::decorationSupportsBlurBehind() const { return Workspace::self()->decorationSupportsBlurBehind(); } // start another painting pass void EffectsHandlerImpl::startPaint() { m_activeEffects.clear(); for(QVector< KWin::EffectPair >::iterator it = loaded_effects.begin(); it != loaded_effects.end(); ++it) { if (it->second->isActive()) { m_activeEffects << it->second; } } m_currentDrawWindowIterator = m_activeEffects.begin(); m_currentPaintWindowIterator = m_activeEffects.begin(); m_currentPaintScreenIterator = m_activeEffects.begin(); m_currentPaintEffectFrameIterator = m_activeEffects.begin(); m_currentBuildQuadsIterator = m_activeEffects.begin(); } void EffectsHandlerImpl::slotClientMaximized(KWin::Client *c, KDecorationDefines::MaximizeMode maxMode) { bool horizontal = false; bool vertical = false; switch (maxMode) { case KDecorationDefines::MaximizeHorizontal: horizontal = true; break; case KDecorationDefines::MaximizeVertical: vertical = true; break; case KDecorationDefines::MaximizeFull: horizontal = true; vertical = true; break; case KDecorationDefines::MaximizeRestore: // fall through default: // default - nothing to do break; } emit windowMaximizedStateChanged(c->effectWindow(), horizontal, vertical); } void EffectsHandlerImpl::slotClientStartUserMovedResized(Client *c) { emit windowStartUserMovedResized(c->effectWindow()); } void EffectsHandlerImpl::slotClientFinishUserMovedResized(Client *c) { emit windowFinishUserMovedResized(c->effectWindow()); } void EffectsHandlerImpl::slotClientStepUserMovedResized(Client* c, const QRect& geometry) { emit windowStepUserMovedResized(c->effectWindow(), geometry); } void EffectsHandlerImpl::slotOpacityChanged(Toplevel *t, qreal oldOpacity) { if (t->opacity() == oldOpacity || !t->effectWindow()) { return; } emit windowOpacityChanged(t->effectWindow(), oldOpacity, (qreal)t->opacity()); } void EffectsHandlerImpl::slotClientAdded(Client *c) { if (c->readyForPainting()) slotClientShown(c); else connect(c, SIGNAL(windowShown(KWin::Toplevel*)), SLOT(slotClientShown(KWin::Toplevel*))); } void EffectsHandlerImpl::slotUnmanagedAdded(Unmanaged *u) { // regardless, unmanaged windows are -yet?- not synced anyway setupUnmanagedConnections(u); emit windowAdded(u->effectWindow()); } void EffectsHandlerImpl::slotClientShown(KWin::Toplevel *c) { Q_ASSERT(dynamic_cast(c)); setupClientConnections(static_cast(c)); emit windowAdded(c->effectWindow()); } void EffectsHandlerImpl::slotDeletedRemoved(KWin::Deleted *d) { emit windowDeleted(d->effectWindow()); elevated_windows.removeAll(d->effectWindow()); } void EffectsHandlerImpl::slotWindowClosed(KWin::Toplevel *c) { emit windowClosed(c->effectWindow()); } void EffectsHandlerImpl::slotClientActivated(KWin::Client *c) { emit windowActivated(c ? c->effectWindow() : NULL); } void EffectsHandlerImpl::slotClientMinimized(Client *c, bool animate) { // TODO: notify effects even if it should not animate? if (animate) { emit windowMinimized(c->effectWindow()); } } void EffectsHandlerImpl::slotClientUnminimized(Client* c, bool animate) { // TODO: notify effects even if it should not animate? if (animate) { emit windowUnminimized(c->effectWindow()); } } void EffectsHandlerImpl::slotClientGroupItemSwitched(EffectWindow* from, EffectWindow* to) { emit clientGroupItemSwitched(from, to); } void EffectsHandlerImpl::slotClientGroupItemAdded(EffectWindow* from, EffectWindow* to) { emit clientGroupItemAdded(from, to); } void EffectsHandlerImpl::slotClientGroupItemRemoved(EffectWindow* c, EffectWindow* group) { emit clientGroupItemRemoved(c, group); } void EffectsHandlerImpl::slotDesktopChanged(int old) { const int newDesktop = Workspace::self()->currentDesktop(); if (old != 0 && newDesktop != old) { emit desktopChanged(old, newDesktop); } } void EffectsHandlerImpl::slotWindowDamaged(Toplevel* t, const QRect& r) { if (!t->effectWindow()) { // can happen during tear down of window return; } emit windowDamaged(t->effectWindow(), r); } void EffectsHandlerImpl::slotGeometryShapeChanged(Toplevel* t, const QRect& old) { // during late cleanup effectWindow() may be already NULL // in some functions that may still call this if (t == NULL || t->effectWindow() == NULL) return; emit windowGeometryShapeChanged(t->effectWindow(), old); } void EffectsHandlerImpl::setActiveFullScreenEffect(Effect* e) { fullscreen_effect = e; Workspace::self()->checkUnredirect(); } Effect* EffectsHandlerImpl::activeFullScreenEffect() const { return fullscreen_effect; } bool EffectsHandlerImpl::borderActivated(ElectricBorder border) { bool ret = false; foreach (const EffectPair & ep, loaded_effects) if (ep.second->borderActivated(border)) ret = true; // bail out or tell all? return ret; } bool EffectsHandlerImpl::grabKeyboard(Effect* effect) { if (keyboard_grab_effect != NULL) return false; bool ret = grabXKeyboard(); if (!ret) return false; keyboard_grab_effect = effect; return true; } void EffectsHandlerImpl::ungrabKeyboard() { assert(keyboard_grab_effect != NULL); ungrabXKeyboard(); keyboard_grab_effect = NULL; } void EffectsHandlerImpl::grabbedKeyboardEvent(QKeyEvent* e) { if (keyboard_grab_effect != NULL) keyboard_grab_effect->grabbedKeyboardEvent(e); } void* EffectsHandlerImpl::getProxy(QString name) { // All effects start with "kwin4_effect_", prepend it to the name name.prepend("kwin4_effect_"); for (QVector< EffectPair >::iterator it = loaded_effects.begin(); it != loaded_effects.end(); ++it) if ((*it).first == name) return (*it).second->proxy(); return NULL; } void EffectsHandlerImpl::startMousePolling() { if (!mouse_poll_ref_count) // Start timer if required Workspace::self()->startMousePolling(); mouse_poll_ref_count++; } void EffectsHandlerImpl::stopMousePolling() { assert(mouse_poll_ref_count); mouse_poll_ref_count--; if (!mouse_poll_ref_count) // Stop timer if required Workspace::self()->stopMousePolling(); } bool EffectsHandlerImpl::hasKeyboardGrab() const { return keyboard_grab_effect != NULL; } void EffectsHandlerImpl::desktopResized(const QSize &size) { scene->screenGeometryChanged(size); emit screenGeometryChanged(size); Workspace::self()->addRepaintFull(); } void EffectsHandlerImpl::slotPropertyNotify(Toplevel* t, long int atom) { if (!registered_atoms.contains(atom)) return; emit propertyNotify(t->effectWindow(), atom); } void EffectsHandlerImpl::slotPropertyNotify(long int atom) { if (!registered_atoms.contains(atom)) return; emit propertyNotify(NULL, atom); } void EffectsHandlerImpl::registerPropertyType(long atom, bool reg) { if (reg) ++registered_atoms[ atom ]; // initialized to 0 if not present yet else { if (--registered_atoms[ atom ] == 0) registered_atoms.remove(atom); } } QByteArray EffectsHandlerImpl::readRootProperty(long atom, long type, int format) const { return readWindowProperty(rootWindow(), atom, type, format); } void EffectsHandlerImpl::deleteRootProperty(long atom) const { deleteWindowProperty(rootWindow(), atom); } void EffectsHandlerImpl::activateWindow(EffectWindow* c) { if (Client* cl = dynamic_cast< Client* >(static_cast(c)->window())) Workspace::self()->activateClient(cl, true); } EffectWindow* EffectsHandlerImpl::activeWindow() const { return Workspace::self()->activeClient() ? Workspace::self()->activeClient()->effectWindow() : NULL; } void EffectsHandlerImpl::moveWindow(EffectWindow* w, const QPoint& pos, bool snap, double snapAdjust) { Client* cl = dynamic_cast< Client* >(static_cast(w)->window()); if (!cl || !cl->isMovable()) return; if (snap) cl->move(Workspace::self()->adjustClientPosition(cl, pos, true, snapAdjust)); else cl->move(pos); } void EffectsHandlerImpl::windowToDesktop(EffectWindow* w, int desktop) { Client* cl = dynamic_cast< Client* >(static_cast(w)->window()); if (cl && !cl->isDesktop() && !cl->isDock()) Workspace::self()->sendClientToDesktop(cl, desktop, true); } void EffectsHandlerImpl::windowToScreen(EffectWindow* w, int screen) { Client* cl = dynamic_cast< Client* >(static_cast(w)->window()); if (cl && !cl->isDesktop() && !cl->isDock()) Workspace::self()->sendClientToScreen(cl, screen); } void EffectsHandlerImpl::setShowingDesktop(bool showing) { Workspace::self()->setShowingDesktop(showing); } QString EffectsHandlerImpl::currentActivity() const { return Workspace::self()->currentActivity(); } int EffectsHandlerImpl::currentDesktop() const { return Workspace::self()->currentDesktop(); } int EffectsHandlerImpl::numberOfDesktops() const { return Workspace::self()->numberOfDesktops(); } void EffectsHandlerImpl::setCurrentDesktop(int desktop) { Workspace::self()->setCurrentDesktop(desktop); } void EffectsHandlerImpl::setNumberOfDesktops(int desktops) { Workspace::self()->setNumberOfDesktops(desktops); } QSize EffectsHandlerImpl::desktopGridSize() const { return Workspace::self()->desktopGridSize(); } int EffectsHandlerImpl::desktopGridWidth() const { return Workspace::self()->desktopGridWidth(); } int EffectsHandlerImpl::desktopGridHeight() const { return Workspace::self()->desktopGridHeight(); } int EffectsHandlerImpl::workspaceWidth() const { return Workspace::self()->workspaceWidth(); } int EffectsHandlerImpl::workspaceHeight() const { return Workspace::self()->workspaceHeight(); } int EffectsHandlerImpl::desktopAtCoords(QPoint coords) const { return Workspace::self()->desktopAtCoords(coords); } QPoint EffectsHandlerImpl::desktopGridCoords(int id) const { return Workspace::self()->desktopGridCoords(id); } QPoint EffectsHandlerImpl::desktopCoords(int id) const { return Workspace::self()->desktopCoords(id); } int EffectsHandlerImpl::desktopAbove(int desktop, bool wrap) const { return Workspace::self()->desktopAbove(desktop, wrap); } int EffectsHandlerImpl::desktopToRight(int desktop, bool wrap) const { return Workspace::self()->desktopToRight(desktop, wrap); } int EffectsHandlerImpl::desktopBelow(int desktop, bool wrap) const { return Workspace::self()->desktopBelow(desktop, wrap); } int EffectsHandlerImpl::desktopToLeft(int desktop, bool wrap) const { return Workspace::self()->desktopToLeft(desktop, wrap); } QString EffectsHandlerImpl::desktopName(int desktop) const { return Workspace::self()->desktopName(desktop); } bool EffectsHandlerImpl::optionRollOverDesktops() const { return options->rollOverDesktops; } double EffectsHandlerImpl::animationTimeFactor() const { return options->animationTimeFactor(); } WindowQuadType EffectsHandlerImpl::newWindowQuadType() { return WindowQuadType(next_window_quad_type++); } int EffectsHandlerImpl::displayWidth() const { return KWin::displayWidth(); } int EffectsHandlerImpl::displayHeight() const { return KWin::displayWidth(); } EffectWindow* EffectsHandlerImpl::findWindow(WId id) const { if (Client* w = Workspace::self()->findClient(WindowMatchPredicate(id))) return w->effectWindow(); if (Unmanaged* w = Workspace::self()->findUnmanaged(WindowMatchPredicate(id))) return w->effectWindow(); return NULL; } EffectWindowList EffectsHandlerImpl::stackingOrder() const { ToplevelList list = Workspace::self()->xStackingOrder(); EffectWindowList ret; foreach (Toplevel *w, list) ret.append(effectWindow(w)); return ret; } void EffectsHandlerImpl::setElevatedWindow(EffectWindow* w, bool set) { elevated_windows.removeAll(w); if (set) elevated_windows.append(w); } void EffectsHandlerImpl::setTabBoxWindow(EffectWindow* w) { #ifdef KWIN_BUILD_TABBOX if (Client* c = dynamic_cast< Client* >(static_cast< EffectWindowImpl* >(w)->window())) { if (Workspace::self()->hasTabBox()) { Workspace::self()->tabBox()->setCurrentClient(c); } } #else Q_UNUSED(w) #endif } void EffectsHandlerImpl::setTabBoxDesktop(int desktop) { #ifdef KWIN_BUILD_TABBOX if (Workspace::self()->hasTabBox()) { Workspace::self()->tabBox()->setCurrentDesktop(desktop); } #else Q_UNUSED(desktop) #endif } EffectWindowList EffectsHandlerImpl::currentTabBoxWindowList() const { #ifdef KWIN_BUILD_TABBOX EffectWindowList ret; ClientList clients; if (Workspace::self()->hasTabBox()) { clients = Workspace::self()->tabBox()->currentClientList(); } else { clients = ClientList(); } foreach (Client * c, clients) ret.append(c->effectWindow()); return ret; #else return EffectWindowList(); #endif } void EffectsHandlerImpl::refTabBox() { #ifdef KWIN_BUILD_TABBOX if (Workspace::self()->hasTabBox()) { Workspace::self()->tabBox()->reference(); } #endif } void EffectsHandlerImpl::unrefTabBox() { #ifdef KWIN_BUILD_TABBOX if (Workspace::self()->hasTabBox()) { Workspace::self()->tabBox()->unreference(); } #endif } void EffectsHandlerImpl::closeTabBox() { #ifdef KWIN_BUILD_TABBOX if (Workspace::self()->hasTabBox()) { Workspace::self()->tabBox()->close(); } #endif } QList< int > EffectsHandlerImpl::currentTabBoxDesktopList() const { #ifdef KWIN_BUILD_TABBOX if (Workspace::self()->hasTabBox()) { return Workspace::self()->tabBox()->currentDesktopList(); } #endif return QList< int >(); } int EffectsHandlerImpl::currentTabBoxDesktop() const { #ifdef KWIN_BUILD_TABBOX if (Workspace::self()->hasTabBox()) { return Workspace::self()->tabBox()->currentDesktop(); } #endif return -1; } EffectWindow* EffectsHandlerImpl::currentTabBoxWindow() const { #ifdef KWIN_BUILD_TABBOX if (Workspace::self()->hasTabBox()) { if (Client* c = Workspace::self()->tabBox()->currentClient()) return c->effectWindow(); } #endif return NULL; } void EffectsHandlerImpl::addRepaintFull() { Workspace::self()->addRepaintFull(); } void EffectsHandlerImpl::addRepaint(const QRect& r) { Workspace::self()->addRepaint(r); } void EffectsHandlerImpl::addRepaint(const QRegion& r) { Workspace::self()->addRepaint(r); } void EffectsHandlerImpl::addRepaint(int x, int y, int w, int h) { Workspace::self()->addRepaint(x, y, w, h); } int EffectsHandlerImpl::activeScreen() const { return Workspace::self()->activeScreen(); } int EffectsHandlerImpl::numScreens() const { return Workspace::self()->numScreens(); } int EffectsHandlerImpl::screenNumber(const QPoint& pos) const { return Workspace::self()->screenNumber(pos); } QRect EffectsHandlerImpl::clientArea(clientAreaOption opt, int screen, int desktop) const { return Workspace::self()->clientArea(opt, screen, desktop); } QRect EffectsHandlerImpl::clientArea(clientAreaOption opt, const EffectWindow* c) const { const Toplevel* t = static_cast< const EffectWindowImpl* >(c)->window(); if (const Client* cl = dynamic_cast< const Client* >(t)) return Workspace::self()->clientArea(opt, cl); else return Workspace::self()->clientArea(opt, t->geometry().center(), Workspace::self()->currentDesktop()); } QRect EffectsHandlerImpl::clientArea(clientAreaOption opt, const QPoint& p, int desktop) const { return Workspace::self()->clientArea(opt, p, desktop); } Window EffectsHandlerImpl::createInputWindow(Effect* e, int x, int y, int w, int h, const QCursor& cursor) { XSetWindowAttributes attrs; attrs.override_redirect = True; Window win = XCreateWindow(display(), rootWindow(), x, y, w, h, 0, 0, InputOnly, CopyFromParent, CWOverrideRedirect, &attrs); // TODO keeping on top? // TODO enter/leave notify? XSelectInput(display(), win, ButtonPressMask | ButtonReleaseMask | PointerMotionMask); XDefineCursor(display(), win, cursor.handle()); XMapWindow(display(), win); input_windows.append(qMakePair(e, win)); // Raise electric border windows above the input windows // so they can still be triggered. #ifdef KWIN_BUILD_SCREENEDGES Workspace::self()->screenEdge()->ensureOnTop(); #endif return win; } void EffectsHandlerImpl::destroyInputWindow(Window w) { foreach (const InputWindowPair & pos, input_windows) { if (pos.second == w) { input_windows.removeAll(pos); XDestroyWindow(display(), w); return; } } abort(); } bool EffectsHandlerImpl::checkInputWindowEvent(XEvent* e) { if (e->type != ButtonPress && e->type != ButtonRelease && e->type != MotionNotify) return false; foreach (const InputWindowPair & pos, input_windows) { if (pos.second == e->xany.window) { switch(e->type) { case ButtonPress: { XButtonEvent* e2 = &e->xbutton; Qt::MouseButton button = x11ToQtMouseButton(e2->button); Qt::MouseButtons buttons = x11ToQtMouseButtons(e2->state) | button; QMouseEvent ev(QEvent::MouseButtonPress, QPoint(e2->x, e2->y), QPoint(e2->x_root, e2->y_root), button, buttons, x11ToQtKeyboardModifiers(e2->state)); pos.first->windowInputMouseEvent(pos.second, &ev); break; // ---> } case ButtonRelease: { XButtonEvent* e2 = &e->xbutton; Qt::MouseButton button = x11ToQtMouseButton(e2->button); Qt::MouseButtons buttons = x11ToQtMouseButtons(e2->state) & ~button; QMouseEvent ev(QEvent::MouseButtonRelease, QPoint(e2->x, e2->y), QPoint(e2->x_root, e2->y_root), button, buttons, x11ToQtKeyboardModifiers(e2->state)); pos.first->windowInputMouseEvent(pos.second, &ev); break; // ---> } case MotionNotify: { XMotionEvent* e2 = &e->xmotion; QMouseEvent ev(QEvent::MouseMove, QPoint(e2->x, e2->y), QPoint(e2->x_root, e2->y_root), Qt::NoButton, x11ToQtMouseButtons(e2->state), x11ToQtKeyboardModifiers(e2->state)); pos.first->windowInputMouseEvent(pos.second, &ev); break; // ---> } } return true; // eat event } } return false; } void EffectsHandlerImpl::checkInputWindowStacking() { if (input_windows.count() == 0) return; Window* wins = new Window[ input_windows.count()]; int pos = 0; foreach (const InputWindowPair & it, input_windows) wins[ pos++ ] = it.second; XRaiseWindow(display(), wins[ 0 ]); XRestackWindows(display(), wins, pos); delete[] wins; // Raise electric border windows above the input windows // so they can still be triggered. TODO: Do both at once. #ifdef KWIN_BUILD_SCREENEDGES Workspace::self()->screenEdge()->ensureOnTop(); #endif } QPoint EffectsHandlerImpl::cursorPos() const { return Workspace::self()->cursorPos(); } void EffectsHandlerImpl::checkElectricBorder(const QPoint &pos, Time time) { #ifdef KWIN_BUILD_SCREENEDGES Workspace::self()->screenEdge()->check(pos, time); #else Q_UNUSED(pos) Q_UNUSED(time) #endif } void EffectsHandlerImpl::reserveElectricBorder(ElectricBorder border) { #ifdef KWIN_BUILD_SCREENEDGES Workspace::self()->screenEdge()->reserve(border); #else Q_UNUSED(border) #endif } void EffectsHandlerImpl::unreserveElectricBorder(ElectricBorder border) { #ifdef KWIN_BUILD_SCREENEDGES Workspace::self()->screenEdge()->unreserve(border); #else Q_UNUSED(border) #endif } void EffectsHandlerImpl::reserveElectricBorderSwitching(bool reserve) { #ifdef KWIN_BUILD_SCREENEDGES Workspace::self()->screenEdge()->reserveDesktopSwitching(reserve); #else Q_UNUSED(reserve) #endif } unsigned long EffectsHandlerImpl::xrenderBufferPicture() { #ifdef KWIN_HAVE_XRENDER_COMPOSITING if (SceneXrender* s = dynamic_cast< SceneXrender* >(scene)) return s->bufferPicture(); #endif return None; } KLibrary* EffectsHandlerImpl::findEffectLibrary(KService* service) { QString libname = service->library(); #ifdef KWIN_HAVE_OPENGLES if (libname.startsWith(QLatin1String("kwin4_effect_"))) { libname.replace("kwin4_effect_", "kwin4_effect_gles_"); } #endif KLibrary* library = new KLibrary(libname); if (!library) { kError(1212) << "couldn't open library for effect '" << service->name() << "'" << endl; return 0; } return library; } void EffectsHandlerImpl::toggleEffect(const QString& name) { if (isEffectLoaded(name)) unloadEffect(name); else loadEffect(name); } QStringList EffectsHandlerImpl::loadedEffects() const { QStringList listModules; for (QVector< EffectPair >::const_iterator it = loaded_effects.constBegin(); it != loaded_effects.constEnd(); ++it) { listModules << (*it).first; } return listModules; } QStringList EffectsHandlerImpl::listOfEffects() const { KService::List offers = KServiceTypeTrader::self()->query("KWin/Effect"); QStringList listOfModules; // First unload necessary effects foreach (const KService::Ptr & service, offers) { KPluginInfo plugininfo(service); listOfModules << plugininfo.pluginName(); } return listOfModules; } bool EffectsHandlerImpl::loadEffect(const QString& name, bool checkDefault) { Workspace::self()->addRepaintFull(); if (!name.startsWith(QLatin1String("kwin4_effect_"))) kWarning(1212) << "Effect names usually have kwin4_effect_ prefix" ; // Make sure a single effect won't be loaded multiple times for (QVector< EffectPair >::const_iterator it = loaded_effects.constBegin(); it != loaded_effects.constEnd(); ++it) { if ((*it).first == name) { kDebug(1212) << "EffectsHandler::loadEffect : Effect already loaded : " << name; return true; } } kDebug(1212) << "Trying to load " << name; QString internalname = name.toLower(); QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(internalname); KService::List offers = KServiceTypeTrader::self()->query("KWin/Effect", constraint); if (offers.isEmpty()) { kError(1212) << "Couldn't find effect " << name << endl; return false; } KService::Ptr service = offers.first(); KLibrary* library = findEffectLibrary(service.data()); if (!library) { return false; } QString version_symbol = "effect_version_" + name; KLibrary::void_function_ptr version_func = library->resolveFunction(version_symbol.toAscii()); if (version_func == NULL) { kWarning(1212) << "Effect " << name << " does not provide required API version, ignoring."; delete library; return false; } typedef int (*t_versionfunc)(); int version = reinterpret_cast< t_versionfunc >(version_func)(); // call it // Version must be the same or less, but major must be the same. // With major 0 minor must match exactly. if (version > KWIN_EFFECT_API_VERSION || (version >> 8) != KWIN_EFFECT_API_VERSION_MAJOR || (KWIN_EFFECT_API_VERSION_MAJOR == 0 && version != KWIN_EFFECT_API_VERSION)) { kWarning(1212) << "Effect " << name << " requires unsupported API version " << version; delete library; return false; } const QString enabledByDefault_symbol = "effect_enabledbydefault_" + name; KLibrary::void_function_ptr enabledByDefault_func = library->resolveFunction(enabledByDefault_symbol.toAscii().data()); const QString supported_symbol = "effect_supported_" + name; KLibrary::void_function_ptr supported_func = library->resolveFunction(supported_symbol.toAscii().data()); const QString create_symbol = "effect_create_" + name; KLibrary::void_function_ptr create_func = library->resolveFunction(create_symbol.toAscii().data()); if (supported_func) { typedef bool (*t_supportedfunc)(); t_supportedfunc supported = reinterpret_cast(supported_func); if (!supported()) { kWarning(1212) << "EffectsHandler::loadEffect : Effect " << name << " is not supported" ; library->unload(); return false; } } if (checkDefault && enabledByDefault_func) { typedef bool (*t_enabledByDefaultfunc)(); t_enabledByDefaultfunc enabledByDefault = reinterpret_cast(enabledByDefault_func); if (!enabledByDefault()) { library->unload(); return false; } } if (!create_func) { kError(1212) << "EffectsHandler::loadEffect : effect_create function not found" << endl; library->unload(); return false; } typedef Effect*(*t_createfunc)(); t_createfunc create = reinterpret_cast(create_func); // Make sure all depenedencies have been loaded // TODO: detect circular deps KPluginInfo plugininfo(service); QStringList dependencies = plugininfo.dependencies(); foreach (const QString & depName, dependencies) { if (!loadEffect(depName)) { kError(1212) << "EffectsHandler::loadEffect : Couldn't load dependencies for effect " << name << endl; library->unload(); return false; } } Effect* e = create(); effect_order.insert(service->property("X-KDE-Ordering").toInt(), EffectPair(name, e)); effectsChanged(); effect_libraries[ name ] = library; return true; } void EffectsHandlerImpl::unloadEffect(const QString& name) { Workspace::self()->addRepaintFull(); for (QMap< int, EffectPair >::iterator it = effect_order.begin(); it != effect_order.end(); ++it) { if (it.value().first == name) { kDebug(1212) << "EffectsHandler::unloadEffect : Unloading Effect : " << name; if (activeFullScreenEffect() == it.value().second) { setActiveFullScreenEffect(0); } delete it.value().second; effect_order.erase(it); effectsChanged(); effect_libraries[ name ]->unload(); return; } } kDebug(1212) << "EffectsHandler::unloadEffect : Effect not loaded : " << name; } void EffectsHandlerImpl::reconfigureEffect(const QString& name) { for (QVector< EffectPair >::iterator it = loaded_effects.begin(); it != loaded_effects.end(); ++it) if ((*it).first == name) { (*it).second->reconfigure(Effect::ReconfigureAll); return; } } bool EffectsHandlerImpl::isEffectLoaded(const QString& name) { for (QVector< EffectPair >::iterator it = loaded_effects.begin(); it != loaded_effects.end(); ++it) if ((*it).first == name) return true; return false; } void EffectsHandlerImpl::reloadEffect(Effect *effect) { QString effectName; for (QVector< EffectPair >::iterator it = loaded_effects.begin(); it != loaded_effects.end(); ++it) { if ((*it).second == effect) { effectName = (*it).first; break; } } if (!effectName.isNull()) { unloadEffect(effectName); loadEffect(effectName); } } void EffectsHandlerImpl::effectsChanged() { loaded_effects.clear(); // kDebug(1212) << "Recreating effects' list:"; foreach (const EffectPair & effect, effect_order) { // kDebug(1212) << effect.first; loaded_effects.append(effect); } } QStringList EffectsHandlerImpl::activeEffects() const { QStringList ret; for(QVector< KWin::EffectPair >::const_iterator it = loaded_effects.constBegin(), end = loaded_effects.constEnd(); it != end; ++it) { if (it->second->isActive()) { ret << it->first; } } return ret; } EffectFrame* EffectsHandlerImpl::effectFrame(EffectFrameStyle style, bool staticSize, const QPoint& position, Qt::Alignment alignment) const { return new EffectFrameImpl(style, staticSize, position, alignment); } QVariant EffectsHandlerImpl::kwinOption(KWinOption kwopt) { switch (kwopt) { case CloseButtonCorner: return Workspace::self()->decorationCloseButtonCorner(); } return QVariant(); // an invalid one } void EffectsHandlerImpl::slotShowOutline(const QRect& geometry) { emit showOutline(geometry); } void EffectsHandlerImpl::slotHideOutline() { emit hideOutline(); } //**************************************** // EffectWindowImpl //**************************************** -EffectWindowImpl::EffectWindowImpl() - : QObject(NULL) - , EffectWindow() - , toplevel(NULL) +EffectWindowImpl::EffectWindowImpl(Toplevel *toplevel) + : EffectWindow(toplevel) + , toplevel(toplevel) , sw(NULL) { } EffectWindowImpl::~EffectWindowImpl() { QVariant cachedTextureVariant = data(LanczosCacheRole); if (cachedTextureVariant.isValid()) { GLTexture *cachedTexture = static_cast< GLTexture*>(cachedTextureVariant.value()); delete cachedTexture; } } bool EffectWindowImpl::isPaintingEnabled() { return sceneWindow()->isPaintingEnabled(); } void EffectWindowImpl::enablePainting(int reason) { sceneWindow()->enablePainting(reason); } void EffectWindowImpl::disablePainting(int reason) { sceneWindow()->disablePainting(reason); } void EffectWindowImpl::addRepaint(const QRect& r) { toplevel->addRepaint(r); } void EffectWindowImpl::addRepaint(int x, int y, int w, int h) { toplevel->addRepaint(x, y, w, h); } void EffectWindowImpl::addRepaintFull() { toplevel->addRepaintFull(); } int EffectWindowImpl::desktop() const { return toplevel->desktop(); } bool EffectWindowImpl::isOnActivity(QString activity) const { return toplevel->isOnActivity(activity); } bool EffectWindowImpl::isOnAllActivities() const { return toplevel->isOnAllActivities(); } bool EffectWindowImpl::isOnAllDesktops() const { return desktop() == NET::OnAllDesktops; } QString EffectWindowImpl::caption() const { if (Client* c = dynamic_cast(toplevel)) return c->caption(); else return ""; } QString EffectWindowImpl::windowClass() const { return toplevel->resourceName() + ' ' + toplevel->resourceClass(); } QString EffectWindowImpl::windowRole() const { return toplevel->windowRole(); } QPixmap EffectWindowImpl::icon() const { if (Client* c = dynamic_cast(toplevel)) return c->icon(); return QPixmap(); // TODO } const EffectWindowGroup* EffectWindowImpl::group() const { if (Client* c = dynamic_cast< Client* >(toplevel)) return c->group()->effectGroup(); return NULL; // TODO } bool EffectWindowImpl::isMinimized() const { if (Client* c = dynamic_cast(toplevel)) return c->isMinimized(); else return false; } double EffectWindowImpl::opacity() const { return toplevel->opacity(); } bool EffectWindowImpl::hasAlpha() const { return toplevel->hasAlpha(); } bool EffectWindowImpl::isDeleted() const { return (dynamic_cast(toplevel) != 0); } void EffectWindowImpl::refWindow() { if (Deleted* d = dynamic_cast< Deleted* >(toplevel)) return d->refWindow(); abort(); // TODO } void EffectWindowImpl::unrefWindow() { if (Deleted* d = dynamic_cast< Deleted* >(toplevel)) return d->unrefWindow(true); // delayed abort(); // TODO } void EffectWindowImpl::setWindow(Toplevel* w) { toplevel = w; + setParent(w); } void EffectWindowImpl::setSceneWindow(Scene::Window* w) { sw = w; } int EffectWindowImpl::x() const { return toplevel->x(); } int EffectWindowImpl::y() const { return toplevel->y(); } int EffectWindowImpl::width() const { return toplevel->width(); } int EffectWindowImpl::height() const { return toplevel->height(); } QSize EffectWindowImpl::basicUnit() const { Client *client = dynamic_cast(toplevel); return client ? client->basicUnit() : QSize(1,1); } QRect EffectWindowImpl::geometry() const { return toplevel->geometry(); } QRegion EffectWindowImpl::shape() const { return sw ? sw->shape() : geometry(); } int EffectWindowImpl::screen() const { return toplevel->screen(); } bool EffectWindowImpl::hasOwnShape() const { return toplevel->shape(); } QSize EffectWindowImpl::size() const { return toplevel->size(); } QPoint EffectWindowImpl::pos() const { return toplevel->pos(); } QRect EffectWindowImpl::rect() const { return toplevel->rect(); } QRect EffectWindowImpl::contentsRect() const { return QRect(toplevel->clientPos(), toplevel->clientSize()); } QRect EffectWindowImpl::decorationInnerRect() const { Client *client = dynamic_cast(toplevel); return client ? client->transparentRect() : contentsRect(); } QByteArray EffectWindowImpl::readProperty(long atom, long type, int format) const { return readWindowProperty(window()->window(), atom, type, format); } void EffectWindowImpl::deleteProperty(long int atom) const { deleteWindowProperty(window()->window(), atom); } bool EffectWindowImpl::isMovable() const { if (Client* c = dynamic_cast< Client* >(toplevel)) return c->isMovable(); return false; } bool EffectWindowImpl::isMovableAcrossScreens() const { if (Client* c = dynamic_cast< Client* >(toplevel)) return c->isMovableAcrossScreens(); return false; } bool EffectWindowImpl::isUserMove() const { if (Client* c = dynamic_cast< Client* >(toplevel)) return c->isMove(); return false; } bool EffectWindowImpl::isUserResize() const { if (Client* c = dynamic_cast< Client* >(toplevel)) return c->isResize(); return false; } QRect EffectWindowImpl::iconGeometry() const { if (Client* c = dynamic_cast< Client* >(toplevel)) return c->iconGeometry(); return QRect(); } bool EffectWindowImpl::isDesktop() const { return toplevel->isDesktop(); } bool EffectWindowImpl::isDock() const { return toplevel->isDock(); } bool EffectWindowImpl::isToolbar() const { return toplevel->isToolbar(); } bool EffectWindowImpl::isMenu() const { return toplevel->isMenu(); } bool EffectWindowImpl::isNormalWindow() const { return toplevel->isNormalWindow(); } bool EffectWindowImpl::isSpecialWindow() const { if (Client* c = dynamic_cast(toplevel)) return c->isSpecialWindow(); else return true; } bool EffectWindowImpl::isDialog() const { return toplevel->isDialog(); } bool EffectWindowImpl::isSplash() const { return toplevel->isSplash(); } bool EffectWindowImpl::isUtility() const { return toplevel->isUtility(); } bool EffectWindowImpl::isDropdownMenu() const { return toplevel->isDropdownMenu(); } bool EffectWindowImpl::isPopupMenu() const { return toplevel->isPopupMenu(); } bool EffectWindowImpl::isTooltip() const { return toplevel->isTooltip(); } bool EffectWindowImpl::isNotification() const { return toplevel->isNotification(); } bool EffectWindowImpl::isComboBox() const { return toplevel->isComboBox(); } bool EffectWindowImpl::isDNDIcon() const { return toplevel->isDNDIcon(); } NET::WindowType EffectWindowImpl::windowType() const { return toplevel->windowType(); } bool EffectWindowImpl::isManaged() const { return dynamic_cast< const Client* >(toplevel) != NULL; } bool EffectWindowImpl::acceptsFocus() const { const Client* client = dynamic_cast< const Client* >(toplevel); if (!client) return true; // We don't actually know... return client->wantsInput(); } bool EffectWindowImpl::keepAbove() const { const Client* client = dynamic_cast< const Client* >(toplevel); if (!client) return true; return client->keepAbove(); } bool EffectWindowImpl::isModal() const { if (Client* c = dynamic_cast< Client* >(toplevel)) return c->isModal(); return false; } EffectWindow* EffectWindowImpl::findModal() { if (Client* c = dynamic_cast< Client* >(toplevel)) { if (Client* c2 = c->findModal()) return c2->effectWindow(); } return NULL; } EffectWindowList EffectWindowImpl::mainWindows() const { if (Client* c = dynamic_cast< Client* >(toplevel)) { EffectWindowList ret; ClientList mainclients = c->mainClients(); foreach (Client * tmp, mainclients) ret.append(tmp->effectWindow()); return ret; } return EffectWindowList(); } bool EffectWindowImpl::isSkipSwitcher() const { if (Client* c = dynamic_cast< Client* >(toplevel)) return c->skipSwitcher(); return false; } WindowQuadList EffectWindowImpl::buildQuads(bool force) const { return sceneWindow()->buildQuads(force); } void EffectWindowImpl::minimize() const { if (Client* c = dynamic_cast< Client* >(toplevel)) { c->minimize(); } } void EffectWindowImpl::unminimize() const { if (Client* c = dynamic_cast< Client* >(toplevel)) { c->unminimize(); } } void EffectWindowImpl::closeWindow() const { if (Client* c = dynamic_cast< Client* >(toplevel)) { c->closeWindow(); } } bool EffectWindowImpl::visibleInClientGroup() const { if (Client* c = dynamic_cast< Client* >(toplevel)) { if (!c->clientGroup()) return true; return c == c->clientGroup()->visible(); } return false; } void EffectWindowImpl::setData(int role, const QVariant &data) { if (!data.isNull()) dataMap[ role ] = data; else dataMap.remove(role); } QVariant EffectWindowImpl::data(int role) const { if (!dataMap.contains(role)) return QVariant(); return dataMap[ role ]; } EffectWindow* effectWindow(Toplevel* w) { EffectWindowImpl* ret = w->effectWindow(); return ret; } EffectWindow* effectWindow(Scene::Window* w) { EffectWindowImpl* ret = w->window()->effectWindow(); ret->setSceneWindow(w); return ret; } void EffectWindowImpl::registerThumbnail(ThumbnailItem *item) { insertThumbnail(item); connect(item, SIGNAL(destroyed(QObject*)), SLOT(thumbnailDestroyed(QObject*))); connect(item, SIGNAL(wIdChanged(qulonglong)), SLOT(thumbnailTargetChanged())); } void EffectWindowImpl::thumbnailDestroyed(QObject *object) { // we know it is a ThumbnailItem m_thumbnails.remove(static_cast(object)); } void EffectWindowImpl::thumbnailTargetChanged() { if (ThumbnailItem *item = qobject_cast(sender())) { insertThumbnail(item); } } void EffectWindowImpl::insertThumbnail(ThumbnailItem *item) { EffectWindow *w = effects->findWindow(item->wId()); if (w) { m_thumbnails.insert(item, QWeakPointer(static_cast(w))); } else { m_thumbnails.insert(item, QWeakPointer()); } } //**************************************** // EffectWindowGroupImpl //**************************************** EffectWindowList EffectWindowGroupImpl::members() const { EffectWindowList ret; foreach (Toplevel * c, group->members()) ret.append(c->effectWindow()); return ret; } //**************************************** // EffectFrameImpl //**************************************** EffectFrameImpl::EffectFrameImpl(EffectFrameStyle style, bool staticSize, QPoint position, Qt::Alignment alignment) : QObject(0) , EffectFrame() , m_style(style) , m_static(staticSize) , m_point(position) , m_alignment(alignment) , m_shader(NULL) { if (m_style == EffectFrameStyled) { m_frame.setImagePath("widgets/background"); m_frame.setCacheAllRenderedFrames(true); connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(plasmaThemeChanged())); } m_selection.setImagePath("widgets/viewitem"); m_selection.setElementPrefix("hover"); m_selection.setCacheAllRenderedFrames(true); m_selection.setEnabledBorders(Plasma::FrameSvg::AllBorders); if (effects->compositingType() == OpenGLCompositing) { m_sceneFrame = new SceneOpenGL::EffectFrame(this); } else if (effects->compositingType() == XRenderCompositing) { #ifdef KWIN_HAVE_XRENDER_COMPOSITING m_sceneFrame = new SceneXrender::EffectFrame(this); #endif } else { // that should not happen and will definitely crash! m_sceneFrame = NULL; } } EffectFrameImpl::~EffectFrameImpl() { delete m_sceneFrame; } const QFont& EffectFrameImpl::font() const { return m_font; } void EffectFrameImpl::setFont(const QFont& font) { if (m_font == font) { return; } m_font = font; QRect oldGeom = m_geometry; if (!m_text.isEmpty()) { autoResize(); } if (oldGeom == m_geometry) { // Wasn't updated in autoResize() m_sceneFrame->freeTextFrame(); } } void EffectFrameImpl::free() { m_sceneFrame->free(); } const QRect& EffectFrameImpl::geometry() const { return m_geometry; } void EffectFrameImpl::setGeometry(const QRect& geometry, bool force) { QRect oldGeom = m_geometry; m_geometry = geometry; if (m_geometry == oldGeom && !force) { return; } effects->addRepaint(oldGeom); effects->addRepaint(m_geometry); if (m_geometry.size() == oldGeom.size() && !force) { return; } if (m_style == EffectFrameStyled) { qreal left, top, right, bottom; m_frame.getMargins(left, top, right, bottom); // m_geometry is the inner geometry m_frame.resizeFrame(m_geometry.adjusted(-left, -top, right, bottom).size()); } free(); } const QPixmap& EffectFrameImpl::icon() const { return m_icon; } void EffectFrameImpl::setIcon(const QPixmap& icon) { m_icon = icon; if (isCrossFade()) { m_sceneFrame->crossFadeIcon(); } if (m_iconSize.isEmpty()) { // Set a size if we don't already have one setIconSize(m_icon.size()); } m_sceneFrame->freeIconFrame(); } const QSize& EffectFrameImpl::iconSize() const { return m_iconSize; } void EffectFrameImpl::setIconSize(const QSize& size) { if (m_iconSize == size) { return; } m_iconSize = size; autoResize(); m_sceneFrame->freeIconFrame(); } void EffectFrameImpl::plasmaThemeChanged() { free(); } void EffectFrameImpl::render(QRegion region, double opacity, double frameOpacity) { if (m_geometry.isEmpty()) { return; // Nothing to display } m_shader = NULL; effects->paintEffectFrame(this, region, opacity, frameOpacity); } void EffectFrameImpl::finalRender(QRegion region, double opacity, double frameOpacity) const { region = infiniteRegion(); // TODO: Old region doesn't seem to work with OpenGL m_sceneFrame->render(region, opacity, frameOpacity); } Qt::Alignment EffectFrameImpl::alignment() const { return m_alignment; } void EffectFrameImpl::align(QRect &geometry) { if (m_alignment & Qt::AlignLeft) geometry.moveLeft(m_point.x()); else if (m_alignment & Qt::AlignRight) geometry.moveLeft(m_point.x() - geometry.width()); else geometry.moveLeft(m_point.x() - geometry.width() / 2); if (m_alignment & Qt::AlignTop) geometry.moveTop(m_point.y()); else if (m_alignment & Qt::AlignBottom) geometry.moveTop(m_point.y() - geometry.height()); else geometry.moveTop(m_point.y() - geometry.height() / 2); } void EffectFrameImpl::setAlignment(Qt::Alignment alignment) { m_alignment = alignment; align(m_geometry); setGeometry(m_geometry); } void EffectFrameImpl::setPosition(const QPoint& point) { m_point = point; QRect geometry = m_geometry; // this is important, setGeometry need call repaint for old & new geometry align(geometry); setGeometry(geometry); } const QString& EffectFrameImpl::text() const { return m_text; } void EffectFrameImpl::setText(const QString& text) { if (m_text == text) { return; } if (isCrossFade()) { m_sceneFrame->crossFadeText(); } m_text = text; QRect oldGeom = m_geometry; autoResize(); if (oldGeom == m_geometry) { // Wasn't updated in autoResize() m_sceneFrame->freeTextFrame(); } } void EffectFrameImpl::setSelection(const QRect& selection) { if (selection == m_selectionGeometry) { return; } m_selectionGeometry = selection; if (m_selectionGeometry.size() != m_selection.frameSize().toSize()) { m_selection.resizeFrame(m_selectionGeometry.size()); } // TODO; optimize to only recreate when resizing m_sceneFrame->freeSelection(); } void EffectFrameImpl::autoResize() { if (m_static) return; // Not automatically resizing QRect geometry; // Set size if (!m_text.isEmpty()) { QFontMetrics metrics(m_font); geometry.setSize(metrics.size(0, m_text)); } if (!m_icon.isNull() && !m_iconSize.isEmpty()) { geometry.setLeft(-m_iconSize.width()); if (m_iconSize.height() > geometry.height()) geometry.setHeight(m_iconSize.height()); } align(geometry); setGeometry(geometry); } QColor EffectFrameImpl::styledTextColor() { return Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); } } // namespace diff --git a/effects.h b/effects.h index 30be28f35..98db1fc86 100644 --- a/effects.h +++ b/effects.h @@ -1,475 +1,475 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2006 Lubos Lunak Copyright (C) 2010, 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #ifndef KWIN_EFFECTSIMPL_H #define KWIN_EFFECTSIMPL_H #include "kwineffects.h" #include "scene.h" #include #include #include class KService; namespace KWin { class ThumbnailItem; class Client; class Deleted; class Unmanaged; class EffectsHandlerImpl : public EffectsHandler { Q_OBJECT public: EffectsHandlerImpl(CompositingType type); virtual ~EffectsHandlerImpl(); virtual void prePaintScreen(ScreenPrePaintData& data, int time); virtual void paintScreen(int mask, QRegion region, ScreenPaintData& data); virtual void postPaintScreen(); virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time); virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); virtual void postPaintWindow(EffectWindow* w); virtual void paintEffectFrame(EffectFrame* frame, QRegion region, double opacity, double frameOpacity); bool provides(Effect::Feature ef); virtual void drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); virtual void buildQuads(EffectWindow* w, WindowQuadList& quadList); virtual void activateWindow(EffectWindow* c); virtual EffectWindow* activeWindow() const; virtual void moveWindow(EffectWindow* w, const QPoint& pos, bool snap = false, double snapAdjust = 1.0); virtual void windowToDesktop(EffectWindow* w, int desktop); virtual void windowToScreen(EffectWindow* w, int screen); virtual void setShowingDesktop(bool showing); virtual QString currentActivity() const; virtual int currentDesktop() const; virtual int numberOfDesktops() const; virtual void setCurrentDesktop(int desktop); virtual void setNumberOfDesktops(int desktops); virtual QSize desktopGridSize() const; virtual int desktopGridWidth() const; virtual int desktopGridHeight() const; virtual int workspaceWidth() const; virtual int workspaceHeight() const; virtual int desktopAtCoords(QPoint coords) const; virtual QPoint desktopGridCoords(int id) const; virtual QPoint desktopCoords(int id) const; virtual int desktopAbove(int desktop = 0, bool wrap = true) const; virtual int desktopToRight(int desktop = 0, bool wrap = true) const; virtual int desktopBelow(int desktop = 0, bool wrap = true) const; virtual int desktopToLeft(int desktop = 0, bool wrap = true) const; virtual QString desktopName(int desktop) const; virtual bool optionRollOverDesktops() const; virtual int displayWidth() const; virtual int displayHeight() const; virtual QPoint cursorPos() const; virtual bool grabKeyboard(Effect* effect); virtual void ungrabKeyboard(); virtual void* getProxy(QString name); virtual void startMousePolling(); virtual void stopMousePolling(); virtual EffectWindow* findWindow(WId id) const; virtual EffectWindowList stackingOrder() const; virtual void setElevatedWindow(EffectWindow* w, bool set); virtual void setTabBoxWindow(EffectWindow*); virtual void setTabBoxDesktop(int); virtual EffectWindowList currentTabBoxWindowList() const; virtual void refTabBox(); virtual void unrefTabBox(); virtual void closeTabBox(); virtual QList< int > currentTabBoxDesktopList() const; virtual int currentTabBoxDesktop() const; virtual EffectWindow* currentTabBoxWindow() const; virtual void setActiveFullScreenEffect(Effect* e); virtual Effect* activeFullScreenEffect() const; virtual void addRepaintFull(); virtual void addRepaint(const QRect& r); virtual void addRepaint(const QRegion& r); virtual void addRepaint(int x, int y, int w, int h); virtual int activeScreen() const; virtual int numScreens() const; virtual int screenNumber(const QPoint& pos) const; virtual QRect clientArea(clientAreaOption, int screen, int desktop) const; virtual QRect clientArea(clientAreaOption, const EffectWindow* c) const; virtual QRect clientArea(clientAreaOption, const QPoint& p, int desktop) const; virtual double animationTimeFactor() const; virtual WindowQuadType newWindowQuadType(); virtual Window createInputWindow(Effect* e, int x, int y, int w, int h, const QCursor& cursor); using EffectsHandler::createInputWindow; virtual void destroyInputWindow(Window w); virtual bool checkInputWindowEvent(XEvent* e); virtual void checkInputWindowStacking(); virtual void checkElectricBorder(const QPoint &pos, Time time); virtual void reserveElectricBorder(ElectricBorder border); virtual void unreserveElectricBorder(ElectricBorder border); virtual void reserveElectricBorderSwitching(bool reserve); virtual unsigned long xrenderBufferPicture(); virtual void reconfigure(); virtual void registerPropertyType(long atom, bool reg); virtual QByteArray readRootProperty(long atom, long type, int format) const; virtual void deleteRootProperty(long atom) const; virtual bool hasDecorationShadows() const; virtual bool decorationsHaveAlpha() const; virtual bool decorationSupportsBlurBehind() const; virtual EffectFrame* effectFrame(EffectFrameStyle style, bool staticSize, const QPoint& position, Qt::Alignment alignment) const; virtual QVariant kwinOption(KWinOption kwopt); // internal (used by kwin core or compositing code) void startPaint(); bool borderActivated(ElectricBorder border); void grabbedKeyboardEvent(QKeyEvent* e); bool hasKeyboardGrab() const; void desktopResized(const QSize &size); virtual void reloadEffect(Effect *effect); bool loadEffect(const QString& name, bool checkDefault = false); void toggleEffect(const QString& name); void unloadEffect(const QString& name); void reconfigureEffect(const QString& name); bool isEffectLoaded(const QString& name); QStringList loadedEffects() const; QStringList listOfEffects() const; QList elevatedWindows() const; QStringList activeEffects() const; public Q_SLOTS: void slotClientGroupItemSwitched(EffectWindow* from, EffectWindow* to); void slotClientGroupItemAdded(EffectWindow* from, EffectWindow* to); void slotClientGroupItemRemoved(EffectWindow* c, EffectWindow* group); void slotShowOutline(const QRect &geometry); void slotHideOutline(); protected Q_SLOTS: void slotDesktopChanged(int old); void slotClientAdded(KWin::Client *c); void slotClientShown(KWin::Toplevel*); void slotUnmanagedAdded(KWin::Unmanaged *u); void slotWindowClosed(KWin::Toplevel *c); void slotClientActivated(KWin::Client *c); void slotDeletedRemoved(KWin::Deleted *d); void slotClientMaximized(KWin::Client *c, KDecorationDefines::MaximizeMode maxMode); void slotClientStartUserMovedResized(KWin::Client *c); void slotClientStepUserMovedResized(KWin::Client *c, const QRect &geometry); void slotClientFinishUserMovedResized(KWin::Client *c); void slotOpacityChanged(KWin::Toplevel *t, qreal oldOpacity); void slotClientMinimized(KWin::Client *c, bool animate); void slotClientUnminimized(KWin::Client *c, bool animate); void slotGeometryShapeChanged(KWin::Toplevel *t, const QRect &old); void slotWindowDamaged(KWin::Toplevel *t, const QRect& r); void slotPropertyNotify(KWin::Toplevel *t, long atom); void slotPropertyNotify(long atom); protected: KLibrary* findEffectLibrary(KService* service); void effectsChanged(); void setupClientConnections(KWin::Client *c); void setupUnmanagedConnections(KWin::Unmanaged *u); Effect* keyboard_grab_effect; Effect* fullscreen_effect; QList elevated_windows; QMultiMap< int, EffectPair > effect_order; QHash< long, int > registered_atoms; int next_window_quad_type; int mouse_poll_ref_count; private: QList< Effect* > m_activeEffects; QList< Effect* >::iterator m_currentDrawWindowIterator; QList< Effect* >::iterator m_currentPaintWindowIterator; QList< Effect* >::iterator m_currentPaintEffectFrameIterator; QList< Effect* >::iterator m_currentPaintScreenIterator; QList< Effect* >::iterator m_currentBuildQuadsIterator; }; -class EffectWindowImpl : public QObject, public EffectWindow +class EffectWindowImpl : public EffectWindow { Q_OBJECT public: - EffectWindowImpl(); + EffectWindowImpl(Toplevel *toplevel); virtual ~EffectWindowImpl(); virtual void enablePainting(int reason); virtual void disablePainting(int reason); virtual bool isPaintingEnabled(); virtual void addRepaint(const QRect& r); virtual void addRepaint(int x, int y, int w, int h); virtual void addRepaintFull(); virtual void refWindow(); virtual void unrefWindow(); virtual bool isDeleted() const; virtual bool isOnActivity(QString id) const; virtual bool isOnAllActivities() const; virtual bool isOnAllDesktops() const; virtual int desktop() const; // prefer isOnXXX() virtual bool isMinimized() const; virtual double opacity() const; virtual bool hasAlpha() const; virtual QString caption() const; virtual QPixmap icon() const; virtual QString windowClass() const; virtual QString windowRole() const; virtual const EffectWindowGroup* group() const; virtual int x() const; virtual int y() const; virtual int width() const; virtual int height() const; virtual QSize basicUnit() const; virtual QRect geometry() const; virtual QRegion shape() const; virtual int screen() const; virtual bool hasOwnShape() const; virtual QPoint pos() const; virtual QSize size() const; virtual QRect rect() const; virtual bool isMovable() const; virtual bool isMovableAcrossScreens() const; virtual bool isUserMove() const; virtual bool isUserResize() const; virtual QRect iconGeometry() const; virtual QRect contentsRect() const; virtual QRect decorationInnerRect() const; virtual QByteArray readProperty(long atom, long type, int format) const; virtual void deleteProperty(long atom) const; virtual bool isDesktop() const; virtual bool isDock() const; virtual bool isToolbar() const; virtual bool isMenu() const; virtual bool isNormalWindow() const; // normal as in 'NET::Normal or NET::Unknown non-transient' virtual bool isSpecialWindow() const; virtual bool isDialog() const; virtual bool isSplash() const; virtual bool isUtility() const; virtual bool isDropdownMenu() const; virtual bool isPopupMenu() const; // a context popup, not dropdown, not torn-off virtual bool isTooltip() const; virtual bool isNotification() const; virtual bool isComboBox() const; virtual bool isDNDIcon() const; virtual NET::WindowType windowType() const; virtual bool isManaged() const; // managed or override-redirect virtual bool acceptsFocus() const; virtual bool keepAbove() const; virtual bool isModal() const; virtual EffectWindow* findModal(); virtual EffectWindowList mainWindows() const; virtual bool isSkipSwitcher() const; virtual WindowQuadList buildQuads(bool force = false) const; virtual void minimize() const; virtual void unminimize() const; virtual void closeWindow() const; virtual bool visibleInClientGroup() const; const Toplevel* window() const; Toplevel* window(); void setWindow(Toplevel* w); // internal void setSceneWindow(Scene::Window* w); // internal const Scene::Window* sceneWindow() const; // internal Scene::Window* sceneWindow(); // internal void setData(int role, const QVariant &data); QVariant data(int role) const; void registerThumbnail(ThumbnailItem *item); QHash > const &thumbnails() const { return m_thumbnails; } private Q_SLOTS: void thumbnailDestroyed(QObject *object); void thumbnailTargetChanged(); private: void insertThumbnail(ThumbnailItem *item); Toplevel* toplevel; Scene::Window* sw; // This one is used only during paint pass. QHash dataMap; QHash > m_thumbnails; }; class EffectWindowGroupImpl : public EffectWindowGroup { public: EffectWindowGroupImpl(Group* g); virtual EffectWindowList members() const; private: Group* group; }; class EffectFrameImpl : public QObject, public EffectFrame { Q_OBJECT public: explicit EffectFrameImpl(EffectFrameStyle style, bool staticSize = true, QPoint position = QPoint(-1, -1), Qt::Alignment alignment = Qt::AlignCenter); virtual ~EffectFrameImpl(); virtual void free(); virtual void render(QRegion region = infiniteRegion(), double opacity = 1.0, double frameOpacity = 1.0); virtual Qt::Alignment alignment() const; virtual void setAlignment(Qt::Alignment alignment); virtual const QFont& font() const; virtual void setFont(const QFont& font); virtual const QRect& geometry() const; virtual void setGeometry(const QRect& geometry, bool force = false); virtual const QPixmap& icon() const; virtual void setIcon(const QPixmap& icon); virtual const QSize& iconSize() const; virtual void setIconSize(const QSize& size); virtual void setPosition(const QPoint& point); virtual const QString& text() const; virtual void setText(const QString& text); virtual EffectFrameStyle style() const { return m_style; }; Plasma::FrameSvg& frame() { return m_frame; } bool isStatic() const { return m_static; }; void finalRender(QRegion region, double opacity, double frameOpacity) const; virtual void setShader(GLShader* shader) { m_shader = shader; } virtual GLShader* shader() const { return m_shader; } virtual void setSelection(const QRect& selection); const QRect& selection() const { return m_selectionGeometry; } Plasma::FrameSvg& selectionFrame() { return m_selection; } /** * The foreground text color as specified by the default Plasma theme. */ static QColor styledTextColor(); private Q_SLOTS: void plasmaThemeChanged(); private: Q_DISABLE_COPY(EffectFrameImpl) // As we need to use Qt slots we cannot copy this class void align(QRect &geometry); // positions geometry around m_point respecting m_alignment void autoResize(); // Auto-resize if not a static size EffectFrameStyle m_style; Plasma::FrameSvg m_frame; // TODO: share between all EffectFrames Plasma::FrameSvg m_selection; // Position bool m_static; QPoint m_point; Qt::Alignment m_alignment; QRect m_geometry; // Contents QString m_text; QFont m_font; QPixmap m_icon; QSize m_iconSize; QRect m_selectionGeometry; Scene::EffectFrame* m_sceneFrame; GLShader* m_shader; }; inline QList EffectsHandlerImpl::elevatedWindows() const { return elevated_windows; } inline EffectWindowGroupImpl::EffectWindowGroupImpl(Group* g) : group(g) { } EffectWindow* effectWindow(Toplevel* w); EffectWindow* effectWindow(Scene::Window* w); inline const Scene::Window* EffectWindowImpl::sceneWindow() const { return sw; } inline Scene::Window* EffectWindowImpl::sceneWindow() { return sw; } inline const Toplevel* EffectWindowImpl::window() const { return toplevel; } inline Toplevel* EffectWindowImpl::window() { return toplevel; } } // namespace #endif diff --git a/libkwineffects/kwineffects.cpp b/libkwineffects/kwineffects.cpp index 1ad53bce1..9e7e7b1ca 100644 --- a/libkwineffects/kwineffects.cpp +++ b/libkwineffects/kwineffects.cpp @@ -1,1073 +1,1074 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2006 Lubos Lunak Copyright (C) 2009 Lucas Murray This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "kwineffects.h" #include "kwinxrenderutils.h" #include #include #include #include #include #include #include #include #include #include #include #include #ifdef KWIN_HAVE_XRENDER_COMPOSITING #include #include #endif namespace KWin { void WindowPrePaintData::setTranslucent() { mask |= Effect::PAINT_WINDOW_TRANSLUCENT; mask &= ~Effect::PAINT_WINDOW_OPAQUE; clip = QRegion(); // cannot clip, will be transparent } void WindowPrePaintData::setTransformed() { mask |= Effect::PAINT_WINDOW_TRANSFORMED; } WindowPaintData::WindowPaintData(EffectWindow* w) : opacity(w->opacity()) , contents_opacity(1.0) , decoration_opacity(1.0) , xScale(1) , yScale(1) , zScale(1) , xTranslate(0) , yTranslate(0) , zTranslate(0) , saturation(1) , brightness(1) , shader(NULL) , rotation(NULL) { quads = w->buildQuads(); } ScreenPaintData::ScreenPaintData() : xScale(1) , yScale(1) , zScale(1) , xTranslate(0) , yTranslate(0) , zTranslate(0) , rotation(NULL) { } RotationData::RotationData() : axis(ZAxis) , angle(0.0) , xRotationPoint(0.0) , yRotationPoint(0.0) , zRotationPoint(0.0) { } //**************************************** // Effect //**************************************** Effect::Effect() { } Effect::~Effect() { } void Effect::reconfigure(ReconfigureFlags) { } void* Effect::proxy() { return NULL; } void Effect::windowInputMouseEvent(Window, QEvent*) { } void Effect::grabbedKeyboardEvent(QKeyEvent*) { } bool Effect::borderActivated(ElectricBorder) { return false; } void Effect::prePaintScreen(ScreenPrePaintData& data, int time) { effects->prePaintScreen(data, time); } void Effect::paintScreen(int mask, QRegion region, ScreenPaintData& data) { effects->paintScreen(mask, region, data); } void Effect::postPaintScreen() { effects->postPaintScreen(); } void Effect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time) { effects->prePaintWindow(w, data, time); } void Effect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) { effects->paintWindow(w, mask, region, data); } void Effect::postPaintWindow(EffectWindow* w) { effects->postPaintWindow(w); } void Effect::paintEffectFrame(KWin::EffectFrame* frame, QRegion region, double opacity, double frameOpacity) { effects->paintEffectFrame(frame, region, opacity, frameOpacity); } bool Effect::provides(Feature) { return false; } bool Effect::isActive() const { return true; } void Effect::drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) { effects->drawWindow(w, mask, region, data); } void Effect::buildQuads(EffectWindow* w, WindowQuadList& quadList) { effects->buildQuads(w, quadList); } void Effect::setPositionTransformations(WindowPaintData& data, QRect& region, EffectWindow* w, const QRect& r, Qt::AspectRatioMode aspect) { QSize size = w->size(); size.scale(r.size(), aspect); data.xScale = size.width() / double(w->width()); data.yScale = size.height() / double(w->height()); int width = int(w->width() * data.xScale); int height = int(w->height() * data.yScale); int x = r.x() + (r.width() - width) / 2; int y = r.y() + (r.height() - height) / 2; region = QRect(x, y, width, height); data.xTranslate = x - w->x(); data.yTranslate = y - w->y(); } int Effect::displayWidth() { return KWin::displayWidth(); } int Effect::displayHeight() { return KWin::displayHeight(); } QPoint Effect::cursorPos() { return effects->cursorPos(); } double Effect::animationTime(const KConfigGroup& cfg, const QString& key, int defaultTime) { int time = cfg.readEntry(key, 0); return time != 0 ? time : qMax(defaultTime * effects->animationTimeFactor(), 1.); } double Effect::animationTime(int defaultTime) { // at least 1ms, otherwise 0ms times can break some things return qMax(defaultTime * effects->animationTimeFactor(), 1.); } //**************************************** // EffectsHandler //**************************************** EffectsHandler::EffectsHandler(CompositingType type) : compositing_type(type) { if (compositing_type == NoCompositing) return; KWin::effects = this; } EffectsHandler::~EffectsHandler() { // All effects should already be unloaded by Impl dtor assert(loaded_effects.count() == 0); } Window EffectsHandler::createInputWindow(Effect* e, const QRect& r, const QCursor& cursor) { return createInputWindow(e, r.x(), r.y(), r.width(), r.height(), cursor); } Window EffectsHandler::createFullScreenInputWindow(Effect* e, const QCursor& cursor) { return createInputWindow(e, 0, 0, displayWidth(), displayHeight(), cursor); } CompositingType EffectsHandler::compositingType() const { return compositing_type; } void EffectsHandler::sendReloadMessage(const QString& effectname) { QDBusMessage message = QDBusMessage::createMethodCall("org.kde.kwin", "/KWin", "org.kde.KWin", "reconfigureEffect"); message << QString("kwin4_effect_" + effectname); QDBusConnection::sessionBus().send(message); } KConfigGroup EffectsHandler::effectConfig(const QString& effectname) { KSharedConfig::Ptr kwinconfig = KSharedConfig::openConfig("kwinrc", KConfig::NoGlobals); return kwinconfig->group("Effect-" + effectname); } EffectsHandler* effects = 0; //**************************************** // EffectWindow //**************************************** -EffectWindow::EffectWindow() +EffectWindow::EffectWindow(QObject *parent) + : QObject(parent) { } EffectWindow::~EffectWindow() { } bool EffectWindow::isOnCurrentActivity() const { return isOnActivity(effects->currentActivity()); } bool EffectWindow::isOnCurrentDesktop() const { return isOnDesktop(effects->currentDesktop()); } bool EffectWindow::isOnDesktop(int d) const { return desktop() == d || isOnAllDesktops(); } bool EffectWindow::hasDecoration() const { return contentsRect() != QRect(0, 0, width(), height()); } //**************************************** // EffectWindowGroup //**************************************** EffectWindowGroup::~EffectWindowGroup() { } //**************************************** // GlobalShortcutsEditor //**************************************** GlobalShortcutsEditor::GlobalShortcutsEditor(QWidget *parent) : KShortcutsEditor(parent, GlobalAction) { } /*************************************************************** WindowQuad ***************************************************************/ WindowQuad WindowQuad::makeSubQuad(double x1, double y1, double x2, double y2) const { assert(x1 < x2 && y1 < y2 && x1 >= left() && x2 <= right() && y1 >= top() && y2 <= bottom()); #ifndef NDEBUG if (isTransformed()) kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ; #endif WindowQuad ret(*this); // vertices are clockwise starting from topleft ret.verts[ 0 ].px = x1; ret.verts[ 3 ].px = x1; ret.verts[ 1 ].px = x2; ret.verts[ 2 ].px = x2; ret.verts[ 0 ].py = y1; ret.verts[ 1 ].py = y1; ret.verts[ 2 ].py = y2; ret.verts[ 3 ].py = y2; // original x/y are supposed to be the same, no transforming is done here ret.verts[ 0 ].ox = x1; ret.verts[ 3 ].ox = x1; ret.verts[ 1 ].ox = x2; ret.verts[ 2 ].ox = x2; ret.verts[ 0 ].oy = y1; ret.verts[ 1 ].oy = y1; ret.verts[ 2 ].oy = y2; ret.verts[ 3 ].oy = y2; double my_tleft = verts[ 0 ].tx; double my_tright = verts[ 2 ].tx; double my_ttop = verts[ 0 ].ty; double my_tbottom = verts[ 2 ].ty; double tleft = (x1 - left()) / (right() - left()) * (my_tright - my_tleft) + my_tleft; double tright = (x2 - left()) / (right() - left()) * (my_tright - my_tleft) + my_tleft; double ttop = (y1 - top()) / (bottom() - top()) * (my_tbottom - my_ttop) + my_ttop; double tbottom = (y2 - top()) / (bottom() - top()) * (my_tbottom - my_ttop) + my_ttop; ret.verts[ 0 ].tx = tleft; ret.verts[ 3 ].tx = tleft; ret.verts[ 1 ].tx = tright; ret.verts[ 2 ].tx = tright; ret.verts[ 0 ].ty = ttop; ret.verts[ 1 ].ty = ttop; ret.verts[ 2 ].ty = tbottom; ret.verts[ 3 ].ty = tbottom; return ret; } bool WindowQuad::smoothNeeded() const { // smoothing is needed if the width or height of the quad does not match the original size double width = verts[ 1 ].ox - verts[ 0 ].ox; double height = verts[ 2 ].oy - verts[ 1 ].oy; return(verts[ 1 ].px - verts[ 0 ].px != width || verts[ 2 ].px - verts[ 3 ].px != width || verts[ 2 ].py - verts[ 1 ].py != height || verts[ 3 ].py - verts[ 0 ].py != height); } /*************************************************************** WindowQuadList ***************************************************************/ WindowQuadList WindowQuadList::splitAtX(double x) const { WindowQuadList ret; foreach (const WindowQuad & quad, *this) { #ifndef NDEBUG if (quad.isTransformed()) kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ; #endif bool wholeleft = true; bool wholeright = true; for (int i = 0; i < 4; ++i) { if (quad[ i ].x() < x) wholeright = false; if (quad[ i ].x() > x) wholeleft = false; } if (wholeleft || wholeright) { // is whole in one split part ret.append(quad); continue; } if (quad.left() == quad.right()) { // quad has no size ret.append(quad); continue; } ret.append(quad.makeSubQuad(quad.left(), quad.top(), x, quad.bottom())); ret.append(quad.makeSubQuad(x, quad.top(), quad.right(), quad.bottom())); } return ret; } WindowQuadList WindowQuadList::splitAtY(double y) const { WindowQuadList ret; foreach (const WindowQuad & quad, *this) { #ifndef NDEBUG if (quad.isTransformed()) kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ; #endif bool wholetop = true; bool wholebottom = true; for (int i = 0; i < 4; ++i) { if (quad[ i ].y() < y) wholebottom = false; if (quad[ i ].y() > y) wholetop = false; } if (wholetop || wholebottom) { // is whole in one split part ret.append(quad); continue; } if (quad.top() == quad.bottom()) { // quad has no size ret.append(quad); continue; } ret.append(quad.makeSubQuad(quad.left(), quad.top(), quad.right(), y)); ret.append(quad.makeSubQuad(quad.left(), y, quad.right(), quad.bottom())); } return ret; } WindowQuadList WindowQuadList::makeGrid(int maxquadsize) const { if (empty()) return *this; // find the bounding rectangle double left = first().left(); double right = first().right(); double top = first().top(); double bottom = first().bottom(); foreach (const WindowQuad & quad, *this) { #ifndef NDEBUG if (quad.isTransformed()) kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ; #endif left = qMin(left, quad.left()); right = qMax(right, quad.right()); top = qMin(top, quad.top()); bottom = qMax(bottom, quad.bottom()); } WindowQuadList ret; for (double x = left; x < right; x += maxquadsize) { for (double y = top; y < bottom; y += maxquadsize) { foreach (const WindowQuad & quad, *this) { if (QRectF(QPointF(quad.left(), quad.top()), QPointF(quad.right(), quad.bottom())) .intersects(QRectF(x, y, maxquadsize, maxquadsize))) { ret.append(quad.makeSubQuad(qMax(x, quad.left()), qMax(y, quad.top()), qMin(quad.right(), x + maxquadsize), qMin(quad.bottom(), y + maxquadsize))); } } } } return ret; } WindowQuadList WindowQuadList::makeRegularGrid(int xSubdivisions, int ySubdivisions) const { if (empty()) return *this; // find the bounding rectangle double left = first().left(); double right = first().right(); double top = first().top(); double bottom = first().bottom(); foreach (const WindowQuad & quad, *this) { #ifndef NDEBUG if (quad.isTransformed()) kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ; #endif left = qMin(left, quad.left()); right = qMax(right, quad.right()); top = qMin(top, quad.top()); bottom = qMax(bottom, quad.bottom()); } double xincrement = (right - left) / xSubdivisions; double yincrement = (bottom - top) / ySubdivisions; WindowQuadList ret; for (double y = top; y < bottom; y += yincrement) { for (double x = left; x < right; x += xincrement) { foreach (const WindowQuad & quad, *this) { if (QRectF(QPointF(quad.left(), quad.top()), QPointF(quad.right(), quad.bottom())) .intersects(QRectF(x, y, xincrement, yincrement))) { ret.append(quad.makeSubQuad(qMax(x, quad.left()), qMax(y, quad.top()), qMin(quad.right(), x + xincrement), qMin(quad.bottom(), y + yincrement))); } } } } return ret; } void WindowQuadList::makeArrays(float** vertices, float** texcoords, const QSizeF& size, bool yInverted) const { *vertices = new float[ count() * 6 * 2 ]; *texcoords = new float[ count() * 6 * 2 ]; float* vpos = *vertices; float* tpos = *texcoords; for (int i = 0; i < count(); ++i) { *vpos++ = at(i)[ 1 ].x(); *vpos++ = at(i)[ 1 ].y(); *vpos++ = at(i)[ 0 ].x(); *vpos++ = at(i)[ 0 ].y(); *vpos++ = at(i)[ 3 ].x(); *vpos++ = at(i)[ 3 ].y(); *vpos++ = at(i)[ 3 ].x(); *vpos++ = at(i)[ 3 ].y(); *vpos++ = at(i)[ 2 ].x(); *vpos++ = at(i)[ 2 ].y(); *vpos++ = at(i)[ 1 ].x(); *vpos++ = at(i)[ 1 ].y(); if (yInverted) { *tpos++ = at(i)[ 1 ].tx / size.width(); *tpos++ = at(i)[ 1 ].ty / size.height(); *tpos++ = at(i)[ 0 ].tx / size.width(); *tpos++ = at(i)[ 0 ].ty / size.height(); *tpos++ = at(i)[ 3 ].tx / size.width(); *tpos++ = at(i)[ 3 ].ty / size.height(); *tpos++ = at(i)[ 3 ].tx / size.width(); *tpos++ = at(i)[ 3 ].ty / size.height(); *tpos++ = at(i)[ 2 ].tx / size.width(); *tpos++ = at(i)[ 2 ].ty / size.height(); *tpos++ = at(i)[ 1 ].tx / size.width(); *tpos++ = at(i)[ 1 ].ty / size.height(); } else { *tpos++ = at(i)[ 1 ].tx / size.width(); *tpos++ = 1.0f - at(i)[ 1 ].ty / size.height(); *tpos++ = at(i)[ 0 ].tx / size.width(); *tpos++ = 1.0f - at(i)[ 0 ].ty / size.height(); *tpos++ = at(i)[ 3 ].tx / size.width(); *tpos++ = 1.0f - at(i)[ 3 ].ty / size.height(); *tpos++ = at(i)[ 3 ].tx / size.width(); *tpos++ = 1.0f - at(i)[ 3 ].ty / size.height(); *tpos++ = at(i)[ 2 ].tx / size.width(); *tpos++ = 1.0f - at(i)[ 2 ].ty / size.height(); *tpos++ = at(i)[ 1 ].tx / size.width(); *tpos++ = 1.0f - at(i)[ 1 ].ty / size.height(); } } } WindowQuadList WindowQuadList::select(WindowQuadType type) const { foreach (const WindowQuad & q, *this) { if (q.type() != type) { // something else than ones to select, make a copy and filter WindowQuadList ret; foreach (const WindowQuad & q, *this) { if (q.type() == type) ret.append(q); } return ret; } } return *this; // nothing to filter out } WindowQuadList WindowQuadList::filterOut(WindowQuadType type) const { foreach (const WindowQuad & q, *this) { if (q.type() == type) { // something to filter out, make a copy and filter WindowQuadList ret; foreach (const WindowQuad & q, *this) { if (q.type() != type) ret.append(q); } return ret; } } return *this; // nothing to filter out } bool WindowQuadList::smoothNeeded() const { foreach (const WindowQuad & q, *this) if (q.smoothNeeded()) return true; return false; } bool WindowQuadList::isTransformed() const { foreach (const WindowQuad & q, *this) if (q.isTransformed()) return true; return false; } /*************************************************************** PaintClipper ***************************************************************/ QStack< QRegion >* PaintClipper::areas = NULL; PaintClipper::PaintClipper(const QRegion& allowed_area) : area(allowed_area) { push(area); } PaintClipper::~PaintClipper() { pop(area); } void PaintClipper::push(const QRegion& allowed_area) { if (allowed_area == infiniteRegion()) // don't push these return; if (areas == NULL) areas = new QStack< QRegion >; areas->push(allowed_area); } void PaintClipper::pop(const QRegion& allowed_area) { if (allowed_area == infiniteRegion()) return; Q_ASSERT(areas != NULL); Q_ASSERT(areas->top() == allowed_area); areas->pop(); if (areas->isEmpty()) { delete areas; areas = NULL; } } bool PaintClipper::clip() { return areas != NULL; } QRegion PaintClipper::paintArea() { assert(areas != NULL); // can be called only with clip() == true QRegion ret = QRegion(0, 0, displayWidth(), displayHeight()); foreach (const QRegion & r, *areas) ret &= r; return ret; } struct PaintClipper::Iterator::Data { Data() : index(0) {} int index; QVector< QRect > rects; }; PaintClipper::Iterator::Iterator() : data(new Data) { if (clip() && effects->compositingType() == OpenGLCompositing) { data->rects = paintArea().rects(); data->index = -1; next(); // move to the first one } #ifdef KWIN_HAVE_XRENDER_COMPOSITING if (clip() && effects->compositingType() == XRenderCompositing) { XserverRegion region = toXserverRegion(paintArea()); XFixesSetPictureClipRegion(display(), effects->xrenderBufferPicture(), 0, 0, region); XFixesDestroyRegion(display(), region); // it's ref-counted } #endif } PaintClipper::Iterator::~Iterator() { #ifdef KWIN_HAVE_XRENDER_COMPOSITING if (clip() && effects->compositingType() == XRenderCompositing) XFixesSetPictureClipRegion(display(), effects->xrenderBufferPicture(), 0, 0, None); #endif delete data; } bool PaintClipper::Iterator::isDone() { if (!clip()) return data->index == 1; // run once if (effects->compositingType() == OpenGLCompositing) return data->index >= data->rects.count(); // run once per each area #ifdef KWIN_HAVE_XRENDER_COMPOSITING if (effects->compositingType() == XRenderCompositing) return data->index == 1; // run once #endif abort(); } void PaintClipper::Iterator::next() { data->index++; } QRect PaintClipper::Iterator::boundingRect() const { if (!clip()) return infiniteRegion(); if (effects->compositingType() == OpenGLCompositing) return data->rects[ data->index ]; #ifdef KWIN_HAVE_XRENDER_COMPOSITING if (effects->compositingType() == XRenderCompositing) return paintArea().boundingRect(); #endif abort(); return infiniteRegion(); } /*************************************************************** Motion1D ***************************************************************/ Motion1D::Motion1D(double initial, double strength, double smoothness) : Motion(initial, strength, smoothness) { } Motion1D::Motion1D(const Motion1D &other) : Motion(other) { } Motion1D::~Motion1D() { } /*************************************************************** Motion2D ***************************************************************/ Motion2D::Motion2D(QPointF initial, double strength, double smoothness) : Motion(initial, strength, smoothness) { } Motion2D::Motion2D(const Motion2D &other) : Motion(other) { } Motion2D::~Motion2D() { } /*************************************************************** WindowMotionManager ***************************************************************/ WindowMotionManager::WindowMotionManager(bool useGlobalAnimationModifier) : m_useGlobalAnimationModifier(useGlobalAnimationModifier) { // TODO: Allow developer to modify motion attributes } // TODO: What happens when the window moves by an external force? WindowMotionManager::~WindowMotionManager() { } void WindowMotionManager::manage(EffectWindow *w) { if (m_managedWindows.contains(w)) return; double strength = 0.08; double smoothness = 4.0; if (m_useGlobalAnimationModifier && effects->animationTimeFactor()) { // If the factor is == 0 then we just skip the calculation completely strength = 0.08 / effects->animationTimeFactor(); smoothness = effects->animationTimeFactor() * 4.0; } WindowMotion &motion = m_managedWindows[ w ]; motion.translation.setStrength(strength); motion.translation.setSmoothness(smoothness); motion.scale.setStrength(strength * 1.33); motion.scale.setSmoothness(smoothness / 2.0); motion.translation.setValue(w->pos()); motion.scale.setValue(QPointF(1.0, 1.0)); } void WindowMotionManager::unmanage(EffectWindow *w) { m_movingWindowsSet.remove(w); m_managedWindows.remove(w); } void WindowMotionManager::unmanageAll() { m_managedWindows.clear(); m_movingWindowsSet.clear(); } void WindowMotionManager::calculate(int time) { if (!effects->animationTimeFactor()) { // Just skip it completely if the user wants no animation m_movingWindowsSet.clear(); QHash::iterator it = m_managedWindows.begin(); for (; it != m_managedWindows.end(); ++it) { WindowMotion *motion = &it.value(); motion->translation.finish(); motion->scale.finish(); } } QHash::iterator it = m_managedWindows.begin(); for (; it != m_managedWindows.end(); ++it) { WindowMotion *motion = &it.value(); int stopped = 0; // TODO: What happens when distance() == 0 but we are still moving fast? // TODO: Motion needs to be calculated from the window's center Motion2D *trans = &motion->translation; if (trans->distance().isNull()) ++stopped; else { // Still moving trans->calculate(time); const short fx = trans->target().x() <= trans->startValue().x() ? -1 : 1; const short fy = trans->target().y() <= trans->startValue().y() ? -1 : 1; if (trans->distance().x()*fx/0.5 < 1.0 && trans->velocity().x()*fx/0.2 < 1.0 && trans->distance().y()*fy/0.5 < 1.0 && trans->velocity().y()*fy/0.2 < 1.0) { // Hide tiny oscillations motion->translation.finish(); ++stopped; } } Motion2D *scale = &motion->scale; if (scale->distance().isNull()) ++stopped; else { // Still scaling scale->calculate(time); const short fx = scale->target().x() < 1.0 ? -1 : 1; const short fy = scale->target().y() < 1.0 ? -1 : 1; if (scale->distance().x()*fx/0.001 < 1.0 && scale->velocity().x()*fx/0.05 < 1.0 && scale->distance().y()*fy/0.001 < 1.0 && scale->velocity().y()*fy/0.05 < 1.0) { // Hide tiny oscillations motion->scale.finish(); ++stopped; } } // We just finished this window's motion if (stopped == 2) m_movingWindowsSet.remove(it.key()); } } void WindowMotionManager::reset() { QHash::iterator it = m_managedWindows.begin(); for (; it != m_managedWindows.end(); ++it) { WindowMotion *motion = &it.value(); EffectWindow *window = it.key(); motion->translation.setTarget(window->pos()); motion->translation.finish(); motion->scale.setTarget(QPointF(1.0, 1.0)); motion->scale.finish(); } } void WindowMotionManager::reset(EffectWindow *w) { QHash::iterator it = m_managedWindows.find(w); if (it == m_managedWindows.end()) return; WindowMotion *motion = &it.value(); motion->translation.setTarget(w->pos()); motion->translation.finish(); motion->scale.setTarget(QPointF(1.0, 1.0)); motion->scale.finish(); } void WindowMotionManager::apply(EffectWindow *w, WindowPaintData &data) { QHash::iterator it = m_managedWindows.find(w); if (it == m_managedWindows.end()) return; // TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid) WindowMotion *motion = &it.value(); data.xTranslate += motion->translation.value().x() - w->x(); data.yTranslate += motion->translation.value().y() - w->y(); data.xScale *= motion->scale.value().x(); data.yScale *= motion->scale.value().y(); } void WindowMotionManager::moveWindow(EffectWindow *w, QPoint target, double scale, double yScale) { QHash::iterator it = m_managedWindows.find(w); if (it == m_managedWindows.end()) abort(); // Notify the effect author that they did something wrong WindowMotion *motion = &it.value(); if (yScale == 0.0) yScale = scale; QPointF scalePoint(scale, yScale); if (motion->translation.value() == target && motion->scale.value() == scalePoint) return; // Window already at that position motion->translation.setTarget(target); motion->scale.setTarget(scalePoint); m_movingWindowsSet << w; } QRectF WindowMotionManager::transformedGeometry(EffectWindow *w) const { QHash::const_iterator it = m_managedWindows.constFind(w); if (it == m_managedWindows.end()) return w->geometry(); const WindowMotion *motion = &it.value(); QRectF geometry(w->geometry()); // TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid) geometry.moveTo(motion->translation.value()); geometry.setWidth(geometry.width() * motion->scale.value().x()); geometry.setHeight(geometry.height() * motion->scale.value().y()); return geometry; } void WindowMotionManager::setTransformedGeometry(EffectWindow *w, const QRectF &geometry) { QHash::iterator it = m_managedWindows.find(w); if (it == m_managedWindows.end()) return; WindowMotion *motion = &it.value(); motion->translation.setValue(geometry.topLeft()); motion->scale.setValue(QPointF(geometry.width() / qreal(w->width()), geometry.height() / qreal(w->height()))); } QRectF WindowMotionManager::targetGeometry(EffectWindow *w) const { QHash::const_iterator it = m_managedWindows.constFind(w); if (it == m_managedWindows.end()) return w->geometry(); const WindowMotion *motion = &it.value(); QRectF geometry(w->geometry()); // TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid) geometry.moveTo(motion->translation.target()); geometry.setWidth(geometry.width() * motion->scale.target().x()); geometry.setHeight(geometry.height() * motion->scale.target().y()); return geometry; } EffectWindow* WindowMotionManager::windowAtPoint(QPoint point, bool useStackingOrder) const { Q_UNUSED(useStackingOrder); // TODO: Stacking order uses EffectsHandler::stackingOrder() then filters by m_managedWindows QHash< EffectWindow*, WindowMotion >::ConstIterator it = m_managedWindows.constBegin(); while (it != m_managedWindows.constEnd()) { if (transformedGeometry(it.key()).contains(point)) return it.key(); ++it; } return NULL; } /*************************************************************** EffectFramePrivate ***************************************************************/ class EffectFramePrivate { public: EffectFramePrivate(); ~EffectFramePrivate(); bool crossFading; qreal crossFadeProgress; }; EffectFramePrivate::EffectFramePrivate() : crossFading(false) , crossFadeProgress(1.0) { } EffectFramePrivate::~EffectFramePrivate() { } /*************************************************************** EffectFrame ***************************************************************/ EffectFrame::EffectFrame() : d(new EffectFramePrivate) { } EffectFrame::~EffectFrame() { delete d; } qreal EffectFrame::crossFadeProgress() const { return d->crossFadeProgress; } void EffectFrame::setCrossFadeProgress(qreal progress) { d->crossFadeProgress = progress; } bool EffectFrame::isCrossFade() const { return d->crossFading; } void EffectFrame::enableCrossFade(bool enable) { d->crossFading = enable; } } // namespace #include "kwineffects.moc" diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h index b7d8184a2..bae9b79de 100644 --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -1,2167 +1,2168 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2006 Lubos Lunak Copyright (C) 2009 Lucas Murray Copyright (C) 2010, 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #ifndef KWINEFFECTS_H #define KWINEFFECTS_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class KLibrary; class KConfigGroup; class KActionCollection; class QFont; class QKeyEvent; namespace KWin { class EffectWindow; class EffectWindowGroup; class EffectFrame; class EffectFramePrivate; class Effect; class WindowQuad; class GLShader; class XRenderPicture; class RotationData; class WindowQuadList; class WindowPrePaintData; class WindowPaintData; class ScreenPrePaintData; class ScreenPaintData; typedef QPair< QString, Effect* > EffectPair; typedef QPair< Effect*, Window > InputWindowPair; typedef QList< EffectWindow* > EffectWindowList; /** @defgroup kwineffects KWin effects library * KWin effects library contains necessary classes for creating new KWin * compositing effects. * * @section creating Creating new effects * This example will demonstrate the basics of creating an effect. We'll use * CoolEffect as the class name, cooleffect as internal name and * "Cool Effect" as user-visible name of the effect. * * This example doesn't demonstrate how to write the effect's code. For that, * see the documentation of the Effect class. * * @subsection creating-class CoolEffect class * First you need to create CoolEffect class which has to be a subclass of * @ref KWin::Effect. In that class you can reimplement various virtual * methods to control how and where the windows are drawn. * * @subsection creating-macro KWIN_EFFECT macro * To make KWin aware of your new effect, you first need to use the * @ref KWIN_EFFECT macro to connect your effect's class to it's internal * name. The internal name is used by KWin to identify your effect. It can be * freely chosen (although it must be a single word), must be unique and won't * be shown to the user. For our example, you would use the macro like this: * @code * KWIN_EFFECT(cooleffect, CoolEffect) * @endcode * * @subsection creating-buildsystem Buildsystem * To build the effect, you can use the KWIN_ADD_EFFECT() cmake macro which * can be found in effects/CMakeLists.txt file in KWin's source. First * argument of the macro is the name of the library that will contain * your effect. Although not strictly required, it is usually a good idea to * use the same name as your effect's internal name there. Following arguments * to the macro are the files containing your effect's source. If our effect's * source is in cooleffect.cpp, we'd use following: * @code * KWIN_ADD_EFFECT(cooleffect cooleffect.cpp) * @endcode * * This macro takes care of compiling your effect. You'll also need to install * your effect's .desktop file, so the example CMakeLists.txt file would be * as follows: * @code * KWIN_ADD_EFFECT(cooleffect cooleffect.cpp) * install( FILES cooleffect.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) * @endcode * * @subsection creating-desktop Effect's .desktop file * You will also need to create .desktop file to set name, description, icon * and other properties of your effect. Important fields of the .desktop file * are: * @li Name User-visible name of your effect * @li Icon Name of the icon of the effect * @li Comment Short description of the effect * @li Type must be "Service" * @li X-KDE-ServiceTypes must be "KWin/Effect" * @li X-KDE-PluginInfo-Name effect's internal name as passed to the KWIN_EFFECT macro plus "kwin4_effect_" prefix * @li X-KDE-PluginInfo-Category effect's category. Should be one of Appearance, Accessibility, Window Management, Demos, Tests, Misc * @li X-KDE-PluginInfo-EnabledByDefault whether the effect should be enabled by default (use sparingly). Default is false * @li X-KDE-Library name of the library containing the effect. This is the first argument passed to the KWIN_ADD_EFFECT macro in cmake file plus "kwin4_effect_" prefix. * * Example cooleffect.desktop file follows: * @code [Desktop Entry] Name=Cool Effect Comment=The coolest effect you've ever seen Icon=preferences-system-windows-effect-cooleffect Type=Service X-KDE-ServiceTypes=KWin/Effect X-KDE-PluginInfo-Author=My Name X-KDE-PluginInfo-Email=my@email.here X-KDE-PluginInfo-Name=kwin4_effect_cooleffect X-KDE-PluginInfo-Category=Misc X-KDE-Library=kwin4_effect_cooleffect * @endcode * * * @section accessing Accessing windows and workspace * Effects can gain access to the properties of windows and workspace via * EffectWindow and EffectsHandler classes. * * There is one global EffectsHandler object which you can access using the * @ref effects pointer. * For each window, there is an EffectWindow object which can be used to read * window properties such as position and also to change them. * * For more information about this, see the documentation of the corresponding * classes. * * @{ **/ #define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor )) #define KWIN_EFFECT_API_VERSION_MAJOR 0 #define KWIN_EFFECT_API_VERSION_MINOR 182 #define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \ KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR ) enum WindowQuadType { WindowQuadError, // for the stupid default ctor WindowQuadContents, WindowQuadDecoration, // Shadow Quad types WindowQuadShadowTop, WindowQuadShadowTopRight, WindowQuadShadowRight, WindowQuadShadowBottomRight, WindowQuadShadowBottom, WindowQuadShadowBottomLeft, WindowQuadShadowLeft, WindowQuadShadowTopLeft, EFFECT_QUAD_TYPE_START = 100 ///< @internal }; /** * EffectWindow::setData() and EffectWindow::data() global roles. * All values between 0 and 999 are reserved for global roles. */ enum DataRole { // Grab roles are used to force all other animations to ignore the window. // The value of the data is set to the Effect's `this` value. WindowAddedGrabRole = 1, WindowClosedGrabRole, WindowMinimizedGrabRole, WindowUnminimizedGrabRole, WindowForceBlurRole, ///< For fullscreen effects to enforce blurring of windows, WindowBlurBehindRole, ///< For single windows to blur behind LanczosCacheRole }; /** * Style types used by @ref EffectFrame. * @since 4.6 */ enum EffectFrameStyle { EffectFrameNone, ///< Displays no frame around the contents. EffectFrameUnstyled, ///< Displays a basic box around the contents. EffectFrameStyled ///< Displays a Plasma-styled frame around the contents. }; /** * Infinite region (i.e. a special region type saying that everything needs to be painted). */ KWIN_EXPORT inline QRect infiniteRegion() { // INT_MIN / 2 because width/height is used (INT_MIN+INT_MAX==-1) return QRect(INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX); } /** * @short Base class for all KWin effects * * This is the base class for all effects. By reimplementing virtual methods * of this class, you can customize how the windows are painted. * * The virtual methods are used for painting and need to be implemented for * custom painting. * * In order to react to state changes (e.g. a window gets closed) the effect * should provide slots for the signals emitted by the EffectsHandler. * * @section Chaining * Most methods of this class are called in chain style. This means that when * effects A and B area active then first e.g. A::paintWindow() is called and * then from within that method B::paintWindow() is called (although * indirectly). To achieve this, you need to make sure to call corresponding * method in EffectsHandler class from each such method (using @ref effects * pointer): * @code * void MyEffect::postPaintScreen() * { * // Do your own processing here * ... * // Call corresponding EffectsHandler method * effects->postPaintScreen(); * } * @endcode * * @section Effectsptr Effects pointer * @ref effects pointer points to the global EffectsHandler object that you can * use to interact with the windows. * * @section painting Painting stages * Painting of windows is done in three stages: * @li First, the prepaint pass.
* Here you can specify how the windows will be painted, e.g. that they will * be translucent and transformed. * @li Second, the paint pass.
* Here the actual painting takes place. You can change attributes such as * opacity of windows as well as apply transformations to them. You can also * paint something onto the screen yourself. * @li Finally, the postpaint pass.
* Here you can mark windows, part of windows or even the entire screen for * repainting to create animations. * * For each stage there are *Screen() and *Window() methods. The window method * is called for every window which the screen method is usually called just * once. **/ class KWIN_EXPORT Effect : public QObject { Q_OBJECT public: /** Flags controlling how painting is done. */ // TODO: is that ok here? enum { /** * Window (or at least part of it) will be painted opaque. **/ PAINT_WINDOW_OPAQUE = 1 << 0, /** * Window (or at least part of it) will be painted translucent. **/ PAINT_WINDOW_TRANSLUCENT = 1 << 1, /** * Window will be painted with transformed geometry. **/ PAINT_WINDOW_TRANSFORMED = 1 << 2, /** * Paint only a region of the screen (can be optimized, cannot * be used together with TRANSFORMED flags). **/ PAINT_SCREEN_REGION = 1 << 3, /** * The whole screen will be painted with transformed geometry. * Forces the entire screen to be painted. **/ PAINT_SCREEN_TRANSFORMED = 1 << 4, /** * At least one window will be painted with transformed geometry. * Forces the entire screen to be painted. **/ PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5, /** * Clear whole background as the very first step, without optimizing it **/ PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6, // PAINT_DECORATION_ONLY = 1 << 7 has been deprecated /** * Window will be painted with a lanczos filter. **/ PAINT_WINDOW_LANCZOS = 1 << 8, /** * Same as PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS but does not trigger * full repaints of the screen. If this flag is used the effect has * to ensure by itself that the correct areas are repainted. If not * handled correctly it will cause rendering glitches. * Use with care! * @since 4.6 **/ PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS = 1 << 9 }; enum Feature { Nothing = 0, Resize, GeometryTip, Outline }; /** * Constructs new Effect object. **/ Effect(); /** * Destructs the Effect object. **/ virtual ~Effect(); /** * Flags describing which parts of configuration have changed. */ enum ReconfigureFlag { ReconfigureAll = 1 << 0 /// Everything needs to be reconfigured. }; Q_DECLARE_FLAGS(ReconfigureFlags, ReconfigureFlag) /** * Called when configuration changes (either the effect's or KWin's global). */ virtual void reconfigure(ReconfigureFlags flags); /** * Called when another effect requests the proxy for this effect. */ virtual void* proxy(); /** * Called before starting to paint the screen. * In this method you can: * @li set whether the windows or the entire screen will be transformed * @li change the region of the screen that will be painted * @li do various housekeeping tasks such as initing your effect's variables for the upcoming paint pass or updating animation's progress **/ virtual void prePaintScreen(ScreenPrePaintData& data, int time); /** * In this method you can: * @li paint something on top of the windows (by painting after calling * effects->paintScreen()) * @li paint multiple desktops and/or multiple copies of the same desktop * by calling effects->paintScreen() multiple times **/ virtual void paintScreen(int mask, QRegion region, ScreenPaintData& data); /** * Called after all the painting has been finished. * In this method you can: * @li schedule next repaint in case of animations * You shouldn't paint anything here. **/ virtual void postPaintScreen(); /** * Called for every window before the actual paint pass * In this method you can: * @li enable or disable painting of the window (e.g. enable paiting of minimized window) * @li set window to be painted with translucency * @li set window to be transformed * @li request the window to be divided into multiple parts **/ virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time); /** * This is the main method for painting windows. * In this method you can: * @li do various transformations * @li change opacity of the window * @li change brightness and/or saturation, if it's supported **/ virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); /** * Called for every window after all painting has been finished. * In this method you can: * @li schedule next repaint for individual window(s) in case of animations * You shouldn't paint anything here. **/ virtual void postPaintWindow(EffectWindow* w); /** * This method is called directly before painting an @ref EffectFrame. * You can implement this method if you need to bind a shader or perform * other operations before the frame is rendered. * @param frame The EffectFrame which will be rendered * @param region Region to restrict painting to * @param opacity Opacity of text/icon * @param frameOpacity Opacity of background * @since 4.6 **/ virtual void paintEffectFrame(EffectFrame* frame, QRegion region, double opacity, double frameOpacity); /** * Called on Transparent resizes. * return true if your effect substitutes the XOR rubberband */ virtual bool provides(Feature); /** * Can be called to draw multiple copies (e.g. thumbnails) of a window. * You can change window's opacity/brightness/etc here, but you can't * do any transformations **/ virtual void drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data); /** * Define new window quads so that they can be transformed by other effects. * It's up to the effect to keep track of them. **/ virtual void buildQuads(EffectWindow* w, WindowQuadList& quadList); virtual void windowInputMouseEvent(Window w, QEvent* e); virtual void grabbedKeyboardEvent(QKeyEvent* e); virtual bool borderActivated(ElectricBorder border); /** * Overwrite this method to indicate whether your effect will be doing something in * the next frame to be rendered. If the method returns @c false the effect will be * excluded from the chained methods in the next rendered frame. * * This method is called always directly before the paint loop begins. So it is totally * fine to e.g. react on a window event, issue a repaint to trigger an animation and * change a flag to indicate that this method returns @c true. * * As the method is called each frame, you should not perform complex calculations. * Best use just a boolean flag. * * The default implementation of this method returns @c true. * @since 4.8 **/ virtual bool isActive() const; static int displayWidth(); static int displayHeight(); static QPoint cursorPos(); /** * Read animation time from the configuration and possibly adjust using animationTimeFactor(). * The configuration value in the effect should also have special value 'default' (set using * QSpinBox::setSpecialValueText()) with the value 0. This special value is adjusted * using the global animation speed, otherwise the exact time configured is returned. * @param cfg configuration group to read value from * @param key configuration key to read value from * @param defaultTime default animation time in milliseconds */ // return type is intentionally double so that one can divide using it without losing data static double animationTime(const KConfigGroup& cfg, const QString& key, int defaultTime); /** * @overload Use this variant if the animation time is hardcoded and not configurable * in the effect itself. */ static double animationTime(int defaultTime); /** * Linearly interpolates between @p x and @p y. * * Returns @p x when @p a = 0; returns @p y when @p a = 1. **/ static double interpolate(double x, double y, double a) { return x * (1 - a) + y * a; } /** Helper to set WindowPaintData and QRegion to necessary transformations so that * a following drawWindow() would put the window at the requested geometry (useful for thumbnails) **/ static void setPositionTransformations(WindowPaintData& data, QRect& region, EffectWindow* w, const QRect& r, Qt::AspectRatioMode aspect); }; /** * Defines the class to be used for effect with given name. * The name must be same as effect's X-KDE-PluginInfo-Name values in .desktop * file, but without the "kwin4_effect_" prefix. * E.g. KWIN_EFFECT( flames, MyFlameEffect ) * In this case object of MyFlameEffect class would be created when effect * "flames" (which has X-KDE-PluginInfo-Name=kwin4_effect_flames in .desktop * file) is loaded. **/ #define KWIN_EFFECT( name, classname ) \ extern "C" { \ KWIN_EXPORT Effect* effect_create_kwin4_effect_##name() { return new classname; } \ KWIN_EXPORT int effect_version_kwin4_effect_##name() { return KWIN_EFFECT_API_VERSION; } \ } /** * Defines the function used to check whether an effect is supported * E.g. KWIN_EFFECT_SUPPORTED( flames, MyFlameEffect::supported() ) **/ #define KWIN_EFFECT_SUPPORTED( name, function ) \ extern "C" { \ KWIN_EXPORT bool effect_supported_kwin4_effect_##name() { return function; } \ } /** * Defines the function used to check whether an effect should be enabled by default * * This function provides a way for an effect to override the default at runtime, * e.g. based on the capabilities of the hardware. * * This function is optional; the effect doesn't have to provide it. * * Note that this function is only called if the supported() function returns true, * and if X-KDE-PluginInfo-EnabledByDefault is set to true in the .desktop file. * * Example: KWIN_EFFECT_ENABLEDBYDEFAULT(flames, MyFlameEffect::enabledByDefault()) **/ #define KWIN_EFFECT_ENABLEDBYDEFAULT(name, function) \ extern "C" { \ KWIN_EXPORT bool effect_enabledbydefault_kwin4_effect_##name() { return function; } \ } /** * Defines the function used to retrieve an effect's config widget * E.g. KWIN_EFFECT_CONFIG( flames, MyFlameEffectConfig ) **/ #define KWIN_EFFECT_CONFIG( name, classname ) \ K_PLUGIN_FACTORY(EffectFactory, registerPlugin(#name);) \ K_EXPORT_PLUGIN(EffectFactory("kcm_kwin4_effect_" #name)) /** * Defines the function used to retrieve multiple effects' config widget * E.g. KWIN_EFFECT_CONFIG_MULTIPLE( flames, * KWIN_EFFECT_CONFIG_SINGLE( flames, MyFlameEffectConfig ) * KWIN_EFFECT_CONFIG_SINGLE( fire, MyFireEffectConfig ) * ) **/ #define KWIN_EFFECT_CONFIG_MULTIPLE( name, singles ) \ K_PLUGIN_FACTORY(EffectFactory, singles) \ K_EXPORT_PLUGIN(EffectFactory("kcm_kwin4_effect_" #name)) /** * @see KWIN_EFFECT_CONFIG_MULTIPLE */ #define KWIN_EFFECT_CONFIG_SINGLE( name, classname ) \ registerPlugin(#name); /** * The declaration of the factory to export the effect */ #define KWIN_EFFECT_CONFIG_FACTORY K_PLUGIN_FACTORY_DECLARATION(EffectFactory) /** * @short Manager class that handles all the effects. * * This class creates Effect objects and calls it's appropriate methods. * * Effect objects can call methods of this class to interact with the * workspace, e.g. to activate or move a specific window, change current * desktop or create a special input window to receive mouse and keyboard * events. **/ class KWIN_EXPORT EffectsHandler : public QObject { Q_OBJECT friend class Effect; public: EffectsHandler(CompositingType type); virtual ~EffectsHandler(); // for use by effects virtual void prePaintScreen(ScreenPrePaintData& data, int time) = 0; virtual void paintScreen(int mask, QRegion region, ScreenPaintData& data) = 0; virtual void postPaintScreen() = 0; virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time) = 0; virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) = 0; virtual void postPaintWindow(EffectWindow* w) = 0; virtual void paintEffectFrame(EffectFrame* frame, QRegion region, double opacity, double frameOpacity) = 0; virtual void drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) = 0; virtual void buildQuads(EffectWindow* w, WindowQuadList& quadList) = 0; virtual QVariant kwinOption(KWinOption kwopt) = 0; // Functions for handling input - e.g. when an Expose-like effect is shown, an input window // covering the whole screen is created and all mouse events will be intercepted by it. // The effect's windowInputMouseEvent() will get called with such events. virtual Window createInputWindow(Effect* e, int x, int y, int w, int h, const QCursor& cursor) = 0; Window createInputWindow(Effect* e, const QRect& r, const QCursor& cursor); virtual Window createFullScreenInputWindow(Effect* e, const QCursor& cursor); virtual void destroyInputWindow(Window w) = 0; virtual QPoint cursorPos() const = 0; virtual bool grabKeyboard(Effect* effect) = 0; virtual void ungrabKeyboard() = 0; /** * Retrieve the proxy class for an effect if it has one. Will return NULL if * the effect isn't loaded or doesn't have a proxy class. */ virtual void* getProxy(QString name) = 0; // Mouse polling virtual void startMousePolling() = 0; virtual void stopMousePolling() = 0; virtual void checkElectricBorder(const QPoint &pos, Time time) = 0; virtual void reserveElectricBorder(ElectricBorder border) = 0; virtual void unreserveElectricBorder(ElectricBorder border) = 0; virtual void reserveElectricBorderSwitching(bool reserve) = 0; // functions that allow controlling windows/desktop virtual void activateWindow(EffectWindow* c) = 0; virtual EffectWindow* activeWindow() const = 0 ; virtual void moveWindow(EffectWindow* w, const QPoint& pos, bool snap = false, double snapAdjust = 1.0) = 0; virtual void windowToDesktop(EffectWindow* w, int desktop) = 0; virtual void windowToScreen(EffectWindow* w, int screen) = 0; virtual void setShowingDesktop(bool showing) = 0; // Activities /** * @returns The ID of the current activity. */ virtual QString currentActivity() const = 0; // Desktops /** * @returns The ID of the current desktop. */ virtual int currentDesktop() const = 0; /** * @returns Total number of desktops currently in existence. */ virtual int numberOfDesktops() const = 0; /** * Set the current desktop to @a desktop. */ virtual void setCurrentDesktop(int desktop) = 0; /** * Sets the total number of desktops to @a desktops. */ virtual void setNumberOfDesktops(int desktops) = 0; /** * @returns The size of desktop layout in grid units. */ virtual QSize desktopGridSize() const = 0; /** * @returns The width of desktop layout in grid units. */ virtual int desktopGridWidth() const = 0; /** * @returns The height of desktop layout in grid units. */ virtual int desktopGridHeight() const = 0; /** * @returns The width of desktop layout in pixels. */ virtual int workspaceWidth() const = 0; /** * @returns The height of desktop layout in pixels. */ virtual int workspaceHeight() const = 0; /** * @returns The ID of the desktop at the point @a coords or 0 if no desktop exists at that * point. @a coords is to be in grid units. */ virtual int desktopAtCoords(QPoint coords) const = 0; /** * @returns The coords of desktop @a id in grid units. */ virtual QPoint desktopGridCoords(int id) const = 0; /** * @returns The coords of the top-left corner of desktop @a id in pixels. */ virtual QPoint desktopCoords(int id) const = 0; /** * @returns The ID of the desktop above desktop @a id. Wraps around to the bottom of * the layout if @a wrap is set. If @a id is not set use the current one. */ virtual int desktopAbove(int desktop = 0, bool wrap = true) const = 0; /** * @returns The ID of the desktop to the right of desktop @a id. Wraps around to the * left of the layout if @a wrap is set. If @a id is not set use the current one. */ virtual int desktopToRight(int desktop = 0, bool wrap = true) const = 0; /** * @returns The ID of the desktop below desktop @a id. Wraps around to the top of the * layout if @a wrap is set. If @a id is not set use the current one. */ virtual int desktopBelow(int desktop = 0, bool wrap = true) const = 0; /** * @returns The ID of the desktop to the left of desktop @a id. Wraps around to the * right of the layout if @a wrap is set. If @a id is not set use the current one. */ virtual int desktopToLeft(int desktop = 0, bool wrap = true) const = 0; virtual QString desktopName(int desktop) const = 0; virtual bool optionRollOverDesktops() const = 0; virtual int activeScreen() const = 0; // Xinerama virtual int numScreens() const = 0; // Xinerama virtual int screenNumber(const QPoint& pos) const = 0; // Xinerama virtual QRect clientArea(clientAreaOption, int screen, int desktop) const = 0; virtual QRect clientArea(clientAreaOption, const EffectWindow* c) const = 0; virtual QRect clientArea(clientAreaOption, const QPoint& p, int desktop) const = 0; /** * Factor by which animation speed in the effect should be modified (multiplied). * If configurable in the effect itself, the option should have also 'default' * animation speed. The actual value should be determined using animationTime(). * Note: The factor can be also 0, so make sure your code can cope with 0ms time * if used manually. */ virtual double animationTimeFactor() const = 0; virtual WindowQuadType newWindowQuadType() = 0; virtual EffectWindow* findWindow(WId id) const = 0; virtual EffectWindowList stackingOrder() const = 0; // window will be temporarily painted as if being at the top of the stack virtual void setElevatedWindow(EffectWindow* w, bool set) = 0; virtual void setTabBoxWindow(EffectWindow*) = 0; virtual void setTabBoxDesktop(int) = 0; virtual EffectWindowList currentTabBoxWindowList() const = 0; virtual void refTabBox() = 0; virtual void unrefTabBox() = 0; virtual void closeTabBox() = 0; virtual QList< int > currentTabBoxDesktopList() const = 0; virtual int currentTabBoxDesktop() const = 0; virtual EffectWindow* currentTabBoxWindow() const = 0; virtual void setActiveFullScreenEffect(Effect* e) = 0; virtual Effect* activeFullScreenEffect() const = 0; /** * Schedules the entire workspace to be repainted next time. * If you call it during painting (including prepaint) then it does not * affect the current painting. **/ virtual void addRepaintFull() = 0; virtual void addRepaint(const QRect& r) = 0; virtual void addRepaint(const QRegion& r) = 0; virtual void addRepaint(int x, int y, int w, int h) = 0; CompositingType compositingType() const; virtual unsigned long xrenderBufferPicture() = 0; virtual void reconfigure() = 0; /** Makes KWin core watch PropertyNotify events for the given atom, or stops watching if reg is false (must be called the same number of times as registering). Events are sent using Effect::propertyNotify(). Note that even events that haven't been registered for can be received. */ virtual void registerPropertyType(long atom, bool reg) = 0; virtual QByteArray readRootProperty(long atom, long type, int format) const = 0; virtual void deleteRootProperty(long atom) const = 0; /** * Returns @a true if the active window decoration has shadow API hooks. */ virtual bool hasDecorationShadows() const = 0; /** * Returns @a true if the window decorations use the alpha channel, and @a false otherwise. * @since 4.5 */ virtual bool decorationsHaveAlpha() const = 0; /** * Returns @a true if the window decorations support blurring behind the decoration, and @a false otherwise * @since 4.6 */ virtual bool decorationSupportsBlurBehind() const = 0; /** * Creates a new frame object. If the frame does not have a static size * then it will be located at @a position with @a alignment. A * non-static frame will automatically adjust its size to fit the contents. * @returns A new @ref EffectFrame. It is the responsibility of the caller to delete the * EffectFrame. * @since 4.6 */ virtual EffectFrame* effectFrame(EffectFrameStyle style, bool staticSize = true, const QPoint& position = QPoint(-1, -1), Qt::Alignment alignment = Qt::AlignCenter) const = 0; /** * Allows an effect to trigger a reload of itself. * This can be used by an effect which needs to be reloaded when screen geometry changes. * It is possible that the effect cannot be loaded again as it's supported method does no longer * hold. * @param effect The effect to reload * @since 4.8 **/ virtual void reloadEffect(Effect *effect) = 0; /** * Sends message over DCOP to reload given effect. * @param effectname effect's name without "kwin4_effect_" prefix. * Can be called from effect's config module to apply config changes. **/ static void sendReloadMessage(const QString& effectname); /** * @return @ref KConfigGroup which holds given effect's config options **/ static KConfigGroup effectConfig(const QString& effectname); Q_SIGNALS: /** * Signal emitted when the current desktop changed. * @param oldDesktop The previously current desktop * @param newDesktop The new current desktop * @since 4.7 **/ void desktopChanged(int oldDesktop, int newDesktop); /** * Signal emitted when the number of currently existing desktops is changed. * @param old The previous number of desktops in used. * @see EffectsHandler::numberOfDesktops. * @since 4.7 */ void numberDesktopsChanged(int old); /** * Signal emitted when a new window has been added to the Workspace. * @param w The added window * @since 4.7 **/ void windowAdded(EffectWindow *w); /** * Signal emitted when a window is being removed from the Workspace. * An effect which wants to animate the window closing should connect * to this signal and reference the window by using * @link EffectWindow::refWindow * @param w The window which is being closed * @since 4.7 **/ void windowClosed(EffectWindow *w); /** * Signal emitted when a window get's activated. * @param w The new active window, or @c NULL if there is no active window. * @since 4.7 **/ void windowActivated(EffectWindow *w); /** * Signal emitted when a window is deleted. * This means that a closed window is not referenced any more. * An effect bookkeeping the closed windows should connect to this * signal to clean up the internal references. * @param w The window which is going to be deleted. * @see EffectWindow::refWindow * @see EffectWindow::unrefWindow * @see windowClosed * @since 4.7 **/ void windowDeleted(EffectWindow *w); /** * Signal emitted when a user begins a window move or resize operation. * To figure out whether the user resizes or moves the window use * @link EffectWindow::isUserMove or @link EffectWindow::isUserResize. * Whenever the geometry is updated the signal @link windowStepUserMovedResized * is emitted with the current geometry. * The move/resize operation ends with the signal @link windowFinishUserMovedResized. * Only one window can be moved/resized by the user at the same time! * @param w The window which is being moved/resized * @see windowStepUserMovedResized * @see windowFinishUserMovedResized * @see EffectWindow::isUserMove * @see EffectWindow::isUserResize * @since 4.7 **/ void windowStartUserMovedResized(EffectWindow *w); /** * Signal emitted during a move/resize operation when the user changed the geometry. * Please note: KWin supports two operation modes. In one mode all changes are applied * instantly. This means the window's geometry matches the passed in @p geometry. In the * other mode the geometry is changed after the user ended the move/resize mode. * The @p geometry differs from the window's geometry. Also the window's pixmap still has * the same size as before. Depending what the effect wants to do it would be recommended * to scale/translate the window. * @param w The window which is being moved/resized * @param geometry The geometry of the window in the current move/resize step. * @see windowStartUserMovedResized * @see windowFinishUserMovedResized * @see EffectWindow::isUserMove * @see EffectWindow::isUserResize * @since 4.7 **/ void windowStepUserMovedResized(EffectWindow *w, const QRect &geometry); /** * Signal emitted when the user finishes move/resize of window @p w. * @param w The window which has been moved/resized * @see windowStartUserMovedResized * @see windowFinishUserMovedResized * @since 4.7 **/ void windowFinishUserMovedResized(EffectWindow *w); /** * Signal emitted when the maximized state of the window @p w changed. * A window can be in one of four states: * @li restored: both @p horizontal and @p vertical are @c false * @li horizontally maximized: @p horizontal is @c true and @p vertical is @c false * @li vertically maximized: @p horizontal is @c false and @p vertical is @c true * @li completely maximized: both @p horizontal and @p vertical are @C true * @param w The window whose maximized state changed * @param horizontal If @c true maximized horizontally * @param vertical If @c true maximized vertically * @since 4.7 **/ void windowMaximizedStateChanged(EffectWindow *w, bool horizontal, bool vertical); /** * Signal emitted when the geometry or shape of a window changed. * This is caused if the window changes geometry without user interaction. * E.g. the decoration is changed. This is in opposite to windowUserMovedResized * which is caused by direct user interaction. * @param w The window whose geometry changed * @param old The previous geometry * @see windowUserMovedResized * @since 4.7 **/ void windowGeometryShapeChanged(EffectWindow *w, const QRect &old); /** * Signal emitted when the windows opacity is changed. * @param w The window whose opacity level is changed. * @param oldOpacity The previous opacity level * @param newOpacity The new opacity level * @since 4.7 **/ void windowOpacityChanged(EffectWindow *w, qreal oldOpacity, qreal newOpacity); /** * Signal emitted when a window got minimized. * @param w The window which was minimized * @since 4.7 **/ void windowMinimized(EffectWindow *w); /** * Signal emitted when a window got unminimized. * @param w The window which was unminimized * @since 4.7 **/ void windowUnminimized(EffectWindow *w); /** * Signal emitted when an area of a window is scheduled for repainting. * Use this signal in an effect if another area needs to be synced as well. * @param w The window which is scheduled for repainting * @param r The damaged rect * @since 4.7 **/ void windowDamaged(EffectWindow *w, const QRect &r); /** * Signal emitted when a tabbox is added. * An effect who wants to replace the tabbox with itself should use @link refTabBox. * @param mode The TabBoxMode. * @see refTabBox * @see tabBoxClosed * @see tabBoxUpdated * @see tabBoxKeyEvent * @since 4.7 **/ void tabBoxAdded(int mode); /** * Signal emitted when the TabBox was closed by KWin core. * An effect which referenced the TabBox should use @link unrefTabBox to unref again. * @see unrefTabBox * @see tabBoxAdded * @since 4.7 **/ void tabBoxClosed(); /** * Signal emitted when the selected TabBox window changed or the TabBox List changed. * An effect should only response to this signal if it referenced the TabBox with @link refTabBox. * @see refTabBox * @see currentTabBoxWindowList * @see currentTabBoxDesktopList * @see currentTabBoxWindow * @see currentTabBoxDesktop * @since 4.7 **/ void tabBoxUpdated(); /** * Signal emitted when a key event, which is not handled by TabBox directly is, happens while * TabBox is active. An effect might use the key event to e.g. change the selected window. * An effect should only response to this signal if it referenced the TabBox with @link refTabBox. * @param event The key event not handled by TabBox directly * @see refTabBox * @since 4.7 **/ void tabBoxKeyEvent(QKeyEvent* event); void clientGroupItemSwitched(EffectWindow* from, EffectWindow* to); void clientGroupItemAdded(EffectWindow* from, EffectWindow* to); // from merged with to void clientGroupItemRemoved(EffectWindow* c, EffectWindow* group); // c removed from group /** * Signal emitted when mouse changed. * If an effect needs to get updated mouse positions, it needs to first call @link startMousePolling. * For a fullscreen effect it is better to use an input window and react on @link windowInputMouseEvent. * @param pos The new mouse position * @param oldpos The previously mouse position * @param buttons The pressed mouse buttons * @param oldbuttons The previously pressed mouse buttons * @param modifiers Pressed keyboard modifiers * @param oldmodifiers Previously pressed keyboard modifiers. * @see startMousePolling * @since 4.7 **/ void mouseChanged(const QPoint& pos, const QPoint& oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers); /** * Receives events registered for using @link registerPropertyType. * Use readProperty() to get the property data. * Note that the property may be already set on the window, so doing the same * processing from windowAdded() (e.g. simply calling propertyNotify() from it) * is usually needed. * @param w The window whose property changed, is @c null if it is a root window property * @param atom The property * @since 4.7 */ void propertyNotify(EffectWindow* w, long atom); /** * Requests to show an outline. An effect providing to show an outline should * connect to the signal and render an outline. * The outline should be shown till the signal is emitted again with a new * geometry or the @link hideOutline signal is emitted. * @param outline The geometry of the outline to render. * @see hideOutline * @since 4.7 **/ void showOutline(const QRect& outline); /** * Signal emitted when the outline should no longer be shown. * @see showOutline * @since 4.7 **/ void hideOutline(); /** * Signal emitted after the screen geometry changed (e.g. add of a monitor). * Effects using displayWidth()/displayHeight() to cache information should * react on this signal and update the caches. * @param size The new screen size * @since 4.8 **/ void screenGeometryChanged(const QSize &size); protected: QVector< EffectPair > loaded_effects; QHash< QString, KLibrary* > effect_libraries; QList< InputWindowPair > input_windows; //QHash< QString, EffectFactory* > effect_factories; CompositingType compositing_type; }; /** * @short Representation of a window used by/for Effect classes. * * The purpose is to hide internal data and also to serve as a single * representation for the case when Client/Unmanaged becomes Deleted. **/ -class KWIN_EXPORT EffectWindow +class KWIN_EXPORT EffectWindow : public QObject { + Q_OBJECT public: /** Flags explaining why painting should be disabled */ enum { /** Window will not be painted */ PAINT_DISABLED = 1 << 0, /** Window will not be painted because it is deleted */ PAINT_DISABLED_BY_DELETE = 1 << 1, /** Window will not be painted because of which desktop it's on */ PAINT_DISABLED_BY_DESKTOP = 1 << 2, /** Window will not be painted because it is minimized */ PAINT_DISABLED_BY_MINIMIZE = 1 << 3, /** Window will not be painted because it is not the active window in a client group */ PAINT_DISABLED_BY_CLIENT_GROUP = 1 << 4, /** Window will not be painted because it's not on the current activity */ PAINT_DISABLED_BY_ACTIVITY = 1 << 5 }; - EffectWindow(); + EffectWindow(QObject *parent = NULL); virtual ~EffectWindow(); virtual void enablePainting(int reason) = 0; virtual void disablePainting(int reason) = 0; virtual bool isPaintingEnabled() = 0; virtual void addRepaint(const QRect& r) = 0; virtual void addRepaint(int x, int y, int w, int h) = 0; virtual void addRepaintFull() = 0; virtual void refWindow() = 0; virtual void unrefWindow() = 0; virtual bool isDeleted() const = 0; virtual bool isMinimized() const = 0; virtual double opacity() const = 0; virtual bool hasAlpha() const = 0; virtual bool isOnCurrentActivity() const; virtual bool isOnActivity(QString id) const = 0; virtual bool isOnAllActivities() const = 0; virtual bool isOnDesktop(int d) const; virtual bool isOnCurrentDesktop() const; virtual bool isOnAllDesktops() const = 0; virtual int desktop() const = 0; // prefer isOnXXX() virtual int x() const = 0; virtual int y() const = 0; virtual int width() const = 0; virtual int height() const = 0; /** * By how much the window wishes to grow/shrink at least. Usually QSize(1,1). * MAY BE DISOBEYED BY THE WM! It's only for information, do NOT rely on it at all. */ virtual QSize basicUnit() const = 0; virtual QRect geometry() const = 0; virtual QRegion shape() const = 0; virtual int screen() const = 0; /** @internal Do not use */ virtual bool hasOwnShape() const = 0; // only for shadow effect, for now virtual QPoint pos() const = 0; virtual QSize size() const = 0; virtual QRect rect() const = 0; virtual bool isMovable() const = 0; virtual bool isMovableAcrossScreens() const = 0; virtual bool isUserMove() const = 0; virtual bool isUserResize() const = 0; virtual QRect iconGeometry() const = 0; /** * Geometry of the actual window contents inside the whole (including decorations) window. */ virtual QRect contentsRect() const = 0; /** * Geometry of the transparent rect in the decoration. * May be different from contentsRect() if the decoration is extended into the client area. * @since 4.5 */ virtual QRect decorationInnerRect() const = 0; bool hasDecoration() const; virtual QByteArray readProperty(long atom, long type, int format) const = 0; virtual void deleteProperty(long atom) const = 0; virtual QString caption() const = 0; virtual QPixmap icon() const = 0; virtual QString windowClass() const = 0; virtual QString windowRole() const = 0; virtual const EffectWindowGroup* group() const = 0; /** * Returns whether the window is a desktop background window (the one with wallpaper). * See _NET_WM_WINDOW_TYPE_DESKTOP at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isDesktop() const = 0; /** * Returns whether the window is a dock (i.e. a panel). * See _NET_WM_WINDOW_TYPE_DOCK at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isDock() const = 0; /** * Returns whether the window is a standalone (detached) toolbar window. * See _NET_WM_WINDOW_TYPE_TOOLBAR at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isToolbar() const = 0; /** * Returns whether the window is a torn-off menu. * See _NET_WM_WINDOW_TYPE_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isMenu() const = 0; /** * Returns whether the window is a "normal" window, i.e. an application or any other window * for which none of the specialized window types fit. * See _NET_WM_WINDOW_TYPE_NORMAL at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isNormalWindow() const = 0; // normal as in 'NET::Normal or NET::Unknown non-transient' /** * Returns whether the window is any of special windows types (desktop, dock, splash, ...), * i.e. window types that usually don't have a window frame and the user does not use window * management (moving, raising,...) on them. */ virtual bool isSpecialWindow() const = 0; /** * Returns whether the window is a dialog window. * See _NET_WM_WINDOW_TYPE_DIALOG at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isDialog() const = 0; /** * Returns whether the window is a splashscreen. Note that many (especially older) applications * do not support marking their splash windows with this type. * See _NET_WM_WINDOW_TYPE_SPLASH at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isSplash() const = 0; /** * Returns whether the window is a utility window, such as a tool window. * See _NET_WM_WINDOW_TYPE_UTILITY at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isUtility() const = 0; /** * Returns whether the window is a dropdown menu (i.e. a popup directly or indirectly open * from the applications menubar). * See _NET_WM_WINDOW_TYPE_DROPDOWN_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isDropdownMenu() const = 0; /** * Returns whether the window is a popup menu (that is not a torn-off or dropdown menu). * See _NET_WM_WINDOW_TYPE_POPUP_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isPopupMenu() const = 0; // a context popup, not dropdown, not torn-off /** * Returns whether the window is a tooltip. * See _NET_WM_WINDOW_TYPE_TOOLTIP at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isTooltip() const = 0; /** * Returns whether the window is a window with a notification. * See _NET_WM_WINDOW_TYPE_NOTIFICATION at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isNotification() const = 0; /** * Returns whether the window is a combobox popup. * See _NET_WM_WINDOW_TYPE_COMBO at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isComboBox() const = 0; /** * Returns whether the window is a Drag&Drop icon. * See _NET_WM_WINDOW_TYPE_DND at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual bool isDNDIcon() const = 0; /** * Returns the NETWM window type * See http://standards.freedesktop.org/wm-spec/wm-spec-latest.html . */ virtual NET::WindowType windowType() const = 0; /** * Returns whether the window is managed by KWin (it has control over its placement and other * aspects, as opposed to override-redirect windows that are entirely handled by the application). */ virtual bool isManaged() const = 0; // whether it's managed or override-redirect /** * Returns whether or not the window can accept keyboard focus. */ virtual bool acceptsFocus() const = 0; /** * Returns whether or not the window is kept above all other windows. */ virtual bool keepAbove() const = 0; virtual bool isModal() const = 0; virtual EffectWindow* findModal() = 0; virtual EffectWindowList mainWindows() const = 0; /** * Returns whether the window should be excluded from window switching effects. * @since 4.5 */ virtual bool isSkipSwitcher() const = 0; /** * Returns the unmodified window quad list. Can also be used to force rebuilding. */ virtual WindowQuadList buildQuads(bool force = false) const = 0; virtual void minimize() const = 0; virtual void unminimize() const = 0; virtual void closeWindow() const = 0; virtual bool visibleInClientGroup() const = 0; /** * Can be used to by effects to store arbitrary data in the EffectWindow. */ virtual void setData(int role, const QVariant &data) = 0; virtual QVariant data(int role) const = 0; }; class KWIN_EXPORT EffectWindowGroup { public: virtual ~EffectWindowGroup(); virtual EffectWindowList members() const = 0; }; class KWIN_EXPORT GlobalShortcutsEditor : public KShortcutsEditor { public: GlobalShortcutsEditor(QWidget *parent); }; /** * @short Vertex class * * A vertex is one position in a window. WindowQuad consists of four WindowVertex objects * and represents one part of a window. **/ class KWIN_EXPORT WindowVertex { public: double x() const; double y() const; void move(double x, double y); void setX(double x); void setY(double y); double originalX() const; double originalY() const; double textureX() const; double textureY() const; WindowVertex(); WindowVertex(double x, double y, double tx, double ty); private: friend class WindowQuad; friend class WindowQuadList; double px, py; // position double ox, oy; // origional position double tx, ty; // texture coords }; /** * @short Class representing one area of a window. * * WindowQuads consists of four WindowVertex objects and represents one part of a window. */ // NOTE: This class expects the (original) vertices to be in the clockwise order starting from topleft. class KWIN_EXPORT WindowQuad { public: explicit WindowQuad(WindowQuadType type, int id = -1); WindowQuad makeSubQuad(double x1, double y1, double x2, double y2) const; WindowVertex& operator[](int index); const WindowVertex& operator[](int index) const; WindowQuadType type() const; int id() const; bool decoration() const; bool effect() const; double left() const; double right() const; double top() const; double bottom() const; double originalLeft() const; double originalRight() const; double originalTop() const; double originalBottom() const; bool smoothNeeded() const; bool isTransformed() const; private: friend class WindowQuadList; WindowVertex verts[ 4 ]; WindowQuadType quadType; // 0 - contents, 1 - decoration int quadID; }; class KWIN_EXPORT WindowQuadList : public QList< WindowQuad > { public: WindowQuadList splitAtX(double x) const; WindowQuadList splitAtY(double y) const; WindowQuadList makeGrid(int maxquadsize) const; WindowQuadList makeRegularGrid(int xSubdivisions, int ySubdivisions) const; WindowQuadList select(WindowQuadType type) const; WindowQuadList filterOut(WindowQuadType type) const; bool smoothNeeded() const; void makeArrays(float** vertices, float** texcoords, const QSizeF &size, bool yInverted) const; bool isTransformed() const; }; class KWIN_EXPORT WindowPrePaintData { public: int mask; /** * Region that will be painted, in screen coordinates. **/ QRegion paint; /** * The clip region will be substracted from paint region of following windows. * I.e. window will definitely cover it's clip region **/ QRegion clip; WindowQuadList quads; /** * Simple helper that sets data to say the window will be painted as non-opaque. * Takes also care of changing the regions. */ void setTranslucent(); /** * Helper to mark that this window will be transformed **/ void setTransformed(); }; class KWIN_EXPORT WindowPaintData { public: WindowPaintData(EffectWindow* w); /** * Window opacity, in range 0 = transparent to 1 = fully opaque * Opacity for contents is opacity*contents_opacity, the same * way for decoration. */ double opacity; double contents_opacity; double decoration_opacity; double xScale; double yScale; double zScale; int xTranslate; int yTranslate; double zTranslate; /** * Saturation of the window, in range [0; 1] * 1 means that the window is unchanged, 0 means that it's completely * unsaturated (greyscale). 0.5 would make the colors less intense, * but not completely grey * Use EffectsHandler::saturationSupported() to find out whether saturation * is supported by the system, otherwise this value has no effect. **/ double saturation; /** * Brightness of the window, in range [0; 1] * 1 means that the window is unchanged, 0 means that it's completely * black. 0.5 would make it 50% darker than usual **/ double brightness; WindowQuadList quads; /** * Shader to be used for rendering, if any. */ GLShader* shader; RotationData* rotation; }; class KWIN_EXPORT ScreenPaintData { public: ScreenPaintData(); double xScale; double yScale; double zScale; int xTranslate; int yTranslate; double zTranslate; RotationData* rotation; }; class KWIN_EXPORT ScreenPrePaintData { public: int mask; QRegion paint; }; class KWIN_EXPORT RotationData { public: RotationData(); enum RotationAxis { XAxis, YAxis, ZAxis }; RotationAxis axis; float angle; float xRotationPoint; float yRotationPoint; float zRotationPoint; }; /** * @short Helper class for restricting painting area only to allowed area. * * This helper class helps specifying areas that should be painted, clipping * out the rest. The simplest usage is creating an object on the stack * and giving it the area that is allowed to be painted to. When the object * is destroyed, the restriction will be removed. * Note that all painting code must use paintArea() to actually perform the clipping. */ class KWIN_EXPORT PaintClipper { public: /** * Calls push(). */ PaintClipper(const QRegion& allowed_area); /** * Calls pop(). */ ~PaintClipper(); /** * Allows painting only in the given area. When areas have been already * specified, painting is allowed only in the intersection of all areas. */ static void push(const QRegion& allowed_area); /** * Removes the given area. It must match the top item in the stack. */ static void pop(const QRegion& allowed_area); /** * Returns true if any clipping should be performed. */ static bool clip(); /** * If clip() returns true, this function gives the resulting area in which * painting is allowed. It is usually simpler to use the helper Iterator class. */ static QRegion paintArea(); /** * Helper class to perform the clipped painting. The usage is: * @code * for ( PaintClipper::Iterator iterator; * !iterator.isDone(); * iterator.next()) * { // do the painting, possibly use iterator.boundingRect() * } * @endcode */ class KWIN_EXPORT Iterator { public: Iterator(); ~Iterator(); bool isDone(); void next(); QRect boundingRect() const; private: struct Data; Data* data; }; private: QRegion area; static QStack< QRegion >* areas; }; /** * @internal */ template class KWIN_EXPORT Motion { public: /** * Creates a new motion object. "Strength" is the amount of * acceleration that is applied to the object when the target * changes and "smoothness" relates to how fast the object * can change its direction and speed. */ explicit Motion(T initial, double strength, double smoothness); /** * Creates an exact copy of another motion object, including * position, target and velocity. */ Motion(const Motion &other); ~Motion(); inline T value() const { return m_value; } inline void setValue(const T value) { m_value = value; } inline T target() const { return m_target; } inline void setTarget(const T target) { m_start = m_value; m_target = target; } inline T velocity() const { return m_velocity; } inline void setVelocity(const T velocity) { m_velocity = velocity; } inline double strength() const { return m_strength; } inline void setStrength(const double strength) { m_strength = strength; } inline double smoothness() const { return m_smoothness; } inline void setSmoothness(const double smoothness) { m_smoothness = smoothness; } inline T startValue() { return m_start; } /** * The distance between the current position and the target. */ inline T distance() const { return m_target - m_value; } /** * Calculates the new position if not at the target. Called * once per frame only. */ void calculate(const int msec); /** * Place the object on top of the target immediately, * bypassing all movement calculation. */ void finish(); private: T m_value; T m_start; T m_target; T m_velocity; double m_strength; double m_smoothness; }; /** * @short A single 1D motion dynamics object. * * This class represents a single object that can be moved around a * 1D space. Although it can be used directly by itself it is * recommended to use a motion manager instead. */ class KWIN_EXPORT Motion1D : public Motion { public: explicit Motion1D(double initial = 0.0, double strength = 0.08, double smoothness = 4.0); Motion1D(const Motion1D &other); ~Motion1D(); }; /** * @short A single 2D motion dynamics object. * * This class represents a single object that can be moved around a * 2D space. Although it can be used directly by itself it is * recommended to use a motion manager instead. */ class KWIN_EXPORT Motion2D : public Motion { public: explicit Motion2D(QPointF initial = QPointF(), double strength = 0.08, double smoothness = 4.0); Motion2D(const Motion2D &other); ~Motion2D(); }; /** * @short Helper class for motion dynamics in KWin effects. * * This motion manager class is intended to help KWin effect authors * move windows across the screen smoothly and naturally. Once * windows are registered by the manager the effect can issue move * commands with the moveWindow() methods. The position of any * managed window can be determined in realtime by the * transformedGeometry() method. As the manager knows if any windows * are moving at any given time it can also be used as a notifier as * to see whether the effect is active or not. */ class KWIN_EXPORT WindowMotionManager { public: /** * Creates a new window manager object. */ explicit WindowMotionManager(bool useGlobalAnimationModifier = true); ~WindowMotionManager(); /** * Register a window for managing. */ void manage(EffectWindow *w); /** * Register a list of windows for managing. */ inline void manage(EffectWindowList list) { for (int i = 0; i < list.size(); i++) manage(list.at(i)); } /** * Deregister a window. All transformations applied to the * window will be permanently removed and cannot be recovered. */ void unmanage(EffectWindow *w); /** * Deregister all windows, returning the manager to its * originally initiated state. */ void unmanageAll(); /** * Determine the new positions for windows that have not * reached their target. Called once per frame, usually in * prePaintScreen(). Remember to set the * Effect::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS flag. */ void calculate(int time); /** * Modify a registered window's paint data to make it appear * at its real location on the screen. Usually called in * paintWindow(). Remember to flag the window as having been * transformed in prePaintWindow() by calling * WindowPrePaintData::setTransformed() */ void apply(EffectWindow *w, WindowPaintData &data); /** * Set all motion targets and values back to where the * windows were before transformations. The same as * unmanaging then remanaging all windows. */ void reset(); /** * Resets the motion target and current value of a single * window. */ void reset(EffectWindow *w); /** * Ask the manager to move the window to the target position * with the specified scale. If `yScale` is not provided or * set to 0.0, `scale` will be used as the scale in the * vertical direction as well as in the horizontal direction. */ void moveWindow(EffectWindow *w, QPoint target, double scale = 1.0, double yScale = 0.0); /** * This is an overloaded method, provided for convenience. * * Ask the manager to move the window to the target rectangle. * Automatically determines scale. */ inline void moveWindow(EffectWindow *w, QRect target) { // TODO: Scale might be slightly different in the comparison due to rounding moveWindow(w, target.topLeft(), target.width() / double(w->width()), target.height() / double(w->height())); } /** * Retrieve the current tranformed geometry of a registered * window. */ QRectF transformedGeometry(EffectWindow *w) const; /** * Sets the current transformed geometry of a registered window to the given geometry. * @see transformedGeometry * @since 4.5 */ void setTransformedGeometry(EffectWindow *w, const QRectF &geometry); /** * Retrieve the current target geometry of a registered * window. */ QRectF targetGeometry(EffectWindow *w) const; /** * Return the window that has its transformed geometry under * the specified point. It is recommended to use the stacking * order as it's what the user sees, but it is slightly * slower to process. */ EffectWindow* windowAtPoint(QPoint point, bool useStackingOrder = true) const; /** * Return a list of all currently registered windows. */ inline EffectWindowList managedWindows() const { return m_managedWindows.keys(); } /** * Returns whether or not a specified window is being managed * by this manager object. */ inline bool isManaging(EffectWindow *w) const { return m_managedWindows.contains(w); } /** * Returns whether or not this manager object is actually * managing any windows or not. */ inline bool managingWindows() const { return !m_managedWindows.empty(); } /** * Returns whether all windows have reached their targets yet * or not. Can be used to see if an effect should be * processed and displayed or not. */ inline bool areWindowsMoving() const { return !m_movingWindowsSet.isEmpty(); } /** * Returns whether a window has reached its targets yet * or not. */ inline bool isWindowMoving(EffectWindow *w) const { return m_movingWindowsSet.contains(w); } private: bool m_useGlobalAnimationModifier; struct WindowMotion { // TODO: Rotation, etc? Motion2D translation; // Absolute position Motion2D scale; // xScale and yScale }; QHash m_managedWindows; QSet m_movingWindowsSet; }; /** * @short Helper class for displaying text and icons in frames. * * Paints text and/or and icon with an optional frame around them. The * available frames includes one that follows the default Plasma theme and * another that doesn't. * It is recommended to use this class whenever displaying text. */ class KWIN_EXPORT EffectFrame { public: EffectFrame(); virtual ~EffectFrame(); /** * Delete any existing textures to free up graphics memory. They will * be automatically recreated the next time they are required. */ virtual void free() = 0; /** * Render the frame. */ virtual void render(QRegion region = infiniteRegion(), double opacity = 1.0, double frameOpacity = 1.0) = 0; virtual void setPosition(const QPoint& point) = 0; /** * Set the text alignment for static frames and the position alignment * for non-static. */ virtual void setAlignment(Qt::Alignment alignment) = 0; virtual Qt::Alignment alignment() const = 0; virtual void setGeometry(const QRect& geometry, bool force = false) = 0; virtual const QRect& geometry() const = 0; virtual void setText(const QString& text) = 0; virtual const QString& text() const = 0; virtual void setFont(const QFont& font) = 0; virtual const QFont& font() const = 0; /** * Set the icon that will appear on the left-hand size of the frame. */ virtual void setIcon(const QPixmap& icon) = 0; virtual const QPixmap& icon() const = 0; virtual void setIconSize(const QSize& size) = 0; virtual const QSize& iconSize() const = 0; /** * Sets the geometry of a selection. * To remove the selection set a null rect. * @param selection The geometry of the selection in screen coordinates. **/ virtual void setSelection(const QRect& selection) = 0; /** * @param shader The GLShader for rendering. **/ virtual void setShader(GLShader* shader) = 0; /** * @returns The GLShader used for rendering or null if none. **/ virtual GLShader* shader() const = 0; /** * @returns The style of this EffectFrame. **/ virtual EffectFrameStyle style() const = 0; /** * If @p enable is @c true cross fading between icons and text is enabled * By default disabled. Use setCrossFadeProgress to cross fade. * Cross Fading is currently only available if OpenGL is used. * @param enable @c true enables cross fading, @c false disables it again * @see isCrossFade * @see setCrossFadeProgress * @since 4.6 **/ void enableCrossFade(bool enable); /** * @returns @c true if cross fading is enabled, @c false otherwise * @see enableCrossFade * @since 4.6 **/ bool isCrossFade() const; /** * Sets the current progress for cross fading the last used icon/text * with current icon/text to @p progress. * A value of 0.0 means completely old icon/text, a value of 1.0 means * completely current icon/text. * Default value is 1.0. You have to enable cross fade before using it. * Cross Fading is currently only available if OpenGL is used. * @see enableCrossFade * @see isCrossFade * @see crossFadeProgress * @since 4.6 **/ void setCrossFadeProgress(qreal progress); /** * @returns The current progress for cross fading * @see setCrossFadeProgress * @see enableCrossFade * @see isCrossFade * @since 4.6 **/ qreal crossFadeProgress() const; private: EffectFramePrivate* const d; }; /** * Pointer to the global EffectsHandler object. **/ extern KWIN_EXPORT EffectsHandler* effects; /*************************************************************** WindowVertex ***************************************************************/ inline WindowVertex::WindowVertex() : px(0), py(0), tx(0), ty(0) { } inline WindowVertex::WindowVertex(double _x, double _y, double _tx, double _ty) : px(_x), py(_y), ox(_x), oy(_y), tx(_tx), ty(_ty) { } inline double WindowVertex::x() const { return px; } inline double WindowVertex::y() const { return py; } inline double WindowVertex::originalX() const { return ox; } inline double WindowVertex::originalY() const { return oy; } inline double WindowVertex::textureX() const { return tx; } inline double WindowVertex::textureY() const { return ty; } inline void WindowVertex::move(double x, double y) { px = x; py = y; } inline void WindowVertex::setX(double x) { px = x; } inline void WindowVertex::setY(double y) { py = y; } /*************************************************************** WindowQuad ***************************************************************/ inline WindowQuad::WindowQuad(WindowQuadType t, int id) : quadType(t) , quadID(id) { } inline WindowVertex& WindowQuad::operator[](int index) { assert(index >= 0 && index < 4); return verts[ index ]; } inline const WindowVertex& WindowQuad::operator[](int index) const { assert(index >= 0 && index < 4); return verts[ index ]; } inline WindowQuadType WindowQuad::type() const { assert(quadType != WindowQuadError); return quadType; } inline int WindowQuad::id() const { return quadID; } inline bool WindowQuad::decoration() const { assert(quadType != WindowQuadError); return quadType == WindowQuadDecoration; } inline bool WindowQuad::effect() const { assert(quadType != WindowQuadError); return quadType >= EFFECT_QUAD_TYPE_START; } inline bool WindowQuad::isTransformed() const { return !(verts[ 0 ].px == verts[ 0 ].ox && verts[ 0 ].py == verts[ 0 ].oy && verts[ 1 ].px == verts[ 1 ].ox && verts[ 1 ].py == verts[ 1 ].oy && verts[ 2 ].px == verts[ 2 ].ox && verts[ 2 ].py == verts[ 2 ].oy && verts[ 3 ].px == verts[ 3 ].ox && verts[ 3 ].py == verts[ 3 ].oy); } inline double WindowQuad::left() const { return qMin(verts[ 0 ].px, qMin(verts[ 1 ].px, qMin(verts[ 2 ].px, verts[ 3 ].px))); } inline double WindowQuad::right() const { return qMax(verts[ 0 ].px, qMax(verts[ 1 ].px, qMax(verts[ 2 ].px, verts[ 3 ].px))); } inline double WindowQuad::top() const { return qMin(verts[ 0 ].py, qMin(verts[ 1 ].py, qMin(verts[ 2 ].py, verts[ 3 ].py))); } inline double WindowQuad::bottom() const { return qMax(verts[ 0 ].py, qMax(verts[ 1 ].py, qMax(verts[ 2 ].py, verts[ 3 ].py))); } inline double WindowQuad::originalLeft() const { return verts[ 0 ].ox; } inline double WindowQuad::originalRight() const { return verts[ 2 ].ox; } inline double WindowQuad::originalTop() const { return verts[ 0 ].oy; } inline double WindowQuad::originalBottom() const { return verts[ 2 ].oy; } /*************************************************************** Motion ***************************************************************/ template Motion::Motion(T initial, double strength, double smoothness) : m_value(initial) , m_start(initial) , m_target(initial) , m_velocity() , m_strength(strength) , m_smoothness(smoothness) { } template Motion::Motion(const Motion &other) : m_value(other.value()) , m_start(other.target()) , m_target(other.target()) , m_velocity(other.velocity()) , m_strength(other.strength()) , m_smoothness(other.smoothness()) { } template Motion::~Motion() { } template void Motion::calculate(const int msec) { if (m_value == m_target && m_velocity == T()) // At target and not moving return; // Poor man's time independent calculation int steps = qMax(1, msec / 5); for (int i = 0; i < steps; i++) { T diff = m_target - m_value; T strength = diff * m_strength; m_velocity = (m_smoothness * m_velocity + strength) / (m_smoothness + 1.0); m_value += m_velocity; } } template void Motion::finish() { m_value = m_target; m_velocity = T(); } } // namespace /** @} */ #endif // KWINEFFECTS_H