[vte] widget: Split alignment and fill properties



commit 980b3f4f62051e8acf0a2a2973c861dbf8fff4db
Author: Christian Persch <chpe src gnome org>
Date:   Wed Dec 22 21:22:35 2021 +0100

    widget: Split alignment and fill properties
    
    Don't encode fill as a flag within the VteAlign enum.
    
    https://gitlab.gnome.org/GNOME/vte/-/issues/337

 doc/reference/vte-sections.txt.in |   4 ++
 src/app/app.cc                    |  17 ++++-
 src/vte.cc                        |  18 +++--
 src/vte/vteenums.h                |   5 --
 src/vte/vteterminal.h             |  14 ++++
 src/vtegtk.cc                     | 142 ++++++++++++++++++++++++++++++++++++--
 src/vtegtk.hh                     |   2 +
 src/vteinternal.hh                |  10 +--
 src/widget.cc                     |   6 +-
 src/widget.hh                     |  28 +++++++-
 10 files changed, 221 insertions(+), 25 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt.in b/doc/reference/vte-sections.txt.in
index e99fdf49..4c9680f0 100644
--- a/doc/reference/vte-sections.txt.in
+++ b/doc/reference/vte-sections.txt.in
@@ -109,6 +109,10 @@ vte_terminal_get_xalign
 vte_terminal_set_xalign
 vte_terminal_get_yalign
 vte_terminal_set_yalign
+vte_terminal_get_xfill
+vte_terminal_set_xfill
+vte_terminal_get_yfill
+vte_terminal_set_yfill
 
 <SUBSECTION>
 VteFeatureFlags
diff --git a/src/app/app.cc b/src/app/app.cc
index b0c3f3d2..5b0183e1 100644
--- a/src/app/app.cc
+++ b/src/app/app.cc
@@ -75,6 +75,8 @@ public:
         gboolean no_shell{false};
         gboolean no_sixel{false};
         gboolean no_systemd_scope{false};
+        gboolean no_xfill{false};
+        gboolean no_yfill{false};
         gboolean object_notifications{false};
         gboolean require_systemd_scope{false};
         gboolean reverse{false};
@@ -692,9 +694,14 @@ public:
                           "Use foreground and background colors from the gtk+ theme", nullptr },
 
                         { "xalign", 0, 0, G_OPTION_ARG_CALLBACK, (void*)parse_xalign,
-                          "Horizontal alignment (fill|start|end|center)", "ALIGN" },
+                          "Horizontal alignment (start|end|center)", "ALIGN" },
                         { "yalign", 0, 0, G_OPTION_ARG_CALLBACK, (void*)parse_yalign,
                           "Vertical alignment (fill|start|end|center)", "ALIGN" },
