Active round video moving to active window.

This commit is contained in:
John Preston 2023-01-19 11:40:39 +04:00
parent b80b770631
commit ec3957fcf3
14 changed files with 140 additions and 78 deletions

View File

@ -184,6 +184,8 @@ Application::~Application() {
Local::writeSettings();
}
setLastActiveWindow(nullptr);
_lastActivePrimaryWindow = nullptr;
_closingAsyncWindows.clear();
_secondaryWindows.clear();
_primaryWindows.clear();
@ -287,9 +289,8 @@ void Application::run() {
QMimeDatabase().mimeTypeForName(u"text/plain"_q);
_primaryWindows.emplace(nullptr, std::make_unique<Window::Controller>());
_lastActiveWindow
= _lastActivePrimaryWindow
= _primaryWindows.front().second.get();
setLastActiveWindow(_primaryWindows.front().second.get());
_lastActivePrimaryWindow = _lastActiveWindow;
_domain->activeChanges(
) | rpl::start_with_next([=](not_null<Main::Account*> account) {
@ -737,35 +738,12 @@ bool Application::screenIsLocked() const {
return _screenIsLocked;
}
void Application::setDefaultFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> delegate) {
Expects(!_defaultFloatPlayerDelegate == !_floatPlayers);
_defaultFloatPlayerDelegate = delegate;
_replacementFloatPlayerDelegate = nullptr;
if (_floatPlayers) {
_floatPlayers->replaceDelegate(delegate);
} else {
_floatPlayers = std::make_unique<Media::Player::FloatController>(
delegate);
}
}
void Application::replaceFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> replacement) {
Expects(_floatPlayers != nullptr);
_replacementFloatPlayerDelegate = replacement;
_floatPlayers->replaceDelegate(replacement);
}
void Application::restoreFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> replacement) {
Expects(_floatPlayers != nullptr);
if (_replacementFloatPlayerDelegate == replacement) {
_replacementFloatPlayerDelegate = nullptr;
_floatPlayers->replaceDelegate(_defaultFloatPlayerDelegate);
void Application::floatPlayerToggleGifsPaused(bool paused) {
_floatPlayerGifsPaused = paused;
if (_lastActiveWindow) {
if (const auto delegate = _lastActiveWindow->floatPlayerDelegate()) {
delegate->floatPlayerToggleGifsPaused(paused);
}
}
}
@ -1304,6 +1282,35 @@ bool Application::closeNonLastAsync(not_null<Window::Controller*> window) {
return true;
}
void Application::setLastActiveWindow(Window::Controller *window) {
_floatPlayerDelegateLifetime.destroy();
if (_floatPlayerGifsPaused && _lastActiveWindow) {
if (const auto delegate = _lastActiveWindow->floatPlayerDelegate()) {
delegate->floatPlayerToggleGifsPaused(false);
}
}
_lastActiveWindow = window;
if (!window) {
_floatPlayers = nullptr;
return;
}
window->floatPlayerDelegateValue(
) | rpl::start_with_next([=](Media::Player::FloatDelegate *value) {
if (!value) {
_floatPlayers = nullptr;
} else if (_floatPlayers) {
_floatPlayers->replaceDelegate(value);
} else if (value) {
_floatPlayers = std::make_unique<Media::Player::FloatController>(
value);
}
if (value && _floatPlayerGifsPaused) {
value->floatPlayerToggleGifsPaused(true);
}
}, _floatPlayerDelegateLifetime);
}
void Application::closeWindow(not_null<Window::Controller*> window) {
const auto next = (_primaryWindows.front().second.get() != window)
? _primaryWindows.front().second.get()
@ -1314,7 +1321,7 @@ void Application::closeWindow(not_null<Window::Controller*> window) {
_lastActivePrimaryWindow = next;
}
if (_lastActiveWindow == window) {
_lastActiveWindow = next;
setLastActiveWindow(next);
if (_lastActiveWindow) {
_lastActiveWindow->activate();
_lastActiveWindow->widget()->updateGlobalMenu();
@ -1371,7 +1378,8 @@ void Application::closeChatFromWindows(not_null<PeerData*> peer) {
void Application::windowActivated(not_null<Window::Controller*> window) {
const auto was = _lastActiveWindow;
const auto now = window;
_lastActiveWindow = window;
setLastActiveWindow(window);
if (window->isPrimary()) {
_lastActivePrimaryWindow = window;

View File

@ -258,12 +258,7 @@ public:
[[nodiscard]] QString changelogLink() const;
// Float player.
void setDefaultFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> delegate);
void replaceFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> replacement);
void restoreFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> replacement);
void floatPlayerToggleGifsPaused(bool paused);
[[nodiscard]] rpl::producer<FullMsgId> floatPlayerClosed() const;
// Calls.
@ -339,6 +334,7 @@ private:
void startSystemDarkModeViewer();
void startTray();
void setLastActiveWindow(Window::Controller *window);
void showAccount(not_null<Main::Account*> account);
void enumerateWindows(
Fn<void(not_null<Window::Controller*>)> callback) const;
@ -412,8 +408,8 @@ private:
const std::unique_ptr<Tray> _tray;
std::unique_ptr<Media::Player::FloatController> _floatPlayers;
Media::Player::FloatDelegate *_defaultFloatPlayerDelegate = nullptr;
Media::Player::FloatDelegate *_replacementFloatPlayerDelegate = nullptr;
rpl::lifetime _floatPlayerDelegateLifetime;
bool _floatPlayerGifsPaused = false;
rpl::variable<bool> _passcodeLock;
bool _screenIsLocked = false;

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/cached_round_corners.h"
#include "window/section_widget.h"
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "window/main_window.h"
#include "main/main_session.h"
@ -31,7 +32,7 @@ LayerWidget::LayerWidget(
: _controller(controller)
, _content(this, controller, Wrap::Layer, memento) {
setupHeightConsumers();
Core::App().replaceFloatPlayerDelegate(floatPlayerDelegate());
controller->window().replaceFloatPlayerDelegate(floatPlayerDelegate());
}
LayerWidget::LayerWidget(
@ -40,7 +41,7 @@ LayerWidget::LayerWidget(
: _controller(controller)
, _content(memento->takeContent(this, Wrap::Layer)) {
setupHeightConsumers();
Core::App().replaceFloatPlayerDelegate(floatPlayerDelegate());
controller->window().replaceFloatPlayerDelegate(floatPlayerDelegate());
}
auto LayerWidget::floatPlayerDelegate()
@ -52,6 +53,15 @@ not_null<Ui::RpWidget*> LayerWidget::floatPlayerWidget() {
return this;
}
void LayerWidget::floatPlayerToggleGifsPaused(bool paused) {
constexpr auto kReason = Window::GifPauseReason::RoundPlaying;
if (paused) {
_controller->enableGifPauseReason(kReason);
} else {
_controller->disableGifPauseReason(kReason);
}
}
auto LayerWidget::floatPlayerGetSection(Window::Column column)
-> not_null<::Media::Player::FloatSectionDelegate*> {
Expects(_content != nullptr);
@ -357,7 +367,8 @@ void LayerWidget::paintEvent(QPaintEvent *e) {
void LayerWidget::restoreFloatPlayerDelegate() {
if (!_floatPlayerDelegateRestored) {
_floatPlayerDelegateRestored = true;
Core::App().restoreFloatPlayerDelegate(floatPlayerDelegate());
_controller->window().restoreFloatPlayerDelegate(
floatPlayerDelegate());
}
}

View File

@ -58,6 +58,7 @@ private:
void restoreFloatPlayerDelegate();
not_null<::Media::Player::FloatDelegate*> floatPlayerDelegate();
not_null<Ui::RpWidget*> floatPlayerWidget() override;
void floatPlayerToggleGifsPaused(bool paused) override;
not_null<::Media::Player::FloatSectionDelegate*> floatPlayerGetSection(
Window::Column column) override;
void floatPlayerEnumerateSections(Fn<void(

View File

@ -89,7 +89,7 @@ Widget::Widget(
this,
account,
rpl::single(true))) {
Core::App().setDefaultFloatPlayerDelegate(floatPlayerDelegate());
controller->setDefaultFloatPlayerDelegate(floatPlayerDelegate());
getData()->country = ComputeNewAccountCountry();
@ -175,6 +175,9 @@ not_null<Ui::RpWidget*> Widget::floatPlayerWidget() {
return this;
}
void Widget::floatPlayerToggleGifsPaused(bool paused) {
}
auto Widget::floatPlayerGetSection(Window::Column column)
-> not_null<Media::Player::FloatSectionDelegate*> {
return this;

View File

@ -158,6 +158,7 @@ private:
[[nodiscard]] auto floatPlayerSectionDelegate()
-> not_null<Media::Player::FloatSectionDelegate*>;
not_null<Ui::RpWidget*> floatPlayerWidget() override;
void floatPlayerToggleGifsPaused(bool paused) override;
not_null<Media::Player::FloatSectionDelegate*> floatPlayerGetSection(
Window::Column column) override;
void floatPlayerEnumerateSections(Fn<void(

View File

@ -271,9 +271,9 @@ MainWidget::MainWidget(
_callTopBar->finishAnimating();
}
if (isPrimary()) {
Core::App().setDefaultFloatPlayerDelegate(floatPlayerDelegate());
}
controller->window().setDefaultFloatPlayerDelegate(
floatPlayerDelegate());
Core::App().floatPlayerClosed(
) | rpl::start_with_next([=](FullMsgId itemId) {
floatPlayerClosed(itemId);
@ -431,6 +431,15 @@ not_null<Ui::RpWidget*> MainWidget::floatPlayerWidget() {
return this;
}
void MainWidget::floatPlayerToggleGifsPaused(bool paused) {
constexpr auto kReason = Window::GifPauseReason::RoundPlaying;
if (paused) {
_controller->enableGifPauseReason(kReason);
} else {
_controller->disableGifPauseReason(kReason);
}
}
auto MainWidget::floatPlayerGetSection(Window::Column column)
-> not_null<Media::Player::FloatSectionDelegate*> {
if (isThreeColumn()) {

View File

@ -306,6 +306,7 @@ private:
[[nodiscard]] auto floatPlayerDelegate()
-> not_null<Media::Player::FloatDelegate*>;
not_null<Ui::RpWidget*> floatPlayerWidget() override;
void floatPlayerToggleGifsPaused(bool paused) override;
not_null<Media::Player::FloatSectionDelegate*> floatPlayerGetSection(
Window::Column column) override;
void floatPlayerEnumerateSections(Fn<void(

View File

@ -130,6 +130,7 @@ public:
class FloatDelegate {
public:
virtual not_null<Ui::RpWidget*> floatPlayerWidget() = 0;
virtual void floatPlayerToggleGifsPaused(bool paused) = 0;
virtual not_null<FloatSectionDelegate*> floatPlayerGetSection(
Window::Column column) = 0;
virtual void floatPlayerEnumerateSections(Fn<void(

View File

@ -25,12 +25,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item.h"
#include "data/data_media_types.h"
#include "data/data_file_origin.h"
#include "window/window_session_controller.h"
#include "window/window_controller.h"
#include "core/shortcuts.h"
#include "core/application.h"
#include "main/main_domain.h" // Domain::activeSessionValue.
#include "core/core_settings.h"
#include "window/window_controller.h"
#include "mainwindow.h"
#include "main/main_domain.h" // Domain::activeSessionValue.
#include "main/main_session.h"
#include "main/main_account.h" // session->account().sessionChanges().
#include "main/main_session_settings.h"
@ -308,13 +308,7 @@ void Instance::clearStreamed(not_null<Data*> data, bool savePosition) {
data->streamed = nullptr;
_roundPlaying = false;
// #TODO windows
if (const auto window = Core::App().activePrimaryWindow()) {
if (const auto controller = window->sessionController()) {
controller->disableGifPauseReason(
Window::GifPauseReason::RoundPlaying);
}
}
Core::App().floatPlayerToggleGifsPaused(false);
}
void Instance::refreshPlaylist(not_null<Data*> data) {
@ -1277,10 +1271,6 @@ void Instance::setupShortcuts() {
}, _lifetime);
}
bool Instance::pauseGifByRoundVideo() const {
return _roundPlaying;
}
void Instance::stopAndClose() {
_closePlayerRequests.fire({});
@ -1303,13 +1293,7 @@ void Instance::handleStreamingUpdate(
requestRoundVideoRepaint();
});
_roundPlaying = true;
// #TODO windows
if (const auto window = Core::App().activePrimaryWindow()) {
if (const auto controller = window->sessionController()) {
controller->enableGifPauseReason(
Window::GifPauseReason::RoundPlaying);
}
}
Core::App().floatPlayerToggleGifsPaused(true);
requestRoundVideoResize();
}
emitUpdate(data->type);

View File

@ -166,8 +166,6 @@ public:
[[nodiscard]] rpl::producer<Seeking> seekingChanges(
AudioMsgId::Type type) const;
[[nodiscard]] bool pauseGifByRoundVideo() const;
[[nodiscard]] rpl::producer<> closePlayerRequests() const {
return _closePlayerRequests.events();
}

View File

@ -480,6 +480,40 @@ auto Controller::openInMediaViewRequests() const
return _openInMediaViewRequests.events();
}
void Controller::setDefaultFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> delegate) {
_defaultFloatPlayerDelegate = delegate;
_replacementFloatPlayerDelegate = nullptr;
_floatPlayerDelegate = delegate;
}
void Controller::replaceFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> replacement) {
Expects(_defaultFloatPlayerDelegate != nullptr);
_replacementFloatPlayerDelegate = replacement;
_floatPlayerDelegate = replacement;
}
void Controller::restoreFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> replacement) {
Expects(_defaultFloatPlayerDelegate != nullptr);
if (_replacementFloatPlayerDelegate == replacement) {
_replacementFloatPlayerDelegate = nullptr;
_floatPlayerDelegate = _defaultFloatPlayerDelegate;
}
}
auto Controller::floatPlayerDelegate() const -> FloatDelegate* {
return _floatPlayerDelegate.current();
}
auto Controller::floatPlayerDelegateValue() const
-> rpl::producer<FloatDelegate*> {
return _floatPlayerDelegate.value();
}
rpl::lifetime &Controller::lifetime() {
return _lifetime;
}

View File

@ -20,6 +20,10 @@ namespace Media::View {
struct OpenRequest;
} // namespace Media::View
namespace Media::Player {
class FloatDelegate;
} // namespace Media::Player
namespace Window {
class Controller final : public base::has_weak_ptr {
@ -114,9 +118,20 @@ public:
[[nodiscard]] auto openInMediaViewRequests() const
-> rpl::producer<Media::View::OpenRequest>;
QPoint getPointForCallPanelCenter() const;
[[nodiscard]] QPoint getPointForCallPanelCenter() const;
rpl::lifetime &lifetime();
using FloatDelegate = Media::Player::FloatDelegate;
void setDefaultFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> delegate);
void replaceFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> replacement);
void restoreFloatPlayerDelegate(
not_null<Media::Player::FloatDelegate*> replacement);
[[nodiscard]] FloatDelegate *floatPlayerDelegate() const;
[[nodiscard]] auto floatPlayerDelegateValue() const
-> rpl::producer<FloatDelegate*>;
[[nodiscard]] rpl::lifetime &lifetime();
private:
struct CreateArgs {
@ -154,6 +169,10 @@ private:
rpl::event_stream<Media::View::OpenRequest> _openInMediaViewRequests;
FloatDelegate *_defaultFloatPlayerDelegate = nullptr;
FloatDelegate *_replacementFloatPlayerDelegate = nullptr;
rpl::variable<FloatDelegate*> _floatPlayerDelegate = nullptr;
rpl::lifetime _accountLifetime;
rpl::lifetime _lifetime;

View File

@ -745,10 +745,6 @@ SessionController::SessionController(
}
}, _lifetime);
if (Media::Player::instance()->pauseGifByRoundVideo()) {
enableGifPauseReason(GifPauseReason::RoundPlaying);
}
session->changes().peerUpdates(
Data::PeerUpdate::Flag::FullInfo
) | rpl::filter([=](const Data::PeerUpdate &update) {