about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2021-05-25 10:15:40 +0200
committerSören Tempel <soeren+git@soeren-tempel.net>2021-05-25 22:09:19 +0200
commite72f61fb3af060eb018d17fd0d324741503c15ed (patch)
tree7b17fb05d444fbb13d66d5a9bc5e78f629319be5
parent61ca4b802c7df75de8a31c6e409eeae15190accf (diff)
Add workaround for annoying scrollbar if wordwrap is enabled
There is an issue [1] in GTK 3 which causes the automatic hyphenation of
GtkTextViews to cause a horizontal scroll bar to appear despite it being
not necessary (in our case the horizontal scrollbar is rendered over the
hyphens which is hardly cause for concern).

Ideally we would just disable auto hyphenation, but this doesn't seem to
be possible [2] in GTK 3 yet. As a workaround we just disable horizontal
scrolling altogether in in update_wrapmode() if wordwrap is enabled.

While we're at it add a note about the GTK 4 feature [3] which would
allow us to disable auto hyphenation. For GTK 3 it seems to require to
set a pango [4] attribute in the pango layout used for rendering the
widget which is not exposed in a modifiable way by GtkTextView
unfortunately -- or at least I haven't been able to figure out how the
desired result could be achieved.

[1]: https://gitlab.gnome.org/GNOME/gtk/-/issues/2384
[2]: https://gitlab.gnome.org/GNOME/gtk/-/issues/2530
[3]: https://docs.gtk.org/gtk4/property.TextTag.insert-hyphens.html
[4]: See these solutions of other projects that ran into this issue:
     https://github.com/mate-desktop/caja/pull/1334
     https://gitlab.gnome.org/GNOME/nautilus/-/merge_requests/482
-rw-r--r--saneterm/terminal.py6
-rw-r--r--saneterm/termview.py2
2 files changed, 7 insertions, 1 deletions
diff --git a/saneterm/terminal.py b/saneterm/terminal.py
index c48ea04..fcfe0e9 100644
--- a/saneterm/terminal.py
+++ b/saneterm/terminal.py
@@ -72,7 +72,6 @@ class Terminal(Gtk.Window):
         self.pty.attach(None)
 
         self.termview = TermView()
-        self.update_wrapmode()
 
         # Block-wise reading from the PTY requires an incremental decoder.
         self.decoder = codecs.getincrementaldecoder('UTF-8')()
@@ -95,6 +94,8 @@ class Terminal(Gtk.Window):
         self.scroll.add(self.termview)
         self.add(self.scroll)
 
+        self.update_wrapmode()
+
         GObject.signal_new("history-entry", self.termview,
                 GObject.SIGNAL_ACTION, GObject.TYPE_NONE,
                 (GObject.TYPE_LONG,))
@@ -107,6 +108,9 @@ class Terminal(Gtk.Window):
         mode = Gtk.WrapMode.WORD_CHAR if self.config['wordwrap'] else Gtk.WrapMode.NONE
         self.termview.set_wrap_mode(mode)
 
+        scroll_policy = Gtk.PolicyType.NEVER if self.config['wordwrap'] else Gtk.PolicyType.AUTOMATIC
+        self.scroll.set_policy(scroll_policy, self.scroll.get_policy()[1])
+
     def update_size(self, widget, rect):
         # PTY must already be initialized
         if self.pty.master == -1:
diff --git a/saneterm/termview.py b/saneterm/termview.py
index 7276977..ef2af57 100644
--- a/saneterm/termview.py
+++ b/saneterm/termview.py
@@ -28,6 +28,8 @@ class TermView(Gtk.TextView):
     """
 
     def __init__(self):
+        # TODO: set insert-hypens to false in GTK 4
+        # https://docs.gtk.org/gtk4/property.TextTag.insert-hyphens.html
         Gtk.TextView.__init__(self)
 
         self.set_monospace(True)