diff options
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qapplication_mac.mm | 9 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_x11.cpp | 63 | ||||
-rw-r--r-- | src/gui/kernel/qcocoaview_mac.mm | 13 | ||||
-rw-r--r-- | src/gui/kernel/qgesturerecognizer.cpp | 2 | ||||
-rw-r--r-- | src/gui/kernel/qkeymapper_mac.cpp | 54 | ||||
-rw-r--r-- | src/gui/kernel/qkeymapper_p.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qkeymapper_x11.cpp | 34 | ||||
-rw-r--r-- | src/gui/kernel/qkeysequence.cpp | 1 | ||||
-rw-r--r-- | src/gui/kernel/qt_cocoa_helpers_mac.mm | 4 | ||||
-rw-r--r-- | src/gui/kernel/qt_x11_p.h | 6 | ||||
-rw-r--r-- | src/gui/kernel/qwidget_mac.mm | 29 |
11 files changed, 167 insertions, 50 deletions
diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index c7d0e48..28072fc 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -1759,14 +1759,19 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event // (actually two events; one for horizontal and one for vertical). // As a results of this, and to make sure we dont't receive duplicate events, // we try to detect when this happend by checking the 'compatibilityEvent'. + // Since delta is delivered as pixels rather than degrees, we need to + // convert from pixels to degrees in a sensible manner. + // It looks like 1/4 degrees per pixel behaves most native. + // (NB: Qt expects the unit for delta to be 8 per degree): + const int pixelsToDegrees = 2; SInt32 mdelt = 0; GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0, sizeof(mdelt), 0, &mdelt); - wheel_deltaX = mdelt; + wheel_deltaX = mdelt * pixelsToDegrees; mdelt = 0; GetEventParameter(event, kEventParamMouseWheelSmoothVerticalDelta, typeSInt32, 0, sizeof(mdelt), 0, &mdelt); - wheel_deltaY = mdelt; + wheel_deltaY = mdelt * pixelsToDegrees; GetEventParameter(event, kEventParamEventRef, typeEventRef, 0, sizeof(compatibilityEvent), 0, &compatibilityEvent); } else if (ekind == kEventMouseWheelMoved) { diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index 20a7ff2..985f825 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -709,6 +709,10 @@ static int qt_x_errhandler(Display *dpy, XErrorEvent *err) extensionName = "XInputExtension"; else if (err->request_code == X11->mitshm_major) extensionName = "MIT-SHM"; +#ifndef QT_NO_XKB + else if(err->request_code == X11->xkb_major) + extensionName = "XKEYBOARD"; +#endif char minor_str[256]; if (extensionName) { @@ -1635,6 +1639,11 @@ void qt_init(QApplicationPrivate *priv, int, X11->xinput_eventbase = 0; X11->xinput_errorbase = 0; + X11->use_xkb = false; + X11->xkb_major = 0; + X11->xkb_eventbase = 0; + X11->xkb_errorbase = 0; + // MIT-SHM X11->use_mitshm = false; X11->use_mitshm_pixmaps = false; @@ -2108,6 +2117,33 @@ void qt_init(QApplicationPrivate *priv, int, } #endif // QT_NO_XINPUT +#ifndef QT_NO_XKB + int xkblibMajor = XkbMajorVersion; + int xkblibMinor = XkbMinorVersion; + X11->use_xkb = XkbQueryExtension(X11->display, + &X11->xkb_major, + &X11->xkb_eventbase, + &X11->xkb_errorbase, + &xkblibMajor, + &xkblibMinor); + if (X11->use_xkb) { + // If XKB is detected, set the GrabsUseXKBState option so input method + // compositions continue to work (ie. deadkeys) + unsigned int state = XkbPCF_GrabsUseXKBStateMask; + (void) XkbSetPerClientControls(X11->display, state, &state); + + // select for group change events + XkbSelectEventDetails(X11->display, + XkbUseCoreKbd, + XkbStateNotify, + XkbAllStateComponentsMask, + XkbGroupStateMask); + + // current group state is queried when creating the keymapper, no need to do it here + } +#endif + + #if !defined(QT_NO_FONTCONFIG) int dpi = 0; getXDefault("Xft", FC_DPI, &dpi); @@ -2186,15 +2222,6 @@ void qt_init(QApplicationPrivate *priv, int, // initialize key mapper QKeyMapper::changeKeyboard(); -#ifndef QT_NO_XKB - if (qt_keymapper_private()->useXKB) { - // If XKB is detected, set the GrabsUseXKBState option so input method - // compositions continue to work (ie. deadkeys) - unsigned int state = XkbPCF_GrabsUseXKBStateMask; - (void) XkbSetPerClientControls(X11->display, state, &state); - } -#endif // QT_NO_XKB - // Misc. initialization #if 0 //disabled for now.. QSegfaultHandler::initialize(priv->argv, priv->argc); @@ -3229,6 +3256,24 @@ int QApplication::x11ProcessEvent(XEvent* event) QKeyMapper::changeKeyboard(); return 0; } +#ifndef QT_NO_XKB + else if (X11->use_xkb && event->type == X11->xkb_eventbase) { + XkbAnyEvent *xkbevent = (XkbAnyEvent *) event; + switch (xkbevent->xkb_type) { + case XkbStateNotify: + { + XkbStateNotifyEvent *xkbstateevent = (XkbStateNotifyEvent *) xkbevent; + if ((xkbstateevent->changed & XkbGroupStateMask) != 0) { + qt_keymapper_private()->xkb_currentGroup = xkbstateevent->group; + QKeyMapper::changeKeyboard(); + } + break; + } + default: + break; + } + } +#endif if (!widget) { // don't know this windows QWidget* popup = QApplication::activePopupWidget(); diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index f7cb21f..4f71681 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -480,7 +480,7 @@ static int qCocoaViewCount = 0; return; if (QApplicationPrivate::graphicsSystem() != 0) { - if (QWidgetBackingStore *bs = qwidgetprivate->maybeBackingStore()) { + if (qwidgetprivate->maybeBackingStore()) { // Drawing is handled on the window level // See qcocoasharedwindowmethods_mac_p.h if (!qwidget->testAttribute(Qt::WA_PaintOnScreen)) @@ -819,11 +819,12 @@ static int qCocoaViewCount = 0; // The mouse device containts pixel scroll wheel support (Mighty Mouse, Trackpad). // Since deviceDelta is delivered as pixels rather than degrees, we need to // convert from pixels to degrees in a sensible manner. - // It looks like four degrees per pixel behaves most native. - // Qt expects the unit for delta to be 1/8 of a degree: - deltaX = [theEvent deviceDeltaX]; - deltaY = [theEvent deviceDeltaY]; - deltaZ = [theEvent deviceDeltaZ]; + // It looks like 1/4 degrees per pixel behaves most native. + // (NB: Qt expects the unit for delta to be 8 per degree): + const int pixelsToDegrees = 2; // 8 * 1/4 + deltaX = [theEvent deviceDeltaX] * pixelsToDegrees; + deltaY = [theEvent deviceDeltaY] * pixelsToDegrees; + deltaZ = [theEvent deviceDeltaZ] * pixelsToDegrees; } else { // carbonEventKind == kEventMouseWheelMoved // Remove acceleration, and use either -120 or 120 as delta: diff --git a/src/gui/kernel/qgesturerecognizer.cpp b/src/gui/kernel/qgesturerecognizer.cpp index c88a9a7..9dcca17 100644 --- a/src/gui/kernel/qgesturerecognizer.cpp +++ b/src/gui/kernel/qgesturerecognizer.cpp @@ -161,6 +161,8 @@ QGestureRecognizer::~QGestureRecognizer() Reimplement this function to create a custom QGesture-derived gesture object if necessary. + + The application takes ownership of the created gesture object. */ QGesture *QGestureRecognizer::create(QObject *target) { diff --git a/src/gui/kernel/qkeymapper_mac.cpp b/src/gui/kernel/qkeymapper_mac.cpp index a31480d..f259654 100644 --- a/src/gui/kernel/qkeymapper_mac.cpp +++ b/src/gui/kernel/qkeymapper_mac.cpp @@ -323,6 +323,32 @@ static qt_mac_enum_mapper qt_mac_keyvkey_symbols[] = { //real scan codes { 0, QT_MAC_MAP_ENUM(0) } }; +static qt_mac_enum_mapper qt_mac_private_unicode[] = { + { 0xF700, QT_MAC_MAP_ENUM(Qt::Key_Up) }, //NSUpArrowFunctionKey + { 0xF701, QT_MAC_MAP_ENUM(Qt::Key_Down) }, //NSDownArrowFunctionKey + { 0xF702, QT_MAC_MAP_ENUM(Qt::Key_Left) }, //NSLeftArrowFunctionKey + { 0xF703, QT_MAC_MAP_ENUM(Qt::Key_Right) }, //NSRightArrowFunctionKey + { 0xF727, QT_MAC_MAP_ENUM(Qt::Key_Insert) }, //NSInsertFunctionKey + { 0xF728, QT_MAC_MAP_ENUM(Qt::Key_Delete) }, //NSDeleteFunctionKey + { 0xF729, QT_MAC_MAP_ENUM(Qt::Key_Home) }, //NSHomeFunctionKey + { 0xF72B, QT_MAC_MAP_ENUM(Qt::Key_End) }, //NSEndFunctionKey + { 0xF72C, QT_MAC_MAP_ENUM(Qt::Key_PageUp) }, //NSPageUpFunctionKey + { 0xF72D, QT_MAC_MAP_ENUM(Qt::Key_PageDown) }, //NSPageDownFunctionKey + { 0xF72F, QT_MAC_MAP_ENUM(Qt::Key_ScrollLock) }, //NSScrollLockFunctionKey + { 0xF730, QT_MAC_MAP_ENUM(Qt::Key_Pause) }, //NSPauseFunctionKey + { 0xF731, QT_MAC_MAP_ENUM(Qt::Key_SysReq) }, //NSSysReqFunctionKey + { 0xF735, QT_MAC_MAP_ENUM(Qt::Key_Menu) }, //NSMenuFunctionKey + { 0xF738, QT_MAC_MAP_ENUM(Qt::Key_Print) }, //NSPrintFunctionKey + { 0xF73A, QT_MAC_MAP_ENUM(Qt::Key_Clear) }, //NSClearDisplayFunctionKey + { 0xF73D, QT_MAC_MAP_ENUM(Qt::Key_Insert) }, //NSInsertCharFunctionKey + { 0xF73E, QT_MAC_MAP_ENUM(Qt::Key_Delete) }, //NSDeleteCharFunctionKey + { 0xF741, QT_MAC_MAP_ENUM(Qt::Key_Select) }, //NSSelectFunctionKey + { 0xF742, QT_MAC_MAP_ENUM(Qt::Key_Execute) }, //NSExecuteFunctionKey + { 0xF746, QT_MAC_MAP_ENUM(Qt::Key_Help) }, //NSHelpFunctionKey + { 0xF747, QT_MAC_MAP_ENUM(Qt::Key_Mode_switch) }, //NSModeSwitchFunctionKey + { 0, QT_MAC_MAP_ENUM(0) } +}; + static int qt_mac_get_key(int modif, const QChar &key, int virtualKey) { #ifdef DEBUG_KEY_BINDINGS @@ -379,6 +405,19 @@ static int qt_mac_get_key(int modif, const QChar &key, int virtualKey) } } + // check if they belong to key codes in private unicode range + if (key >= 0xf700 && key <= 0xf747) { + if (key >= 0xf704 && key <= 0xf726) { + return Qt::Key_F1 + (key.unicode() - 0xf704) ; + } + for (int i = 0; qt_mac_private_unicode[i].qt_code; i++) { + if (qt_mac_private_unicode[i].mac_code == key) { + return qt_mac_private_unicode[i].qt_code; + } + } + + } + //oh well #ifdef DEBUG_KEY_BINDINGS qDebug("Unknown case.. %s:%d %d[%d] %d", __FILE__, __LINE__, key.unicode(), key.toLatin1(), virtualKey); @@ -847,7 +886,11 @@ bool QKeyMapperPrivate::translateKeyEvent(QWidget *widget, EventHandlerCallRef e } void -QKeyMapperPrivate::updateKeyMap(EventHandlerCallRef, EventRef event, void *) +QKeyMapperPrivate::updateKeyMap(EventHandlerCallRef, EventRef event, void * +#if defined(QT_MAC_USE_COCOA) + unicodeKey // unicode character from NSEvent (modifiers applied) +#endif + ) { UInt32 macVirtualKey = 0; GetEventParameter(event, kEventParamKeyCode, typeUInt32, 0, sizeof(macVirtualKey), 0, &macVirtualKey); @@ -875,6 +918,15 @@ QKeyMapperPrivate::updateKeyMap(EventHandlerCallRef, EventRef event, void *) qtkey = unicode.unicode(); keyLayout[macVirtualKey]->qtKey[i] = qtkey; } +#ifndef Q_WS_MAC32 + else { + const QChar unicode(*((UniChar *)unicodeKey)); + int qtkey = qt_mac_get_key(keyModifier, unicode, macVirtualKey); + if (qtkey == Qt::Key_unknown) + qtkey = unicode.unicode(); + keyLayout[macVirtualKey]->qtKey[i] = qtkey; + } +#endif #ifdef Q_WS_MAC32 } else { const UInt32 keyModifier = (qt_mac_get_mac_modifiers(ModsTbl[i])); diff --git a/src/gui/kernel/qkeymapper_p.h b/src/gui/kernel/qkeymapper_p.h index 3e42d6e..38f141e 100644 --- a/src/gui/kernel/qkeymapper_p.h +++ b/src/gui/kernel/qkeymapper_p.h @@ -183,7 +183,7 @@ public: const XEvent *, bool grab); - bool useXKB; + int xkb_currentGroup; QXCoreDesc coreDesc; #elif defined(Q_WS_MAC) diff --git a/src/gui/kernel/qkeymapper_x11.cpp b/src/gui/kernel/qkeymapper_x11.cpp index d6d1042..428ac3e 100644 --- a/src/gui/kernel/qkeymapper_x11.cpp +++ b/src/gui/kernel/qkeymapper_x11.cpp @@ -248,22 +248,17 @@ qt_XTranslateKey(register QXCoreDesc *dpy, QKeyMapperPrivate::QKeyMapperPrivate() - : keyboardInputDirection(Qt::LeftToRight), useXKB(false) + : keyboardInputDirection(Qt::LeftToRight), xkb_currentGroup(0) { memset(&coreDesc, 0, sizeof(coreDesc)); #ifndef QT_NO_XKB - int opcode = -1; - int xkbEventBase = -1; - int xkbErrorBase = -1; - int xkblibMajor = XkbMajorVersion; - int xkblibMinor = XkbMinorVersion; - if (XkbQueryExtension(X11->display, &opcode, &xkbEventBase, &xkbErrorBase, &xkblibMajor, &xkblibMinor)) - useXKB = true; -#endif - -#if 0 - qDebug() << "useXKB =" << useXKB; + if (X11->use_xkb) { + // get the current group + XkbStateRec xkbState; + if (XkbGetState(X11->display, XkbUseCoreKbd, &xkbState) == Success) + xkb_currentGroup = xkbState.group; + } #endif } @@ -276,7 +271,7 @@ QKeyMapperPrivate::~QKeyMapperPrivate() QList<int> QKeyMapperPrivate::possibleKeys(QKeyEvent *event) { #ifndef QT_NO_XKB - if (useXKB) + if (X11->use_xkb) return possibleKeysXKB(event); #endif return possibleKeysCore(event); @@ -486,7 +481,7 @@ enum { void QKeyMapperPrivate::clearMappings() { #ifndef QT_NO_XKB - if (useXKB) { + if (X11->use_xkb) { // try to determine the layout name and input direction by reading the _XKB_RULES_NAMES property off // the root window QByteArray layoutName; @@ -515,8 +510,13 @@ void QKeyMapperPrivate::clearMappings() p += qstrlen(p) + 1; } while (p < end); - layoutName = QByteArray::fromRawData(names[2], qstrlen(names[2])); - variantName = QByteArray::fromRawData(names[3], qstrlen(names[3])); + // the layout names and variants are saved in the _XKB_RULES_NAMES property as a comma separated list + QList<QByteArray> layoutNames = QByteArray::fromRawData(names[2], qstrlen(names[2])).split(','); + if (uint(xkb_currentGroup) < uint(layoutNames.count())) + layoutName = layoutNames.at(xkb_currentGroup); + QList<QByteArray> variantNames = QByteArray::fromRawData(names[3], qstrlen(names[3])).split(','); + if (uint(xkb_currentGroup) < uint(variantNames.count())) + variantName = variantNames.at(xkb_currentGroup); } // ### ??? @@ -574,7 +574,7 @@ void QKeyMapperPrivate::clearMappings() // look at the modifier mapping, and get the correct masks for alt, meta, super, hyper, and mode_switch #ifndef QT_NO_XKB - if (useXKB) { + if (X11->use_xkb) { XkbDescPtr xkbDesc = XkbGetMap(X11->display, XkbAllClientInfoMask, XkbUseCoreKbd); for (int i = xkbDesc->min_key_code; i < xkbDesc->max_key_code; ++i) { const uint mask = xkbDesc->map->modmap ? xkbDesc->map->modmap[i] : 0; diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index 99bf971..7f92a2c 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -696,6 +696,7 @@ const QKeyBinding QKeySequencePrivate::keyBindings[] = { {QKeySequence::Redo, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, QApplicationPrivate::KB_Mac}, //different priority from above {QKeySequence::PreviousChild, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11}, {QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Backtab, QApplicationPrivate::KB_Mac },//different priority from above + {QKeySequence::Paste, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Insert, QApplicationPrivate::KB_X11}, {QKeySequence::SelectStartOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Home, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11 | QApplicationPrivate::KB_S60}, {QKeySequence::SelectEndOfDocument, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_End, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11 | QApplicationPrivate::KB_S60}, {QKeySequence::SelectPreviousWord, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Left, QApplicationPrivate::KB_Win | QApplicationPrivate::KB_X11 | QApplicationPrivate::KB_S60}, diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index 3fbd978..24fe5f7 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -684,7 +684,9 @@ bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEve EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef])); Q_ASSERT(key_event); if ([event type] == NSKeyDown) { - qt_keymapper_private()->updateKeyMap(0, key_event, 0); + NSString *characters = [event characters]; + unichar value = [characters characterAtIndex:0]; + qt_keymapper_private()->updateKeyMap(0, key_event, (void *)&value); } // Redirect keys to alien widgets. diff --git a/src/gui/kernel/qt_x11_p.h b/src/gui/kernel/qt_x11_p.h index 8af4df5..e1b2625 100644 --- a/src/gui/kernel/qt_x11_p.h +++ b/src/gui/kernel/qt_x11_p.h @@ -439,6 +439,12 @@ struct QX11Data int xinput_eventbase; int xinput_errorbase; + // for XKEYBOARD support + bool use_xkb; + int xkb_major; + int xkb_eventbase; + int xkb_errorbase; + QList<QWidget *> deferred_map; struct ScrollInProgress { long id; diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index a0e4050..b3a6aec 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -3294,7 +3294,7 @@ void QWidgetPrivate::update_sys(const QRect &r) #ifndef QT_MAC_USE_COCOA HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true); #else - [qt_mac_nativeview_for(q) setNeedsDisplay:YES]; + qt_mac_set_needs_display(q, QRegion()); #endif return; } @@ -3332,21 +3332,24 @@ void QWidgetPrivate::update_sys(const QRegion &rgn) HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true); // do a complete repaint on overflow. } #else - // Cocoa doesn't do regions, it seems more efficient to just update the bounding rect instead of a potential number of message passes for each rect. - const QRect & boundingRect = rgn.boundingRect(); - // Alien support: get the first native ancestor widget (will be q itself in the non-alien case), // map the coordinates from q space to NSView space and invalidate the rect. QWidget *nativeParent = q->internalWinId() ? q : q->nativeParentWidget(); if (nativeParent == 0) - return; - const QRect nativeBoundingRect = QRect( - QPoint(q->mapTo(nativeParent, boundingRect.topLeft())), - QSize(boundingRect.size())); + return; + + QVector<QRect> rects = rgn.rects(); + for (int i = 0; i < rects.count(); ++i) { + const QRect &rect = rects.at(i); - [qt_mac_nativeview_for(nativeParent) setNeedsDisplayInRect:NSMakeRect(nativeBoundingRect.x(), - nativeBoundingRect.y(), nativeBoundingRect.width(), - nativeBoundingRect.height())]; + const QRect nativeBoundingRect = QRect( + QPoint(q->mapTo(nativeParent, rect.topLeft())), + QSize(rect.size())); + + [qt_mac_nativeview_for(nativeParent) setNeedsDisplayInRect:NSMakeRect(nativeBoundingRect.x(), + nativeBoundingRect.y(), nativeBoundingRect.width(), + nativeBoundingRect.height())]; + } #endif } @@ -4027,7 +4030,7 @@ static void qt_mac_update_widget_posisiton(QWidget *q, QRect oldRect, QRect newR #else Q_UNUSED(oldRect); NSRect bounds = NSMakeRect(newRect.x(), newRect.y(), - newRect.width(), newRect.height()); + newRect.width(), newRect.height()); [qt_mac_nativeview_for(q) setFrame:bounds]; #endif } @@ -4830,7 +4833,7 @@ void QWidgetPrivate::finishCocoaMaskSetup() [window setOpaque:(extra->imageMask == 0)]; [window invalidateShadow]; } - [qt_mac_nativeview_for(q) setNeedsDisplay:YES]; + qt_mac_set_needs_display(q, QRegion()); } #endif |