fix: migrate X11 integration to Qt6

main
reionwong 2 months ago
parent 34e02fcf44
commit b565a8a12f

@ -4,7 +4,7 @@ set(PROJECT_NAME cutefish-settings)
project(${PROJECT_NAME})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/compat")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

@ -1,43 +0,0 @@
/* Qt 6 compatibility layer for the legacy QX11Info API. */
#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 int appDpiY()
{
QScreen *screen = qGuiApp ? qGuiApp->primaryScreen() : nullptr;
return screen ? qRound(screen->logicalDotsPerInchY()) : 96;
}
private:
static QNativeInterface::QX11Application *nativeInterface()
{
return qGuiApp ? qGuiApp->nativeInterface<QNativeInterface::QX11Application>() : nullptr;
}
};
#endif

@ -23,8 +23,8 @@
#include <QSettings>
#include <QCursor>
#include <QDebug>
#include <QX11Info>
#include <QImage>
#include <QtGui/qguiapplication_platform.h>
#include <X11/Xlib.h>
#include <X11/Xcursor/Xcursor.h>
@ -92,7 +92,7 @@ QPixmap CursorTheme::pixmap() const
int CursorTheme::defaultCursorSize() const
{
if (!QX11Info::isPlatformX11()) {
if (!qGuiApp->nativeInterface<QNativeInterface::QX11Application>()) {
return 32;
}
@ -102,7 +102,7 @@ int CursorTheme::defaultCursorSize() const
this custom value. */
int size = 0;
int dpi = 0;
Display *dpy = QX11Info::display();
Display *dpy = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display();
// The string "v" is owned and will be destroyed by Xlib
char *v = XGetDefault(dpy, "Xft", "dpi");
if (v)
@ -184,7 +184,7 @@ QPixmap CursorTheme::createIcon(int size) const
qulonglong CursorTheme::loadCursor(const QString &name, int size) const
{
if (!QX11Info::isPlatformX11()) {
if (!qGuiApp->nativeInterface<QNativeInterface::QX11Application>()) {
return None;
}
if (size <= 0)
@ -200,7 +200,7 @@ qulonglong CursorTheme::loadCursor(const QString &name, int size) const
return None;
// Create the cursor
Cursor handle = XcursorImagesLoadCursor(QX11Info::display(), images);
Cursor handle = XcursorImagesLoadCursor(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), images);
XcursorImagesDestroy(images);
return handle;
@ -266,13 +266,13 @@ bool CursorTheme::haveXfixes()
{
bool result = false;
if (!QX11Info::isPlatformX11()) {
if (!qGuiApp->nativeInterface<QNativeInterface::QX11Application>()) {
return result;
}
int event_base, error_base;
if (XFixesQueryExtension(QX11Info::display(), &event_base, &error_base)) {
if (XFixesQueryExtension(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), &event_base, &error_base)) {
int major, minor;
XFixesQueryVersion(QX11Info::display(), &major, &minor);
XFixesQueryVersion(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), &major, &minor);
result = (major >= 2);
}

@ -25,8 +25,8 @@
#include <QFileInfo>
#include <QDebug>
#include <QDir>
#include <QtGui/qguiapplication_platform.h>
#include <QX11Info>
#include <X11/Xcursor/Xcursor.h>
#include <X11/extensions/Xfixes.h>
@ -164,7 +164,7 @@ void CursorThemeModel::setCurrentTheme(const QString &theme)
int cursorSize = m_settings.value("CursorSize").toInt() * m_settings.value("PixelRatio").toReal();
foreach (const QString &name, names) {
XFixesChangeCursorByName(QX11Info::display(), theme->loadCursor(name, cursorSize), QFile::encodeName(name));
XFixesChangeCursorByName(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), theme->loadCursor(name, cursorSize), QFile::encodeName(name));
}
}
}

@ -18,6 +18,7 @@
*/
#include "kxftconfig.h"
#include "x11utils.h"
#include <ctype.h>
#include <math.h>
@ -33,7 +34,6 @@
#include <QFile>
#include <QFileInfo>
#include <QStandardPaths>
#include <QX11Info>
#include <fontconfig/fontconfig.h>
@ -41,12 +41,12 @@ using namespace std;
static int point2Pixel(double point)
{
return (int)(((point * QX11Info::appDpiY()) / 72.0) + 0.5);
return (int)(((point * Cutefish::X11::dpiY()) / 72.0) + 0.5);
}
static int pixel2Point(double pixel)
{
return (int)(((pixel * 72.0) / (double)QX11Info::appDpiY()) + 0.5);
return (int)(((pixel * 72.0) / (double)Cutefish::X11::dpiY()) + 0.5);
}
static bool equal(double d1, double d2)

@ -0,0 +1,12 @@
#pragma once
#include <QGuiApplication>
#include <QScreen>
namespace Cutefish::X11
{
inline int dpiY()
{
const auto screen = qGuiApp ? qGuiApp->primaryScreen() : nullptr;
return screen ? qRound(screen->logicalDotsPerInchY()) : 96;
}
}
Loading…
Cancel
Save