linux: minor improvements

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-04-17 18:30:16 +08:00
parent 45ebbee471
commit bb42c69d36
10 changed files with 43 additions and 29 deletions

View File

@ -26,7 +26,7 @@
#include "framelesshelperwidgets_global.h" #include "framelesshelperwidgets_global.h"
#include <QtCore/qobject.h> #include <QtCore/qobject.h>
#include <QtGui/qwindowdefs.h> #include <QtGui/qwindow.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QLabel; class QLabel;

View File

@ -22,6 +22,11 @@
SOFTWARE. SOFTWARE.
]] ]]
if(UNIX AND NOT APPLE)
find_package(GTK3 REQUIRED)
find_package(X11 REQUIRED)
endif()
set(SUB_PROJ_NAME FramelessHelperCore) set(SUB_PROJ_NAME FramelessHelperCore)
set(INCLUDE_PREFIX ../../include/FramelessHelper/Core) set(INCLUDE_PREFIX ../../include/FramelessHelper/Core)
@ -102,6 +107,19 @@ else()
) )
endif() 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 target_link_libraries(${SUB_PROJ_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::CorePrivate Qt${QT_VERSION_MAJOR}::CorePrivate
Qt${QT_VERSION_MAJOR}::GuiPrivate Qt${QT_VERSION_MAJOR}::GuiPrivate

View File

@ -33,7 +33,7 @@
#if ((QT_VERSION >= QT_VERSION_CHECK(5, 9, 1)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))) #if ((QT_VERSION >= QT_VERSION_CHECK(5, 9, 1)) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
# include <QtPlatformHeaders/qxcbscreenfunctions.h> # include <QtPlatformHeaders/qxcbscreenfunctions.h>
#endif #endif
//#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
FRAMELESSHELPER_BEGIN_NAMESPACE 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; static constexpr const auto _NET_WM_MOVERESIZE_MOVE = 8;
#endif #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(display)
FRAMELESSHELPER_BYTEARRAY_CONSTANT(x11screen) FRAMELESSHELPER_BYTEARRAY_CONSTANT(x11screen)
FRAMELESSHELPER_BYTEARRAY_CONSTANT(rootwindow) FRAMELESSHELPER_BYTEARRAY_CONSTANT(rootwindow)
#if 0 FRAMELESSHELPER_STRING_CONSTANT2(GTK_THEME_DARK_REGEX, "[:-]dark")
template<typename T> template<typename T>
[[nodiscard]] static inline T gtkSetting(const gchar *propertyName) [[nodiscard]] static inline T gtkSetting(const gchar *propertyName)
{ {
@ -80,12 +85,11 @@ template<typename T>
if (!propertyName) { if (!propertyName) {
return {}; return {};
} }
const auto value = gtkSetting<gchararray>(propertyName); const auto propertyValue = gtkSetting<gchararray>(propertyName);
const QString result = QString::fromUtf8(value); const QString result = QString::fromUtf8(propertyValue);
g_free(value); g_free(propertyValue);
return result; return result;
} }
#endif
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
[[nodiscard]] static inline Qt::WindowFrameSection qtEdgesToQtWindowFrameSection(const Qt::Edges edges) [[nodiscard]] static inline Qt::WindowFrameSection qtEdgesToQtWindowFrameSection(const Qt::Edges edges)
@ -123,7 +127,6 @@ template<typename T>
[[nodiscard]] bool shouldAppsUseDarkMode_linux() [[nodiscard]] bool shouldAppsUseDarkMode_linux()
{ {
#if 0
/* /*
https://docs.gtk.org/gtk3/running.html https://docs.gtk.org/gtk3/running.html
@ -137,10 +140,10 @@ template<typename T>
it's mainly used for easy debugging, so it should be possible to use it it's mainly used for easy debugging, so it should be possible to use it
to override any other settings. to override any other settings.
*/ */
QString themeName = qEnvironmentVariable("GTK_THEME"); static const QRegularExpression darkRegex(kGTK_THEME_DARK_REGEX, QRegularExpression::CaseInsensitiveOption);
const QRegularExpression darkRegex(QStringLiteral("[:-]dark"), QRegularExpression::CaseInsensitiveOption); const QString envThemeName = qEnvironmentVariable(GTK_THEME_NAME_ENV_VAR);
if (!themeName.isEmpty()) { if (!envThemeName.isEmpty()) {
return darkRegex.match(themeName).hasMatch(); return darkRegex.match(envThemeName).hasMatch();
} }
/* /*
@ -150,7 +153,7 @@ template<typename T>
gtk-theme-name provides both light and dark variants. We can save a gtk-theme-name provides both light and dark variants. We can save a
regex check by testing this property first. regex check by testing this property first.
*/ */
const auto preferDark = gtkSetting<bool>("gtk-application-prefer-dark-theme"); const auto preferDark = gtkSetting<bool>(GTK_THEME_PREFER_DARK_PROP);
if (preferDark) { if (preferDark) {
return true; return true;
} }
@ -158,15 +161,12 @@ template<typename T>
/* /*
https://docs.gtk.org/gtk3/property.Settings.gtk-theme-name.html https://docs.gtk.org/gtk3/property.Settings.gtk-theme-name.html
*/ */
themeName = gtkSetting("gtk-theme-name"); const QString curThemeName = gtkSetting(GTK_THEME_NAME_PROP);
if (!themeName.isEmpty()) { if (!curThemeName.isEmpty()) {
return darkRegex.match(themeName).hasMatch(); return darkRegex.match(curThemeName).hasMatch();
} }
return false; return false;
#else
return false;
#endif
} }
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))

