Skip to content

Commit 6c19cb0

Browse files
committed
Refer from konsole, prohibit to look up the historical information with the middle mouse scrolling.
https://invent.kde.org/utilities/konsole/-/commit/17c77a8729336c69bdeff970e3674d929b915b17
1 parent 8f63478 commit 6c19cb0

File tree

6 files changed

+80
-24
lines changed

6 files changed

+80
-24
lines changed

lib/Emulation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ ScreenWindow* Emulation::createWindow()
118118
return window;
119119
}
120120

121+
void Emulation::checkScreenInUse()
122+
{
123+
emit primaryScreenInUse(_currentScreen == _screen[0]);
124+
}
125+
121126
Emulation::~Emulation()
122127
{
123128
QListIterator<ScreenWindow*> windowIter(_windows);
@@ -141,6 +146,7 @@ void Emulation::setScreen(int n)
141146
// tell all windows onto this emulation to switch to the newly active screen
142147
for(ScreenWindow* window : qAsConst(_windows))
143148
window->setScreen(_currentScreen);
149+
checkScreenInUse();
144150
}
145151
}
146152

lib/Emulation.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ public slots:
433433
*/
434434
void flowControlKeyPressed(bool suspendKeyPressed);
435435

436+
/**
437+
* Emitted when the active screen is switched, to indicate whether the primary
438+
* screen is in use.
439+
*/
440+
void primaryScreenInUse(bool use);
441+
436442
/**
437443
* Emitted when the cursor shape or its blinking state is changed via
438444
* DECSCUSR sequences.
@@ -497,6 +503,9 @@ protected slots:
497503
*/
498504
void bufferedUpdate();
499505

506+
// used to emit the primaryScreenInUse(bool) signal
507+
void checkScreenInUse();
508+
500509
private slots:
501510

502511
// triggered by timer, causes the emulation to send an updated screen image to each

lib/Session.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Session::Session(QObject* parent) :
7171
// , _zmodemProc(0)
7272
// , _zmodemProgress(0)
7373
, _hasDarkBackground(false)
74+
, _isPrimaryScreen(true)
7475
{
7576
//prepare DBus communication
7677
// new SessionAdaptor(this);
@@ -94,7 +95,8 @@ Session::Session(QObject* parent) :
9495
this, SIGNAL( changeTabTextColorRequest( int ) ) );
9596
connect( _emulation, SIGNAL(profileChangeCommandReceived(const QString &)),
9697
this, SIGNAL( profileChangeCommandReceived(const QString &)) );
97-
98+
connect(_emulation, &Konsole::Emulation::primaryScreenInUse,
99+
this, &Session::onPrimaryScreenInUse);
98100
connect(_emulation, SIGNAL(imageResizeRequest(QSize)),
99101
this, SLOT(onEmulationSizeChange(QSize)));
100102
connect(_emulation, SIGNAL(imageSizeChanged(int, int)),
@@ -204,6 +206,8 @@ void Session::addView(TerminalDisplay * widget)
204206
SLOT(viewDestroyed(QObject *)) );
205207
//slot for close
206208
QObject::connect(this, SIGNAL(finished()), widget, SLOT(close()));
209+
//slot for primaryScreen
210+
QObject::connect(this, &Session::primaryScreenInUse, widget, &TerminalDisplay::usingPrimaryScreen);
207211

208212
}
209213

@@ -448,6 +452,11 @@ void Session::monitorTimerDone()
448452
_notifiedActivity=false;
449453
}
450454

