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(); Core::App().saveSettingsDelayed();
}; };
_stories->setShowTooltip( _stories->setShowTooltip(
parentWidget(), controller()->content(),
rpl::combine( rpl::combine(
Core::App().settings().storiesClickTooltipHiddenValue(), Core::App().settings().storiesClickTooltipHiddenValue(),
shownValue(), shownValue(),

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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