Hi,
Your segmentation problem is due to you using a local variable "toggle" in the function main(), but also expecting to be able to have access to the function toggle(), which you can not do in C. This was fixed by renaming the local variable.
I have slightly rewritten your code to correct that problem and re-formatted it so that it is easier to read. The main things with reformatting was to move the variable definitions in the function main() to the start of the function so that it will compile under more C compilers. I can make my compiler complain about it if I ask it to warn me about everything and be strict (note this is how I found the bug). I also added more spaces between lines, function arguments, etc., as before it was almost like reading a book with all the spaces taken out!!!!
Note I have left a bug in the application for you ;-) It is a memory leak. You are able to create and hide your second window as many times as you like, and every time you lose the reference to the old window. But you never destroy the window.
Code:
#include <gtk/gtk.h>
//the one to create after the first
GtkWidget *x;
static void create_window(int w, int h)
{
GtkWidget *newlabel;
x = gtk_window_new(GTK_WINDOW_TOPLEVEL);
newlabel = gtk_label_new("Salut Pula!");
gtk_window_set_default_size(GTK_WINDOW(x), w, h);
gtk_container_set_border_width(GTK_CONTAINER(x), 10);
gtk_container_add(GTK_CONTAINER(x), newlabel);
gtk_widget_show_all(x);
}
static void toggle(GtkWidget *widget, gpointer data)
{
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
create_window(200, 200);
} else {
gtk_widget_hide(x);
}
}
static void die(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
int main(int argc, char *argv[])
{
//window,togglebutton
GtkWidget *window;
GtkWidget *toggle_button;
//forgot it again...
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "delete-event", G_CALLBACK(die), NULL);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
toggle_button = gtk_toggle_button_new_with_label("Apasa!");
//is the problem with the "toggled" signal or the callback func?
g_signal_connect(toggle_button, "toggled", G_CALLBACK(toggle), NULL);
gtk_container_add(GTK_CONTAINER(window), toggle_button);
gtk_widget_show_all(window);
gtk_main();
return 0;
}