Make F (:hint tab) honour background-tabs.

Fixes #621.
This commit is contained in:
Florian Bruhin 2015-05-06 23:23:54 +02:00
parent 98596d439f
commit 9ceb43ec44
5 changed files with 40 additions and 21 deletions

View File

@ -30,6 +30,7 @@ Changed
- The `content -> geolocation` and `notifications` settings now support a `true` value to always allow those. However, this is *not recommended*. - The `content -> geolocation` and `notifications` settings now support a `true` value to always allow those. However, this is *not recommended*.
- New bindings `<Ctrl-R>` (rapid), `<Ctrl-F>` (foreground) and `<Ctrl-B>` (background) to switch hint modes while hinting. - New bindings `<Ctrl-R>` (rapid), `<Ctrl-F>` (foreground) and `<Ctrl-B>` (background) to switch hint modes while hinting.
- `<Ctrl-M>` is now accepted as an additional alias for `<Return>`/`<Ctrl-J>` - `<Ctrl-M>` is now accepted as an additional alias for `<Return>`/`<Ctrl-J>`
- `:hint tab` and `F` now respect the `background-tabs` setting. To enforce a foreground tab (what `F` did before), use `:hint tab-fg` or `;f`.
v0.2.2 (unreleased) v0.2.2 (unreleased)
------------------- -------------------

View File

@ -198,7 +198,9 @@ Start hinting.
* +'target'+: What to do with the selected element. * +'target'+: What to do with the selected element.
- `normal`: Open the link in the current tab. - `normal`: Open the link in the current tab.
- `tab`: Open the link in a new tab. - `tab`: Open the link in a new tab (honoring the
background-tabs setting).
- `tab-fg`: Open the link in a new foreground tab.
- `tab-bg`: Open the link in a new background tab. - `tab-bg`: Open the link in a new background tab.
- `window`: Open the link in a new window. - `window`: Open the link in a new window.
- `hover` : Hover over the link. - `hover` : Hover over the link.
@ -227,8 +229,8 @@ Start hinting.
==== optional arguments ==== optional arguments
* +*-r*+, +*--rapid*+: Whether to do rapid hinting. This is only possible with targets `tab-bg`, `window`, `run`, `hover`, `userscript` and * +*-r*+, +*--rapid*+: Whether to do rapid hinting. This is only possible with targets `tab` (with background-tabs=true), `tab-bg`,
`spawn`. `window`, `run`, `hover`, `userscript` and `spawn`.
[[home]] [[home]]

View File

@ -33,7 +33,7 @@
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="0.8791156" inkscape:zoom="0.8791156"
inkscape:cx="327.65084" inkscape:cx="641.54005"
inkscape:cy="233.0095" inkscape:cy="233.0095"
inkscape:document-units="px" inkscape:document-units="px"
inkscape:current-layer="layer1" inkscape:current-layer="layer1"
@ -2999,6 +2999,8 @@
style="font-size:10px;fill:#000000" style="font-size:10px;fill:#000000"
id="flowPara3626-73">;b - open hint in background tab</flowPara><flowPara id="flowPara3626-73">;b - open hint in background tab</flowPara><flowPara
style="font-size:10px;fill:#000000" style="font-size:10px;fill:#000000"
id="flowPara4051">;f - open hint in foreground tab</flowPara><flowPara
style="font-size:10px;fill:#000000"
id="flowPara3788">;h - hover over hint (mouse-over)</flowPara><flowPara id="flowPara3788">;h - hover over hint (mouse-over)</flowPara><flowPara
style="font-size:10px;fill:#000000" style="font-size:10px;fill:#000000"
id="flowPara3790">;i - hint images</flowPara><flowPara id="flowPara3790">;i - hint images</flowPara><flowPara

Before

Width:  |  Height:  |  Size: 137 KiB

After

Width:  |  Height:  |  Size: 137 KiB

View File

