Turn ScreenEdges into a Singleton

In fact it already used to be a Singleton as there is just one object
hold by the Singleton Workspace. So let's make it a proper Singleton
following our kind of standard approach of having a ::create factory
method called from Workspace ctor and a ::self to get to the singleton
instance.
This commit is contained in:
Martin Gräßlin 2013-01-25 10:15:00 +01:00
parent 7a7f9d1a34
commit a8539ff54e
9 changed files with 60 additions and 40 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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()

View file

@ -163,7 +163,7 @@ void Workspace::propagateClients(bool propagate_new_clients)
// windows (e.g. popups).
newWindowStack << (Window*)supportWindow->winId();
#ifdef KWIN_BUILD_SCREENEDGES
QVectorIterator<xcb_window_t> it(m_screenEdge->windows());
QVectorIterator<xcb_window_t> it(ScreenEdges::self()->windows());
while (it.hasNext()) {
if ((Window)it.next() != None) {
newWindowStack << (Window*)&it;

View file

@ -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()

View file

@ -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

View file

@ -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<KWin::ElectricBorder>(edge), script, "borderActivated");
ScreenEdges::self()->reserve(static_cast<KWin::ElectricBorder>(edge), script, "borderActivated");
#endif
script->screenEdgeCallbacks().insert(edge, QList<QScriptValue>() << context->argument(1));
} else {

View file

@ -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; i<metaScreenEdges->propertyCount(); ++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");

View file

@ -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;
//-------------------------------------------------