Skip to content

Commit da214ed

Browse files
committed
fixup! Wayland Auto-Type with XDG Desktop Portals
1 parent 7f7bbe5 commit da214ed

8 files changed

Lines changed: 149 additions & 113 deletions

File tree

share/translations/keepassxc_en.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,6 @@
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>
623619
<message>
624620
<source>Keep remote desktop connection open after performing Auto-Type</source>
625621
<translation type="unfinished"></translation>
@@ -640,6 +636,10 @@
640636
<source>Remember session until revoked by desktop</source>
641637
<translation type="unfinished"></translation>
642638
</message>
639+
<message>
640+
<source>Not configured</source>
641+
<translation type="unfinished"></translation>
642+
</message>
643643
</context>
644644
<context>
645645
<name>ApplicationSettingsWidgetSecurity</name>
@@ -6718,7 +6718,11 @@ This version is not meant for production use.</source>
67186718
<translation type="unfinished"></translation>
67196719
</message>
67206720
<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>
6721+
<source>KeePassXC - Global Auto-Type</source>
6722+
<translation type="unfinished"></translation>
6723+
</message>
6724+
<message>
6725+
<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>
67226726
<translation type="unfinished"></translation>
67236727
</message>
67246728
</context>

src/gui/ApplicationSettingsWidget.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,28 @@ ApplicationSettingsWidget::ApplicationSettingsWidget(QWidget* parent)
9292
m_generalUi->autoTypeEntryTitleMatchCheckBox->setVisible(true);
9393
m_generalUi->autoTypeEntryURLMatchCheckBox->setVisible(true);
9494
m_generalUi->autoTypeAskCheckBox->setDisabled(false);
95+
96+
m_generalUi->autoTypeDesktopPortalPersistConnectionCheckBox->setVisible(false);
97+
m_generalUi->autoTypeDesktopPortalPersistModeLabel->setVisible(false);
98+
m_generalUi->autoTypeDesktopPortalPersistModeComboBox->setVisible(false);
9599
} else {
96100
m_generalUi->autoTypeEntryTitleMatchCheckBox->setVisible(false);
97101
m_generalUi->autoTypeEntryURLMatchCheckBox->setVisible(false);
98102
m_generalUi->autoTypeAskCheckBox->setChecked(true);
99103
m_generalUi->autoTypeAskCheckBox->setDisabled(true);
100-
}
101-
if (osUtils->externalGlobalShortcutsConfigurator()) {
102-
m_generalUi->autoTypeShortcutWidget->setVisible(false);
103-
m_generalUi->autoTypeShortcutConfigureButton->setVisible(true);
104-
connect(m_generalUi->autoTypeShortcutConfigureButton,
105-
&QPushButton::clicked,
106-
osUtils,
107-
&OSUtilsBase::configureGlobalShortcuts);
104+
108105
// effectively these only get shown with the Wayland plugin enabled
109106
m_generalUi->autoTypeDesktopPortalPersistConnectionCheckBox->setVisible(true);
110107
m_generalUi->autoTypeDesktopPortalPersistModeLabel->setVisible(true);
111108
m_generalUi->autoTypeDesktopPortalPersistModeComboBox->setVisible(true);
112-
} else {
113-
m_generalUi->autoTypeShortcutWidget->setVisible(true);
114-
m_generalUi->autoTypeShortcutConfigureButton->setVisible(false);
115-
m_generalUi->autoTypeDesktopPortalPersistConnectionCheckBox->setVisible(false);
116-
m_generalUi->autoTypeDesktopPortalPersistModeLabel->setVisible(false);
117-
m_generalUi->autoTypeDesktopPortalPersistModeComboBox->setVisible(false);
118109
}
110+
111+
m_generalUi->autoTypeShortcutWidget->setExternalConfigurator(osUtils->externalGlobalShortcutsConfigurator());
112+
connect(m_generalUi->autoTypeShortcutWidget,
113+
&ShortcutWidget::clicked,
114+
osUtils,
115+
&OSUtilsBase::configureGlobalShortcut);
116+
connect(osUtils, &OSUtilsBase::globalShortcutChanged, m_generalUi->autoTypeShortcutWidget, &QLineEdit::setText);
119117
}
120118

