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 ...@@ -68,8 +68,8 @@ PtyIFace::PtyIFace(int pid, int masterFd, Terminal *term, QString charset, QObje
iTerm->setPtyIFace(this); iTerm->setPtyIFace(this);
resize(iTerm->termSize()); resize(iTerm->rows(), iTerm->columns());
connect(iTerm,SIGNAL(termSizeChanged(QSize)),this,SLOT(resize(QSize))); connect(iTerm,SIGNAL(termSizeChanged(int,int)),this,SLOT(resize(int,int)));
iReadNotifier = new QSocketNotifier(iMasterFd, QSocketNotifier::Read, this); iReadNotifier = new QSocketNotifier(iMasterFd, QSocketNotifier::Read, this);
connect(iReadNotifier,SIGNAL(activated(int)),this,SLOT(readActivated())); connect(iReadNotifier,SIGNAL(activated(int)),this,SLOT(readActivated()));
...@@ -104,14 +104,14 @@ void PtyIFace::readActivated() ...@@ -104,14 +104,14 @@ void PtyIFace::readActivated()
iTerm->insertInBuffer( iTextCodec->toUnicode(data) ); iTerm->insertInBuffer( iTextCodec->toUnicode(data) );
} }
void PtyIFace::resize(QSize newSize) void PtyIFace::resize(int rows, int columns)
{ {
if(childProcessQuit) if(childProcessQuit)
return; return;
winsize winp; winsize winp;
winp.ws_col = newSize.width(); winp.ws_col = columns;
winp.ws_row = newSize.height(); winp.ws_row = rows;
ioctl(iMasterFd, TIOCSWINSZ, &winp); ioctl(iMasterFd, TIOCSWINSZ, &winp);
} }
......
...@@ -38,10 +38,8 @@ public: ...@@ -38,10 +38,8 @@ public:
void writeTerm(const QString &chars); void writeTerm(const QString &chars);
bool failed() { return iFailed; } bool failed() { return iFailed; }
public slots:
void resize(QSize newSize);
private slots: private slots:
void resize(int rows, int columns);
void readActivated(); void readActivated();
private: private:
......
...@@ -294,9 +294,6 @@ Item { ...@@ -294,9 +294,6 @@ Item {
NotifyWin { NotifyWin {
id: aboutDialog id: aboutDialog
property int termW
property int termH
text: { text: {
var str = "<font size=\"+3\">FingerTerm " + util.versionString() + "</font><br>\n" + var str = "<font size=\"+3\">FingerTerm " + util.versionString() + "</font><br>\n" +
"<font size=\"+1\">" + "<font size=\"+1\">" +
...@@ -304,11 +301,11 @@ Item { ...@@ -304,11 +301,11 @@ Item {
"Config files for adjusting settings are at:<br>\n" + "Config files for adjusting settings are at:<br>\n" +
util.configPath() + "/<br><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>" "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 str += "<br><br>Current window title: <font color=\"gray\">" + util.windowTitle.substring(0,40) + "</font>"; //cut long window title
if(util.windowTitle.length>40) if(util.windowTitle.length>40)
str += "..."; 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 += "<br>Charset: <font color=\"gray\">" + util.charset + "</font>";
} }
str += "</font>"; str += "</font>";
......
...@@ -176,7 +176,7 @@ Item { ...@@ -176,7 +176,7 @@ Item {
text: "<font size=\"+3\">+</font>" text: "<font size=\"+3\">+</font>"
onClicked: { onClicked: {
util.fontSize = util.fontSize + window.pixelRatio util.fontSize = util.fontSize + window.pixelRatio
util.notifyText(term.termSize().width+"x"+term.termSize().height); util.notifyText(term.columns + "×" + term.rows);
} }
width: window.buttonWidthHalf width: window.buttonWidthHalf
height: window.buttonHeightSmall height: window.buttonHeightSmall
...@@ -185,7 +185,7 @@ Item { ...@@ -185,7 +185,7 @@ Item {
text: "<font size=\"+3\">-</font>" text: "<font size=\"+3\">-</font>"
onClicked: { onClicked: {
util.fontSize = util.fontSize - window.pixelRatio util.fontSize = util.fontSize - window.pixelRatio
util.notifyText(term.termSize().width+"x"+term.termSize().height); util.notifyText(term.columns + "×" + term.rows);
} }
width: window.buttonWidthHalf width: window.buttonWidthHalf
height: window.buttonHeightSmall height: window.buttonHeightSmall
...@@ -361,8 +361,6 @@ Item { ...@@ -361,8 +361,6 @@ Item {
text: "About" text: "About"
onClicked: { onClicked: {
menuWin.showing = false; menuWin.showing = false;
aboutDialog.termW = term.termSize().width
aboutDialog.termH = term.termSize().height
aboutDialog.show = true aboutDialog.show = true
} }
} }
......
...@@ -128,7 +128,7 @@ void Terminal::setTermSize(QSize size) ...@@ -128,7 +128,7 @@ void Terminal::setTermSize(QSize size)
resetTabs(); resetTabs();
emit termSizeChanged(size); emit termSizeChanged(size.height(), size.width());
} }
} }
...@@ -349,7 +349,7 @@ void Terminal::insertInBuffer(const QString& chars) ...@@ -349,7 +349,7 @@ void Terminal::insertInBuffer(const QString& chars)
if(iNewLineMode) if(iNewLineMode)
setCursorPos(QPoint(1,cursorPos().y())); 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) if(iNewLineMode)
setCursorPos(QPoint(1,cursorPos().y()+1)); setCursorPos(QPoint(1,cursorPos().y()+1));
...@@ -1046,9 +1046,9 @@ void Terminal::escControlChar(const QString& seq) ...@@ -1046,9 +1046,9 @@ void Terminal::escControlChar(const QString& seq)
return; return;
if( seq.at(0) == '#' && seq.at(1)=='8' ) { // test mode, fill screen with 'E' if( seq.at(0) == '#' && seq.at(1)=='8' ) { // test mode, fill screen with 'E'
clearAll(true); clearAll(true);
for(int i=0; i<termSize().height(); i++) { for (int i = 0; i < rows(); i++) {
QList<TermChar> line; QList<TermChar> line;
for(int j=0; j<termSize().width(); j++) { for(int j = 0; j < columns(); j++) {
TermChar c = zeroChar; TermChar c = zeroChar;
c.c = 'E'; c.c = 'E';
line.append(c); line.append(c);
...@@ -1498,6 +1498,16 @@ void Terminal::clearSelection() ...@@ -1498,6 +1498,16 @@ void Terminal::clearSelection()
emit selectionChanged(); emit selectionChanged();
} }
int Terminal::rows()
{
return iTermSize.height();
}
int Terminal::columns()
{
return iTermSize.width();
}
QRect Terminal::selection() QRect Terminal::selection()
{ {
return iSelection; return iSelection;
......
...@@ -53,6 +53,9 @@ struct TermAttribs { ...@@ -53,6 +53,9 @@ struct TermAttribs {
class Terminal : public QObject class Terminal : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int rows READ rows NOTIFY termSizeChanged)
Q_PROPERTY(int columns READ columns NOTIFY termSizeChanged)
public: public:
static const int defaultFgColor = 7; static const int defaultFgColor = 7;
static const int defaultBgColor = 0; static const int defaultBgColor = 0;
...@@ -70,7 +73,7 @@ public: ...@@ -70,7 +73,7 @@ public:
void setCursorPos(QPoint pos); void setCursorPos(QPoint pos);
bool showCursor(); bool showCursor();
Q_INVOKABLE QSize termSize() { return iTermSize; } QSize termSize() { return iTermSize; }
void setTermSize(QSize size); void setTermSize(QSize size);
QList<QList<TermChar> >& buffer(); QList<QList<TermChar> >& buffer();
...@@ -98,11 +101,14 @@ public: ...@@ -98,11 +101,14 @@ public:
Q_INVOKABLE void clearSelection(); Q_INVOKABLE void clearSelection();
bool hasSelection(); bool hasSelection();
int rows();
int columns();
TermChar zeroChar; TermChar zeroChar;
signals: signals:
void cursorPosChanged(QPoint newPos); void cursorPosChanged(QPoint newPos);
void termSizeChanged(QSize newSize); void termSizeChanged(int rows, int columns);
void displayBufferChanged(); void displayBufferChanged();
void selectionChanged(); void selectionChanged();
void scrollBackBufferAdjusted(bool reset); void scrollBackBufferAdjusted(bool reset);
......
...@@ -106,17 +106,17 @@ void TextRender::paint(QPainter* painter) ...@@ -106,17 +106,17 @@ void TextRender::paint(QPainter* painter)
if(from<0) if(from<0)
from=0; from=0;
int to = sTerm->backBuffer().size(); int to = sTerm->backBuffer().size();
if(to-from > sTerm->termSize().height()) if(to-from > sTerm->rows())
to = from + sTerm->termSize().height(); to = from + sTerm->rows();
paintFromBuffer(painter, sTerm->backBuffer(), from, to, y); paintFromBuffer(painter, sTerm->backBuffer(), from, to, y);
if(to-from < sTerm->termSize().height() && sTerm->buffer().size()>0) { if(to-from < sTerm->rows() && sTerm->buffer().size()>0) {
int to2 = sTerm->termSize().height() - (to-from); int to2 = sTerm->rows() - (to-from);
if(to2 > sTerm->buffer().size()) if(to2 > sTerm->buffer().size())
to2 = sTerm->buffer().size(); to2 = sTerm->buffer().size();
paintFromBuffer(painter, sTerm->buffer(), 0, to2, y); paintFromBuffer(painter, sTerm->buffer(), 0, to2, y);
} }
} else { } 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); paintFromBuffer(painter, sTerm->buffer(), 0, count, y);
} }
...@@ -145,12 +145,12 @@ void TextRender::paint(QPainter* painter) ...@@ -145,12 +145,12 @@ void TextRender::paint(QPainter* painter)
end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight()); end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight());
} else { } else {
start = charsToPixels(selection.topLeft()); 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(), painter->drawRect(start.x(), start.y(),
end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight()); end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight());
start = charsToPixels(QPoint(1, selection.top()+1)); 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(), painter->drawRect(start.x(), start.y(),
end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight()); end.x()-start.x()+fontWidth(), end.y()-start.y()+fontHeight());
...@@ -181,7 +181,7 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf ...@@ -181,7 +181,7 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf
else else
painter->setOpacity(1.0); 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 // background for the current line
currentX = leftmargin; 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