diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index b774461b2..35a22db40 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -43,6 +43,7 @@ |<>|Whether to remove finished downloads automatically. |<>|Whether to hide the statusbar unless a message is shown. |<>|The format to use for the window title. The following placeholders are defined: +|<>|Whether to hide the mouse cursor. |============== .Quick reference for section ``network'' @@ -564,6 +565,17 @@ The format to use for the window title. The following placeholders are defined: Default: +pass:[{perc}{title}{title_sep}qutebrowser]+ +[[ui-hide-mouse-cursor]] +=== hide-mouse-cursor +Whether to hide the mouse cursor. + +Valid values: + + * +true+ + * +false+ + +Default: +pass:[false]+ + == network Settings related to the network. diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 359f7cd3d..6b05f369a 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -33,7 +33,7 @@ import faulthandler import json from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox -from PyQt5.QtGui import QDesktopServices, QPixmap, QIcon +from PyQt5.QtGui import QDesktopServices, QPixmap, QIcon, QCursor from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QTimer, QUrl, QObject, Qt, QSocketNotifier) try: @@ -210,6 +210,19 @@ class Application(QApplication): objreg.register('cache', diskcache) log.init.debug("Initializing completions...") completionmodels.init() + log.init.debug("Misc initialization...") + self.maybe_hide_mouse_cursor() + objreg.get('config').changed.connect(self.maybe_hide_mouse_cursor) + + @config.change_filter('ui', 'hide-mouse-cursor') + def maybe_hide_mouse_cursor(self): + """Hide the mouse cursor if it isn't yet and it's configured.""" + if config.get('ui', 'hide-mouse-cursor'): + if self.overrideCursor() is not None: + return + self.setOverrideCursor(QCursor(Qt.BlankCursor)) + else: + self.restoreOverrideCursor() def _init_icon(self): """Initialize the icon of qutebrowser.""" @@ -940,8 +953,10 @@ class Application(QApplication): objreg.delete('last-focused-main-window') except KeyError: pass + self.restoreOverrideCursor() else: objreg.register('last-focused-main-window', window, update=True) + self.maybe_hide_mouse_cursor() @pyqtSlot(QUrl) def open_desktopservices_url(self, url): diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 96e146ada..fec9c93fe 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -297,6 +297,10 @@ def data(readonly=False): "otherwise.\n" "* `{id}`: The internal window ID of this window."), + ('hide-mouse-cursor', + SettingValue(typ.Bool(), 'false'), + "Whether to hide the mouse cursor."), + readonly=readonly )), diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py index 4699de8e9..00c0a4d73 100644 --- a/qutebrowser/keyinput/modeman.py +++ b/qutebrowser/keyinput/modeman.py @@ -131,9 +131,20 @@ class EventFilter(QObject): def eventFilter(self, obj, event): """Forward events to the correct modeman.""" try: + qapp = QApplication.instance() if not self._activated: return False - if event.type() not in [QEvent.KeyPress, QEvent.KeyRelease]: + if event.type() in [QEvent.MouseButtonDblClick, + QEvent.MouseButtonPress, + QEvent.MouseButtonRelease, + QEvent.MouseMove]: + if qapp.overrideCursor() is None: + # Mouse cursor shown -> don't filter event + return False + else: + # Mouse cursor hidden -> filter event + return True + elif event.type() not in [QEvent.KeyPress, QEvent.KeyRelease]: # We're not interested in non-key-events so we pass them # through. return False @@ -141,8 +152,7 @@ class EventFilter(QObject): # We already handled this same event at some point earlier, so # we're not interested in it anymore. return False - if (QApplication.instance().activeWindow() not in - objreg.window_registry.values()): + if qapp.activeWindow() not in objreg.window_registry.values(): # Some other window (print dialog, etc.) is focused so we pass # the event through. return False diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index c619a6f47..b9e456b42 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -128,6 +128,10 @@ class MainWindow(QWidget): # we defer this until everything else is initialized. QTimer.singleShot(0, self._connect_resize_completion) objreg.get('config').changed.connect(self.on_config_changed) + + if config.get('ui', 'hide-mouse-cursor'): + self.setCursor(Qt.BlankCursor) + #self.retranslateUi(MainWindow) #self.tabWidget.setCurrentIndex(0) #QtCore.QMetaObject.connectSlotsByName(MainWindow)