mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Redirect IME to search on Windows.
This commit is contained in:
parent
1f3a3ec04b
commit
2cb0651b04
6 changed files with 56 additions and 6 deletions
|
@ -356,6 +356,14 @@ Widget::Widget(
|
|||
Ui::PostponeCall(this, [=] { listScrollUpdated(); });
|
||||
}, lifetime());
|
||||
|
||||
setAttribute(Qt::WA_InputMethodEnabled);
|
||||
controller->widget()->imeCompositionStarts(
|
||||
) | rpl::filter([=] {
|
||||
return redirectImeToSearch();
|
||||
}) | rpl::start_with_next([=] {
|
||||
_search->setFocusFast();
|
||||
}, lifetime());
|
||||
|
||||
_search->changes(
|
||||
) | rpl::start_with_next([=] {
|
||||
applySearchUpdate();
|
||||
|
@ -3290,12 +3298,17 @@ void Widget::keyPressEvent(QKeyEvent *e) {
|
|||
}
|
||||
}
|
||||
|
||||
bool Widget::redirectToSearchPossible() const {
|
||||
return !_openedFolder
|
||||
&& !_openedForum
|
||||
&& !_childList
|
||||
&& _search->isVisible()
|
||||
&& !_search->hasFocus()
|
||||
&& hasFocus();
|
||||
}
|
||||
|
||||
bool Widget::redirectKeyToSearch(QKeyEvent *e) const {
|
||||
if (_openedFolder
|
||||
|| _openedForum
|
||||
|| _childList
|
||||
|| !_search->isVisible()
|
||||
|| _search->hasFocus()) {
|
||||
if (!redirectToSearchPossible()) {
|
||||
return false;
|
||||
}
|
||||
const auto character = !(e->modifiers() & ~Qt::ShiftModifier)
|
||||
|
@ -3316,6 +3329,10 @@ bool Widget::redirectKeyToSearch(QKeyEvent *e) const {
|
|||
return data && data->hasText();
|
||||
}
|
||||
|
||||
bool Widget::redirectImeToSearch() const {
|
||||
return redirectToSearchPossible();
|
||||
}
|
||||
|
||||
void Widget::paintEvent(QPaintEvent *e) {
|
||||
if (controller()->contentOverlapped(this, e)) {
|
||||
return;
|
||||
|
|
|
@ -250,7 +250,9 @@ private:
|
|||
void updateSuggestions(anim::type animated);
|
||||
void processSearchFocusChange();
|
||||
|
||||
[[nodiscard]] bool redirectToSearchPossible() const;
|
||||
[[nodiscard]] bool redirectKeyToSearch(QKeyEvent *e) const;
|
||||
[[nodiscard]] bool redirectImeToSearch() const;
|
||||
|
||||
MTP::Sender _api;
|
||||
|
||||
|
|
|
@ -480,6 +480,21 @@ bool MainWindow::initGeometryFromSystem() {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MainWindow::nativeEvent(
|
||||
const QByteArray &eventType,
|
||||
void *message,
|
||||
long *result) {
|
||||
if (message) {
|
||||
const auto msg = static_cast<MSG*>(message);
|
||||
if (msg->message == WM_IME_STARTCOMPOSITION) {
|
||||
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||
imeCompositionStartReceived();
|
||||
});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainWindow::updateWindowIcon() {
|
||||
updateTaskbarAndIconCounters();
|
||||
}
|
||||
|
|
|
@ -48,6 +48,11 @@ protected:
|
|||
|
||||
bool initGeometryFromSystem() override;
|
||||
|
||||
bool nativeEvent(
|
||||
const QByteArray &eventType,
|
||||
void *message,
|
||||
long *result) override;
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
|
||||
|
|
|
@ -795,10 +795,18 @@ void MainWindow::setPositionInited() {
|
|||
_positionInited = true;
|
||||
}
|
||||
|
||||
void MainWindow::imeCompositionStartReceived() {
|
||||
_imeCompositionStartReceived.fire({});
|
||||
}
|
||||
|
||||
rpl::producer<> MainWindow::leaveEvents() const {
|
||||
return _leaveEvents.events();
|
||||
}
|
||||
|
||||
rpl::producer<> MainWindow::imeCompositionStarts() const {
|
||||
return _imeCompositionStartReceived.events();
|
||||
}
|
||||
|
||||
void MainWindow::leaveEventHook(QEvent *e) {
|
||||
_leaveEvents.fire({});
|
||||
}
|
||||
|
|
|
@ -119,7 +119,8 @@ public:
|
|||
|
||||
void launchDrag(std::unique_ptr<QMimeData> data, Fn<void()> &&callback);
|
||||
|
||||
rpl::producer<> leaveEvents() const;
|
||||
[[nodiscard]] rpl::producer<> leaveEvents() const;
|
||||
[[nodiscard]] rpl::producer<> imeCompositionStarts() const;
|
||||
|
||||
virtual void updateWindowIcon() = 0;
|
||||
void updateTitle();
|
||||
|
@ -185,6 +186,7 @@ protected:
|
|||
return false;
|
||||
}
|
||||
|
||||
void imeCompositionStartReceived();
|
||||
void setPositionInited();
|
||||
|
||||
virtual QRect computeDesktopRect() const;
|
||||
|
@ -214,6 +216,7 @@ private:
|
|||
bool _isActive = false;
|
||||
|
||||
rpl::event_stream<> _leaveEvents;
|
||||
rpl::event_stream<> _imeCompositionStartReceived;
|
||||
|
||||
bool _maximizedBeforeHide = false;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue