Skip to content

Commit

Permalink
Merge branch 'master' into 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
grulja committed Nov 10, 2021
2 parents d482a4b + f296642 commit f75a948
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 138 deletions.
50 changes: 42 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,66 @@ env:
BUILD_TYPE: Release

jobs:
build:
runs-on: ubuntu-20.04
Linux_Qt5:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install base dependencies
run: |
sudo apt update
sudo apt install cmake make pkg-config libx11-dev xcb libx11-xcb-dev libgtk-3-dev
sudo apt install cmake make pkg-config libx11-dev xcb libx11-xcb-dev libxkbcommon-dev libgtk-3-dev sassc
- name: Install Qt
uses: jurplel/install-qt-action@v2
with:
version: 5.15.2

- name: Install Adwaita-qt
run: |
git clone https://github.com/FedoraQt/adwaita-qt.git adwaita-qt
cd adwaita-qt
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
make -j5
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT6=OFF
make -j2
sudo make install
- name: Build
run: |
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
make -j5
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT6=OFF
make -j2
Linux_Qt6:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install base dependencies
run: |
sudo apt update
sudo apt install cmake make pkg-config libx11-dev xcb libx11-xcb-dev libxkbcommon-dev libgtk-3-dev sassc
- name: Install Qt
uses: jurplel/install-qt-action@v2
with:
version: 6.2.0

- name: Install Adwaita-qt
run: |
git clone https://github.com/FedoraQt/adwaita-qt.git adwaita-qt
cd adwaita-qt
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT6=ON
make -j2
sudo make install
- name: Build
run: |
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT6=ON
make -j2
66 changes: 49 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,53 @@ project(QGnomePlatform)

cmake_minimum_required(VERSION 3.0)

set(QGNOMEPLATFORM_VERSION "0.8.0")
set(QGNOMEPLATFORM_VERSION "0.8.1")

option(USE_QT6 "Use Qt6 instead of Qt5" OFF)

if (USE_QT6)
set(QT_MIN_VERSION "6.2.0")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(LIBQGNOMEPLATFORM_SUFFIX "6")
else()
set(QT_MIN_VERSION "5.15.2")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(LIBQGNOMEPLATFORM_SUFFIX "")
endif()

set(QT_MIN_VERSION "5.12.0")
set(CMAKE_AUTOMOC ON)

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

include(GNUInstallDirs)
include(FeatureSummary)

add_definitions(-std=c++11)
if (USE_QT6)
find_package(QT NAMES Qt6 COMPONENTS Core DBus Gui Widgets REQUIRED)
else()
find_package(QT NAMES Qt5 COMPONENTS Core DBus Gui Widgets REQUIRED)
endif()

find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core DBus Gui Widgets)
find_package(Qt5Gui ${QT_MIN_VERSION} CONFIG REQUIRED Private)
find_package(Qt${QT_VERSION_MAJOR} ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core
DBus
Gui
Widgets
)

find_package(Qt5ThemeSupport REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}Gui ${QT_MIN_VERSION} CONFIG REQUIRED Private)
if (NOT USE_QT6)
find_package(Qt${QT_VERSION_MAJOR}ThemeSupport REQUIRED)
endif()

find_package(GSettingSchemas REQUIRED)
find_package(AdwaitaQt "1.3.0" REQUIRED)
if (USE_QT6)
find_package(AdwaitaQt6 "1.4.1" REQUIRED)
else()
find_package(AdwaitaQt "1.4.1" REQUIRED)
endif()

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK+3 REQUIRED IMPORTED_TARGET gtk+-3.0)
Expand All @@ -30,17 +58,19 @@ pkg_check_modules(GTK+3 REQUIRED IMPORTED_TARGET gtk+-3.0)
if (DISABLE_DECORATION_SUPPORT)
message(STATUS "Disabling Qt Wayland decoration support")
else()
find_package(Qt5WaylandClient ${QT_MIN_VERSION} CONFIG REQUIRED)
set_package_properties(Qt5WaylandClient PROPERTIES
find_package(Qt${QT_VERSION_MAJOR}WaylandClient ${QT_MIN_VERSION} CONFIG REQUIRED)
set_package_properties(Qt${QT_VERSION_MAJOR}WaylandClient PROPERTIES
DESCRIPTION "Qt Wayland decoration support"
PURPOSE "Required for QGnomePlatform decoration plugin"
TYPE REQUIRED
)
# NOTE: I don't know how to do this only in case of qt_config(xkbcommon).
# We would miss an include in QWaylandDisplay header file.
find_package(Qt5XkbCommonSupport ${QT_MIN_VERSION})
if (NOT USE_QT6)
find_package(Qt${QT_VERSION_MAJOR}XkbCommonSupport ${QT_MIN_VERSION})
endif()

if (DECORATION_SHADOWS_SUPPORT)
if (DECORATION_SHADOWS_SUPPORT OR USE_QT6)
message(STATUS "Enabling Qt Wayland decoration shadows support")
message(STATUS "NOTE: This support requires changes in Qt Wayland from Qt 6.2")
add_definitions(-DDECORATION_SHADOWS_SUPPORT)
Expand All @@ -51,13 +81,15 @@ if (DISABLE_THEME_SUPPORT)
message(STATUS "Disabling platform theme support")
endif()

get_target_property(REAL_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE}
IMPORTED_LOCATION)
if (NOT USE_QT6)
get_target_property(REAL_QMAKE_EXECUTABLE ${Qt5Core_QMAKE_EXECUTABLE}
IMPORTED_LOCATION)

