unixsmsg.inc 3.7 KB

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