diff --git a/src/properties.cpp b/src/properties.cpp index 268c0e49..841279c9 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -164,6 +164,8 @@ void Properties::loadSettings() windowMaximized = m_settings->value(QLatin1String("LastWindowMaximized"), false).toBool(); + swapMouseButtons2and3 = m_settings->value(QLatin1String("SwapMouseButtons2and3"), false).toBool(); + prefDialogSize = m_settings->value(QLatin1String("PrefDialogSize")).toSize(); } @@ -273,6 +275,7 @@ void Properties::saveSettings() m_settings->setValue(QLatin1String("TrimPastedTrailingNewlines"), trimPastedTrailingNewlines); m_settings->setValue(QLatin1String("LastWindowMaximized"), windowMaximized); + m_settings->setValue(QLatin1String("SwapMouseButtons2and3"), swapMouseButtons2and3); m_settings->setValue(QLatin1String("PrefDialogSize"), prefDialogSize); } diff --git a/src/properties.h b/src/properties.h index f8f0b358..96872954 100644 --- a/src/properties.h +++ b/src/properties.h @@ -124,6 +124,7 @@ class Properties bool trimPastedTrailingNewlines; bool windowMaximized; + bool swapMouseButtons2and3; bool useFontBoxDrawingChars; private: diff --git a/src/termwidget.cpp b/src/termwidget.cpp index bea52f3c..309b3847 100644 --- a/src/termwidget.cpp +++ b/src/termwidget.cpp @@ -76,8 +76,17 @@ TermWidgetImpl::TermWidgetImpl(TerminalConfig &cfg, QWidget * parent) disableBracketedPasteMode(Properties::Instance()->m_disableBracketedPasteMode); setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, &QWidget::customContextMenuRequested, - this, &TermWidgetImpl::customContextMenuCall); + + if(Properties::Instance()->swapMouseButtons2and3) + { + connect(this, &QWidget::customContextMenuRequested, + this, &TermWidgetImpl::pasteSelection); + } + else + { + connect(this, &QWidget::customContextMenuRequested, + this, &TermWidgetImpl::customContextMenuCall); + } connect(this, &QTermWidget::urlActivated, this, &TermWidgetImpl::activateUrl); connect(this, &QTermWidget::bell, this, &TermWidgetImpl::bell); @@ -238,6 +247,27 @@ void TermWidgetImpl::bell() { } } +bool TermWidget::eventFilter(QObject * /*obj*/, QEvent * ev) +{ + if (ev->type() == QEvent::MouseButtonPress) + { + QMouseEvent *mev = static_cast(ev); + if ( mev->button() == Qt::MiddleButton ) + { + if(Properties::Instance()->swapMouseButtons2and3) + { + impl()->customContextMenuCall(mev->pos()); + } + else + { + impl()->pasteSelection(); + } + return true; + } + } + return false; +} + TermWidget::TermWidget(TerminalConfig &cfg, QWidget * parent) : QWidget(parent), DBusAddressable(QStringLiteral("/terminals")) @@ -254,6 +284,17 @@ TermWidget::TermWidget(TerminalConfig &cfg, QWidget * parent) setLayout(m_layout); m_layout->addWidget(m_term); + const auto objs = m_term->children(); + + for (QObject *o : objs) + { + // Find TerminalDisplay + if (!o->isWidgetType() || qobject_cast(o)->isHidden()) + { + continue; + } + o->installEventFilter(this); + } propertiesChanged(); diff --git a/src/termwidget.h b/src/termwidget.h index 01c356ce..75600b73 100644 --- a/src/termwidget.h +++ b/src/termwidget.h @@ -50,9 +50,9 @@ class TermWidgetImpl : public QTermWidget void zoomIn(); void zoomOut(); void zoomReset(); + void customContextMenuCall(const QPoint & pos); private slots: - void customContextMenuCall(const QPoint & pos); void activateUrl(const QUrl& url, bool fromContextMenu); void bell(); @@ -87,6 +87,8 @@ class TermWidget : public QWidget, public DBusAddressable void closeTerminal(); #endif + bool eventFilter(QObject * obj, QEvent * evt) override; + signals: void finished(); void renameSession();