Use RpWidget::windowActiveValue

This commit is contained in:
Ilya Fedin 2024-06-18 12:32:27 +04:00 committed by John Preston
parent 8a5797e1bd
commit a22cf8e303
8 changed files with 25 additions and 40 deletions

View file

@ -897,7 +897,7 @@ void Widget::setupStories() {
Core::App().saveSettingsDelayed();
};
_stories->setShowTooltip(
parentWidget(),
controller()->content(),
rpl::combine(
Core::App().settings().storiesClickTooltipHiddenValue(),
shownValue(),

View file

@ -903,7 +903,7 @@ TextWithEntities List::computeTooltipText() const {
}
void List::setShowTooltip(
not_null<QWidget*> tooltipParent,
not_null<Ui::RpWidget*> tooltipParent,
rpl::producer<bool> shown,
Fn<void()> hide) {
_tooltip = nullptr;
@ -925,16 +925,6 @@ void List::setShowTooltip(
tooltip->toggleFast(false);
updateTooltipGeometry();
const auto handle = tooltipParent->window()->windowHandle();
auto windowActive = rpl::single(
handle->isActive()
) | rpl::then(base::qt_signal_producer(
handle,
&QWindow::activeChanged
) | rpl::map([=] {
return handle->isActive();
})) | rpl::distinct_until_changed();
{
const auto recompute = [=] {
updateTooltipGeometry();
@ -955,7 +945,7 @@ void List::setShowTooltip(
_tooltipText.value() | rpl::map(
notEmpty
) | rpl::distinct_until_changed(),
std::move(windowActive)
tooltipParent->windowActiveValue()
) | rpl::start_with_next([=](bool, bool, bool active) {
_tooltipWindowActive = active;
if (!isHidden()) {
@ -981,7 +971,7 @@ void List::toggleTooltip(bool fast) {
&& !isHidden()
&& _tooltipNotHidden.current()
&& !_tooltipText.current().empty()
&& window()->windowHandle()->isActive();
&& isActiveWindow();
if (_tooltip) {
if (fast) {
_tooltip->toggleFast(shown);

View file

@ -72,7 +72,7 @@ public:
style::align alignSmall,
QRect geometryFull = QRect());
void setShowTooltip(
not_null<QWidget*> tooltipParent,
not_null<Ui::RpWidget*> tooltipParent,
rpl::producer<bool> shown,
Fn<void()> hide);
void raiseTooltip();

View file

@ -342,11 +342,9 @@ void Controller::createWindow() {
_window = std::make_unique<Ui::RpWindow>();
const auto window = _window.get();
base::qt_signal_producer(
window->window()->windowHandle(),
&QWindow::activeChanged
) | rpl::filter([=] {
return _webview && window->window()->windowHandle()->isActive();
window->windowActiveValue(
) | rpl::filter([=](bool active) {
return _webview && active;
}) | rpl::start_with_next([=] {
setInnerFocus();
}, window->lifetime());

View file

@ -139,7 +139,9 @@ void MainWindow::finishFirstShow() {
applyInitialWorkMode();
createGlobalMenu();
windowDeactivateEvents(
windowActiveValue(
) | rpl::skip(1) | rpl::filter(
!rpl::mappers::_1
) | rpl::start_with_next([=] {
Ui::Tooltip::Hide();
}, lifetime());
@ -594,7 +596,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *e) {
case QEvent::ApplicationActivate: {
if (object == QCoreApplication::instance()) {
InvokeQueued(this, [=] {
handleActiveChanged();
handleActiveChanged(isActiveWindow());
});
}
} break;

View file

@ -328,16 +328,11 @@ Controller::Controller(not_null<Delegate*> delegate)
}
}, _lifetime);
const auto window = _wrap->window()->windowHandle();
Assert(window != nullptr);
base::qt_signal_producer(
window,
&QWindow::activeChanged
) | rpl::start_with_next([=] {
_windowActive = window->isActive();
_wrap->windowActiveValue(
) | rpl::start_with_next([=](bool active) {
_windowActive = active;
updatePlayingAllowed();
}, _lifetime);
_windowActive = window->isActive();
_contentFadeAnimation.stop();
}

View file

@ -351,6 +351,13 @@ MainWindow::MainWindow(not_null<Controller*> controller)
Ui::Toast::SetDefaultParent(_body.data());
}
windowActiveValue(
) | rpl::skip(1) | rpl::start_with_next([=](bool active) {
InvokeQueued(this, [=] {
handleActiveChanged(active);
});
}, lifetime());
body()->sizeValue(
) | rpl::start_with_next([=](QSize size) {
updateControlsGeometry();
@ -445,13 +452,6 @@ void MainWindow::init() {
initHook();
// Non-queued activeChanged handlers must use QtSignalProducer.
connect(
windowHandle(),
&QWindow::activeChanged,
this,
[=] { handleActiveChanged(); },
Qt::QueuedConnection);
connect(
windowHandle(),
&QWindow::windowStateChanged,
@ -495,9 +495,9 @@ void MainWindow::handleStateChanged(Qt::WindowState state) {
savePosition(state);
}
void MainWindow::handleActiveChanged() {
void MainWindow::handleActiveChanged(bool active) {
checkActivation();
if (isActiveWindow()) {
if (active) {
Core::App().windowActivated(&controller());
}
if (const auto controller = sessionController()) {

View file

@ -151,7 +151,7 @@ protected:
void savePosition(Qt::WindowState state = Qt::WindowActive);
void handleStateChanged(Qt::WindowState state);
void handleActiveChanged();
void handleActiveChanged(bool active);
void handleVisibleChanged(bool visible);
virtual void checkActivation() {