Browse Source

* add window resizing support for unix

pierre 23 years ago
parent
commit
d51ea019eb
4 changed files with 152 additions and 8 deletions
  1. 7 1
      fv/platform.inc
  2. 69 3
      fv/unixsmsg.inc
  3. 7 1
      fvision/platform.inc
  4. 69 3
      fvision/unixsmsg.inc

+ 7 - 1
fv/platform.inc

@@ -196,18 +196,21 @@ FOR FPC THESE ARE THE TRANSLATIONS
   {$UNDEF OS_DOS}
   {$UNDEF OS_DOS}
   {$DEFINE OS_LINUX}
   {$DEFINE OS_LINUX}
   {$DEFINE OS_UNIX}
   {$DEFINE OS_UNIX}
+  {$DEFINE HasSysMsgUnit}
 {$ENDIF}
 {$ENDIF}
 
 
 {$IFDEF FreeBSD}
 {$IFDEF FreeBSD}
   {$UNDEF OS_DOS}
   {$UNDEF OS_DOS}
   {$DEFINE OS_FREEBSD}
   {$DEFINE OS_FREEBSD}
   {$DEFINE OS_UNIX}
   {$DEFINE OS_UNIX}
+  {$DEFINE HasSysMsgUnit}
 {$ENDIF}
 {$ENDIF}
 
 
 {$IFDEF NETBSD}
 {$IFDEF NETBSD}
   {$UNDEF OS_DOS}
   {$UNDEF OS_DOS}
   {$DEFINE OS_NETBSD}
   {$DEFINE OS_NETBSD}
   {$DEFINE OS_UNIX}
   {$DEFINE OS_UNIX}
+  {$DEFINE HasSysMsgUnit}
 {$ENDIF}
 {$ENDIF}
 
 
 
 
@@ -400,7 +403,10 @@ FOR FPC THESE ARE THE TRANSLATIONS
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.8  2002-06-02 08:32:51  marco
+ Revision 1.9  2002-06-07 14:15:10  pierre
+  * add window resizing support for unix
+
+ Revision 1.8  2002/06/02 08:32:51  marco
   * renamefest
   * renamefest
 
 
  Revision 1.7  2002/05/21 12:02:02  pierre
  Revision 1.7  2002/05/21 12:02:02  pierre

+ 69 - 3
fv/unixsmsg.inc

@@ -24,15 +24,45 @@
 { This file is still a dummy,
 { This file is still a dummy,
   it should use ioctl to get information about resizing of windows }
   it should use ioctl to get information about resizing of windows }
 
 
+uses
+{$ifdef VER1_0}
+  linux;
+{$else}
+  unix;
+{$endif}
+
 Const
 Const
   SystemEventActive : Boolean = false;
   SystemEventActive : Boolean = false;
 
 
+type
+  TWinSize = record
+    ws_row, ws_col, ws_xpixel, ws_ypixel : smallint;
+  end;
+
+
+var
+  lastxsize,lastysize : longint;
 
 
 procedure InitSystemMsg;
 procedure InitSystemMsg;
+var
+  WinSize : TWinSize;
 begin
 begin
   If SystemEventActive then
   If SystemEventActive then
     exit;
     exit;
   { Code to enable size tracking should go here }
   { Code to enable size tracking should go here }
+  PendingSystemHead:=@PendingSystemEvent;
+  PendingSystemTail:=@PendingSystemEvent;
+  PendingSystemEvents:=0;
+  FillChar(LastSystemEvent,sizeof(TSystemEvent),0);
+  FillChar(WinSize,sizeof(WinSize),0);
+  ioctl(stdinputhandle,TIOCGWINSZ,@winsize);
+  LastXSize:=WinSize.ws_row;
+  LastYSize:=WinSize.ws_col;
+  If LastXSize=0 then
+    LastXSize:=80;
+  If LastYSize=0 then
+    LastYSize:=25;
+
   SystemEventActive:=true;
   SystemEventActive:=true;
 end;
 end;
 
 
@@ -47,22 +77,58 @@ end;
 
 
 procedure GetSystemEvent(var SystemEvent: TSystemEvent);
 procedure GetSystemEvent(var SystemEvent: TSystemEvent);
 begin
 begin
