1
0
mirror of https://github.com/KDE/krfb synced 2026-07-02 00:01:18 -07:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Nicolas Fella
f8cd48fd5d Port framebuffers away from deprecated QDesktopWidget
Use QPlatformNativeInterface to get the WId instead
2022-08-04 13:22:57 +02:00
Nicolas Fella
04494dfeb0 Fix broken WId refactoring
Actually remove the WId member from the abtract framebuffer class and use the member in xcbframebuffer

qtframebuffer also uses the WId so add a member there
2022-08-04 11:57:55 +02:00
Nicolas Fella
4169a9f50a Don't pass unused window ids around
The wid is only relevant for the xcb framebuffer

We can just query it there, no need to pass it around everywhere
2022-08-03 22:00:16 +02:00
28 changed files with 66 additions and 97 deletions

View File

@@ -27,11 +27,7 @@ include(CheckIncludeFile)
check_include_file("linux/input.h" HAVE_LINUX_INPUT_H)
find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED COMPONENTS Core DBus Widgets)
if(QT_MAJOR_VERSION EQUAL "5")
find_package(Qt5X11Extras REQUIRED)
endif()
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Core DBus Widgets X11Extras)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
I18n
@@ -85,8 +81,8 @@ find_package(PlasmaWaylandProtocols 1.5.0)
if(PipeWire_FOUND AND PlasmaWaylandProtocols_FOUND)
find_package(KF5Wayland ${KF5_MIN_VERSION})
find_package(QtWaylandScanner REQUIRED)
find_package(Qt${QT_MAJOR_VERSION}WaylandClient)
find_package(Qt${QT_MAJOR_VERSION}XkbCommonSupport)
find_package(Qt5WaylandClient)
find_package(Qt5XkbCommonSupport)
find_package(Wayland REQUIRED COMPONENTS Client)
endif()

View File

