summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoakeymapper.mm
Commit message (Collapse)AuthorAgeFilesLines
* iOS: Handle keyboard events when using an external keyboardAndy Shaw2021-01-201-547/+0
| | | | | | | | | | | | | | | | | | This enables the two possible approaches for handling external keyboard events. While support still exists for before 13.4 then both approaches are needed. This ensures that all external keyboard events are handled as key events and passed on accordingly. Additionally, this accounts for possible shortcuts too, therefore a new function is added to QShortcutMap to aid that. As a result, code has now moved from QCocoaKeyMapper to be part of the gui/platforms/darwin part to make it easier to reuse this code elsewhere. Fixes: QTBUG-85727 Change-Id: I349af43468b03fd8dcb16adba02669974affe154 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QChar: make construction from integral explicitGiuseppe D'Angelo2020-11-151-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QChar should not be convertible from any integral type except from char16_t, short and possibly char (since it's a direct superset). David provided the perfect example: if (str == 123) { ~~~ } compiles, with 123 implicitly converted to QChar (str == "123" was meant instead). But similarly one can construct other scenarios where QString(123) gets accidentally used (instead of QString::number(123)), like QString s; s += 123;. Add a macro to revert to the implicit constructors, for backwards compatibility. The breaks are mostly in tests that "abuse" of integers (arithmetic, etc.). Maybe it's time for user-defined literals for QChar/QString, but that is left for another commit. [ChangeLog][Potentially Source-Incompatible Changes][QChar] QChar constructors from integral types are now by default explicit. It is recommended to use explicit conversions, QLatin1Char, QChar::fromUcs4 instead of implicit conversions. The old behavior can be restored by defining the QT_IMPLICIT_QCHAR_CONSTRUCTION macro. Change-Id: I6175f6ab9bcf1956f6f97ab0c9d9d5aaf777296d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Un-special-case macOS in handling of QKeyEvent::nativeScanCode()Tor Arne Vestbø2020-10-061-1/+5
| | | | | | | | | | | | | | | | | | | | | | | In the porting from Qt 4 to Qt 5 an assumption was made in QKeyMapper that the underlying platform implementation needed the native scan code to be able to resolve the possible keymaps for an event. As a result, the macOS platform plugin started sending key events with a fake native scan code of 1, so that it would still be allowed to map key events. Which in turn led to the documentation of QKeyEvent::nativeScanCode() getting an exception for macOS. Let's clean up this by removing the original assumption, and leave it up to the platforms to decide what information from the key event is needed. QKeyMapperPrivate::possibleKeys() will still call extractKeyFromEvent as a fallback if the platform layer doesn't return any possible keys. Change-Id: I122a45bcec658c45ccc0b2c0671eb264d85d7be6 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Prevent mapping non-keydown events to charactersTor Arne Vestbø2020-10-061-13/+21
| | | | | | | | | | The [NSEvent charactersByApplyingModifiers:] API only supports key down events, but we might get into QCocoaKeyMapper::keyMapForKey for modifier key presses as well (even if QShortcutMap::nextState tries to filter out modifier keys). Change-Id: I02f163edac2baa9052f34b4d5d31b6a627d3d85c Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* QCocoaKeyMapper: do not sum integral+QFlagsGiuseppe D'Angelo2020-09-031-2/+2
| | | | | | | | It will become illegal; keep the semantics but force the right casts. Change-Id: I4002c5bca6eb90e798e35ca263e7bbb4ff5ad4b1 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Clarify that QCocoaKeyMapper only computes 8 modifier statesTor Arne Vestbø2020-07-241-1/+4
| | | | | Change-Id: Ie4a53bbc16cde7b4aa68172015bbfeaa9e316bcc Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Use Cocoa to map key events to possible shortcut key sequencesTor Arne Vestbø2020-07-131-3/+19
| | | | | | | | For now we just verify that the Cocoa API produces the same keymaps as we get from Carbon. Once that's verified we can solidify the code. Change-Id: I0d2aa1bb0a006d29c0149e3ff2fd5299ba922326 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Modernize QCocoaKeyMapper key mapTor Arne Vestbø2020-07-131-44/+23
| | | | | Change-Id: I3e8a4cfa611b6ae575466c493aac438dc831e89a Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Remove unused method QKeyMapper::clearMappings()Tor Arne Vestbø2020-07-101-6/+0
| | | | | | | | | | | The plumbing from QKeyMapper to the platform specific key mappers via QPA was never done, so this method is unused. The code path in QKeyMapper that would trigger it would be changeKeyboard(), but that's already handled in QCocoaKeyMapper, and wouldn't be initiated from the cross platform code in any case. Change-Id: Ibc0c419627fc0430d028945038c1f2fbafe42d4b Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Add QCocoaKeyMapper::toCocoaModifiersTor Arne Vestbø2020-07-101-0/+13
| | | | | Change-Id: I489c64733275260bb041f8df5cc5ff4a571d4e9c Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Map Qt::KeyboardModifier to a single Carbon modifierTor Arne Vestbø2020-07-081-3/+0
| | | | | | | | | The modifier is passed to UCKeyTranslate, and we don't need to turn e.g. Qt::ShiftModifier into both shiftKey and rightShiftKey. One is enough to map the virtual key to a unicode character. Change-Id: I33c46c016df03ecf17b5d87885d80a6d581767bc Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* macOS: Don't rely on Carbon for QCocoaKeyMapper::queryKeyboardModifiers()Tor Arne Vestbø2020-07-081-23/+12
| | | | | | | | | | | The semantics of the Cocoa API matches that of the Carbon API we are replacing, in that it reflects the "state of devices combined with synthesized events at the moment, independent of which events have been delivered via the event stream.", which is the same semantics as QGuiApplication::queryKeyboardModifiers() expects. Change-Id: Ic00ccbb3e8ae571522245df30924952aa2cc71de Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* macOS: Simplify QCocoaKeyMapper::fromCocoaModifiersTor Arne Vestbø2020-07-081-13/+15
| | | | | Change-Id: I6c25c1cfd4253d13623b2706c3b93632711fc577 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* macOS: Use helper method in QCocoaKeyMapper for swapping Ctrl and CmdTor Arne Vestbø2020-07-081-32/+23
| | | | | | | | | Centralizes the logic for swapping the two modifiers. The debug logging for modifier mapping has been removed as that level of granular logging is overkill. Change-Id: Ib4818c77f5b32ff20c9fe6df56528a120e5bd80e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* macOS: Fix mapping of Qt to Carbon modifiers with AA_MacDontSwapCtrlAndMetaTor Arne Vestbø2020-07-031-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | The macOS platform plugin function toCarbonModifiers is based on a mapping table with already swapped modifiers, where Qt::MetaModifier maps to controlKey. We were using the Carbon fooKeyBit constants instead of the fooKey constants, so the logic for mapping from Qt to Carbon modifiers when AA_MacDontSwapCtrlAndMeta was set to true would fail to reverse the swap from the mapping table. Since the command and control modifiers rarely produce different unicode characters from the base keyboard layout, at least not in the tested key layouts, and the AA_MacDontSwapCtrlAndMeta is not commonly used, this bug was not that visible. The logic maintains the behavior of mapping a single Qt modifier to multiple Carbon modifiers (both left and right command e.g.). This is a bit weird, but existing behavior that should be looked at in a followup. Change-Id: I8b30854770d1230a47f5144bf3245d0ac1493b51 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Simplify QCocoaKeyMapper::(to/from)CocoaKeyTor Arne Vestbø2020-07-021-67/+19
| | | | | Change-Id: I8daf735e9b49b24b8144b2aab8966b6313dfa3fa Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Move key mapping from QtCore to platform pluginTor Arne Vestbø2020-07-021-0/+142
| | | | | | | | | | | There's a bunch of similar and overlapping logic in QCocoaKeyMapper already. Moving it to the same place allows us to easier find ways to reduce the overlap. None of the exported functions were used outside of the plugin. Change-Id: I6953690cdfda5ee8265b33ccbf919184c3a1700f Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Move Cocoa modifier mapping logic to QCocoaKeyMapperTor Arne Vestbø2020-07-021-0/+17
| | | | | | | Along with similar logic for Carbon. Change-Id: Ie32f8ffa336006387d50d3b9e8491816aba4ea04 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Pass correct modifier to QCocoaKeyMapper::toKeyCode()Tor Arne Vestbø2020-06-301-1/+1
| | | | | | | | | | | | | The modifierKeyState variable is based on the Carbon modifiers, and then further mangled to match the expected format of UCKeyTranslate. But inside QCocoaKeyMapper::toKeyCode() we compare the modifiers to Qt::KeyboardModifiers. To ensure the logic works as expected we need to pass in the Qt modifiers. This fixes shortcut sequences based on "Backtab". Change-Id: I089fe601f0fe7a92f746e0a6447e2de0d974d0b2 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Simplify QCocoaKeyMapper by always returning a valid keymapTor Arne Vestbø2020-06-301-14/+13
| | | | | | | | | | | | | QCocoaKeyMapper::updateKeyMap would always end up creating a valid key map, so the logic in CocoaKeyMapper::possibleKeys for dealing with missing keymaps was not needed, and was likely copied from one of the other key map implementations. Since we know that we have a key map we might as well return it after possibly updating it. Change-Id: If83974f4ddedae8b1acefbadef48da3ee326eadd Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* macOS: Modernize QCocoaKeyMapperTor Arne Vestbø2020-06-301-308/+276
| | | | | | | | | | | | | | | Paying off technical debt from Qt 4 times, and preparation for removing Carbon dependency. - Proper variable names (m_ prefix, titleCase, fullyWrittenOut) - Modern data structures for lookups - Removal of dead code/variables - Categorized logging - Built in constants instead of magic numbers - Typed variables instead of naked integers Change-Id: Ie14621e0da8ed61e2185fa05373047204dc4ea62 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* macOS: Clean up headersTor Arne Vestbø2020-06-051-0/+2
| | | | | | | | | | | | | | The headers are now C++ clean and can be used outside of Objective-C code. All includes of Objective-C frameworks have been moved to the implementation files. Header guards have been added in the few places they were missing. All includes are now done via #include, instead of sometimes using the #import variant. Change-Id: Ibb0a9c0bcfefbda4347737212e40e300a3184982 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Cocoa integration: fix incorrect keyboard mappingTimur Pocheptsov2018-10-041-4/+6
| | | | | | | | When switching between different input sources, we have to update layouts. Task-number: QTBUG-50865 Change-Id: I0c23c19b79a2102dcc533822b0f861c387582c6c Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* QCocoaKeyMapper: Properly initialize all members and reset on updateUlf Hermann2018-10-041-4/+5
| | | | | | | | | | | Previously some of the members would have random initial values. Also, on updateKeyboard() if we don't find usable uchrData, we should just reset keyboard_layout_format and keyboard_mode, rather than keep the previous values. Task-number: QTBUG-50865 Change-Id: I1297fa55bb1593dd549d0bc122713d5d98f7b1fc Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Fix QGuiApplication::queryKeyboardModifiers() on macOSNils Jeisecke2018-07-201-1/+1
| | | | | | | | | | | | | | | | | | To quote the documentation: Queries and returns the state of the modifier keys on the keyboard. Unlike keyboardModifiers, this method returns the actual keys held on the input device at the time of calling the method. So GetCurrentKeyModifiers seems to be the correct Carbon function to use. [ChangeLog][QtGui][QGuiApplication] Fix queryKeyboardModifiers() on macOS to actually return the current modifier key state Change-Id: I11f2ef1897a39aea13df4afbfebb8172ca803a30 Task-number: QTBUG-26413 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Cocoa QPA: Clean up 0 as pointerGabriel de Dietrich2018-04-191-4/+4
| | | | | | | | We use nil for Objective-C null pointers and nullptr everywhere else, including CoreFoundation and similar opaque types. Change-Id: Id75c59413dec54bf4d8e83cf7ed0ff7f3d8bb480 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QCocoaKeyMapper: Remove unused member variablesGabriel de Dietrich2017-09-061-11/+0
| | | | | | | These are written into, but never read from. Change-Id: I23af5dbb2d162b06ed93f32459140a8385d65a95 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Remove unused function qt_mac_secure_keyboardGabriel de Dietrich2017-04-051-8/+0
| | | | | | | This function was also relying on Carbon APIs. Change-Id: I87bc942800f5f3dc4ab69cad80f3cbf06d1ad4e2 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* cocoa: Account for getting a keyboard using input methods correctlyAndy Shaw2017-01-101-1/+3
| | | | | | | | | | | | When a keyboard is using an input method then the layout for it needs to be retrieved with TISCopyInputMethodKeyboardLayoutOverride(). For cases where it is not using an input method this will return null and in that case we can use the original approach as before. Task-number: QTBUG-53804 Task-number: QTBUG-57934 Change-Id: I6283785bf002602113e208bb38d5eb2a9a7ceb36 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Merge remote-tracking branch 'origin/5.7' into 5.8Liang Qi2016-10-111-9/+7
|\ | | | | | | | | | | | | | | Conflicts: src/gui/image/qpixmap.cpp src/widgets/kernel/qformlayout.cpp Change-Id: I8a8391a202adf7f18464a22ddf0a6c4974eab692
| * Revert "QCocoaKeyMapper - correctly update key layouts"Timur Pocheptsov2016-10-101-9/+7
| | | | | | | | | | | | | | | | | | | | This reverts commit 26961e32f34c06f083fe441c23be6874f03446a3. This patch was apparently a bit ill-considered and while fixed one problem introduced others. Task-number: QTBUG-50865 Change-Id: I2e3569d16c8fc47b4a492d4aed6e747d7ff93a55 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* | Replace QCFString::to(CF/NS/Q)String usage with QString methodsTor Arne Vestbø2016-10-061-1/+1
| | | | | | | | | | | | | | | | Slims down QCFString and leaves only one implementation of converting back and forth between CF/NS strings and QStrings. Change-Id: I068568ffa25e6f4f6d6c99dcf47078b7a8e70e10 Reviewed-by: Jake Petroules <jake.petroules@qt.io>
* | Fix PrintScreen mapping on macOS and moreAllan Sandfeld Jensen2016-10-041-1/+5
|/ | | | | | | | | | | Fixes the mapping of the rare multimedia Print key, adds the real mapping of the Print Screen key. Also adds a mapping for few other short-cut keys that were added in 5.6 Change-Id: I931bf1eed062536e1be2aa6aa6f19d773bb5ec55 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
* QCocoaKeyMapper - correctly update key layoutsTimur Pocheptsov2016-02-251-7/+9
| | | | | | | | | | | | | QCocoaKeyMapper has 2 bugs: - fails to update layouts even if input source changed - while looking for the possible keys it clears bits for neededMods thus making later shortcut match impossible Change-Id: Ie230b973acd5ca6f50b97ca4901ede61b581d273 Task-number: QTBUG-50865 Reviewed-by: Andy Shaw <andy.shaw@theqtcompany.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
* Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Fixed license headersJani Heikkinen2015-02-171-1/+1
| | | | | Change-Id: Ibebe1318d1c2de97601aa07269705c87737083ee Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* Update copyright headersJani Heikkinen2015-02-111-22/+14
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* OS X: Add scan code mappings for Escape, Return and function keys.Dyami Caliri2014-09-171-16/+26
| | | | | | | | | | | | In OS X, certain keyboard layouts (such as Japanese) do not produce unicode character conversions for Escape and other keys. In these cases the code uses a fallback scan code check to map the key. The scan code mapping had the function keys, but there are several other important keys it can map. Task-number: QTBUG-41090 Change-Id: I624793c9bb28ae8c98b54539c277943905cac7e2 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
* Cocoa: added queryKeyboardModifiers() in platform pluginLiang Qi2014-03-151-0/+5
| | | | | | Task-number: QTBUG-37181 Change-Id: I9256d0c9b83d6e5982864dc747586cbe2322b60c Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Implement Cocoa KeyMapper.Morten Johan Sorvig2012-12-071-0/+468
Port Qt 4 implementation. Shortcuts such as shift-5 should now work. Change-Id: I1d8c4c6c4a903142361996b558ee31c8549fcef6 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Oliver Wolff <oliver.wolff@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>