Skip to content

Commit 28df367

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 bbd4423 commit 28df367

23 files changed

Lines changed: 2045 additions & 130 deletions

share/translations/keepassxc_en.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,30 @@
616616
<source>Auto-generate password for new entries</source>
617617
<translation type="unfinished"></translation>
618618
</message>
619+
<message>
620+
<source>Configure...</source>
621+
<translation type="unfinished"></translation>
622+
</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>
619643
</context>
620644
<context>
621645
<name>ApplicationSettingsWidgetSecurity</name>
@@ -810,6 +834,29 @@
810834
<translation type="unfinished"></translation>
811835
</message>
812836
</context>
837+
<context>
838+
<name>AutoTypePlatformWayland</name>
839+
<message>
840+
<source>Session closed</source>
841+
<translation type="unfinished"></translation>
842+
</message>
843+
<message>
844+
<source>User cancelled the interaction</source>
845+
<translation type="unfinished"></translation>
846+
</message>
847+
<message>
848+
<source>User interaction was canceled for unknown reason</source>
849+
<translation type="unfinished"></translation>
850+
</message>
851+
<message>
852+
<source>No symbol found for key: &apos;%1&apos;</source>
853+
<translation type="unfinished"></translation>
854+
</message>
855+
<message>
856+
<source>No symbol found for character: &apos;%1&apos;</source>
857+
<translation type="unfinished"></translation>
858+
</message>
859+
</context>
813860
<context>
814861
<name>AutoTypePlatformX11</name>
815862
<message>
@@ -6658,6 +6705,22 @@ This version is not meant for production use.</source>
66586705
<source>Could not register global shortcut</source>
66596706
<translation type="unfinished"></translation>
66606707
</message>
6708+
<message>
6709+
<source>The XDG Desktop Portal for global shortcuts is not available on this system.</source>
6710+
<translation type="unfinished"></translation>
6711+
</message>
6712+
<message>
6713+
<source>Trigger global Auto-Type</source>
6714+
<translation type="unfinished"></translation>
6715+
</message>
6716+
<message>
6717+
<source>KeePassXC - Global Shortcuts</source>
6718+
<translation type="unfinished"></translation>
6719+
</message>
6720+
<message>
6721+
<source>Global shortcuts are already configured. To change them, open your system settings and navigate to the keyboard or application shortcuts section.</source>
6722+
<translation type="unfinished"></translation>
6723+
</message>
66616724
</context>
66626725
<context>
66636726
<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: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ void AutoType::loadPlugin(const QString& pluginPath)
183183
this,
184184
[this](const QString& name, const QString& initialSearch) {
185185
if (name == "autotype") {
186+
m_plugin->prepareForAutoType();
186187
startGlobalAutoType(initialSearch);
187188
}
188189
});
@@ -398,6 +399,10 @@ void AutoType::performAutoTypeWithSequence(const Entry* entry, const QString& se
398399

399400
void AutoType::startGlobalAutoType(const QString& search)
400401
{
402+
if (!m_plugin) {
403+
return;
404+
}
405+
401406
// Never Auto-Type into KeePassXC itself
402407
if (getMainWindow() && (qApp->activeWindow() || qApp->activeModalWidget())) {
403408
return;
@@ -472,9 +477,10 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
472477
qWarning() << "Auto-Type: Window title was empty from the operating system";
473478
}
474479

475-
// Show the selection dialog if we always ask, have multiple matches, or no matches
480+
// Show the selection dialog if we always ask, have multiple matches, no matches, or the window title was empty
476481
if (getMainWindow()
477-
&& (config()->get(Config::Security_AutoTypeAsk).toBool() || matchList.size() > 1 || matchList.isEmpty())) {
482+
&& (config()->get(Config::Security_AutoTypeAsk).toBool() || matchList.size() > 1 || matchList.isEmpty()
483+
|| m_windowTitleForGlobal.isEmpty())) {
478484
// Close any open modal windows that would interfere with the process
479485
getMainWindow()->closeModalWindow();
480486

@@ -486,18 +492,19 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
486492
}
487493

488494
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-
});
495+
connect(
496+
selectDialog,
497+
&AutoTypeSelectDialog::matchActivated,
498+
this,
499+
[this](const AutoTypeMatch& match, bool virtualMode) {
500+
m_lastMatch = match;
501+
m_lastMatchRetypeTimer.start(config()->get(Config::GlobalAutoTypeRetypeTime).toInt() * 1000);
502+
executeAutoTypeActions(match.first,
503+
match.second,
504+
m_windowForGlobal,
505+
virtualMode ? AutoTypeExecutor::Mode::VIRTUAL : AutoTypeExecutor::Mode::NORMAL);
506+
},
507+
Qt::QueuedConnection);
501508
connect(selectDialog, &QDialog::rejected, this, [this] {
502509
restoreWindowState();
503510
emit autotypeFinished();
@@ -751,6 +758,8 @@ AutoType::parseSequence(const QString& entrySequence, const Entry* entry, QStrin
751758
}
752759
}
753760

761+
actions << QSharedPointer<AutoTypeEnd>::create();
762+
754763
return actions;
755764
}
756765

src/autotype/AutoTypeAction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ AutoTypeAction::Result AutoTypeBegin::exec(AutoTypeExecutor* executor) const
6666
return executor->execBegin(this);
6767
}
6868

69+
AutoTypeAction::Result AutoTypeEnd::exec(AutoTypeExecutor* executor) const
70+
{
71+
return executor->execEnd(this);
72+
}
73+
6974
AutoTypeMode::AutoTypeMode(AutoTypeExecutor::Mode mode)
7075
: mode(mode)
7176
{

src/autotype/AutoTypeAction.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ class KEEPASSXC_EXPORT AutoTypeBegin : public AutoTypeAction
118118
Result exec(AutoTypeExecutor* executor) const override;
119119
};
120120

121+
class KEEPASSXC_EXPORT AutoTypeEnd : public AutoTypeAction
122+
{
123+
public:
124+
Result exec(AutoTypeExecutor* executor) const override;
125+
};
126+
121127
class KEEPASSXC_EXPORT AutoTypeExecutor
122128
{
123129
public:
@@ -131,6 +137,10 @@ class KEEPASSXC_EXPORT AutoTypeExecutor
131137
virtual AutoTypeAction::Result execBegin(const AutoTypeBegin* action) = 0;
132138
virtual AutoTypeAction::Result execType(const AutoTypeKey* action) = 0;
133139
virtual AutoTypeAction::Result execClearField(const AutoTypeClearField* action) = 0;
140+
virtual AutoTypeAction::Result execEnd(const AutoTypeEnd*)
141+
{
142+
return AutoTypeAction::Result::Ok();
143+
};
134144

135145
int execDelayMs = 25;
136146
Mode mode = Mode::NORMAL;

src/autotype/AutoTypePlatformPlugin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class AutoTypePlatformInterface
3535
{
3636
}
3737

38+
virtual void prepareForAutoType()
39+
{
40+
}
41+
3842
virtual AutoTypeExecutor* createExecutor() = 0;
3943

4044
#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)