unixsmsg.inc 3.2 KB

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