Rotation support in gnome-display-properties



Hello,

	I attach a patch that adds rotation support in gnome-display-properties
capplet. I have a table pc and it's useful for me. I don't know if it
useful for the average user. If the X doesn't have rotation support, it
always displays the normal value.

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	12 Dec 2005 09:25:36 -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	12 Dec 2005 09:25:37 -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", 
+ "left", 
+ "inverted", 
+ "right"
+};
 
 struct ScreenInfo
 {
@@ -30,6 +38,7 @@ struct ScreenInfo
   
   GtkWidget *resolution_widget;
   GtkWidget *rate_widget;
+  GtkWidget *rotation_widget;
 };
 
 struct DisplayInfo {
@@ -43,6 +52,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)
@@ -149,6 +159,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 +196,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 +277,7 @@ revert_config (struct DisplayInfo *info)
       
       generate_resolution_menu (screen_info);
       generate_rate_menu (screen_info);
+      generate_rotation_menu (screen_info);
     }
 
   if ((cmd = g_find_program_in_path ("gnome-screensaver-command")))
@@ -409,6 +441,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 +506,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 +523,7 @@ create_screen_widgets (struct ScreenInfo
   GtkWidget *ret;
   char *str;
 
-  table = gtk_table_new (2, 2, FALSE);
+  table = gtk_table_new (3, 3, FALSE);
 
   gtk_table_set_row_spacings ( GTK_TABLE (table), 6);
   gtk_table_set_col_spacings ( GTK_TABLE (table), 12);
@@ -483,6 +566,26 @@ create_screen_widgets (struct ScreenInfo
 		    1, 2,
 		    GTK_FILL | GTK_EXPAND, 0,
 		    0, 0);
+
+  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"));
@@ -713,6 +816,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 +836,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]