[Xfce4-commits] <xfce4-terminal:master> Allow setting the geometry in the preferences.

Nick Schermer noreply at xfce.org
Mon Dec 31 20:22:01 CET 2012


Updating branch refs/heads/master
         to 174e5f41705ad6b821141b29966192722fc3a1b2 (commit)
       from b20622bd0d66b7634993df041241b68e288429b7 (commit)

commit 174e5f41705ad6b821141b29966192722fc3a1b2
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Dec 31 20:20:20 2012 +0100

    Allow setting the geometry in the preferences.
    
    It preserves the x and y positions as well.

 terminal/terminal-preferences-dialog.c |  135 ++++++++++++++++++++++++++++++++
 terminal/terminal-preferences.glade    |  124 +++++++++++++++++++++++++++++
 2 files changed, 259 insertions(+), 0 deletions(-)

diff --git a/terminal/terminal-preferences-dialog.c b/terminal/terminal-preferences-dialog.c
index d494f82..9be0826 100644
--- a/terminal/terminal-preferences-dialog.c
+++ b/terminal/terminal-preferences-dialog.c
@@ -23,6 +23,11 @@
 
 #include <libxfce4ui/libxfce4ui.h>
 
+#ifdef GDK_WINDOWING_X11
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#endif
+
 #include <terminal/terminal-util.h>
 #include <terminal/terminal-enum-types.h>
 #include <terminal/terminal-preferences-dialog.h>
@@ -35,6 +40,13 @@ static void terminal_preferences_dialog_finalize          (GObject
 static void terminal_preferences_dialog_response          (GtkWidget                 *widget,
                                                            gint                       response,
                                                            TerminalPreferencesDialog *dialog);
+#ifdef GDK_WINDOWING_X11
+static void terminal_preferences_dialog_geometry_changed  (TerminalPreferencesDialog *dialog);
+static void terminal_preferences_dialog_geometry_columns  (GtkAdjustment             *adj,
+                                                           TerminalPreferencesDialog *dialog);
+static void terminal_preferences_dialog_geometry_rows     (GtkAdjustment             *adj,
+                                                           TerminalPreferencesDialog *dialog);
+#endif
 static void terminal_preferences_dialog_palette_changed   (GtkWidget                 *button,
                                                            TerminalPreferencesDialog *dialog);
 static void terminal_preferences_dialog_palette_notify    (TerminalPreferencesDialog *dialog);
@@ -69,6 +81,7 @@ struct _TerminalPreferencesDialog
 
   gulong               bg_image_signal_id;
   gulong               palette_signal_id;
+  gulong               geometry_sigal_id;
 };
 
 enum
@@ -255,6 +268,28 @@ error:
                           G_OBJECT (object2), "sensitive",
                           G_BINDING_SYNC_CREATE);
 
+#ifdef GDK_WINDOWING_X11
+  terminal_preferences_dialog_geometry_changed (dialog);
+  dialog->geometry_sigal_id = g_signal_connect_swapped (G_OBJECT (dialog->preferences),
+      "notify::misc-default-geometry",
+      G_CALLBACK (terminal_preferences_dialog_geometry_changed), dialog);
+
+  /* geo changes */
+  object = gtk_builder_get_object (GTK_BUILDER (dialog), "geo-columns");
+  terminal_return_if_fail (G_IS_OBJECT (object));
+  g_signal_connect (G_OBJECT (object), "value-changed",
+      G_CALLBACK (terminal_preferences_dialog_geometry_columns), dialog);
+  object = gtk_builder_get_object (GTK_BUILDER (dialog), "geo-rows");
+  terminal_return_if_fail (G_IS_OBJECT (object));
+  g_signal_connect (G_OBJECT (object), "value-changed",
+      G_CALLBACK (terminal_preferences_dialog_geometry_rows), dialog);
+#else
+  /* hide */
+  object = gtk_builder_get_object (GTK_BUILDER (dialog), "geo-box");
+  terminal_return_if_fail (G_IS_OBJECT (object));
+  gtk_widget_hide (GTK_BOX (object));
+#endif
+
   /* background widgets visibility */
   object = gtk_builder_get_object (GTK_BUILDER (dialog), "background-mode");
   terminal_return_if_fail (G_IS_OBJECT (object));
@@ -308,6 +343,8 @@ terminal_preferences_dialog_finalize (GObject *object)
     g_signal_handler_disconnect (dialog->preferences, dialog->bg_image_signal_id);
   if (G_LIKELY (dialog->palette_signal_id != 0))
     g_signal_handler_disconnect (dialog->preferences, dialog->palette_signal_id);
+  if (G_LIKELY (dialog->geometry_sigal_id != 0))
+    g_signal_handler_disconnect (dialog->preferences, dialog->geometry_sigal_id);
 
   /* release the preferences */
   g_object_unref (G_OBJECT (dialog->preferences));
