fix: migrate X11 integration to Qt6

main
Reion Wong 4 weeks ago
parent 31450b6ecd
commit fee443b31f

@ -19,7 +19,7 @@ find_package(PkgConfig REQUIRED)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
include(GNUInstallDirs)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/compat")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
add_subdirectory(polkit-agent)
add_subdirectory(screen-brightness)

@ -18,10 +18,10 @@
*/
#include "hotkeys.h"
#include "x11utils.h"
#include <QApplication>
#include <QKeySequence>
#include <QX11Info>
#include <QTimer>
#include <QDebug>
@ -80,7 +80,6 @@ bool Hotkeys::nativeEventFilter(const QByteArray &eventType, void *message, qint
// // Keyboard needs to be ungrabed after XGrabKey() activates the grab,
// // otherwise it becomes frozen.
// xcb_connection_t *c = QX11Info::connection();
// xcb_void_cookie_t cookie = xcb_ungrab_keyboard_checked(c, XCB_TIME_CURRENT_TIME);
// xcb_flush(c);
@ -96,10 +95,6 @@ bool Hotkeys::nativeEventFilter(const QByteArray &eventType, void *message, qint
// }
// // All that work for this hey... argh...
// if (NET::timestampCompare(keyEvent->time, QX11Info::appTime()) > 0) {
// QX11Info::setAppTime(keyEvent->time);
// }
// bool found = false;
// for (QKeySequence &seq : m_shortcuts.values()) {
// if (seq == QKeySequence(keyQt)) {
@ -167,17 +162,17 @@ void Hotkeys::registerKey(quint32 keycode)
void Hotkeys::registerKey(quint32 key, quint32 mods)
{
xcb_grab_key(QX11Info::connection(),
xcb_grab_key(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection(),
1,
QX11Info::appRootWindow(),
Cutefish::X11::rootWindow(),
mods,
key,
XCB_GRAB_MODE_ASYNC,
XCB_GRAB_MODE_ASYNC);
xcb_grab_key(QX11Info::connection(),
xcb_grab_key(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection(),
1,
QX11Info::appRootWindow(),
Cutefish::X11::rootWindow(),
mods | XCB_MOD_MASK_2,
key,
XCB_GRAB_MODE_ASYNC,
@ -186,7 +181,7 @@ void Hotkeys::registerKey(quint32 key, quint32 mods)
void Hotkeys::unregisterKey(quint32 key, quint32 mods)
{
xcb_ungrab_key(QX11Info::connection(), key, QX11Info::appRootWindow(), mods);
xcb_ungrab_key(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection(), key, Cutefish::X11::rootWindow(), mods);
}
quint32 Hotkeys::nativeKeycode(Qt::Key k)
@ -263,7 +258,7 @@ quint32 Hotkeys::nativeKeycode(Qt::Key k)
key = 0;
}
}
return XKeysymToKeycode(QX11Info::display(), key);
return XKeysymToKeycode(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), key);
}
quint32 Hotkeys::nativeModifiers(Qt::KeyboardModifiers m)

@ -1,71 +0,0 @@
/*
* Small Qt 6 compatibility layer for the Qt 5 QX11Info calls used by the
* original Cutefish X11 helpers. Qt 6 exposes the same handles through the
* public QNativeInterface API instead of QtX11Extras.
*/
#ifndef CUTEFISH_QX11INFO_COMPAT
#define CUTEFISH_QX11INFO_COMPAT
#include <QGuiApplication>
#include <QScreen>
#include <QtGui/qguiapplication_platform.h>
#include <xcb/xcb.h>
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;
}
static int appScreen()
{
return 0;
}
static int appDpiY()
{
QScreen *screen = qGuiApp ? qGuiApp->primaryScreen() : nullptr;
return screen ? qRound(screen->logicalDotsPerInchY()) : 96;
}
// This is only used as the timestamp in synthetic tray input events.
static unsigned long getTimestamp()
{
return 0;
}
private:
static QNativeInterface::QX11Application *nativeInterface()
{
return qGuiApp ? qGuiApp->nativeInterface<QNativeInterface::QX11Application>() : nullptr;
}
};
#endif

