[vte] widget: Store the usable view area
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] widget: Store the usable view area
- Date: Tue, 22 Dec 2015 21:47:33 +0000 (UTC)
commit a202fa4ada43bd4383a4e4ca6606be04ed8fb9d1
Author: Christian Persch <chpe gnome org>
Date: Tue Dec 22 22:47:13 2015 +0100
widget: Store the usable view area
src/vte.cc | 21 ++++++++-------------
src/vteinternal.hh | 17 +++++++++++++----
src/vteseq.cc | 4 ++--
src/vtetypes.cc | 8 ++++++++
src/vtetypes.hh | 21 +++++++++++++++++++--
5 files changed, 50 insertions(+), 21 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index 016d3a7..58baca1 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -268,13 +268,6 @@ VteTerminalPrivate::reset_default_attributes()
m_defaults = m_color_defaults = m_fill_defaults = basic_cell.cell;
}
-/* Height excluding padding, but including additional bottom area if not grid aligned */
-inline vte::view::coord_t
-VteTerminalPrivate::usable_height_px() const
-{
- return get_allocated_height() - m_padding.top - m_padding.bottom;
-}
-
//FIXMEchpe this function is bad
inline vte::view::coord_t
VteTerminalPrivate::scroll_delta_pixel() const
@@ -318,7 +311,7 @@ inline vte::grid::row_t
VteTerminalPrivate::last_displayed_row() const
{
/* Get the logical row number displayed at the bottom pixel position */
- auto r = pixel_to_row(usable_height_px() - 1);
+ auto r = pixel_to_row(m_view_usable_extents.height() - 1);
/* If we have an extra padding at the bottom which is currently unused,
* this number is one too big. Adjust here.
@@ -1892,7 +1885,7 @@ VteTerminalPrivate::rowcol_from_event(GdkEvent *event,
x -= m_padding.left;
y -= m_padding.top;
if (x < 0 || x >= m_column_count * m_char_width ||
- y < 0 || y >= usable_height_px())
+ y < 0 || y >= m_view_usable_extents.height())
return false;
*column = x / m_char_width;
*row = pixel_to_row(y);
@@ -4643,6 +4636,7 @@ VteTerminalPrivate::widget_style_updated()
new_padding.top, new_padding.bottom);
m_padding = new_padding;
+ update_view_extents();
gtk_widget_queue_resize(m_widget);
}
@@ -5493,8 +5487,8 @@ _vte_terminal_size_to_grid_size(VteTerminal *terminal,
VteTerminalPrivate *pvt = terminal->pvt;
long n_cols, n_rows;
- n_cols = (w - pvt->padding.left - pvt->padding.right) / pvt->char_width;
- n_rows = (h - pvt->padding.top -pvt->padding.bottom) / pvt->char_height;
+ n_cols = (w - pvt->m_padding.left - pvt->m_padding.right) / pvt->char_width;
+ n_rows = (h - pvt->m_padding.top -pvt->m_padding.bottom) / pvt->char_height;
if (n_cols <= 0 || n_rows <= 0)
return FALSE;
@@ -6450,7 +6444,7 @@ VteTerminalPrivate::confine_coordinates(long *xp,
long y_stop;
/* Allow to use the bottom extra padding only if there's content there. */
- y_stop = MIN(usable_height_px(),
+ y_stop = MIN(m_view_usable_extents.height(),
row_to_pixel(m_screen->insert_delta + m_row_count));
if (y < 0) {
@@ -7041,7 +7035,7 @@ VteTerminalPrivate::autoscroll()
}
_vte_debug_print(VTE_DEBUG_EVENTS, "Autoscrolling down.\n");
}
- if (m_mouse_last_y >= usable_height_px()) {
+ if (m_mouse_last_y >= m_view_usable_extents.height()) {
if (m_vadjustment) {
/* Try to scroll up by one line. */
adj = m_screen->scroll_delta + 1;
@@ -8167,6 +8161,7 @@ VteTerminalPrivate::VteTerminalPrivate(VteTerminal *t) :
m_visibility_state = GDK_VISIBILITY_UNOBSCURED;
m_padding = default_padding;
+ update_view_extents();
}
void
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 6804db1..4a9158a 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -434,7 +434,7 @@ public:
glong strikethrough_position;
/* Style stuff */
- GtkBorder padding;
+ GtkBorder m_padding;
/* GtkScrollable impl */
GtkAdjustment *hadjustment; /* unused */
@@ -445,7 +445,6 @@ public:
public:
- inline vte::view::coord_t usable_height_px() const;
inline vte::view::coord_t scroll_delta_pixel() const;
inline vte::grid::row_t pixel_to_row(vte::view::coord_t y) const;
inline vte::view::coord_t row_to_pixel(vte::grid::row_t row) const;
@@ -496,8 +495,19 @@ public:
VteCursorBlinkMode decscusr_cursor_blink();
VteCursorShape decscusr_cursor_shape();
+ /* The allocation of the widget */
cairo_rectangle_int_t m_allocated_rect;
- void set_allocated_rect(cairo_rectangle_int_t const& r) { m_allocated_rect = r; }
+ /* The usable view area. This is the allocation, minus the padding, but
+ * including additional right/bottom area if the allocation is not grid aligned.
+ */
+ vte::view::extents m_view_usable_extents;
+
+ void set_allocated_rect(cairo_rectangle_int_t const& r) { m_allocated_rect = r;
update_view_extents(); }
+ void update_view_extents() {
+ m_view_usable_extents =
+ vte::view::extents(m_allocated_rect.width - m_padding.left - m_padding.right,
+ m_allocated_rect.height - m_padding.top - m_padding.bottom);
+ }
inline bool widget_realized() const { return gtk_widget_get_realized(m_widget); }
inline cairo_rectangle_int_t const& get_allocated_rect() const { return m_allocated_rect; }
@@ -975,7 +985,6 @@ public:
#define m_invalidated_all invalidated_all
#define m_column_count column_count
#define m_row_count row_count
-#define m_padding padding
#define m_char_width char_width
#define m_char_height char_height
#define m_active active
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 94cef3e..30a57b2 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -2970,8 +2970,8 @@ vte_sequence_handler_window_manipulation (VteTerminal *terminal, GValueArray *pa
&width, &height);
g_snprintf(buf, sizeof(buf),
_VTE_CAP_CSI "3;%d;%dt",
- width + terminal->pvt->padding.left,
- height + terminal->pvt->padding.top);
+ width + terminal->pvt->m_padding.left,
+ height + terminal->pvt->m_padding.top);
_vte_debug_print(VTE_DEBUG_PARSE,
"Reporting window location"
"(%d++,%d++).\n",
diff --git a/src/vtetypes.cc b/src/vtetypes.cc
index 3d88910..1365a29 100644
--- a/src/vtetypes.cc
+++ b/src/vtetypes.cc
@@ -160,6 +160,14 @@ vte::view::coords::to_string() const
}
char const*
+vte::view::extents::to_string() const
+{
+ char *buf = debug_get_buf();
+ g_snprintf(buf, DEBUG_STRING_SIZE, "view::extents[%ld x %ld]", width(), height());
+ return buf;
+}
+
+char const*
vte::color::rgb::to_string() const
{
char *buf = debug_get_buf();
diff --git a/src/vtetypes.hh b/src/vtetypes.hh
index 0096e33..eff2743 100644
--- a/src/vtetypes.hh
+++ b/src/vtetypes.hh
@@ -99,13 +99,12 @@ namespace grid {
} /* namespace grid */
-
namespace view {
/* FIXMEchpe: actually 32-bit int would be sufficient here */
typedef long coord_t;
- struct coords {
+ class coords {
public:
coords() = default;
coords(coord_t x_, coord_t y_) : x(x_), y(y_) { }
@@ -122,6 +121,24 @@ namespace view {
coord_t y;
};
+ class extents {
+ public:
+ extents() = default;
+ extents(coord_t w, coord_t h) : m_width(w), m_height(h) { }
+
+ inline coord_t width() const { return m_width; }
+ inline coord_t height() const { return m_height; }
+
+ inline bool operator == (extents const& rhs) const { return m_width == rhs.m_width &&
m_height == rhs.m_height; }
+ inline bool operator != (extents const& rhs) const { return m_width != rhs.m_width ||
m_height != rhs.m_height; }
+
+ IFDEF_DEBUG(char const* to_string() const);
+
+ private:
+ coord_t m_width;
+ coord_t m_height;
+ };
+
} /* namespace view */
namespace color {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]