diff --git a/autotests/libkwineffects/CMakeLists.txt b/autotests/libkwineffects/CMakeLists.txt index e91ef57923..6c7868e3f8 100644 --- a/autotests/libkwineffects/CMakeLists.txt +++ b/autotests/libkwineffects/CMakeLists.txt @@ -14,7 +14,7 @@ kwineffects_unit_tests( timelinetest ) -add_executable(kwinglplatformtest kwinglplatformtest.cpp mock_gl.cpp ../../src/libkwineffects/glplatform.cpp ../../src/libkwineffects/openglcontext.cpp) +add_executable(kwinglplatformtest kwinglplatformtest.cpp mock_gl.cpp ../../src/libkwineffects/glplatform.cpp ../../src/libkwineffects/openglcontext.cpp ../../src/libkwineffects/version.cpp) add_test(NAME kwineffects-kwinglplatformtest COMMAND kwinglplatformtest) target_link_libraries(kwinglplatformtest Qt::Test Qt::Gui KF6::ConfigCore XCB::XCB) ecm_mark_as_test(kwinglplatformtest) diff --git a/src/libkwineffects/CMakeLists.txt b/src/libkwineffects/CMakeLists.txt index 4bac5f8308..f13aeee9eb 100644 --- a/src/libkwineffects/CMakeLists.txt +++ b/src/libkwineffects/CMakeLists.txt @@ -56,6 +56,7 @@ set(kwin_GLUTILSLIB_SRCS openglcontext.cpp rendertarget.cpp renderviewport.cpp + version.cpp ) add_library(kwinglutils SHARED ${kwin_GLUTILSLIB_SRCS}) diff --git a/src/libkwineffects/openglcontext.cpp b/src/libkwineffects/openglcontext.cpp index cc3f8d19ff..2b7fbf4104 100644 --- a/src/libkwineffects/openglcontext.cpp +++ b/src/libkwineffects/openglcontext.cpp @@ -16,75 +16,6 @@ namespace KWin { -Version::Version(uint32_t major, uint32_t minor, uint32_t patch) - : m_major(major) - , m_minor(minor) - , m_patch(patch) -{ -} - -int Version::operator<=>(const Version &other) const -{ - if (m_major != other.m_major) { - return m_major - other.m_major; - } - if (m_minor != other.m_minor) { - return m_minor - other.m_minor; - } - return m_patch - other.m_patch; -} - -bool Version::operator==(const Version &other) const -{ - return other.major() == major() && other.minor() == minor() && other.patch() == patch(); -} - -bool Version::isValid() const -{ - return m_major > 0 || m_minor > 0 || m_patch > 0; -} - -uint32_t Version::major() const -{ - return m_major; -} - -uint32_t Version::minor() const -{ - return m_minor; -} - -uint32_t Version::patch() const -{ - return m_patch; -} - -Version Version::parseString(QByteArrayView versionString) -{ - // Skip any leading non digit - int start = 0; - while (start < versionString.length() && !QChar::fromLatin1(versionString[start]).isDigit()) { - start++; - } - - // Strip any non digit, non '.' characters from the end - int end = start; - while (end < versionString.length() && (versionString[end] == '.' || QChar::fromLatin1(versionString[end]).isDigit())) { - end++; - } - - const QByteArray result = versionString.toByteArray().mid(start, end - start); - const QList tokens = result.split('.'); - if (tokens.empty()) { - return Version(0, 0, 0); - } - const uint64_t major = tokens.at(0).toInt(); - const uint64_t minor = tokens.count() > 1 ? tokens.at(1).toInt() : 0; - const uint64_t patch = tokens.count() > 2 ? tokens.at(2).toInt() : 0; - - return Version(major, minor, patch); -} - static QSet getExtensions(OpenGlContext *context) { QSet ret; diff --git a/src/libkwineffects/openglcontext.h b/src/libkwineffects/openglcontext.h index 30af84f624..9e92a7f03b 100644 --- a/src/libkwineffects/openglcontext.h +++ b/src/libkwineffects/openglcontext.h @@ -8,6 +8,7 @@ */ #pragma once #include "libkwineffects/kwinglutils_export.h" +#include "version.h" #include #include @@ -18,27 +19,6 @@ namespace KWin { -class KWINGLUTILS_EXPORT Version -{ -public: - Version(uint32_t major, uint32_t minor, uint32_t patch = 0); - Version() = default; - - int operator<=>(const Version &other) const; - bool operator==(const Version &other) const; - bool isValid() const; - uint32_t major() const; - uint32_t minor() const; - uint32_t patch() const; - - static Version parseString(QByteArrayView versionString); - -private: - uint32_t m_major = 0; - uint32_t m_minor = 0; - uint32_t m_patch = 0; -}; - class KWINGLUTILS_EXPORT OpenGlContext { public: diff --git a/src/libkwineffects/version.cpp b/src/libkwineffects/version.cpp new file mode 100644 index 0000000000..2ad45cd56e --- /dev/null +++ b/src/libkwineffects/version.cpp @@ -0,0 +1,71 @@ +/* + KWin - the KDE window manager + This file is part of the KDE project. + + SPDX-FileCopyrightText: 2023 Xaver Hugl + + SPDX-License-Identifier: GPL-2.0-or-later +*/ +#include "version.h" + +#include +#include +#include + +namespace KWin +{ + +Version::Version(uint32_t major, uint32_t minor, uint32_t patch) + : m_major(major) + , m_minor(minor) + , m_patch(patch) +{ +} + +bool Version::isValid() const +{ + return m_major > 0 || m_minor > 0 || m_patch > 0; +} + +uint32_t Version::major() const +{ + return m_major; +} + +uint32_t Version::minor() const +{ + return m_minor; +} + +uint32_t Version::patch() const +{ + return m_patch; +} + +Version Version::parseString(QByteArrayView versionString) +{ + // Skip any leading non digit + int start = 0; + while (start < versionString.length() && !QChar::fromLatin1(versionString[start]).isDigit()) { + start++; + } + + // Strip any non digit, non '.' characters from the end + int end = start; + while (end < versionString.length() && (versionString[end] == '.' || QChar::fromLatin1(versionString[end]).isDigit())) { + end++; + } + + const QByteArray result = versionString.toByteArray().mid(start, end - start); + const QList tokens = result.split('.'); + if (tokens.empty()) { + return Version(0, 0, 0); + } + const uint64_t major = tokens.at(0).toInt(); + const uint64_t minor = tokens.count() > 1 ? tokens.at(1).toInt() : 0; + const uint64_t patch = tokens.count() > 2 ? tokens.at(2).toInt() : 0; + + return Version(major, minor, patch); +} + +} diff --git a/src/libkwineffects/version.h b/src/libkwineffects/version.h new file mode 100644 index 0000000000..78b883b1b9 --- /dev/null +++ b/src/libkwineffects/version.h @@ -0,0 +1,37 @@ +/* + KWin - the KDE window manager + This file is part of the KDE project. + + SPDX-FileCopyrightText: 2023 Xaver Hugl + + SPDX-License-Identifier: GPL-2.0-or-later +*/ +#pragma once +#include "libkwineffects/kwinglutils_export.h" + +#include + +namespace KWin +{ + +class KWINGLUTILS_EXPORT Version +{ +public: + Version(uint32_t major, uint32_t minor, uint32_t patch = 0); + Version() = default; + + auto operator<=>(const Version &other) const = default; + bool isValid() const; + uint32_t major() const; + uint32_t minor() const; + uint32_t patch() const; + + static Version parseString(QByteArrayView versionString); + +private: + uint32_t m_major = 0; + uint32_t m_minor = 0; + uint32_t m_patch = 0; +}; + +}