[gnome-flashback] desktop: add more layout settings



commit 3d64badcff2cf4f23442a78f726096c33b799b35
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Nov 4 16:26:30 2019 +0200

    desktop: add more layout settings

 ...gnome.gnome-flashback.desktop.icons.gschema.xml |  21 ++++
 gnome-flashback/libdesktop/gf-icon-view.c          |  25 ++++-
 gnome-flashback/libdesktop/gf-icon.c               |  35 +++++++
 gnome-flashback/libdesktop/gf-monitor-view.c       | 116 ++++++++++++++++++++-
 gnome-flashback/libdesktop/gf-monitor-view.h       |   5 +-
 5 files changed, 199 insertions(+), 3 deletions(-)
---
diff --git a/data/schemas/org.gnome.gnome-flashback.desktop.icons.gschema.xml 
b/data/schemas/org.gnome.gnome-flashback.desktop.icons.gschema.xml
index 2fdc942..f28c26b 100644
--- a/data/schemas/org.gnome.gnome-flashback.desktop.icons.gschema.xml
+++ b/data/schemas/org.gnome.gnome-flashback.desktop.icons.gschema.xml
@@ -5,5 +5,26 @@
       <summary>Icon size</summary>
       <description>The size of desktop icons.</description>
     </key>
+
+    <key name="extra-text-width" type="u">
+      <default>48</default>
+      <range min='0' max='100'/>
+      <summary>Extra text width</summary>
+      <description>Extra width for icon text.</description>
+    </key>
+
+    <key name="column-spacing" type="u">
+      <default>10</default>
+      <range min='0' max='100'/>
+      <summary>Column spacing</summary>
+      <description>The amount of space between columns.</description>
+    </key>
+
+    <key name="row-spacing" type="u">
+      <default>2</default>
+      <range min='0' max='100'/>
+      <summary>Row spacing</summary>
+      <description>The amount of space between rows.</description>
+    </key>
   </schema>
 </schemalist>
diff --git a/gnome-flashback/libdesktop/gf-icon-view.c b/gnome-flashback/libdesktop/gf-icon-view.c
index ad7a475..b0fb78d 100644
--- a/gnome-flashback/libdesktop/gf-icon-view.c
+++ b/gnome-flashback/libdesktop/gf-icon-view.c
@@ -103,14 +103,25 @@ create_monitor_view (GfIconView *self,
                      GdkMonitor *monitor)
 {
   guint icon_size;
+  guint extra_text_width;
+  guint column_spacing;
+  guint row_spacing;
   GdkRectangle workarea;
   GtkWidget *view;
 
   icon_size = g_settings_get_enum (self->settings, "icon-size");
+  extra_text_width = g_settings_get_uint (self->settings, "extra-text-width");
+  column_spacing = g_settings_get_uint (self->settings, "column-spacing");
+  row_spacing = g_settings_get_uint (self->settings, "row-spacing");
 
   gdk_monitor_get_workarea (monitor, &workarea);
 
-  view = gf_monitor_view_new (monitor, icon_size);
+  view = gf_monitor_view_new (monitor,
+                              icon_size,
+                              extra_text_width,
+                              column_spacing,
+                              row_spacing);
+
   gtk_fixed_put (GTK_FIXED (self->fixed), view, workarea.x, workarea.y);
   gtk_widget_show (view);
 
@@ -122,6 +133,18 @@ create_monitor_view (GfIconView *self,
                                 self,
                                 NULL);
 
+  g_settings_bind (self->settings, "extra-text-width",
+                   view, "extra-text-width",
+                   G_SETTINGS_BIND_GET);
+
+  g_settings_bind (self->settings, "column-spacing",
+                   view, "column-spacing",
+                   G_SETTINGS_BIND_GET);
+
+  g_settings_bind (self->settings, "row-spacing",
+                   view, "row-spacing",
+                   G_SETTINGS_BIND_GET);
+
   g_signal_connect_object (monitor, "notify::workarea",
                            G_CALLBACK (workarea_cb),
                            self, 0);
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index d9efef2..5510038 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -26,6 +26,7 @@ struct _GfIcon
   GFileInfo *info;
 
   guint      icon_size;
+  guint      extra_text_width;
 
   GtkWidget *image;
   GtkWidget *label;
@@ -41,6 +42,7 @@ enum
   PROP_INFO,
 
   PROP_ICON_SIZE,
+  PROP_EXTRA_TEXT_WIDTH,
 
   LAST_PROP
 };
