Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Unix, copy to clipboard using wl-clipboard if xclip is not available #4323

Merged
merged 1 commit into from
Apr 9, 2020
Merged

Conversation

tezkerek
Copy link
Contributor

Type of change

  • ✅ Bug fix (non-breaking change which fixes an issue)

Description and Context

This fix allows copying passwords on Wayland, where xclip does not work. I've also slightly changed the code so that other clipboard tools could be easily added in the future. #3812

Checklist:

  • ✅ I have read the CONTRIBUTING document. [REQUIRED]
  • ✅ My code follows the code style of this project. [REQUIRED]
  • ✅ All new and existing tests passed. [REQUIRED]
  • ✅ I have compiled and verified my code with -DWITH_ASAN=ON. [REQUIRED]

@droidmonkey
Copy link
Member

No need for a struct, use a QPair

@tezkerek
Copy link
Contributor Author

Isn't it clearer to have a struct with suggestively named fields?

I don't really know Qt and C++, and this doesn't seem to work:

QList<QPair<QString, QStringList>> clipPrograms;
#ifdef Q_OS_UNIX
    clipPrograms << qMakePair("xclip", (QStringList() << "-i" << "selection" << "clipboard"))
                 << qMakePair("wl-copy", QStringList());
#endif
/usr/include/qt/QtCore/qpair.h:61:31: error: array used as initializer
   61 |         : first(t1), second(t2) {}

@droidmonkey
Copy link
Member

droidmonkey commented Feb 13, 2020

Its just more code to deal with. Try doing:

clipPrograms << {QStringLiteral("xclip"), QStringList() << "arg1" << "arg2"}

You can also forgo the QStringList and just use a QString. When you pass it to QProcess just split the arguments: process.second().split(" ")

@tezkerek
Copy link
Contributor Author

I figured out how to use QPair, it works now. I don't know why the Ubuntu build failed though. It says something about GUI tests, but I only touched the CLI part.

@louib
Copy link
Member

louib commented Feb 16, 2020

@tezkerek I think for historical reason the CLI tests are bundled with the GUI tests. In this case I think there really might be a problem with the patch:

[14:39:05][Step 5/5] FAIL!  : TestCli::testClip() Compared values are not the same
[14:39:05][Step 5/5]    Actual   (clipboard->text())  : ""
[14:39:05][Step 5/5]    Expected (QString("Password")): "Password"
[14:39:05][Step 5/5]    Loc: [/opt/buildagent/work/c401303cba1b4098/tests/TestCli.cpp(481)]

@tezkerek
Copy link
Contributor Author

I'd somehow managed to mess up xclip's arguments. I fixed that.

I have another issue now: it seems that xclip doesn't fail to run on Wayland, it simply doesn't copy it to Wayland's clipboard. So if xclip is installed and the user is running Wayland, clipping still won't work, because xclip will exit successfully.

Maybe check for WAYLAND_DISPLAY to determine what the user is running? Or simply let the user specify what clipboard program they wish to use?

@louib
Copy link
Member

louib commented Feb 18, 2020

@tezkerek I'm not sure what's best to be honest. Maybe change the order? Start with wl-clipboard and fallback to xclip, would that work?

@tezkerek
Copy link
Contributor Author

I really don't get how QClipboard works. The cli test fails when I use wl-copy (even if it works when I test it manually), and passes when I use xclip (even if it doesn't work when I test it manually, because I'm running wayland).

Is it because of xwayland? The test fails even with QT_QPA_PLATFORM set.

@louib
Copy link
Member

louib commented Feb 28, 2020

@tezkerek did you try using WAYLAND_DISPLAY as you proposed? If this env var is always defined on wayland, that might be the way to go.

@tezkerek
Copy link
Contributor Author

tezkerek commented Feb 28, 2020 via email

@droidmonkey
Copy link
Member

Is this ready to go or do you want to fix the test wayland situation?

@tezkerek
Copy link
Contributor Author

I could modify it to just skip the clip test if it's running on Wayland, for now.

@louib
Copy link
Member

louib commented Mar 18, 2020

@tezkerek another option could be to fetch the text from the clipboard after pasting to make sure the operation was successful, and fallback on the other programs if it didn't work.

@tezkerek
Copy link
Contributor Author

@louib How would I fetch the text? QClipboard isn't available in the cli tool, or am I wrong?

@louib
Copy link
Member

louib commented Mar 19, 2020

@tezkerek you're right, it's not available. We could fetch the text using the same command used for clipping, but that would be additional work and I'm not sure it works for all the clipboard apps we use.

@droidmonkey
Copy link
Member

Ping @tezkerek @louib whatcha wanna do about this PR?

@tezkerek
Copy link
Contributor Author

