diff options
Diffstat (limited to 'src-qt5')
9 files changed, 107 insertions, 28 deletions
diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.cpp new file mode 100644 index 00000000..0899337c --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.cpp @@ -0,0 +1,46 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2018, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include <global-objects.h> +#include "QMLImageProvider.h" + +QMLImageProvider::QMLImageProvider() : QQuickImageProvider(QQmlImageProviderBase::Image, 0){ + +} + +QMLImageProvider::~QMLImageProvider(){ + +} + +/*QMLImageProvider* QMLImageProvider::instance(){ + static QMLImageProvider *_prov = 0; + if(_prov==0){ _prov = new QMLImageProvider(); } + return _prov; +}*/ + +QImage QMLImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize){ + NativeWindowObject *win = Lumina::NWS->findWindow( id.section(":",1,1).toInt(), false); + qDebug() << "Request Image:" << id << win << requestedSize; + QImage img(requestedSize,QImage::Format_RGB32); + if(win==0){ img.fill("black"); } //invalid window ID (should never happen) + else if(id.startsWith("image:")){ img = Lumina::NWS->GetWindowImage(win); } + //else if(id.startsWith("icon:")){ img = Lumina::NWS->GetWindowIcon(win); } + qDebug() << "Got Window Image:" << img.size(); + if(img.size().isNull()){ + if(requestedSize.isValid()){ img = QImage(requestedSize,QImage::Format_RGB32); } + else{ img = QImage(QSize(64,64), QImage::Format_RGB32); } + img.fill("black"); + } + qDebug() << "Final Window Image:" << img.size(); + if(size!=0){ + size->setHeight(img.height()); + size->setWidth( img.width() ); + } + if(requestedSize.isValid() && !requestedSize.isNull() && img.size()!=requestedSize){ + img = img.scaled(requestedSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + } + return img; +} diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.h b/src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.h new file mode 100644 index 00000000..d0ab74ff --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/QMLImageProvider.h @@ -0,0 +1,26 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2018, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_DESKTOP_QML_IMAGE_PROVIDER_H +#define _LUMINA_DESKTOP_QML_IMAGE_PROVIDER_H + +#include <QQuickImageProvider> +#include <QImage> +#include <QPixmap> +#include <QSize> + +class QMLImageProvider : public QQuickImageProvider{ +public: + QMLImageProvider(); + ~QMLImageProvider(); + + //static QMLImageProvider* instance(); + + virtual QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize); + +}; + +#endif diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/RootWindow.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/RootWindow.cpp index 0cfa4e6b..5a9b8e09 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/RootWindow.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/RootWindow.cpp @@ -5,6 +5,7 @@ // See the LICENSE file for full details //=========================================== #include "RootWindow.h" +#include "QMLImageProvider.h" RootWindow::RootWindow() : QObject(){ root_win = QWindow::fromWinId( QX11Info::appRootWindow() ); // @@ -16,6 +17,7 @@ RootWindow::RootWindow() : QObject(){ //Now setup the QQuickView root_view->setResizeMode(QQuickView::SizeRootObjectToView); root_view->engine()->rootContext()->setContextProperty("RootObject", root_obj); + root_view->engine()->addImageProvider("native_window", new QMLImageProvider() ); RootDesktopObject::RegisterType(); //make sure object classes are registered with the QML subsystems } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/desktop.pri b/src-qt5/core/lumina-desktop-unified/src-desktop/desktop.pri index f4a6882d..ee5ada62 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/desktop.pri +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/desktop.pri @@ -1,10 +1,12 @@ QT *= gui widgets qml quick SOURCES *= $${PWD}/RootWindow.cpp \ - $${PWD}/Desktopmanager.cpp + $${PWD}/Desktopmanager.cpp \ + $${PWD}/QMLImageProvider.cpp HEADERS *= $${PWD}/RootWindow.h \ - $${PWD}/DesktopManager.h + $${PWD}/DesktopManager.h \ + $${PWD}/QMLImageProvider.h #update the includepath so we can just #include as needed without paths INCLUDEPATH *= $${PWD} 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 e9049cdd..8ea00cc1 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 @@ -21,7 +21,7 @@ void NativeWindowObject::RegisterType(){ NativeWindowObject::NativeWindowObject(WId id) : QObject(){ winid = id; frameid = 0; - dmgID = 0; + dmgID = dmg = 0; } NativeWindowObject::~NativeWindowObject(){ @@ -143,7 +143,10 @@ QRect NativeWindowObject::geometry(){ // QML ACCESS FUNCTIONS (shortcuts for particular properties in a format QML can use) QString NativeWindowObject::winImage(){ - return this->property(NativeWindowObject::WinImage).toString(); + //Need to alternate something on the end to ensure that QML knows to fetch the new image (non-cached only) + if(dmg==0){ dmg = 1; } + else{ dmg = 0; } + return "image://native_window/image:"+QString::number(winid)+":"+QString::number(dmg); } QString NativeWindowObject::name(){ 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 fc4a7101..0030d27c 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 @@ -125,7 +125,7 @@ private: //QWindow *WIN; WId winid, frameid; QList<WId> relatedTo; - unsigned int dmgID; + unsigned int dmgID, dmg; void emitSinglePropChanged(NativeWindowObject::Property); @@ -135,7 +135,6 @@ signals: void RequestPropertiesChange(WId, QList<NativeWindowObject::Property>, QList<QVariant>); void WindowClosed(WId); void WindowNotResponding(WId); //will be sent out if a window does not respond to a ping request - void VisualChanged(); //Action Requests (not automatically emitted - typically used to ask the WM to do something) //Note: "WId" should be the NativeWindowObject id() diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/NativeWindow.qml b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/NativeWindow.qml index 36853cc5..74c3f025 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/NativeWindow.qml +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-qml/NativeWindow.qml @@ -172,6 +172,7 @@ Rectangle { Image { id: frameContents + cache: false source: windowFrame.object.winImage anchors.top: titleBar.bottom anchors.bottom: parent.bottom diff --git a/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.cpp b/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.cpp index 30a6a47d..15c79099 100644 --- a/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.cpp @@ -10,7 +10,7 @@ #include "NativeWindowSystem.h" #include <global-objects.h> -#define DISABLE_COMPOSITING 1 +#define DISABLE_COMPOSITING 0 //XCB Library includes #include <xcb/xcb.h> @@ -628,7 +628,7 @@ void NativeWindowSystem::SetupNewWindow(NativeWindowObject *win){ registerClientEvents(win->id()); } -void NativeWindowSystem::UpdateWindowImage(NativeWindowObject* win){ +QImage NativeWindowSystem::GetWindowImage(NativeWindowObject* win){ QImage img; qDebug() << "Update Window Image:" << win->name(); QRect geom(QPoint(0,0), win->property(NativeWindowObject::Size).toSize()); @@ -641,12 +641,12 @@ void NativeWindowSystem::UpdateWindowImage(NativeWindowObject* win){ //Pull the XCB pixmap out of the compositing layer xcb_pixmap_t pix = xcb_generate_id(QX11Info::connection()); xcb_composite_name_window_pixmap(QX11Info::connection(), win->id(), pix); - if(pix==0){ qDebug() << "Got blank pixmap!"; return; } + if(pix==0){ qDebug() << "Got blank pixmap!"; return QImage(); } //Convert this pixmap into a QImage //xcb_image_t *ximg = xcb_image_get(QX11Info::connection(), pix, 0, 0, this->width(), this->height(), ~0, XCB_IMAGE_FORMAT_Z_PIXMAP); xcb_image_t *ximg = xcb_image_get(QX11Info::connection(), pix, geom.x(), geom.y(), geom.width(), geom.height(), ~0, XCB_IMAGE_FORMAT_Z_PIXMAP); - if(ximg == 0){ qDebug() << "Got blank image!"; return; } + if(ximg == 0){ qDebug() << "Got blank image!"; return QImage(); } QImage tmp(ximg->data, ximg->width, ximg->height, ximg->stride, QImage::Format_ARGB32_Premultiplied); img = tmp.copy(); //detach this image from the XCB data structures before we clean them up, otherwise the QImage will try to clean it up a second time on window close and crash xcb_image_destroy(ximg); @@ -654,7 +654,8 @@ void NativeWindowSystem::UpdateWindowImage(NativeWindowObject* win){ //Cleanup the XCB data structures xcb_free_pixmap(QX11Info::connection(), pix); } - win->setProperty(NativeWindowObject::WinImage, QVariant::fromValue<QImage>(img) ); + return img; + //win->setProperty(NativeWindowObject::WinImage, QVariant::fromValue<QImage>(img) ); } // === PUBLIC SLOTS === @@ -942,12 +943,12 @@ void NativeWindowSystem::NewMouseRelease(int buttoncode, WId win){ } void NativeWindowSystem::CheckDamageID(WId win){ - qDebug() << "Got Damage Event:" << win; + //qDebug() << "Got Damage Event:" << win; for(int i=0; i<NWindows.length(); i++){ if(NWindows[i]->damageId() == win || NWindows[i]->id() == win || NWindows[i]->frameId()==win){ - qDebug() << " - Found window"; - UpdateWindowImage(NWindows[i]); - NWindows[i]->emit VisualChanged(); + //qDebug() << " - Found window"; + //UpdateWindowImage(NWindows[i]); + NWindows[i]->emit winImageChanged(); return; } } diff --git a/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.h b/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.h index c50babff..24128f32 100644 --- a/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.h +++ b/src-qt5/core/lumina-desktop-unified/src-events/NativeWindowSystem.h @@ -23,11 +23,6 @@ private: QList<NativeWindowObject*> NWindows; QList<NativeWindowObject*> TWindows; - //Simplifications to find an already-created window object - NativeWindowObject* findWindow(WId id, bool checkRelated = true); - - NativeWindowObject* findTrayWindow(WId id); - //Now define a simple private_objects class so that each implementation // has a storage container for defining/placing private objects as needed class p_objects; @@ -51,14 +46,6 @@ private: } } - // Since some properties may be easier to update in bulk - // let the native system interaction do them in whatever logical groups are best - void UpdateWindowProperties(NativeWindowObject* win, QList< NativeWindowObject::Property > props); - void ChangeWindowProperties(NativeWindowObject* win, QList< NativeWindowObject::Property > props, QList<QVariant> vals); - - void SetupNewWindow(NativeWindowObject *win); - void UpdateWindowImage(NativeWindowObject *win); - //Generic private variables bool screenLocked; @@ -66,6 +53,18 @@ public: //enum Property{ None, CurrentWorkspace, Workspaces, VirtualRoots, WorkAreas }; enum MouseButton{NoButton, LeftButton, RightButton, MidButton, BackButton, ForwardButton, TaskButton, WheelUp, WheelDown, WheelLeft, WheelRight}; + //Simplifications to find an already-created window object + NativeWindowObject* findWindow(WId id, bool checkRelated = true); + + NativeWindowObject* findTrayWindow(WId id); + // Since some properties may be easier to update in bulk + // let the native system interaction do them in whatever logical groups are best + void UpdateWindowProperties(NativeWindowObject* win, QList< NativeWindowObject::Property > props); + void ChangeWindowProperties(NativeWindowObject* win, QList< NativeWindowObject::Property > props, QList<QVariant> vals); + + void SetupNewWindow(NativeWindowObject *win); + QImage GetWindowImage(NativeWindowObject *win); + NativeWindowSystem(); ~NativeWindowSystem(); |