[gnome-control-center] shell: Be smarter about smaller screen sizes



commit ad0e02f100966c244aef9f4b1710c561bf9cb899
Author: Jon McCann <jmccann redhat com>
Date:   Tue May 8 16:56:20 2012 +0100

    shell: Be smarter about smaller screen sizes
    
    Make the minimum window size smaller, and the window resizable when
    using small screens.
    
    Based on patch from Ubuntu
    
    https://bugzilla.gnome.org/show_bug.cgi?id=673869

 shell/gnome-control-center.c |  106 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 102 insertions(+), 4 deletions(-)
---
diff --git a/shell/gnome-control-center.c b/shell/gnome-control-center.c
index 32e9092..2fbe45b 100644
--- a/shell/gnome-control-center.c
+++ b/shell/gnome-control-center.c
@@ -49,6 +49,7 @@ G_DEFINE_TYPE (GnomeControlCenter, gnome_control_center, CC_TYPE_SHELL)
  * Both sizes are defined in https://live.gnome.org/Design/SystemSettings/ */
 #define FIXED_WIDTH 740
 #define FIXED_HEIGHT 636
+#define SMALL_SCREEN_FIXED_HEIGHT 500
 
 #define MIN_ICON_VIEW_HEIGHT 300
 
@@ -86,6 +87,10 @@ struct _GnomeControlCenterPrivate
 
   gchar *default_window_title;
   gchar *default_window_icon;
+
+  int monitor_num;
+  gboolean small_screen;
+  gboolean small_screen_set;
 };
 
 static const gchar *
@@ -591,6 +596,7 @@ setup_search (GnomeControlCenter *shell)
   gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (search_view),
                                       GTK_ORIENTATION_HORIZONTAL);
   gtk_icon_view_set_spacing (GTK_ICON_VIEW (search_view), 6);
+  gtk_icon_view_set_margin (GTK_ICON_VIEW (search_view), 12);
   gtk_icon_view_set_model (GTK_ICON_VIEW (search_view),
                            GTK_TREE_MODEL (priv->search_filter));
 
@@ -753,7 +759,10 @@ setup_model (GnomeControlCenter *shell)
 {
   GnomeControlCenterPrivate *priv = shell->priv;
 
-  gtk_container_set_border_width (GTK_CONTAINER (shell->priv->main_vbox), 10);
+  gtk_widget_set_margin_top (shell->priv->main_vbox, 8);
+  gtk_widget_set_margin_bottom (shell->priv->main_vbox, 8);
+  gtk_widget_set_margin_left (shell->priv->main_vbox, 12);
+  gtk_widget_set_margin_right (shell->priv->main_vbox, 12);
   gtk_container_set_focus_vadjustment (GTK_CONTAINER (shell->priv->main_vbox),
                                        gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (shell->priv->scrolled_window)));
 
@@ -813,11 +822,10 @@ notebook_switch_page_cb (GtkNotebook               *book,
       gtk_widget_show (W (priv->builder, "search-entry"));
       gtk_widget_hide (W (priv->builder, "lock-button"));
 
-      /* FIXME: select a height that fits into the screen
-       * for small displays */
       gtk_widget_get_preferred_height_for_width (GTK_WIDGET (priv->main_vbox),
                                                  FIXED_WIDTH, NULL, &nat_height);
-      gtk_widget_set_size_request (priv->scrolled_window, FIXED_WIDTH, nat_height);
+      gtk_widget_set_size_request (priv->scrolled_window, FIXED_WIDTH,
+                                   priv->small_screen ? SMALL_SCREEN_FIXED_HEIGHT : nat_height);
     }
   else
     {
@@ -1095,14 +1103,101 @@ window_key_press_event (GtkWidget          *win,
   return retval;
 }
 
+static gint
+get_monitor_height (GnomeControlCenter *self)
+{
+  GdkScreen *screen;
+  GdkRectangle rect;
+
+  /* FIXME use workarea instead of raw screen geometry */
+  screen = gtk_widget_get_screen (self->priv->window);
+  gdk_screen_get_monitor_geometry (screen, self->priv->monitor_num, &rect);
+
+  return rect.height;
+}
+
+static gboolean
+update_monitor_number (GnomeControlCenter *self)
+{
+  gboolean changed = FALSE;
+  GtkWidget *widget;
+  GdkScreen *screen;
+  GdkWindow *window;
+  int monitor;
+
+  widget = self->priv->window;
+
+  window = gtk_widget_get_window (widget);
+  screen = gtk_widget_get_screen (widget);
+  monitor = gdk_screen_get_monitor_at_window (screen, window);
+  if (self->priv->monitor_num != monitor)
+    {
+      self->priv->monitor_num = monitor;
+      changed = TRUE;
+    }
+
+  return changed;
+}
+
+static void
+update_small_screen_settings (GnomeControlCenter *self)
+{
+  gboolean small;
+
+  update_monitor_number (self);
+  small = get_monitor_height (self) <= FIXED_HEIGHT;
+
+  if (small)
+    {
+      gtk_window_set_resizable (GTK_WINDOW (self->priv->window), TRUE);
+      gtk_widget_set_size_request (self->priv->scrolled_window, FIXED_WIDTH, SMALL_SCREEN_FIXED_HEIGHT);
+
+      if (!self->priv->small_screen_set
+          && self->priv->small_screen != small)
+        gtk_window_maximize (GTK_WINDOW (self->priv->window));
+    }
+  else
+    {
+      if (!self->priv->small_screen_set
+          && self->priv->small_screen != small)
+        gtk_window_unmaximize (GTK_WINDOW (self->priv->window));
+
+      gtk_window_set_resizable (GTK_WINDOW (self->priv->window), FALSE);
+    }
+
+  self->priv->small_screen = small;
+  self->priv->small_screen_set = TRUE;
+}
+
+static gboolean
+main_window_configure_cb (GtkWidget *widget,
+                          GdkEvent  *event,
+                          GnomeControlCenter *self)
+{
+  update_small_screen_settings (self);
+  return FALSE;
+}
+
+static void
+monitors_changed_cb (GdkScreen *screen,
+                     GnomeControlCenter *self)
+{
+  update_small_screen_settings (self);
+}
+
 static void
 gnome_control_center_init (GnomeControlCenter *self)
 {
   GError *err = NULL;
   GnomeControlCenterPrivate *priv;
+  GdkScreen *screen;
 
   priv = self->priv = CONTROL_CENTER_PRIVATE (self);
 
+  priv->monitor_num = -1;
+  self->priv->small_screen = FALSE;
+  self->priv->small_screen_set = FALSE;
+
   /* load the user interface */
   priv->builder = gtk_builder_new ();
 
@@ -1116,6 +1211,9 @@ gnome_control_center_init (GnomeControlCenter *self)
 
   /* connect various signals */
   priv->window = W (priv->builder, "main-window");
+  screen = gtk_widget_get_screen (priv->window);
+  g_signal_connect (screen, "monitors-changed", G_CALLBACK (monitors_changed_cb), self);
+  g_signal_connect (priv->window, "configure-event", G_CALLBACK (main_window_configure_cb), self);
   g_signal_connect_swapped (priv->window, "delete-event", G_CALLBACK (g_object_unref), self);
   g_signal_connect (priv->window, "key_press_event",
                     G_CALLBACK (window_key_press_event), self);



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