-  PollSystemEvent(SystemEvent);
+  if PendingSystemEvents=0 then
+    PollSystemEvent(SystemEvent);
+  if PendingSystemEvents=0 then
+    exit;
+  SystemEvent:=PendingSystemHead^;
+  inc(PendingSystemHead);
+  if longint(PendingSystemHead)=longint(@PendingSystemEvent)+sizeof(PendingSystemEvent) then
+   PendingSystemHead:=@PendingSystemEvent;
+  dec(PendingSystemEvents);
+  LastSystemEvent:=SystemEvent;
 end;
 end;
 
 
+
 function PollSystemEvent(var SystemEvent: TSystemEvent):boolean;
 function PollSystemEvent(var SystemEvent: TSystemEvent):boolean;
 var
 var
   CloseState : word;
   CloseState : word;
+  WinSize : TWinSize;
 begin
 begin
   SystemEvent.typ:=SysNothing;
   SystemEvent.typ:=SysNothing;
   if not SystemEventActive then
   if not SystemEventActive then
     exit(false);
     exit(false);
-  PollSystemEvent:=false;
+  if PendingSystemEvents>0 then
+   begin
+     SystemEvent:=PendingSystemHead^;
+     PollSystemEvent:=true;
+   end
+  else
+   begin
+     FillChar(WinSize,sizeof(WinSize),0);
+     ioctl(stdinputhandle,TIOCGWINSZ,@winsize);
+     if (winsize.ws_col<>0) and (winsize.ws_row<>0) and
+        ((winsize.ws_row<>lastxsize) or (winsize.ws_col<>lastysize)) then
+       begin
+         SystemEvent.typ:=SysResize;
+         SystemEvent.x:=WinSize.ws_row;
+         SystemEvent.y:=WinSize.ws_col;
+         PutSystemEvent(SystemEvent);
+         LastXSize:=WinSize.ws_row;
+         LastYSize:=WinSize.ws_col;
+         PollSystemEvent:=true;
+       end
+     else
+       PollSystemEvent:=false;
+    end;
 end;
 end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.1  2002-05-21 11:59:57  pierre
+  Revision 1.2  2002-06-07 14:15:10  pierre
+   * add window resizing support for unix
+
+  Revision 1.1  2002/05/21 11:59:57  pierre
    + system messages unit added
    + system messages unit added
 
 
 }
 }

+ 7 - 1
fvision/platform.inc

@@ -196,18 +196,21 @@ FOR FPC THESE ARE THE TRANSLATIONS
   {$UNDEF OS_DOS}
   {$UNDEF OS_DOS}
   {$DEFINE OS_LINUX}
   {$DEFINE OS_LINUX}
   {$DEFINE OS_UNIX}
   {$DEFINE OS_UNIX}
+  {$DEFINE HasSysMsgUnit}
 {$ENDIF}
 {$ENDIF}
 
 
 {$IFDEF FreeBSD}
 {$IFDEF FreeBSD}
   {$UNDEF OS_DOS}
   {$UNDEF OS_DOS}
   {$DEFINE OS_FREEBSD}
   {$DEFINE OS_FREEBSD}
   {$DEFINE OS_UNIX}
   {$DEFINE OS_UNIX}
+  {$DEFINE HasSysMsgUnit}
 {$ENDIF}
 {$ENDIF}
 
 
 {$IFDEF NETBSD}
 {$IFDEF NETBSD}
   {$UNDEF OS_DOS}
   {$UNDEF OS_DOS}
   {$DEFINE OS_NETBSD}
   {$DEFINE OS_NETBSD}
   {$DEFINE OS_UNIX}
   {$DEFINE OS_UNIX}
+  {$DEFINE HasSysMsgUnit}
 {$ENDIF}
 {$ENDIF}
 
 
 
 
