Re: centering child dialogs on parent windows in gtk+ 2.0



Michael Meeks <michael ximian com> writes:
> 
> 	I'm attempting to port this to Gtk+ 2.0, essentially it uses
> set_uposition to center a child over it's parent when it's not a
> transient, nor modal dialog:
>

What is it if it isn't a dialog? (Just curious, but also want to be
sure the WM spec covers this case.)
 
> static void
> center_dialog_over_rect (GtkWindow *window, GdkRectangle rect)
> {
> 	fit_rect_on_screen (&rect);
> 	gtk_widget_set_uposition (GTK_WIDGET (window), 
> 		rect.x + rect.width / 2 
> 			- GTK_WIDGET (window)->allocation.width / 2,
> 		rect.y + rect.height / 2
> 			- GTK_WIDGET (window)->allocation.height / 2);
> }
> 
> static void
> center_dialog_over_window (GtkWindow *window, GtkWindow *over)
> {
> 	GdkRectangle rect;
> 	int x, y, w, h;
> 
> 	gdk_window_get_root_origin (GTK_WIDGET (over)->window, &x, &y);
> 	gdk_window_get_size (GTK_WIDGET (over)->window, &w, &h);
> 	rect.x = x;
> 	rect.y = y;
> 	rect.width = w;
> 	rect.height = h;
> 	center_dialog_over_rect (window, rect);
> }

In the above code you could just change set_uposition to
gtk_window_move(), change get_root_origin() to
gtk_window_get_position(), and change gdk_window_get_size to
gtk_window_get_size().

> 	I tried something like:
> 
> 	GdkGeometry geometry = { 0 };
> 	geometry.win_gravity = GDK_GRAVITY_CENTER;
> 	gtk_window_set_geometry_hints (window,
> 				       GTK_WIDGET (over),
> 				       &geometry,
> 				       GDK_HINT_WIN_GRAVITY);
> 
> 	mainly because it had the text CENTER in it :-) this appeared to have
> no effect whatsoever - is that sawfish brokenness, or is this totally
> the wrong way to do it ? what is the right way ? advice much
> appreciated.

This simply changes how the arguments to gtk_window_move() are
interpreted.

Havoc



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