Centering a window...



I've used gtk_window_set_position() before to center a window,
but for some reason it's not working for me now. I'm using
GTK 1.2.6 on Linux. Here's a little test program that
reproduces the problem. I'm using gtk_window_set_position(),
but the window pops up in different spots each time I start
the program. Is there something I'm forgetting to do?

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

gint destroy(GtkWidget *widget, GdkEvent *event, gpointer data);

/* main - Constructs the GUI and initializes program variables. */
int main(int argc, char **argv)
{
   GtkWidget *box, *main_win;

   gtk_init(&argc, &argv);

   main_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(main_win), "TEST");
   gtk_widget_set_usize(main_win, 500, 500);
   gtk_signal_connect(GTK_OBJECT(main_win), "destroy",
                      GTK_SIGNAL_FUNC(destroy), NULL);
   gtk_signal_connect(GTK_OBJECT(main_win), "delete_event",
                      GTK_SIGNAL_FUNC(destroy), NULL);
   gtk_window_set_policy(GTK_WINDOW(main_win), FALSE, TRUE, TRUE);
   gtk_window_set_position(GTK_WINDOW(main_win), GTK_WIN_POS_CENTER);

   box = gtk_vbox_new(FALSE, 0);
   gtk_container_add(GTK_CONTAINER(main_win), box);

   gtk_widget_show(box);
   gtk_widget_show(main_win);

   gtk_main();
   return 0;
}

/* destroy - responsible for safely shutting down the program */
gint destroy(GtkWidget *widget, GdkEvent *event, gpointer data)
{
   gtk_main_quit();
   return FALSE;
}


Jeff "Shippy" Shipman     E-Mail: shippy cs nmt edu
CS Major / EE Minor       ICQ: 1786493
New Mexico Institute of Mining and Technology
Homepage: http://www.nmt.edu/~shippy





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]