diff --git a/include/FramelessHelper/Widgets/framelesswidgetshelper.h b/include/FramelessHelper/Widgets/framelesswidgetshelper.h index c155a81..57d3868 100644 --- a/include/FramelessHelper/Widgets/framelesswidgetshelper.h +++ b/include/FramelessHelper/Widgets/framelesswidgetshelper.h @@ -26,7 +26,7 @@ #include "framelesshelperwidgets_global.h" #include -#include +#include QT_BEGIN_NAMESPACE class QLabel; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 4cb03a7..2190126 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -22,6 +22,11 @@ SOFTWARE. ]] +if(UNIX AND NOT APPLE) + find_package(GTK3 REQUIRED) + find_package(X11 REQUIRED) +endif() + set(SUB_PROJ_NAME FramelessHelperCore) set(INCLUDE_PREFIX ../../include/FramelessHelper/Core) @@ -102,6 +107,19 @@ else() ) endif() +if(UNIX AND NOT APPLE) + target_compile_definitions(${SUB_PROJ_NAME} PRIVATE + GDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_6 + ) + target_link_libraries(${SUB_PROJ_NAME} PRIVATE + PkgConfig::GTK3 + X11::X11 + ) + target_include_directories(${SUB_PROJ_NAME} PRIVATE + "/usr/include/harfbuzz" # GCC complains about can't find "hb.h". Why do we need this? + ) +endif() + target_link_libraries(${SUB_PROJ_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::CorePrivate Qt${QT_VERSION_MAJOR}::GuiPrivate diff --git a/src/core/utils_linux.cpp b/src/core/utils_linux.cpp index bfd034e..21726e1 100644 --- a/src/core/utils_linux.cpp +++ b/src/core/utils_linux.cpp @@ -33,7 +33,7 @@ #if ((QT_VERSION >= QT_VERSION_CHECK(5, 9, 1)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))) # include #endif -//#include +#include #include FRAMELESSHELPER_BEGIN_NAMESPACE @@ -52,11 +52,16 @@ static constexpr const auto _NET_WM_MOVERESIZE_SIZE_LEFT = 7; static constexpr const auto _NET_WM_MOVERESIZE_MOVE = 8; #endif +static constexpr const char GTK_THEME_NAME_ENV_VAR[] = "GTK_THEME"; +static constexpr const char GTK_THEME_NAME_PROP[] = "gtk-theme-name"; +static constexpr const char GTK_THEME_PREFER_DARK_PROP[] = "gtk-application-prefer-dark-theme"; + FRAMELESSHELPER_BYTEARRAY_CONSTANT(display) FRAMELESSHELPER_BYTEARRAY_CONSTANT(x11screen) FRAMELESSHELPER_BYTEARRAY_CONSTANT(rootwindow) -#if 0 +FRAMELESSHELPER_STRING_CONSTANT2(GTK_THEME_DARK_REGEX, "[:-]dark") + template [[nodiscard]] static inline T gtkSetting(const gchar *propertyName) { @@ -80,12 +85,11 @@ template if (!propertyName) { return {}; } - const auto value = gtkSetting(propertyName); - const QString result = QString::fromUtf8(value); - g_free(value); + const auto propertyValue = gtkSetting(propertyName); + const QString result = QString::fromUtf8(propertyValue); + g_free(propertyValue); return result; } -#endif #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) [[nodiscard]] static inline Qt::WindowFrameSection qtEdgesToQtWindowFrameSection(const Qt::Edges edges) @@ -123,7 +127,6 @@ template [[nodiscard]] bool shouldAppsUseDarkMode_linux() { -#if 0 /* https://docs.gtk.org/gtk3/running.html @@ -137,10 +140,10 @@ template it's mainly used for easy debugging, so it should be possible to use it to override any other settings. */ - QString themeName = qEnvironmentVariable("GTK_THEME"); - const QRegularExpression darkRegex(QStringLiteral("[:-]dark"), QRegularExpression::CaseInsensitiveOption); - if (!themeName.isEmpty()) { - return darkRegex.match(themeName).hasMatch(); + static const QRegularExpression darkRegex(kGTK_THEME_DARK_REGEX, QRegularExpression::CaseInsensitiveOption); + const QString envThemeName = qEnvironmentVariable(GTK_THEME_NAME_ENV_VAR); + if (!envThemeName.isEmpty()) { + return darkRegex.match(envThemeName).hasMatch(); } /* @@ -150,7 +153,7 @@ template gtk-theme-name provides both light and dark variants. We can save a regex check by testing this property first. */ - const auto preferDark = gtkSetting("gtk-application-prefer-dark-theme"); + const auto preferDark = gtkSetting(GTK_THEME_PREFER_DARK_PROP); if (preferDark) { return true; } @@ -158,15 +161,12 @@ template /* https://docs.gtk.org/gtk3/property.Settings.gtk-theme-name.html */ - themeName = gtkSetting("gtk-theme-name"); - if (!themeName.isEmpty()) { - return darkRegex.match(themeName).hasMatch(); + const QString curThemeName = gtkSetting(GTK_THEME_NAME_PROP); + if (!curThemeName.isEmpty()) { + return darkRegex.match(curThemeName).hasMatch(); } return false; -#else - return false; -#endif } #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) diff --git a/src/quick/quickstandardclosebutton.cpp b/src/quick/quickstandardclosebutton.cpp index 56dcafe..e23f70b 100644 --- a/src/quick/quickstandardclosebutton.cpp +++ b/src/quick/quickstandardclosebutton.cpp @@ -29,7 +29,6 @@ #include #include #include -#include static inline void initResource() { diff --git a/src/quick/quickstandardclosebutton_p.h b/src/quick/quickstandardclosebutton_p.h index 875b509..b37b40e 100644 --- a/src/quick/quickstandardclosebutton_p.h +++ b/src/quick/quickstandardclosebutton_p.h @@ -24,13 +24,13 @@ #pragma once -#include #include "framelesshelperquick_global.h" +#include +#include QT_BEGIN_NAMESPACE class QQuickImage; class QQuickRectangle; -class QQuickToolTipAttached; QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE diff --git a/src/quick/quickstandardmaximizebutton.cpp b/src/quick/quickstandardmaximizebutton.cpp index 7446901..c0ffce4 100644 --- a/src/quick/quickstandardmaximizebutton.cpp +++ b/src/quick/quickstandardmaximizebutton.cpp @@ -29,7 +29,6 @@ #include #include #include -#include static inline void initResource() { diff --git a/src/quick/quickstandardmaximizebutton_p.h b/src/quick/quickstandardmaximizebutton_p.h index 85865a3..d256dfc 100644 --- a/src/quick/quickstandardmaximizebutton_p.h +++ b/src/quick/quickstandardmaximizebutton_p.h @@ -24,13 +24,13 @@ #pragma once -#include #include "framelesshelperquick_global.h" +#include +#include QT_BEGIN_NAMESPACE class QQuickImage; class QQuickRectangle; -class QQuickToolTipAttached; QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE diff --git a/src/quick/quickstandardminimizebutton.cpp b/src/quick/quickstandardminimizebutton.cpp index 98c92a1..9b5885f 100644 --- a/src/quick/quickstandardminimizebutton.cpp +++ b/src/quick/quickstandardminimizebutton.cpp @@ -29,7 +29,6 @@ #include #include #include -#include static inline void initResource() { diff --git a/src/quick/quickstandardminimizebutton_p.h b/src/quick/quickstandardminimizebutton_p.h index 6a7c609..17dee5a 100644 --- a/src/quick/quickstandardminimizebutton_p.h +++ b/src/quick/quickstandardminimizebutton_p.h @@ -24,13 +24,13 @@ #pragma once -#include #include "framelesshelperquick_global.h" +#include +#include QT_BEGIN_NAMESPACE class QQuickImage; class QQuickRectangle; -class QQuickToolTipAttached; QT_END_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index 76c78bd..d8798c2 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include