Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[65_6] Qt 6: Fix Option+Command+key and Ctrl+Command+key #1347

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading