Re: Rotation support in gnome-display-properties



On Tue, 2005-12-13 at 02:53 -0500, Sean D'Epagnier wrote:
> I tested out your patch.  I got an option for rotation now, but the
> only setting I can choose is Normal.  Does this depend on my hardware?
> Perhaps you should update it to only have this option if it has more
> than one setting to choose.

	This is the patch that implement that behaviour.

Regards.
-- 
Jorge P�z Burgos
Adaptia Soluciones Integrales
http://www.adaptia.es
jorge perez adaptia es
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-control-center/ChangeLog,v
retrieving revision 1.742
diff -u -p -r1.742 ChangeLog
--- ChangeLog	25 Nov 2005 20:18:23 -0000	1.742
+++ ChangeLog	13 Dec 2005 18:01:07 -0000
@@ -1,3 +1,9 @@
+2005-12-12  Jorge Perez Burgos  <jorge perez adaptia es>
+
+	reviewed by: <>
+
+	* capplets/display/main.c: Adding rotation support. 
+
 2005-11-25  Brian Cameron  <Brian Cameron sun com>
 
 	* configure.in, capplets/about-me/Makefile.am
Index: capplets/display/main.c
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/display/main.c,v
retrieving revision 1.19
diff -u -p -r1.19 main.c
--- capplets/display/main.c	14 Nov 2005 15:18:03 -0000	1.19
+++ capplets/display/main.c	13 Dec 2005 18:01:07 -0000
@@ -11,6 +11,14 @@
 #include "capplet-util.h"
 
 #define REVERT_COUNT 20
+#define ROTATION_MAX_DIRECTIONS 4
+
+static gchar *RotationDirections[ROTATION_MAX_DIRECTIONS] = {
+ "normal", /* RR_Rotate_0 */
+ "left", /* RR_Rotate_90 */
+ "inverted", /* RR_Rotate_180 */
+ "right" /* RR_Rotate_270 */
+};
 
 struct ScreenInfo
 {
@@ -23,13 +31,15 @@ struct ScreenInfo
   SizeID old_size;
   short old_rate;
   Rotation old_rotation;
-  
+  gboolean rotation_support;
+
   XRRScreenConfiguration *config;
   XRRScreenSize *sizes;
   int n_sizes;
-  
+
   GtkWidget *resolution_widget;
   GtkWidget *rate_widget;
+  GtkWidget *rotation_widget;
 };
 
 struct DisplayInfo {
@@ -43,6 +53,7 @@ struct DisplayInfo {
 
 static void generate_rate_menu (struct ScreenInfo *screen_info);
 static void generate_resolution_menu(struct ScreenInfo* screen_info);
+static void generate_rotation_menu(struct ScreenInfo* screen_info);
 
 static struct DisplayInfo *
 read_display_info (GdkDisplay *display)
@@ -51,6 +62,7 @@ read_display_info (GdkDisplay *display)
   struct ScreenInfo *screen_info;
   GdkScreen *screen;
   GdkWindow *root_window;
+  Rotation rotations;
   int i;
 
   info = g_new (struct DisplayInfo, 1);
@@ -72,6 +84,9 @@ read_display_info (GdkDisplay *display)
       screen_info->current_rate = XRRConfigCurrentRate (screen_info->config);
       screen_info->current_size = XRRConfigCurrentConfiguration (screen_info->config, &screen_info->current_rotation);
       screen_info->sizes = XRRConfigSizes (screen_info->config, &screen_info->n_sizes);
+      rotations = XRRConfigRotations (screen_info->config, &screen_info->current_rotation);
+      /* If rotations only support normal, we don't display rotation menu */
+      screen_info->rotation_support = (rotations != RR_Rotate_0);
     }
 
   return info;
@@ -149,6 +164,25 @@ get_current_rate (struct ScreenInfo *scr
     return 0;
 }
 
+static int
+get_current_rotation (struct ScreenInfo *screen_info)
+{
+  GtkWidget *menu;
+  GList *children;
+  GList *child;
+  int i;
+
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (screen_info->rotation_widget));
+  menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (screen_info->rotation_widget));
+  children = gtk_container_get_children (GTK_CONTAINER (menu));
+  child = g_list_nth (children, i);
+
+  if (child != NULL)
+    return GPOINTER_TO_INT (g_object_get_data (child->data, "rotation"));
+  else
+    return 0;
+}
+
 static gboolean
 apply_config (struct DisplayInfo *info)
 {
@@ -167,23 +201,25 @@ apply_config (struct DisplayInfo *info)
       struct ScreenInfo *screen_info = &info->screens[i];
       Status status;
       GdkWindow *root_window;
-      int new_res, new_rate;
+      int new_res, new_rate, new_rotation;
 
       screen = gdk_display_get_screen (display, i);
       root_window = gdk_screen_get_root_window (screen);
 
       new_res = get_current_resolution (screen_info);
       new_rate = get_current_rate (screen_info);
+      new_rotation = get_current_rotation (screen_info);
       
       if (new_res != screen_info->current_size ||
-	  new_rate != screen_info->current_rate)
+	  new_rate != screen_info->current_rate ||
+	  new_rotation != screen_info->current_rotation)
 	{
 	  changed = TRUE; 
 	  status = XRRSetScreenConfigAndRate (xdisplay, 
 					      screen_info->config,
 					      gdk_x11_drawable_get_xid (GDK_DRAWABLE (root_window)),
 					      new_res,
-					      screen_info->current_rotation,
+					      new_rotation,
 					      new_rate,
 					      GDK_CURRENT_TIME);
 	}
@@ -246,6 +282,10 @@ revert_config (struct DisplayInfo *info)
       
       generate_resolution_menu (screen_info);
       generate_rate_menu (screen_info);
