Skip to content

Commit

Permalink
Putty-Style-Mousebutton-Swap (#1071)
Browse files Browse the repository at this point in the history
* Adding putty style mousebutton swap

* Adding putty style mousebutton swap

* Adding putty style mousebutton swap

* code changes as requested

* fixed letter in swapMouseButtons2and3

* did miss behind commit

* fixed tabs

* requested fixes to termwidget.cpp

* fixed tabs

* Update termwidget.h - fix tabs

* Replace remaining tabs with spaces

---------

Co-authored-by: macz <[email protected]>
Co-authored-by: Chih-Hsuan Yen <[email protected]>
  • Loading branch information
3 people authored Sep 30, 2023
1 parent 5872777 commit 7100d5a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
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;
}
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

0 comments on commit 7100d5a

Please sign in to comment.