69 m_LocalData->nWidth = width;
70 m_LocalData->nHeight = height;
72 if (!m_LocalData->pCairo) {
73 pedigree_log(LOG_ALERT,
"TUI: cairo instance is not yet valid!");
77 cairo_set_line_cap(m_LocalData->pCairo, CAIRO_LINE_CAP_SQUARE);
78 cairo_set_line_join(m_LocalData->pCairo, CAIRO_LINE_JOIN_MITER);
79 cairo_set_antialias(m_LocalData->pCairo, CAIRO_ANTIALIAS_NONE);
80 cairo_set_line_width(m_LocalData->pCairo, 1.0);
82 cairo_set_operator(m_LocalData->pCairo, CAIRO_OPERATOR_SOURCE);
83 cairo_set_source_rgba(m_LocalData->pCairo, 0, 0, 0, 1.0);
84 cairo_paint(m_LocalData->pCairo);
86 if (!m_LocalData->pNormalFont) {
87 m_LocalData->pNormalFont =
new Font(m_LocalData->pCairo, 14,
"DejaVu Sans Mono 10",
true, 0);
88 if (!m_LocalData->pNormalFont) {
89 pedigree_log(LOG_EMERG,
"Error: Normal font not loaded!");
94 if (!m_LocalData->pBoldFont) {
95 m_LocalData->pBoldFont =
new Font(m_LocalData->pCairo, 14,
"DejaVu Sans Mono Bold 10",
true, 0);
96 if (!m_LocalData->pBoldFont) {
97 pedigree_log(LOG_EMERG,
"Error: Bold font not loaded!");
102 if (m_LocalData->pTerminal) {
103 delete m_LocalData->pTerminal;
106 char newTermName[256];
107 sprintf(newTermName,
"Console%d", getpid());
111 m_LocalData->pTerminal =
new Terminal(newTermName, m_LocalData->nWidth, m_LocalData->nHeight, 0,
112 0, 0, m_LocalData->pCairo, m_pWidget,
this,
113 m_LocalData->pNormalFont, m_LocalData->pBoldFont);
114 m_LocalData->pTerminal->setCairo(m_LocalData->pCairo, m_LocalData->pSurface);
116 delete m_LocalData->pTerminal;
117 m_LocalData->pTerminal =
nullptr;
119 m_LocalData->pTerminal->setActive(
true, rect);
120 m_LocalData->pTerminal->redrawAll(rect);
124 rect.point(m_LocalData->nWidth, m_LocalData->nHeight);
126 if (!m_LocalData->pTerminal) {
127 pedigree_log(LOG_ALERT,
"TUI: couldn't start up a terminal - failing gracefully...");
128 m_LocalData->pBoldFont->render(
"There are no pseudo-terminals available.", 5, 5, 0xFFFFFF,
130 m_LocalData->pBoldFont->render(
"Press any key to close this window.", 5,
131 m_LocalData->pBoldFont->getHeight() + 5, 0xFFFFFF, 0x000000,
136 m_LocalData->bKeyPressed =
false;
137 while (!m_LocalData->bKeyPressed) {
163 if (!(m_LocalData->nWidth && m_LocalData->nHeight)) {
168 if (m_LocalData->pSurface) {
169 cairo_surface_destroy(m_LocalData->pSurface);
170 cairo_destroy(m_LocalData->pCairo);
174 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, m_LocalData->nWidth);
175 memset(fb, 0, m_LocalData->nHeight * stride);
177 m_LocalData->pSurface = cairo_image_surface_create_for_data(
178 (uint8_t*)fb, CAIRO_FORMAT_ARGB32, m_LocalData->nWidth, m_LocalData->nHeight, stride);
179 m_LocalData->pCairo = cairo_create(m_LocalData->pSurface);
181 if (m_LocalData->pTerminal) {
182 m_LocalData->pTerminal->setCairo(m_LocalData->pCairo, m_LocalData->pSurface);
185 if (m_LocalData->pNormalFont) {
186 m_LocalData->pNormalFont->updateCairo(m_LocalData->pCairo);
189 if (m_LocalData->pBoldFont) {
190 m_LocalData->pBoldFont->updateCairo(m_LocalData->pCairo);
195 m_LocalData->nWidth = newWidth;
196 m_LocalData->nHeight = newHeight;
198 if (!(m_LocalData->pTerminal && m_LocalData->pCairo)) {
204 cairo_set_operator(m_LocalData->pCairo, CAIRO_OPERATOR_SOURCE);
205 cairo_set_source_rgba(m_LocalData->pCairo, 0, 0, 0, 0.8);
206 cairo_rectangle(m_LocalData->pCairo, 0, 0, m_LocalData->nWidth, m_LocalData->nHeight);
207 cairo_fill(m_LocalData->pCairo);
209 if (m_LocalData->pTerminal) {
210 m_LocalData->pTerminal->
renewBuffer(newWidth, newHeight);
213 m_LocalData->pTerminal->redrawAll(rect);
214 m_LocalData->pTerminal->showCursor(rect);
217 kill(m_LocalData->pTerminal->getPid(), SIGWINCH);
222 size_t maxBuffSz = 32768;
225 m_LocalData->bRunning =
true;
226 while (m_LocalData->bRunning) {
237 if (m_LocalData->pTerminal) {
238 if (!m_LocalData->pTerminal->
isAlive()) {
239 m_LocalData->bRunning =
false;
247 if (!m_LocalData->bRunning) {
251 int nReady = select(n + 1, &fds, NULL, NULL, 0);
258 if (FD_ISSET(m_pWidget->
getSocket(), &fds)) {
270 bool bShouldRedraw =
false;
273 if (m_LocalData->pTerminal) {
275 if (FD_ISSET(fd, &fds)) {
277 ssize_t len = read(fd, buffer, maxBuffSz);
279 m_LocalData->pTerminal->
write(buffer,
static_cast<size_t>(len), dirtyRect);
280 bShouldRedraw =
true;
290 pedigree_log(LOG_INFO,
"TUI shutting down cleanly.");
310 if (rect.getX() == ~0UL && rect.getY() == ~0UL && rect.getX2() == 0 && rect.getY2() == 0) {
315 if (m_LocalData->pSurface) {
316 cairo_surface_flush(m_LocalData->pSurface);
321 }
else if (m_pRedrawer) {
322 m_pRedrawer->redraw(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());