The Pedigree Project  0.1
Terminal.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef TERMINAL_H
21 #define TERMINAL_H
22 
23 #include "environment.h"
24 #include <syslog.h>
25 
26 #ifndef NEW_XTERM
27 #include "Xterm.h"
28 #else
29 #include "Vt100.h"
30 #endif
31 
32 #include "pedigree/native/graphics/Graphics.h"
33 
34 #include <cairo/cairo.h>
35 
38 class Terminal
39 {
40  public:
41  friend class Xterm;
42  Terminal(
43  char *pName, size_t nWidth, size_t nHeight, size_t offsetLeft,
44  size_t offsetTop, rgb_t *pBackground, cairo_t *pCairo,
45  class Widget *pWidget, class Tui *pTui, class Font *pNormalFont,
46  class Font *pBoldFont);
47  ~Terminal();
48 
49  bool initialise();
50 
52  bool isAlive();
53 
55  void renewBuffer(size_t nWidth, size_t nHeight);
56 
58  void processKey(uint64_t key);
59 
61  void clearQueue();
62 
64  char getFromQueue();
65 
67  size_t queueLength()
68  {
69  return m_Len;
70  }
71 
74  int getSelectFd() const
75  {
76  return m_MasterPty;
77  }
78 
80  void write(const char *pStr, DirtyRectangle &rect);
81 
82  void setHasPendingRequest(bool b, size_t sz)
83  {
84  m_bHasPendingRequest = b;
85  m_PendingRequestSz = sz;
86  }
87 
88  bool hasPendingRequest()
89  {
90  return m_bHasPendingRequest;
91  }
92  size_t getPendingRequestSz()
93  {
94  return m_PendingRequestSz;
95  }
96 
97  void setActive(bool b, DirtyRectangle &rect);
98 
99  size_t getRows()
100  {
101  return m_pXterm->getRows();
102  }
103  size_t getCols()
104  {
105  return m_pXterm->getCols();
106  }
107 
108  void redrawAll(DirtyRectangle &rect)
109  {
110  m_pXterm->renderAll(rect);
111  }
112 
113  void refresh()
114  {
115  // Force our buffer to the screen
116  if (m_pFramebuffer)
117  m_pFramebuffer->redraw(
118  0, 0, m_pFramebuffer->getWidth(), m_pFramebuffer->getHeight(),
119  false);
120  }
121 
122  rgb_t *getBuffer()
123  {
124  return m_pBuffer;
125  }
126 
127  int getPid()
128  {
129  return m_Pid;
130  }
131 
132  void showCursor(DirtyRectangle &rect)
133  {
134  m_pXterm->showCursor(rect);
135  }
136 
137  void hideCursor(DirtyRectangle &rect)
138  {
139  m_pXterm->hideCursor(rect);
140  }
141 
142  void setCursorStyle(bool bFilled = true)
143  {
144  m_pXterm->setCursorStyle(bFilled);
145  }
146 
148  void cancel()
149  {
150  if (m_WriteInProgress)
151  {
152  m_Cancel = 1;
153  }
154  }
155 
156  void setCairo(cairo_t *pCairo, cairo_surface_t *pSurface)
157  {
158  m_pXterm->setCairo(pCairo, pSurface);
159  }
160 
161  void setFonts(Font *pNormalFont, Font *pBoldFont)
162  {
163  m_pXterm->setFonts(pNormalFont, pBoldFont);
164  }
165 
166  private:
167  Terminal(const Terminal &);
168  Terminal &operator=(const Terminal &);
169 
170  void addToQueue(char c, bool bFlush = false);
171 
172  rgb_t *m_pBuffer;
173 
174  PedigreeGraphics::Framebuffer *m_pFramebuffer;
175 #ifndef NEW_XTERM
176  Xterm *m_pXterm;
177 #else
178  Vt100 *m_pXterm;
179 #endif
180 
181  char m_pName[256];
182 
183  char m_pQueue[256];
184  size_t m_Len;
185 
186  char m_pWriteBuffer[4];
187  size_t m_WriteBufferLen;
188 
189  bool m_bHasPendingRequest;
190  size_t m_PendingRequestSz;
191 
192  int m_Pid;
193 
194  int m_MasterPty;
195 
196  size_t m_OffsetLeft, m_OffsetTop;
197 
198  volatile char m_Cancel;
199  volatile bool m_WriteInProgress;
200 };
201 
202 #endif
void processKey(uint64_t key)
Definition: Terminal.cc:251
Definition: tui.h:36
char getFromQueue()
Definition: Terminal.cc:256
void write(const char *pStr, DirtyRectangle &rect)
Definition: Terminal.cc:275
void renderAll(DirtyRectangle &rect)
Definition: Xterm.cc:1554
Definition: Font.h:33
bool initialise()
Definition: Terminal.cc:85
Definition: Xterm.h:44
void clearQueue()
Definition: Terminal.cc:270
void renewBuffer(size_t nWidth, size_t nHeight)
Definition: Terminal.cc:240
int getSelectFd() const
Definition: Terminal.h:74
bool isAlive()
Definition: Terminal.cc:225
Definition: Widget.h:63
void cancel()
Definition: Terminal.h:148
size_t queueLength()
Definition: Terminal.h:67
void redraw(size_t x=~0UL, size_t y=~0UL, size_t w=~0UL, size_t h=~0UL, bool bChild=false)