Repository: qutebrowser/qutebrowser

Issue:
Any way to put the scroll percentage on the titlebar?
Right now the titlebar shows the page load percentage on the titlebar. Is it possible to move the scroll percentage from the statusbar to the titlebar?

Any way to put the scroll percentage on the titlebar?
Right now the titlebar shows the page load percentage on the titlebar. Is it possible to move the scroll percentage from the statusbar to the titlebar?



Discussion:
Do you mean the window title, displayed by your window manager?

You can customize it using the `ui -> window-title-format` setting - however there's no placehoder for the scroll percentage. It should be easy to add one, however.

Yes, I meant the titlebar that the window manager handles.

This kind of element is supposed to be available for Luakit, but I have not managed to make it work https://github.com/mason-larobina/luakit/wiki/Scroll-indicator-in-window-title

Do you mean the window title, displayed by your window manager?

You can customize it using the `ui -> window-title-format` setting - however there's no placehoder for the scroll percentage. It should be easy to add one, however.

Yes, I meant the titlebar that the window manager handles.

This kind of element is supposed to be available for Luakit, but I have not managed to make it work https://github.com/mason-larobina/luakit/wiki/Scroll-indicator-in-window-title


Resolving patch:
diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py
--- a/qutebrowser/config/configdata.py
+++ b/qutebrowser/config/configdata.py
@@ -299,7 +299,8 @@ def data(readonly=False):
 
             ('window-title-format',
              SettingValue(typ.FormatString(fields=['perc', 'perc_raw', 'title',
-                                                   'title_sep', 'id']),
+                                                   'title_sep', 'id',
+                                                   'scroll_pos']),
                           '{perc}{title}{title_sep}qutebrowser'),
              "The format to use for the window title. The following "
              "placeholders are defined:\n\n"
@@ -308,7 +309,8 @@ def data(readonly=False):
              "* `{title}`: The title of the current web page\n"
              "* `{title_sep}`: The string ` - ` if a title is set, empty "
              "otherwise.\n"
-             "* `{id}`: The internal window ID of this window."),
+             "* `{id}`: The internal window ID of this window.\n"
+             "* `{scroll_pos}`: The page scroll position."),
 
             ('hide-mouse-cursor',
              SettingValue(typ.Bool(), 'false'),
@@ -534,7 +536,7 @@ def data(readonly=False):
             ('title-format',
              SettingValue(typ.FormatString(
                  fields=['perc', 'perc_raw', 'title', 'title_sep', 'index',
-                         'id']), '{index}: {title}'),
+                         'id', 'scroll_pos']), '{index}: {title}'),
              "The format to use for the tab title. The following placeholders "
              "are defined:\n\n"
              "* `{perc}`: The percentage as a string like `[10%]`.\n"
@@ -543,7 +545,8 @@ def data(readonly=False):
              "* `{title_sep}`: The string ` - ` if a title is set, empty "
              "otherwise.\n"
              "* `{index}`: The index of this tab.\n"
-             "* `{id}`: The internal tab ID of this tab."),
+             "* `{id}`: The internal tab ID of this tab.\n"
+             "* `{scroll_pos}`: The page scroll position."),
 
             ('mousewheel-tab-switching',
              SettingValue(typ.Bool(), 'true'),
diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py
--- a/qutebrowser/mainwindow/tabbedbrowser.py
+++ b/qutebrowser/mainwindow/tabbedbrowser.py
@@ -165,6 +165,15 @@ def update_window_title(self):
         fields['title'] = tabtitle
         fields['title_sep'] = ' - ' if tabtitle else ''
         fields['id'] = self._win_id
+        y = widget.scroll_pos[1]
+        if y <= 0:
+            scroll_pos = 'top'
+        elif y >= 100:
+            scroll_pos = 'bot'
+        else:
+            scroll_pos = '{:2}%'.format(y)
+
+        fields['scroll_pos'] = str(scroll_pos)
         fmt = config.get('ui', 'window-title-format')
         self.window().setWindowTitle(fmt.format(**fields))
 
@@ -185,6 +194,7 @@ def _connect_tab_signals(self, tab):
             self._filter.create(self.cur_statusbar_message, tab))
         tab.scroll_pos_changed.connect(
             self._filter.create(self.cur_scroll_perc_changed, tab))
+        tab.scroll_pos_changed.connect(self.on_scroll_pos_changed)
         tab.url_text_changed.connect(
             self._filter.create(self.cur_url_text_changed, tab))
         tab.load_status_changed.connect(
@@ -577,6 +587,12 @@ def on_load_finished(self, tab):
         if idx == self.currentIndex():
             self.update_window_title()
 
+    @pyqtSlot()
+    def on_scroll_pos_changed(self):
+        """Update tab and window title when scroll position changed."""
+        self.update_window_title()
+        self.update_tab_titles()
+
     def resizeEvent(self, e):
         """Extend resizeEvent of QWidget to emit a resized signal afterwards.
 
diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py
--- a/qutebrowser/mainwindow/tabwidget.py
+++ b/qutebrowser/mainwindow/tabwidget.py
@@ -112,6 +112,15 @@ def update_tab_title(self, idx):
         fields['index'] = idx + 1
         fields['id'] = widget.tab_id
         fields['title_sep'] = ' - ' if page_title else ''
+        y = widget.scroll_pos[1]
+        if y <= 0:
+            scroll_pos = 'top'
+        elif y >= 100:
+            scroll_pos = 'bot'
+        else:
+            scroll_pos = '{:2}%'.format(y)
+
+        fields['scroll_pos'] = str(scroll_pos)
 
         fmt = config.get('tabs', 'title-format')
         self.tabBar().setTabText(idx, fmt.format(**fields))


Test patch: