From 822c1cafd2b8fc20399b39ac29b1c55669eaea43 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 24 Mar 2021 08:58:47 +0400 Subject: [PATCH 01/17] Fix a space on end of a line in linux_mpris_support --- Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp index 339ae554e..ab438585e 100644 --- a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp @@ -367,7 +367,7 @@ void MPRISSupport::Private::updateTrackState( const auto &item1, const auto &item2) { return item1.first == item2.first - && item1.second.equal(item2.second); + && item1.second.equal(item2.second); })) { metadata = currentMetadata; PlayerPropertyChanged( From 81d052adfc6f35772cb70e2c090e3c0458f6ded3 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 24 Mar 2021 08:59:04 +0400 Subject: [PATCH 02/17] Add a way to get dark mode state on KDE --- .../platform/linux/specific_linux.cpp | 115 ++++++++++++++---- 1 file changed, 92 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index c52eef5f8..eb9f63bea 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #include "base/platform/linux/base_linux_dbus_utilities.h" +#include "base/platform/linux/base_linux_xdp_utilities.h" #include "platform/linux/linux_notification_service_watcher.h" #include "platform/linux/linux_mpris_support.h" #include "platform/linux/linux_gsd_media_keys.h" @@ -36,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION #include +#include #include #include #include @@ -67,6 +69,7 @@ namespace { constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs; constexpr auto kIconName = "telegram"_cs; constexpr auto kHandlerTypeName = "x-scheme-handler/tg"_cs; +constexpr auto kDarkColorLimit = 192; constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs; constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs; @@ -503,15 +506,36 @@ QImage GetImageFromClipboard() { } std::optional IsDarkMode() { + std::optional failResult; + if (static auto Once = false; !std::exchange(Once, true)) { + const auto onChanged = [] { + Core::Sandbox::Instance().customEnterFromEventLoop([] { + Core::App().settings().setSystemDarkMode(IsDarkMode()); + }); + }; + + QObject::connect( + qGuiApp, + &QGuiApplication::paletteChanged, + onChanged); + +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION + using XDPSettingWatcher = base::Platform::XDP::SettingWatcher; + static const XDPSettingWatcher KdeColorSchemeWatcher( + [=]( + const Glib::ustring &group, + const Glib::ustring &key, + const Glib::VariantBase &value) { + if (group == "org.kde.kdeglobals.General" + && key == "ColorScheme") { + onChanged(); + } + }); +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION + const auto integration = BaseGtkIntegration::Instance(); if (integration) { - const auto onChanged = [] { - Core::Sandbox::Instance().customEnterFromEventLoop([] { - Core::App().settings().setSystemDarkMode(IsDarkMode()); - }); - }; - integration->connectToSetting( "gtk-theme-name", onChanged); @@ -524,32 +548,77 @@ std::optional IsDarkMode() { } } - const auto integration = BaseGtkIntegration::Instance(); - if (!integration) { - return std::nullopt; - } + const auto styleName = QApplication::style()->metaObject()->className(); + if (styleName != qstr("QFusionStyle") + && styleName != qstr("QWindowsStyle")) { + failResult = false; - if (integration->checkVersion(3, 0, 0)) { - const auto preferDarkTheme = integration->getBoolSetting( - qsl("gtk-application-prefer-dark-theme")); + const auto paletteBackgroundGray = qGray( + QPalette().color(QPalette::Window).rgb()); - if (!preferDarkTheme.has_value()) { - return std::nullopt; - } else if (*preferDarkTheme) { + if (paletteBackgroundGray < kDarkColorLimit) { return true; } } - const auto themeName = integration->getStringSetting( - qsl("gtk-theme-name")); +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION + try { + using namespace base::Platform::XDP; - if (!themeName.has_value()) { - return std::nullopt; - } else if (themeName->contains(qsl("-dark"), Qt::CaseInsensitive)) { - return true; + const auto kdeBackgroundColorOptional = ReadSetting( + "org.kde.kdeglobals.Colors:Window", + "BackgroundNormal"); + + if (kdeBackgroundColorOptional.has_value()) { + const auto kdeBackgroundColorList = QString::fromStdString( + base::Platform::GlibVariantCast( + *kdeBackgroundColorOptional)).split(','); + + if (kdeBackgroundColorList.size() >= 3) { + failResult = false; + + const auto kdeBackgroundGray = qGray( + kdeBackgroundColorList[0].toInt(), + kdeBackgroundColorList[1].toInt(), + kdeBackgroundColorList[2].toInt()); + + if (kdeBackgroundGray < kDarkColorLimit) { + return true; + } + } + } + } catch (...) { + } +#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION + + const auto integration = BaseGtkIntegration::Instance(); + if (integration) { + if (integration->checkVersion(3, 0, 0)) { + const auto preferDarkTheme = integration->getBoolSetting( + qsl("gtk-application-prefer-dark-theme")); + + if (preferDarkTheme.has_value()) { + failResult = false; + + if (*preferDarkTheme) { + return true; + } + } + } + + const auto themeName = integration->getStringSetting( + qsl("gtk-theme-name")); + + if (themeName.has_value()) { + failResult = false; + + if (themeName->contains(qsl("-dark"), Qt::CaseInsensitive)) { + return true; + } + } } - return false; + return failResult; } bool AutostartSupported() { From a814c3f428db8ae01c16f5a600221a9cd15e800e Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 1 Apr 2021 02:38:48 +0000 Subject: [PATCH 03/17] Update User-Agent for DNS to Chrome 89.0.4389.90. --- .../SourceFiles/mtproto/details/mtproto_domain_resolver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp b/Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp index 384723a14..8d6eb07ac 100644 --- a/Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp +++ b/Telegram/SourceFiles/mtproto/details/mtproto_domain_resolver.cpp @@ -65,7 +65,7 @@ QByteArray DnsUserAgent() { static const auto kResult = QByteArray( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " "AppleWebKit/537.36 (KHTML, like Gecko) " - "Chrome/88.0.4324.182 Safari/537.36"); + "Chrome/89.0.4389.90 Safari/537.36"); return kResult; } From f528a240d9d3456b041a2c100f67e67f53e22bc3 Mon Sep 17 00:00:00 2001 From: Nicholas Guriev Date: Sat, 6 Mar 2021 09:38:12 +0300 Subject: [PATCH 04/17] Rely on QT_STRINGIFY instead of custom macro --- Telegram/SourceFiles/config.h | 2 +- Telegram/SourceFiles/platform/linux/launcher_linux.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 40ee00143..57a8ac904 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -75,7 +75,7 @@ w/CVnbwQOw0g5GBwwFV3r0uTTvy44xx8XXxk+Qknu4eBCsmrAFNnAgMBAAE=\n\ #if defined TDESKTOP_API_ID && defined TDESKTOP_API_HASH constexpr auto ApiId = TDESKTOP_API_ID; -constexpr auto ApiHash = MACRO_TO_STRING(TDESKTOP_API_HASH); +constexpr auto ApiHash = QT_STRINGIFY(TDESKTOP_API_HASH); #else // TDESKTOP_API_ID && TDESKTOP_API_HASH diff --git a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp index b3d097b43..fe219721e 100644 --- a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp @@ -66,7 +66,7 @@ void Launcher::initHook() { AppName.utf16().replace(' ', '_')); } - return qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME) ".desktop"); + return qsl(QT_STRINGIFY(TDESKTOP_LAUNCHER_BASENAME) ".desktop"); }()); } From 0cd8cc67c5f67ffb3171037ac7293d4967edf8da Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 27 Mar 2021 01:37:25 +0400 Subject: [PATCH 05/17] Scale window icon manually when getting from icon theme --- Telegram/SourceFiles/window/main_window.cpp | 38 ++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index f4fbe21af..5c148558a 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -119,7 +119,43 @@ QIcon CreateOfficialIcon(Main::Session *session) { QIcon CreateIcon(Main::Session *session) { auto result = CreateOfficialIcon(session); #if defined Q_OS_UNIX && !defined Q_OS_MAC - return QIcon::fromTheme(Platform::GetIconName(), result); + const auto iconFromTheme = QIcon::fromTheme( + Platform::GetIconName(), + result); + + result = QIcon(); + + static const auto iconSizes = { + 16, + 22, + 32, + 48, + 64, + 128, + 256, + }; + + // Qt's standard QIconLoaderEngine sets availableSizes + // to XDG directories sizes, since svg icons are scalable, + // they could be only in one XDG folder (like 48x48) + // and Qt will set only a 48px icon to the window + // even though the icon could be scaled to other sizes. + // Thus, scale it manually to the most widespread sizes. + for (const auto iconSize : iconSizes) { + // We can't use QIcon::actualSize here + // since it works incorrectly with svg icon themes + const auto iconPixmap = iconFromTheme.pixmap(iconSize); + + const auto iconPixmapSize = iconPixmap.size() + / iconPixmap.devicePixelRatio(); + + // Not a svg icon, don't scale it + if (iconPixmapSize.width() != iconSize) { + return iconFromTheme; + } + + result.addPixmap(iconPixmap); + } #endif return result; } From 073b5b106cca27b27ea92f91b0a96b638e5f80d4 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 2 Apr 2021 15:29:47 +0400 Subject: [PATCH 06/17] Get rid of modal parent hack It was introduced to workaround the absence of size hints propagating in Qt 5.12 Wayland backend, there's no need in it anymore --- Telegram/SourceFiles/calls/calls_group_panel.cpp | 1 - Telegram/SourceFiles/calls/calls_panel.cpp | 2 -- Telegram/SourceFiles/core/application.cpp | 8 -------- Telegram/SourceFiles/core/application.h | 1 - Telegram/SourceFiles/media/view/media_view_pip.cpp | 3 +-- Telegram/SourceFiles/settings/settings_notifications.cpp | 4 +--- Telegram/SourceFiles/ui/widgets/separate_panel.cpp | 3 +-- .../SourceFiles/window/notifications_manager_default.cpp | 4 +--- 8 files changed, 4 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/calls/calls_group_panel.cpp b/Telegram/SourceFiles/calls/calls_group_panel.cpp index e659dc03d..f6e36c991 100644 --- a/Telegram/SourceFiles/calls/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_group_panel.cpp @@ -253,7 +253,6 @@ std::unique_ptr InviteContactsController::createRow( Panel::Panel(not_null call) : _call(call) , _peer(call->peer()) -, _window(std::make_unique(Core::App().getModalParent())) , _layerBg(std::make_unique(_window->body())) #ifndef Q_OS_MAC , _controls(std::make_unique( diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index 2c3f5e6c6..1411d02d0 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -33,7 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/empty_userpic.h" #include "ui/emoji_config.h" #include "core/application.h" -#include "mainwindow.h" #include "lang/lang_keys.h" #include "main/main_session.h" #include "apiwrap.h" @@ -185,7 +184,6 @@ void Panel::Incoming::fillBottomShadow(QPainter &p) { Panel::Panel(not_null call) : _call(call) , _user(call->user()) -, _window(std::make_unique(Core::App().getModalParent())) #ifndef Q_OS_MAC , _controls(std::make_unique( _window->body(), diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 4139ee015..ce88bc621 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -23,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/ui_integration.h" #include "chat_helpers/emoji_keywords.h" #include "chat_helpers/stickers_emoji_image_loader.h" -#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_last_input.h" #include "platform/platform_specific.h" #include "mainwindow.h" @@ -977,13 +976,6 @@ void Application::notifyFileDialogShown(bool shown) { } } -QWidget *Application::getModalParent() { - return (Platform::IsWayland() && activeWindow()) - ? activeWindow()->widget().get() - : nullptr; -} - - void Application::checkMediaViewActivation() { if (_mediaView && !_mediaView->isHidden()) { _mediaView->activateWindow(); diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 8fe0c986a..eb0dc9ef2 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -139,7 +139,6 @@ public: bool minimizeActiveWindow(); [[nodiscard]] QWidget *getFileDialogParent(); void notifyFileDialogShown(bool shown); - [[nodiscard]] QWidget *getModalParent(); void checkSystemDarkMode(); // Media view interface. diff --git a/Telegram/SourceFiles/media/view/media_view_pip.cpp b/Telegram/SourceFiles/media/view/media_view_pip.cpp index d00596889..7bdbfcad6 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip.cpp @@ -373,8 +373,7 @@ QImage RotateFrameImage(QImage image, int rotation) { PipPanel::PipPanel( QWidget *parent, Fn paint) -: PipParent(Core::App().getModalParent()) -, _parent(parent) +: _parent(parent) , _paint(std::move(paint)) { setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index 8c6d4c4fb..0b686e405 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "platform/platform_notifications_manager.h" #include "base/platform/base_platform_info.h" -#include "mainwindow.h" #include "core/application.h" #include "main/main_session.h" #include "main/main_account.h" @@ -438,8 +437,7 @@ NotificationsCount::~NotificationsCount() { NotificationsCount::SampleWidget::SampleWidget( NotificationsCount *owner, const QPixmap &cache) -: QWidget(Core::App().getModalParent()) -, _owner(owner) +: _owner(owner) , _cache(cache) { const QSize size( cache.width() / cache.devicePixelRatio(), diff --git a/Telegram/SourceFiles/ui/widgets/separate_panel.cpp b/Telegram/SourceFiles/ui/widgets/separate_panel.cpp index 799405a79..281bc8387 100644 --- a/Telegram/SourceFiles/ui/widgets/separate_panel.cpp +++ b/Telegram/SourceFiles/ui/widgets/separate_panel.cpp @@ -31,8 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { SeparatePanel::SeparatePanel() -: RpWidget(Core::App().getModalParent()) -, _close(this, st::separatePanelClose) +: _close(this, st::separatePanelClose) , _back(this, object_ptr(this, st::separatePanelBack)) , _body(this) { setMouseTracking(true); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 5b706347a..a5ea81f96 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -30,7 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/call_delayed.h" #include "facades.h" #include "app.h" -#include "mainwindow.h" #include "styles/style_dialogs.h" #include "styles/style_layers.h" #include "styles/style_window.h" @@ -422,8 +421,7 @@ Widget::Widget( QPoint startPosition, int shift, Direction shiftDirection) -: RpWidget(Core::App().getModalParent()) -, _manager(manager) +: _manager(manager) , _startPosition(startPosition) , _direction(shiftDirection) , _shift(shift) From 6463890b1102ad19ca582262cb2e33afbaeefbe5 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 23 Feb 2021 06:34:01 +0400 Subject: [PATCH 07/17] Workaround snap's activation restriction --- .../linux_notification_service_watcher.cpp | 15 +- .../linux/notifications_manager_linux.cpp | 157 +++++++++++------- 2 files changed, 104 insertions(+), 68 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.cpp b/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.cpp index 8c5223b56..f0dc477bd 100644 --- a/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.cpp @@ -20,21 +20,21 @@ namespace Platform { namespace internal { namespace { -constexpr auto kNotificationService = "org.freedesktop.Notifications"_cs; +constexpr auto kService = "org.freedesktop.Notifications"_cs; -bool IsNotificationServiceActivatable() { - static const auto Result = [] { +auto Activatable() { + static const auto Result = []() -> std::optional { try { const auto connection = Gio::DBus::Connection::get_sync( Gio::DBus::BusType::BUS_TYPE_SESSION); return ranges::contains( base::Platform::DBus::ListActivatableNames(connection), - Glib::ustring(std::string(kNotificationService))); + Glib::ustring(std::string(kService))); } catch (...) { } - return false; + return std::nullopt; }(); return Result; @@ -56,14 +56,13 @@ NotificationServiceWatcher::NotificationServiceWatcher() _private->signalId = base::Platform::DBus::RegisterServiceWatcher( _private->dbusConnection, - std::string(kNotificationService), + std::string(kService), []( const Glib::ustring &service, const Glib::ustring &oldOwner, const Glib::ustring &newOwner) { if (!Core::App().domain().started() - || (IsNotificationServiceActivatable() - && newOwner.empty())) { + || (Activatable().value_or(true) && newOwner.empty())) { return; } diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index afec532fe..cf5a07099 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -46,6 +46,40 @@ bool InhibitionSupported = false; std::optional CurrentServerInformation; QStringList CurrentCapabilities; +void StartServiceAsync( + Fn callback, + const Glib::RefPtr &cancellable = Glib::RefPtr()) { + try { + const auto connection = Gio::DBus::Connection::get_sync( + Gio::DBus::BusType::BUS_TYPE_SESSION); + + base::Platform::DBus::StartServiceByNameAsync( + connection, + std::string(kService), + [=](Fn result) { + try { + result(); // get the error if any + } catch (const Glib::Error &e) { + LOG(("Native Notification Error: %1").arg( + QString::fromStdString(e.what()))); + } catch (const std::exception &e) { + LOG(("Native Notification Error: %1").arg( + QString::fromStdString(e.what()))); + } + + crl::on_main([=] { callback(); }); + }, + cancellable); + + return; + } catch (const Glib::Error &e) { + LOG(("Native Notification Error: %1").arg( + QString::fromStdString(e.what()))); + } + + crl::on_main([=] { callback(); }); +} + bool GetServiceRegistered() { try { const auto connection = Gio::DBus::Connection::get_sync( @@ -125,7 +159,7 @@ void GetServerInformation( QString::fromStdString(e.what()))); } - crl::on_main([=] { callback({}); }); + crl::on_main([=] { callback(std::nullopt); }); }, std::string(kService)); @@ -244,6 +278,11 @@ bool Inhibited() { const auto connection = Gio::DBus::Connection::get_sync( Gio::DBus::BusType::BUS_TYPE_SESSION); + // a hack for snap's activation restriction + base::Platform::DBus::StartServiceByName( + connection, + std::string(kService)); + auto reply = connection->call_sync( std::string(kObjectPath), std::string(kPropertiesInterface), @@ -336,6 +375,7 @@ public: private: Glib::RefPtr _dbusConnection; + Glib::RefPtr _cancellable; base::weak_ptr _manager; Glib::ustring _title; @@ -350,13 +390,13 @@ private: uint _notificationClosedSignalId = 0; NotificationId _id; + void notificationShown( + const Glib::RefPtr &result); + void notificationClosed(uint id, uint reason); void actionInvoked(uint id, const Glib::ustring &actionName); void notificationReplied(uint id, const Glib::ustring &text); - void notificationShown( - const Glib::RefPtr &result); - void signalEmitted( const Glib::RefPtr &connection, const Glib::ustring &sender_name, @@ -376,7 +416,8 @@ NotificationData::NotificationData( const QString &msg, NotificationId id, bool hideReplyButton) -: _manager(manager) +: _cancellable(Gio::Cancellable::create()) +, _manager(manager) , _title(title.toStdString()) , _imageKey(GetImageKey(CurrentServerInformationValue().specVersion)) , _id(id) { @@ -475,6 +516,10 @@ NotificationData::NotificationData( } NotificationData::~NotificationData() { + if (_cancellable) { + _cancellable->cancel(); + } + if (_dbusConnection) { if (_actionInvokedSignalId != 0) { _dbusConnection->signal_unsubscribe(_actionInvokedSignalId); @@ -491,7 +536,8 @@ NotificationData::~NotificationData() { } void NotificationData::show() { - try { + // a hack for snap's activation restriction + StartServiceAsync([=] { const auto iconName = _imageKey.empty() || _hints.find(_imageKey) == end(_hints) ? Glib::ustring(GetIconName().toStdString()) @@ -513,16 +559,7 @@ void NotificationData::show() { }), sigc::mem_fun(this, &NotificationData::notificationShown), std::string(kService)); - } catch (const Glib::Error &e) { - LOG(("Native Notification Error: %1").arg( - QString::fromStdString(e.what()))); - - const auto manager = _manager; - const auto my = _id; - crl::on_main(manager, [=] { - manager->clearNotification(my); - }); - } + }, _cancellable); } void NotificationData::notificationShown( @@ -549,20 +586,15 @@ void NotificationData::notificationShown( } void NotificationData::close() { - try { - _dbusConnection->call( - std::string(kObjectPath), - std::string(kInterface), - "CloseNotification", - base::Platform::MakeGlibVariant(std::tuple{ - _notificationId, - }), - {}, - std::string(kService)); - } catch (const Glib::Error &e) { - LOG(("Native Notification Error: %1").arg( - QString::fromStdString(e.what()))); - } + _dbusConnection->call( + std::string(kObjectPath), + std::string(kInterface), + "CloseNotification", + base::Platform::MakeGlibVariant(std::tuple{ + _notificationId, + }), + {}, + std::string(kService)); } void NotificationData::setImage(const QString &imagePath) { @@ -710,8 +742,6 @@ bool ByDefault() { } void Create(Window::Notifications::System *system) { - ServiceRegistered = GetServiceRegistered(); - const auto managerSetter = [=] { using ManagerType = Window::Notifications::ManagerType; if ((Core::App().settings().nativeNotifications() && Supported()) @@ -726,13 +756,39 @@ void Create(Window::Notifications::System *system) { } }; - if (!ServiceRegistered) { - CurrentServerInformation = std::nullopt; - CurrentCapabilities = QStringList{}; - InhibitionSupported = false; - managerSetter(); - return; - } + const auto counter = std::make_shared(3); + const auto oneReady = [=] { + if (!--*counter) { + managerSetter(); + } + }; + + const auto serviceActivated = [=] { + ServiceRegistered = GetServiceRegistered(); + + if (!ServiceRegistered) { + CurrentServerInformation = std::nullopt; + CurrentCapabilities = QStringList{}; + InhibitionSupported = false; + managerSetter(); + return; + } + + GetServerInformation([=](const std::optional &result) { + CurrentServerInformation = result; + oneReady(); + }); + + GetCapabilities([=](const QStringList &result) { + CurrentCapabilities = result; + oneReady(); + }); + + GetInhibitionSupported([=](bool result) { + InhibitionSupported = result; + oneReady(); + }); + }; // There are some asserts that manager is not nullptr, // avoid crashes until some real manager is created @@ -741,27 +797,8 @@ void Create(Window::Notifications::System *system) { system->setManager(std::make_unique(system)); } - const auto counter = std::make_shared(3); - const auto oneReady = [=] { - if (!--*counter) { - managerSetter(); - } - }; - - GetServerInformation([=](const std::optional &result) { - CurrentServerInformation = result; - oneReady(); - }); - - GetCapabilities([=](const QStringList &result) { - CurrentCapabilities = result; - oneReady(); - }); - - GetInhibitionSupported([=](bool result) { - InhibitionSupported = result; - oneReady(); - }); + // snap doesn't allow access when the daemon is not running :( + StartServiceAsync(serviceActivated); } class Manager::Private { From 13a497cf5dda765b3616cd6fa32e3e2496215e51 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 5 Apr 2021 09:02:09 +0400 Subject: [PATCH 08/17] Update lib_base --- Telegram/lib_base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/lib_base b/Telegram/lib_base index f8c660278..2d5153421 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit f8c660278e78ecb4763af760bc28efa8c505b6dd +Subproject commit 2d51534213cf14fc816eca84f06765704a3b45d7 From 9a6e571154d82367900ed39f5df30d60f2d8e608 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 4 Apr 2021 00:51:17 +0400 Subject: [PATCH 09/17] Move XDP file dialog to glibmm mime type & regex methods --- .../platform/linux/linux_xdp_file_dialog.cpp | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp b/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp index ecbe52ed5..cc7e32b37 100644 --- a/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp @@ -16,8 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/openssl_help.h" #include "base/qt_adapters.h" -#include -#include #include #include @@ -282,7 +280,7 @@ void XDPFileDialog::openPortal() { if (_acceptMode == QFileDialog::AcceptSave) { if (!_directory.empty()) { options["current_folder"] = Glib::Variant::create( - _directory +'\0'); + _directory + '\0'); } if (!_selectedFiles.empty()) { @@ -302,8 +300,12 @@ void XDPFileDialog::openPortal() { if (!_mimeTypesFilters.empty()) { for (const auto &mimeTypeFilter : _mimeTypesFilters) { - const auto mimeType = QMimeDatabase().mimeTypeForName( - QString::fromStdString(mimeTypeFilter)); + auto mimeTypeUncertain = false; + const auto mimeType = Gio::content_type_guess( + mimeTypeFilter, + nullptr, + 0, + mimeTypeUncertain); // Creates e.g. (1, "image/png") const auto filterCondition = FilterCondition{ @@ -313,7 +315,7 @@ void XDPFileDialog::openPortal() { // Creates e.g. [("Images", [((1, "image/png"))])] filterList.push_back({ - mimeType.comment().toStdString(), + Gio::content_type_get_description(mimeType), FilterConditionList{filterCondition}, }); @@ -326,18 +328,16 @@ void XDPFileDialog::openPortal() { for (const auto &nameFilter : _nameFilters) { // Do parsing: // Supported format is ("Images (*.png *.jpg)") - const QRegularExpression regexp( - QString::fromLatin1(filterRegExp)); + const auto regexp = Glib::Regex::create(filterRegExp); - const QRegularExpressionMatch match = regexp.match( - QString::fromStdString(nameFilter)); + Glib::MatchInfo match; + regexp->match(nameFilter, match); - if (match.hasMatch()) { - const auto userVisibleName = match.captured(1).toStdString(); - const auto filterStrings = QStringListToStd( - match.captured(2).split( - QLatin1Char(' '), - base::QStringSkipEmptyParts)); + if (match.matches()) { + const auto userVisibleName = match.fetch(1); + const auto filterStrings = Glib::Regex::create(" ")->split( + match.fetch(2), + Glib::RegexMatchFlags::REGEX_MATCH_NOTEMPTY); if (filterStrings.empty()) { LOG(( From 30c86523ff678acbcb13d73e2eecdf7eb331d2ae Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 31 Mar 2021 21:54:47 +0400 Subject: [PATCH 10/17] Remove redudant indenattion level in MPRIS XML --- .../platform/linux/linux_mpris_support.cpp | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp index ab438585e..f6d936ca4 100644 --- a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp @@ -36,59 +36,59 @@ constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs; constexpr auto kSongType = AudioMsgId::Type::Song; constexpr auto kIntrospectionXML = R"INTROSPECTION( - - - - - - - - - - - - - - )INTROSPECTION"_cs; + + + + + + + + + + + + + +)INTROSPECTION"_cs; constexpr auto kPlayerIntrospectionXML = R"INTROSPECTION( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - )INTROSPECTION"_cs; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +)INTROSPECTION"_cs; auto CreateMetadata(const Media::Player::TrackState &state) { std::map result; From ae54c8af6ab65d8573b52dd789dcaaa9b03235f3 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 31 Mar 2021 21:55:14 +0400 Subject: [PATCH 11/17] Add support for setting cover with MPRIS --- .../platform/linux/linux_mpris_support.cpp | 126 +++++++++++++----- 1 file changed, 92 insertions(+), 34 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp index f6d936ca4..6925d5cee 100644 --- a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp @@ -11,13 +11,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/linux/base_linux_glibmm_helper.h" #include "media/audio/media_audio.h" #include "media/player/media_player_instance.h" +#include "data/data_file_origin.h" #include "data/data_document.h" +#include "data/data_document_media.h" #include "core/sandbox.h" #include "core/application.h" #include "core/core_settings.h" +#include "main/main_domain.h" +#include "main/main_account.h" +#include "main/main_session.h" #include "mainwindow.h" #include "app.h" +#include #include #include @@ -90,34 +96,57 @@ constexpr auto kPlayerIntrospectionXML = R"INTROSPECTION( )INTROSPECTION"_cs; -auto CreateMetadata(const Media::Player::TrackState &state) { +auto CreateMetadata( + const Media::Player::TrackState &state, + Data::DocumentMedia *trackView) { std::map result; - if (!Media::Player::IsStoppedOrStopping(state.state)) { - result["mpris:trackid"] = Glib::wrap(g_variant_new_object_path( - kFakeTrackPath.utf8().constData())); - result["mpris:length"] = Glib::Variant::create( - state.length * 1000); + if (Media::Player::IsStoppedOrStopping(state.state)) { + return result; + } - const auto audioData = state.id.audio(); - if (audioData) { - result["xesam:title"] = Glib::Variant< - Glib::ustring - >::create(audioData->filename().toStdString()); + result["mpris:trackid"] = Glib::wrap(g_variant_new_object_path( + kFakeTrackPath.utf8().constData())); + result["mpris:length"] = Glib::Variant::create( + state.length * 1000); - if (audioData->isSong()) { - const auto songData = audioData->song(); - if (!songData->performer.isEmpty()) { - result["xesam:artist"] = Glib::Variant< - std::vector - >::create({ songData->performer.toStdString() }); - } - if (!songData->performer.isEmpty()) { - result["xesam:title"] = Glib::Variant< - Glib::ustring - >::create(songData->title.toStdString()); - } + const auto audioData = state.id.audio(); + if (audioData) { + result["xesam:title"] = Glib::Variant< + Glib::ustring + >::create(audioData->filename().toStdString()); + + if (audioData->isSong()) { + const auto songData = audioData->song(); + if (!songData->performer.isEmpty()) { + result["xesam:artist"] = Glib::Variant< + std::vector + >::create({ songData->performer.toStdString() }); } + if (!songData->performer.isEmpty()) { + result["xesam:title"] = Glib::Variant< + Glib::ustring + >::create(songData->title.toStdString()); + } + } + } + + if (trackView) { + trackView->thumbnailWanted(Data::FileOrigin()); + if (trackView->thumbnail()) { + QByteArray thumbnailData; + QBuffer thumbnailBuffer(&thumbnailData); + trackView->thumbnail()->original().save( + &thumbnailBuffer, + "JPG", + 87); + + result["mpris:artUrl"] = Glib::Variant< + Glib::ustring + >::create("data:image/jpeg;base64," + + thumbnailData + .toBase64() + .toStdString()); } } @@ -237,8 +266,16 @@ void HandleGetProperty( const auto state = Media::Player::instance()->getState( kSongType); + const auto trackView = [&]() -> std::shared_ptr { + const auto audioData = state.id.audio(); + if (audioData && audioData->isSongWithCover()) { + return audioData->activeMediaView(); + } + return nullptr; + }(); + property = base::Platform::MakeGlibVariant( - CreateMetadata(state)); + CreateMetadata(state, trackView.get())); } else if (property_name == "MinimumRate") { property = Glib::Variant::create(1.0); } else if (property_name == "PlaybackStatus") { @@ -346,10 +383,13 @@ public: uint registerId = 0; uint playerRegisterId = 0; - std::map metadata; Glib::ustring playbackStatus; gint64 position = 0; + DocumentData *audioData = nullptr; + std::shared_ptr trackView; + Image *thumbnail = nullptr; + rpl::lifetime lifetime; }; @@ -359,22 +399,34 @@ void MPRISSupport::Private::updateTrackState( return; } - const auto currentMetadata = CreateMetadata(state); + const auto currentAudioData = state.id.audio(); const auto currentPosition = state.position * 1000; const auto currentPlaybackStatus = PlaybackStatus(state.state); - if (!ranges::equal(currentMetadata, metadata, [&]( - const auto &item1, - const auto &item2) { - return item1.first == item2.first - && item1.second.equal(item2.second); - })) { - metadata = currentMetadata; + if (currentAudioData != audioData) { + audioData = currentAudioData; + if (audioData && audioData->isSongWithCover()) { + trackView = audioData->createMediaView(); + thumbnail = trackView->thumbnail(); + } else { + trackView = nullptr; + thumbnail = nullptr; + } + PlayerPropertyChanged( "Metadata", Glib::Variant< std::map - >::create(metadata)); + >::create(CreateMetadata(state, trackView.get()))); + } + + if (trackView && (trackView->thumbnail() != thumbnail)) { + thumbnail = trackView->thumbnail(); + PlayerPropertyChanged( + "Metadata", + Glib::Variant< + std::map + >::create(CreateMetadata(state, trackView.get()))); } if (currentPlaybackStatus != playbackStatus) { @@ -423,6 +475,12 @@ MPRISSupport::MPRISSupport() _private->updateTrackState( Media::Player::instance()->getState(kSongType)); + Core::App().domain().active().session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { + _private->updateTrackState( + Media::Player::instance()->getState(kSongType)); + }, _private->lifetime); + Media::Player::instance()->updatedNotifier( ) | rpl::start_with_next([=]( const Media::Player::TrackState &state) { From 591488c497baf6d79077ddc47376f2f141a865c5 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 3 Apr 2021 01:50:07 +0400 Subject: [PATCH 12/17] Close players instead of quitting the app --- .../SourceFiles/platform/linux/linux_mpris_support.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp index 6925d5cee..f3319b234 100644 --- a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp @@ -21,7 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_account.h" #include "main/main_session.h" #include "mainwindow.h" -#include "app.h" +#include "mainwidget.h" #include #include @@ -174,9 +174,13 @@ void HandleMethodCall( auto parametersCopy = parameters; if (method_name == "Quit") { - App::quit(); + if (const auto main = App::main()) { + main->closeBothPlayers(); + } } else if (method_name == "Raise") { - App::wnd()->showFromTray(); + if (const auto window = App::wnd()) { + window->showFromTray(); + } } else if (method_name == "Next") { Media::Player::instance()->next(); } else if (method_name == "Pause") { From 7ab3be36311bdf30330726c01d24ef4778e5aeee Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 3 Apr 2021 01:57:43 +0400 Subject: [PATCH 13/17] Handle any audio type with MPRIS --- .../platform/linux/linux_mpris_support.cpp | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp index f3319b234..9cd382425 100644 --- a/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_mpris_support.cpp @@ -39,7 +39,6 @@ constexpr auto kFakeTrackPath = "/org/telegram/desktop/track/0"_cs; constexpr auto kInterface = "org.mpris.MediaPlayer2"_cs; constexpr auto kPlayerInterface = "org.mpris.MediaPlayer2.Player"_cs; constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs; -constexpr auto kSongType = AudioMsgId::Type::Song; constexpr auto kIntrospectionXML = R"INTROSPECTION( @@ -109,12 +108,16 @@ auto CreateMetadata( kFakeTrackPath.utf8().constData())); result["mpris:length"] = Glib::Variant::create( state.length * 1000); + result["xesam:title"] = Glib::Variant::create( + "Unknown Track"); const auto audioData = state.id.audio(); if (audioData) { - result["xesam:title"] = Glib::Variant< - Glib::ustring - >::create(audioData->filename().toStdString()); + if (!audioData->filename().isEmpty()) { + result["xesam:title"] = Glib::Variant< + Glib::ustring + >::create(audioData->filename().toStdString()); + } if (audioData->isSong()) { const auto songData = audioData->song(); @@ -123,7 +126,7 @@ auto CreateMetadata( std::vector >::create({ songData->performer.toStdString() }); } - if (!songData->performer.isEmpty()) { + if (!songData->title.isEmpty()) { result["xesam:title"] = Glib::Variant< Glib::ustring >::create(songData->title.toStdString()); @@ -196,10 +199,10 @@ void HandleMethodCall( parametersCopy.get_child(0)); const auto state = Media::Player::instance()->getState( - kSongType); + Media::Player::instance()->getActiveType()); Media::Player::instance()->finishSeeking( - kSongType, + Media::Player::instance()->getActiveType(), float64(state.position * 1000 + offset) / (state.length * 1000)); } else if (method_name == "SetPosition") { @@ -207,10 +210,10 @@ void HandleMethodCall( parametersCopy.get_child(1)); const auto state = Media::Player::instance()->getState( - kSongType); + Media::Player::instance()->getActiveType()); Media::Player::instance()->finishSeeking( - kSongType, + Media::Player::instance()->getActiveType(), float64(position) / (state.length * 1000)); } else if (method_name == "Stop") { Media::Player::instance()->stop(); @@ -268,7 +271,7 @@ void HandleGetProperty( property = Glib::Variant::create(1.0); } else if (property_name == "Metadata") { const auto state = Media::Player::instance()->getState( - kSongType); + Media::Player::instance()->getActiveType()); const auto trackView = [&]() -> std::shared_ptr { const auto audioData = state.id.audio(); @@ -284,13 +287,13 @@ void HandleGetProperty( property = Glib::Variant::create(1.0); } else if (property_name == "PlaybackStatus") { const auto state = Media::Player::instance()->getState( - kSongType); + Media::Player::instance()->getActiveType()); property = Glib::Variant::create( PlaybackStatus(state.state)); } else if (property_name == "Position") { const auto state = Media::Player::instance()->getState( - kSongType); + Media::Player::instance()->getActiveType()); property = Glib::Variant::create(state.position * 1000); } else if (property_name == "Rate") { @@ -399,10 +402,6 @@ public: void MPRISSupport::Private::updateTrackState( const Media::Player::TrackState &state) { - if (state.id.type() != kSongType) { - return; - } - const auto currentAudioData = state.id.audio(); const auto currentPosition = state.position * 1000; const auto currentPlaybackStatus = PlaybackStatus(state.state); @@ -477,16 +476,20 @@ MPRISSupport::MPRISSupport() InterfaceVTable); _private->updateTrackState( - Media::Player::instance()->getState(kSongType)); + Media::Player::instance()->getState( + Media::Player::instance()->getActiveType())); Core::App().domain().active().session().downloaderTaskFinished( ) | rpl::start_with_next([=] { _private->updateTrackState( - Media::Player::instance()->getState(kSongType)); + Media::Player::instance()->getState( + Media::Player::instance()->getActiveType())); }, _private->lifetime); Media::Player::instance()->updatedNotifier( - ) | rpl::start_with_next([=]( + ) | rpl::filter([=](const Media::Player::TrackState &state) { + return state.id.type() == Media::Player::instance()->getActiveType(); + }) | rpl::start_with_next([=]( const Media::Player::TrackState &state) { _private->updateTrackState(state); }, _private->lifetime); From cffb615a4d8c9f11ae05acbf295c17c6a8a2bd07 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 5 Apr 2021 10:17:36 +0400 Subject: [PATCH 14/17] Fix build --- Telegram/SourceFiles/settings/settings_notifications.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index 0b686e405..cca41e9c0 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "platform/platform_notifications_manager.h" #include "base/platform/base_platform_info.h" +#include "mainwindow.h" #include "core/application.h" #include "main/main_session.h" #include "main/main_account.h" From 0e126e2550929045ad0c3a067184808a42337e00 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 5 Apr 2021 10:19:33 +0400 Subject: [PATCH 15/17] More advanced logging about... logging --- Telegram/SourceFiles/logs.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/logs.cpp b/Telegram/SourceFiles/logs.cpp index b8b7ee033..9941ab5ff 100644 --- a/Telegram/SourceFiles/logs.cpp +++ b/Telegram/SourceFiles/logs.cpp @@ -132,11 +132,11 @@ private: auto to = std::make_unique(_logsFilePath(type, postfix)); if (to->exists() && !to->remove()) { - LOG(("Could not delete '%1' file to start new logging!").arg(to->fileName())); + LOG(("Could not delete '%1' file to start new logging: %2").arg(to->fileName(), to->errorString())); return false; } if (!QFile(files[type]->fileName()).copy(to->fileName())) { // don't close files[type] yet - LOG(("Could not copy '%1' to '%2' to start new logging!").arg(files[type]->fileName(), to->fileName())); + LOG(("Could not copy '%1' to '%2' to start new logging: %3").arg(files[type]->fileName(), to->fileName(), to->errorString())); return false; } if (to->open(mode | QIODevice::Append)) { @@ -158,7 +158,7 @@ private: return true; } - LOG(("Could not open '%1' file to start new logging!").arg(to->fileName())); + LOG(("Could not open '%1' file to start new logging: %2").arg(to->fileName(), to->errorString())); return false; } else { bool found = false; @@ -209,7 +209,7 @@ NEW LOGGING INSTANCE STARTED!!!\n\ return true; } else if (type != LogDataMain) { - LOG(("Could not open debug log '%1'!").arg(files[type]->fileName())); + LOG(("Could not open debug log '%1': %2").arg(files[type]->fileName(), files[type]->errorString())); } return false; } From 75a782cced2f1cf95acf4126b53a5a539fe4ddc7 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 2 Apr 2021 15:32:08 +0400 Subject: [PATCH 16/17] Workaround force setting of WM_TRANSIENT_HINT in Qt's xcb backend --- Telegram/SourceFiles/media/view/media_view_pip.cpp | 12 +++++++++++- Telegram/SourceFiles/media/view/media_view_pip.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/media/view/media_view_pip.cpp b/Telegram/SourceFiles/media/view/media_view_pip.cpp index 7bdbfcad6..f224f8045 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip.cpp @@ -387,7 +387,17 @@ PipPanel::PipPanel( Ui::Platform::InitOnTopPanel(this); setMouseTracking(true); resize(0, 0); - show(); + hide(); + createWinId(); +} + +void PipPanel::setVisibleHook(bool visible) { + PipParent::setVisibleHook(visible); + + // workaround Qt's forced transient parent + if (visible) { + Ui::Platform::ClearTransientParent(this); + } } void PipPanel::setAspectRatio(QSize ratio) { diff --git a/Telegram/SourceFiles/media/view/media_view_pip.h b/Telegram/SourceFiles/media/view/media_view_pip.h index 544d6f9ed..a4a5f80e5 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.h +++ b/Telegram/SourceFiles/media/view/media_view_pip.h @@ -78,6 +78,8 @@ protected: void mouseReleaseEvent(QMouseEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; + void setVisibleHook(bool visible) override; + private: void setPositionDefault(); void setPositionOnScreen(Position position, QRect available); From df73bda1ff07966fae8341de66ddb975ec3df8e5 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 5 Apr 2021 11:18:08 +0400 Subject: [PATCH 17/17] Update lib_ui --- Telegram/lib_ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 91e1979da..99089134e 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 91e1979da5394525c8373cfbd19f5593a2f483d7 +Subproject commit 99089134e34c19e4c6fdb25569ade0d6f081bdb1