@ -1,16 +1,17 @@
#include <QGuiApplication>
#include <QX11Info>
#include <QFile>
#include <QDebug>
#include <QSettings>
#include <QStandardPaths>
#include <QtGui/qguiapplication_platform.h>
#include <X11/X.h>
#include <X11/Xcursor/Xcursor.h>
inline void applyTheme(const QString &theme, int size)
{
Display *display = QX11Info::display();
Display *display = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display();
if (!theme.isEmpty())
XcursorSetTheme(display, QFile::encodeName(theme));
@ -41,7 +42,7 @@ int main(int argc, char *argv[])
if (argc != 3)
return 1;
if (!QX11Info::isPlatformX11())
if (!qGuiApp->nativeInterface<QNativeInterface::QX11Application>())
return 2;
QString theme = QFile::decodeName(argv[1]);

@ -16,6 +16,7 @@
#include <QTimer>
#include <QSettings>
#include <QDebug>
#include <QtGui/qguiapplication_platform.h>
// #include <KConfigGroup>
#include <KDirWatch>
@ -24,7 +25,6 @@
#include <KWindowInfo>
#include <netwm.h>
#include <QX11Info>
#include <xcb/xcb.h>
#include "window.h"
@ -50,7 +50,7 @@ static const QString s_appMenuGtkModule = QStringLiteral("appmenu-gtk-module");
MenuProxy::MenuProxy()
: QObject()
, m_xConnection(QX11Info::connection())
, m_xConnection(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection())
, m_serviceWatcher(new QDBusServiceWatcher(this))
, m_gtk2RcWatch(new KDirWatch(this))
, m_writeGtk2SettingsTimer(new QTimer(this))

@ -22,9 +22,9 @@
#include <QSettings>
#include <QTimer>
#include <QDBusPendingCall>
#include <QX11Info>
#include <QProcess>
#include <QDebug>
#include <QtGui/qguiapplication_platform.h>
#include <X11/Xlib.h>
#include <xcb/dpms.h>
@ -35,11 +35,11 @@ DimDisplayAction::DimDisplayAction(QObject *parent)
"/Brightness",
"com.cutefish.Brightness", QDBusConnection::sessionBus())
{
if (QX11Info::isPlatformX11()) {
if (qGuiApp->nativeInterface<QNativeInterface::QX11Application>()) {
// Disable a default timeout, if any
xcb_dpms_set_timeouts(QX11Info::connection(), 0, 0, 0);
xcb_dpms_set_timeouts(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection(), 0, 0, 0);
XSetScreenSaver(QX11Info::display(), 0, 0, 0, 0);
XSetScreenSaver(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), 0, 0, 0, 0);
}
}