@@ -359,6 +396,104 @@ terminal_preferences_dialog_response (GtkWidget                 *widget,
 
 
 
+#ifdef GDK_WINDOWING_X11
+static void
+terminal_preferences_dialog_geometry_changed (TerminalPreferencesDialog *dialog)
+{
+  GObject *object;
+  gchar   *geo;
+  guint    w = 0, h = 0;
+  gint     x, y;
+
+  g_object_get (G_OBJECT (dialog->preferences), "misc-default-geometry", &geo, NULL);
+  if (G_LIKELY (geo != NULL))
+    {
+      /* parse the string */
+      XParseGeometry (geo, &x, &y, &w, &h);
+      g_free (geo);
+    }
+
+  /* set cols */
+  object = gtk_builder_get_object (GTK_BUILDER (dialog), "geo-columns");
+  terminal_return_if_fail (GTK_IS_ADJUSTMENT (object));
+  g_signal_handlers_block_by_func (G_OBJECT (object),
+      terminal_preferences_dialog_geometry_columns, dialog);
+  gtk_adjustment_set_value (GTK_ADJUSTMENT (object), w != 0 ? w : 80);
+  g_signal_handlers_unblock_by_func (G_OBJECT (object),
+      terminal_preferences_dialog_geometry_columns, dialog);
+
+  /* set rows */
+  object = gtk_builder_get_object (GTK_BUILDER (dialog), "geo-rows");
+  terminal_return_if_fail (GTK_IS_ADJUSTMENT (object));
+  g_signal_handlers_block_by_func (G_OBJECT (object),
+      terminal_preferences_dialog_geometry_columns, dialog);
+  gtk_adjustment_set_value (GTK_ADJUSTMENT (object), h != 0 ? h : 24);
+  g_signal_handlers_unblock_by_func (G_OBJECT (object),
+      terminal_preferences_dialog_geometry_columns, dialog);
+}
+
+
+
+static void
+terminal_preferences_dialog_geometry (TerminalPreferencesDialog *dialog,
+                                      gint                       columns,
+                                      gint                       rows)
+{
+  gint     x, y;
+  guint    w, h;
+  gchar   *geo;
+  gint     mask = NoValue;
+
+  g_object_get (G_OBJECT (dialog->preferences), "misc-default-geometry", &geo, NULL);
+  if (G_LIKELY (geo != NULL))
+    {
+      /* parse the string */
+      mask = XParseGeometry (geo, &x, &y, &w, &h);
+      g_free (geo);
+    }
+
+  /* set new value */
+  if (columns > 0)
+    w = columns;
+  if (rows > 0)
+    h = rows;
+
+  /* if there is an x or y value, preserve this */
+  if ((mask & XValue) != 0 || (mask & YValue) != 0)
+    geo = g_strdup_printf ("%dx%d%+d%+d", w, h, x, y);
+  else
+    geo = g_strdup_printf ("%dx%d", w, h);
+
+  /* save */
+  g_signal_handler_block (G_OBJECT (dialog->preferences), dialog->geometry_sigal_id);
+  g_object_set (G_OBJECT (dialog->preferences), "misc-default-geometry", geo, NULL);
+  g_signal_handler_unblock (G_OBJECT (dialog->preferences), dialog->geometry_sigal_id);
+  g_free (geo);
+}
+
+
+
+static void
+terminal_preferences_dialog_geometry_columns (GtkAdjustment             *adj,
+                                              TerminalPreferencesDialog *dialog)
+{
+  terminal_return_if_fail (GTK_IS_ADJUSTMENT (adj));
+  terminal_preferences_dialog_geometry (dialog, gtk_adjustment_get_value (adj), -1);
+}
+
+
+
+static void
+terminal_preferences_dialog_geometry_rows (GtkAdjustment             *adj,
+                                           TerminalPreferencesDialog *dialog)
+{
+  terminal_return_if_fail (GTK_IS_ADJUSTMENT (adj));
+  terminal_preferences_dialog_geometry (dialog, -1, gtk_adjustment_get_value (adj));
+}
+#endif
+
+
+
 static void
 terminal_preferences_dialog_palette_changed (GtkWidget                 *button,
                                              TerminalPreferencesDialog *dialog)
diff --git a/terminal/terminal-preferences.glade b/terminal/terminal-preferences.glade
index f41cdc4..7316da9 100644
--- a/terminal/terminal-preferences.glade
+++ b/terminal/terminal-preferences.glade
@@ -35,6 +35,20 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
+  <object class="GtkAdjustment" id="geo-columns">
+    <property name="lower">1</property>
+    <property name="upper">1000</property>
+    <property name="value">80</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="geo-rows">
+    <property name="lower">1</property>
+    <property name="upper">1000</property>
+    <property name="value">24</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkListStore" id="liststore1">
     <columns>
       <!-- column-name title -->
@@ -1399,6 +1413,116 @@
                                 <property name="position">2</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkHBox" id="geo-box">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="spacing">12</property>
+                                <child>
+                                  <object class="GtkLabel" id="label50">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">Default size:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkHBox" id="hbox6">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="spacing">6</property>
+                                    <child>
+                                      <object class="GtkSpinButton" id="spin-columns">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="invisible_char">●</property>
+                                        <property name="primary_icon_activatable">False</property>
+                                        <property name="secondary_icon_activatable">False</property>
+                                        <property name="primary_icon_sensitive">True</property>
+                                        <property name="secondary_icon_sensitive">True</property>
+                                        <property name="adjustment">geo-columns</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label51">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="label" translatable="yes">c_olumns</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="mnemonic_widget">spin-columns</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkHBox" id="hbox7">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="spacing">6</property>
+                                    <child>
+                                      <object class="GtkSpinButton" id="spin-rows">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="invisible_char">●</property>
+                                        <property name="primary_icon_activatable">False</property>
+                                        <property name="secondary_icon_activatable">False</property>
+                                        <property name="primary_icon_sensitive">True</property>
+                                        <property name="secondary_icon_sensitive">True</property>
+                                        <property name="adjustment">geo-rows</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label52">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="label" translatable="yes">row_s</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="mnemonic_widget">spin-rows</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">2</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">True</property>
+                                <property name="fill">True</property>
+                                <property name="position">3</property>
+                              </packing>
+                            </child>
                           </object>
                         </child>
                       </object>


More information about the Xfce4-commits mailing list