diff --git a/effects.cpp b/effects.cpp index 047fd4e308..1f581fa667 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1072,7 +1072,7 @@ xcb_window_t EffectsHandlerImpl::createInputWindow(Effect* e, int x, int y, int // Raise electric border windows above the input windows // so they can still be triggered. #ifdef KWIN_BUILD_SCREENEDGES - Workspace::self()->screenEdge()->ensureOnTop(); + ScreenEdges::self()->ensureOnTop(); #endif if (input_windows.count() > 10) // that sounds like some leak - could still be correct, thoug - so NO ABORT HERE! kDebug() << "** warning ** there are now " << input_windows.count() << @@ -1086,7 +1086,7 @@ void EffectsHandlerImpl::destroyInputWindow(xcb_window_t w) if (pos.second == w) { xcb_unmap_window(connection(), w); #ifdef KWIN_BUILD_SCREENEDGES - Workspace::self()->screenEdge()->raisePanelProxies(); + ScreenEdges::self()->raisePanelProxies(); #endif return; } @@ -1169,7 +1169,7 @@ void EffectsHandlerImpl::checkInputWindowStacking() // so they can still be triggered. TODO: Do both at once. #ifdef KWIN_BUILD_SCREENEDGES if (pos) - Workspace::self()->screenEdge()->ensureOnTop(); + ScreenEdges::self()->ensureOnTop(); #endif } @@ -1181,7 +1181,7 @@ QPoint EffectsHandlerImpl::cursorPos() const void EffectsHandlerImpl::reserveElectricBorder(ElectricBorder border, Effect *effect) { #ifdef KWIN_BUILD_SCREENEDGES - Workspace::self()->screenEdge()->reserve(border, effect, "borderActivated"); + ScreenEdges::self()->reserve(border, effect, "borderActivated"); #else Q_UNUSED(border) Q_UNUSED(effect) @@ -1191,7 +1191,7 @@ void EffectsHandlerImpl::reserveElectricBorder(ElectricBorder border, Effect *ef void EffectsHandlerImpl::unreserveElectricBorder(ElectricBorder border, Effect *effect) { #ifdef KWIN_BUILD_SCREENEDGES - Workspace::self()->screenEdge()->unreserve(border, effect); + ScreenEdges::self()->unreserve(border, effect); #else Q_UNUSED(border) Q_UNUSED(effect) diff --git a/events.cpp b/events.cpp index b542f3c5bb..781359ea42 100644 --- a/events.cpp +++ b/events.cpp @@ -386,7 +386,7 @@ bool Workspace::workspaceEvent(XEvent * e) QWhatsThis::leaveWhatsThisMode(); } #ifdef KWIN_BUILD_SCREENEDGES - if (m_screenEdge->isEntered(e)) + if (ScreenEdges::self()->isEntered(e)) return true; #endif break; @@ -440,7 +440,7 @@ bool Workspace::workspaceEvent(XEvent * e) return true; // always eat these, they would tell Qt that KWin is the active app case ClientMessage: #ifdef KWIN_BUILD_SCREENEDGES - if (m_screenEdge->isEntered(e)) + if (ScreenEdges::self()->isEntered(e)) return true; #endif break; diff --git a/geometry.cpp b/geometry.cpp index b9c0728fde..682e013556 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -82,7 +82,7 @@ void Workspace::desktopResized() // TODO: emit a signal instead and remove the deep function calls into edges and effects #ifdef KWIN_BUILD_SCREENEDGES - m_screenEdge->recreateEdges(); + ScreenEdges::self()->recreateEdges(); #endif if (effects) { @@ -2580,8 +2580,8 @@ bool Client::startMoveResize() Notify::raise(isResize() ? Notify::ResizeStart : Notify::MoveStart); emit clientStartUserMovedResized(this); #ifdef KWIN_BUILD_SCREENEDGES - if (workspace()->screenEdge()->isDesktopSwitchingMovingClients()) - workspace()->screenEdge()->reserveDesktopSwitching(true, Qt::Vertical|Qt::Horizontal); + if (ScreenEdges::self()->isDesktopSwitchingMovingClients()) + ScreenEdges::self()->reserveDesktopSwitching(true, Qt::Vertical|Qt::Horizontal); #endif if (fakeMove) // fix geom_restore position - it HAS to happen at the end, ie. when all moving is set up. inline call will lock focus!! handleMoveResize(QCursor::pos().x(), QCursor::pos().y(), QCursor::pos().x(), QCursor::pos().y()); @@ -2662,8 +2662,8 @@ void Client::leaveMoveResize() syncRequest.timeout = NULL; #endif #ifdef KWIN_BUILD_SCREENEDGES - if (workspace()->screenEdge()->isDesktopSwitchingMovingClients()) - workspace()->screenEdge()->reserveDesktopSwitching(false, Qt::Vertical|Qt::Horizontal); + if (ScreenEdges::self()->isDesktopSwitchingMovingClients()) + ScreenEdges::self()->reserveDesktopSwitching(false, Qt::Vertical|Qt::Horizontal); #endif } @@ -3027,11 +3027,11 @@ void Client::handleMoveResize(int x, int y, int x_root, int y_root) #endif performMoveResize(); - if (isMove()) { #ifdef KWIN_BUILD_SCREENEDGES - workspace()->screenEdge()->check(globalPos, QDateTime::fromMSecsSinceEpoch(xTime())); -#endif + if (isMove()) { + ScreenEdges::self()->check(globalPos, QDateTime::fromMSecsSinceEpoch(xTime())); } +#endif } void Client::performMoveResize() diff --git a/layers.cpp b/layers.cpp index 1dab283484..71868c605f 100644 --- a/layers.cpp +++ b/layers.cpp @@ -163,7 +163,7 @@ void Workspace::propagateClients(bool propagate_new_clients) // windows (e.g. popups). newWindowStack << (Window*)supportWindow->winId(); #ifdef KWIN_BUILD_SCREENEDGES - QVectorIterator it(m_screenEdge->windows()); + QVectorIterator it(ScreenEdges::self()->windows()); while (it.hasNext()) { if ((Window)it.next() != None) { newWindowStack << (Window*)⁢ diff --git a/screenedge.cpp b/screenedge.cpp index dbdaec3017..8b7837a0f2 100644 --- a/screenedge.cpp +++ b/screenedge.cpp @@ -338,6 +338,15 @@ void WindowBasedEdge::doGeometryUpdate() /********************************************************** * ScreenEdges *********************************************************/ +ScreenEdges *ScreenEdges::s_self = NULL; + +ScreenEdges *ScreenEdges::create(QObject *parent) +{ + Q_ASSERT(!s_self); + s_self = new ScreenEdges(parent); + return s_self; +} + ScreenEdges::ScreenEdges(QObject *parent) : QObject(parent) , m_desktopSwitching(false) @@ -358,6 +367,7 @@ ScreenEdges::ScreenEdges(QObject *parent) ScreenEdges::~ScreenEdges() { + s_self = NULL; } void ScreenEdges::init() diff --git a/screenedge.h b/screenedge.h index 749f8e94ed..b6efe1ab6e 100644 --- a/screenedge.h +++ b/screenedge.h @@ -261,6 +261,20 @@ public: ElectricBorderAction actionBottom() const; ElectricBorderAction actionBottomLeft() const; ElectricBorderAction actionLeft() const; + + /** + * Singleton getter for this manager. + * + * Does not create a new instance. If the manager has not been created yet a @c null pointer + * is returned. + * @see create + **/ + static ScreenEdges *self(); + /** + * Factory method to create the ScreenEdges. + * @see self + **/ + static ScreenEdges *create(QObject *parent = NULL); public Q_SLOTS: void reconfigure(); /** @@ -300,6 +314,8 @@ private: ElectricBorderAction m_actionBottom; ElectricBorderAction m_actionBottomLeft; ElectricBorderAction m_actionLeft; + + static ScreenEdges *s_self; }; /********************************************************** @@ -479,5 +495,11 @@ ACTION(actionLeft) #undef ACTION +inline ScreenEdges *ScreenEdges::self() +{ + Q_ASSERT(s_self); + return s_self; +} + } #endif // KWIN_SCREENEDGE_H diff --git a/scripting/scriptingutils.h b/scripting/scriptingutils.h index ed163df42b..6f4a5684c5 100644 --- a/scripting/scriptingutils.h +++ b/scripting/scriptingutils.h @@ -162,7 +162,7 @@ QScriptValue registerScreenEdge(QScriptContext *context, QScriptEngine *engine) if (it == script->screenEdgeCallbacks().end()) { // not yet registered #ifdef KWIN_BUILD_SCREENEDGES - KWin::Workspace::self()->screenEdge()->reserve(static_cast(edge), script, "borderActivated"); + ScreenEdges::self()->reserve(static_cast(edge), script, "borderActivated"); #endif script->screenEdgeCallbacks().insert(edge, QList() << context->argument(1)); } else { diff --git a/workspace.cpp b/workspace.cpp index 47e84a8abb..d16d7fd1d2 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -99,9 +99,6 @@ Workspace* Workspace::_self = 0; Workspace::Workspace(bool restore) : QObject(0) -#ifdef KWIN_BUILD_SCREENEDGES - , m_screenEdge(new ScreenEdges(this)) -#endif , m_compositor(NULL) // Unsorted , active_popup(NULL) @@ -197,6 +194,10 @@ Workspace::Workspace(bool restore) ExposureMask ); +#ifdef KWIN_BUILD_SCREENEDGES + ScreenEdges::create(this); +#endif + // VirtualDesktopManager needs to be created prior to init shortcuts // and prior to TabBox, due to TabBox connecting to signals // actual initialization happens in init() @@ -261,10 +262,11 @@ void Workspace::screenChangeTimeout() void Workspace::init() { #ifdef KWIN_BUILD_SCREENEDGES - m_screenEdge->setConfig(KGlobal::config()); - m_screenEdge->init(); - connect(options, SIGNAL(configChanged()), m_screenEdge, SLOT(reconfigure())); - connect(VirtualDesktopManager::self(), SIGNAL(layoutChanged(int,int)), m_screenEdge, SLOT(updateLayout())); + ScreenEdges *screenEdges = ScreenEdges::self(); + screenEdges->setConfig(KGlobal::config()); + screenEdges->init(); + connect(options, SIGNAL(configChanged()), screenEdges, SLOT(reconfigure())); + connect(VirtualDesktopManager::self(), SIGNAL(layoutChanged(int,int)), screenEdges, SLOT(updateLayout())); #endif supportWindow = new QWidget(NULL, Qt::X11BypassWindowManagerHint); @@ -1934,13 +1936,6 @@ Outline* Workspace::outline() return m_outline; } -#ifdef KWIN_BUILD_SCREENEDGES -ScreenEdges* Workspace::screenEdge() -{ - return m_screenEdge; -} -#endif - bool Workspace::hasTabBox() const { #ifdef KWIN_BUILD_TABBOX @@ -1999,13 +1994,13 @@ QString Workspace::supportInformation() const #ifdef KWIN_BUILD_SCREENEDGES support.append("\nScreen Edges\n"); support.append( "============\n"); - const QMetaObject *metaScreenEdges = m_screenEdge->metaObject(); + const QMetaObject *metaScreenEdges = ScreenEdges::self()->metaObject(); for (int i=0; ipropertyCount(); ++i) { const QMetaProperty property = metaScreenEdges->property(i); if (QLatin1String(property.name()) == "objectName") { continue; } - support.append(QLatin1String(property.name()) % ": " % m_screenEdge->property(property.name()).toString() % '\n'); + support.append(QLatin1String(property.name()) % ": " % ScreenEdges::self()->property(property.name()).toString() % '\n'); } #endif support.append("\nScreens\n"); diff --git a/workspace.h b/workspace.h index 4d7a75ce91..d663c9ef3b 100644 --- a/workspace.h +++ b/workspace.h @@ -75,7 +75,6 @@ class Scripting; class UserActionsMenu; class WindowRules; class Compositor; -class ScreenEdges; class Workspace : public QObject, public KDecorationDefines { @@ -199,9 +198,6 @@ public: } Outline* outline(); -#ifdef KWIN_BUILD_SCREENEDGES - ScreenEdges* screenEdge(); -#endif public: QPoint cascadeOffset(const Client *c) const; @@ -214,9 +210,6 @@ private: #endif Outline* m_outline; -#ifdef KWIN_BUILD_SCREENEDGES - ScreenEdges *m_screenEdge; -#endif Compositor *m_compositor; //-------------------------------------------------