[PATCH] rocker-gestures

Florian Bruhin me at the-compiler.org
Mon Mar 2 13:39:36 CET 2015


Hi,

First of all, sorry for the late answer!

* Gregor Pohl <gregorpohl2003 at yahoo.de> [2015-02-28 19:24:36 +0100]:
> Attached is a patch adding a config option "input->rocker-gestures",
> which disables the context menu and replaces it with Opera-like
> rocker gestures.
> 
> Specifically, holding the right mouse button and pressing the left
> button will go back in history. Holding the left mouse button and
> pressing the right button moves forward (It is very easy to get used
> to this. I can't live without it anymore, hence the patch).
> 
> I'm not sure if there is any interest in merging this, but I thought
> I'd at least share the patch.

I'd be okay with merging this - though I think the code can be
simplified a bit: A QMouseEvent has a button() and a buttons() method:

    http://doc.qt.io/qt-5/qmouseevent.html#button
    Returns the button that caused the event.

    http://doc.qt.io/qt-5/qmouseevent.html#buttons
    Returns the button state when the event was generated. [...]
    For mouse press and double click events this includes the button
    that caused the event.

Couldn't you just check if button() is Qt.LeftButton and buttons() is
Qt.LeftButton | Qt.RightButton, instead of saving the button state
yourself?

Also there are some other issues and nitpicks - though for the minor
stuff, if you prefer to not deal with my perfectionism that's
perfectly fine, I can also do those changes for you :)

> diff --git a/qutebrowser/browser/webview.py b/qutebrowser/browser/webview.py
> index 13b2cbb..644e349 100644
> --- a/qutebrowser/browser/webview.py
> +++ b/qutebrowser/browser/webview.py
> @@ -42,6 +42,7 @@ LoadStatus = usertypes.enum('LoadStatus', ['none', 'success', 'error', 'warn',
>  tab_id_gen = itertools.count(0)
>  
>  
> +

Remove that blank line.

> @@ -86,6 +87,10 @@ class WebView(QWebView):
>      url_text_changed = pyqtSignal(str)
>      shutting_down = pyqtSignal()
>  
> +    #Mouse button states for rocker gestures
> +    left_pressed = False
> +    right_pressed = False
> +

If those are still needed, they should be initialized in __init__, not
here. Otherwise they'd be class rather than instance variables, and
all instances of the class would share them.

> @@ -178,6 +185,12 @@ class WebView(QWebView):
>                                     100)
>              self._default_zoom_changed = False
>              self.init_neighborlist()
> +        if section == 'input' and option == 'rocker-gestures':
> +            if config.get('input','rocker-gestures'):

Add a space after the comma here.

> +                self.setContextMenuPolicy(Qt.PreventContextMenu)
> +            else:
> +                self.setContextMenuPolicy(Qt.DefaultContextMenu)
> +
>  
>      def init_neighborlist(self):

Only one newline between methods, so remove the added newline here.

> @@ -497,7 +510,15 @@ class WebView(QWebView):
>          Return:
>              The superclass return value.
>          """
> -        if e.button() in (Qt.XButton1, Qt.XButton2):
> +        if e.button() == Qt.LeftButton:
> +           self.left_pressed = True
> +        elif e.button() == Qt.RightButton:
> +            self.right_pressed = True
> +
> +        if e.button() in (Qt.XButton1, Qt.XButton2) or (
> +                     e.button() in (Qt.LeftButton, Qt.RightButton)
> +                     and config.get('input', 'rocker-gestures')
> +                     and self.right_pressed and self.left_pressed):

I'd prefer this to be written like this:

        is_rocker_gesture = (e.button() in (Qt.LeftButton, Qt.RightButton) and
                             config.get('input', 'rocker-gestures') and
                             self.right_pressed and self.left_pressed)

        if e.button() in (Qt.XButton1, Qt.XButton2) or is_rocker_gesture:

Otherwise this if gets rather long to grasp.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://listi.jpberlin.de/pipermail/qutebrowser/attachments/20150302/dbcf8146/attachment.sig>


More information about the qutebrowser mailing list