diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b5df29b1..ac0155fc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,9 @@ find_package(Qt5Widgets 5.2 REQUIRED) find_package(Qt5Test 5.2 REQUIRED) find_package(Qt5LinguistTools 5.2 REQUIRED) find_package(Qt5Network 5.2 REQUIRED) +if (UNIX AND NOT APPLE) + find_package(Qt5DBus 5.2 REQUIRED) +endif() set(CMAKE_AUTOMOC ON) # Debian sets the the build type to None for package builds. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c3948842..5c37c2372 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -197,7 +197,11 @@ target_link_libraries(zxcvbn) if(WITH_XC_HTTP) add_library(keepasshttp STATIC ${keepasshttp_SOURCES}) - target_link_libraries(keepasshttp ${MHD_LIBRARIES} Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network) + target_link_libraries(keepasshttp ${MHD_LIBRARIES} + Qt5::Core + Qt5::Concurrent + Qt5::Widgets + Qt5::Network) endif() add_library(autotype STATIC ${autotype_SOURCES}) @@ -207,7 +211,14 @@ set(autotype_LIB autotype) add_library(keepassx_core STATIC ${keepassx_SOURCES}) set_target_properties(keepassx_core PROPERTIES COMPILE_DEFINITIONS KEEPASSX_BUILDING_CORE) -target_link_libraries(keepassx_core zxcvbn ${keepasshttp_LIB} ${autotype_LIB} Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network) +target_link_libraries(keepassx_core zxcvbn ${keepasshttp_LIB} ${autotype_LIB} + Qt5::Core + Qt5::Concurrent + Qt5::Widgets + Qt5::Network) +if (UNIX AND NOT APPLE) + target_link_libraries(keepassx_core Qt5::DBus) +endif() add_executable(${PROGNAME} WIN32 MACOSX_BUNDLE ${keepassx_SOURCES_MAINEXE}) target_link_libraries(${PROGNAME} @@ -221,6 +232,7 @@ target_link_libraries(${PROGNAME} ${GPGERROR_LIBRARIES} ${ZLIB_LIBRARIES}) + set_target_properties(${PROGNAME} PROPERTIES ENABLE_EXPORTS ON) if(APPLE) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 2ab42bb61..9e264bd93 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -22,6 +22,11 @@ #include #include +#if defined(Q_OS_LINUX) && ! defined(QT_NO_DBUS) +#include +#include +#endif + #include "config-keepassx.h" #include "autotype/AutoType.h" @@ -735,6 +740,24 @@ void MainWindow::toggleWindow() setWindowState(windowState() & ~Qt::WindowMinimized); raise(); activateWindow(); + +#if defined(Q_OS_LINUX) && ! defined(QT_NO_DBUS) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) + // re-register global D-Bus menu (needed on Ubuntu with Unity) + // see https://github.com/keepassxreboot/keepassxc/issues/271 + // and https://bugreports.qt.io/browse/QTBUG-58723 + if (m_ui->menubar->isNativeMenuBar()) { + QDBusMessage msg = QDBusMessage::createMethodCall( + "com.canonical.AppMenu.Registrar", + "/com/canonical/AppMenu/Registrar", + "com.canonical.AppMenu.Registrar", + "RegisterWindow"); + QList args; + args << QVariant::fromValue(static_cast(winId())) + << QVariant::fromValue(QDBusObjectPath("/MenuBar/1")); + msg.setArguments(args); + QDBusConnection::sessionBus().send(msg); + } +#endif } }