Add ipc-open-target config option.
This commit is contained in:
parent
ca85dde71f
commit
817259f4f5
@ -33,7 +33,7 @@ import traceback
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QDialog
|
||||
from PyQt5.QtCore import (pyqtSlot, qInstallMessageHandler, QTimer, QUrl,
|
||||
QStandardPaths, QObject)
|
||||
QStandardPaths, QObject, Qt)
|
||||
|
||||
import qutebrowser
|
||||
from qutebrowser.commands import cmdutils, runners
|
||||
@ -230,6 +230,28 @@ class Application(QApplication):
|
||||
self._open_startpage()
|
||||
self._open_quickstart()
|
||||
|
||||
def _get_window(self, ipc):
|
||||
"""Helper function for process_args to get a window id."""
|
||||
if not ipc:
|
||||
return 0
|
||||
open_target = config.get('general', 'ipc-open-target')
|
||||
if open_target in ('tab', 'tab-silent'):
|
||||
try:
|
||||
window = objreg.get('last-main-window')
|
||||
except KeyError:
|
||||
message.error("No main window found!")
|
||||
return None
|
||||
else:
|
||||
if open_target != 'tab-silent':
|
||||
window.setWindowState(window.windowState() &
|
||||
~Qt.WindowMinimized |
|
||||
Qt.WindowActive)
|
||||
window.raise_()
|
||||
window.activateWindow()
|
||||
return window.win_id
|
||||
else:
|
||||
return mainwindow.MainWindow.spawn()
|
||||
|
||||
def process_args(self, args, ipc=False):
|
||||
"""Process commandline args.
|
||||
|
||||
@ -239,10 +261,9 @@ class Application(QApplication):
|
||||
args: A list of arguments to process.
|
||||
ipc: Whether the arguments were transmitted over IPC.
|
||||
"""
|
||||
if ipc:
|
||||
win_id = mainwindow.MainWindow.spawn()
|
||||
else:
|
||||
win_id = 0
|
||||
win_id = self._get_window(ipc)
|
||||
if win_id is None:
|
||||
return
|
||||
for cmd in args:
|
||||
if cmd.startswith(':'):
|
||||
log.init.debug("Startup cmd {}".format(cmd))
|
||||
|
@ -181,6 +181,11 @@ DATA = collections.OrderedDict([
|
||||
"The encoding must be a string describing an encoding such as "
|
||||
'_utf-8_, _iso-8859-1_, etc. If left empty a default value will be '
|
||||
"used."),
|
||||
|
||||
('ipc-open-target',
|
||||
SettingValue(typ.IPCOpenTarget(), 'window'),
|
||||
"How to open links in an existing instance if a new one is "
|
||||
"launched."),
|
||||
)),
|
||||
|
||||
('ui', sect.KeyValue(
|
||||
|
@ -1254,3 +1254,15 @@ class IgnoreCase(Bool):
|
||||
('false', 'Search case-sensitively'),
|
||||
('smart', 'Search case-sensitively if there are capital '
|
||||
'chars')]
|
||||
|
||||
|
||||
class IPCOpenTarget(BaseType):
|
||||
|
||||
"""How to open links in an existing instance if a new one is launched."""
|
||||
|
||||
valid_values = ValidValues(('tab', "Open a new tab in the existing "
|
||||
"window and activate it."),
|
||||
('tab-silent', "Open a new tab in the existing "
|
||||
"window without activating "
|
||||
"it."),
|
||||
('window', "Open in a new window."))
|
||||
|
@ -62,6 +62,7 @@ class MainWindow(QWidget):
|
||||
self.registry = objreg.ObjectRegistry()
|
||||
objreg.window_registry[win_id] = self
|
||||
objreg.register('main-window', self, scope='window', window=win_id)
|
||||
objreg.register('last-main-window', self, update=True)
|
||||
tab_registry = objreg.ObjectRegistry()
|
||||
objreg.register('tab-registry', tab_registry, scope='window',
|
||||
window=win_id)
|
||||
|
Loading…
Reference in New Issue
Block a user