Version 5.0.2: Fix IME-to-search on macOS.

This commit is contained in:
John Preston 2024-05-24 16:09:21 +04:00
parent f4864cddc9
commit 31fcca245f
2 changed files with 40 additions and 2 deletions

View File

@ -20,8 +20,6 @@ class MainWindow : public Window::MainWindow {
public:
explicit MainWindow(not_null<Window::Controller*> 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();

View File

@ -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<NSEvent*>(message);
if (PossiblyTextTypingEvent(event)) {
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
imeCompositionStartReceived();
});
}
}
return false;
}
void MainWindow::hideAndDeactivate() {
hide();
}