Skip to content

Commit

Permalink
fix: don't consume wheel event if no there are wheel shortcuts
Browse files Browse the repository at this point in the history
Fixes #21
  • Loading branch information
BlueGreenMagick committed Nov 25, 2024
1 parent 1728b75 commit 6255862
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion addon/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def WEBVIEW_TARGETS() -> List[AnkiWebView]:
def refresh_config() -> None:
global config
config = mw.addonManager.getConfig(__name__)
manager.refresh_shortcuts()


def turn_on() -> None:
Expand Down Expand Up @@ -144,10 +145,13 @@ def from_web(cls, delta: int) -> Optional["WheelDir"]:


class HotmouseManager:
has_wheel_hotkey: bool

def __init__(self) -> None:
self.enabled = config["default_enabled"]
self.last_scroll_time = datetime.datetime.now()
self.add_menu()
self.refresh_shortcuts()

def add_menu(self) -> None:
self.action = QAction("Enable/Disable Review Hotmouse", mw)
Expand All @@ -170,6 +174,14 @@ def disable(self) -> None:
self.enabled = False
self.update_menu()

def refresh_shortcuts(self) -> None:
self.has_wheel_hotkey = False
for shortcut in config["shortcuts"]:
if "wheel" in shortcut:
self.has_wheel_hotkey = True
break
print("has wheel", self.has_wheel_hotkey)

@staticmethod
def get_pressed_buttons(qbuttons: "Qt.MouseButton") -> List[Button]:
"""Returns list of pressed button names, excluding the button that caused the trigger"""
Expand Down Expand Up @@ -274,7 +286,7 @@ def eventFilter(self, obj: QObject, event: QEvent) -> bool:
if btn == Button.xbutton1 or btn == Button.xbutton2:
return True
elif event.type() == QEvent.Type.Wheel:
if manager.on_mouse_scroll(event):
if manager.has_wheel_hotkey and manager.on_mouse_scroll(event):
return True
elif event.type() == QEvent.Type.ContextMenu:
if manager.enabled:
Expand Down

0 comments on commit 6255862

Please sign in to comment.