Skip to content

Commit

Permalink
[65_6] Qt 6: Fix Option+Command+key and Ctrl+Command+key
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Nov 14, 2023
1 parent 1f9d07a commit c41f09a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
41 changes: 33 additions & 8 deletions src/Plugins/Qt/QTMWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "preferences.hpp"
#include "object_l5.hpp"
#include "scheme.hpp"
#include "sys_utils.hpp"

#include "config.h"

Expand Down Expand Up @@ -419,18 +420,14 @@ QTMWidget::keyPressEvent (QKeyEvent* event) {
if (r == "less") r= "<";
else if (r == "gtr") r= ">";
}
#ifdef Q_OS_MAC
if (mods & Qt::AltModifier) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (os_macos () && (mods & Qt::AltModifier)) {
// Alt produces many symbols in Mac keyboards: []|{} etc.
if ((N(r) != 1 ||
((int) (unsigned char) r[0]) < 32 ||
((int) (unsigned char) r[0]) >= 128) &&
((int) (unsigned char) r[0]) < 32 ||
((int) (unsigned char) r[0]) >= 128) &&
key >= 32 && key < 128 &&
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
((mods & (Qt::MetaModifier + Qt::ControlModifier)) == 0)) {
#else
((mods & (Qt::MetaModifier | Qt::ControlModifier)) == 0)) {
#endif
if ((mods & Qt::ShiftModifier) == 0 && key >= 65 && key <= 90)
key += 32;
qtcomposemap (key)= r;
Expand Down Expand Up @@ -459,6 +456,34 @@ QTMWidget::keyPressEvent (QKeyEvent* event) {
}
}

void
QTMWidget::keyReleaseEvent (QKeyEvent* event) {
if (os_macos ()) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Qt::KeyboardModifiers mods = event->modifiers();
int key = event->key();

// see https://bugreports.qt.io/browse/QTBUG-115525
if (mods & Qt::ControlModifier) {
string r;
if (key >=32 && key < 128) {
if ((mods & Qt::ShiftModifier) == 0 && key >= 65 && key <= 90)
key += 32;
r= string ((char) key);
if (mods & Qt::AltModifier) {
r= "M-A-" * r;
}
if (mods & Qt::MetaModifier) {
r= "M-C-" * r;
}
}
if (DEBUG_QT && DEBUG_KEYBOARD) debug_qt << "key press: " << r << LF;
the_gui->process_keypress (tm_widget(), r, texmacs_time());
}
#endif
}
}

static unsigned int
mouse_state (QMouseEvent* event, bool flag) {
unsigned int i= 0;
Expand Down
1 change: 1 addition & 0 deletions src/Plugins/Qt/QTMWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class QTMWidget: public QTMScrollView {
virtual void focusInEvent (QFocusEvent* event);
virtual void focusOutEvent (QFocusEvent* event);
virtual void keyPressEvent (QKeyEvent* event);
virtual void keyReleaseEvent (QKeyEvent* event);
virtual void kbdEvent (int key, Qt::KeyboardModifiers mods, const QString& s);
virtual void inputMethodEvent (QInputMethodEvent* event);
virtual void mousePressEvent (QMouseEvent* event);
Expand Down

0 comments on commit c41f09a

Please sign in to comment.