Disable/modify middle-click-to-paste in X11/Xorg

5,629

You can modify ButtonMapping Option in X config: http://www.linuxquestions.org/questions/linux-newbie-8/disable-xorgs-highlight-to-copy-middle-click-to-paste-clipboard-647810/

Option "ButtonMapping" "1 1 3 4 5"

Update: in the thread: https://askubuntu.com/questions/4507/how-do-i-disable-middle-mouse-button-click-paste

the patch to gtk is linked, which will disable middle button as paste: http://subversion.assembla.com/svn/slipstream/patches/gtk_disable_middle_mouse_button_paste.patch

There is an overview of middle button action in different graphic libs/applications: http://os.livejournal.com/811721.html - so I can assume that middleButton action as XA_PRIMARY Paste is not hardcoded in Xorg/Xserver itself (after searching in sources for hour)

And here is likely the handling of middle button in QT:

qt/src/gui/text/qtextcontrol.cpp

void QTextControlPrivate::mouseReleaseEvent (...
...
} else if (button == Qt::MidButton
           && (interactionFlags & Qt::TextEditable)
           && QApplication::clipboard()->supportsSelection()) {
    setCursorPosition(pos);
    const QMimeData *md = QApplication::clipboard()->mimeData(QClipboard::Selection);
    if (md)
        q->insertFromMimeData(md);

Also here for lineedit: qt/src/gui/widgets/qlineedit.cpp

void QLineEdit::mouseReleaseEvent(QMouseEvent* e)
...
    } else if (!d->readOnly && e->button() == Qt::MidButton) {
        d->deselect();
        insert(QApplication::clipboard()->text(QClipboard::Selection));

and may be here for qt3 compat layer: qt/src/qt3support/text/q3textedit.cpp

void Q3TextEdit::contentsMouseReleaseEvent(QMouseEvent * e)
...
else if (e->button() == Qt::MidButton && !isReadOnly()) {
    // only do middle-click pasting on systems that have selections (ie. X11)
    if (QApplication::clipboard()->supportsSelection()) {

So, you can download QT sources and comment this if branch to disable Midbutton action as paste.

After patching QT & GTK you should only compile them and install instead system's gtk and QT (or place in some dir e.g. /usr/local/lib and put this dir in /etc/ld.so.conf) earlier. Then every dynamically linked application will use patched gtk/QT lib and will not paste anything for middle button press.

If the application linked statically, you should recompile it with patched static library or to recompile it into dynamically linked.

If you need more graphic toolkits to be patched just say name of the toolkit and I will try to find source point of middle button handling as paste.

Share:
5,629

Related videos on Youtube

Cloud
Author by

Cloud

Updated on September 18, 2022

Comments

  • Cloud
    Cloud over 1 year

    I am using Slackware 13.1 (kernel 2.6) with FVWM as my desktop manager.

    I have frequently had issues when coding where my over-sensitive mouse registers a middle-button (mouse-wheel) click while scrolling with the mouse-wheel.

    Is there any way to modify the shortcut so that middle-click no longer pastes using the built-in clipboard with X11/Xorg/Xfree86? I would prefer if it were re-mapped to something like +MiddleClick, or something similar.

    I have searched through the forums already, and have found some suggestions using XMODMAP, but none have worked so far.

    Thank you all in advance for your time and assistance.

    • Luc M
      Luc M over 12 years
      It could help if you tell what you tried.
    • Arsen Ghazaryan
      Arsen Ghazaryan over 12 years
      Can you say what was tried by you? And give links to forums. I was only able to find this askubuntu.com/questions/4507/…
  • Marius
    Marius over 5 years
    Except for the first couple of lines (which applies to fvwm), this deals with different libraries than fvwm actually uses.