block screen change when edge is occupied

--unfortunately this contains also white spaces
fixes. Sorry for this but by implementing multi-screen
the laptop wasnt correctly configured for
astyle and whitespaces
pull/1/head
Michail Vourlakos 8 years ago
parent 0bef60838a
commit 18f57f51fd

@ -246,6 +246,7 @@ void DockCorona::addOutput(QScreen *screen)
Q_ASSERT(screen); Q_ASSERT(screen);
int id = m_screenPool->id(screen->name()); int id = m_screenPool->id(screen->name());
if (id == -1) { if (id == -1) {
int newId = m_screenPool->firstAvailableId(); int newId = m_screenPool->firstAvailableId();
m_screenPool->insertScreenMapping(newId, screen->name()); m_screenPool->insertScreenMapping(newId, screen->name());
@ -282,6 +283,7 @@ void DockCorona::screenCountChangedTimer()
qDebug() << "adding consideration...."; qDebug() << "adding consideration....";
qDebug() << "dock view running : " << m_dockViews.count(); qDebug() << "dock view running : " << m_dockViews.count();
foreach (auto scr, qGuiApp->screens()) { foreach (auto scr, qGuiApp->screens()) {
qDebug() << "Found screen: " << scr->name(); qDebug() << "Found screen: " << scr->name();
@ -302,8 +304,10 @@ void DockCorona::screenCountChangedTimer()
} }
qDebug() << "removing consideration & updating screen for always on primary docks...."; qDebug() << "removing consideration & updating screen for always on primary docks....";
foreach (auto view, m_dockViews) { foreach (auto view, m_dockViews) {
bool found{false}; bool found{false};
foreach (auto scr, qGuiApp->screens()) { foreach (auto scr, qGuiApp->screens()) {
int id = view->containment()->screen(); int id = view->containment()->screen();
@ -375,6 +379,21 @@ void DockCorona::aboutApplication()
aboutDialog->show(); aboutDialog->show();
} }
QList<Plasma::Types::Location> DockCorona::freeEdges(QScreen *screen) const
{
using Plasma::Types;
QList<Types::Location> edges{Types::BottomEdge, Types::LeftEdge,
Types::TopEdge, Types::RightEdge};
for (auto *view : m_dockViews) {
if (view && view->currentScreen() == screen->name()) {
edges.removeOne(view->location());
}
}
return edges;
}
QList<Plasma::Types::Location> DockCorona::freeEdges(int screen) const QList<Plasma::Types::Location> DockCorona::freeEdges(int screen) const
{ {
using Plasma::Types; using Plasma::Types;
@ -475,6 +494,7 @@ void DockCorona::addDock(Plasma::Containment *containment)
QString connector = m_screenPool->connector(id); QString connector = m_screenPool->connector(id);
qDebug() << "add dock - connector : " << connector; qDebug() << "add dock - connector : " << connector;
bool found{false}; bool found{false};
foreach (auto scr, qGuiApp->screens()) { foreach (auto scr, qGuiApp->screens()) {
if (scr && scr->name() == connector) { if (scr && scr->name() == connector) {
found = true; found = true;

@ -55,6 +55,7 @@ public:
QRect availableScreenRect(int id) const override; QRect availableScreenRect(int id) const override;
QList<Plasma::Types::Location> freeEdges(int screen) const; QList<Plasma::Types::Location> freeEdges(int screen) const;
QList<Plasma::Types::Location> freeEdges(QScreen *screen) const;
int docksCount(int screen) const; int docksCount(int screen) const;
int screenForContainment(const Plasma::Containment *containment) const override; int screenForContainment(const Plasma::Containment *containment) const override;

@ -153,24 +153,39 @@ void DockView::init()
qDebug() << "SOURCE:" << source(); qDebug() << "SOURCE:" << source();
} }
void DockView::setCurrentScreen(const QString id) bool DockView::setCurrentScreen(const QString id)
{ {
if (!m_screenToFollow || m_screenToFollow->name() == id) { if (!m_screenToFollow || m_screenToFollow->name() == id) {
return; return false;
} }
QScreen *nextScreen{nullptr}; QScreen *nextScreen{qGuiApp->primaryScreen()};
if (id != "primary") {
foreach (auto scr, qGuiApp->screens()) { foreach (auto scr, qGuiApp->screens()) {
if (scr && scr->name() == id) { if (scr && scr->name() == id) {
nextScreen = scr; nextScreen = scr;
break; break;
} }
} }
}
if (nextScreen) {
auto *dockCorona = qobject_cast<DockCorona *>(this->corona());
if (dockCorona) {
auto freeEdges = dockCorona->freeEdges(nextScreen);
if (nextScreen) if (!freeEdges.contains(location())) {
return false;
} else {
setScreenToFollow(nextScreen); setScreenToFollow(nextScreen);
} }
}
}
return false;
}
void DockView::setScreenToFollow(QScreen *screen) void DockView::setScreenToFollow(QScreen *screen)
{ {

@ -130,7 +130,7 @@ public slots:
Q_INVOKABLE QList<int> freeEdges() const; Q_INVOKABLE QList<int> freeEdges() const;
Q_INVOKABLE QVariantList containmentActions(); Q_INVOKABLE QVariantList containmentActions();
Q_INVOKABLE void setLocalDockGeometry(const QRect &geometry); Q_INVOKABLE void setLocalDockGeometry(const QRect &geometry);
Q_INVOKABLE void setCurrentScreen(const QString id); Q_INVOKABLE bool setCurrentScreen(const QString id);
Q_INVOKABLE bool tasksPresent(); Q_INVOKABLE bool tasksPresent();
Q_INVOKABLE void updateEnabledBorders(); Q_INVOKABLE void updateEnabledBorders();

@ -99,14 +99,43 @@ PlasmaComponents.Page {
Layout.fillWidth: true Layout.fillWidth: true
Component.onCompleted: screenRow.updateScreens(); Component.onCompleted: screenRow.updateScreens();
//they are used to restore the index when the screen edge
//is occuppied
property bool acceptedIndex: true
property int previousIndex: -1
onCurrentIndexChanged: {
//it is used to restore the index when the screen edge
//is occuppied
if (!acceptedIndex) {
acceptedIndex = true;
currentIndex = previousIndex;
}
}
onActivated: { onActivated: {
previousIndex = currentIndex;
if (index === 0) { if (index === 0) {
var succeed = dock.setCurrentScreen("primary");
if (succeed) {
dock.onPrimary = true; dock.onPrimary = true;
} else {
console.log("the edge is already occupied!!!");
acceptedIndex = false;
}
} else if (index>0 && (index !== find(dock.currentScreen) || dock.onPrimary)) { } else if (index>0 && (index !== find(dock.currentScreen) || dock.onPrimary)) {
console.log("current index changed!!! :"+ index); console.log("current index changed!!! :"+ index);
console.log("screen must be changed..."); console.log("screen must be changed...");
var succeed = dock.setCurrentScreen(textAt(index));
if(succeed) {
dock.onPrimary = false; dock.onPrimary = false;
dock.setCurrentScreen(textAt(index)); } else {
console.log("the edge is already occupied!!!");
acceptedIndex = false;
}
} }
} }
} }

Loading…
Cancel
Save