8#include <QGuiApplication>
9#include <qpa/qwindowsysteminterface.h>
14#if QT_CONFIG(xcb_xlib)
20using namespace Qt::StringLiterals;
27 GtkSettings *settings = gtk_settings_get_default();
29 g_object_get(settings, propertyName, &value, NULL);
35 gchararray value = gtkSetting<gchararray>(propertyName);
36 QString str = QString::fromUtf8(value);
42 GLogLevelFlags log_level,
44 gpointer unused_data) {
46
47
48 if (g_strcmp0(message,
"GtkDialog mapped without a transient parent. "
49 "This is discouraged.") != 0) {
51 g_log_default_handler(log_domain, log_level, message, unused_data);
60 if (QGuiApplication::platformName().startsWith(
"wayland"_L1))
61 gdk_set_allowed_backends(
"wayland,x11");
62 else if (QGuiApplication::platformName() ==
"xcb"_L1)
63 gdk_set_allowed_backends(
"x11,wayland");
65#if QT_CONFIG(xcb_xlib)
68 int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(
nullptr);
71 gtk_init(
nullptr,
nullptr);
73#if QT_CONFIG(xcb_xlib)
74 XSetErrorHandler(oldErrorHandler);
78
79
80 g_type_ensure(PANGO_TYPE_FONT_FAMILY);
81 g_type_ensure(PANGO_TYPE_FONT_FACE);
84 g_log_set_handler(
"Gtk", G_LOG_LEVEL_MESSAGE, gtkMessageHandler,
nullptr);
86#define SETTING_CONNECT(setting) g_signal_connect(settings, "notify::" setting, G_CALLBACK(notifyThemeChanged), nullptr)
87 auto notifyThemeChanged = [] {
88 QWindowSystemInterface::handleThemeChange();
91 GtkSettings *settings = gtk_settings_get_default();
106#undef SETTING_CONNECT
108 m_storage.reset(
new QGtk3Storage);
113 const char *gtk_long_press_time =
"gtk-long-press-time";
114 static bool found = g_object_class_find_property(G_OBJECT_GET_CLASS(gtk_settings_get_default()), gtk_long_press_time);
117 return QVariant(gtkSetting<guint>(gtk_long_press_time));
123 case QPlatformTheme::CursorFlashTime:
124 if (gtkSetting<gboolean>(
"gtk-cursor-blink"))
125 return QVariant(gtkSetting<gint>(
"gtk-cursor-blink-time"));
128 case QPlatformTheme::MouseDoubleClickDistance:
129 return QVariant(gtkSetting<gint>(
"gtk-double-click-distance"));
130 case QPlatformTheme::MouseDoubleClickInterval:
131 return QVariant(gtkSetting<gint>(
"gtk-double-click-time"));
132 case QPlatformTheme::MousePressAndHoldInterval: {
133 QVariant v = gtkGetLongPressTime();
135 v = QGnomeTheme::themeHint(hint);
138 case QPlatformTheme::PasswordMaskDelay:
139 return QVariant(gtkSetting<guint>(
"gtk-entry-password-hint-timeout"));
140 case QPlatformTheme::StartDragDistance:
141 return QVariant(gtkSetting<gint>(
"gtk-dnd-drag-threshold"));
142 case QPlatformTheme::SystemIconThemeName:
143 return QVariant(gtkSetting(
"gtk-icon-theme-name"));
144 case QPlatformTheme::SystemIconFallbackThemeName:
145 return QVariant(gtkSetting(
"gtk-fallback-icon-theme"));
146 case QPlatformTheme::MouseCursorTheme:
147 return QVariant(gtkSetting(
"gtk-cursor-theme-name"));
148 case QPlatformTheme::MouseCursorSize: {
149 int s = gtkSetting<gint>(
"gtk-cursor-theme-size");
151 return QVariant(QSize(s, s));
152 return QGnomeTheme::themeHint(hint);
155 return QGnomeTheme::themeHint(hint);
161 QString cfgFontName = gtkSetting(
"gtk-font-name");
162 if (!cfgFontName.isEmpty())
164 return QGnomeTheme::gtkFontName();
171 Q_D(
const QGnomeTheme);
172 const Qt::ColorScheme colorScheme = d->colorScheme();
173 const bool hasRequestedColorScheme = d->hasRequestedColorScheme();
176 if (hasRequestedColorScheme && colorScheme != m_storage->colorScheme()) {
177 qCDebug(lcQGtk3Interface) <<
"Requested color scheme" << colorScheme
178 <<
"differs from theme color scheme" << m_storage->colorScheme();
182 return hasRequestedColorScheme ? colorScheme : m_storage->colorScheme();
187 const Qt::ColorScheme oldColorScheme = colorScheme();
188 QGnomeTheme::requestColorScheme(scheme);
189 if (oldColorScheme == colorScheme())
191 qCDebug(lcQGtk3Interface) << scheme <<
"has been requested. Theme supports color scheme:"
192 << m_storage->colorScheme();
193 m_storage->handleThemeChange();
194 QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents);
203 return useNativeFileDialog();
217 if (!useNativeFileDialog())
230
231
232
233
234
235
236
237 return gtk_check_version(3, 15, 5) ==
nullptr;
244 Q_D(
const QGnomeTheme);
245 const Qt::ColorScheme colorScheme = d->colorScheme();
246 const bool hasRequestedColorScheme = d->hasRequestedColorScheme();
249 if (hasRequestedColorScheme && colorScheme != m_storage->colorScheme()) {
250 qCDebug(lcQGtk3Interface) <<
"Current KDE theme doesn't support requested color scheme"
251 << colorScheme <<
"Falling back to fusion palette.";
252 return QPlatformTheme::palette(type);
256 return (hasRequestedColorScheme && colorScheme != m_storage->colorScheme())
257 ? QPlatformTheme::palette(type)
258 : m_storage->palette(type);
264 return m_storage->standardPixmap(sp, size);
270 return m_storage->font(type);
274 QPlatformTheme::IconOptions iconOptions)
const
276 Q_UNUSED(iconOptions);
278 return m_storage->fileIcon(fileInfo);
282void QGtk3Theme::updateColorScheme(Qt::ColorScheme newColorScheme)
284 if (newColorScheme == colorScheme())
285 QGnomeTheme::updateColorScheme(newColorScheme);
287 m_storage->handleThemeChange();
QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions={ }) const override
Return an icon for fileInfo, observing iconOptions.
Qt::ColorScheme colorScheme() const override
bool usePlatformNativeDialog(DialogType type) const override
virtual QVariant themeHint(ThemeHint hint) const override
void requestColorScheme(Qt::ColorScheme scheme) override
QPlatformDialogHelper * createPlatformDialogHelper(DialogType type) const override
const QPalette * palette(Palette type=SystemPalette) const override
Return a color palette for type type.
virtual QString gtkFontName() const override
QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const override
Return a pixmap for standardPixmap, at the given size.
const QFont * font(Font type=SystemFont) const override
void gtkMessageHandler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data)
static QString gtkSetting(const gchar *propertyName)
static QVariant gtkGetLongPressTime()
static T gtkSetting(const gchar *propertyName)
#define SETTING_CONNECT(setting)