@@ -122,12 +124,34 @@ gf_icon_set_property (GObject      *object,
         gtk_image_set_pixel_size (GTK_IMAGE (self->image), self->icon_size);
         break;
 
+      case PROP_EXTRA_TEXT_WIDTH:
+        self->extra_text_width = g_value_get_uint (value);
+        gtk_widget_queue_resize (GTK_WIDGET (self));
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
     }
 }
 
+static void
+gf_icon_get_preferred_width (GtkWidget *widget,
+                             gint      *minimum_width,
+                             gint      *natural_width)
+{
+  GfIcon *self;
+
+  self = GF_ICON (widget);
+
+  GTK_WIDGET_CLASS (gf_icon_parent_class)->get_preferred_width (widget,
+                                                                minimum_width,
+                                                                natural_width);
+
+  *minimum_width += self->extra_text_width;
+  *natural_width += self->extra_text_width;
+}
+
 static void
 install_properties (GObjectClass *object_class)
 {
@@ -160,6 +184,15 @@ install_properties (GObjectClass *object_class)
                        G_PARAM_WRITABLE |
                        G_PARAM_STATIC_STRINGS);
 
+  icon_properties[PROP_EXTRA_TEXT_WIDTH] =
+    g_param_spec_uint ("extra-text-width",
+                       "extra-text-width",
+                       "extra-text-width",
+                       0, 100, 48,
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_WRITABLE |
+                       G_PARAM_STATIC_STRINGS);
+
   g_object_class_install_properties (object_class, LAST_PROP, icon_properties);
 }
 
@@ -176,6 +209,8 @@ gf_icon_class_init (GfIconClass *self_class)
   object_class->dispose = gf_icon_dispose;
   object_class->set_property = gf_icon_set_property;
 
+  widget_class->get_preferred_width = gf_icon_get_preferred_width;
+
   install_properties (object_class);
 
   gtk_widget_class_set_css_name (widget_class, "gf-icon");
diff --git a/gnome-flashback/libdesktop/gf-monitor-view.c b/gnome-flashback/libdesktop/gf-monitor-view.c
index 35dc013..4a89f6c 100644
--- a/gnome-flashback/libdesktop/gf-monitor-view.c
+++ b/gnome-flashback/libdesktop/gf-monitor-view.c
@@ -25,6 +25,9 @@ struct _GfMonitorView
   GdkMonitor *monitor;
 
   guint       icon_size;
+  guint       extra_text_width;
+  guint       column_spacing;
+  guint       row_spacing;
 
   int         width;
   int         height;
@@ -37,6 +40,9 @@ enum
   PROP_MONITOR,
 
   PROP_ICON_SIZE,
+  PROP_EXTRA_TEXT_WIDTH,
+  PROP_COLUMN_SPACING,
+  PROP_ROW_SPACING,
 
   LAST_PROP
 };
@@ -57,6 +63,42 @@ set_icon_size (GfMonitorView *self,
   gtk_widget_queue_resize (GTK_WIDGET (self));
 }
 
+static void
+set_extra_text_width (GfMonitorView *self,
+                      guint          extra_text_width)
+{
+  if (self->extra_text_width == extra_text_width)
+    return;
+
+  self->extra_text_width = extra_text_width;
+
+  gtk_widget_queue_resize (GTK_WIDGET (self));
+}
+
+static void
+set_column_spacing (GfMonitorView *self,
+                    guint          column_spacing)
+{
+  if (self->column_spacing == column_spacing)
+    return;
+
+  self->column_spacing = column_spacing;
+
+  gtk_widget_queue_resize (GTK_WIDGET (self));
+}
+
+static void
+set_row_spacing (GfMonitorView *self,
+                 guint          row_spacing)
+{
+  if (self->row_spacing == row_spacing)
+    return;
+
+  self->row_spacing = row_spacing;
+
+  gtk_widget_queue_resize (GTK_WIDGET (self));
+}
+
 static void
 workarea_cb (GdkMonitor    *monitor,
              GParamSpec    *pspec,
@@ -100,6 +142,32 @@ gf_monitor_view_dispose (GObject *object)
   G_OBJECT_CLASS (gf_monitor_view_parent_class)->dispose (object);
 }
 
