[vte] widget: Move style update handler to Widget
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] widget: Move style update handler to Widget
- Date: Fri, 1 May 2020 21:11:14 +0000 (UTC)
commit 9f139a093ec7d832a5ebc13ebef6f71d2503b9a6
Author: Christian Persch <chpe src gnome org>
Date: Fri May 1 23:08:42 2020 +0200
widget: Move style update handler to Widget
src/vte.cc | 51 ++++++++++++++++++++++-----------------------------
src/vteinternal.hh | 4 +++-
src/widget.cc | 27 +++++++++++++++++++++++++++
src/widget.hh | 4 ++--
4 files changed, 54 insertions(+), 32 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 25885ed2..ec7a6148 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -4405,38 +4405,41 @@ Terminal::im_update_cursor()
}
void
-Terminal::widget_style_updated()
+Terminal::set_border_padding(GtkBorder const* padding)
{
- set_font_desc(m_unscaled_font_desc.get());
-
- auto context = gtk_widget_get_style_context(m_widget);
- GtkBorder new_padding;
- gtk_style_context_get_padding(context, gtk_style_context_get_state(context),
- &new_padding);
- if (memcmp(&new_padding, &m_padding, sizeof(GtkBorder)) != 0) {
+ if (memcmp(padding, &m_padding, sizeof(*padding)) != 0) {
_vte_debug_print(VTE_DEBUG_MISC | VTE_DEBUG_WIDGET_SIZE,
"Setting padding to (%d,%d,%d,%d)\n",
- new_padding.left, new_padding.right,
- new_padding.top, new_padding.bottom);
+ padding->left, padding->right,
+ padding->top, padding->bottom);
- m_padding = new_padding;
+ m_padding = *padding;
update_view_extents();
gtk_widget_queue_resize(m_widget);
} else {
_vte_debug_print(VTE_DEBUG_MISC | VTE_DEBUG_WIDGET_SIZE,
"Keeping padding the same at (%d,%d,%d,%d)\n",
- new_padding.left, new_padding.right,
- new_padding.top, new_padding.bottom);
+ padding->left, padding->right,
+ padding->top, padding->bottom);
}
+}
- float aspect;
- gtk_widget_style_get(m_widget, "cursor-aspect-ratio", &aspect, nullptr);
- if (!_vte_double_equal(aspect, m_cursor_aspect_ratio)) {
- m_cursor_aspect_ratio = aspect;
- invalidate_cursor_once();
- }
+void
+Terminal::set_cursor_aspect(float aspect)
+{
+ if (_vte_double_equal(aspect, m_cursor_aspect_ratio))
+ return;
+ m_cursor_aspect_ratio = aspect;
+ invalidate_cursor_once();
+}
+
+void
+Terminal::widget_style_updated()
+{
+ // FIXMEchpe: remove taking font info from the widget style
+ set_font_desc(m_unscaled_font_desc.get());
}
void
@@ -7755,16 +7758,6 @@ Terminal::Terminal(vte::platform::Widget* w,
#endif
}
-void
-Terminal::widget_constructed()
-{
- /* Set the style as early as possible, before GTK+ starts
- * invoking various callbacks. This is needed in order to
- * compute the initial geometry correctly in presence of
- * non-default padding, see bug 787710. */
- widget_style_updated();
-}
-
void
Terminal::widget_get_preferred_width(int *minimum_width,
int *natural_width)
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index d1b19d7f..4dc40e60 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -1115,6 +1115,9 @@ public:
void confine_coordinates(long *xp,
long *yp);
+ void set_border_padding(GtkBorder const* padding);
+ void set_cursor_aspect(float aspect);
+
void widget_paste(GdkAtom board);
void widget_copy(VteSelection sel,
VteFormat format);
@@ -1126,7 +1129,6 @@ public:
void widget_set_vadjustment(vte::glib::RefPtr<GtkAdjustment>&& adjustment);
- void widget_constructed();
void widget_realize();
void widget_unrealize();
void widget_unmap();
diff --git a/src/widget.cc b/src/widget.cc
index c4bb17b3..6f095f42 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -177,6 +177,17 @@ Widget::set_cursor(Cursor const& cursor) noexcept
g_object_unref(gdk_cursor);
}
+void
+Widget::constructed() noexcept
+{
+ /* Set the style as early as possible, before GTK+ starts
+ * invoking various callbacks. This is needed in order to
+ * compute the initial geometry correctly in presence of
+ * non-default padding, see bug 787710.
+ */
+ style_updated();
+}
+
void
Widget::dispose() noexcept
{
@@ -555,6 +566,22 @@ Widget::should_emit_signal(int id) noexcept
false /* not interested in blocked handlers */) != FALSE;
}
+void
+Widget::style_updated() noexcept
+{
+ auto padding = GtkBorder{};
+ auto context = gtk_widget_get_style_context(gtk());
+ gtk_style_context_get_padding(context, gtk_style_context_get_state(context),
+ &padding);
+ m_terminal->set_border_padding(&padding);
+
+ auto aspect = float{};
+ gtk_widget_style_get(gtk(), "cursor-aspect-ratio", &aspect, nullptr);
+ m_terminal->set_cursor_aspect(aspect);
+
+ m_terminal->widget_style_updated();
+}
+
void
Widget::unmap() noexcept
{
diff --git a/src/widget.hh b/src/widget.hh
index d44d4079..59e74cce 100644
--- a/src/widget.hh
+++ b/src/widget.hh
@@ -58,13 +58,13 @@ public:
inline constexpr vte::terminal::Terminal* terminal() const noexcept { return m_terminal; }
- void constructed() noexcept { m_terminal->widget_constructed(); }
+ void constructed() noexcept;
void dispose() noexcept;
void realize() noexcept;
void unrealize() noexcept;
void map() noexcept;
void unmap() noexcept;
- void style_updated() noexcept { m_terminal->widget_style_updated(); }
+ void style_updated() noexcept;
void draw(cairo_t *cr) noexcept { m_terminal->widget_draw(cr); }
void get_preferred_width(int *minimum_width,
int *natural_width) const noexcept {
m_terminal->widget_get_preferred_width(minimum_width, natural_width); }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]