diff --git a/panels/wacom/gsd-wacom-device.c b/panels/wacom/gsd-wacom-device.c index 6390b0ba2..0d865cc9f 100644 --- a/panels/wacom/gsd-wacom-device.c +++ b/panels/wacom/gsd-wacom-device.c @@ -47,6 +47,17 @@ #define WACOM_ERASER_SCHEMA "org.gnome.settings-daemon.peripherals.wacom.eraser" #define WACOM_BUTTON_SCHEMA "org.gnome.settings-daemon.peripherals.wacom.tablet-button" +static struct { + GnomeRRRotation rotation; + GsdWacomRotation rotation_wacom; + const gchar *rotation_string; +} rotation_table[] = { + { GNOME_RR_ROTATION_0, GSD_WACOM_ROTATION_NONE, "none" }, + { GNOME_RR_ROTATION_90, GSD_WACOM_ROTATION_CCW, "ccw" }, + { GNOME_RR_ROTATION_180, GSD_WACOM_ROTATION_HALF, "half" }, + { GNOME_RR_ROTATION_270, GSD_WACOM_ROTATION_CW, "cw" } +}; + static WacomDeviceDatabase *db = NULL; struct GsdWacomStylusPrivate @@ -716,6 +727,18 @@ set_display_by_output (GsdWacomDevice *device, g_free (o_serial_s); } +static GsdWacomRotation +get_rotation_wacom (GnomeRRRotation rotation) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (rotation_table); i++) { + if (rotation_table[i].rotation & rotation) + return (rotation_table[i].rotation_wacom); + } + g_assert_not_reached (); +} + void gsd_wacom_device_set_display (GsdWacomDevice *device, int monitor) @@ -871,6 +894,31 @@ gsd_wacom_device_get_display_matrix (GsdWacomDevice *device, float matrix[NUM_EL return TRUE; } +GsdWacomRotation +gsd_wacom_device_get_display_rotation (GsdWacomDevice *device) +{ + GError *error = NULL; + GnomeRRScreen *rr_screen; + GnomeRROutput *rr_output; + GnomeRRRotation rotation = GNOME_RR_ROTATION_0; + + rr_screen = gnome_rr_screen_new (gdk_screen_get_default (), &error); + if (rr_screen == NULL) { + g_warning ("Failed to create GnomeRRScreen: %s", error->message); + g_error_free (error); + return -1; + } + + rr_output = find_output (rr_screen, device); + if (rr_output) { + GnomeRRCrtc *crtc = gnome_rr_output_get_crtc (rr_output); + rotation = gnome_rr_crtc_get_current_rotation (crtc); + } + g_object_unref (rr_screen); + + return get_rotation_wacom (rotation); +} + static void add_stylus_to_device (GsdWacomDevice *device, const char *settings_path, @@ -1746,6 +1794,34 @@ gsd_wacom_device_get_button (GsdWacomDevice *device, } } +GsdWacomRotation +gsd_wacom_device_rotation_name_to_type (const char *rotation) +{ + guint i; + + g_return_val_if_fail (rotation != NULL, GSD_WACOM_ROTATION_NONE); + + for (i = 0; i < G_N_ELEMENTS (rotation_table); i++) { + if (strcmp (rotation_table[i].rotation_string, rotation) == 0) + return (rotation_table[i].rotation_wacom); + } + + return GSD_WACOM_ROTATION_NONE; +} + +const char * +gsd_wacom_device_rotation_type_to_name (GsdWacomRotation type) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (rotation_table); i++) { + if (rotation_table[i].rotation_wacom == type) + return (rotation_table[i].rotation_string); + } + + return "none"; +} + GsdWacomDevice * gsd_wacom_device_create_fake (GsdWacomDeviceType type, const char *name, diff --git a/panels/wacom/gsd-wacom-device.h b/panels/wacom/gsd-wacom-device.h index b59493d9e..59c4b2777 100644 --- a/panels/wacom/gsd-wacom-device.h +++ b/panels/wacom/gsd-wacom-device.h @@ -23,6 +23,7 @@ #define __GSD_WACOM_DEVICE_MANAGER_H #include +#include "gsd-enums.h" G_BEGIN_DECLS @@ -128,6 +129,7 @@ void gsd_wacom_device_set_display (GsdWacomDevice *device, gint gsd_wacom_device_get_display_monitor (GsdWacomDevice *device); gboolean gsd_wacom_device_get_display_matrix (GsdWacomDevice *device, float matrix[NUM_ELEMS_MATRIX]); +GsdWacomRotation gsd_wacom_device_get_display_rotation (GsdWacomDevice *device); GsdWacomDevice * gsd_wacom_device_new (GdkDevice *device); GList * gsd_wacom_device_list_styli (GsdWacomDevice *device); @@ -153,6 +155,9 @@ GsdWacomTabletButton *gsd_wacom_device_get_button (GsdWacomDevice *device, GtkDirectionType *dir); int gsd_wacom_device_set_next_mode (GsdWacomDevice *device, int group_id); +GsdWacomRotation gsd_wacom_device_rotation_name_to_type (const char *rotation); +const char * gsd_wacom_device_rotation_type_to_name (GsdWacomRotation type); + /* Helper and debug functions */ GsdWacomDevice * gsd_wacom_device_create_fake (GsdWacomDeviceType type,