Re: How to Center Dialogs or Popups Over Any Widget (Source Code Included)
- From: Havoc Pennington <hp redhat com>
- To: Paul Serice <serice bigfoot com>
- Cc: gtk-app-devel Mailing List <gtk-app-devel-list gnome org>
- Subject: Re: How to Center Dialogs or Popups Over Any Widget (Source Code Included)
- Date: 19 Sep 2000 01:48:48 -0400
Paul Serice <serice bigfoot com> writes:
/*
* One of my biggest complaints about Gtk+-based programs is that
* popups never popup centered over the correct window. At best they
* come up in the middle of the display or over the mouse. More
* commonly, they quietly come up in some random location on the
* display.
*
* The correct way, IMHO, to popup a dialog is to place it in the
* center of the window responsible for popping it. The fact that it
* is centered over the window tells me that, yes, this pop up is part
* of the program underneath it. When a dialog popups up over a
* different program, it is confusing because the program underneath
* the popup has no relationship with the popup itself.
*
* What follows is an example of how to popup a dialog centered over
* any widget including a GTK_WINDOW widget. It also shows how to
* raise an iconified popup to the same place where it was originally
* iconified.
*
* If you find a better way of doing this, please let me know.
*
GTK+ 2.0 supports this natively with GTK_WIN_POS_CENTER_ON_PARENT
(parent being the transient parent from set_transient_for()).
So that will be a better way in the future.
/*
* Either I'm not doing something right or I'm not thinking about
* something right or . . . , but it seems to me that
* "gtk_widget_show()" should raise iconified windows. It does
* not. So, we have to also call gdk_window_show().
*/
gdk_window_show(dialog->window);
gtk_widget_show() simply realizes and maps the window if it isn't, it
does nothing if it already is (where "map" refers to the GTK+ flag,
not the X state). gdk_window_show() will affect the X state even if
GTK flags the widget already mapped.
GTK+ 2.0 will likely have gtk_window_set_iconified(window, FALSE) or
the like, and an "iconified" signal. (If you're not catching the theme
here, basically there's no reason you should have to do all these
weird undocumented hacks, and GTK+ should support an official nice way
to do them, so 2.0 will support nice ways.) Also we wanted to add a
present_window() function that deiconifies and raises the window, and
maybe once we have the proper WM extensions will make sure the window
is on the current desktop. present_window() will be the right thing if
you want to bring an existing dialog forward to the user's attention.
/*
* Show.
*/
gtk_widget_show(window_manager_decides_button);
gtk_widget_show(center_over_display_button);
gtk_widget_show(center_over_pointer_button);
gtk_widget_show(center_over_widget_button);
gtk_widget_show(label);
gtk_widget_show_all() would save you a lot of typing. ;-)
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]