Skip to content

Commit a887235

Browse files
committed
Also override GObject introspection called functions
Some functions that we need to override may also be called via GObject introspection (e.g. when calling them from Python and other scripting languages), so we need to make sure that also this method of calling these functions causes our overrides to be called. To this end, override the g_function_info_prep_invoker method to replace the function pointers if necessary.
1 parent 0b54b7f commit a887235

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PKG_CONFIG ?= pkg-config
22
CFLAGS ?= -O2 -g
3-
CFLAGS += $(shell ${PKG_CONFIG} --cflags gtk+-3.0) -pthread -Wall -fPIC
3+
CFLAGS += $(shell ${PKG_CONFIG} --cflags gtk+-3.0) $(shell ${PKG_CONFIG} --cflags gobject-introspection-1.0) -pthread -Wall -fPIC
44
LDLIBS = -ldl
55

66
libdir ?= /usr/lib

gtk3-nocsd.c

+33-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <gtk/gtk.h>
3333
#include <gdk/gdk.h>
3434

35+
#include <girffi.h>
36+
3537
typedef void (*gtk_window_buildable_add_child_t) (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *type);
3638
typedef GObject* (*gtk_dialog_constructor_t) (GType type, guint n_construct_properties, GObjectConstructParam *construct_params);
3739
typedef char *(*gtk_check_version_t) (guint required_major, guint required_minor, guint required_micro);
@@ -42,6 +44,7 @@ enum {
4244
GDK_LIBRARY,
4345
GOBJECT_LIBRARY,
4446
GLIB_LIBRARY,
47+
GIREPOSITORY_LIBRARY,
4548
NUM_LIBRARIES
4649
};
4750

@@ -61,17 +64,23 @@ enum {
6164
#define GLIB_LIBRARY_SONAME "libglib-2.0.so"
6265
#endif
6366

67+
#ifndef GIREPOSITORY_LIBRARY_SONAME
68+
#define GIREPOSITORY_LIBRARY_SONAME "libgirepository-1.0.so.1"
69+
#endif
70+
6471
static const char *library_sonames[NUM_LIBRARIES] = {
6572
GTK_LIBRARY_SONAME,
6673
GDK_LIBRARY_SONAME,
6774
GOBJECT_LIBRARY_SONAME,
68-
GLIB_LIBRARY_SONAME
75+
GLIB_LIBRARY_SONAME,
76+
GIREPOSITORY_LIBRARY_SONAME
6977
};
7078

7179
static void * volatile library_handles[NUM_LIBRARIES] = {
7280
NULL,
7381
NULL,
7482
NULL,
83+
NULL,
7584
NULL
7685
};
7786

@@ -171,6 +180,7 @@ RUNTIME_IMPORT_FUNCTION(GOBJECT_LIBRARY, g_type_instance_get_private, gpointer,
171180
RUNTIME_IMPORT_FUNCTION(GOBJECT_LIBRARY, g_signal_connect_data, gulong, (gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags), (instance, detailed_signal, c_handler, data, destroy_data, connect_flags))
172181
RUNTIME_IMPORT_FUNCTION(GLIB_LIBRARY, g_getenv, gchar *, (const char *name), (name))
173182
RUNTIME_IMPORT_FUNCTION(GLIB_LIBRARY, g_logv, void, (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args), (log_domain, log_level, format, args))
183+
RUNTIME_IMPORT_FUNCTION(GIREPOSITORY_LIBRARY, g_function_info_prep_invoker, gboolean, (GIFunctionInfo *info, GIFunctionInvoker *invoker, GError **error), (info, invoker, error))
174184

175185
/* All methods that we want to overwrite are named orig_, all methods
176186
* that we just want to call (either directly or indirectrly)
@@ -209,6 +219,7 @@ RUNTIME_IMPORT_FUNCTION(GLIB_LIBRARY, g_logv, void, (const gchar *log_domain, GL
209219
#define g_getenv rtlookup_g_getenv
210220
#define g_logv rtlookup_g_logv
211221
#define g_log static_g_log
222+
#define orig_g_function_info_prep_invoker rtlookup_g_function_info_prep_invoker
212223

213224
/* Forwarding of varadic functions is tricky. */
214225
static void static_g_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...)
@@ -679,3 +690,24 @@ static gtk_window_private_info_t gtk_window_private_info ()
679690
}
680691
return info;
681692
}
693+
694+
gboolean g_function_info_prep_invoker (GIFunctionInfo *info, GIFunctionInvoker *invoker, GError **error)
695+
{
696+
static gpointer orig_set_titlebar = NULL, orig_set_show_close_button = NULL;
697+
gboolean result;
698+
699+
if (!orig_set_titlebar)
700+
orig_set_titlebar = (gpointer) find_orig_function (GTK_LIBRARY, "gtk_window_set_titlebar");
701+
if (!orig_set_show_close_button)
702+
orig_set_show_close_button = (gpointer) find_orig_function (GTK_LIBRARY, "gtk_header_bar_set_show_close_button");
703+
704+
result = orig_g_function_info_prep_invoker (info, invoker, error);
705+
if (result) {
706+
if (G_UNLIKELY (invoker->native_address == orig_set_titlebar))
707+
invoker->native_address = gtk_window_set_titlebar;
708+
if (G_UNLIKELY (invoker->native_address == orig_set_show_close_button))
709+
invoker->native_address = gtk_header_bar_set_show_close_button;
710+
}
711+
712+
return result;
713+
}

0 commit comments

Comments
 (0)