diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 444e141c45..38d133c951 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -943,8 +943,6 @@ PRIVATE platform/win/windows_dlls.h platform/win/windows_event_filter.cpp platform/win/windows_event_filter.h - platform/win/windows_system_media_controls_manager.cpp - platform/win/windows_system_media_controls_manager.h platform/platform_audio.h platform/platform_file_utilities.h platform/platform_launcher.h @@ -1088,6 +1086,8 @@ PRIVATE window/section_memento.h window/section_widget.cpp window/section_widget.h + window/system_media_controls_manager.cpp + window/system_media_controls_manager.h window/window_connecting_widget.cpp window/window_connecting_widget.h window/window_controller.cpp diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 9bad8c5f5a..033fd78ff9 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -45,6 +45,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/notifications_manager.h" #include "window/themes/window_theme.h" #include "window/themes/window_theme_warning.h" +#include "window/system_media_controls_manager.h" #include "window/window_lock_widgets.h" #include "window/window_main_menu.h" #include "window/window_controller.h" // App::wnd. @@ -81,7 +82,11 @@ void FeedLangTestingKey(int key) { } // namespace MainWindow::MainWindow(not_null controller) -: Platform::MainWindow(controller) { +: Platform::MainWindow(controller) +, _mediaControlsManager(Window::SystemMediaControlsManager::Supported() + ? std::make_unique(this) + : nullptr) { + auto logo = Core::App().logo(); icon16 = logo.scaledToWidth(16, Qt::SmoothTransformation); icon32 = logo.scaledToWidth(32, Qt::SmoothTransformation); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 93127e6687..2920ce16a6 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -24,6 +24,7 @@ class MediaPreviewWidget; class SectionMemento; struct SectionShow; class PasscodeLockWidget; +class SystemMediaControlsManager; namespace Theme { struct BackgroundUpdate; class WarningWidget; @@ -130,6 +131,9 @@ private: QPixmap grabInner(); + using MediaControlsManager = Window::SystemMediaControlsManager; + const std::unique_ptr _mediaControlsManager; + QImage icon16, icon32, icon64, iconbig16, iconbig32, iconbig64; crl::time _lastTrayClickTime = 0; diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index a4d4b17139..ad90832f0b 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_notifications_manager.h" #include "platform/win/windows_dlls.h" #include "platform/win/windows_event_filter.h" -#include "platform/win/windows_system_media_controls_manager.h" #include "window/notifications_manager.h" #include "mainwindow.h" #include "base/crc32hash.h" @@ -431,10 +430,6 @@ void MainWindow::initHook() { } psInitSysMenu(); - - if (IsWindows10OrGreater()) { - _smtcManager = std::make_unique(psHwnd()); - } } void MainWindow::initShadows() { diff --git a/Telegram/SourceFiles/platform/win/main_window_win.h b/Telegram/SourceFiles/platform/win/main_window_win.h index 246a10e4e6..28bd7aa40e 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.h +++ b/Telegram/SourceFiles/platform/win/main_window_win.h @@ -20,8 +20,6 @@ class PopupMenu; namespace Platform { -class SystemMediaControlsManager; - class MainWindow : public Window::MainWindow { public: explicit MainWindow(not_null controller); @@ -125,8 +123,6 @@ private: HICON ps_iconSmall = nullptr; HICON ps_iconOverlay = nullptr; - std::unique_ptr _smtcManager; - int _deltaLeft = 0; int _deltaTop = 0; int _deltaRight = 0; diff --git a/Telegram/SourceFiles/platform/win/windows_system_media_controls_manager.cpp b/Telegram/SourceFiles/window/system_media_controls_manager.cpp similarity index 84% rename from Telegram/SourceFiles/platform/win/windows_system_media_controls_manager.cpp rename to Telegram/SourceFiles/window/system_media_controls_manager.cpp index d783f28028..abb1a6a094 100644 --- a/Telegram/SourceFiles/platform/win/windows_system_media_controls_manager.cpp +++ b/Telegram/SourceFiles/window/system_media_controls_manager.cpp @@ -5,10 +5,10 @@ the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ -#include "platform/win/windows_system_media_controls_manager.h" +#include "window/system_media_controls_manager.h" #include "base/observer.h" -#include "base/platform/win/base_windows_system_media_controls.h" +#include "base/platform/base_platform_system_media_controls.h" #include "core/application.h" #include "data/data_document.h" #include "data/data_document_media.h" @@ -18,16 +18,25 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/player/media_player_instance.h" #include "ui/text/format_song_document_name.h" -namespace Platform { +namespace Window { -SystemMediaControlsManager::SystemMediaControlsManager(HWND hwnd) -: _controls(std::make_unique()) { +bool SystemMediaControlsManager::Supported() { + return base::Platform::SystemMediaControls::Supported(); +} + +SystemMediaControlsManager::SystemMediaControlsManager( + not_null parent) +: _controls(std::make_unique()) { using PlaybackStatus = - base::Platform::SystemMediaControlsWin::PlaybackStatus; - using Command = base::Platform::SystemMediaControlsWin::Command; + base::Platform::SystemMediaControls::PlaybackStatus; + using Command = base::Platform::SystemMediaControls::Command; - _controls->init(hwnd); + const auto inited = _controls->init(parent.get()); + if (!inited) { + LOG(("SystemMediaControlsManager failed to init.")); + return; + } const auto type = AudioMsgId::Type::Song; const auto mediaPlayer = Media::Player::instance(); @@ -52,8 +61,8 @@ SystemMediaControlsManager::SystemMediaControlsManager(HWND hwnd) mediaPlayer->stops(type) | rpl::map_to(false), mediaPlayer->startsPlay(type) | rpl::map_to(true) ) | rpl::start_with_next([=](bool audio) { + _controls->setEnabled(audio); if (audio) { - _controls->setEnabled(audio); _controls->setIsNextEnabled(mediaPlayer->nextAvailable(type)); _controls->setIsPreviousEnabled( mediaPlayer->previousAvailable(type)); @@ -75,8 +84,8 @@ SystemMediaControlsManager::SystemMediaControlsManager(HWND hwnd) }); auto unlocked = Core::App().passcodeLockChanges( - ) | rpl::filter([](bool locked) { - return !locked; + ) | rpl::filter([=](bool locked) { + return !locked && (mediaPlayer->current(type)); }) | rpl::map([=] { return type; }) | rpl::before_next([=] { @@ -145,4 +154,4 @@ SystemMediaControlsManager::SystemMediaControlsManager(HWND hwnd) SystemMediaControlsManager::~SystemMediaControlsManager() = default; -} // namespace Platform +} // namespace Window diff --git a/Telegram/SourceFiles/platform/win/windows_system_media_controls_manager.h b/Telegram/SourceFiles/window/system_media_controls_manager.h similarity index 72% rename from Telegram/SourceFiles/platform/win/windows_system_media_controls_manager.h rename to Telegram/SourceFiles/window/system_media_controls_manager.h index 76222d9b04..edf370868d 100644 --- a/Telegram/SourceFiles/platform/win/windows_system_media_controls_manager.h +++ b/Telegram/SourceFiles/window/system_media_controls_manager.h @@ -8,22 +8,24 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once namespace base::Platform { -class SystemMediaControlsWin; +class SystemMediaControls; } // namespace base::Platform namespace Data { class DocumentMedia; } // namespace Data -namespace Platform { +namespace Window { class SystemMediaControlsManager { public: - SystemMediaControlsManager(HWND hwnd); + SystemMediaControlsManager(not_null parent); ~SystemMediaControlsManager(); + static bool Supported(); + private: - const std::unique_ptr _controls; + const std::unique_ptr _controls; std::vector> _cachedMediaView; @@ -31,4 +33,4 @@ private: rpl::lifetime _lifetime; }; -} // namespace Platform +} // namespace Window diff --git a/Telegram/lib_base b/Telegram/lib_base index 846282f36f..3f791f9794 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit 846282f36fc4270a1d6b926163d104b40800e781 +Subproject commit 3f791f9794b102c5c14485e0f25df2e18b49f129 diff --git a/cmake b/cmake index 4caa867468..03efe01ff9 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 4caa8674681fb50a2244b58eb701508017c360d6 +Subproject commit 03efe01ff978b84745414e046e4766225ffffb7f