Merge lp:~3v1n0/appmenu-qt5/avoid-x11-calls-in-other-envs into lp:appmenu-qt5

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: 45
Merged at revision: 45
Proposed branch: lp:~3v1n0/appmenu-qt5/avoid-x11-calls-in-other-envs
Merge into: lp:appmenu-qt5
Prerequisite: lp:~3v1n0/appmenu-qt5/x11-usertime-on-activate
Diff against target: 45 lines (+14/-3)
1 file modified
src/appmenuplatformmenubar.cpp (+14/-3)
To merge this branch: bzr merge lp:~3v1n0/appmenu-qt5/avoid-x11-calls-in-other-envs
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+311677@code.launchpad.net

This proposal supersedes a proposal from 2016-11-24.

Commit message

AppMenuPlatformMenuBar: Don't initialize X11 related functions in other environments

To post a comment you must log in.
Andrea Azzarone (azzar1) wrote :

+1

review: Approve
Dmitry Shachnev (mitya57) wrote :

Can you please provide more details on how this was failing?

XSetErrorHandler should be safe to call on non-x11 environments, because it only sets an libX11-internal variable, and does not interact with the server.

Or maybe the real reason is that GTK+ 2.x does not interact well with Mir? Then the commit message is misleading: the X11 related functions to blame are not in appmenu-qt5, but in GTK+ 2.

If you are sure there is some kind of failure, then we may need to fix the mainline Qt too: it has similar code in http://code.qt.io/cgit/qt/qtbase.git/tree/src/plugins/platformthemes/gtk3/qgtk3theme.cpp#n78.

Marco Trevisan (Treviño) (3v1n0) wrote :

The problem here was not in XSetErrorHandler (that was not needed anyway at this point), but in the call `QGnomeTheme::themeHint(hint);`

I don't remember the details now, but it was somewhat caused by some code in gtk2 yes.
Upstream qt has not this kind of issues. Also gtk3 is not X11-only toolkit, thus it self-protects when not running in such environments

Dmitry Shachnev (mitya57) wrote :

OK. Now that we have Qt 5.7 in Zesty, we can port appmenu-qt5 to GTK+ 3, though I would prefer to remove it altogether instead (bug 1634941).

Marco Trevisan (Treviño) (3v1n0) wrote :

Yeah, I do agree that removing appmenu-qt5 is way better (considering also that shipping this in a snap world, would just be annoying).

We should take care of changes going to be needed for unity8 appmenus too, though.
You might get in touch with Nick Dedekind.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/appmenuplatformmenubar.cpp'
2--- src/appmenuplatformmenubar.cpp 2014-12-13 15:38:51 +0000
3+++ src/appmenuplatformmenubar.cpp 2016-11-24 02:16:30 +0000
4@@ -35,6 +35,7 @@
5 #include <QDebug>
6 #include <QList>
7 #include <QVariant>
8+#include <QX11Info>
9
10 #undef signals // Needed to make sure we can include gtk.h
11 #include <gtk/gtk.h>
12@@ -229,6 +230,10 @@
13 /* Helper function, as copy-pasted from Qt 5.2.1 gtk2 platformthemeplugin */
14 static QString gtkSetting(const gchar *propertyName)
15 {
16+ if (!QX11Info::isPlatformX11()) {
17+ return QString();
18+ }
19+
20 GtkSettings *settings = gtk_settings_get_default();
21 gchararray value;
22 g_object_get(settings, propertyName, &value, NULL);
23@@ -261,13 +266,19 @@
24 GnomeAppMenuPlatformTheme::GnomeAppMenuPlatformTheme()
25 : QGnomeTheme()
26 {
27- int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL);
28- gtk_init(0, 0);
29- XSetErrorHandler(oldErrorHandler);
30+ if (QX11Info::isPlatformX11()) {
31+ int (*oldErrorHandler)(Display *, XErrorEvent *) = XSetErrorHandler(NULL);
32+ gtk_init(0, 0);
33+ XSetErrorHandler(oldErrorHandler);
34+ }
35 }
36
37 QVariant GnomeAppMenuPlatformTheme::themeHint(QPlatformTheme::ThemeHint hint) const
38 {
39+ if (!QX11Info::isPlatformX11()) {
40+ return QVariant(QVariant::String);
41+ }
42+
43 switch (hint) {
44 case QPlatformTheme::SystemIconThemeName:
45 return QVariant(gtkSetting("gtk-icon-theme-name"));

Subscribers

People subscribed via source and target branches