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

Putty-Style-Mousebutton-Swap #1071

Merged
merged 12 commits into from
Sep 30, 2023
3 changes: 3 additions & 0 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class Properties
bool trimPastedTrailingNewlines;

bool windowMaximized;
bool swapMouseButtons2and3;

bool useFontBoxDrawingChars;
private:
Expand Down
45 changes: 43 additions & 2 deletions src/termwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -238,6 +247,27 @@ void TermWidgetImpl::bell() {
}
}

bool TermWidget::eventFilter(QObject * /*obj*/, QEvent * ev)
{
if (ev->type() == QEvent::MouseButtonPress)
{
QMouseEvent *mev = static_cast<QMouseEvent*>(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"))
Expand All @@ -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<QWidget*>(o)->isHidden())
{
continue;
macrl2000 marked this conversation as resolved.
Show resolved Hide resolved
}
o->installEventFilter(this);
}

propertiesChanged();

Expand Down
4 changes: 3 additions & 1 deletion src/termwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
Loading