Skip to content

Commit

Permalink
Version 5.0.2: Fix IME-to-search on macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed May 24, 2024
1 parent f4864cd commit 31fcca2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Telegram/SourceFiles/platform/mac/main_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class MainWindow : public Window::MainWindow {
public:

This comment has been minimized.

Copy link
@lumhtawng2002

lumhtawng2002 May 25, 2024

xvg bv b vb v b vgvd cgvcvxg @hcbh hb h h sjn ghj hhs h hcgh h ccscscc

explicit MainWindow(not_null<Window::Controller*> controller);

bool psFilterNativeEvent(void *event);

int getCustomTitleHeight() const {
return _customTitleHeight;
}
Expand All @@ -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();

Expand Down
35 changes: 35 additions & 0 deletions Telegram/SourceFiles/platform/mac/main_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<NSEvent*>(message);
if (PossiblyTextTypingEvent(event)) {
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
imeCompositionStartReceived();
});
}
}
return false;
}

void MainWindow::hideAndDeactivate() {
hide();
}
Expand Down

0 comments on commit 31fcca2

Please sign in to comment.