Pass QWindow to PowerSaveBlocker.

This commit is contained in:
John Preston 2022-02-04 09:43:56 +03:00
parent 28dff5ba6d
commit f918c6bb83
13 changed files with 43 additions and 26 deletions

View File

@ -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::PowerSaveBlocker>(
base::PowerSaveBlockType::PreventDisplaySleep,
u"Video call is active"_q))
, _videoIncoming(
std::make_unique<Webrtc::VideoTrack>(
StartVideoState(video)))
, _videoOutgoing(
std::make_unique<Webrtc::VideoTrack>(
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) {

View File

@ -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<base::PowerSaveBlocker> _powerSaveBlocker;
rpl::variable<bool> _muted = false;
DhConfig _dhConfig;

View File

@ -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::PowerSaveBlocker>(
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,

View File

@ -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<Ui::Platform::SeparateTitleControls> _controls;
#endif // !Q_OS_MAC
std::unique_ptr<base::PowerSaveBlocker> _powerSaveBlocker;
QSize _incomingFrameSize;
rpl::lifetime _callLifetime;

View File

@ -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::PowerSaveBlocker>(
base::PowerSaveBlockType::PreventDisplaySleep,
u"Video chat is active"_q))
, _joinAs(info.joinAs)
, _possibleJoinAs(std::move(info.possibleJoinAs))
, _joinHash(info.joinHash)

View File

@ -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<base::PowerSaveBlocker> _powerSaveBlocker;
MTP::DcId _broadcastDcId = 0;
base::flat_map<not_null<LoadPartTask*>, LoadingPart> _broadcastParts;
base::flat_set<

View File

@ -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<GroupCall*> call)
window(),
st::groupCallTitle))
#endif // !Q_OS_MAC
, _powerSaveBlocker(std::make_unique<base::PowerSaveBlocker>(
base::PowerSaveBlockType::PreventDisplaySleep,
u"Video chat is active"_q,
window()->windowHandle()))
, _viewport(
std::make_unique<Viewport>(widget(), PanelMode::Wide, _window.backend()))
, _mute(std::make_unique<Ui::CallMuteButton>(

View File

@ -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<Ui::Platform::SeparateTitleControls> _controls;
#endif // !Q_OS_MAC
const std::unique_ptr<base::PowerSaveBlocker> _powerSaveBlocker;
rpl::lifetime _callLifetime;
object_ptr<Ui::FlatLabel> _title = { nullptr };

View File

@ -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*> data, int delta) {

View File

@ -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 {

View File

@ -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(

@ -1 +1 @@
Subproject commit d0e2cd26bf288d5f27b121636ff0c80dd2da2c11
Subproject commit 0437cd92adc5706c1fe3409a0459c2f70ced21f4

2
cmake

@ -1 +1 @@
Subproject commit 605ad62e110ddd2dea43ae9bf7b7565aa23c0978
Subproject commit 6d81711cf8d7feda1314ebccc262eeb28b6f8103