diff --git a/.gitmodules b/.gitmodules index b685a8775a..af8be44b63 100644 --- a/.gitmodules +++ b/.gitmodules @@ -52,9 +52,6 @@ [submodule "Telegram/lib_qr"] path = Telegram/lib_qr url = https://github.com/desktop-app/lib_qr.git -[submodule "Telegram/ThirdParty/libdbusmenu-qt"] - path = Telegram/ThirdParty/libdbusmenu-qt - url = https://github.com/desktop-app/libdbusmenu-qt.git [submodule "Telegram/ThirdParty/hunspell"] path = Telegram/ThirdParty/hunspell url = https://github.com/hunspell/hunspell diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index fb32be384d..136af3c7c6 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1334,7 +1334,6 @@ else() if (NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION) target_link_libraries(Telegram PRIVATE - desktop-app::external_dbusmenu_qt desktop-app::external_glibmm desktop-app::external_glib ) diff --git a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp index cc747a15a2..7574bc7335 100644 --- a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include -#include using namespace KWayland::Client; @@ -26,7 +25,6 @@ struct WaylandIntegration::Private { Registry registry; std::unique_ptr xdgExporter; std::unique_ptr plasmaShell; - std::unique_ptr appMenuManager; }; WaylandIntegration::WaylandIntegration() @@ -73,21 +71,6 @@ WaylandIntegration::WaylandIntegration() _private->plasmaShell.get(), &PlasmaShell::destroy); }); - - QObject::connect( - &_private->registry, - &Registry::appMenuAnnounced, - [=](uint name, uint version) { - _private->appMenuManager = std::unique_ptr{ - _private->registry.createAppMenuManager(name, version), - }; - - QObject::connect( - _private->connection.get(), - &ConnectionThread::connectionDied, - _private->appMenuManager.get(), - &AppMenuManager::destroy); - }); } WaylandIntegration::~WaylandIntegration() = default; @@ -141,27 +124,5 @@ void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) { plasmaSurface->setSkipTaskbar(skip); } -void WaylandIntegration::registerAppMenu( - QWindow *window, - const QString &serviceName, - const QString &objectPath) { - const auto manager = _private->appMenuManager.get(); - if (!manager) { - return; - } - - const auto surface = Surface::fromWindow(window); - if (!surface) { - return; - } - - const auto appMenu = manager->create(surface, surface); - if (!appMenu) { - return; - } - - appMenu->setAddress(serviceName, objectPath); -} - } // namespace internal } // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h index e6fa915cae..342c7c3d6d 100644 --- a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h +++ b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h @@ -17,10 +17,6 @@ public: [[nodiscard]] QString nativeHandle(QWindow *window); [[nodiscard]] bool skipTaskbarSupported(); void skipTaskbar(QWindow *window, bool skip); - void registerAppMenu( - QWindow *window, - const QString &serviceName, - const QString &objectPath); private: WaylandIntegration(); diff --git a/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp b/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp index ffd6bace35..aecb73eded 100644 --- a/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp @@ -37,11 +37,5 @@ bool WaylandIntegration::skipTaskbarSupported() { void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) { } -void WaylandIntegration::registerAppMenu( - QWindow *window, - const QString &serviceName, - const QString &objectPath) { -} - } // namespace internal } // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 3d465403ad..efaf0a792b 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -44,14 +44,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include +#include + +#include +#include #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION -#include -#include -#include - -#include - #include #include #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION @@ -66,14 +64,6 @@ constexpr auto kPanelTrayIconName = "telegram-panel"_cs; constexpr auto kMutePanelTrayIconName = "telegram-mute-panel"_cs; constexpr auto kAttentionPanelTrayIconName = "telegram-attention-panel"_cs; -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION -constexpr auto kAppMenuService = "com.canonical.AppMenu.Registrar"_cs; -constexpr auto kAppMenuObjectPath = "/com/canonical/AppMenu/Registrar"_cs; -constexpr auto kAppMenuInterface = kAppMenuService; - -constexpr auto kMainMenuObjectPath = "/MenuBar"_cs; -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION - bool TrayIconMuted = true; int32 TrayIconCount = 0; base::flat_map TrayIconImageBack; @@ -377,6 +367,11 @@ void ForceDisabled(QAction *action, bool disabled) { if (disabled) action->setDisabled(true); } else if (!disabled) { action->setDisabled(false); + + const auto privateAction = QActionPrivate::get(action); + privateAction->setShortcutEnabled( + false, + QGuiApplicationPrivate::instance()->shortcutMap); } } @@ -406,65 +401,6 @@ uint djbStringHash(const std::string &string) { } return hash; } - -bool IsAppMenuSupported() { - try { - const auto connection = Gio::DBus::Connection::get_sync( - Gio::DBus::BusType::BUS_TYPE_SESSION); - - return base::Platform::DBus::NameHasOwner( - connection, - std::string(kAppMenuService)); - } catch (...) { - } - - return false; -} - -// This call must be made from the same bus connection as DBusMenuExporter -// So it must use QDBusConnection -void RegisterAppMenu(QWindow *window, const QString &menuPath) { - if (const auto integration = WaylandIntegration::Instance()) { - integration->registerAppMenu( - window, - QDBusConnection::sessionBus().baseService(), - menuPath); - return; - } - - auto message = QDBusMessage::createMethodCall( - kAppMenuService.utf16(), - kAppMenuObjectPath.utf16(), - kAppMenuInterface.utf16(), - qsl("RegisterWindow")); - - message.setArguments({ - uint(window->winId()), - QVariant::fromValue(QDBusObjectPath(menuPath)) - }); - - QDBusConnection::sessionBus().send(message); -} - -// This call must be made from the same bus connection as DBusMenuExporter -// So it must use QDBusConnection -void UnregisterAppMenu(QWindow *window) { - if (const auto integration = WaylandIntegration::Instance()) { - return; - } - - auto message = QDBusMessage::createMethodCall( - kAppMenuService.utf16(), - kAppMenuObjectPath.utf16(), - kAppMenuInterface.utf16(), - qsl("UnregisterWindow")); - - message.setArguments({ - uint(window->winId()) - }); - - QDBusConnection::sessionBus().send(message); -} #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION } // namespace @@ -480,15 +416,6 @@ public: #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION Glib::RefPtr dbusConnection; - - bool appMenuSupported = false; - uint appMenuWatcherId = 0; - DBusMenuExporter *mainMenuExporter = nullptr; - - void handleAppMenuOwnerChanged( - const QString &service, - const QString &oldOwner, - const QString &newOwner); #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION protected: @@ -512,27 +439,6 @@ bool MainWindow::Private::eventFilter(QObject *obj, QEvent *e) { return QObject::eventFilter(obj, e); } -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION -void MainWindow::Private::handleAppMenuOwnerChanged( - const QString &service, - const QString &oldOwner, - const QString &newOwner) { - if (oldOwner.isEmpty() && !newOwner.isEmpty()) { - appMenuSupported = true; - LOG(("Using D-Bus global menu.")); - } else if (!oldOwner.isEmpty() && newOwner.isEmpty()) { - appMenuSupported = false; - LOG(("Not using D-Bus global menu.")); - } - - if (appMenuSupported && mainMenuExporter) { - RegisterAppMenu(_public->windowHandle(), kMainMenuObjectPath.utf16()); - } else { - UnregisterAppMenu(_public->windowHandle()); - } -} -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION - MainWindow::MainWindow(not_null controller) : Window::MainWindow(controller) , _private(std::make_unique(this)) { @@ -561,33 +467,12 @@ void MainWindow::initHook() { }); #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION - _private->appMenuSupported = IsAppMenuSupported(); - try { _private->dbusConnection = Gio::DBus::Connection::get_sync( Gio::DBus::BusType::BUS_TYPE_SESSION); - - _private->appMenuWatcherId = base::Platform::DBus::RegisterServiceWatcher( - _private->dbusConnection, - std::string(kAppMenuService), - [=]( - const Glib::ustring &service, - const Glib::ustring &oldOwner, - const Glib::ustring &newOwner) { - _private->handleAppMenuOwnerChanged( - QString::fromStdString(service), - QString::fromStdString(oldOwner), - QString::fromStdString(newOwner)); - }); } catch (...) { } - if (_private->appMenuSupported) { - LOG(("Using D-Bus global menu.")); - } else { - LOG(("Not using D-Bus global menu.")); - } - if (UseUnityCounter()) { LOG(("Using Unity launcher counter.")); } else { @@ -715,7 +600,8 @@ void MainWindow::createGlobalMenu() { } }; - psMainMenu = new QMenu(this); + psMainMenu = new QMenuBar(this); + psMainMenu->hide(); auto file = psMainMenu->addMenu(tr::lng_mac_menu_file(tr::now)); @@ -897,15 +783,16 @@ void MainWindow::createGlobalMenu() { about->setMenuRole(QAction::AboutQtRole); -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION - _private->mainMenuExporter = new DBusMenuExporter( - kMainMenuObjectPath.utf16(), - psMainMenu); - - if (_private->appMenuSupported) { - RegisterAppMenu(windowHandle(), kMainMenuObjectPath.utf16()); + // avoid shadowing actual shortcuts by the menubar + for (const auto &child : psMainMenu->children()) { + const auto action = qobject_cast(child); + if (action) { + const auto privateAction = QActionPrivate::get(action); + privateAction->setShortcutEnabled( + false, + QGuiApplicationPrivate::instance()->shortcutMap); + } } -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION updateGlobalMenu(); } @@ -980,31 +867,9 @@ void MainWindow::handleNativeSurfaceChanged(bool exist) { (Core::App().settings().workMode() == WorkMode::TrayOnly) && TrayIconSupported()); } - -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION - if (_private->appMenuSupported && _private->mainMenuExporter) { - if (exist) { - RegisterAppMenu(windowHandle(), kMainMenuObjectPath.utf16()); - } else { - UnregisterAppMenu(windowHandle()); - } - } -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION } MainWindow::~MainWindow() { -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION - if (_private->dbusConnection) { - if (_private->appMenuWatcherId != 0) { - _private->dbusConnection->signal_unsubscribe( - _private->appMenuWatcherId); - } - } - - if (_private->appMenuSupported) { - UnregisterAppMenu(windowHandle()); - } -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION } } // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.h b/Telegram/SourceFiles/platform/linux/main_window_linux.h index 11f19b2cb1..561804e5f7 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.h +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.h @@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_main_window.h" +class QMenuBar; + namespace Platform { class MainWindow : public Window::MainWindow { @@ -43,7 +45,7 @@ private: friend class Private; const std::unique_ptr _private; - QMenu *psMainMenu = nullptr; + QMenuBar *psMainMenu = nullptr; QAction *psLogout = nullptr; QAction *psUndo = nullptr; QAction *psRedo = nullptr; diff --git a/Telegram/ThirdParty/libdbusmenu-qt b/Telegram/ThirdParty/libdbusmenu-qt deleted file mode 160000 index af9fa001da..0000000000 --- a/Telegram/ThirdParty/libdbusmenu-qt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit af9fa001dac49eedc76e15613b67abfd097105f3