emacs-eaf / emacs-application-framework

EAF, an extensible framework that revolutionizes the graphical capabilities of Emacs
GNU General Public License v3.0
3.1k stars 234 forks source link

Wheel mouse button open page in the same window instead of other-window #1136

Closed nicola-leoni closed 9 months ago

nicola-leoni commented 9 months ago

Describe the bug

Middle mouse button is not opening the link in other-window but in the same window. Splitting Emacs in two middle mouse should pop the page in the other half of Emacs.

Inspecting the code I've found the mouse button management was there but the event in the comparison was wrong. This patch fixes the issue:

diff --git a/core/webengine.py b/core/webengine.py
index c21fac6..b774f17 100755
--- a/core/webengine.py
+++ b/core/webengine.py
@@ -38,11 +38,6 @@ from PyQt6.QtWebEngineCore import QWebEnginePage, QWebEngineProfile, QWebEngineS
 from PyQt6.QtWebEngineWidgets import QWebEngineView
 from PyQt6.QtWidgets import QApplication, QWidget

-MOUSE_LEFT_BUTTON = 1
-MOUSE_WHEEL_BUTTON = 4
-MOUSE_BACK_BUTTON = 8
-MOUSE_FORWARD_BUTTON = 16
-
 class BrowserView(QWebEngineView):

     translate_selected_text = QtCore.pyqtSignal(str)
@@ -274,7 +269,7 @@ Note, we need hook this function to signal 'loadProgress', signal 'loadStarted'
             if platform.system() == "Darwin":
                 eval_in_emacs('eaf-activate-emacs-window', [])

-            if event.button() == MOUSE_FORWARD_BUTTON:
+            if event.button() == Qt.MouseButton.ForwardButton:
                 modifiers = QApplication.keyboardModifiers()
                 if modifiers == Qt.KeyboardModifier.ControlModifier:
                     self.switch_to_next_webpage_buffer()
@@ -284,7 +279,7 @@ Note, we need hook this function to signal 'loadProgress', signal 'loadStarted'
                 event.accept()
                 return True

-            elif event.button() == MOUSE_BACK_BUTTON:
+            elif event.button() == Qt.MouseButton.BackButton:
                 modifiers = QApplication.keyboardModifiers()
                 if modifiers == Qt.KeyboardModifier.ControlModifier:
                     self.switch_to_previous_webpage_buffer()
@@ -294,13 +289,13 @@ Note, we need hook this function to signal 'loadProgress', signal 'loadStarted'
                 event.accept()
                 return True

-            elif event.button() == MOUSE_LEFT_BUTTON:
+            elif event.button() == Qt.MouseButton.LeftButton:
                 modifiers = QApplication.keyboardModifiers()
                 if modifiers == Qt.KeyboardModifier.ControlModifier and self.url_hovered:
                     self.open_url_background_buffer(self.url_hovered)
                     return True

-            elif event.button() == MOUSE_WHEEL_BUTTON:
+            elif event.button() == Qt.MouseButton.MiddleButton:
                 if self.url_hovered:
                     self.open_url_new_buffer_other_window(self.url_hovered)
                     return True
manateelazycat commented 9 months ago

Thanks for patch, has merge in master. ;)