From 31fcca245f35f4a98c79f9bc8eb41241e40d652d Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 24 May 2024 16:09:21 +0400 Subject: [PATCH] Version 5.0.2: Fix IME-to-search on macOS. --- .../platform/mac/main_window_mac.h | 7 ++-- .../platform/mac/main_window_mac.mm | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.h b/Telegram/SourceFiles/platform/mac/main_window_mac.h index 36dc140bda7a1f..6c2d15d07254ee 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 @@ class MainWindow : public Window::MainWindow { 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 055722742bd68a..0b2adb9aab44bb 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -63,6 +63,26 @@ - (void) screenIsUnlocked:(NSNotification *)aNotification; // 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 @@ QString strNotificationAboutScreenUnlocked() { 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(); }