Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose terminal rows and columns as properties
  • Loading branch information
pvuorela committed Jun 27, 2016
1 parent caaf20b commit 9ff2af5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 31 deletions.
10 changes: 5 additions & 5 deletions ptyiface.cpp
Expand Up @@ -68,8 +68,8 @@ PtyIFace::PtyIFace(int pid, int masterFd, Terminal *term, QString charset, QObje

iTerm->setPtyIFace(this);

resize(iTerm->termSize());
connect(iTerm,SIGNAL(termSizeChanged(QSize)),this,SLOT(resize(QSize)));
resize(iTerm->rows(), iTerm->columns());
connect(iTerm,SIGNAL(termSizeChanged(int,int)),this,SLOT(resize(int,int)));

iReadNotifier = new QSocketNotifier(iMasterFd, QSocketNotifier::Read, this);
connect(iReadNotifier,SIGNAL(activated(int)),this,SLOT(readActivated()));
Expand Down Expand Up @@ -104,14 +104,14 @@ void PtyIFace::readActivated()
iTerm->insertInBuffer( iTextCodec->toUnicode(data) );
}

void PtyIFace::resize(QSize newSize)
void PtyIFace::resize(int rows, int columns)
{
if(childProcessQuit)
return;

winsize winp;
winp.ws_col = newSize.width();
winp.ws_row = newSize.height();
winp.ws_col = columns;
winp.ws_row = rows;

ioctl(iMasterFd, TIOCSWINSZ, &winp);
}
Expand Down
4 changes: 1 addition & 3 deletions ptyiface.h
Expand Up @@ -38,10 +38,8 @@ class PtyIFace : public QObject
void writeTerm(const QString &chars);
bool failed() { return iFailed; }

public slots:
void resize(QSize newSize);

private slots:
void resize(int rows, int columns);
void readActivated();