@ -41,10 +41,10 @@ from qutebrowser.utils import usertypes, log, qtutils, message, objreg
ElemTuple = collections.namedtuple('ElemTuple', ['elem', 'label']) ElemTuple = collections.namedtuple('ElemTuple', ['elem', 'label'])
Target = usertypes.enum('Target', ['normal', 'tab', 'tab_bg', 'window', 'yank', Target = usertypes.enum('Target', ['normal', 'tab', 'tab_fg', 'tab_bg',
'yank_primary', 'run', 'fill', 'hover', 'window', 'yank', 'yank_primary', 'run',
'rapid', 'rapid_win', 'download', 'fill', 'hover', 'rapid', 'rapid_win',
'userscript', 'spawn']) 'download', 'userscript', 'spawn'])
@pyqtSlot(usertypes.KeyMode) @pyqtSlot(usertypes.KeyMode)
@ -65,7 +65,7 @@ class HintContext:
elems: A mapping from key strings to (elem, label) namedtuples. elems: A mapping from key strings to (elem, label) namedtuples.
baseurl: The URL of the current page. baseurl: The URL of the current page.
target: What to do with the opened links. target: What to do with the opened links.
normal/tab/tab_bg/window: Get passed to BrowserTab. normal/tab/tab_fg/tab_bg/window: Get passed to BrowserTab.
yank/yank_primary: Yank to clipboard/primary selection. yank/yank_primary: Yank to clipboard/primary selection.
run: Run a command. run: Run a command.
fill: Fill commandline with link. fill: Fill commandline with link.
@ -124,6 +124,7 @@ class HintManager(QObject):
HINT_TEXTS = { HINT_TEXTS = {
Target.normal: "Follow hint", Target.normal: "Follow hint",
Target.tab: "Follow hint in new tab", Target.tab: "Follow hint in new tab",
Target.tab_fg: "Follow hint in foreground tab",
Target.tab_bg: "Follow hint in background tab", Target.tab_bg: "Follow hint in background tab",
Target.window: "Follow hint in new window", Target.window: "Follow hint in new window",
Target.yank: "Yank hint to clipboard", Target.yank: "Yank hint to clipboard",
@ -417,11 +418,15 @@ class HintManager(QObject):
Target.rapid: usertypes.ClickTarget.tab_bg, Target.rapid: usertypes.ClickTarget.tab_bg,
Target.rapid_win: usertypes.ClickTarget.window, Target.rapid_win: usertypes.ClickTarget.window,
Target.normal: usertypes.ClickTarget.normal, Target.normal: usertypes.ClickTarget.normal,
Target.tab: usertypes.ClickTarget.tab, Target.tab_fg: usertypes.ClickTarget.tab,
Target.tab_bg: usertypes.ClickTarget.tab_bg, Target.tab_bg: usertypes.ClickTarget.tab_bg,
Target.window: usertypes.ClickTarget.window, Target.window: usertypes.ClickTarget.window,
Target.hover: usertypes.ClickTarget.normal, Target.hover: usertypes.ClickTarget.normal,
} }
if config.get('tabs', 'background-tabs'):
target_mapping[Target.tab] = usertypes.ClickTarget.tab_bg
else:
target_mapping[Target.tab] = usertypes.ClickTarget.tab
# FIXME Instead of clicking the center, we could have nicer heuristics. # FIXME Instead of clicking the center, we could have nicer heuristics.
# e.g. parse (-webkit-)border-radius correctly and click text fields at # e.g. parse (-webkit-)border-radius correctly and click text fields at
# the bottom right, and everything else on the top left or so. # the bottom right, and everything else on the top left or so.
@ -431,8 +436,8 @@ class HintManager(QObject):
log.hints.debug("{} on '{}' at {}/{}".format( log.hints.debug("{} on '{}' at {}/{}".format(
action, elem, pos.x(), pos.y())) action, elem, pos.x(), pos.y()))
self.start_hinting.emit(target_mapping[context.target]) self.start_hinting.emit(target_mapping[context.target])
if context.target in [Target.tab, Target.tab_bg, Target.window, if context.target in [Target.tab, Target.tab_fg, Target.tab_bg,
Target.rapid, Target.rapid_win]: Target.window, Target.rapid, Target.rapid_win]:
modifiers = Qt.ControlModifier modifiers = Qt.ControlModifier
else: else:
modifiers = Qt.NoModifier modifiers = Qt.NoModifier
@ -705,8 +710,8 @@ class HintManager(QObject):
Args: Args:
rapid: Whether to do rapid hinting. This is only possible with rapid: Whether to do rapid hinting. This is only possible with
targets `tab-bg`, `window`, `run`, `hover`, `userscript` and targets `tab` (with background-tabs=true), `tab-bg`,
`spawn`. `window`, `run`, `hover`, `userscript` and `spawn`.
group: The hinting mode to use. group: The hinting mode to use.
- `all`: All clickable elements. - `all`: All clickable elements.
@ -716,7 +721,9 @@ class HintManager(QObject):
target: What to do with the selected element. target: What to do with the selected element.
- `normal`: Open the link in the current tab. - `normal`: Open the link in the current tab.
- `tab`: Open the link in a new tab. - `tab`: Open the link in a new tab (honoring the
background-tabs setting).
- `tab-fg`: Open the link in a new foreground tab.
- `tab-bg`: Open the link in a new background tab. - `tab-bg`: Open the link in a new background tab.
- `window`: Open the link in a new window. - `window`: Open the link in a new window.
- `hover` : Hover over the link. - `hover` : Hover over the link.
@ -754,12 +761,17 @@ class HintManager(QObject):
if mode_manager.mode == usertypes.KeyMode.hint: if mode_manager.mode == usertypes.KeyMode.hint:
modeman.leave(win_id, usertypes.KeyMode.hint, 're-hinting') modeman.leave(win_id, usertypes.KeyMode.hint, 're-hinting')
if rapid and target not in (Target.tab_bg, Target.window, Target.run, if rapid:
Target.hover, Target.userscript, if target in [Target.tab_bg, Target.window, Target.run,
Target.spawn): Target.hover, Target.userscript, Target.spawn]:
name = target.name.replace('_', '-') pass
raise cmdexc.CommandError("Rapid hinting makes no sense with " elif (target == Target.tab and
"target {}!".format(name)) config.get('tabs', 'background-tabs')):
pass
else:
name = target.name.replace('_', '-')
raise cmdexc.CommandError("Rapid hinting makes no sense with "
"target {}!".format(name))
self._check_args(target, *args) self._check_args(target, *args)
self._context = HintContext() self._context = HintContext()
@ -878,6 +890,7 @@ class HintManager(QObject):
elem_handlers = { elem_handlers = {
Target.normal: self._click, Target.normal: self._click,
Target.tab: self._click, Target.tab: self._click,
Target.tab_fg: self._click,
Target.tab_bg: self._click, Target.tab_bg: self._click,
Target.window: self._click, Target.window: self._click,
Target.hover: self._click, Target.hover: self._click,

View File

@ -1130,6 +1130,7 @@ KEY_DATA = collections.OrderedDict([
('hint all tab', ['F']), ('hint all tab', ['F']),
('hint all window', ['wf']), ('hint all window', ['wf']),
('hint all tab-bg', [';b']), ('hint all tab-bg', [';b']),
('hint all tab-fg', [';f']),
('hint all hover', [';h']), ('hint all hover', [';h']),
('hint images', [';i']), ('hint images', [';i']),
('hint images tab', [';I']), ('hint images tab', [';I']),