frameworkintegration/0001-Update-XCursor-settings.patch

142 lines
5.2 KiB
Diff

From 0e949d2b5b54ae7cc44ba21a43cecbde5ddaacc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= <mgraesslin@kde.org>
Date: Thu, 8 Jan 2015 16:31:40 +0100
Subject: [PATCH 1/8] Update XCursor settings
Code taken and adjusted from KGlobalSettings.
REVIEW: 121927
CHANGELOG: Update XCursor settings on X11 platform.
---
autotests/CMakeLists.txt | 1 +
src/platformtheme/CMakeLists.txt | 7 +++++-
src/platformtheme/khintssettings.cpp | 44 ++++++++++++++++++++++++++++++++++++
src/platformtheme/khintssettings.h | 1 +
4 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 00337e775e4e2d3e2d1bb583f4102323f0e5973b..e8ed6a99bb45969231ba21b8c5588e093bbbe3ee 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -17,6 +17,7 @@ remove_definitions(-DQT_NO_CAST_FROM_ASCII)
macro(FRAMEWORKINTEGRATION_TESTS _testname)
add_executable(${_testname} ${_testname}.cpp ${ARGN})
+ set_target_properties(${_testname} PROPERTIES COMPILE_FLAGS "-DUNIT_TEST")
add_test(frameworkintegration-${_testname} ${_testname})
ecm_mark_as_test(${_testname})
target_link_libraries(${_testname} Qt5::Test Qt5::DBus KF5::ConfigWidgets KF5::ConfigCore KF5::IconThemes KF5::Style KF5::KIOFileWidgets KF5::I18n KF5::Notifications)
diff --git a/src/platformtheme/CMakeLists.txt b/src/platformtheme/CMakeLists.txt
index 8a3b1b43d617083730517fe8db0a1e2f543913ab..b0d804904b5df2996893046b2b942be6ad952860 100644
--- a/src/platformtheme/CMakeLists.txt
+++ b/src/platformtheme/CMakeLists.txt
@@ -7,6 +7,11 @@ if(NOT APPLE)
set(HAVE_X11 ${XCB_XCB_FOUND})
if (XCB_XCB_FOUND)
find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED X11Extras)
+ find_package(X11)
+ set_package_properties(X11 PROPERTIES DESCRIPTION "Required for updating the Cursor theme on X11"
+ URL "http://www.x.org"
+ TYPE REQUIRED
+ )
endif()
else()
set(HAVE_X11 FALSE)
@@ -46,7 +51,7 @@ target_link_libraries(KDEPlatformTheme
)
if(HAVE_X11)
- target_link_libraries(KDEPlatformTheme PRIVATE Qt5::X11Extras XCB::XCB)
+ target_link_libraries(KDEPlatformTheme PRIVATE Qt5::X11Extras XCB::XCB ${X11_Xcursor_LIB})
endif()
install(TARGETS KDEPlatformTheme DESTINATION ${QT_PLUGIN_INSTALL_DIR}/platformthemes)
diff --git a/src/platformtheme/khintssettings.cpp b/src/platformtheme/khintssettings.cpp
index a477a1078f7d62294abfffc92a77889832b1e0db..6e8313d02f5392802a4c8155c2b7341b84a4bd39 100644
--- a/src/platformtheme/khintssettings.cpp
+++ b/src/platformtheme/khintssettings.cpp
@@ -33,6 +33,7 @@
#include <QApplication>
#include <QGuiApplication>
#include <QDialogButtonBox>
+#include <QScreen>
#include <QDBusConnection>
#include <QDBusInterface>
@@ -42,6 +43,16 @@
#include <ksharedconfig.h>
#include <kcolorscheme.h>
+#ifndef UNIT_TEST
+#include <config-platformtheme.h>
+#else
+#define HAVE_X11 0
+#endif
+#if HAVE_X11
+#include <QX11Info>
+#include <X11/Xcursor/Xcursor.h>
+#endif
+
static const QString defaultLookAndFeelPackage = "org.kde.breeze.desktop";
KHintsSettings::KHintsSettings() : QObject(0)
@@ -234,6 +245,9 @@ void KHintsSettings::slotNotifyChange(int type, int arg)
case IconChanged:
iconChanged(arg); //Once the KCM is ported to use IconChanged, this should not be needed
break;
+ case CursorChanged:
+ updateCursorTheme();
+ break;
case StyleChanged: {
QApplication *app = qobject_cast<QApplication *>(QCoreApplication::instance());
if (!app) {
@@ -363,3 +377,33 @@ void KHintsSettings::loadPalettes()
}
}
}
+
+void KHintsSettings::updateCursorTheme()
+{
+ KConfig config("kcminputrc");
+ KConfigGroup g(&config, "Mouse");
+
+ QString theme = g.readEntry("cursorTheme", QString());
+ int size = g.readEntry("cursorSize", -1);
+
+ // Default cursor size is 16 points
+ if (size == -1) {
+ if (QScreen *s = QGuiApplication::primaryScreen()) {
+ size = s->logicalDotsPerInchY() * 16 / 72;
+ } else {
+ size = 0;
+ }
+ }
+
+#if HAVE_X11
+ if (QX11Info::isPlatformX11()) {
+ // Note that in X11R7.1 and earlier, calling XcursorSetTheme()
+ // with a NULL theme would cause Xcursor to use "default", but
+ // in 7.2 and later it will cause it to revert to the theme that
+ // was configured when the application was started.
+ XcursorSetTheme(QX11Info::display(), theme.isNull() ?
+ "default" : QFile::encodeName(theme).constData());
+ XcursorSetDefaultSize(QX11Info::display(), size);
+ }
+#endif
+}
diff --git a/src/platformtheme/khintssettings.h b/src/platformtheme/khintssettings.h
index 281e24037b63706ca6af2843e3d38fb2dd10e73c..ec064d32c8516e3647b7731e643bc90d03e7a833 100644
--- a/src/platformtheme/khintssettings.h
+++ b/src/platformtheme/khintssettings.h
@@ -76,6 +76,7 @@ private:
void iconChanged(int group);
void updateQtSettings(KConfigGroup &cg);
Qt::ToolButtonStyle toolButtonStyle(const KConfigGroup &cg) const;
+ void updateCursorTheme();
QStringList xdgIconThemePaths() const;
QHash<QPlatformTheme::Palette, QPalette *> m_palettes;
--
2.2.2