#1638 Make building GTK2 support code optional when building with GTK3

Open
opened 7 months ago by wolfbeast · 5 comments
wolfbeast commented 7 months ago (Migrated from github.com)

Apparently when building GTK3 applications on UXP, there are still some dependencies on GTK2 libraries.
We should investigate what causes this dependency and if possible to do so without affecting GTK2 builds, eliminate this dependency when building with GTK3.

Apparently when building GTK3 applications on UXP, there are still some dependencies on GTK2 libraries. We should investigate what causes this dependency and if possible to do so without affecting GTK2 builds, eliminate this dependency when building with GTK3.
thesquash commented 7 months ago (Migrated from github.com)
Owner

I think I found all instances where GTK+ 2 libraries and header files are expected, but I am sure that my solutions are not optimal. I know it’s unfortunate, but remember this is my first contribution.

For starters, the old-configure.in file contains a reference to GTK+ 2 even if a GTK+ 3 version is to be built. Notice the line starting with PKG_CHECK_MODULES(MOZ_GTK2, near the bottom of the excerpt:

 if test "$MOZ_WIDGET_TOOLKIT" = gtk3; then
   PKG_CHECK_MODULES(MOZ_GTK3, gtk+-3.0 >= $GTK3_VERSION gtk+-unix-print-3.0 glib-2.0 gobject-2.0 $GDK_PACKAGES)
   MOZ_GTK3_CFLAGS="-I${_topsrcdir}/widget/gtk/compat-gtk3 $MOZ_GTK3_CFLAGS"
   TK_CFLAGS=$MOZ_GTK3_CFLAGS
   TK_LIBS=$MOZ_GTK3_LIBS
   dnl GDK_VERSION_MIN_REQUIRED is not set here as GDK3 deprecated warnings
   dnl are suppressed by widget/gtk/compat-gtk3/gdk/gdkversionmacros.h.
   AC_DEFINE_UNQUOTED(GDK_VERSION_MAX_ALLOWED,$GDK_VERSION_MAX_ALLOWED)
   GLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32
 fi
 if test "$MOZ_WIDGET_TOOLKIT" = gtk2; then
   GLIB_VERSION_MAX_ALLOWED=$GLIB_VERSION_MIN_REQUIRED
 fi
 if test "$MOZ_ENABLE_GTK"; then
   if test "$MOZ_X11"; then
     GDK_PACKAGES=gdk-x11-2.0
   fi
   AC_DEFINE_UNQUOTED(GLIB_VERSION_MIN_REQUIRED,$GLIB_VERSION_MIN_REQUIRED)
   AC_DEFINE_UNQUOTED(GLIB_VERSION_MAX_ALLOWED,$GLIB_VERSION_MAX_ALLOWED)

   PKG_CHECK_MODULES(MOZ_GTK2, gtk+-2.0 >= $GTK2_VERSION gtk+-unix-print-2.0 glib-2.0 >= $GLIB_VERSION gobject-2.0 $GDK_PACKAGES)
   MOZ_GTK2_CFLAGS="-I${_topsrcdir}/widget/gtk/compat $MOZ_GTK2_CFLAGS"
 fi
 if test "$MOZ_WIDGET_TOOLKIT" = gtk2; then
   TK_CFLAGS=$MOZ_GTK2_CFLAGS
   TK_LIBS=$MOZ_GTK2_LIBS
 fi

That is the first thing that would need to be changed: The fi, followed by if test "$MOZ_ENABLE_GTK"; then, should be removed.

The plug-ins support also seems to be a sticky wicket: Most of the dependencies upon GTK+ 2 are for plug-in support. Based on my own tests however even GTK+ 2-based plug-ins don’t seem to be adversely affected by my patches. Almost all of the plug-in layer’s dependencies on GTK+ 2 were caused by one compatibility layer for Netscape 4.x-era plug-ins: GtkXtBin. As far as I can tell, GtkXtBin actually crashes (for me at least) unless UXP is built against GTK+ 2. (It’s another topic, but it’s questionable exactly what purpose GtkXtBin serves anymore.)

diff -uprN uxp-original/dom/plugins/ipc/moz.build uxp-patched/dom/plugins/ipc/moz.build
--- uxp-original/dom/plugins/ipc/moz.build	2020-07-30 05:37:13.000000000 -0400
+++ uxp-patched/dom/plugins/ipc/moz.build	2020-08-18 14:55:40.548143359 -0400
@@ -121,11 +121,7 @@ LOCAL_INCLUDES += [
 
 DEFINES['FORCE_PR_LOG'] = True
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gtk3':
-    CXXFLAGS += CONFIG['TK_CFLAGS']
-else:
-    # Force build against gtk+2 for struct offsets and such.
-    CXXFLAGS += CONFIG['MOZ_GTK2_CFLAGS']
+CXXFLAGS += CONFIG['TK_CFLAGS']
 
 CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
 
diff -uprN uxp-original/dom/plugins/ipc/PluginInstanceChild.cpp uxp-patched/dom/plugins/ipc/PluginInstanceChild.cpp
--- uxp-original/dom/plugins/ipc/PluginInstanceChild.cpp	2020-07-30 05:37:13.000000000 -0400
+++ uxp-patched/dom/plugins/ipc/PluginInstanceChild.cpp	2020-08-19 12:33:46.736239327 -0400
@@ -52,7 +52,9 @@ using namespace std;
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include <gdk/gdk.h>
+#if MOZ_WIDGET_GTK == 2
 #include "gtk2xtbin.h"
+#endif
 
 #elif defined(OS_WIN)
 
@@ -152,7 +154,7 @@ PluginInstanceChild::PluginInstanceChild
     , mAsyncInvalidateTask(0)
     , mCachedWindowActor(nullptr)
     , mCachedElementActor(nullptr)
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
     , mXEmbed(false)
 #endif // MOZ_WIDGET_GTK
 #if defined(OS_WIN)
@@ -201,7 +203,7 @@ PluginInstanceChild::PluginInstanceChild
 #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
     mWindow.ws_info = &mWsInfo;
     memset(&mWsInfo, 0, sizeof(mWsInfo));
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
     mWsInfo.display = nullptr;
     mXtClient.top_widget = nullptr;
 #else
@@ -610,7 +612,7 @@ PluginInstanceChild::NPN_SetValue(NPPVar
             return NPERR_GENERIC_ERROR;
 
         NPWindowType newWindowType = windowed ? NPWindowTypeWindow : NPWindowTypeDrawable;
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
         if (mWindow.type != newWindowType && mWsInfo.display) {
            // plugin type has been changed but we already have a valid display
            // so update it for the recent plugin mode
@@ -1202,7 +1204,7 @@ bool PluginInstanceChild::CreateWindow(c
                       aWindow.x, aWindow.y,
                       aWindow.width, aWindow.height));
 
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
     if (mXEmbed) {
         mWindow.window = reinterpret_cast<void*>(aWindow.window);
     }
@@ -1231,7 +1233,7 @@ void PluginInstanceChild::DeleteWindow()
   if (!mWindow.window)
       return;
 
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
   if (mXtClient.top_widget) {     
       xt_client_unrealize(&mXtClient);
       xt_client_destroy(&mXtClient); 
@@ -1313,7 +1315,7 @@ PluginInstanceChild::AnswerNPP_SetWindow
         CreateWindow(aWindow);
     }
 
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
     if (mXEmbed && gtk_check_version(2,18,7) != nullptr) { // older
         if (aWindow.type == NPWindowTypeWindow) {
             GdkWindow* socket_window = gdk_window_lookup(static_cast<GdkNativeWindow>(aWindow.window));
@@ -1439,7 +1441,7 @@ PluginInstanceChild::AnswerNPP_SetWindow
 bool
 PluginInstanceChild::Initialize()
 {
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
     NPError rv;
 
     if (mWsInfo.display) {
@@ -4650,7 +4652,7 @@ PluginInstanceChild::Destroy()
 
     mPendingAsyncCalls.Clear();
     
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
     if (mWindow.type == NPWindowTypeWindow && !mXEmbed) {
       xt_client_xloop_destroy();
     }
diff -uprN uxp-original/dom/plugins/ipc/PluginInstanceChild.h uxp-patched/dom/plugins/ipc/PluginInstanceChild.h
--- uxp-original/dom/plugins/ipc/PluginInstanceChild.h	2020-07-30 05:37:13.000000000 -0400
+++ uxp-patched/dom/plugins/ipc/PluginInstanceChild.h	2020-08-19 11:51:36.556135241 -0400
@@ -35,7 +35,7 @@
 
 #include <map>
 
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
 #include "gtk2xtbin.h"
 #endif
 
@@ -458,7 +458,7 @@ private:
 
 #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
     NPSetWindowCallbackStruct mWsInfo;
-#ifdef MOZ_WIDGET_GTK
+#if MOZ_WIDGET_GTK == 2
     bool mXEmbed;
     XtClient mXtClient;
 #endif

And a little cleanup work has to be done in PluginModuleChild.cpp:

diff -uprN uxp-original/dom/plugins/ipc/PluginModuleChild.cpp uxp-patched/dom/plugins/ipc/PluginModuleChild.cpp
--- uxp-original/dom/plugins/ipc/PluginModuleChild.cpp	2020-07-30 05:37:13.000000000 -0400
+++ uxp-patched/dom/plugins/ipc/PluginModuleChild.cpp	2020-08-19 12:52:01.880284378 -0400
@@ -13,6 +13,7 @@
 
 #ifdef MOZ_WIDGET_GTK
 #include <gtk/gtk.h>
+#include <gtk/gtkx.h>
 #endif
 
 #include "nsIFile.h"
@@ -1094,7 +1095,7 @@ _getvalue(NPP aNPP,
         case NPNVSupportsWindowless:
             *(NPBool*)aValue = PluginModuleChild::GetChrome()->Settings().supportsWindowless();
             return NPERR_NO_ERROR;
-#if defined(MOZ_WIDGET_GTK)
+#if MOZ_WIDGET_GTK == 2
         case NPNVxDisplay: {
             if (aNPP) {
                 return InstCast(aNPP)->NPN_GetValue(aVariable, aValue);

And for the famed MozGTK wrapper libraries -- the libraries which I still don’t understand completely, but seem to be stub functions which crash the UXP application if any component attempts to use a GTK+ 2 symbol / function: I found that you can’t just remove them willy-nilly, because Mozilla inserted a Cairo bug workaround in the library. Hence I spun the workaround off into a separate C source file and then removed the code to build MozGTK:

diff -uprN uxp-original/widget/gtk/gtk3frictionworkarounds.c uxp-patched/widget/gtk/gtk3frictionworkarounds.c
--- uxp-original/widget/gtk/gtk3frictionworkarounds.c     1969-12-31 19:00:00.000000000 -0500
+++ uxp-patched/widget/gtk/gtk3frictionworkarounds.c      2020-08-21 20:30:01.616049093 -0400
@@ -0,0 +1,16 @@
+/*
+ * This file was added by Gordon N. Squash.  Please see his original patch
+ * for details on what this code is for.  If you have not received his patch
+ * then at least understand that THIS IS NOT THE OFFICIAL UXP SOURCE CODE IN
+ * ANY WAY, SHAPE OR FORM:  IT IS A PATCHED VERSION.  DO NOT CONTACT THE
+ * ORIGINAL DEVELOPERS OF UXP OR MOZILLA FOR SUPPORT OF THIS CODE.
+ */
+
+#include "mozilla/Types.h"
+#include <X11/Xlib.h>
+
+MOZ_EXPORT Bool
+XShmQueryExtension(Display* aDisplay)
+{
+  return False;
+}
diff -uprN uxp-original/widget/gtk/moz.build uxp-patched/widget/gtk/moz.build
--- uxp-original/widget/gtk/moz.build     2020-08-20 21:24:39.148073190 -0400
+++ uxp-patched/widget/gtk/moz.build      2020-08-21 20:31:09.660050615 -0400
@@ -104,6 +104,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk2
 else:
     UNIFIED_SOURCES += [
         'gtk3drawing.cpp',
+        'gtk3frictionworkarounds.c',
         'nsApplicationChooser.cpp',
         'WidgetStyleCache.cpp',
     ]

(That is the original message I included in my patch as a warning that my patch is unofficial.) And as for no longer building MozGTK:

diff -uprN uxp-original/config/recurse.mk uxp-patched/config/recurse.mk
--- uxp-original/config/recurse.mk	2020-07-30 05:37:13.000000000 -0400
+++ uxp-patched/config/recurse.mk	2020-08-19 13:12:24.228334662 -0400
@@ -161,9 +161,9 @@ endif
 
 # Interdependencies that moz.build world don't know about yet for compilation.
 # Note some others are hardcoded or "guessed" in recursivemake.py and emitter.py
-ifeq ($(MOZ_WIDGET_TOOLKIT),gtk3)
-toolkit/library/target: widget/gtk/mozgtk/gtk3/target
-endif
+#ifeq ($(MOZ_WIDGET_TOOLKIT),gtk3)
+#toolkit/library/target: widget/gtk/mozgtk/gtk3/target
+#endif
 ifdef MOZ_LDAP_XPCOM
 ldap/target: config/external/nss/target mozglue/build/target
 toolkit/library/target: ldap/target
diff -uprN uxp-original/toolkit/library/moz.build uxp-patched/toolkit/library/moz.build
--- uxp-original/toolkit/library/moz.build	2020-07-30 05:37:13.000000000 -0400
+++ uxp-patched/toolkit/library/moz.build	2020-08-19 14:14:17.820487430 -0400
@@ -117,10 +117,10 @@ if CONFIG['USE_ICU']:
         'icu',
     ]
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
-    USE_LIBS += [
-        'mozgtk_stub',
-    ]
+#if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
+#    USE_LIBS += [
+#        'mozgtk_stub',
+#    ]
 
 if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT'] or \
         CONFIG['MOZ_TREE_FREETYPE']:
@@ -231,16 +231,18 @@ if CONFIG['MOZ_ENABLE_DBUS']:
     OS_LIBS += CONFIG['MOZ_DBUS_GLIB_LIBS']
 
 if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
-    if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
-        OS_LIBS += [l for l in CONFIG['TK_LIBS']
-            if l not in ('-lgtk-3', '-lgdk-3')]
-    else:
-        OS_LIBS += CONFIG['TK_LIBS']
+#    if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
+#        OS_LIBS += [l for l in CONFIG['TK_LIBS']
+#            if l not in ('-lgtk-3', '-lgdk-3')]
+#    else:
+#        OS_LIBS += CONFIG['TK_LIBS']
+    OS_LIBS += CONFIG['TK_LIBS']
     OS_LIBS += CONFIG['XLDFLAGS']
     OS_LIBS += CONFIG['XLIBS']
     OS_LIBS += CONFIG['XEXT_LIBS']
     OS_LIBS += CONFIG['MOZ_PANGO_LIBS']
-    OS_LIBS += CONFIG['XT_LIBS']
+    if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk2':
+        OS_LIBS += CONFIG['XT_LIBS']
     OS_LIBS += [
         'gthread-2.0',
     ]
diff -uprN uxp-original/widget/gtk/moz.build uxp-patched/widget/gtk/moz.build
--- uxp-original/widget/gtk/moz.build	2020-07-30 05:37:13.000000000 -0400
+++ uxp-patched/widget/gtk/moz.build	2020-08-19 12:31:16.304233138 -0400
@@ -4,8 +4,8 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
-    DIRS += ['mozgtk']
+#if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
+#    DIRS += ['mozgtk']
 
 EXPORTS += [
     'mozcontainer.h',
diff -uprN uxp-original/widget/moz.build uxp-patched/widget/moz.build
--- uxp-original/widget/moz.build	2020-07-30 05:37:13.000000000 -0400
+++ uxp-patched/widget/moz.build	2020-08-18 15:01:26.856151106 -0400
@@ -53,7 +53,7 @@ if toolkit in ('cocoa', 'gtk2', 'gtk3'):
 if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
     DIRS += ['gtk']
 
-    if CONFIG['MOZ_X11']:
+    if CONFIG['MOZ_X11'] and CONFIG['MOZ_WIDGET_TOOKIT'] == 'gtk2':
         DIRS += ['gtkxtbin']
 
 XPIDL_SOURCES += [

Last but not least, UXP applications need to be changed oh-so-slightly to compensate for the loss of MozGTK. The following example is for Pale Moon:

diff -uprN palemoon-28.12.0-original/palemoon/installer/package-manifest.in palemoon-28.12.0-patched/palemoon/installer/package-manifest.in
--- palemoon-28.12.0-original/palemoon/installer/package-manifest.in	2020-07-30 06:09:43.000000000 -0400
+++ palemoon-28.12.0-patched/palemoon/installer/package-manifest.in	2020-08-20 20:57:55.116007204 -0400
@@ -103,10 +103,6 @@
 #ifdef MOZ_ICU_DATA_ARCHIVE
 @RESPATH@/@ICU_DATA_FILE@
 #endif
-#ifdef MOZ_GTK3
-@BINPATH@/@DLL_PREFIX@mozgtk@DLL_SUFFIX@
-@BINPATH@/gtk2/@DLL_PREFIX@mozgtk@DLL_SUFFIX@
-#endif
 
 [browser]
 ; [Base Browser Files]
I think I found all instances where GTK+ 2 libraries and header files are expected, but I am sure that my solutions are not optimal. I know it's unfortunate, but remember this is my first contribution. For starters, the `old-configure.in` file contains a reference to GTK+ 2 even if a GTK+ 3 version is to be built. Notice the line starting with `PKG_CHECK_MODULES(MOZ_GTK2`, near the bottom of the excerpt: if test "$MOZ_WIDGET_TOOLKIT" = gtk3; then PKG_CHECK_MODULES(MOZ_GTK3, gtk+-3.0 >= $GTK3_VERSION gtk+-unix-print-3.0 glib-2.0 gobject-2.0 $GDK_PACKAGES) MOZ_GTK3_CFLAGS="-I${_topsrcdir}/widget/gtk/compat-gtk3 $MOZ_GTK3_CFLAGS" TK_CFLAGS=$MOZ_GTK3_CFLAGS TK_LIBS=$MOZ_GTK3_LIBS dnl GDK_VERSION_MIN_REQUIRED is not set here as GDK3 deprecated warnings dnl are suppressed by widget/gtk/compat-gtk3/gdk/gdkversionmacros.h. AC_DEFINE_UNQUOTED(GDK_VERSION_MAX_ALLOWED,$GDK_VERSION_MAX_ALLOWED) GLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32 fi if test "$MOZ_WIDGET_TOOLKIT" = gtk2; then GLIB_VERSION_MAX_ALLOWED=$GLIB_VERSION_MIN_REQUIRED fi if test "$MOZ_ENABLE_GTK"; then if test "$MOZ_X11"; then GDK_PACKAGES=gdk-x11-2.0 fi AC_DEFINE_UNQUOTED(GLIB_VERSION_MIN_REQUIRED,$GLIB_VERSION_MIN_REQUIRED) AC_DEFINE_UNQUOTED(GLIB_VERSION_MAX_ALLOWED,$GLIB_VERSION_MAX_ALLOWED) PKG_CHECK_MODULES(MOZ_GTK2, gtk+-2.0 >= $GTK2_VERSION gtk+-unix-print-2.0 glib-2.0 >= $GLIB_VERSION gobject-2.0 $GDK_PACKAGES) MOZ_GTK2_CFLAGS="-I${_topsrcdir}/widget/gtk/compat $MOZ_GTK2_CFLAGS" fi if test "$MOZ_WIDGET_TOOLKIT" = gtk2; then TK_CFLAGS=$MOZ_GTK2_CFLAGS TK_LIBS=$MOZ_GTK2_LIBS fi That is the first thing that would need to be changed: The `fi`, followed by `if test "$MOZ_ENABLE_GTK"; then`, should be removed. The plug-ins support also seems to be a sticky wicket: Most of the dependencies upon GTK+ 2 are for plug-in support. Based on my own tests however even GTK+ 2-based plug-ins don't seem to be adversely affected by my patches. Almost all of the plug-in layer's dependencies on GTK+ 2 were caused by one compatibility layer for Netscape 4.x-era plug-ins: GtkXtBin. As far as I can tell, GtkXtBin actually crashes (for me at least) unless UXP is *built* against GTK+ 2. (It's another topic, but it's questionable exactly what purpose GtkXtBin serves anymore.) diff -uprN uxp-original/dom/plugins/ipc/moz.build uxp-patched/dom/plugins/ipc/moz.build --- uxp-original/dom/plugins/ipc/moz.build 2020-07-30 05:37:13.000000000 -0400 +++ uxp-patched/dom/plugins/ipc/moz.build 2020-08-18 14:55:40.548143359 -0400 @@ -121,11 +121,7 @@ LOCAL_INCLUDES += [ DEFINES['FORCE_PR_LOG'] = True -if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gtk3': - CXXFLAGS += CONFIG['TK_CFLAGS'] -else: - # Force build against gtk+2 for struct offsets and such. - CXXFLAGS += CONFIG['MOZ_GTK2_CFLAGS'] +CXXFLAGS += CONFIG['TK_CFLAGS'] CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS'] diff -uprN uxp-original/dom/plugins/ipc/PluginInstanceChild.cpp uxp-patched/dom/plugins/ipc/PluginInstanceChild.cpp --- uxp-original/dom/plugins/ipc/PluginInstanceChild.cpp 2020-07-30 05:37:13.000000000 -0400 +++ uxp-patched/dom/plugins/ipc/PluginInstanceChild.cpp 2020-08-19 12:33:46.736239327 -0400 @@ -52,7 +52,9 @@ using namespace std; #include <gtk/gtk.h> #include <gdk/gdkx.h> #include <gdk/gdk.h> +#if MOZ_WIDGET_GTK == 2 #include "gtk2xtbin.h" +#endif #elif defined(OS_WIN) @@ -152,7 +154,7 @@ PluginInstanceChild::PluginInstanceChild , mAsyncInvalidateTask(0) , mCachedWindowActor(nullptr) , mCachedElementActor(nullptr) -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 , mXEmbed(false) #endif // MOZ_WIDGET_GTK #if defined(OS_WIN) @@ -201,7 +203,7 @@ PluginInstanceChild::PluginInstanceChild #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX) mWindow.ws_info = &mWsInfo; memset(&mWsInfo, 0, sizeof(mWsInfo)); -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 mWsInfo.display = nullptr; mXtClient.top_widget = nullptr; #else @@ -610,7 +612,7 @@ PluginInstanceChild::NPN_SetValue(NPPVar return NPERR_GENERIC_ERROR; NPWindowType newWindowType = windowed ? NPWindowTypeWindow : NPWindowTypeDrawable; -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 if (mWindow.type != newWindowType && mWsInfo.display) { // plugin type has been changed but we already have a valid display // so update it for the recent plugin mode @@ -1202,7 +1204,7 @@ bool PluginInstanceChild::CreateWindow(c aWindow.x, aWindow.y, aWindow.width, aWindow.height)); -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 if (mXEmbed) { mWindow.window = reinterpret_cast<void*>(aWindow.window); } @@ -1231,7 +1233,7 @@ void PluginInstanceChild::DeleteWindow() if (!mWindow.window) return; -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 if (mXtClient.top_widget) { xt_client_unrealize(&mXtClient); xt_client_destroy(&mXtClient); @@ -1313,7 +1315,7 @@ PluginInstanceChild::AnswerNPP_SetWindow CreateWindow(aWindow); } -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 if (mXEmbed && gtk_check_version(2,18,7) != nullptr) { // older if (aWindow.type == NPWindowTypeWindow) { GdkWindow* socket_window = gdk_window_lookup(static_cast<GdkNativeWindow>(aWindow.window)); @@ -1439,7 +1441,7 @@ PluginInstanceChild::AnswerNPP_SetWindow bool PluginInstanceChild::Initialize() { -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 NPError rv; if (mWsInfo.display) { @@ -4650,7 +4652,7 @@ PluginInstanceChild::Destroy() mPendingAsyncCalls.Clear(); -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 if (mWindow.type == NPWindowTypeWindow && !mXEmbed) { xt_client_xloop_destroy(); } diff -uprN uxp-original/dom/plugins/ipc/PluginInstanceChild.h uxp-patched/dom/plugins/ipc/PluginInstanceChild.h --- uxp-original/dom/plugins/ipc/PluginInstanceChild.h 2020-07-30 05:37:13.000000000 -0400 +++ uxp-patched/dom/plugins/ipc/PluginInstanceChild.h 2020-08-19 11:51:36.556135241 -0400 @@ -35,7 +35,7 @@ #include <map> -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 #include "gtk2xtbin.h" #endif @@ -458,7 +458,7 @@ private: #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX) NPSetWindowCallbackStruct mWsInfo; -#ifdef MOZ_WIDGET_GTK +#if MOZ_WIDGET_GTK == 2 bool mXEmbed; XtClient mXtClient; #endif And a little cleanup work has to be done in `PluginModuleChild.cpp`: diff -uprN uxp-original/dom/plugins/ipc/PluginModuleChild.cpp uxp-patched/dom/plugins/ipc/PluginModuleChild.cpp --- uxp-original/dom/plugins/ipc/PluginModuleChild.cpp 2020-07-30 05:37:13.000000000 -0400 +++ uxp-patched/dom/plugins/ipc/PluginModuleChild.cpp 2020-08-19 12:52:01.880284378 -0400 @@ -13,6 +13,7 @@ #ifdef MOZ_WIDGET_GTK #include <gtk/gtk.h> +#include <gtk/gtkx.h> #endif #include "nsIFile.h" @@ -1094,7 +1095,7 @@ _getvalue(NPP aNPP, case NPNVSupportsWindowless: *(NPBool*)aValue = PluginModuleChild::GetChrome()->Settings().supportsWindowless(); return NPERR_NO_ERROR; -#if defined(MOZ_WIDGET_GTK) +#if MOZ_WIDGET_GTK == 2 case NPNVxDisplay: { if (aNPP) { return InstCast(aNPP)->NPN_GetValue(aVariable, aValue); And for the famed MozGTK wrapper libraries -- the libraries which I still don't understand completely, but seem to be stub functions which crash the UXP application if any component attempts to use a GTK+ 2 symbol / function: I found that you can't just remove them willy-nilly, because Mozilla inserted a Cairo bug workaround in the library. Hence I spun the workaround off into a separate C source file and then removed the code to build MozGTK: diff -uprN uxp-original/widget/gtk/gtk3frictionworkarounds.c uxp-patched/widget/gtk/gtk3frictionworkarounds.c --- uxp-original/widget/gtk/gtk3frictionworkarounds.c 1969-12-31 19:00:00.000000000 -0500 +++ uxp-patched/widget/gtk/gtk3frictionworkarounds.c 2020-08-21 20:30:01.616049093 -0400 @@ -0,0 +1,16 @@ +/* + * This file was added by Gordon N. Squash. Please see his original patch + * for details on what this code is for. If you have not received his patch + * then at least understand that THIS IS NOT THE OFFICIAL UXP SOURCE CODE IN + * ANY WAY, SHAPE OR FORM: IT IS A PATCHED VERSION. DO NOT CONTACT THE + * ORIGINAL DEVELOPERS OF UXP OR MOZILLA FOR SUPPORT OF THIS CODE. + */ + +#include "mozilla/Types.h" +#include <X11/Xlib.h> + +MOZ_EXPORT Bool +XShmQueryExtension(Display* aDisplay) +{ + return False; +} diff -uprN uxp-original/widget/gtk/moz.build uxp-patched/widget/gtk/moz.build --- uxp-original/widget/gtk/moz.build 2020-08-20 21:24:39.148073190 -0400 +++ uxp-patched/widget/gtk/moz.build 2020-08-21 20:31:09.660050615 -0400 @@ -104,6 +104,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk2 else: UNIFIED_SOURCES += [ 'gtk3drawing.cpp', + 'gtk3frictionworkarounds.c', 'nsApplicationChooser.cpp', 'WidgetStyleCache.cpp', ] (That is the original message I included in my patch as a warning that my patch is unofficial.) And as for no longer building MozGTK: diff -uprN uxp-original/config/recurse.mk uxp-patched/config/recurse.mk --- uxp-original/config/recurse.mk 2020-07-30 05:37:13.000000000 -0400 +++ uxp-patched/config/recurse.mk 2020-08-19 13:12:24.228334662 -0400 @@ -161,9 +161,9 @@ endif # Interdependencies that moz.build world don't know about yet for compilation. # Note some others are hardcoded or "guessed" in recursivemake.py and emitter.py -ifeq ($(MOZ_WIDGET_TOOLKIT),gtk3) -toolkit/library/target: widget/gtk/mozgtk/gtk3/target -endif +#ifeq ($(MOZ_WIDGET_TOOLKIT),gtk3) +#toolkit/library/target: widget/gtk/mozgtk/gtk3/target +#endif ifdef MOZ_LDAP_XPCOM ldap/target: config/external/nss/target mozglue/build/target toolkit/library/target: ldap/target diff -uprN uxp-original/toolkit/library/moz.build uxp-patched/toolkit/library/moz.build --- uxp-original/toolkit/library/moz.build 2020-07-30 05:37:13.000000000 -0400 +++ uxp-patched/toolkit/library/moz.build 2020-08-19 14:14:17.820487430 -0400 @@ -117,10 +117,10 @@ if CONFIG['USE_ICU']: 'icu', ] -if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3': - USE_LIBS += [ - 'mozgtk_stub', - ] +#if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3': +# USE_LIBS += [ +# 'mozgtk_stub', +# ] if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT'] or \ CONFIG['MOZ_TREE_FREETYPE']: @@ -231,16 +231,18 @@ if CONFIG['MOZ_ENABLE_DBUS']: OS_LIBS += CONFIG['MOZ_DBUS_GLIB_LIBS'] if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']: - if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3': - OS_LIBS += [l for l in CONFIG['TK_LIBS'] - if l not in ('-lgtk-3', '-lgdk-3')] - else: - OS_LIBS += CONFIG['TK_LIBS'] +# if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3': +# OS_LIBS += [l for l in CONFIG['TK_LIBS'] +# if l not in ('-lgtk-3', '-lgdk-3')] +# else: +# OS_LIBS += CONFIG['TK_LIBS'] + OS_LIBS += CONFIG['TK_LIBS'] OS_LIBS += CONFIG['XLDFLAGS'] OS_LIBS += CONFIG['XLIBS'] OS_LIBS += CONFIG['XEXT_LIBS'] OS_LIBS += CONFIG['MOZ_PANGO_LIBS'] - OS_LIBS += CONFIG['XT_LIBS'] + if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk2': + OS_LIBS += CONFIG['XT_LIBS'] OS_LIBS += [ 'gthread-2.0', ] diff -uprN uxp-original/widget/gtk/moz.build uxp-patched/widget/gtk/moz.build --- uxp-original/widget/gtk/moz.build 2020-07-30 05:37:13.000000000 -0400 +++ uxp-patched/widget/gtk/moz.build 2020-08-19 12:31:16.304233138 -0400 @@ -4,8 +4,8 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3': - DIRS += ['mozgtk'] +#if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3': +# DIRS += ['mozgtk'] EXPORTS += [ 'mozcontainer.h', diff -uprN uxp-original/widget/moz.build uxp-patched/widget/moz.build --- uxp-original/widget/moz.build 2020-07-30 05:37:13.000000000 -0400 +++ uxp-patched/widget/moz.build 2020-08-18 15:01:26.856151106 -0400 @@ -53,7 +53,7 @@ if toolkit in ('cocoa', 'gtk2', 'gtk3'): if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']: DIRS += ['gtk'] - if CONFIG['MOZ_X11']: + if CONFIG['MOZ_X11'] and CONFIG['MOZ_WIDGET_TOOKIT'] == 'gtk2': DIRS += ['gtkxtbin'] XPIDL_SOURCES += [ Last but not least, UXP applications need to be changed oh-so-slightly to compensate for the loss of MozGTK. The following example is for Pale Moon: diff -uprN palemoon-28.12.0-original/palemoon/installer/package-manifest.in palemoon-28.12.0-patched/palemoon/installer/package-manifest.in --- palemoon-28.12.0-original/palemoon/installer/package-manifest.in 2020-07-30 06:09:43.000000000 -0400 +++ palemoon-28.12.0-patched/palemoon/installer/package-manifest.in 2020-08-20 20:57:55.116007204 -0400 @@ -103,10 +103,6 @@ #ifdef MOZ_ICU_DATA_ARCHIVE @RESPATH@/@ICU_DATA_FILE@ #endif -#ifdef MOZ_GTK3 -@BINPATH@/@DLL_PREFIX@mozgtk@DLL_SUFFIX@ -@BINPATH@/gtk2/@DLL_PREFIX@mozgtk@DLL_SUFFIX@ -#endif [browser] ; [Base Browser Files]
mattatobin commented 3 months ago
Collaborator

According to something a user brought up in Topic 25969.. The GTK2 bits when doing GTK3 is for NPAPI plugins like flash that don’t seem to be GTK3 aware.

Of course, Mozilla just removed str8 building of GTK2 in m-r59 but had to leave the code to build the GTK2 support code when building GTK3.

We still need to have a way to decouple GTK2 from 3 because distros in the future may not provide GTK2 at all or may sabotage projects with not providing the devel support. However, we will need to note to the Flash or old NPAPI plugin die-hards that there will come a time when we can’t support those plugins on Linux due to GTK2 both of which we can’t control.

According to something a user brought up in [Topic 25969](https://forum.palemoon.org/viewtopic.php?t=25969).. The GTK2 bits when doing GTK3 is for NPAPI plugins like flash that don't seem to be GTK3 aware. Of course, Mozilla just removed str8 building of GTK2 in `m-r59` but had to leave the code to build the GTK2 support code when building GTK3. We still need to have a way to decouple GTK2 from 3 because distros in the future may not provide GTK2 at all or may sabotage projects with not providing the devel support. However, we will need to note to the Flash or old NPAPI plugin die-hards that there will come a time when we can't support those plugins on Linux due to GTK2 both of which we can't control.
mattatobin changed title from Investigate reliance on GTK2 when building GTK3 to Make building GTK2 support code optional when building with GTK3 3 months ago
mattatobin added the
C: Plugins
label 3 months ago
mattatobin added the
OS: Other
label 3 months ago
mattatobin added the
OS: Solaris / Illumos
label 3 months ago
mattatobin commented 3 months ago
Collaborator

BMO Reference: Bug 1377445

BMO Reference: [Bug 1377445](https://bugzilla.mozilla.org/show_bug.cgi?id=1377445)

If there is any progress/findings on this and the main Linux people are unavailable I am more than happy to test :)

If there is any progress/findings on this and the main Linux people are unavailable I am more than happy to test :)
mattatobin commented 3 months ago
Collaborator

You are seeing it. Posted 2 hours ago. So I dunno why you asked.

You are seeing it. Posted 2 hours ago. So I dunno why you asked.
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.