[Xfce4-commits] <xfce4-settings:xrandr-display-settings> Add a minimal dialog for quick display setup.
Jérôme Guelfucci
noreply at xfce.org
Thu Jun 17 22:36:01 CEST 2010
Updating branch refs/heads/xrandr-display-settings
to baed6139adfecd279a9653c717f4ee98b6b5d153 (commit)
from ec593ba8472533253b3147ab32b65476ed399dd6 (commit)
commit baed6139adfecd279a9653c717f4ee98b6b5d153
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Thu Jun 17 22:34:14 2010 +0200
Add a minimal dialog for quick display setup.
Currently, it only handles two outputs. The user can choose which
screens should be activated or choose to clone the two screens. This is
work in progress.
dialogs/display-settings/Makefile.am | 10 +-
dialogs/display-settings/main.c | 259 ++++++++++++++++----
.../display-settings/minimal-display-dialog.glade | 155 ++++++++++++
3 files changed, 378 insertions(+), 46 deletions(-)
diff --git a/dialogs/display-settings/Makefile.am b/dialogs/display-settings/Makefile.am
index 36184dc..65aeb1f 100644
--- a/dialogs/display-settings/Makefile.am
+++ b/dialogs/display-settings/Makefile.am
@@ -20,6 +20,7 @@ xfce4_display_settings_SOURCES = \
xfce-randr-legacy.h \
display-dialog_ui.h \
display-dialog-xrandr1.2_ui.h \
+ minimal-display-dialog_ui.h \
display-name.c \
edid-parse.c \
edid.h
@@ -47,7 +48,8 @@ if MAINTAINER_MODE
BUILT_SOURCES = \
display-dialog_ui.h \
- display-dialog-xrandr1.2_ui.h
+ display-dialog-xrandr1.2_ui.h \
+ minimal-display-dialog_ui.h
display-dialog_ui.h: display-dialog.glade
exo-csource --static --strip-comments --strip-content --name=display_dialog_ui $< >$@
@@ -55,6 +57,9 @@ display-dialog_ui.h: display-dialog.glade
display-dialog-xrandr1.2_ui.h: display-dialog-xrandr1.2.glade
exo-csource --static --strip-comments --strip-content --name=display_dialog_xrandr12_ui $< >$@
+minimal-display-dialog_ui.h: minimal-display-dialog.glade
+ exo-csource --static --strip-comments --strip-content --name=minimal_display_dialog_ui $< >$@
+
endif
desktopdir = $(datadir)/applications
@@ -66,7 +71,8 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
EXTRA_DIST = \
$(desktop_in_files) \
display-dialog.glade \
- display-dialog-xrandr1.2.glade
+ display-dialog-xrandr1.2.glade \
+ minimal-display-dialog.glade
DISTCLEANFILES = \
$(desktop_DATA)
diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index 43239f4..4e9d1fe 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -45,6 +45,7 @@
#include "display-dialog_ui.h"
#ifdef HAS_RANDR_ONE_POINT_TWO
#include "display-dialog-xrandr1.2_ui.h"
+#include "minimal-display-dialog_ui.h"
#endif
enum
@@ -64,7 +65,6 @@ enum
-
/* xrandr rotation name conversion */
static const XfceRotation rotation_names[] =
{
@@ -91,9 +91,19 @@ static const XfceRotation reflection_names[] =
/* option entries */
static gboolean opt_version = FALSE;
+#ifdef HAS_RANDR_ONE_POINT_TWO
+static gboolean minimal = FALSE;
+#endif
static GOptionEntry option_entries[] =
{
{ "version", 'v', 0, G_OPTION_ARG_NONE, &opt_version, N_("Version information"), NULL },
+ #ifdef HAS_RANDR_ONE_POINT_TWO
+ {
+ "minimal", 'm', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &minimal,
+ N_("Minimal interface to set up an external output"),
+ NULL
+ },
+ #endif
{ NULL }
};
@@ -776,6 +786,80 @@ screen_on_event (GdkXEvent *xevent,
/* Pass the event on to GTK+ */
return GDK_FILTER_CONTINUE;
}
+
+
+
+static void
+display_settings_minimal_dialog_response (GtkDialog *dialog,
+ gint response_id,
+ GtkBuilder *builder)
+{
+ if (response_id == 1)
+ {
+ /* OK */
+ GObject *first_screen_radio;
+ GObject *second_screen_radio;
+ GObject *both_radio;
+ gboolean use_first_screen;
+ gboolean use_second_screen;
+ gboolean use_both;
+ gint first;
+ gint second;
+ gint n;
+
+ first = second = -1;
+
+ for (n = 0; n < xfce_randr->resources->noutput; n++)
+ {
+ if (xfce_randr->status[n] != XFCE_OUTPUT_STATUS_NONE)
+ {
+ if (first < 0)
+ first = n;
+ else if (second < 0)
+ second = n;
+ else
+ break;
+ }
+ }
+
+ first_screen_radio = gtk_builder_get_object (builder, "radiobutton1");
+ second_screen_radio = gtk_builder_get_object (builder, "radiobutton2");
+ both_radio = gtk_builder_get_object (builder, "radiobutton3");
+
+ use_first_screen =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (first_screen_radio));
+ use_second_screen =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (second_screen_radio));
+ use_both =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (both_radio));
+
+ if (use_first_screen)
+ {
+ xfce_randr->mode[first] = xfce_randr->preferred_mode[first];
+ xfce_randr->mode[second] = None;
+ }
+ else if (use_second_screen)
+ {
+ xfce_randr->mode[second] = xfce_randr->preferred_mode[second];
+ xfce_randr->mode[first] = None;
+ }
+ else
+ {
+ if (xfce_randr->clone_modes[0] != None)
+ {
+ xfce_randr->mode[first] = xfce_randr->clone_modes[0];
+ xfce_randr->mode[second] = xfce_randr->clone_modes[0];
+ }
+ }
+
+ xfce_randr_save (xfce_randr, "AutoConfigSecondary", display_channel);
+ gtk_main_quit ();
+ }
+ else
+ {
+ gtk_main_quit ();
+ }
+}
#endif
@@ -892,64 +976,151 @@ main (gint argc, gchar **argv)
if (xfce_titled_dialog_get_type () == 0)
return EXIT_FAILURE;
- /* load the Gtk user-interface file */
- builder = gtk_builder_new ();
#ifdef HAS_RANDR_ONE_POINT_TWO
- if (xfce_randr != NULL)
+ if (!minimal)
{
- ui_ret = gtk_builder_add_from_string (builder, display_dialog_xrandr12_ui,
- display_dialog_xrandr12_ui_length, &error);
- }
- else
#endif
- {
- ui_ret = gtk_builder_add_from_string (builder, display_dialog_ui,
- display_dialog_ui_length, &error);
- }
+ /* load the Gtk user-interface file */
+ builder = gtk_builder_new ();
+ #ifdef HAS_RANDR_ONE_POINT_TWO
+ if (xfce_randr != NULL)
+ {
+ ui_ret = gtk_builder_add_from_string (builder, display_dialog_xrandr12_ui,
+ display_dialog_xrandr12_ui_length, &error);
+ }
+ else
+ #endif
+ {
+ ui_ret = gtk_builder_add_from_string (builder, display_dialog_ui,
+ display_dialog_ui_length, &error);
+ }
- if (ui_ret != 0)
- {
- /* build the dialog */
- dialog = display_settings_dialog_new (builder);
- g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (display_settings_dialog_response), builder);
+ if (ui_ret != 0)
+ {
+ /* build the dialog */
+ dialog = display_settings_dialog_new (builder);
+ g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (display_settings_dialog_response), builder);
-#ifdef HAS_RANDR_ONE_POINT_TWO
- if (xfce_randr != NULL)
+ #ifdef HAS_RANDR_ONE_POINT_TWO
+ if (xfce_randr != NULL)
+ {
+ XFCE_RANDR_EVENT_BASE (xfce_randr) = event_base;
+ /* set up notifications */
+ XRRSelectInput (gdk_x11_display_get_xdisplay (display),
+ GDK_WINDOW_XID (gdk_get_default_root_window ()),
+ RRScreenChangeNotifyMask);
+ gdk_x11_register_standard_event_type (display,
+ event_base,
+ RRNotify + 1);
+ gdk_window_add_filter (gdk_get_default_root_window (), screen_on_event, builder);
+ }
+ #endif
+
+ /* show the dialog */
+ gtk_widget_show (dialog);
+
+ /* To prevent the settings dialog to be saved in the session */
+ gdk_set_sm_client_id ("FAKE ID");
+
+ /* enter the main loop */
+ gtk_main ();
+ }
+ else
{
- XFCE_RANDR_EVENT_BASE (xfce_randr) = event_base;
- /* set up notifications */
- XRRSelectInput (gdk_x11_display_get_xdisplay (display),
- GDK_WINDOW_XID (gdk_get_default_root_window ()),
- RRScreenChangeNotifyMask);
- gdk_x11_register_standard_event_type (display,
- event_base,
- RRNotify + 1);
- gdk_window_add_filter (gdk_get_default_root_window (), screen_on_event, builder);
+ g_error ("Failed to load the UI file: %s.", error->message);
+ g_error_free (error);
}
-#endif
- /* show the dialog */
- gtk_widget_show (dialog);
+ #ifdef HAS_RANDR_ONE_POINT_TWO
+ if (xfce_randr != NULL)
+ gdk_window_remove_filter (gdk_get_default_root_window (), screen_on_event, builder);
+ #endif
- /* To prevent the settings dialog to be saved in the session */
- gdk_set_sm_client_id ("FAKE ID");
+ /* release the builder */
+ g_object_unref (G_OBJECT (builder));
- /* enter the main loop */
- gtk_main ();
+ #ifdef HAS_RANDR_ONE_POINT_TWO
}
else
{
- g_error ("Failed to load the UI file: %s.", error->message);
- g_error_free (error);
- }
+ gint n;
+ gint first, second;
-#ifdef HAS_RANDR_ONE_POINT_TWO
- if (xfce_randr != NULL)
- gdk_window_remove_filter (gdk_get_default_root_window (), screen_on_event, builder);
-#endif
+ if (xfce_randr->resources->noutput < 2 || xfce_randr == NULL)
+ goto err1;
+
+ first = second = -1;
+
+ for (n = 0; n < xfce_randr->resources->noutput; n++)
+ {
+ if (xfce_randr->status[n] != XFCE_OUTPUT_STATUS_NONE)
+ {
+ if (first < 0)
+ first = n;
+ else if (second < 0)
+ second = n;
+ else
+ break;
+ }
+ }
- /* release the builder */
- g_object_unref (G_OBJECT (builder));
+ if (first < 0 || second < 0)
+ goto err1;
+
+ builder = gtk_builder_new ();
+
+ ui_ret =
+ gtk_builder_add_from_string (builder,
+ minimal_display_dialog_ui,
+ minimal_display_dialog_ui_length,
+ &error);
+
+ if (ui_ret != 0)
+ {
+ GObject *first_screen_radio;
+ GObject *second_screen_radio;
+ gchar *screen_name;
+
+ /* Build the minimal dialog */
+ dialog = (GtkWidget *) gtk_builder_get_object (builder, "dialog1");
+ g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (display_settings_minimal_dialog_response), builder);
+
+ /* Set the radio buttons captions */
+ first_screen_radio =
+ gtk_builder_get_object (builder, "radiobutton1");
+ second_screen_radio =
+ gtk_builder_get_object (builder, "radiobutton2");
+
+ screen_name =
+ xfce_randr_friendly_name (xfce_randr,
+ xfce_randr->resources->outputs[first],
+ xfce_randr->output_info[first]->name);
+ gtk_button_set_label (GTK_BUTTON (first_screen_radio),
+ screen_name);
+ g_free (screen_name);
+
+ screen_name =
+ xfce_randr_friendly_name (xfce_randr,
+ xfce_randr->resources->outputs[second],
+ xfce_randr->output_info[second]->name);
+ gtk_button_set_label (GTK_BUTTON (second_screen_radio),
+ screen_name);
+ g_free (screen_name);
+
+ /* Show the minimal dialog and start the main loop */
+ gtk_widget_show (dialog);
+ gtk_main ();
+ }
+ else
+ {
+ g_error ("Failed to load the UI file: %s.", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (G_OBJECT (builder));
+
+ }
+#endif
err1:
diff --git a/dialogs/display-settings/minimal-display-dialog.glade b/dialogs/display-settings/minimal-display-dialog.glade
new file mode 100644
index 0000000..21792f4
--- /dev/null
+++ b/dialogs/display-settings/minimal-display-dialog.glade
@@ -0,0 +1,155 @@
+<?xml version="1.0"?>
+<interface>
+ <!-- interface-requires gtk+ 2.12 -->
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkDialog" id="dialog1">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Display settings</property>
+ <property name="resizable">False</property>
+ <property name="window_position">center</property>
+ <property name="icon_name">video-display</property>
+ <property name="type_hint">normal</property>
+ <property name="has_separator">False</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Several displays are available. Use:
+</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="xpad">20</property>
+ <property name="pixel_size">64</property>
+ <property name="icon_name">video-display</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="vbox3">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">4</property>
+ <child>
+ <object class="GtkRadioButton" id="radiobutton1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="radiobutton2">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">radiobutton1</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="radiobutton3">
+ <property name="label" translatable="yes">Both displays cloned</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Use both displays to show the same contents</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">radiobutton1</property>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="padding">4</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="button2">
+ <property name="label">gtk-cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button1">
+ <property name="label">gtk-ok</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">button2</action-widget>
+ <action-widget response="1">button1</action-widget>
+ </action-widgets>
+ </object>
+</interface>
More information about the Xfce4-commits
mailing list