[vte] terminal: Use an enum class for cursor shape
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] terminal: Use an enum class for cursor shape
- Date: Mon, 18 Nov 2019 21:43:30 +0000 (UTC)
commit b7667a5209d3e64ebaedd7db7b8e1bd7e6f99a8f
Author: Christian Persch <chpe src gnome org>
Date: Mon Nov 18 22:42:22 2019 +0100
terminal: Use an enum class for cursor shape
src/vte.cc | 23 ++++++++++-------------
src/vtegtk.cc | 4 ++--
src/vteinternal.hh | 14 +++++++++++---
src/widget.hh | 3 +++
4 files changed, 26 insertions(+), 18 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 1e07eb5c..ffe84293 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -7889,9 +7889,6 @@ Terminal::Terminal(vte::platform::Widget* w,
set_delete_binding(VTE_ERASE_AUTO);
m_text_blink_mode = VTE_TEXT_BLINK_ALWAYS;
- /* Cursor shape. */
- m_cursor_shape = VTE_CURSOR_SHAPE_BLOCK;
-
/* Initialize the saved cursor. */
save_cursor(&m_normal_screen);
save_cursor(&m_alternate_screen);
@@ -9183,7 +9180,7 @@ Terminal::paint_cursor()
switch (decscusr_cursor_shape()) {
- case VTE_CURSOR_SHAPE_IBEAM: {
+ case CursorShape::eIBEAM: {
/* Draw at the very left of the cell (before the spacing), even in case of CJK.
* IMO (egmont) not overrunning the letter improves readability, vertical movement
* looks good (no zigzag even when a somewhat wider glyph that starts filling up
@@ -9216,7 +9213,7 @@ Terminal::paint_cursor()
break;
}
- case VTE_CURSOR_SHAPE_UNDERLINE: {
+ case CursorShape::eUNDERLINE: {
/* The width is at least the overall width of the cell (or two cells) minus the two
* half spacings on the two edges. That is, underlines under a CJK are more than
twice
* as wide as narrow characters in case of letter spacing. Plus, if necessary, the
width
@@ -9247,7 +9244,7 @@ Terminal::paint_cursor()
break;
}
- case VTE_CURSOR_SHAPE_BLOCK:
+ case CursorShape::eBLOCK:
/* Include the spacings in the cursor, see bug 781479 comments 39-44.
* Make the cursor even wider if the glyph is wider. */
@@ -9451,7 +9448,7 @@ Terminal::widget_draw(cairo_t *cr)
/* Re-clip, allowing VTE_LINE_WIDTH more pixel rows for the outline cursor. */
/* TODOegmont: It's really ugly to do it here. */
cairo_save(cr);
- extra_area_for_cursor = (decscusr_cursor_shape() == VTE_CURSOR_SHAPE_BLOCK && !m_has_focus) ?
VTE_LINE_WIDTH : 0;
+ extra_area_for_cursor = (decscusr_cursor_shape() == CursorShape::eBLOCK && !m_has_focus) ?
VTE_LINE_WIDTH : 0;
cairo_rectangle(cr, 0, m_padding.top - extra_area_for_cursor, allocated_width, allocated_height -
m_padding.top - m_padding.bottom + 2 * extra_area_for_cursor);
cairo_clip(cr);
@@ -9798,7 +9795,7 @@ Terminal::set_cursor_blink_mode(CursorBlinkMode mode)
}
bool
-Terminal::set_cursor_shape(VteCursorShape shape)
+Terminal::set_cursor_shape(CursorShape shape)
{
if (shape == m_cursor_shape)
return false;
@@ -9861,8 +9858,8 @@ Terminal::decscusr_cursor_blink() const noexcept
*
* Return value: cursor shape
*/
-VteCursorShape
-Terminal::decscusr_cursor_shape()
+Terminal::CursorShape
+Terminal::decscusr_cursor_shape() const noexcept
{
switch (m_cursor_style) {
default:
@@ -9870,13 +9867,13 @@ Terminal::decscusr_cursor_shape()
return m_cursor_shape;
case CursorStyle::eBLINK_BLOCK:
case CursorStyle::eSTEADY_BLOCK:
- return VTE_CURSOR_SHAPE_BLOCK;
+ return CursorShape::eBLOCK;
case CursorStyle::eBLINK_UNDERLINE:
case CursorStyle::eSTEADY_UNDERLINE:
- return VTE_CURSOR_SHAPE_UNDERLINE;
+ return CursorShape::eUNDERLINE;
case CursorStyle::eBLINK_IBEAM:
case CursorStyle::eSTEADY_IBEAM:
- return VTE_CURSOR_SHAPE_IBEAM;
+ return CursorShape::eIBEAM;
}
}
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 62236640..81f035d6 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -3794,7 +3794,7 @@ vte_terminal_get_cursor_shape(VteTerminal *terminal)
{
g_return_val_if_fail(VTE_IS_TERMINAL(terminal), VTE_CURSOR_SHAPE_BLOCK);
- return IMPL(terminal)->m_cursor_shape;
+ return WIDGET(terminal)->cursor_shape();
}
/**
@@ -3810,7 +3810,7 @@ vte_terminal_set_cursor_shape(VteTerminal *terminal, VteCursorShape shape)
g_return_if_fail(VTE_IS_TERMINAL(terminal));
g_return_if_fail(shape >= VTE_CURSOR_SHAPE_BLOCK && shape <= VTE_CURSOR_SHAPE_UNDERLINE);
- if (IMPL(terminal)->set_cursor_shape(shape))
+ if (WIDGET(terminal)->set_cursor_shape(shape))
g_object_notify_by_pspec(G_OBJECT(terminal), pspecs[PROP_CURSOR_SHAPE]);
}
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 8f62573a..0fc77da5 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -340,6 +340,13 @@ protected:
eOFF
};
+ /* NOTE: This needs to be kept in sync with the public VteCursorShape enum */
+ enum class CursorShape {
+ eBLOCK,
+ eIBEAM,
+ eUNDERLINE
+ };
+
public:
Terminal(vte::platform::Widget* w,
VteTerminal *t);
@@ -499,7 +506,7 @@ public:
gboolean m_scrolling_restricted;
/* Cursor shape, as set via API */
- VteCursorShape m_cursor_shape;
+ CursorShape m_cursor_shape{CursorShape::eBLOCK};
double m_cursor_aspect_ratio{0.04};
/* Cursor blinking */
@@ -845,7 +852,7 @@ public:
void remove_cursor_timeout();
void update_cursor_blinks();
CursorBlinkMode decscusr_cursor_blink() const noexcept;
- VteCursorShape decscusr_cursor_shape();
+ CursorShape decscusr_cursor_shape() const noexcept;
void remove_text_blink_timeout();
@@ -1293,7 +1300,8 @@ public:
void set_colors_default();
bool set_cursor_blink_mode(CursorBlinkMode mode);
auto cursor_blink_mode() const noexcept { return m_cursor_blink_mode; }
- bool set_cursor_shape(VteCursorShape shape);
+ bool set_cursor_shape(CursorShape shape);
+ auto cursor_shape() const noexcept { return m_cursor_shape; }
bool set_cursor_style(CursorStyle style);
bool set_delete_binding(VteEraseBinding binding);
bool set_enable_bidi(bool setting);
diff --git a/src/widget.hh b/src/widget.hh
index 53e3d7be..b5452cbf 100644
--- a/src/widget.hh
+++ b/src/widget.hh
@@ -108,6 +108,9 @@ public:
bool set_cursor_blink_mode(VteCursorBlinkMode mode) { return
terminal()->set_cursor_blink_mode(vte::terminal::Terminal::CursorBlinkMode(mode)); }
auto cursor_blink_mode() const noexcept { return
VteCursorBlinkMode(terminal()->cursor_blink_mode()); }
+ bool set_cursor_shape(VteCursorShape shape) { return
terminal()->set_cursor_shape(vte::terminal::Terminal::CursorShape(shape)); }
+ auto cursor_shape() const noexcept { return VteCursorShape(terminal()->cursor_shape()); }
+
char const* encoding() const noexcept { return m_terminal->encoding(); }
void emit_child_exited(int status) noexcept;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]