From 674269724f2cddd71944147d40b6c44f228efc12 Mon Sep 17 00:00:00 2001 From: Aneesh Roy Date: Mon, 16 Oct 2017 15:44:52 +0100 Subject: [PATCH 1/3] Configurable behavior of close mouse button on bar --- qutebrowser/config/configdata.yml | 10 ++++++++++ qutebrowser/mainwindow/tabbedbrowser.py | 1 + qutebrowser/mainwindow/tabwidget.py | 22 +++++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 44c405a2f..ae5c6623b 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1127,6 +1127,16 @@ tabs.close_mouse_button: - none: "Don't close tabs using the mouse." desc: On which mouse button to close tabs. +tabs.close_mouse_button_on_bar: + default: new-tab + type: + name: String + valid_values: + - new-tab: "Open a new tab." + - close-current: "Close the current tab." + - close-last: "Close the last tab." + desc: Behavior when the close mouse button is pressed on the tab bar. + tabs.favicons.scale: default: 1.0 type: diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 0571d7e34..91ae1a410 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -116,6 +116,7 @@ class TabbedBrowser(tabwidget.TabWidget): self._tab_insert_idx_right = -1 self.shutting_down = False self.tabCloseRequested.connect(self.on_tab_close_requested) + self.new_tab_requested.connect(self.openurl) self.currentChanged.connect(self.on_current_changed) self.cur_load_started.connect(self.on_cur_load_started) self.cur_fullscreen_requested.connect(self.tabBar().maybe_hide) diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 56cb922f8..ae658d42e 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -46,9 +46,11 @@ class TabWidget(QTabWidget): tab_index_changed: Emitted when the current tab was changed. arg 0: The index of the tab which is now focused. arg 1: The total count of tabs. + new_tab_requested: Emitted when a new tab is requested. """ tab_index_changed = pyqtSignal(int, int) + new_tab_requested = pyqtSignal('QUrl', bool) def __init__(self, win_id, parent=None): super().__init__(parent) @@ -59,6 +61,7 @@ class TabWidget(QTabWidget): bar.tabMoved.connect(functools.partial( QTimer.singleShot, 0, self._update_tab_titles)) bar.currentChanged.connect(self._on_current_changed) + bar.new_tab_requested.connect(self._on_new_tab_requested) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.setDocumentMode(True) self.setElideMode(Qt.ElideRight) @@ -261,6 +264,11 @@ class TabWidget(QTabWidget): self.tabBar().on_current_changed() self.tab_index_changed.emit(index, self.count()) + @pyqtSlot() + def _on_new_tab_requested(self): + """Open a new tab.""" + self.new_tab_requested.emit(config.val.url.default_page, True) + def tab_url(self, idx): """Get the URL of the tab at the given index. @@ -290,8 +298,13 @@ class TabBar(QTabBar): Attributes: vertical: When the tab bar is currently vertical. win_id: The window ID this TabBar belongs to. + + Signals: + new_tab_requested: Emitted when a new tab is requested. """ + new_tab_requested = pyqtSignal() + def __init__(self, win_id, parent=None): super().__init__(parent) self._win_id = win_id @@ -424,7 +437,14 @@ class TabBar(QTabBar): e.accept() idx = self.tabAt(e.pos()) if idx == -1: - idx = self.currentIndex() + action = config.val.tabs.close_mouse_button_on_bar + if action == 'new-tab': + self.new_tab_requested.emit() + return + elif action == 'close-current': + idx = self.currentIndex() + elif action == 'close-last': + idx = self.count() - 1 self.tabCloseRequested.emit(idx) return super().mousePressEvent(e) From 4d780e23af24005067289e35714e96c9ee3b29ad Mon Sep 17 00:00:00 2001 From: Aneesh Roy Date: Mon, 16 Oct 2017 15:49:19 +0100 Subject: [PATCH 2/3] Add tabs.close_mouse_button_on_bar ignore option --- qutebrowser/config/configdata.yml | 1 + qutebrowser/mainwindow/tabwidget.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index ae5c6623b..e8260438e 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1135,6 +1135,7 @@ tabs.close_mouse_button_on_bar: - new-tab: "Open a new tab." - close-current: "Close the current tab." - close-last: "Close the last tab." + - ignore: "Don't do anything." desc: Behavior when the close mouse button is pressed on the tab bar. tabs.favicons.scale: diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index ae658d42e..9dfd720d3 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -438,7 +438,9 @@ class TabBar(QTabBar): idx = self.tabAt(e.pos()) if idx == -1: action = config.val.tabs.close_mouse_button_on_bar - if action == 'new-tab': + if action == 'ignore': + return + elif action == 'new-tab': self.new_tab_requested.emit() return elif action == 'close-current': From 50983f01b85778b779ce3a4d249a6a804cf1f4fd Mon Sep 17 00:00:00 2001 From: Aneesh Roy Date: Mon, 16 Oct 2017 17:14:48 +0100 Subject: [PATCH 3/3] New tab opens as unrelated --- qutebrowser/mainwindow/tabbedbrowser.py | 3 ++- qutebrowser/mainwindow/tabwidget.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py index 91ae1a410..d8f883889 100644 --- a/qutebrowser/mainwindow/tabbedbrowser.py +++ b/qutebrowser/mainwindow/tabbedbrowser.py @@ -116,7 +116,7 @@ class TabbedBrowser(tabwidget.TabWidget): self._tab_insert_idx_right = -1 self.shutting_down = False self.tabCloseRequested.connect(self.on_tab_close_requested) - self.new_tab_requested.connect(self.openurl) + self.new_tab_requested.connect(self.tabopen) self.currentChanged.connect(self.on_current_changed) self.cur_load_started.connect(self.on_cur_load_started) self.cur_fullscreen_requested.connect(self.tabBar().maybe_hide) @@ -403,6 +403,7 @@ class TabbedBrowser(tabwidget.TabWidget): @pyqtSlot('QUrl') @pyqtSlot('QUrl', bool) + @pyqtSlot('QUrl', bool, bool) def tabopen(self, url=None, background=None, related=True, idx=None, *, ignore_tabs_are_windows=False): """Open a new tab with a given URL. diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 9dfd720d3..f12978604 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -50,7 +50,7 @@ class TabWidget(QTabWidget): """ tab_index_changed = pyqtSignal(int, int) - new_tab_requested = pyqtSignal('QUrl', bool) + new_tab_requested = pyqtSignal('QUrl', bool, bool) def __init__(self, win_id, parent=None): super().__init__(parent) @@ -267,7 +267,7 @@ class TabWidget(QTabWidget): @pyqtSlot() def _on_new_tab_requested(self): """Open a new tab.""" - self.new_tab_requested.emit(config.val.url.default_page, True) + self.new_tab_requested.emit(config.val.url.default_page, False, False) def tab_url(self, idx): """Get the URL of the tab at the given index.