+                        { "no-xfill", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &no_xfill,
+                          "No horizontal fillment", nullptr },
+                        { "no-yfill", 0, 0, G_OPTION_ARG_NONE, &no_yfill,
+                          "No vertical fillment", nullptr },
+
 
 #if VTE_GTK == 3
                         { "no-argb-visual", 0, 0, G_OPTION_ARG_NONE, &no_argb_visual,
@@ -2574,9 +2581,13 @@ vteapp_window_constructed(GObject *object)
         vte_terminal_set_scrollback_lines(window->terminal, options.scrollback_lines);
         vte_terminal_set_text_blink_mode(window->terminal, options.text_blink_mode);
         if (options.xalign != VteAlign(-1))
-            vte_terminal_set_xalign(window->terminal, options.xalign);
+                vte_terminal_set_xalign(window->terminal, options.xalign);
         if (options.yalign != VteAlign(-1))
-            vte_terminal_set_yalign(window->terminal, options.yalign);
+                vte_terminal_set_yalign(window->terminal, options.yalign);
+        if (options.no_xfill)
+                vte_terminal_set_xfill(window->terminal, false);
+        if (options.no_yfill)
+                vte_terminal_set_yfill(window->terminal, false);
 
         /* Style */
         if (options.font_string != nullptr) {
diff --git a/src/vte.cc b/src/vte.cc
index c326dd54..c0053900 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -7755,13 +7755,17 @@ Terminal::widget_size_allocate(int allocation_x,
                                int allocation_height,
                                int allocation_baseline,
                                Alignment xalign,
-                               Alignment yalign)
+                               Alignment yalign,
+                               bool xfill,
+                               bool yfill)
 #elif VTE_GTK == 4
 Terminal::widget_size_allocate(int allocation_width,
                                int allocation_height,
                                int allocation_baseline,
                                Alignment xalign,
-                               Alignment yalign)
+                               Alignment yalign,
+                               bool xfill,
+                               bool yfill)
 #endif /* VTE_GTK */
 {
         auto width = allocation_width - (m_style_padding.left + m_style_padding.right);
@@ -7775,22 +7779,26 @@ Terminal::widget_size_allocate(int allocation_width,
         /* assert(width >= 0); assert(height >= 0); */
 
         /* Distribute extra space according to alignment */
+        /* xfill doesn't have any effect */
         auto lpad = 0, rpad = 0;
         switch (xalign) {
         default:
-        case Alignment::START_FILL:
         case Alignment::START:  lpad = 0; rpad = width; break;
         case Alignment::CENTRE: lpad = width / 2; rpad = width - lpad; break;
         case Alignment::END:    lpad = width; rpad = 0; break;
         }
 
+        /* yfill is only applied to START */
         auto tpad = 0, bpad = 0;
         switch (yalign) {
         default:
-        case Alignment::START:       tpad = 0; bpad = height; break;
+        case Alignment::START:
+                tpad = 0;
+                bpad = yfill ? 0 : height;
+                break;
+
         case Alignment::CENTRE:      tpad = height / 2; bpad = height - tpad; break;
         case Alignment::END:         tpad = height; bpad = 0; break;
-        case Alignment::START_FILL:  tpad = bpad = 0; break;
         }
 
         m_padding.left   = m_style_padding.left   + lpad;
diff --git a/src/vte/vteenums.h b/src/vte/vteenums.h
index f02d3e78..4082fe88 100644
--- a/src/vte/vteenums.h
+++ b/src/vte/vteenums.h
@@ -202,7 +202,6 @@ typedef enum /*< skip >*/ {
  * @VTE_ALIGN_START: align to left/top
  * @VTE_ALIGN_CENTER: align to centre
  * @VTE_ALIGN_END: align to right/bottom
- * @VTE_ALIGN_FILL: fill available space
  *
  * An enumeration type that can be used to specify how the terminal
  * uses extra allocated space.
@@ -214,10 +213,6 @@ typedef enum {
         VTE_ALIGN_CENTER      = 1U,
         /* VTE_ALIGN_BASELINE    = 2U, */
         VTE_ALIGN_END         = 3U,
-        VTE_ALIGN_FILL        = 4U, /*< skip >*/ /* flag */
-        VTE_ALIGN_START_FILL  = 4U,
-        /* VTE_ALIGN_CENTER_FILL = 5U, */
-        /* VTE_ALIGN_END_FILL    = 6U, */
 } VteAlign;
 
 G_END_DECLS
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index 31e9038f..7e52a850 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -574,6 +574,20 @@ void vte_terminal_set_yalign(VteTerminal* terminal,
 _VTE_PUBLIC
 VteAlign vte_terminal_get_yalign(VteTerminal* terminal) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1);
 
+_VTE_PUBLIC
+void vte_terminal_set_xfill(VteTerminal* terminal,
+                            gboolean fill) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1);
+
+_VTE_PUBLIC
+gboolean vte_terminal_get_xfill(VteTerminal* terminal) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1);
+
+_VTE_PUBLIC
+void vte_terminal_set_yfill(VteTerminal* terminal,
+                            gboolean fill) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1);
+
+_VTE_PUBLIC
+gboolean vte_terminal_get_yfill(VteTerminal* terminal) _VTE_CXX_NOEXCEPT _VTE_GNUC_NONNULL(1);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(VteTerminal, g_object_unref)
 
 G_END_DECLS
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 0dbf5b00..1ec20def 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -1023,6 +1023,14 @@ try
                         g_value_set_enum(value, vte_terminal_get_yalign(terminal));
                         break;
 
+                case PROP_XFILL:
+                        g_value_set_boolean(value, vte_terminal_get_xfill(terminal));
+                        break;
+
+                case PROP_YFILL:
+                        g_value_set_boolean(value, vte_terminal_get_yfill(terminal));
+                        break;
+
                 default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        return;
@@ -1149,6 +1157,14 @@ try
                         vte_terminal_set_yalign(terminal, VteAlign(g_value_get_enum(value)));
                         break;
 
+                case PROP_XFILL:
+                        vte_terminal_set_xfill(terminal, g_value_get_boolean(value));
+                        break;
+
+                case PROP_YFILL:
+                        vte_terminal_set_yfill(terminal, g_value_get_boolean(value));
+                        break;
+
                         /* Not writable */
                 case PROP_CURRENT_DIRECTORY_URI:
                 case PROP_CURRENT_FILE_URI:
