Skip to content

Commit 1af1ee5

Browse files
committed
Wayland Auto-Type with XDG Desktop Portals
Needs an implementation of global shortcuts to bind the global trigger and an implementation of remote desktop to type entries.
1 parent 02784b0 commit 1af1ee5

22 files changed

Lines changed: 2172 additions & 134 deletions

share/translations/keepassxc_en.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@
282282
<source>Custom</source>
283283
<translation type="unfinished"></translation>
284284
</message>
285+
<message>
286+
<source>None</source>
287+
<translation type="unfinished"></translation>
288+
</message>
285289
</context>
286290
<context>
287291
<name>ApplicationSettingsWidgetGeneral</name>
@@ -616,6 +620,34 @@
616620
<source>Auto-generate password for new entries</source>
617621
<translation type="unfinished"></translation>
618622
</message>
623+
<message>
624+
<source>Keep remote desktop connection open after performing Auto-Type</source>
625+
<translation type="unfinished"></translation>
626+
</message>
627+
<message>
628+
<source>Remote desktop mode:</source>
629+
<translation type="unfinished"></translation>
630+
</message>
631+
<message>
632+
<source>Never remember session</source>
633+
<translation type="unfinished"></translation>
634+
</message>
635+
<message>
636+
<source>Remember session until exit</source>
637+
<translation type="unfinished"></translation>
638+
</message>
639+
<message>
640+
<source>Remember session until revoked by desktop</source>
641+
<translation type="unfinished"></translation>
642+
</message>
643+
<message>
644+
<source>None</source>
645+
<translation type="unfinished"></translation>
646+
</message>
647+
<message>
648+
<source>Configure...</source>
649+
<translation type="unfinished"></translation>
650+
</message>
619651
</context>
620652
<context>
621653
<name>ApplicationSettingsWidgetSecurity</name>
@@ -810,6 +842,29 @@
810842
<translation type="unfinished"></translation>
811843
</message>
812844
</context>
845+
<context>
846+
<name>AutoTypePlatformWayland</name>
847+
<message>
848+
<source>Session closed</source>
849+
<translation type="unfinished"></translation>
850+
</message>
851+
<message>
852+
<source>User cancelled the interaction</source>
853+
<translation type="unfinished"></translation>
854+
</message>
855+
<message>
856+
<source>User interaction was canceled for unknown reason</source>
857+
<translation type="unfinished"></translation>
858+
</message>
859+
<message>
860+
<source>No symbol found for key: &apos;%1&apos;</source>
861+
<translation type="unfinished"></translation>
862+
</message>
863+
<message>
864+
<source>No symbol found for character: &apos;%1&apos;</source>
865+
<translation type="unfinished"></translation>
866+
</message>
867+
</context>
813868
<context>
814869
<name>AutoTypePlatformX11</name>
815870
<message>
@@ -6658,6 +6713,22 @@ This version is not meant for production use.</source>
66586713
<source>Could not register global shortcut</source>
66596714
<translation type="unfinished"></translation>
66606715
</message>
6716+
<message>
6717+
<source>The XDG Desktop Portal for global shortcuts is not available on this system.</source>
6718+
<translation type="unfinished"></translation>
6719+
</message>
6720+
<message>
6721+
<source>Trigger global Auto-Type</source>
6722+
<translation type="unfinished"></translation>
6723+
</message>
6724+
<message>
6725+
<source>KeePassXC - Global Shortcuts</source>
6726+
<translation type="unfinished"></translation>
6727+
</message>
6728+
<message>
6729+
<source>Global Auto-Type shortcut is already configured. To change it, open your system settings and navigate to the keyboard or application shortcuts section.</source>
6730+
<translation type="unfinished"></translation>
6731+
</message>
66616732
</context>
66626733
<context>
66636734
<name>OpData01</name>

src/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ if(UNIX AND NOT APPLE)
257257
quickunlock/dbus/org.freedesktop.PolicyKit1.Authority.xml
258258
polkit_dbus
259259
)
260+
qt6_add_dbus_interface(core_SOURCES
261+
gui/osutils/nixutils/dbus/org.freedesktop.portal.Request.xml
262+
xdp_request
263+
)
264+
qt6_add_dbus_interface(core_SOURCES
265+
gui/osutils/nixutils/dbus/org.freedesktop.portal.Session.xml
266+
xdp_session
267+
)
268+
qt6_add_dbus_interface(core_SOURCES
269+
gui/osutils/nixutils/dbus/org.freedesktop.portal.GlobalShortcuts.xml
270+
xdp_globalshortcuts
271+
)
272+
qt6_add_dbus_interface(core_SOURCES
273+
gui/osutils/nixutils/dbus/org.freedesktop.portal.RemoteDesktop.xml
274+
xdp_remotedesktop
275+
)
260276
endif()
261277

262278
if(WIN32)

src/autotype/AutoType.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ AutoType::AutoType(QObject* parent, bool test)
155155
}
156156