121119
connect(this, SIGNAL(accepted()), SLOT(saveSettings()));
@@ -337,7 +335,8 @@ void ApplicationSettingsWidget::loadSettings()
337335
m_globalAutoTypeKey = static_cast<Qt::Key>(config()->get(Config::GlobalAutoTypeKey).toInt());
338336
m_globalAutoTypeModifiers =
339337
static_cast<Qt::KeyboardModifiers>(config()->get(Config::GlobalAutoTypeModifiers).toInt());
340-
if (m_globalAutoTypeKey > 0 && m_globalAutoTypeModifiers > 0) {
338+
if (!osUtils->externalGlobalShortcutsConfigurator() && m_globalAutoTypeKey > 0
339+
&& m_globalAutoTypeModifiers > 0) {
341340
m_generalUi->autoTypeShortcutWidget->setShortcut(m_globalAutoTypeKey, m_globalAutoTypeModifiers);
342341
}
343342
m_generalUi->autoTypeRetypeTimeSpinBox->setValue(config()->get(Config::GlobalAutoTypeRetypeTime).toInt());

src/gui/ApplicationSettingsWidgetGeneral.ui

Lines changed: 75 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,38 +1303,16 @@
13031303
</property>
13041304
</widget>
13051305
</item>
1306-
<item row="1" column="0">
1307-
<widget class="QLabel" name="autoTypeDesktopPortalPersistModeLabel">
1306+
<item row="4" column="0">
1307+
<widget class="QLabel" name="autoTypeDelayLabel">
13081308
<property name="text">
1309-
<string>Remote desktop mode:</string>
1309+
<string>Auto-Type typing delay:</string>
13101310
</property>
13111311
<property name="alignment">
13121312
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
13131313
</property>
1314-
</widget>
1315-
</item>
1316-
<item row="4" column="1">
1317-
<widget class="QSpinBox" name="autoTypeDelaySpinBox">
1318-
<property name="sizePolicy">
1319-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
1320-
<horstretch>0</horstretch>
1321-
<verstretch>0</verstretch>
1322-
</sizepolicy>
1323-
</property>
1324-
<property name="accessibleName">
1325-
<string>Auto-type character typing delay milliseconds</string>
1326-
</property>
1327-
<property name="suffix">
1328-
<string comment="Milliseconds"> ms</string>
1329-
</property>
1330-
<property name="prefix">
1331-
<string/>
1332-
</property>
1333-
<property name="maximum">
1334-
<number>1000</number>
1335-
</property>
1336-
<property name="value">
1337-
<number>25</number>
1314+
<property name="buddy">
1315+
<cstring>autoTypeDelaySpinBox</cstring>
13381316
</property>
13391317
</widget>
13401318
</item>
@@ -1351,6 +1329,22 @@
13511329
</property>
13521330
</widget>
13531331
</item>
1332+
<item row="2" column="1">
1333+
<widget class="QSpinBox" name="autoTypeRetypeTimeSpinBox">
1334+
<property name="suffix">
1335+
<string comment="Seconds"> sec</string>
1336+
</property>
1337+
<property name="minimum">
1338+
<number>0</number>
1339+
</property>
1340+
<property name="maximum">
1341+
<number>60</number>
1342+
</property>
1343+
<property name="value">
1344+
<number>15</number>
1345+
</property>
1346+
</widget>
1347+
</item>
13541348
<item row="2" column="0">
13551349
<widget class="QLabel" name="autoTypeRetypeLabel">
13561350
<property name="text">
@@ -1361,46 +1355,6 @@
13611355
</property>
13621356
</widget>
13631357
</item>
1364-
<item row="0" column="1">
1365-
<layout class="QVBoxLayout" name="autoTypeShortcutLayout">
1366-
<item>
1367-
<widget class="ShortcutWidget" name="autoTypeShortcutWidget">
1368-
<property name="sizePolicy">
1369-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
1370-
<horstretch>0</horstretch>
1371-
<verstretch>0</verstretch>
1372-
</sizepolicy>
1373-
</property>
1374-
<property name="accessibleName">
1375-
<string>Global auto-type shortcut</string>
1376-
</property>
1377-
</widget>
1378-
</item>
1379-
<item>
1380-
<widget class="QPushButton" name="autoTypeShortcutConfigureButton">
1381-
<property name="enabled">
1382-
<bool>true</bool>
1383-
</property>
1384-
<property name="text">
1385-
<string>Configure...</string>
1386-
</property>
1387-
</widget>
1388-
</item>
1389-
</layout>
1390-
</item>
1391-
<item row="1" column="3">
1392-
<spacer name="horizontalSpacer_14">
1393-
<property name="orientation">
1394-
<enum>Qt::Orientation::Horizontal</enum>
1395-
</property>
1396-
<property name="sizeHint" stdset="0">
1397-
<size>
1398-
<width>0</width>
1399-
<height>0</height>
1400-
</size>
1401-
</property>
1402-
</spacer>
1403-
</item>
14041358
<item row="1" column="1" colspan="2">
14051359
<widget class="QComboBox" name="autoTypeDesktopPortalPersistModeComboBox">
14061360
<property name="sizePolicy">
@@ -1426,17 +1380,14 @@
14261380
</item>
14271381
</widget>
14281382
</item>
1429-
<item row="4" column="0">
1430-
<widget class="QLabel" name="autoTypeDelayLabel">
1383+
<item row="1" column="0">
1384+
<widget class="QLabel" name="autoTypeDesktopPortalPersistModeLabel">
14311385
<property name="text">
1432-
<string>Auto-Type typing delay:</string>
1386+
<string>Remote desktop mode:</string>
14331387
</property>
14341388
<property name="alignment">
14351389
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
14361390
</property>
1437-
<property name="buddy">
1438-
<cstring>autoTypeDelaySpinBox</cstring>
1439-
</property>
14401391
</widget>
14411392
</item>
14421393
<item row="3" column="1">
@@ -1470,21 +1421,18 @@
14701421
</property>
14711422
</widget>
14721423
</item>
1473-
<item row="2" column="1">
1474-
<widget class="QSpinBox" name="autoTypeRetypeTimeSpinBox">
1475-
<property name="suffix">
1476-
<string comment="Seconds"> sec</string>
1477-
</property>
1478-
<property name="minimum">
1479-
<number>0</number>
1480-
</property>
1481-
<property name="maximum">
1482-
<number>60</number>
1424+
<item row="1" column="3">
1425+
<spacer name="horizontalSpacer_14">
1426+
<property name="orientation">
1427+
<enum>Qt::Orientation::Horizontal</enum>
14831428
</property>
1484-
<property name="value">
1485-
<number>15</number>
1429+
<property name="sizeHint" stdset="0">
1430+
<size>
1431+
<width>0</width>
1432+
<height>0</height>
1433+
</size>
14861434
</property>
1487-
</widget>
1435+
</spacer>
14881436
</item>
14891437
<item row="0" column="2" colspan="2">
14901438
<spacer name="horizontalSpacer_6">
@@ -1499,6 +1447,47 @@
14991447
</property>
15001448
</spacer>
15011449
</item>
1450+
<item row="4" column="1">
1451+
<widget class="QSpinBox" name="autoTypeDelaySpinBox">
1452+
<property name="sizePolicy">
1453+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
1454+
<horstretch>0</horstretch>
1455+
<verstretch>0</verstretch>
1456+
</sizepolicy>
1457+
</property>
1458+
<property name="accessibleName">
1459+
<string>Auto-type character typing delay milliseconds</string>
1460+
</property>
1461+
<property name="suffix">
1462+
<string comment="Milliseconds"> ms</string>
1463+
</property>
1464+
<property name="prefix">
1465+
<string/>
1466+
</property>
1467+
<property name="maximum">
1468+
<number>1000</number>
1469+
</property>
1470+
<property name="value">
1471+
<number>25</number>
1472+
</property>
1473+
</widget>
1474+
</item>
1475+
<item row="0" column="1">
1476+
<widget class="ShortcutWidget" name="autoTypeShortcutWidget">
1477+
<property name="sizePolicy">
1478+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
1479+
<horstretch>0</horstretch>
1480+
<verstretch>0</verstretch>
1481+
</sizepolicy>
1482+
</property>
1483+
<property name="accessibleName">
1484+
<string>Global auto-type shortcut</string>
1485+
</property>
1486+
<property name="placeholderText">
1487+
<string>Not configured</string>
1488+
</property>
1489+
</widget>
1490+
</item>
15021491
</layout>
15031492
</item>
15041493
<item>
@@ -1581,7 +1570,6 @@
15811570
<tabstop>autoTypeRelockDatabaseCheckBox</tabstop>
15821571
<tabstop>autoTypeDesktopPortalPersistConnectionCheckBox</tabstop>
15831572
<tabstop>autoTypeShortcutWidget</tabstop>
1584-
<tabstop>autoTypeShortcutConfigureButton</tabstop>
15851573
<tabstop>autoTypeDesktopPortalPersistModeComboBox</tabstop>
15861574
<tabstop>autoTypeRetypeTimeSpinBox</tabstop>
15871575
<tabstop>autoTypeStartDelaySpinBox</tabstop>

src/gui/osutils/OSUtilsBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ class OSUtilsBase : public QObject
7878
}
7979