@ -29,11 +29,11 @@
#include <QTimer>
#include <QThread>
#include <QDir>
#include <QtGui/qguiapplication_platform.h>
#include <QDBusInterface>
#include <QDBusPendingCall>
#include <QX11Info>
#include <KWindowSystem>
#include <netwm.h>
@ -246,7 +246,7 @@ bool ProcessManager::nativeEventFilter(const QByteArray &eventType, void *messag
// ref: lxqt session
if (!m_wmStarted && m_waitLoop) {
// all window managers must set their name according to the spec
if (!QString::fromUtf8(NETRootInfo(QX11Info::connection(), NET::SupportingWMCheck).wmName()).isEmpty()) {
if (!QString::fromUtf8(NETRootInfo(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection(), NET::SupportingWMCheck).wmName()).isEmpty()) {
qDebug() << "Window manager started";
m_wmStarted = true;
if (m_waitLoop && m_waitLoop->isRunning())

@ -20,9 +20,11 @@
#include "mousemanager.h"
#include "mouseadaptor.h"
#include <QtGui/qguiapplication_platform.h>
Mouse::Mouse(QObject *parent)
: QObject(parent)
, m_inputDummydevice(new X11LibinputDummyDevice(this, QX11Info::display()))
, m_inputDummydevice(new X11LibinputDummyDevice(this, qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display()))
{
// init dbus
new MouseAdaptor(this);

@ -9,9 +9,9 @@
#include <QObject>
#include <QString>
#include <QX11Info>
#include <X11/Xdefs.h>
#include <QtGui/qguiapplication_platform.h>
struct LibinputSettings;

@ -8,7 +8,7 @@
#define PROPERTYINFO_H
#include <QSharedPointer>
#include <QX11Info>
#include <QtGui/qguiapplication_platform.h>
#include <X11/Xdefs.h>
void XDeleter(void *p);

@ -13,7 +13,6 @@
#include <QSet>
#include <QSharedPointer>
#include <QStringList>
#include <QX11Info>
#include "libinputtouchpad.h"
#include "synapticstouchpad.h"

@ -8,7 +8,6 @@
#define XLIBNOTIFICATIONS_H
#include <QSocketNotifier>
#include <QX11Info>
#include <X11/Xlib.h>
#include <xcb/xcb.h>

@ -9,7 +9,8 @@
#include <QSocketNotifier>
#include <QVector>
#include <QX11Info>
#include <QtGui/qguiapplication_platform.h>
#include <xcb/record.h>
#include <xcb/xcb.h>

@ -0,0 +1,26 @@
#pragma once
#include <QGuiApplication>
#include <QtGui/qguiapplication_platform.h>
#include <xcb/xcb.h>
namespace Cutefish::X11
{
inline xcb_window_t rootWindow()
{
const auto native = qGuiApp ? qGuiApp->nativeInterface<QNativeInterface::QX11Application>() : 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;
}
inline int screenNumber()
{
return 0;
}
}

@ -11,7 +11,6 @@
#include <QCoreApplication>
#include <QTimer>
#include <QX11Info>
#include <KSelectionOwner>
@ -46,7 +45,7 @@ FdoSelectionManager::~FdoSelectionManager()
void FdoSelectionManager::init()
{
// load damage extension
xcb_connection_t *c = QX11Info::connection();
xcb_connection_t *c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
xcb_prefetch_extension_data(c, &xcb_damage_id);
const auto *reply = xcb_get_extension_data(c, &xcb_damage_id);
if (reply && reply->present) {
@ -70,7 +69,7 @@ bool FdoSelectionManager::addDamageWatch(xcb_window_t client)
{
qCDebug(SNIPROXY) << "adding damage watch for " << client;
xcb_connection_t *c = QX11Info::connection();
xcb_connection_t *c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
const auto attribsCookie = xcb_get_window_attributes_unchecked(c, client);
const auto damageId = xcb_generate_id(c);
@ -135,7 +134,7 @@ bool FdoSelectionManager::nativeEventFilter(const QByteArray &eventType, void *m
const auto sniProxy = m_proxies.value(damagedWId);
if (sniProxy) {
sniProxy->update();
xcb_damage_subtract(QX11Info::connection(), m_damageWatches[damagedWId], XCB_NONE, XCB_NONE);
xcb_damage_subtract(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection(), m_damageWatches[damagedWId], XCB_NONE, XCB_NONE);
}
} else if (responseType == XCB_CONFIGURE_REQUEST) {
const auto event = reinterpret_cast<xcb_configure_request_event_t *>(ev);
@ -205,7 +204,7 @@ void FdoSelectionManager::onLostOwnership()
void FdoSelectionManager::setSystemTrayVisual()
{
xcb_connection_t *c = QX11Info::connection();
xcb_connection_t *c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
auto screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
auto trayVisual = screen->root_visual;
xcb_depth_iterator_t depth_iterator = xcb_screen_allowed_depths_iterator(screen);

@ -13,12 +13,12 @@
#include <xcb/xcb_event.h>
#include "debug.h"
#include "x11utils.h"
#include "xcbutils.h"
#include <QGuiApplication>
#include <QScreen>
#include <QTimer>
#include <QX11Info>
#include <QBitmap>
@ -54,7 +54,7 @@ void xembed_message_send(xcb_window_t towin, long message, long d1, long d2, lon
ev.data.data32[3] = d2;
ev.data.data32[4] = d3;
ev.type = Xcb::atoms->xembedAtom;
xcb_send_event(QX11Info::connection(), false, towin, XCB_EVENT_MASK_NO_EVENT, (char *)&ev);
xcb_send_event(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection(), false, towin, XCB_EVENT_MASK_NO_EVENT, (char *)&ev);
}
SNIProxy::SNIProxy(xcb_window_t wid, QObject *parent)
@ -80,7 +80,7 @@ SNIProxy::SNIProxy(xcb_window_t wid, QObject *parent)
qCWarning(SNIPROXY) << "could not register SNI:" << reply.error().message();
}
auto c = QX11Info::connection();
auto c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
// create a container window
auto screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
@ -179,7 +179,7 @@ SNIProxy::SNIProxy(xcb_window_t wid, QObject *parent)
SNIProxy::~SNIProxy()
{
auto c = QX11Info::connection();
auto c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
xcb_destroy_window(c, m_containerWid);
QDBusConnection::disconnectFromBus(m_dbus.name());
@ -207,7 +207,7 @@ void SNIProxy::update()
void SNIProxy::resizeWindow(const uint16_t width, const uint16_t height) const
{
auto connection = QX11Info::connection();
auto connection = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
uint16_t widthNormalized = std::min(width, s_embedSize);
uint16_t heighNormalized = std::min(height, s_embedSize);
@ -228,7 +228,7 @@ void SNIProxy::hideContainerWindow(xcb_window_t windowId) const
QSize SNIProxy::calculateClientWindowSize() const
{
auto c = QX11Info::connection();
auto c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
auto cookie = xcb_get_geometry(c, m_windowId);
QScopedPointer<xcb_get_geometry_reply_t, QScopedPointerPodDeleter> clientGeom(xcb_get_geometry_reply(c, cookie, nullptr));
@ -282,7 +282,7 @@ bool SNIProxy::isTransparentImage(const QImage &image) const
QImage SNIProxy::getImageNonComposite() const
{
auto c = QX11Info::connection();
auto c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
QSize clientWindowSize = calculateClientWindowSize();
@ -381,7 +381,7 @@ QPoint SNIProxy::calculateClickPoint() const
{
QPoint clickPoint = QPoint(0, 0);
auto c = QX11Info::connection();
auto c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
// request extent to check if shape has been set
xcb_shape_query_extents_cookie_t extentsCookie = xcb_shape_query_extents(c, m_windowId);
@ -418,7 +418,7 @@ QPoint SNIProxy::calculateClickPoint() const
void SNIProxy::stackContainerWindow(const uint32_t stackMode) const
{
auto c = QX11Info::connection();
auto c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
const uint32_t stackData[] = {stackMode};
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackData);
}
@ -506,7 +506,7 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y)
qCDebug(SNIPROXY) << "Received click" << mouseButton << "with passed x*y" << x << y;
sendingClickEvent = true;
auto c = QX11Info::connection();
auto c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection();
auto cookieSize = xcb_get_geometry(c, m_windowId);
QScopedPointer<xcb_get_geometry_reply_t, QScopedPointerPodDeleter> clientGeom(xcb_get_geometry_reply(c, cookieSize, nullptr));
@ -549,9 +549,9 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y)
memset(event, 0x00, sizeof(xcb_button_press_event_t));
event->response_type = XCB_BUTTON_PRESS;
event->event = m_windowId;
event->time = QX11Info::getTimestamp();
event->time = XCB_CURRENT_TIME;
event->same_screen = 1;
event->root = QX11Info::appRootWindow();
event->root = Cutefish::X11::rootWindow();
event->root_x = x;
event->root_y = y;
event->event_x = static_cast<int16_t>(clickPoint.x());
@ -563,7 +563,7 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y)
xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);
delete event;
} else {
sendXTestPressed(QX11Info::display(), mouseButton);
sendXTestPressed(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), mouseButton);
}
// mouse up
@ -572,9 +572,9 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y)
memset(event, 0x00, sizeof(xcb_button_release_event_t));
event->response_type = XCB_BUTTON_RELEASE;
event->event = m_windowId;
event->time = QX11Info::getTimestamp();
event->time = XCB_CURRENT_TIME;
event->same_screen = 1;
event->root = QX11Info::appRootWindow();
event->root = Cutefish::X11::rootWindow();
event->root_x = x;
event->root_y = y;
event->event_x = static_cast<int16_t>(clickPoint.x());
@ -586,7 +586,7 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y)
xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_RELEASE, (char *)event);
delete event;
} else {
sendXTestReleased(QX11Info::display(), mouseButton);
sendXTestReleased(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), mouseButton);
}
#ifndef VISUAL_DEBUG

@ -17,7 +17,8 @@
#include <QScopedPointer>
#include <QVector>
#include <QX11Info>
#include "x11utils.h"
/** XEMBED messages */
#define XEMBED_EMBEDDED_NOTIFY 0
@ -39,7 +40,7 @@ using ScopedCPointer = QScopedPointer<T, QScopedPointerPodDeleter>;
class Atom
{
public:
explicit Atom(const QByteArray &name, bool onlyIfExists = false, xcb_connection_t *c = QX11Info::connection())
explicit Atom(const QByteArray &name, bool onlyIfExists = false, xcb_connection_t *c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection())
: m_connection(c)
, m_retrieved(false)
, m_cookie(xcb_intern_atom_unchecked(m_connection, onlyIfExists, name.length(), name.constData()))
@ -102,7 +103,7 @@ class Atoms
public:
Atoms()
: xembedAtom("_XEMBED")
, selectionAtom(xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", QX11Info::appScreen()))
, selectionAtom(xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", Cutefish::X11::screenNumber()))
, opcodeAtom("_NET_SYSTEM_TRAY_OPCODE")
, messageData("_NET_SYSTEM_TRAY_MESSAGE_DATA")
, visualAtom("_NET_SYSTEM_TRAY_VISUAL")

Loading…
Cancel
Save