Add support for muting tabs
This commit is contained in:
parent
48c44e1b4d
commit
7a297e2e3f
@ -649,6 +649,7 @@ class AbstractTab(QWidget):
|
||||
fullscreen_requested = pyqtSignal(bool)
|
||||
renderer_process_terminated = pyqtSignal(TerminationStatus, int)
|
||||
predicted_navigation = pyqtSignal(QUrl)
|
||||
audio_muted_changed = pyqtSignal(bool)
|
||||
|
||||
def __init__(self, *, win_id, mode_manager, private, parent=None):
|
||||
self.private = private
|
||||
@ -923,3 +924,11 @@ class AbstractTab(QWidget):
|
||||
|
||||
def is_deleted(self):
|
||||
return sip.isdeleted(self._widget)
|
||||
|
||||
def set_muted(self, muted: bool):
|
||||
"""Set this tab as muted or not."""
|
||||
raise NotImplementedError
|
||||
|
||||
def is_muted(self):
|
||||
"""Whether this tab is muted."""
|
||||
raise NotImplementedError
|
||||
|
@ -2230,3 +2230,20 @@ class CommandDispatcher:
|
||||
|
||||
window = self._tabbed_browser.widget.window()
|
||||
window.setWindowState(window.windowState() ^ Qt.WindowFullScreen)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window',
|
||||
name='tab-mute')
|
||||
@cmdutils.argument('count', count=True)
|
||||
def tab_mute(self, count=None):
|
||||
"""Mute/Unmute the current/[count]th tab.
|
||||
|
||||
Args:
|
||||
count: The tab index to pin or unpin, or None
|
||||
"""
|
||||
tab = self._cntwidget(count)
|
||||
if tab is None:
|
||||
return
|
||||
try:
|
||||
tab.set_muted(not tab.is_muted())
|
||||
except browsertab.WebTabError as e:
|
||||
raise cmdexc.CommandError(e)
|
||||
|
@ -1092,6 +1092,7 @@ class WebEngineTab(browsertab.AbstractTab):
|
||||
page.fullScreenRequested.connect(self._on_fullscreen_requested)
|
||||
page.contentsSizeChanged.connect(self.contents_size_changed)
|
||||
page.navigation_request.connect(self._on_navigation_request)
|
||||
page.audioMutedChanged.connect(self.audio_muted_changed)
|
||||
|
||||
view.titleChanged.connect(self.title_changed)
|
||||
view.urlChanged.connect(self._on_url_changed)
|
||||
@ -1116,3 +1117,11 @@ class WebEngineTab(browsertab.AbstractTab):
|
||||
|
||||
def event_target(self):
|
||||
return self._widget.focusProxy()
|
||||
|
||||
def set_muted(self, muted: bool):
|
||||
page = self._widget.page()
|
||||
page.setAudioMuted(muted)
|
||||
|
||||
def is_muted(self):
|
||||
page = self._widget.page()
|
||||
return page.isAudioMuted()
|
||||
|
@ -828,3 +828,10 @@ class WebKitTab(browsertab.AbstractTab):
|
||||
|
||||
def event_target(self):
|
||||
return self._widget
|
||||
|
||||
def set_muted(self, muted: bool):
|
||||
raise browsertab.WebTabError('Muting is not supported on QtWebKit!')
|
||||
|
||||
def is_muted(self):
|
||||
# Dummy value for things that read muted status
|
||||
return False
|
||||
|
@ -1359,6 +1359,7 @@ tabs.title.format:
|
||||
- private
|
||||
- current_url
|
||||
- protocol
|
||||
- muted
|
||||
none_ok: true
|
||||
desc: |
|
||||
Format to use for the tab title.
|
||||
@ -1376,6 +1377,7 @@ tabs.title.format:
|
||||
* `{private}`: Indicates when private mode is enabled.
|
||||
* `{current_url}`: URL of the current web page.
|
||||
* `{protocol}`: Protocol (http/https/...) of the current web page.
|
||||
* `{muted}`: Icon if the tab is muted
|
||||
|
||||
tabs.title.format_pinned:
|
||||
default: '{index}'
|
||||
@ -1393,6 +1395,7 @@ tabs.title.format_pinned:
|
||||
- private
|
||||
- current_url
|
||||
- protocol
|
||||
- muted
|
||||
none_ok: true
|
||||
desc: Format to use for the tab title for pinned tabs. The same placeholders
|
||||
like for `tabs.title.format` are defined.
|
||||
@ -1560,6 +1563,7 @@ window.title_format:
|
||||
- private
|
||||
- current_url
|
||||
- protocol
|
||||
- muted
|
||||
default: '{perc}{title}{title_sep}qutebrowser'
|
||||
desc: |
|
||||
Format to use for the window title. The same placeholders like for
|
||||
|
@ -238,6 +238,8 @@ class TabbedBrowser(QWidget):
|
||||
functools.partial(self.on_window_close_requested, tab))
|
||||
tab.renderer_process_terminated.connect(
|
||||
functools.partial(self._on_renderer_process_terminated, tab))
|
||||
tab.audio_muted_changed.connect(
|
||||
functools.partial(self.on_mute_changed, tab))
|
||||
tab.new_tab_requested.connect(self.tabopen)
|
||||
if not self.private:
|
||||
web_history = objreg.get('web-history')
|
||||
@ -733,6 +735,18 @@ class TabbedBrowser(QWidget):
|
||||
self._update_window_title('scroll_pos')
|
||||
self.widget.update_tab_title(idx, 'scroll_pos')
|
||||
|
||||
@pyqtSlot()
|
||||
def on_mute_changed(self, tab, muted):
|
||||
"""Update tab and window title when scroll position changed."""
|
||||
try:
|
||||
idx = self._tab_index(tab)
|
||||
except TabDeletedError:
|
||||
# We can get signals for tabs we already deleted...
|
||||
return
|
||||
self.widget.update_tab_title(idx, 'muted')
|
||||
if idx == self.widget.currentIndex():
|
||||
self._update_window_title('muted')
|
||||
|
||||
def _on_renderer_process_terminated(self, tab, status, code):
|
||||
"""Show an error when a renderer process terminated."""
|
||||
if status == browsertab.TerminationStatus.normal:
|
||||
|
@ -172,6 +172,7 @@ class TabWidget(QTabWidget):
|
||||
fields['perc_raw'] = tab.progress()
|
||||
fields['backend'] = objects.backend.name
|
||||
fields['private'] = ' [Private Mode] ' if tab.private else ''
|
||||
fields['muted'] = '[M] ' if tab.is_muted() else ''
|
||||
|
||||
if tab.load_status() == usertypes.LoadStatus.loading:
|
||||
fields['perc'] = '[{}%] '.format(tab.progress())
|
||||
|
Loading…
Reference in New Issue
Block a user