Index: dialogs/display-settings/xfce-randr.h =================================================================== --- dialogs/display-settings/xfce-randr.h (revision 29288) +++ dialogs/display-settings/xfce-randr.h (working copy) @@ -89,7 +89,8 @@ -XfceRandr *xfce_randr_new (GdkDisplay *display); +XfceRandr *xfce_randr_new (GdkDisplay *display, + GError **error); void xfce_randr_free (XfceRandr *randr); Index: dialogs/display-settings/xfce-randr-legacy.h =================================================================== --- dialogs/display-settings/xfce-randr-legacy.h (revision 29288) +++ dialogs/display-settings/xfce-randr-legacy.h (working copy) @@ -61,7 +61,8 @@ -XfceRandrLegacy *xfce_randr_legacy_new (GdkDisplay *display); +XfceRandrLegacy *xfce_randr_legacy_new (GdkDisplay *display, + GError **error); void xfce_randr_legacy_free (XfceRandrLegacy *legacy); Index: dialogs/display-settings/main.c =================================================================== --- dialogs/display-settings/main.c (revision 29288) +++ dialogs/display-settings/main.c (working copy) @@ -629,6 +629,8 @@ GladeXML *gxml; GError *error = NULL; GdkDisplay *display; + gboolean succeeded = TRUE; + gint event_base, error_base; /* setup translation domain */ xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8"); @@ -666,6 +668,23 @@ return EXIT_SUCCESS; } + /* get the default display */ + display = gdk_display_get_default (); + + /* check if the randr extension is avaible on the system */ + if (!XRRQueryExtension (gdk_x11_display_get_xdisplay (display), &event_base, &error_base)) + { + dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + _("RANDR extension missing on display %s"), + gdk_display_get_name (display)); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + _("%s. The application will now exit."), _("Enable the extension and try again")); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + + return EXIT_FAILURE; + } + /* initialize xfconf */ if (!xfconf_init (&error)) { @@ -680,28 +699,33 @@ display_channel = xfconf_channel_new ("displays"); if (G_LIKELY (display_channel)) { - /* get the default display */ - display = gdk_display_get_default (); - #ifdef HAS_RANDR_ONE_POINT_TWO /* create a new xfce randr (>= 1.2) for this display * this will only work if there is 1 screen on this display */ if (gdk_display_get_n_screens (display) == 1) - xfce_randr = xfce_randr_new (display); + xfce_randr = xfce_randr_new (display, NULL); /* fall back on the legacy backend */ if (xfce_randr == NULL) +#endif { - xfce_randr_legacy = xfce_randr_legacy_new (display); + xfce_randr_legacy = xfce_randr_legacy_new (display, &error); if (G_UNLIKELY (xfce_randr_legacy == NULL)) - goto backend_failed; + { + /* show an error dialog the version is too old */ + dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + _("Failed to use the RANDR extension")); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + /* TRANSLATORS: The %s will be the error message returned from the randr backend */ + _("%s. The application will now exit."), error->message); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + g_error_free (error); + + /* leave and cleanup the data */ + goto err1; + } } -#else - /* create a legacy backend */ - xfce_randr_legacy = xfce_randr_legacy_new (display); - if (G_UNLIKELY (xfce_randr_legacy == NULL)) - goto backend_failed; -#endif /* load the dialog glade xml */ gxml = glade_xml_new_from_buffer (display_dialog_glade, display_dialog_glade_length, NULL, NULL); @@ -735,6 +759,8 @@ /* release the glade xml */ g_object_unref (G_OBJECT (gxml)); } + + err1: /* release the channel */ g_object_unref (G_OBJECT (display_channel)); @@ -753,12 +779,6 @@ /* shutdown xfconf */ xfconf_shutdown (); - return EXIT_SUCCESS; - - backend_failed: - - /* print error */ - g_error ("Creating a randr backend failed, leaving..."); - - return EXIT_FAILURE; + return (succeeded ? EXIT_SUCCESS : EXIT_FAILURE); + } Index: dialogs/display-settings/xfce-randr.c =================================================================== --- dialogs/display-settings/xfce-randr.c (revision 29288) +++ dialogs/display-settings/xfce-randr.c (working copy) @@ -34,25 +34,44 @@ #ifdef HAS_RANDR_ONE_POINT_TWO XfceRandr * -xfce_randr_new (GdkDisplay *display) +xfce_randr_new (GdkDisplay *display, + GError **error) { XfceRandr *randr; Display *xdisplay; GdkWindow *root_window; gint n; + gint major, minor; g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); - /* get the x display and the root window */ + /* get the x display */ xdisplay = gdk_x11_display_get_xdisplay (display); - root_window = gdk_get_default_root_window (); + /* check if the randr extension is available */ + if (XRRQueryVersion (xdisplay, &major, &minor) == FALSE) + { + g_set_error (error, 0, 0, _("Unable to query the RANDR extension")); + return NULL; + } + + /* we need atleast randr 1.2, 2.0 will probably break the api */ + if (major < 1 || (major == 1 && minor < 2)) + { + g_set_error (error, 0, 0, _("The RANDR version on the system (%d.%d) is too old"), major, minor); + return NULL; + } + /* allocate the structure */ randr = g_slice_new0 (XfceRandr); /* set display */ randr->display = display; + /* get the root window */ + root_window = gdk_get_default_root_window (); + /* get the screen resource */ randr->resources = XRRGetScreenResources (xdisplay, GDK_WINDOW_XID (root_window)); Index: dialogs/display-settings/xfce-randr-legacy.c =================================================================== --- dialogs/display-settings/xfce-randr-legacy.c (revision 29288) +++ dialogs/display-settings/xfce-randr-legacy.c (working copy) @@ -35,7 +35,8 @@ XfceRandrLegacy * -xfce_randr_legacy_new (GdkDisplay *display) +xfce_randr_legacy_new (GdkDisplay *display, + GError **error) { XfceRandrLegacy *legacy; gint n, num_screens; @@ -43,8 +44,10 @@ GdkWindow *root_window; Display *xdisplay; Rotation rotation; + gint major, minor; g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); /* get the number of screens on this diaply */ num_screens = gdk_display_get_n_screens (display); @@ -54,6 +57,20 @@ /* get the x display */ xdisplay = gdk_x11_display_get_xdisplay (display); + /* check if the randr extension is available */ + if (XRRQueryVersion (xdisplay, &major, &minor) == FALSE) + { + g_set_error (error, 0, 0, _("Unable to query the RANDR extension")); + return NULL; + } + + /* we need atleast randr 1.1, 2.0 will probably break the api */ + if (major < 1 || (major == 1 && minor < 1)) + { + g_set_error (error, 0, 0, _("The RANDR version on the system (%d.%d) is too old"), major, minor); + return NULL; + } + /* allocate a slice for the structure */ legacy = g_slice_new0 (XfceRandrLegacy);