Skip to content

Commit

Permalink
Add signal handler to the gtk_builder / glade example
Browse files Browse the repository at this point in the history
  • Loading branch information
bstpierre committed May 15, 2012
1 parent 364ed9e commit c4341d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -2,9 +2,9 @@ SRCS := $(wildcard *.c)
APPS := $(patsubst %.c,%,$(wildcard *.c))

CFLAGS := -O2 -Wall -Wextra -Werror
CFLAGS += $(shell pkg-config --cflags --libs gtk+-3.0)
CFLAGS += $(shell pkg-config --cflags --libs gtk+-3.0 gmodule-2.0)

LIBS := $(shell pkg-config --libs gtk+-3.0)
LIBS := $(shell pkg-config --libs gtk+-3.0 gmodule-2.0)

all: $(APPS)

Expand Down
18 changes: 17 additions & 1 deletion builder.c
@@ -1,6 +1,17 @@
// This example demonstrates the use of a glade UI file.
//
// Note: This file must be compiled with the linker flags emitted by
// $(pkg-config gmodule-2.0) so that the dynamic loader can find the
// signal handler at runtime. See the Makefile for implementation.

#include <gtk/gtk.h>
#include <stdio.h>

G_MODULE_EXPORT void handle_button_click(GtkButton* button,
gpointer user_data)
{
printf("click: %p, %X\n", button, *(int*)user_data);
}

int main(int argc, char** argv)
{
Expand All @@ -16,7 +27,12 @@ int main(int argc, char** argv)
GObject* window = gtk_builder_get_object(builder, "main_window");
gtk_widget_show(GTK_WIDGET(window));

// TODO: add signal handlers/actions.
// Connect the signal handlers defined in the glade file.
// (Note: if you're looking for the c++ way to do this, there's no
// support for binding C++ signal handlers. You must use 'extern
// "C"' functions as handlers.)
int my_user_data = 0xDEADBEEF;
gtk_builder_connect_signals(builder, &my_user_data);

// Quit the app when the window is closed.
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
Expand Down
14 changes: 12 additions & 2 deletions test.glade
@@ -1,8 +1,18 @@
<!-- This is a very simple XML UI file. -->

<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="main_window">
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="handle_button_click" swapped="no"/>
</object>
</child>
</object>
</interface>

0 comments on commit c4341d8

Please sign in to comment.