+static void
+gf_monitor_view_get_property (GObject    *object,
+                              guint       property_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  GfMonitorView *self;
+
+  self = GF_MONITOR_VIEW (object);
+
+  switch (property_id)
+    {
+      case PROP_ICON_SIZE:
+        g_value_set_uint (value, self->icon_size);
+        break;
+
+      case PROP_EXTRA_TEXT_WIDTH:
+        g_value_set_uint (value, self->extra_text_width);
+        break;
+
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+        break;
+    }
+}
+
 static void
 gf_monitor_view_set_property (GObject      *object,
                               guint         property_id,
@@ -121,6 +189,18 @@ gf_monitor_view_set_property (GObject      *object,
         set_icon_size (self, g_value_get_uint (value));
         break;
 
+      case PROP_EXTRA_TEXT_WIDTH:
+        set_extra_text_width (self, g_value_get_uint (value));
+        break;
+
+      case PROP_COLUMN_SPACING:
+        set_column_spacing (self, g_value_get_uint (value));
+        break;
+
+      case PROP_ROW_SPACING:
+        set_row_spacing (self, g_value_get_uint (value));
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -177,6 +257,33 @@ install_properties (GObjectClass *object_class)
                        "icon-size",
                        16, 128, 48,
                        G_PARAM_CONSTRUCT |
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS);
+
+  view_properties[PROP_EXTRA_TEXT_WIDTH] =
+    g_param_spec_uint ("extra-text-width",
+                       "extra-text-width",
+                       "extra-text-width",
+                       0, 100, 48,
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS);
+
+  view_properties[PROP_COLUMN_SPACING] =
+    g_param_spec_uint ("column-spacing",
+                       "column-spacing",
+                       "column-spacing",
+                       0, 100, 10,
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_WRITABLE |
+                       G_PARAM_STATIC_STRINGS);
+
+  view_properties[PROP_ROW_SPACING] =
+    g_param_spec_uint ("row-spacing",
+                       "row-spacing",
+                       "row-spacing",
+                       0, 100, 10,
+                       G_PARAM_CONSTRUCT |
                        G_PARAM_WRITABLE |
                        G_PARAM_STATIC_STRINGS);
 
@@ -194,6 +301,7 @@ gf_monitor_view_class_init (GfMonitorViewClass *self_class)
 
   object_class->constructed = gf_monitor_view_constructed;
   object_class->dispose = gf_monitor_view_dispose;
+  object_class->get_property = gf_monitor_view_get_property;
   object_class->set_property = gf_monitor_view_set_property;
 
   widget_class->get_preferred_height = gf_monitor_view_get_preferred_height;
@@ -210,11 +318,17 @@ gf_monitor_view_init (GfMonitorView *self)
 
 GtkWidget *
 gf_monitor_view_new (GdkMonitor *monitor,
-                     guint       icon_size)
+                     guint       icon_size,
+                     guint       extra_text_width,
+                     guint       column_spacing,
+                     guint       row_spacing)
 {
   return g_object_new (GF_TYPE_MONITOR_VIEW,
                        "monitor", monitor,
                        "icon-size", icon_size,
+                       "extra-text-width", extra_text_width,
+                       "column-spacing", column_spacing,
+                       "row-spacing", row_spacing,
                        NULL);
 }
 
diff --git a/gnome-flashback/libdesktop/gf-monitor-view.h b/gnome-flashback/libdesktop/gf-monitor-view.h
index 951ad2d..28063dd 100644
--- a/gnome-flashback/libdesktop/gf-monitor-view.h
+++ b/gnome-flashback/libdesktop/gf-monitor-view.h
@@ -26,7 +26,10 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GfMonitorView, gf_monitor_view, GF, MONITOR_VIEW, GtkFixed)
 
 GtkWidget  *gf_monitor_view_new         (GdkMonitor    *monitor,
-                                         guint          icon_size);
+                                         guint          icon_size,
+                                         guint          extra_text_width,
+                                         guint          column_spacing,
+                                         guint          row_spacing);
 
 GdkMonitor *gf_monitor_view_get_monitor (GfMonitorView *self);
 


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