From c994f822e77cd174da258638d9e44dfb85e001fc Mon Sep 17 00:00:00 2001 From: Sravan Kumar Lakkimsetti Date: Wed, 5 Nov 2014 18:09:17 +0530 Subject: Bug 450486 - [GTK+] Make GTK+ 2.18 the minimum supported version Change-Id: I2d07db2db9b7b6305614eea2aafd6dc266a0c70a Signed-off-by: Sravan Kumar Lakkimsetti --- .../library/eclipse.c | 6 ++ .../library/gtk/eclipseGtkCommon.c | 5 ++ .../library/gtk/eclipseGtkInit.c | 98 ++++++++++++++++++++-- 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipse.c b/features/org.eclipse.equinox.executable.feature/library/eclipse.c index c5e399e16..2f448daee 100644 --- a/features/org.eclipse.equinox.executable.feature/library/eclipse.c +++ b/features/org.eclipse.equinox.executable.feature/library/eclipse.c @@ -203,6 +203,7 @@ static _TCHAR* returnCodeMsg = _T_ECLIPSE("Java was started but returned exit co static _TCHAR* goVMMsg = _T_ECLIPSE("Start VM: %s\n"); static _TCHAR* pathMsg = _T_ECLIPSE("%s in your current PATH"); static _TCHAR* shareMsg = _T_ECLIPSE("No exit data available."); +static _TCHAR* gtkCheck = _T_ECLIPSE("GTK+ Version Check"); static _TCHAR* noVMMsg = _T_ECLIPSE("A Java Runtime Environment (JRE) or Java Development Kit (JDK)\n\ must be available in order to run %s. No Java virtual machine\n\ @@ -603,6 +604,11 @@ static int _run(int argc, _TCHAR* argv[], _TCHAR* vmArgs[]) } } +#ifndef _WIN32 +#ifndef MACOSX + displayMessage( officialName, gtkCheck ); +#endif +#endif /* the startup jarFile goes on the classpath */ if (launchMode == LAUNCH_JNI) { /* JNI launching, classpath is set using -Djava.class.path */ diff --git a/features/org.eclipse.equinox.executable.feature/library/gtk/eclipseGtkCommon.c b/features/org.eclipse.equinox.executable.feature/library/gtk/eclipseGtkCommon.c index c28593a6f..06bed2a9d 100644 --- a/features/org.eclipse.equinox.executable.feature/library/gtk/eclipseGtkCommon.c +++ b/features/org.eclipse.equinox.executable.feature/library/gtk/eclipseGtkCommon.c @@ -17,6 +17,7 @@ #include #include #include +#include #define ECLIPSE_ICON 401 @@ -52,6 +53,10 @@ void displayMessage(char* title, char* message) return; } + if (strcmp( message, _T_ECLIPSE("GTK+ Version Check")) == 0) { + return; + } + dialog = gtk.gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", message); diff --git a/features/org.eclipse.equinox.executable.feature/library/gtk/eclipseGtkInit.c b/features/org.eclipse.equinox.executable.feature/library/gtk/eclipseGtkInit.c index 92fcfaa8c..2ff651d22 100644 --- a/features/org.eclipse.equinox.executable.feature/library/gtk/eclipseGtkInit.c +++ b/features/org.eclipse.equinox.executable.feature/library/gtk/eclipseGtkInit.c @@ -17,6 +17,13 @@ struct GTK_PTRS gtk = { 1 }; /* initialize the first field "not_initialized" so we can tell when we've loaded the pointers */ +static _TCHAR* minVerMsg = _T_ECLIPSE("Starting from the Eclipse Mars (4.5) release, \nGTK+ versions below 2.18.0 are not supported.\n\nGTK+ version found is"); +static _TCHAR* minVerTitle = _T_ECLIPSE("Unsupported GTK+ 2 version found"); +static _TCHAR* gtkInitFail = _T_ECLIPSE("Unable to initialize GTK+\n"); +static int minGtkMajorVersion = 2; +static int minGtkMinorVersion = 18; +static int minGtkMicroVersion = 0; + /* tables to help initialize the function pointers */ /* functions from libgtk-x11-2.0 or libgtk-3.so.0*/ static FN_TABLE gtkFunctions[] = { @@ -78,7 +85,6 @@ static FN_TABLE x11Functions[] = { { NULL, NULL } }; - static int loadGtkSymbols( void * library, FN_TABLE * table) { int i = 0; void * fn; @@ -112,23 +118,105 @@ int loadGtk() { gdkLib = dlopen(GDK3_LIB, DLFLAGS); gtkLib = dlopen(GTK3_LIB, DLFLAGS); } - if (!gtkLib || !gdkLib) { + if (!gtkLib || !gdkLib) { //if GTK+ 2 gdkLib = dlopen(GDK_LIB, DLFLAGS); gtkLib = dlopen(GTK_LIB, DLFLAGS); setenv("SWT_GTK3","0",1); + + const char * (*func)(int, int, int); + dlerror(); + + char *gtk_version_check_ok = getenv("ECLIPSE_GTK_OK"); + if (gtk_version_check_ok == NULL) { + *(void**) (&func) = dlsym(gtkLib, "gtk_check_version"); + if (dlerror() == NULL && func) { + const char *check = (*func)(minGtkMajorVersion, minGtkMinorVersion, minGtkMicroVersion); + if ((check != NULL) && (gtk.not_initialized == 1)) { + GtkWidget* dialog; + gint result; + int gtkMajorVersion, gtkMinorVersion, gtkMicroVersion; + void *gtkMajorPtr, *gtkMinorPtr, *gtkMicroPtr; + + /* this code is applicable for GTK+ 2 only*/ + dlerror(); + gtkMajorPtr = dlsym(gtkLib, "gtk_major_version"); + if ((dlerror() != NULL) || (gtkMajorPtr == NULL)) return -1; + gtkMajorVersion = *(int *)gtkMajorPtr; + + gtkMinorPtr = dlsym(gtkLib, "gtk_minor_version"); + if ((dlerror() != NULL) || (gtkMinorPtr == NULL)) return -1; + gtkMinorVersion = *(int *)gtkMinorPtr; + + gtkMicroPtr = dlsym(gtkLib, "gtk_micro_version"); + if ((dlerror() != NULL) || (gtkMicroPtr == NULL)) return -1; + gtkMicroVersion = *(int *)gtkMicroPtr; + + + printf("%s %d.%d.%d\n", minVerMsg, gtkMajorVersion, gtkMinorVersion, gtkMicroVersion); + + objLib = dlopen(GOBJ_LIB, DLFLAGS); + pixLib = dlopen(PIXBUF_LIB, DLFLAGS); + x11Lib = dlopen(X11_LIB, DLFLAGS); + + memset(>k, 0, sizeof(struct GTK_PTRS)); + + if ( gtkLib == NULL || loadGtkSymbols(gtkLib, gtkFunctions) != 0) return -1; + if ( gdkLib == NULL || loadGtkSymbols(gdkLib, gdkFunctions) != 0) return -1; + if ( pixLib == NULL || loadGtkSymbols(pixLib, pixFunctions) != 0) return -1; + if ( objLib == NULL || loadGtkSymbols(objLib, gobjFunctions) != 0) return -1; + if ( x11Lib == NULL || loadGtkSymbols(x11Lib, x11Functions) != 0) return -1; + + /* Initialize GTK. */ + if (gtk.gtk_set_locale) gtk.gtk_set_locale(); + if (gtk.gtk_init_with_args) { + GError *error = NULL; + if (!gtk.gtk_init_with_args(0, NULL, NULL, NULL, NULL, &error)) { + printf("%s", gtkInitFail); + exit (1); + } + } + dialog = gtk.gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO, + "%s %d.%d.%d\nDo you want to continue with unsupported GTK+ version?", minVerMsg, gtkMajorVersion, gtkMinorVersion, gtkMicroVersion); + gtk.gtk_window_set_title((GtkWindow*)dialog, minVerTitle); + result = gtk.gtk_dialog_run((GtkDialog*)dialog); + switch (result) { + case GTK_RESPONSE_YES: + gtk.gtk_widget_destroy(dialog); + setenv("ECLIPSE_GTK_OK", "1", 1); + return 0; + break; + default: + gtk.gtk_widget_destroy(dialog); + dlclose(gdkLib); + dlclose(gtkLib); + gdkLib = gtkLib = NULL; + setenv("ECLIPSE_GTK_OK", "0", 1); + exit (1); + } + } + } + } else if (strcmp(gtk_version_check_ok, "0") == 0) { + exit (1); + } else { + setenv("ECLIPSE_GTK_OK", "1", 1); + } + } + + objLib = dlopen(GOBJ_LIB, DLFLAGS); pixLib = dlopen(PIXBUF_LIB, DLFLAGS); x11Lib = dlopen(X11_LIB, DLFLAGS); - + /* initialize ptr struct to 0's */ memset(>k, 0, sizeof(struct GTK_PTRS)); - + if ( gtkLib == NULL || loadGtkSymbols(gtkLib, gtkFunctions) != 0) return -1; if ( gdkLib == NULL || loadGtkSymbols(gdkLib, gdkFunctions) != 0) return -1; if ( pixLib == NULL || loadGtkSymbols(pixLib, pixFunctions) != 0) return -1; if ( objLib == NULL || loadGtkSymbols(objLib, gobjFunctions) != 0) return -1; if ( x11Lib == NULL || loadGtkSymbols(x11Lib, x11Functions) != 0) return -1; - + return 0; } -- cgit v1.2.3