• Welcome to Valhalla Legends Archive.
 

Terminate GTK Program On Unload and Size Problems

Started by rabbit, May 20, 2006, 10:50 AM

Previous topic - Next topic

rabbit

Right now I've got a fairly simple little GTK program with a window, TextView and ScrollWindow.  When I run my program from my terminal, it shows up in the proper size and all that, but when I run it from my context menu, it is very small and annoying.

My MAIN issue, however, is that when I click the X in the corner to kill it, the window disappears, but the program itself doesn't terminate.  I've tried a few methods, but I don't know how to kill it completely.  My code:
#include <gtk/gtk.h>

GtkWidget *window;
GtkWidget *text;
GtkWidget *sw;

void printmsg(char* msg);

int main(int argc, char *argv[])
{
gtk_init (&argc, &argv);
   
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
text = gtk_text_view_new();

gtk_window_set_resizable((GtkWindow *) window, 1);

sw = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);

gtk_container_add(GTK_CONTAINER(window), sw);

gtk_container_add(GTK_CONTAINER(sw), text);

gtk_widget_show(sw);
gtk_widget_show(text);
gtk_widget_show(window);

gtk_window_resize((GtkWindow *) window, 650, 350);

gtk_widget_show(text);
gtk_widget_show(window);

printmsg("hello\n");
printmsg("world\n");

gtk_main();
   
return 0;
}

void printmsg(char* msg)
{
GtkTextBuffer* buffer;
GtkTextIter iter;

buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
gtk_text_buffer_get_end_iter(buffer, &iter);
gtk_text_buffer_place_cursor(buffer, &iter);

gtk_text_buffer_insert_at_cursor(buffer, msg, -1);
gtk_text_buffer_get_end_iter(buffer, &iter);
gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(text), &iter, 0, TRUE, 0, 1);
}
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Kp

You must call gtk_main_quit when the top level window is destroyed.  Otherwise, gtk_main will not return.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

rabbit

I don't really know how to do that.  I figure it's not just putting it after gtk_main() (because that didn't work).
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Kp

You must register for the "destroy" signal and react to it by calling gtk_main_quit.  Just add this somewhere before you call gtk_main:

g_signal_connect (win, "destroy", G_CALLBACK (gtk_main_quit), NULL);
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

rabbit

Thanks.  You know what could be causing the size variations?
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.