diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 84acf4fe57..f8f5846f42 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -17,7 +17,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "calls/calls_instance.h" #include "base/openssl_help.h" #include "base/random.h" -#include "base/power_save_blocker.h" #include "mtproto/mtproto_dh_utils.h" #include "mtproto/mtproto_config.h" #include "core/application.h" @@ -164,17 +163,12 @@ Call::Call( , _api(&_user->session().mtp()) , _type(type) , _discardByTimeoutTimer([=] { hangup(); }) -, _powerSaveBlocker(std::make_unique( - base::PowerSaveBlockType::PreventDisplaySleep, - u"Video call is active"_q)) , _videoIncoming( std::make_unique( StartVideoState(video))) , _videoOutgoing( std::make_unique( StartVideoState(video))) { - ; - if (_type == Type::Outgoing) { setState(State::Requesting); } else { @@ -1014,7 +1008,6 @@ void Call::setState(State state) { || state == State::Busy) { // Destroy controller before destroying Call Panel, // so that the panel hide animation is smooth. - _powerSaveBlocker = nullptr; destroyController(); } switch (state) { diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h index 750c75be58..ffc503d1f9 100644 --- a/Telegram/SourceFiles/calls/calls_call.h +++ b/Telegram/SourceFiles/calls/calls_call.h @@ -13,10 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" #include "mtproto/mtproto_auth_key.h" -namespace base { -class PowerSaveBlocker; -} // namespace base - namespace Media { namespace Audio { class Track; @@ -273,8 +269,6 @@ private: base::DelayedCallTimer _finishByTimeoutTimer; base::Timer _discardByTimeoutTimer; - std::unique_ptr _powerSaveBlocker; - rpl::variable _muted = false; DhConfig _dhConfig; diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index ba59a72f9e..42e059b70a 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -44,6 +44,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "platform/platform_specific.h" #include "base/platform/base_platform_info.h" +#include "base/power_save_blocker.h" #include "window/main_window.h" #include "webrtc/webrtc_video_track.h" #include "webrtc/webrtc_media_devices.h" @@ -357,6 +358,7 @@ void Panel::reinitWithCall(Call *call) { if (!_call) { _incoming = nullptr; _outgoingVideoBubble = nullptr; + _powerSaveBlocker = nullptr; return; } @@ -497,6 +499,11 @@ void Panel::reinitWithCall(Call *call) { _camera->raise(); _mute->raise(); + _powerSaveBlocker = std::make_unique( + base::PowerSaveBlockType::PreventDisplaySleep, + u"Video call is active"_q, + window()->windowHandle()); + _incoming->widget()->lower(); } @@ -804,6 +811,10 @@ void Panel::stateChanged(State state) { && (state != State::EndedByOtherDevice) && (state != State::FailedHangingUp) && (state != State::Failed)) { + if (state == State::Busy) { + _powerSaveBlocker = nullptr; + } + auto toggleButton = [&](auto &&button, bool visible) { button->toggle( visible, diff --git a/Telegram/SourceFiles/calls/calls_panel.h b/Telegram/SourceFiles/calls/calls_panel.h index f06fc7185d..5e448857e7 100644 --- a/Telegram/SourceFiles/calls/calls_panel.h +++ b/Telegram/SourceFiles/calls/calls_panel.h @@ -19,6 +19,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class Image; +namespace base { +class PowerSaveBlocker; +} // namespace base + namespace Data { class PhotoMedia; class CloudImageView; @@ -130,6 +134,8 @@ private: std::unique_ptr _controls; #endif // !Q_OS_MAC + std::unique_ptr _powerSaveBlocker; + QSize _incomingFrameSize; rpl::lifetime _callLifetime; diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index 39f551a162..2fd9fa8e7a 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer_values.h" #include "data/data_session.h" #include "base/global_shortcuts.h" -#include "base/power_save_blocker.h" #include "base/random.h" #include "webrtc/webrtc_video_track.h" #include "webrtc/webrtc_media_devices.h" @@ -568,9 +567,6 @@ GroupCall::GroupCall( , _peer(info.peer) , _history(_peer->owner().history(_peer)) , _api(&_peer->session().mtp()) -, _powerSaveBlocker(std::make_unique( - base::PowerSaveBlockType::PreventDisplaySleep, - u"Video chat is active"_q)) , _joinAs(info.joinAs) , _possibleJoinAs(std::move(info.possibleJoinAs)) , _joinHash(info.joinHash) diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.h b/Telegram/SourceFiles/calls/group/calls_group_call.h index 0776ee5cc4..a3fdf90394 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.h +++ b/Telegram/SourceFiles/calls/group/calls_group_call.h @@ -26,7 +26,6 @@ class VideoCaptureInterface; namespace base { class GlobalShortcutManager; class GlobalShortcutValue; -class PowerSaveBlocker; } // namespace base namespace Webrtc { @@ -565,8 +564,6 @@ private: bool _recordingStoppedByMe = false; bool _requestedVideoChannelsUpdateScheduled = false; - std::unique_ptr _powerSaveBlocker; - MTP::DcId _broadcastDcId = 0; base::flat_map, LoadingPart> _broadcastParts; base::flat_set< diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index e35b9c23c7..972d2e20c9 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -49,6 +49,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "base/qt_signal_producer.h" #include "base/timer_rpl.h" +#include "base/power_save_blocker.h" #include "apiwrap.h" // api().kick. #include "api/api_chat_participants.h" // api().kick. #include "webrtc/webrtc_video_track.h" @@ -92,6 +93,10 @@ Panel::Panel(not_null call) window(), st::groupCallTitle)) #endif // !Q_OS_MAC +, _powerSaveBlocker(std::make_unique( + base::PowerSaveBlockType::PreventDisplaySleep, + u"Video chat is active"_q, + window()->windowHandle())) , _viewport( std::make_unique(widget(), PanelMode::Wide, _window.backend())) , _mute(std::make_unique( diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.h b/Telegram/SourceFiles/calls/group/calls_group_panel.h index 04f8952805..65c0f92ca5 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.h +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.h @@ -22,6 +22,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class Image; +namespace base { +class PowerSaveBlocker; +} // namespace base + namespace Data { class PhotoMedia; class CloudImageView; @@ -198,6 +202,8 @@ private: std::unique_ptr _controls; #endif // !Q_OS_MAC + const std::unique_ptr _powerSaveBlocker; + rpl::lifetime _callLifetime; object_ptr _title = { nullptr }; diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index a4ebcba4ab..2f458262a6 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #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. @@ -577,16 +578,22 @@ void Instance::updatePowerSaveBlocker( const auto blockVideo = block && data->current.audio() && data->current.audio()->isVideoMessage(); + const auto windowResolver = [] { + const auto window = Core::App().activeWindow(); + return window ? window->widget()->windowHandle() : nullptr; + }; base::UpdatePowerSaveBlocker( data->powerSaveBlocker, block, base::PowerSaveBlockType::PreventAppSuspension, - "Audio playback is active"); // const char*, not QString-construct. + [] { return u"Audio playback is active"_q; }, + windowResolver); base::UpdatePowerSaveBlocker( data->powerSaveBlockerVideo, blockVideo, base::PowerSaveBlockType::PreventDisplaySleep, - "Video playback is active"); // const char*, not QString-construct. + [] { return u"Video playback is active"_q; }, + windowResolver); } void Instance::ensureShuffleMove(not_null data, int delta) { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 2254d01827..043875e2ef 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -2805,7 +2805,8 @@ void OverlayWidget::updatePowerSaveBlocker( _streamed->powerSaveBlocker, block, base::PowerSaveBlockType::PreventDisplaySleep, - "Video playback is active"); // const char*, not QString-construct. + [] { return u"Video playback is active"_q; }, + [=] { return window(); }); } QImage OverlayWidget::transformedShownContent() const { diff --git a/Telegram/SourceFiles/media/view/media_view_pip.cpp b/Telegram/SourceFiles/media/view/media_view_pip.cpp index 76235fe320..c1319952f3 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip.cpp @@ -1539,7 +1539,8 @@ void Pip::updatePowerSaveBlocker(const Player::TrackState &state) { _powerSaveBlocker, block, base::PowerSaveBlockType::PreventDisplaySleep, - "Video playback is active"); // const char*, not QString-construct. + [] { return u"Video playback is active"_q; }, + [=] { return _panel.widget()->windowHandle(); }); } void Pip::updatePlaybackTexts( diff --git a/Telegram/lib_base b/Telegram/lib_base index d0e2cd26bf..0437cd92ad 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit d0e2cd26bf288d5f27b121636ff0c80dd2da2c11 +Subproject commit 0437cd92adc5706c1fe3409a0459c2f70ced21f4 diff --git a/cmake b/cmake index 605ad62e11..6d81711cf8 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 605ad62e110ddd2dea43ae9bf7b7565aa23c0978 +Subproject commit 6d81711cf8d7feda1314ebccc262eeb28b6f8103