From 717298e42370443861db53a043bd452406174c76 Mon Sep 17 00:00:00 2001 From: Alexey Nabrodov Date: Fri, 25 Sep 2015 19:06:44 +0300 Subject: [PATCH 1/5] add scroll_pos to title-format --- qutebrowser/config/configdata.py | 2 +- qutebrowser/mainwindow/tabwidget.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 5f04ed9f9..634394b88 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -534,7 +534,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" diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 893af0748..84e95b094 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -112,6 +112,15 @@ class TabWidget(QTabWidget): 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'] = '{}'.format(scroll_pos) fmt = config.get('tabs', 'title-format') self.tabBar().setTabText(idx, fmt.format(**fields)) @@ -158,6 +167,7 @@ class TabWidget(QTabWidget): text = text_or_empty new_idx = super().addTab(page, icon, '') self.set_page_title(new_idx, text) + page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx)) return new_idx def insertTab(self, idx, page, icon_or_text, text_or_empty=None): @@ -188,6 +198,7 @@ class TabWidget(QTabWidget): text = text_or_empty new_idx = super().insertTab(idx, page, icon, '') self.set_page_title(new_idx, text) + page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx)) return new_idx @pyqtSlot(int) From 1b6860b74880ab6b025a637bc6c547479980cb14 Mon Sep 17 00:00:00 2001 From: Alexey Nabrodov Date: Mon, 28 Sep 2015 19:43:50 +0300 Subject: [PATCH 2/5] add scroll_pos to window title && fix signals --- qutebrowser/config/configdata.py | 8 +++++--- qutebrowser/mainwindow/tabbedbrowser.py | 16 ++++++++++++++++ qutebrowser/mainwindow/tabwidget.py | 4 +--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 634394b88..6656e20ec 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -299,7 +299,7 @@ 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 +308,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." + "* `{scroll_pos}`: The page scroll position."), ('hide-mouse-cursor', SettingValue(typ.Bool(), 'false'), @@ -543,7 +544,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." + "* `{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 index 14817ac30..1cdfb1aed 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -165,6 +165,15 @@ class TabbedBrowser(tabwidget.TabWidget): 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 @@ class TabbedBrowser(tabwidget.TabWidget): 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 @@ class TabbedBrowser(tabwidget.TabWidget): if idx == self.currentIndex(): self.update_window_title() + @pyqtSlot(int, int) + def on_scroll_pos_changed(self, x, y): + """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 index 84e95b094..50b7c7dd4 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -120,7 +120,7 @@ class TabWidget(QTabWidget): else: scroll_pos = '{:2}%'.format(y) - fields['scroll_pos'] = '{}'.format(scroll_pos) + fields['scroll_pos'] = str(scroll_pos) fmt = config.get('tabs', 'title-format') self.tabBar().setTabText(idx, fmt.format(**fields)) @@ -167,7 +167,6 @@ class TabWidget(QTabWidget): text = text_or_empty new_idx = super().addTab(page, icon, '') self.set_page_title(new_idx, text) - page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx)) return new_idx def insertTab(self, idx, page, icon_or_text, text_or_empty=None): @@ -198,7 +197,6 @@ class TabWidget(QTabWidget): text = text_or_empty new_idx = super().insertTab(idx, page, icon, '') self.set_page_title(new_idx, text) - page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx)) return new_idx @pyqtSlot(int) From 7cd7b43e7a8b6610f9d35d67577aa4f2b9df0d2d Mon Sep 17 00:00:00 2001 From: Alexey Nabrodov Date: Mon, 28 Sep 2015 19:53:55 +0300 Subject: [PATCH 3/5] fix docs --- qutebrowser/config/configdata.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 6656e20ec..9f3d01f33 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -308,7 +308,7 @@ 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', @@ -544,7 +544,7 @@ 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', From a98878dd8afb9aa5d5ffa565be8ba27cde2e3644 Mon Sep 17 00:00:00 2001 From: Alexey Nabrodov Date: Tue, 29 Sep 2015 12:07:35 +0300 Subject: [PATCH 4/5] fix unused coords --- qutebrowser/mainwindow/tabbedbrowser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 1cdfb1aed..9c181ddfc 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -587,8 +587,8 @@ class TabbedBrowser(tabwidget.TabWidget): if idx == self.currentIndex(): self.update_window_title() - @pyqtSlot(int, int) - def on_scroll_pos_changed(self, x, y): + @pyqtSlot() + def on_scroll_pos_changed(self, *args): """Update tab and window title when scroll position changed.""" self.update_window_title() self.update_tab_titles() From 75d53e2879de3b4ad3c6f144f4c122af77915cfa Mon Sep 17 00:00:00 2001 From: Alexey Nabrodov Date: Tue, 29 Sep 2015 12:19:47 +0300 Subject: [PATCH 5/5] and again --- qutebrowser/config/configdata.py | 3 ++- qutebrowser/mainwindow/tabbedbrowser.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 9f3d01f33..ba63e02be 100644 --- 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', 'scroll_pos']), + '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" diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 9c181ddfc..26fd08923 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -588,7 +588,7 @@ class TabbedBrowser(tabwidget.TabWidget): self.update_window_title() @pyqtSlot() - def on_scroll_pos_changed(self, *args): + def on_scroll_pos_changed(self): """Update tab and window title when scroll position changed.""" self.update_window_title() self.update_tab_titles()