Roles/kde: remove all patches

This commit is contained in:
Toast 2025-07-04 18:00:51 +02:00
parent d87450b305
commit d05764d3dd
6 changed files with 0 additions and 4296 deletions

View file

@ -1,72 +0,0 @@
From 7cc7fe9783a68e086369bd0b96b280082097d60a Mon Sep 17 00:00:00 2001
From: Oliver Beard <olib141@outlook.com>
Date: Thu, 20 Feb 2025 22:49:25 +0000
Subject: [PATCH] kcms/about-distro: Fix hint expanding height of parent layout
Instead, use an label with padding to match the height of normal text. A
background is used to fill this padded area.
If smallFont is larger than normal text, the text will draw outside the label which would be restricted to the same height as normal text by negative padding. I don't see this as worth fixing - if the small font is larger than normal text, that would be the problem, not this...
When valueLabel spans multiple lines, it will be vertically centered.
CCBUG: 500355
---
kcms/about-distro/src/ui/main.qml | 35 +++++++++++++++++++------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/kcms/about-distro/src/ui/main.qml b/kcms/about-distro/src/ui/main.qml
index 7a3f72bfb..80fbc2c13 100644
--- a/kcms/about-distro/src/ui/main.qml
+++ b/kcms/about-distro/src/ui/main.qml
@@ -136,26 +136,35 @@ KCMUtils.SimpleKCM {
}
}
- QQC2.Control {
+ QQC2.Label {
+ Kirigami.Theme.colorSet: Kirigami.Theme.Window
visible: hint !== ""
- topPadding: Kirigami.Units.smallSpacing
- rightPadding: Kirigami.Units.smallSpacing
- bottomPadding: Kirigami.Units.smallSpacing
- leftPadding: Kirigami.Units.smallSpacing
- Kirigami.Theme.colorSet: Kirigami.Theme.Window
+ // Vertical padding accounts for the difference in normal label height and the content height of this small label
+ readonly property real verticalPadding: (hintMetrics.height - contentHeight) / 2
+ // Horizontal padding also accounts for the difference in content height and the font's pixelSize to better balance the text
+ readonly property real horizontalPadding: ((hintMetrics.height - contentHeight) + (contentHeight - font.pixelSize)) / 2
+
+ TextMetrics {
+ // Necessary as valueLabel could be multiple lines
+ id: hintMetrics
+ text: " "
+ }
+
+ topPadding: verticalPadding
+ bottomPadding: verticalPadding
+ leftPadding: horizontalPadding
+ rightPadding: horizontalPadding
+
+ text: hint
+ color: hintColorForeground
+ font.bold: true
+ font.pixelSize: Kirigami.Theme.smallFont.pixelSize
background: Rectangle {
color: hintColorBackground
radius: Kirigami.Units.cornerRadius
}
-
- contentItem: QQC2.Label {
- text: hint
- color: hintColorForeground
- font.bold: true
- font.pixelSize: Kirigami.Theme.smallFont.pixelSize
- }
}
QQC2.Button {
--
GitLab

View file

@ -1,426 +0,0 @@
From f44af69b07ed19d076819fe4cc84e5777747d957 Mon Sep 17 00:00:00 2001
From: Oliver Beard <olib141@outlook.com>
Date: Thu, 20 Feb 2025 22:43:47 +0000
Subject: [PATCH 1/2] kcms/about-distro: Add help property to Entry & show
total amount of installed memory in MemoryEntry This provides additional
information to the user, with a new help tooltip that clarifies the displayed
values as is contextually appropriate. For example, if the shown message is
"32 GB of RAM (31.3 GB usable)", the tooltip will elucidate that some memory
is reserved for use by system hardware. BUG: 500412
---
CMakeLists.txt | 4 +
kcms/about-distro/src/CMakeLists.txt | 5 +
kcms/about-distro/src/Entry.cpp | 5 +
kcms/about-distro/src/Entry.h | 3 +
kcms/about-distro/src/MemoryEntry.cpp | 144 +++++++++++++++++++++++---
kcms/about-distro/src/MemoryEntry.h | 9 +-
kcms/about-distro/src/ui/main.qml | 5 +
7 files changed, 157 insertions(+), 18 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 51f940789..e3005878a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,10 @@ find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS
find_package(PkgConfig)
pkg_check_modules(libdrm REQUIRED IMPORTED_TARGET libdrm)
+if(CMAKE_SYSTEM_NAME MATCHES "Linux")
+ find_package(UDev REQUIRED COMPONENTS UDev)
+endif()
+
ecm_find_qmlmodule(org.kde.kirigami 2.5)
macro(kinfocenter_add_kcm target)
diff --git a/kcms/about-distro/src/CMakeLists.txt b/kcms/about-distro/src/CMakeLists.txt
index 13ad8d0af..d731d81a1 100644
--- a/kcms/about-distro/src/CMakeLists.txt
+++ b/kcms/about-distro/src/CMakeLists.txt
@@ -43,6 +43,11 @@ target_link_libraries(kcm_about-distro PRIVATE
PkgConfig::libdrm
)
+if(UDev_FOUND)
+ target_link_libraries(kcm_about-distro PRIVATE UDev::UDev)
+ target_compile_definitions(kcm_about-distro PRIVATE UDEV_FOUND)
+endif()
+
cmake_path(RELATIVE_PATH KDE_INSTALL_FULL_LIBEXECDIR BASE_DIRECTORY "${KDE_INSTALL_FULL_PLUGINDIR}/plasma/kcms/" OUTPUT_VARIABLE LIBEXECDIR_FROM_KCM)
target_compile_options(
diff --git a/kcms/about-distro/src/Entry.cpp b/kcms/about-distro/src/Entry.cpp
index a4077efda..63dc71fbb 100644
--- a/kcms/about-distro/src/Entry.cpp
+++ b/kcms/about-distro/src/Entry.cpp
@@ -82,4 +82,9 @@ Hint Entry::localizedHint(Language) const
return {};
}
+QString Entry::localizedHelp(Language) const
+{
+ return {};
+}
+
#include "moc_Entry.cpp"
diff --git a/kcms/about-distro/src/Entry.h b/kcms/about-distro/src/Entry.h
index e5c3f6f17..bc053a4f4 100644
--- a/kcms/about-distro/src/Entry.h
+++ b/kcms/about-distro/src/Entry.h
@@ -78,6 +78,9 @@ public:
// Returns a hint for the user to consider when interpreting the value.
Q_INVOKABLE [[nodiscard]] virtual Hint localizedHint(Language language = Language::System) const;
+ // Returns a help string for the entry, shown with a ContextualHelpButton
+ Q_SCRIPTABLE [[nodiscard]] virtual QString localizedHelp(Language language = Language::System) const;
+
protected:
// Returns localized QString for the given language.
QString localize(const KLocalizedString &string, Language language) const;
diff --git a/kcms/about-distro/src/MemoryEntry.cpp b/kcms/about-distro/src/MemoryEntry.cpp
index 1baaea2ac..b58b55237 100644
--- a/kcms/about-distro/src/MemoryEntry.cpp
+++ b/kcms/about-distro/src/MemoryEntry.cpp
@@ -9,6 +9,9 @@
#ifdef Q_OS_LINUX
#include <sys/sysinfo.h>
+#ifdef UDEV_FOUND
+#include <libudev.h>
+#endif
#elif defined(Q_OS_FREEBSD)
// clang-format off
#include <sys/types.h>
@@ -21,34 +24,141 @@ MemoryEntry::MemoryEntry()
{
}
-qlonglong MemoryEntry::calculateTotalRam()
+std::optional<qlonglong> MemoryEntry::calculateTotalRam()
+{
+#if defined(Q_OS_LINUX) && defined(UDEV_FOUND)
+ std::unique_ptr<struct udev, decltype(&udev_unref)> udev(udev_new(), &udev_unref);
+ if (!udev) {
+ return {};
+ }
+
+ std::unique_ptr<struct udev_device, decltype(&udev_device_unref)> dmi(udev_device_new_from_syspath(udev.get(), "/sys/class/dmi/id/"), &udev_device_unref);
+ if (!dmi) {
+ return {};
+ }
+
+ const char *numMemoryDevicesCStr = udev_device_get_property_value(dmi.get(), "MEMORY_ARRAY_NUM_DEVICES");
+ if (!numMemoryDevicesCStr) {
+ return {};
+ }
+
+ bool ok;
+ int numMemoryDevices = QByteArray(numMemoryDevicesCStr).toInt(&ok);
+ if (!ok) {
+ return {};
+ }
+
+ qlonglong totalBytes = 0;
+ for (int i = 0; i < numMemoryDevices; ++i) {
+ const char *memoryBytesCStr = udev_device_get_property_value(dmi.get(), QStringLiteral("MEMORY_DEVICE_%1_SIZE").arg(i).toLatin1());
+ qlonglong memoryBytes = QByteArray(memoryBytesCStr).toLongLong(&ok);
+ if (ok) {
+ totalBytes += memoryBytes;
+ }
+ }
+
+ return totalBytes;
+#endif
+
+ /*
+ * TODO: A FreeBSD impl is likely possible, but it appears that
+ * sysctlbyname() cannot get what we want with either "hw.physmem",
+ * "hw.usermem" or "hw.realmem".
+ * On a system with 2 x 4 GiB memory modules installed, we would need
+ * to return a value of 8 GiB in bytes.
+ */
+
+ return {};
+}
+
+std::optional<qlonglong> MemoryEntry::calculateAvailableRam()
{
- qlonglong ret = -1;
#ifdef Q_OS_LINUX
struct sysinfo info;
- if (sysinfo(&info) == 0)
- // manpage "sizes are given as multiples of mem_unit bytes"
- ret = qlonglong(info.totalram) * info.mem_unit;
+ if (sysinfo(&info) == 0) {
+ // manpage: "sizes are given as multiples of mem_unit bytes"
+ return qlonglong(info.totalram) * info.mem_unit;
+ }
#elif defined(Q_OS_FREEBSD)
/* Stuff for sysctl */
- size_t len;
-
unsigned long memory;
- len = sizeof(memory);
- sysctlbyname("hw.physmem", &memory, &len, NULL, 0);
-
- ret = memory;
+ size_t len = sizeof(memory);
+ if (sysctlbyname("hw.physmem", &memory, &len, NULL, 0) == 0) {
+ return memory;
+ }
#endif
- return ret;
+
+ return {};
}
QString MemoryEntry::localizedValue(Language language) const
{
- const qlonglong totalRam = calculateTotalRam();
- if (totalRam > 0) {
- const auto string = ki18nc("@label %1 is the formatted amount of system memory (e.g. 7,7 GiB)", "%1 of RAM")
- .subs(KFormat(localeForLanguage(language)).formatByteSize(totalRam));
+ auto precisionForGiB = [](std::optional<qlonglong> bytes) -> int {
+ if (!bytes.has_value()) {
+ return 0;
+ }
+
+ constexpr qlonglong GiB = 1024 * 1024 * 1024;
+ return (bytes.value() % GiB == 0) ? 0 : 1;
+ };
+
+ const int totalRamPrecision = precisionForGiB(m_totalRam);
+ const int availableRamPrecision = precisionForGiB(m_availableRam);
+
+ if (m_totalRam.has_value() && m_availableRam.has_value()) {
+ // Both known
+ const auto string = ki18nc("@label, %1 is the total amount of installed system memory, %2 is the amount of which is usable, both expressed as 7.7 GiB",
+ "%1 of RAM (%2 usable)")
+ .subs(KFormat(localeForLanguage(language)).formatByteSize(m_totalRam.value(), totalRamPrecision))
+ .subs(KFormat(localeForLanguage(language)).formatByteSize(m_availableRam.value(), availableRamPrecision));
+ return localize(string, language);
+ }
+
+ if (m_totalRam.has_value() && !m_availableRam.has_value()) {
+ // Known total, unknown available
+ const auto string = ki18nc("@label, %1 is the amount of installed system memory expressed as 7.7 GiB", "%1 of RAM")
+ .subs(KFormat(localeForLanguage(language)).formatByteSize(m_totalRam.value(), totalRamPrecision));
+ return localize(string, language);
+ }
+
+ if (!m_totalRam.has_value() && m_availableRam.has_value()) {
+ // Unknown total, known available
+ const auto string = ki18nc("@label, %1 is the amount of usable system memory expressed as 7.7 GiB", "%1 of usable RAM")
+ .subs(KFormat(localeForLanguage(language)).formatByteSize(m_availableRam.value(), availableRamPrecision));
return localize(string, language);
}
- return localize(ki18nc("Unknown amount of RAM", "Unknown"), language);
+
+ // Both unknown
+ return localize(ki18nc("@label, Unknown amount of system memory", "Unknown"), language);
+}
+
+QString MemoryEntry::localizedHelp(Language language) const
+{
+ if (m_totalRam.has_value() && m_availableRam.has_value()) {
+ // Both known
+ return localize(ki18nc("@info:tooltip, referring to system memory or RAM",
+ "Some memory is reserved for use by the kernel or system hardware such as integrated graphics memory."),
+ language);
+ }
+
+ if (m_totalRam.has_value() && !m_availableRam.has_value()) {
+ // Known total, unknown available
+ return localize(
+ ki18nc("@info:tooltip, referring to system memory or RAM",
+ "The amount of usable memory may be lower than the displayed amount because some memory is reserved for use by the kernel or system "
+ "hardware, such as integrated graphics memory."),
+ language);
+ }
+
+ if (!m_totalRam.has_value() && m_availableRam.has_value()) {
+ // Unknown total, known available
+ return localize(
+ ki18nc("@info:tooltip, referring to system memory or RAM",
+ "The amount of memory displayed may be lower than the installed amount because some memory is reserved for use by the kernel or system "
+ "hardware, such as integrated graphics memory."),
+ language);
+ }
+
+ // Both unknown
+ return QString();
}
diff --git a/kcms/about-distro/src/MemoryEntry.h b/kcms/about-distro/src/MemoryEntry.h
index 43beb2e87..d0757651f 100644
--- a/kcms/about-distro/src/MemoryEntry.h
+++ b/kcms/about-distro/src/MemoryEntry.h
@@ -12,10 +12,17 @@ class MemoryEntry : public Entry
{
public:
MemoryEntry();
- static qlonglong calculateTotalRam();
// Overwrite to get correct localization for the value.
QString localizedValue(Language language = Language::System) const final;
+ QString localizedHelp(Language language = Language::System) const final;
+
+private:
+ static std::optional<qlonglong> calculateTotalRam();
+ static std::optional<qlonglong> calculateAvailableRam();
+
+ std::optional<qlonglong> m_totalRam = calculateTotalRam();
+ std::optional<qlonglong> m_availableRam = calculateAvailableRam();
};
#endif // MEMORYENTRY_H
diff --git a/kcms/about-distro/src/ui/main.qml b/kcms/about-distro/src/ui/main.qml
index 80fbc2c13..e80b7fe93 100644
--- a/kcms/about-distro/src/ui/main.qml
+++ b/kcms/about-distro/src/ui/main.qml
@@ -167,6 +167,11 @@ KCMUtils.SimpleKCM {
}
}
+ Kirigami.ContextualHelpButton {
+ visible: toolTipText.length > 0
+ toolTipText: entry.localizedHelp()
+ }
+
QQC2.Button {
visible: hidden
property var dialog: null
--
GitLab
From fc2e540dc6f4784c2602a520f4b3285355213f5a Mon Sep 17 00:00:00 2001
From: Oliver Beard <olib141@outlook.com>
Date: Mon, 24 Feb 2025 23:17:48 +0000
Subject: [PATCH 2/2] kcms/about-distro: Clean-up and refactoring - Spacing
specified on RowLayout - Instead of specifying properties up-front for each
entry, entries use them as needed. - Use .length > 0 instead of !== "" -
[[nodiscard]] and Q_INVOKABLE specified on virtual Entry methods
---
kcms/about-distro/src/Entry.h | 8 +++---
kcms/about-distro/src/ui/main.qml | 42 +++++++++++++++----------------
2 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/kcms/about-distro/src/Entry.h b/kcms/about-distro/src/Entry.h
index bc053a4f4..3c7dd8491 100644
--- a/kcms/about-distro/src/Entry.h
+++ b/kcms/about-distro/src/Entry.h
@@ -66,20 +66,20 @@ public:
// Returns textual representation of entry.
QString diagnosticLine(Language language = Language::System) const;
- Q_SCRIPTABLE virtual QString localizedLabel(Language language = Language::System) const;
+ Q_INVOKABLE [[nodiscard]] virtual QString localizedLabel(Language language = Language::System) const;
// Returns the value by default. Needs to be overridden in subclasses if localization
// is needed for the value.
- Q_SCRIPTABLE virtual QString localizedValue(Language language = Language::System) const;
+ Q_INVOKABLE [[nodiscard]] virtual QString localizedValue(Language language = Language::System) const;
// Returns whether this Entry should be hidden by default (i.e. only shown upon user request)
- Q_INVOKABLE virtual bool isHidden() const;
+ Q_INVOKABLE [[nodiscard]] virtual bool isHidden() const;
// Returns a hint for the user to consider when interpreting the value.
Q_INVOKABLE [[nodiscard]] virtual Hint localizedHint(Language language = Language::System) const;
// Returns a help string for the entry, shown with a ContextualHelpButton
- Q_SCRIPTABLE [[nodiscard]] virtual QString localizedHelp(Language language = Language::System) const;
+ Q_INVOKABLE [[nodiscard]] virtual QString localizedHelp(Language language = Language::System) const;
protected:
// Returns localized QString for the given language.
diff --git a/kcms/about-distro/src/ui/main.qml b/kcms/about-distro/src/ui/main.qml
index e80b7fe93..547f4b665 100644
--- a/kcms/about-distro/src/ui/main.qml
+++ b/kcms/about-distro/src/ui/main.qml
@@ -54,14 +54,14 @@ KCMUtils.SimpleKCM {
}
Kirigami.Heading {
- visible: kcm.distroVariant !== ""
+ visible: kcm.distroVariant.length > 0
text: kcm.distroVariant
level: 2
type: Kirigami.Heading.Type.Secondary
}
QQC2.Label {
- visible: kcm.distroUrl !== ""
+ visible: kcm.distroUrl.length > 0
text: "<a href='%1'>%1</a>".arg(kcm.distroUrl)
textFormat: Text.RichText
onLinkActivated: link => Qt.openUrlExternally(link)
@@ -82,23 +82,11 @@ KCMUtils.SimpleKCM {
Kirigami.FormData.label: entry.localizedLabel()
Kirigami.FormData.labelAlignment: idealAlignment
Layout.alignment: idealAlignment
+
readonly property int idealAlignment: valueLabel.lineCount > 1 ? Qt.AlignTop : Qt.AlignVCenter // looks tidier this way
readonly property bool hidden: entry.isHidden()
- readonly property string hint: entry.localizedHint().text
- readonly property color hintColorForeground: {
- switch (entry.localizedHint().color) {
- case Private.Hint.Color.One: return Kirigami.Theme.linkColor
- case Private.Hint.Color.Two: return Kirigami.Theme.positiveTextColor
- case Private.Hint.Color.Three: return Kirigami.Theme.alternateTextColor
- }
- }
- readonly property color hintColorBackground: {
- switch (entry.localizedHint().color) {
- case Private.Hint.Color.One: return Kirigami.Theme.linkBackgroundColor
- case Private.Hint.Color.Two: return Kirigami.Theme.positiveBackgroundColor
- case Private.Hint.Color.Three: return Kirigami.Theme.alternateBackgroundColor
- }
- }
+
+ spacing: Kirigami.Units.smallSpacing
Component {
id: unhideDialog
@@ -138,7 +126,7 @@ KCMUtils.SimpleKCM {
QQC2.Label {
Kirigami.Theme.colorSet: Kirigami.Theme.Window
- visible: hint !== ""
+ visible: text.length > 0
// Vertical padding accounts for the difference in normal label height and the content height of this small label
readonly property real verticalPadding: (hintMetrics.height - contentHeight) / 2
@@ -156,13 +144,25 @@ KCMUtils.SimpleKCM {
leftPadding: horizontalPadding
rightPadding: horizontalPadding
- text: hint
- color: hintColorForeground
+ text: entry.localizedHint().text
+ color: {
+ switch (entry.localizedHint().color) {
+ case Private.Hint.Color.One: return Kirigami.Theme.linkColor
+ case Private.Hint.Color.Two: return Kirigami.Theme.positiveTextColor
+ case Private.Hint.Color.Three: return Kirigami.Theme.alternateTextColor
+ }
+ }
font.bold: true
font.pixelSize: Kirigami.Theme.smallFont.pixelSize
background: Rectangle {
- color: hintColorBackground
+ color: {
+ switch (entry.localizedHint().color) {
+ case Private.Hint.Color.One: return Kirigami.Theme.linkBackgroundColor
+ case Private.Hint.Color.Two: return Kirigami.Theme.positiveBackgroundColor
+ case Private.Hint.Color.Three: return Kirigami.Theme.alternateBackgroundColor
+ }
+ }
radius: Kirigami.Units.cornerRadius
}
}
--
GitLab

View file

@ -1,193 +0,0 @@
diff --git a/autotests/integration/lockscreen.cpp b/autotests/integration/lockscreen.cpp
index 8d3b5d1a72..4786617ca6 100644
--- a/autotests/integration/lockscreen.cpp
+++ b/autotests/integration/lockscreen.cpp
@@ -665,18 +665,18 @@ void LockScreenTest::testAxisShortcut()
// try to trigger the shortcut
quint32 timestamp = 1;
-#define PERFORM(expectedCount) \
- do { \
- Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++); \
- if (direction == Qt::Vertical) \
- Test::pointerAxisVertical(sign * 5.0, timestamp++); \
- else \
- Test::pointerAxisHorizontal(sign * 5.0, timestamp++); \
- QCoreApplication::instance()->processEvents(); \
- QCOMPARE(actionSpy.count(), expectedCount); \
- Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++); \
- QCoreApplication::instance()->processEvents(); \
- QCOMPARE(actionSpy.count(), expectedCount); \
+#define PERFORM(expectedCount) \
+ do { \
+ Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++); \
+ if (direction == Qt::Vertical) \
+ Test::pointerAxisVertical(sign * 15.0, timestamp++); \
+ else \
+ Test::pointerAxisHorizontal(sign * 15.0, timestamp++); \
+ QCoreApplication::instance()->processEvents(); \
+ QCOMPARE(actionSpy.count(), expectedCount); \
+ Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++); \
+ QCoreApplication::instance()->processEvents(); \
+ QCOMPARE(actionSpy.count(), expectedCount); \
} while (false)
PERFORM(1);
diff --git a/src/globalshortcuts.cpp b/src/globalshortcuts.cpp
index 5682e2a797..40b99d2018 100644
--- a/src/globalshortcuts.cpp
+++ b/src/globalshortcuts.cpp
@@ -240,17 +240,16 @@ bool GlobalShortcutsManager::processKeyRelease(Qt::KeyboardModifiers mods, int k
}
template<typename ShortcutKind, typename... Args>
-bool match(QList<GlobalShortcut> &shortcuts, Args... args)
+GlobalShortcut *match(QList<GlobalShortcut> &shortcuts, Args... args)
{
for (auto &sc : shortcuts) {
if (std::holds_alternative<ShortcutKind>(sc.shortcut())) {
if (std::get<ShortcutKind>(sc.shortcut()) == ShortcutKind{args...}) {
- sc.invoke();
- return true;
+ return &sc;
}
}
}
- return false;
+ return nullptr;
}
// TODO(C++20): use ranges for a nicer way of filtering by shortcut type
@@ -266,10 +265,14 @@ bool GlobalShortcutsManager::processPointerPressed(Qt::KeyboardModifiers mods, Q
Q_ARG(Qt::MouseButtons, pointerButtons));
}
#endif
- return match<PointerButtonShortcut>(m_shortcuts, mods, pointerButtons);
+ GlobalShortcut *shortcut = match<PointerButtonShortcut>(m_shortcuts, mods, pointerButtons);
+ if (shortcut) {
+ shortcut->invoke();
+ }
+ return shortcut != nullptr;
}
-bool GlobalShortcutsManager::processAxis(Qt::KeyboardModifiers mods, PointerAxisDirection axis)
+bool GlobalShortcutsManager::processAxis(Qt::KeyboardModifiers mods, PointerAxisDirection axis, qreal delta)
{
#if KWIN_BUILD_GLOBALSHORTCUTS
// currently only used to better support modifier only shortcuts
@@ -281,7 +284,11 @@ bool GlobalShortcutsManager::processAxis(Qt::KeyboardModifiers mods, PointerAxis
Q_ARG(int, axis));
}
#endif
- return match<PointerAxisShortcut>(m_shortcuts, mods, axis);
+ GlobalShortcut *shortcut = match<PointerAxisShortcut>(m_shortcuts, mods, axis);
+ if (shortcut && std::abs(delta) >= 1.0f) {
+ shortcut->invoke();
+ }
+ return shortcut != nullptr;
}
void GlobalShortcutsManager::processSwipeStart(DeviceType device, uint fingerCount)
diff --git a/src/globalshortcuts.h b/src/globalshortcuts.h
index 13c4239cae..4a2748cf39 100644
--- a/src/globalshortcuts.h
+++ b/src/globalshortcuts.h
@@ -98,7 +98,7 @@ public:
* @param axis The axis direction which has triggered this event
* @return @c true if a shortcut triggered, @c false otherwise
*/
- bool processAxis(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis);
+ bool processAxis(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, qreal delta);
void processSwipeStart(DeviceType device, uint fingerCount);
void processSwipeUpdate(DeviceType device, const QPointF &delta);
diff --git a/src/input.cpp b/src/input.cpp
index 52dd7be865..4bc5b7f719 100644
--- a/src/input.cpp
+++ b/src/input.cpp
@@ -976,6 +976,29 @@ private:
QMap<quint32, QPointF> m_touchPoints;
};
+class MouseWheelAccumulator
+{
+public:
+ qreal accumulate(PointerAxisEvent *event)
+ {
+ const qreal delta = event->deltaV120 != 0 ? event->deltaV120 / 120.0 : event->delta / 15.0;
+ if (std::signbit(m_scrollDistance) != std::signbit(delta)) {
+ m_scrollDistance = 0;
+ }
+ m_scrollDistance += delta;
+ if (std::abs(m_scrollDistance) >= 1.0) {
+ const qreal ret = m_scrollDistance;
+ m_scrollDistance = std::fmod(m_scrollDistance, 1.0f);
+ return ret - m_scrollDistance;
+ } else {
+ return 0;
+ }
+ }
+
+private:
+ qreal m_scrollDistance = 0;
+};
+
#if KWIN_BUILD_GLOBALSHORTCUTS
class GlobalShortcutFilter : public InputEventFilter
{
@@ -1008,15 +1031,15 @@ public:
} else if (event->delta > 0) {
direction = PointerAxisLeft;
}
+ return input()->shortcuts()->processAxis(event->modifiers, direction, m_horizontalAccumulator.accumulate(event));
} else {
if (event->delta < 0) {
direction = PointerAxisDown;
} else if (event->delta > 0) {
direction = PointerAxisUp;
}
+ return input()->shortcuts()->processAxis(event->modifiers, direction, m_verticalAccumulator.accumulate(event));
}
-
- return input()->shortcuts()->processAxis(event->modifiers, direction);
}
bool keyboardKey(KeyboardKeyEvent *event) override
{
@@ -1229,6 +1252,8 @@ private:
QPointF m_lastAverageDistance;
QMap<int32_t, QPointF> m_touchPoints;
int m_touchpadGestureFingerCount = 0;
+ MouseWheelAccumulator m_horizontalAccumulator;
+ MouseWheelAccumulator m_verticalAccumulator;
QTimer m_powerDown;
};
@@ -1515,28 +1540,6 @@ private:
QList<QWindowSystemInterface::TouchPoint> m_touchPoints;
};
-class MouseWheelAccumulator
-{
-public:
- float accumulate(PointerAxisEvent *event)
- {
- m_scrollV120 += event->deltaV120;
- m_scrollDistance += event->delta;
- if (std::abs(m_scrollV120) >= 120 || (!event->deltaV120 && std::abs(m_scrollDistance) >= 15)) {
- float ret = m_scrollDistance;
- m_scrollV120 = 0;
- m_scrollDistance = 0;
- return ret;
- } else {
- return 0;
- }
- }
-
-private:
- float m_scrollDistance = 0;
- int m_scrollV120 = 0;
-};
-
class DecorationEventFilter : public InputEventFilter
{
public:

View file

@ -1,151 +0,0 @@
diff --git a/autotests/integration/decoration_input_test.cpp b/autotests/integration/decoration_input_test.cpp
index 7390b34aab..61312a389b 100644
--- a/autotests/integration/decoration_input_test.cpp
+++ b/autotests/integration/decoration_input_test.cpp
@@ -655,9 +655,9 @@ void DecorationInputTest::testModifierScrollOpacity()
}
QFETCH(int, modifierKey);
Test::keyboardKeyPressed(modifierKey, timestamp++);
- Test::pointerAxisVertical(-5, timestamp++);
+ Test::pointerAxisVertical(-15, timestamp++);
QCOMPARE(window->opacity(), 0.6);
- Test::pointerAxisVertical(5, timestamp++);
+ Test::pointerAxisVertical(15, timestamp++);
QCOMPARE(window->opacity(), 0.5);
Test::keyboardKeyReleased(modifierKey, timestamp++);
if (capsLock) {
diff --git a/autotests/integration/internal_window.cpp b/autotests/integration/internal_window.cpp
index 338ad6eca9..8ebd191e9a 100644
--- a/autotests/integration/internal_window.cpp
+++ b/autotests/integration/internal_window.cpp
@@ -291,9 +291,9 @@ void InternalWindowTest::testPointerAxis()
quint32 timestamp = 1;
Test::pointerMotion(QPoint(50, 50), timestamp++);
- Test::pointerAxisVertical(5.0, timestamp++);
+ Test::pointerAxisVertical(15.0, timestamp++);
QTRY_COMPARE(wheelSpy.count(), 1);
- Test::pointerAxisHorizontal(5.0, timestamp++);
+ Test::pointerAxisHorizontal(15.0, timestamp++);
QTRY_COMPARE(wheelSpy.count(), 2);
}
@@ -465,9 +465,9 @@ void InternalWindowTest::testModifierScroll()
QCOMPARE(internalWindow->opacity(), 0.5);
quint32 timestamp = 1;
Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
- Test::pointerAxisVertical(-5, timestamp++);
+ Test::pointerAxisVertical(-15, timestamp++);
QCOMPARE(internalWindow->opacity(), 0.6);
- Test::pointerAxisVertical(5, timestamp++);
+ Test::pointerAxisVertical(15, timestamp++);
QCOMPARE(internalWindow->opacity(), 0.5);
Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++);
}
diff --git a/autotests/integration/lockscreen.cpp b/autotests/integration/lockscreen.cpp
index 8d3b5d1a72..62fe990550 100644
--- a/autotests/integration/lockscreen.cpp
+++ b/autotests/integration/lockscreen.cpp
@@ -339,7 +339,7 @@ void LockScreenTest::testPointerAxis()
// and simulate axis
Test::pointerAxisHorizontal(5.0, timestamp++);
QVERIFY(!axisChangedSpy.wait(10));
- Test::pointerAxisVertical(5.0, timestamp++);
+ Test::pointerAxisVertical(15.0, timestamp++);
QVERIFY(!axisChangedSpy.wait(10));
// and unlock
@@ -348,9 +348,9 @@ void LockScreenTest::testPointerAxis()
QCOMPARE(enteredSpy.count(), 2);
// and move axis again
- Test::pointerAxisHorizontal(5.0, timestamp++);
+ Test::pointerAxisHorizontal(15.0, timestamp++);
QVERIFY(axisChangedSpy.wait());
- Test::pointerAxisVertical(5.0, timestamp++);
+ Test::pointerAxisVertical(15.0, timestamp++);
QVERIFY(axisChangedSpy.wait());
}
diff --git a/autotests/integration/no_global_shortcuts_test.cpp b/autotests/integration/no_global_shortcuts_test.cpp
index 5e5ea1676b..65add952ea 100644
--- a/autotests/integration/no_global_shortcuts_test.cpp
+++ b/autotests/integration/no_global_shortcuts_test.cpp
@@ -177,9 +177,9 @@ void NoGlobalShortcutsTest::testAxisShortcut()
quint32 timestamp = 1;
Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
if (direction == Qt::Vertical) {
- Test::pointerAxisVertical(sign * 5.0, timestamp++);
+ Test::pointerAxisVertical(sign * 15.0, timestamp++);
} else {
- Test::pointerAxisHorizontal(sign * 5.0, timestamp++);
+ Test::pointerAxisHorizontal(sign * 15.0, timestamp++);
}
QCoreApplication::instance()->processEvents();
QCOMPARE(actionSpy.count(), 0);
diff --git a/autotests/integration/pointer_constraints_test.cpp b/autotests/integration/pointer_constraints_test.cpp
index 06ab277863..497bb5ac73 100644
--- a/autotests/integration/pointer_constraints_test.cpp
+++ b/autotests/integration/pointer_constraints_test.cpp
@@ -189,9 +189,9 @@ void TestPointerConstraints::testConfinedPointer()
QCOMPARE(window->opacity(), 0.5);
// pointer is confined so shortcut should not work
- Test::pointerAxisVertical(-5, timestamp++);
+ Test::pointerAxisVertical(-15, timestamp++);
QCOMPARE(window->opacity(), 0.5);
- Test::pointerAxisVertical(5, timestamp++);
+ Test::pointerAxisVertical(15, timestamp++);
QCOMPARE(window->opacity(), 0.5);
Test::keyboardKeyReleased(KEY_LEFTALT, timestamp++);
diff --git a/autotests/integration/pointer_input.cpp b/autotests/integration/pointer_input.cpp
index f444471562..12c8c5736b 100644
--- a/autotests/integration/pointer_input.cpp
+++ b/autotests/integration/pointer_input.cpp
@@ -695,9 +695,9 @@ void PointerInputTest::testModifierScrollOpacity()
}
QFETCH(int, modifierKey);
Test::keyboardKeyPressed(modifierKey, timestamp++);
- Test::pointerAxisVertical(-5, timestamp++);
+ Test::pointerAxisVertical(-15, timestamp++);
QCOMPARE(window->opacity(), 0.6);
- Test::pointerAxisVertical(5, timestamp++);
+ Test::pointerAxisVertical(15, timestamp++);
QCOMPARE(window->opacity(), 0.5);
Test::keyboardKeyReleased(modifierKey, timestamp++);
if (capsLock) {
@@ -753,9 +753,9 @@ void PointerInputTest::testModifierScrollOpacityGlobalShortcutsDisabled()
// simulate modifier+wheel
quint32 timestamp = 1;
Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
- Test::pointerAxisVertical(-5, timestamp++);
+ Test::pointerAxisVertical(-15, timestamp++);
QCOMPARE(window->opacity(), 0.5);
- Test::pointerAxisVertical(5, timestamp++);
+ Test::pointerAxisVertical(15, timestamp++);
QCOMPARE(window->opacity(), 0.5);
Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++);
@@ -800,7 +800,7 @@ void PointerInputTest::testScrollAction()
quint32 timestamp = 1;
QVERIFY(!window1->isActive());
- Test::pointerAxisVertical(5, timestamp++);
+ Test::pointerAxisVertical(15, timestamp++);
QVERIFY(window1->isActive());
// but also the wheel event should be passed to the window
diff --git a/autotests/integration/touch_input_test.cpp b/autotests/integration/touch_input_test.cpp
index 8f739ff2a5..df68e1b47e 100644
--- a/autotests/integration/touch_input_test.cpp
+++ b/autotests/integration/touch_input_test.cpp
@@ -146,7 +146,7 @@ void TouchInputTest::testTouchHidesCursor()
QCOMPARE(Cursors::self()->isCursorHidden(), true);
// wheel should also show
- Test::pointerAxisVertical(1.0, timestamp++);
+ Test::pointerAxisVertical(15.0, timestamp++);
QCOMPARE(Cursors::self()->isCursorHidden(), false);
}

