unixsmsg.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. {
  2. System dependent system messages for unix
  3. Copyright (c) 2002 by Pierre Muller
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public
  11. License along with this library; if not, write to the Free
  12. Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  13. MA 02110-1301, USA.
  14. }
  15. { This file is still a dummy,
  16. it should use ioctl to get information about resizing of windows }
  17. uses
  18. BaseUnix,termio;
  19. Const
  20. SystemEventActive : Boolean = false;
  21. var
  22. lastxsize,lastysize : longint;
  23. procedure InitSystemMsg;
  24. var
  25. WinSize : TWinSize;
  26. begin
  27. If SystemEventActive then
  28. exit;
  29. { Code to enable size tracking should go here }
  30. PendingSystemHead:=@PendingSystemEvent;
  31. PendingSystemTail:=@PendingSystemEvent;
  32. PendingSystemEvents:=0;
  33. FillChar(LastSystemEvent,sizeof(TSystemEvent),0);
  34. FillChar(WinSize,sizeof(WinSize),0);
  35. fpioctl(stdinputhandle,TIOCGWINSZ,@winsize);
  36. LastXSize:=WinSize.ws_row;
  37. LastYSize:=WinSize.ws_col;
  38. If LastXSize=0 then
  39. LastXSize:=80;
  40. If LastYSize=0 then
  41. LastYSize:=25;
  42. SystemEventActive:=true;
  43. end;
  44. procedure DoneSystemMsg;
  45. begin
  46. if not SystemEventActive then
  47. exit;
  48. { Code to disable size tracking should go here }
  49. SystemEventActive:=false;
  50. end;
  51. procedure GetSystemEvent(var SystemEvent: TSystemEvent);
  52. begin
  53. if PendingSystemEvents=0 then
  54. PollSystemEvent(SystemEvent);
  55. if PendingSystemEvents=0 then
  56. exit;
  57. SystemEvent:=PendingSystemHead^;
  58. inc(PendingSystemHead);
  59. if longint(PendingSystemHead)=longint(@PendingSystemEvent)+sizeof(PendingSystemEvent) then
  60. PendingSystemHead:=@PendingSystemEvent;
  61. dec(PendingSystemEvents);
  62. LastSystemEvent:=SystemEvent;
  63. end;
  64. function PollSystemEvent(var SystemEvent: TSystemEvent):boolean;
  65. var
  66. CloseState : word;
  67. WinSize : TWinSize;
  68. begin
  69. SystemEvent.typ:=SysNothing;
  70. if not SystemEventActive then
  71. exit(false);
  72. if PendingSystemEvents>0 then
  73. begin
  74. SystemEvent:=PendingSystemHead^;
  75. PollSystemEvent:=true;
  76. end
  77. else
  78. begin
  79. FillChar(WinSize,sizeof(WinSize),0);
  80. fpioctl(stdinputhandle,TIOCGWINSZ,@winsize);
  81. if (winsize.ws_col<>0) and (winsize.ws_row<>0) and
  82. ((winsize.ws_row<>lastxsize) or (winsize.ws_col<>lastysize)) then
  83. begin
  84. SystemEvent.typ:=SysResize;
  85. SystemEvent.x:=WinSize.ws_col;
  86. SystemEvent.y:=WinSize.ws_row;
  87. PutSystemEvent(SystemEvent);
  88. LastXSize:=WinSize.ws_row;
  89. LastYSize:=WinSize.ws_col;
  90. PollSystemEvent:=true;
  91. end
  92. else
  93. PollSystemEvent:=false;
  94. end;
  95. end;