/* SPDX-FileCopyrightText: 2017 Xuetian Weng SPDX-FileCopyrightText: 2018 Roman Gilg SPDX-License-Identifier: GPL-2.0-or-later */ #include "x11_backend.h" #include "x11_libinput_backend.h" #include "logging.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #if HAVE_XCURSOR #include #include #endif X11Backend *X11Backend::implementation(QObject *parent) { auto dpy = QX11Info::display(); Atom testAtom = XInternAtom(dpy, LIBINPUT_PROP_ACCEL, True); if (testAtom) { qCDebug(KCM_MOUSE) << "Using libinput driver on X11."; return new X11LibinputBackend(parent); } return nullptr; } X11Backend::X11Backend(QObject *parent) : InputBackend(parent) { m_platformX11 = QX11Info::isPlatformX11(); if (m_platformX11) { m_dpy = QX11Info::display(); } else { // TODO: remove this - not needed anymore with Wayland backend! // let's hope we have a compatibility system like Xwayland ready m_dpy = XOpenDisplay(nullptr); } } X11Backend::~X11Backend() { if (!m_platformX11 && m_dpy) { XCloseDisplay(m_dpy); } } QString X11Backend::currentCursorTheme() { if (!m_dpy) { return QString(); } QByteArray name = XGetDefault(m_dpy, "Xcursor", "theme"); #if HAVE_XCURSOR if (name.isEmpty()) { name = QByteArray(XcursorGetTheme(m_dpy)); } #endif return QFile::decodeName(name); } void X11Backend::applyCursorTheme(const QString &theme, int size) { #if HAVE_XCURSOR // Apply the KDE cursor theme to ourselves if (!m_dpy) { return; } if (!theme.isEmpty()) { XcursorSetTheme(m_dpy, QFile::encodeName(theme)); } if (size >= 0) { XcursorSetDefaultSize(m_dpy, size); } // Load the default cursor from the theme and apply it to the root window. Cursor handle = XcursorLibraryLoadCursor(m_dpy, "left_ptr"); XDefineCursor(m_dpy, DefaultRootWindow(m_dpy), handle); XFreeCursor(m_dpy, handle); // Don't leak the cursor XFlush(m_dpy); #endif } void X11Backend::kcmInit() { auto config = KSharedConfig::openConfig("kcminputrc", KConfig::NoGlobals); KConfigGroup group = config->group(QStringLiteral("Mouse")); const QString theme = group.readEntry("cursorTheme", QStringLiteral("breeze_cursors")); const int size = group.readEntry("cursorSize", 24); // Note: If you update this code, update kapplymousetheme as well. applyCursorTheme(theme, size); }