Set geometry to fill each screen correctly

DesktopView incorrectly filled the geometry of screen()
screen() will be the screen of the parent shell, not the correct
screen.

As we are using QScreen, shellcorona is ported to use that instead
of QDesktopWidget.

REVIEW: 114149
This commit is contained in:
David Edmundson 2013-11-27 00:23:51 +01:00
parent 5f151c691d
commit 9462866755
4 changed files with 37 additions and 40 deletions

View File

@ -29,11 +29,12 @@
#include <Plasma/Package> #include <Plasma/Package>
DesktopView::DesktopView(ShellCorona *corona, QWindow *parent) DesktopView::DesktopView(ShellCorona *corona, QScreen *screen)
: PlasmaQuickView(corona, parent), : PlasmaQuickView(corona, 0),
m_stayBehind(false), m_stayBehind(false),
m_fillScreen(false) m_fillScreen(false)
{ {
setScreen(screen);
engine()->rootContext()->setContextProperty("desktop", this); engine()->rootContext()->setContextProperty("desktop", this);
setSource(QUrl::fromLocalFile(corona->package().filePath("views", "Desktop.qml"))); setSource(QUrl::fromLocalFile(corona->package().filePath("views", "Desktop.qml")));
} }
@ -75,10 +76,15 @@ void DesktopView::setFillScreen(bool fillScreen)
return; return;
} }
resize(screen()->geometry().width(), screen()->geometry().height());
connect(screen(), &QScreen::geometryChanged, [=]{resize(screen()->geometry().width(), screen()->geometry().height());});
m_fillScreen = fillScreen; m_fillScreen = fillScreen;
if (m_fillScreen) {
setGeometry(screen()->geometry());
connect(screen(), &QScreen::geometryChanged, this, static_cast<void (QWindow::*)(const QRect&)>(&QWindow::setGeometry));
} else {
disconnect(screen(), &QScreen::geometryChanged, this, static_cast<void (QWindow::*)(const QRect&)>(&QWindow::setGeometry));
}
emit fillScreenChanged(); emit fillScreenChanged();
} }
@ -132,5 +138,4 @@ void DesktopView::showConfigurationInterface(Plasma::Applet *applet)
m_configView.data()->show(); m_configView.data()->show();
} }
#include "moc_desktopview.cpp" #include "moc_desktopview.cpp"

View File

@ -33,7 +33,7 @@ class DesktopView : public PlasmaQuickView
Q_PROPERTY(bool fillScreen READ fillScreen WRITE setFillScreen NOTIFY fillScreenChanged) Q_PROPERTY(bool fillScreen READ fillScreen WRITE setFillScreen NOTIFY fillScreenChanged)
public: public:
explicit DesktopView(ShellCorona *corona, QWindow *parent = 0); explicit DesktopView(ShellCorona *corona, QScreen *screen);
virtual ~DesktopView(); virtual ~DesktopView();
bool stayBehind() const; bool stayBehind() const;

View File