+      if (screen_info->rotation_support)
+      {
+        generate_rotation_menu (screen_info);
+      }
     }
 
   if ((cmd = g_find_program_in_path ("gnome-screensaver-command")))
@@ -409,6 +449,48 @@ generate_resolution_menu(struct ScreenIn
 	gtk_widget_show (screen_info->resolution_widget);
 }
 
+static void
+generate_rotation_menu(struct ScreenInfo* screen_info)
+{
+  GtkWidget *menu;
+  GtkWidget *menuitem;
+  int i, item, current_item;
+  char *str;
+  Rotation current_rotation;
+  Rotation rotations;
+
+  gtk_option_menu_remove_menu(GTK_OPTION_MENU(screen_info->rotation_widget));
+  menu = gtk_menu_new ();
+  rotations = XRRConfigRotations (screen_info->config, &current_rotation);
+
+  current_item = 0;
+  item = 0;
+
+  for (i = 0; i < ROTATION_MAX_DIRECTIONS; i ++)
+  {
+    if ((rotations >> i) & 1)
+    {
+      str = g_strdup_printf (_("%s"), _(RotationDirections[i]));
+      if ((1 << i) == current_rotation)
+      {
+	    current_item = item;
+      }
+      menuitem = gtk_menu_item_new_with_label (str);
+      g_object_set_data (G_OBJECT (menuitem), "rotation", GINT_TO_POINTER (1 << i));
+
+      g_free (str);
+      gtk_widget_show (menuitem);
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+      item++;
+    }
+  }
+
+  gtk_option_menu_set_menu (GTK_OPTION_MENU (screen_info->rotation_widget), menu);
+  gtk_option_menu_set_history (GTK_OPTION_MENU (screen_info->rotation_widget), current_item);
+  
+  gtk_widget_show (screen_info->rotation_widget);
+}
+
 static GtkWidget *
 create_resolution_menu (struct ScreenInfo *screen_info) 
 {
@@ -432,6 +514,15 @@ create_rate_menu (struct ScreenInfo *scr
 }
 
 static GtkWidget *
+create_rotation_menu (struct ScreenInfo *screen_info) 
+{
+  screen_info->rotation_widget = gtk_option_menu_new ();
+  generate_rotation_menu (screen_info);
+
+  return screen_info->rotation_widget;
+}
+
+static GtkWidget *
 create_screen_widgets (struct ScreenInfo *screen_info, int nr, gboolean no_header)
 {
   GtkWidget *table;
@@ -440,7 +531,14 @@ create_screen_widgets (struct ScreenInfo
   GtkWidget *ret;
   char *str;
 
-  table = gtk_table_new (2, 2, FALSE);
+  if(screen_info->rotation_support)
+  {
+    table = gtk_table_new (3, 3, FALSE);
+  }
+  else
+  {
+    table = gtk_table_new (2, 2, FALSE);
+  }
 
   gtk_table_set_row_spacings ( GTK_TABLE (table), 6);
   gtk_table_set_col_spacings ( GTK_TABLE (table), 12);
@@ -483,7 +581,30 @@ create_screen_widgets (struct ScreenInfo
 		    1, 2,
 		    GTK_FILL | GTK_EXPAND, 0,
 		    0, 0);
+
+  if(screen_info->rotation_support)
+  {
+    label = gtk_label_new_with_mnemonic (_("Ro_tation:"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+    gtk_widget_show (label);
+    gtk_table_attach (GTK_TABLE (table),
+		    label,
+		    0, 1,
+		    2, 3,
+		    GTK_FILL, 0,
+		    0, 0);
+    gtk_widget_show (table);
   
+    option_menu = create_rotation_menu (screen_info);
+    gtk_label_set_mnemonic_widget (GTK_LABEL (label), option_menu);
+    gtk_table_attach (GTK_TABLE (table),
+		    option_menu,
+		    1, 2,
+		    2, 3,
+		    GTK_FILL | GTK_EXPAND, 0,
+		    0, 0);
+  }
+
   if (nr == 0)
     str = g_strdup (_("Default Settings"));
   else
@@ -713,6 +834,10 @@ save_to_gconf (struct DisplayInfo *info,
 				 hostname, i);
 	  gconf_client_unset (client, key, NULL);
 	  g_free (key);
+          key = g_strdup_printf ("/desktop/gnome/screen/%s/%d/rotation",
+				 hostname, i);
+         gconf_client_unset (client, key, NULL);
+         g_free (key);
 	}
     }
   
@@ -729,22 +854,27 @@ save_to_gconf (struct DisplayInfo *info,
   for (i = 0; i < info->n_screens; i++)
     {
       struct ScreenInfo *screen_info = &info->screens[i];
-      int new_res, new_rate;
+      int new_res, new_rate, new_rotation;
 
       new_res = get_current_resolution (screen_info);
       new_rate = get_current_rate (screen_info);
+      new_rotation = get_current_rotation (screen_info);
 
       key = g_strdup_printf ("%s%d/resolution", path, i);
       str = g_strdup_printf ("%dx%d",
 			     screen_info->sizes[new_res].width,
 			     screen_info->sizes[new_res].height);
-      
+
       res = gconf_client_set_string  (client, key, str, NULL);
       g_free (str);
       g_free (key);
-      
+
       key = g_strdup_printf ("%s%d/rate", path, i);
       res = gconf_client_set_int  (client, key, new_rate, NULL);
+      g_free (key);
+
+      key = g_strdup_printf ("%s%d/rotation", path, i);
+      res = gconf_client_set_int  (client, key, new_rotation, NULL);
       g_free (key);
     }
 


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