You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
8.3 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* X11 screen routines header.
  2. Copyright (c) 2001-2003 by Salvador E. Tropea (SET)
  3. Covered by the GPL license. */
  4. // X headers are needed to include it
  5. #if (defined(TVOS_UNIX) || defined(TVCompf_Cygwin)) && defined(HAVE_X11) && !defined(X11SCR_HEADER_INCLUDED)
  6. #define X11SCR_HEADER_INCLUDED
  7. class TVX11Clipboard;
  8. // virtual to avoid problems with multiple inheritance
  9. class TDisplayX11 : virtual public TDisplay
  10. {
  11. protected:
  12. TDisplayX11() {};
  13. // We will use casts to base classes, destructors must be pointers
  14. virtual ~TDisplayX11();
  15. // This sets the pointers of TDisplay to point to this class
  16. static void Init();
  17. // Behaviors to replace TDisplay
  18. static void SetCursorPos(unsigned x, unsigned y);
  19. static void GetCursorPos(unsigned &x, unsigned &y);
  20. static void GetCursorShape(unsigned &start, unsigned &end);
  21. static void SetCursorShape(unsigned start, unsigned end);
  22. static ushort GetRows();
  23. static ushort GetCols();
  24. // Not available static void SetCrtMode(ushort mode);
  25. // Not available static void SetCrtModeExt(char *mode);
  26. // Not available static ushort GetCrtModeExt()
  27. static int CheckForWindowSize(void);
  28. // Not available static const char *getWindowTitle(void);
  29. // Not available static int setWindowTitle(const char *name);
  30. // Variables for this driver
  31. // Cursor position
  32. static int cursorX, cursorY;
  33. // Cursor position in pixels
  34. static int cursorPX, cursorPY;
  35. // Size of the font
  36. static unsigned fontW,fontWb,fontH,fontSz;
  37. // Cursor shape in absolute values (0-fontH)
  38. static char cShapeFrom,cShapeTo;
  39. // Flag to indicate that the size of the window changed
  40. static char windowSizeChanged;
  41. // Window size in characters
  42. static int maxX, maxY;
  43. // Window size before last resize
  44. static int newX, newY;
  45. };
  46. // With this order the destructor will be called first for TScreenX11,
  47. // TScreen, TDisplayX11 and finally TDisplay.
  48. class TScreenX11 : public TDisplayX11, public TScreen
  49. {
  50. public:
  51. TScreenX11();
  52. // We will use casts to base classes, destructors must be pointers
  53. virtual ~TScreenX11();
  54. friend class TGKeyX11;
  55. friend class THWMouseX11;
  56. friend class TDisplayX11;
  57. friend class TVX11Clipboard;
  58. protected:
  59. // Default: void Resume();
  60. // Default: void Suspend();
  61. // Default: ushort fixCrtMode( ushort mode )
  62. // Default: static void setCrtData();
  63. static void clearScreen();
  64. // Default: static void setVideoMode(ushort mode);
  65. // Default: static void setVideoModeExt(char *mode);
  66. // Default: static void getCharacters(unsigned offset,ushort *buf,unsigned count);
  67. // Default: static ushort getCharacter(unsigned dst);
  68. static void setCharacter(unsigned offset, uint32 value);
  69. static void setCharacterU16(unsigned offset, uint32 value);
  70. static void setCharacters(unsigned dst, ushort *src, unsigned len);
  71. static void setCharactersU16(unsigned offset, ushort *values, unsigned count);
  72. static void setCharactersX11U16(unsigned offset, ushort *values, unsigned w);
  73. static int System(const char *command, pid_t *pidChild, int in, int out, int err);
  74. static int setWindowTitle(const char *aName);
  75. static const char *getWindowTitle(void);
  76. static int SetDisPaletteColors(int from, int number, TScreenColor *colors);
  77. static int GetFontGeometry(unsigned &w, unsigned &h);
  78. static int GetFontGeometryRange(unsigned &wmin, unsigned &hmin,
  79. unsigned &umax, unsigned &hmax);
  80. static int SetFont(int changeP, TScreenFont256 *fontP,
  81. int changeS, TScreenFont256 *fontS,
  82. int fontCP=-1, int appCP=-1);
  83. static void RestoreFonts();
  84. static int SetCrtModeRes(unsigned w, unsigned h, int fW=-1, int fH=-1);
  85. static Boolean ShowBusyState(Boolean state);
  86. static void Beep();
  87. protected:
  88. // Blinking cursor emulation
  89. static void UnDrawCursor();
  90. static void DrawCursor();
  91. static void DisableCursor();
  92. static void EnableCursor();
  93. // Events processing
  94. // Events loop
  95. static void ProcessGenericEvents();
  96. // Internal line update
  97. static void writeLineCP(int x, int y, int w, void *str, unsigned color);
  98. static void writeLineU16(int x, int y, int w, void *str, unsigned color);
  99. static void writeLineX11U16(int x, int y, int w, void *str, unsigned color);
  100. static void (*writeLine)(int x, int y, int w, void *str, unsigned color);
  101. // Internal rectangle update
  102. static void redrawBufCP(int x, int y, unsigned w, unsigned off);
  103. static void redrawBufU16(int x, int y, unsigned w, unsigned off);
  104. static void (*redrawBuf)(int x, int y, unsigned w, unsigned off);
  105. // Font helpers
  106. static void CreateXImageFont(int which, uchar *font, unsigned w, unsigned h);
  107. static void DestroyXImageFont(int which);
  108. // It creates the XImage used for the cursor.
  109. static void AdjustCursorImage();
  110. static TScreenFont256 *ChooseClosestFont(unsigned fW, unsigned fH);
  111. static void FullRedraw();
  112. static void DoResize(unsigned w, unsigned h);
  113. inline
  114. static void drawChar(GC gc, unsigned x, unsigned y, uchar aChar, uchar aAttr);
  115. inline
  116. static void drawCharU16(GC gc, unsigned x, unsigned y, uint16 aChar);
  117. // Creates the mouse cursors
  118. static Boolean createCursors();
  119. // Unicode font helpers
  120. inline // Find which glyph represents the unicode value
  121. static uint16 unicode2index(uint16 unicode);
  122. inline // Ensure the glyph is available as XImage
  123. static void checkUnicodeGlyph(uint16 code);
  124. // Helper to set the bacground and foreground in one step
  125. static void XSetBgFg(uint16 attr);
  126. static void XSetBgFgC(uint16 attr);
  127. // Variables for this driver
  128. // Foreground and background colors
  129. static int fg,bg;
  130. // Cursor state
  131. static char cursorEnabled,cursorInScreen;
  132. // Packed colors
  133. static uchar curAttr;
  134. // Buffer for cursor shape
  135. static char *cursorData;
  136. // Timers for the cursor blinking
  137. static struct timeval refCursorTime, curCursorTime;
  138. // X display we are connected
  139. static Display *disp;
  140. // Screen we are on
  141. static ulong screen;
  142. static Visual *visual;
  143. // The parent of all the windows
  144. static Window rootWin;
  145. // The main window, that's the visible thing where we draw
  146. static Window mainWin;
  147. // Color map we have
  148. static Colormap cMap;
  149. // Normal graphics context
  150. static GC gc;
  151. // Cursor graphics context
  152. static GC cursorGC;
  153. // Internationalization stuff
  154. static XIC xic;
  155. static XIM xim;
  156. // Needed to catch the windows close
  157. static Atom theProtocols;
  158. // Our colors mapped to X ones
  159. static ulong colorMap[16];
  160. // The images that makes our font
  161. static XImage *ximgFont[256];
  162. static XImage *ximgSecFont[256];
  163. // The image for the cursor
  164. static XImage *cursorImage;
  165. // Hints about our size preferences
  166. static XSizeHints *sizeHints;
  167. // Window class and resources name
  168. static XClassHint *classHint;
  169. // Default fonts
  170. static TScreenFont256 font8x16;
  171. static TScreenFont256 font10x20;
  172. static TScreenFont256 *defaultFont;
  173. static uchar shapeFont10x20[];
  174. static uchar shapeFont8x16[];
  175. static uchar primaryFontChanged;
  176. // Should we hide the cursor when we lose the focus?
  177. static char hideCursorWhenNoFocus;
  178. // Avoid resizing to a cells multiple if the WM doesn't follow our hints
  179. static char dontResizeToCells;
  180. // Busy cursor stuff
  181. static Cursor busyCursor, leftPtr;
  182. static char busyCursorMap[];
  183. static char busyCursorMask[];
  184. // For testing purposes should be removed
  185. void LoadFontAsUnicode();
  186. char *SearchX11Font(const char *foundry, const char *family, int w, int h);
  187. char *SearchX11Font(const char *foundry, const char *family);
  188. char *SearchX11Font(const char *pattern);
  189. };
  190. // A small class to encapsulate the cliboard, this is too tied to TScreen
  191. class TVX11Clipboard
  192. {
  193. public:
  194. TVX11Clipboard() {};
  195. protected:
  196. static int copy(int id, const char *buffer, unsigned len);
  197. static char *paste(int id, unsigned &len);
  198. static void destroy();
  199. static void Init();
  200. static char *buffer;
  201. static unsigned length;
  202. static Atom property;
  203. static int waiting;
  204. static const
  205. char *x11NameError[];
  206. friend class TScreenX11;
  207. };
  208. const int x11clipNoSelection=1,
  209. x11clipWrongType=2,
  210. x11clipNoData=3,
  211. x11clipX11Error=4,
  212. x11clipAnother=5,
  213. x11clipErrors=5;
  214. #define aMouseEvent (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
  215. #define aKeyEvent (KeyPressMask | KeyReleaseMask)
  216. #define charPos 0
  217. #define attrPos 1
  218. #endif // X11SCR_HEADER_INCLUDED