From 2ffc0196dde086e887c68dd75ddbc0cc8efd9a00 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 19 Oct 2016 16:31:18 +0300 Subject: [PATCH] Fix reply from notifications (Qt 5.6.2 broke it). Now the mouse press on Qt::BypassWindowManagerHint window doesn't activate it. So if you want a working input field in a Qt::BypassWindowManagerHint window, you should activate it yourself from any mouse press event. --- Telegram/SourceFiles/mediaview.cpp | 13 +++++------ Telegram/SourceFiles/mediaview.h | 1 + .../window/notifications_manager_default.cpp | 22 ++++++++++++++++++- .../window/notifications_manager_default.h | 1 + 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index f7320ab9c4..82d603b4c5 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1185,14 +1185,7 @@ void MediaView::displayPhoto(PhotoData *photo, HistoryItem *item) { _from = _user; } _photo->download(); - updateControls(); - if (isHidden()) { - psUpdateOverlayed(this); - show(); - psShowOverAll(this); - activateWindow(); - setFocus(); - } + displayFinished(); } void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty messages shown as docs: doc can be NULL @@ -1330,6 +1323,10 @@ void MediaView::displayDocument(DocumentData *doc, HistoryItem *item) { // empty _from = _user; } _full = 1; + displayFinished(); +} + +void MediaView::displayFinished() { updateControls(); if (isHidden()) { psUpdateOverlayed(this); diff --git a/Telegram/SourceFiles/mediaview.h b/Telegram/SourceFiles/mediaview.h index 3957b3ef80..320b86fb5e 100644 --- a/Telegram/SourceFiles/mediaview.h +++ b/Telegram/SourceFiles/mediaview.h @@ -132,6 +132,7 @@ private slots: private: void displayPhoto(PhotoData *photo, HistoryItem *item); void displayDocument(DocumentData *doc, HistoryItem *item); + void displayFinished(); void findCurrent(); void loadBack(); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index bea4199822..1be72cfa8a 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "window/notifications_manager_default.h" #include "platform/platform_notifications_manager.h" +#include "application.h" #include "mainwindow.h" #include "lang.h" #include "ui/buttons/icon_button.h" @@ -725,7 +726,12 @@ void Notification::toggleActionButtons(bool visible) { } void Notification::showReplyField() { - if (_replyArea) return; + activateWindow(); + + if (_replyArea) { + _replyArea->setFocus(); + return; + } stopHiding(); _background = new Background(this); @@ -739,6 +745,9 @@ void Notification::showReplyField() { _replyArea->setFocus(); _replyArea->setMaxLength(MaxMessageSize); _replyArea->setCtrlEnterSubmit(CtrlEnterSubmitBoth); + + // Catch mouse press event to activate the window. + Sandbox::installEventFilter(this); connect(_replyArea, SIGNAL(resized()), this, SLOT(onReplyResize())); connect(_replyArea, SIGNAL(submitted(bool)), this, SLOT(onReplySubmit(bool))); connect(_replyArea, SIGNAL(cancelled()), this, SLOT(onReplyCancel())); @@ -820,6 +829,17 @@ void Notification::mousePressEvent(QMouseEvent *e) { } } +bool Notification::eventFilter(QObject *o, QEvent *e) { + if (e->type() == QEvent::MouseButtonPress) { + if (auto receiver = qobject_cast(o)) { + if (isAncestorOf(receiver)) { + activateWindow(); + } + } + } + return false; +} + void Notification::stopHiding() { if (!_history) return; _hideTimer.stop(); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.h b/Telegram/SourceFiles/window/notifications_manager_default.h index 228f4e62fd..490bad48bd 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.h +++ b/Telegram/SourceFiles/window/notifications_manager_default.h @@ -208,6 +208,7 @@ protected: void leaveEvent(QEvent *e) override; void paintEvent(QPaintEvent *e) override; void mousePressEvent(QMouseEvent *e) override; + bool eventFilter(QObject *o, QEvent *e) override; private slots: void onHideByTimer();