Bug 441668

Summary: Please make middle-click pasting optional
Product: [Applications] systemsettings Reporter: geisserml <geisserml>
Component: generalAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: wishlist CC: all, andy, bronsonmathews, bugseforuns, cornelis, Danielgaba, dmatteo002, ethan.reesor, geisserml, gratzer, Guyc1800, hunterholloway2023, jeremy9856, katyaberezyaka, kresimircindric, loudsquid, me, meven.car, meven, natalie_clarius, nate, postix, ralim, rdieter, ryu.ketsueki
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In: 5.26

Description geisserml 2021-08-28 19:24:26 UTC
SUMMARY
Recently middle-click pasting got implemented for the Wayland platform (Bug 422426).
However, this feature could be regarded as an annoyance due to the risk of inadvertent pasting. Especially users coming from different operating systems are not used to this behaviour and dislike it. Moreover, this feature could potentially be a privacy risk, since marked texts are automatically added to a clipboard, altough they might contain sensitive information. Additionally, it might conflict different uses of the middle mouse button.
There currently appears to be no way to disable middle-click paste on both Plasma Wayland and X11. It would be nice if an option could be added to the System Settings mouse configuration page (or alternatively to the clipboard settings) to disable middle-click paste at least for the Wayland platform (and if technically possible, also for X11).


STEPS TO REPRODUCE
1. Mark an arbitrary text in a Wayland (or X11) session
2. Activate a text input widget
3. Press the middle mouse button

OBSERVED RESULT
The marked text will be pasted into the widget.

EXPECTED RESULT
There should be an option to disable middle-click pasting, at least for Wayland (and for X11 if feasible).

SOFTWARE/OS VERSIONS
Operating System: KDE neon 5.22
KDE Plasma Version: 5.22.4
KDE Frameworks Version: 5.85.0
Qt Version: 5.15.3
Kernel Version: 5.11.0-27-generic (64-bit)
Graphics Platform: Wayland