@@ -2370,9 +2386,33 @@ vte_terminal_class_init(VteTerminalClass *klass)
         pspecs[PROP_YALIGN] =
                 g_param_spec_enum("yalign", nullptr, nullptr,
                                   VTE_TYPE_ALIGN,
-                                  VTE_ALIGN_START_FILL,
+                                  VTE_ALIGN_START,
                                   GParamFlags(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | 
G_PARAM_EXPLICIT_NOTIFY));
 
+        /**
+         * VteTerminal:xfill:
+         *
+         * The horizontal fillment of @terminal within its allocation.
+         *
+         * Since: 0.68
+         */
+        pspecs[PROP_XFILL] =
+                g_param_spec_boolean("xfill", nullptr, nullptr,
+                                     TRUE,
+                                     GParamFlags(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | 
G_PARAM_EXPLICIT_NOTIFY));
+
+        /**
+         * VteTerminal:yfill:
+         *
+         * The vertical fillment of @terminal within its allocation
+         *
+         * Since: 0.68
+         */
+        pspecs[PROP_YFILL] =
+                g_param_spec_boolean("yfill", nullptr, nullptr,
+                                     TRUE,
+                                     GParamFlags(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | 
G_PARAM_EXPLICIT_NOTIFY));
+
         g_object_class_install_properties(gobject_class, LAST_PROP, pspecs);
 
 #if VTE_GTK == 3
@@ -6220,7 +6260,6 @@ constexpr bool check_enum_value<VteAlign>(VteAlign value) noexcept
         case VTE_ALIGN_START:
         case VTE_ALIGN_CENTER:
         case VTE_ALIGN_END:
-        case VTE_ALIGN_START_FILL:
                 return true;
         default:
                 return false;
@@ -6314,14 +6353,109 @@ VteAlign
 vte_terminal_get_yalign(VteTerminal* terminal) noexcept
 try
 {
-        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), VTE_ALIGN_START_FILL);
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), VTE_ALIGN_START);
 
         return WIDGET(terminal)->yalign();
 }
 catch (...)
 {
         vte::log_exception();
-        return VTE_ALIGN_START_FILL;
+        return VTE_ALIGN_START;
+}
+
+/**
+ * vte_terminal_set_xfill:
+ * @terminal: a #VteTerminal
+ * @fill: fillment value from #VteFill
+ *
+ * Sets the horizontal fillment of @terminal within its allocation.
+ *
+ * Note: %VTE_FILL_START_FILL is not supported, and will be treated
+ *   like %VTE_FILL_START.
+ *
+ * Since: 0.68
+ */
+void
+vte_terminal_set_xfill(VteTerminal* terminal,
+                        gboolean fill) noexcept
+try
+{
+        g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+        if (WIDGET(terminal)->set_xfill(fill != false))
+                g_object_notify_by_pspec(G_OBJECT(terminal), pspecs[PROP_XFILL]);
+}
+catch (...)
+{
+        vte::log_exception();
+}
+
+/**
+ * vte_terminal_get_xfill:
+ * @terminal: a #VteTerminal
+ *
+ * Returns: the horizontal fillment of @terminal within its allocation
+ *
+ * Since: 0.68
+ */
+gboolean
+vte_terminal_get_xfill(VteTerminal* terminal) noexcept
+try
+{
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), true);
+
+        return WIDGET(terminal)->xfill();
+}
+catch (...)
+{
+        vte::log_exception();
+        return true;
+}
+
+/**
+ * vte_terminal_set_yfill:
+ * @terminal: a #VteTerminal
+ * @fill: fillment value from #VteFill
+ *
+ * Sets the vertical fillment of @terminal within its allocation.
+ *
+ * Since: 0.68
+ */
+void
+vte_terminal_set_yfill(VteTerminal* terminal,
+                        gboolean fill) noexcept
+try
+{
+        g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+        if (WIDGET(terminal)->set_yfill(fill != false))
+                g_object_notify_by_pspec(G_OBJECT(terminal), pspecs[PROP_YFILL]);
+}
+catch (...)
+{
+        vte::log_exception();
+}
+
+/**
+ * vte_terminal_get_yfill:
+ * @terminal: a #VteTerminal
+ *
+ * Returns: the vertical fillment of @terminal within its allocation
+ *
+ * Since: 0.68
+ */
+gboolean
+vte_terminal_get_yfill(VteTerminal* terminal) noexcept
+try
+{
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), true);
+
+        return WIDGET(terminal)->yfill();
+}
+catch (...)
+{
+        vte::log_exception();
+        return true;
 }
 
 namespace vte {
diff --git a/src/vtegtk.hh b/src/vtegtk.hh
index e32430be..778b555a 100644
--- a/src/vtegtk.hh
+++ b/src/vtegtk.hh
@@ -94,6 +94,8 @@ enum {
         PROP_WORD_CHAR_EXCEPTIONS,
         PROP_XALIGN,
         PROP_YALIGN,
+        PROP_XFILL,
+        PROP_YFILL,
         LAST_PROP,
 
         /* override properties */
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index db5f6364..54409499 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -213,8 +213,6 @@ private:
                 CENTRE = 1u,
                 /* BASELINE = 2u, */
                 END    = 3u,
-                FILL   = 0x4u,
-                START_FILL = START | FILL,
         };
 
 protected:
@@ -932,13 +930,17 @@ public:
                                   int height,
                                   int baseline,
                                   Alignment xalign,
-                                  Alignment yalign);
+                                  Alignment yalign,
+                                  bool xfill,
+                                  bool yfill);
 #elif VTE_GTK == 4
         void widget_size_allocate(int width,
                                   int height,
                                   int baseline,
                                   Alignment xalign,
-                                  Alignment yalign);
+                                  Alignment yalign,
+                                  bool xfill,
+                                  bool yfill);
 #endif /* VTE_GTK */
 
         void set_blink_settings(bool blink,
diff --git a/src/widget.cc b/src/widget.cc
index c5181505..f56c1830 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -1858,7 +1858,8 @@ Widget::size_allocate(GtkAllocation* allocation)
                                          allocation->width, allocation->height,
                                          -1,
                                          vte::terminal::Terminal::Alignment(m_xalign),
-                                         vte::terminal::Terminal::Alignment(m_yalign));
+                                         vte::terminal::Terminal::Alignment(m_yalign),
+                                         m_xfill, m_yfill);
 
         gtk_widget_set_allocation(gtk(), allocation);
 
