diff -Nurp a/capplets/display/xrandr-capplet.c b/capplets/display/xrandr-capplet.c --- a/capplets/display/xrandr-capplet.c 2008-04-01 01:28:57.000000000 +0200 +++ b/capplets/display/xrandr-capplet.c 2008-04-02 02:26:59.000000000 +0200 @@ -30,6 +30,8 @@ #include #include +#define REVERT_COUNT 40 + typedef struct App App; struct App @@ -824,18 +826,129 @@ make_text_combo (GtkWidget *widget, int } } -static Atom -gnome_randr_atom (void) +struct TimeoutData { + int time; + GtkLabel *label; + GtkDialog *dialog; + gboolean timed_out; +}; + +static char * +timeout_string (int time) { - static Atom atom = None; + return g_strdup_printf ("Testing the new settings. If you don't respond in %d second the previous settings will be restored.", time); +} + +static gboolean +save_timeout_callback (gpointer _data) +{ + struct TimeoutData *data = _data; + char *str; + + data->time--; - if (!atom) + if (data->time == 0) { - atom = XInternAtom (gdk_x11_get_default_xdisplay(), - "_GNOME_RANDR_ATOM", FALSE); + gtk_dialog_response (data->dialog, GTK_RESPONSE_NO); + data->timed_out = TRUE; + return FALSE; } - return atom; + 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; + + 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 Atom +get_x_atom (char *atom_name) +{ + return gdk_x11_atom_to_xatom (gdk_atom_intern(atom_name, FALSE)); +} + +static void +send_xrandr_update_message (char *atom_name) +{ + XEvent message; + + message.xclient.type = ClientMessage; + message.xclient.message_type = get_x_atom (atom_name); + message.xclient.format = 8; + + g_print ("Sending event (name = %s)\n",atom_name); + + XSendEvent (gdk_x11_get_default_xdisplay(), + gdk_x11_get_default_root_xwindow(), + FALSE, + StructureNotifyMask, &message); } static void @@ -843,20 +956,22 @@ apply (App *app) { GError *err = NULL; - if (configuration_save (app->current_configuration, &err)) - { - XEvent message; + if ( ! configuration_save_test (app->current_configuration, &err)) { + g_warning("Fail to save test configuration file"); + return; + } - message.xclient.type = ClientMessage; - message.xclient.message_type = gnome_randr_atom(); - message.xclient.format = 8; + send_xrandr_update_message("_GNOME_RANDR_TEST_ATOM"); - g_print ("Sending client message\n"); + if ( ! run_revert_dialog () ) { + g_print("Reverting to original configuration\n"); + send_xrandr_update_message ("_GNOME_RANDR_ATOM"); + return; + } - XSendEvent (gdk_x11_get_default_xdisplay(), - gdk_x11_get_default_root_xwindow(), - FALSE, - StructureNotifyMask, &message); + if ( ! configuration_save (app->current_configuration, &err)) { + g_warning("Fail to save configuration file"); + return; } }