diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.h b/Telegram/SourceFiles/platform/mac/main_window_mac.h index 36dc140bd..6c2d15d07 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.h +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.h @@ -20,8 +20,6 @@ class MainWindow : public Window::MainWindow { public: explicit MainWindow(not_null controller); - bool psFilterNativeEvent(void *event); - int getCustomTitleHeight() const { return _customTitleHeight; } @@ -47,6 +45,11 @@ protected: private: friend class Private; + bool nativeEvent( + const QByteArray &eventType, + void *message, + qintptr *result) override; + void hideAndDeactivate(); void updateDockCounter(); diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 055722742..0b2adb9aa 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -63,6 +63,26 @@ namespace { // fullscreen mode, after that we'll hide the window no matter what. constexpr auto kHideAfterFullscreenTimeoutMs = 3000; +[[nodiscard]] bool PossiblyTextTypingEvent(NSEvent *e) { + if ([e type] != NSEventTypeKeyDown) { + return false; + } + NSEventModifierFlags flags = [e modifierFlags] + & NSEventModifierFlagDeviceIndependentFlagsMask; + if ((flags & ~NSEventModifierFlagShift) != 0) { + return false; + } + NSString *text = [e characters]; + const auto length = int([text length]); + for (auto i = 0; i != length; ++i) { + const auto utf16 = [text characterAtIndex:i]; + if (utf16 >= 32) { + return true; + } + } + return false; +} + } // namespace class MainWindow::Private { @@ -280,6 +300,21 @@ void MainWindow::initHook() { void MainWindow::updateWindowIcon() { } +bool MainWindow::nativeEvent( + const QByteArray &eventType, + void *message, + qintptr *result) { + if (message && eventType == "NSEvent") { + const auto event = static_cast(message); + if (PossiblyTextTypingEvent(event)) { + Core::Sandbox::Instance().customEnterFromEventLoop([&] { + imeCompositionStartReceived(); + }); + } + } + return false; +} + void MainWindow::hideAndDeactivate() { hide(); }