From f228077850b16fdd92310782aafe3f7f2b437adb Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 26 Apr 2018 17:48:37 -0400 Subject: Commit a bunch more work on the Lumina 2 screen reservations. --- .../src-desktop/src-cpp/NativeWindowObject.cpp | 18 ++++++++---- .../src-desktop/src-cpp/NativeWindowObject.h | 2 +- .../src-desktop/src-cpp/PanelObject.cpp | 20 ++++++++++--- .../src-desktop/src-cpp/PanelObject.h | 3 +- .../src-desktop/src-cpp/RootDesktopObject.cpp | 33 +++++++++++++++++++++- .../src-desktop/src-cpp/RootDesktopObject.h | 7 ++++- .../src-desktop/src-cpp/ScreenObject.cpp | 26 ++++++++++++++++- .../src-desktop/src-cpp/ScreenObject.h | 5 ++++ 8 files changed, 99 insertions(+), 15 deletions(-) (limited to 'src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp') diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp index c9dd97f8..45aa1101 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.cpp @@ -268,10 +268,11 @@ void NativeWindowObject::updateGeometry(int x, int y, int width, int height, boo QPoint pos(x+fgeom[0], y+fgeom[2]); QSize sz(width-fgeom[0]-fgeom[1], height-fgeom[2]-fgeom[3]); newgeom = QRect(pos, sz); + lastgeom = QRect(x,y,width,height); //save this for later if(!now){ //qDebug() << "Update Geometry:" << fgeom << QRect(x,y,width,height) << pos << sz; //requestProperties(QList() << NativeWindowObject::GlobalPos << NativeWindowObject::Size, QList() << pos << sz); - if(!geomTimer->isActive()){ geomTimer->start(); } + if(!geomTimer->isActive()){ QTimer::singleShot(0,geomTimer, SLOT(start())); } }else{ sendNewGeom(); } @@ -295,18 +296,23 @@ void NativeWindowObject::toggleMaximize(){ } } //Now compare the current geometry to the screen geometry + qDebug() << "Maximize Toggle:" << curgeom << max; if(curgeom!=max){ + qDebug() << " - maximize"; setGeometryNow(max); //will set newgeom to max - newgeom = curgeom; //now reset newgeom + lastgeom = curgeom; //save this for later }else{ + qDebug() << " - restore" << lastgeom; //Already maximized, look at the old geometry and figure out how to restore it - if(newgeom.isNull()){ + if(lastgeom.isNull() || lastgeom == max){ + qDebug() << " -- Reset lastgeom to half-screen size"; //no old info available - center the window at half maximum size - newgeom = QRect(max.x()-max.width()/2, max.y()-max.height()/2, max.width()/2, max.height()/2); + lastgeom = QRect(max.x()-max.width()/2, max.y()-max.height()/2, max.width()/2, max.height()/2); } - setGeometryNow(newgeom); + setGeometryNow(lastgeom); } - emit geomChanged(); + qDebug() << "After toggle:" << lastgeom; + //emit geomChanged(); } void NativeWindowObject::requestClose(){ diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.h index ed52c956..c1851d0e 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/NativeWindowObject.h @@ -133,7 +133,7 @@ private: unsigned int dmgID, dmg, icodmg; //Collation/Delay for window resize events QTimer *geomTimer; - QRect newgeom; + QRect newgeom, lastgeom; void emitSinglePropChanged(NativeWindowObject::Property); diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp index e8830bde..94079bf7 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp @@ -48,6 +48,7 @@ void PanelObject::setBackground(QString fileOrColor){ void PanelObject::setGeometry( QRect newgeom ){ if(geom!=newgeom){ geom = newgeom; + fullside_geom = geom; //unknown full-side geom - no parent info given emit geomChanged(); } } @@ -88,10 +89,19 @@ void PanelObject::syncWithSettings(QRect parent_geom){ this->setBackground( DesktopSettings::instance()->value(DesktopSettings::Panels, id+"/background", "rgba(0,0,0,120)").toString() ); // qDebug() << "Update Panel:" << panel_id << id << anchor+"/"+align << length << width; //Now calculate the geometry of the panel - QRect newgeom; + QRect newgeom, newfullsidegeom; //Figure out the size of the panel - if(anchor=="top" || anchor=="bottom"){ newgeom.setWidth( parent_geom.width()*length ); newgeom.setHeight(width); } - else{ newgeom.setWidth(width); newgeom.setHeight(parent_geom.height()*length); } + if(anchor=="top" || anchor=="bottom"){ + newgeom.setWidth( parent_geom.width()*length ); newgeom.setHeight(width); + newfullsidegeom.setWidth(parent_geom.width()); newfullsidegeom.setHeight(width); + if(anchor=="top"){ newfullsidegeom.moveTopLeft(QPoint(0,0)); } + else{ newfullsidegeom.moveBottomLeft( QPoint(0, parent_geom.height()) ); } + }else{ + newgeom.setWidth(width); newgeom.setHeight(parent_geom.height()*length); + newfullsidegeom.setWidth(width); newfullsidegeom.setHeight(parent_geom.height()); + if(anchor=="left"){ newfullsidegeom.moveTopLeft(QPoint(0,0)); } + else{ newfullsidegeom.moveTopRight( QPoint(parent_geom.width(), 0) ); } + } //qDebug() << " - Size:" << newgeom; //Now figure out the location of the panel if(align=="left" || align=="top"){ @@ -114,7 +124,9 @@ void PanelObject::syncWithSettings(QRect parent_geom){ //qDebug() << " - Calculated Geometry (relative to parent):" << newgeom; //Note: newgeom is currently in parent-relative coordinates (not global) newgeom.translate(parent_geom.x(), parent_geom.y()); + newfullsidegeom.translate(parent_geom.x(), parent_geom.y()); + fullside_geom = newfullsidegeom; //qDebug() << " - Calculated Geometry (global):" << newgeom; - this->setGeometry(newgeom); //shift to global coordinates + this->setGeometry(newgeom); //in global coordinates this->setPlugins( DesktopSettings::instance()->value(DesktopSettings::Panels, id+"/plugins", QStringList()).toStringList() ); } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.h index 5ae75ea4..645e20c0 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.h @@ -25,7 +25,7 @@ class PanelObject : public QObject { private: QString panel_id, bg; - QRect geom; + QRect geom, fullside_geom; QStringList panel_plugins; public: @@ -42,6 +42,7 @@ public: Q_INVOKABLE bool isVertical(); Q_INVOKABLE QStringList plugins(); Q_INVOKABLE QRect geometry(){ return geom; } + Q_INVOKABLE QRect fullSideGeometry(){ return fullside_geom; } public slots: void setBackground(QString fileOrColor); diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp index d9a81f54..79737ddc 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.cpp @@ -18,6 +18,10 @@ RootDesktopObject::RootDesktopObject(QObject *parent) : QObject(parent){ connect(this, SIGNAL(changePanels(QStringList)), this, SLOT(setPanels(QStringList)) ); currentTimeTimer = new QTimer(this); connect(currentTimeTimer, SIGNAL(timeout()), this, SLOT(updateCurrentTime()) ); + availgeomTimer = new QTimer(this); + availgeomTimer->setInterval(100); + availgeomTimer->setSingleShot(true); + connect(availgeomTimer, SIGNAL(timeout()), this, SLOT(submitSessionGeom()) ); } RootDesktopObject::~RootDesktopObject(){ @@ -170,6 +174,16 @@ void RootDesktopObject::setPanels(QStringList ids){ change = true; //list changed } } //end loop over screens+session + //Now calculate the available session geometry + QRegion sess(geom); + for(int i=0; i RootDesktopObject::windowObjects(){ return window_objects; } +QList RootDesktopObject::screenObjects(){ + return s_objects; +} + // === PUBLIC SLOTS === void RootDesktopObject::updateScreens(){ QList scrns = QApplication::screens(); @@ -251,7 +269,11 @@ void RootDesktopObject::updateScreens(){ for(int j=0; jname()==scrns[i]->name()){ found = true; tmp << s_objects.takeAt(j); } } - if(!found){ tmp << new ScreenObject(scrns[i], this); } + if(!found){ + //Create new screen object + tmp << new ScreenObject(scrns[i], this); + connect(tmp.last(), SIGNAL(availableGeomChanged()), this, SLOT(availableScreenGeomChanged()) ); + } } //Delete any leftover objects for(int i=0; ideleteLater(); } @@ -291,3 +313,12 @@ void RootDesktopObject::updateCurrentTime(){ emit currentTimeChanged(); } } + +void RootDesktopObject::availableScreenGeomChanged(){ + if(availgeomTimer->isActive()){ availgeomTimer->stop(); } + availgeomTimer->start(); +} + +void RootDesktopObject::submitSessionGeom(){ + //TODO - read off the available geom from each ScreenObject and register that with NativeWindowSystem +} diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h index 3c525848..4a722ec0 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/RootDesktopObject.h @@ -57,6 +57,7 @@ public: //C++ Access Functions (simplifications for the QML ones) QList windowObjects(); + QList screenObjects(); private: QList s_objects; @@ -64,9 +65,10 @@ private: QList window_objects; QList tray_window_objects; QPointer last_window_up; - QTimer *currentTimeTimer; + QTimer *currentTimeTimer, *availgeomTimer; QString currentTimeFormat, currentTimeString; QDateTime currentDateTimeStruct; + QRegion session_avail_geom; public slots: void updateScreens(); //rescan/update screen objects @@ -84,6 +86,8 @@ public slots: private slots: void updateCurrentTime(); + void availableScreenGeomChanged(); + void submitSessionGeom(); signals: void screensChanged(); @@ -91,6 +95,7 @@ signals: void windowsChanged(); void trayWindowsChanged(); void currentTimeChanged(); + void sessionGeomAvailableChanged(); void startLogout(); void mouseMoved(); diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.cpp index c754906d..d6e0abb6 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.cpp @@ -11,6 +11,7 @@ ScreenObject::ScreenObject(QScreen *scrn, QObject *parent) : QObject(parent){ bg_screen = scrn; connect(this, SIGNAL(changePanels(QStringList)), this, SLOT(setPanels(QStringList)) ); + connect(RootWindowObject::instance(), SIGNAL(sessionGeomAvailableChanged()), this, SLOT(updateAvailableGeometry()) ); } void ScreenObject::RegisterType(){ @@ -49,12 +50,15 @@ void ScreenObject::setPanels(QStringList ids){ return; } + QRegion *sess = RootDesktopObject::instance()->availableGeometry(); + QRect avail = sess->intersected(bg_screen->geometry()).boundingRect(); + if(session_available_geometry.isNull()){ avail = bg_screen->geometry(); } //First update/remove any current panel objects bool change = false; for(int i=0; iname()) ){ ids.removeAll(panel_objects[i]->name()); //already handled - panel_objects[i]->syncWithSettings(bg_screen->geometry()); + panel_objects[i]->syncWithSettings(avail); }else{ panel_objects.takeAt(i)->deleteLater(); i--; @@ -87,3 +91,23 @@ PanelObject* ScreenObject::panel(QString id){ } return 0; } + +QRect ScreenObject::availableGeometry(){ + return avail_geom; +} + +void ScreenObject::updateAvailableGeometry(){ + QRegion *sess = RootDesktopObject::instance()->availableGeometry(); + QRegion availRegion = sess->intersected(bg_screen->geometry()); + QRect avail = availRegion.boundingRect(); + for(int i=0; isyncWithSettings(avail); + //Note: Use the "full side" geometry to ensure that we are cleanly cutting off the entire side of the region + availRegion = availRegion.subtracted( panel_objects[i]->fullSideGeometry() ); + } + avail = availRegion.boundingRect(); + if(avail != avail_geom){ + avail_geom = avail; + emit availableGeomChanged(); + } +} diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.h index 250c9403..66c30969 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/ScreenObject.h @@ -24,11 +24,13 @@ class ScreenObject : public QObject { Q_PROPERTY( int width READ width NOTIFY geomChanged) Q_PROPERTY( int height READ height NOTIFY geomChanged) Q_PROPERTY( QStringList panels READ panels NOTIFY panelsChanged) + Q_PROPERTY( QRect availableGeom READ availableGeometry NOTIFY availableGeomChanged) private: QScreen *bg_screen; QString bg; QList panel_objects; + QRect avail_geom; public: ScreenObject(QScreen *scrn = 0, QObject *parent = 0); @@ -44,6 +46,7 @@ public: Q_INVOKABLE QStringList panels(); Q_INVOKABLE PanelObject* panel(QString id); Q_INVOKABLE QRect geometry(){ return bg_screen->geometry(); } + Q_INVOKABLE QRect availableGeometry(); void setPanels(QList list); @@ -52,10 +55,12 @@ public: public slots: void setPanels(QStringList ids); void setBackground(QString fileOrColor); + void updateAvailableGeometry(); signals: void backgroundChanged(); void geomChanged(); + void availableGeomChanged(); void panelsChanged(); //Internal signals for thread-safety -- cgit