modal dialog implementation
gtk in, modal dialog is that the realization of the general nested by g_main_loop achieved. But the recent discovery is not the case.
Whether modal dialog, mainly by whether the call is as follows function control:
1, gtk_window_set_modal (window, TRUE); but this function is mainly to do several things:
(1), the window manager to set the value _NET_WM_STATE atom in _NET_WM_STATE_MODAL
(2), gtk_grab_add (window)
gtk_grab_add (window), the and the window in the window of a group receive the click event so do not be processed
When the modal window is hide or turn off, then call gtk_grab_remove (window) function.
2, gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DIALOG);
When you set this property after, window manager will be in the original window is always displayed in the window click on the under, even if the window has been received before the focus.
When has a main loop in run situations, in the main loop of the callback function can be new and run the other main loop, then the first block of a main loop is in the implementation of the callback function, and the new generation the main loop and a main loop because using the same context, would replace the first main loop handling the event loop.
shutdown_loop (GtkWidget * widget, GdkEventAny * evt, gpointer user_data)
GMainLoop * loop = (GMainLoop *) user_data;
if (g_main_loop_is_running (loop))
show_modal_window (GtkWidget * widget, GdkEventButton * evt)
GMainLoop * loop = g_main_loop_new (NULL, FALSE); / / NULL ensures that this loop uses default context
g_signal_connect (window, "delete_event", G_CALLBACK (shutdown_loop), loop);
When a dialog is the modal, not by whether or red part of the code (nested main loop) control, but the two functions by the above mentioned decision.
The existence of the second loop, so even in the absence of the first loop of the case, a separate call show_modal_window, still can handle the message loop.
g_object_notify to use
0 registered some
g_param_spec_boolean ("modal", P_ ("Modal"), P_ ("if true, the window is modal (other windows are not usable while this one is up)"), FALSE, GTK_PARAM_READWRITE)
1, emit some
g_object_notify (G_OBJECT (window), "modal");
2. Connect some
g_signal_connect (window, "notify:: modal", G_CALLBACK (notify_modal_received), NULL);
3, the callback function
void notify_modal_received (GtkWidget * window, GParamSpec * pspec)
printf ("notify modal received");
4. Call the sequence and running the results:
1 -> 2 -> 3
notify modal received
5.g_object_notify role Description:
Submit a "notify" signal to the 'window' object 'pspec' property
g_object_notify alternative use
We can use the exo library provides the function to be associated with the properties of multiple objects
Thunar 1.0.0 part of the code
thunar / thunar-preferences-dialog.c:
GtkWidget *button; button = gtk_radio_button_new_with_mnemonic (NULL, _("_Object1")); exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-single-click", G_OBJECT (button), "active");// Two object associated with the 'dialog->preferences' And the ' button ' property g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (g_object_notify), "active");//radio button Select send to notify active gtk_table_attach (GTK_TABLE (table), button, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); gtk_widget_show (button); button = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (button), _("_Object2")); exo_mutual_binding_new_with_negation (G_OBJECT (dialog->preferences), "misc-single-click", G_OBJECT (button), "active"); g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (g_object_notify), "active"); gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0); gtk_widget_show (button);
Binding on the control can refer to related articles: