diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index 5e22d9204..7d1ec6b79 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -218,6 +218,8 @@ void AutoType::performAutoTypeFromGlobal(Entry* entry, const QString& sequence) { Q_ASSERT(m_inAutoType); + m_plugin->raiseWindow(m_windowFromGlobal); + m_inAutoType = false; performAutoType(entry, nullptr, sequence, m_windowFromGlobal); } diff --git a/src/autotype/AutoTypePlatformPlugin.h b/src/autotype/AutoTypePlatformPlugin.h index 1e78f0d28..614c8060b 100644 --- a/src/autotype/AutoTypePlatformPlugin.h +++ b/src/autotype/AutoTypePlatformPlugin.h @@ -33,6 +33,7 @@ public: virtual void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers) = 0; virtual int platformEventFilter(void* event) = 0; virtual int initialTimeout() = 0; + virtual bool raiseWindow(WId window) = 0; virtual void unload() {} virtual AutoTypeExecutor* createExecutor() = 0; diff --git a/src/autotype/test/AutoTypeTest.cpp b/src/autotype/test/AutoTypeTest.cpp index 04f39d6f7..19f0f357e 100644 --- a/src/autotype/test/AutoTypeTest.cpp +++ b/src/autotype/test/AutoTypeTest.cpp @@ -103,6 +103,13 @@ int AutoTypePlatformTest::initialTimeout() return 0; } +bool AutoTypePlatformTest::raiseWindow(WId window) +{ + Q_UNUSED(window); + + return false; +} + AutoTypeExecturorTest::AutoTypeExecturorTest(AutoTypePlatformTest* platform) : m_platform(platform) { diff --git a/src/autotype/test/AutoTypeTest.h b/src/autotype/test/AutoTypeTest.h index 2d652ced4..be57af050 100644 --- a/src/autotype/test/AutoTypeTest.h +++ b/src/autotype/test/AutoTypeTest.h @@ -42,6 +42,7 @@ public: void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers); int platformEventFilter(void* event); int initialTimeout(); + bool raiseWindow(WId window); AutoTypeExecutor* createExecutor(); void setActiveWindowTitle(const QString& title); diff --git a/src/autotype/xcb/AutoTypeXCB.cpp b/src/autotype/xcb/AutoTypeXCB.cpp index bac9e8ca1..1a6d27d63 100644 --- a/src/autotype/xcb/AutoTypeXCB.cpp +++ b/src/autotype/xcb/AutoTypeXCB.cpp @@ -36,6 +36,7 @@ AutoTypePlatformX11::AutoTypePlatformX11() m_atomNetWmName = XInternAtom(m_dpy, "_NET_WM_NAME", true); m_atomString = XInternAtom(m_dpy, "STRING", true); m_atomUtf8String = XInternAtom(m_dpy, "UTF8_STRING", true); + m_atomNetActiveWindow = XInternAtom(m_dpy, "_NET_ACTIVE_WINDOW", true); m_classBlacklist << "desktop_window" << "gnome-panel"; // Gnome m_classBlacklist << "kdesktop" << "kicker"; // KDE 3 @@ -790,3 +791,37 @@ int AutoTypePlatformX11::initialTimeout() { return 500; } + +bool AutoTypePlatformX11::raiseWindow(WId window) +{ + if (m_atomNetActiveWindow == None) { + return false; + } + + XRaiseWindow(m_dpy, window); + + XEvent event; + event.xclient.type = ClientMessage; + event.xclient.serial = 0; + event.xclient.send_event = True; + event.xclient.window = window; + event.xclient.message_type = m_atomNetActiveWindow; + event.xclient.format = 32; + event.xclient.data.l[0] = 1; // FromApplication + event.xclient.data.l[1] = QX11Info::appUserTime(); + QWidget* activeWindow = QApplication::activeWindow(); + if (activeWindow) { + event.xclient.data.l[2] = activeWindow->internalWinId(); + } + else { + event.xclient.data.l[2] = 0; + } + event.xclient.data.l[3] = 0; + event.xclient.data.l[4] = 0; + XSendEvent(m_dpy, m_rootWindow, False, + SubstructureRedirectMask | SubstructureNotifyMask, + &event); + XFlush(m_dpy); + + return true; +} diff --git a/src/autotype/xcb/AutoTypeXCB.h b/src/autotype/xcb/AutoTypeXCB.h index 46af6ed9b..a924b9586 100644 --- a/src/autotype/xcb/AutoTypeXCB.h +++ b/src/autotype/xcb/AutoTypeXCB.h @@ -50,6 +50,7 @@ public: void unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers); int platformEventFilter(void* event); int initialTimeout(); + bool raiseWindow(WId window); AutoTypeExecutor* createExecutor(); KeySym charToKeySym(const QChar& ch); @@ -89,6 +90,7 @@ private: Atom m_atomNetWmName; Atom m_atomString; Atom m_atomUtf8String; + Atom m_atomNetActiveWindow; QSet m_classBlacklist; Qt::Key m_currentGlobalKey; Qt::KeyboardModifiers m_currentGlobalModifiers; diff --git a/src/gui/Clipboard.cpp b/src/gui/Clipboard.cpp index 52dd6c16a..bf4db8ff5 100644 --- a/src/gui/Clipboard.cpp +++ b/src/gui/Clipboard.cpp @@ -31,7 +31,7 @@ Clipboard::Clipboard(QObject* parent) { m_timer->setSingleShot(true); connect(m_timer, SIGNAL(timeout()), SLOT(clearClipboard())); - connect(qApp, SIGNAL(aboutToQuit()), SLOT(cleanup())); + connect(qApp, SIGNAL(aboutToQuit()), SLOT(clearCopiedText())); } void Clipboard::setText(const QString& text) @@ -52,6 +52,14 @@ void Clipboard::setText(const QString& text) } } +void Clipboard::clearCopiedText() +{ + if (m_timer->isActive()) { + m_timer->stop(); + clearClipboard(); + } +} + void Clipboard::clearClipboard() { QClipboard* clipboard = QApplication::clipboard(); @@ -73,14 +81,6 @@ void Clipboard::clearClipboard() m_lastCopied.clear(); } -void Clipboard::cleanup() -{ - if (m_timer->isActive()) { - m_timer->stop(); - clearClipboard(); - } -} - Clipboard* Clipboard::instance() { if (!m_instance) { diff --git a/src/gui/Clipboard.h b/src/gui/Clipboard.h index 9c0b6eae7..dafce70a2 100644 --- a/src/gui/Clipboard.h +++ b/src/gui/Clipboard.h @@ -31,9 +31,11 @@ public: static Clipboard* instance(); +public Q_SLOTS: + void clearCopiedText(); + private Q_SLOTS: void clearClipboard(); - void cleanup(); private: explicit Clipboard(QObject* parent = nullptr); diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 88299dc58..b9ccccd86 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -28,6 +28,7 @@ #include "core/Group.h" #include "core/Metadata.h" #include "format/CsvExporter.h" +#include "gui/Clipboard.h" #include "gui/DatabaseWidget.h" #include "gui/DatabaseWidgetStateSync.h" #include "gui/DragTabBar.h" @@ -633,6 +634,8 @@ bool DatabaseTabWidget::hasLockableDatabases() const void DatabaseTabWidget::lockDatabases() { + clipboard()->clearCopiedText(); + for (int i = 0; i < count(); i++) { DatabaseWidget* dbWidget = static_cast(widget(i)); Database* db = databaseFromDatabaseWidget(dbWidget); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index b91da0c6c..b6dc6a4e4 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -92,9 +92,7 @@ MainWindow::MainWindow() m_ui->actionEntryOpenUrl->setShortcut(Qt::CTRL + Qt::Key_U); m_ui->actionEntryCopyURL->setShortcut(Qt::CTRL + Qt::ALT + Qt::Key_U); -#ifdef Q_OS_MAC new QShortcut(Qt::CTRL + Qt::Key_M, this, SLOT(showMinimized())); -#endif m_ui->actionDatabaseNew->setIcon(filePath()->icon("actions", "document-new")); m_ui->actionDatabaseOpen->setIcon(filePath()->icon("actions", "document-open"));