View File

@ -29,7 +29,6 @@
#include <QtQuick/private/qquickimage_p.h> #include <QtQuick/private/qquickimage_p.h>
#include <QtQuick/private/qquickrectangle_p.h> #include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickanchors_p.h> #include <QtQuick/private/qquickanchors_p.h>
#include <QtQuickTemplates2/private/qquicktooltip_p.h>
static inline void initResource() static inline void initResource()
{ {

View File

@ -24,13 +24,13 @@
#pragma once #pragma once
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#include "framelesshelperquick_global.h" #include "framelesshelperquick_global.h"
#include <QtQuickTemplates2/private/qquicktooltip_p.h>
#include <QtQuickTemplates2/private/qquickbutton_p.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QQuickImage; class QQuickImage;
class QQuickRectangle; class QQuickRectangle;
class QQuickToolTipAttached;
QT_END_NAMESPACE QT_END_NAMESPACE
FRAMELESSHELPER_BEGIN_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE

View File

@ -29,7 +29,6 @@
#include <QtQuick/private/qquickimage_p.h> #include <QtQuick/private/qquickimage_p.h>
#include <QtQuick/private/qquickrectangle_p.h> #include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickanchors_p.h> #include <QtQuick/private/qquickanchors_p.h>
#include <QtQuickTemplates2/private/qquicktooltip_p.h>
static inline void initResource() static inline void initResource()
{ {

View File

@ -24,13 +24,13 @@
#pragma once #pragma once
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#include "framelesshelperquick_global.h" #include "framelesshelperquick_global.h"
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#include <QtQuickTemplates2/private/qquicktooltip_p.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QQuickImage; class QQuickImage;
class QQuickRectangle; class QQuickRectangle;
class QQuickToolTipAttached;
QT_END_NAMESPACE QT_END_NAMESPACE
FRAMELESSHELPER_BEGIN_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE

View File

@ -29,7 +29,6 @@
#include <QtQuick/private/qquickimage_p.h> #include <QtQuick/private/qquickimage_p.h>
#include <QtQuick/private/qquickrectangle_p.h> #include <QtQuick/private/qquickrectangle_p.h>
#include <QtQuick/private/qquickanchors_p.h> #include <QtQuick/private/qquickanchors_p.h>
#include <QtQuickTemplates2/private/qquicktooltip_p.h>
static inline void initResource() static inline void initResource()
{ {

View File

@ -24,13 +24,13 @@
#pragma once #pragma once
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#include "framelesshelperquick_global.h" #include "framelesshelperquick_global.h"
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#include <QtQuickTemplates2/private/qquicktooltip_p.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QQuickImage; class QQuickImage;
class QQuickRectangle; class QQuickRectangle;
class QQuickToolTipAttached;
QT_END_NAMESPACE QT_END_NAMESPACE
FRAMELESSHELPER_BEGIN_NAMESPACE FRAMELESSHELPER_BEGIN_NAMESPACE

View File

@ -27,7 +27,6 @@
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
#include <QtGui/qpainter.h> #include <QtGui/qpainter.h>
#include <QtGui/qevent.h> #include <QtGui/qevent.h>
#include <QtGui/qwindow.h>
#include <QtWidgets/qboxlayout.h> #include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qlabel.h> #include <QtWidgets/qlabel.h>
#include <framelesswindowsmanager.h> #include <framelesswindowsmanager.h>