I use this gtk_window_set_gravity to init location of window on screen. but it doesn't work. no matter what value of Gravity is specify, the location of window always at top left of screen.I try gtk_window_move function, it work well.

Can you tell me how to use gtk_window_set_gravity function ? what problem in my code?

follow by code :


/**
* extend privous sample
*/
void extends_first_window(int * p_argc, char ** p_argv[]) {
GtkWidget * window, *label;

gtk_init(p_argc, p_argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
label = gtk_label_new(NULL);


gtk_window_set_title(GTK_WINDOW(window), "hello GTK 2!");

gtk_container_set_border_width (GTK_CONTAINER(window), 10);

gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);

gtk_widget_set_events(GTK_WIDGET(window), GDK_KEY_PRESS_MASK);
//event binding
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
g_signal_connect(G_OBJECT(window), "delete-event", G_CALLBACK(delete_event), NULL);
g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(kpress_on_main_window_handler), label);


gtk_label_set_markup(GTK_LABEL(label), "<b><i>Hello World!</i></b>");

gtk_label_set_selectable(GTK_LABEL(label), TRUE);

gtk_container_add(GTK_CONTAINER(window), label);

gtk_window_set_gravity(GTK_WINDOW(window), GDK_GRAVITY_NORTH);

gtk_widget_show_all(window);

gtk_main();
}

/**
* exit main loop
*/
void destroy (GtkWidget *window, gpointer data) {
printf("Close window title --> %s\n", GTK_WINDOW(window) -> title);
gtk_main_quit ();
}

gboolean delete_event(GtkWidget *window, GdkEvent *event, gpointer data) {
if (event -> type == GDK_DELETE) {
printf("GDK_DELETE event is happened! \n");
}
return FALSE;
}

gboolean kpress_on_main_window_handler(GtkWidget *window, GdkEventKey *event, gpointer data) {
printf("press keyborde : %d\n", event -> keyval);
gtk_widget_grab_focus(GTK_WIDGET(data));
gtk_window_move(GTK_WINDOW(window), 0, 0);
return FALSE;
}


int main(int argc, char * argv[]) {
extends_first_window(&argc, &argv);
return 0;
}