@@ -22,6 +22,7 @@
#include "x11events.h"
#include <QApplication>
#include <QX11Info>
#include <QDesktopWidget>
#include <QGlobalStatic>
@@ -29,11 +30,7 @@
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QX11Info>
#else
#include <QtGui/private/qtx11extras_p.h>
#endif
enum {
LEFTSHIFT = 1,

View File

@@ -22,12 +22,7 @@
#include "x11events.h"
#include <KPluginFactory>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QX11Info>
#else
#include <QtGui/private/qtx11extras_p.h>
#endif
K_PLUGIN_CLASS(X11EventsPlugin)

View File

@@ -7,7 +7,7 @@ set (krfb_events_xdp_SRCS
xdpeventsplugin.cpp
)
qt_add_dbus_interface(
qt5_add_dbus_interface(
krfb_events_xdp_SRCS
${CMAKE_SOURCE_DIR}/dbus/xdp_dbus_remotedesktop_interface.xml
xdp_dbus_remotedesktop_interface
@@ -18,7 +18,7 @@ add_library (krfb_events_xdp MODULE ${krfb_events_xdp_SRCS})
target_link_libraries (krfb_events_xdp
KF5::CoreAddons
KF5::I18n
Qt::DBus
Qt5::DBus
krfbprivate
)
set_target_properties(krfb_events_xdp PROPERTIES OUTPUT_NAME xdp)

View File

@@ -27,6 +27,7 @@
#include <linux/input.h>
#include <QApplication>
#include <QDesktopWidget>
#include <QGlobalStatic>
class EventData

View File

@@ -22,13 +22,13 @@ ecm_qt_declare_logging_category(krfb_framebuffer_pw_SRCS
EXPORT KRFB
)
qt_add_dbus_interface(
qt5_add_dbus_interface(
krfb_framebuffer_pw_SRCS
${CMAKE_SOURCE_DIR}/dbus/xdp_dbus_screencast_interface.xml
xdp_dbus_screencast_interface
)
qt_add_dbus_interface(
qt5_add_dbus_interface(
krfb_framebuffer_pw_SRCS
${CMAKE_SOURCE_DIR}/dbus/xdp_dbus_remotedesktop_interface.xml
xdp_dbus_remotedesktop_interface
@@ -41,9 +41,9 @@ add_library(krfb_framebuffer_pw
set_property(TARGET krfb_framebuffer_pw PROPERTY C_STANDARD 99)
target_link_libraries(krfb_framebuffer_pw
Qt::Core
Qt::Gui
Qt::DBus
Qt5::Core
Qt5::Gui
Qt5::DBus
KF5::CoreAddons
KF5::WaylandClient
Wayland::Client

View File

@@ -961,8 +961,8 @@ PWFrameBuffer::Private::~Private()
}
}
PWFrameBuffer::PWFrameBuffer(WId winid, QObject *parent)
: FrameBuffer (winid, parent),
PWFrameBuffer::PWFrameBuffer(QObject *parent)
: FrameBuffer (parent),
d(new Private(this))
{
fb = nullptr;

View File

@@ -30,7 +30,7 @@ public:
};
using Streams = QList<Stream>;
PWFrameBuffer(WId winid, QObject *parent = nullptr);
PWFrameBuffer(QObject *parent = nullptr);
virtual ~PWFrameBuffer() override;
void initDBus();

View File

@@ -30,11 +30,9 @@ PWFrameBufferPlugin::PWFrameBufferPlugin(QObject *parent, const QVariantList &ar
}
FrameBuffer *PWFrameBufferPlugin::frameBuffer(WId id, const QVariantMap &args)
FrameBuffer *PWFrameBufferPlugin::frameBuffer(const QVariantMap &args)
{
//NOTE WId is irrelevant in Wayland
auto pwfb = new PWFrameBuffer(id);
auto pwfb = new PWFrameBuffer;
if (args.contains(QLatin1String("name"))) {
pwfb->startVirtualMonitor(args[QStringLiteral("name")].toString(), args[QStringLiteral("resolution")].toSize(), args[QStringLiteral("scale")].toDouble());
} else {

View File

@@ -34,7 +34,7 @@ class PWFrameBufferPlugin: public FrameBufferPlugin
public:
PWFrameBufferPlugin(QObject *parent, const QVariantList &args);
FrameBuffer *frameBuffer(WId id, const QVariantMap &args) override;
FrameBuffer *frameBuffer(const QVariantMap &args) override;
private:
Q_DISABLE_COPY(PWFrameBufferPlugin)

View File

@@ -21,9 +21,10 @@ add_library(krfb_framebuffer_qt
)
target_link_libraries (krfb_framebuffer_qt
Qt::Core
Qt::Gui
Qt5::Core
Qt5::Gui
KF5::CoreAddons
Qt::GuiPrivate
krfbprivate
)

View File

@@ -13,17 +13,20 @@
#include <QRegion>
#include <QPixmap>
#include <QBitmap>
#include <QGuiApplication>
#include <QApplication>
#include <QScreen>
#include <qpa/qplatformnativeinterface.h>
const int UPDATE_TIME = 500;
QtFrameBuffer::QtFrameBuffer(WId id, QObject *parent)
: FrameBuffer(id, parent)
QtFrameBuffer::QtFrameBuffer(QObject *parent)
: FrameBuffer(parent)
{
QScreen *screen = QGuiApplication::primaryScreen();
QPlatformNativeInterface* native = qApp->platformNativeInterface();
if (screen) {
win = reinterpret_cast<WId>(native->nativeResourceForScreen(QByteArrayLiteral("rootwindow"), screen));
primaryScreen = screen;
fbImage = screen->grabWindow(win).toImage();
fb = new char[fbImage.sizeInBytes()];

View File

@@ -22,7 +22,7 @@ class QtFrameBuffer : public FrameBuffer
{
Q_OBJECT
public:
explicit QtFrameBuffer(WId id, QObject *parent = nullptr);
explicit QtFrameBuffer(QObject *parent = nullptr);
~QtFrameBuffer() override;
@@ -38,6 +38,7 @@ public Q_SLOTS:
void updateFrameBuffer();
private:
WId win;
QImage fbImage;
QTimer *t;
QScreen *primaryScreen;

View File

@@ -31,10 +31,10 @@ QtFrameBufferPlugin::QtFrameBufferPlugin(QObject *parent, const QVariantList &ar
{
}
FrameBuffer *QtFrameBufferPlugin::frameBuffer(WId id, const QVariantMap &args)
FrameBuffer *QtFrameBufferPlugin::frameBuffer(const QVariantMap &args)
{
Q_UNUSED(args);
return new QtFrameBuffer(id);
return new QtFrameBuffer;
}
#include "qtframebufferplugin.moc"

View File

@@ -34,7 +34,7 @@ class QtFrameBufferPlugin : public FrameBufferPlugin
public:
QtFrameBufferPlugin(QObject *parent, const QVariantList &args);
FrameBuffer *frameBuffer(WId id, const QVariantMap &args) override;
FrameBuffer *frameBuffer(const QVariantMap &args) override;
private:
Q_DISABLE_COPY(QtFrameBufferPlugin)

View File

@@ -18,8 +18,9 @@ ecm_qt_declare_logging_category(krfb_framebuffer_xcb_SRCS
add_library(krfb_framebuffer_xcb MODULE ${krfb_framebuffer_xcb_SRCS})
target_link_libraries (krfb_framebuffer_xcb
Qt::Core
Qt::Gui
Qt5::Core
Qt5::Gui
Qt::GuiPrivate
XCB::XCB
XCB::RENDER
XCB::SHAPE

View File

@@ -18,16 +18,13 @@
#include <sys/ipc.h>
#include <sys/shm.h>
#include <QCoreApplication>
#include <QX11Info>
#include <QApplication>
#include <QGuiApplication>
#include <QScreen>
#include <QAbstractNativeEventFilter>
#include <qpa/qplatformnativeinterface.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QX11Info>
#else
#include <QtGui/private/qtx11extras_p.h>
#endif
class KrfbXCBEventFilter: public QAbstractNativeEventFilter
{
@@ -35,11 +32,7 @@ public:
KrfbXCBEventFilter(XCBFrameBuffer *owner);
public:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
#else
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
#endif
public:
int xdamageBaseEvent;
@@ -106,11 +99,7 @@ KrfbXCBEventFilter::KrfbXCBEventFilter(XCBFrameBuffer *owner):
bool KrfbXCBEventFilter::nativeEventFilter(const QByteArray &eventType,
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void *message, long *result) {
#else
void *message, qintptr *result) {
#endif
Q_UNUSED(result); // "result" is only used on windows
if (xdamageBaseEvent == 0) return false; // no xdamage extension
@@ -142,6 +131,7 @@ public:
bool running;
QRect area; // capture area, primary monitor coordinates
WId win;
};
@@ -156,8 +146,8 @@ static xcb_screen_t *get_xcb_screen(xcb_connection_t *conn, int screen_num) {
XCBFrameBuffer::XCBFrameBuffer(WId winid, QObject *parent):
FrameBuffer(winid, parent), d(new XCBFrameBuffer::P)
XCBFrameBuffer::XCBFrameBuffer(QObject *parent):
FrameBuffer(parent), d(new XCBFrameBuffer::P)
{
d->running = false;
d->damage = XCB_NONE;
@@ -174,6 +164,8 @@ XCBFrameBuffer::XCBFrameBuffer(WId winid, QObject *parent):
QScreen *primaryScreen = QGuiApplication::primaryScreen();
if (primaryScreen) {
QPlatformNativeInterface* native = qApp->platformNativeInterface();
d->win = reinterpret_cast<WId>(native->nativeResourceForScreen(QByteArrayLiteral("rootwindow"), primaryScreen));
qreal scaleFactor = primaryScreen->devicePixelRatio();
d->area = { primaryScreen->geometry().topLeft() * scaleFactor,
primaryScreen->geometry().bottomRight() * scaleFactor };
@@ -189,7 +181,7 @@ XCBFrameBuffer::XCBFrameBuffer(WId winid, QObject *parent):
}
d->framebufferImage = xcb_image_get(QX11Info::connection(),
this->win,
d->win,
d->area.left(),
d->area.top(),
d->area.width(),
@@ -258,7 +250,7 @@ XCBFrameBuffer::XCBFrameBuffer(WId winid, QObject *parent):
// will return 1 on success (yes!)
int shmget_res = xcb_image_shm_get(
QX11Info::connection(),
this->win,
d->win,
d->updateTile,
d->shminfo,
d->area.left(), // x
@@ -566,7 +558,7 @@ QList<QRect> XCBFrameBuffer::modifiedTiles() {
// translate whe coordinates
xcb_shm_get_image_cookie_t sgi_cookie = xcb_shm_get_image(
QX11Info::connection(),
this->win,
d->win,
d->area.left() + r.left(),
d->area.top() + r.top(),
r.width(),
@@ -621,7 +613,7 @@ QList<QRect> XCBFrameBuffer::modifiedTiles() {
// need function that copies pixels from one image to another
xcb_image_t *damagedImage = xcb_image_get(
QX11Info::connection(),
this->win,
d->win,
r.left(),
r.top(),
r.width(),
@@ -661,7 +653,7 @@ void XCBFrameBuffer::startMonitor() {
d->running = true;
d->damage = xcb_generate_id(QX11Info::connection());
xcb_damage_create(QX11Info::connection(), d->damage, this->win,
xcb_damage_create(QX11Info::connection(), d->damage, d->win,
XCB_DAMAGE_REPORT_LEVEL_RAW_RECTANGLES);
// (currently) we do not call xcb_damage_subtract() EVER, because

View File

@@ -22,7 +22,7 @@ class XCBFrameBuffer: public FrameBuffer
{
Q_OBJECT
public:
explicit XCBFrameBuffer(WId winid, QObject *parent = nullptr);
explicit XCBFrameBuffer(QObject *parent = nullptr);
~XCBFrameBuffer() override;
public:

View File

@@ -29,10 +29,10 @@ XCBFrameBufferPlugin::XCBFrameBufferPlugin(QObject *parent, const QVariantList &
{
}
FrameBuffer *XCBFrameBufferPlugin::frameBuffer(WId id, const QVariantMap &args)
FrameBuffer *XCBFrameBufferPlugin::frameBuffer(const QVariantMap &args)
{
Q_UNUSED(args);
return new XCBFrameBuffer(id);
return new XCBFrameBuffer;
}
#include "xcb_framebufferplugin.moc"

View File

@@ -34,7 +34,7 @@ class XCBFrameBufferPlugin: public FrameBufferPlugin
public:
XCBFrameBufferPlugin(QObject *parent, const QVariantList &args);
FrameBuffer *frameBuffer(WId id, const QVariantMap &args) override;
FrameBuffer *frameBuffer(const QVariantMap &args) override;
private:
Q_DISABLE_COPY(XCBFrameBufferPlugin)

View File

@@ -23,18 +23,13 @@ generate_export_header(krfbprivate BASE_NAME krfbprivate)
target_link_libraries (krfbprivate
Qt::Core
Qt::Widgets
Qt5::Core
Qt5::Widgets
Qt5::X11Extras
${X11_X11_LIB}
${LIBVNCSERVER_LIBRARIES}
)
if(QT_MAJOR_VERSION EQUAL "5")
target_link_libraries (krfbprivate Qt::X11Extras)
else()
target_link_libraries (krfbprivate Qt::GuiPrivate)
endif()
set_target_properties (krfbprivate PROPERTIES
VERSION 5
SOVERSION 5.0
@@ -85,7 +80,7 @@ ki18n_wrap_ui (krfb_UI_SRCS
ui/mainwidget.ui
)
qt_add_resources(krfb_SRCS
qt5_add_resources(krfb_SRCS
krfb.qrc
)
@@ -100,7 +95,7 @@ target_link_libraries (krfb
${X11_Xext_LIB}
${X11_X11_LIB}
${X11_Xdamage_LIB}
Qt::Network
Qt5::Network
KF5::CoreAddons
KF5::DBusAddons
KF5::DNSSD
@@ -140,8 +135,8 @@ add_executable(krfb-virtualmonitor main-virtualmonitor.cpp ${krfbvm_SRCS} ${krfb
rfbserver.cpp rfbclient.cpp rfbservermanager.cpp eventsmanager.cpp framebuffermanager.cpp sockethelpers.cpp)
target_link_libraries(krfb-virtualmonitor
krfbprivate
Qt::Gui
Qt::Network
Qt5::Gui
Qt5::Network
KF5::ConfigGui
KF5::CoreAddons
KF5::I18n

View File

@@ -13,8 +13,8 @@
#include <QCursor>
FrameBuffer::FrameBuffer(WId id, QObject *parent)
: QObject(parent), win(id)
FrameBuffer::FrameBuffer(QObject *parent)
: QObject(parent)
{
}

View File

@@ -29,7 +29,7 @@ class KRFBPRIVATE_EXPORT FrameBuffer : public QObject
{
Q_OBJECT
public:
explicit FrameBuffer(WId id, QObject *parent = nullptr);
explicit FrameBuffer(QObject *parent = nullptr);
~FrameBuffer() override;
@@ -52,7 +52,6 @@ Q_SIGNALS:
void frameBufferChanged();
protected:
WId win;
char *fb = nullptr;
QList<QRect> tiles;

View File

@@ -81,7 +81,7 @@ QSharedPointer<FrameBuffer> FrameBufferManager::frameBuffer(WId id, const QVaria
if (it.key() == KrfbConfig::preferredFrameBufferPlugin()) {
qCDebug(KRFB) << "Using FrameBuffer:" << KrfbConfig::preferredFrameBufferPlugin();
QSharedPointer<FrameBuffer> frameBuffer(it.value()->frameBuffer(id, args));
QSharedPointer<FrameBuffer> frameBuffer(it.value()->frameBuffer(args));
if (frameBuffer) {
m_frameBuffers.insert(id, frameBuffer.toWeakRef());

View File

@@ -37,7 +37,7 @@ public:
explicit FrameBufferPlugin(QObject *parent, const QVariantList &args);
~FrameBufferPlugin() override;
virtual FrameBuffer *frameBuffer(WId id, const QVariantMap &args) = 0;
virtual FrameBuffer *frameBuffer(const QVariantMap &args) = 0;
};
#endif // Header guard

View File

@@ -30,7 +30,7 @@
#include <KLocalizedString>
#include <KUser>
#include <KStringHandler>
#include <KWallet>
#include <KWallet/KWallet>
#include <kdnssd_version.h>
#if KDNSSD_VERSION >= QT_VERSION_CHECK(5, 84, 0)

View File

@@ -30,12 +30,7 @@
#include <QPixmap>
#include <qwindowdefs.h>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QX11Info>
#else
#include <QtGui/private/qtx11extras_p.h>
#endif
#include <csignal>
#include <X11/extensions/XTest.h>

View File

@@ -24,12 +24,7 @@
#include <QApplication>
#include <QClipboard>
#include <QPointer>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QX11Info>
#else
#include <QtGui/private/qtx11extras_p.h>
#endif
struct RfbServer::Private
{