Skip to content

Commit

Permalink
feat/macos_modifiers_fix: switch ctrl with cmd and fix key recognition
Browse files Browse the repository at this point in the history
Added AA_MacDontSwapCtrlAndMeta attribute before QApplication
initialization.
Replaced isprintable check with isalnum and isascii to fix key
recognition with modifiers and prevent their change to special
symbols/letters with option key.
  • Loading branch information
l4zygreed committed Jan 9, 2025
1 parent cbce18b commit 69e01d7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions vimiv/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from vimiv.qt.gui import QIcon
from vimiv.qt.widgets import QApplication
from vimiv.qt.core import Qt, MacDontSwapCtrlAndMeta

import vimiv
from vimiv import api, utils
Expand All @@ -25,6 +26,8 @@ def __init__(self, *qtargs: str) -> None:
qtargs: Arguments passed directly to the QApplication.
"""
_logger.debug("Passing %s to qt", utils.quotedjoin(qtargs))
if MacDontSwapCtrlAndMeta:
super().setAttribute(MacDontSwapCtrlAndMeta, True)
super().__init__([vimiv.__name__, *qtargs])
self.setApplicationVersion(vimiv.__version__)
self.setDesktopFileName(vimiv.__name__)
Expand Down
2 changes: 1 addition & 1 deletion vimiv/gui/eventhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,6 @@ def _get_base_keysequence(event: QKeyEvent) -> SequenceT:
return (text,)
if event.key() in configparser_keys: # Required as configparser crashes otherwise
return (configparser_keys[event.key()],) # type: ignore
if event.text().isprintable():
if event.text().isalnum() and event.text().isascii():
return (event.text(),)
return (QKeySequence(event.key()).toString().lower(),)
3 changes: 3 additions & 0 deletions vimiv/qt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

if qt.USE_PYQT5:
from PyQt5.QtCore import *
MacDontSwapCtrlAndMeta = Qt.AA_MacDontSwapCtrlAndMeta
elif qt.USE_PYQT6:
from PyQt6.QtCore import *
MacDontSwapCtrlAndMeta = Qt.ApplicationAttribute.AA_MacDontSwapCtrlAndMeta
elif qt.USE_PYSIDE6:
# TODO remove useless-suppression once we add PySide6 back to pylint toxenv
# pylint: disable=no-name-in-module,undefined-variable,useless-suppression
Expand All @@ -17,6 +19,7 @@

BoundSignal = SignalInstance
QT_VERSION_STR = qVersion()
MacDontSwapCtrlAndMeta = None

if qt.USE_PYQT: # Signal aliases
# pylint: disable=used-before-assignment
Expand Down

0 comments on commit 69e01d7

Please sign in to comment.