hrev47678 adds 2 changesets to branch 'master' old head: 87e8603d9f4cecce2250564deb85bc2ef5c23bfa new head: e6e13325db17c87f25ae34f955121ae989d5a1d7 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=e6e1332+%5E87e8603 ---------------------------------------------------------------------------- c53c7dd: Style fixes. e6e1332: SerialConnect: some simplifications * Use integers for x and y coordinates in the draw loop, too * Simplify _GetCell by using the return value of vterm_screen_get_cell to detect out of bounds access, instead of testing for that manually. [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 2 files changed, 37 insertions(+), 42 deletions(-) src/apps/serialconnect/SerialApp.cpp | 25 ++++++++------- src/apps/serialconnect/TermView.cpp | 54 ++++++++++++++------------------ ############################################################################ Commit: c53c7dded24f3f9dfbf9da1fb5d6fc062c04faae URL: http://cgit.haiku-os.org/haiku/commit/?id=c53c7dd Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> Date: Wed Aug 13 10:50:06 2014 UTC Style fixes. ---------------------------------------------------------------------------- diff --git a/src/apps/serialconnect/SerialApp.cpp b/src/apps/serialconnect/SerialApp.cpp index 0afb356..e932da6 100644 --- a/src/apps/serialconnect/SerialApp.cpp +++ b/src/apps/serialconnect/SerialApp.cpp @@ -50,7 +50,7 @@ void SerialApp::MessageReceived(BMessage* message) { case kMsgOpenPort: { - if(message->FindString("port name", &fPortPath) == B_OK) + if (message->FindString("port name", &fPortPath) == B_OK) { fSerialPort.Open(fPortPath); release_sem(fSerialLock); @@ -71,7 +71,7 @@ void SerialApp::MessageReceived(BMessage* message) ssize_t length; message->FindData("data", B_RAW_TYPE, (const void**)&bytes, &length); - if(fLogFile->Write(bytes, length) != length) + if (fLogFile->Write(bytes, length) != length) { // TODO error handling } @@ -108,7 +108,7 @@ void SerialApp::MessageReceived(BMessage* message) fLogFile = new BFile(&directory, filename, B_WRITE_ONLY | B_CREATE_FILE | B_OPEN_AT_END); status_t error = fLogFile->InitCheck(); - if(error != B_OK) + if (error != B_OK) { puts(strerror(error)); } @@ -125,19 +125,19 @@ void SerialApp::MessageReceived(BMessage* message) parity_mode parity; uint32 flowcontrol; - if(message->FindInt32("databits", (int32*)&dataBits) == B_OK) + if (message->FindInt32("databits", (int32*)&dataBits) == B_OK) fSerialPort.SetDataBits(dataBits); - if(message->FindInt32("stopbits", (int32*)&stopBits) == B_OK) + if (message->FindInt32("stopbits", (int32*)&stopBits) == B_OK) fSerialPort.SetStopBits(stopBits); - if(message->FindInt32("parity", (int32*)&parity) == B_OK) + if (message->FindInt32("parity", (int32*)&parity) == B_OK) fSerialPort.SetParityMode(parity); - if(message->FindInt32("flowcontrol", (int32*)&flowcontrol) == B_OK) + if (message->FindInt32("flowcontrol", (int32*)&flowcontrol) == B_OK) fSerialPort.SetFlowControl(flowcontrol); - if(message->FindInt32("baudrate", &baudrate) == B_OK) { + if (message->FindInt32("baudrate", &baudrate) == B_OK) { data_rate rate = (data_rate)baudrate; fSerialPort.SetDataRate(rate); } @@ -152,7 +152,7 @@ void SerialApp::MessageReceived(BMessage* message) bool SerialApp::QuitRequested() { - if(BApplication::QuitRequested()) { + if (BApplication::QuitRequested()) { SaveSettings(); return true; } @@ -174,7 +174,7 @@ void SerialApp::LoadSettings() BFile file(path.Path(), B_READ_ONLY); BMessage message(kMsgSettings); - if(message.Unflatten(&file) != B_OK) + if (message.Unflatten(&file) != B_OK) { message.AddInt32("parity", fSerialPort.ParityMode()); message.AddInt32("databits", fSerialPort.DataBits()); @@ -212,7 +212,7 @@ status_t SerialApp::PollSerial(void*) SerialApp* application = (SerialApp*)be_app; char buffer[256]; - for(;;) + for (;;) { ssize_t bytesRead; @@ -228,11 +228,12 @@ status_t SerialApp::PollSerial(void*) be_app_messenger.SendMessage(serialData); } } - + // Should not reach this line anyway... return B_OK; } + const char* SerialApp::kApplicationSignature = "application/x-vnd.haiku.SerialConnect"; ############################################################################ Revision: hrev47678 Commit: e6e13325db17c87f25ae34f955121ae989d5a1d7 URL: http://cgit.haiku-os.org/haiku/commit/?id=e6e1332 Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> Date: Wed Aug 13 11:35:07 2014 UTC SerialConnect: some simplifications * Use integers for x and y coordinates in the draw loop, too * Simplify _GetCell by using the return value of vterm_screen_get_cell to detect out of bounds access, instead of testing for that manually. ---------------------------------------------------------------------------- diff --git a/src/apps/serialconnect/TermView.cpp b/src/apps/serialconnect/TermView.cpp index 07e45bf..9192151 100644 --- a/src/apps/serialconnect/TermView.cpp +++ b/src/apps/serialconnect/TermView.cpp @@ -66,8 +66,8 @@ TermView::Draw(BRect updateRect) for (pos.row = updatedChars.start_row; pos.row <= updatedChars.end_row; pos.row++) { - float x = updatedChars.start_col * fFontWidth + kBorderSpacing; - float y = pos.row * fFontHeight + height.ascent + kBorderSpacing; + int x = updatedChars.start_col * fFontWidth + kBorderSpacing; + int y = pos.row * fFontHeight + (int)ceil(height.ascent) + kBorderSpacing; MovePenTo(x, y); for (pos.col = updatedChars.start_col; @@ -97,14 +97,14 @@ TermView::Draw(BRect updateRect) SetHighColor(foreground); } - FillRect(BRect(x, - y - ceil(height.ascent) + 1, + FillRect(BRect(x, y - ceil(height.ascent) + 1, x + cell.width * fFontWidth - 1, y + ceil(height.descent) + ceil(height.leading)), B_SOLID_LOW); if (cell.chars[0] == 0) { x += fFontWidth; + MovePenTo(x, y); pos.col ++; } else { char buffer[VTERM_MAX_CHARS_PER_CELL]; @@ -112,7 +112,7 @@ TermView::Draw(BRect updateRect) VTERM_MAX_CHARS_PER_CELL); DrawString(buffer); - x += StringWidth(buffer); + x += (int)ceil(StringWidth(buffer)); pos.col += cell.width; } } @@ -279,35 +279,29 @@ TermView::_GlyphsToPixels(const int width, const int height) const void TermView::_GetCell(VTermPos pos, VTermScreenCell& cell) { - int availableRows, availableCols; - vterm_get_size(fTerm, &availableRows, &availableCols); + // First handle cells from the normal screen + if (vterm_screen_get_cell(fTermScreen, pos, &cell) != 0) + return; - if (pos.col < 0 || pos.row < -kScrollBackSize || pos.col >= availableCols - || pos.row >= availableRows) { - // All cells outside the used terminal area are drawn with the same - // background color as the top-left one. - // TODO should they use the attributes of the closest neighbor instead? - VTermPos firstPos; - firstPos.row = 0; - firstPos.col = 0; - vterm_screen_get_cell(fTermScreen, firstPos, &cell); - cell.chars[0] = 0; - cell.width = 1; - } else if (pos.row < 0) { - // This is a cell from the scroll-back buffer + // Try the scroll-back buffer + if (pos.row < 0 && pos.col >= 0) { int offset = - pos.row - 1; ScrollBufferItem* line = (ScrollBufferItem*)fScrollBuffer.ItemAt(offset); - if (line == NULL || pos.col >= line->cols) { - VTermPos firstPos; - firstPos.row = 0; - firstPos.col = 0; - vterm_screen_get_cell(fTermScreen, firstPos, &cell); - cell.chars[0] = 0; - cell.width = 1; - } else + if (line != NULL && pos.col < line->cols) { cell = line->cells[pos.col]; - } else - vterm_screen_get_cell(fTermScreen, pos, &cell); + return; + } + } + + // All cells outside the used terminal area are drawn with the same + // background color as the top-left one. + // TODO should they use the attributes of the closest neighbor instead? + VTermPos firstPos; + firstPos.row = 0; + firstPos.col = 0; + vterm_screen_get_cell(fTermScreen, firstPos, &cell); + cell.chars[0] = 0; + cell.width = 1; }