We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Have logger scroll automatically only when at the bottom
Currently the logger scrolls whenever it outputs which makes scrolling up useless unless the game is stopped. This behavior is annoying.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lutris/gui/logwindow.py`
Content:
```
1 from gi.repository import Gtk
2 from lutris.gui.widgets.dialogs import Dialog
3 
4 
5 class LogTextView(Gtk.TextView):
6     def __init__(self, buffer):
7         super(LogTextView, self).__init__()
8 
9         self.set_buffer(buffer)
10         self.set_editable(False)
11         self.set_monospace(True)
12         self.set_left_margin(10)
13         self.set_wrap_mode(Gtk.WrapMode.CHAR)
14         self.get_style_context().add_class('lutris-logview')
15         self.connect("size-allocate", self.autoscroll)
16 
17     def autoscroll(self, *args):
18         adj = self.get_vadjustment()
19         adj.set_value(adj.get_upper() - adj.get_page_size())
20 
21 
22 class LogWindow(Dialog):
23     def __init__(self, title, buffer, parent):
24         super(LogWindow, self).__init__(title, parent, 0,
25                                         ('_OK', Gtk.ResponseType.OK))
26         self.set_size_request(640, 480)
27         self.grid = Gtk.Grid()
28         self.buffer = buffer
29         self.logtextview = LogTextView(self.buffer)
30 
31         scrolledwindow = Gtk.ScrolledWindow(hexpand=True, vexpand=True,
32                                             child=self.logtextview)
33         self.vbox.add(scrolledwindow)
34         self.show_all()
35
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lutris/gui/logwindow.py b/lutris/gui/logwindow.py
--- a/lutris/gui/logwindow.py
+++ b/lutris/gui/logwindow.py
@@ -10,13 +10,16 @@
         self.set_editable(False)
         self.set_monospace(True)
         self.set_left_margin(10)
+        self.scroll_max = 0
         self.set_wrap_mode(Gtk.WrapMode.CHAR)
         self.get_style_context().add_class('lutris-logview')
         self.connect("size-allocate", self.autoscroll)
 
     def autoscroll(self, *args):
         adj = self.get_vadjustment()
-        adj.set_value(adj.get_upper() - adj.get_page_size())
+        if adj.get_value() == self.scroll_max or self.scroll_max == 0:
+            adj.set_value(adj.get_upper() - adj.get_page_size())
+        self.scroll_max = adj.get_upper() - adj.get_page_size()
 
 
 class LogWindow(Dialog):

{"golden_diff": "diff --git a/lutris/gui/logwindow.py b/lutris/gui/logwindow.py\n--- a/lutris/gui/logwindow.py\n+++ b/lutris/gui/logwindow.py\n@@ -10,13 +10,16 @@\n         self.set_editable(False)\n         self.set_monospace(True)\n         self.set_left_margin(10)\n+        self.scroll_max = 0\n         self.set_wrap_mode(Gtk.WrapMode.CHAR)\n         self.get_style_context().add_class('lutris-logview')\n         self.connect(\"size-allocate\", self.autoscroll)\n \n     def autoscroll(self, *args):\n         adj = self.get_vadjustment()\n-        adj.set_value(adj.get_upper() - adj.get_page_size())\n+        if adj.get_value() == self.scroll_max or self.scroll_max == 0:\n+            adj.set_value(adj.get_upper() - adj.get_page_size())\n+        self.scroll_max = adj.get_upper() - adj.get_page_size()\n \n \n class LogWindow(Dialog):\n", "issue": "Have logger scroll automatically only when at the bottom\nCurrently the logger scrolls whenever it outputs which makes scrolling up useless unless the game is stopped. This behavior is annoying.\n", "before_files": [{"content": "from gi.repository import Gtk\nfrom lutris.gui.widgets.dialogs import Dialog\n\n\nclass LogTextView(Gtk.TextView):\n    def __init__(self, buffer):\n        super(LogTextView, self).__init__()\n\n        self.set_buffer(buffer)\n        self.set_editable(False)\n        self.set_monospace(True)\n        self.set_left_margin(10)\n        self.set_wrap_mode(Gtk.WrapMode.CHAR)\n        self.get_style_context().add_class('lutris-logview')\n        self.connect(\"size-allocate\", self.autoscroll)\n\n    def autoscroll(self, *args):\n        adj = self.get_vadjustment()\n        adj.set_value(adj.get_upper() - adj.get_page_size())\n\n\nclass LogWindow(Dialog):\n    def __init__(self, title, buffer, parent):\n        super(LogWindow, self).__init__(title, parent, 0,\n                                        ('_OK', Gtk.ResponseType.OK))\n        self.set_size_request(640, 480)\n        self.grid = Gtk.Grid()\n        self.buffer = buffer\n        self.logtextview = LogTextView(self.buffer)\n\n        scrolledwindow = Gtk.ScrolledWindow(hexpand=True, vexpand=True,\n                                            child=self.logtextview)\n        self.vbox.add(scrolledwindow)\n        self.show_all()\n", "path": "lutris/gui/logwindow.py"}], "after_files": [{"content": "from gi.repository import Gtk\nfrom lutris.gui.widgets.dialogs import Dialog\n\n\nclass LogTextView(Gtk.TextView):\n    def __init__(self, buffer):\n        super(LogTextView, self).__init__()\n\n        self.set_buffer(buffer)\n        self.set_editable(False)\n        self.set_monospace(True)\n        self.set_left_margin(10)\n        self.scroll_max = 0\n        self.set_wrap_mode(Gtk.WrapMode.CHAR)\n        self.get_style_context().add_class('lutris-logview')\n        self.connect(\"size-allocate\", self.autoscroll)\n\n    def autoscroll(self, *args):\n        adj = self.get_vadjustment()\n        if adj.get_value() == self.scroll_max or self.scroll_max == 0:\n            adj.set_value(adj.get_upper() - adj.get_page_size())\n        self.scroll_max = adj.get_upper() - adj.get_page_size()\n\n\nclass LogWindow(Dialog):\n    def __init__(self, title, buffer, parent):\n        super(LogWindow, self).__init__(title, parent, 0,\n                                        ('_OK', Gtk.ResponseType.OK))\n        self.set_size_request(640, 480)\n        self.grid = Gtk.Grid()\n        self.buffer = buffer\n        self.logtextview = LogTextView(self.buffer)\n\n        scrolledwindow = Gtk.ScrolledWindow(hexpand=True, vexpand=True,\n                                            child=self.logtextview)\n        self.vbox.add(scrolledwindow)\n        self.show_all()\n", "path": "lutris/gui/logwindow.py"}]}