[vte] terminal: Use smart pointer
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] terminal: Use smart pointer
- Date: Thu, 21 Nov 2019 19:02:24 +0000 (UTC)
commit 60c0c3423c43fa1f64d1c50452197db43e51bbe6
Author: Christian Persch <chpe src gnome org>
Date: Thu Nov 21 20:01:30 2019 +0100
terminal: Use smart pointer
src/vte.cc | 22 +++++++---------------
src/vteinternal.hh | 5 +++--
src/widget.cc | 15 ++++++++-------
3 files changed, 18 insertions(+), 24 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 6879e0f2..138cd553 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -3311,15 +3311,10 @@ Terminal::watch_child (pid_t child_pid)
void
Terminal::im_reset()
{
- m_real_widget->im_reset();
-
- m_im_preedit.clear();
- m_im_preedit.shrink_to_fit();
+ if (widget())
+ widget()->im_reset();
- if (m_im_preedit_attrs) {
- pango_attr_list_unref(m_im_preedit_attrs);
- m_im_preedit_attrs = nullptr;
- }
+ im_preedit_reset();
}
void
@@ -4342,16 +4337,13 @@ Terminal::im_preedit_reset() noexcept
m_im_preedit.clear();
m_im_preedit.shrink_to_fit();
m_im_preedit_cursor = 0;
- if (m_im_preedit_attrs != nullptr) {
- pango_attr_list_unref(m_im_preedit_attrs);
- m_im_preedit_attrs = nullptr;
- }
+ m_im_preedit_attrs.reset();
}
void
Terminal::im_preedit_changed(std::string_view const& str,
int cursorpos,
- PangoAttrList* attrs) noexcept
+ pango_attr_list_unique_type&& attrs) noexcept
{
/* Queue the area where the current preedit string is being displayed
* for repainting. */
@@ -4359,7 +4351,7 @@ Terminal::im_preedit_changed(std::string_view const& str,
im_preedit_reset();
m_im_preedit = str;
- m_im_preedit_attrs = attrs;
+ m_im_preedit_attrs = std::move(attrs);
m_im_preedit_cursor = cursorpos;
/* Invalidate again with the new cursor position */
@@ -9304,7 +9296,7 @@ Terminal::paint_im_preedit_string()
}
draw_cells_with_attributes(
items, len,
- m_im_preedit_attrs,
+ m_im_preedit_attrs.get(),
TRUE,
width, height);
preedit_cursor = m_im_preedit_cursor;
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 9c49efdd..2d580f12 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -683,7 +683,8 @@ public:
/* Input method support. */
bool m_im_preedit_active;
std::string m_im_preedit;
- PangoAttrList *m_im_preedit_attrs;
+ using pango_attr_list_unique_type = std::unique_ptr<PangoAttrList, decltype(&pango_attr_list_unref)>;
+ pango_attr_list_unique_type m_im_preedit_attrs{nullptr, &pango_attr_list_unref};
int m_im_preedit_cursor;
#ifdef WITH_A11Y
@@ -985,7 +986,7 @@ public:
void im_preedit_reset() noexcept;
void im_preedit_changed(std::string_view const& str,
int cursorpos,
- PangoAttrList* attrs) noexcept;
+ pango_attr_list_unique_type&& attrs) noexcept;
bool im_retrieve_surrounding();
bool im_delete_surrounding(int offset,
int n_chars);
diff --git a/src/widget.cc b/src/widget.cc
index 7aef2bf5..afc429e2 100644
--- a/src/widget.cc
+++ b/src/widget.cc
@@ -223,18 +223,19 @@ Widget::im_focus_out() noexcept
void
Widget::im_preedit_changed() noexcept
{
- char* str;
- PangoAttrList* attrs;
- int cursorpos;
+ char* str = nullptr;
+ PangoAttrList* attrs = nullptr;
+ int cursorpos = 0;
gtk_im_context_get_preedit_string(m_im_context.get(), &str, &attrs, &cursorpos);
- if (str == nullptr)
- return;
-
_vte_debug_print(VTE_DEBUG_EVENTS, "Input method pre-edit changed (%s,%d).\n",
str, cursorpos);
- m_terminal->im_preedit_changed(str, cursorpos, attrs);
+ if (str != nullptr)
+ m_terminal->im_preedit_changed(str, cursorpos, {attrs, &pango_attr_list_unref});
+ else
+ pango_attr_list_unref(attrs);
+
g_free(str);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]