tezkerek commented Apr 8, 2020

Well, the clip test still fails on Wayland, and I don't know how to debug that. If you're okay with just skipping the test when running on Wayland, it works.

@droidmonkey
Copy link
Member

I'm ok with skipping it on Wayland.

src/cli/Utils.cpp Outdated Show resolved Hide resolved
@phoerious phoerious merged commit 6128e5d into keepassxreboot:develop Apr 9, 2020
droidmonkey added a commit that referenced this pull request Jul 7, 2020
Added

- Custom Light and Dark themes [#4110, #4769, #4791, #4796, #4892, #4915]
- Compact mode to use classic Group and Entry line height [#4910]
- View menu to quickly switch themes, compact mode, and toggle UI elements [#4910]
- Search for groups and scope search to matched groups [#4705]
- Save Database Backup feature [#4550]
- Sort entries by "natural order" and move lines up/down [#4357]
- Option to launch KeePassXC on system startup/login [#4675]
- Caps Lock warning on password input fields [#3646]
- Add "Size" column to entry view [#4588]
- Browser-like tab experience using Ctrl+[Num] (Alt+[Num] on Linux) [#4063, #4305]
- Password Generator: Define additional characters to choose from [#3876]
- Reports: Database password health check (offline) [#3993]
- Reports: HIBP online service to check for breached passwords [#4438]
- Auto-Type: DateTime placeholders [#4409]
- Browser: Show group name in results sent to browser extension [#4111]
- Browser: Ability to define a custom browser location (macOS and Linux only) [#4148]
- Browser: Ability to change root group UUID and inline edit connection ID [#4315, #4591]
- CLI: `db-info` command [#4231]
- CLI: Use wl-clipboard if xclip is not available (Linux) [#4323]
- CLI: Incorporate xclip into snap builds [#4697]
- SSH Agent: Key file path env substitution, SSH_AUTH_SOCK override, and connection test [#3769, #3801, #4545]
- SSH Agent: Context menu actions to add/remove keys [#4290]

Changed

- Complete replacement of default database icons [#4699]
- Complete replacement of application icons [#4066, #4161, #4203, #4411]
- Complete rewrite of documentation and manpages using Asciidoctor [#4937]
- Complete refactor of config files; separate between local and roaming [#4665]
- Complete refactor of browser integration and proxy code [#4680]
- Complete refactor of hardware key integration (YubiKey and OnlyKey) [#4584, #4843]
- Significantly improve performance when saving and opening databases [#4309, #4833]
- Remove read-only detection for database files [#4508]
- Overhaul of password fields and password generator [#4367]
- Replace instances of "Master Key" with "Database Credentials" [#4929]
- Change settings checkboxes to positive phrasing for consistency [#4715]
- Improve UX of using entry actions (focus fix) [#3893]
- Set expiration time to Now when enabling entry expiration [#4406]
- Always show "New Entry" in context menu [#4617]
- Issue warning before adding large attachments [#4651]
- Improve importing OPVault [#4630]
- Improve AutoOpen capability [#3901, #4752]
- Check for updates every 7 days even while still running [#4752]
- Improve Windows installer UI/UX [#4675]
- Improve config file handling of portable distribution [#4131, #4752]
- macOS: Hide dock icon when application is hidden to tray [#4782]
- Browser: Use unlock dialog to improve UX of opening a locked database [#3698]
- Browser: Improve database and entry settings experience [#4392, #4591]
- Browser: Improve confirm access dialog [#2143, #4660]
- KeeShare: Improve monitoring file changes of shares [#4720]
- CLI: Rename `create` command to `db-create` [#4231]
- CLI: Cleanup `db-create` options (`--set-key-file` and `--set-password`) [#4313]
- CLI: Use stderr for help text and password prompts [#4086, #4623]
- FdoSecrets: Display existing secret service process [#4128]

Fixed

- Fix changing focus around the main window using tab key [#4641]
- Fix search field clearing while still using the application [#4368]
- Improve search help widget displaying on macOS and Linux [#4236]
- Return keyboard focus after editing an entry [#4287]
- Reset database path after failed "Save As" [#4526]
- Use SHA256 Digest for Windows code signing [#4129]
- Improve handling of ccache when building [#4104, #4335]
- macOS: Properly re-hide application window after browser integration and Auto-Type usage [#4909]
- Auto-Type: Fix crash when performing on new entry [#4132]
- Browser: Send legacy HTTP settings to recycle bin [#4589]
- Browser: Fix merging browser keys [#4685]
- CLI: Fix encoding when exporting database [#3921]
- SSH Agent: Improve reliability and underlying code [#3833, #4256, #4549, #4595]
- FdoSecrets: Fix crash when editing settings before service is enabled [#4332]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants