[gnome-builder] Disable 'scroll-on-output' in build log panel
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] Disable 'scroll-on-output' in build log panel
- Date: Mon, 12 Dec 2016 19:31:46 +0000 (UTC)
commit 60b5efe466d2dea347f41d53738068a6823ba11a
Author: kritarth <kritarth 3010 gmail com>
Date: Mon Dec 12 23:59:35 2016 +0530
Disable 'scroll-on-output' in build log panel
Currently, the build log panel is bound to scroll to end whenever new output
is added to the buffer using gtk_text_view_scroll_to_mark. In order to disable
this auto-scrolling I added horizontal and vertical GtkAdjustments. These
adjustments are initialised in gbp_build_log_panel_init(). They point to
the adjustments of GtkScrolledWindow scroller. With these adjustments I check
if the user has scrolled back or right manually.
expression1: value >= upper - page_size - offset
This expression returns true if the user has not scrolled vertically back.
The 'offset' is defined as VERTICAL_AUTOSCROLL_TOLERENCE - this means the
limit upto which scroll-on-output will still work even if the user has
manually scrolled.
Similarly HORIZONTAL_AUTOSCROLL_TOLERENCE is defined.
Detection of horizontal scrolling is done by
expression2: value <= HORIZONTAL_AUTOSCROLL_TOLERENCE
HORIZONTAL_AUTOSCROLL_TOLERENCE is set to 3 because the left-margin of text_view is also set at 3.
if (expression1 && expression2) then
set the vertical adjustment to upper - page_size
apply this adjustment to the container
https://bugzilla.gnome.org/show_bug.cgi?id=775642
plugins/build-tools/gbp-build-log-panel.c | 25 ++++++++++++++++++++++---
1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/plugins/build-tools/gbp-build-log-panel.c b/plugins/build-tools/gbp-build-log-panel.c
index 59d02e0..a6a015c 100644
--- a/plugins/build-tools/gbp-build-log-panel.c
+++ b/plugins/build-tools/gbp-build-log-panel.c
@@ -25,6 +25,9 @@
#include "gbp-build-log-panel.h"
+#define HORIZONTAL_AUTOSCROLL_TOLERENCE 3.0
+#define VERTICAL_AUTOSCROLL_TOLERENCE 30.0
+
struct _GbpBuildLogPanel
{
PnlDockWidget parent_instance;
@@ -38,6 +41,9 @@ struct _GbpBuildLogPanel
GtkScrolledWindow *scroller;
GtkTextView *text_view;
GtkTextTag *stderr_tag;
+
+ GtkAdjustment *hadjustment;
+ GtkAdjustment *vadjustment;
};
enum {
@@ -92,13 +98,23 @@ gbp_build_log_panel_log (GbpBuildLogPanel *self,
const gchar *message,
IdeBuildResult *result)
{
- GtkTextMark *insert;
GtkTextIter iter;
+ gboolean h_scroll_left;
+ gboolean v_scroll_bottom;
+ gdouble last_page_pos;
g_assert (GBP_IS_BUILD_LOG_PANEL (self));
g_assert (message != NULL);
g_assert (IDE_IS_BUILD_RESULT (result));
+ last_page_pos = gtk_adjustment_get_upper (self->vadjustment) -
+ gtk_adjustment_get_page_size (self->vadjustment);
+ h_scroll_left =
+ gtk_adjustment_get_value (self->hadjustment) <= HORIZONTAL_AUTOSCROLL_TOLERENCE;
+ v_scroll_bottom =
+ gtk_adjustment_get_value (self->vadjustment) >= last_page_pos -
+ VERTICAL_AUTOSCROLL_TOLERENCE;
+
gtk_text_buffer_get_end_iter (self->buffer, &iter);
if (G_LIKELY (log == IDE_BUILD_RESULT_LOG_STDOUT))
@@ -116,8 +132,8 @@ gbp_build_log_panel_log (GbpBuildLogPanel *self,
gtk_text_buffer_apply_tag (self->buffer, self->stderr_tag, &begin, &iter);
}
- insert = gtk_text_buffer_get_insert (self->buffer);
- gtk_text_view_scroll_to_mark (self->text_view, insert, 0.0, TRUE, 0.0, 0.0);
+ if (v_scroll_bottom && h_scroll_left)
+ gtk_adjustment_set_value (self->vadjustment, last_page_pos);
}
void
@@ -270,4 +286,7 @@ gbp_build_log_panel_init (GbpBuildLogPanel *self)
self,
G_CONNECT_SWAPPED);
gbp_build_log_panel_changed_font_name (self, "font-name", self->settings);
+
+ self->hadjustment = gtk_scrolled_window_get_hadjustment (self->scroller);
+ self->vadjustment = gtk_scrolled_window_get_vadjustment (self->scroller);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]