ADDITIONAL INFORMATION
- The idea for this report started on Nate Graham's blog (https://pointieststick.com/2021/08/20/this-week-in-kde-some-cool-new-stuff/#comment-23401).
- Middle-click pasting is optional in GNOME (according to https://linuxconfig.org/how-to-disable-middle-mouse-button-click-paste-on-ubuntu-20-04-focal-fossa-linux)
- Not sure whether I chose the right component. Feel free to move the issue if you know a better place.
Comment 1 geisserml 2021-08-28 19:31:07 UTC
l. 6: * and might dislike it
l. 8/9: * conflict with

Pity one can't edit posts in Bugzilla.
Comment 2 Nate Graham 2021-08-30 16:57:03 UTC
Should be optional on X11 too.
Comment 3 Ethan Reesor 2021-10-18 05:00:47 UTC
If someone can give me some pointers, I'd be interested in working on an MR. I've skimmed through https://invent.kde.org/plasma/kwayland-server/-/merge_requests/15/diffs?commit_id=c82b0db029f35e0c853f7170cf03c81d09cd25c7 but given that I have zero experience with KDE's code base it is not obvious where to add the conditional behavior, or where/how to pull in configuration. And I don't have the time to invest in digging through and understanding the project.
Comment 4 postix 2021-10-18 08:43:50 UTC
*** Bug 392488 has been marked as a duplicate of this bug. ***
Comment 5 Nate Graham 2021-10-29 13:57:44 UTC
*** Bug 389710 has been marked as a duplicate of this bug. ***
Comment 6 Nate Graham 2022-04-07 14:55:11 UTC
*** Bug 443855 has been marked as a duplicate of this bug. ***
Comment 7 Nate Graham 2022-04-07 14:55:15 UTC
*** Bug 452364 has been marked as a duplicate of this bug. ***
Comment 8 ryu.ketsueki 2022-05-06 18:08:08 UTC
Is there even a way to disable this behavior on Plasma Wayland? This is annoying when using the middle click to move the canvas around on Figma, for example, but pasting whatever is on clipboard after releasing the button
Comment 9 Bug Janitor Service 2022-05-29 19:15:16 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/2487
Comment 10 geisserml 2022-05-29 19:28:36 UTC
(In reply to Bug Janitor Service from comment #9)
> A possibly relevant merge request was started @
> https://invent.kde.org/plasma/kwin/-/merge_requests/2487
If I understood this right, once the PR is merged, we can add the lines below to `~/.config/kwinrc` to disable middle-click paste on Wayland?
```
[Wayland]
EnablePrimarySelection=false
```
Comment 11 Méven Car 2022-05-30 17:48:59 UTC
(In reply to geisserml from comment #10)
> (In reply to Bug Janitor Service from comment #9)
> > A possibly relevant merge request was started @
> > https://invent.kde.org/plasma/kwin/-/merge_requests/2487
> If I understood this right, once the PR is merged, we can add the lines
> below to `~/.config/kwinrc` to disable middle-click paste on Wayland?
> ```
> [Wayland]
> EnablePrimarySelection=false
> ```

Yes you got correct.
But this needs to be reviewed, please be patient.
In any case I am on it, they are chances we can have it for Plasma 5.25 but more assuredly 5.26.
Comment 12 geisserml 2022-05-30 18:20:14 UTC
> But this needs to be reviewed, please be patient.
Sure, take your time :)
Comment 13 Bug Janitor Service 2022-06-02 20:15:58 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/970
Comment 14 ryantg 2022-06-07 23:47:23 UTC
I was really hoping for a setting to disable middle-click altogether. Even with paste disabled, middle click still has weird outcomes, like middle clicking on a firefox tab closes that tab.

Currently you can set the touchpad to left or right-handed (which swaps the left/right buttons while keeping middle click in place), or you can set right click to "Press bottom-right corner" (which, of course, is actually the bottom left corner when in left handed mode) or "Press anywhere with two fingers"). The latter disables middle click on the touchpad, which is cool, but it also makes it so the mouse moves around when you rest your thumb on the bottom of the touchpad.

In conclusion, disabling middle click paste is cool, but where is the option to disable middle click completely (and choose how you want the middle area mapped)? I would prefer the middle area to be a left click, with only the corner used for right click.
Comment 15 Nate Graham 2022-06-08 00:55:42 UTC
Remapping/disabling hardware or virtual software buttons is kind of out of scope, but you can do it. I used to re-map Libinput's virtual buttons using xinput to do the same thing IIRC.

FWIW if leaving your thumb on the bottom of your touchpad moves the cursor or starts a two-finger scroll, that's a bug in Libinput and you should report it at https://gitlab.freedesktop.org/libinput/libinput/-/issues/. It's supposed to filter out a lazy thumb on the touchpad, and this works for me with my touchpad.
Comment 16 Méven Car 2022-06-08 07:33:41 UTC
(In reply to ryantg from comment #14)
> I was really hoping for a setting to disable middle-click altogether. 

Please open a different, this is not the same issue.

> Even with paste disabled, middle click still has weird outcomes, like middle
> clicking on a firefox tab closes that tab.

This is common to most applications with tabs including dolphin.

> 
> In conclusion, disabling middle click paste is cool, but where is the option
> to disable middle click completely (and choose how you want the middle area
> mapped)? I would prefer the middle area to be a left click, with only the
> corner used for right click.
Comment 17 Méven Car 2022-06-19 06:01:54 UTC
Git commit 4082fdf96092005106b5895e238e94a614035b0b by Méven Car.
Committed on 19/06/2022 at 05:49.
Pushed by meven into branch 'master'.

WaylandServer: Add a setting to disable PrimarySelection

M  +3    -0    src/kwin.kcfg
M  +1    -4    src/main.cpp
M  +8    -4    src/main_wayland.cpp
M  +14   -1    src/wayland_server.cpp
M  +3    -0    src/wayland_server.h

https://invent.kde.org/plasma/kwin/commit/4082fdf96092005106b5895e238e94a614035b0b
Comment 18 Méven Car 2022-06-19 07:50:52 UTC
Git commit 9577fd5c762ea14382961fd359b3365bcec512a9 by Méven Car.
Committed on 19/06/2022 at 05:43.
Pushed by meven into branch 'master'.

KCM Behavior: in Wayland allow to disable primary selection

Aka middle click pasting

M  +0    -0    kcms/activities/kcm_activities.desktop
M  +21   -0    kcms/workspaceoptions/package/contents/ui/main.qml
M  +17   -6    kcms/workspaceoptions/workspaceoptions.cpp
M  +6    -0    kcms/workspaceoptions/workspaceoptions_kwinsettings.kcfg

https://invent.kde.org/plasma/plasma-desktop/commit/9577fd5c762ea14382961fd359b3365bcec512a9
Comment 19 geisserml 2022-06-19 09:24:47 UTC
Thanks!
Comment 20 soredake 2022-06-19 12:10:40 UTC
It's fixed only in wayland, not in x11.
Comment 21 geisserml 2022-06-19 12:56:23 UTC
I think it was stated in comment [1] that it is not nicely possible to implement this setting with X11.

[1] https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/970#note_462083
Comment 22 andy 2022-06-25 23:30:47 UTC
What is currently working for me seamlessly in X11 is `while true; do xsel -fin </dev/null; done`  (source https://unix.stackexchange.com/a/501445) in a user service. 

Not sure if that could be incorporated in a patch somehow. Seems robust and with no performance issues.
Comment 23 andy 2022-10-13 22:01:48 UTC
(In reply to geisserml from comment #21)
> I think it was stated in comment [1] that it is not nicely possible to
> implement this setting with X11.
> 
> [1]
> https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/970#note_462083

> I don't want to devote time to implement this in X11, it is going to take me far longer than what it took for the Wayland case. Users have already available workarounds.

The work arounds are not perfect. E.g. obsidian users currently have no solution https://forum.obsidian.md/t/linux-middle-click-paste-is-problematic-and-needs-to-be-automatically-disabled/34717/12

The workaround I use does not work here.
Comment 24 dmatteo002 2022-12-04 20:11:15 UTC
(In reply to soredake from comment #20)
> It's fixed only in wayland, not in x11.

For me still doesn't work even in wayland (even after enabling the setting)
Comment 25 Mel 2022-12-04 20:15:03 UTC
(In reply to matteodinoia02 from comment #24)
> (In reply to soredake from comment #20)
> > It's fixed only in wayland, not in x11.
> 
> For me still doesn't work even in wayland (even after enabling the setting)

It's functional for most applications for me in Wayland. I found some applications like Firefox or the Jetbrains suite have a built-in config/key bind for this that aren't affected by the KDE setting. 

For Firefox (as an example) the about:config option `middlemouse.paste` needs to be set to false manually.
Comment 26 dmatteo002 2022-12-05 07:17:07 UTC
(In reply to Mel from comment #25)
> (In reply to matteodinoia02 from comment #24)
> > (In reply to soredake from comment #20)
> > > It's fixed only in wayland, not in x11.
> > 
> > For me still doesn't work even in wayland (even after enabling the setting)
> 
> It's functional for most applications for me in Wayland. I found some
> applications like Firefox or the Jetbrains suite have a built-in config/key
> bind for this that aren't affected by the KDE setting. 
> 
> For Firefox (as an example) the about:config option `middlemouse.paste`
> needs to be set to false manually.

I tried again and now is working (nothing is different than before). I already had tried rebooting several times, so i really don't know why.
Comment 27 Méven 2023-01-26 10:01:33 UTC
(In reply to Mel from comment #25)
> (In reply to matteodinoia02 from comment #24)
> > (In reply to soredake from comment #20)
> > > It's fixed only in wayland, not in x11.
> > 
> > For me still doesn't work even in wayland (even after enabling the setting)
> 
> It's functional for most applications for me in Wayland. I found some
> applications like Firefox or the Jetbrains suite have a built-in config/key
> bind for this that aren't affected by the KDE setting. 
> 

Are those applications run using XWayland ?
Comment 28 dmatteo002 2023-01-26 13:53:11 UTC
(In reply to Méven from comment #27)
> (In reply to Mel from comment #25)
> > (In reply to matteodinoia02 from comment #24)
> > > (In reply to soredake from comment #20)
> > > > It's fixed only in wayland, not in x11.
> > > 
> > > For me still doesn't work even in wayland (even after enabling the setting)
> > 
> > It's functional for most applications for me in Wayland. I found some
> > applications like Firefox or the Jetbrains suite have a built-in config/key
> > bind for this that aren't affected by the KDE setting. 
> > 
> 
> Are those applications run using XWayland ?

Dunno, i did try on various kde applications (like dolphin, setting, konsole...) and it still pasted but after some day it just stopped being a problem. No clue why (i did already reboot various time but gained nothing). So I still don't know what was the problem.