Skip to content

Commit f75a948

Browse files
committed
Merge branch 'master' into 0.8
2 parents d482a4b + f296642 commit f75a948

12 files changed

+293
-138
lines changed

.github/workflows/build.yml

+42-8
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,66 @@ env:
1212
BUILD_TYPE: Release
1313

1414
jobs:
15-
build:
16-
runs-on: ubuntu-20.04
15+
Linux_Qt5:
16+
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v2
1919

2020
- name: Install base dependencies
2121
run: |
2222
sudo apt update
23-
sudo apt install cmake make pkg-config libx11-dev xcb libx11-xcb-dev libgtk-3-dev
24-
23+
sudo apt install cmake make pkg-config libx11-dev xcb libx11-xcb-dev libxkbcommon-dev libgtk-3-dev sassc
24+
2525
- name: Install Qt
2626
uses: jurplel/install-qt-action@v2
27+
with:
28+
version: 5.15.2
2729

2830
- name: Install Adwaita-qt
2931
run: |
3032
git clone https://github.com/FedoraQt/adwaita-qt.git adwaita-qt
3133
cd adwaita-qt
3234
mkdir build
3335
cd build
34-
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
35-
make -j5
36+
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT6=OFF
37+
make -j2
3638
sudo make install
3739
3840
- name: Build
3941
run: |
4042
mkdir build
4143
cd build
42-
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
43-
make -j5
44+
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT6=OFF
45+
make -j2
46+
47+
Linux_Qt6:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v2
51+
52+
- name: Install base dependencies
53+
run: |
54+
sudo apt update
55+
sudo apt install cmake make pkg-config libx11-dev xcb libx11-xcb-dev libxkbcommon-dev libgtk-3-dev sassc
56+
57+
- name: Install Qt
58+
uses: jurplel/install-qt-action@v2
59+
with:
60+
version: 6.2.0
61+
62+
- name: Install Adwaita-qt
63+
run: |
64+
git clone https://github.com/FedoraQt/adwaita-qt.git adwaita-qt
65+
cd adwaita-qt
66+
mkdir build
67+
cd build
68+
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT6=ON
69+
make -j2
70+
sudo make install
71+
72+
- name: Build
73+
run: |
74+
mkdir build
75+
cd build
76+
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT6=ON
77+
make -j2

CMakeLists.txt

+49-17
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,53 @@ project(QGnomePlatform)
22

33
cmake_minimum_required(VERSION 3.0)
44

5-
set(QGNOMEPLATFORM_VERSION "0.8.0")
5+
set(QGNOMEPLATFORM_VERSION "0.8.1")
6+
7+
option(USE_QT6 "Use Qt6 instead of Qt5" OFF)
8+
9+
if (USE_QT6)
10+
set(QT_MIN_VERSION "6.2.0")
11+
set(CMAKE_CXX_STANDARD 17)
12+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
13+
set(LIBQGNOMEPLATFORM_SUFFIX "6")
14+
else()
15+
set(QT_MIN_VERSION "5.15.2")
16+
set(CMAKE_CXX_STANDARD 11)
17+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
18+
set(LIBQGNOMEPLATFORM_SUFFIX "")
19+
endif()
620

7-
set(QT_MIN_VERSION "5.12.0")
821
set(CMAKE_AUTOMOC ON)
922

1023
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})
1124

1225
include(GNUInstallDirs)
1326
include(FeatureSummary)
1427

15-
add_definitions(-std=c++11)
28+
if (USE_QT6)
29+
find_package(QT NAMES Qt6 COMPONENTS Core DBus Gui Widgets REQUIRED)
30+
else()
31+
find_package(QT NAMES Qt5 COMPONENTS Core DBus Gui Widgets REQUIRED)
32+
endif()
1633

17-
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core DBus Gui Widgets)
18-
find_package(Qt5Gui ${QT_MIN_VERSION} CONFIG REQUIRED Private)
34+
find_package(Qt${QT_VERSION_MAJOR} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
35+
Core
36+
DBus
37+
Gui
38+
Widgets
39+
)
1940

20-
find_package(Qt5ThemeSupport REQUIRED)
41+
find_package(Qt${QT_VERSION_MAJOR}Gui ${QT_MIN_VERSION} CONFIG REQUIRED Private)
42+
if (NOT USE_QT6)
43+
find_package(Qt${QT_VERSION_MAJOR}ThemeSupport REQUIRED)
44+
endif()
2145

2246
find_package(GSettingSchemas REQUIRED)
23-
find_package(AdwaitaQt "1.3.0" REQUIRED)
47+
if (USE_QT6)
48+
find_package(AdwaitaQt6 "1.4.1" REQUIRED)
49+
else()
50+
find_package(AdwaitaQt "1.4.1" REQUIRED)
51+
endif()
2452