8080
public slots:
81-
virtual void configureGlobalShortcuts()
81+
virtual void configureGlobalShortcut()
8282
{
8383
}
8484

8585
signals:
8686
void globalShortcutTriggered(const QString& name, const QString& search = {});
87+
void globalShortcutChanged(const QString& description);
8788

8889
/**
8990
* Indicates platform UI theme change (light mode to dark mode).

src/gui/osutils/nixutils/NixUtils.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ void NixUtils::initGlobalShortcutsSession()
134134
}
135135
});
136136

137+
connect(s_shortcutsInterface,
138+
&OrgFreedesktopPortalGlobalShortcutsInterface::ShortcutsChanged,
139+
this,
140+
[this](const QDBusObjectPath& session_handle, const XdpShortcuts& shortcuts) {
141+
if (!m_globalShortcutsSession || session_handle.path() != m_globalShortcutsSession->path()) {
142+
return;
143+
}
144+
for (const auto& [id, map] : shortcuts) {
145+
if (id == QLatin1String("autotype")) {
146+
emit globalShortcutChanged(map.value(QStringLiteral("trigger_description")).toString());
147+
return;
148+
}
149+
}
150+
});
151+
137152
createGlobalShortcutsSession();
138153
}
139154

@@ -517,6 +532,12 @@ void NixUtils::bindShortcutsToCurrentSession()
517532

518533
auto existing = qdbus_cast<XdpShortcuts>(listResults.value("shortcuts"));
519534
if (!existing.isEmpty()) {
535+
for (const auto& [id, map] : existing) {
536+
if (id == QLatin1String("autotype")) {
537+
emit globalShortcutChanged(map.value(QStringLiteral("trigger_description")).toString());
538+
break;
539+
}
540+
}
520541
return; // already active, nothing to do
521542
}
522543

@@ -572,7 +593,7 @@ void NixUtils::createGlobalShortcutsSession()
572593
}
573594
}
574595

575-
void NixUtils::configureGlobalShortcuts()
596+
void NixUtils::configureGlobalShortcut()
576597
{
577598
if (!s_shortcutsInterface->isValid() || !m_globalShortcutsSession) {
578599
MessageBox::warning(getMainWindow(),
@@ -608,9 +629,9 @@ void NixUtils::configureGlobalShortcuts()
608629

609630
// Portal v1 (e.g. GNOME): no reconfiguration API, direct the user to system settings
610631
MessageBox::information(getMainWindow(),
611-
tr("KeePassXC - Global Shortcuts"),
612-
tr("Global shortcuts are already configured. "
613-
"To change them, open your system settings and navigate to the "
632+
tr("KeePassXC - Global Auto-Type"),
633+
tr("Global Auto-Type shortcut is already configured. "
634+
"To change it, open your system settings and navigate to the "
614635
"keyboard or application shortcuts section."));
615636
return;
616637
}

src/gui/osutils/nixutils/NixUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class NixUtils : public OSUtilsBase, QAbstractNativeEventFilter
6161
QString portalRequest(const std::function<void(uint, const QVariantMap&)> handler);
6262

6363
public slots:
64-
void configureGlobalShortcuts() override;
64+
void configureGlobalShortcut() override;
6565

6666
private slots:
6767
void handleColorSchemeRead(QDBusVariant value);

0 commit comments

Comments
 (0)