Commit 9ffa69e1 authored by Tomas Mecir's avatar Tomas Mecir

don't spam NAWS all the time

parent faa01e04
......@@ -293,6 +293,9 @@ void cTelnet::reset ()
//reset telnet status
d->iac = d->iac2 = d->insb = false;
d->command = "";
// reset these so that we report dimensions correctly
d->curX = 0;
d->curY = 0;
}
void cTelnet::socketConnected ()
......@@ -519,39 +522,37 @@ void cTelnet::windowSizeChanged (int x, int y)
//remember the size - we'll need it if NAWS is currently disabled but will
//be enabled. Also remember it if no connection exists at the moment;
//we won't be called again when connecting
d->curX = x;
d->curY = y;
if (!(isConnected()))
return;
if (d->myOptionState[OPT_NAWS]) //only if we have negotiated this option
{
string s;
s = TN_IAC;
s += TN_SB;
s += OPT_NAWS;
unsigned char x1, x2, y1, y2;
x1 = (unsigned char) x / 256;
x2 = (unsigned char) x % 256;
y1 = (unsigned char) y / 256;
y2 = (unsigned char) y % 256;
//IAC must be doubled
s += x1;
if (x1 == TN_IAC)
s += TN_IAC;
s += x2;
if (x2 == TN_IAC)
s += TN_IAC;
s += y1;
if (y1 == TN_IAC)
s += TN_IAC;
s += y2;
if (y2 == TN_IAC)
s += TN_IAC;
if (!d->myOptionState[OPT_NAWS]) return; //only if we have negotiated this option
if ((x == d->curX) && (y == d->curY)) return; // don't spam sizes if we have sent the current one already
string s;
s = TN_IAC;
s += TN_SB;
s += OPT_NAWS;
unsigned char x1, x2, y1, y2;
x1 = (unsigned char) x / 256;
x2 = (unsigned char) x % 256;
y1 = (unsigned char) y / 256;
y2 = (unsigned char) y % 256;
//IAC must be doubled
s += x1;
if (x1 == TN_IAC)
s += TN_IAC;
s += TN_SE;
doSendData (s);
}
s += x2;
if (x2 == TN_IAC)
s += TN_IAC;
s += y1;
if (y1 == TN_IAC)
s += TN_IAC;
s += y2;
if (y2 == TN_IAC)
s += TN_IAC;
s += TN_IAC;
s += TN_SE;
doSendData (s);
}
void cTelnet::sendTelnetOption (unsigned char type, unsigned char option)
......
......@@ -218,7 +218,7 @@ cConsole::cConsole(QWidget *parent) : QGraphicsView(parent) {
viewport()->setCursor (Qt::IBeamCursor);
forceBeginOfLine ();
fixupOutput();
fixupOutput(true);
}
cConsole::~cConsole() {
......@@ -242,7 +242,7 @@ void cConsole::setFont (QFont f) {
d->charWidth = fm.width ("m");
d->charHeight = fm.lineSpacing() + 2;
fixupOutput();
fixupOutput(true);
}
QFont cConsole::font () {
......@@ -415,7 +415,7 @@ void cConsole::addNewText (cTextChunk *chunk, bool endTheLine)
if (!d->atBottom) bar->setValue (bar->value() - fheight);
}
fixupOutput();
fixupOutput(false);
}
void cConsole::forceBeginOfLine () {
......@@ -459,14 +459,14 @@ void cConsole::pageDown () {
void cConsole::resizeEvent (QResizeEvent *)
{
fixupOutput();
fixupOutput(true);
}
// this is needed to resize the text display at startup
bool cConsole::viewportEvent(QEvent *event)
{
if (event->type() == QEvent::Resize)
fixupOutput();
fixupOutput(true);
return QGraphicsView::viewportEvent (event);
}
......@@ -493,7 +493,7 @@ void cConsole::scrollContentsBy (int dx, int dy)
adjustScrollBack();
}
void cConsole::fixupOutput ()
void cConsole::fixupOutput (bool sizeChanged)
{
double h = max ((qreal) viewport()->height(), d->text->documentLayout()->documentSize().height());
scene()->setSceneRect (0, 0, viewport()->width(), h);
......@@ -503,7 +503,8 @@ void cConsole::fixupOutput ()
d->scrollText->updateSize();
adjustScrollBack ();
forceEmitSize ();
if (sizeChanged)
forceEmitSize ();
}
void cConsole::linkHovered (const QString &link)
......
......@@ -116,7 +116,7 @@ protected:
bool viewportEvent(QEvent *event) override;
virtual void scrollContentsBy (int dx, int dy) override;
/** called when resizing and when changing font */
void fixupOutput ();
void fixupOutput (bool sizeChanged = false);
void adjustScrollBack ();
void addNewText (cTextChunk *chunk, bool endTheLine);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment