x11consolei.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. Constructor TX11Console.Create;
  2. Var
  3. s : AnsiString;
  4. Begin
  5. Inherited Create;
  6. { default flags }
  7. FFlags := [PTC_X11_TRY_XSHM, PTC_X11_TRY_XF86VIDMODE];
  8. FTitle := '';
  9. Configure('/usr/share/ptcpas/ptcpas.conf');
  10. s := fpgetenv('HOME');
  11. If s = '' Then
  12. s := '/';
  13. If s[Length(s)] <> '/' Then
  14. s := s + '/';
  15. s := s + '.ptcpas.conf';
  16. Configure(s);
  17. End;
  18. Destructor TX11Console.Destroy;
  19. Var
  20. I : Integer;
  21. Begin
  22. Close;
  23. FreeAndNil(FX11Display);
  24. For I := Low(FModes) To High(FModes) Do
  25. FreeAndNil(FModes[I]);
  26. Inherited Destroy;
  27. End;
  28. Procedure TX11Console.Configure(Const AFileName : String);
  29. Var
  30. F : Text;
  31. S : String;
  32. Begin
  33. AssignFile(F, AFileName);
  34. {$I-}
  35. Reset(F);
  36. {$I+}
  37. If IOResult <> 0 Then
  38. Exit;
  39. While Not EoF(F) Do
  40. Begin
  41. {$I-}
  42. Readln(F, S);
  43. {$I+}
  44. If IOResult <> 0 Then
  45. Break;
  46. Option(S);
  47. End;
  48. CloseFile(F);
  49. End;
  50. Function TX11Console.Option(Const AOption : String) : Boolean;
  51. Begin
  52. Result := True;
  53. If AOption = 'default output' Then
  54. Begin
  55. { default is windowed for now }
  56. FFlags := FFlags - [PTC_X11_FULLSCREEN];
  57. Exit;
  58. End;
  59. If AOption = 'windowed output' Then
  60. Begin
  61. FFlags := FFlags - [PTC_X11_FULLSCREEN];
  62. Exit;
  63. End;
  64. If AOption = 'fullscreen output' Then
  65. Begin
  66. FFlags := FFlags + [PTC_X11_FULLSCREEN];
  67. Exit;
  68. End;
  69. If AOption = 'leave window open' Then
  70. Begin
  71. FFlags := FFlags + [PTC_X11_LEAVE_WINDOW];
  72. Exit;
  73. End;
  74. If AOption = 'leave display open' Then
  75. Begin
  76. FFlags := FFlags + [PTC_X11_LEAVE_DISPLAY];
  77. Exit;
  78. End;
  79. If AOption = 'dga' Then
  80. Begin
  81. FFlags := FFlags + [PTC_X11_TRY_DGA];
  82. Exit;
  83. End;
  84. If AOption = 'dga off' Then
  85. Begin
  86. FFlags := FFlags - [PTC_X11_TRY_DGA];
  87. Exit;
  88. End;
  89. If AOption = 'xf86vidmode' Then
  90. Begin
  91. FFlags := FFlags + [PTC_X11_TRY_XF86VIDMODE];
  92. Exit;
  93. End;
  94. If AOption = 'xf86vidmode off' Then
  95. Begin
  96. FFlags := FFlags - [PTC_X11_TRY_XF86VIDMODE];
  97. Exit;
  98. End;
  99. If AOption = 'xrandr' Then
  100. Begin
  101. FFlags := FFlags + [PTC_X11_TRY_XRANDR];
  102. Exit;
  103. End;
  104. If AOption = 'xrandr off' Then
  105. Begin
  106. FFlags := FFlags - [PTC_X11_TRY_XRANDR];
  107. Exit;
  108. End;
  109. If AOption = 'xshm' Then
  110. Begin
  111. FFlags := FFlags + [PTC_X11_TRY_XSHM];
  112. Exit;
  113. End;
  114. If AOption = 'xshm off' Then
  115. Begin
  116. FFlags := FFlags - [PTC_X11_TRY_XSHM];
  117. Exit;
  118. End;
  119. If AOption = 'default cursor' Then
  120. Begin
  121. FFlags := FFlags - [PTC_X11_FULLSCREEN_CURSOR_VISIBLE, PTC_X11_WINDOWED_CURSOR_INVISIBLE];
  122. UpdateCursor;
  123. Exit;
  124. End;
  125. If AOption = 'show cursor' Then
  126. Begin
  127. FFlags := (FFlags - [PTC_X11_WINDOWED_CURSOR_INVISIBLE]) + [PTC_X11_FULLSCREEN_CURSOR_VISIBLE];
  128. UpdateCursor;
  129. Exit;
  130. End;
  131. If AOption = 'hide cursor' Then
  132. Begin
  133. FFlags := (FFlags - [PTC_X11_FULLSCREEN_CURSOR_VISIBLE]) + [PTC_X11_WINDOWED_CURSOR_INVISIBLE];
  134. UpdateCursor;
  135. Exit;
  136. End;
  137. If AOption = 'enable logging' Then
  138. Begin
  139. LOG_enabled := True;
  140. Result := True;
  141. Exit;
  142. End;
  143. If AOption = 'disable logging' Then
  144. Begin
  145. LOG_enabled := False;
  146. Result := True;
  147. Exit;
  148. End;
  149. If Assigned(FX11Display) Then
  150. Result := FX11Display.FCopy.Option(AOption)
  151. Else
  152. Result := False;
  153. End;
  154. Function TX11Console.Modes : PPTCMode;
  155. Var
  156. I : Integer;
  157. Begin
  158. For I := Low(FModes) To High(FModes) Do
  159. FreeAndNil(FModes[I]);
  160. If FX11Display = Nil Then
  161. FX11Display := CreateDisplay;
  162. FX11Display.GetModes(FModes);
  163. Result := @FModes[0];
  164. End;
  165. {TODO: Find current pixel depth}
  166. Procedure TX11Console.Open(Const ATitle : String; APages : Integer = 0);
  167. Var
  168. tmp : TPTCFormat;
  169. Begin
  170. tmp := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
  171. Try
  172. Open(ATitle, tmp, APages);
  173. Finally
  174. tmp.Free;
  175. End;
  176. End;
  177. Procedure TX11Console.Open(Const ATitle : String; Const AFormat : TPTCFormat;
  178. APages : Integer = 0);
  179. Begin
  180. Open(ATitle, 640, 480, AFormat, APages);
  181. End;
  182. Procedure TX11Console.Open(Const ATitle : String; Const AMode : TPTCMode;
  183. APages : Integer = 0);
  184. Begin
  185. Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
  186. End;
  187. Function TX11Console.CreateDisplay : TX11Display;
  188. Var
  189. display : PDisplay;
  190. screen : Integer;
  191. Begin
  192. { Check if we can open an X display }
  193. display := XOpenDisplay(Nil);
  194. If display = Nil Then
  195. Raise TPTCError.Create('Cannot open X display');
  196. { DefaultScreen should be fine }
  197. screen := DefaultScreen(display);
  198. {$IFDEF ENABLE_X11_EXTENSION_XF86DGA2}
  199. If PTC_X11_TRY_DGA In FFlags Then
  200. Begin
  201. Try
  202. Result := TX11DGA2Display.Create(display, screen, FFlags + [PTC_X11_LEAVE_DISPLAY]);
  203. Result.SetFlags(FFlags);
  204. Exit;
  205. Except
  206. LOG('DGA 2.0 failed');
  207. End;
  208. End;
  209. {$ENDIF ENABLE_X11_EXTENSION_XF86DGA2}
  210. {$IFDEF ENABLE_X11_EXTENSION_XF86DGA1}
  211. If PTC_X11_TRY_DGA In FFlags Then
  212. Begin
  213. Try
  214. Result := TX11DGA1Display.Create(display, screen, FFlags + [PTC_X11_LEAVE_DISPLAY]);
  215. Result.SetFlags(FFlags);
  216. Except
  217. LOG('DGA 1.0 failed');
  218. End;
  219. End;
  220. {$ENDIF ENABLE_X11_EXTENSION_XF86DGA1}
  221. Result := TX11WindowDisplay.Create(display, screen, FFlags);
  222. End;
  223. Procedure TX11Console.Open(Const ATitle : String; AWidth, AHeight : Integer;
  224. Const AFormat : TPTCFormat; APages : Integer = 0);
  225. Begin
  226. Close;
  227. FTitle := ATitle;
  228. If FX11Display = Nil Then
  229. FX11Display := CreateDisplay;
  230. FX11Display.Open(ATitle, AWidth, AHeight, AFormat);
  231. UpdateCursor;
  232. End;
  233. Procedure TX11Console.Close;
  234. Begin
  235. FreeAndNil(FX11Display);
  236. End;
  237. Procedure TX11Console.Flush;
  238. Begin
  239. Update;
  240. End;
  241. Procedure TX11Console.Finish;
  242. Begin
  243. Update;
  244. End;
  245. Procedure TX11Console.Update;
  246. Begin
  247. FX11Display.Update;
  248. End;
  249. Procedure TX11Console.Update(Const AArea : TPTCArea);
  250. Begin
  251. FX11Display.Update(AArea);
  252. End;
  253. Function TX11Console.NextEvent(Var AEvent : TPTCEvent; AWait : Boolean; Const AEventMask : TPTCEventMask) : Boolean;
  254. Begin
  255. Result := FX11Display.NextEvent(AEvent, AWait, AEventMask);
  256. End;
  257. Function TX11Console.PeekEvent(AWait : Boolean; Const AEventMask : TPTCEventMask) : TPTCEvent;
  258. Begin
  259. Result := FX11Display.PeekEvent(AWait, AEventMask);
  260. End;
  261. Procedure TX11Console.Copy(Var ASurface : TPTCBaseSurface);
  262. Begin
  263. {todo!...}
  264. End;
  265. Procedure TX11Console.Copy(Var ASurface : TPTCBaseSurface;
  266. Const ASource, ADestination : TPTCArea);
  267. Begin
  268. {todo!...}
  269. End;
  270. Function TX11Console.Lock : Pointer;
  271. Begin
  272. Result := FX11Display.Lock;
  273. End;
  274. Procedure TX11Console.Unlock;
  275. Begin
  276. FX11Display.Unlock;
  277. End;
  278. Procedure TX11Console.Load(Const APixels : Pointer;
  279. AWidth, AHeight, APitch : Integer;
  280. Const AFormat : TPTCFormat;
  281. Const APalette : TPTCPalette);
  282. Begin
  283. FX11Display.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette);
  284. End;
  285. Procedure TX11Console.Load(Const APixels : Pointer;
  286. AWidth, AHeight, APitch : Integer;
  287. Const AFormat : TPTCFormat;
  288. Const APalette : TPTCPalette;
  289. Const ASource, ADestination : TPTCArea);
  290. Begin
  291. FX11Display.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination);
  292. End;
  293. Procedure TX11Console.Save(APixels : Pointer;
  294. AWidth, AHeight, APitch : Integer;
  295. Const AFormat : TPTCFormat;
  296. Const APalette : TPTCPalette);
  297. Begin
  298. {todo!...}
  299. End;
  300. Procedure TX11Console.Save(APixels : Pointer;
  301. AWidth, AHeight, APitch : Integer;
  302. Const AFormat : TPTCFormat;
  303. Const APalette : TPTCPalette;
  304. Const ASource, ADestination : TPTCArea);
  305. Begin
  306. {todo!...}
  307. End;
  308. Procedure TX11Console.Clear;
  309. Var
  310. tmp : TPTCColor;
  311. Begin
  312. If Format.Direct Then
  313. tmp := TPTCColor.Create(0, 0, 0, 0)
  314. Else
  315. tmp := TPTCColor.Create(0);
  316. Try
  317. Clear(tmp);
  318. Finally
  319. tmp.Free;
  320. End;
  321. End;
  322. Procedure TX11Console.Clear(Const AColor : TPTCColor);
  323. Begin
  324. FX11Display.Clear(AColor);
  325. End;
  326. Procedure TX11Console.Clear(Const AColor : TPTCColor;
  327. Const AArea : TPTCArea);
  328. Begin
  329. FX11Display.Clear(AColor, AArea);
  330. End;
  331. Procedure TX11Console.Palette(Const APalette : TPTCPalette);
  332. Begin
  333. FX11Display.Palette(APalette);
  334. End;
  335. Function TX11Console.Palette : TPTCPalette;
  336. Begin
  337. Result := FX11Display.Palette;
  338. End;
  339. Procedure TX11Console.Clip(Const AArea : TPTCArea);
  340. Begin
  341. FX11Display.Clip(AArea);
  342. End;
  343. Function TX11Console.GetWidth : Integer;
  344. Begin
  345. Result := FX11Display.Width;
  346. End;
  347. Function TX11Console.GetHeight : Integer;
  348. Begin
  349. Result := FX11Display.Height;
  350. End;
  351. Function TX11Console.GetPitch : Integer;
  352. Begin
  353. Result := FX11Display.Pitch;
  354. End;
  355. Function TX11Console.GetPages : Integer;
  356. Begin
  357. Result := 2;
  358. End;
  359. Function TX11Console.GetArea : TPTCArea;
  360. Begin
  361. Result := FX11Display.Area;
  362. End;
  363. Function TX11Console.Clip : TPTCArea;
  364. Begin
  365. Result := FX11Display.Clip;
  366. End;
  367. Function TX11Console.GetFormat : TPTCFormat;
  368. Begin
  369. Result := FX11Display.Format;
  370. End;
  371. Function TX11Console.GetName : String;
  372. Begin
  373. Result := 'X11';
  374. End;
  375. Function TX11Console.GetTitle : String;
  376. Begin
  377. Result := FTitle;
  378. End;
  379. Function TX11Console.GetInformation : String;
  380. Begin
  381. If FX11Display = Nil Then
  382. Exit('PTC X11');
  383. Result := 'PTC X11, ';
  384. If FX11Display.IsFullScreen Then
  385. Result := Result + 'fullscreen '
  386. Else
  387. Result := Result + 'windowed ';
  388. { TODO: use virtual methods, instead of "is" }
  389. If FX11Display Is TX11WindowDisplay Then
  390. Begin
  391. If TX11WindowDisplay(FX11Display).FPrimary <> Nil Then
  392. Result := Result + '(' + TX11WindowDisplay(FX11Display).FPrimary.Name + ') '
  393. Else
  394. Result := Result + '';
  395. End
  396. Else
  397. Begin
  398. {$IFDEF ENABLE_X11_EXTENSION_XF86DGA2}
  399. If FX11Display Is TX11DGA2Display Then
  400. Result := Result + '(DGA) '
  401. Else
  402. {$ENDIF ENABLE_X11_EXTENSION_XF86DGA2}
  403. {$IFDEF ENABLE_X11_EXTENSION_XF86DGA1}
  404. If FX11Display Is TX11DGA1Display Then
  405. Result := Result + '(DGA) '
  406. Else
  407. {$ENDIF ENABLE_X11_EXTENSION_XF86DGA1}
  408. Begin
  409. {...}
  410. End;
  411. End;
  412. Result := Result + 'mode, ' +
  413. IntToStr(FX11Display.Width) + 'x' +
  414. IntToStr(FX11Display.Height) + ', ' +
  415. IntToStr(FX11Display.Format.Bits) + ' bit';
  416. End;
  417. Procedure TX11Console.UpdateCursor;
  418. Begin
  419. If Assigned(FX11Display) Then
  420. Begin
  421. If FX11Display.IsFullScreen Then
  422. FX11Display.SetCursor(PTC_X11_FULLSCREEN_CURSOR_VISIBLE In FFlags)
  423. Else
  424. FX11Display.SetCursor(Not (PTC_X11_WINDOWED_CURSOR_INVISIBLE In FFlags));
  425. End;
  426. End;