RE: [gtk-list] Re: Modality
- From: "Timothy M. Shead" <tshead sheaddataproc com>
- To: <gtk-list redhat com>
- Subject: RE: [gtk-list] Re: Modality
- Date: Thu, 12 Aug 1999 00:31:04 -0700
Thanks, this really clears things up ... my sample app really *was* modal
(in the Gtk sense) ... gtk_window_set_transient_for() took care of the
window manager side.
Cheerio,
Tim
> -----Original Message-----
> From: Havoc Pennington [mailto:hp@redhat.com]
> Sent: Wednesday, August 11, 1999 9:06 PM
> To: gtk-list@redhat.com
> Subject: [gtk-list] Re: Modality
>
>
>
> On Tue, 10 Aug 1999, Timothy M. Shead wrote:
> >
> > ... so my intent here is that window2 should capture all input
> / prevent you
> > from bringing window1 to the top of the Z order, etc. But it
> doesn't work.
> > Do I have the wrong technique, or does "modal" mean something
> different in
> > Gtk?
> >
>
> Lee has it right that to make a window modal you want to use
> gtk_window_set_modal(). Modality in Gtk means that the window is the only
> one that can receive input; try clicking widgets in the other window, they
> won't respond.
>
> You will also want to tell the window manager that the modal dialog is a
> "child" of the window the user was previously interacting with; call
> gtk_window_set_transient_for() to do this. Most window managers will then
> keep the window on top of the parent, maybe center the child window, etc;
> this is all up to the window manager though. Just don't worry about the
> exact behavior since it's not your problem if the user runs a sucky WM.
>
> You can "stack" dialogs with transient for relationships; that is, say you
> pop up a dialog from the main app window, make it transient for the main
> window; if the dialog causes a new dialog to appear, make the new dialog
> transient for the first dialog; etc. Gtk keeps a "Modal widget stack" so
> if you set a second window modal, it will get exclusive input until you
> unset it, then the previous modal window will become the active one, etc.
>
> Another useful thing to do is call gtk_widget_set_sensitive(window, FALSE)
> on the non-active windows, so the user can tell they won't accept input.
>
> A nice way to code all this I thought of the other day is:
>
> static GSList* modal_stack = NULL;
>
> void my_app_push_modal(GtkWindow* win)
> {
> GtkWindow* parent = modal_stack ? modal_stack->data : NULL;
> modal_stack = g_slist_prepend(modal_stack, win);
>
> if (parent)
> gtk_window_set_transient_for(win, parent);
>
> gtk_window_set_modal(win, TRUE);
> gtk_window_set_sensitive(win, FALSE);
> }
>
> void my_app_pop_modal()
> {
> /* undo all the above, you can guess */
>
> }
>
> Haven't tried that in practice but I think it might be nice. If you wanted
> you could associate one "modal stack" with each main app window.
>
> Havoc
>
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com <
> /dev/null
>
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]