Skip to content

Commit

Permalink
Refer from konsole, prohibit to look up the historical information wi…
Browse files Browse the repository at this point in the history
…th the middle mouse scrolling.

There is url can help understanding new code.
https://invent.kde.org/utilities/konsole/-/commit/17c77a8729336c69bdeff970e3674d929b915b17

For function TerminalDisplay::wheelEvent, I get idea from the latest konsole code.
https://invent.kde.org/utilities/konsole/-/blob/master/src/terminalDisplay/TerminalDisplay.cpp#L1662
  • Loading branch information
ch593030323 committed Apr 28, 2022
1 parent 8f63478 commit 17fb53e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 24 deletions.
6 changes: 6 additions & 0 deletions lib/Emulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ ScreenWindow* Emulation::createWindow()
return window;
}

void Emulation::checkScreenInUse()
{
emit primaryScreenInUse(_currentScreen == _screen[0]);
}

Emulation::~Emulation()
{
QListIterator<ScreenWindow*> windowIter(_windows);
Expand All @@ -141,6 +146,7 @@ void Emulation::setScreen(int n)
// tell all windows onto this emulation to switch to the newly active screen
for(ScreenWindow* window : qAsConst(_windows))
window->setScreen(_currentScreen);
checkScreenInUse();
}
}

Expand Down
9 changes: 9 additions & 0 deletions lib/Emulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ public slots:
*/
void flowControlKeyPressed(bool suspendKeyPressed);

/**
* Emitted when the active screen is switched, to indicate whether the primary
* screen is in use.
*/
void primaryScreenInUse(bool use);

/**
* Emitted when the cursor shape or its blinking state is changed via
* DECSCUSR sequences.
Expand Down Expand Up @@ -497,6 +503,9 @@ protected slots:
*/
void bufferedUpdate();

// used to emit the primaryScreenInUse(bool) signal
void checkScreenInUse();

private slots:

// triggered by timer, causes the emulation to send an updated screen image to each
Expand Down
17 changes: 16 additions & 1 deletion lib/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Session::Session(QObject* parent) :
// , _zmodemProc(0)
// , _zmodemProgress(0)
, _hasDarkBackground(false)
, _isPrimaryScreen(true)
{
//prepare DBus communication
// new SessionAdaptor(this);
Expand All @@ -94,7 +95,8 @@ Session::Session(QObject* parent) :
this, SIGNAL( changeTabTextColorRequest( int ) ) );
connect( _emulation, SIGNAL(profileChangeCommandReceived(const QString &)),
this, SIGNAL( profileChangeCommandReceived(const QString &)) );

connect(_emulation, &Konsole::Emulation::primaryScreenInUse,
this, &Session::onPrimaryScreenInUse);
connect(_emulation, SIGNAL(imageResizeRequest(QSize)),
this, SLOT(onEmulationSizeChange(QSize)));
connect(_emulation, SIGNAL(imageSizeChanged(int, int)),
Expand Down Expand Up @@ -204,6 +206,8 @@ void Session::addView(TerminalDisplay * widget)
SLOT(viewDestroyed(QObject *)) );
//slot for close
QObject::connect(this, SIGNAL(finished()), widget, SLOT(close()));
//slot for primaryScreen
QObject::connect(this, &Session::primaryScreenInUse, widget, &TerminalDisplay::usingPrimaryScreen);

}

Expand Down Expand Up @@ -448,6 +452,11 @@ void Session::monitorTimerDone()
_notifiedActivity=false;
}

bool Session::isPrimaryScreen()
{
return _isPrimaryScreen;
}

