Use QMenuBar instead of own global menu implementation on Linux
This is another attempt of 79f96480c2
This commit is contained in:
parent
b65d40a22b
commit
ceb323ac7c
|
@ -52,9 +52,6 @@
|
||||||
[submodule "Telegram/lib_qr"]
|
[submodule "Telegram/lib_qr"]
|
||||||
path = Telegram/lib_qr
|
path = Telegram/lib_qr
|
||||||
url = https://github.com/desktop-app/lib_qr.git
|
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"]
|
[submodule "Telegram/ThirdParty/hunspell"]
|
||||||
path = Telegram/ThirdParty/hunspell
|
path = Telegram/ThirdParty/hunspell
|
||||||
url = https://github.com/hunspell/hunspell
|
url = https://github.com/hunspell/hunspell
|
||||||
|
|
|
@ -1334,7 +1334,6 @@ else()
|
||||||
if (NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION)
|
if (NOT DESKTOP_APP_DISABLE_DBUS_INTEGRATION)
|
||||||
target_link_libraries(Telegram
|
target_link_libraries(Telegram
|
||||||
PRIVATE
|
PRIVATE
|
||||||
desktop-app::external_dbusmenu_qt
|
|
||||||
desktop-app::external_glibmm
|
desktop-app::external_glibmm
|
||||||
desktop-app::external_glib
|
desktop-app::external_glib
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <surface.h>
|
#include <surface.h>
|
||||||
#include <xdgforeign.h>
|
#include <xdgforeign.h>
|
||||||
#include <plasmashell.h>
|
#include <plasmashell.h>
|
||||||
#include <appmenu.h>
|
|
||||||
|
|
||||||
using namespace KWayland::Client;
|
using namespace KWayland::Client;
|
||||||
|
|
||||||
|
@ -26,7 +25,6 @@ struct WaylandIntegration::Private {
|
||||||
Registry registry;
|
Registry registry;
|
||||||
std::unique_ptr<XdgExporter> xdgExporter;
|
std::unique_ptr<XdgExporter> xdgExporter;
|
||||||
std::unique_ptr<PlasmaShell> plasmaShell;
|
std::unique_ptr<PlasmaShell> plasmaShell;
|
||||||
std::unique_ptr<AppMenuManager> appMenuManager;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
WaylandIntegration::WaylandIntegration()
|
WaylandIntegration::WaylandIntegration()
|
||||||
|
@ -73,21 +71,6 @@ WaylandIntegration::WaylandIntegration()
|
||||||
_private->plasmaShell.get(),
|
_private->plasmaShell.get(),
|
||||||
&PlasmaShell::destroy);
|
&PlasmaShell::destroy);
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
&_private->registry,
|
|
||||||
&Registry::appMenuAnnounced,
|
|
||||||
[=](uint name, uint version) {
|
|
||||||
_private->appMenuManager = std::unique_ptr<AppMenuManager>{
|
|
||||||
_private->registry.createAppMenuManager(name, version),
|
|
||||||
};
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
_private->connection.get(),
|
|
||||||
&ConnectionThread::connectionDied,
|
|
||||||
_private->appMenuManager.get(),
|
|
||||||
&AppMenuManager::destroy);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WaylandIntegration::~WaylandIntegration() = default;
|
WaylandIntegration::~WaylandIntegration() = default;
|
||||||
|
@ -141,27 +124,5 @@ void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
|
||||||
plasmaSurface->setSkipTaskbar(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 internal
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -17,10 +17,6 @@ public:
|
||||||
[[nodiscard]] QString nativeHandle(QWindow *window);
|
[[nodiscard]] QString nativeHandle(QWindow *window);
|
||||||
[[nodiscard]] bool skipTaskbarSupported();
|
[[nodiscard]] bool skipTaskbarSupported();
|
||||||
void skipTaskbar(QWindow *window, bool skip);
|
void skipTaskbar(QWindow *window, bool skip);
|
||||||
void registerAppMenu(
|
|
||||||
QWindow *window,
|
|
||||||
const QString &serviceName,
|
|
||||||
const QString &objectPath);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WaylandIntegration();
|
WaylandIntegration();
|
||||||
|
|
|
@ -37,11 +37,5 @@ bool WaylandIntegration::skipTaskbarSupported() {
|
||||||
void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
|
void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaylandIntegration::registerAppMenu(
|
|
||||||
QWindow *window,
|
|
||||||
const QString &serviceName,
|
|
||||||
const QString &objectPath) {
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -44,14 +44,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtCore/QSize>
|
#include <QtCore/QSize>
|
||||||
#include <QtCore/QMimeData>
|
#include <QtCore/QMimeData>
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
|
#include <QtWidgets/QMenuBar>
|
||||||
|
|
||||||
|
#include <private/qguiapplication_p.h>
|
||||||
|
#include <private/qaction_p.h>
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
#include <QtDBus/QDBusConnection>
|
|
||||||
#include <QtDBus/QDBusMessage>
|
|
||||||
#include <QtDBus/QDBusObjectPath>
|
|
||||||
|
|
||||||
#include <dbusmenuexporter.h>
|
|
||||||
|
|
||||||
#include <glibmm.h>
|
#include <glibmm.h>
|
||||||
#include <giomm.h>
|
#include <giomm.h>
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#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 kMutePanelTrayIconName = "telegram-mute-panel"_cs;
|
||||||
constexpr auto kAttentionPanelTrayIconName = "telegram-attention-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;
|
bool TrayIconMuted = true;
|
||||||
int32 TrayIconCount = 0;
|
int32 TrayIconCount = 0;
|
||||||
base::flat_map<int, QImage> TrayIconImageBack;
|
base::flat_map<int, QImage> TrayIconImageBack;
|
||||||
|
@ -377,6 +367,11 @@ void ForceDisabled(QAction *action, bool disabled) {
|
||||||
if (disabled) action->setDisabled(true);
|
if (disabled) action->setDisabled(true);
|
||||||
} else if (!disabled) {
|
} else if (!disabled) {
|
||||||
action->setDisabled(false);
|
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;
|
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
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -480,15 +416,6 @@ public:
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
Glib::RefPtr<Gio::DBus::Connection> dbusConnection;
|
Glib::RefPtr<Gio::DBus::Connection> 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
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -512,27 +439,6 @@ bool MainWindow::Private::eventFilter(QObject *obj, QEvent *e) {
|
||||||
return QObject::eventFilter(obj, 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<Window::Controller*> controller)
|
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
||||||
: Window::MainWindow(controller)
|
: Window::MainWindow(controller)
|
||||||
, _private(std::make_unique<Private>(this)) {
|
, _private(std::make_unique<Private>(this)) {
|
||||||
|
@ -561,33 +467,12 @@ void MainWindow::initHook() {
|
||||||
});
|
});
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
_private->appMenuSupported = IsAppMenuSupported();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_private->dbusConnection = Gio::DBus::Connection::get_sync(
|
_private->dbusConnection = Gio::DBus::Connection::get_sync(
|
||||||
Gio::DBus::BusType::BUS_TYPE_SESSION);
|
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 (...) {
|
} catch (...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_private->appMenuSupported) {
|
|
||||||
LOG(("Using D-Bus global menu."));
|
|
||||||
} else {
|
|
||||||
LOG(("Not using D-Bus global menu."));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UseUnityCounter()) {
|
if (UseUnityCounter()) {
|
||||||
LOG(("Using Unity launcher counter."));
|
LOG(("Using Unity launcher counter."));
|
||||||
} else {
|
} 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));
|
auto file = psMainMenu->addMenu(tr::lng_mac_menu_file(tr::now));
|
||||||
|
|
||||||
|
@ -897,15 +783,16 @@ void MainWindow::createGlobalMenu() {
|
||||||
|
|
||||||
about->setMenuRole(QAction::AboutQtRole);
|
about->setMenuRole(QAction::AboutQtRole);
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
// avoid shadowing actual shortcuts by the menubar
|
||||||
_private->mainMenuExporter = new DBusMenuExporter(
|
for (const auto &child : psMainMenu->children()) {
|
||||||
kMainMenuObjectPath.utf16(),
|
const auto action = qobject_cast<QAction*>(child);
|
||||||
psMainMenu);
|
if (action) {
|
||||||
|
const auto privateAction = QActionPrivate::get(action);
|
||||||
if (_private->appMenuSupported) {
|
privateAction->setShortcutEnabled(
|
||||||
RegisterAppMenu(windowHandle(), kMainMenuObjectPath.utf16());
|
false,
|
||||||
|
QGuiApplicationPrivate::instance()->shortcutMap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
||||||
|
|
||||||
updateGlobalMenu();
|
updateGlobalMenu();
|
||||||
}
|
}
|
||||||
|
@ -980,31 +867,9 @@ void MainWindow::handleNativeSurfaceChanged(bool exist) {
|
||||||
(Core::App().settings().workMode() == WorkMode::TrayOnly)
|
(Core::App().settings().workMode() == WorkMode::TrayOnly)
|
||||||
&& TrayIconSupported());
|
&& 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() {
|
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
|
} // namespace Platform
|
||||||
|
|
|
@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "platform/platform_main_window.h"
|
#include "platform/platform_main_window.h"
|
||||||
|
|
||||||
|
class QMenuBar;
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
|
||||||
class MainWindow : public Window::MainWindow {
|
class MainWindow : public Window::MainWindow {
|
||||||
|
@ -43,7 +45,7 @@ private:
|
||||||
friend class Private;
|
friend class Private;
|
||||||
const std::unique_ptr<Private> _private;
|
const std::unique_ptr<Private> _private;
|
||||||
|
|
||||||
QMenu *psMainMenu = nullptr;
|
QMenuBar *psMainMenu = nullptr;
|
||||||
QAction *psLogout = nullptr;
|
QAction *psLogout = nullptr;
|
||||||
QAction *psUndo = nullptr;
|
QAction *psUndo = nullptr;
|
||||||
QAction *psRedo = nullptr;
|
QAction *psRedo = nullptr;
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit af9fa001dac49eedc76e15613b67abfd097105f3
|
|
Loading…
Reference in New Issue