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,7 +246,8 @@ void DockCorona::addOutput(QScreen *screen)
Q_ASSERT(screen);
int id = m_screenPool->id(screen->name());
if (id==-1){
if (id == -1) {
int newId = m_screenPool->firstAvailableId();
m_screenPool->insertScreenMapping(newId, screen->name());
}
@ -278,47 +279,50 @@ void DockCorona::screenCountChanged()
void DockCorona::screenCountChangedTimer()
{
qDebug() << "screen count changed -+-+ "<< qGuiApp->screens().size();
qDebug() << "screen count changed -+-+ " << qGuiApp->screens().size();
qDebug() << "adding consideration....";
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();
if (id == -1){
if (id == -1) {
id = cont->lastScreen();
}
bool onPrimary = cont->config().readEntry("onPrimary", true);
if ( (onPrimary || (m_screenPool->connector(id) == scr->name())) && (!m_dockViews.contains(cont))) {
qDebug() << "screen Count signal: view must be added... for:"<< scr->name();
if ((onPrimary || (m_screenPool->connector(id) == scr->name())) && (!m_dockViews.contains(cont))) {
qDebug() << "screen Count signal: view must be added... for:" << scr->name();
addDock(cont);
}
}
}
qDebug() << "removing consideration & updating screen for always on primary docks....";
foreach(auto view, m_dockViews){
foreach (auto view, m_dockViews) {
bool found{false};
foreach(auto scr, qGuiApp->screens()){
foreach (auto scr, qGuiApp->screens()) {
int id = view->containment()->screen();
if (id == -1){
if (id == -1) {
id = view->containment()->lastScreen();
}
if(scr->name() == view->currentScreen()){
if (scr->name() == view->currentScreen()) {
found = true;
break;
}
}
if (!found && !view->onPrimary() && (m_dockViews.size()>1) && m_dockViews.contains(view->containment())) {
qDebug() << "screen Count signal: view must be deleted... for:"<<view->currentScreen();
if (!found && !view->onPrimary() && (m_dockViews.size() > 1) && m_dockViews.contains(view->containment())) {
qDebug() << "screen Count signal: view must be deleted... for:" << view->currentScreen();
auto viewToDelete = m_dockViews.take(view->containment());
viewToDelete->deleteLater();
} else {
@ -375,6 +379,21 @@ void DockCorona::aboutApplication()
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
{
using Plasma::Types;
@ -469,15 +488,16 @@ void DockCorona::addDock(Plasma::Containment *containment)
id = containment->lastScreen();
}
qDebug() << "add dock - containment id : "<< id;
qDebug() << "add dock - containment id : " << id;
if (id >= 0 && !onPrimary) {
QString connector = m_screenPool->connector(id);
qDebug() << "add dock - connector : "<< connector;
qDebug() << "add dock - connector : " << connector;
bool found{false};
foreach(auto scr, qGuiApp->screens()){
if (scr && scr->name() == connector){
found=true;
foreach (auto scr, qGuiApp->screens()) {
if (scr && scr->name() == connector) {
found = true;
nextScreen = scr;
break;
}
@ -488,7 +508,7 @@ void DockCorona::addDock(Plasma::Containment *containment)
}
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);
dockView->init();
dockView->setContainment(containment);

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

@ -153,23 +153,38 @@ void DockView::init()
qDebug() << "SOURCE:" << source();
}
void DockView::setCurrentScreen(const QString id)
bool DockView::setCurrentScreen(const QString 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()) {
if (scr && scr->name() == id) {
nextScreen = scr;
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);
}
}
}
return false;
}
void DockView::setScreenToFollow(QScreen *screen)

@ -116,7 +116,7 @@ public:
QString currentScreen() const;
VisibilityManager * visibility() const;
VisibilityManager *visibility() const;
QQmlListProperty<QScreen> screens();
static int countScreens(QQmlListProperty<QScreen> *property);
@ -130,7 +130,7 @@ public slots:
Q_INVOKABLE QList<int> freeEdges() const;
Q_INVOKABLE QVariantList containmentActions();
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 void updateEnabledBorders();

@ -99,14 +99,43 @@ PlasmaComponents.Page {
Layout.fillWidth: true
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: {
previousIndex = currentIndex;
if (index === 0) {
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)) {
console.log("current index changed!!! :"+ index);
console.log("screen must be changed...");
var succeed = dock.setCurrentScreen(textAt(index));
if(succeed) {
dock.onPrimary = false;
dock.setCurrentScreen(textAt(index));
} else {
console.log("the edge is already occupied!!!");
acceptedIndex = false;
}
}
}
}

Loading…
Cancel
Save