2553
find_package(PkgConfig REQUIRED)
2654
pkg_check_modules(GTK+3 REQUIRED IMPORTED_TARGET gtk+-3.0)
@@ -30,17 +58,19 @@ pkg_check_modules(GTK+3 REQUIRED IMPORTED_TARGET gtk+-3.0)
3058
if (DISABLE_DECORATION_SUPPORT)
3159
message(STATUS "Disabling Qt Wayland decoration support")
3260
else()
33-
find_package(Qt5WaylandClient ${QT_MIN_VERSION} CONFIG REQUIRED)
34-
set_package_properties(Qt5WaylandClient PROPERTIES
61+
find_package(Qt${QT_VERSION_MAJOR}WaylandClient ${QT_MIN_VERSION} CONFIG REQUIRED)
62+
set_package_properties(Qt${QT_VERSION_MAJOR}WaylandClient PROPERTIES
3563
DESCRIPTION "Qt Wayland decoration support"
3664
PURPOSE "Required for QGnomePlatform decoration plugin"
3765
TYPE REQUIRED
3866
)
3967
# NOTE: I don't know how to do this only in case of qt_config(xkbcommon).
4068
# We would miss an include in QWaylandDisplay header file.
41-
find_package(Qt5XkbCommonSupport ${QT_MIN_VERSION})
69+
if (NOT USE_QT6)
70+
find_package(Qt${QT_VERSION_MAJOR}XkbCommonSupport ${QT_MIN_VERSION})
71+
endif()
4272

43-
if (DECORATION_SHADOWS_SUPPORT)
73+
if (DECORATION_SHADOWS_SUPPORT OR USE_QT6)
4474
message(STATUS "Enabling Qt Wayland decoration shadows support")
4575
message(STATUS "NOTE: This support requires changes in Qt Wayland from Qt 6.2")
4676
add_definitions(-DDECORATION_SHADOWS_SUPPORT)
@@ -51,13 +81,15 @@ if (DISABLE_THEME_SUPPORT)
5181
message(STATUS "Disabling platform theme support")
5282
endif()
5383

54-
get_target_property(REAL_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE}
55-
IMPORTED_LOCATION)
84+
if (NOT USE_QT6)
85+
get_target_property(REAL_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE}
86+
IMPORTED_LOCATION)
5687