@@ -1882,7 +1883,8 @@ Widget::size_allocate(int width,
 
         terminal()->widget_size_allocate(width, height, baseline,
                                          vte::terminal::Terminal::Alignment(m_xalign),
-                                         vte::terminal::Terminal::Alignment(m_yalign));
+                                         vte::terminal::Terminal::Alignment(m_yalign),
+                                         m_xfill, m_yfill);
 
         gtk_widget_allocate(gtk(), width, height, baseline, nullptr);
 }
diff --git a/src/widget.hh b/src/widget.hh
index 634f6614..2acb0e07 100644
--- a/src/widget.hh
+++ b/src/widget.hh
@@ -478,13 +478,15 @@ public:
 
         constexpr auto xalign() const noexcept { return m_xalign; }
         constexpr auto yalign() const noexcept { return m_yalign; }
+        constexpr auto xfill() const noexcept { return m_xfill; }
+        constexpr auto yfill() const noexcept { return m_yfill; }
 
         bool set_xalign(VteAlign align) noexcept
         {
                 if (align == m_xalign)
                         return false;
 
-                m_xalign = VteAlign(align & ~VTE_ALIGN_FILL);
+                m_xalign = VteAlign(align);
                 gtk_widget_queue_allocate(gtk());
                 return true;
         }
@@ -499,6 +501,26 @@ public:
                 return true;
         }
 
+        bool set_xfill(bool fill) noexcept
+        {
+                if (fill == m_xfill)
+                        return false;
+
+                m_xfill = fill;
+                gtk_widget_queue_allocate(gtk());
+                return true;
+        }
+
+        bool set_yfill(bool fill) noexcept
+        {
+                if (fill == m_yfill)
+                        return false;
+
+                m_yfill = fill;
+                gtk_widget_queue_allocate(gtk());
+                return true;
+        }
+
 protected:
 
         enum class CursorType {
@@ -610,7 +632,9 @@ private:
         unsigned m_changing_scroll_position:1{false};
 
         VteAlign m_xalign{VTE_ALIGN_START};
-        VteAlign m_yalign{VTE_ALIGN_START_FILL};
+        VteAlign m_yalign{VTE_ALIGN_START};
+        bool m_xfill{true};
+        bool m_yfill{true};
 };
 
 } // namespace platform


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