有没有办法禁用 gnome 默认情况下的鼠标中键粘贴行为?
我有一个灵敏的鼠标滚轮,每当我滚动文本时,有时它会将内容随机粘贴到文本中。当我将文件发送给其他人时,我会失去很多可信度,而文件上到处都是随机的文本片段。
我见过一个解决方案,通过将鼠标的中键映射到一个不存在的鼠标按钮,但这意味着完全摆脱鼠标中键(即没有选项卡关闭,自动打开新选项卡的链接等) . 我想保持我的鼠标中键处于活动状态,只需禁用粘贴行为。
当我用触摸板滚动文本时也会发生这种情况(不小心碰到了两个手指而没有移动,砰。)
因此,仅通过更换新鼠标并不能解决问题(事实上,我相信我的触摸板比我的鼠标更常发生这种情况)。
小智 72
我使用 gnome-tweak-tool 在 Ubuntu 16.04 中禁用中间按钮粘贴。
安装它
sudo apt install gnome-tweak-tool
Run Code Online (Sandbox Code Playgroud)通过在已安装的应用程序中搜索“tweak tool”或输入gnome-tweak-tool
终端来运行它。
关掉。
就是这样。
gsettings set org.gnome.desktop.interface gtk-enable-primary-paste false
Run Code Online (Sandbox Code Playgroud)
在 16.04 上测试。
小智 53
我意识到这不是您想要的答案,但是您可以在 Firefox 中关闭此功能(例如,如果您不介意其他地方的功能,但仍希望在 Firefox 中单击鼠标中键以在新选项卡中打开链接)
在 about:config 中,设置
middlemouse.contentLoadURL false
middlemouse.paste false
Run Code Online (Sandbox Code Playgroud)
不是你问的问题,但由于这个问题与几个地方有关,我希望有人觉得这个答案有用。
小智 36
Jared Robinson 给出了一个适用于我的机器的简单解决方案:
运行以下命令:
xmodmap -e "pointer = 1 25 3 4 5 6 7 8 9"
Run Code Online (Sandbox Code Playgroud)
要保持此行为,请编辑 ~/.Xmodmap 并添加
pointer = 1 25 3 4 5 6 7 8 9
Run Code Online (Sandbox Code Playgroud)
Mar*_*ppi 22
这目前是不可能的 - 但是,正如您所提到的,有一些方法可以禁用 MOUSE 3 按钮 - 或重新映射它 - 这些都没有找到问题的根源。X11 主要选择。
虽然这不是一个解决方案,但希望这个解释能清楚地说明原因。在 Ubuntu 中有两个剪贴板在工作。每个人都熟悉的 freedesktop.org 剪贴板(捕获Ctrl+C命令)第二个是剪贴板管理器,它在 Ubuntu 出现之前就一直在发挥作用 - X11。X Server (X11) 管理其他三个剪贴板:Primary Selection、Secondary Selection和Clipboard. 当您用指针选择文本时,它会被复制到 XServer 中的缓冲区,即主要选择,并等待通过鼠标 3 按钮粘贴。另外两个被设计为由其他应用程序使用,以在应用程序之间共享公共剪贴板。在这种情况下,Ubuntu 中的 freedesktop.org 剪贴板管理器已经为我们完成了这项工作。
通过我的研究,我找不到禁用 X11 选择管理器的方法。没有可以禁用此功能的编译标志、应用程序或配置值。在每个应用程序的基础上有多种解决方法(这些应用程序中的大多数是命令行应用程序) - 但在全球范围内没有。
我意识到这不是一个理想的解决方案 - 但似乎是问题的真相。我能想到的唯一相关解决方案实际上是一个 hack,创建一个脚本来执行一个无限的 while 循环,该循环只是用空值替换主要选择。
首次安装xsel
(用于操作 X 选择的工具)sudo apt-get install xsel
代码如下:
while(true)
do
echo -n | xsel -n -i
sleep 0.5
done
Run Code Online (Sandbox Code Playgroud)
如果你把它放在一个脚本中并将它添加到你的启动脚本中,这应该不是问题。
Wes*_*ler 21
不知何故,我的 Ubuntu 安装中没有任何 xmodmap 文件,所以我不得不找到一种不同的方法来解决这个问题。
看看xinput命令。
xinput list | grep -i mouse
Run Code Online (Sandbox Code Playgroud)
其中列出了有关您的鼠标的信息。它显示我的鼠标是“Dell Premium USB Optical Mouse”,而且我还有“Macintosh mouse button emulation”。有了这些信息,我可以
xinput get-button-map "Dell Premium USB Optical Mouse"
Run Code Online (Sandbox Code Playgroud)
这给了我一个看起来像的清单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Run Code Online (Sandbox Code Playgroud)
这是有用的、必需的知识。我的鼠标理论上有 18 个按钮。每个按钮的默认操作与其按钮编号具有相同的名称。换句话说,按钮 1 执行动作 1,按钮 4 执行动作 4,等等。动作 0 表示“关闭”。
该位置在清单显示分配给该按钮的功能。所以如果我的按钮映射读取
1 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
这意味着按钮 1(位置 1)执行动作 1(正常左按钮),按钮 2(位置 2)执行动作 3(中间按钮),按钮 3(位置 3)执行动作 2(右按钮)。
要制作左手鼠标,您只需要一个开始的按钮图
3 2 1 4 5 .....
Run Code Online (Sandbox Code Playgroud)
或者,在您的情况下,您似乎希望中间按钮与按钮 1(左按钮)执行相同的操作,因此您的地图需要启动
1 1 3 ....
Run Code Online (Sandbox Code Playgroud)
我会因此重置我的鼠标按钮映射:
xinput set-button-map "Dell Premium USB Optical Mouse" 1 1 3 5 6 6 7 8 9 10 11 12 13 14 15 16 17 18
Run Code Online (Sandbox Code Playgroud)
在您的情况下,您可能有不同数量的映射按钮,并且已经定义了一些特殊的按钮映射。同样,您的鼠标也有不同的名称。首先,获取鼠标的“名称”。然后,使用get-button-map操作来查找您的基本按钮映射。最后,使用set-button-map选项,修改按钮 2 以执行操作 1。
这不是永久性的变化。我将必要的代码添加到我的.bashrc 中,以便在我每次登录或打开终端时执行。
希望这可以帮助。
Jel*_*rts 16
有关问题的解决方案,请查看我写的本指南:
不久前,我写了一个补丁来禁用 GTK 中的“鼠标中键粘贴”功能。我以为会有其他人也想禁用它,因此我想我应该写一个小指南来解释如何实现这一壮举。
现在,有些人可能会问,为什么有人要禁用它?有几个原因:
- 鼠标中键实际上并没有粘贴所谓的 XA_CLIPBOARD 剪贴板,而是 XA_PRIMARY 剪贴板。这对许多人来说可能是违反直觉的(也许来自 Windows 的用户),因此有些人可能认为禁用“不一致”或意外行为对用户更友好。
- 有些人可能会不小心使用鼠标中键粘贴文本,并希望避免这种情况。
关于 XA_CLIPBOARD 和 XA_PRIMARY 剪贴板的一些背景知识: XA_PRIMARY 剪贴板主要用于存储选择。每当您在例如 GNOME 文本编辑器 (gedit) 中选择某些文本时,该文本就会被复制到 XA_PRIMARY 剪贴板。当您使用“编辑 -> 粘贴”菜单项时,不会粘贴此文本,仅当您单击鼠标中键时。XA_CLIPBOARD 剪贴板主要用于使用一般的“复制/粘贴”功能(通过键盘快捷键,例如 CTRL+C 和 CTRL+V,或通过菜单项“编辑 -> 复制”和“编辑 -> 粘贴”) )。
也许这种补丁(或对 X 剪贴板和/或库/应用程序如何使用它的更剧烈的变化)有一天会成为 Linux 的标准。我意识到对此的看法大相径庭。然而,对于那些试图尽量减少意外粘贴一些随机文本的机会的人来说,补丁可能非常有用。例如,使用补丁,您不会意外地将文本粘贴(至少使用鼠标中键)到您正在编辑的文档、网页或即时消息等中。
该指南适用于 Debian 或基于 Debian 的 Linux 发行版,例如 Ubuntu 和 Mint。
下面是终端命令及其功能的简要说明(以 # 开头的行是注释,其中包含这些说明)。仔细阅读说明后,您应该启动终端并一一输入命令。
Run Code Online (Sandbox Code Playgroud)# This is a small guide that explains how to patch GTK so that the middle mouse # button doesn't paste text anymore. # NOTE: # The below instructions are for GTK2. However, they should be easy to adapt # for GTK3 (at the time of writing, the patch works fine for GTK3 too). # First, update the system by first synchronizing the package index files, and # then upgrading the packages. sudo apt-get update sudo apt-get upgrade # Get the build dependencies and essential packages needed in order to compile # code and create packages. sudo apt-get build-dep libgtk2.0-0 sudo apt-get install build-essential # Create a temporary directory, in which we will store the GTK sources and # later on the packages. mkdir /tmp/gtk cd /tmp/gtk # Download the actual patch that will disable the 'middle mouse button paste' # functionality (it should be stored in the directory '/tmp/gtk', and will be, # if you indeed executed the command 'cd /tmp/gtk'). wget http://subversion.assembla.com/svn/slipstream/patches/gtk_disable_middle_mouse_button_paste.patch # Retrieve the GTK sources. apt-get source libgtk2.0-0 # You should adapt this line so that it changes to the correct directory (the # name of the directory that I used here will probably not match the name of # the directory that was created during 'apt-get source libgtk2.0-0', as it # contains a version number that often changes). You can find out what the # correct directory is by entering 'ls -d */' (without the quotes) and looking # at the names of the directories that it shows. cd gtk+2.0-2.20.1 # Apply the patch that we downloaded earlier. patch -p1 < /tmp/gtk/gtk_disable_middle_mouse_button_paste.patch # The output of the previous command should be: # patching file gtk/gtkselection.c # If it wasn't, then something went wrong. Maybe you mistyped something, maybe # the current directory isn't the correct directory, maybe the GTK sources # were changed and the patch doesn't work anymore, etc. # Build the package (you may have to be patient, this may or may not take a # while). dpkg-buildpackage -uc -us --source-option=--auto-commit # You should adapt this line so that it installs the correct package. The # package that we want to install is the package containing the GTK library, # thus _not_ the 'bin', 'udeb', 'common', 'dev', or 'doc' package. To find out # what the exact package is that you should install, try to find the package (a # file with a name ending in '.deb') which is closest to the example filename I # used here (the packages are stored in '/tmp/gtk', and you can list the # packages using the command 'ls /tmp/gtk/*.deb' (without the quotes)). sudo dpkg -i ../libgtk2.0-0_2.20.1-2_i386.deb # And lastly, to make sure that only the patched library is in use, you should # either log out and back in, or restart your computer. # And then, the 'middle mouse button paste' functionality should be disabled. # To test whether it is, try selecting some text in the GNOME Text Editor, or # in a GNOME Terminal, and then press the middle mouse button while the cursor # hovers over some place where you can normally type text. If indeed no text # appears, then it appears that the patch worked. # If however, the patch did not work, try to re-read this document, to see if # you made any mistake. And if you did, you may want to either start all over # again (should be fail-safe), or continue with the guide from the point where # you made a mistake.
或者,更直接地,这是在 GTK 中禁用“鼠标中键粘贴”功能的补丁:
diff -ur gtk+2.0-2.20.1/gtk/gtkselection.c gtk+2.0-2.20.1-patched/gtk/gtkselection.c
--- gtk+2.0-2.20.1/gtk/gtkselection.c 2010-05-01 22:14:29.000000000 -0500
+++ gtk+2.0-2.20.1-patched/gtk/gtkselection.c 2011-09-17 10:45:37.000000000 -0500
@@ -1065,6 +1065,24 @@
display = gtk_widget_get_display (widget);
owner_window = gdk_selection_owner_get_for_display (display, selection);
+ if (selection == gdk_atom_intern("PRIMARY", TRUE)) {
+ GtkSelectionData selection_data;
+
+ selection_data.selection = selection;
+ selection_data.target = target;
+ selection_data.type = gdk_atom_intern("STRING", TRUE);
+ selection_data.format = 8;
+ selection_data.data = (unsigned char *)"";
+ selection_data.length = 0;
+ selection_data.display = display;
+
+ gtk_selection_retrieval_report(info, selection_data.type,
+ selection_data.format, selection_data.data,
+ selection_data.length, time_);
+
+ return TRUE;
+ }
+
if (owner_window != NULL)
{
GtkWidget *owner_widget;
Run Code Online (Sandbox Code Playgroud)
该脚本将禁用鼠标中键粘贴,它支持 Wayland 和 X11,您仍然可以正常使用鼠标中键:
#!/bin/sh
#Script to disable middle mouse paste; Dependencies: xsel, wl-clipboard
if [ "$XDG_SESSION_TYPE" == "wayland" ]; then
wl-paste -p --watch wl-copy -p '' # Usually works.
#wl-paste -p --watch wl-copy -cp # 100% Effective, may cause issues selecting text in GTK applications.
fi
while [ "$XDG_SESSION_TYPE" == "x11" ]; do
xsel -fin </dev/null # 100% Effective, May cause issues selecting text in GTK applications.
done
Run Code Online (Sandbox Code Playgroud)
旧答案(X11 的一种方法,不会导致 GTK 中的文本选择问题):https ://askubuntu.com/revisions/1079832/4
唯一对我有用的答案是在https://unix.stackexchange.com/a/277488/288916 Radivarig上给出的(所有功劳归他所有)。请注意,我必须进行一项更改才能使其正常工作:
安装 xbindkeys:
sudo apt-get install xbindkeys xsel xdotool
Run Code Online (Sandbox Code Playgroud)
~/.xbindkeysrc
使用文本为 xbindkeys 创建配置文件 :
"echo -n | xsel -n -i; pkill xbindkeys; xdotool click 2; xbindkeys"
b:2
Run Code Online (Sandbox Code Playgroud)
使用加载配置文件
xbindkeys -p
Run Code Online (Sandbox Code Playgroud)
将此行添加到,~./bashrc
以便xbindkeys
始终在启动时加载。
这对我有用,但 Radivarig 建议改用这条线
"echo -n | xsel -n -i; pkill xbindkeys; xdotool click 2; xbindkeys"
b:2 + Release
Run Code Online (Sandbox Code Playgroud)
最后一个对我不起作用,但如果其中一个版本不起作用,我建议尝试另一个。
看了很长时间后,这是我发现的唯一解决方案,它可以普遍关闭鼠标中键粘贴按钮,而不必完全禁用鼠标中键。
请注意,对于现有的投票答案,要么他们不回答问题,而是告诉您如何完全禁用鼠标中键,要么他们提供仅适用于少数程序的解决方案(仅在 gedit 和gnome 终端和其他几个)或者他们只是说这是不可能的。
spawn 的回答具有类似的精神,也可能有效,但在找到此解决方案之前我没有看到它。
我建议使用其中一种,这对我来说最有效:
使用 xbindkeys:每当按下中间按钮时,清除主剪贴板。至少在我的系统上,在粘贴发生之前它已被清除。详细信息:创建 xbindkeys-config:
xbindkeys --defaults > $HOME/.xbindkeysrc
Run Code Online (Sandbox Code Playgroud)
粘贴以下新热键:
"xclip -i /dev/null"
b:2``
Run Code Online (Sandbox Code Playgroud)
重新加载 xbindkeys(例如 killall xbindkeys;xbindkeys)。完毕。
使用 xdotool:清除窗口焦点更改时的剪贴板(应该适用于大多数窗口管理器)。详细信息:执行以下命令:
xdotool search --onlyvisible . behave %@ focus exec xclip -i /dev/null
Run Code Online (Sandbox Code Playgroud)
请注意,使用此命令,您仍然可以在同一窗口中使用主剪贴板,或者在聚焦之前将鼠标中键按到另一个窗口上(如果您没有“焦点跟随鼠标”或其他东西被激活)。
小智 5
对于 Gnome 应用程序,您可以在“键盘和鼠标”选项卡下使用gnome-tweaks
(程序包的新名称gnome-tweak-tool
),其中有“中键单击粘贴”选项,或者直接编辑 org.gnome.desktop.interface/gtk-enable-primary-paste Gnome 选项。
对于 KDE 应用程序似乎有一个等效的解决方案。
对于整个 X(包括非 Gnome 应用程序),您可以安装XMousePasteBlock,然后它必须运行(由用户运行就足够了,不需要 root)才能工作。这将完全禁用中键单击粘贴,而不会禁用其他中键单击功能。