Skip to content

Commit

Permalink
Use RpWidget::screenValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Jun 22, 2024
1 parent 5180e0e commit 006d6fe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
10 changes: 5 additions & 5 deletions Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,10 @@ OverlayWidget::OverlayWidget()
_widget->setMouseTracking(true);
_window->createWinId();

QObject::connect(
window(),
&QWindow::screenChanged,
[=](QScreen *screen) { handleScreenChanged(screen); });
_window->screenValue(
) | rpl::skip(1) | rpl::start_with_next([=](not_null<QScreen*> screen) {
handleScreenChanged(screen);
}, lifetime());
subscribeToScreenGeometry();
updateGeometry();
updateControlsGeometry();
Expand Down Expand Up @@ -2315,7 +2315,7 @@ void OverlayWidget::dropdownHidden() {
}
}

void OverlayWidget::handleScreenChanged(QScreen *screen) {
void OverlayWidget::handleScreenChanged(not_null<QScreen*> screen) {
subscribeToScreenGeometry();
if (isHidden()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class OverlayWidget final
bool moveToNext(int delta);
void preloadData(int delta);

void handleScreenChanged(QScreen *screen);
void handleScreenChanged(not_null<QScreen*> screen);

[[nodiscard]] bool computeSaveButtonVisible() const;
void checkForSaveLoaded();
Expand Down
12 changes: 5 additions & 7 deletions Telegram/SourceFiles/media/view/media_view_pip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,10 @@ void PipPanel::init() {
Ui::Platform::ClearTransientParent(widget());
}, rp()->lifetime());

QObject::connect(
widget()->windowHandle(),
&QWindow::screenChanged,
[=](QScreen *screen) {
handleScreenChanged(screen);
});
rp()->screenValue(
) | rpl::skip(1) | rpl::start_with_next([=](not_null<QScreen*> screen) {
handleScreenChanged(screen);
}, rp()->lifetime());

if (Platform::IsWayland()) {
rp()->sizeValue(
Expand Down Expand Up @@ -637,7 +635,7 @@ void PipPanel::handleWaylandResize(QSize size) {
_inHandleWaylandResize = false;
}

void PipPanel::handleScreenChanged(QScreen *screen) {
void PipPanel::handleScreenChanged(not_null<QScreen*> screen) {
const auto screenGeometry = screen->availableGeometry();
const auto minimalSize = _ratio.scaled(
st::pipMinimalSize,
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/media/view/media_view_pip.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PipPanel final {
[[nodiscard]] bool dragging() const;

void handleWaylandResize(QSize size);
void handleScreenChanged(QScreen *screen);
void handleScreenChanged(not_null<QScreen*> screen);
void handleMousePress(QPoint position, Qt::MouseButton button);
void handleMouseRelease(QPoint position, Qt::MouseButton button);
void handleMouseMove(QPoint position);
Expand Down
18 changes: 6 additions & 12 deletions Telegram/SourceFiles/window/window_main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,21 +957,15 @@ void MainMenu::drawName(Painter &p) {
}

void MainMenu::initResetScaleButton() {
if (!window() || !window()->windowHandle()) {
return;
}
const auto handle = window()->windowHandle();
rpl::single(
handle->screen()
) | rpl::then(
base::qt_signal_producer(handle, &QWindow::screenChanged)
) | rpl::filter([](QScreen *screen) {
return screen != nullptr;
}) | rpl::map([](QScreen * screen) {
_controller->widget()->screenValue(
) | rpl::map([](not_null<QScreen*> screen) {
return rpl::single(
screen->availableGeometry()
) | rpl::then(
base::qt_signal_producer(screen, &QScreen::availableGeometryChanged)
base::qt_signal_producer(
screen.get(),
&QScreen::availableGeometryChanged
)
);
}) | rpl::flatten_latest(
) | rpl::map([](QRect available) {
Expand Down

0 comments on commit 006d6fe

Please sign in to comment.