Commit 9ff2af5f authored by Pekka Vuorela's avatar Pekka Vuorela

Expose terminal rows and columns as properties

parent caaf20b5
......@@ -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()));
......@@ -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);
}
......
......@@ -38,10 +38,8 @@ public:
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:
......
......@@ -294,9 +294,6 @@ 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\">" +
......@@ -304,11 +301,11 @@ Item {
"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>";
......
......@@ -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
......@@ -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
......@@ -361,8 +361,6 @@ Item {
text: "About"
onClicked: {
menuWin.showing = false;
aboutDialog.termW = term.termSize().width
aboutDialog.termH = term.termSize().height
aboutDialog.show = true
}
}
......
......@@ -128,7 +128,7 @@ void Terminal::setTermSize(QSize size)
resetTabs();
emit termSizeChanged(size);
emit termSizeChanged(size.height(), size.width());
}
}
......@@ -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));
......@@ -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);
......@@ -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;
......
......@@ -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;
......@@ -70,7 +73,7 @@ public:
void setCursorPos(QPoint pos);
bool showCursor();
Q_INVOKABLE QSize termSize() { return iTermSize; }
QSize termSize() { return iTermSize; }
void setTermSize(QSize size);
QList<QList<TermChar> >& buffer();
......@@ -98,11 +101,14 @@ public:
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);
......
......@@ -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);
}
......@@ -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());
......@@ -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;
......
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