1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include <stdio.h> 27 #include <linux/fb.h> 28 #include <fcntl.h> 29 #ifndef __USE_GNU // required for dladdr() & Dl_info 30 #define __USE_GNU 31 #endif 32 #include <dlfcn.h> 33 #include <sys/ioctl.h> 34 35 #include <jni.h> 36 #include <gtk/gtk.h> 37 #include <gdk/gdk.h> 38 39 #include "wrapped.h" 40 41 extern jboolean gtk_verbose; 42 43 /* 44 * cpp and dlsym don't play nicely together. Do all dynamic loading in C 45 */ 46 47 // Note added in Glib 2.36 which is >= our OEL 7.0 version of 2.36 48 // but does not seem to be in the headers properly 49 static GSettingsSchemaSource * (*_g_settings_schema_source_get_default) (void); 50 51 GSettingsSchemaSource * wrapped_g_settings_schema_source_get_default (void) 52 { 53 if(_g_settings_schema_source_get_default == NULL) { 54 _g_settings_schema_source_get_default = dlsym(RTLD_DEFAULT, "g_settings_schema_source_get_default"); 55 if (gtk_verbose && _g_settings_schema_source_get_default) { 56 fprintf(stderr, "loaded g_settings_schema_source_get_default\n"); fflush(stderr); 57 } 58 } 59 60 if(_g_settings_schema_source_get_default != NULL) { 61 return (*_g_settings_schema_source_get_default)(); 62 } 63 64 return NULL; 65 } 66 67 68 // Note added in Glib 2.36 which is >= our OEL 7.0 version of 2.36 69 // but does not seem to be in the headers properly 70 static GSettingsSchema * 71 (*_g_settings_schema_source_lookup) (GSettingsSchemaSource *source, 72 const gchar *schema_id, 73 gboolean recursive); 74 75 GSettingsSchema * 76 wrapped_g_settings_schema_source_lookup (GSettingsSchemaSource *source, 77 const gchar *schema_id, 78 gboolean recursive) 79 { 80 if(_g_settings_schema_source_lookup == NULL) { 81 _g_settings_schema_source_lookup = dlsym(RTLD_DEFAULT, "g_settings_schema_source_lookup"); 82 if (gtk_verbose && _g_settings_schema_source_lookup) { 83 fprintf(stderr, "loaded g_settings_schema_source_lookup\n"); fflush(stderr); 84 } 85 } 86 87 if(_g_settings_schema_source_lookup != NULL) { 88 return (*_g_settings_schema_source_lookup)(source, schema_id, recursive); 89 } 90 91 return NULL; 92 } 93 94 // Note added in Glib 2.40 which is > our OEL 7.0 version of 2.36 95 static gboolean (*_g_settings_schema_has_key) (GSettingsSchema *schema, const gchar *name); 96 97 gboolean wrapped_g_settings_schema_has_key (GSettingsSchema *schema, 98 const gchar *name) 99 { 100 if(_g_settings_schema_has_key == NULL) { 101 _g_settings_schema_has_key = dlsym(RTLD_DEFAULT, "g_settings_schema_has_key"); 102 if (gtk_verbose && _g_settings_schema_has_key) { 103 fprintf(stderr, "loaded g_settings_schema_has_key\n"); fflush(stderr); 104 } 105 } 106 107 if(_g_settings_schema_has_key != NULL) { 108 return (*_g_settings_schema_has_key)(schema, name); 109 } 110 111 return 0; 112 } 113 114 static void (*_g_settings_schema_unref) (GSettingsSchema *schema); 115 116 void wrapped_g_settings_schema_unref (GSettingsSchema *schema) 117 { 118 if(_g_settings_schema_unref == NULL) { 119 _g_settings_schema_unref = dlsym(RTLD_DEFAULT, "g_settings_schema_unref"); 120 if (gtk_verbose && _g_settings_schema_unref) { 121 fprintf(stderr, "loaded g_settings_schema_unref\n"); fflush(stderr); 122 } 123 } 124 125 if(_g_settings_schema_unref != NULL) { 126 (*_g_settings_schema_unref)(schema); 127 } 128 129 } 130 131 static void (*_gdk_x11_display_set_window_scale) (GdkDisplay *display, gint scale); 132 133 // Note added in libgdk 3.10 which is > our OEL 7.0 version of 3.8 134 void wrapped_gdk_x11_display_set_window_scale (GdkDisplay *display, 135 gint scale) 136 { 137 #if GTK_CHECK_VERSION(3, 0, 0) 138 if(_gdk_x11_display_set_window_scale == NULL) { 139 _gdk_x11_display_set_window_scale = dlsym(RTLD_DEFAULT, "gdk_x11_display_set_window_scale"); 140 if (gtk_verbose && _gdk_x11_display_set_window_scale) { 141 fprintf(stderr, "loaded gdk_x11_display_set_window_scale\n"); fflush(stderr); 142 } 143 } 144 #endif 145 146 if(_gdk_x11_display_set_window_scale != NULL) { 147 (*_gdk_x11_display_set_window_scale)(display, scale); 148 } 149 } 150