From c74fa4b571727dbcea901780314aef51aefd6e01 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 14 Jul 2022 10:04:43 +0300 Subject: [PATCH] backends/x11: Port windowed backend from Screens --- src/backends/x11/windowed/egl_x11_backend.cpp | 1 - .../windowed/scene_qpainter_x11_backend.cpp | 23 +++++++++++-------- .../x11/windowed/scene_qpainter_x11_backend.h | 4 +++- .../x11/windowed/x11windowed_backend.cpp | 3 +-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/backends/x11/windowed/egl_x11_backend.cpp b/src/backends/x11/windowed/egl_x11_backend.cpp index b83ff1a210..5d095d2ea3 100644 --- a/src/backends/x11/windowed/egl_x11_backend.cpp +++ b/src/backends/x11/windowed/egl_x11_backend.cpp @@ -11,7 +11,6 @@ #include "basiceglsurfacetexture_internal.h" #include "basiceglsurfacetexture_wayland.h" #include "main.h" -#include "screens.h" #include "softwarevsyncmonitor.h" #include "x11windowed_backend.h" #include "x11windowed_output.h" diff --git a/src/backends/x11/windowed/scene_qpainter_x11_backend.cpp b/src/backends/x11/windowed/scene_qpainter_x11_backend.cpp index e535b111fa..f646e4be08 100644 --- a/src/backends/x11/windowed/scene_qpainter_x11_backend.cpp +++ b/src/backends/x11/windowed/scene_qpainter_x11_backend.cpp @@ -8,7 +8,6 @@ */ #include "scene_qpainter_x11_backend.h" #include "main.h" -#include "screens.h" #include "softwarevsyncmonitor.h" #include "x11windowed_backend.h" #include "x11windowed_output.h" @@ -52,8 +51,13 @@ X11WindowedQPainterBackend::X11WindowedQPainterBackend(X11WindowedBackend *backe : QPainterBackend() , m_backend(backend) { - connect(screens(), &Screens::changed, this, &X11WindowedQPainterBackend::createOutputs); - createOutputs(); + const auto outputs = m_backend->enabledOutputs(); + for (Output *output : outputs) { + addOutput(output); + } + + connect(backend, &X11WindowedBackend::outputEnabled, this, &X11WindowedQPainterBackend::addOutput); + connect(backend, &X11WindowedBackend::outputDisabled, this, &X11WindowedQPainterBackend::removeOutput); } X11WindowedQPainterBackend::~X11WindowedQPainterBackend() @@ -64,13 +68,14 @@ X11WindowedQPainterBackend::~X11WindowedQPainterBackend() } } -void X11WindowedQPainterBackend::createOutputs() +void X11WindowedQPainterBackend::addOutput(Output *output) { - m_outputs.clear(); - const auto &outputs = m_backend->outputs(); - for (const auto &x11Output : outputs) { - m_outputs[x11Output] = std::make_shared(x11Output, m_backend->windowForScreen(x11Output)); - } + m_outputs[output] = std::make_shared(output, m_backend->windowForScreen(output)); +} + +void X11WindowedQPainterBackend::removeOutput(Output *output) +{ + m_outputs.remove(output); } void X11WindowedQPainterBackend::present(Output *output) diff --git a/src/backends/x11/windowed/scene_qpainter_x11_backend.h b/src/backends/x11/windowed/scene_qpainter_x11_backend.h index eb7996eec9..b05ca3d010 100644 --- a/src/backends/x11/windowed/scene_qpainter_x11_backend.h +++ b/src/backends/x11/windowed/scene_qpainter_x11_backend.h @@ -50,7 +50,9 @@ public: OutputLayer *primaryLayer(Output *output) override; private: - void createOutputs(); + void addOutput(Output *output); + void removeOutput(Output *output); + xcb_gcontext_t m_gc = XCB_NONE; X11WindowedBackend *m_backend; QMap> m_outputs; diff --git a/src/backends/x11/windowed/x11windowed_backend.cpp b/src/backends/x11/windowed/x11windowed_backend.cpp index dfcff56519..5bb3b37bb5 100644 --- a/src/backends/x11/windowed/x11windowed_backend.cpp +++ b/src/backends/x11/windowed/x11windowed_backend.cpp @@ -13,7 +13,6 @@ #include "egl_x11_backend.h" #include "logging.h" #include "scene_qpainter_x11_backend.h" -#include "screens.h" #include "session.h" #include "utils/xcbutils.h" #include "wayland_server.h" @@ -516,7 +515,7 @@ void X11WindowedBackend::handleClientMessage(xcb_client_message_event_t *event) Q_EMIT outputDisabled(removedOutput); Q_EMIT outputRemoved(removedOutput); delete removedOutput; - QMetaObject::invokeMethod(screens(), "updateCount"); + Q_EMIT screensQueried(); } } }