Make PreventDelayedActivation more reliable.
This commit is contained in:
parent
8415f7058c
commit
214c5e8e22
1 changed files with 33 additions and 2 deletions
|
|
@ -7,19 +7,35 @@
|
||||||
#include "ui/delayed_activation.h"
|
#include "ui/delayed_activation.h"
|
||||||
|
|
||||||
#include "ui/ui_utility.h"
|
#include "ui/ui_utility.h"
|
||||||
|
#include "base/call_delayed.h"
|
||||||
|
#include "base/invoke_queued.h"
|
||||||
|
|
||||||
#include <QtCore/QPointer>
|
#include <QtCore/QPointer>
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
auto Paused = false;
|
constexpr auto kPreventTimeout = crl::time(100);
|
||||||
|
|
||||||
|
bool Paused/* = false*/;
|
||||||
|
bool Attempted/* = false*/;
|
||||||
auto Window = QPointer<QWidget>();
|
auto Window = QPointer<QWidget>();
|
||||||
|
|
||||||
|
bool Unpause(bool force = false) {
|
||||||
|
if (force || Attempted) {
|
||||||
|
Attempted = false;
|
||||||
|
Paused = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void ActivateWindowDelayed(not_null<QWidget*> widget) {
|
void ActivateWindowDelayed(not_null<QWidget*> widget) {
|
||||||
if (Paused) {
|
if (Paused) {
|
||||||
|
Attempted = true;
|
||||||
return;
|
return;
|
||||||
} else if (std::exchange(Window, widget.get())) {
|
} else if (std::exchange(Window, widget.get())) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -40,7 +56,22 @@ void PreventDelayedActivation() {
|
||||||
Window = nullptr;
|
Window = nullptr;
|
||||||
Paused = true;
|
Paused = true;
|
||||||
PostponeCall([] {
|
PostponeCall([] {
|
||||||
Paused = false;
|
if (Unpause()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
InvokeQueued(qApp, [] {
|
||||||
|
if (Unpause()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
crl::on_main([] {
|
||||||
|
if (Unpause()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
base::call_delayed(kPreventTimeout, [] {
|
||||||
|
Unpause(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue