[gnome-settings-daemon] wacom: Add public 'gsd_wacom_device_set_display' function



commit 3e94c6e03316aa1c92f2a1ef4e8fada7d3f27a73
Author: Jason Gerecke <killertofu gmail com>
Date:   Fri Jan 20 15:20:10 2012 -0800

    wacom: Add public 'gsd_wacom_device_set_display' function
    
    Provides a way for callers to set the 'display' key, without
    requring them to know details of the how its stored. All that
    is required is the monitor number.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=668546

 plugins/wacom/gsd-wacom-device.c |   74 +++++++++++++++++++++++++++++++++++++-
 plugins/wacom/gsd-wacom-device.h |    2 +
 2 files changed, 75 insertions(+), 1 deletions(-)
---
diff --git a/plugins/wacom/gsd-wacom-device.c b/plugins/wacom/gsd-wacom-device.c
index 66048b8..ec9697a 100644
--- a/plugins/wacom/gsd-wacom-device.c
+++ b/plugins/wacom/gsd-wacom-device.c
@@ -573,6 +573,61 @@ find_output_by_display (GsdWacomDevice *device)
 	return find_output_by_edid (edid[0], edid[1], edid[2]);
 }
 
+static GnomeRROutputInfo*
+find_output_by_monitor (GdkScreen *screen,
+			int        monitor)
+{
+	GError *error = NULL;
+	GnomeRRScreen *rr_screen;
+	GnomeRRConfig *rr_config;
+	GnomeRROutputInfo **rr_output_infos;
+	GnomeRROutputInfo *ret;
+	guint i;
+
+	ret = NULL;
+
+	rr_screen = gnome_rr_screen_new (screen, &error);
+	if (rr_screen == NULL) {
+		g_warning ("gnome_rr_screen_new() failed: %s", error->message);
+		g_error_free (error);
+		return NULL;
+	}
+
+	rr_config = gnome_rr_config_new_current (rr_screen, &error);
+	if (rr_screen == NULL) {
+		g_warning ("gnome_rr_config_new_current() failed: %s", error->message);
+		g_error_free (error);
+		g_object_unref (rr_screen);
+		return NULL;
+	}
+
+	rr_output_infos = gnome_rr_config_get_outputs (rr_config);
+
+	for (i = 0; rr_output_infos[i] != NULL; i++) {
+		GnomeRROutputInfo *info;
+		int x, y, w, h;
+
+		info = rr_output_infos[i];
+
+		if (!gnome_rr_output_info_is_active (info))
+			continue;
+
+		gnome_rr_output_info_get_geometry (info, &x, &y, &w, &h);
+		if (monitor == gdk_screen_get_monitor_at_point (screen, x, y)) {
+			ret = g_object_ref (info);
+			break;
+		}
+	}
+
+	g_object_unref (rr_config);
+	g_object_unref (rr_screen);
+
+	if (ret == NULL)
+		g_warning ("No output found for monitor %d.", monitor);
+
+	return ret;
+}
+
 static void
 set_display_by_output (GsdWacomDevice    *device,
                        GnomeRROutputInfo *rr_output_info)
@@ -617,6 +672,21 @@ set_display_by_output (GsdWacomDevice    *device,
 	g_free (o_serial);
 }
 
+
+void
+gsd_wacom_device_set_display (GsdWacomDevice *device,
+                              int             monitor)
+{
+	GnomeRROutputInfo *output;
+
+        g_return_if_fail (GSD_IS_WACOM_DEVICE (device));
+        g_return_if_fail (monitor >= 0);
+
+	output = find_output_by_monitor (gdk_screen_get_default (), monitor);
+	if (output != NULL)
+		set_display_by_output (device, output);
+}
+
 static GnomeRROutputInfo*
 find_output (GsdWacomDevice *device)
 {
@@ -674,13 +744,15 @@ calculate_transformation_matrix (const GdkRectangle mapped, const GdkRectangle d
 	return;
 }
 
-gint
+int
 gsd_wacom_device_get_display_monitor (GsdWacomDevice *device)
 {
 	gint area[4];
 	gboolean is_active;
 	GnomeRROutputInfo *rr_output_info;
 
+        g_return_val_if_fail (GSD_IS_WACOM_DEVICE (device), -1);
+
 	rr_output_info = find_output(device);
 	if (rr_output_info == NULL)
 		return -1;
diff --git a/plugins/wacom/gsd-wacom-device.h b/plugins/wacom/gsd-wacom-device.h
index da81909..56ecbeb 100644
--- a/plugins/wacom/gsd-wacom-device.h
+++ b/plugins/wacom/gsd-wacom-device.h
@@ -121,6 +121,8 @@ typedef enum {
 
 GType gsd_wacom_device_get_type     (void);
 
+void     gsd_wacom_device_set_display         (GsdWacomDevice    *device,
+                                               int                monitor);
 gint     gsd_wacom_device_get_display_monitor (GsdWacomDevice *device);
 gboolean gsd_wacom_device_get_display_matrix  (GsdWacomDevice *device,
                                                float           matrix[NUM_ELEMS_MATRIX]);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]