157157
connect(this, SIGNAL(autotypeFinished()), SLOT(resetAutoTypeState()));
158+
connect(this, &AutoType::autotypeFinished, this, [this] {
159+
if (m_plugin) {
160+
m_plugin->finishAutoType();
161+
}
162+
});
158163
connect(qApp, SIGNAL(aboutToQuit()), SLOT(unloadPlugin()));
159164
}
160165

@@ -398,6 +403,10 @@ void AutoType::performAutoTypeWithSequence(const Entry* entry, const QString& se
398403

399404
void AutoType::startGlobalAutoType(const QString& search)
400405
{
406+
if (!m_plugin) {
407+
return;
408+
}
409+
401410
// Never Auto-Type into KeePassXC itself
402411
if (getMainWindow() && (qApp->activeWindow() || qApp->activeModalWidget())) {
403412
return;
@@ -472,9 +481,10 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
472481
qWarning() << "Auto-Type: Window title was empty from the operating system";
473482
}
474483

475-
// Show the selection dialog if we always ask, have multiple matches, or no matches
484+
// Show the selection dialog if we always ask, have multiple matches, no matches, or the window title was empty
476485
if (getMainWindow()
477-
&& (config()->get(Config::Security_AutoTypeAsk).toBool() || matchList.size() > 1 || matchList.isEmpty())) {
486+
&& (config()->get(Config::Security_AutoTypeAsk).toBool() || matchList.size() > 1 || matchList.isEmpty()
487+
|| m_windowTitleForGlobal.isEmpty())) {
478488
// Close any open modal windows that would interfere with the process
479489
getMainWindow()->closeModalWindow();
480490

@@ -486,18 +496,19 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
486496
}
487497

488498
connect(getMainWindow(), &MainWindow::databaseLocked, selectDialog, &AutoTypeSelectDialog::reject);
489-
connect(selectDialog,
490-
&AutoTypeSelectDialog::matchActivated,
491-
this,
492-
[this](const AutoTypeMatch& match, bool virtualMode) {
493-
m_lastMatch = match;
494-
m_lastMatchRetypeTimer.start(config()->get(Config::GlobalAutoTypeRetypeTime).toInt() * 1000);
495-
executeAutoTypeActions(match.first,
496-
match.second,
497-
m_windowForGlobal,
498-
virtualMode ? AutoTypeExecutor::Mode::VIRTUAL
499-
: AutoTypeExecutor::Mode::NORMAL);
500-
});
499+
connect(
500+
selectDialog,
501+
&AutoTypeSelectDialog::matchActivated,
502+
this,
503+
[this](const AutoTypeMatch& match, bool virtualMode) {
504+
m_lastMatch = match;
505+
m_lastMatchRetypeTimer.start(config()->get(Config::GlobalAutoTypeRetypeTime).toInt() * 1000);
506+
executeAutoTypeActions(match.first,
507+
match.second,
508+
m_windowForGlobal,
509+
virtualMode ? AutoTypeExecutor::Mode::VIRTUAL : AutoTypeExecutor::Mode::NORMAL);
510+
},
511+
Qt::QueuedConnection);
501512
connect(selectDialog, &QDialog::rejected, this, [this] {
502513
restoreWindowState();
503514
emit autotypeFinished();
@@ -510,6 +521,7 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
510521
selectDialog->show();
511522
selectDialog->raise();
512523
selectDialog->activateWindow();
524+
m_plugin->prepareAutoType();
513525
} else if (!matchList.isEmpty()) {
514526
// Only one match and not asking, do it!
515527
executeAutoTypeActions(matchList.first().first, matchList.first().second, m_windowForGlobal);

src/autotype/AutoType.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "AutoTypeAction.h"
2929
#include "AutoTypeMatch.h"
3030

31+
#include "autotype/AutoTypePlatformPlugin.h"
3132
#include "core/Database.h"
3233
#include "core/Entry.h"
3334

@@ -52,6 +53,11 @@ class AutoType : public QObject
5253
return m_plugin;
5354
}
5455

56+
inline bool hasWindowAccess()
57+
{
58+
return m_plugin && m_plugin->hasWindowAccess();
59+
}
60+
5561
static AutoType* instance();
5662
static void createTestInstance();
5763

src/autotype/AutoTypePlatformPlugin.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,23 @@ class AutoTypePlatformInterface
3131
virtual WId activeWindow() = 0;
3232
virtual QString activeWindowTitle() = 0;
3333
virtual bool raiseWindow(WId window) = 0;
34+
virtual bool hasWindowAccess()
35+
{
36+
return true;
37+
}
38+
3439
virtual void unload()
3540
{
3641
}
3742

43+
virtual void prepareAutoType()
44+
{
45+
}
46+
47+
virtual void finishAutoType()
48+
{
49+
}
50+
3851
virtual AutoTypeExecutor* createExecutor() = 0;
3952

4053
#if defined(Q_OS_MACOS)

src/autotype/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ if(UNIX AND NOT APPLE AND NOT HAIKU)
2323

2424
add_subdirectory(xcb)
2525
endif()
26+
27+
add_subdirectory(wayland)
2628
elseif(APPLE)
2729
add_subdirectory(mac)
2830
elseif(WIN32)

0 commit comments

Comments
 (0)