private:
Expand Down
7 changes: 2 additions & 5 deletions qml/Main.qml
Expand Up @@ -294,21 +294,18 @@ Item {
NotifyWin {
id: aboutDialog

property int termW
property int termH

text: {
var str = "<font size=\"+3\">FingerTerm " + util.versionString() + "</font><br>\n" +
"<font size=\"+1\">" +
"by Heikki Holstila &lt;<a href=\"mailto:heikki.holstila@gmail.com?subject=FingerTerm\">heikki.holstila@gmail.com</a>&gt;<br><br>\n\n" +
"Config files for adjusting settings are at:<br>\n" +
util.configPath() + "/<br><br>\n" +
"Source code:<br>\n<a href=\"https://git.merproject.org/mer-core/fingerterm/\">https://git.merproject.org/mer-core/fingerterm/</a>"
if (termH != 0 && termW != 0) {
if (term.rows != 0 && term.columns != 0) {
str += "<br><br>Current window title: <font color=\"gray\">" + util.windowTitle.substring(0,40) + "</font>"; //cut long window title
if(util.windowTitle.length>40)
str += "...";
str += "<br>Current terminal size: <font color=\"gray\">" + termW + "x" + termH + "</font>";
str += "<br>Current terminal size: <font color=\"gray\">" + term.columns + "×" + term.rows + "</font>";
str += "<br>Charset: <font color=\"gray\">" + util.charset + "</font>";
}
str += "</font>";
Expand Down
6 changes: 2 additions & 4 deletions qml/MenuFingerterm.qml
Expand Up @@ -176,7 +176,7 @@ Item {
text: "<font size=\"+3\">+</font>"
onClicked: {
util.fontSize = util.fontSize + window.pixelRatio
util.notifyText(term.termSize().width+"x"+term.termSize().height);
util.notifyText(term.columns + "×" + term.rows);
}
width: window.buttonWidthHalf
height: window.buttonHeightSmall
Expand All @@ -185,7 +185,7 @@ Item {
text: "<font size=\"+3\">-</font>"
onClicked: {
util.fontSize = util.fontSize - window.pixelRatio
util.notifyText(term.termSize().width+"x"+term.termSize().height);
util.notifyText(term.columns + "×" + term.rows);
}
width: window.buttonWidthHalf
height: window.buttonHeightSmall
Expand Down Expand Up @@ -361,8 +361,6 @@ Item {
text: "About"
onClicked: {
menuWin.showing = false;
aboutDialog.termW = term.termSize().width
aboutDialog.termH = term.termSize().height
aboutDialog.show = true
}
}
Expand Down
18 changes: 14 additions & 4 deletions terminal.cpp
Expand Up @@ -128,7 +128,7 @@ void Terminal::setTermSize(QSize size)

resetTabs();

emit termSizeChanged(size);
emit termSizeChanged(size.height(), size.width());
}
}

Expand Down Expand Up @@ -349,7 +349,7 @@ void Terminal::insertInBuffer(const QString& chars)
if(iNewLineMode)
setCursorPos(QPoint(1,cursorPos().y()));
}
else if(cursorPos().x() <= termSize().width()) // ignore newline after <termwidth> cols (terminfo: xenl)
else if(cursorPos().x() <= columns()) // ignore newline after <termwidth> cols (terminfo: xenl)
{
if(iNewLineMode)
setCursorPos(QPoint(1,cursorPos().y()+1));
Expand Down Expand Up @@ -1046,9 +1046,9 @@ void Terminal::escControlChar(const QString& seq)
return;
if( seq.at(0) == '#' && seq.at(1)=='8' ) { // test mode, fill screen with 'E'
clearAll(true);
for(int i=0; i<termSize().height(); i++) {
for (int i = 0; i < rows(); i++) {
QList<TermChar> line;
for(int j=0; j<termSize().width(); j++) {
for(int j = 0; j < columns(); j++) {
TermChar c = zeroChar;
c.c = 'E';
line.append(c);
Expand Down Expand Up @@ -1498,6 +1498,16 @@ void Terminal::clearSelection()
emit selectionChanged();
}

int Terminal::rows()
{
return iTermSize.height();
}

int Terminal::columns()
{
return iTermSize.width();
}

QRect Terminal::selection()
{
return iSelection;
Expand Down
10 changes: 8 additions & 2 deletions terminal.h
Expand Up @@ -53,6 +53,9 @@ struct TermAttribs {
class Terminal : public QObject
{
Q_OBJECT
Q_PROPERTY(int rows READ rows NOTIFY termSizeChanged)
Q_PROPERTY(int columns READ columns NOTIFY termSizeChanged)

public:
static const int defaultFgColor = 7;
static const int defaultBgColor = 0;
Expand All @@ -70,7 +73,7 @@ class Terminal : public QObject
void setCursorPos(QPoint pos);
bool showCursor();

Q_INVOKABLE QSize termSize() { return iTermSize; }
QSize termSize() { return iTermSize; }
void setTermSize(QSize size);

QList<QList<TermChar> >& buffer();
Expand Down Expand Up @@ -98,11 +101,14 @@ class Terminal : public QObject
Q_INVOKABLE void clearSelection();
bool hasSelection();

int rows();
int columns();

TermChar zeroChar;

signals:
void cursorPosChanged(QPoint newPos);
void termSizeChanged(QSize newSize);
void termSizeChanged(int rows, int columns);
void displayBufferChanged();
void selectionChanged();
void scrollBackBufferAdjusted(bool reset);
Expand Down
16 changes: 8 additions & 8 deletions textrender.cpp
Expand Up @@ -106,17 +106,17 @@ void TextRender::paint(QPainter* painter)
if(from<0)
from=0;
int to = sTerm->backBuffer().size();
if(to-from > sTerm->termSize().height())
to = from + sTerm->termSize().height();
if(to-from > sTerm->rows())
to = from + sTerm->rows();
paintFromBuffer(painter, sTerm->backBuffer(), from, to, y);
if(to-from < sTerm->termSize().height() && sTerm->buffer().size()>0) {
int to2 = sTerm->termSize().height() - (to-from);
if(to-from < sTerm->rows() && sTerm->buffer().size()>0) {
int to2 = sTerm->rows() - (to-from);
if(to2 > sTerm->buffer().size())
to2 = sTerm->buffer().size();
paintFromBuffer(painter, sTerm->buffer(), 0, to2, y);
}
} else {
int count = qMin(sTerm->termSize().height(), sTerm->buffer().size());
int count = qMin(sTerm->rows(), sTerm->buffer().size());
paintFromBuffer(painter, sTerm->buffer(), 0, count, y);
}

Expand Down Expand Up @@ -145,12 +145,12 @@ void TextRender::paint(QPainter* painter)
end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight());
} else {
start = charsToPixels(selection.topLeft());
end = charsToPixels(QPoint(sTerm->termSize().width(), selection.top()));
end = charsToPixels(QPoint(sTerm->columns(), selection.top()));
painter->drawRect(start.x(), start.y(),
end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight());

start = charsToPixels(QPoint(1, selection.top()+1));
end = charsToPixels(QPoint(sTerm->termSize().width(), selection.bottom()-1));
end = charsToPixels(QPoint(sTerm->columns(), selection.bottom()-1));
painter->drawRect(start.x(), start.y(),
end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight());

Expand Down Expand Up @@ -181,7 +181,7 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf
else
painter->setOpacity(1.0);

int xcount = qMin(buffer.at(i).count(), sTerm->termSize().width());
int xcount = qMin(buffer.at(i).count(), sTerm->columns());

// background for the current line
currentX = leftmargin;
Expand Down

0 comments on commit 9ff2af5

Please sign in to comment.