changeset 6400:913d116b0797

RT-35976 [Linux, GTK] JavaFX X11 WM_CLASS Reviewed by: anthony
author Alexander Zvegintsev
date Fri, 28 Feb 2014 22:42:18 +0400
parents 4f709b0404ba
children 2760b72aa249
files modules/graphics/src/main/native-glass/gtk/glass_general.cpp modules/graphics/src/main/native-glass/gtk/glass_general.h modules/graphics/src/main/native-glass/gtk/glass_window.cpp
diffstat 3 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/gtk/glass_general.cpp	Fri Feb 28 09:11:04 2014 -0800
+++ b/modules/graphics/src/main/native-glass/gtk/glass_general.cpp	Fri Feb 28 22:42:18 2014 +0400
@@ -108,6 +108,8 @@
 jfieldID jApplicationScreen;
 jfieldID jApplicationVisualID;
 jmethodID jApplicationReportException;
+jmethodID jApplicationGetApplication;
+jmethodID jApplicationGetName;
 
 void init_threads() {
     if (!g_thread_supported()) {
@@ -222,6 +224,9 @@
     jApplicationVisualID = env->GetStaticFieldID(jApplicationCls, "visualID", "J");
     jApplicationReportException = env->GetStaticMethodID(
         jApplicationCls, "reportException", "(Ljava/lang/Throwable;)V");
+    jApplicationGetApplication = env->GetStaticMethodID(
+        jApplicationCls, "GetApplication", "()Lcom/sun/glass/ui/Application;");
+    jApplicationGetName = env->GetMethodID(jApplicationCls, "getName", "()Ljava/lang/String;");
 
     clazz = env->FindClass("sun/misc/GThreadHelper");
     if (clazz) {
@@ -305,6 +310,21 @@
     return FALSE;
 }
 
+// The returned string should be freed with g_free().
+gchar* get_application_name() {
+    gchar* ret = NULL;
+    
+    jobject japp = mainEnv->CallStaticObjectMethod(jApplicationCls, jApplicationGetApplication);
+    CHECK_JNI_EXCEPTION_RET(mainEnv, NULL);
+    jstring jname = (jstring) mainEnv->CallObjectMethod(japp, jApplicationGetName);
+    CHECK_JNI_EXCEPTION_RET(mainEnv, NULL);
+    if (const gchar *name = mainEnv->GetStringUTFChars(jname, NULL)) {
+        ret = g_strdup(name);
+        mainEnv->ReleaseStringUTFChars(jname, name);
+    }
+    return ret;
+}
+
 gpointer glass_try_malloc_n(gsize m, gsize n, 
         gboolean zer0 /* initialized to 0 if true*/) {
     if (n > 0 && m > G_MAXSIZE / n) {
--- a/modules/graphics/src/main/native-glass/gtk/glass_general.h	Fri Feb 28 09:11:04 2014 -0800
+++ b/modules/graphics/src/main/native-glass/gtk/glass_general.h	Fri Feb 28 22:42:18 2014 +0400
@@ -185,6 +185,8 @@
     extern jfieldID jApplicationScreen; //com.sun.glass.ui.gtk.GtkApplication#screen
     extern jfieldID jApplicationVisualID; //com.sun.glass.ui.gtk.GtkApplication#visualID
     extern jmethodID jApplicationReportException; // reportException(Ljava/lang/Throwable;)V
+    extern jmethodID jApplicationGetApplication; // GetApplication()()Lcom/sun/glass/ui/Application;
+    extern jmethodID jApplicationGetName; // getName()Ljava/lang/String;
 
 #ifdef VERBOSE
 #define LOG0(msg) {printf(msg);fflush(stdout);}
@@ -220,6 +222,7 @@
 
 #define LOG_EXCEPTION(env) check_and_clear_exception(env);
 
+    gchar* get_application_name();
     void glass_throw_exception(JNIEnv * env,
             const char * exceptionClass,
             const char * exceptionMessage);
--- a/modules/graphics/src/main/native-glass/gtk/glass_window.cpp	Fri Feb 28 09:11:04 2014 -0800
+++ b/modules/graphics/src/main/native-glass/gtk/glass_window.cpp	Fri Feb 28 22:42:18 2014 +0400
@@ -630,6 +630,11 @@
     jwindow = mainEnv->NewGlobalRef(_jwindow);
 
     gtk_widget =  gtk_window_new(type == POPUP ? GTK_WINDOW_POPUP : GTK_WINDOW_TOPLEVEL);
+    
+    if (gchar* app_name = get_application_name()) {
+        gtk_window_set_wmclass(GTK_WINDOW(gtk_widget), app_name, app_name);
+        g_free(app_name);
+    }
 
     if (owner) {
         owner->add_child(this);