summaryrefslogtreecommitdiffstats
path: root/src/plugins/platformthemes
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platformthemes')
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp84
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h9
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3menu.cpp6
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3theme.cpp38
-rw-r--r--src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp9
-rw-r--r--src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp4
6 files changed, 66 insertions, 84 deletions
diff --git a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp
index 9826d1f4b1..6636a13444 100644
--- a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp
+++ b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp
@@ -35,12 +35,10 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
-class QGtk3Dialog : public QWindow
+class QGtk3Dialog
{
- Q_OBJECT
-
public:
- QGtk3Dialog(GtkWidget *gtkWidget);
+ QGtk3Dialog(GtkWidget *gtkWidget, QPlatformDialogHelper *helper);
~QGtk3Dialog();
GtkDialog *gtkDialog() const;
@@ -49,23 +47,20 @@ public:
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent);
void hide();
-Q_SIGNALS:
- void accept();
- void reject();
-
protected:
- static void onResponse(QGtk3Dialog *dialog, int response);
-
-private slots:
- void onParentWindowDestroyed();
+ static void onResponse(QPlatformDialogHelper *helper, int response);
private:
GtkWidget *gtkWidget;
+ QPlatformDialogHelper *helper;
+ Qt::WindowModality modality;
};
-QGtk3Dialog::QGtk3Dialog(GtkWidget *gtkWidget) : gtkWidget(gtkWidget)
+QGtk3Dialog::QGtk3Dialog(GtkWidget *gtkWidget, QPlatformDialogHelper *helper)
+ : gtkWidget(gtkWidget)
+ , helper(helper)
{
- g_signal_connect_swapped(G_OBJECT(gtkWidget), "response", G_CALLBACK(onResponse), this);
+ g_signal_connect_swapped(G_OBJECT(gtkWidget), "response", G_CALLBACK(onResponse), helper);
g_signal_connect(G_OBJECT(gtkWidget), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
}
@@ -82,27 +77,22 @@ GtkDialog *QGtk3Dialog::gtkDialog() const
void QGtk3Dialog::exec()
{
- if (modality() == Qt::ApplicationModal) {
+ if (modality == Qt::ApplicationModal) {
// block input to the whole app, including other GTK dialogs
gtk_dialog_run(gtkDialog());
} else {
// block input to the window, allow input to other GTK dialogs
QEventLoop loop;
- connect(this, SIGNAL(accept()), &loop, SLOT(quit()));
- connect(this, SIGNAL(reject()), &loop, SLOT(quit()));
+ loop.connect(helper, SIGNAL(accept()), SLOT(quit()));
+ loop.connect(helper, SIGNAL(reject()), SLOT(quit()));
loop.exec();
}
}
bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent)
{
- if (parent) {
- connect(parent, &QWindow::destroyed, this, &QGtk3Dialog::onParentWindowDestroyed,
- Qt::UniqueConnection);
- }
- setParent(parent);
- setFlags(flags);
- setModality(modality);
+ Q_UNUSED(flags);
+ this->modality = modality;
gtk_widget_realize(gtkWidget); // creates X window
@@ -120,7 +110,6 @@ bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWind
if (modality != Qt::NonModal) {
gdk_window_set_modal_hint(gdkWindow, true);
- QGuiApplicationPrivate::showModalWindow(this);
}
gtk_widget_show(gtkWidget);
@@ -130,30 +119,20 @@ bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWind
void QGtk3Dialog::hide()
{
- QGuiApplicationPrivate::hideModalWindow(this);
gtk_widget_hide(gtkWidget);
}
-void QGtk3Dialog::onResponse(QGtk3Dialog *dialog, int response)
+void QGtk3Dialog::onResponse(QPlatformDialogHelper *helper, int response)
{
if (response == GTK_RESPONSE_OK)
- emit dialog->accept();
+ emit helper->accept();
else
- emit dialog->reject();
-}
-
-void QGtk3Dialog::onParentWindowDestroyed()
-{
- // The QGtk3*DialogHelper classes own this object. Make sure the parent doesn't delete it.
- setParent(nullptr);
+ emit helper->reject();
}
QGtk3ColorDialogHelper::QGtk3ColorDialogHelper()
{
- d.reset(new QGtk3Dialog(gtk_color_chooser_dialog_new("", nullptr)));
- connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
- connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
-
+ d.reset(new QGtk3Dialog(gtk_color_chooser_dialog_new("", nullptr), this));
g_signal_connect_swapped(d->gtkDialog(), "notify::rgba", G_CALLBACK(onColorChanged), this);
}
@@ -198,11 +177,6 @@ QColor QGtk3ColorDialogHelper::currentColor() const
return QColor::fromRgbF(gdkColor.red, gdkColor.green, gdkColor.blue, gdkColor.alpha);
}
-void QGtk3ColorDialogHelper::onAccepted()
-{
- emit accept();
-}
-
void QGtk3ColorDialogHelper::onColorChanged(QGtk3ColorDialogHelper *dialog)
{
emit dialog->currentColorChanged(dialog->currentColor());
@@ -222,10 +196,7 @@ QGtk3FileDialogHelper::QGtk3FileDialogHelper()
GTK_FILE_CHOOSER_ACTION_OPEN,
qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Cancel)), GTK_RESPONSE_CANCEL,
qUtf8Printable(QGtk3Theme::defaultStandardButtonText(QPlatformDialogHelper::Ok)), GTK_RESPONSE_OK,
- NULL)));
-
- connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
- connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
+ NULL), this));
g_signal_connect(GTK_FILE_CHOOSER(d->gtkDialog()), "selection-changed", G_CALLBACK(onSelectionChanged), this);
g_signal_connect_swapped(GTK_FILE_CHOOSER(d->gtkDialog()), "current-folder-changed", G_CALLBACK(onCurrentFolderChanged), this);
@@ -348,11 +319,6 @@ QString QGtk3FileDialogHelper::selectedNameFilter() const
return _filterNames.value(gtkFilter);
}
-void QGtk3FileDialogHelper::onAccepted()
-{
- emit accept();
-}
-
void QGtk3FileDialogHelper::onSelectionChanged(GtkDialog *gtkDialog, QGtk3FileDialogHelper *helper)
{
QString selection;
@@ -508,10 +474,7 @@ void QGtk3FileDialogHelper::setNameFilters(const QStringList &filters)
QGtk3FontDialogHelper::QGtk3FontDialogHelper()
{
- d.reset(new QGtk3Dialog(gtk_font_chooser_dialog_new("", nullptr)));
- connect(d.data(), SIGNAL(accept()), this, SLOT(onAccepted()));
- connect(d.data(), SIGNAL(reject()), this, SIGNAL(reject()));
-
+ d.reset(new QGtk3Dialog(gtk_font_chooser_dialog_new("", nullptr), this));
g_signal_connect_swapped(d->gtkDialog(), "notify::font", G_CALLBACK(onFontChanged), this);
}
@@ -615,11 +578,6 @@ QFont QGtk3FontDialogHelper::currentFont() const
return font;
}
-void QGtk3FontDialogHelper::onAccepted()
-{
- emit accept();
-}
-
void QGtk3FontDialogHelper::onFontChanged(QGtk3FontDialogHelper *dialog)
{
emit dialog->currentFontChanged(dialog->currentFont());
@@ -636,5 +594,3 @@ void QGtk3FontDialogHelper::applyOptions()
QT_END_NAMESPACE
#include "moc_qgtk3dialoghelpers.cpp"
-
-#include "qgtk3dialoghelpers.moc"
diff --git a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h
index e5c4c72539..89f48d8b01 100644
--- a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h
+++ b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h
@@ -35,9 +35,6 @@ public:
void setCurrentColor(const QColor &color) override;
QColor currentColor() const override;
-private Q_SLOTS:
- void onAccepted();
-
private:
static void onColorChanged(QGtk3ColorDialogHelper *helper);
void applyOptions();
@@ -66,9 +63,6 @@ public:
void selectNameFilter(const QString &filter) override;
QString selectedNameFilter() const override;
-private Q_SLOTS:
- void onAccepted();
-
private:
static void onSelectionChanged(GtkDialog *dialog, QGtk3FileDialogHelper *helper);
static void onCurrentFolderChanged(QGtk3FileDialogHelper *helper);
@@ -102,9 +96,6 @@ public:
void setCurrentFont(const QFont &font) override;
QFont currentFont() const override;
-private Q_SLOTS:
- void onAccepted();
-
private:
static void onFontChanged(QGtk3FontDialogHelper *helper);
void applyOptions();
diff --git a/src/plugins/platformthemes/gtk3/qgtk3menu.cpp b/src/plugins/platformthemes/gtk3/qgtk3menu.cpp
index 5589ff8836..c4ea0e5e33 100644
--- a/src/plugins/platformthemes/gtk3/qgtk3menu.cpp
+++ b/src/plugins/platformthemes/gtk3/qgtk3menu.cpp
@@ -123,13 +123,13 @@ static QString convertMnemonics(QString text, bool *found)
{
*found = false;
- qsizetype i = text.length() - 1;
+ qsizetype i = text.size() - 1;
while (i >= 0) {
const QChar c = text.at(i);
if (c == u'&') {
if (i == 0 || text.at(i - 1) != u'&') {
// convert Qt to GTK mnemonic
- if (i < text.length() - 1 && !text.at(i + 1).isSpace()) {
+ if (i < text.size() - 1 && !text.at(i + 1).isSpace()) {
text.replace(i, 1, u'_');
*found = true;
}
@@ -329,7 +329,7 @@ void QGtk3Menu::insertMenuItem(QPlatformMenuItem *item, QPlatformMenuItem *befor
GtkWidget *handle = gitem->create();
int index = m_items.indexOf(static_cast<QGtk3MenuItem *>(before));
if (index < 0)
- index = m_items.count();
+ index = m_items.size();
m_items.insert(index, gitem);
gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), handle, index);
}
diff --git a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp
index 8551966678..1f912aaf26 100644
--- a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp
+++ b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp
@@ -7,6 +7,7 @@
#include <QVariant>
#include <QtCore/qregularexpression.h>
#include <QGuiApplication>
+#include <qpa/qwindowsysteminterface.h>
#undef signals
#include <gtk/gtk.h>
@@ -82,6 +83,39 @@ QGtk3Theme::QGtk3Theme()
/* Use our custom log handler. */
g_log_set_handler("Gtk", G_LOG_LEVEL_MESSAGE, gtkMessageHandler, nullptr);
+
+#define SETTING_CONNECT(setting) g_signal_connect(settings, "notify::" setting, G_CALLBACK(notifyThemeChanged), nullptr)
+ auto notifyThemeChanged = [] {
+ QWindowSystemInterface::handleThemeChange();
+ };
+
+ GtkSettings *settings = gtk_settings_get_default();
+ SETTING_CONNECT("gtk-cursor-blink-time");
+ SETTING_CONNECT("gtk-double-click-distance");
+ SETTING_CONNECT("gtk-double-click-time");
+ SETTING_CONNECT("gtk-long-press-time");
+ SETTING_CONNECT("gtk-entry-password-hint-timeout");
+ SETTING_CONNECT("gtk-dnd-drag-threshold");
+ SETTING_CONNECT("gtk-icon-theme-name");
+ SETTING_CONNECT("gtk-fallback-icon-theme");
+ SETTING_CONNECT("gtk-font-name");
+ SETTING_CONNECT("gtk-application-prefer-dark-theme");
+ SETTING_CONNECT("gtk-theme-name");
+#undef SETTING_CONNECT
+
+ /* Set XCURSOR_SIZE and XCURSOR_THEME for Wayland sessions */
+ if (QGuiApplication::platformName().startsWith("wayland"_L1)) {
+ if (qEnvironmentVariableIsEmpty("XCURSOR_SIZE")) {
+ const int cursorSize = gtkSetting<gint>("gtk-cursor-theme-size");
+ if (cursorSize > 0)
+ qputenv("XCURSOR_SIZE", QByteArray::number(cursorSize));
+ }
+ if (qEnvironmentVariableIsEmpty("XCURSOR_THEME")) {
+ const QString cursorTheme = gtkSetting("gtk-cursor-theme-name");
+ if (!cursorTheme.isEmpty())
+ qputenv("XCURSOR_THEME", cursorTheme.toUtf8());
+ }
+ }
}
static inline QVariant gtkGetLongPressTime()
@@ -116,8 +150,6 @@ QVariant QGtk3Theme::themeHint(QPlatformTheme::ThemeHint hint) const
return QVariant(gtkSetting("gtk-icon-theme-name"));
case QPlatformTheme::SystemIconFallbackThemeName:
return QVariant(gtkSetting("gtk-fallback-icon-theme"));
- case QPlatformTheme::PreselectFirstFileInDirectory:
- return true;
default:
return QGnomeTheme::themeHint(hint);
}
@@ -158,7 +190,7 @@ QPlatformTheme::Appearance QGtk3Theme::appearance() const
gtk-theme-name provides both light and dark variants. We can save a
regex check by testing this property first.
*/
- const auto preferDark = gtkSetting<bool>("gtk-application-prefer-dark-theme");
+ const auto preferDark = gtkSetting<gboolean>("gtk-application-prefer-dark-theme");
if (preferDark)
return Appearance::Dark;
diff --git a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp
index 54e600fcbe..9e3afea7c5 100644
--- a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp
+++ b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp
@@ -173,9 +173,12 @@ void QXdgDesktopPortalFileDialog::openPortal(Qt::WindowFlags windowFlags, Qt::Wi
if (!d->selectedFiles.isEmpty()) {
// current_file for the file to be pre-selected, current_name for the file name to be pre-filled
- // current_file accepts absolute path while current_name accepts just file name
- options.insert("current_file"_L1, QFile::encodeName(d->selectedFiles.first()).append('\0'));
- options.insert("current_name"_L1, QFileInfo(d->selectedFiles.first()).fileName());
+ // current_file accepts absolute path and requires the file to exist
+ // while current_name accepts just file name
+ QFileInfo selectedFileInfo(d->selectedFiles.first());
+ if (selectedFileInfo.exists())
+ options.insert("current_file"_L1, QFile::encodeName(d->selectedFiles.first()).append('\0'));
+ options.insert("current_name"_L1, selectedFileInfo.fileName());
}
}
diff --git a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp
index e6a72e4289..552a78278f 100644
--- a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp
+++ b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportaltheme.cpp
@@ -75,7 +75,7 @@ QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
QStringList themeNames;
themeNames += QGuiApplicationPrivate::platform_integration->themeNames();
// 1) Look for a theme plugin.
- for (const QString &themeName : qAsConst(themeNames)) {
+ for (const QString &themeName : std::as_const(themeNames)) {
d->baseTheme = QPlatformThemeFactory::create(themeName, nullptr);
if (d->baseTheme)
break;
@@ -84,7 +84,7 @@ QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
// 2) If no theme plugin was found ask the platform integration to
// create a theme
if (!d->baseTheme) {
- for (const QString &themeName : qAsConst(themeNames)) {
+ for (const QString &themeName : std::as_const(themeNames)) {
d->baseTheme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName);
if (d->baseTheme)
break;