57-
if (NOT QT_PLUGINS_DIR)
58-
execute_process(COMMAND "${REAL_QMAKE_EXECUTABLE}" -query QT_INSTALL_PLUGINS
59-
OUTPUT_VARIABLE QT_PLUGINS_DIR
60-
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
88+
if (NOT QT_PLUGINS_DIR)
89+
execute_process(COMMAND "${REAL_QMAKE_EXECUTABLE}" -query QT_INSTALL_PLUGINS
90+
OUTPUT_VARIABLE QT_PLUGINS_DIR
91+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
92+
endif()
6193
endif()
6294

6395
add_subdirectory(src)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This library uses private Qt headers and will likely not be forward nor backward
1010
```
1111
mkdir build
1212
cd build
13-
cmake [OPTIONS] ..
13+
cmake [OPTIONS] [-DUSE_QT6=true] ..
1414
make && make install
1515
```
1616

src/common/CMakeLists.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ set(common_SRCS
33
gnomesettings.cpp
44
)
55

6-
add_library(qgnomeplatform SHARED ${common_SRCS})
7-
target_link_libraries(qgnomeplatform
8-
Qt::Core
9-
Qt::DBus
10-
Qt::GuiPrivate
11-
Qt::Widgets
6+
add_library(qgnomeplatform${LIBQGNOMEPLATFORM_SUFFIX} SHARED ${common_SRCS})
7+
target_link_libraries(qgnomeplatform${LIBQGNOMEPLATFORM_SUFFIX}
8+
Qt${QT_VERSION_MAJOR}::Core
9+
Qt${QT_VERSION_MAJOR}::DBus
10+
Qt${QT_VERSION_MAJOR}::GuiPrivate
11+
Qt${QT_VERSION_MAJOR}::Widgets
1212
${ADWAITAQT_LIBRARIES}
1313
PkgConfig::GTK+3
1414
)
1515

16-
install(TARGETS qgnomeplatform RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
16+
install(TARGETS "qgnomeplatform${LIBQGNOMEPLATFORM_SUFFIX}" RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

src/common/gnomesettings.cpp

+87-38
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
#include "gnomesettings.h"
2121
#include "gnomesettings_p.h"
2222

23+
#if QT_VERSION >= 0x060000
24+
#include <AdwaitaQt6/adwaitacolors.h>
25+
#else
2326
#include <AdwaitaQt/adwaitacolors.h>
27+
#endif
2428

2529
// QtCore
2630
#include <QDir>
@@ -102,6 +106,11 @@ bool GnomeSettings::isGtkThemeDarkVariant()
102106
return gnomeSettingsGlobal->isGtkThemeDarkVariant();
103107
}
104108

109+
bool GnomeSettings::isGtkThemeHighContrastVariant()
110+
{
111+
return gnomeSettingsGlobal->isGtkThemeHighContrastVariant();
112+
}
113+
105114
QString GnomeSettings::gtkTheme()
106115
{
107116
return gnomeSettingsGlobal->gtkTheme();
@@ -210,7 +219,11 @@ GnomeSettingsPrivate::GnomeSettingsPrivate(QObject *parent)
210219
loadTheme();
211220
loadTitlebar();
212221

213-
m_palette = new QPalette(Adwaita::Colors::palette(m_gtkThemeDarkVariant ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita));
222+
if (m_gtkThemeHighContrastVariant) {
223+
m_palette = new QPalette(Adwaita::Colors::palette(m_gtkThemeDarkVariant ? Adwaita::ColorVariant::AdwaitaHighcontrastInverse : Adwaita::ColorVariant::AdwaitaHighcontrast));
224+
} else {
225+
m_palette = new QPalette(Adwaita::Colors::palette(m_gtkThemeDarkVariant ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita));
226+
}
214227

215228
if (m_canUseFileChooserPortal) {
216229
QTimer::singleShot(0, this, [this] () {
@@ -290,6 +303,11 @@ bool GnomeSettingsPrivate::isGtkThemeDarkVariant() const
290303
return m_gtkThemeDarkVariant;
291304
}
292305

306+
bool GnomeSettingsPrivate::isGtkThemeHighContrastVariant() const
307+
{
308+
return m_gtkThemeHighContrastVariant;
309+
}
310+
293311
QString GnomeSettingsPrivate::gtkTheme() const
294312
{
295313
return QString(m_gtkTheme);
@@ -472,7 +490,11 @@ void GnomeSettingsPrivate::loadTheme()
472490
} else {
473491
qCDebug(QGnomePlatform) << "Theme name: " << m_gtkTheme;
474492

475-
if (m_gtkTheme.toLower().contains("-dark")) {
493+
if (m_gtkTheme.toLower().startsWith("highcontrast")) {
494+
m_gtkThemeHighContrastVariant = true;
495+
}
496+
497+
if (m_gtkTheme.toLower().contains("-dark") || m_gtkTheme.toLower().endsWith("inverse")) {
476498
m_gtkThemeDarkVariant = true;
477499
}
478500

@@ -481,7 +503,11 @@ void GnomeSettingsPrivate::loadTheme()
481503
} else {
482504
qCDebug(QGnomePlatform) << "Theme name: " << styleOverride;
483505

484-
if (styleOverride.toLower().contains("-dark")) {
506+
if (styleOverride.toLower().startsWith("highcontrast")) {
507+
m_gtkThemeHighContrastVariant = true;
508+
}
509+
510+
if (styleOverride.toLower().contains("-dark") || styleOverride.toLower().endsWith("inverse")) {
485511
m_gtkThemeDarkVariant = true;
486512
}
487513

@@ -517,6 +543,53 @@ void GnomeSettingsPrivate::loadTheme()
517543
m_hints[QPlatformTheme::StyleNames] = styleNames;
518544
}
519545

546+
// FIXME: duplicate
547+
static QFont* qt_fontFromString(const QString &name)
548+
{
549+
QFont *font = new QFont(QLatin1String("Sans"), 10);
550+
551+
PangoFontDescription *desc = pango_font_description_from_string(name.toUtf8());
552+
font->setPointSizeF(static_cast<float>(pango_font_description_get_size(desc)) / PANGO_SCALE);
553+
554+
QString family = QString::fromUtf8(pango_font_description_get_family(desc));
555+
if (!family.isEmpty()) {
556+
font->setFamily(family);
557+
}
558+
559+
const int weight = pango_font_description_get_weight(desc);
560+
if (weight >= PANGO_WEIGHT_HEAVY) {
561+
font->setWeight(QFont::Black);
562+
} else if (weight >= PANGO_WEIGHT_ULTRABOLD) {
563+
font->setWeight(QFont::ExtraBold);
564+
} else if (weight >= PANGO_WEIGHT_BOLD) {
565+
font->setWeight(QFont::Bold);
566+
} else if (weight >= PANGO_WEIGHT_SEMIBOLD) {
567+
font->setWeight(QFont::DemiBold);
568+
} else if (weight >= PANGO_WEIGHT_MEDIUM) {
569+
font->setWeight(QFont::Medium);
570+
} else if (weight >= PANGO_WEIGHT_NORMAL) {
571+
font->setWeight(QFont::Normal);
572+
} else if (weight >= PANGO_WEIGHT_LIGHT) {
573+
font->setWeight(QFont::Light);
574+
} else if (weight >= PANGO_WEIGHT_ULTRALIGHT) {
575+
font->setWeight(QFont::ExtraLight);
576+
} else {
577+
font->setWeight(QFont::Thin);
578+
}
579+
580+
PangoStyle style = pango_font_description_get_style(desc);
581+
if (style == PANGO_STYLE_ITALIC) {
582+
font->setStyle(QFont::StyleItalic);
583+
} else if (style == PANGO_STYLE_OBLIQUE) {
584+
font->setStyle(QFont::StyleOblique);
585+
} else {
586+
font->setStyle(QFont::StyleNormal);
587+
}
588+
589+
pango_font_description_free(desc);
590+
return font;
591+
}
592+
520593
void GnomeSettingsPrivate::loadFonts()
521594
{
522595
qDeleteAll(m_fonts);
@@ -529,41 +602,17 @@ void GnomeSettingsPrivate::loadFonts()
529602
if (fontName.isEmpty()) {
530603
qCWarning(QGnomePlatform) << "Couldn't get " << fontType;
531604
} else {
532-
bool bold = false;
533-
int fontSize;
534-
QString name;
535-
QRegExp re("^([^,]+)[, \t]+([0-9]+)$");
536-
if (re.indexIn(fontName) == 0) {
537-
fontSize = re.cap(2).toInt();
538-
name = re.cap(1);
539-
// Bold is most likely not part of the name
540-
if (name.endsWith(QStringLiteral(" Bold"))) {
541-
bold = true;
542-
name = name.remove(QStringLiteral(" Bold"));
543-
}
544-
545-
QFont *font = new QFont(name, fontSize, bold ? QFont::Bold : QFont::Normal);
546-
if (fontType == QStringLiteral("font-name")) {
547-
m_fonts[QPlatformTheme::SystemFont] = font;
548-
qCDebug(QGnomePlatform) << "Font name: " << name << " (size " << fontSize << ")";
549-
} else if (fontType == QStringLiteral("monospace-font-name")) {
550-
m_fonts[QPlatformTheme::FixedFont] = font;
551-
qCDebug(QGnomePlatform) << "Monospace font name: " << name << " (size " << fontSize << ")";
552-
} else if (fontType == QStringLiteral("titlebar-font")) {
553-
m_fonts[QPlatformTheme::TitleBarFont] = font;
554-
qCDebug(QGnomePlatform) << "TitleBar font name: " << name << " (size " << fontSize << ")";
555-
}
556-
} else {
557-
if (fontType == QStringLiteral("font-name")) {
558-
m_fonts[QPlatformTheme::SystemFont] = new QFont(fontName);
559-
qCDebug(QGnomePlatform) << "Font name: " << fontName;
560-
} else if (fontType == QStringLiteral("monospace-font-name")) {
561-
m_fonts[QPlatformTheme::FixedFont] = new QFont(fontName);
562-
qCDebug(QGnomePlatform) << "Monospace font name: " << fontName;
563-
} else if (fontType == QStringLiteral("titlebar-font")) {
564-
m_fonts[QPlatformTheme::TitleBarFont] = new QFont(fontName);
565-
qCDebug(QGnomePlatform) << "TitleBar font name: " << fontName;
566-
}
605+
qCDebug(QGnomePlatform) << "String name: " << fontName;
606+
QFont *font = qt_fontFromString(fontName);
607+
if (fontType == QStringLiteral("font-name")) {
608+
m_fonts[QPlatformTheme::SystemFont] = font;
609+
qCDebug(QGnomePlatform) << "Font name: " << font->family() << " (size " << font->pointSize() << ")";
610+
} else if (fontType == QStringLiteral("monospace-font-name")) {
611+
m_fonts[QPlatformTheme::FixedFont] = font;
612+
qCDebug(QGnomePlatform) << "Monospace font name: " << font->family() << " (size " << font->pointSize() << ")";
613+
} else if (fontType == QStringLiteral("titlebar-font")) {
614+
m_fonts[QPlatformTheme::TitleBarFont] = font;
615+
qCDebug(QGnomePlatform) << "TitleBar font name: " << font->family() << " (size " << font->pointSize() << ")";
567616
}
568617
}
569618
}

0 commit comments

Comments
 (0)