From 84759a49288aa8b947d78f1fd9000ccc7fccb6d7 Mon Sep 17 00:00:00 2001 From: rikn00 Date: Sat, 1 Nov 2014 01:54:19 +0200 Subject: [PATCH 1/3] Add support to hover mouse over a hint --- doc/help/commands.asciidoc | 1 + qutebrowser/browser/hints.py | 23 ++++++++++++++++++++++- qutebrowser/config/configdata.py | 1 + qutebrowser/utils/usertypes.py | 3 ++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/doc/help/commands.asciidoc b/doc/help/commands.asciidoc index 8d48490b5..c1fe9ef9e 100644 --- a/doc/help/commands.asciidoc +++ b/doc/help/commands.asciidoc @@ -145,6 +145,7 @@ Start hinting. - `tab`: Open the link in a new tab. - `tab-bg`: Open the link in a new background tab. - `window`: Open the link in a new window. + - `hover` : Hover over the link. - `yank`: Yank the link to the clipboard. - `yank-primary`: Yank the link to the primary selection. - `fill`: Fill the commandline with the command given as diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index c990b5b32..4e8415bf6 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -40,7 +40,7 @@ ElemTuple = collections.namedtuple('ElemTuple', ['elem', 'label']) Target = usertypes.enum('Target', ['normal', 'tab', 'tab_bg', 'window', 'yank', - 'yank_primary', 'fill', 'rapid', + 'yank_primary', 'fill', 'hover', 'rapid', 'rapid_win', 'download', 'userscript', 'spawn']) @@ -115,6 +115,7 @@ class HintManager(QObject): Target.yank: "Yank hint to clipboard...", Target.yank_primary: "Yank hint to primary selection...", Target.fill: "Set hint in commandline...", + Target.hover: "Hover over a hint", Target.rapid: "Follow hint (rapid mode)...", Target.rapid_win: "Follow hint in new window (rapid mode)...", Target.download: "Download hint...", @@ -354,6 +355,25 @@ class HintManager(QObject): for evt in events: self.mouse_event.emit(evt) + def _hover(self, elem): + """Hover over an element. + + Args: + elem: The QWebElement to hover. + """ + target = self._context.target + self.set_open_target.emit(target.name) + # FIXME Instead of clicking the center, we could have nicer heuristics. + # e.g. parse (-webkit-)border-radius correctly and click text fields at + # the bottom right, and everything else on the top left or so. + # https://github.com/The-Compiler/qutebrowser/issues/70 + pos = elem.rect_on_view().center() + log.hints.debug("Hovering on '{}' at {}/{}".format( + elem, pos.x(), pos.y())) + event = QMouseEvent( + QEvent.MouseMove, pos, Qt.NoButton, Qt.NoButton, Qt.NoModifier) + self.mouse_event.emit(event) + def _yank(self, url): """Yank an element to the clipboard or primary selection. @@ -685,6 +705,7 @@ class HintManager(QObject): Target.window: self._click, Target.rapid: self._click, Target.rapid_win: self._click, + Target.hover: self._hover, # _download needs a QWebElement to get the frame. Target.download: self._download, } diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index eba965ad1..dd0faea75 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -923,6 +923,7 @@ KEY_DATA = collections.OrderedDict([ ('hint all tab', ['F']), ('hint all window', ['wf']), ('hint all tab-bg', [';b']), + ('hint all hover', ['e']), ('hint images', [';i']), ('hint images tab', [';I']), ('hint images tab-bg', ['.i']), diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index c21b7febf..cdb2da0df 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -220,7 +220,8 @@ PromptMode = enum('PromptMode', ['yesno', 'text', 'user_pwd', 'alert']) # Where to open a clicked link. -ClickTarget = enum('ClickTarget', ['normal', 'tab', 'tab_bg', 'window']) +ClickTarget = enum('ClickTarget', ['normal', 'tab', 'tab_bg', 'window', + 'hover']) # Key input modes From 4d101eea598753a42550e252bff7715d3040ee1e Mon Sep 17 00:00:00 2001 From: rikn00 Date: Sun, 2 Nov 2014 16:37:34 +0200 Subject: [PATCH 2/3] Improve hovering a hint --- qutebrowser/browser/hints.py | 45 +++++++++++--------------------- qutebrowser/config/configdata.py | 2 +- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 4e8415bf6..05fb51e85 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -115,7 +115,7 @@ class HintManager(QObject): Target.yank: "Yank hint to clipboard...", Target.yank_primary: "Yank hint to primary selection...", Target.fill: "Set hint in commandline...", - Target.hover: "Hover over a hint", + Target.hover: "Hover over a hint...", Target.rapid: "Follow hint (rapid mode)...", Target.rapid_win: "Follow hint in new window (rapid mode)...", Target.download: "Download hint...", @@ -336,44 +336,29 @@ class HintManager(QObject): target = Target.window else: target = self._context.target - self.set_open_target.emit(target.name) # FIXME Instead of clicking the center, we could have nicer heuristics. # e.g. parse (-webkit-)border-radius correctly and click text fields at # the bottom right, and everything else on the top left or so. # https://github.com/The-Compiler/qutebrowser/issues/70 pos = elem.rect_on_view().center() - log.hints.debug("Clicking on '{}' at {}/{}".format( - elem, pos.x(), pos.y())) - events = ( + action = "Hovering" if target == Target.hover else "Clicking" + log.hints.debug("{} on '{}' at {}/{}".format( + action, elem, pos.x(), pos.y())) + events = [ QMouseEvent(QEvent.MouseMove, pos, Qt.NoButton, Qt.NoButton, Qt.NoModifier), - QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton, - Qt.NoButton, Qt.NoModifier), - QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton, - Qt.NoButton, Qt.NoModifier), - ) + ] + if target != Target.hover: + self.set_open_target.emit(target.name) + events += [ + QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton, + Qt.NoButton, Qt.NoModifier), + QMouseEvent(QEvent.MouseButtonRelease, pos, Qt.LeftButton, + Qt.NoButton, Qt.NoModifier), + ] for evt in events: self.mouse_event.emit(evt) - def _hover(self, elem): - """Hover over an element. - - Args: - elem: The QWebElement to hover. - """ - target = self._context.target - self.set_open_target.emit(target.name) - # FIXME Instead of clicking the center, we could have nicer heuristics. - # e.g. parse (-webkit-)border-radius correctly and click text fields at - # the bottom right, and everything else on the top left or so. - # https://github.com/The-Compiler/qutebrowser/issues/70 - pos = elem.rect_on_view().center() - log.hints.debug("Hovering on '{}' at {}/{}".format( - elem, pos.x(), pos.y())) - event = QMouseEvent( - QEvent.MouseMove, pos, Qt.NoButton, Qt.NoButton, Qt.NoModifier) - self.mouse_event.emit(event) - def _yank(self, url): """Yank an element to the clipboard or primary selection. @@ -705,7 +690,7 @@ class HintManager(QObject): Target.window: self._click, Target.rapid: self._click, Target.rapid_win: self._click, - Target.hover: self._hover, + Target.hover: self._click, # _download needs a QWebElement to get the frame. Target.download: self._download, } diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index dd0faea75..a7cfacf65 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -923,7 +923,7 @@ KEY_DATA = collections.OrderedDict([ ('hint all tab', ['F']), ('hint all window', ['wf']), ('hint all tab-bg', [';b']), - ('hint all hover', ['e']), + ('hint all hover', [';h']), ('hint images', [';i']), ('hint images tab', [';I']), ('hint images tab-bg', ['.i']), From 33b6e17772ade3c1a683fdbf0f94102ed607d989 Mon Sep 17 00:00:00 2001 From: rikn00 Date: Sun, 2 Nov 2014 20:49:18 +0200 Subject: [PATCH 3/3] Remove unneeded change to ClickTarget --- qutebrowser/utils/usertypes.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/qutebrowser/utils/usertypes.py b/qutebrowser/utils/usertypes.py index cdb2da0df..c21b7febf 100644 --- a/qutebrowser/utils/usertypes.py +++ b/qutebrowser/utils/usertypes.py @@ -220,8 +220,7 @@ PromptMode = enum('PromptMode', ['yesno', 'text', 'user_pwd', 'alert']) # Where to open a clicked link. -ClickTarget = enum('ClickTarget', ['normal', 'tab', 'tab_bg', 'window', - 'hover']) +ClickTarget = enum('ClickTarget', ['normal', 'tab', 'tab_bg', 'window']) # Key input modes