View file

@ -1,61 +0,0 @@
From 2022febc84989dba04a4677f3c187a057dece522 Mon Sep 17 00:00:00 2001
From: Aleix Pol <aleixpol@kde.org>
Date: Fri, 4 Apr 2025 00:59:29 +0200
Subject: [PATCH] screenedge: Hardcode the cornerOffset value
At the moment we were using fonts to calculate it which would slow us
down at startup for little pay-off.
We were using visual metrics for a touch scaling which is wrong so let's
just hardcode a value.
On my system (running default fonts) gridUnit was 9 and thus was
resulting on 36, rounded up to 40.
---
src/screenedge.cpp | 9 +--------
src/screenedge.h | 2 +-
2 files changed, 2 insertions(+), 9 deletions(-)
diff --git a/src/screenedge.cpp b/src/screenedge.cpp
index adbac936f20..fb42ecc9330 100644
--- a/src/screenedge.cpp
+++ b/src/screenedge.cpp
@@ -42,12 +42,6 @@
#include <QAbstractEventDispatcher>
#include <QAction>
#include <QDBusInterface>
-#include <QDBusPendingCall>
-#include <QFontDatabase>
-#include <QFontMetrics>
-#include <QTextStream>
-#include <QTimer>
-#include <QWidget>
#include <span>
using namespace std::chrono_literals;
@@ -766,10 +760,9 @@ ScreenEdges::ScreenEdges()
, m_actionBottom(ElectricActionNone)
, m_actionBottomLeft(ElectricActionNone)
, m_actionLeft(ElectricActionNone)
+ , m_cornerOffset(40)
, m_gestureRecognizer(new GestureRecognizer(this))
{
- const int gridUnit = QFontMetrics(QFontDatabase::systemFont(QFontDatabase::GeneralFont)).boundingRect(QLatin1Char('M')).height();
- m_cornerOffset = 4 * gridUnit;
}
void ScreenEdges::init()
diff --git a/src/screenedge.h b/src/screenedge.h
index b208edf3c98..8417f2aee57 100644
--- a/src/screenedge.h
+++ b/src/screenedge.h
@@ -388,7 +388,7 @@ private:
ElectricBorderAction m_actionBottomLeft;
ElectricBorderAction m_actionLeft;
QMap<ElectricBorder, ElectricBorderAction> m_touchCallbacks;
- int m_cornerOffset;
+ const int m_cornerOffset;
GestureRecognizer *m_gestureRecognizer;
bool m_remainActiveOnFullscreen = false;
};
--
GitLab

File diff suppressed because it is too large Load diff