if (NOT QT_PLUGINS_DIR)
execute_process(COMMAND "${REAL_QMAKE_EXECUTABLE}" -query QT_INSTALL_PLUGINS
OUTPUT_VARIABLE QT_PLUGINS_DIR
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT QT_PLUGINS_DIR)
execute_process(COMMAND "${REAL_QMAKE_EXECUTABLE}" -query QT_INSTALL_PLUGINS
OUTPUT_VARIABLE QT_PLUGINS_DIR
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif()

add_subdirectory(src)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This library uses private Qt headers and will likely not be forward nor backward
```
mkdir build
cd build
cmake [OPTIONS] ..
cmake [OPTIONS] [-DUSE_QT6=true] ..
make && make install
```

Expand Down
14 changes: 7 additions & 7 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ set(common_SRCS
gnomesettings.cpp
)

add_library(qgnomeplatform SHARED ${common_SRCS})
target_link_libraries(qgnomeplatform
Qt::Core
Qt::DBus
Qt::GuiPrivate
Qt::Widgets
add_library(qgnomeplatform${LIBQGNOMEPLATFORM_SUFFIX} SHARED ${common_SRCS})
target_link_libraries(qgnomeplatform${LIBQGNOMEPLATFORM_SUFFIX}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::GuiPrivate
Qt${QT_VERSION_MAJOR}::Widgets
${ADWAITAQT_LIBRARIES}
PkgConfig::GTK+3
)

install(TARGETS qgnomeplatform RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS "qgnomeplatform${LIBQGNOMEPLATFORM_SUFFIX}" RUNTIME DESTINATION bin LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
125 changes: 87 additions & 38 deletions src/common/gnomesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#include "gnomesettings.h"
#include "gnomesettings_p.h"

#if QT_VERSION >= 0x060000
#include <AdwaitaQt6/adwaitacolors.h>
#else
#include <AdwaitaQt/adwaitacolors.h>
#endif

// QtCore
#include <QDir>
Expand Down Expand Up @@ -102,6 +106,11 @@ bool GnomeSettings::isGtkThemeDarkVariant()
return gnomeSettingsGlobal->isGtkThemeDarkVariant();
}

bool GnomeSettings::isGtkThemeHighContrastVariant()
{
return gnomeSettingsGlobal->isGtkThemeHighContrastVariant();
}

QString GnomeSettings::gtkTheme()
{
return gnomeSettingsGlobal->gtkTheme();
Expand Down Expand Up @@ -210,7 +219,11 @@ GnomeSettingsPrivate::GnomeSettingsPrivate(QObject *parent)
loadTheme();
loadTitlebar();

m_palette = new QPalette(Adwaita::Colors::palette(m_gtkThemeDarkVariant ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita));
if (m_gtkThemeHighContrastVariant) {
m_palette = new QPalette(Adwaita::Colors::palette(m_gtkThemeDarkVariant ? Adwaita::ColorVariant::AdwaitaHighcontrastInverse : Adwaita::ColorVariant::AdwaitaHighcontrast));
} else {
m_palette = new QPalette(Adwaita::Colors::palette(m_gtkThemeDarkVariant ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita));
}

if (m_canUseFileChooserPortal) {
QTimer::singleShot(0, this, [this] () {
Expand Down Expand Up @@ -290,6 +303,11 @@ bool GnomeSettingsPrivate::isGtkThemeDarkVariant() const
return m_gtkThemeDarkVariant;
}

bool GnomeSettingsPrivate::isGtkThemeHighContrastVariant() const
{
return m_gtkThemeHighContrastVariant;
}

QString GnomeSettingsPrivate::gtkTheme() const
{
return QString(m_gtkTheme);
Expand Down Expand Up @@ -472,7 +490,11 @@ void GnomeSettingsPrivate::loadTheme()
} else {
qCDebug(QGnomePlatform) << "Theme name: " << m_gtkTheme;

if (m_gtkTheme.toLower().contains("-dark")) {
if (m_gtkTheme.toLower().startsWith("highcontrast")) {
m_gtkThemeHighContrastVariant = true;
}

if (m_gtkTheme.toLower().contains("-dark") || m_gtkTheme.toLower().endsWith("inverse")) {
m_gtkThemeDarkVariant = true;
}

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

if (styleOverride.toLower().contains("-dark")) {
if (styleOverride.toLower().startsWith("highcontrast")) {
m_gtkThemeHighContrastVariant = true;
}

if (styleOverride.toLower().contains("-dark") || styleOverride.toLower().endsWith("inverse")) {
m_gtkThemeDarkVariant = true;
}

Expand Down Expand Up @@ -517,6 +543,53 @@ void GnomeSettingsPrivate::loadTheme()
m_hints[QPlatformTheme::StyleNames] = styleNames;
}

// FIXME: duplicate
static QFont* qt_fontFromString(const QString &name)
{
QFont *font = new QFont(QLatin1String("Sans"), 10);

PangoFontDescription *desc = pango_font_description_from_string(name.toUtf8());
font->setPointSizeF(static_cast<float>(pango_font_description_get_size(desc)) / PANGO_SCALE);

QString family = QString::fromUtf8(pango_font_description_get_family(desc));
if (!family.isEmpty()) {
font->setFamily(family);
}

const int weight = pango_font_description_get_weight(desc);
if (weight >= PANGO_WEIGHT_HEAVY) {
font->setWeight(QFont::Black);
} else if (weight >= PANGO_WEIGHT_ULTRABOLD) {
font->setWeight(QFont::ExtraBold);
} else if (weight >= PANGO_WEIGHT_BOLD) {
font->setWeight(QFont::Bold);
} else if (weight >= PANGO_WEIGHT_SEMIBOLD) {
font->setWeight(QFont::DemiBold);
} else if (weight >= PANGO_WEIGHT_MEDIUM) {
font->setWeight(QFont::Medium);
} else if (weight >= PANGO_WEIGHT_NORMAL) {
font->setWeight(QFont::Normal);
} else if (weight >= PANGO_WEIGHT_LIGHT) {
font->setWeight(QFont::Light);
} else if (weight >= PANGO_WEIGHT_ULTRALIGHT) {
font->setWeight(QFont::ExtraLight);
} else {
font->setWeight(QFont::Thin);
}

PangoStyle style = pango_font_description_get_style(desc);
if (style == PANGO_STYLE_ITALIC) {
font->setStyle(QFont::StyleItalic);
} else if (style == PANGO_STYLE_OBLIQUE) {
font->setStyle(QFont::StyleOblique);
} else {
font->setStyle(QFont::StyleNormal);
}

pango_font_description_free(desc);
return font;
}

void GnomeSettingsPrivate::loadFonts()
{
qDeleteAll(m_fonts);
Expand All @@ -529,41 +602,17 @@ void GnomeSettingsPrivate::loadFonts()
if (fontName.isEmpty()) {
qCWarning(QGnomePlatform) << "Couldn't get " << fontType;
} else {
bool bold = false;
int fontSize;
QString name;
QRegExp re("^([^,]+)[, \t]+([0-9]+)$");
if (re.indexIn(fontName) == 0) {
fontSize = re.cap(2).toInt();
name = re.cap(1);
// Bold is most likely not part of the name
if (name.endsWith(QStringLiteral(" Bold"))) {
bold = true;
name = name.remove(QStringLiteral(" Bold"));
}

QFont *font = new QFont(name, fontSize, bold ? QFont::Bold : QFont::Normal);
if (fontType == QStringLiteral("font-name")) {
m_fonts[QPlatformTheme::SystemFont] = font;
qCDebug(QGnomePlatform) << "Font name: " << name << " (size " << fontSize << ")";
} else if (fontType == QStringLiteral("monospace-font-name")) {
m_fonts[QPlatformTheme::FixedFont] = font;
qCDebug(QGnomePlatform) << "Monospace font name: " << name << " (size " << fontSize << ")";
} else if (fontType == QStringLiteral("titlebar-font")) {
m_fonts[QPlatformTheme::TitleBarFont] = font;
qCDebug(QGnomePlatform) << "TitleBar font name: " << name << " (size " << fontSize << ")";
}
} else {
if (fontType == QStringLiteral("font-name")) {
m_fonts[QPlatformTheme::SystemFont] = new QFont(fontName);
qCDebug(QGnomePlatform) << "Font name: " << fontName;
} else if (fontType == QStringLiteral("monospace-font-name")) {
m_fonts[QPlatformTheme::FixedFont] = new QFont(fontName);
qCDebug(QGnomePlatform) << "Monospace font name: " << fontName;
} else if (fontType == QStringLiteral("titlebar-font")) {
m_fonts[QPlatformTheme::TitleBarFont] = new QFont(fontName);
qCDebug(QGnomePlatform) << "TitleBar font name: " << fontName;
}
qCDebug(QGnomePlatform) << "String name: " << fontName;
QFont *font = qt_fontFromString(fontName);
if (fontType == QStringLiteral("font-name")) {
m_fonts[QPlatformTheme::SystemFont] = font;
qCDebug(QGnomePlatform) << "Font name: " << font->family() << " (size " << font->pointSize() << ")";
} else if (fontType == QStringLiteral("monospace-font-name")) {
m_fonts[QPlatformTheme::FixedFont] = font;
qCDebug(QGnomePlatform) << "Monospace font name: " << font->family() << " (size " << font->pointSize() << ")";
} else if (fontType == QStringLiteral("titlebar-font")) {
m_fonts[QPlatformTheme::TitleBarFont] = font;
qCDebug(QGnomePlatform) << "TitleBar font name: " << font->family() << " (size " << font->pointSize() << ")";
}
}
}
Expand Down
Loading

0 comments on commit f75a948

Please sign in to comment.