@@ -400,7 +403,10 @@ FOR FPC THESE ARE THE TRANSLATIONS
 
 
 {
 {
  $Log$
  $Log$
- Revision 1.8  2002-06-02 08:32:51  marco
+ Revision 1.9  2002-06-07 14:15:10  pierre
+  * add window resizing support for unix
+
+ Revision 1.8  2002/06/02 08:32:51  marco
   * renamefest
   * renamefest
 
 
  Revision 1.7  2002/05/21 12:02:02  pierre
  Revision 1.7  2002/05/21 12:02:02  pierre

+ 69 - 3
fvision/unixsmsg.inc

@@ -24,15 +24,45 @@
 { This file is still a dummy,
 { This file is still a dummy,
   it should use ioctl to get information about resizing of windows }
   it should use ioctl to get information about resizing of windows }
 
 
+uses
+{$ifdef VER1_0}
+  linux;
+{$else}
+  unix;
+{$endif}
+
 Const
 Const
   SystemEventActive : Boolean = false;
   SystemEventActive : Boolean = false;
 
 
+type
+  TWinSize = record
+    ws_row, ws_col, ws_xpixel, ws_ypixel : smallint;
+  end;
+
+
+var
+  lastxsize,lastysize : longint;
 
 
 procedure InitSystemMsg;
 procedure InitSystemMsg;
+var
+  WinSize : TWinSize;
 begin
 begin
   If SystemEventActive then
   If SystemEventActive then
     exit;
     exit;
   { Code to enable size tracking should go here }
   { Code to enable size tracking should go here }
+  PendingSystemHead:=@PendingSystemEvent;
+  PendingSystemTail:=@PendingSystemEvent;
+  PendingSystemEvents:=0;
+  FillChar(LastSystemEvent,sizeof(TSystemEvent),0);
+  FillChar(WinSize,sizeof(WinSize),0);
+  ioctl(stdinputhandle,TIOCGWINSZ,@winsize);
+  LastXSize:=WinSize.ws_row;
+  LastYSize:=WinSize.ws_col;
+  If LastXSize=0 then
+    LastXSize:=80;
+  If LastYSize=0 then
+    LastYSize:=25;
+
   SystemEventActive:=true;
   SystemEventActive:=true;
 end;
 end;
 
 
@@ -47,22 +77,58 @@ end;
 
 
 procedure GetSystemEvent(var SystemEvent: TSystemEvent);
 procedure GetSystemEvent(var SystemEvent: TSystemEvent);
 begin
 begin
-  PollSystemEvent(SystemEvent);
+  if PendingSystemEvents=0 then
+    PollSystemEvent(SystemEvent);
+  if PendingSystemEvents=0 then
+    exit;
+  SystemEvent:=PendingSystemHead^;
+  inc(PendingSystemHead);
+  if longint(PendingSystemHead)=longint(@PendingSystemEvent)+sizeof(PendingSystemEvent) then
+   PendingSystemHead:=@PendingSystemEvent;
+  dec(PendingSystemEvents);
+  LastSystemEvent:=SystemEvent;
 end;
 end;
 
 
+
 function PollSystemEvent(var SystemEvent: TSystemEvent):boolean;
 function PollSystemEvent(var SystemEvent: TSystemEvent):boolean;
 var
 var
   CloseState : word;
   CloseState : word;
+  WinSize : TWinSize;
 begin
 begin
   SystemEvent.typ:=SysNothing;
   SystemEvent.typ:=SysNothing;
   if not SystemEventActive then
   if not SystemEventActive then
     exit(false);
     exit(false);
-  PollSystemEvent:=false;
+  if PendingSystemEvents>0 then
+   begin
+     SystemEvent:=PendingSystemHead^;
+     PollSystemEvent:=true;
+   end
+  else
+   begin
+     FillChar(WinSize,sizeof(WinSize),0);
+     ioctl(stdinputhandle,TIOCGWINSZ,@winsize);
+     if (winsize.ws_col<>0) and (winsize.ws_row<>0) and
+        ((winsize.ws_row<>lastxsize) or (winsize.ws_col<>lastysize)) then
+       begin
+         SystemEvent.typ:=SysResize;
+         SystemEvent.x:=WinSize.ws_row;
+         SystemEvent.y:=WinSize.ws_col;
+         PutSystemEvent(SystemEvent);
+         LastXSize:=WinSize.ws_row;
+         LastYSize:=WinSize.ws_col;
+         PollSystemEvent:=true;
+       end
+     else
+       PollSystemEvent:=false;
+    end;
 end;
 end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.1  2002-05-21 11:59:57  pierre
+  Revision 1.2  2002-06-07 14:15:10  pierre
+   * add window resizing support for unix
+
+  Revision 1.1  2002/05/21 11:59:57  pierre
    + system messages unit added
    + system messages unit added
 
 
 }
 }