Add Ui::AppInFocus() method.

This commit is contained in:
John Preston 2019-12-31 16:48:25 +03:00
parent f0e95ee933
commit 765e525458
4 changed files with 14 additions and 10 deletions

View file

@ -462,10 +462,10 @@ void LayerStackWidget::setCacheImages() {
void LayerStackWidget::closeLayer(not_null<LayerWidget*> layer) { void LayerStackWidget::closeLayer(not_null<LayerWidget*> layer) {
const auto weak = Ui::MakeWeak(layer.get()); const auto weak = Ui::MakeWeak(layer.get());
if (weak->inFocusChain()) { if (Ui::InFocusChain(layer)) {
setFocus(); setFocus();
} }
if (!weak || !weak->setClosing()) { if (!layer->setClosing()) {
// This layer is already closing. // This layer is already closing.
return; return;
} else if (!weak) { } else if (!weak) {
@ -734,9 +734,11 @@ void LayerStackWidget::appendBox(
LayerWidget *LayerStackWidget::pushBox( LayerWidget *LayerStackWidget::pushBox(
object_ptr<BoxContent> box, object_ptr<BoxContent> box,
anim::type animated) { anim::type animated) {
auto oldLayer = currentLayer(); const auto oldLayer = currentLayer();
if (oldLayer) { if (oldLayer) {
if (oldLayer->inFocusChain()) setFocus(); if (Ui::InFocusChain(oldLayer)) {
setFocus();
}
oldLayer->hide(); oldLayer->hide();
} }
_layers.push_back( _layers.push_back(
@ -793,7 +795,7 @@ void LayerStackWidget::clearClosingLayers() {
while (!_closingLayers.empty()) { while (!_closingLayers.empty()) {
const auto index = _closingLayers.size() - 1; const auto index = _closingLayers.size() - 1;
const auto layer = _closingLayers.back().get(); const auto layer = _closingLayers.back().get();
if (layer->inFocusChain()) { if (Ui::InFocusChain(layer)) {
setFocus(); setFocus();
} }

View file

@ -28,10 +28,6 @@ public:
return QMargins(); return QMargins();
} }
bool inFocusChain() const {
return Ui::InFocusChain(this);
}
void hideChildren() { void hideChildren() {
for (auto child : Base::children()) { for (auto child : Base::children()) {
if (child->isWidgetType()) { if (child->isWidgetType()) {

View file

@ -8,8 +8,8 @@
#include "ui/style/style_core.h" #include "ui/style/style_core.h"
#include <QtWidgets/QApplication>
#include <QtGui/QWindow> #include <QtGui/QWindow>
#include <QtGui/QGuiApplication>
#include <QtGui/QtEvents> #include <QtGui/QtEvents>
#include <array> #include <array>
@ -82,6 +82,10 @@ void SendPendingEventsRecursive(QWidget *target, bool parentHiddenFlag) {
} // namespace } // namespace
bool AppInFocus() {
return QApplication::focusWidget() != nullptr;
}
void SendPendingMoveResizeEvents(not_null<QWidget*> target) { void SendPendingMoveResizeEvents(not_null<QWidget*> target) {
CreateWidgetStateRecursive(target); CreateWidgetStateRecursive(target);
SendPendingEventsRecursive(target, !target->isVisible()); SendPendingEventsRecursive(target, !target->isVisible());

View file

@ -98,6 +98,8 @@ inline not_null<std::decay_t<Value>*> AttachAsChild(
std::forward<Value>(value))->value(); std::forward<Value>(value))->value();
} }
[[nodiscard]] bool AppInFocus();
[[nodiscard]] inline bool InFocusChain(not_null<const QWidget*> widget) { [[nodiscard]] inline bool InFocusChain(not_null<const QWidget*> widget) {
if (const auto top = widget->window()) { if (const auto top = widget->window()) {
if (auto focused = top->focusWidget()) { if (auto focused = top->focusWidget()) {