455+
bool Session::isPrimaryScreen()
456+
{
457+
return _isPrimaryScreen;
458+
}
459+
451460
void Session::activityStateSet(int state)
452461
{
453462
if (state==NOTIFYBELL) {
@@ -485,6 +494,12 @@ void Session::onEmulationSizeChange(QSize size)
485494
setSize(size);
486495
}
487496

497+
void Session::onPrimaryScreenInUse(bool use)
498+
{
499+
_isPrimaryScreen = use;
500+
emit primaryScreenInUse(use);
501+
}
502+
488503
void Session::updateTerminalSize()
489504
{
490505
QListIterator<TerminalDisplay *> viewIter(_views);

lib/Session.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ class Session : public QObject {
375375
*/
376376
int getPtySlaveFd() const;
377377

378+
// Returns true if the current screen is the secondary/alternate one
379+
// or false if it's the primary/normal buffer
380+
bool isPrimaryScreen();
381+
378382
public slots:
379383

380384
/**
@@ -480,6 +484,15 @@ public slots:
480484
*/
481485
void flowControlEnabledChanged(bool enabled);
482486

487+
/**
488+
* Emitted when the active screen is switched, to indicate whether the primary
489+
* screen is in use.
490+
*
491+
* This signal serves as a relayer of Emulation::priamyScreenInUse(bool),
492+
* making it usable for higher level component.
493+
*/
494+
void primaryScreenInUse(bool use);
495+
483496
/**
484497
* Broker for Emulation::cursorChanged() signal
485498
*/
@@ -509,6 +522,9 @@ private slots:
509522
// void zmodemRcvBlock(const char *data, int len);
510523
// void zmodemFinished();
511524

525+
// Relays the signal from Emulation and sets _isPrimaryScreen
526+
void onPrimaryScreenInUse(bool use);
527+
512528
private:
513529

514530
void updateTerminalSize();
@@ -570,6 +586,7 @@ private slots:
570586

571587
int ptySlaveFd;
572588

589+
bool _isPrimaryScreen;
573590
};
574591

575592
/**

lib/TerminalDisplay.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ TerminalDisplay::TerminalDisplay(QWidget *parent)
334334
,_terminalSizeStartup(true)
335335
,_bidiEnabled(false)
336336
,_mouseMarks(false)
337+
,_isPrimaryScreen(true)
337338
,_disabledBracketedPasteMode(false)
338339
,_actSel(0)
339340
,_wordSelectionMode(false)
@@ -2554,17 +2555,13 @@ void TerminalDisplay::wheelEvent( QWheelEvent* ev )
25542555
if (ev->angleDelta().y() == 0)
25552556
return;
25562557

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

25822579
for (int i=0;i<linesToScroll;i++)
25832580
emit keyPressedSignal(&keyScrollEvent, false);
2584-
}
2585-
}
2586-
else
2587-
{
2588-
// terminal program wants notification of mouse activity
2581+
} else if(!_mouseMarks) {
2582+
// terminal program wants notification of mouse activity
25892583

2590-
int charLine;
2591-
int charColumn;
2592-
getCharacterPosition( ev->position() , charLine , charColumn );
2584+
int charLine;
2585+
int charColumn;
2586+
getCharacterPosition( ev->pos() , charLine , charColumn );
25932587

2594-
emit mouseSignal( ev->angleDelta().y() > 0 ? 4 : 5,
2595-
charColumn + 1,
2596-
charLine + 1 +_scrollBar->value() -_scrollBar->maximum() ,
2597-
0);
2598-
}
2588+
emit mouseSignal( ev->angleDelta().y() > 0 ? 4 : 5,
2589+
charColumn + 1,
2590+
charLine + 1 +_scrollBar->value() -_scrollBar->maximum() ,
2591+
0);
2592+
}
25992593
}
26002594

26012595
void TerminalDisplay::tripleClickTimeout()
@@ -2700,6 +2694,11 @@ bool TerminalDisplay::usesMouse() const
27002694
return _mouseMarks;
27012695
}
27022696

2697+
void TerminalDisplay::usingPrimaryScreen(bool use)
2698+
{
2699+
_isPrimaryScreen = use;
2700+
}
2701+
27032702
void TerminalDisplay::setBracketedPasteMode(bool on)
27042703
{
27052704
_bracketedPasteMode = on;

lib/TerminalDisplay.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,15 @@ public slots:
505505
/** See setUsesMouse() */
506506
bool usesMouse() const;
507507

508+
/**
509+
* Sets _isPrimaryScreen depending on which screen is currently in
510+
* use, primary or alternate
511+
*
512+
* @param use Set to @c true if the primary screen is in use or to
513+
* @c false otherwise (i.e. the alternate screen is in use)
514+
*/
515+
void usingPrimaryScreen(bool use);
516+
508517
void setBracketedPasteMode(bool bracketedPasteMode);
509518
bool bracketedPasteMode() const;
510519

@@ -767,6 +776,7 @@ private slots:
767776
bool _terminalSizeStartup;
768777
bool _bidiEnabled;
769778
bool _mouseMarks;
779+
bool _isPrimaryScreen;
770780
bool _bracketedPasteMode;
771781
bool _disabledBracketedPasteMode;
772782

0 commit comments

Comments
 (0)