From c0f96372c34124a59dfac03a1a25829336732abd Mon Sep 17 00:00:00 2001 From: Alexander Tuxen <tuxen@silpion.de> Date: Fri, 23 Sep 2022 20:43:06 +0200 Subject: [PATCH] IVI surface handling works without crashes now. PID based approach doesn't seem to have an easy way of manipulating windows. --- .../compositor-messages.cpp | 1 + multiscreen-compositor/main.cpp | 10 ----- multiscreen-compositor/message-server.cpp | 1 - multiscreen-compositor/qml/main.qml | 45 ++++++++++++++++--- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/multiscreen-compositor/compositor-messages.cpp b/multiscreen-compositor/compositor-messages.cpp index 07a9adc..8f44b5f 100644 --- a/multiscreen-compositor/compositor-messages.cpp +++ b/multiscreen-compositor/compositor-messages.cpp @@ -12,6 +12,7 @@ void CompositorMessages::messageReceived(QString message, quint32 windowId, quin if(message == "moveWindowToScreen"){ emit moveWindowToScreen(windowId, screenId); + emit sendStatus(screenId); }else if(message == "hideWindow"){ emit hideWindow(windowId); diff --git a/multiscreen-compositor/main.cpp b/multiscreen-compositor/main.cpp index 26fd0cb..555506f 100644 --- a/multiscreen-compositor/main.cpp +++ b/multiscreen-compositor/main.cpp @@ -100,15 +100,5 @@ int main(int argc, char *argv[]) appEngine.rootContext()->setContextProperty("commands", &commands); appEngine.load(QUrl("qrc:///qml/main.qml")); - /* - QQmlEngine engine; - QQmlComponent component(&engine, QUrl("qrc:///qml/main.qml"), nullptr); - QObject *object = component.create(); - - QObject *object = appEngine.rootObjects().constFirst()->findChild<QObject *>("screenSignal"); - QObject::connect(object, SIGNAL(sendStatus(int)), - &commands, SLOT(screenInfoReceived(int))); - */ - return app.exec(); } diff --git a/multiscreen-compositor/message-server.cpp b/multiscreen-compositor/message-server.cpp index 532be30..e75ab0c 100644 --- a/multiscreen-compositor/message-server.cpp +++ b/multiscreen-compositor/message-server.cpp @@ -52,7 +52,6 @@ void MessageServer::handleConnection() MessageServerConnection *c = new MessageServerConnection(server->nextPendingConnection(), this); connect(c, &MessageServerConnection::disconnected, this, &MessageServer::connectionGone); connect(c, &MessageServerConnection::newMessage, this, &MessageServer::messageReceived); - //connect(c, &MessageServerConnection::newMessage, this, &MessageServer::messageReceived); connect(this, &MessageServer::sendStatus, c, &MessageServerConnection::sendStatus); connections.append(c); } diff --git a/multiscreen-compositor/qml/main.qml b/multiscreen-compositor/qml/main.qml index 822ad06..b825556 100644 --- a/multiscreen-compositor/qml/main.qml +++ b/multiscreen-compositor/qml/main.qml @@ -128,6 +128,7 @@ WaylandCompositor { function createShellSurfaceItem(shellSurface, output) { console.log("createShellSurfaceItem: Creating surface", shellSurface, "on output", output); + cleanUpApplist(); var item = chromeComponent.createObject(output.surfaceArea, { "shellSurface": shellSurface, }); @@ -158,6 +159,7 @@ WaylandCompositor { // if more than one screen is present. // If the unique ivi id is greater or equal 2000 we select screen 2 console.log("handleIviSurfaceCreated: surface", iviSurface, "id", iviSurface.iviId); + cleanUpApplist(); var item; if (screens.count > 1) { if (iviSurface.iviId > 1999) @@ -169,14 +171,27 @@ WaylandCompositor { } console.log("Add to applist: ", item, "id", iviSurface.iviId); - var surfaceOnScreen = ({ 'surface': item, 'screen': active_screen }); + var surfaceOnScreen = ({ 'surface': item, 'screen': (iviSurface.iviId > 1999) ? 1 : 0 }); activeSurfaces.push(surfaceOnScreen); } + function cleanUpApplist() + { + for (var i=0; i < activeSurfaces.length; i++) { + var item = activeSurfaces[i]; + if ((!item.surface.shellSurface) && (!item.surface.surface)) + { + console.log("Removing lost surface from applist!") + activeSurfaces = Array.from(activeSurfaces).filter((e, idx) => idx !== i) + } + } + } + // ============================================= // Remove destroyed surface from the suface list // ============================================= onSurfaceAboutToBeDestroyed: { + /* console.log("Surface will be destroyed", surface); console.log("appList length: ", activeSurfaces.length); for (var i=0; i < activeSurfaces.length; i++) { @@ -213,6 +228,7 @@ WaylandCompositor { console.log("surface not defined!", item.surface); } } + */ } // ============================================= @@ -222,12 +238,12 @@ WaylandCompositor { console.log("Lookung for surface with id", id); for (var i=0; i < activeSurfaces.length; i++) { var item = activeSurfaces[i]; - if( id === item.surface.shellSurface.iviId){ + if ((item.surface.shellSurface) && ( id === item.surface.shellSurface.iviId)) { console.log("found IVI Shell Surface", i, id, item.surface.shellSurface, item.surface.shellSurface.surface) return item.surface; } - else if( id === item.surface.surface.client.processId){ - console.log("found XDG Shell Surface", i, id, item.surface.shellSurface, item.surface.shellSurface.surface) + else if ((item.surface.surface) && ( id === item.surface.surface.client.processId)) { + console.log("found XDG Shell Surface", i, id, item.surface) return item.surface; } } @@ -235,6 +251,17 @@ WaylandCompositor { return; } + function updateScreenAssignment(surface, screen) + { + console.log("Updating screen for surface", surface); + for (var i=0; i < activeSurfaces.length; i++) { + var item = activeSurfaces[i]; + if (surface === item.surface) { + item.screen = screen; + } + } + } + // ============================================= // Handle the signals emmitted by the external // compositor commands class @@ -255,11 +282,15 @@ WaylandCompositor { console.log("Move", surface, "to screen", screenid) surface.parent = screens.objectAt(screenid).surfaceArea; + updateScreenAssignment(surface, screenid); } function windowVisibility(windowid, show){ var surface = findSurfaceById(windowid) if( !surface ) return; + if (surface.shellSurface){ + console.log("Set visable to", show,"for", surface.shellSurface) + } console.log("Set visable to", show,"for", surface) surface.visible = show } @@ -286,10 +317,14 @@ WaylandCompositor { for (var i=0; i < activeSurfaces.length; i++) { var item = activeSurfaces[i]; if (item.surface) { - if( windowid === item.surface.surface.client.processId){ + if ((item.surface.surface) && ( windowid === item.surface.surface.client.processId)) { console.log("Surface", i, item.surface, "pid", item.surface.surface.client.processId, "on screen", item.screen) screenId = item.screen; } + else if ((item.surface.shellSurface) && ( windowid === item.surface.shellSurface.iviId)) { + console.log("Surface", i, item.surface, "on screen", item.screen) + screenId = item.screen; + } } } -- GitLab