From 95913823505c0b49efea521c1c954d8ccdadfa99 Mon Sep 17 00:00:00 2001 From: reionwong Date: Sun, 30 Aug 2026 06:36:35 -0400 Subject: [PATCH] fix: migrate X11 integration to Qt6 --- CMakeLists.txt | 2 +- compat/QX11Info | 47 -------------------------------- platformtheme/x11integration.cpp | 9 +++--- widgetstyle/blurhelper.cpp | 5 ++-- x11utils.h | 21 ++++++++++++++ 5 files changed, 30 insertions(+), 54 deletions(-) delete mode 100644 compat/QX11Info create mode 100644 x11utils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8715a2d..26f5eb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16) project(cutefish-qt-plugins) -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/compat") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") diff --git a/compat/QX11Info b/compat/QX11Info deleted file mode 100644 index 43e1989..0000000 --- a/compat/QX11Info +++ /dev/null @@ -1,47 +0,0 @@ -/* Qt 6 compatibility layer for the legacy QX11Info API. */ -#ifndef CUTEFISH_QX11INFO_COMPAT -#define CUTEFISH_QX11INFO_COMPAT - -#include -#include -#include - -class QX11Info -{ -public: - static bool isPlatformX11() - { - return nativeInterface() != nullptr; - } - - static xcb_connection_t *connection() - { - const auto native = nativeInterface(); - return native ? native->connection() : nullptr; - } - - static Display *display() - { - const auto native = nativeInterface(); - return native ? native->display() : nullptr; - } - - static xcb_window_t appRootWindow() - { - xcb_connection_t *c = connection(); - if (!c) - return XCB_WINDOW_NONE; - - const xcb_setup_t *setup = xcb_get_setup(c); - const xcb_screen_iterator_t iterator = xcb_setup_roots_iterator(setup); - return iterator.data ? iterator.data->root : XCB_WINDOW_NONE; - } - -private: - static QNativeInterface::QX11Application *nativeInterface() - { - return qGuiApp ? qGuiApp->nativeInterface() : nullptr; - } -}; - -#endif diff --git a/platformtheme/x11integration.cpp b/platformtheme/x11integration.cpp index 7b10cc3..fc8b5df 100644 --- a/platformtheme/x11integration.cpp +++ b/platformtheme/x11integration.cpp @@ -19,11 +19,12 @@ * Boston, MA 02110-1301, USA. */ #include "x11integration.h" +#include "x11utils.h" #include -#include #include #include +#include #include #include #include @@ -58,7 +59,7 @@ bool X11Integration::eventFilter(QObject *watched, QEvent *event) if (event->type() == QEvent::Show && watched->inherits("QShapedPixmapWindow")) { //static cast should be safe there QWindow *w = static_cast(watched); - NETWinInfo info(QX11Info::connection(), w->winId(), QX11Info::appRootWindow(), NET::WMWindowType, NET::Properties2()); + NETWinInfo info(qGuiApp->nativeInterface()->connection(), w->winId(), Cutefish::X11::rootWindow(), NET::WMWindowType, NET::Properties2()); info.setWindowType(NET::DNDIcon); // TODO: does this flash the xcb connection? } @@ -103,13 +104,13 @@ void X11Integration::installDesktopFileName(QWindow *w) if (desktopFileName.endsWith(QLatin1String(".desktop"))) { desktopFileName.chop(8); } - NETWinInfo info(QX11Info::connection(), w->winId(), QX11Info::appRootWindow(), NET::Properties(), NET::Properties2()); + NETWinInfo info(qGuiApp->nativeInterface()->connection(), w->winId(), Cutefish::X11::rootWindow(), NET::Properties(), NET::Properties2()); info.setDesktopFileName(desktopFileName.toUtf8().constData()); } void X11Integration::setWindowProperty(QWindow *window, const QByteArray &name, const QByteArray &value) { - auto *c = QX11Info::connection(); + auto *c = qGuiApp->nativeInterface()->connection(); xcb_atom_t atom; auto it = m_atoms.find(name); diff --git a/widgetstyle/blurhelper.cpp b/widgetstyle/blurhelper.cpp index 571e4c1..79391f8 100644 --- a/widgetstyle/blurhelper.cpp +++ b/widgetstyle/blurhelper.cpp @@ -30,6 +30,7 @@ ////////////////////////////////////////////////////////////////////////////// #include "blurhelper.h" +#include "x11utils.h" // KDE Frameworks #include @@ -43,7 +44,7 @@ #include #include #include -#include +#include // XCB #include @@ -124,7 +125,7 @@ void BlurHelper::enableBlurBehind(QWidget *widget, bool enable, qreal windowRadi if (!widget) return; - xcb_connection_t *c = QX11Info::connection(); + xcb_connection_t *c = qGuiApp->nativeInterface()->connection(); if (!c) return; diff --git a/x11utils.h b/x11utils.h new file mode 100644 index 0000000..d3546ee --- /dev/null +++ b/x11utils.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +#include + +namespace Cutefish::X11 +{ +inline xcb_window_t rootWindow() +{ + const auto native = qGuiApp ? qGuiApp->nativeInterface() : nullptr; + const auto c = native ? native->connection() : nullptr; + if (!c) + return XCB_WINDOW_NONE; + + const auto *setup = xcb_get_setup(c); + const auto iterator = xcb_setup_roots_iterator(setup); + return iterator.data ? iterator.data->root : XCB_WINDOW_NONE; +} +}