From 1bf036d1bad7549a482c1bdec43a46beabcba398 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 1 Jun 2015 22:27:15 +0200 Subject: [PATCH] Add setting for the webpage bg color to use. Fixes #719. --- CHANGELOG.asciidoc | 1 + qutebrowser/browser/webview.py | 13 +++++++++++++ qutebrowser/config/configdata.py | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index aaf69e22a..92129b3e1 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -37,6 +37,7 @@ Added - New flag `-d`/`--detach` for `:spawn` to detach the spawned process so it's not closed when qutebrowser is. - New (hidden) command `:follow-selected` (bound to `Enter`/`Ctrl-Enter` by default) to follow the link which is currently selected (e.g. after searching via `/`). - New setting `ui -> modal-js-dialog` to use the standard modal dialogs for javascript questions instead of using the statusbar. +- New setting `colors -> webpage.bg` to set the background color to use for websites which don't set one. Changed ~~~~~~~ diff --git a/qutebrowser/browser/webview.py b/qutebrowser/browser/webview.py index 06176064d..584c7f268 100644 --- a/qutebrowser/browser/webview.py +++ b/qutebrowser/browser/webview.py @@ -24,6 +24,7 @@ import itertools import functools from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer, QUrl +from PyQt5.QtGui import QPalette from PyQt5.QtWidgets import QApplication, QStyleFactory from PyQt5.QtWebKit import QWebSettings from PyQt5.QtWebKitWidgets import QWebView, QWebPage @@ -108,6 +109,7 @@ class WebView(QWebView): self.search_flags = 0 self.selection_enabled = False self.init_neighborlist() + self._set_bg_color() cfg = objreg.get('config') cfg.changed.connect(self.init_neighborlist) # For some reason, this signal doesn't get disconnected automatically @@ -181,6 +183,15 @@ class WebView(QWebView): self.load_status = val self.load_status_changed.emit(val.name) + def _set_bg_color(self): + """Set the webpage background color as configured.""" + col = config.get('colors', 'webpage.bg') + palette = self.palette() + if col is None: + col = self.style().standardPalette().color(QPalette.Base) + palette.setColor(QPalette.Base, col) + self.setPalette(palette) + @pyqtSlot(str, str) def on_config_changed(self, section, option): """Reinitialize the zoom neighborlist if related config changed.""" @@ -195,6 +206,8 @@ class WebView(QWebView): self.setContextMenuPolicy(Qt.PreventContextMenu) else: self.setContextMenuPolicy(Qt.DefaultContextMenu) + elif section == 'colors' and option == 'webpage.bg': + self._set_bg_color() def init_neighborlist(self): """Initialize the _zoom neighborlist.""" diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index e95a54ea8..a3bbe2d48 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -959,6 +959,11 @@ def data(readonly=False): SettingValue(typ.QtColor(), 'red'), "Background color for downloads with errors."), + ('webpage.bg', + SettingValue(typ.QtColor(none_ok=True), 'white'), + "Background color for webpages if unset (or empty to use the " + "theme's color)"), + readonly=readonly )),