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

@ -227,13 +227,13 @@ QRect DockCorona::availableScreenRect(int id) const
// need calculate available space for top and bottom location, // need calculate available space for top and bottom location,
// because the left and right are those who dodge others docks // because the left and right are those who dodge others docks
switch (view->location()) { switch (view->location()) {
case Plasma::Types::TopEdge: case Plasma::Types::TopEdge:
available.setTopLeft({available.x(), dockRect.bottom()}); available.setTopLeft({available.x(), dockRect.bottom()});
break; break;
case Plasma::Types::BottomEdge: case Plasma::Types::BottomEdge:
available.setBottomLeft({available.x(), dockRect.top()}); available.setBottomLeft({available.x(), dockRect.top()});
break; break;
} }
} }
} }
@ -246,7 +246,8 @@ 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());
} }
@ -254,16 +255,16 @@ void DockCorona::addOutput(QScreen *screen)
void DockCorona::primaryOutputChanged() void DockCorona::primaryOutputChanged()
{ {
/* qDebug() << "primary changed ### "<< qGuiApp->primaryScreen()->name(); /* qDebug() << "primary changed ### "<< qGuiApp->primaryScreen()->name();
foreach(auto scr, qGuiApp->screens()){ foreach(auto scr, qGuiApp->screens()){
qDebug() << "Found screen: "<<scr->name(); qDebug() << "Found screen: "<<scr->name();
}*/ }*/
//if (m_dockViews.count()==1 && qGuiApp->screens().size()==1) { //if (m_dockViews.count()==1 && qGuiApp->screens().size()==1) {
// foreach(auto view, m_dockViews) { // foreach(auto view, m_dockViews) {
// view->setScreenToFollow(qGuiApp->primaryScreen()); // view->setScreenToFollow(qGuiApp->primaryScreen());
// } // }
// } // }
} }
void DockCorona::screenRemoved(QScreen *screen) void DockCorona::screenRemoved(QScreen *screen)
@ -278,47 +279,50 @@ void DockCorona::screenCountChanged()
void DockCorona::screenCountChangedTimer() void DockCorona::screenCountChangedTimer()
{ {
qDebug() << "screen count changed -+-+ "<< qGuiApp->screens().size(); qDebug() << "screen count changed -+-+ " << qGuiApp->screens().size();
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()){
qDebug() << "Found screen: "<<scr->name();
foreach(auto cont, containments()) { foreach (auto scr, qGuiApp->screens()) {
qDebug() << "Found screen: " << scr->name();
foreach (auto cont, containments()) {
int id = cont->screen(); int id = cont->screen();
if (id == -1){ if (id == -1) {
id = cont->lastScreen(); id = cont->lastScreen();
} }
bool onPrimary = cont->config().readEntry("onPrimary", true); bool onPrimary = cont->config().readEntry("onPrimary", true);
if ( (onPrimary || (m_screenPool->connector(id) == scr->name())) && (!m_dockViews.contains(cont))) { if ((onPrimary || (m_screenPool->connector(id) == scr->name())) && (!m_dockViews.contains(cont))) {
qDebug() << "screen Count signal: view must be added... for:"<< scr->name(); qDebug() << "screen Count signal: view must be added... for:" << scr->name();
addDock(cont); addDock(cont);
} }
} }
} }
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();
if (id == -1){ if (id == -1) {
id = view->containment()->lastScreen(); id = view->containment()->lastScreen();
} }
if(scr->name() == view->currentScreen()){ if (scr->name() == view->currentScreen()) {
found = true; found = true;
break; break;
} }
} }
if (!found && !view->onPrimary() && (m_dockViews.size()>1) && m_dockViews.contains(view->containment())) { if (!found && !view->onPrimary() && (m_dockViews.size() > 1) && m_dockViews.contains(view->containment())) {
qDebug() << "screen Count signal: view must be deleted... for:"<<view->currentScreen(); qDebug() << "screen Count signal: view must be deleted... for:" << view->currentScreen();
auto viewToDelete = m_dockViews.take(view->containment()); auto viewToDelete = m_dockViews.take(view->containment());
viewToDelete->deleteLater(); viewToDelete->deleteLater();
} else { } else {
@ -346,8 +350,8 @@ int DockCorona::docksCount(int screen) const
for (const auto &view : m_dockViews) { for (const auto &view : m_dockViews) {
if (view && view->containment() if (view && view->containment()
&& view->containment()->screen() == screen && view->containment()->screen() == screen
&& !view->containment()->destroyed()) { && !view->containment()->destroyed()) {
++docks; ++docks;
} }
} }
@ -375,17 +379,32 @@ 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;
QList<Types::Location> edges{Types::BottomEdge, Types::LeftEdge, QList<Types::Location> edges{Types::BottomEdge, Types::LeftEdge,
Types::TopEdge, Types::RightEdge}; Types::TopEdge, Types::RightEdge};
//when screen=-1 is passed then the primaryScreenid is used //when screen=-1 is passed then the primaryScreenid is used
int fixedScreen = (screen == -1) ? primaryScreenId() : screen; int fixedScreen = (screen == -1) ? primaryScreenId() : screen;
for (auto *view : m_dockViews) { for (auto *view : m_dockViews) {
if (view && view->containment() if (view && view->containment()
&& view->containment()->screen() == fixedScreen) { && view->containment()->screen() == fixedScreen) {
edges.removeOne(view->location()); edges.removeOne(view->location());
} }
} }
@ -432,8 +451,8 @@ int DockCorona::screenForContainment(const Plasma::Containment *containment) con
for (auto screen : qGuiApp->screens()) { for (auto screen : qGuiApp->screens()) {
// containment->lastScreen() == m_screenPool->id(screen->name()) to check if the lastScreen refers to a screen that exists/it's known // containment->lastScreen() == m_screenPool->id(screen->name()) to check if the lastScreen refers to a screen that exists/it's known
if (containment->lastScreen() == m_screenPool->id(screen->name()) && if (containment->lastScreen() == m_screenPool->id(screen->name()) &&
(containment->activity() == m_activityConsumer->currentActivity() || (containment->activity() == m_activityConsumer->currentActivity() ||
containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment)) { containment->containmentType() == Plasma::Types::PanelContainment || containment->containmentType() == Plasma::Types::CustomPanelContainment)) {
return containment->lastScreen(); return containment->lastScreen();
} }
} }
@ -469,15 +488,16 @@ void DockCorona::addDock(Plasma::Containment *containment)
id = containment->lastScreen(); id = containment->lastScreen();
} }
qDebug() << "add dock - containment id : "<< id; qDebug() << "add dock - containment id : " << id;
if (id >= 0 && !onPrimary) { if (id >= 0 && !onPrimary) {
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()){
if (scr && scr->name() == connector){ foreach (auto scr, qGuiApp->screens()) {
found=true; if (scr && scr->name() == connector) {
found = true;
nextScreen = scr; nextScreen = scr;
break; break;
} }
@ -488,7 +508,7 @@ void DockCorona::addDock(Plasma::Containment *containment)
} }
qDebug() << "Adding dock for container..."; qDebug() << "Adding dock for container...";
qDebug() << "onPrimary: " << onPrimary << "screen!!! :" << containment->screen() << " - "<<m_screenPool->connector(containment->screen()); qDebug() << "onPrimary: " << onPrimary << "screen!!! :" << containment->screen() << " - " << m_screenPool->connector(containment->screen());
auto dockView = new DockView(this, nextScreen); auto dockView = new DockView(this, nextScreen);
dockView->init(); dockView->init();
dockView->setContainment(containment); dockView->setContainment(containment);

@ -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,23 +153,38 @@ 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()};
foreach (auto scr, qGuiApp->screens()) { if (id != "primary") {
if (scr && scr->name() == id) { foreach (auto scr, qGuiApp->screens()) {
nextScreen = scr; if (scr && scr->name() == id) {
break; nextScreen = scr;
break;
}
} }
} }
if (nextScreen) if (nextScreen) {
setScreenToFollow(nextScreen); auto *dockCorona = qobject_cast<DockCorona *>(this->corona());
if (dockCorona) {
auto freeEdges = dockCorona->freeEdges(nextScreen);
if (!freeEdges.contains(location())) {
return false;
} else {
setScreenToFollow(nextScreen);
}
}
}
return false;
} }
void DockView::setScreenToFollow(QScreen *screen) void DockView::setScreenToFollow(QScreen *screen)

@ -116,7 +116,7 @@ public:
QString currentScreen() const; QString currentScreen() const;
VisibilityManager * visibility() const; VisibilityManager *visibility() const;
QQmlListProperty<QScreen> screens(); QQmlListProperty<QScreen> screens();
static int countScreens(QQmlListProperty<QScreen> *property); static int countScreens(QQmlListProperty<QScreen> *property);
@ -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) {
dock.onPrimary = true; var succeed = dock.setCurrentScreen("primary");
if (succeed) {
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...");
dock.onPrimary = false;
dock.setCurrentScreen(textAt(index)); var succeed = dock.setCurrentScreen(textAt(index));
if(succeed) {
dock.onPrimary = false;
} else {
console.log("the edge is already occupied!!!");
acceptedIndex = false;
}
} }
} }
} }

Loading…
Cancel
Save