diff -Nurp gnome-control-center-2.22.0-patched/capplets/display/xrandr-capplet.c gnome-control-center-2.22.0-working/capplets/display/xrandr-capplet.c --- gnome-control-center-2.22.0-patched/capplets/display/xrandr-capplet.c 2008-03-27 18:42:39.000000000 -0700 +++ gnome-control-center-2.22.0-working/capplets/display/xrandr-capplet.c 2008-03-27 19:04:50.000000000 -0700 @@ -838,25 +838,145 @@ gnome_randr_atom (void) return atom; } +struct TimeoutData { + int time; + GtkLabel *label; + GtkDialog *dialog; + gboolean timed_out; +}; + +static char * +timeout_string (int time) +{ + return g_strdup_printf (ngettext ("Testing the new settings. If you don't respond in %d second the previous settings will be restored.", "Testing the new settings. If you don't respond in %d seconds the previous settings will be restored.", time), time); +} + +static gboolean +save_timeout_callback (gpointer _data) +{ + struct TimeoutData *data = _data; + char *str; + + data->time--; + + if (data->time == 0) + { + gtk_dialog_response (data->dialog, GTK_RESPONSE_NO); + data->timed_out = TRUE; + return FALSE; + } + + str = timeout_string (data->time); + gtk_label_set_text (data->label, str); + g_free (str); + + return TRUE; +} + +static int +run_revert_dialog () +{ + GtkWidget *dialog; + GtkWidget *hbox; + GtkWidget *vbox; + GtkWidget *label; + GtkWidget *label_sec; + GtkWidget *image; + int res; + struct TimeoutData timeout_data; + guint timeout; + char *str; + + g_warning("Creating revert dialog"); + + dialog = gtk_dialog_new (); + gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 12); + gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); + gtk_window_set_title (GTK_WINDOW (dialog), _("Keep Settings")); + gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER_ALWAYS); + + label = gtk_label_new (NULL); + str = g_strdup_printf ("%s", _("Do you want to keep these screen settings?")); + gtk_label_set_markup (GTK_LABEL (label), str); + g_free (str); + image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); + + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_label_set_selectable (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + + str = timeout_string (REVERT_COUNT); + label_sec = gtk_label_new (str); + g_free (str); + gtk_label_set_line_wrap (GTK_LABEL (label_sec), TRUE); + gtk_label_set_selectable (GTK_LABEL (label_sec), TRUE); + gtk_misc_set_alignment (GTK_MISC (label_sec), 0.0, 0.5); + + hbox = gtk_hbox_new (FALSE, 6); + vbox = gtk_vbox_new (FALSE, 6); + + gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox), label_sec, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0); + gtk_dialog_add_buttons (GTK_DIALOG (dialog),_("Use _previous settings"), GTK_RESPONSE_NO, _("_Keep settings"), GTK_RESPONSE_YES, NULL); + + gtk_widget_show_all (hbox); + + timeout_data.time = REVERT_COUNT; + timeout_data.label = GTK_LABEL (label_sec); + timeout_data.dialog = GTK_DIALOG (dialog); + timeout_data.timed_out = FALSE; + + timeout = g_timeout_add (1000, save_timeout_callback, &timeout_data); + res = gtk_dialog_run (GTK_DIALOG (dialog)); + + if (!timeout_data.timed_out) + g_source_remove (timeout); + + gtk_widget_destroy (dialog); + + return res == GTK_RESPONSE_YES; +} + +static void +send_xrandr_update_message () +{ + XEvent message; + + message.xclient.type = ClientMessage; + message.xclient.message_type = gnome_randr_atom(); + message.xclient.format = 8; + + g_print ("Sending client message\n"); + + XSendEvent (gdk_x11_get_default_xdisplay(), + gdk_x11_get_default_root_xwindow(), + FALSE, + StructureNotifyMask, &message); +} + static void apply (App *app) { GError *err = NULL; - - if (configuration_save (app->current_configuration, &err)) - { - XEvent message; - message.xclient.type = ClientMessage; - message.xclient.message_type = gnome_randr_atom(); - message.xclient.format = 8; + /* Only allow the configuration to be used once */ + if (configuration_save_onetime (app->current_configuration, &err)) + { + send_xrandr_update_message (); - g_print ("Sending client message\n"); + if ( ! run_revert_dialog () ) { + g_print("Reverting to original configuration\n"); + send_xrandr_update_message (); + return; + } - XSendEvent (gdk_x11_get_default_xdisplay(), - gdk_x11_get_default_root_xwindow(), - FALSE, - StructureNotifyMask, &message); + /* Save the configuration permanently */ + configuration_save (app->current_configuration, &err); } }