@ -106,8 +106,6 @@ ShellCorona::ShellCorona(QObject *parent)
connect(d->desktopWidget, &QDesktopWidget::resized, connect(d->desktopWidget, &QDesktopWidget::resized,
this, &ShellCorona::screenResized ); this, &ShellCorona::screenResized );
connect(d->desktopWidget, &QDesktopWidget::screenCountChanged,
this, &ShellCorona::screenCountChanged);
connect(d->desktopWidget, &QDesktopWidget::workAreaResized, connect(d->desktopWidget, &QDesktopWidget::workAreaResized,
this, &ShellCorona::workAreaResized); this, &ShellCorona::workAreaResized);
@ -159,6 +157,7 @@ ShellCorona::ShellCorona(QObject *parent)
ShellCorona::~ShellCorona() ShellCorona::~ShellCorona()
{ {
qDeleteAll(d->views);
} }
void ShellCorona::setShell(const QString &shell) void ShellCorona::setShell(const QString &shell)
@ -186,7 +185,6 @@ void ShellCorona::load()
{ {
if (d->shell.isEmpty()) return; if (d->shell.isEmpty()) return;
checkViews();
loadLayout("plasma-" + d->shell + "-appletsrc"); loadLayout("plasma-" + d->shell + "-appletsrc");
if (containments().isEmpty()) { if (containments().isEmpty()) {
@ -195,6 +193,13 @@ void ShellCorona::load()
processUpdateScripts(); processUpdateScripts();
checkActivities(); checkActivities();
for (QScreen *screen : QGuiApplication::screens()) {
screenAdded(screen);
}
connect(qApp, &QGuiApplication::screenAdded,
this, &ShellCorona::screenAdded);
checkScreens(); checkScreens();
} }
@ -251,9 +256,6 @@ KActivities::Controller *ShellCorona::activityController()
void ShellCorona::checkScreens(bool signalWhenExists) void ShellCorona::checkScreens(bool signalWhenExists)
{ {
checkViews();
// quick sanity check to ensure we have containments for each screen // quick sanity check to ensure we have containments for each screen
int num = numScreens(); int num = numScreens();
for (int i = 0; i < num; ++i) { for (int i = 0; i < num; ++i) {
@ -271,7 +273,7 @@ void ShellCorona::checkScreen(int screen, bool signalWhenExists)
// ShellCorona will, when signalWhenExists is true, emit a containmentAdded signal // ShellCorona will, when signalWhenExists is true, emit a containmentAdded signal
// even if the containment actually existed prior to this method being called. // even if the containment actually existed prior to this method being called.
// //
//note: hte signal actually triggers view creation only for panels, atm. //note: the signal actually triggers view creation only for panels, atm.
//desktop views are created in response to containment's screenChanged signal instead, which is //desktop views are created in response to containment's screenChanged signal instead, which is
//buggy (sometimes the containment thinks it's already on the screen, so no view is created) //buggy (sometimes the containment thinks it's already on the screen, so no view is created)
@ -355,7 +357,6 @@ PanelView *ShellCorona::panelView(Plasma::Containment *containment) const
void ShellCorona::screenCountChanged(int newCount) void ShellCorona::screenCountChanged(int newCount)
{ {
qDebug() << "New screen count" << newCount; qDebug() << "New screen count" << newCount;
checkViews();
} }
void ShellCorona::screenResized(int screen) void ShellCorona::screenResized(int screen)
@ -368,34 +369,23 @@ void ShellCorona::workAreaResized(int screen)
qDebug() << "Work area resized" << screen; qDebug() << "Work area resized" << screen;
} }
void ShellCorona::checkViews() void ShellCorona::screenAdded(QScreen *screen)
{ {
if (d->shell.isEmpty()) { DesktopView *view = new DesktopView(this, screen);
return; d->views << view;
} view->show();
if (d->views.count() == d->desktopWidget->screenCount()) { connect(screen, SIGNAL(destroyed(QObject*)), SLOT(screenRemoved(QObject*)));
return; }
} else if (d->views.count() < d->desktopWidget->screenCount()) {
for (int i = d->views.count(); i < d->desktopWidget->screenCount(); ++i) {
DesktopView *view = new DesktopView(this); void ShellCorona::screenRemoved(QObject *screen)
QSurfaceFormat format; {
view->show(); for (auto i = d->views.begin(); i != d->views.end() ; i++) {
if ((*i)->screen() == screen) {
d->views << view; (*i)->deleteLater();
d->views.erase(i);
break;
} }
} else {
for (int i = d->desktopWidget->screenCount(); i < d->views.count(); ++i) {
DesktopView *view = d->views.last();
view->deleteLater();
d->views.pop_back();
}
}
//check every containment is in proper view
for (int i = 0; i < d->desktopWidget->screenCount(); ++i) {
qDebug() << "TODO: Implement loading containments into the views";
} }
} }

View File

@ -30,6 +30,7 @@ namespace Plasma
class Activity; class Activity;
class PanelView; class PanelView;
class QScreen;
namespace WorkspaceScripting { namespace WorkspaceScripting {
class DesktopScriptEngine; class DesktopScriptEngine;
} }
@ -97,7 +98,8 @@ protected Q_SLOTS:
void screenResized(int screen); void screenResized(int screen);
void workAreaResized(int screen); void workAreaResized(int screen);
void checkViews(); void screenAdded(QScreen *screen);
void screenRemoved(QObject *screen);
void updateScreenOwner(int wasScreen, int isScreen, Plasma::Containment *containment); void updateScreenOwner(int wasScreen, int isScreen, Plasma::Containment *containment);
void printScriptError(const QString &error); void printScriptError(const QString &error);