From 5226b6adcedb5bd001c31e3a51cdbf9e1bf532d0 Mon Sep 17 00:00:00 2001 From: Johan Smith Agudelo Rodriguez Date: Sun, 12 Mar 2017 15:14:30 -0500 Subject: [PATCH] code formatted --- app/abstractwindowinterface.cpp | 8 +++--- app/alternativeshelper.cpp | 6 +++-- app/alternativeshelper.h | 3 +-- app/screenpool.cpp | 45 ++++++++++++++++++++------------- app/screenpool.h | 5 ++-- app/visibilitymanager.cpp | 23 +++++++++-------- app/windowinfowrap.h | 6 ++--- 7 files changed, 53 insertions(+), 43 deletions(-) diff --git a/app/abstractwindowinterface.cpp b/app/abstractwindowinterface.cpp index 00d5cd355..d09c3010b 100644 --- a/app/abstractwindowinterface.cpp +++ b/app/abstractwindowinterface.cpp @@ -44,10 +44,10 @@ void AbstractWindowInterface::addDock(WId wid) void AbstractWindowInterface::removeDock(WId wid) { - auto it = std::find(m_docks.begin(), m_docks.end(), wid); + auto it = std::find(m_docks.begin(), m_docks.end(), wid); - if (it != m_docks.end()) - m_docks.erase(it); + if (it != m_docks.end()) + m_docks.erase(it); } AbstractWindowInterface &AbstractWindowInterface::self() @@ -57,7 +57,7 @@ AbstractWindowInterface &AbstractWindowInterface::self() if (KWindowSystem::isPlatformWayland()) { //! TODO: WaylandWindowInterface - } else /* if(KWindowSystem::isPlatformX11) */ { + } else { /* if(KWindowSystem::isPlatformX11) */ m_wm = std::make_unique(); } diff --git a/app/alternativeshelper.cpp b/app/alternativeshelper.cpp index c4117bb85..90c7f0f36 100644 --- a/app/alternativeshelper.cpp +++ b/app/alternativeshelper.cpp @@ -68,12 +68,14 @@ void AlternativesHelper::loadAlternative(const QString &plugin) } Plasma::Containment *cont = m_applet->containment(); + if (!cont) { return; } QQuickItem *appletItem = m_applet->property("_plasma_graphicObject").value(); QQuickItem *contItem = cont->property("_plasma_graphicObject").value(); + if (!appletItem || !contItem) { return; } @@ -82,11 +84,11 @@ void AlternativesHelper::loadAlternative(const QString &plugin) const QKeySequence &shortcut = m_applet->globalShortcut(); m_applet->setGlobalShortcut(QKeySequence()); // need to unmap the old one first - const QPoint newPos = appletItem->mapToItem(contItem, QPointF(0,0)).toPoint(); + const QPoint newPos = appletItem->mapToItem(contItem, QPointF(0, 0)).toPoint(); m_applet->destroy(); - connect(m_applet, &QObject::destroyed, [=]() { + connect(m_applet, &QObject::destroyed, [ = ]() { Plasma::Applet *newApplet = Q_NULLPTR; QMetaObject::invokeMethod(contItem, "createApplet", Q_RETURN_ARG(Plasma::Applet *, newApplet), Q_ARG(QString, plugin), Q_ARG(QVariantList, QVariantList()), Q_ARG(QPoint, newPos)); diff --git a/app/alternativeshelper.h b/app/alternativeshelper.h index a302bf01e..a732dd0f1 100644 --- a/app/alternativeshelper.h +++ b/app/alternativeshelper.h @@ -24,8 +24,7 @@ #include -class AlternativesHelper : public QObject -{ +class AlternativesHelper : public QObject { Q_OBJECT Q_PROPERTY(QStringList appletProvides READ appletProvides CONSTANT) Q_PROPERTY(QString currentPlugin READ currentPlugin CONSTANT) diff --git a/app/screenpool.cpp b/app/screenpool.cpp index c168c7041..c7be0a226 100644 --- a/app/screenpool.cpp +++ b/app/screenpool.cpp @@ -25,10 +25,10 @@ #include #if HAVE_X11 -#include -#include -#include -#include + #include + #include + #include + #include #endif ScreenPool::ScreenPool(KSharedConfig::Ptr config, QObject *parent) @@ -38,7 +38,7 @@ ScreenPool::ScreenPool(KSharedConfig::Ptr config, QObject *parent) qApp->installNativeEventFilter(this); m_configSaveTimer.setSingleShot(true); - connect(&m_configSaveTimer, &QTimer::timeout, this, [this](){ + connect(&m_configSaveTimer, &QTimer::timeout, this, [this]() { m_configGroup.sync(); }); } @@ -50,8 +50,10 @@ void ScreenPool::load() m_idForConnector.clear(); QScreen *primary = qGuiApp->primaryScreen(); + if (primary) { m_primaryConnector = primary->name(); + if (!m_primaryConnector.isEmpty()) { //m_connectorForId[0] = m_primaryConnector; //m_idForConnector[m_primaryConnector] = 0; @@ -61,7 +63,8 @@ void ScreenPool::load() //restore the known ids to connector mappings foreach (const QString &key, m_configGroup.keyList()) { QString connector = m_configGroup.readEntry(key, QString()); - qDebug() << "connector :" << connector << " - " <screen() will return an incorrect -1 // at startup, if it' asked before corona::addOutput() // is performed, driving to the creation of a new containment - for (QScreen* screen : qGuiApp->screens()) { + for (QScreen *screen : qGuiApp->screens()) { if (!m_idForConnector.contains(screen->name())) { insertScreenMapping(firstAvailableId(), screen->name()); } @@ -101,28 +104,31 @@ void ScreenPool::setPrimaryConnector(const QString &primary) //there are case that the QScreen instead of the correct screen name //returns "0:0", this check prevents from breaking the screens database //from garbage ids - if ((m_primaryConnector == primary)|| primary.startsWith(":")) { + if ((m_primaryConnector == primary) || primary.startsWith(":")) { return; } + Q_ASSERT(m_idForConnector.contains(primary)); - /* int oldIdForPrimary = m_idForConnector.value(primary); + /* int oldIdForPrimary = m_idForConnector.value(primary); - m_idForConnector[primary] = 0; - m_connectorForId[0] = primary; - m_idForConnector[m_primaryConnector] = oldIdForPrimary; - m_connectorForId[oldIdForPrimary] = m_primaryConnector; - m_primaryConnector = primary; -*/ + m_idForConnector[primary] = 0; + m_connectorForId[0] = primary; + m_idForConnector[m_primaryConnector] = oldIdForPrimary; + m_connectorForId[oldIdForPrimary] = m_primaryConnector; + m_primaryConnector = primary; + */ save(); } void ScreenPool::save() { QMap::const_iterator i; + for (i = m_connectorForId.constBegin(); i != m_connectorForId.constEnd(); ++i) { m_configGroup.writeEntry(QString::number(i.key()), i.value()); } + //write to disck every 30 seconds at most m_configSaveTimer.start(30000); } @@ -173,12 +179,14 @@ int ScreenPool::firstAvailableId() const //be used for special cases. //e.g primaryScreen, id=0 int i = 10; + //find the first integer not stored in m_connectorForId //m_connectorForId is the only map, so the ids are sorted foreach (int existingId, m_connectorForId.keys()) { if (i != existingId) { return i; } + ++i; } @@ -190,10 +198,11 @@ QList ScreenPool::knownIds() const return m_connectorForId.keys(); } -bool ScreenPool::nativeEventFilter(const QByteArray& eventType, void* message, long int* result) +bool ScreenPool::nativeEventFilter(const QByteArray &eventType, void *message, long int *result) { Q_UNUSED(result); #if HAVE_X11 + // a particular edge case: when we switch the only enabled screen // we don't have any signal about it, the primary screen changes but we have the same old QScreen* getting recycled // see https://bugs.kde.org/show_bug.cgi?id=373880 @@ -206,7 +215,7 @@ bool ScreenPool::nativeEventFilter(const QByteArray& eventType, void* message, l const auto responseType = XCB_EVENT_RESPONSE_TYPE(ev); - const xcb_query_extension_reply_t* reply = xcb_get_extension_data(QX11Info::connection(), &xcb_randr_id); + const xcb_query_extension_reply_t *reply = xcb_get_extension_data(QX11Info::connection(), &xcb_randr_id); if (responseType == reply->first_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY) { if (qGuiApp->primaryScreen()->name() != primaryConnector()) { @@ -214,12 +223,14 @@ bool ScreenPool::nativeEventFilter(const QByteArray& eventType, void* message, l if (id(qGuiApp->primaryScreen()->name()) < 0) { insertScreenMapping(firstAvailableId(), qGuiApp->primaryScreen()->name()); } + //switch the primary screen in the pool setPrimaryConnector(qGuiApp->primaryScreen()->name()); emit primaryPoolChanged(); } } + #endif return false; } diff --git a/app/screenpool.h b/app/screenpool.h index ac33d1ed8..c84ace6cf 100644 --- a/app/screenpool.h +++ b/app/screenpool.h @@ -29,8 +29,7 @@ #include #include -class ScreenPool : public QObject, public QAbstractNativeEventFilter -{ +class ScreenPool : public QObject, public QAbstractNativeEventFilter { Q_OBJECT public: @@ -56,7 +55,7 @@ signals: void primaryPoolChanged(); protected: - bool nativeEventFilter(const QByteArray & eventType, void * message, long * result) Q_DECL_OVERRIDE; + bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE; private: void save(); diff --git a/app/visibilitymanager.cpp b/app/visibilitymanager.cpp index dad6f5de5..ce0deb187 100644 --- a/app/visibilitymanager.cpp +++ b/app/visibilitymanager.cpp @@ -84,16 +84,16 @@ inline void VisibilityManagerPrivate::setMode(Dock::Visibility mode) wm->removeDockStruts(view->winId()); } else { connections[3] = connect(wm, &WindowSystem::currentDesktopChanged - , this, [&]{ + , this, [&] { if (raiseOnDesktopChange) raiseDockTemporarily(); }); connections[4] = connect(wm, &WindowSystem::currentActivityChanged - , this, [&]() { - if (raiseOnActivityChange) - raiseDockTemporarily(); - else - updateHiddenState(); + , this, [&]() { + if (raiseOnActivityChange) + raiseDockTemporarily(); + else + updateHiddenState(); }); } @@ -139,7 +139,7 @@ inline void VisibilityManagerPrivate::setMode(Dock::Visibility mode) connections[0] = connect(wm, &WindowSystem::activeWindowChanged , this, &VisibilityManagerPrivate::dodgeMaximized); connections[1] = connect(wm, &WindowSystem::windowChanged - , this, &VisibilityManagerPrivate::dodgeMaximized); + , this, &VisibilityManagerPrivate::dodgeMaximized); dodgeMaximized(wm->activeWindow()); } break; @@ -355,7 +355,7 @@ void VisibilityManagerPrivate::dodgeMaximized(WId wid) if (wm->isOnCurrentDesktop(wid) && !winfo.isMinimized()) raiseDock(!(view->formFactor() == Plasma::Types::Vertical - ? winfo.isMaxHoriz() : winfo.isMaxVert())); + ? winfo.isMaxHoriz() : winfo.isMaxVert())); } void VisibilityManagerPrivate::dodgeWindows(WId wid) @@ -434,9 +434,9 @@ inline void VisibilityManagerPrivate::restoreConfig() emit q->timerHideChanged(); if (mode == Dock::AlwaysVisible) { - setMode(mode); + setMode(mode); } else { - QTimer::singleShot(5000, this, [&, mode]() { + QTimer::singleShot(5000, this, [ &, mode]() { setMode(mode); }); setRaiseOnDesktop(config.readEntry("raiseOnDesktopChange", false)); @@ -445,7 +445,7 @@ inline void VisibilityManagerPrivate::restoreConfig() qDebug() << config.entryMap(); connect(view->containment(), &Plasma::Containment::userConfiguringChanged - , this, [&](bool configuring) { + , this, [&](bool configuring) { if (!configuring) saveConfig(); }); @@ -477,6 +477,7 @@ bool VisibilityManagerPrivate::event(QEvent *ev) case QEvent::DragEnter: dragEnter = true; + if (isHidden) emit q->mustBeShown(VisibilityManager::QPrivateSignal{}); diff --git a/app/windowinfowrap.h b/app/windowinfowrap.h index 6417c5b23..22c4172e7 100644 --- a/app/windowinfowrap.h +++ b/app/windowinfowrap.h @@ -37,8 +37,7 @@ public: , m_isMaxHorz(false) , m_isFullscreen(false) , m_isPlasmaDesktop(false) - , m_wid(0) - { + , m_wid(0) { } constexpr WindowInfoWrap(const WindowInfoWrap &other) @@ -49,8 +48,7 @@ public: , m_isMaxHorz(other.m_isMaxHorz) , m_isFullscreen(other.m_isFullscreen) , m_isPlasmaDesktop(other.m_isPlasmaDesktop) - , m_wid(other.m_wid) - { + , m_wid(other.m_wid) { } inline WindowInfoWrap &operator=(const WindowInfoWrap &rhs);