Skip to content

Commit

Permalink
Also override GtkDialog's GtkBuildable->add_child
Browse files Browse the repository at this point in the history
This fixes CSDs not being properly disabled on some dialog windows.
  • Loading branch information
chris-se committed May 19, 2016
1 parent 8311a16 commit e9a1e5b
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions gtk3-nocsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ GType g_type_register_static_simple (GType parent_type, const gchar *type_name,
}

static gtk_window_buildable_add_child_t orig_gtk_window_buildable_add_child = NULL;
static gtk_window_buildable_add_child_t orig_gtk_dialog_buildable_add_child = NULL;

static void fake_gtk_window_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *type) {
if (type && strcmp (type, "titlebar") == 0) {
Expand All @@ -623,7 +624,16 @@ static void fake_gtk_window_buildable_add_child (GtkBuildable *buildable, GtkBui
orig_gtk_window_buildable_add_child(buildable, builder, child, type);
}

static void fake_gtk_dialog_buildable_add_child (GtkBuildable *buildable, GtkBuilder *builder, GObject *child, const gchar *type) {
if (type && strcmp (type, "titlebar") == 0) {
gtk_window_set_titlebar (GTK_WINDOW (buildable), GTK_WIDGET (child));
return;
}
orig_gtk_dialog_buildable_add_child(buildable, builder, child, type);
}

static GInterfaceInitFunc orig_gtk_window_buildable_interface_init = NULL;
static GInterfaceInitFunc orig_gtk_dialog_buildable_interface_init = NULL;

static void fake_gtk_window_buildable_interface_init (GtkBuildableIface *iface, gpointer data)
{
Expand All @@ -634,13 +644,25 @@ static void fake_gtk_window_buildable_interface_init (GtkBuildableIface *iface,
// iface->set_buildable_property = gtk_window_buildable_set_buildable_property;
}

static void fake_gtk_dialog_buildable_interface_init (GtkBuildableIface *iface, gpointer data)
{
orig_gtk_dialog_buildable_interface_init(iface, data);
orig_gtk_dialog_buildable_add_child = iface->add_child;
iface->add_child = fake_gtk_dialog_buildable_add_child;
}

void g_type_add_interface_static (GType instance_type, GType interface_type, const GInterfaceInfo *info) {
if(is_compatible_gtk_version() && are_csd_disabled() && instance_type == gtk_window_type) {
if(is_compatible_gtk_version() && are_csd_disabled() && (instance_type == gtk_window_type || instance_type == gtk_dialog_type)) {
if(interface_type == GTK_TYPE_BUILDABLE) {
// register GtkBuildable interface for GtkWindow class
// register GtkBuildable interface for GtkWindow/GtkDialog class
GInterfaceInfo fake_info = *info;
orig_gtk_window_buildable_interface_init = info->interface_init;
fake_info.interface_init = (GInterfaceInitFunc)fake_gtk_window_buildable_interface_init;
if (instance_type == gtk_window_type) {
orig_gtk_window_buildable_interface_init = info->interface_init;
fake_info.interface_init = (GInterfaceInitFunc)fake_gtk_window_buildable_interface_init;
} else {
orig_gtk_dialog_buildable_interface_init = info->interface_init;
fake_info.interface_init = (GInterfaceInitFunc)fake_gtk_dialog_buildable_interface_init;
}
orig_g_type_add_interface_static (instance_type, interface_type, &fake_info);
return;
}
Expand Down

0 comments on commit e9a1e5b

Please sign in to comment.