From 369dec9319a37314ec3a0b1230fe2d5dd8048a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28x=E2=8B=85ln=287=29=29=E2=81=BB=C2=B9?= <100133857+derivativeoflog7@users.noreply.github.com> Date: Tue, 15 Apr 2025 11:51:00 +0200 Subject: [PATCH] Add an option to disable middle click to paste on Linux (#3904) * Add checkbox * Working in editor * Toolbar webview * Other webviews * Even more webviews * Move to profile settings * Add to contributors [skip ci] * Fix checks * Fix checks * Better? * Remove unneded * Remove checkbox and a few other things * How the hell did that happen * Undo FTL changes (dae) * Remove superfluous config entry (dae) * Add comment about profile keys (dae) --- CONTRIBUTORS | 1 + qt/aqt/profiles.py | 8 ++++++++ qt/aqt/webview.py | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 92fa12da3..033c30a3e 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -219,6 +219,7 @@ Jakub Fidler Valerie Enfys Julien Chol ikkz +derivativeoflog7 rreemmii-dev babofitos diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 817e00139..d92d7f59f 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -94,6 +94,8 @@ metaConf = dict( defaultLang=None, ) +# Old Anki versions expected these keys to exist. Don't add new ones here - it's better practice +# to always use profile.get(..., defaultValue) instead, as keys may be missing. profileConf: dict[str, Any] = dict( # profile mainWindowGeom=None, @@ -698,6 +700,12 @@ create table if not exists profiles def set_current_sync_url(self, url: str | None) -> None: self.profile["currentSyncUrl"] = url + def middle_click_paste_enabled(self) -> bool: + return self.profile.get("middleClickPasteEnabled", True) + + def set_middle_click_paste_enabled(self, val: bool) -> None: + self.profile["middleClickPasteEnabled"] = val + def custom_sync_url(self) -> str | None: """A custom server provided by the user.""" return self.profile.get("customSyncUrl") diff --git a/qt/aqt/webview.py b/qt/aqt/webview.py index b5b50ad72..f8ea04247 100644 --- a/qt/aqt/webview.py +++ b/qt/aqt/webview.py @@ -350,8 +350,11 @@ class AnkiWebView(QWebEngineView): isinstance(evt, QMouseEvent) and evt.type() == QEvent.Type.MouseButtonRelease ): + from aqt import mw + if evt.button() == Qt.MouseButton.MiddleButton and is_lin: - self.onMiddleClickPaste() + if mw.pm.middle_click_paste_enabled(): + self.onMiddleClickPaste() return True return False