void Session::activityStateSet(int state)
{
if (state==NOTIFYBELL) {
Expand Down Expand Up @@ -485,6 +494,12 @@ void Session::onEmulationSizeChange(QSize size)
setSize(size);
}

void Session::onPrimaryScreenInUse(bool use)
{
_isPrimaryScreen = use;
emit primaryScreenInUse(use);
}

void Session::updateTerminalSize()
{
QListIterator<TerminalDisplay *> viewIter(_views);
Expand Down
17 changes: 17 additions & 0 deletions lib/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ class Session : public QObject {
*/
int getPtySlaveFd() const;

// Returns true if the current screen is the secondary/alternate one
// or false if it's the primary/normal buffer
bool isPrimaryScreen();

public slots:

/**
Expand Down Expand Up @@ -480,6 +484,15 @@ public slots:
*/
void flowControlEnabledChanged(bool enabled);

/**
* Emitted when the active screen is switched, to indicate whether the primary
* screen is in use.
*
* This signal serves as a relayer of Emulation::priamyScreenInUse(bool),
* making it usable for higher level component.
*/
void primaryScreenInUse(bool use);

/**
* Broker for Emulation::cursorChanged() signal
*/
Expand Down Expand Up @@ -509,6 +522,9 @@ private slots:
// void zmodemRcvBlock(const char *data, int len);
// void zmodemFinished();

// Relays the signal from Emulation and sets _isPrimaryScreen
void onPrimaryScreenInUse(bool use);

private:

void updateTerminalSize();
Expand Down Expand Up @@ -570,6 +586,7 @@ private slots:

int ptySlaveFd;

bool _isPrimaryScreen;
};

/**
Expand Down
45 changes: 22 additions & 23 deletions lib/TerminalDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ TerminalDisplay::TerminalDisplay(QWidget *parent)
,_terminalSizeStartup(true)
,_bidiEnabled(false)
,_mouseMarks(false)
,_isPrimaryScreen(true)
,_disabledBracketedPasteMode(false)
,_actSel(0)
,_wordSelectionMode(false)
Expand Down Expand Up @@ -2554,17 +2555,13 @@ void TerminalDisplay::wheelEvent( QWheelEvent* ev )
if (ev->angleDelta().y() == 0)
return;

// if the terminal program is not interested mouse events
// then send the event to the scrollbar if the slider has room to move
// or otherwise send simulated up / down key presses to the terminal program
// for the benefit of programs such as 'less'
if ( _mouseMarks )
{
bool canScroll = _scrollBar->maximum() > 0;
if (canScroll)
_scrollBar->event(ev);
else
if (_mouseMarks && _scrollBar->maximum() > 0)
{
// If the program running in the terminal is not interested in
// Mouse events, send the event to the scrollbar if the slider
// has room to move
_scrollBar->event(ev);
} else if(_mouseMarks && !_isPrimaryScreen) {
// assume that each Up / Down key event will cause the terminal application
// to scroll by one line.
//
Expand All @@ -2581,21 +2578,18 @@ void TerminalDisplay::wheelEvent( QWheelEvent* ev )

for (int i=0;i<linesToScroll;i++)
emit keyPressedSignal(&keyScrollEvent, false);
}
}
else
{
// terminal program wants notification of mouse activity
} else if(!_mouseMarks) {
// terminal program wants notification of mouse activity

int charLine;
int charColumn;
getCharacterPosition( ev->position() , charLine , charColumn );
int charLine;
int charColumn;
getCharacterPosition( ev->pos() , charLine , charColumn );

emit mouseSignal( ev->angleDelta().y() > 0 ? 4 : 5,
charColumn + 1,
charLine + 1 +_scrollBar->value() -_scrollBar->maximum() ,
0);
}
emit mouseSignal( ev->angleDelta().y() > 0 ? 4 : 5,
charColumn + 1,
charLine + 1 +_scrollBar->value() -_scrollBar->maximum() ,
0);
}
}

void TerminalDisplay::tripleClickTimeout()
Expand Down Expand Up @@ -2700,6 +2694,11 @@ bool TerminalDisplay::usesMouse() const
return _mouseMarks;
}

void TerminalDisplay::usingPrimaryScreen(bool use)
{
_isPrimaryScreen = use;
}

void TerminalDisplay::setBracketedPasteMode(bool on)
{
_bracketedPasteMode = on;
Expand Down
10 changes: 10 additions & 0 deletions lib/TerminalDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,15 @@ public slots:
/** See setUsesMouse() */
bool usesMouse() const;

/**
* Sets _isPrimaryScreen depending on which screen is currently in
* use, primary or alternate
*
* @param use Set to @c true if the primary screen is in use or to
* @c false otherwise (i.e. the alternate screen is in use)
*/
void usingPrimaryScreen(bool use);

void setBracketedPasteMode(bool bracketedPasteMode);
bool bracketedPasteMode() const;

Expand Down Expand Up @@ -767,6 +776,7 @@ private slots:
bool _terminalSizeStartup;
bool _bidiEnabled;
bool _mouseMarks;
bool _isPrimaryScreen;
bool _bracketedPasteMode;
bool _disabledBracketedPasteMode;

Expand Down

0 comments on commit 17fb53e

Please sign in to comment.